2017-09-23 21:48:13 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
2018-02-12 20:29:23 +00:00
|
|
|
#include <stdlib.h>
|
2017-09-23 15:13:18 +00:00
|
|
|
#include <wayland-server.h>
|
2017-09-23 21:48:13 +00:00
|
|
|
#include <wlr/types/wlr_box.h>
|
2017-09-23 15:13:18 +00:00
|
|
|
#include <wlr/types/wlr_surface.h>
|
2017-09-23 21:48:13 +00:00
|
|
|
#include <wlr/types/wlr_xdg_shell_v6.h>
|
2017-09-23 15:13:18 +00:00
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include "rootston/desktop.h"
|
2017-09-23 22:18:19 +00:00
|
|
|
#include "rootston/input.h"
|
2018-02-12 20:29:23 +00:00
|
|
|
#include "rootston/server.h"
|
2017-09-23 15:13:18 +00:00
|
|
|
|
2019-02-23 13:18:32 +00:00
|
|
|
static const struct roots_view_child_interface popup_impl;
|
|
|
|
|
2018-01-21 20:06:37 +00:00
|
|
|
static void popup_destroy(struct roots_view_child *child) {
|
2019-02-23 13:18:32 +00:00
|
|
|
assert(child->impl == &popup_impl);
|
2018-01-21 20:06:37 +00:00
|
|
|
struct roots_xdg_popup_v6 *popup = (struct roots_xdg_popup_v6 *)child;
|
|
|
|
wl_list_remove(&popup->destroy.link);
|
|
|
|
wl_list_remove(&popup->new_popup.link);
|
2018-05-04 08:27:55 +00:00
|
|
|
wl_list_remove(&popup->map.link);
|
|
|
|
wl_list_remove(&popup->unmap.link);
|
2018-01-21 20:06:37 +00:00
|
|
|
free(popup);
|
|
|
|
}
|
|
|
|
|
2019-02-23 13:18:32 +00:00
|
|
|
static const struct roots_view_child_interface popup_impl = {
|
|
|
|
.destroy = popup_destroy,
|
|
|
|
};
|
|
|
|
|
2018-01-21 20:06:37 +00:00
|
|
|
static void popup_handle_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_popup_v6 *popup =
|
|
|
|
wl_container_of(listener, popup, destroy);
|
2019-02-23 13:18:32 +00:00
|
|
|
view_child_destroy(&popup->view_child);
|
2018-01-21 20:06:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 23:02:28 +00:00
|
|
|
static void popup_handle_map(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_popup_v6 *popup =
|
|
|
|
wl_container_of(listener, popup, map);
|
|
|
|
view_damage_whole(popup->view_child.view);
|
2018-07-29 17:02:00 +00:00
|
|
|
input_update_cursor_focus(popup->view_child.view->desktop->server->input);
|
2018-03-26 23:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void popup_handle_unmap(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_popup_v6 *popup =
|
|
|
|
wl_container_of(listener, popup, unmap);
|
|
|
|
view_damage_whole(popup->view_child.view);
|
|
|
|
}
|
|
|
|
|
2018-01-21 20:06:37 +00:00
|
|
|
static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view,
|
|
|
|
struct wlr_xdg_popup_v6 *wlr_popup);
|
|
|
|
|
|
|
|
static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_popup_v6 *popup =
|
|
|
|
wl_container_of(listener, popup, new_popup);
|
|
|
|
struct wlr_xdg_popup_v6 *wlr_popup = data;
|
|
|
|
popup_create(popup->view_child.view, wlr_popup);
|
|
|
|
}
|
|
|
|
|
2018-03-28 20:27:08 +00:00
|
|
|
static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) {
|
2018-03-28 20:55:16 +00:00
|
|
|
// get the output of the popup's positioner anchor point and convert it to
|
|
|
|
// the toplevel parent's coordinate system and then pass it to
|
|
|
|
// wlr_xdg_popup_v6_unconstrain_from_box
|
2018-03-29 02:26:56 +00:00
|
|
|
|
|
|
|
// TODO: unconstrain popups for rotated windows
|
|
|
|
if (popup->view_child.view->rotation != 0.0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-27 18:49:31 +00:00
|
|
|
struct roots_view *view = popup->view_child.view;
|
|
|
|
struct wlr_output_layout *layout = view->desktop->layout;
|
|
|
|
struct wlr_xdg_popup_v6 *wlr_popup = popup->wlr_popup;
|
2018-03-27 03:48:32 +00:00
|
|
|
|
2018-03-27 18:49:31 +00:00
|
|
|
int anchor_lx, anchor_ly;
|
|
|
|
wlr_xdg_popup_v6_get_anchor_point(wlr_popup, &anchor_lx, &anchor_ly);
|
2018-03-27 03:48:32 +00:00
|
|
|
|
2018-03-28 20:27:08 +00:00
|
|
|
int popup_lx, popup_ly;
|
|
|
|
wlr_xdg_popup_v6_get_toplevel_coords(wlr_popup, wlr_popup->geometry.x,
|
|
|
|
wlr_popup->geometry.y, &popup_lx, &popup_ly);
|
2018-12-05 09:01:25 +00:00
|
|
|
popup_lx += view->box.x;
|
|
|
|
popup_ly += view->box.y;
|
2018-03-27 18:49:31 +00:00
|
|
|
|
|
|
|
anchor_lx += popup_lx;
|
|
|
|
anchor_ly += popup_ly;
|
|
|
|
|
|
|
|
double dest_x = 0, dest_y = 0;
|
|
|
|
wlr_output_layout_closest_point(layout, NULL, anchor_lx, anchor_ly,
|
|
|
|
&dest_x, &dest_y);
|
2018-03-27 03:48:32 +00:00
|
|
|
|
|
|
|
struct wlr_output *output =
|
2018-03-27 18:49:31 +00:00
|
|
|
wlr_output_layout_output_at(layout, dest_x, dest_y);
|
2018-03-28 22:36:48 +00:00
|
|
|
if (output == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-27 03:48:32 +00:00
|
|
|
|
2019-03-11 10:21:18 +00:00
|
|
|
struct wlr_box *output_box =
|
|
|
|
wlr_output_layout_get_box(view->desktop->layout, output);
|
2018-03-27 18:49:31 +00:00
|
|
|
|
2018-03-29 00:51:25 +00:00
|
|
|
// the output box expressed in the coordinate system of the toplevel parent
|
|
|
|
// of the popup
|
2018-03-29 03:24:39 +00:00
|
|
|
struct wlr_box output_toplevel_sx_box = {
|
2019-03-11 10:21:18 +00:00
|
|
|
.x = output_box->x - view->box.x,
|
|
|
|
.y = output_box->y - view->box.y,
|
|
|
|
.width = output_box->width,
|
|
|
|
.height = output_box->height,
|
2018-03-28 20:27:08 +00:00
|
|
|
};
|
2018-03-27 21:16:08 +00:00
|
|
|
|
2018-03-29 03:24:39 +00:00
|
|
|
wlr_xdg_popup_v6_unconstrain_from_box(popup->wlr_popup, &output_toplevel_sx_box);
|
2018-03-27 18:49:31 +00:00
|
|
|
}
|
2018-03-27 03:48:32 +00:00
|
|
|
|
2018-03-27 18:49:31 +00:00
|
|
|
static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view,
|
|
|
|
struct wlr_xdg_popup_v6 *wlr_popup) {
|
|
|
|
struct roots_xdg_popup_v6 *popup =
|
|
|
|
calloc(1, sizeof(struct roots_xdg_popup_v6));
|
|
|
|
if (popup == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-01-21 20:06:37 +00:00
|
|
|
popup->wlr_popup = wlr_popup;
|
2019-02-23 13:18:32 +00:00
|
|
|
view_child_init(&popup->view_child, &popup_impl,
|
|
|
|
view, wlr_popup->base->surface);
|
2018-01-21 20:06:37 +00:00
|
|
|
popup->destroy.notify = popup_handle_destroy;
|
|
|
|
wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy);
|
2018-03-26 23:02:28 +00:00
|
|
|
popup->map.notify = popup_handle_map;
|
|
|
|
wl_signal_add(&wlr_popup->base->events.map, &popup->map);
|
|
|
|
popup->unmap.notify = popup_handle_unmap;
|
|
|
|
wl_signal_add(&wlr_popup->base->events.unmap, &popup->unmap);
|
2018-01-21 20:06:37 +00:00
|
|
|
popup->new_popup.notify = popup_handle_new_popup;
|
|
|
|
wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup);
|
2018-03-27 18:49:31 +00:00
|
|
|
|
|
|
|
popup_unconstrain(popup);
|
|
|
|
|
2018-01-21 20:06:37 +00:00
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-23 14:24:28 +00:00
|
|
|
static void get_size(struct roots_view *view, struct wlr_box *box) {
|
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
roots_xdg_surface_v6_from_view(view)->xdg_surface_v6;
|
2017-11-11 14:39:15 +00:00
|
|
|
|
2018-06-01 11:27:10 +00:00
|
|
|
struct wlr_box geo_box;
|
|
|
|
wlr_xdg_surface_v6_get_geometry(surface, &geo_box);
|
|
|
|
box->width = geo_box.width;
|
|
|
|
box->height = geo_box.height;
|
2017-09-30 12:02:09 +00:00
|
|
|
}
|
2017-09-23 21:48:13 +00:00
|
|
|
|
|
|
|
static void activate(struct roots_view *view, bool active) {
|
2019-02-23 14:24:28 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
roots_xdg_surface_v6_from_view(view)->xdg_surface_v6;
|
2017-11-05 09:22:42 +00:00
|
|
|
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
|
|
|
wlr_xdg_toplevel_v6_set_activated(surface, active);
|
2017-09-23 21:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 09:22:42 +00:00
|
|
|
static void apply_size_constraints(struct wlr_xdg_surface_v6 *surface,
|
2017-11-03 13:49:15 +00:00
|
|
|
uint32_t width, uint32_t height, uint32_t *dest_width,
|
|
|
|
uint32_t *dest_height) {
|
|
|
|
*dest_width = width;
|
|
|
|
*dest_height = height;
|
|
|
|
|
2018-03-13 21:09:44 +00:00
|
|
|
struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel->current;
|
2017-11-03 13:49:15 +00:00
|
|
|
if (width < state->min_width) {
|
|
|
|
*dest_width = state->min_width;
|
|
|
|
} else if (state->max_width > 0 &&
|
|
|
|
width > state->max_width) {
|
|
|
|
*dest_width = state->max_width;
|
|
|
|
}
|
|
|
|
if (height < state->min_height) {
|
|
|
|
*dest_height = state->min_height;
|
|
|
|
} else if (state->max_height > 0 &&
|
|
|
|
height > state->max_height) {
|
|
|
|
*dest_height = state->max_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 09:57:39 +00:00
|
|
|
static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
2019-02-23 14:24:28 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
roots_xdg_surface_v6_from_view(view)->xdg_surface_v6;
|
2017-11-05 09:22:42 +00:00
|
|
|
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
2017-11-03 13:49:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-05 09:22:42 +00:00
|
|
|
uint32_t constrained_width, constrained_height;
|
|
|
|
apply_size_constraints(surface, width, height, &constrained_width,
|
|
|
|
&constrained_height);
|
2017-11-03 13:49:15 +00:00
|
|
|
|
2017-11-05 09:22:42 +00:00
|
|
|
wlr_xdg_toplevel_v6_set_size(surface, constrained_width,
|
|
|
|
constrained_height);
|
2017-11-03 13:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void move_resize(struct roots_view *view, double x, double y,
|
|
|
|
uint32_t width, uint32_t height) {
|
2019-02-23 14:24:28 +00:00
|
|
|
struct roots_xdg_surface_v6 *roots_surface =
|
|
|
|
roots_xdg_surface_v6_from_view(view);
|
|
|
|
struct wlr_xdg_surface_v6 *surface = roots_surface->xdg_surface_v6;
|
2017-11-05 09:22:42 +00:00
|
|
|
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
2017-11-03 13:49:15 +00:00
|
|
|
return;
|
2017-09-30 09:57:39 +00:00
|
|
|
}
|
2017-11-03 13:49:15 +00:00
|
|
|
|
2018-12-05 09:01:25 +00:00
|
|
|
bool update_x = x != view->box.x;
|
|
|
|
bool update_y = y != view->box.y;
|
2017-11-03 13:49:15 +00:00
|
|
|
|
2017-11-05 09:22:42 +00:00
|
|
|
uint32_t constrained_width, constrained_height;
|
|
|
|
apply_size_constraints(surface, width, height, &constrained_width,
|
|
|
|
&constrained_height);
|
2017-11-03 13:49:15 +00:00
|
|
|
|
2017-11-18 08:09:23 +00:00
|
|
|
if (update_x) {
|
|
|
|
x = x + width - constrained_width;
|
|
|
|
}
|
|
|
|
if (update_y) {
|
|
|
|
y = y + height - constrained_height;
|
|
|
|
}
|
2017-11-03 13:49:15 +00:00
|
|
|
|
2017-11-20 11:05:21 +00:00
|
|
|
view->pending_move_resize.update_x = update_x;
|
|
|
|
view->pending_move_resize.update_y = update_y;
|
|
|
|
view->pending_move_resize.x = x;
|
|
|
|
view->pending_move_resize.y = y;
|
|
|
|
view->pending_move_resize.width = constrained_width;
|
|
|
|
view->pending_move_resize.height = constrained_height;
|
2017-11-03 13:49:15 +00:00
|
|
|
|
2017-11-18 08:13:31 +00:00
|
|
|
uint32_t serial = wlr_xdg_toplevel_v6_set_size(surface, constrained_width,
|
|
|
|
constrained_height);
|
|
|
|
if (serial > 0) {
|
2017-11-20 11:05:21 +00:00
|
|
|
roots_surface->pending_move_resize_configure_serial = serial;
|
2018-02-07 19:26:30 +00:00
|
|
|
} else if (roots_surface->pending_move_resize_configure_serial == 0) {
|
2018-01-18 11:25:39 +00:00
|
|
|
view_update_position(view, x, y);
|
2017-11-18 08:13:31 +00:00
|
|
|
}
|
2017-09-30 09:57:39 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 15:29:43 +00:00
|
|
|
static void maximize(struct roots_view *view, bool maximized) {
|
2019-02-23 14:24:28 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
roots_xdg_surface_v6_from_view(view)->xdg_surface_v6;
|
2017-11-05 15:29:43 +00:00
|
|
|
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_xdg_toplevel_v6_set_maximized(surface, maximized);
|
|
|
|
}
|
|
|
|
|
2017-11-20 16:27:36 +00:00
|
|
|
static void set_fullscreen(struct roots_view *view, bool fullscreen) {
|
2019-02-23 14:24:28 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
roots_xdg_surface_v6_from_view(view)->xdg_surface_v6;
|
2017-11-20 16:27:36 +00:00
|
|
|
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_xdg_toplevel_v6_set_fullscreen(surface, fullscreen);
|
|
|
|
}
|
|
|
|
|
2017-10-06 13:58:49 +00:00
|
|
|
static void close(struct roots_view *view) {
|
2019-02-23 14:24:28 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
roots_xdg_surface_v6_from_view(view)->xdg_surface_v6;
|
2018-03-24 19:10:15 +00:00
|
|
|
struct wlr_xdg_popup_v6 *popup = NULL;
|
|
|
|
wl_list_for_each(popup, &surface->popups, link) {
|
|
|
|
wlr_xdg_surface_v6_send_close(popup->base);
|
2017-10-06 13:58:49 +00:00
|
|
|
}
|
2018-03-24 19:10:15 +00:00
|
|
|
wlr_xdg_surface_v6_send_close(surface);
|
2017-10-06 13:58:49 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 13:59:57 +00:00
|
|
|
static void for_each_surface(struct roots_view *view,
|
|
|
|
wlr_surface_iterator_func_t iterator, void *user_data) {
|
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
roots_xdg_surface_v6_from_view(view)->xdg_surface_v6;
|
|
|
|
wlr_xdg_surface_v6_for_each_surface(surface, iterator, user_data);
|
|
|
|
}
|
|
|
|
|
2018-03-12 08:17:06 +00:00
|
|
|
static void destroy(struct roots_view *view) {
|
2019-02-23 14:24:28 +00:00
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
|
|
|
roots_xdg_surface_v6_from_view(view);
|
2018-03-12 08:17:06 +00:00
|
|
|
wl_list_remove(&roots_xdg_surface->surface_commit.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->destroy.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->new_popup.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->map.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->unmap.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->request_move.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->request_resize.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->request_maximize.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->request_fullscreen.link);
|
2018-08-25 19:46:55 +00:00
|
|
|
wl_list_remove(&roots_xdg_surface->set_title.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->set_app_id.link);
|
2018-03-12 08:17:06 +00:00
|
|
|
free(roots_xdg_surface);
|
|
|
|
}
|
|
|
|
|
2019-02-23 11:15:37 +00:00
|
|
|
static const struct roots_view_interface view_impl = {
|
|
|
|
.activate = activate,
|
|
|
|
.resize = resize,
|
|
|
|
.move_resize = move_resize,
|
|
|
|
.maximize = maximize,
|
|
|
|
.set_fullscreen = set_fullscreen,
|
|
|
|
.close = close,
|
2019-02-25 13:59:57 +00:00
|
|
|
.for_each_surface = for_each_surface,
|
2019-02-23 11:15:37 +00:00
|
|
|
.destroy = destroy,
|
|
|
|
};
|
|
|
|
|
2017-09-23 22:18:19 +00:00
|
|
|
static void handle_request_move(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
|
|
|
wl_container_of(listener, roots_xdg_surface, request_move);
|
2019-02-23 14:24:28 +00:00
|
|
|
struct roots_view *view = &roots_xdg_surface->view;
|
2017-09-23 22:18:19 +00:00
|
|
|
struct roots_input *input = view->desktop->server->input;
|
|
|
|
struct wlr_xdg_toplevel_v6_move_event *e = data;
|
2017-11-07 20:56:11 +00:00
|
|
|
struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat);
|
|
|
|
// TODO verify event serial
|
|
|
|
if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
|
2017-09-23 22:18:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-07 20:56:11 +00:00
|
|
|
roots_seat_begin_move(seat, view);
|
2017-09-23 22:18:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 08:39:06 +00:00
|
|
|
static void handle_request_resize(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
|
|
|
wl_container_of(listener, roots_xdg_surface, request_resize);
|
2019-02-23 14:24:28 +00:00
|
|
|
struct roots_view *view = &roots_xdg_surface->view;
|
2017-09-30 08:39:06 +00:00
|
|
|
struct roots_input *input = view->desktop->server->input;
|
|
|
|
struct wlr_xdg_toplevel_v6_resize_event *e = data;
|
2017-11-07 20:56:11 +00:00
|
|
|
// TODO verify event serial
|
|
|
|
struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat);
|
2017-11-08 13:35:27 +00:00
|
|
|
assert(seat);
|
2017-11-07 20:56:11 +00:00
|
|
|
if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
|
2017-09-30 08:39:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-07 20:56:11 +00:00
|
|
|
roots_seat_begin_resize(seat, view, e->edges);
|
2017-09-30 08:39:06 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 20:41:11 +00:00
|
|
|
static void handle_request_maximize(struct wl_listener *listener, void *data) {
|
2017-11-05 15:29:43 +00:00
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
2017-11-09 20:41:11 +00:00
|
|
|
wl_container_of(listener, roots_xdg_surface, request_maximize);
|
2019-02-23 14:24:28 +00:00
|
|
|
struct roots_view *view = &roots_xdg_surface->view;
|
|
|
|
struct wlr_xdg_surface_v6 *surface = roots_xdg_surface->xdg_surface_v6;
|
2017-11-05 15:29:43 +00:00
|
|
|
|
|
|
|
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-18 17:58:01 +00:00
|
|
|
view_maximize(view, surface->toplevel->client_pending.maximized);
|
2017-11-09 20:41:11 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 16:27:36 +00:00
|
|
|
static void handle_request_fullscreen(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
|
|
|
wl_container_of(listener, roots_xdg_surface, request_fullscreen);
|
2019-02-23 14:24:28 +00:00
|
|
|
struct roots_view *view = &roots_xdg_surface->view;
|
|
|
|
struct wlr_xdg_surface_v6 *surface = roots_xdg_surface->xdg_surface_v6;
|
2017-11-20 16:27:36 +00:00
|
|
|
struct wlr_xdg_toplevel_v6_set_fullscreen_event *e = data;
|
|
|
|
|
|
|
|
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
view_set_fullscreen(view, e->fullscreen, e->output);
|
|
|
|
}
|
|
|
|
|
2018-08-25 19:46:55 +00:00
|
|
|
static void handle_set_title(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
|
|
|
wl_container_of(listener, roots_xdg_surface, set_title);
|
2018-10-02 11:08:23 +00:00
|
|
|
|
2019-02-23 14:24:28 +00:00
|
|
|
view_set_title(&roots_xdg_surface->view,
|
|
|
|
roots_xdg_surface->xdg_surface_v6->toplevel->title);
|
2018-08-25 19:46:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_app_id(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
2018-10-02 11:08:23 +00:00
|
|
|
wl_container_of(listener, roots_xdg_surface, set_app_id);
|
|
|
|
|
2019-02-23 14:24:28 +00:00
|
|
|
view_set_app_id(&roots_xdg_surface->view,
|
|
|
|
roots_xdg_surface->xdg_surface_v6->toplevel->app_id);
|
2018-08-25 19:46:55 +00:00
|
|
|
}
|
|
|
|
|
2018-01-21 20:06:37 +00:00
|
|
|
static void handle_surface_commit(struct wl_listener *listener, void *data) {
|
2017-11-05 09:22:42 +00:00
|
|
|
struct roots_xdg_surface_v6 *roots_surface =
|
2018-01-21 20:06:37 +00:00
|
|
|
wl_container_of(listener, roots_surface, surface_commit);
|
2019-02-23 14:24:28 +00:00
|
|
|
struct roots_view *view = &roots_surface->view;
|
|
|
|
struct wlr_xdg_surface_v6 *surface = roots_surface->xdg_surface_v6;
|
2017-11-05 09:22:42 +00:00
|
|
|
|
2018-03-10 10:18:50 +00:00
|
|
|
if (!surface->mapped) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-20 00:04:35 +00:00
|
|
|
view_apply_damage(view);
|
|
|
|
|
2018-01-28 09:11:31 +00:00
|
|
|
struct wlr_box size;
|
|
|
|
get_size(view, &size);
|
|
|
|
view_update_size(view, size.width, size.height);
|
|
|
|
|
2017-11-20 11:05:21 +00:00
|
|
|
uint32_t pending_serial =
|
|
|
|
roots_surface->pending_move_resize_configure_serial;
|
|
|
|
if (pending_serial > 0 && pending_serial >= surface->configure_serial) {
|
2018-12-05 09:01:25 +00:00
|
|
|
double x = view->box.x;
|
|
|
|
double y = view->box.y;
|
2017-11-20 11:05:21 +00:00
|
|
|
if (view->pending_move_resize.update_x) {
|
2018-01-20 00:04:35 +00:00
|
|
|
x = view->pending_move_resize.x + view->pending_move_resize.width -
|
|
|
|
size.width;
|
2017-11-18 08:09:23 +00:00
|
|
|
}
|
2017-11-20 11:05:21 +00:00
|
|
|
if (view->pending_move_resize.update_y) {
|
2018-01-20 00:04:35 +00:00
|
|
|
y = view->pending_move_resize.y + view->pending_move_resize.height -
|
|
|
|
size.height;
|
2017-11-18 08:09:23 +00:00
|
|
|
}
|
2018-01-20 00:04:35 +00:00
|
|
|
view_update_position(view, x, y);
|
2017-11-19 21:55:44 +00:00
|
|
|
|
2017-11-20 11:05:21 +00:00
|
|
|
if (pending_serial == surface->configure_serial) {
|
|
|
|
roots_surface->pending_move_resize_configure_serial = 0;
|
2017-11-19 21:55:44 +00:00
|
|
|
}
|
2017-11-05 09:22:42 +00:00
|
|
|
}
|
2017-10-08 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
2018-01-21 20:06:37 +00:00
|
|
|
static void handle_new_popup(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
|
|
|
wl_container_of(listener, roots_xdg_surface, new_popup);
|
|
|
|
struct wlr_xdg_popup_v6 *wlr_popup = data;
|
2019-02-23 14:24:28 +00:00
|
|
|
popup_create(&roots_xdg_surface->view, wlr_popup);
|
2018-01-21 20:06:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 10:18:50 +00:00
|
|
|
static void handle_map(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
|
|
|
wl_container_of(listener, roots_xdg_surface, map);
|
2019-02-23 14:24:28 +00:00
|
|
|
struct roots_view *view = &roots_xdg_surface->view;
|
2018-03-10 10:18:50 +00:00
|
|
|
|
|
|
|
struct wlr_box box;
|
|
|
|
get_size(view, &box);
|
2018-12-05 09:01:25 +00:00
|
|
|
view->box.width = box.width;
|
|
|
|
view->box.height = box.height;
|
2018-03-10 10:18:50 +00:00
|
|
|
|
2019-02-23 14:24:28 +00:00
|
|
|
view_map(view, roots_xdg_surface->xdg_surface_v6->surface);
|
2018-03-10 10:18:50 +00:00
|
|
|
view_setup(view);
|
2018-10-02 11:08:23 +00:00
|
|
|
|
|
|
|
wlr_foreign_toplevel_handle_v1_set_title(view->toplevel_handle,
|
2019-02-23 14:24:28 +00:00
|
|
|
roots_xdg_surface->xdg_surface_v6->toplevel->title ?: "none");
|
2018-10-02 11:08:23 +00:00
|
|
|
wlr_foreign_toplevel_handle_v1_set_app_id(view->toplevel_handle,
|
2019-02-23 14:24:28 +00:00
|
|
|
roots_xdg_surface->xdg_surface_v6->toplevel->app_id ?: "none");
|
2018-03-10 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_unmap(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
|
|
|
wl_container_of(listener, roots_xdg_surface, unmap);
|
2019-02-23 14:24:28 +00:00
|
|
|
view_unmap(&roots_xdg_surface->view);
|
2018-03-10 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
2017-09-23 15:13:18 +00:00
|
|
|
static void handle_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
|
|
|
wl_container_of(listener, roots_xdg_surface, destroy);
|
2019-02-23 14:24:28 +00:00
|
|
|
view_destroy(&roots_xdg_surface->view);
|
2017-09-23 15:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
|
2017-10-02 13:15:21 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface = data;
|
|
|
|
assert(surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE);
|
|
|
|
|
|
|
|
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) {
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log(WLR_DEBUG, "new xdg popup");
|
2017-10-02 13:15:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-23 15:13:18 +00:00
|
|
|
struct roots_desktop *desktop =
|
|
|
|
wl_container_of(listener, desktop, xdg_shell_v6_surface);
|
|
|
|
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log(WLR_DEBUG, "new xdg toplevel: title=%s, app_id=%s",
|
2018-03-26 23:32:21 +00:00
|
|
|
surface->toplevel->title, surface->toplevel->app_id);
|
2017-09-23 15:13:18 +00:00
|
|
|
wlr_xdg_surface_v6_ping(surface);
|
|
|
|
|
|
|
|
struct roots_xdg_surface_v6 *roots_surface =
|
|
|
|
calloc(1, sizeof(struct roots_xdg_surface_v6));
|
2017-10-08 10:17:25 +00:00
|
|
|
if (!roots_surface) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-23 14:24:28 +00:00
|
|
|
|
|
|
|
view_init(&roots_surface->view, &view_impl, ROOTS_XDG_SHELL_V6_VIEW, desktop);
|
|
|
|
roots_surface->xdg_surface_v6 = surface;
|
|
|
|
|
2019-07-12 12:08:29 +00:00
|
|
|
view_maximize(&roots_surface->view, surface->toplevel->client_pending.maximized);
|
|
|
|
view_set_fullscreen(&roots_surface->view, surface->toplevel->client_pending.fullscreen,
|
|
|
|
surface->toplevel->client_pending.fullscreen_output);
|
|
|
|
|
2018-01-21 20:06:37 +00:00
|
|
|
roots_surface->surface_commit.notify = handle_surface_commit;
|
|
|
|
wl_signal_add(&surface->surface->events.commit,
|
|
|
|
&roots_surface->surface_commit);
|
2017-09-23 15:13:18 +00:00
|
|
|
roots_surface->destroy.notify = handle_destroy;
|
|
|
|
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
|
2018-03-10 10:18:50 +00:00
|
|
|
roots_surface->map.notify = handle_map;
|
|
|
|
wl_signal_add(&surface->events.map, &roots_surface->map);
|
|
|
|
roots_surface->unmap.notify = handle_unmap;
|
|
|
|
wl_signal_add(&surface->events.unmap, &roots_surface->unmap);
|
2017-09-23 22:18:19 +00:00
|
|
|
roots_surface->request_move.notify = handle_request_move;
|
2018-03-26 23:32:21 +00:00
|
|
|
wl_signal_add(&surface->toplevel->events.request_move,
|
|
|
|
&roots_surface->request_move);
|
2017-09-30 08:39:06 +00:00
|
|
|
roots_surface->request_resize.notify = handle_request_resize;
|
2018-03-26 23:32:21 +00:00
|
|
|
wl_signal_add(&surface->toplevel->events.request_resize,
|
2017-09-30 08:39:06 +00:00
|
|
|
&roots_surface->request_resize);
|
2017-11-09 20:41:11 +00:00
|
|
|
roots_surface->request_maximize.notify = handle_request_maximize;
|
2018-03-26 23:32:21 +00:00
|
|
|
wl_signal_add(&surface->toplevel->events.request_maximize,
|
2017-11-09 20:41:11 +00:00
|
|
|
&roots_surface->request_maximize);
|
2017-11-20 16:27:36 +00:00
|
|
|
roots_surface->request_fullscreen.notify = handle_request_fullscreen;
|
2018-03-26 23:32:21 +00:00
|
|
|
wl_signal_add(&surface->toplevel->events.request_fullscreen,
|
2017-11-20 16:27:36 +00:00
|
|
|
&roots_surface->request_fullscreen);
|
2018-08-25 19:46:55 +00:00
|
|
|
roots_surface->set_title.notify = handle_set_title;
|
2019-02-23 11:15:37 +00:00
|
|
|
wl_signal_add(&surface->toplevel->events.set_title,
|
|
|
|
&roots_surface->set_title);
|
2018-08-25 19:46:55 +00:00
|
|
|
roots_surface->set_app_id.notify = handle_set_app_id;
|
|
|
|
wl_signal_add(&surface->toplevel->events.set_app_id,
|
|
|
|
&roots_surface->set_app_id);
|
2018-01-21 20:06:37 +00:00
|
|
|
roots_surface->new_popup.notify = handle_new_popup;
|
|
|
|
wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup);
|
2019-02-23 14:24:28 +00:00
|
|
|
}
|
2017-09-23 15:13:18 +00:00
|
|
|
|
2019-02-23 14:24:28 +00:00
|
|
|
struct roots_xdg_surface_v6 *roots_xdg_surface_v6_from_view(
|
|
|
|
struct roots_view *view) {
|
|
|
|
assert(view->impl == &view_impl);
|
|
|
|
return (struct roots_xdg_surface_v6 *)view;
|
2017-09-23 15:13:18 +00:00
|
|
|
}
|