2019-01-10 10:13:20 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Red Hat
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Author: Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*/
|
|
|
|
|
2019-03-29 17:03:27 -04:00
|
|
|
#include "config.h"
|
2019-01-10 10:13:20 -05:00
|
|
|
|
2019-03-29 17:03:27 -04:00
|
|
|
#include "backends/native/meta-keymap-native.h"
|
2019-10-04 15:57:26 -04:00
|
|
|
#include "backends/native/meta-seat-native.h"
|
2019-01-10 10:13:20 -05:00
|
|
|
|
|
|
|
static const char *option_xkb_layout = "us";
|
|
|
|
static const char *option_xkb_variant = "";
|
|
|
|
static const char *option_xkb_options = "";
|
|
|
|
|
2019-03-29 17:03:27 -04:00
|
|
|
typedef struct _MetaKeymapNative MetaKeymapNative;
|
2019-01-10 10:13:20 -05:00
|
|
|
|
2019-03-29 17:03:27 -04:00
|
|
|
struct _MetaKeymapNative
|
2019-01-10 10:13:20 -05:00
|
|
|
{
|
|
|
|
ClutterKeymap parent_instance;
|
|
|
|
|
|
|
|
struct xkb_keymap *keymap;
|
|
|
|
};
|
|
|
|
|
2019-03-29 17:03:27 -04:00
|
|
|
G_DEFINE_TYPE (MetaKeymapNative, meta_keymap_native,
|
2019-01-10 10:13:20 -05:00
|
|
|
CLUTTER_TYPE_KEYMAP)
|
|
|
|
|
|
|
|
static void
|
2019-03-29 17:03:27 -04:00
|
|
|
meta_keymap_native_finalize (GObject *object)
|
2019-01-10 10:13:20 -05:00
|
|
|
{
|
2019-03-29 17:03:27 -04:00
|
|
|
MetaKeymapNative *keymap = META_KEYMAP_NATIVE (object);
|
2019-01-10 10:13:20 -05:00
|
|
|
|
|
|
|
xkb_keymap_unref (keymap->keymap);
|
|
|
|
|
2019-03-29 17:03:27 -04:00
|
|
|
G_OBJECT_CLASS (meta_keymap_native_parent_class)->finalize (object);
|
2019-01-10 10:13:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-03-29 17:03:27 -04:00
|
|
|
meta_keymap_native_get_num_lock_state (ClutterKeymap *keymap)
|
2019-01-10 10:13:20 -05:00
|
|
|
{
|
|
|
|
struct xkb_state *xkb_state;
|
2019-10-04 09:44:27 -04:00
|
|
|
ClutterSeat *seat;
|
2019-01-10 10:13:20 -05:00
|
|
|
|
2019-10-04 09:44:27 -04:00
|
|
|
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
|
|
|
|
xkb_state = meta_seat_native_get_xkb_state (META_SEAT_NATIVE (seat));
|
2019-01-10 10:13:20 -05:00
|
|
|
|
|
|
|
return xkb_state_mod_name_is_active (xkb_state,
|
|
|
|
XKB_MOD_NAME_NUM,
|
2019-10-07 13:13:23 -04:00
|
|
|
XKB_STATE_MODS_LATCHED |
|
2019-01-10 10:13:20 -05:00
|
|
|
XKB_STATE_MODS_LOCKED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-03-29 17:03:27 -04:00
|
|
|
meta_keymap_native_get_caps_lock_state (ClutterKeymap *keymap)
|
2019-01-10 10:13:20 -05:00
|
|
|
{
|
|
|
|
struct xkb_state *xkb_state;
|
2019-10-04 09:44:27 -04:00
|
|
|
ClutterSeat *seat;
|
2019-01-10 10:13:20 -05:00
|
|
|
|
2019-10-04 09:44:27 -04:00
|
|
|
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
|
|
|
|
xkb_state = meta_seat_native_get_xkb_state (META_SEAT_NATIVE (seat));
|
2019-01-10 10:13:20 -05:00
|
|
|
|
|
|
|
return xkb_state_mod_name_is_active (xkb_state,
|
|
|
|
XKB_MOD_NAME_CAPS,
|
2019-10-07 13:13:23 -04:00
|
|
|
XKB_STATE_MODS_LATCHED |
|
2019-01-10 10:13:20 -05:00
|
|
|
XKB_STATE_MODS_LOCKED);
|
|
|
|
}
|
|
|
|
|
2019-10-01 07:51:12 -04:00
|
|
|
static PangoDirection
|
|
|
|
meta_keymap_native_get_direction (ClutterKeymap *keymap)
|
|
|
|
{
|
|
|
|
return PANGO_DIRECTION_NEUTRAL;
|
|
|
|
}
|
|
|
|
|
2019-01-10 10:13:20 -05:00
|
|
|
static void
|
2019-03-29 17:03:27 -04:00
|
|
|
meta_keymap_native_class_init (MetaKeymapNativeClass *klass)
|
2019-01-10 10:13:20 -05:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterKeymapClass *keymap_class = CLUTTER_KEYMAP_CLASS (klass);
|
|
|
|
|
2019-03-29 17:03:27 -04:00
|
|
|
object_class->finalize = meta_keymap_native_finalize;
|
2019-01-10 10:13:20 -05:00
|
|
|
|
2019-03-29 17:03:27 -04:00
|
|
|
keymap_class->get_num_lock_state = meta_keymap_native_get_num_lock_state;
|
|
|
|
keymap_class->get_caps_lock_state = meta_keymap_native_get_caps_lock_state;
|
2019-10-01 07:51:12 -04:00
|
|
|
keymap_class->get_direction = meta_keymap_native_get_direction;
|
2019-01-10 10:13:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-29 17:03:27 -04:00
|
|
|
meta_keymap_native_init (MetaKeymapNative *keymap)
|
2019-01-10 10:13:20 -05:00
|
|
|
{
|
|
|
|
struct xkb_context *ctx;
|
|
|
|
struct xkb_rule_names names;
|
|
|
|
|
|
|
|
names.rules = "evdev";
|
|
|
|
names.model = "pc105";
|
|
|
|
names.layout = option_xkb_layout;
|
|
|
|
names.variant = option_xkb_variant;
|
|
|
|
names.options = option_xkb_options;
|
|
|
|
|
|
|
|
ctx = xkb_context_new (0);
|
|
|
|
g_assert (ctx);
|
|
|
|
keymap->keymap = xkb_keymap_new_from_names (ctx, &names, 0);
|
|
|
|
xkb_context_unref (ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-03-29 17:03:27 -04:00
|
|
|
meta_keymap_native_set_keyboard_map (MetaKeymapNative *keymap,
|
|
|
|
struct xkb_keymap *xkb_keymap)
|
2019-01-10 10:13:20 -05:00
|
|
|
{
|
|
|
|
if (keymap->keymap)
|
|
|
|
xkb_keymap_unref (keymap->keymap);
|
|
|
|
keymap->keymap = xkb_keymap_ref (xkb_keymap);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct xkb_keymap *
|
2019-03-29 17:03:27 -04:00
|
|
|
meta_keymap_native_get_keyboard_map (MetaKeymapNative *keymap)
|
2019-01-10 10:13:20 -05:00
|
|
|
{
|
|
|
|
return keymap->keymap;
|
|
|
|
}
|