From 5b6e48987204c0d2298dda2d9b30b4208abdd8d5 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Tue, 18 Aug 2015 16:28:24 -0500 Subject: More patches for wlc compat --- sway/handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 534b4e4f..1fe2dc27 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -427,7 +427,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, - uint32_t button, enum wlc_button_state state) { + uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { swayc_t *focused = get_focused_container(&root_container); //dont change focus if fullscreen if (focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) { -- cgit v1.2.3 From cf916bbf6fbdf75abc55d4c1abe26ed6b8153687 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 18 Aug 2015 18:44:50 -0400 Subject: Improvements to gaps --- sway/handlers.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 1fe2dc27..9b96a5cf 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -168,7 +168,11 @@ static bool handle_view_created(wlc_handle handle) { } if (newview) { set_focused_container(newview); - arrange_windows(newview->parent, -1, -1); + swayc_t *output = newview->parent; + while (output && output->type != C_OUTPUT) { + output = output->parent; + } + arrange_windows(output, -1, -1); } return true; } -- cgit v1.2.3 From 3e950c2b1c77fd3bd6a029eea6d50fbbe124b581 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Tue, 18 Aug 2015 17:45:26 -0500 Subject: Basic fixes to floating movement --- sway/handlers.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 9b96a5cf..d0915fe5 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -337,6 +337,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } // Do checks to determine if proper keys are being held swayc_t *view = active_workspace->focused; + uint32_t edge = 0; if (m1_held && view) { if (view->is_floating) { while (keys_pressed[i++]) { @@ -348,7 +349,6 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct view->x += dx; view->y += dy; - changed_floating = true; break; } } @@ -366,25 +366,30 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct int midway_x = view->x + view->width/2; int midway_y = view->y + view->height/2; + if (dx < 0) { changed_floating = true; if (mouse_origin.x > midway_x) { sway_log(L_INFO, "Downsizing view to the left"); view->width += dx; + edge = WLC_RESIZE_EDGE_RIGHT; } else { sway_log(L_INFO, "Upsizing view to the left"); view->x += dx; view->width -= dx; + edge = WLC_RESIZE_EDGE_LEFT; } } else if (dx > 0){ changed_floating = true; if (mouse_origin.x > midway_x) { sway_log(L_INFO, "Upsizing to the right"); view->width += dx; + edge = WLC_RESIZE_EDGE_RIGHT; } else { sway_log(L_INFO, "Downsizing to the right"); view->x += dx; view->width -= dx; + edge = WLC_RESIZE_EDGE_LEFT; } } @@ -393,20 +398,25 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct if (mouse_origin.y > midway_y) { sway_log(L_INFO, "Downsizing view to the top"); view->height += dy; + edge += WLC_RESIZE_EDGE_BOTTOM; } else { sway_log(L_INFO, "Upsizing the view to the top"); view->y += dy; view->height -= dy; + edge += WLC_RESIZE_EDGE_TOP; } } else if (dy > 0) { changed_floating = true; if (mouse_origin.y > midway_y) { sway_log(L_INFO, "Upsizing to the bottom"); view->height += dy; + edge += WLC_RESIZE_EDGE_BOTTOM; } else { + edge = WLC_RESIZE_EDGE_BOTTOM; sway_log(L_INFO, "Downsizing to the bottom"); view->y += dy; view->height -= dy; + edge += WLC_RESIZE_EDGE_TOP; } } break; @@ -424,7 +434,17 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct prev_handle = handle; prev_pos = mouse_origin; if (changed_floating) { - arrange_windows(view, -1, -1); + struct wlc_geometry geometry = { + .origin = { + .x = view->x, + .y = view->y + }, + .size = { + .w = view->width, + .h = view->height + } + }; + wlc_view_set_geometry(view->handle, edge, &geometry); return true; } return false; -- cgit v1.2.3 From 7137be9a3fac4780c356d3f7a5d33c4235314a57 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Tue, 18 Aug 2015 18:03:11 -0500 Subject: Fixes to make floating windows work better --- sway/handlers.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index d0915fe5..99d57529 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -345,10 +345,10 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct int dx = mouse_origin.x - prev_pos.x; int dy = mouse_origin.y - prev_pos.y; 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); - sway_log(L_DEBUG, "Moving: dx: %d, dy: %d", dx, dy); view->x += dx; view->y += dy; + changed_floating = true; break; } } @@ -360,7 +360,6 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct int dx = mouse_origin.x - prev_pos.x; int dy = mouse_origin.y - prev_pos.y; 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); - sway_log(L_INFO, "Moving: dx: %d, dy: %d", dx, dy); // Move and resize the view based on the dx/dy and mouse position int midway_x = view->x + view->width/2; -- cgit v1.2.3 From ab43927a470f46271ae98faa4e1cfe3a936c6c9d Mon Sep 17 00:00:00 2001 From: Luminarys Date: Tue, 18 Aug 2015 18:04:46 -0500 Subject: Minor fixes that might be helpful later --- sway/handlers.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 99d57529..c20f3ca0 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -371,24 +371,24 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct if (mouse_origin.x > midway_x) { sway_log(L_INFO, "Downsizing view to the left"); view->width += dx; - edge = WLC_RESIZE_EDGE_RIGHT; + edge += WLC_RESIZE_EDGE_RIGHT; } else { sway_log(L_INFO, "Upsizing view to the left"); view->x += dx; view->width -= dx; - edge = WLC_RESIZE_EDGE_LEFT; + edge += WLC_RESIZE_EDGE_LEFT; } } else if (dx > 0){ changed_floating = true; if (mouse_origin.x > midway_x) { sway_log(L_INFO, "Upsizing to the right"); view->width += dx; - edge = WLC_RESIZE_EDGE_RIGHT; + edge += WLC_RESIZE_EDGE_RIGHT; } else { sway_log(L_INFO, "Downsizing to the right"); view->x += dx; view->width -= dx; - edge = WLC_RESIZE_EDGE_LEFT; + edge += WLC_RESIZE_EDGE_LEFT; } } -- cgit v1.2.3 From f718556a850a5c2bff6a00729c11f630c4b9c00f Mon Sep 17 00:00:00 2001 From: Luminarys Date: Tue, 18 Aug 2015 21:05:58 -0500 Subject: Removed debugging, added in proper gap resets for config reloads --- sway/handlers.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'sway/handlers.c') 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]; static struct wlc_origin mouse_origin; static bool m1_held = false; +static bool dragging = false; static bool m2_held = false; +static bool resizing = false; static bool pointer_test(swayc_t *view, void *_origin) { const struct wlc_origin *origin = _origin; @@ -338,14 +340,12 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct // Do checks to determine if proper keys are being held swayc_t *view = active_workspace->focused; uint32_t edge = 0; - if (m1_held && view) { + if (dragging && view) { if (view->is_floating) { while (keys_pressed[i++]) { if (keys_pressed[i] == config->floating_mod) { int dx = mouse_origin.x - prev_pos.x; int dy = mouse_origin.y - prev_pos.y; - 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); - view->x += dx; view->y += dy; changed_floating = true; @@ -353,13 +353,12 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } } - } else if (m2_held && view) { + } else if (resizing && view) { if (view->is_floating) { while (keys_pressed[i++]) { if (keys_pressed[i] == config->floating_mod) { int dx = mouse_origin.x - prev_pos.x; int dy = mouse_origin.y - prev_pos.y; - 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); // Move and resize the view based on the dx/dy and mouse position 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 if (dx < 0) { changed_floating = true; if (mouse_origin.x > midway_x) { - sway_log(L_INFO, "Downsizing view to the left"); view->width += dx; edge += WLC_RESIZE_EDGE_RIGHT; } else { - sway_log(L_INFO, "Upsizing view to the left"); view->x += dx; view->width -= dx; edge += WLC_RESIZE_EDGE_LEFT; @@ -381,11 +378,9 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } else if (dx > 0){ changed_floating = true; if (mouse_origin.x > midway_x) { - sway_log(L_INFO, "Upsizing to the right"); view->width += dx; edge += WLC_RESIZE_EDGE_RIGHT; } else { - sway_log(L_INFO, "Downsizing to the right"); view->x += dx; view->width -= dx; edge += WLC_RESIZE_EDGE_LEFT; @@ -395,11 +390,9 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct if (dy < 0) { changed_floating = true; if (mouse_origin.y > midway_y) { - sway_log(L_INFO, "Downsizing view to the top"); view->height += dy; edge += WLC_RESIZE_EDGE_BOTTOM; } else { - sway_log(L_INFO, "Upsizing the view to the top"); view->y += dy; view->height -= dy; edge += WLC_RESIZE_EDGE_TOP; @@ -407,12 +400,10 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } else if (dy > 0) { changed_floating = true; if (mouse_origin.y > midway_y) { - sway_log(L_INFO, "Upsizing to the bottom"); view->height += dy; edge += WLC_RESIZE_EDGE_BOTTOM; } else { edge = WLC_RESIZE_EDGE_BOTTOM; - sway_log(L_INFO, "Downsizing to the bottom"); view->y += dy; view->height -= dy; edge += WLC_RESIZE_EDGE_TOP; @@ -426,7 +417,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct if (config->focus_follows_mouse && prev_handle != handle) { //Dont change focus if fullscreen swayc_t *focused = get_focused_view(view); - if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) { + if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) && !(m1_held || m2_held)) { set_focused_container(container_under_pointer()); } } @@ -476,15 +467,19 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w } } arrange_windows(pointer->parent, -1, -1); + dragging = m1_held; + resizing = m2_held; } return (pointer && pointer != focused); } else { sway_log(L_DEBUG, "Mouse button %u released", button); if (button == 272) { m1_held = false; + dragging = false; } if (button == 273) { m2_held = false; + resizing = false; } } return false; -- cgit v1.2.3 From 1bf02144e558630f36b1efca45d6074be456c0b4 Mon Sep 17 00:00:00 2001 From: taiyu Date: Tue, 18 Aug 2015 23:52:42 -0700 Subject: fixed floating_modifier related things --- sway/handlers.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index e785e9c5..d5909c8f 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -139,35 +139,54 @@ static void handle_output_focused(wlc_handle output, bool focus) { } static bool handle_view_created(wlc_handle handle) { - swayc_t *focused = get_focused_container(&root_container); + // if view is child of another view, the use that as focused container + wlc_handle parent = wlc_view_get_parent(handle); + swayc_t *focused = NULL; swayc_t *newview = NULL; + + // Get parent container, to add view in + if (parent) { + focused = get_swayc_for_handle(parent, &root_container); + } + if (!focused || focused->type == C_OUTPUT) { + focused = get_focused_container(&root_container); + } + sway_log(L_DEBUG, "creating view %ld with type %x, state %x, with parent %ld", + handle, wlc_view_get_type(handle), wlc_view_get_state(handle), parent); + + // TODO properly figure out how each window should be handled. switch (wlc_view_get_type(handle)) { // regular view created regularly case 0: newview = new_view(focused, handle); wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true); break; - // takes keyboard focus + + // Dmenu keeps viewfocus, but others with this flag dont, for now simulate + // dmenu case WLC_BIT_OVERRIDE_REDIRECT: - sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT", handle); - locked_view_focus = true; +// locked_view_focus = true; wlc_view_focus(handle); wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); wlc_view_bring_to_front(handle); break; - // Takes container focus + + // Firefox popups have this flag set. case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: - sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT|WLC_BIT_MANAGED", handle); wlc_view_bring_to_front(handle); locked_container_focus = true; break; - // set modals as floating containers + + // Modals, get focus, popups do not case WLC_BIT_MODAL: + wlc_view_focus(handle); wlc_view_bring_to_front(handle); newview = new_floating_view(handle); case WLC_BIT_POPUP: + wlc_view_bring_to_front(handle); break; } + if (newview) { set_focused_container(newview); swayc_t *output = newview->parent; @@ -187,19 +206,19 @@ static void handle_view_destroyed(wlc_handle handle) { // regular view created regularly case 0: case WLC_BIT_MODAL: + case WLC_BIT_POPUP: if (view) { swayc_t *parent = destroy_view(view); arrange_windows(parent, -1, -1); } break; - // takes keyboard focus + // DMENU has this flag, and takes view_focus, but other things with this + // flag dont case WLC_BIT_OVERRIDE_REDIRECT: - locked_view_focus = false; +// locked_view_focus = false; break; - // Takes container focus case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: locked_container_focus = false; - case WLC_BIT_POPUP: break; } set_focused_container(get_focused_view(&root_container)); @@ -279,10 +298,12 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier while (mid < head && keys_pressed[mid] != sym) { ++mid; } + //Add or remove key depending on state if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) { keys_pressed[head++] = sym; } else if (state == WLC_KEY_STATE_RELEASED && mid < head) { memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--head - mid)); + keys_pressed[head] = 0; } // TODO: reminder to check conflicts with mod+q+a versus mod+q int i; @@ -314,6 +335,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier uint8_t k; for (k = 0; k < head; ++k) { memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--head - k)); + keys_pressed[head] = 0; break; } } @@ -469,6 +491,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w arrange_windows(pointer->parent, -1, -1); dragging = m1_held; resizing = m2_held; + return true; } return (pointer && pointer != focused); } else { -- cgit v1.2.3 From e16a4015ff216594eeb237ef81534bfaea7533d6 Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 00:28:53 -0700 Subject: fixed focus key handler --- sway/handlers.c | 163 +++++++++++++++++++++++++++----------------------------- 1 file changed, 79 insertions(+), 84 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index d5909c8f..3ae33294 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -15,6 +15,7 @@ #include "focus.h" uint32_t keys_pressed[32]; +int keys_pressed_length = 0; static struct wlc_origin mouse_origin; @@ -23,6 +24,15 @@ static bool dragging = false; static bool m2_held = false; static bool resizing = false; +static bool floating_mod_pressed(void) { + int i = 0; + while (i < keys_pressed_length) { + if (keys_pressed[i++] == config->floating_mod) + return true; + } + return false; +} + static bool pointer_test(swayc_t *view, void *_origin) { const struct wlc_origin *origin = _origin; // Determine the output that the view is under @@ -286,7 +296,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { return false; } - static uint8_t head = 0; bool cmd_success = false; struct sway_mode *mode = config->current_mode; @@ -295,15 +304,15 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier // Find key, if it has been pressed int mid = 0; - while (mid < head && keys_pressed[mid] != sym) { + while (mid < keys_pressed_length && keys_pressed[mid] != sym) { ++mid; } //Add or remove key depending on state - if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) { - keys_pressed[head++] = sym; - } else if (state == WLC_KEY_STATE_RELEASED && mid < head) { - memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--head - mid)); - keys_pressed[head] = 0; + if (state == WLC_KEY_STATE_PRESSED && mid == keys_pressed_length && keys_pressed_length + 1 < QSIZE) { + keys_pressed[keys_pressed_length++] = sym; + } else if (state == WLC_KEY_STATE_RELEASED && mid < keys_pressed_length) { + memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--keys_pressed_length - mid)); + keys_pressed[keys_pressed_length] = 0; } // TODO: reminder to check conflicts with mod+q+a versus mod+q int i; @@ -317,7 +326,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier match = false; xkb_keysym_t *key = binding->keys->items[j]; uint8_t k; - for (k = 0; k < head; ++k) { + for (k = 0; k < keys_pressed_length; ++k) { if (keys_pressed[k] == *key) { match = true; break; @@ -333,9 +342,9 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier int j; for (j = 0; j < binding->keys->length; ++j) { uint8_t k; - for (k = 0; k < head; ++k) { - memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--head - k)); - keys_pressed[head] = 0; + for (k = 0; k < keys_pressed_length; ++k) { + memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--keys_pressed_length - k)); + keys_pressed[keys_pressed_length] = 0; break; } } @@ -355,84 +364,67 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct static wlc_handle prev_handle = 0; mouse_origin = *origin; bool changed_floating = false; - int i = 0; if (!active_workspace) { return false; } // Do checks to determine if proper keys are being held - swayc_t *view = active_workspace->focused; + swayc_t *view = get_focused_view(active_workspace); uint32_t edge = 0; - if (dragging && view) { - if (view->is_floating) { - while (keys_pressed[i++]) { - if (keys_pressed[i] == config->floating_mod) { - int dx = mouse_origin.x - prev_pos.x; - int dy = mouse_origin.y - prev_pos.y; - view->x += dx; - view->y += dy; - changed_floating = true; - break; - } + if (dragging && view && view->is_floating) { + int dx = mouse_origin.x - prev_pos.x; + int dy = mouse_origin.y - prev_pos.y; + view->x += dx; + view->y += dy; + changed_floating = true; + } else if (resizing && view && view->is_floating) { + int dx = mouse_origin.x - prev_pos.x; + int dy = mouse_origin.y - prev_pos.y; + + // Move and resize the view based on the dx/dy and mouse position + int midway_x = view->x + view->width/2; + int midway_y = view->y + view->height/2; + if (dx < 0) { + changed_floating = true; + if (mouse_origin.x > midway_x) { + view->width += dx; + edge += WLC_RESIZE_EDGE_RIGHT; + } else { + view->x += dx; + view->width -= dx; + edge += WLC_RESIZE_EDGE_LEFT; + } + } else if (dx > 0){ + changed_floating = true; + if (mouse_origin.x > midway_x) { + view->width += dx; + edge += WLC_RESIZE_EDGE_RIGHT; + } else { + view->x += dx; + view->width -= dx; + edge += WLC_RESIZE_EDGE_LEFT; } } - } else if (resizing && view) { - if (view->is_floating) { - while (keys_pressed[i++]) { - if (keys_pressed[i] == config->floating_mod) { - int dx = mouse_origin.x - prev_pos.x; - int dy = mouse_origin.y - prev_pos.y; - - // Move and resize the view based on the dx/dy and mouse position - int midway_x = view->x + view->width/2; - int midway_y = view->y + view->height/2; - - - if (dx < 0) { - changed_floating = true; - if (mouse_origin.x > midway_x) { - view->width += dx; - edge += WLC_RESIZE_EDGE_RIGHT; - } else { - view->x += dx; - view->width -= dx; - edge += WLC_RESIZE_EDGE_LEFT; - } - } else if (dx > 0){ - changed_floating = true; - if (mouse_origin.x > midway_x) { - view->width += dx; - edge += WLC_RESIZE_EDGE_RIGHT; - } else { - view->x += dx; - view->width -= dx; - edge += WLC_RESIZE_EDGE_LEFT; - } - } - if (dy < 0) { - changed_floating = true; - if (mouse_origin.y > midway_y) { - view->height += dy; - edge += WLC_RESIZE_EDGE_BOTTOM; - } else { - view->y += dy; - view->height -= dy; - edge += WLC_RESIZE_EDGE_TOP; - } - } else if (dy > 0) { - changed_floating = true; - if (mouse_origin.y > midway_y) { - view->height += dy; - edge += WLC_RESIZE_EDGE_BOTTOM; - } else { - edge = WLC_RESIZE_EDGE_BOTTOM; - view->y += dy; - view->height -= dy; - edge += WLC_RESIZE_EDGE_TOP; - } - } - break; - } + if (dy < 0) { + changed_floating = true; + if (mouse_origin.y > midway_y) { + view->height += dy; + edge += WLC_RESIZE_EDGE_BOTTOM; + } else { + view->y += dy; + view->height -= dy; + edge += WLC_RESIZE_EDGE_TOP; + } + } else if (dy > 0) { + changed_floating = true; + if (mouse_origin.y > midway_y) { + view->height += dy; + edge += WLC_RESIZE_EDGE_BOTTOM; + } else { + edge = WLC_RESIZE_EDGE_BOTTOM; + view->y += dy; + view->height -= dy; + edge += WLC_RESIZE_EDGE_TOP; } } } @@ -489,9 +481,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w } } arrange_windows(pointer->parent, -1, -1); - dragging = m1_held; - resizing = m2_held; - return true; + if (floating_mod_pressed()) { + dragging = m1_held; + resizing = m2_held; + } + //Dont want pointer sent to window while dragging or resizing + return (dragging || resizing); } return (pointer && pointer != focused); } else { -- cgit v1.2.3 From 8205a6fd3bb544b11c9d56abc93da02b03543297 Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 09:09:35 -0700 Subject: floating_modifier uses mod_keys instead of anykey --- sway/handlers.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 3ae33294..670569cb 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -15,8 +15,10 @@ #include "focus.h" uint32_t keys_pressed[32]; +uint32_t key_modifiers; int keys_pressed_length = 0; + static struct wlc_origin mouse_origin; static bool m1_held = false; @@ -25,12 +27,7 @@ static bool m2_held = false; static bool resizing = false; static bool floating_mod_pressed(void) { - int i = 0; - while (i < keys_pressed_length) { - if (keys_pressed[i++] == config->floating_mod) - return true; - } - return false; + return key_modifiers & config->floating_mod; } static bool pointer_test(swayc_t *view, void *_origin) { @@ -297,6 +294,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier return false; } bool cmd_success = false; + key_modifiers = modifiers->mods; struct sway_mode *mode = config->current_mode; // Lowercase if necessary -- cgit v1.2.3 From 9542f8746ae691b867ed127a7897dd5e8c7f4305 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Wed, 19 Aug 2015 10:52:01 -0500 Subject: Added in resize locking --- sway/handlers.c | 135 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 52 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 670569cb..faade5eb 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -25,6 +25,7 @@ static bool m1_held = false; static bool dragging = false; static bool m2_held = false; static bool resizing = false; +static bool lock_left, lock_right, lock_top, lock_bottom = false; static bool floating_mod_pressed(void) { return key_modifiers & config->floating_mod; @@ -368,61 +369,89 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct // Do checks to determine if proper keys are being held swayc_t *view = get_focused_view(active_workspace); uint32_t edge = 0; - if (dragging && view && view->is_floating) { - int dx = mouse_origin.x - prev_pos.x; - int dy = mouse_origin.y - prev_pos.y; - view->x += dx; - view->y += dy; - changed_floating = true; - } else if (resizing && view && view->is_floating) { - int dx = mouse_origin.x - prev_pos.x; - int dy = mouse_origin.y - prev_pos.y; - - // Move and resize the view based on the dx/dy and mouse position - int midway_x = view->x + view->width/2; - int midway_y = view->y + view->height/2; - if (dx < 0) { - changed_floating = true; - if (mouse_origin.x > midway_x) { - view->width += dx; - edge += WLC_RESIZE_EDGE_RIGHT; - } else { - view->x += dx; - view->width -= dx; - edge += WLC_RESIZE_EDGE_LEFT; - } - } else if (dx > 0){ + if (dragging && view) { + if (view->is_floating) { + int dx = mouse_origin.x - prev_pos.x; + int dy = mouse_origin.y - prev_pos.y; + view->x += dx; + view->y += dy; changed_floating = true; - if (mouse_origin.x > midway_x) { - view->width += dx; - edge += WLC_RESIZE_EDGE_RIGHT; - } else { - view->x += dx; - view->width -= dx; - edge += WLC_RESIZE_EDGE_LEFT; - } } - - if (dy < 0) { - changed_floating = true; - if (mouse_origin.y > midway_y) { - view->height += dy; - edge += WLC_RESIZE_EDGE_BOTTOM; - } else { - view->y += dy; - view->height -= dy; - edge += WLC_RESIZE_EDGE_TOP; + } else if (resizing && view) { + if (view->is_floating) { + int dx = mouse_origin.x - prev_pos.x; + int dy = mouse_origin.y - prev_pos.y; + int min_sane_w = 100; + int min_sane_h = 60; + + // Move and resize the view based on the dx/dy and mouse position + int midway_x = view->x + view->width/2; + int midway_y = view->y + view->height/2; + if (dx < 0) { + if (mouse_origin.x > midway_x && !lock_right) { + if (view->width > min_sane_w) { + lock_left = true; + changed_floating = true; + view->width += dx; + edge += WLC_RESIZE_EDGE_RIGHT; + } + } else if (mouse_origin.x < midway_x && !lock_left) { + lock_right = true; + changed_floating = true; + view->x += dx; + view->width -= dx; + edge += WLC_RESIZE_EDGE_LEFT; + } + } else if (dx > 0){ + if (mouse_origin.x > midway_x && !lock_right) { + lock_left = true; + changed_floating = true; + view->width += dx; + edge += WLC_RESIZE_EDGE_RIGHT; + if (view->width > min_sane_w) { + lock_left = false; + } + } else if (mouse_origin.x < midway_x && !lock_left) { + if (view->width > min_sane_w) { + lock_right = true; + changed_floating = true; + view->x += dx; + view->width -= dx; + edge += WLC_RESIZE_EDGE_LEFT; + } + } } - } else if (dy > 0) { - changed_floating = true; - if (mouse_origin.y > midway_y) { - view->height += dy; - edge += WLC_RESIZE_EDGE_BOTTOM; - } else { - edge = WLC_RESIZE_EDGE_BOTTOM; - view->y += dy; - view->height -= dy; - edge += WLC_RESIZE_EDGE_TOP; + + if (dy < 0) { + if (mouse_origin.y > midway_y && !lock_bottom) { + if (view->height > min_sane_h) { + lock_top = true; + changed_floating = true; + view->height += dy; + edge += WLC_RESIZE_EDGE_BOTTOM; + } + } else if (mouse_origin.y < midway_y && !lock_top) { + lock_bottom = true; + changed_floating = true; + view->y += dy; + view->height -= dy; + edge += WLC_RESIZE_EDGE_TOP; + } + } else if (dy > 0) { + if (mouse_origin.y > midway_y && !lock_bottom) { + lock_top = true; + changed_floating = true; + view->height += dy; + edge += WLC_RESIZE_EDGE_BOTTOM; + } else if (mouse_origin.y < midway_y && !lock_top) { + if (view->height > min_sane_h) { + lock_bottom = true; + changed_floating = true; + view->y += dy; + view->height -= dy; + edge += WLC_RESIZE_EDGE_TOP; + } + } } } } @@ -492,10 +521,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w if (button == 272) { m1_held = false; dragging = false; + lock_top = lock_bottom = lock_left = lock_right = false; } if (button == 273) { m2_held = false; resizing = false; + lock_top = lock_bottom = lock_left = lock_right = false; } } return false; -- cgit v1.2.3 From daea22bc8920fea1d6fba923169173a2bbdc75f9 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Wed, 19 Aug 2015 12:06:00 -0500 Subject: Resize lock fixes --- sway/handlers.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index faade5eb..5e8e05b8 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -388,15 +388,13 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct int midway_x = view->x + view->width/2; int midway_y = view->y + view->height/2; if (dx < 0) { - if (mouse_origin.x > midway_x && !lock_right) { + if (!lock_right) { if (view->width > min_sane_w) { - lock_left = true; changed_floating = true; view->width += dx; edge += WLC_RESIZE_EDGE_RIGHT; } } else if (mouse_origin.x < midway_x && !lock_left) { - lock_right = true; changed_floating = true; view->x += dx; view->width -= dx; @@ -404,16 +402,11 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } else if (dx > 0){ if (mouse_origin.x > midway_x && !lock_right) { - lock_left = true; changed_floating = true; view->width += dx; edge += WLC_RESIZE_EDGE_RIGHT; + } else if (!lock_left) { if (view->width > min_sane_w) { - lock_left = false; - } - } else if (mouse_origin.x < midway_x && !lock_left) { - if (view->width > min_sane_w) { - lock_right = true; changed_floating = true; view->x += dx; view->width -= dx; @@ -423,15 +416,13 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } if (dy < 0) { - if (mouse_origin.y > midway_y && !lock_bottom) { + if (!lock_bottom) { if (view->height > min_sane_h) { - lock_top = true; changed_floating = true; view->height += dy; edge += WLC_RESIZE_EDGE_BOTTOM; } } else if (mouse_origin.y < midway_y && !lock_top) { - lock_bottom = true; changed_floating = true; view->y += dy; view->height -= dy; @@ -439,13 +430,11 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } else if (dy > 0) { if (mouse_origin.y > midway_y && !lock_bottom) { - lock_top = true; changed_floating = true; view->height += dy; edge += WLC_RESIZE_EDGE_BOTTOM; - } else if (mouse_origin.y < midway_y && !lock_top) { + } else if (!lock_top) { if (view->height > min_sane_h) { - lock_bottom = true; changed_floating = true; view->y += dy; view->height -= dy; @@ -511,6 +500,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w if (floating_mod_pressed()) { dragging = m1_held; resizing = m2_held; + int midway_x = pointer->x + pointer->width/2; + int midway_y = pointer->y + pointer->height/2; + lock_bottom = origin->y < midway_y; + lock_top = !lock_bottom; + lock_right = origin->x < midway_x; + lock_left = !lock_right; } //Dont want pointer sent to window while dragging or resizing return (dragging || resizing); -- cgit v1.2.3 From 8f529536e3183cb2ebecee71903edd135316b197 Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 10:27:53 -0700 Subject: pointer uses its own modifiers --- sway/handlers.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 5e8e05b8..71691d7d 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -15,7 +15,6 @@ #include "focus.h" uint32_t keys_pressed[32]; -uint32_t key_modifiers; int keys_pressed_length = 0; @@ -27,10 +26,6 @@ static bool m2_held = false; static bool resizing = false; static bool lock_left, lock_right, lock_top, lock_bottom = false; -static bool floating_mod_pressed(void) { - return key_modifiers & config->floating_mod; -} - static bool pointer_test(swayc_t *view, void *_origin) { const struct wlc_origin *origin = _origin; // Determine the output that the view is under @@ -295,7 +290,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier return false; } bool cmd_success = false; - key_modifiers = modifiers->mods; struct sway_mode *mode = config->current_mode; // Lowercase if necessary @@ -497,7 +491,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w } } arrange_windows(pointer->parent, -1, -1); - if (floating_mod_pressed()) { + if (modifiers->mods & config->floating_mod) { dragging = m1_held; resizing = m2_held; int midway_x = pointer->x + pointer->width/2; @@ -516,7 +510,6 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w if (button == 272) { m1_held = false; dragging = false; - lock_top = lock_bottom = lock_left = lock_right = false; } if (button == 273) { m2_held = false; -- cgit v1.2.3 From 7bbb102e2d49e90f70fa8a954febb091a4d8bb81 Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 10:45:40 -0700 Subject: reset floating view on floating_mod repress --- sway/handlers.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 71691d7d..46d1fff5 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -91,6 +91,31 @@ swayc_t *container_under_pointer(void) { return lookup; } +static struct wlc_geometry saved_floating; + +static void start_floating(swayc_t *view) { + if (view->is_floating) { + saved_floating.origin.x = view->x; + saved_floating.origin.y = view->y; + saved_floating.size.w = view->width; + saved_floating.size.h = view->height; + } +} + +static void reset_floating(swayc_t *view) { + if (view->is_floating) { + view->x = saved_floating.origin.x; + view->y = saved_floating.origin.y; + view->width = saved_floating.size.w; + view->height = saved_floating.size.h; + arrange_windows(view->parent, -1, -1); + } + dragging = resizing = false; + lock_left = lock_right = lock_top = lock_bottom = false; +} + +/* Handles */ + static bool handle_output_created(wlc_handle output) { swayc_t *op = new_output(output); @@ -291,6 +316,10 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier } bool cmd_success = false; + if ((modifiers->mods & config->floating_mod) && (dragging||resizing)) { + reset_floating(get_focused_view(&root_container)); + } + struct sway_mode *mode = config->current_mode; // Lowercase if necessary sym = tolower(sym); @@ -500,6 +529,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w lock_top = !lock_bottom; lock_right = origin->x < midway_x; lock_left = !lock_right; + start_floating(pointer); } //Dont want pointer sent to window while dragging or resizing return (dragging || resizing); -- cgit v1.2.3 From e53a95c60d281ab751e05f4af43eb117ab0880be Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 11:15:13 -0700 Subject: style --- sway/handlers.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 46d1fff5..f7d5386a 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -258,7 +258,7 @@ static void handle_view_focus(wlc_handle view, bool focus) { static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geometry *geometry) { sway_log(L_DEBUG, "geometry request %d x %d : %d x %d", - geometry->origin.x, geometry->origin.y, geometry->size.w,geometry->size.h); + geometry->origin.x, geometry->origin.y, geometry->size.w, geometry->size.h); // If the view is floating, then apply the geometry. // Otherwise save the desired width/height for the view. // This will not do anything for the time being as WLC improperly sends geometry requests @@ -279,12 +279,12 @@ static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geo static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) { swayc_t *c = NULL; - switch(state) { + switch (state) { case WLC_BIT_FULLSCREEN: // i3 just lets it become fullscreen wlc_view_set_state(view, state, toggle); c = get_swayc_for_handle(view, &root_container); - sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d",view,c->name,toggle); + sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d", view, c->name, toggle); if (c) { arrange_windows(c->parent, -1, -1); // Set it as focused window for that workspace if its going fullscreen @@ -316,7 +316,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier } bool cmd_success = false; - if ((modifiers->mods & config->floating_mod) && (dragging||resizing)) { + if ((modifiers->mods & config->floating_mod) && (dragging || resizing)) { reset_floating(get_focused_view(&root_container)); } -- cgit v1.2.3 From c29214f348cef5951eeece3b60383993eaaca305 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Wed, 19 Aug 2015 14:14:54 -0500 Subject: Minor style fix --- sway/handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index f7d5386a..7b82fd03 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -423,7 +423,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct view->width -= dx; edge += WLC_RESIZE_EDGE_LEFT; } - } else if (dx > 0){ + } else if (dx > 0) { if (mouse_origin.x > midway_x && !lock_right) { changed_floating = true; view->width += dx; -- cgit v1.2.3 From 48a983316c01d9ccd9fdd7aab56ee4e779654915 Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 13:02:29 -0700 Subject: floating mode_toggle --- sway/handlers.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 7b82fd03..75adf7dd 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -316,6 +316,9 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier } bool cmd_success = false; + sway_log(L_DEBUG, "modifier %x: state %d: key %d, sym: %d", + modifiers->mods, state, key, sym); + if ((modifiers->mods & config->floating_mod) && (dragging || resizing)) { reset_floating(get_focused_view(&root_container)); } -- cgit v1.2.3 From 269d6ba4ea9d317b4dfae640acce4d5ff142ef84 Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 13:27:06 -0700 Subject: fixed --- sway/handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 75adf7dd..344edd07 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -319,7 +319,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier sway_log(L_DEBUG, "modifier %x: state %d: key %d, sym: %d", modifiers->mods, state, key, sym); - if ((modifiers->mods & config->floating_mod) && (dragging || resizing)) { + if (state == WLC_KEY_STATE_PRESSED && (dragging || resizing)) { reset_floating(get_focused_view(&root_container)); } -- cgit v1.2.3 From a31f23f90c7259f48dcd02eaef08449a226460cd Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 15:22:55 -0700 Subject: fixed active_workspace update on focus change --- sway/handlers.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 344edd07..24189003 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -179,8 +179,14 @@ static bool handle_view_created(wlc_handle handle) { if (!focused || focused->type == C_OUTPUT) { focused = get_focused_container(&root_container); } - sway_log(L_DEBUG, "creating view %ld with type %x, state %x, with parent %ld", - handle, wlc_view_get_type(handle), wlc_view_get_state(handle), parent); + sway_log(L_DEBUG, "handle:%ld type:%x state:%x parent:%ld " + "mask:%d (x:%d y:%d w:%d h:%d) title:%s " + "class:%s appid:%s", + handle, wlc_view_get_type(handle), wlc_view_get_state(handle), parent, + wlc_view_get_mask(handle), wlc_view_get_geometry(handle)->origin.x, + wlc_view_get_geometry(handle)->origin.y,wlc_view_get_geometry(handle)->size.w, + wlc_view_get_geometry(handle)->size.h, wlc_view_get_title(handle), + wlc_view_get_class(handle), wlc_view_get_app_id(handle)); // TODO properly figure out how each window should be handled. switch (wlc_view_get_type(handle)) { @@ -319,6 +325,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier sway_log(L_DEBUG, "modifier %x: state %d: key %d, sym: %d", modifiers->mods, state, key, sym); + //Revert floating container back to original position on keypress if (state == WLC_KEY_STATE_PRESSED && (dragging || resizing)) { reset_floating(get_focused_view(&root_container)); } -- cgit v1.2.3 From b79a49a394ede1c07773dadab97b00a4c7b4d835 Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 15:44:13 -0700 Subject: use enums for pointer click names --- sway/handlers.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 24189003..a6dbf94c 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -503,6 +503,14 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct return false; } +enum pointer_values { + M_LEFT_CLICK = 272, + M_RIGHT_CLICK = 273, + M_SCROLL_CLICK = 274, + M_SCROLL_UP = 275, + M_SCROLL_DOWN = 276, +}; + static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { swayc_t *focused = get_focused_container(&root_container); @@ -512,10 +520,10 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w } if (state == WLC_BUTTON_STATE_PRESSED) { sway_log(L_DEBUG, "Mouse button %u pressed", button); - if (button == 272) { + if (button == M_LEFT_CLICK) { m1_held = true; } - if (button == 273) { + if (button == M_RIGHT_CLICK) { m2_held = true; } swayc_t *pointer = container_under_pointer(); @@ -547,11 +555,11 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w return (pointer && pointer != focused); } else { sway_log(L_DEBUG, "Mouse button %u released", button); - if (button == 272) { + if (button == M_LEFT_CLICK) { m1_held = false; dragging = false; } - if (button == 273) { + if (button == M_RIGHT_CLICK) { m2_held = false; resizing = false; lock_top = lock_bottom = lock_left = lock_right = false; -- cgit v1.2.3 From c068f47ce392dab0374b619d6a501ab6974749cc Mon Sep 17 00:00:00 2001 From: Alexander 'z33ky' Hirsch <1zeeky@gmail.com> Date: Thu, 20 Aug 2015 02:10:45 +0200 Subject: Fix potential crash when toggling fullscreen mode --- sway/handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index a6dbf94c..0bb181cc 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -290,8 +290,8 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s // i3 just lets it become fullscreen wlc_view_set_state(view, state, toggle); c = get_swayc_for_handle(view, &root_container); - sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d", view, c->name, toggle); if (c) { + sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d", view, c->name, toggle); arrange_windows(c->parent, -1, -1); // Set it as focused window for that workspace if its going fullscreen if (toggle) { -- cgit v1.2.3 From 2dabca03f404b4c5f0275b39dc6d103a26d43663 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 19 Aug 2015 19:55:40 -0400 Subject: Remove logging of all key presess This makes the logs a bit too hard to read --- sway/handlers.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 0bb181cc..6889fb22 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -322,9 +322,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier } bool cmd_success = false; - sway_log(L_DEBUG, "modifier %x: state %d: key %d, sym: %d", - modifiers->mods, state, key, sym); - //Revert floating container back to original position on keypress if (state == WLC_KEY_STATE_PRESSED && (dragging || resizing)) { reset_floating(get_focused_view(&root_container)); -- cgit v1.2.3 From 84a778b688320ca535cee29f1b6c580ed7f36715 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 19 Aug 2015 20:12:05 -0400 Subject: Improve key buffer handling --- sway/handlers.c | 55 ++++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 6889fb22..c789662e 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -14,9 +14,8 @@ #include "container.h" #include "focus.h" -uint32_t keys_pressed[32]; -int keys_pressed_length = 0; - +#define KEY_CACHE_SIZE 32 +uint32_t keys_pressed[KEY_CACHE_SIZE]; static struct wlc_origin mouse_origin; @@ -284,12 +283,11 @@ static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geo } static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) { - swayc_t *c = NULL; + swayc_t *c = get_swayc_for_handle(view, &root_container); switch (state) { case WLC_BIT_FULLSCREEN: // i3 just lets it become fullscreen wlc_view_set_state(view, state, toggle); - c = get_swayc_for_handle(view, &root_container); if (c) { sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d", view, c->name, toggle); arrange_windows(c->parent, -1, -1); @@ -307,7 +305,9 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s case WLC_BIT_MAXIMIZED: case WLC_BIT_RESIZING: case WLC_BIT_MOVING: + break; case WLC_BIT_ACTIVATED: + sway_log(L_DEBUG, "View %p requested to be activated", c); break; } return; @@ -316,13 +316,12 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { - enum { QSIZE = 32 }; if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { return false; } bool cmd_success = false; - //Revert floating container back to original position on keypress + // Revert floating container back to original position on keypress if (state == WLC_KEY_STATE_PRESSED && (dragging || resizing)) { reset_floating(get_focused_view(&root_container)); } @@ -331,20 +330,23 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier // Lowercase if necessary sym = tolower(sym); - // Find key, if it has been pressed - int mid = 0; - while (mid < keys_pressed_length && keys_pressed[mid] != sym) { - ++mid; + int i; + + for (i = 0; i < KEY_CACHE_SIZE; ++i) { + if (state == WLC_KEY_STATE_PRESSED && keys_pressed[i] == 0) { + keys_pressed[i] = sym; + break; + } else if (state == WLC_KEY_STATE_RELEASED && keys_pressed[i] == sym) { + keys_pressed[i] = 0; + break; + } } - //Add or remove key depending on state - if (state == WLC_KEY_STATE_PRESSED && mid == keys_pressed_length && keys_pressed_length + 1 < QSIZE) { - keys_pressed[keys_pressed_length++] = sym; - } else if (state == WLC_KEY_STATE_RELEASED && mid < keys_pressed_length) { - memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--keys_pressed_length - mid)); - keys_pressed[keys_pressed_length] = 0; + if (i == KEY_CACHE_SIZE) { + sway_log(L_DEBUG, "Key buffer full!"); + return false; } + // TODO: reminder to check conflicts with mod+q+a versus mod+q - int i; for (i = 0; i < mode->bindings->length; ++i) { struct sway_binding *binding = mode->bindings->items[i]; @@ -354,8 +356,8 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier for (j = 0; j < binding->keys->length; ++j) { match = false; xkb_keysym_t *key = binding->keys->items[j]; - uint8_t k; - for (k = 0; k < keys_pressed_length; ++k) { + int k; + for (k = 0; k < KEY_CACHE_SIZE; ++k) { if (keys_pressed[k] == *key) { match = true; break; @@ -368,15 +370,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier if (match) { // Remove matched keys from keys_pressed - int j; - for (j = 0; j < binding->keys->length; ++j) { - uint8_t k; - for (k = 0; k < keys_pressed_length; ++k) { - memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--keys_pressed_length - k)); - keys_pressed[keys_pressed_length] = 0; - break; - } - } if (state == WLC_KEY_STATE_PRESSED) { cmd_success = handle_command(config, binding->command); } else if (state == WLC_KEY_STATE_RELEASED) { @@ -574,6 +567,10 @@ static void handle_wlc_ready(void) { } free_flat_list(config->cmd_queue); config->active = true; + + for (i = 0; i < KEY_CACHE_SIZE; ++i) { + keys_pressed[i] = 0; + } } -- cgit v1.2.3 From 1d8591d9026c19f5c308bed5961341b00aef69ca Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 19 Aug 2015 20:52:52 -0400 Subject: Improve key handling somewhat XKB is fucking bullshit --- sway/handlers.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index c789662e..18f1d13c 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -316,6 +316,14 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { + + static const uint32_t modifier_syms[] = { + XKB_KEY_Shift_L, XKB_KEY_Shift_R, XKB_KEY_Control_L, XKB_KEY_Control_R, + XKB_KEY_Caps_Lock, XKB_KEY_Shift_Lock, XKB_KEY_Meta_L, XKB_KEY_Meta_R, + XKB_KEY_Alt_L, XKB_KEY_Alt_R, XKB_KEY_Super_L, XKB_KEY_Super_R, + XKB_KEY_Hyper_L, XKB_KEY_Hyper_R + }; + if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { return false; } @@ -327,12 +335,28 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier } struct sway_mode *mode = config->current_mode; + + if (!isalnum(sym)) { + // God fucking dammit + return false; + } + // Lowercase if necessary sym = tolower(sym); int i; + bool mod = false; - for (i = 0; i < KEY_CACHE_SIZE; ++i) { + for (i = 0; i < sizeof(modifier_syms) / sizeof(uint32_t); ++i) { + if (modifier_syms[i] == sym) { + mod = true; + break; + } + } + + int total = 0; + for (i = 0; i < KEY_CACHE_SIZE && !mod; ++i) { + total += keys_pressed[i] != 0; if (state == WLC_KEY_STATE_PRESSED && keys_pressed[i] == 0) { keys_pressed[i] = sym; break; @@ -341,10 +365,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier break; } } - if (i == KEY_CACHE_SIZE) { - sway_log(L_DEBUG, "Key buffer full!"); - return false; - } // TODO: reminder to check conflicts with mod+q+a versus mod+q for (i = 0; i < mode->bindings->length; ++i) { -- cgit v1.2.3 From e5d3074d702906f2da8f94d017fd687bebbc3d8e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 19 Aug 2015 21:04:06 -0400 Subject: Whitelist a handful of characters for keys Ones that don't change when you hold shift --- sway/handlers.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 18f1d13c..d45340ad 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -336,7 +336,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier struct sway_mode *mode = config->current_mode; - if (!isalnum(sym)) { + if (!isalnum(sym) && sym != ' ' && sym != XKB_KEY_Escape && sym != XKB_KEY_Tab) { // God fucking dammit return false; } @@ -391,7 +391,8 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier if (match) { // Remove matched keys from keys_pressed if (state == WLC_KEY_STATE_PRESSED) { - cmd_success = handle_command(config, binding->command); + handle_command(config, binding->command); + cmd_success = true; } else if (state == WLC_KEY_STATE_RELEASED) { // TODO: --released } -- cgit v1.2.3 From 4db89b5fe46e8e7dc741b0ccb9fa3d0708c6fa59 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 19 Aug 2015 21:14:34 -0400 Subject: Deal with more xkb bullshit --- sway/handlers.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index d45340ad..63db972e 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -336,9 +336,11 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier struct sway_mode *mode = config->current_mode; - if (!isalnum(sym) && sym != ' ' && sym != XKB_KEY_Escape && sym != XKB_KEY_Tab) { - // God fucking dammit - return false; + if (sym < 70000 /* bullshit made up number */) { + if (!isalnum(sym) && sym != ' ' && sym != XKB_KEY_Escape && sym != XKB_KEY_Tab) { + // God fucking dammit + return false; + } } // Lowercase if necessary -- cgit v1.2.3 From 470b4dfbae146d83c0061b39534c16b5aad90f1c Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 18:59:27 -0700 Subject: key_state.ch, and command conflicts resolved --- sway/handlers.c | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 63db972e..c9d7c7ac 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -13,9 +13,7 @@ #include "workspace.h" #include "container.h" #include "focus.h" - -#define KEY_CACHE_SIZE 32 -uint32_t keys_pressed[KEY_CACHE_SIZE]; +#include "key_state.h" static struct wlc_origin mouse_origin; @@ -327,7 +325,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { return false; } - bool cmd_success = false; // Revert floating container back to original position on keypress if (state == WLC_KEY_STATE_PRESSED && (dragging || resizing)) { @@ -356,16 +353,10 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier } } - int total = 0; - for (i = 0; i < KEY_CACHE_SIZE && !mod; ++i) { - total += keys_pressed[i] != 0; - if (state == WLC_KEY_STATE_PRESSED && keys_pressed[i] == 0) { - keys_pressed[i] = sym; - break; - } else if (state == WLC_KEY_STATE_RELEASED && keys_pressed[i] == sym) { - keys_pressed[i] = 0; - break; - } + if (state == WLC_KEY_STATE_PRESSED) { + press_key(sym); + } else { // WLC_KEY_STATE_RELEASED + release_key(sym); } // TODO: reminder to check conflicts with mod+q+a versus mod+q @@ -376,32 +367,22 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier bool match; int j; for (j = 0; j < binding->keys->length; ++j) { - match = false; xkb_keysym_t *key = binding->keys->items[j]; - int k; - for (k = 0; k < KEY_CACHE_SIZE; ++k) { - if (keys_pressed[k] == *key) { - match = true; - break; - } - } - if (match == false) { + if ((match = check_key(*key)) == false) { break; } } - if (match) { - // Remove matched keys from keys_pressed if (state == WLC_KEY_STATE_PRESSED) { handle_command(config, binding->command); - cmd_success = true; + return true; } else if (state == WLC_KEY_STATE_RELEASED) { // TODO: --released } } } } - return cmd_success; + return false; } static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) { @@ -590,10 +571,6 @@ static void handle_wlc_ready(void) { } free_flat_list(config->cmd_queue); config->active = true; - - for (i = 0; i < KEY_CACHE_SIZE; ++i) { - keys_pressed[i] = 0; - } } -- cgit v1.2.3 From 5ff0619ca1cab044004df044c253c9170b8316c3 Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 20:22:15 -0700 Subject: input state, find_container_in_direction --- sway/handlers.c | 93 +++++++++++++++++++-------------------------------------- 1 file changed, 30 insertions(+), 63 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index c9d7c7ac..03a32835 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -13,16 +13,10 @@ #include "workspace.h" #include "container.h" #include "focus.h" -#include "key_state.h" +#include "input_state.h" static struct wlc_origin mouse_origin; -static bool m1_held = false; -static bool dragging = false; -static bool m2_held = false; -static bool resizing = false; -static bool lock_left, lock_right, lock_top, lock_bottom = false; - static bool pointer_test(swayc_t *view, void *_origin) { const struct wlc_origin *origin = _origin; // Determine the output that the view is under @@ -88,29 +82,6 @@ swayc_t *container_under_pointer(void) { return lookup; } -static struct wlc_geometry saved_floating; - -static void start_floating(swayc_t *view) { - if (view->is_floating) { - saved_floating.origin.x = view->x; - saved_floating.origin.y = view->y; - saved_floating.size.w = view->width; - saved_floating.size.h = view->height; - } -} - -static void reset_floating(swayc_t *view) { - if (view->is_floating) { - view->x = saved_floating.origin.x; - view->y = saved_floating.origin.y; - view->width = saved_floating.size.w; - view->height = saved_floating.size.h; - arrange_windows(view->parent, -1, -1); - } - dragging = resizing = false; - lock_left = lock_right = lock_top = lock_bottom = false; -} - /* Handles */ static bool handle_output_created(wlc_handle output) { @@ -327,7 +298,8 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier } // Revert floating container back to original position on keypress - if (state == WLC_KEY_STATE_PRESSED && (dragging || resizing)) { + if (state == WLC_KEY_STATE_PRESSED && + (pointer_state.floating.drag || pointer_state.floating.resize)) { reset_floating(get_focused_view(&root_container)); } @@ -396,7 +368,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct // Do checks to determine if proper keys are being held swayc_t *view = get_focused_view(active_workspace); uint32_t edge = 0; - if (dragging && view) { + if (pointer_state.floating.drag && view) { if (view->is_floating) { int dx = mouse_origin.x - prev_pos.x; int dy = mouse_origin.y - prev_pos.y; @@ -404,7 +376,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct view->y += dy; changed_floating = true; } - } else if (resizing && view) { + } else if (pointer_state.floating.resize && view) { if (view->is_floating) { int dx = mouse_origin.x - prev_pos.x; int dy = mouse_origin.y - prev_pos.y; @@ -415,24 +387,24 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct int midway_x = view->x + view->width/2; int midway_y = view->y + view->height/2; if (dx < 0) { - if (!lock_right) { + if (!pointer_state.lock.right) { if (view->width > min_sane_w) { changed_floating = true; view->width += dx; edge += WLC_RESIZE_EDGE_RIGHT; } - } else if (mouse_origin.x < midway_x && !lock_left) { + } else if (mouse_origin.x < midway_x && !pointer_state.lock.left) { changed_floating = true; view->x += dx; view->width -= dx; edge += WLC_RESIZE_EDGE_LEFT; } } else if (dx > 0) { - if (mouse_origin.x > midway_x && !lock_right) { + if (mouse_origin.x > midway_x && !pointer_state.lock.right) { changed_floating = true; view->width += dx; edge += WLC_RESIZE_EDGE_RIGHT; - } else if (!lock_left) { + } else if (!pointer_state.lock.left) { if (view->width > min_sane_w) { changed_floating = true; view->x += dx; @@ -443,24 +415,24 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } if (dy < 0) { - if (!lock_bottom) { + if (!pointer_state.lock.bottom) { if (view->height > min_sane_h) { changed_floating = true; view->height += dy; edge += WLC_RESIZE_EDGE_BOTTOM; } - } else if (mouse_origin.y < midway_y && !lock_top) { + } else if (mouse_origin.y < midway_y && !pointer_state.lock.top) { changed_floating = true; view->y += dy; view->height -= dy; edge += WLC_RESIZE_EDGE_TOP; } } else if (dy > 0) { - if (mouse_origin.y > midway_y && !lock_bottom) { + if (mouse_origin.y > midway_y && !pointer_state.lock.bottom) { changed_floating = true; view->height += dy; edge += WLC_RESIZE_EDGE_BOTTOM; - } else if (!lock_top) { + } else if (!pointer_state.lock.top) { if (view->height > min_sane_h) { changed_floating = true; view->y += dy; @@ -474,7 +446,8 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct if (config->focus_follows_mouse && prev_handle != handle) { //Dont change focus if fullscreen swayc_t *focused = get_focused_view(view); - if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) && !(m1_held || m2_held)) { + if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) + && !(pointer_state.l_held || pointer_state.r_held)) { set_focused_container(container_under_pointer()); } } @@ -497,13 +470,6 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct return false; } -enum pointer_values { - M_LEFT_CLICK = 272, - M_RIGHT_CLICK = 273, - M_SCROLL_CLICK = 274, - M_SCROLL_UP = 275, - M_SCROLL_DOWN = 276, -}; static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { @@ -515,10 +481,10 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w if (state == WLC_BUTTON_STATE_PRESSED) { sway_log(L_DEBUG, "Mouse button %u pressed", button); if (button == M_LEFT_CLICK) { - m1_held = true; + pointer_state.l_held = true; } if (button == M_RIGHT_CLICK) { - m2_held = true; + pointer_state.r_held = true; } swayc_t *pointer = container_under_pointer(); set_focused_container(pointer); @@ -533,30 +499,31 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w } arrange_windows(pointer->parent, -1, -1); if (modifiers->mods & config->floating_mod) { - dragging = m1_held; - resizing = m2_held; int midway_x = pointer->x + pointer->width/2; int midway_y = pointer->y + pointer->height/2; - lock_bottom = origin->y < midway_y; - lock_top = !lock_bottom; - lock_right = origin->x < midway_x; - lock_left = !lock_right; + + pointer_state.floating.drag = pointer_state.l_held; + pointer_state.floating.resize = pointer_state.r_held; + pointer_state.lock.bottom = origin->y < midway_y; + pointer_state.lock.top = !pointer_state.lock.bottom; + pointer_state.lock.right = origin->x < midway_x; + pointer_state.lock.left = !pointer_state.lock.right; start_floating(pointer); } //Dont want pointer sent to window while dragging or resizing - return (dragging || resizing); + return (pointer_state.floating.drag || pointer_state.floating.resize); } return (pointer && pointer != focused); } else { sway_log(L_DEBUG, "Mouse button %u released", button); if (button == M_LEFT_CLICK) { - m1_held = false; - dragging = false; + pointer_state.l_held = false; + pointer_state.floating.drag = false; } if (button == M_RIGHT_CLICK) { - m2_held = false; - resizing = false; - lock_top = lock_bottom = lock_left = lock_right = false; + pointer_state.r_held = false; + pointer_state.floating.resize = false; + pointer_state.lock = (struct pointer_lock){false ,false ,false ,false}; } } return false; -- cgit v1.2.3 From 85ae987515a9227bde15c736a941d5ee59e49dc3 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 20 Aug 2015 07:38:40 -0400 Subject: Fix compiler warning --- sway/handlers.c | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 03a32835..6c103b02 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -286,13 +286,6 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { - static const uint32_t modifier_syms[] = { - XKB_KEY_Shift_L, XKB_KEY_Shift_R, XKB_KEY_Control_L, XKB_KEY_Control_R, - XKB_KEY_Caps_Lock, XKB_KEY_Shift_Lock, XKB_KEY_Meta_L, XKB_KEY_Meta_R, - XKB_KEY_Alt_L, XKB_KEY_Alt_R, XKB_KEY_Super_L, XKB_KEY_Super_R, - XKB_KEY_Hyper_L, XKB_KEY_Hyper_R - }; - if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { return false; } @@ -316,14 +309,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier sym = tolower(sym); int i; - bool mod = false; - - for (i = 0; i < sizeof(modifier_syms) / sizeof(uint32_t); ++i) { - if (modifier_syms[i] == sym) { - mod = true; - break; - } - } if (state == WLC_KEY_STATE_PRESSED) { press_key(sym); -- cgit v1.2.3 From f5fde7c45c04b02406eabc34cbb4248189c6a26e Mon Sep 17 00:00:00 2001 From: taiyu Date: Thu, 20 Aug 2015 05:06:22 -0700 Subject: style --- sway/handlers.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 03a32835..2f062911 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -87,7 +87,7 @@ swayc_t *container_under_pointer(void) { static bool handle_output_created(wlc_handle output) { swayc_t *op = new_output(output); - //Switch to workspace if we need to + // Switch to workspace if we need to if (active_workspace == NULL) { swayc_t *ws = op->children->items[0]; workspace_switch(ws); @@ -109,7 +109,7 @@ static void handle_output_destroyed(wlc_handle output) { if (list->length == 0) { active_workspace = NULL; } else { - //switch to other outputs active workspace + // switch to other outputs active workspace workspace_switch(((swayc_t *)root_container.children->items[0])->focused); } } @@ -167,7 +167,7 @@ static bool handle_view_created(wlc_handle handle) { // Dmenu keeps viewfocus, but others with this flag dont, for now simulate // dmenu case WLC_BIT_OVERRIDE_REDIRECT: -// locked_view_focus = true; +// locked_view_focus = true; wlc_view_focus(handle); wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); wlc_view_bring_to_front(handle); @@ -217,7 +217,7 @@ static void handle_view_destroyed(wlc_handle handle) { // DMENU has this flag, and takes view_focus, but other things with this // flag dont case WLC_BIT_OVERRIDE_REDIRECT: -// locked_view_focus = false; +// locked_view_focus = false; break; case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: locked_container_focus = false; @@ -444,7 +444,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } if (config->focus_follows_mouse && prev_handle != handle) { - //Dont change focus if fullscreen + // Dont change focus if fullscreen swayc_t *focused = get_focused_view(view); if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) && !(pointer_state.l_held || pointer_state.r_held)) { @@ -474,7 +474,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { swayc_t *focused = get_focused_container(&root_container); - //dont change focus if fullscreen + // dont change focus if fullscreen if (focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) { return false; } @@ -510,7 +510,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w pointer_state.lock.left = !pointer_state.lock.right; start_floating(pointer); } - //Dont want pointer sent to window while dragging or resizing + // Dont want pointer sent to window while dragging or resizing return (pointer_state.floating.drag || pointer_state.floating.resize); } return (pointer && pointer != focused); -- cgit v1.2.3 From 36e07e9ebc55b3fc8a8b8cd76ee743202691ad56 Mon Sep 17 00:00:00 2001 From: taiyu Date: Thu, 20 Aug 2015 09:52:54 -0700 Subject: find_parent_by_type --- sway/handlers.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 5993223d..79628fe5 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -20,10 +20,7 @@ static struct wlc_origin mouse_origin; static bool pointer_test(swayc_t *view, void *_origin) { const struct wlc_origin *origin = _origin; // Determine the output that the view is under - swayc_t *parent = view; - while (parent->type != C_OUTPUT) { - parent = parent->parent; - } + swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); if (origin->x >= view->x && origin->y >= view->y && origin->x < view->x + view->width && origin->y < view->y + view->height && view->visible && parent == root_container.focused) { @@ -191,10 +188,7 @@ static bool handle_view_created(wlc_handle handle) { if (newview) { set_focused_container(newview); - swayc_t *output = newview->parent; - while (output && output->type != C_OUTPUT) { - output = output->parent; - } + swayc_t *output = swayc_parent_by_type(newview, C_OUTPUT); arrange_windows(output, -1, -1); } return true; @@ -262,10 +256,7 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s arrange_windows(c->parent, -1, -1); // Set it as focused window for that workspace if its going fullscreen if (toggle) { - swayc_t *ws = c; - while (ws->type != C_WORKSPACE) { - ws = ws->parent; - } + swayc_t *ws = swayc_parent_by_type(c, C_WORKSPACE); // Set ws focus to c set_focused_container_for(ws, c); } -- cgit v1.2.3