diff options
| author | Yuuki Harano | 2021-02-11 19:30:01 +0900 |
|---|---|---|
| committer | Yuuki Harano | 2021-02-11 19:30:01 +0900 |
| commit | ef76e64427bb980cca23c338df2526766431ea52 (patch) | |
| tree | f7e0dba7945479fd31569fda08a7c0ef6e0b1c99 /src/pgtkselect.c | |
| parent | ed2205a288a7c38f8614fa134f27be41baad00dc (diff) | |
| download | emacs-ef76e64427bb980cca23c338df2526766431ea52.tar.gz emacs-ef76e64427bb980cca23c338df2526766431ea52.zip | |
Support getting a image from clipboard
* src/pgtkselect.c (Fpgtk_get_selection_internal): Reimplement
referring selection_data_to_lisp_data in xselect.c
(syms_of_pgtkselect): Add symbols.
Diffstat (limited to 'src/pgtkselect.c')
| -rw-r--r-- | src/pgtkselect.c | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/src/pgtkselect.c b/src/pgtkselect.c index 3e57fc7526c..2d81d1274ca 100644 --- a/src/pgtkselect.c +++ b/src/pgtkselect.c | |||
| @@ -546,14 +546,41 @@ On PGTK, TIME-STAMP is unused. */) | |||
| 546 | 546 | ||
| 547 | cb = symbol_to_gtk_clipboard (FRAME_GTK_WIDGET (f), selection_symbol); | 547 | cb = symbol_to_gtk_clipboard (FRAME_GTK_WIDGET (f), selection_symbol); |
| 548 | 548 | ||
| 549 | gchar *s = gtk_clipboard_wait_for_text (cb); | 549 | GdkAtom target_atom = gdk_atom_intern (SSDATA (SYMBOL_NAME (target_type)), false); |
| 550 | if (s == NULL) | 550 | GtkSelectionData *seldata = gtk_clipboard_wait_for_contents (cb, target_atom); |
| 551 | |||
| 552 | if (seldata == NULL) | ||
| 551 | return Qnil; | 553 | return Qnil; |
| 552 | int size = strlen (s); | 554 | |
| 553 | Lisp_Object str = make_unibyte_string (s, size); | 555 | const guchar *sd_data = gtk_selection_data_get_data (seldata); |
| 554 | Fput_text_property (make_fixnum (0), make_fixnum (size), | 556 | int sd_len = gtk_selection_data_get_length (seldata); |
| 555 | Qforeign_selection, QUTF8_STRING, str); | 557 | int sd_format = gtk_selection_data_get_format (seldata); |
| 556 | return str; | 558 | GdkAtom sd_type = gtk_selection_data_get_data_type (seldata); |
| 559 | |||
| 560 | if (sd_format == 8) | ||
| 561 | { | ||
| 562 | Lisp_Object str, lispy_type; | ||
| 563 | |||
| 564 | str = make_unibyte_string ((char *) sd_data, sd_len); | ||
| 565 | /* Indicate that this string is from foreign selection by a text | ||
| 566 | property `foreign-selection' so that the caller of | ||
| 567 | x-get-selection-internal (usually x-get-selection) can know | ||
| 568 | that the string must be decode. */ | ||
| 569 | if (sd_type == gdk_atom_intern("COMPOUND_TEXT", false)) | ||
| 570 | lispy_type = QCOMPOUND_TEXT; | ||
| 571 | else if (sd_type == gdk_atom_intern("UTF8_STRING", false)) | ||
| 572 | lispy_type = QUTF8_STRING; | ||
| 573 | else | ||
| 574 | lispy_type = QSTRING; | ||
| 575 | Fput_text_property (make_fixnum (0), make_fixnum (sd_len), | ||
| 576 | Qforeign_selection, lispy_type, str); | ||
| 577 | |||
| 578 | gtk_selection_data_free (seldata); | ||
| 579 | return str; | ||
| 580 | } | ||
| 581 | |||
| 582 | gtk_selection_data_free (seldata); | ||
| 583 | return Qnil; | ||
| 557 | } | 584 | } |
| 558 | 585 | ||
| 559 | 586 | ||
| @@ -576,6 +603,8 @@ syms_of_pgtkselect (void) | |||
| 576 | 603 | ||
| 577 | DEFSYM (Qforeign_selection, "foreign-selection"); | 604 | DEFSYM (Qforeign_selection, "foreign-selection"); |
| 578 | DEFSYM (QUTF8_STRING, "UTF8_STRING"); | 605 | DEFSYM (QUTF8_STRING, "UTF8_STRING"); |
| 606 | DEFSYM (QSTRING, "STRING"); | ||
| 607 | DEFSYM (QCOMPOUND_TEXT, "COMPOUND_TEXT"); | ||
| 579 | 608 | ||
| 580 | defsubr (&Spgtk_disown_selection_internal); | 609 | defsubr (&Spgtk_disown_selection_internal); |
| 581 | defsubr (&Spgtk_get_selection_internal); | 610 | defsubr (&Spgtk_get_selection_internal); |