Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move view marks properties to container struct #3041

Merged
merged 1 commit into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions include/sway/tree/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ struct sway_container {
size_t title_height;
size_t title_baseline;

list_t *marks; // char *
struct wlr_texture *marks_focused;
struct wlr_texture *marks_focused_inactive;
struct wlr_texture *marks_unfocused;
struct wlr_texture *marks_urgent;

struct {
struct wl_signal destroy;
} events;
Expand Down Expand Up @@ -304,4 +310,26 @@ struct sway_container *container_split(struct sway_container *child,
bool container_is_transient_for(struct sway_container *child,
struct sway_container *ancestor);

/**
* Find any container that has the given mark and return it.
*/
struct sway_container *container_find_mark(char *mark);

/**
* Find any container that has the given mark and remove the mark from the
* container. Returns true if it matched a container.
*/
bool container_find_and_unmark(char *mark);

/**
* Remove all marks from the container.
*/
void container_clear_marks(struct sway_container *container);

bool container_has_mark(struct sway_container *container, char *mark);

void container_add_mark(struct sway_container *container, char *mark);

void container_update_marks_textures(struct sway_container *container);

#endif
28 changes: 0 additions & 28 deletions include/sway/tree/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ struct sway_view {
bool destroying;

list_t *executed_criteria; // struct criteria *
list_t *marks; // char *

struct wlr_texture *marks_focused;
struct wlr_texture *marks_focused_inactive;
struct wlr_texture *marks_unfocused;
struct wlr_texture *marks_urgent;

union {
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6;
Expand Down Expand Up @@ -352,28 +346,6 @@ void view_update_title(struct sway_view *view, bool force);
*/
void view_execute_criteria(struct sway_view *view);

/**
* Find any view that has the given mark and return it.
*/
struct sway_view *view_find_mark(char *mark);

/**
* Find any view that has the given mark and remove the mark from the view.
* Returns true if it matched a view.
*/
bool view_find_and_unmark(char *mark);

/**
* Remove all marks from the view.
*/
void view_clear_marks(struct sway_view *view);

bool view_has_mark(struct sway_view *view, char *mark);

void view_add_mark(struct sway_view *view, char *mark);

void view_update_marks_textures(struct sway_view *view);

/**
* Returns true if there's a possibility the view may be rendered on screen.
* Intended for damage tracking.
Expand Down
4 changes: 1 addition & 3 deletions sway/commands/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
19 changes: 10 additions & 9 deletions sway/commands/mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
6 changes: 3 additions & 3 deletions sway/commands/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,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);
}
Expand Down
4 changes: 1 addition & 3 deletions sway/commands/reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 1 addition & 3 deletions sway/commands/show_marks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions sway/commands/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 17 additions & 24 deletions sway/commands/unmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions sway/criteria.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions sway/desktop/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,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) {
Expand Down
30 changes: 15 additions & 15 deletions sway/desktop/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions sway/ipc-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
app_id ? json_object_new_string(app_id) : 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);
Expand Down
8 changes: 3 additions & 5 deletions sway/ipc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
Loading