aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-04-13 10:54:56 +0800
committerPo Lu2022-04-13 10:54:56 +0800
commit1c1ae6ba802cc5813fa6f8f90f21050aae6bb459 (patch)
tree8d9f848a84aad3e9b2a887c21ef5c64b1008f4e2 /src
parentdb56a69274f7690eea2c8d8a12a9c367bb93c4d1 (diff)
downloademacs-1c1ae6ba802cc5813fa6f8f90f21050aae6bb459.tar.gz
emacs-1c1ae6ba802cc5813fa6f8f90f21050aae6bb459.zip
Clean up PGTK code more
* src/pgtkterm.c (STORE_KEYSYM_FOR_DEBUG): Delete macro. (x_find_modifier_meanings): Delete function. (get_modifier_values, pgtk_gtk_to_emacs_modifiers) (pgtk_emacs_to_gtk_modifiers): Use GDK's own modifier mask constants instead of detecting our own from the keymap. This does mean a specific "meta" key will no longer be detected on X Windows, but that interface doesn't exist on Wayland, and X users should use the X port anyway. (key_press_event): Avoid decoding input text. (pgtk_term_init): Stop computing modifiers. (syms_of_pgtkterm): Delete obsolete comment. * src/pgtkterm.h (struct pgtk_display_info): Delete modifier masks.
Diffstat (limited to 'src')
-rw-r--r--src/pgtkterm.c211
-rw-r--r--src/pgtkterm.h3
2 files changed, 30 insertions, 184 deletions
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index 8b60064c421..566fc1f03d1 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -68,11 +68,9 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
68#include <gdk/gdkwayland.h> 68#include <gdk/gdkwayland.h>
69#endif 69#endif
70 70
71#define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0) 71#define FRAME_CR_CONTEXT(f) ((f)->output_data.pgtk->cr_context)
72
73#define FRAME_CR_CONTEXT(f) ((f)->output_data.pgtk->cr_context)
74#define FRAME_CR_ACTIVE_CONTEXT(f) ((f)->output_data.pgtk->cr_active) 72#define FRAME_CR_ACTIVE_CONTEXT(f) ((f)->output_data.pgtk->cr_active)
75#define FRAME_CR_SURFACE(f) (cairo_get_target (FRAME_CR_CONTEXT (f))) 73#define FRAME_CR_SURFACE(f) (cairo_get_target (FRAME_CR_CONTEXT (f)))
76 74
77/* Non-zero means that a HELP_EVENT has been generated since Emacs 75/* Non-zero means that a HELP_EVENT has been generated since Emacs
78 start. */ 76 start. */
@@ -5161,88 +5159,8 @@ size_allocate (GtkWidget * widget, GtkAllocation * alloc,
5161} 5159}
5162 5160
5163static void 5161static void
5164x_find_modifier_meanings (struct pgtk_display_info *dpyinfo) 5162get_modifier_values (int *mod_ctrl, int *mod_meta, int *mod_alt,
5165{ 5163 int *mod_hyper, int *mod_super)
5166 GdkDisplay *gdpy = dpyinfo->gdpy;
5167 GdkKeymap *keymap = gdk_keymap_get_for_display (gdpy);
5168 GdkModifierType state = GDK_META_MASK;
5169 gboolean r = gdk_keymap_map_virtual_modifiers (keymap, &state);
5170 if (r)
5171 {
5172 /* Meta key exists. */
5173 if (state == GDK_META_MASK)
5174 {
5175 dpyinfo->meta_mod_mask = GDK_MOD1_MASK; /* maybe this is meta. */
5176 dpyinfo->alt_mod_mask = 0;
5177 }
5178 else
5179 {
5180 dpyinfo->meta_mod_mask = state & ~GDK_META_MASK;
5181 if (dpyinfo->meta_mod_mask == GDK_MOD1_MASK)
5182 dpyinfo->alt_mod_mask = 0;
5183 else
5184 dpyinfo->alt_mod_mask = GDK_MOD1_MASK;
5185 }
5186 }
5187 else
5188 {
5189 dpyinfo->meta_mod_mask = GDK_MOD1_MASK;
5190 dpyinfo->alt_mod_mask = 0;
5191 }
5192
5193 state = GDK_SUPER_MASK;
5194 r = gdk_keymap_map_virtual_modifiers (keymap, &state);
5195 if (r)
5196 {
5197 /* Super key exists. */
5198 if (state == GDK_SUPER_MASK)
5199 {
5200 dpyinfo->super_mod_mask = GDK_MOD4_MASK; /* maybe this is super. */
5201 }
5202 else
5203 {
5204 dpyinfo->super_mod_mask = state & ~GDK_SUPER_MASK;
5205 }
5206 }
5207 else
5208 {
5209 dpyinfo->super_mod_mask = GDK_MOD4_MASK;
5210 }
5211
5212 state = GDK_HYPER_MASK;
5213 r = gdk_keymap_map_virtual_modifiers (keymap, &state);
5214 if (r)
5215 {
5216 /* Hyper key exists. */
5217 if (state == GDK_HYPER_MASK)
5218 {
5219 dpyinfo->hyper_mod_mask = GDK_MOD3_MASK; /* maybe this is hyper. */
5220 }
5221 else
5222 {
5223 dpyinfo->hyper_mod_mask = state & ~GDK_HYPER_MASK;
5224 }
5225 }
5226 else
5227 {
5228 dpyinfo->hyper_mod_mask = GDK_MOD3_MASK;
5229 }
5230
5231 /* If xmodmap says:
5232 * $ xmodmap | grep mod4
5233 * mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
5234 * then, when mod4 is pressed, both of super and hyper are recognized ON.
5235 * Maybe many people have such configuration, and they don't like such behavior,
5236 * so I disable hyper if such configuration is detected.
5237 */
5238 if (dpyinfo->hyper_mod_mask == dpyinfo->super_mod_mask)
5239 dpyinfo->hyper_mod_mask = 0;
5240}
5241
5242static void
5243get_modifier_values (int *mod_ctrl,
5244 int *mod_meta,
5245 int *mod_alt, int *mod_hyper, int *mod_super)
5246{ 5164{
5247 Lisp_Object tem; 5165 Lisp_Object tem;
5248 5166
@@ -5287,14 +5205,13 @@ pgtk_gtk_to_emacs_modifiers (struct pgtk_display_info *dpyinfo, int state)
5287 mod |= shift_modifier; 5205 mod |= shift_modifier;
5288 if (state & GDK_CONTROL_MASK) 5206 if (state & GDK_CONTROL_MASK)
5289 mod |= mod_ctrl; 5207 mod |= mod_ctrl;
5290 if (state & dpyinfo->meta_mod_mask) 5208 if (state & GDK_META_MASK || state & GDK_MOD1_MASK)
5291 mod |= mod_meta; 5209 mod |= mod_meta;
5292 if (state & dpyinfo->alt_mod_mask) 5210 if (state & GDK_SUPER_MASK)
5293 mod |= mod_alt;
5294 if (state & dpyinfo->super_mod_mask)
5295 mod |= mod_super; 5211 mod |= mod_super;
5296 if (state & dpyinfo->hyper_mod_mask) 5212 if (state & GDK_HYPER_MASK)
5297 mod |= mod_hyper; 5213 mod |= mod_hyper;
5214
5298 return mod; 5215 return mod;
5299} 5216}
5300 5217
@@ -5312,18 +5229,16 @@ pgtk_emacs_to_gtk_modifiers (struct pgtk_display_info *dpyinfo, int state)
5312 &mod_super); 5229 &mod_super);
5313 5230
5314 mask = 0; 5231 mask = 0;
5315 if (state & mod_alt)
5316 mask |= dpyinfo->alt_mod_mask;
5317 if (state & mod_super) 5232 if (state & mod_super)
5318 mask |= dpyinfo->super_mod_mask; 5233 mask |= GDK_SUPER_MASK;
5319 if (state & mod_hyper) 5234 if (state & mod_hyper)
5320 mask |= dpyinfo->hyper_mod_mask; 5235 mask |= GDK_HYPER_MASK;
5321 if (state & shift_modifier) 5236 if (state & shift_modifier)
5322 mask |= GDK_SHIFT_MASK; 5237 mask |= GDK_SHIFT_MASK;
5323 if (state & mod_ctrl) 5238 if (state & mod_ctrl)
5324 mask |= GDK_CONTROL_MASK; 5239 mask |= GDK_CONTROL_MASK;
5325 if (state & mod_meta) 5240 if (state & mod_meta)
5326 mask |= dpyinfo->meta_mod_mask; 5241 mask |= GDK_MOD1_MASK;
5327 return mask; 5242 return mask;
5328} 5243}
5329 5244
@@ -5382,16 +5297,13 @@ pgtk_enqueue_preedit (struct frame *f, Lisp_Object preedit)
5382static gboolean 5297static gboolean
5383key_press_event (GtkWidget *widget, GdkEvent *event, gpointer *user_data) 5298key_press_event (GtkWidget *widget, GdkEvent *event, gpointer *user_data)
5384{ 5299{
5385 struct coding_system coding;
5386 union buffered_input_event inev; 5300 union buffered_input_event inev;
5387 ptrdiff_t nbytes = 0; 5301 ptrdiff_t nbytes = 0;
5388 Mouse_HLInfo *hlinfo; 5302 Mouse_HLInfo *hlinfo;
5303 struct frame *f;
5389 5304
5390 USE_SAFE_ALLOCA; 5305 f = pgtk_any_window_to_frame (gtk_widget_get_window (widget));
5391
5392 EVENT_INIT (inev.ie); 5306 EVENT_INIT (inev.ie);
5393
5394 struct frame *f = pgtk_any_window_to_frame (gtk_widget_get_window (widget));
5395 hlinfo = MOUSE_HL_INFO (f); 5307 hlinfo = MOUSE_HL_INFO (f);
5396 5308
5397 /* If mouse-highlight is an integer, input clears out 5309 /* If mouse-highlight is an integer, input clears out
@@ -5404,20 +5316,6 @@ key_press_event (GtkWidget *widget, GdkEvent *event, gpointer *user_data)
5404 5316
5405 if (f != 0) 5317 if (f != 0)
5406 { 5318 {
5407 /* While super is pressed, gtk_im_context_filter_keypress() always process the
5408 * key events ignoring super.
5409 * As a work around, don't call it while super or hyper are pressed...
5410 */
5411 struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
5412 if (!(event->key.state & (dpyinfo->super_mod_mask | dpyinfo->hyper_mod_mask)))
5413 {
5414 if (pgtk_im_filter_keypress (f, &event->key))
5415 return TRUE;
5416 }
5417 }
5418
5419 if (f != 0)
5420 {
5421 guint keysym, orig_keysym; 5319 guint keysym, orig_keysym;
5422 /* al%imercury@uunet.uu.net says that making this 81 5320 /* al%imercury@uunet.uu.net says that making this 81
5423 instead of 80 fixed a bug whereby meta chars made 5321 instead of 80 fixed a bug whereby meta chars made
@@ -5434,9 +5332,19 @@ key_press_event (GtkWidget *widget, GdkEvent *event, gpointer *user_data)
5434 unsigned char *copy_bufptr = copy_buffer; 5332 unsigned char *copy_bufptr = copy_buffer;
5435 int copy_bufsiz = sizeof (copy_buffer); 5333 int copy_bufsiz = sizeof (copy_buffer);
5436 int modifiers; 5334 int modifiers;
5437 Lisp_Object coding_system = Qlatin_1;
5438 Lisp_Object c; 5335 Lisp_Object c;
5439 guint state = event->key.state; 5336 guint state;
5337
5338 state = event->key.state;
5339
5340 /* While super is pressed, the input method will always always
5341 resend the key events ignoring super. As a workaround, don't
5342 filter key events with super or hyper pressed. */
5343 if (!(event->key.state & (GDK_SUPER_MASK | GDK_HYPER_MASK)))
5344 {
5345 if (pgtk_im_filter_keypress (f, &event->key))
5346 return TRUE;
5347 }
5440 5348
5441 state |= 5349 state |=
5442 pgtk_emacs_to_gtk_modifiers (FRAME_DISPLAY_INFO (f), 5350 pgtk_emacs_to_gtk_modifiers (FRAME_DISPLAY_INFO (f),
@@ -5582,7 +5490,6 @@ key_press_event (GtkWidget *widget, GdkEvent *event, gpointer *user_data)
5582#endif 5490#endif
5583 )) 5491 ))
5584 { 5492 {
5585 STORE_KEYSYM_FOR_DEBUG (keysym);
5586 /* make_lispy_event will convert this to a symbolic 5493 /* make_lispy_event will convert this to a symbolic
5587 key. */ 5494 key. */
5588 inev.ie.kind = NON_ASCII_KEYSTROKE_EVENT; 5495 inev.ie.kind = NON_ASCII_KEYSTROKE_EVENT;
@@ -5593,62 +5500,11 @@ key_press_event (GtkWidget *widget, GdkEvent *event, gpointer *user_data)
5593 goto done; 5500 goto done;
5594 } 5501 }
5595 5502
5596 { /* Raw bytes, not keysym. */ 5503 {
5597 ptrdiff_t i; 5504 inev.ie.kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
5598 int nchars, len; 5505 inev.ie.arg = make_unibyte_string ((char *) copy_bufptr, nbytes);
5599 5506 inev.ie.device
5600 for (i = 0, nchars = 0; i < nbytes; i++) 5507 = pgtk_get_device_for_event (FRAME_DISPLAY_INFO (f), event);
5601 {
5602 if (ASCII_CHAR_P (copy_bufptr[i]))
5603 nchars++;
5604 STORE_KEYSYM_FOR_DEBUG (copy_bufptr[i]);
5605 }
5606
5607 if (nchars < nbytes)
5608 {
5609 /* Decode the input data. */
5610
5611 /* The input should be decoded with locale `coding_system'. */
5612 if (!NILP (Vlocale_coding_system))
5613 coding_system = Vlocale_coding_system;
5614 setup_coding_system (coding_system, &coding);
5615 coding.src_multibyte = false;
5616 coding.dst_multibyte = true;
5617 /* The input is converted to events, thus we can't
5618 handle composition. Anyway, there's no XIM that
5619 gives us composition information. */
5620 coding.common_flags &= ~CODING_ANNOTATION_MASK;
5621
5622 SAFE_NALLOCA (coding.destination, MAX_MULTIBYTE_LENGTH, nbytes);
5623 coding.dst_bytes = MAX_MULTIBYTE_LENGTH * nbytes;
5624 coding.mode |= CODING_MODE_LAST_BLOCK;
5625 decode_coding_c_string (&coding, copy_bufptr, nbytes, Qnil);
5626 nbytes = coding.produced;
5627 nchars = coding.produced_char;
5628 copy_bufptr = coding.destination;
5629 }
5630
5631 /* Convert the input data to a sequence of
5632 character events. */
5633 for (i = 0; i < nbytes; i += len)
5634 {
5635 int ch;
5636 if (nchars == nbytes)
5637 ch = copy_bufptr[i], len = 1;
5638 else
5639 ch = string_char_and_length (copy_bufptr + i, &len);
5640 inev.ie.kind = (SINGLE_BYTE_CHAR_P (ch)
5641 ? ASCII_KEYSTROKE_EVENT
5642 : MULTIBYTE_CHAR_KEYSTROKE_EVENT);
5643 inev.ie.code = ch;
5644 inev.ie.device
5645 = pgtk_get_device_for_event (FRAME_DISPLAY_INFO (f), event);
5646 evq_enqueue (&inev);
5647 }
5648
5649 /* count += nchars; */
5650
5651 inev.ie.kind = NO_EVENT; /* Already stored above. */
5652 5508
5653 if (keysym == GDK_KEY_VoidSymbol) 5509 if (keysym == GDK_KEY_VoidSymbol)
5654 goto done; 5510 goto done;
@@ -5660,11 +5516,8 @@ done:
5660 { 5516 {
5661 XSETFRAME (inev.ie.frame_or_window, f); 5517 XSETFRAME (inev.ie.frame_or_window, f);
5662 evq_enqueue (&inev); 5518 evq_enqueue (&inev);
5663 /* count++; */
5664 } 5519 }
5665 5520
5666 SAFE_FREE ();
5667
5668 return TRUE; 5521 return TRUE;
5669} 5522}
5670 5523
@@ -6793,9 +6646,6 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name)
6793 *nametail++ = '@'; 6646 *nametail++ = '@';
6794 lispstpcpy (nametail, system_name); 6647 lispstpcpy (nametail, system_name);
6795 6648
6796 /* Figure out which modifier bits mean what. */
6797 x_find_modifier_meanings (dpyinfo);
6798
6799 /* Get the scroll bar cursor. */ 6649 /* Get the scroll bar cursor. */
6800 /* We must create a GTK cursor, it is required for GTK widgets. */ 6650 /* We must create a GTK cursor, it is required for GTK widgets. */
6801 dpyinfo->xg_cursor = xg_create_default_cursor (dpyinfo->gdpy); 6651 dpyinfo->xg_cursor = xg_create_default_cursor (dpyinfo->gdpy);
@@ -7044,7 +6894,6 @@ pgtk_clear_area (struct frame *f, int x, int y, int width, int height)
7044void 6894void
7045syms_of_pgtkterm (void) 6895syms_of_pgtkterm (void)
7046{ 6896{
7047 /* from 23+ we need to tell emacs what modifiers there are.. */
7048 DEFSYM (Qmodifier_value, "modifier-value"); 6897 DEFSYM (Qmodifier_value, "modifier-value");
7049 DEFSYM (Qalt, "alt"); 6898 DEFSYM (Qalt, "alt");
7050 DEFSYM (Qhyper, "hyper"); 6899 DEFSYM (Qhyper, "hyper");
diff --git a/src/pgtkterm.h b/src/pgtkterm.h
index 56c5d22e54e..321c923db53 100644
--- a/src/pgtkterm.h
+++ b/src/pgtkterm.h
@@ -225,9 +225,6 @@ struct pgtk_display_info
225 /* The frame where the mouse was last time we reported a mouse position. */ 225 /* The frame where the mouse was last time we reported a mouse position. */
226 struct frame *last_mouse_glyph_frame; 226 struct frame *last_mouse_glyph_frame;
227 227
228 /* Modifier masks in gdk */
229 int meta_mod_mask, alt_mod_mask, super_mod_mask, hyper_mod_mask;
230
231 /* The last click event. */ 228 /* The last click event. */
232 GdkEvent *last_click_event; 229 GdkEvent *last_click_event;
233 230