VisualNaCro: support clipboard and symbolic key names with X11::Keysyms

pull/1/head
dscho 16 years ago
parent 87a4c9be7d
commit ff9c0be844
  1. 2
      AUTHORS
  2. 4
      VisualNaCro/NEWS
  3. 45
      VisualNaCro/nacro.c
  4. 22
      VisualNaCro/nacro.h
  5. 42
      VisualNaCro/recorder.pl

@ -29,7 +29,7 @@ Oliver Mihatsch, Greg Sternberg, Werner Hofer, Giampiero Giancipoli,
Glenn Mabutt, Paul Kreiner, Erik Kunze, Mike Frysinger, Martin Waitz,
Mark McLoughlin, Paul Fox, Juan Jose Costello, Andre Leiadella,
Alberto Lusiani, Malvina Mazin, Dave Stuart, Rohit Kumar, Donald Dugger,
and Steven Carr.
Steven Carr, and Uwe Völker.
Probably I forgot quite a few people sending a patch here and there, which
really made a difference. Without those, some obscure bugs still would

@ -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.

@ -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)

@ -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 */

@ -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);

Loading…
Cancel
Save