1 /*
2  * Wayland Support
3  *
4  * Copyright (C) 2013 Intel Corporation
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19  * 02111-1307, USA.
20  */
21 
22 /*
23  * Copyright © 2008-2011 Kristian Høgsberg
24  * Copyright © 2012 Collabora, Ltd.
25  *
26  * Permission to use, copy, modify, distribute, and sell this software and
27  * its documentation for any purpose is hereby granted without fee, provided
28  * that the above copyright notice appear in all copies and that both that
29  * copyright notice and this permission notice appear in supporting
30  * documentation, and that the name of the copyright holders not be used in
31  * advertising or publicity pertaining to distribution of the software
32  * without specific, written prior permission.  The copyright holders make
33  * no representations about the suitability of this software for any
34  * purpose.  It is provided "as is" without express or implied warranty.
35  *
36  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
37  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
38  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
39  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
40  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
41  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
42  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43  */
44 
45 #ifndef META_WAYLAND_KEYBOARD_H
46 #define META_WAYLAND_KEYBOARD_H
47 
48 #include <wayland-server.h>
49 #include <xkbcommon/xkbcommon.h>
50 
51 #include "clutter/clutter.h"
52 #include "core/meta-anonymous-file.h"
53 #include "wayland/meta-wayland-types.h"
54 
55 #define META_TYPE_WAYLAND_KEYBOARD (meta_wayland_keyboard_get_type ())
56 G_DECLARE_FINAL_TYPE (MetaWaylandKeyboard, meta_wayland_keyboard,
57                       META, WAYLAND_KEYBOARD,
58                       MetaWaylandInputDevice)
59 
60 struct _MetaWaylandKeyboardGrabInterface
61 {
62   gboolean (*key)       (MetaWaylandKeyboardGrab *grab,
63                          const ClutterEvent      *event);
64   void     (*modifiers) (MetaWaylandKeyboardGrab *grab,
65                          ClutterModifierType      modifiers);
66 };
67 
68 struct _MetaWaylandKeyboardGrab
69 {
70   const MetaWaylandKeyboardGrabInterface *interface;
71   MetaWaylandKeyboard *keyboard;
72 };
73 
74 typedef struct
75 {
76   struct xkb_keymap *keymap;
77   struct xkb_state *state;
78   MetaAnonymousFile *keymap_rofile;
79 } MetaWaylandXkbInfo;
80 
81 struct _MetaWaylandKeyboard
82 {
83   MetaWaylandInputDevice parent;
84 
85   struct wl_list resource_list;
86   struct wl_list focus_resource_list;
87 
88   MetaWaylandSurface *focus_surface;
89   struct wl_listener focus_surface_listener;
90   uint32_t focus_serial;
91 
92   uint32_t key_down_keycode;
93   uint32_t key_down_serial;
94 
95   uint32_t key_up_keycode;
96   uint32_t key_up_serial;
97 
98   MetaWaylandXkbInfo xkb_info;
99   enum xkb_state_component mods_changed;
100   xkb_mod_mask_t kbd_a11y_latched_mods;
101   xkb_mod_mask_t kbd_a11y_locked_mods;
102 
103   MetaWaylandKeyboardGrab *grab;
104   MetaWaylandKeyboardGrab default_grab;
105 
106   GSettings *settings;
107 };
108 
109 void meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard);
110 
111 void meta_wayland_keyboard_disable (MetaWaylandKeyboard *keyboard);
112 
113 void meta_wayland_keyboard_update (MetaWaylandKeyboard *keyboard,
114                                    const ClutterKeyEvent *event);
115 
116 gboolean meta_wayland_keyboard_handle_event (MetaWaylandKeyboard *keyboard,
117                                              const ClutterKeyEvent *event);
118 void meta_wayland_keyboard_update_key_state (MetaWaylandKeyboard *compositor,
119                                              char                *key_vector,
120                                              int                  key_vector_len,
121                                              int                  offset);
122 
123 void meta_wayland_keyboard_set_focus (MetaWaylandKeyboard *keyboard,
124                                       MetaWaylandSurface *surface);
125 
126 struct wl_client * meta_wayland_keyboard_get_focus_client (MetaWaylandKeyboard *keyboard);
127 
128 void meta_wayland_keyboard_create_new_resource (MetaWaylandKeyboard *keyboard,
129                                                 struct wl_client    *client,
130                                                 struct wl_resource  *seat_resource,
131                                                 uint32_t id);
132 
133 gboolean meta_wayland_keyboard_can_popup (MetaWaylandKeyboard *keyboard,
134                                           uint32_t             serial);
135 
136 void meta_wayland_keyboard_start_grab (MetaWaylandKeyboard     *keyboard,
137                                        MetaWaylandKeyboardGrab *grab);
138 void meta_wayland_keyboard_end_grab   (MetaWaylandKeyboard     *keyboard);
139 
140 #endif /* META_WAYLAND_KEYBOARD_H */
141