From 87af08966a5080345e2d4935d886b9fe91f66159 Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Thu, 24 May 2018 21:02:38 +0300 Subject: [PATCH 01/11] Don't focus tabbed and stacked containers on mouseover --- sway/input/cursor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 9a0b4f01..0f8202ea 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -162,7 +162,11 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, seat_set_focus_warp(cursor->seat, c, false); } } else { - seat_set_focus_warp(cursor->seat, c, false); + // Don't switch focus on mouseover for stacked and tabbed layouts + if(c->parent && c->parent->layout != L_STACKED + && c->parent->layout != L_TABBED) { + seat_set_focus_warp(cursor->seat, c, false); + } } } From c1be4b0153fc18b130ce795e71c8600c2dd31fc0 Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Thu, 24 May 2018 23:19:18 +0300 Subject: [PATCH 02/11] Fix focusing from other containers --- sway/input/cursor.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 0f8202ea..72dc8700 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -163,8 +163,9 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, } } else { // Don't switch focus on mouseover for stacked and tabbed layouts - if(c->parent && c->parent->layout != L_STACKED - && c->parent->layout != L_TABBED) { + if(focus->parent == c->parent && + (c->parent->layout != L_STACKED + || c->parent->layout != L_TABBED)) { seat_set_focus_warp(cursor->seat, c, false); } } From c62efbb5cea36300706e0b366a271697da70d201 Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Fri, 25 May 2018 14:12:09 +0300 Subject: [PATCH 03/11] Implement correct focusing for tabbed containers --- sway/input/cursor.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 72dc8700..564c7763 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -162,10 +162,31 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, seat_set_focus_warp(cursor->seat, c, false); } } else { - // Don't switch focus on mouseover for stacked and tabbed layouts - if(focus->parent == c->parent && - (c->parent->layout != L_STACKED - || c->parent->layout != L_TABBED)) { + // Get container-local cursor position + double c_local_y = cursor->cursor->y - c->y; + bool is_below_title = + c_local_y - container_titlebar_height() > 0.001; + + bool do_mouse_focus = true; + + // Don't switch focus on title mouseover for stacked and tabbed + // layouts + if(c->parent && (c->parent->layout == L_STACKED + || c->parent->layout == L_TABBED) + && !is_below_title) { + do_mouse_focus = false; + } + + // If pointed container is in nested container + // inside tabbed/stacked layout we should skip this nested container + if(c->parent && c->parent->parent && + (c->parent->parent->layout == L_STACKED + || c->parent->parent->layout == L_TABBED) + && !is_below_title) { + do_mouse_focus = false; + } + + if(do_mouse_focus) { seat_set_focus_warp(cursor->seat, c, false); } } From 3b672533128d5ff7233e26603d52277abfd6724a Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Fri, 25 May 2018 15:37:06 +0300 Subject: [PATCH 04/11] Skip all nested containers --- sway/input/cursor.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 564c7763..4b15e0e2 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -167,23 +167,19 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, bool is_below_title = c_local_y - container_titlebar_height() > 0.001; + // Don't switch focus on title mouseover for + // stacked and tabbed layouts + // If pointed container is in nested containers which are + // inside tabbed/stacked layout we should skip them bool do_mouse_focus = true; - - // Don't switch focus on title mouseover for stacked and tabbed - // layouts - if(c->parent && (c->parent->layout == L_STACKED - || c->parent->layout == L_TABBED) - && !is_below_title) { - do_mouse_focus = false; - } - - // If pointed container is in nested container - // inside tabbed/stacked layout we should skip this nested container - if(c->parent && c->parent->parent && - (c->parent->parent->layout == L_STACKED - || c->parent->parent->layout == L_TABBED) - && !is_below_title) { - do_mouse_focus = false; + struct sway_container *p = c->parent; + while(p) { + if((p->layout == L_TABBED || p->layout == L_STACKED) + && !is_below_title) { + do_mouse_focus = false; + break; + } + p = p->parent; } if(do_mouse_focus) { From e19fe56e2f6bd0bf6cc9c8d608941116ebd06c49 Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Fri, 25 May 2018 16:41:16 +0300 Subject: [PATCH 05/11] Focus inactive container instead of checking cursor position --- sway/input/cursor.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 4b15e0e2..36247416 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -162,27 +162,27 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, seat_set_focus_warp(cursor->seat, c, false); } } else { - // Get container-local cursor position - double c_local_y = cursor->cursor->y - c->y; - bool is_below_title = - c_local_y - container_titlebar_height() > 0.001; - // Don't switch focus on title mouseover for // stacked and tabbed layouts // If pointed container is in nested containers which are // inside tabbed/stacked layout we should skip them bool do_mouse_focus = true; struct sway_container *p = c->parent; + struct sway_container *first_tabbed_parent = c->parent; while(p) { - if((p->layout == L_TABBED || p->layout == L_STACKED) - && !is_below_title) { + if(p->layout == L_TABBED || p->layout == L_STACKED) { do_mouse_focus = false; - break; + first_tabbed_parent = p; } p = p->parent; } - - if(do_mouse_focus) { + if(!do_mouse_focus) { + struct sway_container *next_focus = seat_get_focus_inactive( + cursor->seat, first_tabbed_parent); + if(next_focus) { + seat_set_focus_warp(cursor->seat, next_focus, false); + } + } else { seat_set_focus_warp(cursor->seat, c, false); } } From f85d3e15ba058daf5b7325ab51a8e5ccca18e8d4 Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Fri, 25 May 2018 16:51:03 +0300 Subject: [PATCH 06/11] Fixed styling issues --- sway/input/cursor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 36247416..bd23af6f 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -169,17 +169,17 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, bool do_mouse_focus = true; struct sway_container *p = c->parent; struct sway_container *first_tabbed_parent = c->parent; - while(p) { - if(p->layout == L_TABBED || p->layout == L_STACKED) { + while (p) { + if (p->layout == L_TABBED || p->layout == L_STACKED) { do_mouse_focus = false; first_tabbed_parent = p; } p = p->parent; } - if(!do_mouse_focus) { + if (!do_mouse_focus) { struct sway_container *next_focus = seat_get_focus_inactive( cursor->seat, first_tabbed_parent); - if(next_focus) { + if (next_focus) { seat_set_focus_warp(cursor->seat, next_focus, false); } } else { From 53516fa03fd291cdcedbd9e27457cf1cfd40f903 Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Fri, 25 May 2018 17:22:25 +0300 Subject: [PATCH 07/11] Fix mouse focusing for horizontal/vertical views in tabbed containers --- sway/input/cursor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index bd23af6f..4e01df70 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -170,7 +170,8 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, struct sway_container *p = c->parent; struct sway_container *first_tabbed_parent = c->parent; while (p) { - if (p->layout == L_TABBED || p->layout == L_STACKED) { + if ((p->layout == L_TABBED || p->layout == L_STACKED) + && !view_is_visible(c->sway_view)) { do_mouse_focus = false; first_tabbed_parent = p; } From 740234a4bc9c8509c766f8feb9f7116bf8950c49 Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Fri, 25 May 2018 17:45:41 +0300 Subject: [PATCH 08/11] Break after first tabbed/stacked layout --- sway/input/cursor.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 4e01df70..0b6999ea 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -168,19 +168,18 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, // inside tabbed/stacked layout we should skip them bool do_mouse_focus = true; struct sway_container *p = c->parent; - struct sway_container *first_tabbed_parent = c->parent; while (p) { if ((p->layout == L_TABBED || p->layout == L_STACKED) && !view_is_visible(c->sway_view)) { do_mouse_focus = false; - first_tabbed_parent = p; + break; } p = p->parent; } if (!do_mouse_focus) { struct sway_container *next_focus = seat_get_focus_inactive( - cursor->seat, first_tabbed_parent); - if (next_focus) { + cursor->seat, p); + if (next_focus && view_is_visible(next_focus->sway_view)) { seat_set_focus_warp(cursor->seat, next_focus, false); } } else { From 820a8c9c2d12b863b7bf9a9d2f45a3214dff72fa Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Sat, 26 May 2018 13:34:14 +0300 Subject: [PATCH 09/11] Moved visibility check of of loop, added asserts --- sway/input/cursor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 0b6999ea..b404a634 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -167,10 +167,12 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, // If pointed container is in nested containers which are // inside tabbed/stacked layout we should skip them bool do_mouse_focus = true; + sway_assert(c->type == C_VIEW, "pointed container is not a view"); + bool is_visible = view_is_visible(c->sway_view); struct sway_container *p = c->parent; while (p) { if ((p->layout == L_TABBED || p->layout == L_STACKED) - && !view_is_visible(c->sway_view)) { + && !is_visible) { do_mouse_focus = false; break; } @@ -179,6 +181,8 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, if (!do_mouse_focus) { struct sway_container *next_focus = seat_get_focus_inactive( cursor->seat, p); + sway_assert(next_focus->type == C_VIEW, + "focus inactive container is not a view"); if (next_focus && view_is_visible(next_focus->sway_view)) { seat_set_focus_warp(cursor->seat, next_focus, false); } From 6e6b0decd95eb3fd4b336817839c08a2c71c7505 Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Sat, 26 May 2018 15:51:36 +0300 Subject: [PATCH 10/11] Fix usage of sway_assert --- sway/input/cursor.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index b404a634..62967cb8 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -167,7 +167,9 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, // If pointed container is in nested containers which are // inside tabbed/stacked layout we should skip them bool do_mouse_focus = true; - sway_assert(c->type == C_VIEW, "pointed container is not a view"); + if(!sway_assert(c->type == C_VIEW, "pointed container is not a view")) { + return; + } bool is_visible = view_is_visible(c->sway_view); struct sway_container *p = c->parent; while (p) { @@ -181,8 +183,10 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, if (!do_mouse_focus) { struct sway_container *next_focus = seat_get_focus_inactive( cursor->seat, p); - sway_assert(next_focus->type == C_VIEW, - "focus inactive container is not a view"); + if(!sway_assert(next_focus->type == C_VIEW, + "focus inactive container is not a view")) { + return; + } if (next_focus && view_is_visible(next_focus->sway_view)) { seat_set_focus_warp(cursor->seat, next_focus, false); } From 464ec44b005aa7584c9240cb9721382d23d288cf Mon Sep 17 00:00:00 2001 From: Ivan Chebykin Date: Sat, 26 May 2018 15:54:49 +0300 Subject: [PATCH 11/11] Check for next_focus before assert --- sway/input/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 62967cb8..98780989 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -183,7 +183,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, if (!do_mouse_focus) { struct sway_container *next_focus = seat_get_focus_inactive( cursor->seat, p); - if(!sway_assert(next_focus->type == C_VIEW, + if(next_focus && !sway_assert(next_focus->type == C_VIEW, "focus inactive container is not a view")) { return; }