diff options
| author | Po Lu | 2022-06-23 13:38:30 +0800 |
|---|---|---|
| committer | Po Lu | 2022-06-23 13:58:38 +0800 |
| commit | 0b4db66a9deae682dc7d444f4ab8d0e49f15c3b9 (patch) | |
| tree | 6f08101c3b9697085153e3babe29dc379d031b9c /src/pgtkselect.c | |
| parent | 00034ad2e635adc93cd1d6dcb1b500c10d990c74 (diff) | |
| download | emacs-0b4db66a9deae682dc7d444f4ab8d0e49f15c3b9.tar.gz emacs-0b4db66a9deae682dc7d444f4ab8d0e49f15c3b9.zip | |
Allow dropping more data types on PGTK
* lisp/loadup.el (featurep): Load `pgtk-dnd'.
* lisp/pgtk-dnd.el: New file.
(pgtk-dnd-test-function, pgtk-dnd-types-alist)
(pgtk-dnd-known-types, pgtk-dnd-use-offix-drop)
(pgtk-dnd-current-state, pgtk-get-selection-internal)
(pgtk-register-dnd-targets, pgtk-dnd-empty-state)
(pgtk-dnd-init-frame, pgtk-dnd-get-state-cons-for-frame)
(pgtk-dnd-get-state-for-frame, pgtk-dnd-default-test-function)
(pgtk-dnd-current-type, pgtk-dnd-forget-drop)
(pgtk-dnd-maybe-call-test-function, pgtk-dnd-save-state)
(pgtk-dnd-handle-moz-url, pgtk-dnd-insert-utf8-text)
(pgtk-dnd-insert-utf16-text, pgtk-dnd-insert-ctext)
(pgtk-dnd-handle-uri-list, pgtk-dnd-handle-file-name)
(pgtk-dnd-choose-type, pgtk-dnd-drop-data)
(pgtk-dnd-handle-drag-n-drop-event, pgtk-update-drop-status)
(pgtk-drop-finish, pgtk-dnd-handle-gdk, pgtk-dnd): New variables
and functions and library.
* lisp/term/pgtk-win.el (special-event-map): Load
`drag-n-drop-event'.
(after-make-frame-functions): Register DND after make frame
functions.
* src/emacs.c (main): Stop calling empty init_pgtkterm function.
* src/pgtkselect.c (Fpgtk_register_dnd_targets, Fpgtk_drop_finish)
(Fpgtk_update_drop_status): New functions.
(syms_of_pgtkselect): Register new functions.
* src/pgtkterm.c (struct event_queue_t): Fix coding style of
definition.
(symbol_to_drag_action, drag_action_to_symbol)
(pgtk_update_drop_status, pgtk_finish_drop): New functions.
(drag_data_received): Delete function.
(pgtk_set_event_handler): Register for DND correctly.
(syms_of_pgtkterm): New defsyms for DND types.
(init_pgtkterm): Delete function.
* src/pgtkterm.h: Update prototypes, fix prototype coding style.
Diffstat (limited to 'src/pgtkselect.c')
| -rw-r--r-- | src/pgtkselect.c | 99 |
1 files changed, 89 insertions, 10 deletions
diff --git a/src/pgtkselect.c b/src/pgtkselect.c index 122b5d8c073..2a4f6adba4b 100644 --- a/src/pgtkselect.c +++ b/src/pgtkselect.c | |||
| @@ -1762,6 +1762,86 @@ pgtk_handle_selection_notify (GdkEventSelection *event) | |||
| 1762 | (event->property != GDK_NONE ? Qt : Qlambda)); | 1762 | (event->property != GDK_NONE ? Qt : Qlambda)); |
| 1763 | } | 1763 | } |
| 1764 | 1764 | ||
| 1765 | |||
| 1766 | /*********************************************************************** | ||
| 1767 | Drag and drop support | ||
| 1768 | ***********************************************************************/ | ||
| 1769 | |||
| 1770 | DEFUN ("pgtk-register-dnd-targets", Fpgtk_register_dnd_targets, | ||
| 1771 | Spgtk_register_dnd_targets, 2, 2, 0, | ||
| 1772 | doc: /* Register TARGETS on FRAME. | ||
| 1773 | TARGETS should be a list of strings describing data types (selection | ||
| 1774 | targets) that can be dropped on top of FRAME. */) | ||
| 1775 | (Lisp_Object frame, Lisp_Object targets) | ||
| 1776 | { | ||
| 1777 | struct frame *f; | ||
| 1778 | GtkTargetEntry *entries; | ||
| 1779 | GtkTargetList *list; | ||
| 1780 | ptrdiff_t length, n; | ||
| 1781 | Lisp_Object tem, t; | ||
| 1782 | char *buf; | ||
| 1783 | USE_SAFE_ALLOCA; | ||
| 1784 | |||
| 1785 | f = decode_window_system_frame (frame); | ||
| 1786 | CHECK_LIST (targets); | ||
| 1787 | length = list_length (targets); | ||
| 1788 | n = 0; | ||
| 1789 | entries = SAFE_ALLOCA (sizeof *entries * length); | ||
| 1790 | memset (entries, 0, sizeof *entries * length); | ||
| 1791 | tem = targets; | ||
| 1792 | |||
| 1793 | FOR_EACH_TAIL (tem) | ||
| 1794 | { | ||
| 1795 | if (!CONSP (tem)) | ||
| 1796 | continue; | ||
| 1797 | |||
| 1798 | t = XCAR (tem); | ||
| 1799 | |||
| 1800 | CHECK_STRING (t); | ||
| 1801 | SAFE_ALLOCA_STRING (buf, t); | ||
| 1802 | |||
| 1803 | entries[n++].target = buf; | ||
| 1804 | } | ||
| 1805 | CHECK_LIST_END (tem, targets); | ||
| 1806 | |||
| 1807 | if (n != length) | ||
| 1808 | emacs_abort (); | ||
| 1809 | |||
| 1810 | list = gtk_target_list_new (entries, n); | ||
| 1811 | gtk_drag_dest_set_target_list (FRAME_GTK_WIDGET (f), list); | ||
| 1812 | gtk_target_list_unref (list); | ||
| 1813 | |||
| 1814 | SAFE_FREE (); | ||
| 1815 | |||
| 1816 | return Qnil; | ||
| 1817 | } | ||
| 1818 | |||
| 1819 | DEFUN ("pgtk-drop-finish", Fpgtk_drop_finish, Spgtk_drop_finish, 3, 3, 0, | ||
| 1820 | doc: /* Finish the drag-n-drop event that happened at TIMESTAMP. | ||
| 1821 | SUCCESS is whether or not the drop was successful, i.e. the action | ||
| 1822 | chosen in the last call to `pgtk-update-drop-status' was performed. | ||
| 1823 | TIMESTAMP is the time associated with the drag-n-drop event that is | ||
| 1824 | being finished. | ||
| 1825 | DELETE is whether or not the action was `move'. */) | ||
| 1826 | (Lisp_Object success, Lisp_Object timestamp, Lisp_Object delete) | ||
| 1827 | { | ||
| 1828 | pgtk_finish_drop (success, timestamp, delete); | ||
| 1829 | |||
| 1830 | return Qnil; | ||
| 1831 | } | ||
| 1832 | |||
| 1833 | DEFUN ("pgtk-update-drop-status", Fpgtk_update_drop_status, | ||
| 1834 | Spgtk_update_drop_status, 2, 2, 0, | ||
| 1835 | doc: /* Update the status of the current drag-and-drop operation. | ||
| 1836 | ACTION is the action the drop source should take. | ||
| 1837 | TIMESTAMP is the same as in `pgtk-drop-finish'. */) | ||
| 1838 | (Lisp_Object action, Lisp_Object timestamp) | ||
| 1839 | { | ||
| 1840 | pgtk_update_drop_status (action, timestamp); | ||
| 1841 | |||
| 1842 | return Qnil; | ||
| 1843 | } | ||
| 1844 | |||
| 1765 | void | 1845 | void |
| 1766 | syms_of_pgtkselect (void) | 1846 | syms_of_pgtkselect (void) |
| 1767 | { | 1847 | { |
| @@ -1777,23 +1857,22 @@ syms_of_pgtkselect (void) | |||
| 1777 | DEFSYM (QNULL, "NULL"); | 1857 | DEFSYM (QNULL, "NULL"); |
| 1778 | DEFSYM (QATOM, "ATOM"); | 1858 | DEFSYM (QATOM, "ATOM"); |
| 1779 | DEFSYM (QTARGETS, "TARGETS"); | 1859 | DEFSYM (QTARGETS, "TARGETS"); |
| 1780 | |||
| 1781 | DEFSYM (Qpgtk_sent_selection_functions, | ||
| 1782 | "pgtk-sent-selection-functions"); | ||
| 1783 | DEFSYM (Qpgtk_lost_selection_functions, | ||
| 1784 | "pgtk-lost-selection-functions"); | ||
| 1785 | |||
| 1786 | DEFSYM (Qforeign_selection, "foreign-selection"); | ||
| 1787 | DEFSYM (QUTF8_STRING, "UTF8_STRING"); | 1860 | DEFSYM (QUTF8_STRING, "UTF8_STRING"); |
| 1788 | DEFSYM (QSTRING, "STRING"); | ||
| 1789 | DEFSYM (QCOMPOUND_TEXT, "COMPOUND_TEXT"); | 1861 | DEFSYM (QCOMPOUND_TEXT, "COMPOUND_TEXT"); |
| 1790 | DEFSYM (Qtext_plain_charset_utf_8, "text/plain;charset=utf-8"); | 1862 | |
| 1863 | DEFSYM (Qforeign_selection, "foreign-selection"); | ||
| 1864 | |||
| 1865 | DEFSYM (Qpgtk_sent_selection_functions, "pgtk-sent-selection-functions"); | ||
| 1866 | DEFSYM (Qpgtk_lost_selection_functions, "pgtk-lost-selection-functions"); | ||
| 1791 | 1867 | ||
| 1792 | defsubr (&Spgtk_disown_selection_internal); | 1868 | defsubr (&Spgtk_disown_selection_internal); |
| 1793 | defsubr (&Spgtk_get_selection_internal); | 1869 | defsubr (&Spgtk_get_selection_internal); |
| 1794 | defsubr (&Spgtk_own_selection_internal); | 1870 | defsubr (&Spgtk_own_selection_internal); |
| 1795 | defsubr (&Spgtk_selection_exists_p); | 1871 | defsubr (&Spgtk_selection_exists_p); |
| 1796 | defsubr (&Spgtk_selection_owner_p); | 1872 | defsubr (&Spgtk_selection_owner_p); |
| 1873 | defsubr (&Spgtk_register_dnd_targets); | ||
| 1874 | defsubr (&Spgtk_update_drop_status); | ||
| 1875 | defsubr (&Spgtk_drop_finish); | ||
| 1797 | 1876 | ||
| 1798 | DEFVAR_LISP ("selection-converter-alist", Vselection_converter_alist, | 1877 | DEFVAR_LISP ("selection-converter-alist", Vselection_converter_alist, |
| 1799 | doc: /* SKIP: real doc in xselect.c. */); | 1878 | doc: /* SKIP: real doc in xselect.c. */); |
| @@ -1817,7 +1896,7 @@ The functions are called with three arguments: | |||
| 1817 | We might have failed (and declined the request) for any number of reasons, | 1896 | We might have failed (and declined the request) for any number of reasons, |
| 1818 | including being asked for a selection that we no longer own, or being asked | 1897 | including being asked for a selection that we no longer own, or being asked |
| 1819 | to convert into a type that we don't know about or that is inappropriate. | 1898 | to convert into a type that we don't know about or that is inappropriate. |
| 1820 | This hook doesn't let you change the behavior of Emacs's selection replies, | 1899 | xThis hook doesn't let you change the behavior of Emacs's selection replies, |
| 1821 | it merely informs you that they have happened. */); | 1900 | it merely informs you that they have happened. */); |
| 1822 | Vpgtk_sent_selection_functions = Qnil; | 1901 | Vpgtk_sent_selection_functions = Qnil; |
| 1823 | 1902 | ||