2017-09-23 21:48:13 +00:00
|
|
|
#include <assert.h>
|
2017-09-23 15:13:18 +00:00
|
|
|
#include <stdlib.h>
|
2017-09-23 21:48:13 +00:00
|
|
|
#include <stdbool.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"
|
|
|
|
#include "rootston/server.h"
|
2017-09-23 22:18:19 +00:00
|
|
|
#include "rootston/input.h"
|
2017-09-23 15:13:18 +00:00
|
|
|
|
2017-09-23 21:48:13 +00:00
|
|
|
static void get_input_bounds(struct roots_view *view, struct wlr_box *box) {
|
|
|
|
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
|
|
|
|
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
|
|
|
|
memcpy(box, surf->geometry, sizeof(struct wlr_box));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void activate(struct roots_view *view, bool active) {
|
|
|
|
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
|
|
|
|
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
|
|
|
|
if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
|
|
|
wlr_xdg_toplevel_v6_set_activated(surf, active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
struct roots_view *view = roots_xdg_surface->view;
|
|
|
|
struct roots_input *input = view->desktop->server->input;
|
|
|
|
struct wlr_xdg_toplevel_v6_move_event *e = data;
|
2017-09-28 23:48:55 +00:00
|
|
|
const struct roots_input_event *event = get_input_event(input, e->serial);
|
2017-09-23 22:18:19 +00:00
|
|
|
if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-28 23:48:55 +00:00
|
|
|
view_begin_move(input, event->cursor, view);
|
2017-09-23 22:18:19 +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);
|
|
|
|
wl_list_remove(&roots_xdg_surface->destroy.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->ping_timeout.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_show_window_menu.link);
|
|
|
|
wl_list_remove(&roots_xdg_surface->request_minimize.link);
|
|
|
|
view_destroy(roots_xdg_surface->view);
|
|
|
|
free(roots_xdg_surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
|
|
|
|
struct roots_desktop *desktop =
|
|
|
|
wl_container_of(listener, desktop, xdg_shell_v6_surface);
|
|
|
|
|
|
|
|
struct wlr_xdg_surface_v6 *surface = data;
|
|
|
|
wlr_log(L_DEBUG, "new xdg surface: title=%s, app_id=%s",
|
|
|
|
surface->title, surface->app_id);
|
|
|
|
wlr_xdg_surface_v6_ping(surface);
|
|
|
|
|
|
|
|
struct roots_xdg_surface_v6 *roots_surface =
|
|
|
|
calloc(1, sizeof(struct roots_xdg_surface_v6));
|
|
|
|
// TODO: all of the trimmings
|
|
|
|
wl_list_init(&roots_surface->destroy.link);
|
|
|
|
roots_surface->destroy.notify = handle_destroy;
|
|
|
|
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
|
|
|
|
wl_list_init(&roots_surface->ping_timeout.link);
|
|
|
|
wl_list_init(&roots_surface->request_minimize.link);
|
|
|
|
wl_list_init(&roots_surface->request_move.link);
|
2017-09-23 22:18:19 +00:00
|
|
|
roots_surface->request_move.notify = handle_request_move;
|
|
|
|
wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
|
2017-09-23 15:13:18 +00:00
|
|
|
wl_list_init(&roots_surface->request_resize.link);
|
|
|
|
wl_list_init(&roots_surface->request_show_window_menu.link);
|
|
|
|
|
|
|
|
struct roots_view *view = calloc(1, sizeof(struct roots_view));
|
|
|
|
view->type = ROOTS_XDG_SHELL_V6_VIEW;
|
|
|
|
view->x = view->y = 200;
|
|
|
|
view->xdg_surface_v6 = surface;
|
|
|
|
view->roots_xdg_surface_v6 = roots_surface;
|
|
|
|
view->wlr_surface = surface->surface;
|
2017-09-23 21:48:13 +00:00
|
|
|
view->get_input_bounds = get_input_bounds;
|
|
|
|
view->activate = activate;
|
2017-09-23 22:18:19 +00:00
|
|
|
view->desktop = desktop;
|
2017-09-23 15:13:18 +00:00
|
|
|
roots_surface->view = view;
|
2017-09-28 23:48:55 +00:00
|
|
|
list_add(desktop->views, view);
|
2017-09-23 15:13:18 +00:00
|
|
|
}
|