diff options
-rw-r--r-- | include/input_state.h | 8 | ||||
-rw-r--r-- | sway/handlers.c | 25 | ||||
-rw-r--r-- | sway/input_state.c | 101 |
3 files changed, 74 insertions, 60 deletions
diff --git a/include/input_state.h b/include/input_state.h index 747a3563..4ab93cd6 100644 --- a/include/input_state.h +++ b/include/input_state.h | |||
@@ -30,11 +30,11 @@ enum pointer_values { | |||
30 | 30 | ||
31 | enum pointer_mode { | 31 | enum pointer_mode { |
32 | // Target | 32 | // Target |
33 | M_FLOATING = 1 << 0, | 33 | M_FLOATING = 1, |
34 | M_TILING = 1 << 1, | 34 | M_TILING = 2, |
35 | // Action | 35 | // Action |
36 | M_DRAGGING = 1 << 2, | 36 | M_DRAGGING = 4, |
37 | M_RESIZING = 1 << 3, | 37 | M_RESIZING = 8, |
38 | }; | 38 | }; |
39 | 39 | ||
40 | struct pointer_button_state { | 40 | struct pointer_button_state { |
diff --git a/sway/handlers.c b/sway/handlers.c index d26ce5f3..0bb4f613 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -17,6 +17,12 @@ | |||
17 | #include "input_state.h" | 17 | #include "input_state.h" |
18 | #include "resize.h" | 18 | #include "resize.h" |
19 | 19 | ||
20 | // Event should be sent to client | ||
21 | #define EVENT_PASSTHROUGH false | ||
22 | |||
23 | // Event handled by sway and should not be sent to client | ||
24 | #define EVENT_HANDLED true | ||
25 | |||
20 | static bool pointer_test(swayc_t *view, void *_origin) { | 26 | static bool pointer_test(swayc_t *view, void *_origin) { |
21 | const struct mouse_origin *origin = _origin; | 27 | const struct mouse_origin *origin = _origin; |
22 | // Determine the output that the view is under | 28 | // Determine the output that the view is under |
@@ -276,7 +282,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
276 | uint32_t key, uint32_t sym, enum wlc_key_state state) { | 282 | uint32_t key, uint32_t sym, enum wlc_key_state state) { |
277 | 283 | ||
278 | if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { | 284 | if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { |
279 | return false; | 285 | return EVENT_PASSTHROUGH; |
280 | } | 286 | } |
281 | 287 | ||
282 | // reset pointer mode on keypress | 288 | // reset pointer mode on keypress |
@@ -289,7 +295,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
289 | if (sym < 70000 /* bullshit made up number */) { | 295 | if (sym < 70000 /* bullshit made up number */) { |
290 | if (!isalnum(sym) && sym != ' ' && sym != XKB_KEY_Escape && sym != XKB_KEY_Tab) { | 296 | if (!isalnum(sym) && sym != ' ' && sym != XKB_KEY_Escape && sym != XKB_KEY_Tab) { |
291 | // God fucking dammit | 297 | // God fucking dammit |
292 | return false; | 298 | return EVENT_PASSTHROUGH; |
293 | } | 299 | } |
294 | } | 300 | } |
295 | 301 | ||
@@ -320,14 +326,14 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
320 | if (match) { | 326 | if (match) { |
321 | if (state == WLC_KEY_STATE_PRESSED) { | 327 | if (state == WLC_KEY_STATE_PRESSED) { |
322 | handle_command(config, binding->command); | 328 | handle_command(config, binding->command); |
323 | return true; | 329 | return EVENT_HANDLED; |
324 | } else if (state == WLC_KEY_STATE_RELEASED) { | 330 | } else if (state == WLC_KEY_STATE_RELEASED) { |
325 | // TODO: --released | 331 | // TODO: --released |
326 | } | 332 | } |
327 | } | 333 | } |
328 | } | 334 | } |
329 | } | 335 | } |
330 | return false; | 336 | return EVENT_PASSTHROUGH; |
331 | } | 337 | } |
332 | 338 | ||
333 | static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) { | 339 | static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) { |
@@ -351,13 +357,12 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
351 | set_focused_container(pointer_state.view); | 357 | set_focused_container(pointer_state.view); |
352 | } | 358 | } |
353 | } | 359 | } |
354 | return false; | 360 | return EVENT_PASSTHROUGH; |
355 | } | 361 | } |
356 | 362 | ||
357 | 363 | ||
358 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, | 364 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, |
359 | uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { | 365 | uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { |
360 | enum { DONT_SEND_CLICK = true, SEND_CLICK = false }; | ||
361 | 366 | ||
362 | // Update view pointer is on | 367 | // Update view pointer is on |
363 | pointer_state.view = container_under_pointer(); | 368 | pointer_state.view = container_under_pointer(); |
@@ -412,7 +417,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
412 | 417 | ||
413 | // dont change focus or mode if fullscreen | 418 | // dont change focus or mode if fullscreen |
414 | if (swayc_is_fullscreen(focused)) { | 419 | if (swayc_is_fullscreen(focused)) { |
415 | return SEND_CLICK; | 420 | return EVENT_PASSTHROUGH; |
416 | } | 421 | } |
417 | 422 | ||
418 | // set pointer mode | 423 | // set pointer mode |
@@ -421,12 +426,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
421 | 426 | ||
422 | // Return if mode has been set | 427 | // Return if mode has been set |
423 | if (pointer_state.mode) { | 428 | if (pointer_state.mode) { |
424 | return DONT_SEND_CLICK; | 429 | return EVENT_HANDLED; |
425 | } | 430 | } |
426 | 431 | ||
427 | // Always send mouse release | 432 | // Always send mouse release |
428 | if (state == WLC_BUTTON_STATE_RELEASED) { | 433 | if (state == WLC_BUTTON_STATE_RELEASED) { |
429 | return SEND_CLICK; | 434 | return EVENT_PASSTHROUGH; |
430 | } | 435 | } |
431 | 436 | ||
432 | // Check whether to change focus | 437 | // Check whether to change focus |
@@ -448,7 +453,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
448 | } | 453 | } |
449 | 454 | ||
450 | // Finally send click | 455 | // Finally send click |
451 | return SEND_CLICK; | 456 | return EVENT_PASSTHROUGH; |
452 | } | 457 | } |
453 | 458 | ||
454 | static void handle_wlc_ready(void) { | 459 | static void handle_wlc_ready(void) { |
diff --git a/sway/input_state.c b/sway/input_state.c index 8450fe7a..acf90d75 100644 --- a/sway/input_state.c +++ b/sway/input_state.c | |||
@@ -56,23 +56,24 @@ static struct mode_state { | |||
56 | // initial view state | 56 | // initial view state |
57 | double x, y, w, h; | 57 | double x, y, w, h; |
58 | swayc_t *ptr; | 58 | swayc_t *ptr; |
59 | // containers resized with tiling resize | 59 | // Containers used for resizing horizontally |
60 | struct { | 60 | struct { |
61 | double x, w; | 61 | double w; |
62 | swayc_t *ptr; | 62 | swayc_t *ptr; |
63 | struct { | 63 | struct { |
64 | double x, w; | 64 | double w; |
65 | swayc_t *ptr; | 65 | swayc_t *ptr; |
66 | } sib; | 66 | } parent; |
67 | } lr; | 67 | } horiz; |
68 | // Containers used for resizing vertically | ||
68 | struct { | 69 | struct { |
69 | double y, h; | 70 | double h; |
70 | swayc_t *ptr; | 71 | swayc_t *ptr; |
71 | struct { | 72 | struct { |
72 | double y, h; | 73 | double h; |
73 | swayc_t *ptr; | 74 | swayc_t *ptr; |
74 | } sib; | 75 | } parent; |
75 | } tb; | 76 | } vert; |
76 | } initial; | 77 | } initial; |
77 | 78 | ||
78 | static struct { | 79 | static struct { |
@@ -92,23 +93,19 @@ static void set_initial_view(swayc_t *view) { | |||
92 | 93 | ||
93 | static void set_initial_sibling(void) { | 94 | static void set_initial_sibling(void) { |
94 | bool reset = true; | 95 | bool reset = true; |
95 | if ((initial.lr.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) { | 96 | if ((initial.horiz.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) { |
96 | initial.lr.x = initial.lr.ptr->x; | 97 | initial.horiz.w = initial.horiz.ptr->width; |
97 | initial.lr.w = initial.lr.ptr->width; | 98 | initial.horiz.parent.ptr = get_swayc_in_direction(initial.horiz.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT); |
98 | initial.lr.sib.ptr = get_swayc_in_direction(initial.lr.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT); | 99 | initial.horiz.parent.w = initial.horiz.parent.ptr->width; |
99 | initial.lr.sib.x = initial.lr.sib.ptr->x; | ||
100 | initial.lr.sib.w = initial.lr.sib.ptr->width; | ||
101 | reset = false; | 100 | reset = false; |
102 | } | 101 | } |
103 | if ((initial.tb.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) { | 102 | if ((initial.vert.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) { |
104 | initial.tb.y = initial.tb.ptr->y; | 103 | initial.vert.h = initial.vert.ptr->height; |
105 | initial.tb.h = initial.tb.ptr->height; | 104 | initial.vert.parent.ptr = get_swayc_in_direction(initial.vert.ptr, lock.top ? MOVE_UP : MOVE_DOWN); |
106 | initial.tb.sib.ptr = get_swayc_in_direction(initial.tb.ptr, lock.top ? MOVE_UP : MOVE_DOWN); | 105 | initial.vert.parent.h = initial.vert.parent.ptr->height; |
107 | initial.tb.sib.y = initial.tb.sib.ptr->y; | ||
108 | initial.tb.sib.h = initial.tb.sib.ptr->height; | ||
109 | reset = false; | 106 | reset = false; |
110 | } | 107 | } |
111 | // If nothing changes just undo the mode | 108 | // If nothing will change just undo the mode |
112 | if (reset) { | 109 | if (reset) { |
113 | pointer_state.mode = 0; | 110 | pointer_state.mode = 0; |
114 | } | 111 | } |
@@ -123,6 +120,16 @@ static void reset_initial_view(void) { | |||
123 | pointer_state.mode = 0; | 120 | pointer_state.mode = 0; |
124 | } | 121 | } |
125 | 122 | ||
123 | static void reset_initial_sibling(void) { | ||
124 | initial.horiz.ptr->width = initial.horiz.w; | ||
125 | initial.horiz.parent.ptr->width = initial.horiz.parent.w; | ||
126 | initial.vert.ptr->height = initial.vert.h; | ||
127 | initial.vert.parent.ptr->height = initial.vert.parent.h; | ||
128 | arrange_windows(initial.horiz.ptr->parent, -1, -1); | ||
129 | arrange_windows(initial.vert.ptr->parent, -1, -1); | ||
130 | pointer_state.mode = 0; | ||
131 | } | ||
132 | |||
126 | // Mode set left/right click | 133 | // Mode set left/right click |
127 | 134 | ||
128 | static void pointer_mode_set_left(void) { | 135 | static void pointer_mode_set_left(void) { |
@@ -228,7 +235,7 @@ void pointer_mode_update(void) { | |||
228 | if (initial.w + dx > min_sane_w) { | 235 | if (initial.w + dx > min_sane_w) { |
229 | initial.ptr->width = initial.w + dx; | 236 | initial.ptr->width = initial.w + dx; |
230 | } | 237 | } |
231 | } else { //lock.right | 238 | } else { // lock.right |
232 | if (initial.w - dx > min_sane_w) { | 239 | if (initial.w - dx > min_sane_w) { |
233 | initial.ptr->width = initial.w - dx; | 240 | initial.ptr->width = initial.w - dx; |
234 | initial.ptr->x = initial.x + dx; | 241 | initial.ptr->x = initial.x + dx; |
@@ -238,7 +245,7 @@ void pointer_mode_update(void) { | |||
238 | if (initial.h + dy > min_sane_h) { | 245 | if (initial.h + dy > min_sane_h) { |
239 | initial.ptr->height = initial.h + dy; | 246 | initial.ptr->height = initial.h + dy; |
240 | } | 247 | } |
241 | } else { //lock.bottom | 248 | } else { // lock.bottom |
242 | if (initial.h - dy > min_sane_h) { | 249 | if (initial.h - dy > min_sane_h) { |
243 | initial.ptr->height = initial.h - dy; | 250 | initial.ptr->height = initial.h - dy; |
244 | initial.ptr->y = initial.y + dy; | 251 | initial.ptr->y = initial.y + dy; |
@@ -264,34 +271,34 @@ void pointer_mode_update(void) { | |||
264 | dx -= pointer_state.right.x; | 271 | dx -= pointer_state.right.x; |
265 | dy -= pointer_state.right.y; | 272 | dy -= pointer_state.right.y; |
266 | // resize if we can | 273 | // resize if we can |
267 | if (initial.lr.ptr) { | 274 | if (initial.horiz.ptr) { |
268 | if (lock.left) { | 275 | if (lock.left) { |
269 | // Check whether its fine to resize | 276 | // Check whether its fine to resize |
270 | if (initial.w + dx > min_sane_w && initial.lr.w - dx > min_sane_w) { | 277 | if (initial.w + dx > min_sane_w && initial.horiz.w - dx > min_sane_w) { |
271 | initial.lr.ptr->width = initial.lr.w - dx; | 278 | initial.horiz.ptr->width = initial.horiz.w - dx; |
272 | initial.lr.sib.ptr->width = initial.lr.sib.w + dx; | 279 | initial.horiz.parent.ptr->width = initial.horiz.parent.w + dx; |
273 | } | 280 | } |
274 | } else { //lock.right | 281 | } else { // lock.right |
275 | if (initial.w - dx > min_sane_w && initial.lr.w + dx > min_sane_w) { | 282 | if (initial.w - dx > min_sane_w && initial.horiz.w + dx > min_sane_w) { |
276 | initial.lr.ptr->width = initial.lr.w + dx; | 283 | initial.horiz.ptr->width = initial.horiz.w + dx; |
277 | initial.lr.sib.ptr->width = initial.lr.sib.w - dx; | 284 | initial.horiz.parent.ptr->width = initial.horiz.parent.w - dx; |
278 | } | 285 | } |
279 | } | 286 | } |
280 | arrange_windows(initial.lr.ptr->parent, -1, -1); | 287 | arrange_windows(initial.horiz.ptr->parent, -1, -1); |
281 | } | 288 | } |
282 | if (initial.tb.ptr) { | 289 | if (initial.vert.ptr) { |
283 | if (lock.top) { | 290 | if (lock.top) { |
284 | if (initial.h + dy > min_sane_h && initial.tb.h - dy > min_sane_h) { | 291 | if (initial.h + dy > min_sane_h && initial.vert.h - dy > min_sane_h) { |
285 | initial.tb.ptr->height = initial.tb.h - dy; | 292 | initial.vert.ptr->height = initial.vert.h - dy; |
286 | initial.tb.sib.ptr->height = initial.tb.sib.h + dy; | 293 | initial.vert.parent.ptr->height = initial.vert.parent.h + dy; |
287 | } | 294 | } |
288 | } else { //lock.bottom | 295 | } else { // lock.bottom |
289 | if (initial.h - dy > min_sane_h && initial.tb.h + dy > min_sane_h) { | 296 | if (initial.h - dy > min_sane_h && initial.vert.h + dy > min_sane_h) { |
290 | initial.tb.ptr->height = initial.tb.h + dy; | 297 | initial.vert.ptr->height = initial.vert.h + dy; |
291 | initial.tb.sib.ptr->height = initial.tb.sib.h - dy; | 298 | initial.vert.parent.ptr->height = initial.vert.parent.h - dy; |
292 | } | 299 | } |
293 | } | 300 | } |
294 | arrange_windows(initial.tb.ptr->parent, -1, -1); | 301 | arrange_windows(initial.vert.ptr->parent, -1, -1); |
295 | } | 302 | } |
296 | default: | 303 | default: |
297 | return; | 304 | return; |
@@ -300,15 +307,17 @@ void pointer_mode_update(void) { | |||
300 | 307 | ||
301 | void pointer_mode_reset(void) { | 308 | void pointer_mode_reset(void) { |
302 | switch (pointer_state.mode) { | 309 | switch (pointer_state.mode) { |
303 | case M_FLOATING | M_DRAGGING: | ||
304 | case M_FLOATING | M_RESIZING: | 310 | case M_FLOATING | M_RESIZING: |
311 | case M_FLOATING | M_DRAGGING: | ||
305 | reset_initial_view(); | 312 | reset_initial_view(); |
306 | break; | 313 | break; |
307 | 314 | ||
308 | case M_TILING | M_DRAGGING: | ||
309 | case M_TILING | M_RESIZING: | 315 | case M_TILING | M_RESIZING: |
316 | (void) reset_initial_sibling; | ||
317 | break; | ||
318 | |||
319 | case M_TILING | M_DRAGGING: | ||
310 | default: | 320 | default: |
311 | return; | 321 | break; |
312 | } | 322 | } |
313 | } | 323 | } |
314 | |||