From ba2f441f18ac2b6ca3d467cd4f5da33b5bd6cd87 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 27 Mar 2006 09:20:24 +0000 Subject: [PATCH] Control clipboard behaviour (and even disable it) using command line options. git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@1206 423420c4-83ab-492f-b58f-81f9feb106b5 --- cliprdr.c | 6 ++++++ proto.h | 2 ++ rdesktop.c | 26 +++++++++++++++++++++++++- xclip.c | 30 +++++++++++++++++++++++++++++- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/cliprdr.c b/cliprdr.c index f8887ad..d361db7 100644 --- a/cliprdr.c +++ b/cliprdr.c @@ -163,6 +163,12 @@ cliprdr_process(STREAM s) } } +void +cliprdr_set_mode(const char *optarg) +{ + ui_clip_set_mode(optarg); +} + BOOL cliprdr_init(void) { diff --git a/proto.h b/proto.h index 4d9bbb0..7de4398 100644 --- a/proto.h +++ b/proto.h @@ -54,6 +54,7 @@ void cliprdr_send_simple_native_format_announce(uint32 format); void cliprdr_send_native_format_announce(uint8 * formats_data, uint32 formats_data_length); void cliprdr_send_data_request(uint32 format); void cliprdr_send_data(uint8 * data, uint32 length); +void cliprdr_set_mode(const char *optarg); BOOL cliprdr_init(void); /* disk.c */ int disk_enum_devices(uint32 * id, char *optarg); @@ -205,6 +206,7 @@ void ui_clip_format_announce(uint8 * data, uint32 length); void ui_clip_handle_data(uint8 * data, uint32 length); void ui_clip_request_data(uint32 format); void ui_clip_sync(void); +void ui_clip_set_mode(const char *optarg); void xclip_init(void); /* xkeymap.c */ BOOL xkeymap_from_locale(const char *locale); diff --git a/rdesktop.c b/rdesktop.c index 77965ee..350756a 100644 --- a/rdesktop.c +++ b/rdesktop.c @@ -84,6 +84,7 @@ BOOL g_fullscreen = False; BOOL g_grab_keyboard = True; BOOL g_hide_decorations = False; BOOL g_use_rdp5 = True; +BOOL g_rdpclip = True; BOOL g_console_session = False; BOOL g_numlock_sync = False; BOOL lspci_enabled = False; @@ -180,6 +181,13 @@ usage(char *program) " or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); fprintf(stderr, " '-r sound:[local|off|remote]': enable sound redirection\n"); fprintf(stderr, " remote would leave sound on server\n"); + fprintf(stderr, + " '-r clipboard:[on|off|auto|PRIMARYCLIPBOARD|CLIPBOARD]': enable clip-\n"); + fprintf(stderr, " board redirection.\n"); + fprintf(stderr, + " 'on|auto|PRIMARYCLIPBOARD' looks at both PRIMARY and\n"); + fprintf(stderr, " CLIPBOARD when sending data to server.\n"); + fprintf(stderr, " 'CLIPBOARD' looks at only CLIPBOARD.\n"); fprintf(stderr, " -0: attach to console\n"); fprintf(stderr, " -4: use RDP version 4\n"); fprintf(stderr, " -5: use RDP version 5 (default)\n"); @@ -705,9 +713,25 @@ main(int argc, char *argv[]) g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); strcpy(g_rdpdr_clientname, optarg + 11); } + else if (str_startswith(optarg, "clipboard")) + { + optarg += 9; + + if (*optarg == ':') + { + optarg++; + + if (str_startswith(optarg, "off")) + g_rdpclip = False; + else + cliprdr_set_mode(optarg); + } + else + g_rdpclip = True; + } else { - warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n"); + warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound, clipboard\n"); } break; diff --git a/xclip.c b/xclip.c index 222e0c0..ca25f85 100644 --- a/xclip.c +++ b/xclip.c @@ -53,7 +53,12 @@ extern Display *g_display; extern Window g_wnd; extern Time g_last_gesturetime; +extern BOOL g_rdpclip; +/* Mode of operation. + - Auto: Look at both PRIMARY and CLIPBOARD and use the most recent. + - Non-auto: Look at just CLIPBOARD. */ +static BOOL auto_mode = True; /* Atoms of the two X selections we're dealing with: CLIPBOARD (explicit-copy) and PRIMARY (selection-copy) */ static Atom clipboard_atom, primary_atom; /* Atom of the TARGETS clipboard target */ @@ -902,7 +907,11 @@ ui_clip_request_data(uint32 format) return; } - primary_owner = XGetSelectionOwner(g_display, primary_atom); + if (auto_mode) + primary_owner = XGetSelectionOwner(g_display, primary_atom); + else + primary_owner = None; + clipboard_owner = XGetSelectionOwner(g_display, clipboard_atom); /* Both available */ @@ -943,10 +952,29 @@ ui_clip_sync(void) cliprdr_send_simple_native_format_announce(RDP_CF_TEXT); } +void +ui_clip_set_mode(const char *optarg) +{ + g_rdpclip = True; + + if (str_startswith(optarg, "auto") || str_startswith(optarg, "on") + || str_startswith(optarg, "PRIMARYCLIPBOARD")) + auto_mode = True; + else if (str_startswith(optarg, "CLIPBOARD")) + auto_mode = False; + else + { + warning("Invalid clipboard mode '%s'.\n", optarg); + g_rdpclip = False; + } +} void xclip_init(void) { + if (!g_rdpclip) + return; + if (!cliprdr_init()) return;