aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-04-14 16:02:12 +0800
committerPo Lu2022-04-14 16:04:59 +0800
commit203c503ff22e6c3c7b75d0e30d1974bb0ca9e60a (patch)
treeea558353a347de0844bcecfcc6e3a6bcb7a30712 /src
parentc10024911d6c225645c22e87a7326c13c0116ac6 (diff)
downloademacs-203c503ff22e6c3c7b75d0e30d1974bb0ca9e60a.tar.gz
emacs-203c503ff22e6c3c7b75d0e30d1974bb0ca9e60a.zip
Minor fixes to menus on XI2
* src/xfns.c (Fx_create_frame): Populate `xi_masks'. * src/xmenu.c (x_activate_menubar) (create_and_show_popup_menu, x_menu_show): Only clear input extension grabs if we (or the toolkit) actually selected for XI_ButtonPress events. * src/xterm.c (xi_frame_selected_for): New function. (xi_populate_device_from_info, handle_one_xevent): Store device use instead of just whether or not it's a master device. (x_dnd_begin_drag_and_drop): Clean up block_input stuff. * src/xterm.h: Update prototypes. (struct xi_device_t): Rename `master_p' to `use'.
Diffstat (limited to 'src')
-rw-r--r--src/xfns.c7
-rw-r--r--src/xmenu.c19
-rw-r--r--src/xterm.c49
-rw-r--r--src/xterm.h9
4 files changed, 64 insertions, 20 deletions
diff --git a/src/xfns.c b/src/xfns.c
index 5cf3eb41996..195af1381b9 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -4845,6 +4845,13 @@ This function is an internal primitive--use `make-frame' instead. */)
4845 x_icon (f, parms); 4845 x_icon (f, parms);
4846 x_make_gc (f); 4846 x_make_gc (f);
4847 4847
4848#ifdef HAVE_XINPUT2
4849 if (dpyinfo->supports_xi2)
4850 FRAME_X_OUTPUT (f)->xi_masks
4851 = XIGetSelectedEvents (dpyinfo->display, FRAME_X_WINDOW (f),
4852 &FRAME_X_OUTPUT (f)->num_xi_masks);
4853#endif
4854
4848 /* Now consider the frame official. */ 4855 /* Now consider the frame official. */
4849 f->terminal->reference_count++; 4856 f->terminal->reference_count++;
4850 FRAME_DISPLAY_INFO (f)->reference_count++; 4857 FRAME_DISPLAY_INFO (f)->reference_count++;
diff --git a/src/xmenu.c b/src/xmenu.c
index d19fe13c295..94cd9dab69b 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -634,15 +634,15 @@ x_activate_menubar (struct frame *f)
634 Otherwise some versions of Motif will emit a warning and hang, 634 Otherwise some versions of Motif will emit a warning and hang,
635 and lwlib will fail to destroy the menu window. */ 635 and lwlib will fail to destroy the menu window. */
636 636
637 if (dpyinfo->num_devices) 637 if (dpyinfo->supports_xi2
638 && xi_frame_selected_for (f, XI_ButtonPress))
638 { 639 {
639 for (int i = 0; i < dpyinfo->num_devices; ++i) 640 for (int i = 0; i < dpyinfo->num_devices; ++i)
640 { 641 {
641 if (dpyinfo->devices[i].grab) 642 if (dpyinfo->devices[i].grab)
642 { 643 XIUngrabDevice (dpyinfo->display,
643 XIUngrabDevice (dpyinfo->display, dpyinfo->devices[i].device_id, 644 dpyinfo->devices[i].device_id,
644 CurrentTime); 645 CurrentTime);
645 }
646 } 646 }
647 } 647 }
648#endif 648#endif
@@ -1528,7 +1528,8 @@ create_and_show_popup_menu (struct frame *f, widget_value *first_wv,
1528 } 1528 }
1529 1529
1530#if !defined HAVE_GTK3 && defined HAVE_XINPUT2 1530#if !defined HAVE_GTK3 && defined HAVE_XINPUT2
1531 if (FRAME_DISPLAY_INFO (f)->num_devices) 1531 if (FRAME_DISPLAY_INFO (f)->supports_xi2
1532 && xi_frame_selected_for (f, XI_ButtonPress))
1532 { 1533 {
1533 for (int i = 0; i < FRAME_DISPLAY_INFO (f)->num_devices; ++i) 1534 for (int i = 0; i < FRAME_DISPLAY_INFO (f)->num_devices; ++i)
1534 { 1535 {
@@ -1696,7 +1697,8 @@ create_and_show_popup_menu (struct frame *f, widget_value *first_wv,
1696 if (dpyinfo->supports_xi2) 1697 if (dpyinfo->supports_xi2)
1697 XGrabServer (dpyinfo->display); 1698 XGrabServer (dpyinfo->display);
1698 1699
1699 if (dpyinfo->num_devices) 1700 if (dpyinfo->supports_xi2
1701 && xi_frame_selected_for (f, XI_ButtonPress))
1700 { 1702 {
1701 for (int i = 0; i < dpyinfo->num_devices; ++i) 1703 for (int i = 0; i < dpyinfo->num_devices; ++i)
1702 { 1704 {
@@ -2677,7 +2679,8 @@ x_menu_show (struct frame *f, int x, int y, int menuflags,
2677 struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); 2679 struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
2678 /* Clear the XI2 grab so a core grab can be set. */ 2680 /* Clear the XI2 grab so a core grab can be set. */
2679 2681
2680 if (dpyinfo->num_devices) 2682 if (dpyinfo->supports_xi2
2683 && xi_frame_selected_for (f, XI_ButtonPress))
2681 { 2684 {
2682 for (int i = 0; i < dpyinfo->num_devices; ++i) 2685 for (int i = 0; i < dpyinfo->num_devices; ++i)
2683 { 2686 {
diff --git a/src/xterm.c b/src/xterm.c
index 367659d3c1c..94f8ce33bb0 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -3704,6 +3704,29 @@ record_event (char *locus, int type)
3704 3704
3705#endif 3705#endif
3706 3706
3707#ifdef HAVE_XINPUT2
3708bool
3709xi_frame_selected_for (struct frame *f, unsigned long event)
3710{
3711 XIEventMask *masks;
3712 int i;
3713
3714 masks = FRAME_X_OUTPUT (f)->xi_masks;
3715
3716 if (!masks)
3717 return false;
3718
3719 for (i = 0; i < FRAME_X_OUTPUT (f)->num_xi_masks; ++i)
3720 {
3721 if (masks[i].mask_len >= XIMaskLen (event)
3722 && XIMaskIsSet (masks[i].mask, event))
3723 return true;
3724 }
3725
3726 return false;
3727}
3728#endif
3729
3707static void 3730static void
3708x_toolkit_position (struct frame *f, int x, int y, 3731x_toolkit_position (struct frame *f, int x, int y,
3709 bool *menu_bar_p, bool *tool_bar_p) 3732 bool *menu_bar_p, bool *tool_bar_p)
@@ -3886,8 +3909,7 @@ xi_populate_device_from_info (struct xi_device_t *xi_device,
3886 xi_device->touchpoints = NULL; 3909 xi_device->touchpoints = NULL;
3887#endif 3910#endif
3888 3911
3889 xi_device->master_p = (device->use == XIMasterKeyboard 3912 xi_device->use = device->use;
3890 || device->use == XIMasterPointer);
3891#ifdef HAVE_XINPUT2_2 3913#ifdef HAVE_XINPUT2_2
3892 xi_device->direct_p = false; 3914 xi_device->direct_p = false;
3893#endif 3915#endif
@@ -9559,7 +9581,6 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
9559 the root window, so we can get notified when window stacking 9581 the root window, so we can get notified when window stacking
9560 changes, a common operation during drag-and-drop. */ 9582 changes, a common operation during drag-and-drop. */
9561 9583
9562 block_input ();
9563 XGetWindowAttributes (FRAME_X_DISPLAY (f), 9584 XGetWindowAttributes (FRAME_X_DISPLAY (f),
9564 FRAME_DISPLAY_INFO (f)->root_window, 9585 FRAME_DISPLAY_INFO (f)->root_window,
9565 &root_window_attrs); 9586 &root_window_attrs);
@@ -9581,6 +9602,7 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
9581 current_hold_quit = &hold_quit; 9602 current_hold_quit = &hold_quit;
9582#endif 9603#endif
9583 9604
9605 block_input ();
9584#ifdef USE_GTK 9606#ifdef USE_GTK
9585 gtk_main_iteration (); 9607 gtk_main_iteration ();
9586#else 9608#else
@@ -9612,6 +9634,7 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
9612 &next_event, &finish, &hold_quit); 9634 &next_event, &finish, &hold_quit);
9613#endif 9635#endif
9614#endif 9636#endif
9637 unblock_input ();
9615 9638
9616 if (x_dnd_movement_frame) 9639 if (x_dnd_movement_frame)
9617 { 9640 {
@@ -9712,7 +9735,6 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
9712 XSelectInput (FRAME_X_DISPLAY (f), 9735 XSelectInput (FRAME_X_DISPLAY (f),
9713 FRAME_DISPLAY_INFO (f)->root_window, 9736 FRAME_DISPLAY_INFO (f)->root_window,
9714 root_window_attrs.your_event_mask); 9737 root_window_attrs.your_event_mask);
9715 unblock_input ();
9716 quit (); 9738 quit ();
9717 } 9739 }
9718 } 9740 }
@@ -9725,11 +9747,11 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
9725#endif 9747#endif
9726 x_dnd_movement_frame = NULL; 9748 x_dnd_movement_frame = NULL;
9727 9749
9750 block_input ();
9728 /* Restore the old event mask. */ 9751 /* Restore the old event mask. */
9729 XSelectInput (FRAME_X_DISPLAY (f), 9752 XSelectInput (FRAME_X_DISPLAY (f),
9730 FRAME_DISPLAY_INFO (f)->root_window, 9753 FRAME_DISPLAY_INFO (f)->root_window,
9731 root_window_attrs.your_event_mask); 9754 root_window_attrs.your_event_mask);
9732
9733 unblock_input (); 9755 unblock_input ();
9734 9756
9735 if (x_dnd_return_frame == 3 9757 if (x_dnd_return_frame == 3
@@ -18024,8 +18046,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
18024 if (info) 18046 if (info)
18025 { 18047 {
18026 if (device && info->enabled) 18048 if (device && info->enabled)
18027 device->master_p = (info->use == XIMasterKeyboard 18049 device->use = info->use;
18028 || info->use == XIMasterPointer);
18029 else if (device) 18050 else if (device)
18030 disabled[n_disabled++] = hev->info[i].deviceid; 18051 disabled[n_disabled++] = hev->info[i].deviceid;
18031 18052
@@ -21666,9 +21687,6 @@ x_free_frame_resources (struct frame *f)
21666#ifdef HAVE_X_I18N 21687#ifdef HAVE_X_I18N
21667 if (FRAME_XIC (f)) 21688 if (FRAME_XIC (f))
21668 free_frame_xic (f); 21689 free_frame_xic (f);
21669
21670 if (f->output_data.x->preedit_chars)
21671 xfree (f->output_data.x->preedit_chars);
21672#endif 21690#endif
21673 21691
21674#ifdef USE_CAIRO 21692#ifdef USE_CAIRO
@@ -21821,6 +21839,17 @@ x_destroy_window (struct frame *f)
21821 21839
21822 xfree (f->output_data.x->saved_menu_event); 21840 xfree (f->output_data.x->saved_menu_event);
21823 xfree (f->output_data.x); 21841 xfree (f->output_data.x);
21842
21843#ifdef HAVE_X_I18N
21844 if (f->output_data.x->preedit_chars)
21845 xfree (f->output_data.x->preedit_chars);
21846#endif
21847
21848#ifdef HAVE_XINPUT2
21849 if (f->output_data.x->xi_masks)
21850 XFree (f->output_data.x->xi_masks);
21851#endif
21852
21824 f->output_data.x = NULL; 21853 f->output_data.x = NULL;
21825 21854
21826 dpyinfo->reference_count--; 21855 dpyinfo->reference_count--;
diff --git a/src/xterm.h b/src/xterm.h
index 75094082683..defeaacc0d7 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -232,8 +232,7 @@ struct xi_device_t
232#ifdef HAVE_XINPUT2_1 232#ifdef HAVE_XINPUT2_1
233 int scroll_valuator_count; 233 int scroll_valuator_count;
234#endif 234#endif
235 int grab; 235 int grab, use;
236 bool master_p;
237#ifdef HAVE_XINPUT2_2 236#ifdef HAVE_XINPUT2_2
238 bool direct_p; 237 bool direct_p;
239#endif 238#endif
@@ -977,6 +976,11 @@ struct x_output
977 bool preedit_active; 976 bool preedit_active;
978 int preedit_caret; 977 int preedit_caret;
979#endif 978#endif
979
980#ifdef HAVE_XINPUT2
981 XIEventMask *xi_masks;
982 int num_xi_masks;
983#endif
980}; 984};
981 985
982enum 986enum
@@ -1571,6 +1575,7 @@ extern struct frame *x_dnd_frame;
1571 1575
1572#ifdef HAVE_XINPUT2 1576#ifdef HAVE_XINPUT2
1573struct xi_device_t *xi_device_from_id (struct x_display_info *, int); 1577struct xi_device_t *xi_device_from_id (struct x_display_info *, int);
1578bool xi_frame_selected_for (struct frame *, unsigned long);
1574#endif 1579#endif
1575 1580
1576extern void mark_xterm (void); 1581extern void mark_xterm (void);