]> git.eshelyaron.com Git - emacs.git/commitdiff
Intern virtual modifier atoms the smart way on X
authorPo Lu <luangruo@yahoo.com>
Tue, 18 Jan 2022 11:52:51 +0000 (19:52 +0800)
committerPo Lu <luangruo@yahoo.com>
Tue, 18 Jan 2022 11:54:22 +0000 (19:54 +0800)
* src/xterm.c (x_find_modifier_meanings): Get rid of calls to
XInternAtom.
(x_term_init): Initialize atom refs for virtual modifiers and
make sure to only call `x_find_modifier_meanings' after they
are interned.
* src/xterm.h (struct x_display_info): New fields for virtual
modifier atoms.

src/xterm.c
src/xterm.h

index 9bf4404c9cf5e2f78483c99e6dfe5e37ef23813a..54d10e01c305af299fb7d95237dd5e8ba8c7dae3 100644 (file)
@@ -5436,11 +5436,6 @@ x_find_modifier_meanings (struct x_display_info *dpyinfo)
   int syms_per_code;
   XModifierKeymap *mods;
 #ifdef HAVE_XKB
-  Atom meta;
-  Atom super;
-  Atom hyper;
-  Atom shiftlock;
-  Atom alt;
   int i;
   int found_meta_p = false;
 #endif
@@ -5454,28 +5449,22 @@ x_find_modifier_meanings (struct x_display_info *dpyinfo)
 #ifdef HAVE_XKB
   if (dpyinfo->xkb_desc)
     {
-      meta = XInternAtom (dpyinfo->display, "Meta", False);
-      super = XInternAtom (dpyinfo->display, "Super", False);
-      hyper = XInternAtom (dpyinfo->display, "Hyper", False);
-      shiftlock = XInternAtom (dpyinfo->display, "ShiftLock", False);
-      alt = XInternAtom (dpyinfo->display, "Alt", False);
-
       for (i = 0; i < XkbNumVirtualMods; i++)
        {
          uint vmodmask = dpyinfo->xkb_desc->server->vmods[i];
 
-         if (dpyinfo->xkb_desc->names->vmods[i] == meta)
+         if (dpyinfo->xkb_desc->names->vmods[i] == dpyinfo->Xatom_Meta)
            {
              dpyinfo->meta_mod_mask |= vmodmask;
              found_meta_p = vmodmask;
            }
-         else if (dpyinfo->xkb_desc->names->vmods[i] == alt)
+         else if (dpyinfo->xkb_desc->names->vmods[i] == dpyinfo->Xatom_Alt)
            dpyinfo->alt_mod_mask |= vmodmask;
-         else if (dpyinfo->xkb_desc->names->vmods[i] == super)
+         else if (dpyinfo->xkb_desc->names->vmods[i] == dpyinfo->Xatom_Super)
            dpyinfo->super_mod_mask |= vmodmask;
-         else if (dpyinfo->xkb_desc->names->vmods[i] == hyper)
+         else if (dpyinfo->xkb_desc->names->vmods[i] == dpyinfo->Xatom_Hyper)
            dpyinfo->hyper_mod_mask |= vmodmask;
-         else if (dpyinfo->xkb_desc->names->vmods[i] == shiftlock)
+         else if (dpyinfo->xkb_desc->names->vmods[i] == dpyinfo->Xatom_ShiftLock)
            dpyinfo->shift_lock_mask |= vmodmask;
        }
 
@@ -15337,9 +15326,6 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
                       XkbNewKeyboardNotifyMask | XkbMapNotifyMask,
                       XkbNewKeyboardNotifyMask | XkbMapNotifyMask);
     }
-
-  /* Figure out which modifier bits mean what.  */
-  x_find_modifier_meanings (dpyinfo);
 #endif
 
 #if defined USE_CAIRO || defined HAVE_XFT
@@ -15455,6 +15441,13 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
       ATOM_REFS_INIT ("_NET_WM_STATE_SKIP_TASKBAR", Xatom_net_wm_state_skip_taskbar)
       ATOM_REFS_INIT ("_NET_WM_STATE_ABOVE", Xatom_net_wm_state_above)
       ATOM_REFS_INIT ("_NET_WM_STATE_BELOW", Xatom_net_wm_state_below)
+#ifdef HAVE_XKB
+      ATOM_REFS_INIT ("Meta", Xatom_Meta)
+      ATOM_REFS_INIT ("Super", Xatom_Super)
+      ATOM_REFS_INIT ("Hyper", Xatom_Hyper)
+      ATOM_REFS_INIT ("ShiftLock", Xatom_ShiftLock)
+      ATOM_REFS_INIT ("Alt", Xatom_Alt)
+#endif
     };
 
     int i;
@@ -15485,6 +15478,11 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
     dpyinfo->Xatom_xsettings_sel = atoms_return[i];
   }
 
+#ifdef HAVE_XKB
+  /* Figure out which modifier bits mean what.  */
+  x_find_modifier_meanings (dpyinfo);
+#endif
+
   dpyinfo->x_dnd_atoms_size = 8;
   dpyinfo->x_dnd_atoms = xmalloc (sizeof *dpyinfo->x_dnd_atoms
                                   * dpyinfo->x_dnd_atoms_size);
index 664db48392d3d845f4b56b1f6148ef924e3892d9..696f9db3d0a7353c0437781b0b28946bccfda9f0 100644 (file)
@@ -496,6 +496,11 @@ struct x_display_info
   /* SM */
   Atom Xatom_SM_CLIENT_ID;
 
+#ifdef HAVE_XKB
+  /* Virtual modifiers */
+  Atom Xatom_Meta, Xatom_Super, Xatom_Hyper, Xatom_ShiftLock, Xatom_Alt;
+#endif
+
 #ifdef HAVE_XRANDR
   int xrandr_major_version;
   int xrandr_minor_version;