aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2010-04-25 14:57:19 +0000
committerSimon Tatham <anakin@pobox.com>2010-04-25 14:57:19 +0000
commit5062bee2ec7094a13e40f4946e1a45d4dcb8b854 (patch)
tree55a943aaae6d1e2ad1748a71aed79a3511f6d7b1
parent68bc396b7bfce5d30581af79863b8e32ea5bf7a8 (diff)
downloadpuzzles-5062bee2ec7094a13e40f4946e1a45d4dcb8b854.zip
puzzles-5062bee2ec7094a13e40f4946e1a45d4dcb8b854.tar.gz
puzzles-5062bee2ec7094a13e40f4946e1a45d4dcb8b854.tar.bz2
puzzles-5062bee2ec7094a13e40f4946e1a45d4dcb8b854.tar.xz
Patch from Debian, to bring the use of the X selection/clipboard in
line with freedesktop.org. (This is relatively simple for Puzzles, since it only writes to the clipboard and never reads it, so the question of which selection to use when is most easily dealt with by always writing to both.) [originally from svn r8929]
-rw-r--r--gtk.c77
1 files changed, 20 insertions, 57 deletions
diff --git a/gtk.c b/gtk.c
index 0fd351b..bfc06d7 100644
--- a/gtk.c
+++ b/gtk.c
@@ -1224,77 +1224,40 @@ static void menu_preset_event(GtkMenuItem *menuitem, gpointer data)
GdkAtom compound_text_atom, utf8_string_atom;
int paste_initialised = FALSE;
-void init_paste()
+static void set_selection(frontend *fe, GdkAtom selection)
{
- unsigned char empty[] = { 0 };
-
- if (paste_initialised)
- return;
-
- if (!compound_text_atom)
- compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE);
- if (!utf8_string_atom)
- utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);
+ if (!paste_initialised) {
+ compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE);
+ utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);
+ paste_initialised = TRUE;
+ }
/*
- * Ensure that all the cut buffers exist - according to the
- * ICCCM, we must do this before we start using cut buffers.
+ * For this simple application we can safely assume that the
+ * data passed to this function is pure ASCII, which means we
+ * can return precisely the same stuff for types STRING,
+ * COMPOUND_TEXT or UTF8_STRING.
*/
- XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER0, XA_STRING, 8, PropModeAppend, empty, 0);
- XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER1, XA_STRING, 8, PropModeAppend, empty, 0);
- XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER2, XA_STRING, 8, PropModeAppend, empty, 0);
- XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER3, XA_STRING, 8, PropModeAppend, empty, 0);
- XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER4, XA_STRING, 8, PropModeAppend, empty, 0);
- XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER5, XA_STRING, 8, PropModeAppend, empty, 0);
- XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER6, XA_STRING, 8, PropModeAppend, empty, 0);
- XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER7, XA_STRING, 8, PropModeAppend, empty, 0);
-}
-
-/* Store data in a cut-buffer. */
-void store_cutbuffer(char *ptr, int len)
-{
- /* ICCCM says we must rotate the buffers before storing to buffer 0. */
- XRotateBuffers(GDK_DISPLAY(), 1);
- XStoreBytes(GDK_DISPLAY(), ptr, len);
+
+ if (gtk_selection_owner_set(fe->area, selection, CurrentTime)) {
+ gtk_selection_clear_targets(fe->area, selection);
+ gtk_selection_add_target(fe->area, selection,
+ GDK_SELECTION_TYPE_STRING, 1);
+ gtk_selection_add_target(fe->area, selection, compound_text_atom, 1);
+ gtk_selection_add_target(fe->area, selection, utf8_string_atom, 1);
+ }
}
void write_clip(frontend *fe, char *data)
{
- init_paste();
-
if (fe->paste_data)
sfree(fe->paste_data);
- /*
- * For this simple application we can safely assume that the
- * data passed to this function is pure ASCII, which means we
- * can return precisely the same stuff for types STRING,
- * COMPOUND_TEXT or UTF8_STRING.
- */
-
fe->paste_data = data;
fe->paste_data_len = strlen(data);
- store_cutbuffer(fe->paste_data, fe->paste_data_len);
-
- if (gtk_selection_owner_set(fe->area, GDK_SELECTION_PRIMARY,
- CurrentTime)) {
- gtk_selection_clear_targets(fe->area, GDK_SELECTION_PRIMARY);
- gtk_selection_add_target(fe->area, GDK_SELECTION_PRIMARY,
- GDK_SELECTION_TYPE_STRING, 1);
- gtk_selection_add_target(fe->area, GDK_SELECTION_PRIMARY,
- compound_text_atom, 1);
- gtk_selection_add_target(fe->area, GDK_SELECTION_PRIMARY,
- utf8_string_atom, 1);
- }
+ set_selection(fe, GDK_SELECTION_PRIMARY);
+ set_selection(fe, GDK_SELECTION_CLIPBOARD);
}
void selection_get(GtkWidget *widget, GtkSelectionData *seldata,