Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Grabbing that mouse cursor in X11

by strredwolf (Chaplain)
on Apr 23, 2010 at 01:43 UTC ( #836388=perlquestion: print w/ replies, xml ) Need Help??
strredwolf has asked for the wisdom of the Perl Monks concerning the following question:

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.

Comment on Grabbing that mouse cursor in X11
Download Code
Re: Grabbing that mouse cursor in X11
by tospo (Hermit) on Apr 23, 2010 at 09:18 UTC
      Won't work. I need to grab the X11 mouse, and that uses XFIXES.

      --
      $Stalag99{"URL"}="http://stalag99.net";

Re: Grabbing that mouse cursor in X11
by Anonymous Monk on Apr 23, 2010 at 09:27 UTC
    In X11, the mouse cursor doesn't get grabbed.

    Do you get an error message? Can you post a short program for testing? Maybe its permissions maybe its a bug.

      No errors, just doesn't happen. I think it's just a X11 limitation that needs to be worked around; I see the same problem documented in the x11vnc app.

      --
      $Stalag99{"URL"}="http://stalag99.net";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://836388]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-09-20 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (152 votes), past polls