From 1bf02144e558630f36b1efca45d6074be456c0b4 Mon Sep 17 00:00:00 2001 From: taiyu Date: Tue, 18 Aug 2015 23:52:42 -0700 Subject: [PATCH] fixed floating_modifier related things --- sway/container.c | 5 +++-- sway/focus.c | 5 ++++- sway/handlers.c | 45 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/sway/container.c b/sway/container.c index ec4d48b8e..9763f3819 100644 --- a/sway/container.c +++ b/sway/container.c @@ -200,8 +200,9 @@ swayc_t *new_floating_view(wlc_handle handle) { // Set the geometry of the floating view const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); - view->x = geometry->origin.x; - view->y = geometry->origin.y; + //give it requested geometry, but place in center + view->x = (active_workspace->width - geometry->size.w) / 2; + view->y = (active_workspace->height- geometry->size.h) / 2; view->width = geometry->size.w; view->height = geometry->size.h; diff --git a/sway/focus.c b/sway/focus.c index 1f17dfc9e..0ee106943 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -168,8 +168,11 @@ void set_focused_container(swayc_t *c) { } // activate current focus if (p->type == C_VIEW) { - wlc_view_focus(p->handle); wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true); + //set focus if view_focus is unlocked + if (!locked_view_focus) { + wlc_view_focus(p->handle); + } } } } diff --git a/sway/handlers.c b/sway/handlers.c index e785e9c52..d5909c8fe 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 {