diff options
author | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2015-12-21 22:01:36 +0100 |
---|---|---|
committer | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2015-12-21 23:07:52 +0100 |
commit | 50b04884b65b7e04234e8fa794a4e6db48c133a4 (patch) | |
tree | ebf8c63bfb812a5d8bd7ab455a5b68ef81054dd2 /sway | |
parent | Merge pull request #390 from mikkeloscar/workspace-ipc-event (diff) | |
download | sway-50b04884b65b7e04234e8fa794a4e6db48c133a4.tar.gz sway-50b04884b65b7e04234e8fa794a4e6db48c133a4.tar.zst sway-50b04884b65b7e04234e8fa794a4e6db48c133a4.zip |
Trigger ipc_event_workspace in all cases
This makes sure that the workspace IPC event is triggered when needed.
Fixes #382 while making sure that the IPC event is only triggered once.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/focus.c | 15 | ||||
-rw-r--r-- | sway/ipc-server.c | 20 | ||||
-rw-r--r-- | sway/layout.c | 7 |
3 files changed, 29 insertions, 13 deletions
diff --git a/sway/focus.c b/sway/focus.c index c1170ca4..cf0ee7f6 100644 --- a/sway/focus.c +++ b/sway/focus.c | |||
@@ -34,7 +34,7 @@ static void update_focus(swayc_t *c) { | |||
34 | // Case where workspace changes | 34 | // Case where workspace changes |
35 | case C_WORKSPACE: | 35 | case C_WORKSPACE: |
36 | if (prev) { | 36 | if (prev) { |
37 | ipc_event_workspace(prev, c); | 37 | ipc_event_workspace(prev, c, "focus"); |
38 | // update visibility of old workspace | 38 | // update visibility of old workspace |
39 | update_visibility(prev); | 39 | update_visibility(prev); |
40 | 40 | ||
@@ -122,11 +122,6 @@ bool set_focused_container(swayc_t *c) { | |||
122 | p = p->parent; | 122 | p = p->parent; |
123 | p->is_focused = false; | 123 | p->is_focused = false; |
124 | } | 124 | } |
125 | // active_ws might have been destroyed by now | ||
126 | // (focus swap away from empty ws = destroy ws) | ||
127 | if (active_ws_child_count == 0) { | ||
128 | active_ws = NULL; | ||
129 | } | ||
130 | 125 | ||
131 | // get new focused view and set focus to it. | 126 | // get new focused view and set focus to it. |
132 | p = get_focused_view(c); | 127 | p = get_focused_view(c); |
@@ -146,7 +141,13 @@ bool set_focused_container(swayc_t *c) { | |||
146 | } | 141 | } |
147 | 142 | ||
148 | if (active_ws != workspace) { | 143 | if (active_ws != workspace) { |
149 | ipc_event_workspace(active_ws, workspace); | 144 | // active_ws might have been destroyed by now |
145 | // (focus swap away from empty ws = destroy ws) | ||
146 | if (active_ws_child_count == 0) { | ||
147 | active_ws = NULL; | ||
148 | } | ||
149 | |||
150 | ipc_event_workspace(active_ws, workspace, "focus"); | ||
150 | } | 151 | } |
151 | return true; | 152 | return true; |
152 | } | 153 | } |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index b459b5ce..e161c756 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -562,15 +562,23 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { | |||
562 | return json; | 562 | return json; |
563 | } | 563 | } |
564 | 564 | ||
565 | void ipc_event_workspace(swayc_t *old, swayc_t *new) { | 565 | void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) { |
566 | json_object *obj = json_object_new_object(); | 566 | json_object *obj = json_object_new_object(); |
567 | json_object_object_add(obj, "change", json_object_new_string("focus")); | 567 | json_object_object_add(obj, "change", json_object_new_string(change)); |
568 | if (old) { | 568 | if (strcmp("focus", change) == 0) { |
569 | json_object_object_add(obj, "old", ipc_json_describe_workspace(old)); | 569 | if (old) { |
570 | json_object_object_add(obj, "old", ipc_json_describe_workspace(old)); | ||
571 | } else { | ||
572 | json_object_object_add(obj, "old", NULL); | ||
573 | } | ||
574 | } | ||
575 | |||
576 | if (new) { | ||
577 | json_object_object_add(obj, "current", ipc_json_describe_workspace(new)); | ||
570 | } else { | 578 | } else { |
571 | json_object_object_add(obj, "old", NULL); | 579 | json_object_object_add(obj, "current", NULL); |
572 | } | 580 | } |
573 | json_object_object_add(obj, "current", ipc_json_describe_workspace(new)); | 581 | |
574 | const char *json_string = json_object_to_json_string(obj); | 582 | const char *json_string = json_object_to_json_string(obj); |
575 | 583 | ||
576 | for (int i = 0; i < ipc_client_list->length; i++) { | 584 | for (int i = 0; i < ipc_client_list->length; i++) { |
diff --git a/sway/layout.c b/sway/layout.c index a9e7c7f1..563e9d11 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "workspace.h" | 10 | #include "workspace.h" |
11 | #include "focus.h" | 11 | #include "focus.h" |
12 | #include "output.h" | 12 | #include "output.h" |
13 | #include "ipc-server.h" | ||
13 | 14 | ||
14 | swayc_t root_container; | 15 | swayc_t root_container; |
15 | list_t *scratchpad; | 16 | list_t *scratchpad; |
@@ -312,6 +313,12 @@ void move_container_to(swayc_t* container, swayc_t* destination) { | |||
312 | // reset container geometry | 313 | // reset container geometry |
313 | container->width = container->height = 0; | 314 | container->width = container->height = 0; |
314 | add_child(destination, container); | 315 | add_child(destination, container); |
316 | |||
317 | // If the workspace only has one child after adding one, it | ||
318 | // means that the workspace was just initialized. | ||
319 | if (destination->children->length + destination->floating->length == 1) { | ||
320 | ipc_event_workspace(NULL, destination, "init"); | ||
321 | } | ||
315 | } else { | 322 | } else { |
316 | // reset container geometry | 323 | // reset container geometry |
317 | container->width = container->height = 0; | 324 | container->width = container->height = 0; |