diff options
Diffstat (limited to 'sway/handlers.c')
-rw-r--r-- | sway/handlers.c | 190 |
1 files changed, 96 insertions, 94 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index cb42196f..7d1e4cde 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -17,10 +17,8 @@ | |||
17 | #include "input_state.h" | 17 | #include "input_state.h" |
18 | #include "resize.h" | 18 | #include "resize.h" |
19 | 19 | ||
20 | struct wlc_origin mouse_origin; | ||
21 | |||
22 | static bool pointer_test(swayc_t *view, void *_origin) { | 20 | static bool pointer_test(swayc_t *view, void *_origin) { |
23 | const struct wlc_origin *origin = _origin; | 21 | const struct mouse_origin *origin = _origin; |
24 | // Determine the output that the view is under | 22 | // Determine the output that the view is under |
25 | swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); | 23 | swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); |
26 | if (origin->x >= view->x && origin->y >= view->y | 24 | if (origin->x >= view->x && origin->y >= view->y |
@@ -55,7 +53,7 @@ swayc_t *container_under_pointer(void) { | |||
55 | i = len = lookup->floating->length; | 53 | i = len = lookup->floating->length; |
56 | bool got_floating = false; | 54 | bool got_floating = false; |
57 | while (--i > -1) { | 55 | while (--i > -1) { |
58 | if (pointer_test(lookup->floating->items[i], &mouse_origin)) { | 56 | if (pointer_test(lookup->floating->items[i], &pointer_state.origin)) { |
59 | lookup = lookup->floating->items[i]; | 57 | lookup = lookup->floating->items[i]; |
60 | got_floating = true; | 58 | got_floating = true; |
61 | break; | 59 | break; |
@@ -68,7 +66,7 @@ swayc_t *container_under_pointer(void) { | |||
68 | // search children | 66 | // search children |
69 | len = lookup->children->length; | 67 | len = lookup->children->length; |
70 | for (i = 0; i < len; ++i) { | 68 | for (i = 0; i < len; ++i) { |
71 | if (pointer_test(lookup->children->items[i], &mouse_origin)) { | 69 | if (pointer_test(lookup->children->items[i], &pointer_state.origin)) { |
72 | lookup = lookup->children->items[i]; | 70 | lookup = lookup->children->items[i]; |
73 | break; | 71 | break; |
74 | } | 72 | } |
@@ -281,10 +279,9 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
281 | return false; | 279 | return false; |
282 | } | 280 | } |
283 | 281 | ||
284 | // Revert floating container back to original position on keypress | 282 | // reset pointer mode on keypress |
285 | if (state == WLC_KEY_STATE_PRESSED && | 283 | if (state == WLC_KEY_STATE_PRESSED && pointer_state.mode) { |
286 | (pointer_state.floating.drag || pointer_state.floating.resize)) { | 284 | pointer_mode_reset(); |
287 | reset_floating(get_focused_view(&root_container)); | ||
288 | } | 285 | } |
289 | 286 | ||
290 | struct sway_mode *mode = config->current_mode; | 287 | struct sway_mode *mode = config->current_mode; |
@@ -334,83 +331,25 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
334 | } | 331 | } |
335 | 332 | ||
336 | static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) { | 333 | static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) { |
337 | static struct wlc_origin prev_pos; | 334 | // Update pointer origin |
338 | static wlc_handle prev_handle = 0; | 335 | pointer_state.delta.x = origin->x - pointer_state.origin.x; |
339 | mouse_origin = *origin; | 336 | pointer_state.delta.y = origin->y - pointer_state.origin.y; |
340 | bool changed_floating = false; | 337 | pointer_state.origin.x = origin->x; |
341 | bool changed_tiling = false; | 338 | pointer_state.origin.y = origin->y; |
342 | if (!swayc_active_workspace()) { | 339 | |
343 | return false; | 340 | // Update view under pointer |
341 | swayc_t *prev_view = pointer_state.view; | ||
342 | pointer_state.view = container_under_pointer(); | ||
343 | |||
344 | // If pointer is in a mode, update it | ||
345 | if (pointer_state.mode) { | ||
346 | pointer_mode_update(); | ||
344 | } | 347 | } |
345 | // Do checks to determine if proper keys are being held | 348 | // Otherwise change focus if config is set an |
346 | swayc_t *view = container_under_pointer(); | 349 | else if (prev_view != pointer_state.view && config->focus_follows_mouse) { |
347 | if (pointer_state.floating.drag && view) { | 350 | if (pointer_state.view && pointer_state.view->type == C_VIEW) { |
348 | if (view->is_floating) { | 351 | set_focused_container(pointer_state.view); |
349 | int dx = mouse_origin.x - prev_pos.x; | ||
350 | int dy = mouse_origin.y - prev_pos.y; | ||
351 | view->x += dx; | ||
352 | view->y += dy; | ||
353 | struct wlc_geometry geometry = { | ||
354 | .origin = { | ||
355 | .x = view->x, | ||
356 | .y = view->y | ||
357 | }, | ||
358 | .size = { | ||
359 | .w = view->width, | ||
360 | .h = view->height | ||
361 | } | ||
362 | }; | ||
363 | wlc_view_set_geometry(view->handle, 0, &geometry); | ||
364 | changed_floating = true; | ||
365 | } else { | ||
366 | swayc_t *init_view = pointer_state.tiling.init_view; | ||
367 | if (view != init_view && view->type == C_VIEW) { | ||
368 | changed_tiling = true; | ||
369 | int i, j; | ||
370 | for (i = 0; i < view->parent->children->length; i++) { | ||
371 | if (view->parent->children->items[i] == view) { | ||
372 | for (j = 0; j < init_view->parent->children->length; j++) { | ||
373 | if (init_view->parent->children->items[j] == init_view) { | ||
374 | double temp_w = view->width; | ||
375 | double temp_h = view->height; | ||
376 | view->width = init_view->width; | ||
377 | view->height = init_view->height; | ||
378 | init_view->width = temp_w; | ||
379 | init_view->height = temp_h; | ||
380 | |||
381 | init_view->parent->children->items[j] = view; | ||
382 | view->parent->children->items[i] = init_view; | ||
383 | |||
384 | swayc_t *temp = view->parent; | ||
385 | view->parent = init_view->parent; | ||
386 | init_view->parent = temp; | ||
387 | |||
388 | arrange_windows(&root_container, -1, -1); | ||
389 | break; | ||
390 | } | ||
391 | } | ||
392 | break; | ||
393 | } | ||
394 | } | ||
395 | } | ||
396 | } | 352 | } |
397 | } else if (pointer_state.floating.resize && view) { | ||
398 | changed_floating = resize_floating(prev_pos); | ||
399 | } else if (pointer_state.tiling.resize && view) { | ||
400 | changed_tiling = mouse_resize_tiled(prev_pos); | ||
401 | } | ||
402 | if (config->focus_follows_mouse && prev_handle != handle) { | ||
403 | // Dont change focus if fullscreen | ||
404 | swayc_t *focused = get_focused_view(view); | ||
405 | if (!swayc_is_fullscreen(focused) | ||
406 | && !(pointer_state.l_held || pointer_state.r_held)) { | ||
407 | set_focused_container(container_under_pointer()); | ||
408 | } | ||
409 | } | ||
410 | prev_handle = handle; | ||
411 | prev_pos = mouse_origin; | ||
412 | if (changed_tiling || changed_floating) { | ||
413 | return true; | ||
414 | } | 353 | } |
415 | return false; | 354 | return false; |
416 | } | 355 | } |
@@ -418,11 +357,82 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
418 | 357 | ||
419 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, | 358 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, |
420 | uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { | 359 | uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { |
360 | enum { DONT_SEND_CLICK = true, SEND_CLICK = false }; | ||
361 | |||
362 | // Update pointer_state | ||
363 | switch (button) { | ||
364 | case M_LEFT_CLICK: | ||
365 | pointer_state.l_held = state == WLC_BUTTON_STATE_PRESSED; | ||
366 | break; | ||
367 | |||
368 | case M_RIGHT_CLICK: | ||
369 | pointer_state.r_held = state == WLC_BUTTON_STATE_PRESSED; | ||
370 | break; | ||
371 | |||
372 | case M_SCROLL_CLICK: | ||
373 | pointer_state.s_held = state == WLC_BUTTON_STATE_PRESSED; | ||
374 | break; | ||
375 | |||
376 | case M_SCROLL_UP: | ||
377 | pointer_state.s_up = state == WLC_BUTTON_STATE_PRESSED; | ||
378 | break; | ||
379 | |||
380 | case M_SCROLL_DOWN: | ||
381 | pointer_state.s_down = state == WLC_BUTTON_STATE_PRESSED; | ||
382 | break; | ||
383 | } | ||
384 | |||
385 | // Update pointer origin | ||
386 | pointer_state.origin.x = origin->x; | ||
387 | pointer_state.origin.y = origin->y; | ||
388 | |||
389 | // Update view pointer is on | ||
390 | pointer_state.view = container_under_pointer(); | ||
391 | |||
392 | // set pointer mode | ||
393 | pointer_mode_set(button, | ||
394 | (modifiers->mods & config->floating_mod) == config->floating_mod); | ||
395 | |||
396 | // Return if mode has been set | ||
397 | if (pointer_state.mode) { | ||
398 | return DONT_SEND_CLICK; | ||
399 | } | ||
400 | |||
401 | // Always send mouse release | ||
402 | if (state == WLC_BUTTON_STATE_RELEASED) { | ||
403 | return SEND_CLICK; | ||
404 | } | ||
405 | |||
406 | // get focused window and check if to change focus on mouse click | ||
421 | swayc_t *focused = get_focused_container(&root_container); | 407 | swayc_t *focused = get_focused_container(&root_container); |
408 | |||
409 | // Check whether to change focus | ||
410 | swayc_t *pointer = pointer_state.view; | ||
411 | if (pointer && focused != pointer) { | ||
412 | set_focused_container(pointer_state.view); | ||
413 | // Send to front if floating | ||
414 | if (pointer->is_floating) { | ||
415 | int i; | ||
416 | for (i = 0; i < pointer->parent->floating->length; i++) { | ||
417 | if (pointer->parent->floating->items[i] == pointer) { | ||
418 | list_del(pointer->parent->floating, i); | ||
419 | list_add(pointer->parent->floating, pointer); | ||
420 | break; | ||
421 | } | ||
422 | } | ||
423 | wlc_view_bring_to_front(view); | ||
424 | } | ||
425 | } | ||
426 | |||
422 | // dont change focus if fullscreen | 427 | // dont change focus if fullscreen |
423 | if (swayc_is_fullscreen(focused)) { | 428 | if (swayc_is_fullscreen(focused)) { |
424 | return false; | 429 | return SEND_CLICK; |
425 | } | 430 | } |
431 | |||
432 | // Finally send click | ||
433 | return SEND_CLICK; | ||
434 | |||
435 | /* OLD */ | ||
426 | if (state == WLC_BUTTON_STATE_PRESSED) { | 436 | if (state == WLC_BUTTON_STATE_PRESSED) { |
427 | sway_log(L_DEBUG, "Mouse button %u pressed", button); | 437 | sway_log(L_DEBUG, "Mouse button %u pressed", button); |
428 | if (button == M_LEFT_CLICK) { | 438 | if (button == M_LEFT_CLICK) { |
@@ -443,15 +453,6 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
443 | } | 453 | } |
444 | 454 | ||
445 | if (pointer->is_floating) { | 455 | if (pointer->is_floating) { |
446 | int i; | ||
447 | for (i = 0; i < pointer->parent->floating->length; i++) { | ||
448 | if (pointer->parent->floating->items[i] == pointer) { | ||
449 | list_del(pointer->parent->floating, i); | ||
450 | list_add(pointer->parent->floating, pointer); | ||
451 | break; | ||
452 | } | ||
453 | } | ||
454 | arrange_windows(pointer->parent, -1, -1); | ||
455 | if (modifiers->mods & config->floating_mod) { | 456 | if (modifiers->mods & config->floating_mod) { |
456 | pointer_state.floating.drag = pointer_state.l_held; | 457 | pointer_state.floating.drag = pointer_state.l_held; |
457 | pointer_state.floating.resize = pointer_state.r_held; | 458 | pointer_state.floating.resize = pointer_state.r_held; |
@@ -484,6 +485,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
484 | pointer_state.lock = (struct pointer_lock){false ,false ,false ,false, false, false, false, false}; | 485 | pointer_state.lock = (struct pointer_lock){false ,false ,false ,false, false, false, false, false}; |
485 | } | 486 | } |
486 | } | 487 | } |
488 | /* OLD */ | ||
487 | return false; | 489 | return false; |
488 | } | 490 | } |
489 | 491 | ||