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
*clipboard
, 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(menu_app_clip_ignore
)->active
) {
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(menu_app_clip_ignore
)->active
||
87 GTK_CHECK_MENU_ITEM(menu_app_clip_lock
)->active
) {
88 if (gtk_selection_owner_set(dock_app
,
89 GDK_SELECTION_PRIMARY
,
90 GDK_CURRENT_TIME
) == 0)
99 * get clipboard content - partialy inspired by Downloader for X
102 my_get_xselection(GtkWidget
*window
, GdkEvent
*event
)
107 gchar
*content
= NULL
;
109 /* previous clipboard content */
110 static size_t old_content_len
= 0;
111 static gchar
*old_content
= "";
114 begin_func("my_get_xselection");
116 gtk_clipboard_request_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY
),
117 my_get_selection_text
, NULL
);
121 length
= (size_t) gdk_selection_property_get(window
->window
,
122 (guchar
**) &content
, &atom
, &format
);
125 if ((length
!= old_content_len
||
126 memcmp(content
, old_content
, length
) != 0) &&
127 !GTK_CHECK_MENU_ITEM(menu_app_clip_ignore
)->active
) {
128 /* new data in clipboard */
129 /* store new content for future comparation */
130 if (old_content_len
> 0)
132 old_content
= content
;
133 old_content_len
= length
;
136 /* process_item(content, length, 0, TRUE); */
142 /* when clipboard is locked, set selection owener to myself */
143 if (GTK_CHECK_MENU_ITEM(menu_app_clip_ignore
)->active
||
144 GTK_CHECK_MENU_ITEM(menu_app_clip_lock
)->active
) {
145 if (gtk_selection_owner_set(dock_app
,
146 GDK_SELECTION_PRIMARY
,
147 GDK_CURRENT_TIME
) == 0)
158 * clipboard conversion - inspired by Downloader for X too :)
163 begin_func("time_conv_select");
165 gtk_selection_convert(main_window
,
166 GDK_SELECTION_PRIMARY
,
174 * handles request for selection from other apps
177 selection_handle(GtkWidget
*widget
,
178 GtkSelectionData
*selection_data
,
183 static gchar
*converted
= NULL
;
185 begin_func("selection_handle");
187 if (converted
!= NULL
) {
192 converted
= from_utf8(selected
->content
);
193 gtk_selection_data_set(selection_data
,
194 GDK_SELECTION_TYPE_STRING
,
196 (guchar
*) converted
,
199 gtk_selection_data_set(selection_data
,
200 GDK_SELECTION_TYPE_STRING
,