#!/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();