2020-09-25 20:05:20 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2020-09-28 20:41:41 +01:00
|
|
|
#include "config/rcxml.h"
|
2019-12-26 21:37:31 +00:00
|
|
|
#include "labwc.h"
|
2020-09-25 19:42:40 +01:00
|
|
|
#include "theme/theme.h"
|
2019-12-26 21:37:31 +00:00
|
|
|
|
2020-09-25 19:42:40 +01:00
|
|
|
#include <signal.h>
|
2020-06-03 18:39:46 +01:00
|
|
|
#include <wlr/types/wlr_data_control_v1.h>
|
2020-09-28 20:41:41 +01:00
|
|
|
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
2020-06-03 18:39:46 +01:00
|
|
|
#include <wlr/types/wlr_gamma_control_v1.h>
|
|
|
|
|
#include <wlr/types/wlr_primary_selection_v1.h>
|
2020-09-28 20:41:41 +01:00
|
|
|
#include <wlr/types/wlr_screencopy_v1.h>
|
2020-09-30 17:18:20 +01:00
|
|
|
#include "layers.h"
|
2020-06-03 18:39:46 +01:00
|
|
|
|
2020-06-05 21:07:57 +01:00
|
|
|
static struct wlr_compositor *compositor;
|
2020-09-25 19:42:40 +01:00
|
|
|
static struct wl_event_source *sighup_source;
|
2020-06-05 21:07:57 +01:00
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
reload_config_and_theme(void)
|
2020-09-25 19:42:40 +01:00
|
|
|
{
|
|
|
|
|
rcxml_finish();
|
|
|
|
|
/* TODO: use rc.config_path */
|
|
|
|
|
rcxml_read(NULL);
|
|
|
|
|
theme_read(rc.theme_name);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static int
|
|
|
|
|
handle_signal(int signal, void *data)
|
2020-09-25 19:42:40 +01:00
|
|
|
{
|
|
|
|
|
switch (signal) {
|
|
|
|
|
case SIGHUP:
|
|
|
|
|
reload_config_and_theme();
|
|
|
|
|
return 0;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
|
|
|
|
server_init(struct server *server)
|
2020-06-03 18:39:46 +01:00
|
|
|
{
|
|
|
|
|
server->wl_display = wl_display_create();
|
|
|
|
|
if (!server->wl_display) {
|
|
|
|
|
wlr_log(WLR_ERROR, "cannot allocate a wayland display");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-25 19:42:40 +01:00
|
|
|
/* Catch SIGHUP */
|
|
|
|
|
struct wl_event_loop *event_loop = NULL;
|
|
|
|
|
event_loop = wl_display_get_event_loop(server->wl_display);
|
|
|
|
|
sighup_source = wl_event_loop_add_signal(
|
|
|
|
|
event_loop, SIGHUP, handle_signal, &server->wl_display);
|
|
|
|
|
|
2020-06-03 18:39:46 +01:00
|
|
|
/*
|
2020-09-29 19:53:46 +01:00
|
|
|
* The backend is a feature which abstracts the underlying input and
|
|
|
|
|
* output hardware. The autocreate option will choose the most suitable
|
|
|
|
|
* backend based on the current environment, such as opening an x11
|
|
|
|
|
* window if an x11 server is running.
|
2020-06-03 18:39:46 +01:00
|
|
|
*/
|
2020-09-29 19:53:46 +01:00
|
|
|
server->backend = wlr_backend_autocreate(server->wl_display, NULL);
|
|
|
|
|
if (!server->backend) {
|
|
|
|
|
wlr_log(WLR_ERROR, "unable to create backend");
|
2020-06-03 18:39:46 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If we don't provide a renderer, autocreate makes a GLES2 renderer
|
|
|
|
|
* for us. The renderer is responsible for defining the various pixel
|
|
|
|
|
* formats it supports for shared memory, this configures that for
|
|
|
|
|
* clients.
|
|
|
|
|
*/
|
2020-09-29 19:53:46 +01:00
|
|
|
server->renderer = wlr_backend_get_renderer(server->backend);
|
2020-06-03 18:39:46 +01:00
|
|
|
wlr_renderer_init_wl_display(server->renderer, server->wl_display);
|
|
|
|
|
|
|
|
|
|
wl_list_init(&server->views);
|
2020-09-04 20:25:20 +01:00
|
|
|
wl_list_init(&server->unmanaged_surfaces);
|
2020-06-03 18:39:46 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Create some hands-off wlroots interfaces. The compositor is
|
|
|
|
|
* necessary for clients to allocate surfaces and the data device
|
|
|
|
|
* manager handles the clipboard. Each of these wlroots interfaces has
|
|
|
|
|
* room for you to dig your fingers in and play with their behavior if
|
|
|
|
|
* you want.
|
|
|
|
|
*/
|
2020-06-05 21:07:57 +01:00
|
|
|
compositor =
|
2020-06-03 18:39:46 +01:00
|
|
|
wlr_compositor_create(server->wl_display, server->renderer);
|
2020-06-05 21:07:57 +01:00
|
|
|
if (!compositor) {
|
2020-06-03 18:39:46 +01:00
|
|
|
wlr_log(WLR_ERROR, "unable to create the wlroots compositor");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_data_device_manager *device_manager = NULL;
|
|
|
|
|
device_manager = wlr_data_device_manager_create(server->wl_display);
|
|
|
|
|
if (!device_manager) {
|
|
|
|
|
wlr_log(WLR_ERROR, "unable to create data device manager");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 19:53:46 +01:00
|
|
|
output_init(server);
|
2020-10-02 21:19:56 +01:00
|
|
|
seat_init(server);
|
2020-06-03 18:39:46 +01:00
|
|
|
|
|
|
|
|
/* Init xdg-shell */
|
|
|
|
|
server->xdg_shell = wlr_xdg_shell_create(server->wl_display);
|
|
|
|
|
if (!server->xdg_shell) {
|
|
|
|
|
wlr_log(WLR_ERROR, "unable to create the XDG shell interface");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
server->new_xdg_surface.notify = xdg_surface_new;
|
|
|
|
|
wl_signal_add(&server->xdg_shell->events.new_surface,
|
|
|
|
|
&server->new_xdg_surface);
|
|
|
|
|
|
|
|
|
|
/* Disable CSD */
|
|
|
|
|
struct wlr_xdg_decoration_manager_v1 *xdg_deco_mgr = NULL;
|
|
|
|
|
xdg_deco_mgr = wlr_xdg_decoration_manager_v1_create(server->wl_display);
|
|
|
|
|
if (!xdg_deco_mgr) {
|
|
|
|
|
wlr_log(WLR_ERROR, "unable to create the XDG deco manager");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
wl_signal_add(&xdg_deco_mgr->events.new_toplevel_decoration,
|
|
|
|
|
&server->xdg_toplevel_decoration);
|
|
|
|
|
server->xdg_toplevel_decoration.notify = xdg_toplevel_decoration;
|
|
|
|
|
|
|
|
|
|
struct wlr_server_decoration_manager *deco_mgr = NULL;
|
|
|
|
|
deco_mgr = wlr_server_decoration_manager_create(server->wl_display);
|
|
|
|
|
if (!deco_mgr) {
|
|
|
|
|
wlr_log(WLR_ERROR, "unable to create the server deco manager");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
wlr_server_decoration_manager_set_default_mode(
|
2020-09-15 21:10:02 +01:00
|
|
|
deco_mgr, rc.xdg_shell_server_side_deco ?
|
2020-06-03 18:39:46 +01:00
|
|
|
WLR_SERVER_DECORATION_MANAGER_MODE_SERVER :
|
|
|
|
|
WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT);
|
|
|
|
|
|
|
|
|
|
wlr_export_dmabuf_manager_v1_create(server->wl_display);
|
|
|
|
|
wlr_screencopy_manager_v1_create(server->wl_display);
|
|
|
|
|
wlr_data_control_manager_v1_create(server->wl_display);
|
|
|
|
|
wlr_gamma_control_manager_v1_create(server->wl_display);
|
|
|
|
|
wlr_primary_selection_v1_device_manager_create(server->wl_display);
|
|
|
|
|
|
2020-09-30 17:18:20 +01:00
|
|
|
layers_init(server);
|
|
|
|
|
|
2020-06-03 18:39:46 +01:00
|
|
|
/* Init xwayland */
|
2020-06-05 21:07:57 +01:00
|
|
|
server->xwayland =
|
2020-10-02 21:19:56 +01:00
|
|
|
wlr_xwayland_create(server->wl_display, compositor, true);
|
2020-06-03 18:39:46 +01:00
|
|
|
if (!server->xwayland) {
|
|
|
|
|
wlr_log(WLR_ERROR, "cannot create xwayland server");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
2020-09-04 20:32:41 +01:00
|
|
|
server->new_xwayland_surface.notify = xwayland_surface_new;
|
2020-06-03 18:39:46 +01:00
|
|
|
wl_signal_add(&server->xwayland->events.new_surface,
|
|
|
|
|
&server->new_xwayland_surface);
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
if (setenv("DISPLAY", server->xwayland->display_name, true) < 0) {
|
2020-06-03 18:39:46 +01:00
|
|
|
wlr_log_errno(WLR_ERROR, "unable to set DISPLAY for xwayland");
|
2020-09-28 20:41:41 +01:00
|
|
|
} else {
|
2020-06-03 18:39:46 +01:00
|
|
|
wlr_log(WLR_DEBUG, "xwayland is running on display %s",
|
|
|
|
|
server->xwayland->display_name);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-03 18:39:46 +01:00
|
|
|
|
2020-10-02 21:19:56 +01:00
|
|
|
if (!wlr_xcursor_manager_load(server->seat.xcursor_manager, 1)) {
|
2020-06-03 18:39:46 +01:00
|
|
|
wlr_log(WLR_ERROR, "cannot load xwayland xcursor theme");
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-03 18:39:46 +01:00
|
|
|
|
|
|
|
|
struct wlr_xcursor *xcursor;
|
2020-10-02 21:19:56 +01:00
|
|
|
xcursor = wlr_xcursor_manager_get_xcursor(server->seat.xcursor_manager,
|
2020-06-03 18:39:46 +01:00
|
|
|
XCURSOR_DEFAULT, 1);
|
|
|
|
|
if (xcursor) {
|
|
|
|
|
struct wlr_xcursor_image *image = xcursor->images[0];
|
|
|
|
|
wlr_xwayland_set_cursor(server->xwayland, image->buffer,
|
|
|
|
|
image->width * 4, image->width,
|
|
|
|
|
image->height, image->hotspot_x,
|
|
|
|
|
image->hotspot_y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
|
|
|
|
server_start(struct server *server)
|
2020-06-03 18:39:46 +01:00
|
|
|
{
|
|
|
|
|
/* Add a Unix socket to the Wayland display. */
|
|
|
|
|
const char *socket = wl_display_add_socket_auto(server->wl_display);
|
|
|
|
|
if (!socket) {
|
|
|
|
|
wlr_log_errno(WLR_ERROR, "unable to open wayland socket");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Start the backend. This will enumerate outputs and inputs, become
|
|
|
|
|
* the DRM master, etc
|
|
|
|
|
*/
|
2020-09-29 19:53:46 +01:00
|
|
|
if (!wlr_backend_start(server->backend)) {
|
2020-06-03 18:39:46 +01:00
|
|
|
wlr_log(WLR_ERROR, "unable to start the wlroots backend");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setenv("WAYLAND_DISPLAY", socket, true);
|
2020-09-28 20:41:41 +01:00
|
|
|
if (setenv("WAYLAND_DISPLAY", socket, true) < 0) {
|
2020-06-03 18:39:46 +01:00
|
|
|
wlr_log_errno(WLR_ERROR, "unable to set WAYLAND_DISPLAY");
|
2020-09-28 20:41:41 +01:00
|
|
|
} else {
|
2020-06-03 18:39:46 +01:00
|
|
|
wlr_log(WLR_DEBUG, "WAYLAND_DISPLAY=%s", socket);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-03 18:39:46 +01:00
|
|
|
|
|
|
|
|
wl_display_init_shm(server->wl_display);
|
|
|
|
|
|
2020-10-02 21:19:56 +01:00
|
|
|
wlr_xwayland_set_seat(server->xwayland, server->seat.seat);
|
2020-06-03 18:39:46 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
|
|
|
|
server_finish(struct server *server)
|
2020-06-03 18:39:46 +01:00
|
|
|
{
|
|
|
|
|
wlr_xwayland_destroy(server->xwayland);
|
2020-09-25 19:42:40 +01:00
|
|
|
wl_event_source_remove(sighup_source);
|
2020-06-03 18:39:46 +01:00
|
|
|
wl_display_destroy_clients(server->wl_display);
|
2020-10-22 19:54:30 +01:00
|
|
|
|
|
|
|
|
seat_finish(server);
|
2020-10-23 20:19:07 +01:00
|
|
|
wlr_output_layout_destroy(server->output_layout);
|
2020-10-22 19:54:30 +01:00
|
|
|
|
2020-06-03 18:39:46 +01:00
|
|
|
wl_display_destroy(server->wl_display);
|
|
|
|
|
}
|