diff --git a/src/main.c b/src/main.c index f3faa14..e669dcf 100644 --- a/src/main.c +++ b/src/main.c @@ -114,6 +114,7 @@ void save_config_file(void) } gint jump_linenum = 0; +GtkClipboard *selection_primary = NULL; static void parse_args(gint argc, gchar **argv, FileInfo *fi) { @@ -207,6 +208,8 @@ gint main(gint argc, gchar **argv) gtk_init(&argc, &argv); g_set_application_name(PACKAGE_NAME); + selection_primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + pub->mw = create_main_window(); conf = g_malloc(sizeof(Conf)); diff --git a/src/view.c b/src/view.c index f6c7a4e..00f91c3 100644 --- a/src/view.c +++ b/src/view.c @@ -24,6 +24,9 @@ static gint keyval; static gboolean view_scroll_flag = FALSE; +extern GtkClipboard *selection_primary; +gchar *selection_primary_str = NULL; + gint get_current_keyval(void) { return keyval; @@ -216,6 +219,16 @@ static gboolean cb_button_press_event(GtkWidget *view, GdkEventButton *event) gtk_text_buffer_place_cursor(buffer, &iter); } + // backup and restore the clipboard + gchar *current_clipboard_str = gtk_clipboard_wait_for_text(selection_primary); + if ((current_clipboard_str == NULL) || (current_clipboard_str[0]=='\0')) { + gtk_clipboard_set_text(selection_primary, selection_primary_str, -1); + } + else { + g_free(selection_primary_str); + selection_primary_str = g_strdup(current_clipboard_str); + } + return FALSE; }