#!/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


In reply to Re: Gtk2 window dragging by FreeBeerReekingMonk
in thread 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.