1 #include "wmcliphist.h"
4 /* when true, clipboard will be automatically taken up by wmcliphist */
7 /* number of items to keep (may be overriden from command line) */
8 gint num_items_to_keep
= 10;
10 /* number if items kept */
13 /* current number of locked items */
16 /* list of clipboard history items */
17 GList
*history_items
= NULL
;
20 HISTORY_ITEM
*selected
= NULL
;
25 * dumps history list to stderr
26 * for debugging purposes only
29 dump_history_list_fn(char *header
)
32 GList
*node
= history_items
;
36 fprintf(stderr
, "%s\n", header
);
38 data
= (HISTORY_ITEM
*)node
->data
;
39 for (i
= 0; i
< indent
; i
++)
41 converted
= from_utf8(data
->content
);
42 fprintf(stderr
, " %s\n", converted
);
47 fprintf(stderr
, "==========\n");
51 my_get_selection_text(GtkClipboard
*cb
, const gchar
*text
, gpointer
54 /* previous clipboard content */
55 static gchar
*old_content
= "";
56 static gint has_old_content
= 0;
60 begin_func("my_get_selection_text");
66 if (g_utf8_collate(text
, old_content
) != 0 &&
67 !gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore
))) {
68 /* new data in clipboard */
69 /* store new content for future comparation */
70 content
= g_strdup(text
);
72 converted
= from_utf8(content
);
73 /* fprintf(stderr, ">>> %s\n", converted); */
76 if (has_old_content
> 0)
78 old_content
= content
;
82 process_item(content
, 0, TRUE
);
85 /* when clipboard is locked, set selection owener to myself */
86 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore
)) ||
87 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_lock
))) {
88 if (gtk_selection_owner_set(dock_app
,
90 GDK_CURRENT_TIME
) == 0)
99 * get clipboard content - partialy inspired by Downloader for X
102 my_get_xselection(GtkWidget
*window
, GdkEvent
*event
)
105 begin_func("my_get_xselection");
107 gtk_clipboard_request_text(gtk_clipboard_get(clipboard
),
108 my_get_selection_text
, NULL
);
115 * clipboard conversion - inspired by Downloader for X too :)
120 begin_func("time_conv_select");
122 gtk_selection_convert(main_window
,
131 * handles request for selection from other apps
134 selection_handle(GtkWidget
*widget
,
135 GtkSelectionData
*selection_data
,
140 static gchar
*converted
= NULL
;
142 begin_func("selection_handle");
144 if (converted
!= NULL
) {
149 converted
= from_utf8(selected
->content
);
150 gtk_selection_data_set(selection_data
,
151 GDK_SELECTION_TYPE_STRING
,
153 (guchar
*) converted
,
156 gtk_selection_data_set(selection_data
,
157 GDK_SELECTION_TYPE_STRING
,