2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2020-09-28 20:53:59 +01:00
|
|
|
#include <assert.h>
|
2022-09-16 18:41:02 -04:00
|
|
|
#include "common/mem.h"
|
2023-03-22 19:56:59 +00:00
|
|
|
#include "decorations.h"
|
2019-12-26 21:37:31 +00:00
|
|
|
#include "labwc.h"
|
2022-03-02 21:07:04 +00:00
|
|
|
#include "node.h"
|
2022-11-21 10:10:39 -05:00
|
|
|
#include "view.h"
|
2023-02-05 19:29:24 +00:00
|
|
|
#include "view-impl-common.h"
|
2022-06-15 02:02:50 +02:00
|
|
|
#include "workspaces.h"
|
2019-12-26 21:37:31 +00:00
|
|
|
|
2023-02-28 11:30:42 -05:00
|
|
|
#define CONFIGURE_TIMEOUT_MS 100
|
|
|
|
|
|
2023-02-24 21:15:11 +00:00
|
|
|
static struct xdg_toplevel_view *
|
|
|
|
|
xdg_toplevel_view_from_view(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view->type == LAB_XDG_SHELL_VIEW);
|
|
|
|
|
return (struct xdg_toplevel_view *)view;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 13:41:12 -05:00
|
|
|
struct wlr_xdg_surface *
|
|
|
|
|
xdg_surface_from_view(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view->type == LAB_XDG_SHELL_VIEW);
|
|
|
|
|
struct xdg_toplevel_view *xdg_toplevel_view =
|
|
|
|
|
(struct xdg_toplevel_view *)view;
|
|
|
|
|
assert(xdg_toplevel_view->xdg_surface);
|
|
|
|
|
return xdg_toplevel_view->xdg_surface;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct wlr_xdg_toplevel *
|
|
|
|
|
xdg_toplevel_from_view(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
struct wlr_xdg_surface *xdg_surface = xdg_surface_from_view(view);
|
|
|
|
|
assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
|
|
|
|
|
assert(xdg_surface->toplevel);
|
|
|
|
|
return xdg_surface->toplevel;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-09 22:51:20 +00:00
|
|
|
static void
|
|
|
|
|
handle_new_xdg_popup(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2022-11-22 20:13:06 +00:00
|
|
|
struct xdg_toplevel_view *xdg_toplevel_view =
|
|
|
|
|
wl_container_of(listener, xdg_toplevel_view, new_popup);
|
|
|
|
|
struct view *view = &xdg_toplevel_view->base;
|
2021-01-09 22:51:20 +00:00
|
|
|
struct wlr_xdg_popup *wlr_popup = data;
|
|
|
|
|
xdg_popup_create(view, wlr_popup);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static bool
|
|
|
|
|
has_ssd(struct view *view)
|
2020-08-06 14:51:45 +01:00
|
|
|
{
|
2023-03-22 19:56:59 +00:00
|
|
|
/*
|
|
|
|
|
* view->ssd_preference may be set by the decoration implementation
|
|
|
|
|
* e.g. src/decorations/xdg-deco.c or src/decorations/kde-deco.c.
|
|
|
|
|
*/
|
2023-03-22 19:53:17 +01:00
|
|
|
switch (view->ssd_preference) {
|
|
|
|
|
case LAB_SSD_PREF_SERVER:
|
2023-03-20 22:36:35 +01:00
|
|
|
return true;
|
2023-03-22 19:53:17 +01:00
|
|
|
case LAB_SSD_PREF_CLIENT:
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
2023-03-20 22:36:35 +01:00
|
|
|
/*
|
2023-03-22 19:56:59 +00:00
|
|
|
* We don't know anything about the client preference
|
|
|
|
|
* so fall back to core.decoration settings in rc.xml
|
2023-03-20 22:36:35 +01:00
|
|
|
*/
|
2023-03-22 19:56:59 +00:00
|
|
|
return rc.xdg_shell_server_side_deco;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-08-06 14:51:45 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_commit(struct wl_listener *listener, void *data)
|
2020-08-31 08:12:44 +01:00
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, commit);
|
2022-11-25 13:41:12 -05:00
|
|
|
struct wlr_xdg_surface *xdg_surface = xdg_surface_from_view(view);
|
2020-09-28 20:53:59 +01:00
|
|
|
assert(view->surface);
|
2022-11-25 13:41:12 -05:00
|
|
|
|
2020-12-22 21:08:17 +00:00
|
|
|
struct wlr_box size;
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xdg_surface_get_geometry(xdg_surface, &size);
|
2020-12-22 21:08:17 +00:00
|
|
|
|
2023-02-08 23:19:14 -05:00
|
|
|
struct wlr_box *current = &view->current;
|
2023-02-25 12:05:22 -05:00
|
|
|
bool update_required = current->width != size.width
|
|
|
|
|
|| current->height != size.height;
|
2020-12-22 21:08:17 +00:00
|
|
|
|
2023-02-08 23:19:14 -05:00
|
|
|
uint32_t serial = view->pending_configure_serial;
|
2023-02-28 11:30:42 -05:00
|
|
|
if (serial > 0 && serial == xdg_surface->current.configure_serial) {
|
|
|
|
|
assert(view->pending_configure_timeout);
|
|
|
|
|
wl_event_source_remove(view->pending_configure_timeout);
|
|
|
|
|
view->pending_configure_serial = 0;
|
|
|
|
|
view->pending_configure_timeout = NULL;
|
2023-02-25 12:05:22 -05:00
|
|
|
update_required = true;
|
2020-12-22 21:08:17 +00:00
|
|
|
}
|
2023-02-28 11:30:42 -05:00
|
|
|
|
2022-09-08 00:55:57 +02:00
|
|
|
if (update_required) {
|
2023-02-25 12:05:22 -05:00
|
|
|
view_impl_apply_geometry(view, size.width, size.height);
|
2022-09-08 00:55:57 +02:00
|
|
|
}
|
2020-08-31 08:12:44 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-28 11:30:42 -05:00
|
|
|
static int
|
|
|
|
|
handle_configure_timeout(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct view *view = data;
|
|
|
|
|
assert(view->pending_configure_serial > 0);
|
|
|
|
|
assert(view->pending_configure_timeout);
|
|
|
|
|
|
|
|
|
|
const char *app_id = view_get_string_prop(view, "app_id");
|
2023-03-05 02:03:41 -05:00
|
|
|
wlr_log(WLR_INFO, "client (%s) did not respond to configure request "
|
2023-02-28 11:30:42 -05:00
|
|
|
"in %d ms", app_id, CONFIGURE_TIMEOUT_MS);
|
|
|
|
|
|
|
|
|
|
wl_event_source_remove(view->pending_configure_timeout);
|
|
|
|
|
view->pending_configure_serial = 0;
|
|
|
|
|
view->pending_configure_timeout = NULL;
|
|
|
|
|
|
|
|
|
|
view_impl_apply_geometry(view, view->current.width,
|
|
|
|
|
view->current.height);
|
|
|
|
|
|
|
|
|
|
return 0; /* ignored per wl_event_loop docs */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_pending_configure_serial(struct view *view, uint32_t serial)
|
|
|
|
|
{
|
|
|
|
|
view->pending_configure_serial = serial;
|
|
|
|
|
if (!view->pending_configure_timeout) {
|
|
|
|
|
view->pending_configure_timeout =
|
|
|
|
|
wl_event_loop_add_timer(view->server->wl_event_loop,
|
|
|
|
|
handle_configure_timeout, view);
|
|
|
|
|
}
|
|
|
|
|
wl_event_source_timer_update(view->pending_configure_timeout,
|
|
|
|
|
CONFIGURE_TIMEOUT_MS);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_map(struct wl_listener *listener, void *data)
|
2019-12-26 21:37:31 +00:00
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, map);
|
2020-09-03 20:50:35 +01:00
|
|
|
view->impl->map(view);
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_unmap(struct wl_listener *listener, void *data)
|
2019-12-26 21:37:31 +00:00
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, unmap);
|
2020-09-03 20:50:35 +01:00
|
|
|
view->impl->unmap(view);
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_destroy(struct wl_listener *listener, void *data)
|
2019-12-26 21:37:31 +00:00
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, destroy);
|
2022-04-23 03:44:41 +02:00
|
|
|
assert(view->type == LAB_XDG_SHELL_VIEW);
|
2023-02-24 21:15:11 +00:00
|
|
|
struct xdg_toplevel_view *xdg_toplevel_view =
|
|
|
|
|
xdg_toplevel_view_from_view(view);
|
|
|
|
|
|
|
|
|
|
xdg_toplevel_view->xdg_surface->data = NULL;
|
|
|
|
|
xdg_toplevel_view->xdg_surface = NULL;
|
|
|
|
|
|
2023-02-24 21:45:03 +00:00
|
|
|
/* Remove xdg-shell view specific listeners */
|
2023-02-24 21:15:11 +00:00
|
|
|
wl_list_remove(&xdg_toplevel_view->set_app_id.link);
|
|
|
|
|
wl_list_remove(&xdg_toplevel_view->new_popup.link);
|
2022-04-23 03:44:41 +02:00
|
|
|
|
2023-02-28 11:30:42 -05:00
|
|
|
if (view->pending_configure_timeout) {
|
|
|
|
|
wl_event_source_remove(view->pending_configure_timeout);
|
|
|
|
|
view->pending_configure_timeout = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-23 03:44:41 +02:00
|
|
|
view_destroy(view);
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_request_move(struct wl_listener *listener, void *data)
|
2019-12-26 21:37:31 +00:00
|
|
|
{
|
2021-09-21 22:05:56 +01:00
|
|
|
/*
|
|
|
|
|
* This event is raised when a client would like to begin an interactive
|
2019-12-26 21:37:31 +00:00
|
|
|
* move, typically because the user clicked on their client-side
|
2019-12-27 21:22:45 +00:00
|
|
|
* decorations. Note that a more sophisticated compositor should check
|
|
|
|
|
* the provied serial against a list of button press serials sent to
|
|
|
|
|
* this
|
|
|
|
|
* client, to prevent the client from requesting this whenever they
|
2021-09-21 22:05:56 +01:00
|
|
|
* want.
|
|
|
|
|
*/
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, request_move);
|
2020-10-21 20:30:06 +01:00
|
|
|
interactive_begin(view, LAB_INPUT_STATE_MOVE, 0);
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_request_resize(struct wl_listener *listener, void *data)
|
2019-12-26 21:37:31 +00:00
|
|
|
{
|
2021-09-21 22:05:56 +01:00
|
|
|
/*
|
|
|
|
|
* This event is raised when a client would like to begin an interactive
|
2019-12-26 21:37:31 +00:00
|
|
|
* resize, typically because the user clicked on their client-side
|
2019-12-27 21:22:45 +00:00
|
|
|
* decorations. Note that a more sophisticated compositor should check
|
|
|
|
|
* the provied serial against a list of button press serials sent to
|
|
|
|
|
* this
|
|
|
|
|
* client, to prevent the client from requesting this whenever they
|
2021-09-21 22:05:56 +01:00
|
|
|
* want.
|
|
|
|
|
*/
|
2019-12-26 21:37:31 +00:00
|
|
|
struct wlr_xdg_toplevel_resize_event *event = data;
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, request_resize);
|
2020-10-21 20:30:06 +01:00
|
|
|
interactive_begin(view, LAB_INPUT_STATE_RESIZE, event->edges);
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-31 02:44:25 +00:00
|
|
|
static void
|
|
|
|
|
handle_request_minimize(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, request_minimize);
|
2022-11-25 13:41:12 -05:00
|
|
|
view_minimize(view, xdg_toplevel_from_view(view)->requested.minimized);
|
2021-12-31 02:44:25 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-27 17:10:53 -05:00
|
|
|
static void
|
|
|
|
|
handle_request_maximize(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, request_maximize);
|
2023-02-03 14:45:04 -05:00
|
|
|
if (!view->mapped && !view->output) {
|
2023-02-28 11:46:48 -05:00
|
|
|
view_set_output(view, output_nearest_to_cursor(view->server));
|
2023-02-03 14:45:04 -05:00
|
|
|
}
|
2022-11-25 13:41:12 -05:00
|
|
|
view_maximize(view, xdg_toplevel_from_view(view)->requested.maximized,
|
2022-11-19 12:58:52 -05:00
|
|
|
/*store_natural_geometry*/ true);
|
2021-02-27 17:10:53 -05:00
|
|
|
}
|
|
|
|
|
|
2023-02-20 13:36:15 -05:00
|
|
|
static void
|
|
|
|
|
set_fullscreen_from_request(struct view *view,
|
|
|
|
|
struct wlr_xdg_toplevel_requested *requested)
|
|
|
|
|
{
|
|
|
|
|
if (!view->fullscreen && requested->fullscreen
|
|
|
|
|
&& requested->fullscreen_output) {
|
2023-02-28 11:46:48 -05:00
|
|
|
view_set_output(view, output_from_wlr_output(view->server,
|
|
|
|
|
requested->fullscreen_output));
|
2023-02-20 13:36:15 -05:00
|
|
|
}
|
|
|
|
|
view_set_fullscreen(view, requested->fullscreen);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 22:05:30 +01:00
|
|
|
static void
|
|
|
|
|
handle_request_fullscreen(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, request_fullscreen);
|
2023-02-03 14:45:04 -05:00
|
|
|
if (!view->mapped && !view->output) {
|
2023-02-28 11:46:48 -05:00
|
|
|
view_set_output(view, output_nearest_to_cursor(view->server));
|
2023-02-03 14:45:04 -05:00
|
|
|
}
|
2023-02-20 13:36:15 -05:00
|
|
|
set_fullscreen_from_request(view,
|
|
|
|
|
&xdg_toplevel_from_view(view)->requested);
|
2021-08-23 22:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-05 12:18:10 +01:00
|
|
|
static void
|
|
|
|
|
handle_set_title(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, set_title);
|
|
|
|
|
view_update_title(view);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-16 21:50:56 +01:00
|
|
|
static void
|
|
|
|
|
handle_set_app_id(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2022-11-22 20:13:06 +00:00
|
|
|
struct xdg_toplevel_view *xdg_toplevel_view =
|
|
|
|
|
wl_container_of(listener, xdg_toplevel_view, set_app_id);
|
|
|
|
|
struct view *view = &xdg_toplevel_view->base;
|
2021-10-16 21:50:56 +01:00
|
|
|
view_update_app_id(view);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
xdg_toplevel_view_configure(struct view *view, struct wlr_box geo)
|
2020-09-02 20:20:52 +01:00
|
|
|
{
|
2023-02-09 01:07:07 -05:00
|
|
|
uint32_t serial = 0;
|
2022-04-02 21:34:51 -04:00
|
|
|
view_adjust_size(view, &geo.width, &geo.height);
|
2020-12-22 21:08:17 +00:00
|
|
|
|
2023-02-09 01:07:07 -05:00
|
|
|
/*
|
|
|
|
|
* We do not need to send a configure request unless the size
|
|
|
|
|
* changed (wayland has no notion of a global position). If the
|
|
|
|
|
* size is the same (and there is no pending configure request)
|
|
|
|
|
* then we can just move the view directly.
|
|
|
|
|
*/
|
|
|
|
|
if (geo.width != view->pending.width
|
|
|
|
|
|| geo.height != view->pending.height) {
|
|
|
|
|
serial = wlr_xdg_toplevel_set_size(xdg_toplevel_from_view(view),
|
|
|
|
|
geo.width, geo.height);
|
2023-02-12 07:38:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
view->pending = geo;
|
2020-12-22 21:08:17 +00:00
|
|
|
if (serial > 0) {
|
2023-02-28 11:30:42 -05:00
|
|
|
set_pending_configure_serial(view, serial);
|
2023-02-08 23:19:14 -05:00
|
|
|
} else if (view->pending_configure_serial == 0) {
|
2023-02-26 20:25:05 -05:00
|
|
|
/*
|
|
|
|
|
* We can't assume here that view->current is equal to
|
|
|
|
|
* view->pending because some clients (e.g. terminals)
|
|
|
|
|
* refuse to accept the exact size we requested. To
|
|
|
|
|
* account for the size difference and avoid visual
|
|
|
|
|
* glitches during resize, we apply the same position
|
|
|
|
|
* adjustments here as in handle_commit().
|
|
|
|
|
*/
|
|
|
|
|
view_impl_apply_geometry(view, view->current.width,
|
|
|
|
|
view->current.height);
|
2020-12-22 21:08:17 +00:00
|
|
|
}
|
2020-09-02 20:20:52 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
xdg_toplevel_view_close(struct view *view)
|
2020-09-02 21:00:28 +01:00
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xdg_toplevel_send_close(xdg_toplevel_from_view(view));
|
2020-09-02 21:00:28 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-12 21:23:46 +00:00
|
|
|
static void
|
|
|
|
|
xdg_toplevel_view_maximize(struct view *view, bool maximized)
|
2020-09-15 20:41:01 +01:00
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xdg_toplevel_set_maximized(xdg_toplevel_from_view(view), maximized);
|
2020-09-15 20:41:01 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-16 19:24:26 +01:00
|
|
|
static void
|
|
|
|
|
xdg_toplevel_view_set_activated(struct view *view, bool activated)
|
|
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xdg_toplevel_set_activated(xdg_toplevel_from_view(view), activated);
|
2021-10-16 19:24:26 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-23 22:05:30 +01:00
|
|
|
static void
|
|
|
|
|
xdg_toplevel_view_set_fullscreen(struct view *view, bool fullscreen)
|
|
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xdg_toplevel_set_fullscreen(xdg_toplevel_from_view(view),
|
|
|
|
|
fullscreen);
|
2020-09-25 20:22:18 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-20 14:30:45 +00:00
|
|
|
static struct view *
|
2022-11-25 13:41:12 -05:00
|
|
|
lookup_view_by_xdg_toplevel(struct server *server,
|
|
|
|
|
struct wlr_xdg_toplevel *xdg_toplevel)
|
2021-03-20 14:30:45 +00:00
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
struct view *view;
|
|
|
|
|
wl_list_for_each(view, &server->views, link) {
|
|
|
|
|
if (view->type != LAB_XDG_SHELL_VIEW) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (xdg_toplevel_from_view(view) == xdg_toplevel) {
|
|
|
|
|
return view;
|
2021-03-20 14:30:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
position_xdg_toplevel_view(struct view *view)
|
|
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
struct wlr_xdg_toplevel *parent_xdg_toplevel =
|
|
|
|
|
xdg_toplevel_from_view(view)->parent;
|
|
|
|
|
|
|
|
|
|
if (!parent_xdg_toplevel) {
|
2023-02-20 16:23:53 -05:00
|
|
|
view_center(view, NULL);
|
2021-03-20 14:30:45 +00:00
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* If child-toplevel-views, we center-align relative to their
|
|
|
|
|
* parents
|
|
|
|
|
*/
|
2022-11-25 13:41:12 -05:00
|
|
|
struct view *parent = lookup_view_by_xdg_toplevel(
|
|
|
|
|
view->server, parent_xdg_toplevel);
|
2021-03-20 14:30:45 +00:00
|
|
|
assert(parent);
|
2023-02-28 11:46:48 -05:00
|
|
|
view_set_output(view, parent->output);
|
2023-02-20 16:23:53 -05:00
|
|
|
view_center(view, &parent->pending);
|
2021-03-20 14:30:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 12:18:10 +01:00
|
|
|
static const char *
|
|
|
|
|
xdg_toplevel_view_get_string_prop(struct view *view, const char *prop)
|
|
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
struct wlr_xdg_toplevel *xdg_toplevel = xdg_toplevel_from_view(view);
|
2021-08-05 12:18:10 +01:00
|
|
|
if (!strcmp(prop, "title")) {
|
2022-11-25 13:41:12 -05:00
|
|
|
return xdg_toplevel->title;
|
2021-08-05 12:18:10 +01:00
|
|
|
}
|
2021-08-16 07:16:56 +01:00
|
|
|
if (!strcmp(prop, "app_id")) {
|
2022-11-25 13:41:12 -05:00
|
|
|
return xdg_toplevel->app_id;
|
2021-08-16 07:16:56 +01:00
|
|
|
}
|
|
|
|
|
return "";
|
2021-08-05 12:18:10 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
xdg_toplevel_view_map(struct view *view)
|
2020-09-03 20:50:35 +01:00
|
|
|
{
|
2022-02-23 01:32:07 +01:00
|
|
|
if (view->mapped) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-03 20:50:35 +01:00
|
|
|
view->mapped = true;
|
2023-02-03 14:45:04 -05:00
|
|
|
if (!view->output) {
|
2023-02-28 11:46:48 -05:00
|
|
|
view_set_output(view, output_nearest_to_cursor(view->server));
|
2023-02-03 14:45:04 -05:00
|
|
|
}
|
2022-11-25 13:41:12 -05:00
|
|
|
struct wlr_xdg_surface *xdg_surface = xdg_surface_from_view(view);
|
|
|
|
|
view->surface = xdg_surface->surface;
|
2022-02-23 01:32:07 +01:00
|
|
|
wlr_scene_node_set_enabled(&view->scene_tree->node, true);
|
2020-09-03 20:50:35 +01:00
|
|
|
if (!view->been_mapped) {
|
2022-01-29 10:44:15 -05:00
|
|
|
struct wlr_xdg_toplevel_requested *requested =
|
2022-11-25 13:41:12 -05:00
|
|
|
&xdg_toplevel_from_view(view)->requested;
|
2021-08-05 12:18:10 +01:00
|
|
|
foreign_toplevel_handle_create(view);
|
2022-11-16 16:46:52 -05:00
|
|
|
view_set_decorations(view, has_ssd(view));
|
2021-07-21 22:04:54 +01:00
|
|
|
|
2023-02-09 01:21:52 -05:00
|
|
|
/*
|
|
|
|
|
* Set initial "pending" dimensions (may be modified by
|
|
|
|
|
* view_set_fullscreen/view_maximize() below). "Current"
|
|
|
|
|
* dimensions remain zero until handle_commit().
|
|
|
|
|
*/
|
2023-02-09 16:06:07 -05:00
|
|
|
if (wlr_box_empty(&view->pending)) {
|
2023-02-20 17:30:17 -05:00
|
|
|
struct wlr_box size;
|
|
|
|
|
wlr_xdg_surface_get_geometry(xdg_surface, &size);
|
|
|
|
|
view->pending.width = size.width;
|
|
|
|
|
view->pending.height = size.height;
|
2023-02-09 16:06:07 -05:00
|
|
|
}
|
2023-02-09 01:21:52 -05:00
|
|
|
|
2023-02-18 00:55:42 -05:00
|
|
|
/*
|
|
|
|
|
* Set initial "pending" position for floating views.
|
|
|
|
|
* Do this before view_set_fullscreen/view_maximize() so
|
|
|
|
|
* that the position is saved with the natural geometry.
|
|
|
|
|
*
|
|
|
|
|
* FIXME: the natural geometry is not saved if either
|
|
|
|
|
* handle_request_fullscreen/handle_request_maximize()
|
|
|
|
|
* is called before map (try "foot --maximized").
|
|
|
|
|
*/
|
|
|
|
|
if (view_is_floating(view)) {
|
|
|
|
|
position_xdg_toplevel_view(view);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 10:44:15 -05:00
|
|
|
if (!view->fullscreen && requested->fullscreen) {
|
2023-02-20 13:36:15 -05:00
|
|
|
set_fullscreen_from_request(view, requested);
|
2022-01-29 10:44:15 -05:00
|
|
|
} else if (!view->maximized && requested->maximized) {
|
2022-11-19 12:58:52 -05:00
|
|
|
view_maximize(view, true,
|
|
|
|
|
/*store_natural_geometry*/ true);
|
2022-01-29 10:44:15 -05:00
|
|
|
}
|
|
|
|
|
|
2023-02-18 00:55:42 -05:00
|
|
|
/*
|
|
|
|
|
* Set initial "current" position directly before
|
|
|
|
|
* calling view_moved() to reduce flicker
|
|
|
|
|
*/
|
|
|
|
|
view->current.x = view->pending.x;
|
|
|
|
|
view->current.y = view->pending.y;
|
|
|
|
|
|
2022-09-04 22:47:54 -04:00
|
|
|
view_moved(view);
|
2021-07-09 21:43:27 +01:00
|
|
|
view->been_mapped = true;
|
2020-09-03 20:50:35 +01:00
|
|
|
}
|
2020-09-15 20:41:01 +01:00
|
|
|
|
2020-09-03 20:50:35 +01:00
|
|
|
view->commit.notify = handle_commit;
|
2022-11-25 13:41:12 -05:00
|
|
|
wl_signal_add(&xdg_surface->surface->events.commit, &view->commit);
|
2020-09-15 20:41:01 +01:00
|
|
|
|
2021-10-16 21:26:57 +01:00
|
|
|
view_impl_map(view);
|
2020-09-03 20:50:35 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
xdg_toplevel_view_unmap(struct view *view)
|
2020-09-03 20:50:35 +01:00
|
|
|
{
|
2021-12-11 23:24:44 +00:00
|
|
|
if (view->mapped) {
|
|
|
|
|
view->mapped = false;
|
2022-02-23 01:32:07 +01:00
|
|
|
wlr_scene_node_set_enabled(&view->scene_tree->node, false);
|
2021-12-11 23:24:44 +00:00
|
|
|
wl_list_remove(&view->commit.link);
|
|
|
|
|
desktop_focus_topmost_mapped_view(view->server);
|
|
|
|
|
}
|
2020-09-03 20:50:35 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-02 20:20:52 +01:00
|
|
|
static const struct view_impl xdg_toplevel_view_impl = {
|
|
|
|
|
.configure = xdg_toplevel_view_configure,
|
2020-09-03 20:50:35 +01:00
|
|
|
.close = xdg_toplevel_view_close,
|
2021-08-05 12:18:10 +01:00
|
|
|
.get_string_prop = xdg_toplevel_view_get_string_prop,
|
2020-09-03 20:50:35 +01:00
|
|
|
.map = xdg_toplevel_view_map,
|
2021-10-16 19:24:26 +01:00
|
|
|
.set_activated = xdg_toplevel_view_set_activated,
|
2021-08-23 22:05:30 +01:00
|
|
|
.set_fullscreen = xdg_toplevel_view_set_fullscreen,
|
2020-09-03 20:50:35 +01:00
|
|
|
.unmap = xdg_toplevel_view_unmap,
|
2021-03-12 21:23:46 +00:00
|
|
|
.maximize = xdg_toplevel_view_maximize,
|
2023-02-05 19:29:24 +00:00
|
|
|
.move_to_front = view_impl_move_to_front,
|
2023-03-25 16:38:43 +00:00
|
|
|
.move_to_back = view_impl_move_to_back,
|
2020-09-02 20:20:52 +01:00
|
|
|
};
|
|
|
|
|
|
2023-02-04 10:07:46 +01:00
|
|
|
void
|
|
|
|
|
xdg_activation_handle_request(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
const struct wlr_xdg_activation_v1_request_activate_event *event = data;
|
|
|
|
|
|
|
|
|
|
if (!wlr_surface_is_xdg_surface(event->surface)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
struct wlr_xdg_surface *xdg_surface =
|
|
|
|
|
wlr_xdg_surface_from_wlr_surface(event->surface);
|
|
|
|
|
struct view *view = xdg_surface ? xdg_surface->data : NULL;
|
|
|
|
|
|
|
|
|
|
if (!view) {
|
|
|
|
|
wlr_log(WLR_INFO, "Not activating surface - no view attached to surface");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!event->token->seat) {
|
|
|
|
|
wlr_log(WLR_INFO, "Denying focus request, seat wasn't supplied");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* We do not check for event->token->surface here because it may already
|
|
|
|
|
* be destroyed and thus being NULL. With wlroots 0.17 we can hook into
|
|
|
|
|
* the `new_token` signal, attach further information to the token and
|
|
|
|
|
* then react to that information here instead. For now we just check
|
|
|
|
|
* for the seat / serial being correct and then allow the request.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* TODO: This is the exact same code as used in foreign.c.
|
|
|
|
|
* Refactor it into a public helper function somewhere.
|
|
|
|
|
*/
|
|
|
|
|
wlr_log(WLR_DEBUG, "Activating surface");
|
|
|
|
|
if (view->workspace != view->server->workspace_current) {
|
|
|
|
|
workspaces_switch_to(view->workspace);
|
|
|
|
|
}
|
|
|
|
|
desktop_focus_and_activate_view(&view->server->seat, view);
|
|
|
|
|
desktop_move_to_front(view);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-11 23:12:45 +00:00
|
|
|
/*
|
|
|
|
|
* We use the following struct user_data pointers:
|
|
|
|
|
* - wlr_xdg_surface->data = view
|
|
|
|
|
* for the wlr_xdg_toplevel_decoration_v1 implementation
|
2022-06-05 15:17:35 +02:00
|
|
|
* - wlr_surface->data = scene_tree
|
2022-02-11 23:12:45 +00:00
|
|
|
* to help the popups find their parent nodes
|
|
|
|
|
*/
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
|
|
|
|
xdg_surface_new(struct wl_listener *listener, void *data)
|
2019-12-26 21:37:31 +00:00
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct server *server =
|
2019-12-26 21:37:31 +00:00
|
|
|
wl_container_of(listener, server, new_xdg_surface);
|
|
|
|
|
struct wlr_xdg_surface *xdg_surface = data;
|
2022-02-11 23:12:45 +00:00
|
|
|
|
|
|
|
|
/*
|
2022-02-20 13:14:10 +00:00
|
|
|
* We deal with popups in xdg-popup.c and layers.c as they have to be
|
|
|
|
|
* treated differently
|
2022-02-11 23:12:45 +00:00
|
|
|
*/
|
2022-02-20 13:14:10 +00:00
|
|
|
if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
2019-12-26 21:37:31 +00:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2022-02-11 23:12:45 +00:00
|
|
|
|
2020-10-08 19:58:47 +01:00
|
|
|
wlr_xdg_surface_ping(xdg_surface);
|
2019-12-26 21:37:31 +00:00
|
|
|
|
2022-11-22 20:13:06 +00:00
|
|
|
struct xdg_toplevel_view *xdg_toplevel_view = znew(*xdg_toplevel_view);
|
|
|
|
|
struct view *view = &xdg_toplevel_view->base;
|
|
|
|
|
|
2019-12-26 21:37:31 +00:00
|
|
|
view->server = server;
|
|
|
|
|
view->type = LAB_XDG_SHELL_VIEW;
|
2020-09-02 20:20:52 +01:00
|
|
|
view->impl = &xdg_toplevel_view_impl;
|
2022-11-25 13:41:12 -05:00
|
|
|
xdg_toplevel_view->xdg_surface = xdg_surface;
|
2019-12-26 21:37:31 +00:00
|
|
|
|
2022-06-15 02:02:50 +02:00
|
|
|
view->workspace = server->workspace_current;
|
|
|
|
|
view->scene_tree = wlr_scene_tree_create(view->workspace->tree);
|
2022-02-23 01:32:07 +01:00
|
|
|
wlr_scene_node_set_enabled(&view->scene_tree->node, false);
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2022-06-05 15:17:35 +02:00
|
|
|
struct wlr_scene_tree *tree = wlr_scene_xdg_surface_create(
|
2022-11-25 13:41:12 -05:00
|
|
|
view->scene_tree, xdg_surface);
|
2022-06-05 15:17:35 +02:00
|
|
|
if (!tree) {
|
2022-02-23 01:32:07 +01:00
|
|
|
/* TODO: might need further clean up */
|
2022-12-08 05:27:25 +00:00
|
|
|
wl_resource_post_no_memory(xdg_surface->resource);
|
|
|
|
|
free(xdg_toplevel_view);
|
2022-02-11 23:12:45 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2022-06-05 15:17:35 +02:00
|
|
|
view->scene_node = &tree->node;
|
2022-02-25 22:31:24 +00:00
|
|
|
node_descriptor_create(&view->scene_tree->node,
|
|
|
|
|
LAB_NODE_DESC_VIEW, view);
|
2022-02-11 23:12:45 +00:00
|
|
|
|
2023-03-24 20:21:21 +01:00
|
|
|
/*
|
|
|
|
|
* The xdg_toplevel_decoration and kde_server_decoration protocols
|
|
|
|
|
* expects clients to use client side decorations unless server side
|
|
|
|
|
* decorations are negotiated. So we default to client side ones here.
|
|
|
|
|
*
|
|
|
|
|
* TODO: We may want to assign the default based on a new rc.xml
|
|
|
|
|
* config option like "enforce-server" in the future.
|
|
|
|
|
*/
|
|
|
|
|
view->ssd_preference = LAB_SSD_PREF_CLIENT;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* xdg_toplevel_decoration and kde_server_decoration use this
|
|
|
|
|
* pointer to connect the view to a decoration object that may
|
|
|
|
|
* be created in the future.
|
|
|
|
|
*/
|
2021-10-20 16:02:45 +00:00
|
|
|
xdg_surface->data = view;
|
|
|
|
|
|
2023-03-22 19:56:59 +00:00
|
|
|
/*
|
|
|
|
|
* GTK4 initializes the decorations on the wl_surface before
|
|
|
|
|
* converting it into a xdg surface. This call takes care of
|
|
|
|
|
* connecting the view to an existing decoration. If there
|
|
|
|
|
* is no existing decoration object available for the
|
|
|
|
|
* wl_surface, this call is a no-op.
|
|
|
|
|
*/
|
|
|
|
|
kde_server_decoration_set_view(view, xdg_surface->surface);
|
|
|
|
|
|
2022-02-11 23:12:45 +00:00
|
|
|
/* In support of xdg popups */
|
2022-06-05 15:17:35 +02:00
|
|
|
xdg_surface->surface->data = tree;
|
2022-02-11 23:12:45 +00:00
|
|
|
|
2020-09-03 21:40:27 +01:00
|
|
|
view->map.notify = handle_map;
|
2019-12-26 21:37:31 +00:00
|
|
|
wl_signal_add(&xdg_surface->events.map, &view->map);
|
2020-09-03 21:40:27 +01:00
|
|
|
view->unmap.notify = handle_unmap;
|
2019-12-26 21:37:31 +00:00
|
|
|
wl_signal_add(&xdg_surface->events.unmap, &view->unmap);
|
2020-09-03 21:40:27 +01:00
|
|
|
view->destroy.notify = handle_destroy;
|
2019-12-26 21:37:31 +00:00
|
|
|
wl_signal_add(&xdg_surface->events.destroy, &view->destroy);
|
|
|
|
|
|
|
|
|
|
struct wlr_xdg_toplevel *toplevel = xdg_surface->toplevel;
|
2020-09-03 21:40:27 +01:00
|
|
|
view->request_move.notify = handle_request_move;
|
2019-12-26 21:37:31 +00:00
|
|
|
wl_signal_add(&toplevel->events.request_move, &view->request_move);
|
2020-09-03 21:40:27 +01:00
|
|
|
view->request_resize.notify = handle_request_resize;
|
2019-12-26 21:37:31 +00:00
|
|
|
wl_signal_add(&toplevel->events.request_resize, &view->request_resize);
|
2021-12-31 02:44:25 +00:00
|
|
|
view->request_minimize.notify = handle_request_minimize;
|
|
|
|
|
wl_signal_add(&toplevel->events.request_minimize, &view->request_minimize);
|
2021-02-27 17:10:53 -05:00
|
|
|
view->request_maximize.notify = handle_request_maximize;
|
|
|
|
|
wl_signal_add(&toplevel->events.request_maximize, &view->request_maximize);
|
2021-08-23 22:05:30 +01:00
|
|
|
view->request_fullscreen.notify = handle_request_fullscreen;
|
2021-12-31 02:41:53 +00:00
|
|
|
wl_signal_add(&toplevel->events.request_fullscreen, &view->request_fullscreen);
|
2021-10-16 21:50:56 +01:00
|
|
|
|
2021-08-05 12:18:10 +01:00
|
|
|
view->set_title.notify = handle_set_title;
|
|
|
|
|
wl_signal_add(&toplevel->events.set_title, &view->set_title);
|
2021-02-27 17:10:53 -05:00
|
|
|
|
2022-11-22 20:13:06 +00:00
|
|
|
/* Events specific to XDG toplevel views */
|
|
|
|
|
xdg_toplevel_view->set_app_id.notify = handle_set_app_id;
|
|
|
|
|
wl_signal_add(&toplevel->events.set_app_id, &xdg_toplevel_view->set_app_id);
|
|
|
|
|
|
|
|
|
|
xdg_toplevel_view->new_popup.notify = handle_new_xdg_popup;
|
|
|
|
|
wl_signal_add(&xdg_surface->events.new_popup, &xdg_toplevel_view->new_popup);
|
2021-10-16 21:50:56 +01:00
|
|
|
|
2019-12-26 21:37:31 +00:00
|
|
|
wl_list_insert(&server->views, &view->link);
|
|
|
|
|
}
|