2017-09-23 06:29:53 +02:00
|
|
|
#define _POSIX_C_SOURCE 199309L
|
2017-09-29 01:48:55 +02:00
|
|
|
#include <assert.h>
|
2017-09-23 06:29:53 +02:00
|
|
|
#include <time.h>
|
|
|
|
#include <stdlib.h>
|
2017-10-04 21:05:00 +02:00
|
|
|
#include <math.h>
|
2017-09-23 23:48:13 +02:00
|
|
|
#include <wlr/types/wlr_box.h>
|
2017-09-23 06:29:53 +02:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
2017-09-23 16:13:05 +02:00
|
|
|
#include <wlr/types/wlr_cursor.h>
|
|
|
|
#include <wlr/types/wlr_gamma_control.h>
|
2017-10-27 00:02:30 +02:00
|
|
|
#include <wlr/types/wlr_server_decoration.h>
|
2017-09-23 16:13:05 +02:00
|
|
|
#include <wlr/types/wlr_output_layout.h>
|
2017-09-23 06:29:53 +02:00
|
|
|
#include <wlr/types/wlr_wl_shell.h>
|
|
|
|
#include <wlr/types/wlr_xdg_shell_v6.h>
|
|
|
|
#include <wlr/util/log.h>
|
2017-10-27 00:02:30 +02:00
|
|
|
#include <server-decoration-protocol.h>
|
|
|
|
#include "rootston/server.h"
|
2017-11-07 21:56:11 +01:00
|
|
|
#include "rootston/seat.h"
|
2017-09-23 06:29:53 +02:00
|
|
|
|
2017-11-07 21:56:11 +01:00
|
|
|
// TODO replace me with a signal
|
2017-09-23 17:13:18 +02:00
|
|
|
void view_destroy(struct roots_view *view) {
|
2017-09-29 01:48:55 +02:00
|
|
|
struct roots_desktop *desktop = view->desktop;
|
2017-10-06 16:51:16 +02:00
|
|
|
|
|
|
|
struct roots_input *input = desktop->server->input;
|
2017-11-07 21:56:11 +01:00
|
|
|
struct roots_seat *seat;
|
|
|
|
wl_list_for_each(seat, &input->seats, link) {
|
|
|
|
if (seat->focus == view) {
|
|
|
|
seat->focus = NULL;
|
|
|
|
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
|
|
|
|
}
|
2017-10-06 16:51:16 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 01:48:55 +02:00
|
|
|
for (size_t i = 0; i < desktop->views->length; ++i) {
|
|
|
|
struct roots_view *_view = desktop->views->items[i];
|
|
|
|
if (view == _view) {
|
2017-10-22 16:56:40 +02:00
|
|
|
wlr_list_del(desktop->views, i);
|
2017-09-29 01:48:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-09-23 17:13:18 +02:00
|
|
|
free(view);
|
2017-09-23 06:29:53 +02:00
|
|
|
}
|
|
|
|
|
2017-09-30 14:02:09 +02:00
|
|
|
void view_get_size(struct roots_view *view, struct wlr_box *box) {
|
|
|
|
if (view->get_size) {
|
|
|
|
view->get_size(view, box);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
box->x = box->y = 0;
|
2017-09-30 19:29:31 +02:00
|
|
|
box->width = view->wlr_surface->current->width;
|
|
|
|
box->height = view->wlr_surface->current->height;
|
2017-09-30 14:02:09 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 14:49:15 +01:00
|
|
|
void view_activate(struct roots_view *view, bool activate) {
|
|
|
|
if (view->activate) {
|
|
|
|
view->activate(view, activate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void view_move(struct roots_view *view, double x, double y) {
|
|
|
|
if (view->move) {
|
|
|
|
view->move(view, x, y);
|
2017-10-19 18:33:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
view->x = x;
|
|
|
|
view->y = y;
|
|
|
|
}
|
|
|
|
|
2017-09-30 11:57:39 +02:00
|
|
|
void view_resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
|
|
|
if (view->resize) {
|
|
|
|
view->resize(view, width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 14:49:15 +01:00
|
|
|
void view_move_resize(struct roots_view *view, double x, double y,
|
|
|
|
uint32_t width, uint32_t height) {
|
|
|
|
if (view->move_resize) {
|
|
|
|
view->move_resize(view, x, y, width, height);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
view_move(view, x, y);
|
|
|
|
view_resize(view, width, height);
|
|
|
|
}
|
|
|
|
|
2017-10-06 15:39:39 +02:00
|
|
|
void view_close(struct roots_view *view) {
|
|
|
|
if (view->close) {
|
|
|
|
view->close(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-08 12:17:25 +02:00
|
|
|
bool view_center(struct roots_view *view) {
|
|
|
|
struct wlr_box size;
|
|
|
|
view_get_size(view, &size);
|
|
|
|
|
|
|
|
struct roots_desktop *desktop = view->desktop;
|
2017-10-16 20:35:16 +02:00
|
|
|
|
|
|
|
struct wlr_output *output =
|
2017-11-07 21:56:11 +01:00
|
|
|
wlr_output_layout_get_center_output(desktop->layout);
|
2017-10-08 12:17:25 +02:00
|
|
|
if (!output) {
|
2017-10-16 20:35:16 +02:00
|
|
|
// empty layout
|
2017-10-08 12:17:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-16 20:35:16 +02:00
|
|
|
const struct wlr_output_layout_output *l_output =
|
|
|
|
wlr_output_layout_get(desktop->layout, output);
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
wlr_output_effective_resolution(output, &width, &height);
|
|
|
|
|
2017-10-24 18:00:43 +02:00
|
|
|
double view_x = (double)(width - size.width) / 2 + l_output->x;
|
|
|
|
double view_y = (double)(height - size.height) / 2 + l_output->y;
|
|
|
|
|
2017-11-03 14:49:15 +01:00
|
|
|
view_move(view, view_x, view_y);
|
2017-10-16 20:35:16 +02:00
|
|
|
|
2017-10-08 12:17:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-25 20:34:40 +02:00
|
|
|
void view_setup(struct roots_view *view) {
|
2017-10-16 20:35:16 +02:00
|
|
|
view_center(view);
|
|
|
|
|
2017-10-25 20:34:40 +02:00
|
|
|
struct roots_input *input = view->desktop->server->input;
|
2017-11-07 21:56:11 +01:00
|
|
|
// TODO what seat gets focus? the one with the last input event?
|
|
|
|
struct roots_seat *seat;
|
|
|
|
wl_list_for_each(seat, &input->seats, link) {
|
|
|
|
roots_seat_focus_view(seat, view);
|
|
|
|
}
|
2017-10-08 18:19:05 +02:00
|
|
|
}
|
|
|
|
|
2017-10-25 20:34:40 +02:00
|
|
|
void view_teardown(struct roots_view *view) {
|
2017-11-07 21:56:11 +01:00
|
|
|
// TODO replace me with a signal
|
2017-11-09 01:53:33 +01:00
|
|
|
/*
|
2017-10-25 20:34:40 +02:00
|
|
|
struct wlr_list *views = view->desktop->views;
|
|
|
|
if (views->length < 2 || views->items[views->length-1] != view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct roots_view *prev_view = views->items[views->length-2];
|
|
|
|
struct roots_input *input = prev_view->desktop->server->input;
|
|
|
|
set_view_focus(input, prev_view->desktop, prev_view);
|
2017-11-09 01:53:33 +01:00
|
|
|
*/
|
2017-10-25 20:34:40 +02:00
|
|
|
}
|
|
|
|
|
2017-09-30 18:33:39 +02:00
|
|
|
struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
|
|
|
|
struct wlr_surface **surface, double *sx, double *sy) {
|
2017-09-30 20:43:24 +02:00
|
|
|
for (int i = desktop->views->length - 1; i >= 0; --i) {
|
2017-09-29 01:48:55 +02:00
|
|
|
struct roots_view *view = desktop->views->items[i];
|
2017-09-30 18:33:39 +02:00
|
|
|
|
2017-10-10 16:00:09 +02:00
|
|
|
if (view->type == ROOTS_WL_SHELL_VIEW &&
|
|
|
|
view->wl_shell_surface->state ==
|
|
|
|
WLR_WL_SHELL_SURFACE_STATE_POPUP) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-09-30 18:33:39 +02:00
|
|
|
double view_sx = lx - view->x;
|
|
|
|
double view_sy = ly - view->y;
|
|
|
|
|
2017-10-08 18:33:39 +02:00
|
|
|
struct wlr_box box = {
|
|
|
|
.x = 0,
|
|
|
|
.y = 0,
|
|
|
|
.width = view->wlr_surface->current->buffer_width,
|
|
|
|
.height = view->wlr_surface->current->buffer_height,
|
|
|
|
};
|
2017-10-04 21:05:00 +02:00
|
|
|
if (view->rotation != 0.0) {
|
|
|
|
// Coordinates relative to the center of the view
|
|
|
|
double ox = view_sx - (double)box.width/2,
|
|
|
|
oy = view_sy - (double)box.height/2;
|
|
|
|
// Rotated coordinates
|
|
|
|
double rx = cos(view->rotation)*ox - sin(view->rotation)*oy,
|
|
|
|
ry = cos(view->rotation)*oy + sin(view->rotation)*ox;
|
2017-10-04 23:05:57 +02:00
|
|
|
view_sx = rx + (double)box.width/2;
|
|
|
|
view_sy = ry + (double)box.height/2;
|
2017-10-04 21:05:00 +02:00
|
|
|
}
|
|
|
|
|
2017-10-03 21:57:43 +02:00
|
|
|
if (view->type == ROOTS_XDG_SHELL_V6_VIEW) {
|
2017-10-06 13:04:27 +02:00
|
|
|
// TODO: test if this works with rotated views
|
2017-10-03 21:57:43 +02:00
|
|
|
double popup_sx, popup_sy;
|
|
|
|
struct wlr_xdg_surface_v6 *popup =
|
2017-10-09 22:51:55 +02:00
|
|
|
wlr_xdg_surface_v6_popup_at(view->xdg_surface_v6,
|
|
|
|
view_sx, view_sy, &popup_sx, &popup_sy);
|
2017-10-03 21:57:43 +02:00
|
|
|
|
|
|
|
if (popup) {
|
|
|
|
*sx = view_sx - popup_sx;
|
|
|
|
*sy = view_sy - popup_sy;
|
|
|
|
*surface = popup->surface;
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 16:00:09 +02:00
|
|
|
if (view->type == ROOTS_WL_SHELL_VIEW) {
|
|
|
|
// TODO: test if this works with rotated views
|
|
|
|
double popup_sx, popup_sy;
|
|
|
|
struct wlr_wl_shell_surface *popup =
|
|
|
|
wlr_wl_shell_surface_popup_at(view->wl_shell_surface,
|
|
|
|
view_sx, view_sy, &popup_sx, &popup_sy);
|
|
|
|
|
|
|
|
if (popup) {
|
|
|
|
*sx = view_sx - popup_sx;
|
|
|
|
*sy = view_sy - popup_sy;
|
|
|
|
*surface = popup->surface;
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 21:17:16 +02:00
|
|
|
double sub_x, sub_y;
|
|
|
|
struct wlr_subsurface *subsurface =
|
2017-10-09 22:51:55 +02:00
|
|
|
wlr_surface_subsurface_at(view->wlr_surface,
|
|
|
|
view_sx, view_sy, &sub_x, &sub_y);
|
2017-10-04 21:17:16 +02:00
|
|
|
if (subsurface) {
|
|
|
|
*sx = view_sx - sub_x;
|
|
|
|
*sy = view_sy - sub_y;
|
|
|
|
*surface = subsurface->surface;
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2017-10-08 18:33:39 +02:00
|
|
|
if (wlr_box_contains_point(&box, view_sx, view_sy) &&
|
|
|
|
pixman_region32_contains_point(
|
|
|
|
&view->wlr_surface->current->input,
|
|
|
|
view_sx, view_sy, NULL)) {
|
2017-09-30 18:33:39 +02:00
|
|
|
*sx = view_sx;
|
|
|
|
*sy = view_sy;
|
|
|
|
*surface = view->wlr_surface;
|
2017-09-23 23:48:13 +02:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-09-23 06:29:53 +02:00
|
|
|
struct roots_desktop *desktop_create(struct roots_server *server,
|
|
|
|
struct roots_config *config) {
|
|
|
|
wlr_log(L_DEBUG, "Initializing roots desktop");
|
|
|
|
|
2017-10-21 13:25:39 +02:00
|
|
|
struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop));
|
|
|
|
if (desktop == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-22 16:56:40 +02:00
|
|
|
desktop->views = wlr_list_create();
|
2017-10-21 13:25:39 +02:00
|
|
|
if (desktop->views == NULL) {
|
|
|
|
free(desktop);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-09-23 06:29:53 +02:00
|
|
|
wl_list_init(&desktop->outputs);
|
|
|
|
|
2017-10-21 12:35:51 +02:00
|
|
|
desktop->output_add.notify = output_add_notify;
|
2017-10-07 11:07:51 +02:00
|
|
|
wl_signal_add(&server->backend->events.output_add, &desktop->output_add);
|
2017-10-21 12:35:51 +02:00
|
|
|
desktop->output_remove.notify = output_remove_notify;
|
2017-09-23 06:29:53 +02:00
|
|
|
wl_signal_add(&server->backend->events.output_remove,
|
2017-10-07 11:07:51 +02:00
|
|
|
&desktop->output_remove);
|
2017-09-23 06:29:53 +02:00
|
|
|
|
|
|
|
desktop->server = server;
|
|
|
|
desktop->config = config;
|
|
|
|
desktop->layout = wlr_output_layout_create();
|
2017-10-07 11:07:51 +02:00
|
|
|
desktop->compositor = wlr_compositor_create(server->wl_display,
|
|
|
|
server->renderer);
|
2017-09-23 06:29:53 +02:00
|
|
|
|
|
|
|
desktop->xdg_shell_v6 = wlr_xdg_shell_v6_create(server->wl_display);
|
|
|
|
wl_signal_add(&desktop->xdg_shell_v6->events.new_surface,
|
|
|
|
&desktop->xdg_shell_v6_surface);
|
|
|
|
desktop->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface;
|
|
|
|
|
2017-09-26 23:59:25 +02:00
|
|
|
desktop->wl_shell = wlr_wl_shell_create(server->wl_display);
|
|
|
|
wl_signal_add(&desktop->wl_shell->events.new_surface,
|
|
|
|
&desktop->wl_shell_surface);
|
|
|
|
desktop->wl_shell_surface.notify = handle_wl_shell_surface;
|
|
|
|
|
2017-10-06 23:50:25 +02:00
|
|
|
#ifdef HAS_XWAYLAND
|
2017-10-06 08:41:50 +02:00
|
|
|
if (config->xwayland) {
|
|
|
|
desktop->xwayland = wlr_xwayland_create(server->wl_display,
|
|
|
|
desktop->compositor);
|
|
|
|
wl_signal_add(&desktop->xwayland->events.new_surface,
|
|
|
|
&desktop->xwayland_surface);
|
|
|
|
desktop->xwayland_surface.notify = handle_xwayland_surface;
|
|
|
|
}
|
2017-10-06 23:50:25 +02:00
|
|
|
#endif
|
2017-09-28 14:54:57 +02:00
|
|
|
|
2017-09-23 06:29:53 +02:00
|
|
|
desktop->gamma_control_manager = wlr_gamma_control_manager_create(
|
2017-10-07 11:07:51 +02:00
|
|
|
server->wl_display);
|
2017-10-08 02:11:56 +02:00
|
|
|
desktop->screenshooter = wlr_screenshooter_create(server->wl_display,
|
|
|
|
server->renderer);
|
2017-10-27 00:02:30 +02:00
|
|
|
desktop->server_decoration_manager =
|
|
|
|
wlr_server_decoration_manager_create(server->wl_display);
|
|
|
|
wlr_server_decoration_manager_set_default_mode(
|
|
|
|
desktop->server_decoration_manager,
|
|
|
|
ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_CLIENT);
|
2017-09-23 06:29:53 +02:00
|
|
|
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void desktop_destroy(struct roots_desktop *desktop) {
|
|
|
|
// TODO
|
|
|
|
}
|