From 976e48d79f46fbab02d7af0ae1b6804018774a63 Mon Sep 17 00:00:00 2001 From: Mykyta Holubakha Date: Tue, 12 Jul 2016 13:58:24 +0000 Subject: Initial work on window events --- sway/commands.c | 2 ++ sway/extensions.c | 2 ++ sway/focus.c | 4 ++++ sway/handlers.c | 3 +++ sway/ipc-server.c | 17 +++++++++++++++++ sway/layout.c | 2 ++ 6 files changed, 30 insertions(+) (limited to 'sway') diff --git a/sway/commands.c b/sway/commands.c index aaacf0fc..5cf93c53 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -679,6 +679,7 @@ static struct cmd_results *cmd_floating(int argc, char **argv) { view->width = view->height = 0; arrange_windows(swayc_active_workspace(), -1, -1); remove_view_from_scratchpad(view); + ipc_event_window(view, "floating"); } set_focused_container(view); return cmd_results_new(CMD_SUCCESS, NULL, NULL); @@ -2495,6 +2496,7 @@ static struct cmd_results *cmd_fullscreen(int argc, char **argv) { arrange_windows(container, -1, -1); workspace->fullscreen = NULL; } + ipc_event_window(container, "fullscreen_mode"); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/extensions.c b/sway/extensions.c index 1fe15ac5..4611f33e 100644 --- a/sway/extensions.c +++ b/sway/extensions.c @@ -8,6 +8,7 @@ #include "log.h" #include "input_state.h" #include "extensions.h" +#include "ipc-server.h" struct desktop_shell_state desktop_shell; @@ -128,6 +129,7 @@ static void set_lock_surface(struct wl_client *client, struct wl_resource *resou } wlc_view_set_state(view->handle, WLC_BIT_FULLSCREEN, true); workspace->fullscreen = view; + ipc_event_window(view, "fullscreen_mode"); desktop_shell.is_locked = true; // reset input state input_init(); diff --git a/sway/focus.c b/sway/focus.c index ff064b72..97fa4b98 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -118,6 +118,10 @@ bool set_focused_container(swayc_t *c) { c = focused; } + if (c->type == C_VIEW) { + // dispatch a window event + ipc_event_window(c, "focus"); + } // update container focus from here to root, making necessary changes along // the way swayc_t *p = c; diff --git a/sway/handlers.c b/sway/handlers.c index b95a6e65..abed8cd7 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -369,6 +369,7 @@ static bool handle_view_created(wlc_handle handle) { suspend_workspace_cleanup = true; if (newview) { + ipc_event_window(newview, "new"); set_focused_container(newview); swayc_t *output = swayc_parent_by_type(newview, C_OUTPUT); arrange_windows(output, -1, -1); @@ -461,6 +462,7 @@ static void handle_view_destroyed(wlc_handle handle) { } arrange_windows(parent, -1, -1); + ipc_event_window(parent, "close"); } else { // Is it unmanaged? int i; @@ -555,6 +557,7 @@ static void handle_view_properties_updated(wlc_handle view, uint32_t mask) { } else if (c->border_type == B_NORMAL) { update_view_border(c); } + ipc_event_window(c, "title"); } } } diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 0729bfd5..1dc3ab79 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -339,6 +339,8 @@ void ipc_client_handle_command(struct ipc_client *client) { client->subscribed_events |= IPC_EVENT_BARCONFIG_UPDATE; } else if (strcmp(event_type, "mode") == 0) { client->subscribed_events |= IPC_EVENT_MODE; + } else if (strcmp(event_type, "window") == 0) { + client->subscribed_events |= IPC_EVENT_WINDOW; } else if (strcmp(event_type, "modifier") == 0) { client->subscribed_events |= IPC_EVENT_MODIFIER; #if SWAY_BINDING_EVENT @@ -556,6 +558,21 @@ void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) { json_object_put(obj); // free } +void ipc_event_window(swayc_t *window, const char *change) { + json_object *obj = json_object_new_object(); + json_object_object_add(obj, "change", json_object_new_string(change)); + if (strcmp(change, "close") == 0 || !window) { + json_object_object_add(obj, "container", NULL); + } else { + json_object_object_add(obj, "container", ipc_json_describe_container(window)); + } + + const char *json_string = json_object_to_json_string(obj); + ipc_send_event(json_string, IPC_EVENT_WINDOW); + + json_object_put(obj); // free +} + void ipc_event_barconfig_update(struct bar_config *bar) { json_object *json = ipc_json_describe_bar_config(bar); const char *json_string = json_object_to_json_string(json); diff --git a/sway/layout.c b/sway/layout.c index 2e0bf0bb..d32b4139 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -91,6 +91,7 @@ void add_floating(swayc_t *ws, swayc_t *child) { if (!ws->focused) { ws->focused = child; } + ipc_event_window(child, "floating"); } swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) { @@ -305,6 +306,7 @@ void move_container(swayc_t *container, enum movement_direction dir) { parent = child->parent; } arrange_windows(parent->parent, -1, -1); + ipc_event_window(container, "move"); set_focused_container_for(parent->parent, container); } -- cgit v1.2.3-54-g00ecf