Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nxagent: add keystrokes to switch clipboard mode on the fly #1047

Open
wants to merge 5 commits into
base: 3.6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/nxagent/README.keystrokes
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 4 additions & 0 deletions etc/keystrokes.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
<keystroke action="reread_keystrokes" Control="1" AltMeta="1" key="k" />
<keystroke action="autograb" Control="1" AltMeta="1" key="g" />
<keystroke action="dump_clipboard" Control="1" Shift="1" AltMeta="1" key="c" />
<keystroke action="clipboard_both" Control="1" Shift="1" AltMeta="1" key="1" />
<keystroke action="clipboard_client" Control="1" Shift="1" AltMeta="1" key="2" />
<keystroke action="clipboard_server" Control="1" Shift="1" AltMeta="1" key="3" />
<keystroke action="clipboard_none" Control="1" Shift="1" AltMeta="1" key="4" />
</keystrokes>
31 changes: 23 additions & 8 deletions nx-X11/programs/Xserver/hw/nxagent/Clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -514,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
*/
Expand Down
1 change: 1 addition & 0 deletions nx-X11/programs/Xserver/hw/nxagent/Clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
8 changes: 8 additions & 0 deletions nx-X11/programs/Xserver/hw/nxagent/Events.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,14 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
nxagentDumpClipboardStat();
break;
}
case doClipboardBoth:
case doClipboardClient:
case doClipboardServer:
case doClipboardNone:
{
nxagentSwitchClipboardMode(ClipboardBoth + result - doClipboardBoth);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like that calculation since it is not self-explanatory. Please add at least a comment the thought behind this calculation. There's another location where I saw that same calculation, comment there too, please

break;
}
default:
{
FatalError("nxagentDispatchEvent: handleKeyPress returned unknown value\n");
Expand Down
6 changes: 5 additions & 1 deletion nx-X11/programs/Xserver/hw/nxagent/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ enum HandleEventResult
doSwitchResizeMode,
doSwitchDeferMode,
doAutoGrab,
doDumpClipboard
doDumpClipboard,
doClipboardBoth,
doClipboardClient,
doClipboardServer,
doClipboardNone
};

extern CARD32 nxagentLastEventTime;
Expand Down
14 changes: 14 additions & 0 deletions nx-X11/programs/Xserver/hw/nxagent/Keystroke.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ char * nxagentSpecialKeystrokeNames[] = {
"autograb",

"dump_clipboard",
"clipboard_both",
"clipboard_client",
"clipboard_server",
"clipboard_none",

NULL,
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain calculation (as mentioned above)

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:
Expand Down
4 changes: 4 additions & 0 deletions nx-X11/programs/Xserver/hw/nxagent/Keystroke.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
1 change: 1 addition & 0 deletions nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ model. Using \fIoff\fR this conversion can be suppressed and with

.TP 8
.B clipboard=<string>
Set initial clipboard mode. Can be toggled during session via keystroke.

.BR both | client | server | none

Expand Down