diff --git a/wmcliphist/clipboard.c b/wmcliphist/clipboard.c index 49d6ac3..dd5c49b 100644 --- a/wmcliphist/clipboard.c +++ b/wmcliphist/clipboard.c @@ -48,7 +48,7 @@ dump_history_list_fn(char *header) } void -my_get_selection_text(GtkClipboard *clipboard, const gchar *text, gpointer +my_get_selection_text(GtkClipboard *cb, const gchar *text, gpointer data) { /* previous clipboard content */ @@ -86,7 +86,7 @@ my_get_selection_text(GtkClipboard *clipboard, const gchar *text, gpointer if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore)) || gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_lock))) { if (gtk_selection_owner_set(dock_app, - GDK_SELECTION_PRIMARY, + clipboard, GDK_CURRENT_TIME) == 0) selected = NULL; } @@ -113,7 +113,7 @@ my_get_xselection(GtkWidget *window, GdkEvent *event) begin_func("my_get_xselection"); - gtk_clipboard_request_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), + gtk_clipboard_request_text(gtk_clipboard_get(clipboard), my_get_selection_text, NULL); return_val(TRUE); @@ -143,7 +143,7 @@ my_get_xselection(GtkWidget *window, GdkEvent *event) if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore)) || gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_lock))) { if (gtk_selection_owner_set(dock_app, - GDK_SELECTION_PRIMARY, + clipboard, GDK_CURRENT_TIME) == 0) selected = NULL; } @@ -163,7 +163,7 @@ time_conv_select() begin_func("time_conv_select"); gtk_selection_convert(main_window, - GDK_SELECTION_PRIMARY, + clipboard, GDK_TARGET_STRING, GDK_CURRENT_TIME); return_val(TRUE); diff --git a/wmcliphist/gui.c b/wmcliphist/gui.c index 76d84ba..1ba4eae 100644 --- a/wmcliphist/gui.c +++ b/wmcliphist/gui.c @@ -33,6 +33,10 @@ GtkWidget *button; /* pixmap */ GtkWidget *pixmap; +/* which clipboard to use */ +gchar clipboard_str[32] = DEF_CLIPBOARD_STR; +GdkAtom clipboard; + /* ========================================================================== * clipboard history menu */ diff --git a/wmcliphist/history.c b/wmcliphist/history.c index 096f450..20d1036 100644 --- a/wmcliphist/history.c +++ b/wmcliphist/history.c @@ -51,7 +51,7 @@ process_item(char *content, gint locked, gboolean exec) if (auto_take_up == 1) { selected = hist_item; if (gtk_selection_owner_set(dock_app, - GDK_SELECTION_PRIMARY, + clipboard, GDK_CURRENT_TIME) == 0) { selected = NULL; } @@ -71,7 +71,7 @@ process_item(char *content, gint locked, gboolean exec) if (auto_take_up == 1) { selected = hist_item; if (gtk_selection_owner_set(dock_app, - GDK_SELECTION_PRIMARY, + clipboard, GDK_CURRENT_TIME) == 0) { selected = NULL; } @@ -99,7 +99,7 @@ move_item_to_begin(HISTORY_ITEM *item) { history_items = g_list_concat(list_node, history_items); selected = item; if (gtk_selection_owner_set(dock_app, - GDK_SELECTION_PRIMARY, + clipboard, GDK_CURRENT_TIME) == 0) selected = NULL; } diff --git a/wmcliphist/rcconfig.c b/wmcliphist/rcconfig.c index 44dce9c..153295c 100644 --- a/wmcliphist/rcconfig.c +++ b/wmcliphist/rcconfig.c @@ -178,6 +178,9 @@ rcconfig_get(char *fname) } else if (strcmp(direc_buf, "lcolor") == 0) { state = STATE_VALUE; buf_index = 0; + } else if (strcmp(direc_buf, "clipboard") == 0) { + state = STATE_VALUE; + buf_index = 0; } else if (strcmp(direc_buf, "autosave") == 0) { state = STATE_VALUE; buf_index = 0; @@ -229,6 +232,11 @@ rcconfig_get(char *fname) memset(locked_color_str, 0, 32); strncpy(locked_color_str, expr_buf, 31); + } else if (strcmp(direc_buf, "clipboard") + == 0) { + memset(clipboard_str, 0, 32); + strncpy(clipboard_str, + expr_buf, 31); } else if (strcmp(direc_buf, "autosave") == 0) { autosave_period = atoi(expr_buf); diff --git a/wmcliphist/wmcliphist.1 b/wmcliphist/wmcliphist.1 index af68043..0b1e2cf 100644 --- a/wmcliphist/wmcliphist.1 +++ b/wmcliphist/wmcliphist.1 @@ -3,7 +3,7 @@ wmcliphist \(em provides a history to X11 selections .SH "SYNOPSIS" .PP -\fBwmcliphist\fR [\fB-h\fP] [\fB-v\fP] [\fB-n \fInum\fR\fP] [\fB-c \fIcol\fR\fP] [\fB-i \fInum\fR\fP] [\fB-s \fIsize\fR\fP] +\fBwmcliphist\fR [\fB-h\fP] [\fB-v\fP] [\fB-n \fInum\fR\fP] [\fB-c \fIcol\fR\fP] [\fB-i \fInum\fR\fP] [\fB-s \fIsize\fR\fP] [\fB-b \fIclipboard\fR\fP] .SH "DESCRIPTION" .PP This manual page documents briefly the program @@ -39,6 +39,10 @@ choose num=1 and for light backgrounds num=2. .IP "\fB-s size\fP " 10 Choose wmcliphist icon size, must be one of 16, 30, 40 or 60 (default). +.IP "\fB-b clipboard\fP " 10 +Choose clipboard to use, must be one of PRIMARY (select copies, middle click +pastes, default), SECONDARY (not used), or CLIPBOARD (Ctrl+C copies, +Ctrl+V pastes) .SH "AUTHOR" .PP diff --git a/wmcliphist/wmcliphist.c b/wmcliphist/wmcliphist.c index 98a9799..3f265c0 100644 --- a/wmcliphist/wmcliphist.c +++ b/wmcliphist/wmcliphist.c @@ -32,8 +32,11 @@ print_help() " 1 = for dark background\n" " 2 = for light background\n"); fprintf(stderr, "-d dumps clipboard history to stdout" - " in pseudo XML format (no escaping etc.)\n\n"); - + " in pseudo XML format (no escaping etc.)\n"); + fprintf(stderr, "-b choose clipboard to manage\n" + " PRIMARY = select copies, middle click pastes (default)\n" + " SECONDARY = not used\n" + " CLIPBOARD = Ctrl+C copies, Ctrl+V pastes\n\n"); exit(1); return_void(); } @@ -169,6 +172,14 @@ main(int argc, char **argv) } else if (*(arg + 1) == 'v') { printf("wmcliphist "WMCLIPHIST_VERSION"\n"); exit(1); + } else if (*(arg + 1) == 'b') { + i++; + if (!argv[i]) { + fprintf(stderr, "Missing value of -b\n"); + print_help(); + } + memset(clipboard_str, 0, 32); + strncpy(clipboard_str, argv[i], 31); } else { fprintf(stderr, "Invalid option -%c\n", *(arg + 1)); print_help(); @@ -318,6 +329,25 @@ main(int argc, char **argv) gdk_rgba_parse(&locked_color, locked_color_str); } + /* set clipboard */ + if (strcmp(clipboard_str, "PRIMARY") == 0) { + clipboard = GDK_SELECTION_PRIMARY; + } else if (strcmp(clipboard_str, "SECONDARY") == 0) { + clipboard = GDK_SELECTION_SECONDARY; + } else if (strcmp(clipboard_str, "CLIPBOARD") == 0) { + clipboard = GDK_SELECTION_CLIPBOARD; + } else { + char msg_str[128]; + + sprintf(msg_str, "Invalid clipboard string: '%s'.\n" + "Falling back to default (" + DEF_CLIPBOARD_STR + ").", + clipboard_str); + show_message(msg_str, "Warning", "OK", NULL, NULL); + clipboard = DEF_CLIPBOARD; + } + /* load previously saved history */ if (history_load(dump_only) != 0) { if (errno == E_TOO_MUCH) { @@ -377,7 +407,7 @@ main(int argc, char **argv) /* setup everything for supplying selection to other apps */ gtk_selection_add_target(dock_app, - GDK_SELECTION_PRIMARY, + clipboard, GDK_SELECTION_TYPE_STRING, 1); diff --git a/wmcliphist/wmcliphist.h b/wmcliphist/wmcliphist.h index 09470be..be14a4b 100644 --- a/wmcliphist/wmcliphist.h +++ b/wmcliphist/wmcliphist.h @@ -28,6 +28,8 @@ #define DEF_MENUKEY "Control+Alt+V" #define DEF_PREV_ITEM_KEY "Control+Alt+C" #define DEF_EXEC_ITEM_KEY "Control+Alt+E" +#define DEF_CLIPBOARD_STR "PRIMARY" +#define DEF_CLIPBOARD GDK_SELECTION_PRIMARY #define MAX_ITEM_LENGTH 40 @@ -63,6 +65,9 @@ extern HISTORY_ITEM *selected; extern gint locked_count; +/* which clipboard to use */ +extern gchar clipboard_str[32]; +extern GdkAtom clipboard; #ifdef DEBUG #define dump_history_list(header) dump_history_list_fn(header) diff --git a/wmcliphist/wmcliphistrc b/wmcliphist/wmcliphistrc index da3b7e6..e68455e 100644 --- a/wmcliphist/wmcliphistrc +++ b/wmcliphist/wmcliphistrc @@ -67,6 +67,11 @@ exec_middleclick yes exec_hotkey yes +# Which clipboard should wmcliphist manage? PRIMARY (select copies, middle click +# pastes), SECONDARY (not used), or CLIPBOARD (Ctrl+C copies, Ctrl+V pastes) +# Default: PRIMARY + +clipboard PRIMARY # You can define regular expressions driven actions executed when new # item is captured. Items can be silently ignored, inserted to submenus