Enable copy on select and Paste on middle button.

This commit is contained in:
Tetralet 2013-12-26 14:25:38 +08:00
parent f832fccd65
commit 84e95ff6fb
2 changed files with 16 additions and 0 deletions

View File

@ -114,6 +114,7 @@ void save_config_file(void)
} }
gint jump_linenum = 0; gint jump_linenum = 0;
GtkClipboard *selection_primary = NULL;
static void parse_args(gint argc, gchar **argv, FileInfo *fi) static void parse_args(gint argc, gchar **argv, FileInfo *fi)
{ {
@ -207,6 +208,8 @@ gint main(gint argc, gchar **argv)
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
g_set_application_name(PACKAGE_NAME); g_set_application_name(PACKAGE_NAME);
selection_primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
pub->mw = create_main_window(); pub->mw = create_main_window();
conf = g_malloc(sizeof(Conf)); conf = g_malloc(sizeof(Conf));

View File

@ -24,6 +24,9 @@
static gint keyval; static gint keyval;
static gboolean view_scroll_flag = FALSE; static gboolean view_scroll_flag = FALSE;
extern GtkClipboard *selection_primary;
gchar *selection_primary_str = NULL;
gint get_current_keyval(void) gint get_current_keyval(void)
{ {
return keyval; return keyval;
@ -216,6 +219,16 @@ static gboolean cb_button_press_event(GtkWidget *view, GdkEventButton *event)
gtk_text_buffer_place_cursor(buffer, &iter); 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; return FALSE;
} }