keyrouter: Replace get_keyroutes() with notify_key()
[platform/core/uifw/libds-tizen.git] / src / keyrouter / keyrouter.h
1 #ifndef DS_TIZEN_KEYROUTER_H
2 #define DS_TIZEN_KEYROUTER_H
3
4 #include <stdbool.h>
5 #include <wayland-server.h>
6 #include <tizen-extension-server-protocol.h>
7
8 #include "libds-tizen/keyrouter.h"
9
10 #define KEYROUTER_MAX_KEYS 512
11
12 /**
13  * Keyroute mode of keyroutes returned by keyrouter_grab_get_keyroutes()
14  * for a given keycode.
15  */
16 enum keyroute_mode {
17     /**
18      * The keycode is not under any keyroute mode.
19      * The compositor may send a keycode to a focused wayland cliet as usual.
20      */
21     KEYROUTE_MODE_NONE,
22     /**
23      * Exclusive mode means that a given keycode is required to be sent
24      * exclusively to wayland clients of returned keyroutes. So the compositor
25      * must not send this keycode to any other wayland clients except for
26      * returned wayland clients.
27      */
28     KEYROUTE_MODE_EXCLUSIVE,
29     /**
30      * The keycode is required to be shared with returned wayland clients.
31      * The compositor must send the keycode not only to returned wayland
32      * clients, but also to a focused wayland client.
33      */
34     KEYROUTE_MODE_SHARED,
35 };
36
37 struct keyroute_info
38 {
39     struct wl_client *wl_client;
40     struct wl_list link;
41 };
42
43 struct keyrouter_grabbed
44 {
45     struct {
46         struct wl_list excl; // keyroute_info::link
47         struct wl_list or_excl; // keyroute_info::link
48         struct wl_list top; // keyroute_info::link
49         struct wl_list shared; // keyroute_info::link
50     } grab;
51
52     struct wl_list pressed;
53 };
54
55 struct keyrouter_grab
56 {
57     struct keyrouter_grabbed hard_keys[KEYROUTER_MAX_KEYS];
58 };
59
60 struct keyrouter_key_options
61 {
62     bool enabled;
63     bool no_privilege;
64 };
65
66 struct ds_tizen_keyrouter
67 {
68     struct wl_global *global;
69
70     struct wl_list clients;
71
72     struct wl_listener display_destroy;
73
74     struct {
75         struct wl_signal destroy;
76     } events;
77
78     struct keyrouter_key_options *opts;
79
80     struct keyrouter_grab keygrab;
81
82     bool security_initialized;
83 };
84
85 struct keyrouter_client
86 {
87     struct ds_tizen_keyrouter *keyrouter;
88
89     struct wl_resource *resource;
90     struct wl_client *wl_client;
91
92     bool privileged;
93
94     struct wl_list link; // ds_tizen_keyrouter::clients
95 };
96
97 struct ds_tizen_grab_data
98 {
99         int key;
100         int mode;
101         int err;
102 };
103
104 struct ds_tizen_ungrab_data
105 {
106         int key;
107         int err;
108 };
109
110 void keyrouter_grab_init(struct keyrouter_grab *keygrab);
111
112 void keyrouter_grab_finish(struct keyrouter_grab *keygrab);
113
114 int keyrouter_grab_grab_key(struct keyrouter_grab *keygrab, int mode,
115         int keycode, struct wl_client *wl_client);
116
117 void keyrouter_grab_ungrab_key(struct keyrouter_grab *keygrab, int mode,
118         int keycode, struct wl_client *wl_client);
119
120 enum keyroute_mode
121 keyrouter_grab_get_keyroutes(struct keyrouter_grab *keygrab, int keycode,
122         struct wl_client *topmost_client, struct wl_array *keyroutes);
123
124 #endif