Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

MY KINGDOM FOR A PIXBUF! :D

I'm building a Perl script that follows the mouse in one screen, snapshots the area, and puts it into a window on a separate screen. I got 99% of it written using Gtk2 and tested; it's working great except for one thing.

In X11, the mouse cursor doesn't get grabbed.

Is there any way to grab the mouse cursor? Anyone try calling the XFIXES extension of X11 from Perl? If I can grab the data I can glue it into the screen and smack it to the destination window.

EDIT: Here's my code for 'mousetracker.pl'. It grabs from the current screen. If you give it an argument (like 192.168.1.8:0, exactly like the DISPLAY env variable), it'll display it on that screen you gave. I have it going from my Linux box to my Mac running X11.app.

#!/usr/bin/perl $|=1; use strict; use Gtk2 -init; use Glib qw/TRUE FALSE/; my $s = Gtk2::Gdk::Screen->get_default; my $iw = $s->get_root_window; my $isw = $s->get_width; my $ish = $s->get_height; my $ddisp; if($ARGV[0]=~/:/) { my $dest=$ARGV[0]; $ddisp=Gtk2::Gdk::Display->open($dest); } else { $ddisp=Gtk2::Gdk::Display->get_default; } my $scr = $ddisp->get_default_screen; my $win = Gtk2::Window->new('toplevel'); $win->set_screen($scr); $win->resize(640,480); $win->set_resizable(FALSE); my $img = Gtk2::Image->new(); $win->add($img); $win->show_all; Glib::Timeout->add(50,\&track); Gtk2->main; sub track { my ($sn,$x,$y,$m) = $iw->get_pointer; # print "$x, $y -->> "; $x=($x > 320 ? $x-320:0); $x=($x>$isw-640 ? $isw-640:$x); $y=($y > 240 ? $y-240:0); $y=($y>$ish-480 ? $ish-480:$y); # print "$x, $y\n"; my $p = Gtk2::Gdk::Pixbuf->get_from_drawable($iw,undef,$x,$y,0,0,6 +40,480); $img->set_from_pixbuf($p); return TRUE; }
Information doesn't want to be free. It wants to be feline.

In reply to Grabbing that mouse cursor in X11 by strredwolf

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (4)
    As of 2021-04-21 07:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?