I want to write a script that detects when the user moves a Gtk2 window across the desktop.

Specifically, I want to know when the user releases the mouse button, at the end of the drag operation, so that I can check the window's new position.

This C tutorial has the right idea, but I can't work out how to do the same thing in Perl:

http://zetcode.com/tutorials/gtktutorial/gtkevents/

The Gtk2 Perl tutorial covers drag-and-drop operations, but I don't want to drop the Gtk2 window into another widget:

http://gtk2-perl.sourceforge.net/doc/gtk2-perl-study-guide/c5651.html

How can I amend the script below?

#!/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 # 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"; }); # Open the window $window->show_all(); Gtk2->main();

In reply to Gtk2 window dragging by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.