From bfd567a014d5d04de6abc24a24c7c75d651ae76f Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 12 Jan 2016 18:57:37 +0100 Subject: [PATCH] Remove clipboard code from vncconfig The clipboard is handled internally in the server now, so the code in vncconfig is no longer useful. --- unix/vncconfig/vncExt.c | 84 --------------------- unix/vncconfig/vncExt.h | 85 --------------------- unix/vncconfig/vncconfig.cxx | 138 +---------------------------------- unix/vncconfig/vncconfig.man | 13 ++-- 4 files changed, 9 insertions(+), 311 deletions(-) diff --git a/unix/vncconfig/vncExt.c b/unix/vncconfig/vncExt.c index ff6b4d65..f93b6eeb 100644 --- a/unix/vncconfig/vncExt.c +++ b/unix/vncconfig/vncExt.c @@ -24,10 +24,6 @@ #define _VNCEXT_PROTO_ #include "vncExt.h" -static Bool XVncExtClientCutTextNotifyWireToEvent(Display* dpy, XEvent* e, - xEvent* w); -static Bool XVncExtSelectionChangeNotifyWireToEvent(Display* dpy, XEvent* e, - xEvent* w); static Bool XVncExtQueryConnectNotifyWireToEvent(Display* dpy, XEvent* e, xEvent* w); @@ -40,10 +36,6 @@ static Bool checkExtension(Display* dpy) extensionInited = True; codes = XInitExtension(dpy, VNCEXTNAME); if (!codes) return False; - XESetWireToEvent(dpy, codes->first_event + VncExtClientCutTextNotify, - XVncExtClientCutTextNotifyWireToEvent); - XESetWireToEvent(dpy, codes->first_event + VncExtSelectionChangeNotify, - XVncExtSelectionChangeNotifyWireToEvent); XESetWireToEvent(dpy, codes->first_event + VncExtQueryConnectNotify, XVncExtQueryConnectNotifyWireToEvent); } @@ -214,53 +206,6 @@ void XVncExtFreeParamList(char** list) } } -Bool XVncExtSetServerCutText(Display* dpy, const char* str, int len) -{ - xVncExtSetServerCutTextReq* req; - - if (!checkExtension(dpy)) return False; - - LockDisplay(dpy); - GetReq(VncExtSetServerCutText, req); - req->reqType = codes->major_opcode; - req->vncExtReqType = X_VncExtSetServerCutText; - req->length += (len + 3) >> 2; - req->textLen = len; - Data(dpy, str, len); - UnlockDisplay(dpy); - SyncHandle(); - return True; -} - -Bool XVncExtGetClientCutText(Display* dpy, char** str, int* len) -{ - xVncExtGetClientCutTextReq* req; - xVncExtGetClientCutTextReply rep; - - if (!checkExtension(dpy)) return False; - - LockDisplay(dpy); - GetReq(VncExtGetClientCutText, req); - req->reqType = codes->major_opcode; - req->vncExtReqType = X_VncExtGetClientCutText; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - UnlockDisplay(dpy); - SyncHandle(); - *len = rep.textLen; - *str = (char*) Xmalloc (*len+1); - if (!*str) { - _XEatData(dpy, (*len+1)&~1); - return False; - } - _XReadPad(dpy, *str, *len); - (*str)[*len] = 0; - return True; -} - Bool XVncExtSelectInput(Display* dpy, Window w, int mask) { xVncExtSelectInputReq* req; @@ -359,35 +304,6 @@ Bool XVncExtApproveConnect(Display* dpy, void* opaqueId, int approve) } -static Bool XVncExtClientCutTextNotifyWireToEvent(Display* dpy, XEvent* e, - xEvent* w) -{ - XVncExtClientCutTextEvent* ev = (XVncExtClientCutTextEvent*)e; - xVncExtClientCutTextNotifyEvent* wire = (xVncExtClientCutTextNotifyEvent*)w; - ev->type = wire->type & 0x7f; - ev->serial = _XSetLastRequestRead(dpy,(xGenericReply*)wire); - ev->send_event = (wire->type & 0x80) != 0; - ev->display = dpy; - ev->window = wire->window; - ev->time = wire->time; - return True; -} - -static Bool XVncExtSelectionChangeNotifyWireToEvent(Display* dpy, XEvent* e, - xEvent* w) -{ - XVncExtSelectionChangeEvent* ev = (XVncExtSelectionChangeEvent*)e; - xVncExtSelectionChangeNotifyEvent* wire - = (xVncExtSelectionChangeNotifyEvent*)w; - ev->type = wire->type & 0x7f; - ev->serial = _XSetLastRequestRead(dpy,(xGenericReply*)wire); - ev->send_event = (wire->type & 0x80) != 0; - ev->display = dpy; - ev->window = wire->window; - ev->selection = wire->selection; - return True; -} - static Bool XVncExtQueryConnectNotifyWireToEvent(Display* dpy, XEvent* e, xEvent* w) { diff --git a/unix/vncconfig/vncExt.h b/unix/vncconfig/vncExt.h index e41e2e5b..2b24469e 100644 --- a/unix/vncconfig/vncExt.h +++ b/unix/vncconfig/vncExt.h @@ -26,18 +26,12 @@ extern "C" { #define X_VncExtGetParam 1 #define X_VncExtGetParamDesc 2 #define X_VncExtListParams 3 -#define X_VncExtSetServerCutText 4 -#define X_VncExtGetClientCutText 5 #define X_VncExtSelectInput 6 #define X_VncExtConnect 7 #define X_VncExtGetQueryConnect 8 #define X_VncExtApproveConnect 9 -#define VncExtClientCutTextNotify 0 -#define VncExtSelectionChangeNotify 1 #define VncExtQueryConnectNotify 2 -#define VncExtClientCutTextMask (1 << VncExtClientCutTextNotify) -#define VncExtSelectionChangeMask (1 << VncExtSelectionChangeNotify) #define VncExtQueryConnectMask (1 << VncExtQueryConnectNotify) #define VncExtNumberEvents 3 @@ -51,8 +45,6 @@ Bool XVncExtGetParam(Display* dpy, const char* param, char** value, int* len); char* XVncExtGetParamDesc(Display* dpy, const char* param); char** XVncExtListParams(Display* dpy, int* nParams); void XVncExtFreeParamList(char** list); -Bool XVncExtSetServerCutText(Display* dpy, const char* str, int len); -Bool XVncExtGetClientCutText(Display* dpy, char** str, int* len); Bool XVncExtSelectInput(Display* dpy, Window w, int mask); Bool XVncExtConnect(Display* dpy, const char* hostAndPort); Bool XVncExtGetQueryConnect(Display* dpy, char** addr, @@ -60,24 +52,6 @@ Bool XVncExtGetQueryConnect(Display* dpy, char** addr, Bool XVncExtApproveConnect(Display* dpy, void* opaqueId, int approve); -typedef struct { - int type; - unsigned long serial; - Bool send_event; - Display *display; - Window window; - Time time; -} XVncExtClientCutTextEvent; - -typedef struct { - int type; - unsigned long serial; - Bool send_event; - Display *display; - Window window; - Atom selection; -} XVncExtSelectionChangeEvent; - typedef struct { int type; unsigned long serial; @@ -192,37 +166,6 @@ typedef struct { #define sz_xVncExtListParamsReply 32 -typedef struct { - CARD8 reqType; /* always VncExtReqCode */ - CARD8 vncExtReqType; /* always VncExtSetServerCutText */ - CARD16 length B16; - CARD32 textLen B32; -} xVncExtSetServerCutTextReq; -#define sz_xVncExtSetServerCutTextReq 8 - - -typedef struct { - CARD8 reqType; /* always VncExtReqCode */ - CARD8 vncExtReqType; /* always VncExtGetClientCutText */ - CARD16 length B16; -} xVncExtGetClientCutTextReq; -#define sz_xVncExtGetClientCutTextReq 4 - -typedef struct { - BYTE type; /* X_Reply */ - BYTE pad0; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 textLen B32; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; -} xVncExtGetClientCutTextReply; -#define sz_xVncExtGetClientCutTextReply 32 - - typedef struct { CARD8 reqType; /* always VncExtReqCode */ CARD8 vncExtReqType; /* always VncExtSelectInput */ @@ -292,34 +235,6 @@ typedef struct { -typedef struct { - BYTE type; /* always eventBase + VncExtClientCutTextNotify */ - BYTE pad0; - CARD16 sequenceNumber B16; - CARD32 window B32; - CARD32 time B32; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; -} xVncExtClientCutTextNotifyEvent; -#define sz_xVncExtClientCutTextNotifyEvent 32 - -typedef struct { - BYTE type; /* always eventBase + VncExtSelectionChangeNotify */ - BYTE pad0; - CARD16 sequenceNumber B16; - CARD32 window B32; - CARD32 selection B32; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; -} xVncExtSelectionChangeNotifyEvent; -#define sz_xVncExtSelectionChangeNotifyEvent 32 - typedef struct { BYTE type; /* always eventBase + VncExtQueryConnectNotify */ BYTE pad0; diff --git a/unix/vncconfig/vncconfig.cxx b/unix/vncconfig/vncconfig.cxx index bffdfbe2..188ebfb8 100644 --- a/unix/vncconfig/vncconfig.cxx +++ b/unix/vncconfig/vncconfig.cxx @@ -38,7 +38,6 @@ #include #include #include -#include #include "TXWindow.h" #include "TXCheckbox.h" #include "TXLabel.h" @@ -51,16 +50,6 @@ LogWriter vlog("vncconfig"); StringParameter displayname("display", "The X display", ""); BoolParameter noWindow("nowin", "Don't display a window", 0); BoolParameter iconic("iconic", "Start with window iconified", 0); -BoolParameter sendPrimary("SendPrimary", "Send the PRIMARY as well as the " - "CLIPBOARD selection", true); -IntParameter pollTime("poll", - "How often to poll for clipboard changes in ms", 0); - -inline const char* selectionName(Atom sel) { - if (sel == xaCLIPBOARD) return "CLIPBOARD"; - if (sel == XA_PRIMARY) return "PRIMARY"; - return "unknown"; -} #define ACCEPT_CUT_TEXT "AcceptCutText" #define SEND_CUT_TEXT "SendCutText" @@ -81,19 +70,14 @@ static bool getBoolParam(Display* dpy, const char* param) { class VncConfigWindow : public TXWindow, public TXEventHandler, public TXDeleteWindowCallback, public TXCheckboxCallback, - public rfb::Timer::Callback, public QueryResultCallback { public: VncConfigWindow(Display* dpy) - : TXWindow(dpy, 300, 100), cutText(0), cutTextLen(0), + : TXWindow(dpy, 300, 100), acceptClipboard(dpy, "Accept clipboard from viewers", this, false, this), sendClipboard(dpy, "Send clipboard to viewers", this, false, this), - sendPrimaryCB(dpy, "Send primary selection to viewers", this,false,this), - pollTimer(this), queryConnectDialog(0) { - selection[0] = selection[1] = 0; - selectionLen[0] = selectionLen[1] = 0; int y = yPad; acceptClipboard.move(xPad, y); acceptClipboard.checked(getBoolParam(dpy, ACCEPT_CUT_TEXT)); @@ -101,62 +85,14 @@ public: sendClipboard.move(xPad, y); sendClipboard.checked(getBoolParam(dpy, SEND_CUT_TEXT)); y += sendClipboard.height(); - sendPrimaryCB.move(xPad, y); - sendPrimaryCB.checked(sendPrimary); - sendPrimaryCB.disabled(!sendClipboard.checked()); - y += sendPrimaryCB.height(); setEventHandler(this); toplevel("VNC config", this, 0, 0, 0, iconic); - XVncExtSelectInput(dpy, win(), - VncExtClientCutTextMask| - VncExtSelectionChangeMask| - VncExtQueryConnectMask); - XConvertSelection(dpy, XA_PRIMARY, XA_STRING, - XA_PRIMARY, win(), CurrentTime); - XConvertSelection(dpy, xaCLIPBOARD, XA_STRING, - xaCLIPBOARD, win(), CurrentTime); - if (pollTime != 0) - pollTimer.start(pollTime); + XVncExtSelectInput(dpy, win(), VncExtQueryConnectMask); } - // handleEvent(). If we get a ClientCutTextNotify event from Xvnc, set the - // primary and clipboard selections to the clientCutText. If we get a - // SelectionChangeNotify event from Xvnc, set the serverCutText to the value - // of the new selection. + // handleEvent() virtual void handleEvent(TXWindow* w, XEvent* ev) { - if (acceptClipboard.checked()) { - if (ev->type == vncExtEventBase + VncExtClientCutTextNotify) { - XVncExtClientCutTextEvent* cutEv = (XVncExtClientCutTextEvent*)ev; - if (cutText) - XFree(cutText); - cutText = 0; - if (XVncExtGetClientCutText(dpy, &cutText, &cutTextLen)) { - vlog.debug("Got client cut text: '%.*s%s'", - cutTextLen<9?cutTextLen:8, cutText, - cutTextLen<9?"":"..."); - XStoreBytes(dpy, cutText, cutTextLen); - ownSelection(XA_PRIMARY, cutEv->time); - ownSelection(xaCLIPBOARD, cutEv->time); - delete [] selection[0]; - delete [] selection[1]; - selection[0] = selection[1] = 0; - selectionLen[0] = selectionLen[1] = 0; - } - } - } - if (sendClipboard.checked()) { - if (ev->type == vncExtEventBase + VncExtSelectionChangeNotify) { - vlog.debug("selection change event"); - XVncExtSelectionChangeEvent* selEv = (XVncExtSelectionChangeEvent*)ev; - if (selEv->selection == xaCLIPBOARD || - (selEv->selection == XA_PRIMARY && sendPrimaryCB.checked())) { - if (!selectionOwner(selEv->selection)) - XConvertSelection(dpy, selEv->selection, XA_STRING, - selEv->selection, win(), CurrentTime); - } - } - } if (ev->type == vncExtEventBase + VncExtQueryConnectNotify) { vlog.debug("query connection event"); if (queryConnectDialog) @@ -178,55 +114,6 @@ public: } } } - - - // selectionRequest() is called when we are the selection owner and another X - // client has requested the selection. We simply put the server's cut text - // into the requested property. TXWindow will handle the rest. - bool selectionRequest(Window requestor, Atom selection, Atom property) - { - if (cutText) - XChangeProperty(dpy, requestor, property, XA_STRING, 8, - PropModeReplace, (unsigned char*)cutText, - cutTextLen); - return cutText; - } - - // selectionNotify() is called when we have requested the selection from the - // selection owner. - void selectionNotify(XSelectionEvent* ev, Atom type, int format, - int nitems, void* data) - { - if (ev->requestor != win() || ev->target != XA_STRING) - return; - - if (data && format == 8) { - int i = (ev->selection == XA_PRIMARY ? 0 : 1); - if (selectionLen[i] == nitems && memcmp(selection[i], data, nitems) == 0) - return; - delete [] selection[i]; - selection[i] = new char[nitems]; - memcpy(selection[i], data, nitems); - selectionLen[i] = nitems; - if (cutTextLen == nitems && memcmp(cutText, data, nitems) == 0) { - vlog.debug("ignoring duplicate cut text"); - return; - } - if (cutText) - XFree(cutText); - cutText = (char*)malloc(nitems); // assuming XFree() same as free() - if (!cutText) { - vlog.error("unable to allocate selection buffer"); - return; - } - memcpy(cutText, data, nitems); - cutTextLen = nitems; - vlog.debug("sending %s selection as server cut text: '%.*s%s'", - selectionName(ev->selection),cutTextLen<9?cutTextLen:8, - cutText, cutTextLen<9?"":"..."); - XVncExtSetServerCutText(dpy, cutText, cutTextLen); - } - } // TXDeleteWindowCallback method virtual void deleteWindow(TXWindow* w) { @@ -241,21 +128,9 @@ public: } else if (checkbox == &sendClipboard) { XVncExtSetParam(dpy, (sendClipboard.checked() ? SEND_CUT_TEXT "=1" : SEND_CUT_TEXT "=0")); - sendPrimaryCB.disabled(!sendClipboard.checked()); } } - // rfb::Timer::Callback interface - virtual bool handleTimeout(rfb::Timer* timer) { - if (sendPrimaryCB.checked() && !selectionOwner(XA_PRIMARY)) - XConvertSelection(dpy, XA_PRIMARY, XA_STRING, - XA_PRIMARY, win(), CurrentTime); - if (!selectionOwner(xaCLIPBOARD)) - XConvertSelection(dpy, xaCLIPBOARD, XA_STRING, - xaCLIPBOARD, win(), CurrentTime); - return true; - } - // QueryResultCallback interface virtual void queryApproved() { XVncExtApproveConnect(dpy, queryConnectId, 1); @@ -265,12 +140,7 @@ public: } private: - char* cutText; - int cutTextLen; - char* selection[2]; - int selectionLen[2]; - TXCheckbox acceptClipboard, sendClipboard, sendPrimaryCB; - rfb::Timer pollTimer; + TXCheckbox acceptClipboard, sendClipboard; QueryConnectDialog* queryConnectDialog; void* queryConnectId; diff --git a/unix/vncconfig/vncconfig.man b/unix/vncconfig/vncconfig.man index 6695be3d..06f9ca97 100644 --- a/unix/vncconfig/vncconfig.man +++ b/unix/vncconfig/vncconfig.man @@ -37,14 +37,11 @@ server with the VNC extension. Note that it cannot be used to control VNC servers prior to version 4. When run with no options, it runs as a kind of "helper" application for Xvnc. -Its main purpose when run in this mode is to support clipboard transfer to and -from the VNC viewer(s). Note that without a running instance of -\fBvncconfig\fP there will be no clipboard support. It puts up a window with -some checkboxes which can be used to disable clipboard transfers if required -(in the future there may be more functions available from this window). The -\fB-nowin\fP flag can be used if you always want clipboard support but don't -wish to clutter the desktop with this window - alternatively the \fB-iconic\fP -option can be used to make it iconified by default. +Its main purpose when run in this mode is to query the user how new +connections should be handled (provided this feature is enabled). The +\fB-nowin\fP flag can be used if you always want the query support but don't +wish to clutter the desktop with the settings window - alternatively the +\fB-iconic\fP option can be used to make it iconified by default. When run in any other mode, \fBvncconfig\fP is a one-shot program used to configure or control Xvnc as appropriate. It can be used to tell Xvnc to -- 2.39.5