aboutsummaryrefslogtreecommitdiffstats
path: root/sway/handlers.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/handlers.c')
-rw-r--r--sway/handlers.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index c20f3ca0..e785e9c5 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -19,7 +19,9 @@ uint32_t keys_pressed[32];
19static struct wlc_origin mouse_origin; 19static struct wlc_origin mouse_origin;
20 20
21static bool m1_held = false; 21static bool m1_held = false;
22static bool dragging = false;
22static bool m2_held = false; 23static bool m2_held = false;
24static bool resizing = false;
23 25
24static bool pointer_test(swayc_t *view, void *_origin) { 26static bool pointer_test(swayc_t *view, void *_origin) {
25 const struct wlc_origin *origin = _origin; 27 const struct wlc_origin *origin = _origin;
@@ -338,14 +340,12 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
338 // Do checks to determine if proper keys are being held 340 // Do checks to determine if proper keys are being held
339 swayc_t *view = active_workspace->focused; 341 swayc_t *view = active_workspace->focused;
340 uint32_t edge = 0; 342 uint32_t edge = 0;
341 if (m1_held && view) { 343 if (dragging && view) {
342 if (view->is_floating) { 344 if (view->is_floating) {
343 while (keys_pressed[i++]) { 345 while (keys_pressed[i++]) {
344 if (keys_pressed[i] == config->floating_mod) { 346 if (keys_pressed[i] == config->floating_mod) {
345 int dx = mouse_origin.x - prev_pos.x; 347 int dx = mouse_origin.x - prev_pos.x;
346 int dy = mouse_origin.y - prev_pos.y; 348 int dy = mouse_origin.y - prev_pos.y;
347 sway_log(L_DEBUG, "Moving from px: %d to cx: %d and from py: %d to cy: %d", prev_pos.x, mouse_origin.x, prev_pos.y, mouse_origin.y);
348
349 view->x += dx; 349 view->x += dx;
350 view->y += dy; 350 view->y += dy;
351 changed_floating = true; 351 changed_floating = true;
@@ -353,13 +353,12 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
353 } 353 }
354 } 354 }
355 } 355 }
356 } else if (m2_held && view) { 356 } else if (resizing && view) {
357 if (view->is_floating) { 357 if (view->is_floating) {
358 while (keys_pressed[i++]) { 358 while (keys_pressed[i++]) {
359 if (keys_pressed[i] == config->floating_mod) { 359 if (keys_pressed[i] == config->floating_mod) {
360 int dx = mouse_origin.x - prev_pos.x; 360 int dx = mouse_origin.x - prev_pos.x;
361 int dy = mouse_origin.y - prev_pos.y; 361 int dy = mouse_origin.y - prev_pos.y;
362 sway_log(L_DEBUG, "Moving from px: %d to cx: %d and from py: %d to cy: %d", prev_pos.x, mouse_origin.x, prev_pos.y, mouse_origin.y);
363 362
364 // Move and resize the view based on the dx/dy and mouse position 363 // Move and resize the view based on the dx/dy and mouse position
365 int midway_x = view->x + view->width/2; 364 int midway_x = view->x + view->width/2;
@@ -369,11 +368,9 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
369 if (dx < 0) { 368 if (dx < 0) {
370 changed_floating = true; 369 changed_floating = true;
371 if (mouse_origin.x > midway_x) { 370 if (mouse_origin.x > midway_x) {
372 sway_log(L_INFO, "Downsizing view to the left");
373 view->width += dx; 371 view->width += dx;
374 edge += WLC_RESIZE_EDGE_RIGHT; 372 edge += WLC_RESIZE_EDGE_RIGHT;
375 } else { 373 } else {
376 sway_log(L_INFO, "Upsizing view to the left");
377 view->x += dx; 374 view->x += dx;
378 view->width -= dx; 375 view->width -= dx;
379 edge += WLC_RESIZE_EDGE_LEFT; 376 edge += WLC_RESIZE_EDGE_LEFT;
@@ -381,11 +378,9 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
381 } else if (dx > 0){ 378 } else if (dx > 0){
382 changed_floating = true; 379 changed_floating = true;
383 if (mouse_origin.x > midway_x) { 380 if (mouse_origin.x > midway_x) {
384 sway_log(L_INFO, "Upsizing to the right");
385 view->width += dx; 381 view->width += dx;
386 edge += WLC_RESIZE_EDGE_RIGHT; 382 edge += WLC_RESIZE_EDGE_RIGHT;
387 } else { 383 } else {
388 sway_log(L_INFO, "Downsizing to the right");
389 view->x += dx; 384 view->x += dx;
390 view->width -= dx; 385 view->width -= dx;
391 edge += WLC_RESIZE_EDGE_LEFT; 386 edge += WLC_RESIZE_EDGE_LEFT;
@@ -395,11 +390,9 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
395 if (dy < 0) { 390 if (dy < 0) {
396 changed_floating = true; 391 changed_floating = true;
397 if (mouse_origin.y > midway_y) { 392 if (mouse_origin.y > midway_y) {
398 sway_log(L_INFO, "Downsizing view to the top");
399 view->height += dy; 393 view->height += dy;
400 edge += WLC_RESIZE_EDGE_BOTTOM; 394 edge += WLC_RESIZE_EDGE_BOTTOM;
401 } else { 395 } else {
402 sway_log(L_INFO, "Upsizing the view to the top");
403 view->y += dy; 396 view->y += dy;
404 view->height -= dy; 397 view->height -= dy;
405 edge += WLC_RESIZE_EDGE_TOP; 398 edge += WLC_RESIZE_EDGE_TOP;
@@ -407,12 +400,10 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
407 } else if (dy > 0) { 400 } else if (dy > 0) {
408 changed_floating = true; 401 changed_floating = true;
409 if (mouse_origin.y > midway_y) { 402 if (mouse_origin.y > midway_y) {
410 sway_log(L_INFO, "Upsizing to the bottom");
411 view->height += dy; 403 view->height += dy;
412 edge += WLC_RESIZE_EDGE_BOTTOM; 404 edge += WLC_RESIZE_EDGE_BOTTOM;
413 } else { 405 } else {
414 edge = WLC_RESIZE_EDGE_BOTTOM; 406 edge = WLC_RESIZE_EDGE_BOTTOM;
415 sway_log(L_INFO, "Downsizing to the bottom");
416 view->y += dy; 407 view->y += dy;
417 view->height -= dy; 408 view->height -= dy;
418 edge += WLC_RESIZE_EDGE_TOP; 409 edge += WLC_RESIZE_EDGE_TOP;
@@ -426,7 +417,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
426 if (config->focus_follows_mouse && prev_handle != handle) { 417 if (config->focus_follows_mouse && prev_handle != handle) {
427 //Dont change focus if fullscreen 418 //Dont change focus if fullscreen
428 swayc_t *focused = get_focused_view(view); 419 swayc_t *focused = get_focused_view(view);
429 if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) { 420 if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) && !(m1_held || m2_held)) {
430 set_focused_container(container_under_pointer()); 421 set_focused_container(container_under_pointer());
431 } 422 }
432 } 423 }
@@ -476,15 +467,19 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
476 } 467 }
477 } 468 }
478 arrange_windows(pointer->parent, -1, -1); 469 arrange_windows(pointer->parent, -1, -1);
470 dragging = m1_held;
471 resizing = m2_held;
479 } 472 }
480 return (pointer && pointer != focused); 473 return (pointer && pointer != focused);
481 } else { 474 } else {
482 sway_log(L_DEBUG, "Mouse button %u released", button); 475 sway_log(L_DEBUG, "Mouse button %u released", button);
483 if (button == 272) { 476 if (button == 272) {
484 m1_held = false; 477 m1_held = false;
478 dragging = false;
485 } 479 }
486 if (button == 273) { 480 if (button == 273) {
487 m2_held = false; 481 m2_held = false;
482 resizing = false;
488 } 483 }
489 } 484 }
490 return false; 485 return false;