simulating a key event/generating a synthetic key event
- From: Scott Weisman <sweisman pobox com>
- To: gtk-perl-list gnome org
- Subject: simulating a key event/generating a synthetic key event
- Date: Sun, 30 Nov 2003 03:35:44 +0200
Hello,
I'm experimenting with embedding GVim in a Perl-GTK2 program. I've based my
code on the socket.pl script in the examples directory, as well as a GtkVim
widget I found on the vim.org site. This GtkVim widget would spawn a new
process every time it needs to send events to the embedded GVim process, like
this:
system "gvim --servername $servername --remote-send '$keypress'";
This strikes me as very odd and extremely inefficient. I'm not an expert on
GTK2 or XEMBED, but since there is already a link betweek the two running
programs via GtkSocket and GtkPlug, isn't there some method to send events to
the GVim process without a system() call?
Here is my script, if you need more information:
#!/usr/bin/perl -w
use strict;
use Gtk2;
use constant TRUE => 1;
use constant FALSE => 0;
my ($win, $socket, $vbox, $hbox, $btn);
my ($xid, $geom, $cmd);
Gtk2->init();
$win = Gtk2::Window->new("toplevel");
$win->set_default_size(640, 480);
$win->signal_connect( 'delete_event' => sub { Gtk2->main_quit() || 1; });
$vbox = Gtk2::VBox->new(0, 5);
$win->add($vbox);
$socket = Gtk2::Socket->new();
$vbox->add($socket);
$btn = Gtk2::Button->new_from_stock('gtk-quit');
$btn->signal_connect( 'clicked' => sub { Gtk2->main_quit() || 1; });
$socket->signal_connect('plug-removed' => sub {
print STDERR "GtkPlug Disconnected\n";
$vbox->remove($socket);
$vbox->add($btn);
$vbox->set_border_width(50);
$btn->show();
1;
});
$xid = $socket->get_id();
my ($init_cols, $init_rows, $init_files) = (20, 10);
$geom = "-geom ${init_cols}x$init_rows"
if ($init_cols || $init_rows);
$cmd = "gvim $geom --servername GtkVim-$xid --socketid $xid $init_files";
system($cmd);
$vbox->pack_start(Gtk2::HSeparator->new(), FALSE, TRUE, 0);
$btn = Gtk2::Button->new("Quit");
$btn->signal_connect( "clicked" => sub { Gtk2->main_quit(); });
$vbox->pack_start($btn, 1, 1, 5);
$win->show_all();
Gtk2->main();
Thanks for your help,
Scott Weisman
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]