From 315d5311b2004b9e148e7b52a7de161b6dfe3878 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 15 Jul 2018 22:43:33 +1000 Subject: Implement urgency base functionality Introduces a command to manually set urgency, as well as rendering of urgent views, sending the IPC event, removing urgency after focused for one second, and matching urgent views via criteria. --- include/sway/commands.h | 1 + include/sway/tree/view.h | 8 ++++++++ include/sway/tree/workspace.h | 3 +++ 3 files changed, 12 insertions(+) (limited to 'include/sway') diff --git a/include/sway/commands.h b/include/sway/commands.h index 3ebd0002..1e93e2a3 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -152,6 +152,7 @@ sway_cmd cmd_swaybg_command; sway_cmd cmd_swap; sway_cmd cmd_title_format; sway_cmd cmd_unmark; +sway_cmd cmd_urgent; sway_cmd cmd_workspace; sway_cmd cmd_ws_auto_back_and_forth; sway_cmd cmd_workspace_layout; diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 21d6403e..9022f7a6 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -70,6 +70,10 @@ struct sway_view { bool border_left; bool border_right; + struct timespec urgent; + bool allow_request_urgent; + struct wl_event_source *urgent_timer; + bool destroying; list_t *executed_criteria; // struct criteria * @@ -305,4 +309,8 @@ void view_update_marks_textures(struct sway_view *view); */ bool view_is_visible(struct sway_view *view); +void view_set_urgent(struct sway_view *view, bool enable); + +bool view_is_urgent(struct sway_view *view); + #endif diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index c72a4ac0..8c2f4cd5 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -42,4 +42,7 @@ 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); + #endif -- cgit v1.2.3 From 5f0a4bb6a46cf359dd270e3c448ca1e112331f9d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 13:15:35 +1000 Subject: 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(-) (limited to 'include/sway') diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index 8c2f4cd5..bc95317a 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 f8de51ed..dbab8e68 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 99d57218..c1de46b5 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 54ddb3f9..197a2fc8 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 ae520b07..b5b73408 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 d71b0a53..d14f01eb 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"); + } } -- cgit v1.2.3 From be28c18ad5a3271aad537a5356662d57f16d9703 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 14:30:31 +1000 Subject: Mark containers as urgent in IPC if they have urgent views --- include/sway/tree/container.h | 2 ++ sway/ipc-json.c | 7 +++---- sway/tree/container.c | 9 +++++++++ sway/tree/workspace.c | 7 +------ 4 files changed, 15 insertions(+), 10 deletions(-) (limited to 'include/sway') diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 04e50fc6..ca7a3288 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -316,4 +316,6 @@ void container_floating_move_to(struct sway_container *con, */ void container_set_dirty(struct sway_container *container); +bool container_has_urgent_child(struct sway_container *container); + #endif diff --git a/sway/ipc-json.c b/sway/ipc-json.c index dbab8e68..c49ea47e 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -198,10 +198,9 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object json_object_new_string(ipc_json_layout_description(c->layout))); } - if (c->type == C_VIEW) { - json_object_object_add(object, "urgent", - json_object_new_boolean(view_is_urgent(c->sway_view))); - } + bool urgent = c->type == C_VIEW ? + view_is_urgent(c->sway_view) : container_has_urgent_child(c); + json_object_object_add(object, "urgent", json_object_new_boolean(urgent)); } static void focus_inactive_children_iterator(struct sway_container *c, void *data) { diff --git a/sway/tree/container.c b/sway/tree/container.c index c1de46b5..6d52c38c 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -1082,3 +1082,12 @@ void container_set_dirty(struct sway_container *container) { container->dirty = true; list_add(server.dirty_containers, container); } + +static bool find_urgent_iterator(struct sway_container *con, + void *data) { + return con->type == C_VIEW && view_is_urgent(con->sway_view); +} + +bool container_has_urgent_child(struct sway_container *container) { + return container_find(container, find_urgent_iterator, NULL); +} diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index d14f01eb..00b479ec 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -520,13 +520,8 @@ struct sway_container *workspace_output_get_highest_available( return NULL; } -static bool find_urgent_iterator(struct sway_container *con, - void *data) { - return con->type == C_VIEW && view_is_urgent(con->sway_view); -} - void workspace_detect_urgent(struct sway_container *workspace) { - bool new_urgent = container_find(workspace, find_urgent_iterator, NULL); + bool new_urgent = container_has_urgent_child(workspace); if (workspace->sway_workspace->urgent != new_urgent) { workspace->sway_workspace->urgent = new_urgent; -- cgit v1.2.3