Commit d09cd5c6 authored by Marwan Tanager's avatar Marwan Tanager Committed by Sebastian Ramacher

Make the X clipboard buffer configurable

This patch adds a new configuration setting, selection-clipboard, which allows
us to choose between the PRIMARY selection, and the CLIPBOARD selection, for
determining which X clipboard to use for storing mouse-selected data. It has
only two valid values: "primary" and "clipboard", with "clipboard" being set as
the it's default value.
Signed-off-by: Sebastian Ramacher's avatarSebastian Ramacher <sebastian+dev@ramacher.at>
parent 72573199
......@@ -128,6 +128,7 @@ config_load_default(zathura_t* zathura)
float float_value = 0;
bool bool_value = false;
bool inc_search = true;
char* string_value = NULL;
girara_session_t* gsession = zathura->ui.session;
/* mode settings */
......@@ -222,6 +223,8 @@ config_load_default(zathura_t* zathura)
girara_setting_add(gsession, "statusbar-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the statusbar"), NULL, NULL);
bool_value = false;
girara_setting_add(gsession, "synctex", &bool_value, BOOLEAN, false, _("Enable synctex support"), NULL, NULL);
string_value = "clipboard";
girara_setting_add(gsession, "selection-clipboard", string_value, STRING, false, _("The clipboard into which mouse-selected data will be written"), NULL, NULL);
/* define default shortcuts */
girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_c, NULL, sc_abort, 0, 0, NULL);
......
......@@ -669,15 +669,20 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
char* text = zathura_page_get_text(priv->page, tmp, NULL);
if (text != NULL) {
if (strlen(text) > 0) {
/* copy to clipboard */
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), text, -1);
GdkAtom* selection = get_selection(priv->zathura);
/* copy to clipboard */
if (selection != NULL) {
gtk_clipboard_set_text(gtk_clipboard_get(*selection), text, -1);
}
if (priv->page != NULL && document != NULL && priv->zathura != NULL) {
char* stripped_text = g_strdelimit(g_strdup(text), "\n\t\r\n", ' ');
girara_notify(priv->zathura->ui.session, GIRARA_INFO, _("Copied selected text to clipboard: %s"), stripped_text);
g_free(stripped_text);
}
g_free(selection);
}
g_free(text);
......@@ -832,9 +837,14 @@ cb_menu_image_copy(GtkMenuItem* item, ZathuraPage* page)
GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0,
0, width, height);
gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), pixbuf);
gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_PRIMARY), pixbuf);
GdkAtom* selection = get_selection(priv->zathura);
if (selection != NULL) {
gtk_clipboard_set_image(gtk_clipboard_get(*selection), pixbuf);
gtk_clipboard_set_image(gtk_clipboard_get(*selection), pixbuf);
}
g_free(selection);
/* reset */
priv->images.current = NULL;
#endif
......
......@@ -274,16 +274,24 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara
g_free(tmp);
}
GdkAtom* selection = get_selection(zathura);
/* we save the X clipboard that will be clear by "grab_focus" */
gchar* x_clipboard_text = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
gchar* x_clipboard_text;
if (selection != NULL) {
x_clipboard_text = gtk_clipboard_wait_for_text(gtk_clipboard_get(*selection));
}
gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar_entry), -1);
if (x_clipboard_text != NULL) {
if (x_clipboard_text != NULL && selection != NULL) {
/* we reset the X clipboard with saved text */
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), x_clipboard_text, -1);
gtk_clipboard_set_text(gtk_clipboard_get(*selection), x_clipboard_text, -1);
g_free(x_clipboard_text);
}
g_free(selection);
}
return true;
......
......@@ -411,3 +411,29 @@ replace_substring(const char* string, const char* old, const char* new)
return ret;
}
GdkAtom* get_selection(zathura_t* zathura)
{
g_return_val_if_fail(zathura != NULL, NULL);
char* value;
girara_setting_get(zathura->ui.session, "selection-clipboard", &value);
GdkAtom* selection = g_malloc(sizeof(GdkAtom));
if (strcmp(value, "primary") == 0) {
*selection = GDK_SELECTION_PRIMARY;
} else if (strcmp(value, "clipboard") == 0) {
*selection = GDK_SELECTION_CLIPBOARD;
} else {
girara_error("Invalid value for the selection-clipboard setting");
g_free(value);
g_free(selection);
return NULL;
}
g_free(value);
return selection;
}
......@@ -154,4 +154,14 @@ char* zathura_get_version_string(zathura_t* zathura, bool markup);
*/
char* replace_substring(const char* string, const char* old, const char* new);
/**
* Get a pointer to the GdkAtom of the current clipboard.
*
* @param zathura The zathura instance
*
* @return A pointer to a GdkAtom object correspoinding to the current
* clipboard, or NULL.
*/
GdkAtom* get_selection(zathura_t* zathura);
#endif // UTILS_H
......@@ -749,6 +749,17 @@ Defines the amount of percent that is zoomed in or out on each command.
* Value type: Integer
* Default value: 10
selection-clipboard
^^^^^^^^^^^^^^^^^^^
Defines the X clipbaord into which mouse-selected data will be written. When it
is "clipboard", selected data will be written to the CLIPBOARD clipboard, and
can be pasted using the Ctrl+v key combination. When it is "primary", selected
data will be written to the PRIMARY clipboard, and can be pasted using the
middle mouse button, or the Shift-Insert key combination.
* Value type: String
* Default value: clipbaord
SEE ALSO
========
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment