aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2015-12-21 20:37:55 -0500
committerDrew DeVault <sir@cmpwn.com>2015-12-21 20:37:55 -0500
commit5a13d19d4967cd90def4c29cd5ebfbaaa43bc1da (patch)
treeebf8c63bfb812a5d8bd7ab455a5b68ef81054dd2
parent442a54c38bb60d92bd4383f0d80ca55b876399e8 (diff)
parent50b04884b65b7e04234e8fa794a4e6db48c133a4 (diff)
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);
void ipc_terminate(void);
struct sockaddr_un *ipc_user_sockaddr(void);
-void ipc_event_workspace(swayc_t *old, swayc_t *new);
+void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change);
void ipc_event_barconfig_update(struct bar_config *bar);
const char *swayc_type_string(enum swayc_types type);
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) {
// Case where workspace changes
case C_WORKSPACE:
if (prev) {
- ipc_event_workspace(prev, c);
+ ipc_event_workspace(prev, c, "focus");
// update visibility of old workspace
update_visibility(prev);
@@ -122,11 +122,6 @@ bool set_focused_container(swayc_t *c) {
p = p->parent;
p->is_focused = false;
}
- // active_ws might have been destroyed by now
- // (focus swap away from empty ws = destroy ws)
- if (active_ws_child_count == 0) {
- active_ws = NULL;
- }
// get new focused view and set focus to it.
p = get_focused_view(c);
@@ -146,7 +141,13 @@ bool set_focused_container(swayc_t *c) {
}
if (active_ws != workspace) {
- ipc_event_workspace(active_ws, workspace);
+ // active_ws might have been destroyed by now
+ // (focus swap away from empty ws = destroy ws)
+ if (active_ws_child_count == 0) {
+ active_ws = NULL;
+ }
+
+ ipc_event_workspace(active_ws, workspace, "focus");
}
return true;
}
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) {
return json;
}
-void ipc_event_workspace(swayc_t *old, swayc_t *new) {
+void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) {
json_object *obj = json_object_new_object();
- json_object_object_add(obj, "change", json_object_new_string("focus"));
- if (old) {
- json_object_object_add(obj, "old", ipc_json_describe_workspace(old));
+ json_object_object_add(obj, "change", json_object_new_string(change));
+ if (strcmp("focus", change) == 0) {
+ if (old) {
+ json_object_object_add(obj, "old", ipc_json_describe_workspace(old));
+ } else {
+ json_object_object_add(obj, "old", NULL);
+ }
+ }
+
+ if (new) {
+ json_object_object_add(obj, "current", ipc_json_describe_workspace(new));
} else {
- json_object_object_add(obj, "old", NULL);
+ json_object_object_add(obj, "current", NULL);
}
- json_object_object_add(obj, "current", ipc_json_describe_workspace(new));
+
const char *json_string = json_object_to_json_string(obj);
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 @@
#include "workspace.h"
#include "focus.h"
#include "output.h"
+#include "ipc-server.h"
swayc_t root_container;
list_t *scratchpad;
@@ -312,6 +313,12 @@ void move_container_to(swayc_t* container, swayc_t* destination) {
// reset container geometry
container->width = container->height = 0;
add_child(destination, container);
+
+ // If the workspace only has one child after adding one, it
+ // means that the workspace was just initialized.
+ if (destination->children->length + destination->floating->length == 1) {
+ ipc_event_workspace(NULL, destination, "init");
+ }
} else {
// reset container geometry
container->width = container->height = 0;