2010-12-18 20:38:49 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
* Copyright (C) 2000 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-18 20:38:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <errno.h>
|
2012-07-16 18:02:41 +00:00
|
|
|
#include <sys/mman.h>
|
2010-12-18 20:38:49 +00:00
|
|
|
|
|
|
|
#include "gdk.h"
|
|
|
|
#include "gdkwayland.h"
|
|
|
|
|
|
|
|
#include "gdkprivate-wayland.h"
|
2019-01-31 19:05:28 +00:00
|
|
|
#include "gdk-private.h"
|
2010-12-18 20:38:49 +00:00
|
|
|
#include "gdkkeysprivate.h"
|
|
|
|
|
2012-06-18 15:02:37 +00:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2010-12-18 20:38:49 +00:00
|
|
|
|
|
|
|
typedef struct _GdkWaylandKeymap GdkWaylandKeymap;
|
|
|
|
typedef struct _GdkWaylandKeymapClass GdkWaylandKeymapClass;
|
|
|
|
|
|
|
|
struct _GdkWaylandKeymap
|
|
|
|
{
|
|
|
|
GdkKeymap parent_instance;
|
2012-07-16 18:02:41 +00:00
|
|
|
|
|
|
|
struct xkb_keymap *xkb_keymap;
|
2012-07-16 18:16:48 +00:00
|
|
|
struct xkb_state *xkb_state;
|
2013-04-04 03:45:54 +00:00
|
|
|
|
|
|
|
PangoDirection *direction;
|
|
|
|
gboolean bidi;
|
2010-12-18 20:38:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GdkWaylandKeymapClass
|
|
|
|
{
|
|
|
|
GdkKeymapClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GDK_TYPE_WAYLAND_KEYMAP (_gdk_wayland_keymap_get_type ())
|
2011-01-07 17:10:41 +00:00
|
|
|
#define GDK_WAYLAND_KEYMAP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WAYLAND_KEYMAP, GdkWaylandKeymap))
|
2010-12-18 20:38:49 +00:00
|
|
|
#define GDK_IS_WAYLAND_KEYMAP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_WAYLAND_KEYMAP))
|
|
|
|
|
2014-09-06 00:41:06 +00:00
|
|
|
GType _gdk_wayland_keymap_get_type (void);
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
G_DEFINE_TYPE (GdkWaylandKeymap, _gdk_wayland_keymap, GDK_TYPE_KEYMAP)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_wayland_keymap_finalize (GObject *object)
|
|
|
|
{
|
2013-03-23 22:02:28 +00:00
|
|
|
GdkWaylandKeymap *keymap = GDK_WAYLAND_KEYMAP (object);
|
|
|
|
|
|
|
|
xkb_keymap_unref (keymap->xkb_keymap);
|
|
|
|
xkb_state_unref (keymap->xkb_state);
|
2013-04-04 03:45:54 +00:00
|
|
|
g_free (keymap->direction);
|
2013-03-23 22:02:28 +00:00
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
G_OBJECT_CLASS (_gdk_wayland_keymap_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PangoDirection
|
|
|
|
gdk_wayland_keymap_get_direction (GdkKeymap *keymap)
|
|
|
|
{
|
2013-04-04 03:45:54 +00:00
|
|
|
GdkWaylandKeymap *keymap_wayland = GDK_WAYLAND_KEYMAP (keymap);
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2013-04-04 03:45:54 +00:00
|
|
|
|
|
|
|
for (i = 0; i < xkb_keymap_num_layouts (keymap_wayland->xkb_keymap); i++)
|
|
|
|
{
|
|
|
|
if (xkb_state_layout_index_is_active (keymap_wayland->xkb_state, i, XKB_STATE_LAYOUT_EFFECTIVE))
|
|
|
|
return keymap_wayland->direction[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return PANGO_DIRECTION_NEUTRAL;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_wayland_keymap_have_bidi_layouts (GdkKeymap *keymap)
|
|
|
|
{
|
2013-04-04 03:45:54 +00:00
|
|
|
GdkWaylandKeymap *keymap_wayland = GDK_WAYLAND_KEYMAP (keymap);
|
|
|
|
|
|
|
|
return keymap_wayland->bidi;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_wayland_keymap_get_caps_lock_state (GdkKeymap *keymap)
|
|
|
|
{
|
2012-07-16 18:51:48 +00:00
|
|
|
return xkb_state_led_name_is_active (GDK_WAYLAND_KEYMAP (keymap)->xkb_state,
|
|
|
|
XKB_LED_NAME_CAPS);
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_wayland_keymap_get_num_lock_state (GdkKeymap *keymap)
|
|
|
|
{
|
2012-07-16 18:51:48 +00:00
|
|
|
return xkb_state_led_name_is_active (GDK_WAYLAND_KEYMAP (keymap)->xkb_state,
|
|
|
|
XKB_LED_NAME_NUM);
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:25:38 +00:00
|
|
|
static gboolean
|
|
|
|
gdk_wayland_keymap_get_scroll_lock_state (GdkKeymap *keymap)
|
|
|
|
{
|
|
|
|
return xkb_state_led_name_is_active (GDK_WAYLAND_KEYMAP (keymap)->xkb_state,
|
|
|
|
XKB_LED_NAME_SCROLL);
|
|
|
|
}
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
static gboolean
|
2020-04-30 04:33:06 +00:00
|
|
|
gdk_wayland_keymap_get_entries_for_keyval (GdkKeymap *keymap,
|
|
|
|
guint keyval,
|
|
|
|
GArray *retval)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
2013-04-05 11:21:40 +00:00
|
|
|
struct xkb_keymap *xkb_keymap = GDK_WAYLAND_KEYMAP (keymap)->xkb_keymap;
|
|
|
|
guint keycode;
|
2016-03-26 22:48:27 +00:00
|
|
|
xkb_keycode_t min_keycode, max_keycode;
|
2020-04-30 04:33:06 +00:00
|
|
|
guint len = retval->len;
|
2013-04-05 11:21:40 +00:00
|
|
|
|
2016-03-26 22:48:27 +00:00
|
|
|
min_keycode = xkb_keymap_min_keycode (xkb_keymap);
|
|
|
|
max_keycode = xkb_keymap_max_keycode (xkb_keymap);
|
|
|
|
for (keycode = min_keycode; keycode < max_keycode; keycode++)
|
2011-01-07 17:10:41 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int num_layouts, layout;
|
2013-04-05 11:21:40 +00:00
|
|
|
num_layouts = xkb_keymap_num_layouts_for_key (xkb_keymap, keycode);
|
|
|
|
for (layout = 0; layout < num_layouts; layout++)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int num_levels, level;
|
2013-04-05 11:21:40 +00:00
|
|
|
num_levels = xkb_keymap_num_levels_for_key (xkb_keymap, keycode, layout);
|
|
|
|
for (level = 0; level < num_levels; level++)
|
|
|
|
{
|
|
|
|
const xkb_keysym_t *syms;
|
2020-07-24 13:54:49 +00:00
|
|
|
int num_syms, sym;
|
2013-04-05 11:21:40 +00:00
|
|
|
num_syms = xkb_keymap_key_get_syms_by_level (xkb_keymap, keycode, layout, level, &syms);
|
|
|
|
for (sym = 0; sym < num_syms; sym++)
|
|
|
|
{
|
|
|
|
if (syms[sym] == keyval)
|
|
|
|
{
|
|
|
|
GdkKeymapKey key;
|
|
|
|
|
|
|
|
key.keycode = keycode;
|
|
|
|
key.group = layout;
|
|
|
|
key.level = level;
|
|
|
|
|
|
|
|
g_array_append_val (retval, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-07 17:10:41 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 04:33:06 +00:00
|
|
|
return retval->len > len;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_wayland_keymap_get_entries_for_keycode (GdkKeymap *keymap,
|
2011-01-07 17:10:41 +00:00
|
|
|
guint hardware_keycode,
|
|
|
|
GdkKeymapKey **keys,
|
|
|
|
guint **keyvals,
|
2020-07-24 13:54:49 +00:00
|
|
|
int *n_entries)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
2013-04-05 01:52:12 +00:00
|
|
|
struct xkb_keymap *xkb_keymap = GDK_WAYLAND_KEYMAP (keymap)->xkb_keymap;
|
2020-07-24 13:54:49 +00:00
|
|
|
int num_layouts, layout;
|
|
|
|
int num_entries;
|
|
|
|
int i;
|
2013-04-05 01:52:12 +00:00
|
|
|
|
|
|
|
num_layouts = xkb_keymap_num_layouts_for_key (xkb_keymap, hardware_keycode);
|
|
|
|
|
|
|
|
num_entries = 0;
|
|
|
|
for (layout = 0; layout < num_layouts; layout++)
|
|
|
|
num_entries += xkb_keymap_num_levels_for_key (xkb_keymap, hardware_keycode, layout);
|
|
|
|
|
2012-07-16 19:08:20 +00:00
|
|
|
if (n_entries)
|
2013-04-05 01:52:12 +00:00
|
|
|
*n_entries = num_entries;
|
2011-01-07 17:10:41 +00:00
|
|
|
if (keys)
|
2013-04-05 11:21:40 +00:00
|
|
|
*keys = g_new0 (GdkKeymapKey, num_entries);
|
2011-01-07 17:10:41 +00:00
|
|
|
if (keyvals)
|
2013-04-05 11:21:40 +00:00
|
|
|
*keyvals = g_new0 (guint, num_entries);
|
2013-04-05 01:52:12 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (layout = 0; layout < num_layouts; layout++)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int num_levels, level;
|
2013-04-05 01:52:12 +00:00
|
|
|
num_levels = xkb_keymap_num_levels_for_key (xkb_keymap, hardware_keycode, layout);
|
|
|
|
for (level = 0; level < num_levels; level++)
|
|
|
|
{
|
2013-04-06 14:38:26 +00:00
|
|
|
const xkb_keysym_t *syms;
|
|
|
|
int num_syms;
|
|
|
|
num_syms = xkb_keymap_key_get_syms_by_level (xkb_keymap, hardware_keycode, layout, 0, &syms);
|
2013-04-05 01:52:12 +00:00
|
|
|
if (keys)
|
|
|
|
{
|
|
|
|
(*keys)[i].keycode = hardware_keycode;
|
|
|
|
(*keys)[i].group = layout;
|
|
|
|
(*keys)[i].level = level;
|
|
|
|
}
|
|
|
|
if (keyvals && num_syms > 0)
|
|
|
|
(*keyvals)[i] = syms[0];
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-05 11:21:40 +00:00
|
|
|
return num_entries > 0;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
gdk_wayland_keymap_lookup_key (GdkKeymap *keymap,
|
2011-01-07 17:10:41 +00:00
|
|
|
const GdkKeymapKey *key)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
2013-04-05 11:21:40 +00:00
|
|
|
struct xkb_keymap *xkb_keymap = GDK_WAYLAND_KEYMAP (keymap)->xkb_keymap;
|
|
|
|
const xkb_keysym_t *syms;
|
|
|
|
int num_syms;
|
|
|
|
|
|
|
|
num_syms = xkb_keymap_key_get_syms_by_level (xkb_keymap,
|
|
|
|
key->keycode,
|
|
|
|
key->group,
|
|
|
|
key->level,
|
|
|
|
&syms);
|
|
|
|
if (num_syms > 0)
|
|
|
|
return syms[0];
|
|
|
|
else
|
|
|
|
return XKB_KEY_NoSymbol;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
2013-04-06 14:43:38 +00:00
|
|
|
static guint32
|
|
|
|
get_xkb_modifiers (struct xkb_keymap *xkb_keymap,
|
|
|
|
GdkModifierType state)
|
|
|
|
{
|
|
|
|
guint32 mods = 0;
|
|
|
|
|
|
|
|
if (state & GDK_SHIFT_MASK)
|
2013-04-06 21:03:27 +00:00
|
|
|
mods |= 1 << xkb_keymap_mod_get_index (xkb_keymap, XKB_MOD_NAME_SHIFT);
|
2013-04-06 14:43:38 +00:00
|
|
|
if (state & GDK_LOCK_MASK)
|
2013-04-06 21:03:27 +00:00
|
|
|
mods |= 1 << xkb_keymap_mod_get_index (xkb_keymap, XKB_MOD_NAME_CAPS);
|
2013-04-06 14:43:38 +00:00
|
|
|
if (state & GDK_CONTROL_MASK)
|
2013-04-06 21:03:27 +00:00
|
|
|
mods |= 1 << xkb_keymap_mod_get_index (xkb_keymap, XKB_MOD_NAME_CTRL);
|
2020-04-05 13:39:03 +00:00
|
|
|
if (state & GDK_ALT_MASK)
|
2013-04-06 21:03:27 +00:00
|
|
|
mods |= 1 << xkb_keymap_mod_get_index (xkb_keymap, XKB_MOD_NAME_ALT);
|
2015-11-03 17:39:27 +00:00
|
|
|
if (state & GDK_SUPER_MASK)
|
|
|
|
mods |= 1 << xkb_keymap_mod_get_index (xkb_keymap, "Super");
|
|
|
|
if (state & GDK_HYPER_MASK)
|
|
|
|
mods |= 1 << xkb_keymap_mod_get_index (xkb_keymap, "Hyper");
|
|
|
|
if (state & GDK_META_MASK)
|
|
|
|
mods |= 1 << xkb_keymap_mod_get_index (xkb_keymap, "Meta");
|
2013-04-06 14:43:38 +00:00
|
|
|
|
|
|
|
return mods;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkModifierType
|
|
|
|
get_gdk_modifiers (struct xkb_keymap *xkb_keymap,
|
|
|
|
guint32 mods)
|
|
|
|
{
|
|
|
|
GdkModifierType state = 0;
|
|
|
|
|
2013-04-06 21:03:27 +00:00
|
|
|
if (mods & (1 << xkb_keymap_mod_get_index (xkb_keymap, XKB_MOD_NAME_SHIFT)))
|
2013-04-06 14:43:38 +00:00
|
|
|
state |= GDK_SHIFT_MASK;
|
2013-04-06 21:03:27 +00:00
|
|
|
if (mods & (1 << xkb_keymap_mod_get_index (xkb_keymap, XKB_MOD_NAME_CAPS)))
|
2013-04-06 14:43:38 +00:00
|
|
|
state |= GDK_LOCK_MASK;
|
2013-04-06 21:03:27 +00:00
|
|
|
if (mods & (1 << xkb_keymap_mod_get_index (xkb_keymap, XKB_MOD_NAME_CTRL)))
|
2013-04-06 14:43:38 +00:00
|
|
|
state |= GDK_CONTROL_MASK;
|
2013-04-06 21:03:27 +00:00
|
|
|
if (mods & (1 << xkb_keymap_mod_get_index (xkb_keymap, XKB_MOD_NAME_ALT)))
|
2020-04-05 13:39:03 +00:00
|
|
|
state |= GDK_ALT_MASK;
|
2015-11-03 17:39:27 +00:00
|
|
|
if (mods & (1 << xkb_keymap_mod_get_index (xkb_keymap, "Super")))
|
|
|
|
state |= GDK_SUPER_MASK;
|
|
|
|
if (mods & (1 << xkb_keymap_mod_get_index (xkb_keymap, "Hyper")))
|
|
|
|
state |= GDK_HYPER_MASK;
|
2019-02-06 09:39:27 +00:00
|
|
|
/* GTK treats MOD1 as a synonym for Alt, and does not expect it to
|
2017-01-11 17:33:11 +00:00
|
|
|
* be mapped around, so we should avoid adding GDK_META_MASK if MOD1
|
2019-02-06 09:39:27 +00:00
|
|
|
* is already included to avoid confusing GTK and applications that
|
2017-01-11 17:33:11 +00:00
|
|
|
* rely on that behavior.
|
|
|
|
*/
|
|
|
|
if (mods & (1 << xkb_keymap_mod_get_index (xkb_keymap, "Meta")) &&
|
2020-04-05 13:39:03 +00:00
|
|
|
(state & GDK_ALT_MASK) == 0)
|
2015-11-03 17:39:27 +00:00
|
|
|
state |= GDK_META_MASK;
|
2013-04-06 14:43:38 +00:00
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-04-05 18:40:55 +00:00
|
|
|
GdkModifierType
|
|
|
|
gdk_wayland_keymap_get_gdk_modifiers (GdkKeymap *keymap,
|
|
|
|
guint32 mods)
|
|
|
|
{
|
|
|
|
struct xkb_keymap *xkb_keymap = GDK_WAYLAND_KEYMAP (keymap)->xkb_keymap;
|
|
|
|
|
|
|
|
return get_gdk_modifiers (xkb_keymap, mods);
|
|
|
|
}
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
static gboolean
|
|
|
|
gdk_wayland_keymap_translate_keyboard_state (GdkKeymap *keymap,
|
2011-01-07 17:10:41 +00:00
|
|
|
guint hardware_keycode,
|
|
|
|
GdkModifierType state,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group,
|
2011-01-07 17:10:41 +00:00
|
|
|
guint *keyval,
|
2020-07-24 13:54:49 +00:00
|
|
|
int *effective_group,
|
|
|
|
int *effective_level,
|
2011-01-07 17:10:41 +00:00
|
|
|
GdkModifierType *consumed_modifiers)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
2013-04-06 14:43:38 +00:00
|
|
|
struct xkb_keymap *xkb_keymap;
|
|
|
|
struct xkb_state *xkb_state;
|
|
|
|
guint32 modifiers;
|
|
|
|
guint32 consumed;
|
|
|
|
xkb_layout_index_t layout;
|
|
|
|
xkb_level_index_t level;
|
|
|
|
xkb_keysym_t sym;
|
|
|
|
|
2011-02-10 21:35:38 +00:00
|
|
|
g_return_val_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap), FALSE);
|
|
|
|
g_return_val_if_fail (group < 4, FALSE);
|
|
|
|
|
2013-04-06 14:43:38 +00:00
|
|
|
xkb_keymap = GDK_WAYLAND_KEYMAP (keymap)->xkb_keymap;
|
|
|
|
|
|
|
|
modifiers = get_xkb_modifiers (xkb_keymap, state);
|
|
|
|
|
|
|
|
xkb_state = xkb_state_new (xkb_keymap);
|
|
|
|
|
|
|
|
xkb_state_update_mask (xkb_state, modifiers, 0, 0, group, 0, 0);
|
|
|
|
|
|
|
|
layout = xkb_state_key_get_layout (xkb_state, hardware_keycode);
|
|
|
|
level = xkb_state_key_get_level (xkb_state, hardware_keycode, layout);
|
|
|
|
sym = xkb_state_key_get_one_sym (xkb_state, hardware_keycode);
|
|
|
|
consumed = modifiers & ~xkb_state_mod_mask_remove_consumed (xkb_state, hardware_keycode, modifiers);
|
|
|
|
|
|
|
|
xkb_state_unref (xkb_state);
|
|
|
|
|
2011-02-10 21:35:38 +00:00
|
|
|
if (keyval)
|
2013-04-06 14:43:38 +00:00
|
|
|
*keyval = sym;
|
2011-02-10 21:35:38 +00:00
|
|
|
if (effective_group)
|
2013-04-06 14:43:38 +00:00
|
|
|
*effective_group = layout;
|
|
|
|
if (effective_level)
|
|
|
|
*effective_level = level;
|
2011-02-10 21:35:38 +00:00
|
|
|
if (consumed_modifiers)
|
2013-04-06 14:43:38 +00:00
|
|
|
*consumed_modifiers = get_gdk_modifiers (xkb_keymap, consumed);
|
2011-02-10 21:35:38 +00:00
|
|
|
|
2016-04-27 12:06:38 +00:00
|
|
|
return (sym != XKB_KEY_NoSymbol);
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 01:16:38 +00:00
|
|
|
static guint
|
|
|
|
gdk_wayland_keymap_get_modifier_state (GdkKeymap *keymap)
|
|
|
|
{
|
|
|
|
struct xkb_keymap *xkb_keymap = GDK_WAYLAND_KEYMAP (keymap)->xkb_keymap;
|
|
|
|
struct xkb_state *xkb_state = GDK_WAYLAND_KEYMAP (keymap)->xkb_state;
|
|
|
|
xkb_mod_mask_t mods;
|
|
|
|
|
|
|
|
mods = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_EFFECTIVE);
|
|
|
|
|
|
|
|
return get_gdk_modifiers (xkb_keymap, mods);
|
|
|
|
}
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
static void
|
|
|
|
_gdk_wayland_keymap_class_init (GdkWaylandKeymapClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GdkKeymapClass *keymap_class = GDK_KEYMAP_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gdk_wayland_keymap_finalize;
|
|
|
|
|
|
|
|
keymap_class->get_direction = gdk_wayland_keymap_get_direction;
|
|
|
|
keymap_class->have_bidi_layouts = gdk_wayland_keymap_have_bidi_layouts;
|
|
|
|
keymap_class->get_caps_lock_state = gdk_wayland_keymap_get_caps_lock_state;
|
|
|
|
keymap_class->get_num_lock_state = gdk_wayland_keymap_get_num_lock_state;
|
2015-04-14 11:25:38 +00:00
|
|
|
keymap_class->get_scroll_lock_state = gdk_wayland_keymap_get_scroll_lock_state;
|
2010-12-18 20:38:49 +00:00
|
|
|
keymap_class->get_entries_for_keyval = gdk_wayland_keymap_get_entries_for_keyval;
|
|
|
|
keymap_class->get_entries_for_keycode = gdk_wayland_keymap_get_entries_for_keycode;
|
|
|
|
keymap_class->lookup_key = gdk_wayland_keymap_lookup_key;
|
|
|
|
keymap_class->translate_keyboard_state = gdk_wayland_keymap_translate_keyboard_state;
|
2013-04-07 01:16:38 +00:00
|
|
|
keymap_class->get_modifier_state = gdk_wayland_keymap_get_modifier_state;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gdk_wayland_keymap_init (GdkWaylandKeymap *keymap)
|
|
|
|
{
|
|
|
|
}
|
2011-01-07 17:10:41 +00:00
|
|
|
|
2013-04-04 03:45:54 +00:00
|
|
|
static void
|
|
|
|
update_direction (GdkWaylandKeymap *keymap)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int num_layouts;
|
|
|
|
int i;
|
|
|
|
int *rtl;
|
2016-05-04 03:14:05 +00:00
|
|
|
xkb_keycode_t min_keycode, max_keycode;
|
2013-04-05 11:21:40 +00:00
|
|
|
guint key;
|
2013-04-04 03:45:54 +00:00
|
|
|
gboolean have_rtl, have_ltr;
|
|
|
|
|
|
|
|
num_layouts = xkb_keymap_num_layouts (keymap->xkb_keymap);
|
|
|
|
|
2016-05-04 03:14:05 +00:00
|
|
|
keymap->direction = g_renew (PangoDirection, keymap->direction, num_layouts);
|
2020-07-24 13:54:49 +00:00
|
|
|
rtl = g_newa (int, num_layouts);
|
2016-05-12 15:37:13 +00:00
|
|
|
for (i = 0; i < num_layouts; i++)
|
|
|
|
rtl[i] = 0;
|
2013-04-04 03:45:54 +00:00
|
|
|
|
2016-05-04 03:14:05 +00:00
|
|
|
min_keycode = xkb_keymap_min_keycode (keymap->xkb_keymap);
|
|
|
|
max_keycode = xkb_keymap_max_keycode (keymap->xkb_keymap);
|
|
|
|
for (key = min_keycode; key < max_keycode; key++)
|
2013-04-04 03:45:54 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int layouts, layout;
|
2013-04-04 03:45:54 +00:00
|
|
|
|
|
|
|
layouts = xkb_keymap_num_layouts_for_key (keymap->xkb_keymap, key);
|
2020-05-26 00:38:16 +00:00
|
|
|
g_assert (layouts <= num_layouts);
|
2013-04-04 03:45:54 +00:00
|
|
|
for (layout = 0; layout < layouts; layout++)
|
|
|
|
{
|
|
|
|
const xkb_keysym_t *syms;
|
2020-07-24 13:54:49 +00:00
|
|
|
int num_syms;
|
|
|
|
int sym;
|
2013-04-04 03:45:54 +00:00
|
|
|
|
|
|
|
num_syms = xkb_keymap_key_get_syms_by_level (keymap->xkb_keymap, key, layout, 0, &syms);
|
|
|
|
for (sym = 0; sym < num_syms; sym++)
|
|
|
|
{
|
|
|
|
PangoDirection dir;
|
2016-05-04 03:14:05 +00:00
|
|
|
|
2019-01-31 19:05:28 +00:00
|
|
|
dir = gdk_unichar_direction (xkb_keysym_to_utf32 (syms[sym]));
|
2013-04-04 03:45:54 +00:00
|
|
|
switch (dir)
|
|
|
|
{
|
|
|
|
case PANGO_DIRECTION_RTL:
|
|
|
|
rtl[layout]++;
|
|
|
|
break;
|
|
|
|
case PANGO_DIRECTION_LTR:
|
|
|
|
rtl[layout]--;
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
case PANGO_DIRECTION_TTB_LTR:
|
|
|
|
case PANGO_DIRECTION_TTB_RTL:
|
|
|
|
case PANGO_DIRECTION_WEAK_LTR:
|
|
|
|
case PANGO_DIRECTION_WEAK_RTL:
|
|
|
|
case PANGO_DIRECTION_NEUTRAL:
|
2013-04-04 03:45:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
have_rtl = have_ltr = FALSE;
|
|
|
|
for (i = 0; i < num_layouts; i++)
|
|
|
|
{
|
|
|
|
if (rtl[i] > 0)
|
|
|
|
{
|
|
|
|
keymap->direction[i] = PANGO_DIRECTION_RTL;
|
|
|
|
have_rtl = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
keymap->direction[i] = PANGO_DIRECTION_LTR;
|
|
|
|
have_ltr = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_rtl && have_ltr)
|
|
|
|
keymap->bidi = TRUE;
|
|
|
|
}
|
|
|
|
|
2013-04-05 01:10:18 +00:00
|
|
|
GdkKeymap *
|
2018-01-12 02:44:49 +00:00
|
|
|
_gdk_wayland_keymap_new (GdkDisplay *display)
|
2013-04-05 01:10:18 +00:00
|
|
|
{
|
|
|
|
GdkWaylandKeymap *keymap;
|
|
|
|
struct xkb_context *context;
|
|
|
|
struct xkb_rule_names names;
|
|
|
|
|
|
|
|
keymap = g_object_new (_gdk_wayland_keymap_get_type(), NULL);
|
2018-01-12 02:44:49 +00:00
|
|
|
GDK_KEYMAP (keymap)->display = display;
|
2013-04-05 01:10:18 +00:00
|
|
|
|
|
|
|
context = xkb_context_new (0);
|
|
|
|
|
|
|
|
names.rules = "evdev";
|
|
|
|
names.model = "pc105";
|
|
|
|
names.layout = "us";
|
|
|
|
names.variant = "";
|
|
|
|
names.options = "";
|
|
|
|
keymap->xkb_keymap = xkb_keymap_new_from_names (context, &names, 0);
|
|
|
|
keymap->xkb_state = xkb_state_new (keymap->xkb_keymap);
|
|
|
|
xkb_context_unref (context);
|
|
|
|
|
|
|
|
update_direction (keymap);
|
|
|
|
|
|
|
|
return GDK_KEYMAP (keymap);
|
|
|
|
}
|
|
|
|
|
2016-04-19 16:43:03 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
static void
|
|
|
|
print_modifiers (struct xkb_keymap *keymap)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
uint32_t real;
|
|
|
|
struct xkb_state *state;
|
|
|
|
|
|
|
|
g_print ("modifiers:\n");
|
|
|
|
for (i = 0; i < xkb_keymap_num_mods (keymap); i++)
|
|
|
|
g_print ("%s ", xkb_keymap_mod_get_name (keymap, i));
|
|
|
|
g_print ("\n\n");
|
|
|
|
|
|
|
|
g_print ("modifier mapping\n");
|
|
|
|
state = xkb_state_new (keymap);
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
gboolean need_arrow = TRUE;
|
|
|
|
g_print ("%s ", xkb_keymap_mod_get_name (keymap, i));
|
|
|
|
for (j = 8; j < xkb_keymap_num_mods (keymap); j++)
|
|
|
|
{
|
|
|
|
xkb_state_update_mask (state, 1 << j, 0, 0, 0, 0, 0);
|
|
|
|
real = xkb_state_serialize_mods (state, XKB_STATE_MODS_EFFECTIVE);
|
|
|
|
if (real & (1 << i))
|
|
|
|
{
|
|
|
|
if (need_arrow)
|
|
|
|
{
|
|
|
|
g_print ("-> ");
|
|
|
|
need_arrow = FALSE;
|
|
|
|
}
|
|
|
|
g_print ("%s ", xkb_keymap_mod_get_name (keymap, j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_print ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
xkb_state_unref (state);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-23 22:02:28 +00:00
|
|
|
void
|
|
|
|
_gdk_wayland_keymap_update_from_fd (GdkKeymap *keymap,
|
|
|
|
uint32_t format,
|
|
|
|
uint32_t fd,
|
|
|
|
uint32_t size)
|
2012-07-16 11:33:35 +00:00
|
|
|
{
|
2013-03-23 22:02:28 +00:00
|
|
|
GdkWaylandKeymap *keymap_wayland = GDK_WAYLAND_KEYMAP (keymap);
|
2012-07-16 18:02:41 +00:00
|
|
|
struct xkb_context *context;
|
2014-08-25 13:55:22 +00:00
|
|
|
struct xkb_keymap *xkb_keymap;
|
2012-07-16 18:02:41 +00:00
|
|
|
char *map_str;
|
2012-07-16 11:33:35 +00:00
|
|
|
|
2012-07-16 18:02:41 +00:00
|
|
|
context = xkb_context_new (0);
|
2012-07-16 11:33:35 +00:00
|
|
|
|
2021-08-11 09:01:55 +00:00
|
|
|
map_str = mmap (NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
2013-03-23 22:02:28 +00:00
|
|
|
if (map_str == MAP_FAILED)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return;
|
2015-02-28 03:28:28 +00:00
|
|
|
}
|
2012-07-16 11:33:35 +00:00
|
|
|
|
2018-01-12 12:40:38 +00:00
|
|
|
GDK_DISPLAY_NOTE (keymap->display, INPUT, g_message ("keymap:\n%s", map_str));
|
2016-04-19 16:23:51 +00:00
|
|
|
|
2014-08-25 13:55:22 +00:00
|
|
|
xkb_keymap = xkb_keymap_new_from_string (context, map_str, format, 0);
|
2012-07-16 18:02:41 +00:00
|
|
|
munmap (map_str, size);
|
|
|
|
close (fd);
|
2012-07-16 11:33:35 +00:00
|
|
|
|
2014-08-25 13:55:22 +00:00
|
|
|
if (!xkb_keymap)
|
|
|
|
{
|
|
|
|
g_warning ("Got invalid keymap from compositor, keeping previous/default one");
|
|
|
|
xkb_context_unref (context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (keymap->display, INPUT, print_modifiers (xkb_keymap));
|
2016-04-19 16:43:03 +00:00
|
|
|
|
2014-08-25 13:55:22 +00:00
|
|
|
xkb_keymap_unref (keymap_wayland->xkb_keymap);
|
|
|
|
keymap_wayland->xkb_keymap = xkb_keymap;
|
|
|
|
|
2013-03-23 22:02:28 +00:00
|
|
|
xkb_state_unref (keymap_wayland->xkb_state);
|
|
|
|
keymap_wayland->xkb_state = xkb_state_new (keymap_wayland->xkb_keymap);
|
|
|
|
|
|
|
|
xkb_context_unref (context);
|
2013-04-04 03:45:54 +00:00
|
|
|
|
|
|
|
update_direction (keymap_wayland);
|
2012-07-16 18:02:41 +00:00
|
|
|
}
|
2012-07-16 11:33:35 +00:00
|
|
|
|
2015-02-28 03:28:28 +00:00
|
|
|
struct xkb_keymap *
|
|
|
|
_gdk_wayland_keymap_get_xkb_keymap (GdkKeymap *keymap)
|
2012-07-16 18:02:41 +00:00
|
|
|
{
|
|
|
|
return GDK_WAYLAND_KEYMAP (keymap)->xkb_keymap;
|
2012-07-16 11:33:35 +00:00
|
|
|
}
|
|
|
|
|
2015-02-28 03:28:28 +00:00
|
|
|
struct xkb_state *
|
|
|
|
_gdk_wayland_keymap_get_xkb_state (GdkKeymap *keymap)
|
2011-01-07 17:10:41 +00:00
|
|
|
{
|
2012-07-16 18:16:48 +00:00
|
|
|
return GDK_WAYLAND_KEYMAP (keymap)->xkb_state;
|
2011-01-07 17:10:41 +00:00
|
|
|
}
|
2013-04-06 14:40:56 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gdk_wayland_keymap_key_is_modifier (GdkKeymap *keymap,
|
|
|
|
guint keycode)
|
|
|
|
{
|
|
|
|
struct xkb_keymap *xkb_keymap = GDK_WAYLAND_KEYMAP (keymap)->xkb_keymap;
|
|
|
|
struct xkb_state *xkb_state;
|
|
|
|
gboolean is_modifier;
|
|
|
|
|
|
|
|
is_modifier = FALSE;
|
|
|
|
|
|
|
|
xkb_state = xkb_state_new (xkb_keymap);
|
|
|
|
|
|
|
|
if (xkb_state_update_key (xkb_state, keycode, XKB_KEY_DOWN) & XKB_STATE_MODS_EFFECTIVE)
|
|
|
|
is_modifier = TRUE;
|
|
|
|
|
|
|
|
xkb_state_unref (xkb_state);
|
|
|
|
|
|
|
|
return is_modifier;
|
|
|
|
}
|