From 2b102a5aee6ecd7f801208d2c6f6aacf59397ee4 Mon Sep 17 00:00:00 2001 From: Tim Mann Date: Tue, 27 Oct 2009 23:57:25 -0700 Subject: [PATCH] Make copy/paste position and game use clipboard, bug #27810 Copy actually sets both the clipboard and the selection for convenience and compatibility with the old way of doing things. Paste pastes from the clipboard by default, but the new -pasteSelection option lets you get back the old behavior of pasting from the selection. --- common.h | 1 + xboard.c | 55 +++++++++++++++++++++++++++++++++++++++---------------- xboard.texi | 7 ++++++- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/common.h b/common.h index a48aee5..72e66ba 100644 --- a/common.h +++ b/common.h @@ -605,6 +605,7 @@ typedef struct { Boolean noJoin; /* [HGM] join */ char *wrapContSeq; /* continuation sequence when xboard wraps text */ Boolean useInternalWrap; /* use internal wrapping -- noJoin usurps this if set */ + Boolean pasteSelection; /* paste X selection instead of clipboard */ } AppData, *AppDataPtr; /* [AS] PGN tags (for showing in the game list) */ diff --git a/xboard.c b/xboard.c index 42192a5..4b34bcd 100644 --- a/xboard.c +++ b/xboard.c @@ -144,6 +144,7 @@ extern char *getenv(); #include #include #include +#include #if USE_XAW3D #include #include @@ -1422,6 +1423,9 @@ XtResource clientResources[] = { { "autoDisplayComment", "autoDisplayComment", XtRBoolean, sizeof(Boolean), XtOffset(AppDataPtr, autoDisplayComment), XtRImmediate, (XtPointer) True}, + { "pasteSelection", "pasteSelection", XtRBoolean, + sizeof(Boolean), XtOffset(AppDataPtr, pasteSelection), + XtRImmediate, (XtPointer) False}, }; XrmOptionDescRec shellOptions[] = { @@ -1796,6 +1800,7 @@ XrmOptionDescRec shellOptions[] = { { "-useInternalWrap", "useInternalWrap", XrmoptionSepArg, NULL }, { "-autoDisplayTags", "autoDisplayTags", XrmoptionSepArg, NULL }, { "-autoDisplayComment", "autoDisplayComment", XrmoptionSepArg, NULL }, + { "-pasteSelection", "pasteSelection", XrmoptionSepArg, NULL }, }; XtActionsRec boardActions[] = { @@ -6284,18 +6289,24 @@ void CopyPositionProc(w, event, prms, nprms) { int ret; + /* + * Set both PRIMARY (the selection) and CLIPBOARD, since we don't + * have a notion of a position that is selected but not copied. + * See http://www.freedesktop.org/wiki/Specifications/ClipboardsWiki + */ if (selected_fen_position) free(selected_fen_position); selected_fen_position = (char *)PositionToFEN(currentMove, NULL); if (!selected_fen_position) return; - ret = XtOwnSelection(menuBarWidget, XA_PRIMARY, - CurrentTime, - SendPositionSelection, - NULL/* lose_ownership_proc */ , - NULL/* transfer_done_proc */); - if (!ret) { - free(selected_fen_position); - selected_fen_position=NULL; - } + XtOwnSelection(menuBarWidget, XA_PRIMARY, + CurrentTime, + SendPositionSelection, + NULL/* lose_ownership_proc */ , + NULL/* transfer_done_proc */); + XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay), + CurrentTime, + SendPositionSelection, + NULL/* lose_ownership_proc */ , + NULL/* transfer_done_proc */); } /* function called when the data to Paste is ready */ @@ -6318,7 +6329,8 @@ void PastePositionProc(w, event, prms, nprms) String *prms; Cardinal *nprms; { - XtGetSelectionValue(menuBarWidget, XA_PRIMARY, XA_STRING, + XtGetSelectionValue(menuBarWidget, + appData.pasteSelection ? XA_PRIMARY: XA_CLIPBOARD(xDisplay), XA_STRING, /* (XtSelectionCallbackProc) */ PastePositionCB, NULL, /* client_data passed to PastePositionCB */ @@ -6376,11 +6388,21 @@ void CopyGameProc(w, event, prms, nprms) ret = SaveGameToFile(gameCopyFilename, FALSE); if (!ret) return; - ret = XtOwnSelection(menuBarWidget, XA_PRIMARY, - CurrentTime, - SendGameSelection, - NULL/* lose_ownership_proc */ , - NULL/* transfer_done_proc */); + /* + * Set both PRIMARY (the selection) and CLIPBOARD, since we don't + * have a notion of a game that is selected but not copied. + * See http://www.freedesktop.org/wiki/Specifications/ClipboardsWiki + */ + XtOwnSelection(menuBarWidget, XA_PRIMARY, + CurrentTime, + SendGameSelection, + NULL/* lose_ownership_proc */ , + NULL/* transfer_done_proc */); + XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay), + CurrentTime, + SendGameSelection, + NULL/* lose_ownership_proc */ , + NULL/* transfer_done_proc */); } /* function called when the data to Paste is ready */ @@ -6411,7 +6433,8 @@ void PasteGameProc(w, event, prms, nprms) String *prms; Cardinal *nprms; { - XtGetSelectionValue(menuBarWidget, XA_PRIMARY, XA_STRING, + XtGetSelectionValue(menuBarWidget, + appData.pasteSelection ? XA_PRIMARY: XA_CLIPBOARD(xDisplay), XA_STRING, /* (XtSelectionCallbackProc) */ PasteGameCB, NULL, /* client_data passed to PasteGameCB */ diff --git a/xboard.texi b/xboard.texi index 5686c70..bd56944 100644 --- a/xboard.texi +++ b/xboard.texi @@ -2093,7 +2093,12 @@ Moves is on. If set to true, these options cause the window with the move comments, and the window with PGN tags, respectively, to pop up automatically when such tags or comments are encountered during the replaying a stored or -loaded game. +loaded game. Default: true. +@item -pasteSelection true/false +@cindex -pasteSelection, option +If this option is set to true, the Paste Position and Paste Game +options paste from the currently selected text. If false, they paste +from the clipboard. Default: false. @end table @node Adjudication Options -- 1.7.0.4