Commit 87a4c9be authored by dscho's avatar dscho

support clipboard

parent 6cfd9afe
#include <assert.h> #include <assert.h>
#include <string.h>
#include <rfb/rfb.h> #include <rfb/rfb.h>
#include <rfb/rfbclient.h> #include <rfb/rfbclient.h>
...@@ -22,6 +23,8 @@ typedef struct private_resource_t { ...@@ -22,6 +23,8 @@ typedef struct private_resource_t {
int x,y; int x,y;
int buttons; int buttons;
char* text;
image_t* grep_image; image_t* grep_image;
int x_origin,y_origin; int x_origin,y_origin;
...@@ -87,6 +90,30 @@ static void got_mouse(int buttons,int x,int y,rfbClientRec* cl) ...@@ -87,6 +90,30 @@ static void got_mouse(int buttons,int x,int y,rfbClientRec* cl)
res->result|=RESULT_MOUSE; res->result|=RESULT_MOUSE;
} }
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;
}
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;
}
static rfbBool malloc_frame_buffer(rfbClient* cl) static rfbBool malloc_frame_buffer(rfbClient* cl)
{ {
private_resource_t* res=(private_resource_t*)cl->clientData; private_resource_t* res=(private_resource_t*)cl->clientData;
...@@ -102,6 +129,7 @@ static rfbBool malloc_frame_buffer(rfbClient* cl) ...@@ -102,6 +129,7 @@ static rfbBool malloc_frame_buffer(rfbClient* cl)
res->server->frameBuffer=res->client->frameBuffer; res->server->frameBuffer=res->client->frameBuffer;
res->server->kbdAddEvent=got_key; res->server->kbdAddEvent=got_key;
res->server->ptrAddEvent=got_mouse; res->server->ptrAddEvent=got_mouse;
res->server->setXCutText=got_text;
rfbInitServer(res->server); rfbInitServer(res->server);
} else { } else {
/* TODO: realloc if necessary */ /* TODO: realloc if necessary */
...@@ -175,10 +203,13 @@ resource_t initvnc(const char* server,int server_port,int listen_port) ...@@ -175,10 +203,13 @@ resource_t initvnc(const char* server,int server_port,int listen_port)
/* remember for later */ /* remember for later */
res->listen_port=listen_port; res->listen_port=listen_port;
res->text = NULL;
res->client=rfbGetClient(8,3,4); res->client=rfbGetClient(8,3,4);
res->client->clientData=res; res->client->clientData=(void*)res;
res->client->GotFrameBufferUpdate=got_frame_buffer; res->client->GotFrameBufferUpdate=got_frame_buffer;
res->client->MallocFrameBuffer=malloc_frame_buffer; res->client->MallocFrameBuffer=malloc_frame_buffer;
res->client->GotXCutText=got_text_from_server;
res->client->serverHost=strdup(server); res->client->serverHost=strdup(server);
res->client->serverPort=server_port; res->client->serverPort=server_port;
res->client->appData.encodingsString="raw"; res->client->appData.encodingsString="raw";
...@@ -484,7 +515,7 @@ result_t alert(resource_t resource,const char* message,timeout_t timeout) ...@@ -484,7 +515,7 @@ result_t alert(resource_t resource,const char* message,timeout_t timeout)
int x,y,w,h; int x,y,w,h;
result_t result; result_t result;
if(res->server==0) if(res == NULL || res->server==NULL)
return -1; return -1;
w=res->server->width; w=res->server->width;
...@@ -540,12 +571,18 @@ buttons_t getbuttons(resource_t res) ...@@ -540,12 +571,18 @@ buttons_t getbuttons(resource_t res)
return r->buttons; return r->buttons;
} }
const char *gettext(resource_t res)
{
private_resource_t* r=get_resource(res);
return r->text;
}
/* send events to the server */ /* send events to the server */
bool_t sendkey(resource_t res,keysym_t keysym,bool_t keydown) bool_t sendkey(resource_t res,keysym_t keysym,bool_t keydown)
{ {
private_resource_t* r=get_resource(res); private_resource_t* r=get_resource(res);
if(r==0) if(r==NULL)
return 0; return 0;
return SendKeyEvent(r->client,keysym,keydown); return SendKeyEvent(r->client,keysym,keydown);
} }
...@@ -553,11 +590,19 @@ bool_t sendkey(resource_t res,keysym_t keysym,bool_t keydown) ...@@ -553,11 +590,19 @@ 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 sendmouse(resource_t res,coordinate_t x,coordinate_t y,buttons_t buttons)
{ {
private_resource_t* r=get_resource(res); private_resource_t* r=get_resource(res);
if(r==0) if(r==NULL)
return 0; return 0;
return SendPointerEvent(r->client,x,y,buttons); return SendPointerEvent(r->client,x,y,buttons);
} }
bool_t sendtext(resource_t res, const char *string)
{
private_resource_t* r=get_resource(res);
if(r==NULL)
return 0;
return SendClientCutText(r->client, (char *)string, (int)strlen(string));
}
/* for visual grepping */ /* for visual grepping */
coordinate_t getxorigin(resource_t res) coordinate_t getxorigin(resource_t res)
......
...@@ -32,9 +32,10 @@ typedef int result_t; ...@@ -32,9 +32,10 @@ typedef int result_t;
%constant int RESULT_TIMEOUT=1; %constant int RESULT_TIMEOUT=1;
%constant int RESULT_KEY=2; %constant int RESULT_KEY=2;
%constant int RESULT_MOUSE=4; %constant int RESULT_MOUSE=4;
%constant int RESULT_SCREEN=8; %constant int RESULT_TEXT=8
%constant int RESULT_FOUNDIMAGE=16; %constant int RESULT_SCREEN=16;
%constant int RESULT_SHUTDOWN=32; %constant int RESULT_FOUNDIMAGE=32;
%constant int RESULT_SHUTDOWN=64;
*/ */
%} %}
...@@ -51,9 +52,10 @@ typedef int result_t; ...@@ -51,9 +52,10 @@ typedef int result_t;
#define RESULT_TIMEOUT 1 #define RESULT_TIMEOUT 1
#define RESULT_KEY 2 #define RESULT_KEY 2
#define RESULT_MOUSE 4 #define RESULT_MOUSE 4
#define RESULT_SCREEN 8 #define RESULT_TEXT 8
#define RESULT_FOUNDIMAGE 16 #define RESULT_SCREEN 16
#define RESULT_SHUTDOWN 32 #define RESULT_FOUNDIMAGE 32
#define RESULT_SHUTDOWN 64
/* init/shutdown */ /* init/shutdown */
...@@ -84,10 +86,13 @@ coordinate_t getx(resource_t res); ...@@ -84,10 +86,13 @@ coordinate_t getx(resource_t res);
coordinate_t gety(resource_t res); coordinate_t gety(resource_t res);
buttons_t getbuttons(resource_t res); buttons_t getbuttons(resource_t res);
const char *gettext(resource_t res);
/* send events to the server */ /* send events to the server */
bool_t sendkey(resource_t res,keysym_t keysym,bool_t keydown); 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 sendmouse(resource_t res,coordinate_t x,coordinate_t y,buttons_t buttons);
bool_t sendtext(resource_t res, const char *string);
/* for visual grepping */ /* for visual grepping */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment