1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
#include "wmcliphist.h"
#include <time.h>
/* when true, clipboard will be automatically taken up by wmcliphist */
gint auto_take_up = 0;
/* number of items to keep (may be overriden from command line) */
gint num_items_to_keep = 10;
/* number if items kept */
gint num_items = 0;
/* current number of locked items */
gint locked_count;
/* list of clipboard history items */
GList *history_items = NULL;
/* selected item */
HISTORY_ITEM *selected = NULL;
/*
* dumps history list to stderr
* for debugging purposes only
*/
void
dump_history_list_fn(char *header)
{
gint indent = 1, i;
GList *node = history_items;
HISTORY_ITEM *data;
gchar *converted;
fprintf(stderr, "%s\n", header);
while (node) {
data = (HISTORY_ITEM *)node->data;
for (i = 0; i < indent; i++)
putc('-', stderr);
converted = from_utf8(data->content);
fprintf(stderr, " %s\n", converted);
g_free(converted);
indent++;
node = node->next;
}
fprintf(stderr, "==========\n");
}
void
my_get_selection_text(GtkClipboard *cb, const gchar *text, gpointer
data)
{
/* previous clipboard content */
static gchar *old_content = "";
static gint has_old_content = 0;
gchar *content;
gchar *converted;
begin_func("my_get_selection_text");
if (text == NULL) {
return_void();
}
if (g_utf8_collate(text, old_content) != 0 &&
!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore))) {
/* new data in clipboard */
/* store new content for future comparation */
content = g_strdup(text);
converted = from_utf8(content);
/* fprintf(stderr, ">>> %s\n", converted); */
g_free(converted);
if (has_old_content > 0)
g_free(old_content);
old_content = content;
has_old_content = 1;
/* process item */
process_item(content, 0, TRUE);
}
/* when clipboard is locked, set selection owener to myself */
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,
clipboard,
GDK_CURRENT_TIME) == 0)
selected = NULL;
}
return_void();
}
/*
* get clipboard content - partialy inspired by Downloader for X
*/
gboolean
my_get_xselection(GtkWidget *window, GdkEvent *event)
{
GdkAtom atom;
gint format;
size_t length;
gchar *content = NULL;
/* previous clipboard content */
static size_t old_content_len = 0;
static gchar *old_content = "";
begin_func("my_get_xselection");
gtk_clipboard_request_text(gtk_clipboard_get(clipboard),
my_get_selection_text, NULL);
return_val(TRUE);
length = (size_t) gdk_selection_property_get(gtk_widget_get_window(window),
(guchar **) &content, &atom, &format);
if (length > 0) {
if ((length != old_content_len ||
memcmp(content, old_content, length) != 0) &&
!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore))) {
/* new data in clipboard */
/* store new content for future comparation */
if (old_content_len > 0)
g_free(old_content);
old_content = content;
old_content_len = length;
/* process item */
/* process_item(content, length, 0, TRUE); */
} else {
/* no new data */
g_free(content);
}
/* when clipboard is locked, set selection owener to myself */
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,
clipboard,
GDK_CURRENT_TIME) == 0)
selected = NULL;
}
}
return_val(TRUE);
}
/*
* clipboard conversion - inspired by Downloader for X too :)
*/
gboolean
time_conv_select()
{
begin_func("time_conv_select");
gtk_selection_convert(main_window,
clipboard,
GDK_TARGET_STRING,
GDK_CURRENT_TIME);
return_val(TRUE);
}
/*
* handles request for selection from other apps
*/
gboolean
selection_handle(GtkWidget *widget,
GtkSelectionData *selection_data,
guint info,
guint time_stamp,
gpointer data)
{
static gchar *converted = NULL;
begin_func("selection_handle");
if (converted != NULL) {
g_free(converted);
}
if (selected) {
converted = from_utf8(selected->content);
gtk_selection_data_set(selection_data,
GDK_SELECTION_TYPE_STRING,
8,
(guchar *) converted,
strlen(converted));
} else {
gtk_selection_data_set(selection_data,
GDK_SELECTION_TYPE_STRING,
8,
(guchar *)"",
0);
}
return_val(TRUE);
}
|