1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
36 #include "gdkwayland.h"
38 #include "gdkprivate-wayland.h"
39 #include "gdkinternals.h"
40 #include "gdkkeysprivate.h"
42 #include <xkbcommon/xkbcommon.h>
44 typedef struct _GdkWaylandKeymap GdkWaylandKeymap;
45 typedef struct _GdkWaylandKeymapClass GdkWaylandKeymapClass;
47 struct _GdkWaylandKeymap
49 GdkKeymap parent_instance;
51 struct xkb_keymap *xkb_keymap;
52 struct xkb_state *xkb_state;
55 struct _GdkWaylandKeymapClass
57 GdkKeymapClass parent_class;
60 #define GDK_TYPE_WAYLAND_KEYMAP (_gdk_wayland_keymap_get_type ())
61 #define GDK_WAYLAND_KEYMAP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WAYLAND_KEYMAP, GdkWaylandKeymap))
62 #define GDK_IS_WAYLAND_KEYMAP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_WAYLAND_KEYMAP))
64 G_DEFINE_TYPE (GdkWaylandKeymap, _gdk_wayland_keymap, GDK_TYPE_KEYMAP)
67 gdk_wayland_keymap_finalize (GObject *object)
69 G_OBJECT_CLASS (_gdk_wayland_keymap_parent_class)->finalize (object);
73 gdk_wayland_keymap_get_direction (GdkKeymap *keymap)
75 return PANGO_DIRECTION_NEUTRAL;
79 gdk_wayland_keymap_have_bidi_layouts (GdkKeymap *keymap)
85 gdk_wayland_keymap_get_caps_lock_state (GdkKeymap *keymap)
87 return xkb_state_led_name_is_active (GDK_WAYLAND_KEYMAP (keymap)->xkb_state,
92 gdk_wayland_keymap_get_num_lock_state (GdkKeymap *keymap)
94 return xkb_state_led_name_is_active (GDK_WAYLAND_KEYMAP (keymap)->xkb_state,
99 gdk_wayland_keymap_get_entries_for_keyval (GdkKeymap *keymap,
108 *keys = g_new0 (GdkKeymapKey, 1);
109 (*keys)->keycode = keyval;
116 gdk_wayland_keymap_get_entries_for_keycode (GdkKeymap *keymap,
117 guint hardware_keycode,
126 *keys = g_new0 (GdkKeymapKey, 1);
127 (*keys)->keycode = hardware_keycode;
131 *keyvals = g_new0 (guint, 1);
132 (*keyvals)[0] = hardware_keycode;
138 gdk_wayland_keymap_lookup_key (GdkKeymap *keymap,
139 const GdkKeymapKey *key)
145 gdk_wayland_keymap_translate_keyboard_state (GdkKeymap *keymap,
146 guint hardware_keycode,
147 GdkModifierType state,
150 gint *effective_group,
152 GdkModifierType *consumed_modifiers)
154 g_return_val_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap), FALSE);
155 g_return_val_if_fail (group < 4, FALSE);
158 *keyval = hardware_keycode;
160 *effective_group = 0;
163 if (consumed_modifiers)
164 *consumed_modifiers = 0;
170 gdk_wayland_keymap_add_virtual_modifiers (GdkKeymap *keymap,
171 GdkModifierType *state)
177 gdk_wayland_keymap_map_virtual_modifiers (GdkKeymap *keymap,
178 GdkModifierType *state)
184 _gdk_wayland_keymap_class_init (GdkWaylandKeymapClass *klass)
186 GObjectClass *object_class = G_OBJECT_CLASS (klass);
187 GdkKeymapClass *keymap_class = GDK_KEYMAP_CLASS (klass);
189 object_class->finalize = gdk_wayland_keymap_finalize;
191 keymap_class->get_direction = gdk_wayland_keymap_get_direction;
192 keymap_class->have_bidi_layouts = gdk_wayland_keymap_have_bidi_layouts;
193 keymap_class->get_caps_lock_state = gdk_wayland_keymap_get_caps_lock_state;
194 keymap_class->get_num_lock_state = gdk_wayland_keymap_get_num_lock_state;
195 keymap_class->get_entries_for_keyval = gdk_wayland_keymap_get_entries_for_keyval;
196 keymap_class->get_entries_for_keycode = gdk_wayland_keymap_get_entries_for_keycode;
197 keymap_class->lookup_key = gdk_wayland_keymap_lookup_key;
198 keymap_class->translate_keyboard_state = gdk_wayland_keymap_translate_keyboard_state;
199 keymap_class->add_virtual_modifiers = gdk_wayland_keymap_add_virtual_modifiers;
200 keymap_class->map_virtual_modifiers = gdk_wayland_keymap_map_virtual_modifiers;
204 _gdk_wayland_keymap_init (GdkWaylandKeymap *keymap)
209 _gdk_wayland_keymap_new ()
211 GdkWaylandKeymap *keymap;
212 struct xkb_context *context;
213 struct xkb_rule_names names;
215 keymap = g_object_new (_gdk_wayland_keymap_get_type(), NULL);
217 context = xkb_context_new (0);
219 names.rules = "evdev";
220 names.model = "pc105";
224 keymap->xkb_keymap = xkb_keymap_new_from_names (context, &names, 0);
225 keymap->xkb_state = xkb_state_new (keymap->xkb_keymap);
226 xkb_context_unref (context);
228 return GDK_KEYMAP (keymap);
232 _gdk_wayland_keymap_new_from_fd (uint32_t format,
233 uint32_t fd, uint32_t size)
235 GdkWaylandKeymap *keymap;
236 struct xkb_context *context;
239 keymap = g_object_new (_gdk_wayland_keymap_get_type(), NULL);
241 context = xkb_context_new (0);
243 map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
244 if (map_str == MAP_FAILED) {
249 keymap->xkb_keymap = xkb_keymap_new_from_string (context, map_str, format, 0);
250 munmap (map_str, size);
252 keymap->xkb_state = xkb_state_new (keymap->xkb_keymap);
253 xkb_context_unref (context);
255 return GDK_KEYMAP (keymap);
258 struct xkb_keymap *_gdk_wayland_keymap_get_xkb_keymap (GdkKeymap *keymap)
260 return GDK_WAYLAND_KEYMAP (keymap)->xkb_keymap;
263 struct xkb_state *_gdk_wayland_keymap_get_xkb_state (GdkKeymap *keymap)
265 return GDK_WAYLAND_KEYMAP (keymap)->xkb_state;