From 5f0a4bb6a46cf359dd270e3c448ca1e112331f9d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 13:15:35 +1000 Subject: [PATCH] Update workspace urgent state when views close or move workspaces --- include/sway/tree/workspace.h | 3 ++- sway/ipc-json.c | 2 +- sway/tree/container.c | 2 ++ sway/tree/layout.c | 11 +++++++++++ sway/tree/view.c | 11 ++++++++--- sway/tree/workspace.c | 9 +++++++-- 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index 8c2f4cd5a..bc95317ac 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -10,6 +10,7 @@ struct sway_workspace { struct sway_view *fullscreen; struct sway_container *floating; list_t *output_priority; + bool urgent; }; extern char *prev_workspace_name; @@ -43,6 +44,6 @@ void workspace_output_add_priority(struct sway_container *workspace, struct sway_container *workspace_output_get_highest_available( struct sway_container *ws, struct sway_container *exclude); -bool workspace_is_urgent(struct sway_container *workspace); +void workspace_detect_urgent(struct sway_container *workspace); #endif diff --git a/sway/ipc-json.c b/sway/ipc-json.c index f8de51edc..dbab8e688 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -171,7 +171,7 @@ static void ipc_json_describe_workspace(struct sway_container *workspace, json_object_new_string(workspace->parent->name) : NULL); json_object_object_add(object, "type", json_object_new_string("workspace")); json_object_object_add(object, "urgent", - json_object_new_boolean(workspace_is_urgent(workspace))); + json_object_new_boolean(workspace->sway_workspace->urgent)); json_object_object_add(object, "representation", workspace->formatted_title ? json_object_new_string(workspace->formatted_title) : NULL); diff --git a/sway/tree/container.c b/sway/tree/container.c index 99d572182..c1de46b5a 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -1070,6 +1070,8 @@ void container_floating_move_to(struct sway_container *con, container_add_child(new_workspace->sway_workspace->floating, con); arrange_windows(old_workspace); arrange_windows(new_workspace); + workspace_detect_urgent(old_workspace); + workspace_detect_urgent(new_workspace); } } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 54ddb3f93..197a2fc8b 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -225,6 +225,15 @@ void container_move_to(struct sway_container *container, } } } + // Update workspace urgent state + struct sway_container *old_workspace = old_parent; + if (old_workspace->type != C_WORKSPACE) { + old_workspace = container_parent(old_workspace, C_WORKSPACE); + } + if (new_workspace != old_workspace) { + workspace_detect_urgent(new_workspace); + workspace_detect_urgent(old_workspace); + } } static bool sway_dir_to_wlr(enum movement_direction dir, @@ -548,6 +557,8 @@ void container_move(struct sway_container *container, } if (last_ws && next_ws && last_ws != next_ws) { ipc_event_workspace(last_ws, container, "focus"); + workspace_detect_urgent(last_ws); + workspace_detect_urgent(next_ws); } } diff --git a/sway/tree/view.c b/sway/tree/view.c index ae520b07b..b5b734082 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -595,16 +595,21 @@ void view_unmap(struct sway_view *view) { view->urgent_timer = NULL; } + struct sway_container *parent; + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); + if (view->is_fullscreen) { - struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); ws->sway_workspace->fullscreen = NULL; - container_destroy(view->swayc); + parent = container_destroy(view->swayc); arrange_windows(ws->parent); } else { struct sway_container *parent = container_destroy(view->swayc); arrange_windows(parent); } + if (parent->type >= C_WORKSPACE) { // if the workspace still exists + workspace_detect_urgent(ws); + } transaction_commit_dirty(); view->surface = NULL; } @@ -1073,7 +1078,7 @@ void view_set_urgent(struct sway_view *view, bool enable) { ipc_event_window(view->swayc, "urgent"); struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); - ipc_event_workspace(NULL, ws, "urgent"); + workspace_detect_urgent(ws); } bool view_is_urgent(struct sway_view *view) { diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index d71b0a530..d14f01eb6 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -525,6 +525,11 @@ static bool find_urgent_iterator(struct sway_container *con, return con->type == C_VIEW && view_is_urgent(con->sway_view); } -bool workspace_is_urgent(struct sway_container *workspace) { - return container_find(workspace, find_urgent_iterator, NULL); +void workspace_detect_urgent(struct sway_container *workspace) { + bool new_urgent = container_find(workspace, find_urgent_iterator, NULL); + + if (workspace->sway_workspace->urgent != new_urgent) { + workspace->sway_workspace->urgent = new_urgent; + ipc_event_workspace(NULL, workspace, "urgent"); + } }