2010-07-12 12:11:30 -04:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corp.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Emmanuele Bassi <ebassi@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
#include "config.h"
|
2010-07-12 12:11:30 -04:00
|
|
|
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/XKBlib.h>
|
|
|
|
|
2020-11-26 17:10:25 -05:00
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "backends/meta-input-settings-private.h"
|
2019-03-22 08:53:00 -04:00
|
|
|
#include "backends/x11/meta-keymap-x11.h"
|
|
|
|
#include "clutter/clutter.h"
|
|
|
|
#include "clutter/clutter-mutter.h"
|
|
|
|
#include "clutter/x11/clutter-x11.h"
|
|
|
|
|
2014-03-03 18:23:12 -05:00
|
|
|
typedef struct _DirectionCacheEntry DirectionCacheEntry;
|
2018-06-29 08:31:23 -04:00
|
|
|
typedef struct _ClutterKeymapKey ClutterKeymapKey;
|
|
|
|
|
|
|
|
struct _ClutterKeymapKey
|
|
|
|
{
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t keycode;
|
|
|
|
uint32_t group;
|
|
|
|
uint32_t level;
|
2018-06-29 08:31:23 -04:00
|
|
|
};
|
2014-03-03 18:23:12 -05:00
|
|
|
|
|
|
|
struct _DirectionCacheEntry
|
|
|
|
{
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t serial;
|
2014-03-03 18:23:12 -05:00
|
|
|
Atom group_atom;
|
|
|
|
PangoDirection direction;
|
|
|
|
};
|
2010-07-12 12:11:30 -04:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
struct _MetaKeymapX11
|
2010-07-12 12:11:30 -04:00
|
|
|
{
|
2019-01-10 06:34:28 -05:00
|
|
|
ClutterKeymap parent_instance;
|
2010-07-12 12:11:30 -04:00
|
|
|
|
|
|
|
ClutterBackend *backend;
|
2010-07-12 13:04:03 -04:00
|
|
|
|
2012-03-07 07:07:15 -05:00
|
|
|
int min_keycode;
|
|
|
|
int max_keycode;
|
2010-07-12 13:04:03 -04:00
|
|
|
|
|
|
|
ClutterModifierType modmap[8];
|
|
|
|
|
|
|
|
ClutterModifierType num_lock_mask;
|
2012-12-22 22:21:16 -05:00
|
|
|
ClutterModifierType scroll_lock_mask;
|
2018-06-29 08:31:23 -04:00
|
|
|
ClutterModifierType level3_shift_mask;
|
2010-07-12 13:04:03 -04:00
|
|
|
|
2014-03-03 18:23:12 -05:00
|
|
|
PangoDirection current_direction;
|
|
|
|
|
2010-07-12 13:04:03 -04:00
|
|
|
XkbDescPtr xkb_desc;
|
2011-02-08 07:08:18 -05:00
|
|
|
int xkb_event_base;
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t xkb_map_serial;
|
2014-03-03 18:23:12 -05:00
|
|
|
Atom current_group_atom;
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t current_cache_serial;
|
2014-03-03 18:23:12 -05:00
|
|
|
DirectionCacheEntry group_direction_cache[4];
|
2018-06-29 08:31:23 -04:00
|
|
|
int current_group;
|
2010-07-13 04:15:21 -04:00
|
|
|
|
2018-07-13 08:49:38 -04:00
|
|
|
GHashTable *reserved_keycodes;
|
|
|
|
GQueue *available_keycodes;
|
|
|
|
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t keymap_serial;
|
2019-03-26 09:53:11 -04:00
|
|
|
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t caps_lock_state : 1;
|
|
|
|
uint32_t num_lock_state : 1;
|
|
|
|
uint32_t has_direction : 1;
|
2019-03-26 09:53:11 -04:00
|
|
|
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t use_xkb : 1;
|
|
|
|
uint32_t have_xkb_autorepeat : 1;
|
2010-07-12 12:11:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
2010-06-21 05:20:32 -04:00
|
|
|
PROP_BACKEND,
|
|
|
|
|
|
|
|
PROP_LAST
|
2010-07-12 12:11:30 -04:00
|
|
|
};
|
|
|
|
|
2011-02-08 07:08:18 -05:00
|
|
|
static GParamSpec *obj_props[PROP_LAST] = { NULL, };
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
G_DEFINE_TYPE (MetaKeymapX11, meta_keymap_x11, CLUTTER_TYPE_KEYMAP)
|
2010-07-12 12:11:30 -04:00
|
|
|
|
2010-07-12 13:04:03 -04:00
|
|
|
/* code adapted from gdk/x11/gdkkeys-x11.c - update_modmap */
|
|
|
|
static void
|
2019-03-22 08:53:00 -04:00
|
|
|
update_modmap (Display *display,
|
|
|
|
MetaKeymapX11 *keymap_x11)
|
2010-07-12 13:04:03 -04:00
|
|
|
{
|
|
|
|
static struct {
|
2019-03-29 16:14:46 -04:00
|
|
|
const char *name;
|
2010-07-12 13:04:03 -04:00
|
|
|
Atom atom;
|
|
|
|
ClutterModifierType mask;
|
|
|
|
} vmods[] = {
|
|
|
|
{ "Meta", 0, CLUTTER_META_MASK },
|
|
|
|
{ "Super", 0, CLUTTER_SUPER_MASK },
|
|
|
|
{ "Hyper", 0, CLUTTER_HYPER_MASK },
|
|
|
|
{ NULL, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
if (vmods[0].atom == 0)
|
|
|
|
for (i = 0; vmods[i].name; i++)
|
|
|
|
vmods[i].atom = XInternAtom (display, vmods[i].name, FALSE);
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
keymap_x11->modmap[i] = 1 << i;
|
|
|
|
|
|
|
|
for (i = 0; i < XkbNumVirtualMods; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; vmods[j].atom; j++)
|
|
|
|
{
|
|
|
|
if (keymap_x11->xkb_desc->names->vmods[i] == vmods[j].atom)
|
|
|
|
{
|
|
|
|
for (k = 0; k < 8; k++)
|
|
|
|
{
|
|
|
|
if (keymap_x11->xkb_desc->server->vmods[i] & (1 << k))
|
|
|
|
keymap_x11->modmap[k] |= vmods[j].mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static XkbDescPtr
|
2019-03-22 08:53:00 -04:00
|
|
|
get_xkb (MetaKeymapX11 *keymap_x11)
|
2010-07-12 13:04:03 -04:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
Display *xdisplay = clutter_x11_get_default_display ();
|
2010-07-12 13:04:03 -04:00
|
|
|
|
|
|
|
if (keymap_x11->max_keycode == 0)
|
2019-03-22 08:53:00 -04:00
|
|
|
XDisplayKeycodes (xdisplay,
|
2010-07-12 13:04:03 -04:00
|
|
|
&keymap_x11->min_keycode,
|
|
|
|
&keymap_x11->max_keycode);
|
|
|
|
|
|
|
|
if (keymap_x11->xkb_desc == NULL)
|
|
|
|
{
|
|
|
|
int flags = XkbKeySymsMask
|
|
|
|
| XkbKeyTypesMask
|
|
|
|
| XkbModifierMapMask
|
|
|
|
| XkbVirtualModsMask;
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
keymap_x11->xkb_desc = XkbGetMap (xdisplay, flags, XkbUseCoreKbd);
|
2010-07-12 13:04:03 -04:00
|
|
|
if (G_UNLIKELY (keymap_x11->xkb_desc == NULL))
|
|
|
|
{
|
|
|
|
g_error ("Failed to get the keymap from XKB");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = XkbGroupNamesMask | XkbVirtualModNamesMask;
|
2019-03-22 08:53:00 -04:00
|
|
|
XkbGetNames (xdisplay, flags, keymap_x11->xkb_desc);
|
2010-07-12 13:04:03 -04:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
update_modmap (xdisplay, keymap_x11);
|
2010-07-12 13:04:03 -04:00
|
|
|
}
|
2019-03-26 09:53:11 -04:00
|
|
|
else if (keymap_x11->xkb_map_serial != keymap_x11->keymap_serial)
|
2011-02-08 07:08:18 -05:00
|
|
|
{
|
|
|
|
int flags = XkbKeySymsMask
|
|
|
|
| XkbKeyTypesMask
|
|
|
|
| XkbModifierMapMask
|
|
|
|
| XkbVirtualModsMask;
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
XkbGetUpdatedMap (xdisplay, flags, keymap_x11->xkb_desc);
|
2011-02-08 07:08:18 -05:00
|
|
|
|
|
|
|
flags = XkbGroupNamesMask | XkbVirtualModNamesMask;
|
2019-03-22 08:53:00 -04:00
|
|
|
XkbGetNames (xdisplay, flags, keymap_x11->xkb_desc);
|
2011-02-08 07:08:18 -05:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
update_modmap (xdisplay, keymap_x11);
|
2011-02-08 07:08:18 -05:00
|
|
|
|
2019-03-26 09:53:11 -04:00
|
|
|
keymap_x11->xkb_map_serial = keymap_x11->keymap_serial;
|
2011-02-08 07:08:18 -05:00
|
|
|
}
|
2010-07-12 13:04:03 -04:00
|
|
|
|
|
|
|
if (keymap_x11->num_lock_mask == 0)
|
2019-03-22 08:53:00 -04:00
|
|
|
keymap_x11->num_lock_mask = XkbKeysymToModifiers (xdisplay, XK_Num_Lock);
|
2010-07-12 13:04:03 -04:00
|
|
|
|
2012-12-22 22:21:16 -05:00
|
|
|
if (keymap_x11->scroll_lock_mask == 0)
|
2019-03-22 08:53:00 -04:00
|
|
|
keymap_x11->scroll_lock_mask = XkbKeysymToModifiers (xdisplay,
|
2012-12-22 22:21:16 -05:00
|
|
|
XK_Scroll_Lock);
|
2018-06-29 08:31:23 -04:00
|
|
|
if (keymap_x11->level3_shift_mask == 0)
|
2019-03-22 08:53:00 -04:00
|
|
|
keymap_x11->level3_shift_mask = XkbKeysymToModifiers (xdisplay,
|
2018-06-29 08:31:23 -04:00
|
|
|
XK_ISO_Level3_Shift);
|
2012-12-22 22:21:16 -05:00
|
|
|
|
2010-07-12 13:04:03 -04:00
|
|
|
return keymap_x11->xkb_desc;
|
|
|
|
}
|
|
|
|
|
2010-07-13 04:15:21 -04:00
|
|
|
static void
|
2019-03-22 08:53:00 -04:00
|
|
|
update_locked_mods (MetaKeymapX11 *keymap_x11,
|
2019-03-29 16:14:46 -04:00
|
|
|
int locked_mods)
|
2010-07-13 04:15:21 -04:00
|
|
|
{
|
|
|
|
gboolean old_caps_lock_state, old_num_lock_state;
|
|
|
|
|
|
|
|
old_caps_lock_state = keymap_x11->caps_lock_state;
|
|
|
|
old_num_lock_state = keymap_x11->num_lock_state;
|
|
|
|
|
|
|
|
keymap_x11->caps_lock_state = (locked_mods & CLUTTER_LOCK_MASK) != 0;
|
|
|
|
keymap_x11->num_lock_state = (locked_mods & keymap_x11->num_lock_mask) != 0;
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
g_debug ("Locks state changed - Num: %s, Caps: %s",
|
|
|
|
keymap_x11->num_lock_state ? "set" : "unset",
|
|
|
|
keymap_x11->caps_lock_state ? "set" : "unset");
|
2010-07-13 06:54:44 -04:00
|
|
|
|
2010-07-13 04:15:21 -04:00
|
|
|
if ((keymap_x11->caps_lock_state != old_caps_lock_state) ||
|
|
|
|
(keymap_x11->num_lock_state != old_num_lock_state))
|
2019-01-10 06:34:28 -05:00
|
|
|
g_signal_emit_by_name (keymap_x11, "state-changed");
|
2020-11-26 17:10:25 -05:00
|
|
|
|
|
|
|
if (keymap_x11->num_lock_state != old_num_lock_state)
|
|
|
|
{
|
|
|
|
MetaBackend *backend;
|
|
|
|
MetaInputSettings *input_settings;
|
|
|
|
|
|
|
|
backend = meta_get_backend ();
|
|
|
|
input_settings = meta_backend_get_input_settings (backend);
|
|
|
|
|
|
|
|
if (input_settings)
|
|
|
|
{
|
|
|
|
meta_input_settings_maybe_save_numlock_state (input_settings,
|
|
|
|
keymap_x11->num_lock_state);
|
|
|
|
}
|
|
|
|
}
|
2010-07-13 04:15:21 -04:00
|
|
|
}
|
|
|
|
|
2014-03-03 18:23:12 -05:00
|
|
|
/* the code to retrieve the keymap direction and cache it
|
|
|
|
* is taken from GDK:
|
|
|
|
* gdk/x11/gdkkeys-x11.c
|
|
|
|
*/
|
|
|
|
static PangoDirection
|
|
|
|
get_direction (XkbDescPtr xkb,
|
|
|
|
int group)
|
|
|
|
{
|
|
|
|
int rtl_minus_ltr = 0; /* total number of RTL keysyms minus LTR ones */
|
|
|
|
int code;
|
|
|
|
|
|
|
|
for (code = xkb->min_key_code;
|
|
|
|
code <= xkb->max_key_code;
|
|
|
|
code += 1)
|
|
|
|
{
|
|
|
|
int level = 0;
|
|
|
|
KeySym sym = XkbKeySymEntry (xkb, code, level, group);
|
2019-05-17 19:11:43 -04:00
|
|
|
PangoDirection dir =
|
|
|
|
_clutter_pango_unichar_direction (clutter_keysym_to_unicode (sym));
|
2014-03-03 18:23:12 -05:00
|
|
|
|
|
|
|
switch (dir)
|
|
|
|
{
|
|
|
|
case PANGO_DIRECTION_RTL:
|
|
|
|
rtl_minus_ltr++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PANGO_DIRECTION_LTR:
|
|
|
|
rtl_minus_ltr--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rtl_minus_ltr > 0)
|
|
|
|
return PANGO_DIRECTION_RTL;
|
|
|
|
|
|
|
|
return PANGO_DIRECTION_LTR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PangoDirection
|
2019-03-22 08:53:00 -04:00
|
|
|
get_direction_from_cache (MetaKeymapX11 *keymap_x11,
|
|
|
|
XkbDescPtr xkb,
|
|
|
|
int group)
|
2014-03-03 18:23:12 -05:00
|
|
|
{
|
|
|
|
Atom group_atom = xkb->names->groups[group];
|
|
|
|
gboolean cache_hit = FALSE;
|
|
|
|
DirectionCacheEntry *cache = keymap_x11->group_direction_cache;
|
|
|
|
PangoDirection direction = PANGO_DIRECTION_NEUTRAL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (keymap_x11->has_direction)
|
|
|
|
{
|
|
|
|
/* look up in the cache */
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (keymap_x11->group_direction_cache); i++)
|
|
|
|
{
|
|
|
|
if (cache[i].group_atom == group_atom)
|
|
|
|
{
|
|
|
|
cache_hit = TRUE;
|
|
|
|
cache[i].serial = keymap_x11->current_cache_serial++;
|
|
|
|
direction = cache[i].direction;
|
|
|
|
group_atom = cache[i].group_atom;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* initialize the cache */
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (keymap_x11->group_direction_cache); i++)
|
|
|
|
{
|
|
|
|
cache[i].group_atom = 0;
|
|
|
|
cache[i].direction = PANGO_DIRECTION_NEUTRAL;
|
|
|
|
cache[i].serial = keymap_x11->current_cache_serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
keymap_x11->current_cache_serial += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* insert the new entry in the cache */
|
|
|
|
if (!cache_hit)
|
|
|
|
{
|
|
|
|
int oldest = 0;
|
|
|
|
|
|
|
|
direction = get_direction (xkb, group);
|
|
|
|
|
|
|
|
/* replace the oldest entry */
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (keymap_x11->group_direction_cache); i++)
|
|
|
|
{
|
|
|
|
if (cache[i].serial < cache[oldest].serial)
|
|
|
|
oldest = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
cache[oldest].group_atom = group_atom;
|
|
|
|
cache[oldest].direction = direction;
|
|
|
|
cache[oldest].serial = keymap_x11->current_cache_serial++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-22 08:53:00 -04:00
|
|
|
update_direction (MetaKeymapX11 *keymap_x11,
|
|
|
|
int group)
|
2014-03-03 18:23:12 -05:00
|
|
|
{
|
|
|
|
XkbDescPtr xkb = get_xkb (keymap_x11);
|
|
|
|
Atom group_atom;
|
|
|
|
|
|
|
|
group_atom = xkb->names->groups[group];
|
|
|
|
|
|
|
|
if (!keymap_x11->has_direction || keymap_x11->current_group_atom != group_atom)
|
|
|
|
{
|
|
|
|
keymap_x11->current_direction = get_direction_from_cache (keymap_x11, xkb, group);
|
|
|
|
keymap_x11->current_group_atom = group_atom;
|
|
|
|
keymap_x11->has_direction = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-12 13:04:03 -04:00
|
|
|
static void
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_constructed (GObject *object)
|
2010-07-12 13:04:03 -04:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
MetaKeymapX11 *keymap_x11 = META_KEYMAP_X11 (object);
|
|
|
|
Display *xdisplay = clutter_x11_get_default_display ();
|
2019-03-29 16:14:46 -04:00
|
|
|
int xkb_major = XkbMajorVersion;
|
|
|
|
int xkb_minor = XkbMinorVersion;
|
2010-07-12 13:04:03 -04:00
|
|
|
|
|
|
|
g_assert (keymap_x11->backend != NULL);
|
|
|
|
|
2018-05-24 11:34:48 -04:00
|
|
|
if (XkbLibraryVersion (&xkb_major, &xkb_minor))
|
|
|
|
{
|
|
|
|
xkb_major = XkbMajorVersion;
|
|
|
|
xkb_minor = XkbMinorVersion;
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
if (XkbQueryExtension (xdisplay,
|
2018-05-24 11:34:48 -04:00
|
|
|
NULL,
|
|
|
|
&keymap_x11->xkb_event_base,
|
|
|
|
NULL,
|
|
|
|
&xkb_major, &xkb_minor))
|
|
|
|
{
|
|
|
|
Bool detectable_autorepeat_supported;
|
|
|
|
|
2019-03-26 09:53:11 -04:00
|
|
|
keymap_x11->use_xkb = TRUE;
|
2018-05-24 11:34:48 -04:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
XkbSelectEvents (xdisplay,
|
2018-05-24 11:34:48 -04:00
|
|
|
XkbUseCoreKbd,
|
|
|
|
XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
|
|
|
|
XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
XkbSelectEventDetails (xdisplay,
|
2018-05-24 11:34:48 -04:00
|
|
|
XkbUseCoreKbd, XkbStateNotify,
|
|
|
|
XkbAllStateComponentsMask,
|
|
|
|
XkbGroupLockMask | XkbModifierLockMask);
|
|
|
|
|
|
|
|
/* enable XKB autorepeat */
|
2019-03-22 08:53:00 -04:00
|
|
|
XkbSetDetectableAutoRepeat (xdisplay,
|
2018-05-24 11:34:48 -04:00
|
|
|
True,
|
|
|
|
&detectable_autorepeat_supported);
|
|
|
|
|
2019-03-26 09:53:11 -04:00
|
|
|
keymap_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
|
2018-05-24 11:34:48 -04:00
|
|
|
}
|
|
|
|
}
|
2010-07-12 13:04:03 -04:00
|
|
|
}
|
|
|
|
|
2010-07-12 12:11:30 -04:00
|
|
|
static void
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-07-12 12:11:30 -04:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
MetaKeymapX11 *keymap = META_KEYMAP_X11 (object);
|
2010-07-12 12:11:30 -04:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_BACKEND:
|
|
|
|
keymap->backend = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-03-22 08:53:00 -04:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2010-07-12 12:11:30 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-13 08:49:38 -04:00
|
|
|
static void
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_refresh_reserved_keycodes (MetaKeymapX11 *keymap_x11)
|
2018-07-13 08:49:38 -04:00
|
|
|
{
|
|
|
|
Display *dpy = clutter_x11_get_default_display ();
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, keymap_x11->reserved_keycodes);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t reserved_keycode = GPOINTER_TO_UINT (key);
|
|
|
|
uint32_t reserved_keysym = GPOINTER_TO_UINT (value);
|
|
|
|
uint32_t actual_keysym = XkbKeycodeToKeysym (dpy, reserved_keycode, 0, 0);
|
2018-07-13 08:49:38 -04:00
|
|
|
|
|
|
|
/* If an available keycode is no longer mapped to the stored keysym, then
|
|
|
|
* the keycode should not be considered available anymore and should be
|
|
|
|
* removed both from the list of available and reserved keycodes.
|
|
|
|
*/
|
|
|
|
if (reserved_keysym != actual_keysym)
|
|
|
|
{
|
|
|
|
g_hash_table_iter_remove (&iter);
|
|
|
|
g_queue_remove (keymap_x11->available_keycodes, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_replace_keycode (MetaKeymapX11 *keymap_x11,
|
|
|
|
KeyCode keycode,
|
|
|
|
KeySym keysym)
|
2018-07-13 08:49:38 -04:00
|
|
|
{
|
2019-03-26 09:53:11 -04:00
|
|
|
if (keymap_x11->use_xkb)
|
2018-07-13 08:49:38 -04:00
|
|
|
{
|
|
|
|
Display *dpy = clutter_x11_get_default_display ();
|
|
|
|
XkbDescPtr xkb = get_xkb (keymap_x11);
|
|
|
|
XkbMapChangesRec changes;
|
|
|
|
|
|
|
|
XFlush (dpy);
|
|
|
|
|
|
|
|
xkb->device_spec = XkbUseCoreKbd;
|
|
|
|
memset (&changes, 0, sizeof(changes));
|
|
|
|
|
|
|
|
if (keysym != NoSymbol)
|
|
|
|
{
|
|
|
|
int types[XkbNumKbdGroups] = { XkbOneLevelIndex };
|
|
|
|
XkbChangeTypesOfKey (xkb, keycode, 1, XkbGroup1Mask, types, &changes);
|
|
|
|
XkbKeySymEntry (xkb, keycode, 0, 0) = keysym;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Reset to NoSymbol */
|
|
|
|
XkbChangeTypesOfKey (xkb, keycode, 0, XkbGroup1Mask, NULL, &changes);
|
|
|
|
}
|
|
|
|
|
|
|
|
changes.changed = XkbKeySymsMask | XkbKeyTypesMask;
|
|
|
|
changes.first_key_sym = keycode;
|
|
|
|
changes.num_key_syms = 1;
|
|
|
|
changes.first_type = 0;
|
|
|
|
changes.num_types = xkb->map->num_types;
|
|
|
|
XkbChangeMap (dpy, xkb, &changes);
|
|
|
|
|
|
|
|
XFlush (dpy);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-12 12:11:30 -04:00
|
|
|
static void
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_finalize (GObject *object)
|
2010-07-12 12:11:30 -04:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
MetaKeymapX11 *keymap;
|
2018-07-13 08:49:38 -04:00
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
2010-07-13 06:54:44 -04:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
keymap = META_KEYMAP_X11 (object);
|
2010-07-13 06:54:44 -04:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_refresh_reserved_keycodes (keymap);
|
2018-07-13 08:49:38 -04:00
|
|
|
g_hash_table_iter_init (&iter, keymap->reserved_keycodes);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t keycode = GPOINTER_TO_UINT (key);
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_replace_keycode (keymap, keycode, NoSymbol);
|
2018-07-13 08:49:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_destroy (keymap->reserved_keycodes);
|
|
|
|
g_queue_free (keymap->available_keycodes);
|
|
|
|
|
2010-07-13 06:54:44 -04:00
|
|
|
if (keymap->xkb_desc != NULL)
|
|
|
|
XkbFreeKeyboard (keymap->xkb_desc, XkbAllComponentsMask, True);
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
G_OBJECT_CLASS (meta_keymap_x11_parent_class)->finalize (object);
|
2010-07-12 12:11:30 -04:00
|
|
|
}
|
|
|
|
|
2019-01-10 06:34:28 -05:00
|
|
|
static gboolean
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_get_num_lock_state (ClutterKeymap *keymap)
|
2019-01-10 06:34:28 -05:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
MetaKeymapX11 *keymap_x11 = META_KEYMAP_X11 (keymap);
|
2019-01-10 06:34:28 -05:00
|
|
|
|
|
|
|
return keymap_x11->num_lock_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_get_caps_lock_state (ClutterKeymap *keymap)
|
2019-01-10 06:34:28 -05:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
MetaKeymapX11 *keymap_x11 = META_KEYMAP_X11 (keymap);
|
2019-01-10 06:34:28 -05:00
|
|
|
|
|
|
|
return keymap_x11->caps_lock_state;
|
|
|
|
}
|
|
|
|
|
2019-10-01 07:51:12 -04:00
|
|
|
static PangoDirection
|
2019-10-01 11:27:23 -04:00
|
|
|
meta_keymap_x11_get_direction (ClutterKeymap *keymap)
|
2019-10-01 07:51:12 -04:00
|
|
|
{
|
2019-10-01 11:27:23 -04:00
|
|
|
MetaKeymapX11 *keymap_x11;
|
|
|
|
|
2019-10-01 07:51:12 -04:00
|
|
|
g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), PANGO_DIRECTION_NEUTRAL);
|
|
|
|
|
2019-10-01 11:27:23 -04:00
|
|
|
keymap_x11 = META_KEYMAP_X11 (keymap);
|
|
|
|
|
|
|
|
if (keymap_x11->use_xkb)
|
2019-10-01 07:51:12 -04:00
|
|
|
{
|
2019-10-01 11:27:23 -04:00
|
|
|
if (!keymap_x11->has_direction)
|
2019-10-01 07:51:12 -04:00
|
|
|
{
|
|
|
|
XkbStateRec state_rec;
|
|
|
|
|
|
|
|
XkbGetState (clutter_x11_get_default_display (),
|
|
|
|
XkbUseCoreKbd, &state_rec);
|
2019-10-01 11:27:23 -04:00
|
|
|
update_direction (keymap_x11, XkbStateGroup (&state_rec));
|
2019-10-01 07:51:12 -04:00
|
|
|
}
|
|
|
|
|
2019-10-01 11:27:23 -04:00
|
|
|
return keymap_x11->current_direction;
|
2019-10-01 07:51:12 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return PANGO_DIRECTION_NEUTRAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-12 12:11:30 -04:00
|
|
|
static void
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_class_init (MetaKeymapX11Class *klass)
|
2010-07-12 12:11:30 -04:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2019-01-10 06:34:28 -05:00
|
|
|
ClutterKeymapClass *keymap_class = CLUTTER_KEYMAP_CLASS (klass);
|
2010-07-12 12:11:30 -04:00
|
|
|
|
2011-02-08 07:08:18 -05:00
|
|
|
obj_props[PROP_BACKEND] =
|
|
|
|
g_param_spec_object ("backend",
|
2019-03-22 08:53:00 -04:00
|
|
|
"Backend",
|
|
|
|
"The Clutter backend",
|
2011-02-08 07:08:18 -05:00
|
|
|
CLUTTER_TYPE_BACKEND,
|
2019-03-22 08:53:00 -04:00
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
2011-02-08 07:08:18 -05:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
gobject_class->constructed = meta_keymap_x11_constructed;
|
|
|
|
gobject_class->set_property = meta_keymap_x11_set_property;
|
|
|
|
gobject_class->finalize = meta_keymap_x11_finalize;
|
2019-01-10 06:34:28 -05:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
keymap_class->get_num_lock_state = meta_keymap_x11_get_num_lock_state;
|
|
|
|
keymap_class->get_caps_lock_state = meta_keymap_x11_get_caps_lock_state;
|
2019-10-01 07:51:12 -04:00
|
|
|
keymap_class->get_direction = meta_keymap_x11_get_direction;
|
2019-01-10 06:34:28 -05:00
|
|
|
|
2011-02-08 07:08:18 -05:00
|
|
|
g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
|
2010-07-12 12:11:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_init (MetaKeymapX11 *keymap)
|
2010-07-12 12:11:30 -04:00
|
|
|
{
|
2014-03-03 18:23:12 -05:00
|
|
|
keymap->current_direction = PANGO_DIRECTION_NEUTRAL;
|
2018-06-29 08:31:23 -04:00
|
|
|
keymap->current_group = -1;
|
2018-07-13 08:49:38 -04:00
|
|
|
keymap->reserved_keycodes = g_hash_table_new (NULL, NULL);
|
|
|
|
keymap->available_keycodes = g_queue_new ();
|
2010-07-12 12:11:30 -04:00
|
|
|
}
|
|
|
|
|
2019-03-26 14:19:45 -04:00
|
|
|
gboolean
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_handle_event (MetaKeymapX11 *keymap_x11,
|
|
|
|
XEvent *xevent)
|
2011-02-08 07:08:18 -05:00
|
|
|
{
|
2019-03-26 14:19:45 -04:00
|
|
|
gboolean retval;
|
2011-02-08 07:08:18 -05:00
|
|
|
|
2019-03-26 09:53:11 -04:00
|
|
|
if (!keymap_x11->use_xkb)
|
2019-03-26 14:19:45 -04:00
|
|
|
return FALSE;
|
2011-02-08 07:08:18 -05:00
|
|
|
|
2019-03-26 14:19:45 -04:00
|
|
|
retval = FALSE;
|
2011-02-08 07:08:18 -05:00
|
|
|
|
|
|
|
if (xevent->type == keymap_x11->xkb_event_base)
|
|
|
|
{
|
|
|
|
XkbEvent *xkb_event = (XkbEvent *) xevent;
|
|
|
|
|
|
|
|
switch (xkb_event->any.xkb_type)
|
|
|
|
{
|
|
|
|
case XkbStateNotify:
|
2019-03-22 08:53:00 -04:00
|
|
|
g_debug ("Updating keyboard state");
|
2018-06-29 08:31:23 -04:00
|
|
|
keymap_x11->current_group = XkbStateGroup (&xkb_event->state);
|
|
|
|
update_direction (keymap_x11, keymap_x11->current_group);
|
2011-02-08 07:08:18 -05:00
|
|
|
update_locked_mods (keymap_x11, xkb_event->state.locked_mods);
|
2019-03-26 14:19:45 -04:00
|
|
|
retval = TRUE;
|
2011-02-08 07:08:18 -05:00
|
|
|
break;
|
|
|
|
|
2013-02-21 18:31:34 -05:00
|
|
|
case XkbNewKeyboardNotify:
|
2011-02-08 07:08:18 -05:00
|
|
|
case XkbMapNotify:
|
2019-03-22 08:53:00 -04:00
|
|
|
g_debug ("Updating keyboard mapping");
|
2011-02-08 07:08:18 -05:00
|
|
|
XkbRefreshKeyboardMapping (&xkb_event->map);
|
2019-03-26 09:53:11 -04:00
|
|
|
keymap_x11->keymap_serial += 1;
|
2019-03-26 14:19:45 -04:00
|
|
|
retval = TRUE;
|
2011-02-08 07:08:18 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-26 09:53:11 -04:00
|
|
|
else if (xevent->type == MappingNotify)
|
|
|
|
{
|
|
|
|
XRefreshKeyboardMapping (&xevent->xmapping);
|
|
|
|
keymap_x11->keymap_serial += 1;
|
2019-03-26 14:19:45 -04:00
|
|
|
retval = TRUE;
|
2019-03-26 09:53:11 -04:00
|
|
|
}
|
2011-02-08 07:08:18 -05:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2019-03-29 16:14:46 -04:00
|
|
|
int
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_get_key_group (MetaKeymapX11 *keymap,
|
|
|
|
ClutterModifierType state)
|
2010-07-12 12:11:30 -04:00
|
|
|
{
|
|
|
|
return XkbGroupForCoreState (state);
|
|
|
|
}
|
2010-07-13 04:15:21 -04:00
|
|
|
|
2012-03-19 10:40:46 -04:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
|
|
|
/* XXX - yes, I know that XKeycodeToKeysym() has been deprecated; hopefully,
|
|
|
|
* this code will never get run on any decent system that is also able to
|
|
|
|
* run Clutter. I just don't want to copy the implementation inside GDK for
|
|
|
|
* a fallback path.
|
|
|
|
*/
|
|
|
|
static int
|
2019-03-22 08:53:00 -04:00
|
|
|
translate_keysym (MetaKeymapX11 *keymap,
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t hardware_keycode)
|
2012-03-19 10:40:46 -04:00
|
|
|
{
|
2019-03-29 16:14:46 -04:00
|
|
|
int retval;
|
2012-03-19 10:40:46 -04:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
retval = XKeycodeToKeysym (clutter_x11_get_default_display (),
|
|
|
|
hardware_keycode, 0);
|
2012-03-19 10:40:46 -04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
|
|
2019-03-29 16:14:46 -04:00
|
|
|
int
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_translate_key_state (MetaKeymapX11 *keymap,
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t hardware_keycode,
|
2019-03-22 08:53:00 -04:00
|
|
|
ClutterModifierType *modifier_state_p,
|
|
|
|
ClutterModifierType *mods_p)
|
2010-07-13 06:54:44 -04:00
|
|
|
{
|
|
|
|
ClutterModifierType unconsumed_modifiers = 0;
|
2012-12-22 22:21:16 -05:00
|
|
|
ClutterModifierType modifier_state = *modifier_state_p;
|
2019-03-29 16:14:46 -04:00
|
|
|
int retval;
|
2010-07-13 06:54:44 -04:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), 0);
|
2010-07-13 06:54:44 -04:00
|
|
|
|
2019-03-26 09:53:11 -04:00
|
|
|
if (keymap->use_xkb)
|
2010-07-13 06:54:44 -04:00
|
|
|
{
|
|
|
|
XkbDescRec *xkb = get_xkb (keymap);
|
|
|
|
KeySym tmp_keysym;
|
|
|
|
|
|
|
|
if (XkbTranslateKeyCode (xkb, hardware_keycode, modifier_state,
|
|
|
|
&unconsumed_modifiers,
|
|
|
|
&tmp_keysym))
|
|
|
|
{
|
|
|
|
retval = tmp_keysym;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
else
|
2012-03-19 10:40:46 -04:00
|
|
|
retval = translate_keysym (keymap, hardware_keycode);
|
2010-07-13 06:54:44 -04:00
|
|
|
|
|
|
|
if (mods_p)
|
|
|
|
*mods_p = unconsumed_modifiers;
|
|
|
|
|
2012-12-22 22:21:16 -05:00
|
|
|
*modifier_state_p = modifier_state & ~(keymap->num_lock_mask |
|
|
|
|
keymap->scroll_lock_mask |
|
|
|
|
LockMask);
|
|
|
|
|
2010-07-13 06:54:44 -04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_get_is_modifier (MetaKeymapX11 *keymap,
|
2019-03-29 16:14:46 -04:00
|
|
|
int keycode)
|
2010-07-13 06:54:44 -04:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), FALSE);
|
2010-07-13 06:54:44 -04:00
|
|
|
|
|
|
|
if (keycode < keymap->min_keycode || keycode > keymap->max_keycode)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-03-26 09:53:11 -04:00
|
|
|
if (keymap->use_xkb)
|
2010-07-13 06:54:44 -04:00
|
|
|
{
|
|
|
|
XkbDescRec *xkb = get_xkb (keymap);
|
|
|
|
|
|
|
|
if (xkb->map->modmap && xkb->map->modmap[keycode] != 0)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-03-03 18:23:12 -05:00
|
|
|
|
2018-06-29 08:31:23 -04:00
|
|
|
static gboolean
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_get_entries_for_keyval (MetaKeymapX11 *keymap_x11,
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t keyval,
|
2019-03-22 08:53:00 -04:00
|
|
|
ClutterKeymapKey **keys,
|
2019-03-29 16:14:46 -04:00
|
|
|
int *n_keys)
|
2018-06-29 08:31:23 -04:00
|
|
|
{
|
2019-03-26 09:53:11 -04:00
|
|
|
if (keymap_x11->use_xkb)
|
2018-06-29 08:31:23 -04:00
|
|
|
{
|
|
|
|
XkbDescRec *xkb = get_xkb (keymap_x11);
|
|
|
|
GArray *retval;
|
2019-03-29 16:14:46 -04:00
|
|
|
int keycode;
|
2018-06-29 08:31:23 -04:00
|
|
|
|
|
|
|
keycode = keymap_x11->min_keycode;
|
|
|
|
retval = g_array_new (FALSE, FALSE, sizeof (ClutterKeymapKey));
|
|
|
|
|
|
|
|
while (keycode <= keymap_x11->max_keycode)
|
|
|
|
{
|
2019-03-29 16:14:46 -04:00
|
|
|
int max_shift_levels = XkbKeyGroupsWidth (xkb, keycode);
|
|
|
|
int group = 0;
|
|
|
|
int level = 0;
|
|
|
|
int total_syms = XkbKeyNumSyms (xkb, keycode);
|
|
|
|
int i = 0;
|
2018-06-29 08:31:23 -04:00
|
|
|
KeySym *entry;
|
|
|
|
|
|
|
|
/* entry is an array with all syms for group 0, all
|
|
|
|
* syms for group 1, etc. and for each group the
|
|
|
|
* shift level syms are in order
|
|
|
|
*/
|
|
|
|
entry = XkbKeySymsPtr (xkb, keycode);
|
|
|
|
|
|
|
|
while (i < total_syms)
|
|
|
|
{
|
|
|
|
g_assert (i == (group * max_shift_levels + level));
|
|
|
|
|
|
|
|
if (entry[i] == keyval)
|
|
|
|
{
|
|
|
|
ClutterKeymapKey key;
|
|
|
|
|
|
|
|
key.keycode = keycode;
|
|
|
|
key.group = group;
|
|
|
|
key.level = level;
|
|
|
|
|
|
|
|
g_array_append_val (retval, key);
|
|
|
|
|
|
|
|
g_assert (XkbKeySymEntry (xkb, keycode, level, group) ==
|
|
|
|
keyval);
|
|
|
|
}
|
|
|
|
|
|
|
|
++level;
|
|
|
|
|
|
|
|
if (level == max_shift_levels)
|
|
|
|
{
|
|
|
|
level = 0;
|
|
|
|
++group;
|
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
++keycode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval->len > 0)
|
|
|
|
{
|
|
|
|
*keys = (ClutterKeymapKey*) retval->data;
|
|
|
|
*n_keys = retval->len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*keys = NULL;
|
|
|
|
*n_keys = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_free (retval, retval->len > 0 ? FALSE : TRUE);
|
|
|
|
|
|
|
|
return *n_keys > 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 16:14:46 -04:00
|
|
|
static uint32_t
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_get_available_keycode (MetaKeymapX11 *keymap_x11)
|
2018-07-13 08:49:38 -04:00
|
|
|
{
|
2019-03-26 09:53:11 -04:00
|
|
|
if (keymap_x11->use_xkb)
|
2018-07-13 08:49:38 -04:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_refresh_reserved_keycodes (keymap_x11);
|
2018-07-13 08:49:38 -04:00
|
|
|
|
|
|
|
if (g_hash_table_size (keymap_x11->reserved_keycodes) < 5)
|
|
|
|
{
|
|
|
|
Display *dpy = clutter_x11_get_default_display ();
|
|
|
|
XkbDescPtr xkb = get_xkb (keymap_x11);
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t i;
|
2018-07-13 08:49:38 -04:00
|
|
|
|
|
|
|
for (i = xkb->max_key_code; i >= xkb->min_key_code; --i)
|
|
|
|
{
|
|
|
|
if (XkbKeycodeToKeysym (dpy, i, 0, 0) == NoSymbol)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GPOINTER_TO_UINT (g_queue_pop_head (keymap_x11->available_keycodes));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
gboolean
|
|
|
|
meta_keymap_x11_reserve_keycode (MetaKeymapX11 *keymap_x11,
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t keyval,
|
|
|
|
uint32_t *keycode_out)
|
2018-07-13 08:49:38 -04:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap_x11), FALSE);
|
2018-07-13 08:49:38 -04:00
|
|
|
g_return_val_if_fail (keyval != 0, FALSE);
|
|
|
|
g_return_val_if_fail (keycode_out != NULL, FALSE);
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
*keycode_out = meta_keymap_x11_get_available_keycode (keymap_x11);
|
2018-07-13 08:49:38 -04:00
|
|
|
|
|
|
|
if (*keycode_out == NoSymbol)
|
|
|
|
{
|
|
|
|
g_warning ("Cannot reserve a keycode for keyval %d: no available keycode", keyval);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
if (!meta_keymap_x11_replace_keycode (keymap_x11, *keycode_out, keyval))
|
2018-07-13 08:49:38 -04:00
|
|
|
{
|
|
|
|
g_warning ("Failed to remap keycode %d to keyval %d", *keycode_out, keyval);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_insert (keymap_x11->reserved_keycodes, GUINT_TO_POINTER (*keycode_out), GUINT_TO_POINTER (keyval));
|
|
|
|
g_queue_remove (keymap_x11->available_keycodes, GUINT_TO_POINTER (*keycode_out));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
void
|
|
|
|
meta_keymap_x11_release_keycode_if_needed (MetaKeymapX11 *keymap_x11,
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t keycode)
|
2018-07-13 08:49:38 -04:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
g_return_if_fail (META_IS_KEYMAP_X11 (keymap_x11));
|
2018-07-13 08:49:38 -04:00
|
|
|
|
|
|
|
if (!g_hash_table_contains (keymap_x11->reserved_keycodes, GUINT_TO_POINTER (keycode)) ||
|
|
|
|
g_queue_index (keymap_x11->available_keycodes, GUINT_TO_POINTER (keycode)) != -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_queue_push_tail (keymap_x11->available_keycodes, GUINT_TO_POINTER (keycode));
|
|
|
|
}
|
|
|
|
|
2018-06-29 08:31:23 -04:00
|
|
|
void
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_latch_modifiers (MetaKeymapX11 *keymap_x11,
|
|
|
|
uint32_t level,
|
|
|
|
gboolean enable)
|
2018-06-29 08:31:23 -04:00
|
|
|
{
|
|
|
|
uint32_t modifiers[] = {
|
|
|
|
0,
|
|
|
|
ShiftMask,
|
|
|
|
keymap_x11->level3_shift_mask,
|
|
|
|
keymap_x11->level3_shift_mask | ShiftMask,
|
|
|
|
};
|
|
|
|
uint32_t value = 0;
|
|
|
|
|
2019-03-26 09:53:11 -04:00
|
|
|
if (!keymap_x11->use_xkb)
|
2018-06-29 08:31:23 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
level = CLAMP (level, 0, G_N_ELEMENTS (modifiers) - 1);
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
value = modifiers[level];
|
|
|
|
else
|
|
|
|
value = 0;
|
|
|
|
|
|
|
|
XkbLatchModifiers (clutter_x11_get_default_display (),
|
|
|
|
XkbUseCoreKbd, modifiers[level],
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_get_current_group (MetaKeymapX11 *keymap_x11)
|
2018-06-29 08:31:23 -04:00
|
|
|
{
|
|
|
|
XkbStateRec state_rec;
|
|
|
|
|
|
|
|
if (keymap_x11->current_group >= 0)
|
|
|
|
return keymap_x11->current_group;
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
XkbGetState (clutter_x11_get_default_display (),
|
|
|
|
XkbUseCoreKbd, &state_rec);
|
2018-06-29 08:31:23 -04:00
|
|
|
return XkbStateGroup (&state_rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_keymap_x11_keycode_for_keyval (MetaKeymapX11 *keymap_x11,
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t keyval,
|
|
|
|
uint32_t *keycode_out,
|
|
|
|
uint32_t *level_out)
|
2018-06-29 08:31:23 -04:00
|
|
|
{
|
|
|
|
ClutterKeymapKey *keys;
|
2019-03-29 16:14:46 -04:00
|
|
|
int i, n_keys, group;
|
2018-06-29 08:31:23 -04:00
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (keycode_out != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (level_out != NULL, FALSE);
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
group = meta_keymap_x11_get_current_group (keymap_x11);
|
2018-06-29 08:31:23 -04:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
if (!meta_keymap_x11_get_entries_for_keyval (keymap_x11, keyval, &keys, &n_keys))
|
2018-06-29 08:31:23 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < n_keys && !found; i++)
|
|
|
|
{
|
|
|
|
if (keys[i].group == group)
|
|
|
|
{
|
|
|
|
*keycode_out = keys[i].keycode;
|
|
|
|
*level_out = keys[i].level;
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 12:20:37 -05:00
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, keymap_x11->reserved_keycodes);
|
|
|
|
while (!found && g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
2019-03-29 16:14:46 -04:00
|
|
|
uint32_t reserved_keycode = GPOINTER_TO_UINT (key);
|
|
|
|
uint32_t reserved_keysym = GPOINTER_TO_UINT (value);
|
2019-01-22 12:20:37 -05:00
|
|
|
|
|
|
|
if (keyval == reserved_keysym)
|
|
|
|
{
|
|
|
|
*keycode_out = reserved_keycode;
|
|
|
|
*level_out = 0;
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-29 08:31:23 -04:00
|
|
|
g_free (keys);
|
|
|
|
return found;
|
|
|
|
}
|