aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-07-06 10:42:12 +0800
committerPo Lu2022-07-06 10:42:12 +0800
commite482379a65e99cb61aba86876587b499eeeef007 (patch)
tree698e03aa0830e0a74279f6f66abd5f0e89081897 /src
parentcd18cee96ee17562a276ea84bc9313e5bcbccb55 (diff)
downloademacs-e482379a65e99cb61aba86876587b499eeeef007.tar.gz
emacs-e482379a65e99cb61aba86876587b499eeeef007.zip
Reduce duplicate code cleaning up DND processes
* src/xterm.c (x_restore_events_after_dnd): New function. (x_dnd_cleanup_drag_and_drop, x_dnd_begin_drag_and_drop): Use that instead of manually cleaning up properties and events.
Diffstat (limited to 'src')
-rw-r--r--src/xterm.c117
1 files changed, 33 insertions, 84 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 2643d1120f9..45aef51ecb3 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -4597,6 +4597,34 @@ x_free_dnd_toplevels (void)
4597 x_dnd_free_toplevels (true); 4597 x_dnd_free_toplevels (true);
4598} 4598}
4599 4599
4600/* Restore event masks and window properties changed during a
4601 drag-and-drop operation, after it finishes. */
4602static void
4603x_restore_events_after_dnd (struct frame *f, XWindowAttributes *wa)
4604{
4605 struct x_display_info *dpyinfo;
4606
4607 dpyinfo = FRAME_DISPLAY_INFO (f);
4608
4609 /* Restore the old event mask. */
4610 XSelectInput (dpyinfo->display, dpyinfo->root_window,
4611 wa->your_event_mask);
4612#ifdef HAVE_XKB
4613 if (dpyinfo->supports_xkb)
4614 XkbSelectEvents (dpyinfo->display, XkbUseCoreKbd,
4615 XkbStateNotifyMask, 0);
4616#endif
4617 /* Delete the Motif drag initiator info if it was set up. */
4618 if (x_dnd_motif_setup_p)
4619 XDeleteProperty (dpyinfo->display, FRAME_X_WINDOW (f),
4620 x_dnd_motif_atom);
4621
4622 /* Remove any type list set as well. */
4623 if (x_dnd_init_type_lists && x_dnd_n_targets > 3)
4624 XDeleteProperty (dpyinfo->display, FRAME_X_WINDOW (f),
4625 dpyinfo->Xatom_XdndTypeList);
4626}
4627
4600static void 4628static void
4601x_dnd_cleanup_drag_and_drop (void *frame) 4629x_dnd_cleanup_drag_and_drop (void *frame)
4602{ 4630{
@@ -4656,32 +4684,9 @@ x_dnd_cleanup_drag_and_drop (void *frame)
4656#endif 4684#endif
4657 x_dnd_return_frame_object = NULL; 4685 x_dnd_return_frame_object = NULL;
4658 x_dnd_movement_frame = NULL; 4686 x_dnd_movement_frame = NULL;
4659
4660 block_input ();
4661 /* Restore the old event mask. */
4662 XSelectInput (FRAME_X_DISPLAY (f),
4663 FRAME_DISPLAY_INFO (f)->root_window,
4664 x_dnd_old_window_attrs.your_event_mask);
4665
4666#ifdef HAVE_XKB
4667 if (FRAME_DISPLAY_INFO (f)->supports_xkb)
4668 XkbSelectEvents (FRAME_X_DISPLAY (f), XkbUseCoreKbd,
4669 XkbStateNotifyMask, 0);
4670#endif
4671
4672 /* Delete the Motif drag initiator info if it was set up. */
4673 if (x_dnd_motif_setup_p)
4674 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4675 FRAME_DISPLAY_INFO (f)->Xatom_XdndSelection);
4676
4677 /* Remove any type list set as well. */
4678 if (x_dnd_init_type_lists && x_dnd_n_targets > 3)
4679 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4680 FRAME_DISPLAY_INFO (f)->Xatom_XdndTypeList);
4681
4682 unblock_input ();
4683
4684 x_dnd_frame = NULL; 4687 x_dnd_frame = NULL;
4688
4689 x_restore_events_after_dnd (f, &x_dnd_old_window_attrs);
4685} 4690}
4686 4691
4687static void 4692static void
@@ -11779,24 +11784,7 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
11779 current_hold_quit = NULL; 11784 current_hold_quit = NULL;
11780#endif 11785#endif
11781 /* Restore the old event mask. */ 11786 /* Restore the old event mask. */
11782 XSelectInput (FRAME_X_DISPLAY (f), 11787 x_restore_events_after_dnd (f, &root_window_attrs);
11783 FRAME_DISPLAY_INFO (f)->root_window,
11784 root_window_attrs.your_event_mask);
11785#ifdef HAVE_XKB
11786 if (FRAME_DISPLAY_INFO (f)->supports_xkb)
11787 XkbSelectEvents (FRAME_X_DISPLAY (f), XkbUseCoreKbd,
11788 XkbStateNotifyMask, 0);
11789#endif
11790 /* Delete the Motif drag initiator info if it was set up. */
11791 if (x_dnd_motif_setup_p)
11792 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
11793 x_dnd_motif_atom);
11794
11795
11796 /* Remove any type list set as well. */
11797 if (x_dnd_init_type_lists && x_dnd_n_targets > 3)
11798 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
11799 FRAME_DISPLAY_INFO (f)->Xatom_XdndTypeList);
11800 11788
11801 /* Call kbd_buffer_store event, which calls 11789 /* Call kbd_buffer_store event, which calls
11802 handle_interrupt and sets `last-event-frame' along 11790 handle_interrupt and sets `last-event-frame' along
@@ -11913,27 +11901,8 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
11913 FRAME_DISPLAY_INFO (f)->grabbed = 0; 11901 FRAME_DISPLAY_INFO (f)->grabbed = 0;
11914 current_hold_quit = NULL; 11902 current_hold_quit = NULL;
11915 11903
11916 block_input ();
11917 /* Restore the old event mask. */ 11904 /* Restore the old event mask. */
11918 XSelectInput (FRAME_X_DISPLAY (f), 11905 x_restore_events_after_dnd (f, &root_window_attrs);
11919 FRAME_DISPLAY_INFO (f)->root_window,
11920 root_window_attrs.your_event_mask);
11921#ifdef HAVE_XKB
11922 if (FRAME_DISPLAY_INFO (f)->supports_xkb)
11923 XkbSelectEvents (FRAME_X_DISPLAY (f), XkbUseCoreKbd,
11924 XkbStateNotifyMask, 0);
11925#endif
11926 /* Delete the Motif drag initiator info if it was set up. */
11927 if (x_dnd_motif_setup_p)
11928 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
11929 x_dnd_motif_atom);
11930
11931
11932 /* Remove any type list set as well. */
11933 if (x_dnd_init_type_lists && x_dnd_n_targets > 3)
11934 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
11935 FRAME_DISPLAY_INFO (f)->Xatom_XdndTypeList);
11936 unblock_input ();
11937 11906
11938 quit (); 11907 quit ();
11939 } 11908 }
@@ -11956,27 +11925,7 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
11956 current_hold_quit = NULL; 11925 current_hold_quit = NULL;
11957#endif 11926#endif
11958 x_dnd_movement_frame = NULL; 11927 x_dnd_movement_frame = NULL;
11959 11928 x_restore_events_after_dnd (f, &root_window_attrs);
11960 block_input ();
11961 /* Restore the old event mask. */
11962 XSelectInput (FRAME_X_DISPLAY (f),
11963 FRAME_DISPLAY_INFO (f)->root_window,
11964 root_window_attrs.your_event_mask);
11965#ifdef HAVE_XKB
11966 if (FRAME_DISPLAY_INFO (f)->supports_xkb)
11967 XkbSelectEvents (FRAME_X_DISPLAY (f), XkbUseCoreKbd,
11968 XkbStateNotifyMask, 0);
11969#endif
11970 /* Delete the Motif drag initiator info if it was set up. */
11971 if (x_dnd_motif_setup_p)
11972 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
11973 x_dnd_motif_atom);
11974
11975 /* Remove any type list set as well. */
11976 if (x_dnd_init_type_lists && x_dnd_n_targets > 3)
11977 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
11978 FRAME_DISPLAY_INFO (f)->Xatom_XdndTypeList);
11979 unblock_input ();
11980 11929
11981 if (x_dnd_return_frame == 3 11930 if (x_dnd_return_frame == 3
11982 && FRAME_LIVE_P (x_dnd_return_frame_object)) 11931 && FRAME_LIVE_P (x_dnd_return_frame_object))