2019-12-26 21:37:31 +00:00
|
|
|
#include "labwc.h"
|
2020-08-12 19:37:44 +01:00
|
|
|
#include "common/log.h"
|
2020-08-31 08:12:44 +01:00
|
|
|
#include "common/bug-on.h"
|
2019-12-26 21:37:31 +00:00
|
|
|
|
2020-08-06 14:51:45 +01:00
|
|
|
static bool has_ssd(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
if (view->xwayland_surface->override_redirect)
|
|
|
|
|
return false;
|
|
|
|
|
if (view->xwayland_surface->decorations !=
|
|
|
|
|
WLR_XWAYLAND_SURFACE_DECORATIONS_ALL)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 08:12:44 +01:00
|
|
|
static void handle_commit(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, commit);
|
|
|
|
|
BUG_ON(!view->surface);
|
|
|
|
|
|
|
|
|
|
/* Must receive commit signal before accessing surface->current* */
|
|
|
|
|
view->w = view->surface->current.width;
|
|
|
|
|
view->h = view->surface->current.height;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 21:22:45 +00:00
|
|
|
void xwl_surface_map(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, map);
|
2019-12-26 21:37:31 +00:00
|
|
|
view->mapped = true;
|
|
|
|
|
view->x = view->xwayland_surface->x;
|
|
|
|
|
view->y = view->xwayland_surface->y;
|
|
|
|
|
view->surface = view->xwayland_surface->surface;
|
2020-08-06 14:51:45 +01:00
|
|
|
if (!view->been_mapped) {
|
|
|
|
|
view->show_server_side_deco = has_ssd(view);
|
2020-06-01 19:42:15 +01:00
|
|
|
view_init_position(view);
|
2020-08-06 14:51:45 +01:00
|
|
|
}
|
2020-05-12 22:24:18 +01:00
|
|
|
view->been_mapped = true;
|
2020-08-31 08:12:44 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Add commit listener here, because xwayland map/unmap can change
|
|
|
|
|
* the wlr_surface
|
|
|
|
|
*/
|
|
|
|
|
wl_signal_add(&view->xwayland_surface->surface->events.commit,
|
|
|
|
|
&view->commit);
|
|
|
|
|
view->commit.notify = handle_commit;
|
|
|
|
|
|
2020-05-16 12:18:00 +01:00
|
|
|
view_focus(view);
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-27 21:22:45 +00:00
|
|
|
void xwl_surface_unmap(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, unmap);
|
2019-12-26 21:37:31 +00:00
|
|
|
view->mapped = false;
|
2020-08-31 08:12:44 +01:00
|
|
|
wl_list_remove(&view->commit.link);
|
2020-05-18 20:54:25 +01:00
|
|
|
/*
|
|
|
|
|
* Note that if 'view' is not a toplevel view, the 'front' toplevel view
|
|
|
|
|
* will be focussed on; but if 'view' is a toplevel view, the 'next'
|
|
|
|
|
* will be focussed on.
|
|
|
|
|
*/
|
|
|
|
|
view_focus(next_toplevel(view));
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-27 21:22:45 +00:00
|
|
|
void xwl_surface_destroy(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, destroy);
|
2019-12-26 21:37:31 +00:00
|
|
|
wl_list_remove(&view->link);
|
2020-08-19 20:52:27 +01:00
|
|
|
wl_list_remove(&view->map.link);
|
|
|
|
|
wl_list_remove(&view->unmap.link);
|
|
|
|
|
wl_list_remove(&view->destroy.link);
|
|
|
|
|
wl_list_remove(&view->request_configure.link);
|
2019-12-26 21:37:31 +00:00
|
|
|
free(view);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 21:22:45 +00:00
|
|
|
void xwl_surface_configure(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, request_configure);
|
2019-12-26 21:37:31 +00:00
|
|
|
struct wlr_xwayland_surface_configure_event *event = data;
|
2019-12-27 21:22:45 +00:00
|
|
|
wlr_xwayland_surface_configure(view->xwayland_surface, event->x,
|
|
|
|
|
event->y, event->width, event->height);
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-27 21:22:45 +00:00
|
|
|
void xwl_surface_new(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
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_xwayland_surface);
|
|
|
|
|
struct wlr_xwayland_surface *xwayland_surface = data;
|
|
|
|
|
wlr_xwayland_surface_ping(xwayland_surface);
|
|
|
|
|
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = calloc(1, sizeof(struct view));
|
2019-12-26 21:37:31 +00:00
|
|
|
view->server = server;
|
|
|
|
|
view->type = LAB_XWAYLAND_VIEW;
|
|
|
|
|
view->xwayland_surface = xwayland_surface;
|
|
|
|
|
|
|
|
|
|
view->map.notify = xwl_surface_map;
|
|
|
|
|
wl_signal_add(&xwayland_surface->events.map, &view->map);
|
|
|
|
|
view->unmap.notify = xwl_surface_unmap;
|
|
|
|
|
wl_signal_add(&xwayland_surface->events.unmap, &view->unmap);
|
|
|
|
|
view->destroy.notify = xwl_surface_destroy;
|
|
|
|
|
wl_signal_add(&xwayland_surface->events.destroy, &view->destroy);
|
|
|
|
|
view->request_configure.notify = xwl_surface_configure;
|
2019-12-27 21:22:45 +00:00
|
|
|
wl_signal_add(&xwayland_surface->events.request_configure,
|
|
|
|
|
&view->request_configure);
|
2019-12-26 21:37:31 +00:00
|
|
|
|
|
|
|
|
wl_list_insert(&server->views, &view->link);
|
|
|
|
|
}
|