diff options
author | 2019-01-14 08:57:20 +0100 | |
---|---|---|
committer | 2019-01-14 08:57:20 +0100 | |
commit | 89ad3f2bbbb6f5f367387992eea5d5c6f7fa7642 (patch) | |
tree | 2ef2485e9a103b9850219b7cf6375e48b20b72b5 /swaylock/seat.c | |
parent | Remove WIP from README.md (diff) | |
parent | Split swaylock into separate project (diff) | |
download | sway-89ad3f2bbbb6f5f367387992eea5d5c6f7fa7642.tar.gz sway-89ad3f2bbbb6f5f367387992eea5d5c6f7fa7642.tar.zst sway-89ad3f2bbbb6f5f367387992eea5d5c6f7fa7642.zip |
Merge pull request #3417 from swaywm/remove-swaylock
Split swaylock into separate project
Diffstat (limited to 'swaylock/seat.c')
-rw-r--r-- | swaylock/seat.c | 178 |
1 files changed, 0 insertions, 178 deletions
diff --git a/swaylock/seat.c b/swaylock/seat.c deleted file mode 100644 index f0b1385e..00000000 --- a/swaylock/seat.c +++ /dev/null | |||
@@ -1,178 +0,0 @@ | |||
1 | #include <assert.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <sys/mman.h> | ||
4 | #include <unistd.h> | ||
5 | #include <wlr/util/log.h> | ||
6 | #include <xkbcommon/xkbcommon.h> | ||
7 | #include "swaylock/swaylock.h" | ||
8 | #include "swaylock/seat.h" | ||
9 | |||
10 | static void keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, | ||
11 | uint32_t format, int32_t fd, uint32_t size) { | ||
12 | struct swaylock_state *state = data; | ||
13 | if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { | ||
14 | close(fd); | ||
15 | wlr_log(WLR_ERROR, "Unknown keymap format %d, aborting", format); | ||
16 | exit(1); | ||
17 | } | ||
18 | char *map_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); | ||
19 | if (map_shm == MAP_FAILED) { | ||
20 | close(fd); | ||
21 | wlr_log(WLR_ERROR, "Unable to initialize keymap shm, aborting"); | ||
22 | exit(1); | ||
23 | } | ||
24 | struct xkb_keymap *keymap = xkb_keymap_new_from_string( | ||
25 | state->xkb.context, map_shm, XKB_KEYMAP_FORMAT_TEXT_V1, 0); | ||
26 | munmap(map_shm, size); | ||
27 | close(fd); | ||
28 | assert(keymap); | ||
29 | struct xkb_state *xkb_state = xkb_state_new(keymap); | ||
30 | assert(xkb_state); | ||
31 | xkb_keymap_unref(state->xkb.keymap); | ||
32 | xkb_state_unref(state->xkb.state); | ||
33 | state->xkb.keymap = keymap; | ||
34 | state->xkb.state = xkb_state; | ||
35 | } | ||
36 | |||
37 | static void keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, | ||
38 | uint32_t serial, struct wl_surface *surface, struct wl_array *keys) { | ||
39 | // Who cares | ||
40 | } | ||
41 | |||
42 | static void keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, | ||
43 | uint32_t serial, struct wl_surface *surface) { | ||
44 | // Who cares | ||
45 | } | ||
46 | |||
47 | static void keyboard_key(void *data, struct wl_keyboard *wl_keyboard, | ||
48 | uint32_t serial, uint32_t time, uint32_t key, uint32_t _key_state) { | ||
49 | struct swaylock_state *state = data; | ||
50 | enum wl_keyboard_key_state key_state = _key_state; | ||
51 | xkb_keysym_t sym = xkb_state_key_get_one_sym(state->xkb.state, key + 8); | ||
52 | uint32_t keycode = key_state == WL_KEYBOARD_KEY_STATE_PRESSED ? | ||
53 | key + 8 : 0; | ||
54 | uint32_t codepoint = xkb_state_key_get_utf32(state->xkb.state, keycode); | ||
55 | if (key_state == WL_KEYBOARD_KEY_STATE_PRESSED) { | ||
56 | swaylock_handle_key(state, sym, codepoint); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | static void keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, | ||
61 | uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, | ||
62 | uint32_t mods_locked, uint32_t group) { | ||
63 | struct swaylock_state *state = data; | ||
64 | xkb_state_update_mask(state->xkb.state, | ||
65 | mods_depressed, mods_latched, mods_locked, 0, 0, group); | ||
66 | int caps_lock = xkb_state_mod_name_is_active(state->xkb.state, | ||
67 | XKB_MOD_NAME_CAPS, XKB_STATE_MODS_LOCKED); | ||
68 | if (caps_lock != state->xkb.caps_lock) { | ||
69 | state->xkb.caps_lock = caps_lock; | ||
70 | damage_state(state); | ||
71 | } | ||
72 | state->xkb.control = xkb_state_mod_name_is_active(state->xkb.state, | ||
73 | XKB_MOD_NAME_CTRL, | ||
74 | XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); | ||
75 | |||
76 | } | ||
77 | |||
78 | static void keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, | ||
79 | int32_t rate, int32_t delay) { | ||
80 | // TODO | ||
81 | } | ||
82 | |||
83 | static const struct wl_keyboard_listener keyboard_listener = { | ||
84 | .keymap = keyboard_keymap, | ||
85 | .enter = keyboard_enter, | ||
86 | .leave = keyboard_leave, | ||
87 | .key = keyboard_key, | ||
88 | .modifiers = keyboard_modifiers, | ||
89 | .repeat_info = keyboard_repeat_info, | ||
90 | }; | ||
91 | |||
92 | static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | ||
93 | uint32_t serial, struct wl_surface *surface, | ||
94 | wl_fixed_t surface_x, wl_fixed_t surface_y) { | ||
95 | wl_pointer_set_cursor(wl_pointer, serial, NULL, 0, 0); | ||
96 | } | ||
97 | |||
98 | static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, | ||
99 | uint32_t serial, struct wl_surface *surface) { | ||
100 | // Who cares | ||
101 | } | ||
102 | |||
103 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, | ||
104 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { | ||
105 | // Who cares | ||
106 | } | ||
107 | |||
108 | static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | ||
109 | uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { | ||
110 | // Who cares | ||
111 | } | ||
112 | |||
113 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | ||
114 | uint32_t time, uint32_t axis, wl_fixed_t value) { | ||
115 | // Who cares | ||
116 | } | ||
117 | |||
118 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { | ||
119 | // Who cares | ||
120 | } | ||
121 | |||
122 | static void wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer, | ||
123 | uint32_t axis_source) { | ||
124 | // Who cares | ||
125 | } | ||
126 | |||
127 | static void wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer, | ||
128 | uint32_t time, uint32_t axis) { | ||
129 | // Who cares | ||
130 | } | ||
131 | |||
132 | static void wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer, | ||
133 | uint32_t axis, int32_t discrete) { | ||
134 | // Who cares | ||
135 | } | ||
136 | |||
137 | static const struct wl_pointer_listener pointer_listener = { | ||
138 | .enter = wl_pointer_enter, | ||
139 | .leave = wl_pointer_leave, | ||
140 | .motion = wl_pointer_motion, | ||
141 | .button = wl_pointer_button, | ||
142 | .axis = wl_pointer_axis, | ||
143 | .frame = wl_pointer_frame, | ||
144 | .axis_source = wl_pointer_axis_source, | ||
145 | .axis_stop = wl_pointer_axis_stop, | ||
146 | .axis_discrete = wl_pointer_axis_discrete, | ||
147 | }; | ||
148 | |||
149 | static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, | ||
150 | enum wl_seat_capability caps) { | ||
151 | struct swaylock_seat *seat = data; | ||
152 | if (seat->pointer) { | ||
153 | wl_pointer_release(seat->pointer); | ||
154 | seat->pointer = NULL; | ||
155 | } | ||
156 | if (seat->keyboard) { | ||
157 | wl_keyboard_release(seat->keyboard); | ||
158 | seat->keyboard = NULL; | ||
159 | } | ||
160 | if ((caps & WL_SEAT_CAPABILITY_POINTER)) { | ||
161 | seat->pointer = wl_seat_get_pointer(wl_seat); | ||
162 | wl_pointer_add_listener(seat->pointer, &pointer_listener, NULL); | ||
163 | } | ||
164 | if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) { | ||
165 | seat->keyboard = wl_seat_get_keyboard(wl_seat); | ||
166 | wl_keyboard_add_listener(seat->keyboard, &keyboard_listener, seat->state); | ||
167 | } | ||
168 | } | ||
169 | |||
170 | static void seat_handle_name(void *data, struct wl_seat *wl_seat, | ||
171 | const char *name) { | ||
172 | // Who cares | ||
173 | } | ||
174 | |||
175 | const struct wl_seat_listener seat_listener = { | ||
176 | .capabilities = seat_handle_capabilities, | ||
177 | .name = seat_handle_name, | ||
178 | }; | ||