Updated for wlroots 0.16.0

This commit is contained in:
Keith Bowes 2022-12-01 17:51:28 -05:00
parent 31d0ef57e5
commit 0c2f744dbf
14 changed files with 17 additions and 298 deletions

View file

@ -16,7 +16,7 @@ sources:
tasks:
- setup: |
cd waybox
meson build
meson setup build
- build: |
cd waybox
ninja -C build

View file

@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v2
- name: setup
run: |
meson build
meson setup build
- name: build
run: |
ninja -C build

View file

@ -20,7 +20,7 @@ contributing.](https://github.com/wizbright/waybox/blob/master/CONTRIBUTING.md)
### Build instructions
```
meson build
meson setup build
cd build
ninja
```

View file

@ -11,22 +11,17 @@ struct wb_output {
struct wb_server *server;
struct {
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_tree *shell_background;
struct wlr_scene_tree *shell_bottom;
struct wlr_scene_tree *shell_fullscreen;
struct wlr_scene_tree *shell_overlay;
struct wlr_scene_tree *shell_top;
#else
struct wlr_scene_node *shell_background;
struct wlr_scene_node *shell_bottom;
struct wlr_scene_node *shell_fullscreen;
struct wlr_scene_node *shell_overlay;
struct wlr_scene_node *shell_top;
#endif
} layers;
#if ! WLR_CHECK_VERSION(0, 17, 0)
/* DEPRECATED: Use a tool like swaybg instead */
struct wlr_scene_rect *background;
#endif
struct wlr_box geometry;
struct wl_listener destroy;
@ -39,12 +34,7 @@ struct wb_view {
struct wl_list link;
struct wb_server *server;
struct wlr_xdg_toplevel *xdg_toplevel;
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_tree *scene_tree;
#else
struct wlr_scene_node *scene_node;
struct wlr_xdg_surface *xdg_surface;
#endif
struct wlr_xdg_toplevel_decoration_v1 *decoration;

View file

@ -17,7 +17,6 @@ struct wb_seat {
struct wb_keyboard {
struct wl_list link;
struct wb_server *server;
struct wlr_input_device *device; /* wlroots 0.15.x */
struct wlr_keyboard *keyboard;
struct wl_listener destroy;

View file

@ -17,9 +17,7 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_screencopy_v1.h>
#if WLR_CHECK_VERSION(0, 16, 0)
#include <wlr/types/wlr_subcompositor.h>
#endif
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
@ -49,9 +47,7 @@ struct wb_server {
struct wlr_xdg_output_manager_v1 *output_manager;
struct wlr_renderer *renderer;
struct wlr_scene *scene;
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_subcompositor *subcompositor;
#endif
struct wb_config *config;
char *config_file;

View file

@ -1,7 +1,7 @@
project(
'Waybox',
'c',
version: '0.2.0',
version: '0.2.1',
license: 'MIT',
meson_version: '>=0.52.0',
default_options: [
@ -26,7 +26,7 @@ cc = meson.get_compiler('c')
inc_dir = include_directories('include')
libxml2 = dependency('libxml-2.0')
wlroots = dependency('wlroots', version: '>=0.15.0')
wlroots = dependency('wlroots', version: '>=0.16.0')
wayland_server = dependency('wayland-server', version: '>=1.15')
wayland_protos = dependency('wayland-protocols', version: '>=1.17')
xkbcommon = dependency('xkbcommon')

View file

@ -10,18 +10,10 @@ void reset_cursor_mode(struct wb_server *server) {
static void process_cursor_move(struct wb_server *server) {
/* Move the grabbed view to the new position. */
struct wb_view *view = server->grabbed_view;
#if WLR_CHECK_VERSION(0, 16, 0)
if (view->scene_tree->node.type == WLR_SCENE_NODE_TREE) {
#else
if (view->scene_node->parent->type == WLR_SCENE_NODE_ROOT) {
#endif
view->current_position.x = server->cursor->cursor->x - server->grab_x;
view->current_position.y = server->cursor->cursor->y - server->grab_y;
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_scene_node_set_position(&view->scene_tree->node,
#else
wlr_scene_node_set_position(view->scene_node,
#endif
view->current_position.x, view->current_position.y);
}
}
@ -62,20 +54,12 @@ static void process_cursor_resize(struct wb_server *server) {
wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box);
view->current_position.x = new_left - geo_box.x;
view->current_position.y = new_top - geo_box.y;
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_scene_node_set_position(&view->scene_tree->node,
#else
wlr_scene_node_set_position(view->scene_node,
#endif
view->current_position.x, view->current_position.y);
int new_width = new_right - new_left;
int new_height = new_bottom - new_top;
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(view->xdg_toplevel, new_width, new_height);
#else
wlr_xdg_toplevel_set_size(view->xdg_surface, new_width, new_height);
#endif
}
static void process_cursor_motion(struct wb_server *server, uint32_t time) {
@ -122,29 +106,18 @@ static void process_cursor_motion(struct wb_server *server, uint32_t time) {
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
struct wb_cursor *cursor =
wl_container_of(listener, cursor, cursor_motion);
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_pointer_motion_event *event = data;
wlr_cursor_move(cursor->cursor, &event->pointer->base,
event->delta_x, event->delta_y);
#else
struct wlr_event_pointer_motion *event = data;
wlr_cursor_move(cursor->cursor, event->device, event->delta_x, event->delta_y);
#endif
process_cursor_motion(cursor->server, event->time_msec);
}
static void handle_cursor_motion_absolute(struct wl_listener *listener, void *data) {
struct wb_cursor *cursor =
wl_container_of(listener, cursor, cursor_motion_absolute);
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_pointer_motion_absolute_event *event = data;
wlr_cursor_warp_absolute(cursor->cursor, &event->pointer->base,
event->x, event->y);
#else
struct wlr_event_pointer_motion_absolute *event = data;
wlr_cursor_warp_absolute(cursor->cursor, event->device,
event->x, event->y);
#endif
process_cursor_motion(cursor->server, event->time_msec);
}
@ -153,11 +126,7 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
* event. */
struct wb_cursor *cursor =
wl_container_of(listener, cursor, cursor_button);
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_pointer_button_event *event = data;
#else
struct wlr_event_pointer_button *event = data;
#endif
/* Notify the client with pointer focus that a button press has occurred */
wlr_seat_pointer_notify_button(cursor->server->seat->seat,
event->time_msec, event->button, event->state);
@ -179,11 +148,7 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) {
* for example when you move the scroll wheel. */
struct wb_cursor *cursor =
wl_container_of(listener, cursor, cursor_axis);
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_pointer_axis_event *event = data;
#else
struct wlr_event_pointer_axis *event = data;
#endif
/* Notify the client with pointer focus of the axis event. */
wlr_seat_pointer_notify_axis(cursor->server->seat->seat,
event->time_msec, event->orientation, event->delta,

View file

@ -46,25 +46,15 @@ void assign_scene_descriptor(struct wlr_scene_node *node,
}
static void arrange_surface(struct wb_output *output, struct wlr_box *full_area,
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_box *usable_area, struct wlr_scene_tree *scene_tree) {
#else
struct wlr_box *usable_area, struct wlr_scene_node *scene_node) {
#endif
struct wlr_scene_node *node;
#if WLR_CHECK_VERSION(0, 16, 0)
wl_list_for_each(node, &scene_tree->children, link) {
#else
wl_list_for_each(node, &scene_node->state.children, state.link) {
#endif
struct wb_scene_descriptor *desc = node->data;
if (desc->type == WB_SCENE_DESC_LAYER_SHELL) {
#if WLR_CHECK_VERSION(0, 16, 0)
struct wb_layer_surface *surface = desc->data;
wlr_scene_layer_surface_v1_configure(surface->scene,
full_area, usable_area);
#endif
}
}
}
@ -83,11 +73,7 @@ void arrange_layers(struct wb_output *output) {
arrange_surface(output, &full_area, &usable_area, output->layers.shell_overlay);
}
#if WLR_CHECK_VERSION(0, 16, 0)
static struct wlr_scene_tree *wb_layer_get_scene(struct wb_output *output,
#else
static struct wlr_scene_node *wb_layer_get_scene(struct wb_output *output,
#endif
enum zwlr_layer_shell_v1_layer type) {
switch (type) {
case ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND:
@ -105,19 +91,13 @@ static struct wlr_scene_node *wb_layer_get_scene(struct wb_output *output,
}
static struct wb_layer_surface *wb_layer_surface_create(
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_layer_surface_v1 *scene) {
#else
struct wlr_layer_surface_v1 *scene) {
#endif
struct wb_layer_surface *surface = calloc(1, sizeof(struct wb_layer_surface));
if (!surface) {
return NULL;
}
#if WLR_CHECK_VERSION(0, 16, 0)
surface->scene = scene;
#endif
return surface;
}
@ -134,20 +114,11 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
uint32_t committed = layer_surface->current.committed;
enum zwlr_layer_shell_v1_layer layer_type = layer_surface->current.layer;
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_tree *output_layer = wb_layer_get_scene(
surface->output, layer_type);
#else
struct wlr_scene_node *output_layer = wb_layer_get_scene(
surface->output, layer_type);
#endif
if (committed & WLR_LAYER_SURFACE_V1_STATE_LAYER) {
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_scene_node_reparent(&surface->scene->tree->node, output_layer);
#else
wlr_scene_node_reparent(surface->scene->node, output_layer);
#endif
}
if (committed || layer_surface->mapped != surface->mapped) {
@ -160,11 +131,7 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
}
if (layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) {
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_scene_node_raise_to_top(&output_layer->node);
#else
wlr_scene_node_raise_to_top(output_layer);
#endif
}
if (layer_surface == surface->server->seat->focused_layer) {
@ -204,11 +171,7 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
}
struct wb_view *view = wl_container_of(surface->server->views.next, view, link);
#if WLR_CHECK_VERSION(0, 16, 0)
if (view && view->scene_tree && view->scene_tree->node.enabled) {
#else
if (view && view->scene_node && view->scene_node->state.enabled) {
#endif
focus_view(view, view->xdg_toplevel->base->surface);
}
}
@ -248,11 +211,7 @@ static void popup_handle_destroy(struct wl_listener *listener, void *data) {
static struct wb_layer_surface *popup_get_layer(
struct wb_layer_popup *popup) {
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_node *current = &popup->scene->node;
#else
struct wlr_scene_node *current = popup->scene;
#endif
while (current) {
if (current->data) {
struct wb_scene_descriptor *desc = current->data;
@ -261,11 +220,7 @@ static struct wb_layer_surface *popup_get_layer(
}
}
#if WLR_CHECK_VERSION(0, 16, 0)
current = &current->parent->node;
#else
current = current->parent;
#endif
}
return NULL;
@ -281,11 +236,7 @@ static void popup_unconstrain(struct wb_layer_popup *popup) {
struct wb_output *output = surface->output;
int lx, ly;
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_scene_node_coords(&popup->scene->node, &lx, &ly);
#else
wlr_scene_node_coords(popup->scene, &lx, &ly);
#endif
/* The output box expressed in the coordinate system of the toplevel
* parent of the popup. */
@ -302,11 +253,7 @@ static void popup_unconstrain(struct wb_layer_popup *popup) {
static void popup_handle_new_popup(struct wl_listener *listener, void *data);
static struct wb_layer_popup *create_popup(struct wlr_xdg_popup *wlr_popup,
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_tree *parent) {
#else
struct wlr_scene_node *parent) {
#endif
struct wb_layer_popup *popup =
calloc(1, sizeof(struct wb_layer_popup));
if (popup == NULL) {
@ -323,11 +270,7 @@ static struct wb_layer_popup *create_popup(struct wlr_xdg_popup *wlr_popup,
return NULL;
}
#if WLR_CHECK_VERSION(0, 16, 0)
assign_scene_descriptor(&popup->scene->node, WB_SCENE_DESC_LAYER_SHELL_POPUP,
#else
assign_scene_descriptor(popup->scene, WB_SCENE_DESC_LAYER_SHELL_POPUP,
#endif
popup);
popup->destroy.notify = popup_handle_destroy;
@ -353,11 +296,7 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
wl_container_of(listener, wb_layer_surface, new_popup);
struct wlr_xdg_popup *wlr_popup = data;
#if WLR_CHECK_VERSION(0, 16, 0)
create_popup(wlr_popup, wb_layer_surface->scene->tree);
#else
create_popup(wlr_popup, wb_layer_surface->scene->node);
#endif
}
void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
@ -379,7 +318,6 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
enum zwlr_layer_shell_v1_layer layer_type = layer_surface->pending.layer;
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_tree *output_layer = wb_layer_get_scene(
output, layer_type);
struct wlr_scene_layer_surface_v1 *scene_surface =
@ -397,19 +335,6 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
wlr_layer_surface_v1_destroy(layer_surface);
return;
}
#else
struct wlr_scene_node *output_layer = wb_layer_get_scene(
output, layer_type);
struct wb_layer_surface *surface =
wb_layer_surface_create(layer_surface);
surface->scene = calloc(1, sizeof(*surface->scene));
surface->scene->layer_surface = layer_surface;
surface->scene->node = output_layer;
if (!surface) {
wlr_layer_surface_v1_destroy(layer_surface);
return;
}
#endif
surface->output = output;
surface->server = output->server;

View file

@ -8,14 +8,7 @@ struct wb_layer_surface {
struct wb_output *output;
struct wb_server *server;
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_layer_surface_v1 *scene;
#else
struct {
struct wlr_layer_surface_v1 *layer_surface;
struct wlr_scene_node *node;
} *scene;
#endif
bool mapped;
@ -28,22 +21,14 @@ struct wb_layer_surface {
struct wb_layer_popup {
struct wlr_xdg_popup *wlr_popup;
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_tree *scene;
#else
struct wlr_scene_node *scene;
#endif
struct wl_listener destroy;
struct wl_listener new_popup;
};
struct wb_layer_subsurface {
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_tree *scene;
#else
struct wlr_scene_node *scene;
#endif
struct wl_listener destroy;
};

View file

@ -8,16 +8,13 @@ void output_frame_notify(struct wl_listener *listener, void *data) {
struct wlr_scene_output *scene_output =
wlr_scene_get_scene_output(scene, output->wlr_output);
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_output_layout_get_box(output->server->output_layout,
output->wlr_output, &output->geometry);
#else
output->geometry = *wlr_output_layout_get_box(
output->server->output_layout, output->wlr_output);
#endif
#if ! WLR_CHECK_VERSION(0, 17, 0)
/* Update the background for the current output size. */
wlr_scene_rect_set_size(output->background,
output->geometry.width, output->geometry.height);
#endif
/* Render the scene if needed and commit the output */
wlr_scene_output_commit(scene_output);
@ -74,24 +71,18 @@ void new_output_notify(struct wl_listener *listener, void *data) {
output->wlr_output = wlr_output;
wlr_output->data = output;
#if ! WLR_CHECK_VERSION(0, 17, 0)
/* Set the background color */
float color[4] = {0.1875, 0.1875, 0.1875, 1.0};
#if WLR_CHECK_VERSION(0, 16, 0)
output->background = wlr_scene_rect_create(&server->scene->tree, 0, 0, color);
#else
output->background = wlr_scene_rect_create(&server->scene->node, 0, 0, color);
#endif
wlr_scene_node_lower_to_bottom(&output->background->node);
#endif
/* Initializes the layers */
size_t num_layers = sizeof(output->layers) / sizeof(struct wlr_scene_node *);
for (size_t i = 0; i < num_layers; i++) {
((struct wlr_scene_node **) &output->layers)[i] =
#if WLR_CHECK_VERSION(0, 16, 0)
&wlr_scene_tree_create(&server->scene->tree)->node;
#else
&wlr_scene_tree_create(&server->scene->node)->node;
#endif
}
wl_list_insert(&server->outputs, &output->link);

View file

@ -81,13 +81,8 @@ static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32
if (key_binding->action & ACTION_CLOSE) {
struct wb_view *current_view = wl_container_of(
server->views.next, current_view, link);
#if WLR_CHECK_VERSION(0, 16, 0)
if (current_view->scene_tree->node.enabled)
wlr_xdg_toplevel_send_close(current_view->xdg_toplevel);
#else
if (current_view->scene_node->state.enabled)
wlr_xdg_toplevel_send_close(current_view->xdg_surface);
#endif
}
if (key_binding->action & ACTION_EXECUTE) {
if (fork() == 0) {
@ -96,56 +91,33 @@ static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32
}
if (key_binding->action & ACTION_TOGGLE_MAXIMIZE) {
struct wb_view *view = wl_container_of(server->views.next, view, link);
#if WLR_CHECK_VERSION(0, 16, 0)
if (view->scene_tree->node.enabled)
#else
if (view->scene_node->state.enabled)
#endif
wl_signal_emit(&view->xdg_toplevel->events.request_maximize, NULL);
}
if (key_binding->action & ACTION_ICONIFY) {
struct wb_view *view = wl_container_of(server->views.next, view, link);
#if WLR_CHECK_VERSION(0, 16, 0)
if (view->scene_tree->node.enabled) {
#else
if (view->scene_node->state.enabled) {
#endif
view->xdg_toplevel->requested.minimized = true;
wl_signal_emit(&view->xdg_toplevel->events.request_minimize, NULL);
}
}
if (key_binding->action & ACTION_SHADE) {
struct wb_view *view = wl_container_of(server->views.next, view, link);
#if WLR_CHECK_VERSION(0, 16, 0)
if (view->scene_tree->node.enabled) {
#else
if (view->scene_node->state.enabled) {
#endif
struct wlr_box geo_box;
wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box);
int decoration_height = MAX(geo_box.y - view->current_position.y, TITLEBAR_HEIGHT);
view->previous_position = view->current_position;
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(view->xdg_toplevel,
view->current_position.width, decoration_height);
#else
wlr_xdg_toplevel_set_size(view->xdg_surface,
view->current_position.width, decoration_height);
#endif
}
}
if (key_binding->action & ACTION_UNSHADE) {
struct wb_view *view = wl_container_of(server->views.next, view, link);
#if WLR_CHECK_VERSION(0, 16, 0)
if (view->scene_tree->node.enabled) {
wlr_xdg_toplevel_set_size(view->xdg_toplevel,
view->previous_position.width, view->previous_position.height);
#else
if (view->scene_node->state.enabled) {
wlr_xdg_toplevel_set_size(view->xdg_surface,
view->previous_position.width, view->previous_position.height);
#endif
}
}
if (key_binding->action & ACTION_RECONFIGURE) {
@ -185,11 +157,7 @@ static void keyboard_handle_modifiers(
* same seat. You can swap out the underlying wlr_keyboard like this and
* wlr_seat handles this transparently.
*/
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_seat_set_keyboard(keyboard->server->seat->seat, keyboard->keyboard);
#else
wlr_seat_set_keyboard(keyboard->server->seat->seat, keyboard->device);
#endif
/* Send modifiers to the client. */
wlr_seat_keyboard_notify_modifiers(keyboard->server->seat->seat,
&keyboard->keyboard->modifiers);
@ -201,11 +169,7 @@ static void keyboard_handle_key(
struct wb_keyboard *keyboard =
wl_container_of(listener, keyboard, key);
struct wb_server *server = keyboard->server;
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_keyboard_key_event *event = data;
#else
struct wlr_event_keyboard_key *event = data;
#endif
struct wlr_seat *seat = server->seat->seat;
/* Translate libinput keycode -> xkbcommon */
@ -225,11 +189,7 @@ static void keyboard_handle_key(
if (!handled) {
/* Otherwise, we pass it along to the client. */
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_seat_set_keyboard(seat, keyboard->keyboard);
#else
wlr_seat_set_keyboard(seat, keyboard->device);
#endif
wlr_seat_keyboard_notify_key(seat, event->time_msec,
event->keycode, event->state);
}
@ -240,12 +200,7 @@ static void handle_new_keyboard(struct wb_server *server,
struct wb_keyboard *keyboard =
calloc(1, sizeof(struct wb_keyboard));
keyboard->server = server;
#if WLR_CHECK_VERSION(0, 16, 0)
keyboard->keyboard = wlr_keyboard_from_input_device(device);
#else
keyboard->device = device;
keyboard->keyboard = device->keyboard;
#endif
/* We need to prepare an XKB keymap and assign it to the keyboard. */
struct xkb_rule_names *rules = malloc(sizeof(struct xkb_rule_names));
@ -287,11 +242,7 @@ static void handle_new_keyboard(struct wb_server *server,
keyboard->key.notify = keyboard_handle_key;
wl_signal_add(&keyboard->keyboard->events.key, &keyboard->key);
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_seat_set_keyboard(server->seat->seat, keyboard->keyboard);
#else
wlr_seat_set_keyboard(server->seat->seat, keyboard->device);
#endif
/* And add the keyboard to our list of keyboards */
wl_list_insert(&server->seat->keyboards, &keyboard->link);
@ -385,8 +336,5 @@ void wb_seat_destroy(struct wb_seat *seat) {
wl_list_remove(&seat->keyboards);
wl_list_remove(&seat->request_set_primary_selection.link);
wl_list_remove(&seat->request_set_selection.link);
#if !WLR_CHECK_VERSION(0, 16, 0)
wlr_seat_destroy(seat->seat);
#endif
free(seat);
}

View file

@ -14,7 +14,11 @@ bool wb_create_backend(struct wb_server* server) {
* 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. */
#if ! WLR_CHECK_VERSION(0, 13, 0) || WLR_CHECK_VERSION(0, 17, 0)
server->backend = wlr_backend_autocreate(server->wl_display, NULL);
#else
server->backend = wlr_backend_autocreate(server->wl_display);
#endif
if (server->backend == NULL) {
wlr_log(WLR_ERROR, "%s", _("Failed to create wlr_backend"));
return false;
@ -44,9 +48,7 @@ bool wb_create_backend(struct wb_server* server) {
server->compositor = wlr_compositor_create(server->wl_display,
server->renderer);
#if WLR_CHECK_VERSION(0, 16, 0)
server->subcompositor = wlr_subcompositor_create(server->wl_display);
#endif
server->output_layout = wlr_output_layout_create();
server->seat = wb_seat_create(server);
server->cursor = wb_cursor_create(server);
@ -112,15 +114,10 @@ bool wb_start_server(struct wb_server* server) {
bool wb_terminate(struct wb_server* server) {
wb_cursor_destroy(server->cursor);
wl_list_remove(&server->new_xdg_decoration.link); /* wb_decoration_destroy */
#if !WLR_CHECK_VERSION(0, 16, 0)
wb_seat_destroy(server->seat);
#endif
deinit_config(server->config);
wl_display_destroy_clients(server->wl_display);
wl_display_destroy(server->wl_display);
#if WLR_CHECK_VERSION(0, 16, 0)
wb_seat_destroy(server->seat);
#endif
wlr_output_layout_destroy(server->output_layout);
wlr_log(WLR_INFO, "%s", _("Display destroyed"));

View file

@ -6,18 +6,11 @@ struct wb_view *get_view_at(
/* This returns the topmost node in the scene at the given layout coords.
* we only care about surface nodes as we are specifically looking for a
* surface in the surface tree of a wb_view. */
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_node *node =
wlr_scene_node_at(&server->scene->tree.node, lx, ly, sx, sy);
if (node == NULL || node->type != WLR_SCENE_NODE_BUFFER) {
#else
struct wlr_scene_node *node =
wlr_scene_node_at(&server->scene->node, lx, ly, sx, sy);
if (node == NULL || node->type != WLR_SCENE_NODE_SURFACE) {
#endif
return NULL;
}
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
struct wlr_scene_surface *scene_surface =
wlr_scene_surface_from_buffer(scene_buffer);
@ -26,23 +19,13 @@ struct wb_view *get_view_at(
}
*surface = scene_surface->surface;
#else
*surface = wlr_scene_surface_from_node(node)->surface;
#endif
/* Find the node corresponding to the wb_view at the root of this
* surface tree, it is the only one for which we set the data field. */
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_tree *tree = node->parent;
while (tree != NULL && tree->node.data == NULL) {
tree = tree->node.parent;
}
return tree->node.data;
#else
while (node != NULL && node->data == NULL) {
node = node->parent;
}
return node->data;
#endif
}
void focus_view(struct wb_view *view, struct wlr_surface *surface) {
@ -71,28 +54,16 @@ void focus_view(struct wb_view *view, struct wlr_surface *surface) {
*/
struct wlr_xdg_surface *previous =
wlr_xdg_surface_from_wlr_surface(prev_surface);
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_activated(previous->toplevel, false);
#else
wlr_xdg_toplevel_set_activated(previous, false);
#endif
}
/* Move the view to the front */
if (!server->seat->focused_layer) {
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_scene_node_raise_to_top(&view->scene_tree->node);
#else
wlr_scene_node_raise_to_top(view->scene_node);
#endif
}
wl_list_remove(&view->link);
wl_list_insert(&server->views, &view->link);
/* Activate the new surface */
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_activated(view->xdg_toplevel, true);
#else
wlr_xdg_toplevel_set_activated(view->xdg_surface, true);
#endif
/*
* Tell the seat to have the keyboard enter this surface. wlroots will keep
* track of this and automatically send key events to the appropriate
@ -147,21 +118,12 @@ static void xdg_toplevel_map(struct wl_listener *listener, void *data) {
if (view->current_position.height > TITLEBAR_HEIGHT &&
view->current_position.height > TITLEBAR_HEIGHT *
(usable_area.width / usable_area.height)) {
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(view->xdg_toplevel,
view->current_position.width, view->current_position.height);
#else
wlr_xdg_toplevel_set_size(view->xdg_surface,
view->current_position.width, view->current_position.height);
#endif
focus_view(view, view->xdg_toplevel->base->surface);
}
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_scene_node_set_position(&view->scene_tree->node,
#else
wlr_scene_node_set_position(view->scene_node,
#endif
view->current_position.x, view->current_position.y);
}
@ -174,11 +136,7 @@ static void xdg_toplevel_unmap(struct wl_listener *listener, void *data) {
/* Focus the next view, if any. */
struct wb_view *next_view = wl_container_of(view->link.next, next_view, link);
#if WLR_CHECK_VERSION(0, 16, 0)
if (next_view && next_view->scene_tree && next_view->scene_tree->node.enabled) {
#else
if (next_view && next_view->scene_node && next_view->scene_node->state.enabled) {
#endif
wlr_log(WLR_INFO, "%s: %s", _("Focusing next view"),
next_view->xdg_toplevel->app_id);
focus_view(next_view, next_view->xdg_toplevel->base->surface);
@ -244,17 +202,10 @@ static void xdg_toplevel_request_maximize(struct wl_listener *listener, void *da
view->current_position.x = view->previous_position.x;
view->current_position.y = view->previous_position.y;
}
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(view->xdg_toplevel, usable_area.width, usable_area.height);
wlr_xdg_toplevel_set_maximized(view->xdg_toplevel, !is_maximized);
wlr_scene_node_set_position(&view->scene_tree->node,
view->current_position.x, view->current_position.y);
#else
wlr_xdg_toplevel_set_size(view->xdg_surface, usable_area.width, usable_area.height);
wlr_xdg_toplevel_set_maximized(view->xdg_surface, !is_maximized);
wlr_scene_node_set_position(view->scene_node,
view->current_position.x, view->current_position.y);
#endif
}
static void xdg_toplevel_request_minimize(struct wl_listener *listener, void *data) {
@ -270,11 +221,7 @@ static void xdg_toplevel_request_minimize(struct wl_listener *listener, void *da
struct wb_view *parent_view = wl_container_of(view->link.prev, parent_view, link);
struct wb_view *previous_view = wl_container_of(parent_view->link.prev, previous_view, link);
focus_view(previous_view, previous_view->xdg_toplevel->base->surface);
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_scene_node_set_position(&view->scene_tree->node,
#else
wlr_scene_node_set_position(view->scene_node,
#endif
view->current_position.x, view->current_position.y);
}
@ -340,13 +287,9 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
struct wlr_output *wlr_output = wlr_output_layout_output_at(
view->server->output_layout,
#if WLR_CHECK_VERSION(0, 16, 0)
view->current_position.x + popup->current.geometry.x,
view->current_position.y + popup->current.geometry.y);
#else
view->current_position.x + popup->geometry.x,
view->current_position.y + popup->geometry.y);
#endif
if (!wlr_output) return;
struct wb_output *output = wlr_output->data;
@ -377,15 +320,9 @@ static void handle_new_xdg_surface(struct wl_listener *listener, void *data) {
if (wlr_surface_is_xdg_surface(xdg_surface->popup->parent)) {
struct wlr_xdg_surface *parent = wlr_xdg_surface_from_wlr_surface(
xdg_surface->popup->parent);
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_tree *parent_tree = parent->data;
xdg_surface->data = wlr_scene_xdg_surface_create(
parent_tree, xdg_surface);
#else
struct wlr_scene_node *parent_node = parent->data;
xdg_surface->data = wlr_scene_xdg_surface_create(
parent_node, xdg_surface);
#endif
}
/* The scene graph doesn't currently unconstrain popups, so keep going */
/* return; */
@ -398,9 +335,6 @@ static void handle_new_xdg_surface(struct wl_listener *listener, void *data) {
calloc(1, sizeof(struct wb_view));
view->server = server;
view->xdg_toplevel = xdg_surface->toplevel;
#if !WLR_CHECK_VERSION(0, 16, 0)
view->xdg_surface = xdg_surface;
#endif
/* Listen to the various events it can emit */
view->map.notify = xdg_toplevel_map;
@ -413,17 +347,10 @@ static void handle_new_xdg_surface(struct wl_listener *listener, void *data) {
wl_signal_add(&xdg_surface->events.new_popup, &view->new_popup);
if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
#if WLR_CHECK_VERSION(0, 16, 0)
view->scene_tree = wlr_scene_xdg_surface_create(
&view->server->scene->tree, view->xdg_toplevel->base);
view->scene_tree->node.data = view;
xdg_surface->data = view->scene_tree;
#else
view->scene_node = wlr_scene_xdg_surface_create(
&view->server->scene->node, view->xdg_toplevel->base);
view->scene_node->data = view;
xdg_surface->data = view->scene_node;
#endif
struct wlr_xdg_toplevel *toplevel = view->xdg_toplevel;
view->request_fullscreen.notify = xdg_toplevel_request_fullscreen;
@ -442,12 +369,8 @@ static void handle_new_xdg_surface(struct wl_listener *listener, void *data) {
}
void init_xdg_shell(struct wb_server *server) {
#if WLR_CHECK_VERSION(0, 16, 0)
/* xdg-shell version 3 */
server->xdg_shell = wlr_xdg_shell_create(server->wl_display, 3);
#else
server->xdg_shell = wlr_xdg_shell_create(server->wl_display);
#endif
server->new_xdg_surface.notify = handle_new_xdg_surface;
wl_signal_add(&server->xdg_shell->events.new_surface, &server->new_xdg_surface);
}