diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-15 18:47:44 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-15 18:47:44 -0400 |
commit | 2732c40813557882a1e5b09fd9cdf592bdcc3247 (patch) | |
tree | 5a2229d9e33968aba41c4bd4cd76dd1d11a41ab9 | |
parent | Merge pull request #33 from Luminarys/master (diff) | |
parent | made better, reduced code duplication (diff) | |
download | sway-2732c40813557882a1e5b09fd9cdf592bdcc3247.tar.gz sway-2732c40813557882a1e5b09fd9cdf592bdcc3247.tar.zst sway-2732c40813557882a1e5b09fd9cdf592bdcc3247.zip |
Merge pull request #34 from taiyu-len/master
fixed fullscreen & focusing
-rw-r--r-- | sway/commands.c | 8 | ||||
-rw-r--r-- | sway/handlers.c | 51 | ||||
-rw-r--r-- | sway/handlers.h | 4 |
3 files changed, 34 insertions, 29 deletions
diff --git a/sway/commands.c b/sway/commands.c index 742d6b86..20e0fc8d 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -286,6 +286,14 @@ static bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | |||
286 | swayc_t *container = get_focused_container(&root_container); | 286 | swayc_t *container = get_focused_container(&root_container); |
287 | bool current = (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) > 0; | 287 | bool current = (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) > 0; |
288 | wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current); | 288 | wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current); |
289 | //Resize workspace if going from fullscreen -> notfullscreen | ||
290 | //otherwise just resize container | ||
291 | if (current) { | ||
292 | while (container->type != C_WORKSPACE) { | ||
293 | container = container->parent; | ||
294 | } | ||
295 | } | ||
296 | //Only resize container when going into fullscreen | ||
289 | arrange_windows(container, -1, -1); | 297 | arrange_windows(container, -1, -1); |
290 | 298 | ||
291 | return true; | 299 | return true; |
diff --git a/sway/handlers.c b/sway/handlers.c index f95683d0..98d4831f 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -28,15 +28,19 @@ static bool pointer_test(swayc_t *view, void *_origin) { | |||
28 | return false; | 28 | return false; |
29 | } | 29 | } |
30 | 30 | ||
31 | void focus_pointer(void) { | 31 | swayc_t *focus_pointer(void) { |
32 | swayc_t *focused = find_container(&root_container, pointer_test, &mouse_origin); | 32 | swayc_t *focused = get_focused_container(&root_container); |
33 | if (focused) { | 33 | if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) { |
34 | sway_log(L_DEBUG, "Switching focus to %p", focused); | 34 | swayc_t *pointer = find_container(&root_container, pointer_test, &mouse_origin); |
35 | unfocus_all(&root_container); | 35 | if (pointer && focused != pointer) { |
36 | focus_view(focused); | 36 | unfocus_all(&root_container); |
37 | } else { | 37 | focus_view(pointer); |
38 | focus_view(active_workspace); | 38 | } else if (!focused){ |
39 | focus_view(active_workspace); | ||
40 | } | ||
41 | focused = pointer; | ||
39 | } | 42 | } |
43 | return focused; | ||
40 | } | 44 | } |
41 | 45 | ||
42 | static bool handle_output_created(wlc_handle output) { | 46 | static bool handle_output_created(wlc_handle output) { |
@@ -82,16 +86,21 @@ static void handle_output_focused(wlc_handle output, bool focus) { | |||
82 | } | 86 | } |
83 | 87 | ||
84 | static bool handle_view_created(wlc_handle handle) { | 88 | static bool handle_view_created(wlc_handle handle) { |
85 | swayc_t *container = get_focused_container(&root_container); | 89 | swayc_t *focused = get_focused_container(&root_container); |
86 | swayc_t *view = new_view(container, handle); | 90 | swayc_t *view = new_view(focused, handle); |
87 | unfocus_all(&root_container); | ||
88 | if (view) { | 91 | if (view) { |
92 | unfocus_all(&root_container); | ||
89 | focus_view(view); | 93 | focus_view(view); |
90 | arrange_windows(view->parent, -1, -1); | 94 | arrange_windows(view->parent, -1, -1); |
91 | } else { //Unmanaged view | 95 | } else { //Unmanaged view |
92 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); | 96 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); |
93 | wlc_view_focus(handle); | 97 | wlc_view_focus(handle); |
94 | } | 98 | } |
99 | if (wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) { | ||
100 | unfocus_all(&root_container); | ||
101 | focus_view(focused); | ||
102 | arrange_windows(focused, -1, -1); | ||
103 | } | ||
95 | return true; | 104 | return true; |
96 | } | 105 | } |
97 | 106 | ||
@@ -189,28 +198,16 @@ static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct w | |||
189 | if (!config->focus_follows_mouse) { | 198 | if (!config->focus_follows_mouse) { |
190 | return true; | 199 | return true; |
191 | } | 200 | } |
192 | swayc_t *c = find_container(&root_container, pointer_test, (void *)origin); | 201 | focus_pointer(); |
193 | swayc_t *focused = get_focused_container(&root_container); | ||
194 | if (c && c != focused) { | ||
195 | sway_log(L_DEBUG, "Switching focus to %p", c); | ||
196 | unfocus_all(&root_container); | ||
197 | focus_view(c); | ||
198 | } | ||
199 | return true; | 202 | return true; |
200 | } | 203 | } |
201 | 204 | ||
202 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, | 205 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, |
203 | uint32_t button, enum wlc_button_state state) { | 206 | uint32_t button, enum wlc_button_state state) { |
207 | swayc_t *focused = get_focused_container(&root_container); | ||
204 | if (state == WLC_BUTTON_STATE_PRESSED) { | 208 | if (state == WLC_BUTTON_STATE_PRESSED) { |
205 | swayc_t *c = find_container(&root_container, pointer_test, &mouse_origin); | 209 | swayc_t *pointer = focus_pointer(); |
206 | swayc_t *focused = get_focused_container(&root_container); | 210 | return !(pointer && pointer != focused); |
207 | if (c && c != focused) { | ||
208 | sway_log(L_DEBUG, "Switching focus to %p", c); | ||
209 | unfocus_all(&root_container); | ||
210 | focus_view(c); | ||
211 | return false; | ||
212 | } | ||
213 | return true; | ||
214 | } | 211 | } |
215 | return true; | 212 | return true; |
216 | } | 213 | } |
diff --git a/sway/handlers.h b/sway/handlers.h index b8b171c3..d1742cce 100644 --- a/sway/handlers.h +++ b/sway/handlers.h | |||
@@ -6,7 +6,7 @@ | |||
6 | 6 | ||
7 | extern struct wlc_interface interface; | 7 | extern struct wlc_interface interface; |
8 | 8 | ||
9 | //set focus to current pointer location | 9 | //set focus to current pointer location and return focused container |
10 | void focus_pointer(void); | 10 | swayc_t *focus_pointer(void); |
11 | 11 | ||
12 | #endif | 12 | #endif |