From 315d5311b2004b9e148e7b52a7de161b6dfe3878 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 15 Jul 2018 22:43:33 +1000 Subject: [PATCH 01/10] 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 +++ sway/commands.c | 1 + sway/commands/urgent.c | 36 ++++++++++++++++++++++++++++ sway/criteria.c | 44 +++++++++++++++++++++++++++++++++-- sway/desktop/render.c | 24 +++++++++++++++---- sway/input/seat.c | 16 +++++++++++++ sway/ipc-json.c | 3 ++- sway/meson.build | 1 + sway/tree/view.c | 30 ++++++++++++++++++++++++ sway/tree/workspace.c | 10 ++++++++ 12 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 sway/commands/urgent.c 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 diff --git a/sway/commands.c b/sway/commands.c index addd64a6..3578e748 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -153,6 +153,7 @@ static struct cmd_handler command_handlers[] = { { "swap", cmd_swap }, { "title_format", cmd_title_format }, { "unmark", cmd_unmark }, + { "urgent", cmd_urgent }, }; static int handler_compare(const void *_a, const void *_b) { diff --git a/sway/commands/urgent.c b/sway/commands/urgent.c new file mode 100644 index 00000000..d199858a --- /dev/null +++ b/sway/commands/urgent.c @@ -0,0 +1,36 @@ +#include "log.h" +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/tree/arrange.h" +#include "sway/tree/container.h" +#include "sway/tree/view.h" +#include "sway/tree/layout.h" + +struct cmd_results *cmd_urgent(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "urgent", EXPECTED_EQUAL_TO, 1))) { + return error; + } + struct sway_container *container = + config->handler_context.current_container; + if (container->type != C_VIEW) { + return cmd_results_new(CMD_INVALID, "urgent", + "Only views can be urgent"); + } + struct sway_view *view = container->sway_view; + + if (strcmp(argv[0], "enable") == 0) { + view_set_urgent(view, true); + } else if (strcmp(argv[0], "disable") == 0) { + view_set_urgent(view, false); + } else if (strcmp(argv[0], "allow") == 0) { + view->allow_request_urgent = true; + } else if (strcmp(argv[0], "deny") == 0) { + view->allow_request_urgent = false; + } else { + return cmd_results_new(CMD_INVALID, "urgent", + "Expected 'urgent '"); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/criteria.c b/sway/criteria.c index 29a3668b..c999d248 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -46,6 +46,31 @@ static int regex_cmp(const char *item, const pcre *regex) { return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0); } +static int cmp_urgent(const void *_a, const void *_b) { + struct sway_view *a = *(void **)_a; + struct sway_view *b = *(void **)_b; + + if (a->urgent.tv_sec < b->urgent.tv_sec) { + return -1; + } else if (a->urgent.tv_sec > b->urgent.tv_sec) { + return 1; + } + if (a->urgent.tv_nsec < b->urgent.tv_nsec) { + return -1; + } else if (a->urgent.tv_nsec > b->urgent.tv_nsec) { + return 1; + } + return 0; +} + +static void find_urgent_iterator(struct sway_container *swayc, void *data) { + if (swayc->type != C_VIEW || !view_is_urgent(swayc->sway_view)) { + return; + } + list_t *urgent_views = data; + list_add(urgent_views, swayc->sway_view); +} + static bool criteria_matches_view(struct criteria *criteria, struct sway_view *view) { if (criteria->title) { @@ -133,8 +158,23 @@ static bool criteria_matches_view(struct criteria *criteria, } if (criteria->urgent) { - // TODO - return false; + if (!view_is_urgent(view)) { + return false; + } + list_t *urgent_views = create_list(); + container_for_each_descendant_dfs(&root_container, + find_urgent_iterator, urgent_views); + list_stable_sort(urgent_views, cmp_urgent); + struct sway_view *target; + if (criteria->urgent == 'o') { // oldest + target = urgent_views->items[0]; + } else { // latest + target = urgent_views->items[urgent_views->length - 1]; + } + list_free(urgent_views); + if (view != target) { + return false; + } } if (criteria->workspace) { diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 17fe823a..3180f8ba 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -553,7 +553,11 @@ static void render_container_simple(struct sway_output *output, struct wlr_texture *marks_texture; struct sway_container_state *state = &child->current; - if (state->focused || parent_focused) { + if (view_is_urgent(view)) { + colors = &config->border_colors.urgent; + title_texture = child->title_urgent; + marks_texture = view->marks_urgent; + } else if (state->focused || parent_focused) { colors = &config->border_colors.focused; title_texture = child->title_focused; marks_texture = view->marks_focused; @@ -608,7 +612,11 @@ static void render_container_tabbed(struct sway_output *output, struct wlr_texture *title_texture; struct wlr_texture *marks_texture; - if (cstate->focused || parent_focused) { + if (view && view_is_urgent(view)) { + colors = &config->border_colors.urgent; + title_texture = child->title_urgent; + marks_texture = view->marks_urgent; + } else if (cstate->focused || parent_focused) { colors = &config->border_colors.focused; title_texture = child->title_focused; marks_texture = view ? view->marks_focused : NULL; @@ -671,7 +679,11 @@ static void render_container_stacked(struct sway_output *output, struct wlr_texture *title_texture; struct wlr_texture *marks_texture; - if (cstate->focused || parent_focused) { + if (view && view_is_urgent(view)) { + colors = &config->border_colors.urgent; + title_texture = child->title_urgent; + marks_texture = view->marks_urgent; + } else if (cstate->focused || parent_focused) { colors = &config->border_colors.focused; title_texture = child->title_focused; marks_texture = view ? view->marks_focused : NULL; @@ -731,7 +743,11 @@ static void render_floating_container(struct sway_output *soutput, struct wlr_texture *title_texture; struct wlr_texture *marks_texture; - if (con->current.focused) { + if (view_is_urgent(view)) { + colors = &config->border_colors.urgent; + title_texture = con->title_urgent; + marks_texture = view->marks_urgent; + } else if (con->current.focused) { colors = &config->border_colors.focused; title_texture = con->title_focused; marks_texture = view->marks_focused; diff --git a/sway/input/seat.c b/sway/input/seat.c index 74f1375e..7058cc92 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -594,6 +594,12 @@ static void seat_send_unfocus(struct sway_container *container, } } +static int handle_urgent_timeout(void *data) { + struct sway_view *view = data; + view_set_urgent(view, false); + return 0; +} + void seat_set_focus_warp(struct sway_seat *seat, struct sway_container *container, bool warp) { if (seat->focused_layer) { @@ -670,6 +676,16 @@ void seat_set_focus_warp(struct sway_seat *seat, } } + // If urgent, start a timer to unset it + if (container && container->type == C_VIEW && + view_is_urgent(container->sway_view) && + !container->sway_view->urgent_timer) { + struct sway_view *view = container->sway_view; + view->urgent_timer = wl_event_loop_add_timer(server.wl_event_loop, + handle_urgent_timeout, view); + wl_event_source_timer_update(view->urgent_timer, 1000); + } + // If we've focused a floating container, bring it to the front. // We do this by putting it at the end of the floating list. // This must happen for both the pending and current children lists. diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 3d0e88f0..8c48e724 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -170,7 +170,8 @@ static void ipc_json_describe_workspace(struct sway_container *workspace, json_object_object_add(object, "output", workspace->parent ? 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(false)); + json_object_object_add(object, "urgent", + json_object_new_boolean(workspace_is_urgent(workspace))); json_object_object_add(object, "representation", workspace->formatted_title ? json_object_new_string(workspace->formatted_title) : NULL); diff --git a/sway/meson.build b/sway/meson.build index f878450d..b64bd137 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -76,6 +76,7 @@ sway_sources = files( 'commands/swap.c', 'commands/title_format.c', 'commands/unmark.c', + 'commands/urgent.c', 'commands/workspace.c', 'commands/workspace_layout.c', 'commands/ws_auto_back_and_forth.c', diff --git a/sway/tree/view.c b/sway/tree/view.c index bf380d98..a2dbe92c 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -25,6 +25,7 @@ void view_init(struct sway_view *view, enum sway_view_type type, view->impl = impl; view->executed_criteria = create_list(); view->marks = create_list(); + view->allow_request_urgent = true; wl_signal_init(&view->events.unmap); } @@ -589,6 +590,11 @@ void view_unmap(struct sway_view *view) { wl_list_remove(&view->surface_new_subsurface.link); wl_list_remove(&view->container_reparent.link); + if (view->urgent_timer) { + wl_event_source_remove(view->urgent_timer); + view->urgent_timer = NULL; + } + if (view->is_fullscreen) { struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); ws->sway_workspace->fullscreen = NULL; @@ -1047,3 +1053,27 @@ bool view_is_visible(struct sway_view *view) { } return true; } + +void view_set_urgent(struct sway_view *view, bool enable) { + if (enable) { + struct sway_seat *seat = input_manager_current_seat(input_manager); + if (seat_get_focus(seat) == view->swayc) { + return; + } + clock_gettime(CLOCK_MONOTONIC, &view->urgent); + } else { + view->urgent = (struct timespec){ 0 }; + if (view->urgent_timer) { + wl_event_source_remove(view->urgent_timer); + view->urgent_timer = NULL; + } + } + container_damage_whole(view->swayc); + + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); + ipc_event_workspace(ws, NULL, "urgent"); +} + +bool view_is_urgent(struct sway_view *view) { + return view->urgent.tv_sec || view->urgent.tv_nsec; +} diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 2a2d834a..d71b0a53 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -11,6 +11,7 @@ #include "sway/ipc-server.h" #include "sway/tree/arrange.h" #include "sway/tree/container.h" +#include "sway/tree/view.h" #include "sway/tree/workspace.h" #include "list.h" #include "log.h" @@ -518,3 +519,12 @@ 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); +} + +bool workspace_is_urgent(struct sway_container *workspace) { + return container_find(workspace, find_urgent_iterator, NULL); +} From f86087d78f25575ddadaa4d3496b34e62b545d2e Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 08:13:58 +1000 Subject: [PATCH 02/10] Fix urgency IPC events --- sway/ipc-json.c | 3 +++ sway/tree/view.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 8c48e724..f9182291 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -197,6 +197,9 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object json_object_object_add(object, "layout", json_object_new_string(ipc_json_layout_description(c->layout))); } + + json_object_object_add(object, "urgent", + json_object_new_boolean(view_is_urgent(c->sway_view))); } static void focus_inactive_children_iterator(struct sway_container *c, void *data) { diff --git a/sway/tree/view.c b/sway/tree/view.c index a2dbe92c..ae520b07 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -1070,8 +1070,10 @@ void view_set_urgent(struct sway_view *view, bool enable) { } container_damage_whole(view->swayc); + ipc_event_window(view->swayc, "urgent"); + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); - ipc_event_workspace(ws, NULL, "urgent"); + ipc_event_workspace(NULL, ws, "urgent"); } bool view_is_urgent(struct sway_view *view) { From e3f90f00fefcfba65d2387ac69f5e9aec2eb9883 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 08:42:34 +1000 Subject: [PATCH 03/10] Implement xwayland urgency hint --- sway/desktop/xwayland.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 11516673..9df7977d 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -297,6 +297,10 @@ static void handle_commit(struct wl_listener *listener, void *data) { } view_damage_from(view); + + if (view->allow_request_urgent) { + view_set_urgent(view, (bool)xsurface->hints_urgency); + } } static void handle_unmap(struct wl_listener *listener, void *data) { From a211daf9e6667102f282a3507d84090cb54c71fe Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 10:15:18 +1000 Subject: [PATCH 04/10] Add documentation for urgent command --- sway/sway.5.scd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sway/sway.5.scd b/sway/sway.5.scd index c6eb5e6d..d369d7b6 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -499,6 +499,11 @@ config after the others, or it will be matched instead of the others. *unmark* will remove _identifier_ from the list of current marks on a window. If _identifier_ is omitted, all marks are removed. +*urgent* enable|disable|allow|deny + Using _enable_ or _disable_ manually sets or unsets the window's urgent + state. Using _allow_ or _deny_ controls the window's ability to set itself + as urgent. By default, windows are allowed to set their own urgency. + *workspace* [number] Switches to the specified workspace. The string "number" is optional and is used to sort workspaces. From 64e3bc3ab09c0cc66b1675d39e4a9e872cbb46fd Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 11:55:53 +1000 Subject: [PATCH 05/10] Fix crash in ipc_json_describe_view I didn't expect a function called ipc_json_describe_view to be passed a container which wasn't a view :\ --- sway/ipc-json.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sway/ipc-json.c b/sway/ipc-json.c index f9182291..f8de51ed 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -198,8 +198,10 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object json_object_new_string(ipc_json_layout_description(c->layout))); } - json_object_object_add(object, "urgent", - json_object_new_boolean(view_is_urgent(c->sway_view))); + if (c->type == C_VIEW) { + json_object_object_add(object, "urgent", + json_object_new_boolean(view_is_urgent(c->sway_view))); + } } static void focus_inactive_children_iterator(struct sway_container *c, void *data) { From 560627437b536db490d7e4a3c6fb4282757a7327 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 12:45:20 +1000 Subject: [PATCH 06/10] Make container_for_each_descendant_dfs descend into floating views --- sway/tree/container.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sway/tree/container.c b/sway/tree/container.c index 35f67cce..99d57218 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -674,16 +674,23 @@ struct sway_container *floating_container_at(double lx, double ly, void container_for_each_descendant_dfs(struct sway_container *container, void (*f)(struct sway_container *container, void *data), void *data) { - if (container) { - if (container->children) { - for (int i = 0; i < container->children->length; ++i) { - struct sway_container *child = - container->children->items[i]; - container_for_each_descendant_dfs(child, f, data); - } + if (!container) { + return; + } + if (container->children) { + for (int i = 0; i < container->children->length; ++i) { + struct sway_container *child = container->children->items[i]; + container_for_each_descendant_dfs(child, f, data); + } + } + if (container->type == C_WORKSPACE) { + struct sway_container *floating = container->sway_workspace->floating; + for (int i = 0; i < floating->children->length; ++i) { + struct sway_container *child = floating->children->items[i]; + container_for_each_descendant_dfs(child, f, data); } - f(container, data); } + f(container, data); } void container_for_each_descendant_bfs(struct sway_container *con, From 5f0a4bb6a46cf359dd270e3c448ca1e112331f9d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 13:15:35 +1000 Subject: [PATCH 07/10] 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 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"); + } } From be28c18ad5a3271aad537a5356662d57f16d9703 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 14:30:31 +1000 Subject: [PATCH 08/10] 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(-) 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; From af5f736277559398d3d3df20adbb3a90ff88dbd0 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 16 Jul 2018 18:22:27 +1000 Subject: [PATCH 09/10] Render containers as urgent if they have an urgent child --- sway/desktop/render.c | 12 ++++++++---- sway/tree/workspace.c | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 3180f8ba..cb995215 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -611,11 +611,13 @@ static void render_container_tabbed(struct sway_output *output, struct border_colors *colors; struct wlr_texture *title_texture; struct wlr_texture *marks_texture; + bool urgent = view ? + view_is_urgent(view) : container_has_urgent_child(child); - if (view && view_is_urgent(view)) { + if (urgent) { colors = &config->border_colors.urgent; title_texture = child->title_urgent; - marks_texture = view->marks_urgent; + marks_texture = view ? view->marks_urgent : NULL; } else if (cstate->focused || parent_focused) { colors = &config->border_colors.focused; title_texture = child->title_focused; @@ -678,11 +680,13 @@ static void render_container_stacked(struct sway_output *output, struct border_colors *colors; struct wlr_texture *title_texture; struct wlr_texture *marks_texture; + bool urgent = view ? + view_is_urgent(view) : container_has_urgent_child(child); - if (view && view_is_urgent(view)) { + if (urgent) { colors = &config->border_colors.urgent; title_texture = child->title_urgent; - marks_texture = view->marks_urgent; + marks_texture = view ? view->marks_urgent : NULL; } else if (cstate->focused || parent_focused) { colors = &config->border_colors.focused; title_texture = child->title_focused; diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 00b479ec..622f01ec 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -526,5 +526,6 @@ void workspace_detect_urgent(struct sway_container *workspace) { if (workspace->sway_workspace->urgent != new_urgent) { workspace->sway_workspace->urgent = new_urgent; ipc_event_workspace(NULL, workspace, "urgent"); + container_damage_whole(workspace); } } From 255dc8bbb040c4f268f318bde86701227d82da3f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 17 Jul 2018 08:29:43 +1000 Subject: [PATCH 10/10] swaybar: Read urgent colors from IPC --- swaybar/ipc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 08531f2a..c2d05920 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -115,6 +115,18 @@ static void ipc_parse_colors( config->colors.inactive_workspace.text = parse_color( json_object_get_string(inactive_workspace_text)); } + if (urgent_workspace_border) { + config->colors.urgent_workspace.border = parse_color( + json_object_get_string(urgent_workspace_border)); + } + if (urgent_workspace_bg) { + config->colors.urgent_workspace.background = parse_color( + json_object_get_string(urgent_workspace_bg)); + } + if (urgent_workspace_text) { + config->colors.urgent_workspace.text = parse_color( + json_object_get_string(urgent_workspace_text)); + } if (binding_mode_border) { config->colors.binding_mode.border = parse_color( json_object_get_string(binding_mode_border));