| 
									
										
										
										
											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>
 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:22:10 -04:00
										 |  |  | #include <wlr/types/wlr_seat.h>
 | 
					
						
							|  |  |  | #include <wlr/types/wlr_subcompositor.h>
 | 
					
						
							|  |  |  | #include <wlr/types/wlr_xdg_shell.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-05 08:43:56 +02:00
										 |  |  | #include "common/scene-helpers.h"
 | 
					
						
							| 
									
										
										
										
											2024-03-07 19:15:02 +00:00
										 |  |  | #include "common/surface-helpers.h"
 | 
					
						
							| 
									
										
										
										
											2022-09-18 05:40:52 +02:00
										 |  |  | #include "dnd.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-11 20:48:28 +01:00
										 |  |  | #include "labwc.h"
 | 
					
						
							| 
									
										
										
										
											2022-12-22 21:58:55 +00:00
										 |  |  | #include "layers.h"
 | 
					
						
							| 
									
										
										
										
											2022-03-02 21:07:04 +00:00
										 |  |  | #include "node.h"
 | 
					
						
							| 
									
										
										
										
											2024-04-10 17:39:31 -05:00
										 |  |  | #include "osd.h"
 | 
					
						
							| 
									
										
										
										
											2025-07-26 15:34:45 -04:00
										 |  |  | #include "output.h"
 | 
					
						
							| 
									
										
										
										
											2021-03-21 20:54:55 +00:00
										 |  |  | #include "ssd.h"
 | 
					
						
							| 
									
										
										
										
											2022-11-21 10:10:39 -05:00
										 |  |  | #include "view.h"
 | 
					
						
							| 
									
										
										
										
											2023-05-20 10:20:36 +01:00
										 |  |  | #include "window-rules.h"
 | 
					
						
							| 
									
										
										
										
											2022-06-15 02:02:50 +02:00
										 |  |  | #include "workspaces.h"
 | 
					
						
							| 
									
										
										
										
											2023-01-07 17:50:33 -05:00
										 |  |  | #include "xwayland.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-11 20:48:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-01 23:01:19 -04:00
										 |  |  | #if HAVE_XWAYLAND
 | 
					
						
							|  |  |  | #include <wlr/xwayland.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-30 20:02:24 +02:00
										 |  |  | void | 
					
						
							|  |  |  | desktop_arrange_all_views(struct server *server) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-02-15 12:52:57 -05:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Adjust window positions/sizes. Skip views with no size since | 
					
						
							|  |  |  | 	 * we can't do anything useful with them; they will presumably | 
					
						
							|  |  |  | 	 * be initialized with valid positions/sizes later. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * We do not simply check view->mapped/been_mapped here because | 
					
						
							|  |  |  | 	 * views can have maximized/fullscreen geometry applied while | 
					
						
							|  |  |  | 	 * still unmapped. We do want to adjust the geometry of those | 
					
						
							|  |  |  | 	 * views. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2022-06-30 20:02:24 +02:00
										 |  |  | 	struct view *view; | 
					
						
							|  |  |  | 	wl_list_for_each(view, &server->views, link) { | 
					
						
							| 
									
										
										
										
											2023-02-15 12:52:57 -05:00
										 |  |  | 		if (!wlr_box_empty(&view->pending)) { | 
					
						
							|  |  |  | 			view_adjust_for_layout_change(view); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-06-30 20:02:24 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-13 11:00:26 -04:00
										 |  |  | static void | 
					
						
							|  |  |  | set_or_offer_focus(struct view *view) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct seat *seat = &view->server->seat; | 
					
						
							|  |  |  | 	switch (view_wants_focus(view)) { | 
					
						
							|  |  |  | 	case VIEW_WANTS_FOCUS_ALWAYS: | 
					
						
							|  |  |  | 		if (view->surface != seat->seat->keyboard_state.focused_surface) { | 
					
						
							|  |  |  | 			seat_focus_surface(seat, view->surface); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case VIEW_WANTS_FOCUS_LIKELY: | 
					
						
							|  |  |  | 	case VIEW_WANTS_FOCUS_UNLIKELY: | 
					
						
							|  |  |  | 		view_offer_focus(view); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case VIEW_WANTS_FOCUS_NEVER: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-16 19:44:54 +01:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2023-09-27 18:37:28 -04:00
										 |  |  | desktop_focus_view(struct view *view, bool raise) | 
					
						
							| 
									
										
										
										
											2020-09-14 17:35:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-09-26 01:35:36 -04:00
										 |  |  | 	assert(view); | 
					
						
							| 
									
										
										
										
											2022-01-02 15:53:05 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Guard against views with no mapped surfaces when handling | 
					
						
							|  |  |  | 	 * 'request_activate' and 'request_minimize'. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2023-10-02 22:12:22 -04:00
										 |  |  | 	if (!view->surface) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-01-02 15:53:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-24 21:40:46 +09:00
										 |  |  | 	if (view->server->input_mode == LAB_INPUT_STATE_WINDOW_SWITCHER) { | 
					
						
							|  |  |  | 		wlr_log(WLR_DEBUG, "not focusing window while window switching"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2023-09-27 18:37:28 -04:00
										 |  |  | 		 * function again (with raise=true). | 
					
						
							| 
									
										
										
										
											2021-10-16 19:44:54 +01:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-02 22:12:22 -04:00
										 |  |  | 	if (!view->mapped) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-10-16 19:44:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-27 18:37:28 -04:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Switch workspace if necessary to make the view visible | 
					
						
							| 
									
										
										
										
											2023-10-14 23:42:56 +02:00
										 |  |  | 	 * (unnecessary for "always on {top,bottom}" views). | 
					
						
							| 
									
										
										
										
											2023-09-27 18:37:28 -04:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2023-10-14 23:42:56 +02:00
										 |  |  | 	if (!view_is_always_on_top(view) && !view_is_always_on_bottom(view)) { | 
					
						
							| 
									
										
										
										
											2023-09-27 18:37:28 -04:00
										 |  |  | 		workspaces_switch_to(view->workspace, /*update_focus*/ false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (raise) { | 
					
						
							|  |  |  | 		view_move_to_front(view); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-06-13 11:00:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * If any child/sibling of the view is a modal dialog, focus | 
					
						
							|  |  |  | 	 * the dialog instead. It does not need to be raised separately | 
					
						
							|  |  |  | 	 * since view_move_to_front() raises all sibling views together. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	struct view *dialog = view_get_modal_dialog(view); | 
					
						
							|  |  |  | 	set_or_offer_focus(dialog ? dialog : view); | 
					
						
							| 
									
										
										
										
											2020-09-14 17:35:44 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-01 23:01:19 -04:00
										 |  |  | /* TODO: focus layer-shell surfaces also? */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | desktop_focus_view_or_surface(struct seat *seat, struct view *view, | 
					
						
							|  |  |  | 		struct wlr_surface *surface, bool raise) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	assert(view || surface); | 
					
						
							|  |  |  | 	if (view) { | 
					
						
							|  |  |  | 		desktop_focus_view(view, raise); | 
					
						
							|  |  |  | #if HAVE_XWAYLAND
 | 
					
						
							| 
									
										
										
										
											2023-02-03 14:53:26 -05:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2023-11-01 23:01:19 -04:00
										 |  |  | 		struct wlr_xwayland_surface *xsurface = | 
					
						
							| 
									
										
										
										
											2023-02-03 14:53:26 -05:00
										 |  |  | 			wlr_xwayland_surface_try_from_wlr_surface(surface); | 
					
						
							| 
									
										
										
										
											2024-11-27 03:41:58 +01:00
										 |  |  | 		if (xsurface && wlr_xwayland_surface_override_redirect_wants_focus(xsurface)) { | 
					
						
							| 
									
										
										
										
											2023-11-01 23:01:19 -04:00
										 |  |  | 			seat_focus_surface(seat, surface); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-19 20:40:40 +01:00
										 |  |  | struct view * | 
					
						
							| 
									
										
										
										
											2023-09-23 11:51:47 -04:00
										 |  |  | desktop_topmost_focusable_view(struct server *server) | 
					
						
							| 
									
										
										
										
											2020-09-18 20:28:48 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-06-15 02:02:50 +02:00
										 |  |  | 	struct view *view; | 
					
						
							|  |  |  | 	struct wl_list *node_list; | 
					
						
							|  |  |  | 	struct wlr_scene_node *node; | 
					
						
							| 
									
										
										
										
											2024-07-25 21:56:05 +02:00
										 |  |  | 	node_list = &server->workspaces.current->tree->children; | 
					
						
							| 
									
										
										
										
											2022-06-15 02:02:50 +02:00
										 |  |  | 	wl_list_for_each_reverse(node, node_list, link) { | 
					
						
							| 
									
										
										
										
											2022-07-06 07:19:28 +02:00
										 |  |  | 		if (!node->data) { | 
					
						
							|  |  |  | 			/* We found some non-view, most likely the region overlay */ | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-06-15 02:02:50 +02:00
										 |  |  | 		view = node_view_from_node(node); | 
					
						
							| 
									
										
										
										
											2024-02-13 22:35:56 -05:00
										 |  |  | 		if (view->mapped && view_is_focusable(view)) { | 
					
						
							| 
									
										
										
										
											2022-06-15 02:02:50 +02:00
										 |  |  | 			return view; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-09-28 20:41:41 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-06-15 02:02:50 +02:00
										 |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2020-09-18 20:28:48 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-10-31 14:32:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-28 20:41:41 +01:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2023-09-23 11:51:47 -04:00
										 |  |  | desktop_focus_topmost_view(struct server *server) | 
					
						
							| 
									
										
										
										
											2020-09-18 20:28:48 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-09-23 11:51:47 -04:00
										 |  |  | 	struct view *view = desktop_topmost_focusable_view(server); | 
					
						
							| 
									
										
										
										
											2023-04-01 14:06:52 -04:00
										 |  |  | 	if (view) { | 
					
						
							| 
									
										
										
										
											2023-09-27 18:37:28 -04:00
										 |  |  | 		desktop_focus_view(view, /*raise*/ true); | 
					
						
							| 
									
										
										
										
											2023-09-26 01:35:36 -04:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * Defocus previous focused surface/view if no longer | 
					
						
							|  |  |  | 		 * focusable (e.g. unmapped or on a different workspace). | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		seat_focus_surface(&server->seat, NULL); | 
					
						
							| 
									
										
										
										
											2023-04-01 14:06:52 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-18 20:28:48 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-05 17:16:23 +01:00
										 |  |  | void | 
					
						
							|  |  |  | desktop_focus_output(struct output *output) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!output_is_usable(output) || output->server->input_mode | 
					
						
							|  |  |  | 			!= LAB_INPUT_STATE_PASSTHROUGH) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	struct view *view; | 
					
						
							|  |  |  | 	struct wlr_scene_node *node; | 
					
						
							|  |  |  | 	struct wlr_output_layout *layout = output->server->output_layout; | 
					
						
							|  |  |  | 	struct wl_list *list_head = | 
					
						
							| 
									
										
										
										
											2024-07-25 21:56:05 +02:00
										 |  |  | 		&output->server->workspaces.current->tree->children; | 
					
						
							| 
									
										
										
										
											2023-03-05 17:16:23 +01:00
										 |  |  | 	wl_list_for_each_reverse(node, list_head, link) { | 
					
						
							|  |  |  | 		if (!node->data) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		view = node_view_from_node(node); | 
					
						
							| 
									
										
										
										
											2023-09-25 22:42:06 -04:00
										 |  |  | 		if (!view_is_focusable(view)) { | 
					
						
							| 
									
										
										
										
											2023-03-05 17:16:23 +01:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (wlr_output_layout_intersects(layout, | 
					
						
							|  |  |  | 				output->wlr_output, &view->current)) { | 
					
						
							| 
									
										
										
										
											2023-09-27 18:37:28 -04:00
										 |  |  | 			desktop_focus_view(view, /*raise*/ false); | 
					
						
							| 
									
										
										
										
											2024-08-21 07:38:44 +03:00
										 |  |  | 			wlr_cursor_warp(view->server->seat.cursor, NULL, | 
					
						
							| 
									
										
										
										
											2023-03-05 17:16:23 +01:00
										 |  |  | 				view->current.x + view->current.width / 2, | 
					
						
							|  |  |  | 				view->current.y + view->current.height / 2); | 
					
						
							| 
									
										
										
										
											2024-08-21 07:38:44 +03:00
										 |  |  | 			cursor_update_focus(view->server); | 
					
						
							| 
									
										
										
										
											2023-03-05 17:16:23 +01:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* No view found on desired output */ | 
					
						
							|  |  |  | 	struct wlr_box layout_box; | 
					
						
							|  |  |  | 	wlr_output_layout_get_box(output->server->output_layout, | 
					
						
							|  |  |  | 		output->wlr_output, &layout_box); | 
					
						
							|  |  |  | 	wlr_cursor_warp(output->server->seat.cursor, NULL, | 
					
						
							|  |  |  | 		layout_box.x + output->usable_area.x + output->usable_area.width / 2, | 
					
						
							|  |  |  | 		layout_box.y + output->usable_area.y + output->usable_area.height / 2); | 
					
						
							|  |  |  | 	cursor_update_focus(output->server); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-10 23:58:25 +01:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2025-01-08 23:35:23 -04:00
										 |  |  | desktop_update_top_layer_visibility(struct server *server) | 
					
						
							| 
									
										
										
										
											2023-11-10 23:58:25 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct view *view; | 
					
						
							|  |  |  | 	struct output *output; | 
					
						
							|  |  |  | 	uint32_t top = ZWLR_LAYER_SHELL_V1_LAYER_TOP; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Enable all top layers */ | 
					
						
							|  |  |  | 	wl_list_for_each(output, &server->outputs, link) { | 
					
						
							|  |  |  | 		if (!output_is_usable(output)) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		wlr_scene_node_set_enabled(&output->layer_tree[top]->node, true); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-13 10:18:28 +09:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * And disable them again when there is a fullscreen view without | 
					
						
							|  |  |  | 	 * any views above it | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	uint64_t outputs_covered = 0; | 
					
						
							|  |  |  | 	for_each_view(view, &server->views, LAB_VIEW_CRITERIA_CURRENT_WORKSPACE) { | 
					
						
							| 
									
										
										
										
											2024-05-08 00:25:44 +02:00
										 |  |  | 		if (view->minimized) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2023-11-10 23:58:25 +01:00
										 |  |  | 		if (!output_is_usable(view->output)) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-05-13 10:18:28 +09:00
										 |  |  | 		if (view->fullscreen && !(view->outputs & outputs_covered)) { | 
					
						
							|  |  |  | 			wlr_scene_node_set_enabled( | 
					
						
							|  |  |  | 				&view->output->layer_tree[top]->node, false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		outputs_covered |= view->outputs; | 
					
						
							| 
									
										
										
										
											2023-11-10 23:58:25 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-22 21:58:55 +00:00
										 |  |  | static struct wlr_surface * | 
					
						
							|  |  |  | get_surface_from_layer_node(struct wlr_scene_node *node) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	assert(node->data); | 
					
						
							|  |  |  | 	struct node_descriptor *desc = (struct node_descriptor *)node->data; | 
					
						
							|  |  |  | 	if (desc->type == LAB_NODE_DESC_LAYER_SURFACE) { | 
					
						
							|  |  |  | 		struct lab_layer_surface *surface; | 
					
						
							|  |  |  | 		surface = node_layer_surface_from_node(node); | 
					
						
							|  |  |  | 		return surface->scene_layer_surface->layer_surface->surface; | 
					
						
							|  |  |  | 	} else if (desc->type == LAB_NODE_DESC_LAYER_POPUP) { | 
					
						
							|  |  |  | 		struct lab_layer_popup *popup; | 
					
						
							|  |  |  | 		popup = node_layer_popup_from_node(node); | 
					
						
							|  |  |  | 		return popup->wlr_popup->base->surface; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | /* TODO: make this less big and scary */ | 
					
						
							|  |  |  | struct cursor_context | 
					
						
							|  |  |  | get_cursor_context(struct server *server) | 
					
						
							| 
									
										
										
										
											2020-09-11 20:48:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 	struct cursor_context ret = {.type = LAB_SSD_NONE}; | 
					
						
							|  |  |  | 	struct wlr_cursor *cursor = server->seat.cursor; | 
					
						
							| 
									
										
										
										
											2022-09-18 05:40:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Prevent drag icons to be on top of the hitbox detection */ | 
					
						
							|  |  |  | 	if (server->seat.drag.active) { | 
					
						
							|  |  |  | 		dnd_icons_show(&server->seat, false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-11 23:12:45 +00:00
										 |  |  | 	struct wlr_scene_node *node = | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 		wlr_scene_node_at(&server->scene->tree.node, | 
					
						
							|  |  |  | 			cursor->x, cursor->y, &ret.sx, &ret.sy); | 
					
						
							| 
									
										
										
										
											2021-07-12 16:44:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-18 05:40:52 +02:00
										 |  |  | 	if (server->seat.drag.active) { | 
					
						
							|  |  |  | 		dnd_icons_show(&server->seat, true); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 	ret.node = node; | 
					
						
							| 
									
										
										
										
											2022-02-18 00:07:37 +01:00
										 |  |  | 	if (!node) { | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 		ret.type = LAB_SSD_ROOT; | 
					
						
							|  |  |  | 		return ret; | 
					
						
							| 
									
										
										
										
											2021-07-19 07:06:36 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-01-28 22:34:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-22 21:58:55 +00:00
										 |  |  | #if HAVE_XWAYLAND
 | 
					
						
							| 
									
										
										
										
											2022-05-26 00:39:04 +02:00
										 |  |  | 	if (node->type == WLR_SCENE_NODE_BUFFER) { | 
					
						
							|  |  |  | 		struct wlr_surface *surface = lab_wlr_surface_from_node(node); | 
					
						
							| 
									
										
										
										
											2022-06-05 15:17:35 +02:00
										 |  |  | 		if (node->parent == server->unmanaged_tree) { | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 			ret.type = LAB_SSD_UNMANAGED; | 
					
						
							|  |  |  | 			ret.surface = surface; | 
					
						
							|  |  |  | 			return ret; | 
					
						
							| 
									
										
										
										
											2022-02-22 07:57:17 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-02-18 00:07:37 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-12-22 21:58:55 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2022-02-25 22:31:24 +00:00
										 |  |  | 	while (node) { | 
					
						
							|  |  |  | 		struct node_descriptor *desc = node->data; | 
					
						
							|  |  |  | 		if (desc) { | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 			switch (desc->type) { | 
					
						
							|  |  |  | 			case LAB_NODE_DESC_VIEW: | 
					
						
							|  |  |  | 			case LAB_NODE_DESC_XDG_POPUP: | 
					
						
							|  |  |  | 				ret.view = desc->data; | 
					
						
							| 
									
										
										
										
											2025-08-13 21:00:11 +09:00
										 |  |  | 				if (ret.node->type == WLR_SCENE_NODE_BUFFER | 
					
						
							|  |  |  | 						&& lab_wlr_surface_from_node(ret.node)) { | 
					
						
							|  |  |  | 					ret.type = LAB_SSD_CLIENT; | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 					ret.surface = lab_wlr_surface_from_node(ret.node); | 
					
						
							| 
									
										
										
										
											2025-08-13 21:00:11 +09:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					/* should never be reached */ | 
					
						
							|  |  |  | 					wlr_log(WLR_ERROR, "cursor not on client or ssd"); | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				return ret; | 
					
						
							| 
									
										
										
										
											2025-08-13 21:00:11 +09:00
										 |  |  | 			case LAB_NODE_DESC_SSD_PART: { | 
					
						
							|  |  |  | 				struct ssd_part *part = node_ssd_part_from_node(node); | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 				ret.node = node; | 
					
						
							| 
									
										
										
										
											2025-08-13 21:00:11 +09:00
										 |  |  | 				ret.view = ssd_part_get_view(part); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* Detect mouse contexts like Top, Left and TRCorner */ | 
					
						
							|  |  |  | 				ret.type = ssd_get_resizing_type(ret.view->ssd, cursor); | 
					
						
							|  |  |  | 				if (ret.type == LAB_SSD_NONE) { | 
					
						
							|  |  |  | 					/*
 | 
					
						
							|  |  |  | 					 * Otherwise, detect mouse contexts like | 
					
						
							|  |  |  | 					 * Title, Titlebar and Iconify | 
					
						
							|  |  |  | 					 */ | 
					
						
							|  |  |  | 					ret.type = ssd_part_get_type(part); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 				return ret; | 
					
						
							| 
									
										
										
										
											2022-06-08 14:37:30 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 			case LAB_NODE_DESC_LAYER_SURFACE: | 
					
						
							| 
									
										
										
										
											2022-12-22 21:58:55 +00:00
										 |  |  | 				ret.node = node; | 
					
						
							|  |  |  | 				ret.type = LAB_SSD_LAYER_SURFACE; | 
					
						
							|  |  |  | 				ret.surface = get_surface_from_layer_node(node); | 
					
						
							|  |  |  | 				return ret; | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 			case LAB_NODE_DESC_LAYER_POPUP: | 
					
						
							| 
									
										
										
										
											2022-12-22 21:58:55 +00:00
										 |  |  | 				ret.node = node; | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 				ret.type = LAB_SSD_CLIENT; | 
					
						
							| 
									
										
										
										
											2022-12-22 21:58:55 +00:00
										 |  |  | 				ret.surface = get_surface_from_layer_node(node); | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 				return ret; | 
					
						
							| 
									
										
										
										
											2024-05-30 00:53:52 +09:00
										 |  |  | 			case LAB_NODE_DESC_SESSION_LOCK_SURFACE: /* fallthrough */ | 
					
						
							| 
									
										
										
										
											2024-02-23 03:50:55 +09:00
										 |  |  | 			case LAB_NODE_DESC_IME_POPUP: | 
					
						
							|  |  |  | 				ret.type = LAB_SSD_CLIENT; | 
					
						
							|  |  |  | 				ret.surface = lab_wlr_surface_from_node(ret.node); | 
					
						
							|  |  |  | 				return ret; | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 			case LAB_NODE_DESC_MENUITEM: | 
					
						
							| 
									
										
										
										
											2022-03-03 04:33:33 +01:00
										 |  |  | 				/* Always return the top scene node for menu items */ | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 				ret.node = node; | 
					
						
							|  |  |  | 				ret.type = LAB_SSD_MENU; | 
					
						
							|  |  |  | 				return ret; | 
					
						
							|  |  |  | 			case LAB_NODE_DESC_NODE: | 
					
						
							|  |  |  | 			case LAB_NODE_DESC_TREE: | 
					
						
							| 
									
										
										
										
											2025-09-02 17:47:01 +09:00
										 |  |  | 			case LAB_NODE_DESC_SCALED_BUFFER: | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2022-03-03 04:33:33 +01:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2022-02-25 22:31:24 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-12-29 20:16:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Edge-case nodes without node-descriptors */ | 
					
						
							|  |  |  | 		if (node->type == WLR_SCENE_NODE_BUFFER) { | 
					
						
							|  |  |  | 			struct wlr_surface *surface = lab_wlr_surface_from_node(node); | 
					
						
							| 
									
										
										
										
											2024-03-07 19:15:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * Handle layer-shell subsurfaces | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * These don't have node-descriptors, but need to be | 
					
						
							|  |  |  | 			 * able to receive pointer actions so we have to process | 
					
						
							|  |  |  | 			 * them here. | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * Test by running `gtk-layer-demo -k exclusive`, then | 
					
						
							|  |  |  | 			 * open the 'set margin' dialog and try setting the | 
					
						
							|  |  |  | 			 * margin with the pointer. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			if (surface && wlr_subsurface_try_from_wlr_surface(surface) | 
					
						
							|  |  |  | 					&& subsurface_parent_layer(surface)) { | 
					
						
							|  |  |  | 				ret.surface = surface; | 
					
						
							|  |  |  | 				ret.type = LAB_SSD_LAYER_SUBSURFACE; | 
					
						
							|  |  |  | 				return ret; | 
					
						
							| 
									
										
										
										
											2022-12-29 20:16:32 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-05 15:17:35 +02:00
										 |  |  | 		/* node->parent is always a *wlr_scene_tree */ | 
					
						
							|  |  |  | 		node = node->parent ? &node->parent->node : NULL; | 
					
						
							| 
									
										
										
										
											2021-09-25 09:40:23 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-02 21:56:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * TODO: add node descriptors for the OSDs and reinstate | 
					
						
							|  |  |  | 	 *       wlr_log(WLR_DEBUG, "Unknown node detected"); | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2022-09-12 04:54:00 -04:00
										 |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2021-11-26 13:03:15 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-08-10 15:46:00 +01:00
										 |  |  | 
 |