2014-11-23 02:48:41 +00:00
|
|
|
#include "wmcliphist.h"
|
2014-11-23 02:48:37 +00:00
|
|
|
#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;
|
2014-11-23 02:48:42 +00:00
|
|
|
|
2014-11-23 02:48:37 +00:00
|
|
|
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
|
2014-11-23 02:48:52 +00:00
|
|
|
my_get_selection_text(GtkClipboard *cb, const gchar *text, gpointer
|
2014-11-23 02:48:37 +00:00
|
|
|
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();
|
|
|
|
}
|
2014-11-23 02:48:42 +00:00
|
|
|
|
2014-11-23 02:48:37 +00:00
|
|
|
if (g_utf8_collate(text, old_content) != 0 &&
|
2014-11-23 02:48:44 +00:00
|
|
|
!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore))) {
|
2014-11-23 02:48:37 +00:00
|
|
|
/* 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 */
|
2014-11-23 02:48:44 +00:00
|
|
|
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))) {
|
2014-11-23 02:48:37 +00:00
|
|
|
if (gtk_selection_owner_set(dock_app,
|
2014-11-23 02:48:52 +00:00
|
|
|
clipboard,
|
2014-11-23 02:48:37 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
|
|
|
begin_func("my_get_xselection");
|
|
|
|
|
2014-11-23 02:48:52 +00:00
|
|
|
gtk_clipboard_request_text(gtk_clipboard_get(clipboard),
|
2014-11-23 02:48:37 +00:00
|
|
|
my_get_selection_text, 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,
|
2014-11-23 02:48:52 +00:00
|
|
|
clipboard,
|
2014-11-23 02:48:37 +00:00
|
|
|
GDK_TARGET_STRING,
|
|
|
|
GDK_CURRENT_TIME);
|
|
|
|
return_val(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handles request for selection from other apps
|
|
|
|
*/
|
|
|
|
gboolean
|
2014-11-23 02:48:42 +00:00
|
|
|
selection_handle(GtkWidget *widget,
|
2014-11-23 02:48:37 +00:00
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint time_stamp,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
static gchar *converted = NULL;
|
2014-11-23 02:48:42 +00:00
|
|
|
|
2014-11-23 02:48:37 +00:00
|
|
|
begin_func("selection_handle");
|
|
|
|
|
|
|
|
if (converted != NULL) {
|
|
|
|
g_free(converted);
|
|
|
|
}
|
2014-11-23 02:48:42 +00:00
|
|
|
|
2014-11-23 02:48:37 +00:00
|
|
|
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);
|
|
|
|
}
|