diff options
author | dscho <dscho> | 2006-09-12 15:38:53 +0000 |
---|---|---|
committer | dscho <dscho> | 2006-09-12 15:38:53 +0000 |
commit | ff9c0be8447561a90e237910bf0d52bb0e11a008 (patch) | |
tree | e21ede531da310076b86701a5181ebf30a932144 /VisualNaCro | |
parent | 87a4c9be7dcde4eed81ad3060b784338bef57aba (diff) | |
download | libtdevnc-ff9c0be8447561a90e237910bf0d52bb0e11a008.tar.gz libtdevnc-ff9c0be8447561a90e237910bf0d52bb0e11a008.zip |
VisualNaCro: support clipboard and symbolic key names with X11::Keysyms
Diffstat (limited to 'VisualNaCro')
-rw-r--r-- | VisualNaCro/NEWS | 4 | ||||
-rw-r--r-- | VisualNaCro/nacro.c | 45 | ||||
-rw-r--r-- | VisualNaCro/nacro.h | 22 | ||||
-rw-r--r-- | VisualNaCro/recorder.pl | 42 |
4 files changed, 83 insertions, 30 deletions
diff --git a/VisualNaCro/NEWS b/VisualNaCro/NEWS index b6040b9..5b5fd29 100644 --- a/VisualNaCro/NEWS +++ b/VisualNaCro/NEWS @@ -2,3 +2,7 @@ With --timing, you can actually record action scripts which are meaningful... Earlier, the events just got garbled, because the GUI could not react as fast as the events were churned out. +Clipboard is supported (thanks to Uwe). + +Keys are recorded by their symbols with the --symbolic switch, provided you +have the X11::Keysyms module. diff --git a/VisualNaCro/nacro.c b/VisualNaCro/nacro.c index fbdb9ca..cf4668b 100644 --- a/VisualNaCro/nacro.c +++ b/VisualNaCro/nacro.c @@ -23,7 +23,8 @@ typedef struct private_resource_t { int x,y; int buttons; - char* text; + char* text_client; + char* text_server; image_t* grep_image; int x_origin,y_origin; @@ -94,24 +95,20 @@ static void got_text(char* str,int len,rfbClientRec* cl) { private_resource_t* res=(private_resource_t*)cl->screen->screenData; - SendClientCutText(res->client, str, len); - - if (res->text) - free(res->text); - res->text=strdup(str); - res->result|=RESULT_TEXT; + if (res->text_client) + free(res->text_client); + res->text_client=strdup(str); + res->result|=RESULT_TEXT_CLIENT; } static void got_text_from_server(rfbClient* cl, const char *str, int textlen) { private_resource_t* res=(private_resource_t*)cl->clientData; - rfbSendServerCutText(res->server, (char *)str, textlen); - - if (res->text) - free(res->text); - res->text=strdup(str); - res->result|=RESULT_TEXT; + if (res->text_server) + free(res->text_server); + res->text_server=strdup(str); + res->result|=RESULT_TEXT_SERVER; } static rfbBool malloc_frame_buffer(rfbClient* cl) @@ -203,7 +200,8 @@ resource_t initvnc(const char* server,int server_port,int listen_port) /* remember for later */ res->listen_port=listen_port; - res->text = NULL; + res->text_client = NULL; + res->text_server = NULL; res->client=rfbGetClient(8,3,4); res->client->clientData=(void*)res; @@ -571,10 +569,16 @@ buttons_t getbuttons(resource_t res) return r->buttons; } -const char *gettext(resource_t res) +const char *gettext_client(resource_t res) +{ + private_resource_t* r=get_resource(res); + return r->text_client; +} + +const char *gettext_server(resource_t res) { private_resource_t* r=get_resource(res); - return r->text; + return r->text_server; } /* send events to the server */ @@ -603,6 +607,15 @@ bool_t sendtext(resource_t res, const char *string) return SendClientCutText(r->client, (char *)string, (int)strlen(string)); } +bool_t sendtext_to_server(resource_t res, const char *string) +{ + private_resource_t* r=get_resource(res); + if(r==NULL) + return 0; + rfbSendServerCutText(r->server, (char *)string, (int)strlen(string)); + return 1; +} + /* for visual grepping */ coordinate_t getxorigin(resource_t res) diff --git a/VisualNaCro/nacro.h b/VisualNaCro/nacro.h index 618cb14..abc4045 100644 --- a/VisualNaCro/nacro.h +++ b/VisualNaCro/nacro.h @@ -32,10 +32,11 @@ typedef int result_t; %constant int RESULT_TIMEOUT=1; %constant int RESULT_KEY=2; %constant int RESULT_MOUSE=4; -%constant int RESULT_TEXT=8 -%constant int RESULT_SCREEN=16; -%constant int RESULT_FOUNDIMAGE=32; -%constant int RESULT_SHUTDOWN=64; +%constant int RESULT_TEXT_CLIENT=8; +%constant int RESULT_TEXT_CLIENT=16; +%constant int RESULT_SCREEN=32; +%constant int RESULT_FOUNDIMAGE=64; +%constant int RESULT_SHUTDOWN=128; */ %} @@ -52,10 +53,11 @@ typedef int result_t; #define RESULT_TIMEOUT 1 #define RESULT_KEY 2 #define RESULT_MOUSE 4 -#define RESULT_TEXT 8 -#define RESULT_SCREEN 16 -#define RESULT_FOUNDIMAGE 32 -#define RESULT_SHUTDOWN 64 +#define RESULT_TEXT_CLIENT 8 +#define RESULT_TEXT_SERVER 16 +#define RESULT_SCREEN 32 +#define RESULT_FOUNDIMAGE 64 +#define RESULT_SHUTDOWN 128 /* init/shutdown */ @@ -86,13 +88,15 @@ coordinate_t getx(resource_t res); coordinate_t gety(resource_t res); buttons_t getbuttons(resource_t res); -const char *gettext(resource_t res); +const char *gettext_client(resource_t res); +const char *gettext_server(resource_t res); /* send events to the server */ bool_t sendkey(resource_t res,keysym_t keysym,bool_t keydown); bool_t sendmouse(resource_t res,coordinate_t x,coordinate_t y,buttons_t buttons); bool_t sendtext(resource_t res, const char *string); +bool_t sendtext_to_server(resource_t res, const char *string); /* for visual grepping */ diff --git a/VisualNaCro/recorder.pl b/VisualNaCro/recorder.pl index 6621380..4f3c825 100644 --- a/VisualNaCro/recorder.pl +++ b/VisualNaCro/recorder.pl @@ -10,23 +10,32 @@ $server="localhost"; $port=5900; $listen_port=5923; $timing=0; +$symbolic=0; if(!GetOptions( "script:s" => \$output, "listen:i" => \$listen_port, - "timing" => \$timing + "timing" => \$timing, + "symbolic" => \$symbolic, ) || $#ARGV!=0) { - print STDERR "Usage: $ARGV0 [--script output_name] [--listen listen_port] server[:port]\n"; + print STDERR "Usage: $ARGV0 [--script output_name] [--listen listen_port] [--timing] [--symbolic] server[:port]\n"; exit 2; } $output=~s/\.pl$//; if ($timing) { - use Time::HiRes qw(time); + eval 'use Time::HiRes'; + $timing=0 if $@; $starttime=-1; } +if ($symbolic) { + eval 'use X11::Keysyms qw(%Keysyms)'; + $symbolic=0 if $@; + %sym_name = reverse %Keysyms; +} + $server=$ARGV[0]; if($server=~/^(.*):(\d+)$/) { @@ -59,6 +68,9 @@ if($vnc<0) { open OUT, ">$output.pl"; print OUT "#!/usr/bin/perl\n"; print OUT "\n"; +if ($symbolic) { + print OUT "use X11::Keysyms qw(\%sym);\n"; +} print OUT "use nacro;\n"; print OUT "\n"; print OUT "\$x_origin=0; \$y_origin=0;\n"; @@ -71,7 +83,7 @@ $x_origin=0; $y_origin=0; sub writetiming () { if ($timing) { - $now=time(); + $now=Time::HiRes::time(); if ($starttime>0) { print OUT "nacro::process(\$vnc," . ($now - $starttime) . ");\n"; } @@ -93,7 +105,11 @@ while(1) { $keydown=nacro::getkeydown($vnc); if(nacro::sendkey($vnc,$keysym,$keydown)) { writetiming(); - print OUT "nacro::sendkey(\$vnc,$keysym,$keydown);\n"; + if ($symbolic and exists $sym_name{$keysym}) { + print OUT 'nacro::sendkey($vnc,$sym{'.$sym_name{$keysym}."},$keydown);\n"; + } else { + print OUT "nacro::sendkey(\$vnc,$keysym,$keydown);\n"; + } } if($keysym==0xffe3 || $keysym==0xffe4) { # Control pressed @@ -120,6 +136,22 @@ while(1) { . ($y>=0?"+":"")."$y,$buttons);\n"; } } + if ($result & $nacro::RESULT_TEXT_CLIENT) { + my $text = nacro::gettext_client($vnc); + if (nacro::sendtext($vnc,$text)) { + writetiming(); + print OUT "nacro::sendtext(\$vnc, q(\Q$text\E));\n"; + print "got text from client: $text\n"; + } + } + if ($result & $nacro::RESULT_TEXT_SERVER) { + my $text = nacro::gettext_server($vnc); + if (nacro::sendtext_to_server($vnc,$text)) { + writetiming(); + print OUT "nacro::sendtext_to_server(\$vnc, q(\Q$text\E));\n"; + print "got text from server: $text\n"; + } + } } else { if($result&$nacro::RESULT_KEY) { $keysym=nacro::getkeysym($vnc); |