diff options
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/border.c | 60 | ||||
-rw-r--r-- | sway/commands/client.c | 4 | ||||
-rw-r--r-- | sway/commands/focus.c | 109 | ||||
-rw-r--r-- | sway/commands/mark.c | 19 | ||||
-rw-r--r-- | sway/commands/move.c | 76 | ||||
-rw-r--r-- | sway/commands/reload.c | 4 | ||||
-rw-r--r-- | sway/commands/show_marks.c | 4 | ||||
-rw-r--r-- | sway/commands/swap.c | 4 | ||||
-rw-r--r-- | sway/commands/unmark.c | 41 | ||||
-rw-r--r-- | sway/criteria.c | 5 | ||||
-rw-r--r-- | sway/desktop/output.c | 17 | ||||
-rw-r--r-- | sway/desktop/render.c | 30 | ||||
-rw-r--r-- | sway/desktop/transaction.c | 16 | ||||
-rw-r--r-- | sway/input/cursor.c | 15 | ||||
-rw-r--r-- | sway/input/input-manager.c | 1 | ||||
-rw-r--r-- | sway/input/seat.c | 6 | ||||
-rw-r--r-- | sway/ipc-json.c | 38 | ||||
-rw-r--r-- | sway/ipc-server.c | 8 | ||||
-rw-r--r-- | sway/main.c | 29 | ||||
-rw-r--r-- | sway/tree/container.c | 170 | ||||
-rw-r--r-- | sway/tree/output.c | 22 | ||||
-rw-r--r-- | sway/tree/view.c | 216 | ||||
-rw-r--r-- | sway/tree/workspace.c | 10 |
23 files changed, 463 insertions, 441 deletions
diff --git a/sway/commands/border.c b/sway/commands/border.c index 37047812..b6eab550 100644 --- a/sway/commands/border.c +++ b/sway/commands/border.c @@ -12,37 +12,41 @@ // in use (we set using_csd instead and render a sway border). // - view->saved_border should be the last applied border when switching to CSD. // - view->using_csd should always reflect whether CSD is applied or not. -static void set_border(struct sway_view *view, +static void set_border(struct sway_container *con, enum sway_container_border new_border) { - if (view->using_csd && new_border != B_CSD) { - view_set_csd_from_server(view, false); - } else if (!view->using_csd && new_border == B_CSD) { - view_set_csd_from_server(view, true); - view->saved_border = view->border; + if (con->view) { + if (con->view->using_csd && new_border != B_CSD) { + view_set_csd_from_server(con->view, false); + } else if (!con->view->using_csd && new_border == B_CSD) { + view_set_csd_from_server(con->view, true); + con->saved_border = con->border; + } + } + if (new_border != B_CSD || container_is_floating(con)) { + con->border = new_border; } - if (new_border != B_CSD || container_is_floating(view->container)) { - view->border = new_border; + if (con->view) { + con->view->using_csd = new_border == B_CSD; } - view->using_csd = new_border == B_CSD; } -static void border_toggle(struct sway_view *view) { - if (view->using_csd) { - set_border(view, B_NONE); +static void border_toggle(struct sway_container *con) { + if (con->view && con->view->using_csd) { + set_border(con, B_NONE); return; } - switch (view->border) { + switch (con->border) { case B_NONE: - set_border(view, B_PIXEL); + set_border(con, B_PIXEL); break; case B_PIXEL: - set_border(view, B_NORMAL); + set_border(con, B_NORMAL); break; case B_NORMAL: - if (view->xdg_decoration) { - set_border(view, B_CSD); + if (con->view && con->view->xdg_decoration) { + set_border(con, B_CSD); } else { - set_border(view, B_NONE); + set_border(con, B_NONE); } break; case B_CSD: @@ -66,33 +70,33 @@ struct cmd_results *cmd_border(int argc, char **argv) { struct sway_view *view = container->view; if (strcmp(argv[0], "none") == 0) { - set_border(view, B_NONE); + set_border(container, B_NONE); } else if (strcmp(argv[0], "normal") == 0) { - set_border(view, B_NORMAL); + set_border(container, B_NORMAL); } else if (strcmp(argv[0], "pixel") == 0) { - set_border(view, B_PIXEL); + set_border(container, B_PIXEL); } else if (strcmp(argv[0], "csd") == 0) { - if (!view->xdg_decoration) { + if (!view || !view->xdg_decoration) { return cmd_results_new(CMD_INVALID, "border", "This window doesn't support client side decorations"); } - set_border(view, B_CSD); + set_border(container, B_CSD); } else if (strcmp(argv[0], "toggle") == 0) { - border_toggle(view); + border_toggle(container); } else { return cmd_results_new(CMD_INVALID, "border", "Expected 'border <none|normal|pixel|csd|toggle>' " "or 'border pixel <px>'"); } if (argc == 2) { - view->border_thickness = atoi(argv[1]); + container->border_thickness = atoi(argv[1]); } - if (container_is_floating(view->container)) { - container_set_geometry_from_floating_view(view->container); + if (container_is_floating(container)) { + container_set_geometry_from_floating_view(container); } - arrange_container(view->container); + arrange_container(container); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/client.c b/sway/commands/client.c index 9f54fa94..746e8713 100644 --- a/sway/commands/client.c +++ b/sway/commands/client.c @@ -5,9 +5,7 @@ #include "sway/tree/container.h" static void rebuild_textures_iterator(struct sway_container *con, void *data) { - if (con->view) { - view_update_marks_textures(con->view); - } + container_update_marks_textures(con); container_update_title_textures(con); } diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 2204f722..cef92144 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c @@ -1,4 +1,5 @@ #include <strings.h> +#include <wlr/types/wlr_output_layout.h> #include <wlr/util/log.h> #include "log.h" #include "sway/commands.h" @@ -13,20 +14,16 @@ #include "stringop.h" #include "util.h" -static bool parse_movement_direction(const char *name, - enum movement_direction *out) { +static bool parse_direction(const char *name, + enum wlr_direction *out) { if (strcasecmp(name, "left") == 0) { - *out = MOVE_LEFT; + *out = WLR_DIRECTION_LEFT; } else if (strcasecmp(name, "right") == 0) { - *out = MOVE_RIGHT; + *out = WLR_DIRECTION_RIGHT; } else if (strcasecmp(name, "up") == 0) { - *out = MOVE_UP; + *out = WLR_DIRECTION_UP; } else if (strcasecmp(name, "down") == 0) { - *out = MOVE_DOWN; - } else if (strcasecmp(name, "parent") == 0) { - *out = MOVE_PARENT; - } else if (strcasecmp(name, "child") == 0) { - *out = MOVE_CHILD; + *out = WLR_DIRECTION_DOWN; } else { return false; } @@ -38,7 +35,7 @@ static bool parse_movement_direction(const char *name, * Get node in the direction of newly entered output. */ static struct sway_node *get_node_in_output_direction( - struct sway_output *output, enum movement_direction dir) { + struct sway_output *output, enum wlr_direction dir) { struct sway_seat *seat = config->handler_context.seat; struct sway_workspace *ws = output_get_active_workspace(output); if (ws->fullscreen) { @@ -48,7 +45,7 @@ static struct sway_node *get_node_in_output_direction( if (ws->tiling->length > 0) { switch (dir) { - case MOVE_LEFT: + case WLR_DIRECTION_LEFT: if (ws->layout == L_HORIZ || ws->layout == L_TABBED) { // get most right child of new output container = ws->tiling->items[ws->tiling->length-1]; @@ -56,7 +53,7 @@ static struct sway_node *get_node_in_output_direction( container = seat_get_focus_inactive_tiling(seat, ws); } break; - case MOVE_RIGHT: + case WLR_DIRECTION_RIGHT: if (ws->layout == L_HORIZ || ws->layout == L_TABBED) { // get most left child of new output container = ws->tiling->items[0]; @@ -64,7 +61,7 @@ static struct sway_node *get_node_in_output_direction( container = seat_get_focus_inactive_tiling(seat, ws); } break; - case MOVE_UP: + case WLR_DIRECTION_UP: if (ws->layout == L_VERT || ws->layout == L_STACKED) { // get most bottom child of new output container = ws->tiling->items[ws->tiling->length-1]; @@ -72,7 +69,7 @@ static struct sway_node *get_node_in_output_direction( container = seat_get_focus_inactive_tiling(seat, ws); } break; - case MOVE_DOWN: { + case WLR_DIRECTION_DOWN: if (ws->layout == L_VERT || ws->layout == L_STACKED) { // get most top child of new output container = ws->tiling->items[0]; @@ -81,9 +78,6 @@ static struct sway_node *get_node_in_output_direction( } break; } - default: - break; - } } if (container) { @@ -95,11 +89,8 @@ static struct sway_node *get_node_in_output_direction( } static struct sway_node *node_get_in_direction(struct sway_container *container, - struct sway_seat *seat, enum movement_direction dir) { + struct sway_seat *seat, enum wlr_direction dir) { if (container->is_fullscreen) { - if (dir == MOVE_PARENT) { - return NULL; - } // Fullscreen container with a direction - go straight to outputs struct sway_output *output = container->workspace->output; struct sway_output *new_output = output_get_in_direction(output, dir); @@ -108,9 +99,6 @@ static struct sway_node *node_get_in_direction(struct sway_container *container, } return get_node_in_output_direction(new_output, dir); } - if (dir == MOVE_PARENT) { - return node_get_parent(&container->node); - } struct sway_container *wrap_candidate = NULL; struct sway_container *current = container; @@ -122,15 +110,15 @@ static struct sway_node *node_get_in_direction(struct sway_container *container, container_parent_layout(current); list_t *siblings = container_get_siblings(current); - if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { + if (dir == WLR_DIRECTION_LEFT || dir == WLR_DIRECTION_RIGHT) { if (parent_layout == L_HORIZ || parent_layout == L_TABBED) { can_move = true; - desired = idx + (dir == MOVE_LEFT ? -1 : 1); + desired = idx + (dir == WLR_DIRECTION_LEFT ? -1 : 1); } } else { if (parent_layout == L_VERT || parent_layout == L_STACKED) { can_move = true; - desired = idx + (dir == MOVE_UP ? -1 : 1); + desired = idx + (dir == WLR_DIRECTION_UP ? -1 : 1); } } @@ -200,15 +188,25 @@ static struct cmd_results *focus_output(struct sway_seat *seat, struct sway_output *output = output_by_name(identifier); if (!output) { - enum movement_direction direction; - if (!parse_movement_direction(identifier, &direction) || - direction == MOVE_PARENT || direction == MOVE_CHILD) { + enum wlr_direction direction; + if (!parse_direction(identifier, &direction)) { free(identifier); return cmd_results_new(CMD_INVALID, "focus", "There is no output with that name"); } struct sway_workspace *ws = seat_get_focused_workspace(seat); output = output_get_in_direction(ws->output, direction); + + if (!output) { + int center_lx = ws->output->lx + ws->output->width / 2; + int center_ly = ws->output->ly + ws->output->height / 2; + struct wlr_output *target = wlr_output_layout_farthest_output( + root->output_layout, opposite_direction(direction), + ws->output->wlr_output, center_lx, center_ly); + if (target) { + output = output_from_wlr_output(target); + } + } } free(identifier); @@ -220,6 +218,31 @@ static struct cmd_results *focus_output(struct sway_seat *seat, return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +static struct cmd_results *focus_parent(void) { + struct sway_seat *seat = config->handler_context.seat; + struct sway_container *con = config->handler_context.container; + if (!con || con->is_fullscreen) { + return cmd_results_new(CMD_SUCCESS, NULL, NULL); + } + struct sway_node *parent = node_get_parent(&con->node); + if (parent) { + seat_set_focus(seat, parent); + seat_consider_warp_to_focus(seat); + } + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + +static struct cmd_results *focus_child(void) { + struct sway_seat *seat = config->handler_context.seat; + struct sway_node *node = config->handler_context.node; + struct sway_node *focus = seat_get_active_tiling_child(seat, node); + if (focus) { + seat_set_focus(seat, focus); + seat_consider_warp_to_focus(seat); + } + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + struct cmd_results *cmd_focus(int argc, char **argv) { if (config->reading || !config->active) { return cmd_results_new(CMD_DEFER, NULL, NULL); @@ -257,27 +280,21 @@ struct cmd_results *cmd_focus(int argc, char **argv) { return focus_output(seat, argc, argv); } - enum movement_direction direction = 0; - if (!parse_movement_direction(argv[0], &direction)) { + if (strcasecmp(argv[0], "parent") == 0) { + return focus_parent(); + } + if (strcasecmp(argv[0], "child") == 0) { + return focus_child(); + } + + enum wlr_direction direction = 0; + if (!parse_direction(argv[0], &direction)) { return cmd_results_new(CMD_INVALID, "focus", "Expected 'focus <direction|parent|child|mode_toggle|floating|tiling>' " "or 'focus output <direction|name>'"); } - if (direction == MOVE_CHILD) { - struct sway_node *focus = seat_get_active_tiling_child(seat, node); - if (focus) { - seat_set_focus(seat, focus); - seat_consider_warp_to_focus(seat); - } - return cmd_results_new(CMD_SUCCESS, NULL, NULL); - } - if (node->type == N_WORKSPACE) { - if (direction == MOVE_PARENT) { - return cmd_results_new(CMD_SUCCESS, NULL, NULL); - } - // Jump to the next output struct sway_output *new_output = output_get_in_direction(workspace->output, direction); diff --git a/sway/commands/mark.c b/sway/commands/mark.c index b1f47be1..c76e1d63 100644 --- a/sway/commands/mark.c +++ b/sway/commands/mark.c @@ -19,11 +19,10 @@ struct cmd_results *cmd_mark(int argc, char **argv) { return error; } struct sway_container *container = config->handler_context.container; - if (!container || !container->view) { + if (!container) { return cmd_results_new(CMD_INVALID, "mark", - "Only views can have marks"); + "Only containers can have marks"); } - struct sway_view *view = container->view; bool add = false, toggle = false; while (argc > 0 && strncmp(*argv, "--", 2) == 0) { @@ -47,22 +46,24 @@ struct cmd_results *cmd_mark(int argc, char **argv) { } char *mark = join_args(argv, argc); - bool had_mark = view_has_mark(view, mark); + bool had_mark = container_has_mark(container, mark); if (!add) { // Replacing - view_clear_marks(view); + container_clear_marks(container); } - view_find_and_unmark(mark); + container_find_and_unmark(mark); if (!toggle || !had_mark) { - view_add_mark(view, mark); + container_add_mark(container, mark); } free(mark); - view_update_marks_textures(view); - view_execute_criteria(view); + container_update_marks_textures(container); + if (container->view) { + view_execute_criteria(container->view); + } return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/move.c b/sway/commands/move.c index ffe12d41..7d8c1f1a 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -27,19 +27,6 @@ static const char *expected_syntax = "'move <container|window|workspace> [to] output <name|direction>' or " "'move <container|window> [to] mark <mark>'"; -enum wlr_direction opposite_direction(enum wlr_direction d) { - switch (d) { - case WLR_DIRECTION_UP: - return WLR_DIRECTION_DOWN; - case WLR_DIRECTION_DOWN: - return WLR_DIRECTION_UP; - case WLR_DIRECTION_RIGHT: - return WLR_DIRECTION_LEFT; - default: - return WLR_DIRECTION_RIGHT; - } -} - static struct sway_output *output_in_direction(const char *direction_string, struct sway_output *reference, int ref_lx, int ref_ly) { struct { @@ -81,14 +68,14 @@ static struct sway_output *output_in_direction(const char *direction_string, } static bool is_parallel(enum sway_container_layout layout, - enum movement_direction dir) { + enum wlr_direction dir) { switch (layout) { case L_TABBED: case L_HORIZ: - return dir == MOVE_LEFT || dir == MOVE_RIGHT; + return dir == WLR_DIRECTION_LEFT || dir == WLR_DIRECTION_RIGHT; case L_STACKED: case L_VERT: - return dir == MOVE_UP || dir == MOVE_DOWN; + return dir == WLR_DIRECTION_UP || dir == WLR_DIRECTION_DOWN; default: return false; } @@ -115,7 +102,7 @@ static void workspace_focus_fullscreen(struct sway_workspace *workspace) { static void container_move_to_container_from_direction( struct sway_container *container, struct sway_container *destination, - enum movement_direction move_dir) { + enum wlr_direction move_dir) { if (destination->view) { if (destination->parent == container->parent && destination->workspace == container->workspace) { @@ -126,7 +113,8 @@ static void container_move_to_container_from_direction( list_swap(siblings, container_index, destination_index); } else { wlr_log(WLR_DEBUG, "Promoting to sibling of cousin"); - int offset = move_dir == MOVE_LEFT || move_dir == MOVE_UP; + int offset = + move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP; int index = container_sibling_index(destination) + offset; if (destination->parent) { container_insert_child(destination->parent, container, index); @@ -141,7 +129,8 @@ static void container_move_to_container_from_direction( if (is_parallel(destination->layout, move_dir)) { wlr_log(WLR_DEBUG, "Reparenting container (parallel)"); - int index = move_dir == MOVE_RIGHT || move_dir == MOVE_DOWN ? + int index = + move_dir == WLR_DIRECTION_RIGHT || move_dir == WLR_DIRECTION_DOWN ? 0 : destination->children->length; container_insert_child(destination, container, index); container->width = container->height = 0; @@ -164,10 +153,11 @@ static void container_move_to_container_from_direction( static void container_move_to_workspace_from_direction( struct sway_container *container, struct sway_workspace *workspace, - enum movement_direction move_dir) { + enum wlr_direction move_dir) { if (is_parallel(workspace->layout, move_dir)) { wlr_log(WLR_DEBUG, "Reparenting container (parallel)"); - int index = move_dir == MOVE_RIGHT || move_dir == MOVE_DOWN ? + int index = + move_dir == WLR_DIRECTION_RIGHT || move_dir == WLR_DIRECTION_DOWN ? 0 : workspace->tiling->length; workspace_insert_tiling(workspace, container, index); return; @@ -258,28 +248,31 @@ static void container_move_to_container(struct sway_container *container, * container, switches the layout of the workspace, and drops the child back in. * In other words, rejigger it. */ static void workspace_rejigger(struct sway_workspace *ws, - struct sway_container *child, enum movement_direction move_dir) { + struct sway_container *child, enum wlr_direction move_dir) { if (!child->parent && ws->tiling->length == 1) { ws->layout = - move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; + move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_RIGHT ? + L_HORIZ : L_VERT; workspace_update_representation(ws); return; } container_detach(child); struct sway_container *new_parent = workspace_wrap_children(ws); - int index = move_dir == MOVE_LEFT || move_dir == MOVE_UP ? 0 : 1; + int index = + move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP ? 0 : 1; workspace_insert_tiling(ws, child, index); container_flatten(new_parent); ws->layout = - move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; + move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_RIGHT ? + L_HORIZ : L_VERT; workspace_update_representation(ws); child->width = child->height = 0; } // Returns true if moved static bool container_move_in_direction(struct sway_container *container, - enum movement_direction move_dir) { + enum wlr_direction move_dir) { // If moving a fullscreen view, only consider outputs if (container->is_fullscreen) { struct sway_output *new_output = @@ -305,7 +298,8 @@ static bool container_move_in_direction(struct sway_container *container, // The below loop stops once we hit the workspace because current->parent // is NULL for the topmost containers in a workspace. struct sway_container *current = container; - int offs = move_dir == MOVE_LEFT || move_dir == MOVE_UP ? -1 : 1; + int offs = + move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP ? -1 : 1; while (current) { list_t *siblings = container_get_siblings(current); @@ -494,12 +488,12 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) { } destination = seat_get_focus_inactive(seat, &new_output->node); } else if (strcasecmp(argv[1], "mark") == 0) { - struct sway_view *dest_view = view_find_mark(argv[2]); - if (dest_view == NULL) { + struct sway_container *dest_con = container_find_mark(argv[2]); + if (dest_con == NULL) { return cmd_results_new(CMD_FAILURE, "move", "Mark '%s' not found", argv[2]); } - destination = &dest_view->container->node; + destination = &dest_con->node; } else { return cmd_results_new(CMD_INVALID, "move", expected_syntax); } @@ -642,7 +636,7 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) { } static struct cmd_results *cmd_move_in_direction( - enum movement_direction direction, int argc, char **argv) { + enum wlr_direction direction, int argc, char **argv) { int move_amt = 10; if (argc > 1) { char *inv; @@ -666,22 +660,18 @@ static struct cmd_results *cmd_move_in_direction( double lx = container->x; double ly = container->y; switch (direction) { - case MOVE_LEFT: + case WLR_DIRECTION_LEFT: lx -= move_amt; break; - case MOVE_RIGHT: + case WLR_DIRECTION_RIGHT: lx += move_amt; break; - case MOVE_UP: + case WLR_DIRECTION_UP: ly -= move_amt; break; - case MOVE_DOWN: + case WLR_DIRECTION_DOWN: ly += move_amt; break; - case MOVE_PARENT: - case MOVE_CHILD: - return cmd_results_new(CMD_FAILURE, "move", - "Cannot move floating container to parent or child"); } container_floating_move_to(container, lx, ly); return cmd_results_new(CMD_SUCCESS, NULL, NULL); @@ -850,13 +840,13 @@ struct cmd_results *cmd_move(int argc, char **argv) { } if (strcasecmp(argv[0], "left") == 0) { - return cmd_move_in_direction(MOVE_LEFT, argc, argv); + return cmd_move_in_direction(WLR_DIRECTION_LEFT, argc, argv); } else if (strcasecmp(argv[0], "right") == 0) { - return cmd_move_in_direction(MOVE_RIGHT, argc, argv); + return cmd_move_in_direction(WLR_DIRECTION_RIGHT, argc, argv); } else if (strcasecmp(argv[0], "up") == 0) { - return cmd_move_in_direction(MOVE_UP, argc, argv); + return cmd_move_in_direction(WLR_DIRECTION_UP, argc, argv); } else if (strcasecmp(argv[0], "down") == 0) { - return cmd_move_in_direction(MOVE_DOWN, argc, argv); + return cmd_move_in_direction(WLR_DIRECTION_DOWN, argc, argv); } else if ((strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) || (strcasecmp(argv[0], "--no-auto-back-and-forth") && argc >= 2 diff --git a/sway/commands/reload.c b/sway/commands/reload.c index 791081a8..62105cdc 100644 --- a/sway/commands/reload.c +++ b/sway/commands/reload.c @@ -10,9 +10,7 @@ #include "log.h" static void rebuild_textures_iterator(struct sway_container *con, void *data) { - if (con->view) { - view_update_marks_textures(con->view); - } + container_update_marks_textures(con); container_update_title_textures(con); } diff --git a/sway/commands/show_marks.c b/sway/commands/show_marks.c index d501584a..0baf6852 100644 --- a/sway/commands/show_marks.c +++ b/sway/commands/show_marks.c @@ -11,9 +11,7 @@ #include "util.h" static void rebuild_marks_iterator(struct sway_container *con, void *data) { - if (con->view) { - view_update_marks_textures(con->view); - } + container_update_marks_textures(con); } struct cmd_results *cmd_show_marks(int argc, char **argv) { diff --git a/sway/commands/swap.c b/sway/commands/swap.c index a70a6cdd..23e8d583 100644 --- a/sway/commands/swap.c +++ b/sway/commands/swap.c @@ -159,8 +159,8 @@ static bool test_id(struct sway_container *container, void *id) { } static bool test_mark(struct sway_container *container, void *mark) { - if (container->view && container->view->marks->length) { - return !list_seq_find(container->view->marks, + if (container->marks->length) { + return !list_seq_find(container->marks, (int (*)(const void *, const void *))strcmp, mark); } return false; diff --git a/sway/commands/unmark.c b/sway/commands/unmark.c index c671ed4e..98ac6ff2 100644 --- a/sway/commands/unmark.c +++ b/sway/commands/unmark.c @@ -9,10 +9,8 @@ #include "stringop.h" static void remove_all_marks_iterator(struct sway_container *con, void *data) { - if (con->view) { - view_clear_marks(con->view); - view_update_marks_textures(con->view); - } + container_clear_marks(con); + container_update_marks_textures(con); } // unmark Remove all marks from all views @@ -21,15 +19,10 @@ static void remove_all_marks_iterator(struct sway_container *con, void *data) { // [criteria] unmark foo Remove single mark from matched view struct cmd_results *cmd_unmark(int argc, char **argv) { - // Determine the view - struct sway_view *view = NULL; + // Determine the container + struct sway_container *con = NULL; if (config->handler_context.using_criteria) { - struct sway_container *container = config->handler_context.container; - if (!container || !container->view) { - return cmd_results_new(CMD_INVALID, "unmark", - "Only views can have marks"); - } - view = container->view; + con = config->handler_context.container; } // Determine the mark @@ -38,20 +31,20 @@ struct cmd_results *cmd_unmark(int argc, char **argv) { mark = join_args(argv, argc); } - if (view && mark) { - // Remove the mark from the given view - if (view_has_mark(view, mark)) { - view_find_and_unmark(mark); + if (con && mark) { + // Remove the mark from the given container + if (container_has_mark(con, mark)) { + container_find_and_unmark(mark); } - } else if (view && !mark) { - // Clear all marks from the given view - view_clear_marks(view); - view_update_marks_textures(view); - } else if (!view && mark) { - // Remove mark from whichever view has it - view_find_and_unmark(mark); + } else if (con && !mark) { + // Clear all marks from the given container + container_clear_marks(con); + container_update_marks_textures(con); + } else if (!con && mark) { + // Remove mark from whichever container has it + container_find_and_unmark(mark); } else { - // Remove all marks from all views + // Remove all marks from all containers root_for_each_container(remove_all_marks_iterator, NULL); } free(mark); diff --git a/sway/criteria.c b/sway/criteria.c index 89630d90..2f9992e9 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -121,8 +121,9 @@ static bool criteria_matches_view(struct criteria *criteria, if (criteria->con_mark) { bool exists = false; - for (int i = 0; i < view->marks->length; ++i) { - if (regex_cmp(view->marks->items[i], criteria->con_mark) == 0) { + struct sway_container *con = view->container; + for (int i = 0; i < con->marks->length; ++i) { + if (regex_cmp(con->marks->items[i], criteria->con_mark) == 0) { exists = true; break; } diff --git a/sway/desktop/output.c b/sway/desktop/output.c index ed9300bb..2b90f151 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -39,6 +39,19 @@ struct sway_output *output_by_name(const char *name) { return NULL; } +struct sway_output *output_by_identifier(const char *identifier) { + for (int i = 0; i < root->outputs->length; ++i) { + struct sway_output *output = root->outputs->items[i]; + char output_identifier[128]; + snprintf(output_identifier, sizeof(output_identifier), "%s %s %s", output->wlr_output->make, + output->wlr_output->model, output->wlr_output->serial); + if (strcasecmp(output_identifier, identifier) == 0) { + return output; + } + } + return NULL; +} + /** * Rotate a child's position relative to a parent. The parent size is (pw, ph), * the child position is (*sx, *sy) and its size is (sw, sh). @@ -519,9 +532,7 @@ static void handle_transform(struct wl_listener *listener, void *data) { static void update_textures(struct sway_container *con, void *data) { container_update_title_textures(con); - if (con->view) { - view_update_marks_textures(con->view); - } + container_update_marks_textures(con); } static void handle_scale(struct wl_listener *listener, void *data) { diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 1a72f752..cf6da682 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -625,19 +625,19 @@ static void render_containers_linear(struct sway_output *output, if (view_is_urgent(view)) { colors = &config->border_colors.urgent; title_texture = child->title_urgent; - marks_texture = view->marks_urgent; + marks_texture = child->marks_urgent; } else if (state->focused || parent->focused) { colors = &config->border_colors.focused; title_texture = child->title_focused; - marks_texture = view->marks_focused; + marks_texture = child->marks_focused; } else if (child == parent->active_child) { colors = &config->border_colors.focused_inactive; title_texture = child->title_focused_inactive; - marks_texture = view->marks_focused_inactive; + marks_texture = child->marks_focused_inactive; } else { colors = &config->border_colors.unfocused; title_texture = child->title_unfocused; - marks_texture = view->marks_unfocused; + marks_texture = child->marks_unfocused; } if (state->border == B_NORMAL) { @@ -681,19 +681,19 @@ static void render_containers_tabbed(struct sway_output *output, if (urgent) { colors = &config->border_colors.urgent; title_texture = child->title_urgent; - marks_texture = view ? view->marks_urgent : NULL; + marks_texture = child->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; + marks_texture = child->marks_focused; } else if (child == parent->active_child) { colors = &config->border_colors.focused_inactive; title_texture = child->title_focused_inactive; - marks_texture = view ? view->marks_focused_inactive : NULL; + marks_texture = child->marks_focused_inactive; } else { colors = &config->border_colors.unfocused; title_texture = child->title_unfocused; - marks_texture = view ? view->marks_unfocused : NULL; + marks_texture = child->marks_unfocused; } int x = cstate->con_x + tab_width * i; @@ -746,19 +746,19 @@ static void render_containers_stacked(struct sway_output *output, if (urgent) { colors = &config->border_colors.urgent; title_texture = child->title_urgent; - marks_texture = view ? view->marks_urgent : NULL; + marks_texture = child->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; + marks_texture = child->marks_focused; } else if (child == parent->active_child) { colors = &config->border_colors.focused_inactive; title_texture = child->title_focused_inactive; - marks_texture = view ? view->marks_focused_inactive : NULL; + marks_texture = child->marks_focused_inactive; } else { colors = &config->border_colors.unfocused; title_texture = child->title_unfocused; - marks_texture = view ? view->marks_unfocused : NULL; + marks_texture = child->marks_unfocused; } int y = parent->box.y + titlebar_height * i; @@ -841,15 +841,15 @@ static void render_floating_container(struct sway_output *soutput, if (view_is_urgent(view)) { colors = &config->border_colors.urgent; title_texture = con->title_urgent; - marks_texture = view->marks_urgent; + marks_texture = con->marks_urgent; } else if (con->current.focused) { colors = &config->border_colors.focused; title_texture = con->title_focused; - marks_texture = view->marks_focused; + marks_texture = con->marks_focused; } else { colors = &config->border_colors.unfocused; title_texture = con->title_unfocused; - marks_texture = view->marks_unfocused; + marks_texture = con->marks_unfocused; } if (con->current.border == B_NORMAL) { diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index 955b05d6..44156d41 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -137,6 +137,12 @@ static void copy_container_state(struct sway_container *container, state->is_fullscreen = container->is_fullscreen; state->parent = container->parent; state->workspace = container->workspace; + state->border = container->border; + state->border_thickness = container->border_thickness; + state->border_top = container->border_top; + state->border_left = container->border_left; + state->border_right = container->border_right; + state->border_bottom = container->border_bottom; if (container->view) { struct sway_view *view = container->view; @@ -144,12 +150,6 @@ static void copy_container_state(struct sway_container *container, state->view_y = view->y; state->view_width = view->width; state->view_height = view->height; - state->border = view->border; - state->border_thickness = view->border_thickness; - state->border_top = view->border_top; - state->border_left = view->border_left; - state->border_right = view->border_right; - state->border_bottom = view->border_bottom; } else { state->children = create_list(); list_cat(state->children, container->children); @@ -301,7 +301,9 @@ static void transaction_apply(struct sway_transaction *transaction) { if (root->outputs->length) { struct sway_seat *seat; wl_list_for_each(seat, &server.input->seats, link) { - cursor_rebase(seat->cursor); + if (seat->operation == OP_NONE) { + cursor_rebase(seat->cursor); + } } } } diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 3942b64f..c539df40 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -187,23 +187,22 @@ static enum wlr_edges find_edge(struct sway_container *cont, if (!cont->view) { return WLR_EDGE_NONE; } - struct sway_view *view = cont->view; - if (view->border == B_NONE || !view->border_thickness || - view->border == B_CSD) { + if (cont->border == B_NONE || !cont->border_thickness || + cont->border == B_CSD) { return WLR_EDGE_NONE; } enum wlr_edges edge = 0; - if (cursor->cursor->x < cont->x + view->border_thickness) { + if (cursor->cursor->x < cont->x + cont->border_thickness) { edge |= WLR_EDGE_LEFT; } - if (cursor->cursor->y < cont->y + view->border_thickness) { + if (cursor->cursor->y < cont->y + cont->border_thickness) { edge |= WLR_EDGE_TOP; } - if (cursor->cursor->x >= cont->x + cont->width - view->border_thickness) { + if (cursor->cursor->x >= cont->x + cont->width - cont->border_thickness) { edge |= WLR_EDGE_RIGHT; } - if (cursor->cursor->y >= cont->y + cont->height - view->border_thickness) { + if (cursor->cursor->y >= cont->y + cont->height - cont->border_thickness) { edge |= WLR_EDGE_BOTTOM; } @@ -585,7 +584,7 @@ static void cursor_do_rebase(struct sway_cursor *cursor, uint32_t time_msec, void cursor_rebase(struct sway_cursor *cursor) { uint32_t time_msec = get_current_time_msec(); - struct wlr_surface *surface; + struct wlr_surface *surface = NULL; double sx, sy; cursor->previous.node = node_at_coords(cursor->seat, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 91c45dd1..68445d68 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -431,6 +431,7 @@ void input_manager_set_focus(struct sway_node *node) { struct sway_seat *seat; wl_list_for_each(seat, &server.input->seats, link) { seat_set_focus(seat, node); + seat_consider_warp_to_focus(seat); } } diff --git a/sway/input/seat.c b/sway/input/seat.c index 577619a7..64419afa 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -185,7 +185,11 @@ static void handle_seat_node_destroy(struct wl_listener *listener, void *data) { seat_set_focus(seat, next_focus); } else { // Setting focus_inactive + focus = seat_get_focus_inactive(seat, &root->node); seat_set_raw_focus(seat, next_focus); + if (focus->type == N_CONTAINER) { + seat_set_raw_focus(seat, &focus->sway_container->workspace->node); + } seat_set_raw_focus(seat, focus); } } @@ -944,7 +948,7 @@ struct sway_node *seat_get_focus(struct sway_seat *seat) { if (!seat->has_focus) { return NULL; } - if (wl_list_length(&seat->focus_stack) == 0) { + if (wl_list_empty(&seat->focus_stack)) { return NULL; } struct sway_seat_node *current = diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 2cd0cb2d..7cc965c8 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -136,13 +136,18 @@ static void ipc_json_describe_output(struct sway_output *output, json_object_new_int(mode->width)); json_object_object_add(mode_object, "height", json_object_new_int(mode->height)); - json_object_object_add(mode_object, "refresh", - json_object_new_int(mode->refresh)); json_object_array_add(modes_array, mode_object); } json_object_object_add(object, "modes", modes_array); + json_object *current_mode_object = json_object_new_object(); + json_object_object_add(current_mode_object, "width", + json_object_new_int(wlr_output->width)); + json_object_object_add(current_mode_object, "height", + json_object_new_int(wlr_output->height)); + json_object_object_add(object, "current_mode", current_mode_object); + struct sway_node *parent = node_get_parent(&output->node); struct wlr_box parent_box = {0, 0, 0, 0}; @@ -229,14 +234,10 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object json_object_object_add(object, "app_id", app_id ? json_object_new_string(app_id) : NULL); - const char *class = view_get_class(c->view); - json_object_object_add(object, "class", - class ? json_object_new_string(class) : NULL); - json_object *marks = json_object_new_array(); - list_t *view_marks = c->view->marks; - for (int i = 0; i < view_marks->length; ++i) { - json_object_array_add(marks, json_object_new_string(view_marks->items[i])); + list_t *con_marks = c->marks; + for (int i = 0; i < con_marks->length; ++i) { + json_object_array_add(marks, json_object_new_string(con_marks->items[i])); } json_object_object_add(object, "marks", marks); @@ -269,13 +270,17 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object json_object *window_props = json_object_new_object(); - json_object_object_add(window_props, "class", - class ? json_object_new_string(class) : NULL); + const char *class = view_get_class(c->view); + if (class) { + json_object_object_add(window_props, "class", json_object_new_string(class)); + } const char *instance = view_get_instance(c->view); - json_object_object_add(window_props, "instance", - instance ? json_object_new_string(instance) : NULL); - json_object_object_add(window_props, "title", - c->title ? json_object_new_string(c->title) : NULL); + if (instance) { + json_object_object_add(window_props, "instance", json_object_new_string(instance)); + } + if (c->title) { + json_object_object_add(window_props, "title", json_object_new_string(c->title)); + } // the transient_for key is always present in i3's output uint32_t parent_id = view_get_x11_parent_id(c->view); @@ -284,8 +289,7 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object const char *role = view_get_window_role(c->view); if (role) { - json_object_object_add(window_props, "window_role", - json_object_new_string(role)); + json_object_object_add(window_props, "window_role", json_object_new_string(role)); } json_object_object_add(object, "window_properties", window_props); diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 21f431be..6466d263 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -563,11 +563,9 @@ static void ipc_get_workspaces_callback(struct sway_workspace *workspace, static void ipc_get_marks_callback(struct sway_container *con, void *data) { json_object *marks = (json_object *)data; - if (con->view && con->view->marks) { - for (int i = 0; i < con->view->marks->length; ++i) { - char *mark = (char *)con->view->marks->items[i]; - json_object_array_add(marks, json_object_new_string(mark)); - } + for (int i = 0; i < con->marks->length; ++i) { + char *mark = (char *)con->marks->items[i]; + json_object_array_add(marks, json_object_new_string(mark)); } } diff --git a/sway/main.c b/sway/main.c index cc5f7187..920cea11 100644 --- a/sway/main.c +++ b/sway/main.c @@ -29,7 +29,7 @@ static bool terminate_request = false; static int exit_value = 0; -struct sway_server server; +struct sway_server server = {0}; void sway_terminate(int exit_code) { terminate_request = true; @@ -194,21 +194,23 @@ static void log_kernel(void) { } -static void drop_permissions(void) { +static bool drop_permissions(void) { if (getuid() != geteuid() || getgid() != getegid()) { if (setgid(getgid()) != 0) { - wlr_log(WLR_ERROR, "Unable to drop root"); - exit(EXIT_FAILURE); + wlr_log(WLR_ERROR, "Unable to drop root, refusing to start"); + return false; } if (setuid(getuid()) != 0) { - wlr_log(WLR_ERROR, "Unable to drop root"); - exit(EXIT_FAILURE); + wlr_log(WLR_ERROR, "Unable to drop root, refusing to start"); + return false; } } if (setuid(0) != -1) { - wlr_log(WLR_ERROR, "Root privileges can be restored."); - exit(EXIT_FAILURE); + wlr_log(WLR_ERROR, "Unable to drop root (we shouldn't be able to " + "restore it after setuid), refusing to start"); + return false; } + return true; } void enable_debug_flag(const char *flag) { @@ -317,11 +319,13 @@ int main(int argc, char **argv) { } if (optind < argc) { // Behave as IPC client - if(optind != 1) { + if (optind != 1) { wlr_log(WLR_ERROR, "Don't use options with the IPC client"); exit(EXIT_FAILURE); } - drop_permissions(); + if (!drop_permissions()) { + exit(EXIT_FAILURE); + } char *socket_path = getenv("SWAYSOCK"); if (!socket_path) { wlr_log(WLR_ERROR, "Unable to retrieve socket path"); @@ -341,7 +345,10 @@ int main(int argc, char **argv) { detect_proprietary(allow_unsupported_gpu); detect_raspi(); - drop_permissions(); + if (!drop_permissions()) { + server_fini(&server); + exit(EXIT_FAILURE); + } // handle SIGTERM signals signal(SIGTERM, sig_handler); diff --git a/sway/tree/container.c b/sway/tree/container.c index 58d3df34..458ed7ff 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -39,6 +39,7 @@ struct sway_container *container_create(struct sway_view *view) { c->children = create_list(); c->current.children = create_list(); } + c->marks = create_list(); c->outputs = create_list(); wl_signal_init(&c->events.destroy); @@ -66,6 +67,13 @@ void container_destroy(struct sway_container *con) { list_free(con->current.children); list_free(con->outputs); + list_foreach(con->marks, free); + list_free(con->marks); + wlr_texture_destroy(con->marks_focused); + wlr_texture_destroy(con->marks_focused_inactive); + wlr_texture_destroy(con->marks_unfocused); + wlr_texture_destroy(con->marks_urgent); + if (con->view) { if (con->view->container == con) { con->view->container = NULL; @@ -639,8 +647,8 @@ void container_init_floating(struct sway_container *con) { view->y = ws->y + (ws->height - view->height) / 2; // If the view's border is B_NONE then these properties are ignored. - view->border_top = view->border_bottom = true; - view->border_left = view->border_right = true; + con->border_top = con->border_bottom = true; + con->border_left = con->border_right = true; container_set_geometry_from_floating_view(con); } @@ -662,7 +670,7 @@ void container_set_floating(struct sway_container *container, bool enable) { if (container->view) { view_set_tiled(container->view, false); if (container->view->using_csd) { - container->view->border = B_CSD; + container->border = B_CSD; } } if (old_parent) { @@ -676,11 +684,8 @@ void container_set_floating(struct sway_container *container, bool enable) { container_detach(container); struct sway_container *reference = seat_get_focus_inactive_tiling(seat, workspace); - if (reference && reference->view) { - reference = reference->parent; - } if (reference) { - container_add_child(reference, container); + container_add_sibling(reference, container, 1); container->width = reference->width; container->height = reference->height; } else { @@ -691,7 +696,7 @@ void container_set_floating(struct sway_container *container, bool enable) { if (container->view) { view_set_tiled(container->view, true); if (container->view->using_csd) { - container->view->border = container->view->saved_border; + container->border = container->saved_border; } } container->is_sticky = false; @@ -713,9 +718,9 @@ void container_set_geometry_from_floating_view(struct sway_container *con) { size_t border_width = 0; size_t top = 0; - if (view->border != B_CSD) { - border_width = view->border_thickness * (view->border != B_NONE); - top = view->border == B_NORMAL ? + if (con->border != B_CSD) { + border_width = con->border_thickness * (con->border != B_NONE); + top = con->border == B_NORMAL ? container_titlebar_height() : border_width; } @@ -999,9 +1004,7 @@ void container_discover_outputs(struct sway_container *con) { double new_scale = new_output ? new_output->wlr_output->scale : -1; if (old_scale != new_scale) { container_update_title_textures(con); - if (con->view) { - view_update_marks_textures(con->view); - } + container_update_marks_textures(con); } } @@ -1221,3 +1224,142 @@ bool container_is_transient_for(struct sway_container *child, child->view && ancestor->view && view_is_transient_for(child->view, ancestor->view); } + +static bool find_by_mark_iterator(struct sway_container *con, void *data) { + char *mark = data; + return container_has_mark(con, mark); +} + +struct sway_container *container_find_mark(char *mark) { + return root_find_container(find_by_mark_iterator, mark); +} + +bool container_find_and_unmark(char *mark) { + struct sway_container *con = root_find_container( + find_by_mark_iterator, mark); + if (!con) { + return false; + } + + for (int i = 0; i < con->marks->length; ++i) { + char *con_mark = con->marks->items[i]; + if (strcmp(con_mark, mark) == 0) { + free(con_mark); + list_del(con->marks, i); + container_update_marks_textures(con); + ipc_event_window(con, "mark"); + return true; + } + } + return false; +} + +void container_clear_marks(struct sway_container *con) { + list_foreach(con->marks, free); + con->marks->length = 0; + ipc_event_window(con, "mark"); +} + +bool container_has_mark(struct sway_container *con, char *mark) { + for (int i = 0; i < con->marks->length; ++i) { + char *item = con->marks->items[i]; + if (strcmp(item, mark) == 0) { + return true; + } + } + return false; +} + +void container_add_mark(struct sway_container *con, char *mark) { + list_add(con->marks, strdup(mark)); + ipc_event_window(con, "mark"); +} + +static void update_marks_texture(struct sway_container *con, + struct wlr_texture **texture, struct border_colors *class) { + struct sway_output *output = container_get_effective_output(con); + if (!output) { + return; + } + if (*texture) { + wlr_texture_destroy(*texture); + *texture = NULL; + } + if (!con->marks->length) { + return; + } + + size_t len = 0; + for (int i = 0; i < con->marks->length; ++i) { + char *mark = con->marks->items[i]; + if (mark[0] != '_') { + len += strlen(mark) + 2; + } + } + char *buffer = calloc(len + 1, 1); + char *part = malloc(len + 1); + + if (!sway_assert(buffer && part, "Unable to allocate memory")) { + free(buffer); + return; + } + + for (int i = 0; i < con->marks->length; ++i) { + char *mark = con->marks->items[i]; + if (mark[0] != '_') { + sprintf(part, "[%s]", mark); + strcat(buffer, part); + } + } + free(part); + + double scale = output->wlr_output->scale; + int width = 0; + int height = con->title_height * scale; + + cairo_t *c = cairo_create(NULL); + get_text_size(c, config->font, &width, NULL, NULL, scale, false, + "%s", buffer); + cairo_destroy(c); + + cairo_surface_t *surface = cairo_image_surface_create( + CAIRO_FORMAT_ARGB32, width, height); + cairo_t *cairo = cairo_create(surface); + cairo_set_source_rgba(cairo, class->background[0], class->background[1], + class->background[2], class->background[3]); + cairo_paint(cairo); + PangoContext *pango = pango_cairo_create_context(cairo); + cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST); + cairo_set_source_rgba(cairo, class->text[0], class->text[1], + class->text[2], class->text[3]); + cairo_move_to(cairo, 0, 0); + + pango_printf(cairo, config->font, scale, false, "%s", buffer); + + cairo_surface_flush(surface); + unsigned char *data = cairo_image_surface_get_data(surface); + int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); + struct wlr_renderer *renderer = wlr_backend_get_renderer( + output->wlr_output->backend); + *texture = wlr_texture_from_pixels( + renderer, WL_SHM_FORMAT_ARGB8888, stride, width, height, data); + cairo_surface_destroy(surface); + g_object_unref(pango); + cairo_destroy(cairo); + free(buffer); +} + +void container_update_marks_textures(struct sway_container *con) { + if (!config->show_marks) { + return; + } + update_marks_texture(con, &con->marks_focused, + &config->border_colors.focused); + update_marks_texture(con, &con->marks_focused_inactive, + &config->border_colors.focused_inactive); + update_marks_texture(con, &con->marks_unfocused, + &config->border_colors.unfocused); + update_marks_texture(con, &con->marks_urgent, + &config->border_colors.urgent); + container_damage_whole(con); +} diff --git a/sway/tree/output.c b/sway/tree/output.c index e5794b8a..2704920d 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -65,8 +65,13 @@ void output_enable(struct sway_output *output, struct output_config *oc) { return; } struct wlr_output *wlr_output = output->wlr_output; + size_t len = sizeof(output->layers) / sizeof(output->layers[0]); + for (size_t i = 0; i < len; ++i) { + wl_list_init(&output->layers[i]); + } + wl_signal_init(&output->events.destroy); + output->enabled = true; - apply_output_config(oc, output); list_add(root->outputs, output); output->lx = wlr_output->lx; @@ -92,11 +97,8 @@ void output_enable(struct sway_output *output, struct output_config *oc) { ipc_event_workspace(NULL, ws, "init"); } - size_t len = sizeof(output->layers) / sizeof(output->layers[0]); - for (size_t i = 0; i < len; ++i) { - wl_list_init(&output->layers[i]); - } - wl_signal_init(&output->events.destroy); + + apply_output_config(oc, output); input_manager_configure_xcursor(); @@ -274,16 +276,14 @@ struct sway_output *output_from_wlr_output(struct wlr_output *output) { } struct sway_output *output_get_in_direction(struct sway_output *reference, - enum movement_direction direction) { - enum wlr_direction wlr_dir = 0; - if (!sway_assert(sway_dir_to_wlr(direction, &wlr_dir), - "got invalid direction: %d", direction)) { + enum wlr_direction direction) { + if (!sway_assert(direction, "got invalid direction: %d", direction)) { return NULL; } int lx = reference->wlr_output->lx + reference->width / 2; int ly = reference->wlr_output->ly + reference->height / 2; struct wlr_output *wlr_adjacent = wlr_output_layout_adjacent_output( - root->output_layout, wlr_dir, reference->wlr_output, lx, ly); + root->output_layout, direction, reference->wlr_output, lx, ly); if (!wlr_adjacent) { return NULL; } diff --git a/sway/tree/view.c b/sway/tree/view.c index 4bc9e0f3..1aa59e68 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -35,7 +35,6 @@ void view_init(struct sway_view *view, enum sway_view_type type, 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); } @@ -55,13 +54,6 @@ void view_destroy(struct sway_view *view) { } list_free(view->executed_criteria); - list_foreach(view->marks, free); - list_free(view->marks); - - wlr_texture_destroy(view->marks_focused); - wlr_texture_destroy(view->marks_focused_inactive); - wlr_texture_destroy(view->marks_unfocused); - wlr_texture_destroy(view->marks_urgent); free(view->title_format); if (view->impl->destroy) { @@ -225,21 +217,21 @@ void view_autoconfigure(struct sway_view *view) { bool no_gaps = config->hide_edge_borders != E_SMART_NO_GAPS || !gaps_to_edge(view); - view->border_top = view->border_bottom = true; - view->border_left = view->border_right = true; + con->border_top = con->border_bottom = true; + con->border_left = con->border_right = true; if (config->hide_edge_borders == E_BOTH || config->hide_edge_borders == E_VERTICAL || (smart && !other_views && no_gaps)) { - view->border_left = con->x - con->current_gaps != ws->x; + con->border_left = con->x - con->current_gaps != ws->x; int right_x = con->x + con->width + con->current_gaps; - view->border_right = right_x != ws->x + ws->width; + con->border_right = right_x != ws->x + ws->width; } if (config->hide_edge_borders == E_BOTH || config->hide_edge_borders == E_HORIZONTAL || (smart && !other_views && no_gaps)) { - view->border_top = con->y - con->current_gaps != ws->y; + con->border_top = con->y - con->current_gaps != ws->y; int bottom_y = con->y + con->height + con->current_gaps; - view->border_bottom = bottom_y != ws->y + ws->height; + con->border_bottom = bottom_y != ws->y + ws->height; } double x, y, width, height; @@ -252,14 +244,14 @@ void view_autoconfigure(struct sway_view *view) { enum sway_container_layout layout = container_parent_layout(con); if (layout == L_TABBED && !container_is_floating(con)) { y_offset = container_titlebar_height(); - view->border_top = false; + con->border_top = false; } else if (layout == L_STACKED && !container_is_floating(con)) { list_t *siblings = container_get_siblings(con); y_offset = container_titlebar_height() * siblings->length; - view->border_top = false; + con->border_top = false; } - switch (view->border) { + switch (con->border) { case B_CSD: case B_NONE: x = con->x; @@ -268,29 +260,29 @@ void view_autoconfigure(struct sway_view *view) { height = con->height - y_offset; break; case B_PIXEL: - x = con->x + view->border_thickness * view->border_left; - y = con->y + view->border_thickness * view->border_top + y_offset; + x = con->x + con->border_thickness * con->border_left; + y = con->y + con->border_thickness * con->border_top + y_offset; width = con->width - - view->border_thickness * view->border_left - - view->border_thickness * view->border_right; + - con->border_thickness * con->border_left + - con->border_thickness * con->border_right; height = con->height - y_offset - - view->border_thickness * view->border_top - - view->border_thickness * view->border_bottom; + - con->border_thickness * con->border_top + - con->border_thickness * con->border_bottom; break; case B_NORMAL: // Height is: 1px border + 3px pad + title height + 3px pad + 1px border - x = con->x + view->border_thickness * view->border_left; + x = con->x + con->border_thickness * con->border_left; width = con->width - - view->border_thickness * view->border_left - - view->border_thickness * view->border_right; + - con->border_thickness * con->border_left + - con->border_thickness * con->border_right; if (y_offset) { y = con->y + y_offset; height = con->height - y_offset - - view->border_thickness * view->border_bottom; + - con->border_thickness * con->border_bottom; } else { y = con->y + container_titlebar_height(); height = con->height - container_titlebar_height() - - view->border_thickness * view->border_bottom; + - con->border_thickness * con->border_bottom; } break; } @@ -347,13 +339,14 @@ void view_set_csd_from_server(struct sway_view *view, bool enabled) { void view_update_csd_from_client(struct sway_view *view, bool enabled) { wlr_log(WLR_DEBUG, "View %p updated CSD to %i", view, enabled); - if (enabled && view->border != B_CSD) { - view->saved_border = view->border; - if (view->container && container_is_floating(view->container)) { - view->border = B_CSD; + struct sway_container *con = view->container; + if (enabled && con && con->border != B_CSD) { + con->saved_border = con->border; + if (container_is_floating(con)) { + con->border = B_CSD; } - } else if (!enabled && view->border == B_CSD) { - view->border = view->saved_border; + } else if (!enabled && con && con->border == B_CSD) { + con->border = con->saved_border; } view->using_csd = enabled; } @@ -584,12 +577,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface, view->surface_new_subsurface.notify = view_handle_surface_new_subsurface; if (view->impl->wants_floating && view->impl->wants_floating(view)) { - view->border = config->floating_border; - view->border_thickness = config->floating_border_thickness; + view->container->border = config->floating_border; + view->container->border_thickness = config->floating_border_thickness; container_set_floating(view->container, true); } else { - view->border = config->border; - view->border_thickness = config->border_thickness; + view->container->border = config->border; + view->container->border_thickness = config->border_thickness; view_set_tiled(view, true); } @@ -936,153 +929,6 @@ void view_update_title(struct sway_view *view, bool force) { ipc_event_window(view->container, "title"); } -static bool find_by_mark_iterator(struct sway_container *con, - void *data) { - char *mark = data; - return con->view && view_has_mark(con->view, mark); -} - -struct sway_view *view_find_mark(char *mark) { - struct sway_container *container = root_find_container( - find_by_mark_iterator, mark); - if (!container) { - return NULL; - } - return container->view; -} - -bool view_find_and_unmark(char *mark) { - struct sway_container *container = root_find_container( - find_by_mark_iterator, mark); - if (!container) { - return false; - } - struct sway_view *view = container->view; - - for (int i = 0; i < view->marks->length; ++i) { - char *view_mark = view->marks->items[i]; - if (strcmp(view_mark, mark) == 0) { - free(view_mark); - list_del(view->marks, i); - view_update_marks_textures(view); - ipc_event_window(container, "mark"); - return true; - } - } - return false; -} - -void view_clear_marks(struct sway_view *view) { - list_foreach(view->marks, free); - view->marks->length = 0; - ipc_event_window(view->container, "mark"); -} - -bool view_has_mark(struct sway_view *view, char *mark) { - for (int i = 0; i < view->marks->length; ++i) { - char *item = view->marks->items[i]; - if (strcmp(item, mark) == 0) { - return true; - } - } - return false; -} - -void view_add_mark(struct sway_view *view, char *mark) { - list_add(view->marks, strdup(mark)); - ipc_event_window(view->container, "mark"); -} - -static void update_marks_texture(struct sway_view *view, - struct wlr_texture **texture, struct border_colors *class) { - struct sway_output *output = - container_get_effective_output(view->container); - if (!output) { - return; - } - if (*texture) { - wlr_texture_destroy(*texture); - *texture = NULL; - } - if (!view->marks->length) { - return; - } - - size_t len = 0; - for (int i = 0; i < view->marks->length; ++i) { - char *mark = view->marks->items[i]; - if (mark[0] != '_') { - len += strlen(mark) + 2; - } - } - char *buffer = calloc(len + 1, 1); - char *part = malloc(len + 1); - - if (!sway_assert(buffer && part, "Unable to allocate memory")) { - free(buffer); - return; - } - - for (int i = 0; i < view->marks->length; ++i) { - char *mark = view->marks->items[i]; - if (mark[0] != '_') { - sprintf(part, "[%s]", mark); - strcat(buffer, part); - } - } - free(part); - - double scale = output->wlr_output->scale; - int width = 0; - int height = view->container->title_height * scale; - - cairo_t *c = cairo_create(NULL); - get_text_size(c, config->font, &width, NULL, NULL, scale, false, - "%s", buffer); - cairo_destroy(c); - - cairo_surface_t *surface = cairo_image_surface_create( - CAIRO_FORMAT_ARGB32, width, height); - cairo_t *cairo = cairo_create(surface); - cairo_set_source_rgba(cairo, class->background[0], class->background[1], - class->background[2], class->background[3]); - cairo_paint(cairo); - PangoContext *pango = pango_cairo_create_context(cairo); - cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST); - cairo_set_source_rgba(cairo, class->text[0], class->text[1], - class->text[2], class->text[3]); - cairo_move_to(cairo, 0, 0); - - pango_printf(cairo, config->font, scale, false, "%s", buffer); - - cairo_surface_flush(surface); - unsigned char *data = cairo_image_surface_get_data(surface); - int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); - struct wlr_renderer *renderer = wlr_backend_get_renderer( - output->wlr_output->backend); - *texture = wlr_texture_from_pixels( - renderer, WL_SHM_FORMAT_ARGB8888, stride, width, height, data); - cairo_surface_destroy(surface); - g_object_unref(pango); - cairo_destroy(cairo); - free(buffer); -} - -void view_update_marks_textures(struct sway_view *view) { - if (!config->show_marks) { - return; - } - update_marks_texture(view, &view->marks_focused, - &config->border_colors.focused); - update_marks_texture(view, &view->marks_focused_inactive, - &config->border_colors.focused_inactive); - update_marks_texture(view, &view->marks_unfocused, - &config->border_colors.unfocused); - update_marks_texture(view, &view->marks_urgent, - &config->border_colors.urgent); - container_damage_whole(view->container); -} - bool view_is_visible(struct sway_view *view) { if (view->container->node.destroying) { return false; diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 27e9ac7a..05cda5c0 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -35,6 +35,10 @@ struct sway_output *workspace_get_initial_output(const char *name) { struct workspace_config *wsc = workspace_find_config(name); if (wsc && wsc->output) { struct sway_output *output = output_by_name(wsc->output); + if (!output) { + output = output_by_identifier(wsc->output); + } + if (output) { return output; } @@ -143,7 +147,11 @@ void workspace_consider_destroy(struct sway_workspace *ws) { static bool workspace_valid_on_output(const char *output_name, const char *ws_name) { struct workspace_config *wsc = workspace_find_config(ws_name); - return !wsc || !wsc->output || strcmp(wsc->output, output_name) == 0; + char identifier[128]; + struct sway_output *output = output_by_name(output_name); + output_get_identifier(identifier, sizeof(identifier), output); + + return !wsc || !wsc->output || strcmp(wsc->output, output_name) == 0 || strcasecmp(identifier, output_name) == 0; } static void workspace_name_from_binding(const struct sway_binding * binding, |