desktop: support switching to windows in other workspaces

This commit is contained in:
Droc 2024-01-29 07:21:01 -06:00
parent f908e332b3
commit 5ba89ca6f8
4 changed files with 70 additions and 45 deletions

View file

@ -299,6 +299,22 @@ bool view_matches_query(struct view *view, struct view_query *query);
view; \ view; \
view = view_next(head, view, criteria)) view = view_next(head, view, criteria))
/**
* for_each_view_iter() - iterate in given direction against criteria
* @view: Iterator.
* @head: Head of list to iterate over.
* @iter: Iterator function to get next or previous view
* @criteria: Criteria to match against.
* Example:
* stuct view *(*iter)(struct wl_list *head, struct view *view,
enum lab_view_criteria criteria);
* iter = forwards ? view_next : view_prev;
*/
#define for_each_view_iter(view, head, iter, criteria) \
for (view = iter(head, NULL, criteria); \
view; \
view = iter(head, view, criteria))
/** /**
* view_next() - Get next view which matches criteria. * view_next() - Get next view which matches criteria.
* @head: Head of list to iterate over. * @head: Head of list to iterate over.
@ -311,6 +327,9 @@ bool view_matches_query(struct view *view, struct view_query *query);
struct view *view_next(struct wl_list *head, struct view *view, struct view *view_next(struct wl_list *head, struct view *view,
enum lab_view_criteria criteria); enum lab_view_criteria criteria);
struct view *view_prev(struct wl_list *head, struct view *view,
enum lab_view_criteria criteria);
/** /**
* view_array_append() - Append views that match criteria to array * view_array_append() - Append views that match criteria to array
* @server: server context * @server: server context

View file

@ -106,18 +106,6 @@ desktop_focus_view_or_surface(struct seat *seat, struct view *view,
} }
} }
static struct wl_list *
get_prev_item(struct wl_list *item)
{
return item->prev;
}
static struct wl_list *
get_next_item(struct wl_list *item)
{
return item->next;
}
static struct view * static struct view *
first_view(struct server *server) first_view(struct server *server)
{ {
@ -167,48 +155,52 @@ desktop_cycle_view(struct server *server, struct view *start_view,
* - Otherwise select the view second from the top * - Otherwise select the view second from the top
*/ */
int views = wl_list_length(&server->views);
/* Make sure to have all nodes in their actual ordering */ /* Make sure to have all nodes in their actual ordering */
osd_preview_restore(server); osd_preview_restore(server);
if (!start_view) { if (!start_view) {
start_view = first_view(server); struct view *view1;
if (!start_view || start_view != server->active_view) { enum lab_view_criteria criteria1 = LAB_VIEW_CRITERIA_NO_SKIP_WINDOW_SWITCHER;
for_each_view(view1, &server->views, criteria1) {
if (view_is_focusable(view1)) {
if (server->workspace_current != view1->workspace) {
workspaces_switch_to(view1->workspace, true);
}
start_view = view1;
break;
}
}
if (!start_view || views < 2) {
return start_view; /* may be NULL */ return start_view; /* may be NULL */
} }
} }
struct view *view = start_view; struct view *(*iter)(struct wl_list *head, struct view *view,
struct wlr_scene_node *node = &view->scene_tree->node; enum lab_view_criteria criteria);
iter = dir == LAB_CYCLE_DIR_FORWARD ? view_next : view_prev;
assert(node->parent); /*
struct wl_list *list_head = &node->parent->children; * TODO: These criteria are the same as in display_osd() in osd.c
struct wl_list *list_item = &node->link; * for the time being.
struct wl_list *(*iter)(struct wl_list *list); *
* A future improvement could be to make this configurable for example
/* Scene nodes are ordered like last node == displayed topmost */ * in rc.xml and then use rc.cycle_view_criteria (or whatever) both
iter = dir == LAB_CYCLE_DIR_FORWARD ? get_prev_item : get_next_item; * here and in the osd.c window-switcher code
*/
do { enum lab_view_criteria criteria = LAB_VIEW_CRITERIA_NO_SKIP_WINDOW_SWITCHER;
list_item = iter(list_item); if (views < 2) {
if (list_item == list_head) { return start_view;
/* Start / End of list reached. Roll over */ }
list_item = iter(list_item); struct view *view;
} for_each_view_iter(view, &start_view->link, iter, criteria) {
node = wl_container_of(list_item, node, link); if (view_is_focusable(view)) {
if (!node->data) {
/* We found some non-view, most likely the region overlay */
view = NULL;
continue;
}
view = node_view_from_node(node);
enum property skip = window_rules_get_property(view, "skipWindowSwitcher");
if (view_is_focusable(view) && skip != LAB_PROP_TRUE) {
return view; return view;
} }
} while (view != start_view); }
/* No focusable views found, including the one we started with */ /* No focusable views found, including the one we started with */
return NULL; return start_view;
} }
struct view * struct view *

View file

@ -409,9 +409,7 @@ display_osd(struct output *output)
struct wl_array views; struct wl_array views;
wl_array_init(&views); wl_array_init(&views);
view_array_append(server, &views, view_array_append(server, &views,
LAB_VIEW_CRITERIA_CURRENT_WORKSPACE LAB_VIEW_CRITERIA_NO_SKIP_WINDOW_SWITCHER);
| LAB_VIEW_CRITERIA_NO_ALWAYS_ON_TOP
| LAB_VIEW_CRITERIA_NO_SKIP_WINDOW_SWITCHER);
float scale = output->wlr_output->scale; float scale = output->wlr_output->scale;
int w = theme->osd_window_switcher_width; int w = theme->osd_window_switcher_width;

View file

@ -136,6 +136,22 @@ view_next(struct wl_list *head, struct view *view, enum lab_view_criteria criter
return NULL; return NULL;
} }
struct view *
view_prev(struct wl_list *head, struct view *view, enum lab_view_criteria criteria)
{
assert(head);
struct wl_list *elm = view ? &view->link : head;
for (elm = elm->prev; elm != head; elm = elm->prev) {
view = wl_container_of(elm, view, link);
if (matches_criteria(view, criteria)) {
return view;
}
}
return NULL;
}
void void
view_array_append(struct server *server, struct wl_array *views, view_array_append(struct server *server, struct wl_array *views,
enum lab_view_criteria criteria) enum lab_view_criteria criteria)