aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-12-21 20:37:55 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-12-21 20:37:55 -0500
commit5a13d19d4967cd90def4c29cd5ebfbaaa43bc1da (patch)
treeebf8c63bfb812a5d8bd7ab455a5b68ef81054dd2
parentMerge pull request #390 from mikkeloscar/workspace-ipc-event (diff)
parentTrigger ipc_event_workspace in all cases (diff)
downloadsway-5a13d19d4967cd90def4c29cd5ebfbaaa43bc1da.tar.gz
sway-5a13d19d4967cd90def4c29cd5ebfbaaa43bc1da.tar.zst
sway-5a13d19d4967cd90def4c29cd5ebfbaaa43bc1da.zip
Merge pull request #391 from mikkeloscar/trigger-workspace-ipc
Trigger ipc_event_workspace in all cases
-rw-r--r--include/ipc-server.h2
-rw-r--r--sway/focus.c15
-rw-r--r--sway/ipc-server.c20
-rw-r--r--sway/layout.c7
4 files changed, 30 insertions, 14 deletions
diff --git a/include/ipc-server.h b/include/ipc-server.h
index 9858d6f0..ab9807ef 100644
--- a/include/ipc-server.h
+++ b/include/ipc-server.h
@@ -9,7 +9,7 @@ void ipc_init(void);
9void ipc_terminate(void); 9void ipc_terminate(void);
10struct sockaddr_un *ipc_user_sockaddr(void); 10struct sockaddr_un *ipc_user_sockaddr(void);
11 11
12void ipc_event_workspace(swayc_t *old, swayc_t *new); 12void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change);
13void ipc_event_barconfig_update(struct bar_config *bar); 13void ipc_event_barconfig_update(struct bar_config *bar);
14const char *swayc_type_string(enum swayc_types type); 14const char *swayc_type_string(enum swayc_types type);
15 15
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
565void ipc_event_workspace(swayc_t *old, swayc_t *new) { 565void 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
14swayc_t root_container; 15swayc_t root_container;
15list_t *scratchpad; 16list_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;