in reply to Gtk2 window dragging

#!/usr/bin/perl package dragwin; use strict; use diagnostics; use warnings; use Gtk2 '-init'; # Want to detect when the user drags a window across the desktop # Specifically, when the user releases their mouse button, meaning the # drag operation has finished my ($mouse_x, $mouse_y, $mask); my ($window_x, $window_y); # Create the window my $window = Gtk2::Window->new(); $window->set_title('Drag me!'); $window->set_position('center'); $window->set_default_size(300, 300); $window->set_border_width(5); $window->signal_connect (destroy => sub { Gtk2->main_quit; }); # We want to detect the end of a drag, but this doesn't work $window->signal_connect('event' => sub { my ($widget, $event) = @_; print "Window event type: " . $event->type . "\n"; exit 0 if $event->type eq "delete"; # Get mouse position (undef, $mouse_x, $mouse_y, $mask) = Gtk2::Gdk::Screen->get_default->get_root_window->get_pointer; # Get Windows (top-left) position ($window_x, $window_y) = $window->get_position; # print current positions print "POS($mouse_x,$mouse_y) - ($window_x, $window_y)\n"; }); # Open the window $window->show_all(); Gtk2->main();

See a perlmonk post here: node_id=980493 and the GTK Window webpage

Replies are listed 'Best First'.
Re^2: Gtk2 window dragging
by Anonymous Monk on May 19, 2015 at 13:31 UTC

    Thanks! But, this only tells me how to check the window's current position. It doesn't tell me that a drag has started, or that a drag has stopped.

    I want to take some action at the end of the drag operation, for example displaying a message, or even moving the window back to its original position.

    I could check the window's position after every Gtk2 event, of course. But this only tells me that the window is moving. It doesn't tell me when the window has stopped moving.

      Hmm.. I am afraid you will need to do it that old fashioned way. Detect a focus change event, then check with your recorded X,Y, if the same, it is a window move start and on the next focus change event, that is the window move end...
      I tried signal_connect to all these other events: http://gtk2-perl.sourceforge.net/doc/gtk2-perl-tut/sec-Events.html They do not give anything for window...