diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-10-06 14:53:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-06 14:53:26 -0400 |
commit | 6fb7d0e30cf7134cc69d6ce0cc116471d6a4f74d (patch) | |
tree | 3f70c9beb4f0ed4e588652969e9e9bcbdaa53adc | |
parent | Merge pull request #928 from wasamasa/bugfix-swaylock-font (diff) | |
parent | add click on title_bar to focus a container (diff) | |
download | sway-6fb7d0e30cf7134cc69d6ce0cc116471d6a4f74d.tar.gz sway-6fb7d0e30cf7134cc69d6ce0cc116471d6a4f74d.tar.zst sway-6fb7d0e30cf7134cc69d6ce0cc116471d6a4f74d.zip |
Merge pull request #933 from alkino/click_title_bar
add click on title_bar to focus a container
-rw-r--r-- | include/sway/container.h | 4 | ||||
-rw-r--r-- | sway/container.c | 19 | ||||
-rw-r--r-- | sway/handlers.c | 15 |
3 files changed, 38 insertions, 0 deletions
diff --git a/include/sway/container.h b/include/sway/container.h index 67b747a0..5e251885 100644 --- a/include/sway/container.h +++ b/include/sway/container.h | |||
@@ -243,6 +243,10 @@ swayc_t *swayc_active_workspace_for(swayc_t *view); | |||
243 | * Finds the container currently underneath the pointer. | 243 | * Finds the container currently underneath the pointer. |
244 | */ | 244 | */ |
245 | swayc_t *container_under_pointer(void); | 245 | swayc_t *container_under_pointer(void); |
246 | /** | ||
247 | * Finds the first container following a callback. | ||
248 | */ | ||
249 | swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *), const void *data); | ||
246 | 250 | ||
247 | /** | 251 | /** |
248 | * Returns true if a container is fullscreen. | 252 | * Returns true if a container is fullscreen. |
diff --git a/sway/container.c b/sway/container.c index 73b627ec..9d5e2690 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -722,6 +722,25 @@ swayc_t *container_under_pointer(void) { | |||
722 | return lookup; | 722 | return lookup; |
723 | } | 723 | } |
724 | 724 | ||
725 | swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *), const void *data) { | ||
726 | if (container->children == NULL || container->children->length == 0) { | ||
727 | return NULL; | ||
728 | } | ||
729 | |||
730 | for (int i = 0; i < container->children->length; ++i) { | ||
731 | if (f(container->children->items[i], data)) { | ||
732 | return container->children->items[i]; | ||
733 | } | ||
734 | |||
735 | swayc_t *find = container_find(container->children->items[i], f, data); | ||
736 | if (find != NULL) { | ||
737 | return find; | ||
738 | } | ||
739 | } | ||
740 | |||
741 | return NULL; | ||
742 | } | ||
743 | |||
725 | // Container information | 744 | // Container information |
726 | 745 | ||
727 | bool swayc_is_fullscreen(swayc_t *view) { | 746 | bool swayc_is_fullscreen(swayc_t *view) { |
diff --git a/sway/handlers.c b/sway/handlers.c index 1afdcbbb..b6bc11c0 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -776,6 +776,14 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
776 | return EVENT_PASSTHROUGH; | 776 | return EVENT_PASSTHROUGH; |
777 | } | 777 | } |
778 | 778 | ||
779 | bool swayc_border_check(swayc_t *c, const void *_origin) { | ||
780 | const struct wlc_point *origin = _origin; | ||
781 | if (origin->x >= c->title_bar_geometry.origin.x && origin->y >= c->title_bar_geometry.origin.y | ||
782 | && origin->x < (c->title_bar_geometry.origin.x + (int)c->title_bar_geometry.size.w) && origin->y < (c->title_bar_geometry.origin.y + (int)c->title_bar_geometry.size.h)) { | ||
783 | return true; | ||
784 | } | ||
785 | return false; | ||
786 | } | ||
779 | 787 | ||
780 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, | 788 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, |
781 | uint32_t button, enum wlc_button_state state, const struct wlc_point *origin) { | 789 | uint32_t button, enum wlc_button_state state, const struct wlc_point *origin) { |
@@ -840,6 +848,13 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
840 | // Check whether to change focus | 848 | // Check whether to change focus |
841 | swayc_t *pointer = pointer_state.view; | 849 | swayc_t *pointer = pointer_state.view; |
842 | if (pointer) { | 850 | if (pointer) { |
851 | swayc_t *ws = swayc_parent_by_type(focused, C_WORKSPACE); | ||
852 | swayc_t *find = container_find(ws, &swayc_border_check, origin); | ||
853 | if (find != NULL) { | ||
854 | set_focused_container(find); | ||
855 | return EVENT_HANDLED; | ||
856 | } | ||
857 | |||
843 | if (focused != pointer) { | 858 | if (focused != pointer) { |
844 | set_focused_container(pointer_state.view); | 859 | set_focused_container(pointer_state.view); |
845 | } | 860 | } |