From f66066bf1ede5d7b4e314d23c35732871bf13e55 Mon Sep 17 00:00:00 2001 From: Xavier G Date: Fri, 20 May 2022 19:16:56 +0000 Subject: [PATCH 1/5] Clipboard.c: introduce getClipboardModeString(). --- .../programs/Xserver/hw/nxagent/Clipboard.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index a45cab01e6..59906cc96d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -253,6 +253,18 @@ static char szAgentCLIPBOARD[] = "CLIPBOARD"; * Some helpers for debugging output */ +static const char * getClipboardModeString(int mode) +{ + switch(mode) + { + case ClipboardBoth: return("[Both]"); break;; + case ClipboardClient: return("[Client]"); break;; + case ClipboardServer: return("[Server]"); break;; + case ClipboardNone: return("[None]"); break;; + default: return("[UNKNOWN] (FAIL!)"); break;; + } +} + static const char * getClientSelectionStageString(int stage) { switch(stage) @@ -438,14 +450,7 @@ void nxagentDumpClipboardStat(void) fprintf(stderr, " serverWindow (XlibWindow) [0x%lx]\n", serverWindow); fprintf(stderr, " Clipboard mode "); - switch(nxagentOption(Clipboard)) - { - case ClipboardBoth: fprintf(stderr, "[Both]"); break;; - case ClipboardClient: fprintf(stderr, "[Client]"); break;; - case ClipboardServer: fprintf(stderr, "[Server]"); break;; - case ClipboardNone: fprintf(stderr, "[None]"); break;; - default: fprintf(stderr, "[UNKNOWN] (FAIL!)"); break;; - } + fprintf(stderr, getClipboardModeString(nxagentOption(Clipboard))); fprintf(stderr, "\n"); if (serverLastRequestedSelection == -1) From 51844fd74fcf4a57d49480d58ff712b469159ace Mon Sep 17 00:00:00 2001 From: Xavier G Date: Fri, 20 May 2022 19:24:23 +0000 Subject: [PATCH 2/5] Clipboard.c: introduce nxagentSwitchClipboardMode(). --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 10 ++++++++++ nx-X11/programs/Xserver/hw/nxagent/Clipboard.h | 1 + 2 files changed, 11 insertions(+) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 59906cc96d..1117a74b2f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -519,6 +519,16 @@ void nxagentDumpClipboardStat(void) fprintf(stderr, "\\------------------------------------------------------------------------------\n"); } +void nxagentSwitchClipboardMode(int new_mode) { + int old_mode = nxagentOption(Clipboard); + if (old_mode == new_mode) + return; + nxagentChangeOption(Clipboard, new_mode); + fprintf(stderr, "Switched clipboard mode from %s to %s.\n", + getClipboardModeString(old_mode), + getClipboardModeString(new_mode)); +} + /* * Helper to handle data transfer */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h index 4518595d1b..7e38e51698 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h @@ -82,5 +82,6 @@ extern WindowPtr nxagentGetClipboardWindow(Atom property); extern int nxagentSendNotificationToSelfViaXServer(xEvent *event); extern void nxagentDumpClipboardStat(void); +extern void nxagentSwitchClipboardMode(int new_mode); #endif /* __Clipboard_H__ */ From ad08b944dd5af21d9cfd71ff4619b776fdfbc486 Mon Sep 17 00:00:00 2001 From: Xavier G Date: Fri, 20 May 2022 19:25:07 +0000 Subject: [PATCH 3/5] Events.c: add doClipboard* events. --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 8 ++++++++ nx-X11/programs/Xserver/hw/nxagent/Events.h | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index 7cadb987b1..b37fc5ecf0 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -1071,6 +1071,14 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) nxagentDumpClipboardStat(); break; } + case doClipboardBoth: + case doClipboardClient: + case doClipboardServer: + case doClipboardNone: + { + nxagentSwitchClipboardMode(ClipboardBoth + result - doClipboardBoth); + break; + } default: { FatalError("nxagentDispatchEvent: handleKeyPress returned unknown value\n"); diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.h b/nx-X11/programs/Xserver/hw/nxagent/Events.h index a334897ec3..1f0d88b3c8 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.h @@ -52,7 +52,11 @@ enum HandleEventResult doSwitchResizeMode, doSwitchDeferMode, doAutoGrab, - doDumpClipboard + doDumpClipboard, + doClipboardBoth, + doClipboardClient, + doClipboardServer, + doClipboardNone }; extern CARD32 nxagentLastEventTime; From ff646ed13b887cd0a5ada208a37bcd0706df0e26 Mon Sep 17 00:00:00 2001 From: Xavier G Date: Fri, 20 May 2022 19:27:15 +0000 Subject: [PATCH 4/5] Keystroke.c: add keyboard shortcuts to switch clipboard mode. --- nx-X11/programs/Xserver/hw/nxagent/Keystroke.c | 14 ++++++++++++++ nx-X11/programs/Xserver/hw/nxagent/Keystroke.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c index 5196e28b70..de03576a88 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c @@ -103,6 +103,10 @@ char * nxagentSpecialKeystrokeNames[] = { "autograb", "dump_clipboard", + "clipboard_both", + "clipboard_client", + "clipboard_server", + "clipboard_none", NULL, }; @@ -145,6 +149,10 @@ struct nxagentSpecialKeystrokeMap default_map[] = { {KEYSTROKE_REREAD_KEYSTROKES, ControlMask, True, XK_k}, {KEYSTROKE_AUTOGRAB, ControlMask, True, XK_g}, {KEYSTROKE_DUMP_CLIPBOARD, ControlMask | ShiftMask, True, XK_c}, + {KEYSTROKE_SET_CLIPBOARD_BOTH, ControlMask | ShiftMask, True, XK_1}, + {KEYSTROKE_SET_CLIPBOARD_CLIENT, ControlMask | ShiftMask, True, XK_2}, + {KEYSTROKE_SET_CLIPBOARD_SERVER, ControlMask | ShiftMask, True, XK_3}, + {KEYSTROKE_SET_CLIPBOARD_NONE, ControlMask | ShiftMask, True, XK_4}, {KEYSTROKE_END_MARKER, 0, False, NoSymbol}, }; struct nxagentSpecialKeystrokeMap *map = default_map; @@ -725,6 +733,12 @@ Bool nxagentCheckSpecialKeystroke(XKeyEvent *X, enum HandleEventResult *result) case KEYSTROKE_DUMP_CLIPBOARD: *result = doDumpClipboard; break; + case KEYSTROKE_SET_CLIPBOARD_BOTH: + case KEYSTROKE_SET_CLIPBOARD_CLIENT: + case KEYSTROKE_SET_CLIPBOARD_SERVER: + case KEYSTROKE_SET_CLIPBOARD_NONE: + *result = doClipboardBoth + stroke - KEYSTROKE_SET_CLIPBOARD_BOTH; + break; case KEYSTROKE_NOTHING: /* do nothing. difference to KEYSTROKE_IGNORE is the return value */ case KEYSTROKE_END_MARKER: /* just to make gcc STFU */ case KEYSTROKE_MAX: diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.h b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.h index a5a6fbcf14..79c0e0d745 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.h @@ -79,6 +79,10 @@ enum nxagentSpecialKeystroke { KEYSTROKE_AUTOGRAB, KEYSTROKE_DUMP_CLIPBOARD, + KEYSTROKE_SET_CLIPBOARD_BOTH, + KEYSTROKE_SET_CLIPBOARD_CLIENT, + KEYSTROKE_SET_CLIPBOARD_SERVER, + KEYSTROKE_SET_CLIPBOARD_NONE, /* insert more here and in the string translation */ From 7505eb3f8df3137cbbc233c3263e9590a0a53ac2 Mon Sep 17 00:00:00 2001 From: Xavier G Date: Fri, 20 May 2022 19:54:33 +0000 Subject: [PATCH 5/5] Clipboard keystrokes: update documentation. --- doc/nxagent/README.keystrokes | 12 ++++++++++++ etc/keystrokes.cfg | 4 ++++ nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 | 1 + 3 files changed, 17 insertions(+) diff --git a/doc/nxagent/README.keystrokes b/doc/nxagent/README.keystrokes index e916bddc0f..90a6b48bc6 100644 --- a/doc/nxagent/README.keystrokes +++ b/doc/nxagent/README.keystrokes @@ -133,6 +133,18 @@ dump_clipboard print the current internal clipboard state (for debugging) to the log. +clipboard_both + allow copy/paste from/to real X server + +clipboard_client + allow copy/paste from real X server + +clipboard_server + allow copy/paste to real X server + +clipboard_none + forbid copy/paste from/to real X server + force_synchronization Forces immediate drawing of elements to be synchronized which can fix some visual bugs. diff --git a/etc/keystrokes.cfg b/etc/keystrokes.cfg index ea9feeea6e..4c8b735e69 100644 --- a/etc/keystrokes.cfg +++ b/etc/keystrokes.cfg @@ -26,4 +26,8 @@ + + + + diff --git a/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 b/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 index f373cb2391..788605d6bb 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 +++ b/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 @@ -706,6 +706,7 @@ model. Using \fIoff\fR this conversion can be suppressed and with .TP 8 .B clipboard= +Set initial clipboard mode. Can be toggled during session via keystroke. .BR both | client | server | none