2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2020-12-30 10:29:21 +00:00
|
|
|
#include "config.h"
|
2020-09-28 20:53:59 +01:00
|
|
|
#include <assert.h>
|
2020-09-11 20:48:28 +01:00
|
|
|
#include "labwc.h"
|
2021-07-12 16:44:30 +01:00
|
|
|
#include "layers.h"
|
2022-02-25 22:31:24 +00:00
|
|
|
#include "node-descriptor.h"
|
2021-03-21 20:54:55 +00:00
|
|
|
#include "ssd.h"
|
2020-09-11 20:48:28 +01:00
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
move_to_front(struct view *view)
|
2020-09-11 20:48:28 +01:00
|
|
|
{
|
|
|
|
|
wl_list_remove(&view->link);
|
|
|
|
|
wl_list_insert(&view->server->views, &view->link);
|
2022-02-18 00:07:37 +01:00
|
|
|
wlr_scene_node_raise_to_top(&view->scene_tree->node);
|
2020-09-11 20:48:28 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-30 10:29:21 +00:00
|
|
|
#if HAVE_XWAYLAND
|
2020-09-28 20:41:41 +01:00
|
|
|
static struct wlr_xwayland_surface *
|
|
|
|
|
top_parent_of(struct view *view)
|
2020-09-11 20:48:28 +01:00
|
|
|
{
|
|
|
|
|
struct wlr_xwayland_surface *s = view->xwayland_surface;
|
2020-09-28 20:41:41 +01:00
|
|
|
while (s->parent) {
|
2020-09-11 20:48:28 +01:00
|
|
|
s = s->parent;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-09-11 20:48:28 +01:00
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
move_xwayland_sub_views_to_front(struct view *parent)
|
2020-09-11 20:48:28 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!parent || parent->type != LAB_XWAYLAND_VIEW) {
|
2020-09-11 20:48:28 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-09-11 20:48:28 +01:00
|
|
|
struct view *view, *next;
|
|
|
|
|
wl_list_for_each_reverse_safe(view, next, &parent->server->views, link)
|
|
|
|
|
{
|
|
|
|
|
/* need to stop here, otherwise loops keeps going forever */
|
2020-09-28 20:41:41 +01:00
|
|
|
if (view == parent) {
|
2020-09-11 20:48:28 +01:00
|
|
|
break;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
if (view->type != LAB_XWAYLAND_VIEW) {
|
2020-09-11 20:48:28 +01:00
|
|
|
continue;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
if (!view->mapped && !view->minimized) {
|
2020-09-11 20:48:28 +01:00
|
|
|
continue;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
if (top_parent_of(view) != parent->xwayland_surface) {
|
2020-09-11 20:48:28 +01:00
|
|
|
continue;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-09-11 20:48:28 +01:00
|
|
|
move_to_front(view);
|
|
|
|
|
/* TODO: we should probably focus on these too here */
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-30 10:29:21 +00:00
|
|
|
#endif
|
2020-09-11 20:48:28 +01:00
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
2021-12-06 21:23:49 +00:00
|
|
|
desktop_move_to_front(struct view *view)
|
2021-10-16 19:44:54 +01:00
|
|
|
{
|
|
|
|
|
if (!view) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
move_to_front(view);
|
|
|
|
|
#if HAVE_XWAYLAND
|
|
|
|
|
move_xwayland_sub_views_to_front(view);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 21:23:49 +00:00
|
|
|
static void
|
|
|
|
|
wl_list_insert_tail(struct wl_list *list, struct wl_list *elm)
|
|
|
|
|
{
|
|
|
|
|
elm->prev = list->prev;
|
|
|
|
|
elm->next = list;
|
|
|
|
|
list->prev = elm;
|
|
|
|
|
elm->prev->next = elm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
desktop_move_to_back(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
if (!view) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
wl_list_remove(&view->link);
|
|
|
|
|
wl_list_insert_tail(&view->server->views, &view->link);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-16 19:44:54 +01:00
|
|
|
static void
|
|
|
|
|
deactivate_all_views(struct server *server)
|
|
|
|
|
{
|
|
|
|
|
struct view *view;
|
|
|
|
|
wl_list_for_each (view, &server->views, link) {
|
|
|
|
|
if (!view->mapped) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
view_set_activated(view, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
desktop_focus_and_activate_view(struct seat *seat, struct view *view)
|
2020-09-14 17:35:44 +01:00
|
|
|
{
|
2020-09-18 20:28:48 +01:00
|
|
|
if (!view) {
|
2020-10-08 20:22:52 +01:00
|
|
|
seat_focus_surface(seat, NULL);
|
2020-09-14 17:35:44 +01:00
|
|
|
return;
|
2020-09-18 20:28:48 +01:00
|
|
|
}
|
2021-12-31 02:58:34 +00:00
|
|
|
|
2022-01-02 15:53:05 +00:00
|
|
|
/*
|
|
|
|
|
* Guard against views with no mapped surfaces when handling
|
|
|
|
|
* 'request_activate' and 'request_minimize'.
|
|
|
|
|
* See notes by isfocusable()
|
|
|
|
|
*/
|
|
|
|
|
if (!view->surface) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input_inhibit_blocks_surface(seat, view->surface->resource)) {
|
2021-08-25 19:59:49 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2021-08-21 17:12:02 +01:00
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
if (view->minimized) {
|
2021-10-16 19:44:54 +01:00
|
|
|
/*
|
|
|
|
|
* Unminimizing will map the view which triggers a call to this
|
|
|
|
|
* function again.
|
|
|
|
|
*/
|
2021-08-05 13:00:34 +01:00
|
|
|
view_minimize(view, false);
|
2020-10-08 20:08:41 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-12-31 02:58:34 +00:00
|
|
|
|
2022-01-02 15:53:05 +00:00
|
|
|
if (!view->mapped) {
|
2021-10-16 19:44:54 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_surface *prev_surface;
|
|
|
|
|
prev_surface = seat->seat->keyboard_state.focused_surface;
|
|
|
|
|
|
|
|
|
|
/* Do not re-focus an already focused surface. */
|
|
|
|
|
if (prev_surface == view->surface) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deactivate_all_views(view->server);
|
|
|
|
|
view_set_activated(view, true);
|
|
|
|
|
seat_focus_surface(seat, view->surface);
|
2020-09-14 17:35:44 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-11 20:48:28 +01:00
|
|
|
/*
|
|
|
|
|
* Some xwayland apps produce unmapped surfaces on startup and also leave
|
2021-08-25 19:59:49 +01:00
|
|
|
* some unmapped surfaces kicking around on 'close' (for example leafpad's
|
2020-09-11 20:48:28 +01:00
|
|
|
* "about" dialogue). Whilst this is not normally a problem, we have to be
|
2020-09-14 17:35:44 +01:00
|
|
|
* careful when cycling between views. The only views we should focus are
|
2020-09-11 20:48:28 +01:00
|
|
|
* those that are already mapped and those that have been minimized.
|
|
|
|
|
*/
|
2021-08-16 07:16:56 +01:00
|
|
|
bool
|
2020-09-28 20:41:41 +01:00
|
|
|
isfocusable(struct view *view)
|
2020-09-11 20:48:28 +01:00
|
|
|
{
|
|
|
|
|
/* filter out those xwayland surfaces that have never been mapped */
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!view->surface) {
|
2020-09-11 20:48:28 +01:00
|
|
|
return false;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-09-11 20:48:28 +01:00
|
|
|
return (view->mapped || view->minimized);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static bool
|
|
|
|
|
has_focusable_view(struct wl_list *wl_list)
|
2020-09-11 20:48:28 +01:00
|
|
|
{
|
|
|
|
|
struct view *view;
|
|
|
|
|
wl_list_for_each (view, wl_list, link) {
|
2020-09-28 20:41:41 +01:00
|
|
|
if (isfocusable(view)) {
|
2020-09-11 20:48:28 +01:00
|
|
|
return true;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-09-11 20:48:28 +01:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static struct view *
|
|
|
|
|
first_view(struct server *server)
|
2020-09-11 20:48:28 +01:00
|
|
|
{
|
|
|
|
|
struct view *view;
|
|
|
|
|
view = wl_container_of(server->views.next, view, link);
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
struct view *
|
2021-12-26 23:29:01 +00:00
|
|
|
desktop_cycle_view(struct server *server, struct view *current,
|
|
|
|
|
enum lab_cycle_dir dir)
|
2020-09-11 20:48:28 +01:00
|
|
|
{
|
2020-10-31 14:46:33 +00:00
|
|
|
if (!has_focusable_view(&server->views)) {
|
2020-09-11 20:48:28 +01:00
|
|
|
return NULL;
|
2020-10-31 14:46:33 +00:00
|
|
|
}
|
2020-09-11 20:48:28 +01:00
|
|
|
|
|
|
|
|
struct view *view = current ? current : first_view(server);
|
2021-10-17 22:53:43 +00:00
|
|
|
if (dir == LAB_CYCLE_DIR_FORWARD) {
|
|
|
|
|
/* Replacement for wl_list_for_each_from() */
|
|
|
|
|
do {
|
|
|
|
|
view = wl_container_of(view->link.next, view, link);
|
|
|
|
|
} while (&view->link == &server->views || !isfocusable(view));
|
|
|
|
|
} else if (dir == LAB_CYCLE_DIR_BACKWARD) {
|
|
|
|
|
do {
|
|
|
|
|
view = wl_container_of(view->link.prev, view, link);
|
|
|
|
|
} while (&view->link == &server->views || !isfocusable(view));
|
|
|
|
|
}
|
2020-09-11 20:48:28 +01:00
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static bool
|
|
|
|
|
has_mapped_view(struct wl_list *wl_list)
|
2020-09-18 20:28:48 +01:00
|
|
|
{
|
|
|
|
|
struct view *view;
|
|
|
|
|
wl_list_for_each (view, wl_list, link) {
|
2020-09-28 20:41:41 +01:00
|
|
|
if (view->mapped) {
|
2020-09-18 20:28:48 +01:00
|
|
|
return true;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-09-18 20:28:48 +01:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-20 22:07:19 +01:00
|
|
|
static struct view *
|
2020-10-31 14:32:31 +00:00
|
|
|
topmost_mapped_view(struct server *server)
|
2020-09-18 20:28:48 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!has_mapped_view(&server->views)) {
|
2020-09-18 20:28:48 +01:00
|
|
|
return NULL;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-10-31 14:32:31 +00:00
|
|
|
|
|
|
|
|
/* start from tail of server->views */
|
|
|
|
|
struct view *view = wl_container_of(server->views.prev, view, link);
|
2020-09-18 20:28:48 +01:00
|
|
|
do {
|
|
|
|
|
view = wl_container_of(view->link.next, view, link);
|
|
|
|
|
} while (&view->link == &server->views || !view->mapped);
|
|
|
|
|
return view;
|
|
|
|
|
}
|
2020-10-31 14:32:31 +00:00
|
|
|
|
2021-09-19 22:20:54 +00:00
|
|
|
struct view *
|
2021-09-20 22:12:34 +01:00
|
|
|
desktop_focused_view(struct server *server)
|
2021-09-19 22:20:54 +00:00
|
|
|
{
|
|
|
|
|
struct seat *seat = &server->seat;
|
|
|
|
|
struct wlr_surface *focused_surface;
|
|
|
|
|
focused_surface = seat->seat->keyboard_state.focused_surface;
|
|
|
|
|
if (!focused_surface) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
struct view *view;
|
|
|
|
|
wl_list_for_each (view, &server->views, link) {
|
|
|
|
|
if (view->surface == focused_surface) {
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
2020-10-31 14:32:31 +00:00
|
|
|
desktop_focus_topmost_mapped_view(struct server *server)
|
2020-09-18 20:28:48 +01:00
|
|
|
{
|
2020-10-31 14:32:31 +00:00
|
|
|
struct view *view = topmost_mapped_view(server);
|
2021-10-16 19:44:54 +01:00
|
|
|
desktop_focus_and_activate_view(&server->seat, view);
|
2021-12-06 21:23:49 +00:00
|
|
|
desktop_move_to_front(view);
|
2020-09-18 20:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
struct view *
|
2022-02-18 00:07:37 +01:00
|
|
|
desktop_node_and_view_at(struct server *server, double lx, double ly,
|
|
|
|
|
struct wlr_scene_node **scene_node, double *sx, double *sy,
|
2022-01-29 17:52:16 +01:00
|
|
|
enum ssd_part_type *view_area)
|
2020-09-11 20:48:28 +01:00
|
|
|
{
|
2022-02-11 23:12:45 +00:00
|
|
|
struct wlr_scene_node *node =
|
|
|
|
|
wlr_scene_node_at(&server->scene->node, lx, ly, sx, sy);
|
2021-07-12 16:44:30 +01:00
|
|
|
|
2022-02-18 00:07:37 +01:00
|
|
|
*scene_node = node;
|
|
|
|
|
if (!node) {
|
2022-02-22 07:57:17 +01:00
|
|
|
*view_area = LAB_SSD_ROOT;
|
2021-07-19 07:06:36 +01:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2022-02-18 00:07:37 +01:00
|
|
|
if (node->type == WLR_SCENE_NODE_SURFACE) {
|
|
|
|
|
struct wlr_surface *surface =
|
|
|
|
|
wlr_scene_surface_from_node(node)->surface;
|
|
|
|
|
if (wlr_surface_is_layer_surface(surface)) {
|
|
|
|
|
*view_area = LAB_SSD_LAYER_SURFACE;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2022-02-22 07:57:17 +01:00
|
|
|
#if HAVE_XWAYLAND
|
|
|
|
|
if (node->parent == &server->unmanaged_tree->node) {
|
|
|
|
|
*view_area = LAB_SSD_UNMANAGED;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-02-18 00:07:37 +01:00
|
|
|
}
|
|
|
|
|
struct wlr_scene_node *osd = &server->osd_tree->node;
|
2022-02-19 02:05:38 +01:00
|
|
|
struct wlr_scene_node *menu = &server->menu_tree->node;
|
2022-02-25 22:31:24 +00:00
|
|
|
while (node) {
|
|
|
|
|
struct node_descriptor *desc = node->data;
|
|
|
|
|
if (desc) {
|
|
|
|
|
if (desc->type == LAB_NODE_DESC_VIEW) {
|
|
|
|
|
goto has_view_data;
|
|
|
|
|
}
|
|
|
|
|
if (desc->type == LAB_NODE_DESC_XDG_POPUP) {
|
|
|
|
|
goto has_view_data;
|
|
|
|
|
}
|
|
|
|
|
if (desc->type == LAB_NODE_DESC_LAYER_POPUP) {
|
|
|
|
|
/* FIXME: we shouldn't have to set *view_area */
|
2022-02-26 23:30:02 +00:00
|
|
|
*view_area = LAB_SSD_CLIENT;
|
2022-02-25 22:31:24 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-18 00:07:37 +01:00
|
|
|
if (node == osd) {
|
|
|
|
|
*view_area = LAB_SSD_OSD;
|
|
|
|
|
return NULL;
|
2022-02-19 02:05:38 +01:00
|
|
|
} else if (node == menu) {
|
|
|
|
|
*view_area = LAB_SSD_MENU;
|
|
|
|
|
return NULL;
|
2022-02-18 00:07:37 +01:00
|
|
|
}
|
2022-02-11 23:12:45 +00:00
|
|
|
node = node->parent;
|
2021-09-25 09:40:23 +01:00
|
|
|
}
|
2022-02-18 00:07:37 +01:00
|
|
|
if (!node) {
|
|
|
|
|
wlr_log(WLR_ERROR, "Unknown node detected");
|
|
|
|
|
}
|
2022-02-25 22:31:24 +00:00
|
|
|
*view_area = LAB_SSD_NONE;
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
has_view_data:
|
|
|
|
|
struct node_descriptor *desc = node->data;
|
|
|
|
|
struct view *view = desc->data;
|
2022-02-21 03:18:38 +01:00
|
|
|
*view_area = ssd_get_part_type(view, *scene_node);
|
2022-02-18 00:07:37 +01:00
|
|
|
return view;
|
2020-09-11 20:48:28 +01:00
|
|
|
}
|
2021-11-26 13:03:15 -05:00
|
|
|
|
|
|
|
|
struct view *
|
2021-11-26 19:27:50 +00:00
|
|
|
desktop_view_at_cursor(struct server *server)
|
|
|
|
|
{
|
2021-11-26 13:03:15 -05:00
|
|
|
double sx, sy;
|
2022-02-18 00:07:37 +01:00
|
|
|
struct wlr_scene_node *node;
|
2022-01-29 17:52:16 +01:00
|
|
|
enum ssd_part_type view_area = LAB_SSD_NONE;
|
2021-11-26 13:03:15 -05:00
|
|
|
|
2022-02-18 00:07:37 +01:00
|
|
|
return desktop_node_and_view_at(server,
|
2021-11-26 13:03:15 -05:00
|
|
|
server->seat.cursor->x, server->seat.cursor->y,
|
2022-02-18 00:07:37 +01:00
|
|
|
&node, &sx, &sy, &view_area);
|
2021-11-26 13:03:15 -05:00
|
|
|
}
|