Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-25 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found