X11::Protocol often is just a simple network socket. You can access the deep underlying handle and wait for input via select - and it is pretty simple. I did that in File::KeePass::Agent in the unix.pm module because I wanted to listen for global events as well as have a local gui running at the same time in the same process. Here is the relevant code snippet:

sub _listen { my $self = shift; my $x = $self->x; $x->event_handler('queue'); # listen to both the x protocol events as well as our local term require IO::Select; my $in_fh = ...; # some other handle I'm looking at my $x_fh = $x->{'connection'}->fh; $x_fh->autoflush(1); $in_fh->autoflush(1); my $sel = IO::Select->new($x_fh, $in_fh); # handle events as they occur $self->_init_state(1); my $i; while (1) { my ($fh) = $sel->can_read(10); next if ! $fh; if ($fh == $in_fh) { $self->_handle_term_input($fh) || last; } else { $self->read_x_event; } } } sub read_x_event { my $self = shift; my $cb_map = shift || $self->{'global_cb_map'} || die "No global c +allbacks initialized\n"; my $x = $self->x; my %event = $x->next_event; return if ($event{'name'} || '') ne 'KeyRelease'; my $code = $event{'detail'}; my $mod = $event{'state'}; ... the rest of my code here }

Once you have a select handle, you can can_read for input with a time out as part of the Gtk loop or any AnyEvent loop - but I'll leave that for you to setup :)

my @a=qw(random brilliant braindead); print $a[rand(@a)];

In reply to Re: Gtk2 X11 GrabKey by Rhandom
in thread Gtk2 X11 GrabKey by basiliscos

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.