diff options
Diffstat (limited to 'sway/handlers.c')
-rw-r--r-- | sway/handlers.c | 102 |
1 files changed, 32 insertions, 70 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index 7d1e4cde..896caa10 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -359,36 +359,54 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
359 | 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 }; | 360 | enum { DONT_SEND_CLICK = true, SEND_CLICK = false }; |
361 | 361 | ||
362 | // Update view pointer is on | ||
363 | pointer_state.view = container_under_pointer(); | ||
364 | |||
365 | // Update pointer origin | ||
366 | pointer_state.origin.x = origin->x; | ||
367 | pointer_state.origin.y = origin->y; | ||
368 | |||
362 | // Update pointer_state | 369 | // Update pointer_state |
363 | switch (button) { | 370 | switch (button) { |
364 | case M_LEFT_CLICK: | 371 | case M_LEFT_CLICK: |
365 | pointer_state.l_held = state == WLC_BUTTON_STATE_PRESSED; | 372 | if (state == WLC_BUTTON_STATE_PRESSED) { |
373 | pointer_state.left.held = true; | ||
374 | pointer_state.left.x = origin->x; | ||
375 | pointer_state.left.y = origin->y; | ||
376 | pointer_state.left.view = pointer_state.view; | ||
377 | } else { | ||
378 | pointer_state.left.held = false; | ||
379 | } | ||
366 | break; | 380 | break; |
367 | 381 | ||
368 | case M_RIGHT_CLICK: | 382 | case M_RIGHT_CLICK: |
369 | pointer_state.r_held = state == WLC_BUTTON_STATE_PRESSED; | 383 | if (state == WLC_BUTTON_STATE_PRESSED) { |
384 | pointer_state.right.held = true; | ||
385 | pointer_state.right.x = origin->x; | ||
386 | pointer_state.right.y = origin->y; | ||
387 | pointer_state.right.view = pointer_state.view; | ||
388 | } else { | ||
389 | pointer_state.right.held = false; | ||
390 | } | ||
370 | break; | 391 | break; |
371 | 392 | ||
372 | case M_SCROLL_CLICK: | 393 | case M_SCROLL_CLICK: |
373 | pointer_state.s_held = state == WLC_BUTTON_STATE_PRESSED; | 394 | if (state == WLC_BUTTON_STATE_PRESSED) { |
395 | pointer_state.scroll.held = true; | ||
396 | pointer_state.scroll.x = origin->x; | ||
397 | pointer_state.scroll.y = origin->y; | ||
398 | pointer_state.scroll.view = pointer_state.view; | ||
399 | } else { | ||
400 | pointer_state.scroll.held = false; | ||
401 | } | ||
374 | break; | 402 | break; |
375 | 403 | ||
404 | //TODO scrolling behavior | ||
376 | case M_SCROLL_UP: | 405 | case M_SCROLL_UP: |
377 | pointer_state.s_up = state == WLC_BUTTON_STATE_PRESSED; | ||
378 | break; | ||
379 | |||
380 | case M_SCROLL_DOWN: | 406 | case M_SCROLL_DOWN: |
381 | pointer_state.s_down = state == WLC_BUTTON_STATE_PRESSED; | ||
382 | break; | 407 | break; |
383 | } | 408 | } |
384 | 409 | ||
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 | 410 | // set pointer mode |
393 | pointer_mode_set(button, | 411 | pointer_mode_set(button, |
394 | (modifiers->mods & config->floating_mod) == config->floating_mod); | 412 | (modifiers->mods & config->floating_mod) == config->floating_mod); |
@@ -431,62 +449,6 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
431 | 449 | ||
432 | // Finally send click | 450 | // Finally send click |
433 | return SEND_CLICK; | 451 | return SEND_CLICK; |
434 | |||
435 | /* OLD */ | ||
436 | if (state == WLC_BUTTON_STATE_PRESSED) { | ||
437 | sway_log(L_DEBUG, "Mouse button %u pressed", button); | ||
438 | if (button == M_LEFT_CLICK) { | ||
439 | pointer_state.l_held = true; | ||
440 | } | ||
441 | if (button == M_RIGHT_CLICK) { | ||
442 | pointer_state.r_held = true; | ||
443 | } | ||
444 | swayc_t *pointer = container_under_pointer(); | ||
445 | if (pointer) { | ||
446 | set_focused_container(pointer); | ||
447 | int midway_x = pointer->x + pointer->width/2; | ||
448 | int midway_y = pointer->y + pointer->height/2; | ||
449 | pointer_state.lock.bottom = origin->y < midway_y; | ||
450 | pointer_state.lock.top = !pointer_state.lock.bottom; | ||
451 | pointer_state.lock.right = origin->x < midway_x; | ||
452 | pointer_state.lock.left = !pointer_state.lock.right; | ||
453 | } | ||
454 | |||
455 | if (pointer->is_floating) { | ||
456 | if (modifiers->mods & config->floating_mod) { | ||
457 | pointer_state.floating.drag = pointer_state.l_held; | ||
458 | pointer_state.floating.resize = pointer_state.r_held; | ||
459 | start_floating(pointer); | ||
460 | } | ||
461 | // Dont want pointer sent to window while dragging or resizing | ||
462 | return (pointer_state.floating.drag || pointer_state.floating.resize); | ||
463 | } else { | ||
464 | if (modifiers->mods & config->floating_mod) { | ||
465 | pointer_state.floating.drag = pointer_state.l_held; | ||
466 | pointer_state.tiling.resize = pointer_state.r_held; | ||
467 | pointer_state.tiling.init_view = pointer; | ||
468 | // Dont want pointer sent when resizing | ||
469 | return (pointer_state.tiling.resize); | ||
470 | } | ||
471 | } | ||
472 | return (pointer && pointer != focused); | ||
473 | } else { | ||
474 | sway_log(L_DEBUG, "Mouse button %u released", button); | ||
475 | if (button == M_LEFT_CLICK) { | ||
476 | pointer_state.l_held = false; | ||
477 | pointer_state.floating.drag = false; | ||
478 | pointer_state.tiling.init_view = NULL; | ||
479 | } | ||
480 | if (button == M_RIGHT_CLICK) { | ||
481 | pointer_state.r_held = false; | ||
482 | pointer_state.floating.resize = false; | ||
483 | pointer_state.tiling.resize = false; | ||
484 | pointer_state.tiling.init_view = NULL; | ||
485 | pointer_state.lock = (struct pointer_lock){false ,false ,false ,false, false, false, false, false}; | ||
486 | } | ||
487 | } | ||
488 | /* OLD */ | ||
489 | return false; | ||
490 | } | 452 | } |
491 | 453 | ||
492 | static void handle_wlc_ready(void) { | 454 | static void handle_wlc_ready(void) { |