aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/wm
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/wm')
-rw-r--r--src/cmd/wm/arg.c0
-rw-r--r--src/cmd/wm/client.c274
-rw-r--r--src/cmd/wm/config.h70
-rw-r--r--src/cmd/wm/input.c316
-rw-r--r--src/cmd/wm/layer.c107
-rw-r--r--src/cmd/wm/main.c177
-rw-r--r--src/cmd/wm/monitor.c386
-rwxr-xr-xsrc/cmd/wm/protocol/sync6
-rw-r--r--src/cmd/wm/protocol/wlr-layer-shell-unstable-v1.xml390
-rw-r--r--src/cmd/wm/render.c160
-rw-r--r--src/cmd/wm/rules.mk62
-rw-r--r--src/cmd/wm/util.c99
-rw-r--r--src/cmd/wm/wlr-layer-shell-unstable-v1-protocol.c93
-rw-r--r--src/cmd/wm/wlr-layer-shell-unstable-v1-protocol.h564
-rw-r--r--src/cmd/wm/wm.h350
-rw-r--r--src/cmd/wm/xdg-shell-protocol.c181
-rw-r--r--src/cmd/wm/xdg-shell-protocol.h1676
-rw-r--r--src/cmd/wm/xdg.c118
18 files changed, 5029 insertions, 0 deletions
diff --git a/src/cmd/wm/arg.c b/src/cmd/wm/arg.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/cmd/wm/arg.c
diff --git a/src/cmd/wm/client.c b/src/cmd/wm/client.c
new file mode 100644
index 0000000..5e0927a
--- /dev/null
+++ b/src/cmd/wm/client.c
@@ -0,0 +1,274 @@
+#include "wm.h"
+
+static char broken[] = "broken";
+
+// -----------------------------------------------------------------------
+// scripts
+
+static inline
+void
+grab_client(void)
+{
+ if(server.cursor.mode != CursorNormal)
+ return;
+ if(!(server.grab.client = client_at(server.cursor.dot->x, server.cursor.dot->y)))
+ return;
+
+ floating(server.grab.client, 1);
+}
+
+void
+move_client(Arg *arg)
+{
+ grab_client();
+ server.cursor.mode = CursorMove;
+
+ server.grab.x = server.cursor.dot->x - server.grab.client->geometry.x;
+ server.grab.y = server.cursor.dot->y - server.grab.client->geometry.y;
+ wlr_xcursor_manager_set_cursor_image(server.cursor.manager, "fleur", server.cursor.dot);
+}
+
+void
+float_client(Arg *arg)
+{
+ Client *client = selected_client();
+ wlr_log(WLR_DEBUG, "client selected = %lx", (uintptr)client);
+ if(!client)
+ return;
+
+ floating(client, client->isfloating ? 0 : 1);
+}
+
+void
+resize_client(Arg *arg)
+{
+ double x, y;
+ struct wlr_box geometry;
+
+ grab_client();
+ server.cursor.mode = CursorResize;
+
+ wlr_xdg_surface_get_geometry(server.grab.client->xdg, &geometry);
+
+ x = server.grab.client->geometry.x + geometry.x + geometry.width;
+ y = server.grab.client->geometry.y + geometry.y + geometry.height;
+
+ server.grab.x = server.cursor.dot->x - x;
+ server.grab.y = server.cursor.dot->y - y;
+
+ server.grab.box = geometry;
+ server.grab.box.x += server.grab.client->geometry.x;
+ server.grab.box.y += server.grab.client->geometry.y;
+}
+
+// -----------------------------------------------------------------------
+// core
+
+static inline
+void
+activate(struct wlr_surface *surface, int state)
+{
+}
+
+void
+focus(Client *client, int lift)
+{
+ struct wlr_xdg_surface *xdg;
+ struct wlr_surface *old, *new;
+ struct wlr_keyboard *keyboard;
+
+ if(!client) {
+ wlr_seat_keyboard_notify_clear_focus(server.input.seat);
+ return;
+ }
+
+ old = server.input.seat->keyboard_state.focused_surface;
+
+ if(lift) {
+ wl_list_remove(&client->stack);
+ wl_list_insert(&server.client.stack, &client->stack);
+ }
+
+ new = client->xdg->surface;
+ if(old==new)
+ return;
+
+ wl_list_remove(&client->focus);
+ wl_list_insert(&server.client.focus, &client->focus);
+ server.monitor.selected = client->monitor;
+ client->isurgent = 0;
+
+ if(old) {
+ if(wlr_surface_is_xdg_surface(old)) {
+ xdg = wlr_xdg_surface_from_wlr_surface(old);
+ wlr_xdg_toplevel_set_activated(xdg, false);
+ }
+ }
+
+ keyboard = wlr_seat_get_keyboard(server.input.seat);
+
+ wlr_seat_keyboard_notify_enter(server.input.seat, new,
+ keyboard->keycodes,
+ keyboard->num_keycodes,
+ &keyboard->modifiers
+ );
+
+ wlr_xdg_toplevel_set_activated(client->xdg, true);
+}
+
+Client*
+client_at(double x, double y)
+{
+ Client *client;
+ wl_list_for_each(client, &server.client.stack, stack)
+ if(VISIBLE_ON(client, client->monitor) && wlr_box_contains_point(&client->geometry, x, y))
+ return client;
+ return nil;
+}
+
+static
+int
+has(Client *client, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy)
+{
+ double x, y, vsx = lx - client->geometry.x, vsy = ly - client->geometry.y;
+ struct wlr_surface *find = nil;
+
+ find = wlr_xdg_surface_surface_at(client->xdg, vsx, vsy, &x, &y);
+ if(find) {
+ *sx = x;
+ *sy = y;
+ *surface = find;
+ return true;
+ }
+
+ return false;
+}
+
+struct wlr_surface *
+client_surface_at(Client *client, double cx, double cy, double *sx, double *sy)
+{
+ return wlr_xdg_surface_surface_at(client->xdg, cx, cy, sx, sy);
+}
+
+
+static
+void
+constrain(Client *client, struct wlr_box *box)
+{
+ client->geometry.width = MAX(1, client->geometry.width);
+ client->geometry.height = MAX(1, client->geometry.height);
+
+ if(client->geometry.x >= box->x + box->width)
+ client->geometry.x = box->x + box->width - client->geometry.width;
+ if(client->geometry.y >= box->y + box->height)
+ client->geometry.y = box->y + box->height - client->geometry.height;
+ if(client->geometry.x + client->geometry.width + 2*client->border <= box->x)
+ client->geometry.x = box->x;
+ if(client->geometry.y + client->geometry.height + 2*client->border <= box->y)
+ client->geometry.y = box->y;
+}
+
+void
+resize(Client *client, int x, int y, int w, int h, int interact)
+{
+ struct wlr_box *box = interact ? &server.monitor.geometry : &client->monitor->window;
+
+ client->geometry.x = x;
+ client->geometry.y = y;
+ client->geometry.width = w;
+ client->geometry.height = h;
+
+ constrain(client, box);
+
+ client->resize = wlr_xdg_toplevel_set_size(client->xdg,
+ client->geometry.width - 2*client->border,
+ client->geometry.height - 2*client->border
+ );
+}
+
+void
+attach(Client *client, Monitor *monitor, uint tags)
+{
+ Monitor *old = client->monitor;
+ if(old == monitor)
+ return;
+
+ client->monitor = monitor;
+
+ if(old) {
+ wlr_surface_send_leave(client->xdg->surface, old->output);
+ arrange(old);
+ }
+
+ if(monitor) {
+ /* make sure window actually overlaps with the monitor */
+ constrain(client, &monitor->geometry);
+ wlr_surface_send_enter(client->xdg->surface, monitor->output);
+ client->tags = tags ? tags : monitor->tag.set[monitor->tag.selected];
+ arrange(monitor);
+ }
+
+ focus(focused_client(server.monitor.selected), 1);
+}
+
+void
+rules(Client *client)
+{
+ /* rule matching */
+ Rule *rule;
+ uint i, tags;
+ char *id, *title;
+ Monitor *monitor, *it;
+
+ monitor = server.monitor.selected;
+
+ if (!(id=client->xdg->toplevel->app_id))
+ id = broken;
+ if (!(title=client->xdg->toplevel->title))
+ title = broken;
+
+ for(tags=0, rule=cfg·rule; rule != cfg·endrule; ++rule) {
+ if ((!rule->title || strstr(title, rule->title))
+ && (!rule->id || strstr(id, rule->id))) {
+ client->isfloating = rule->isfloating;
+ tags |= rule->tags;
+ i = 0;
+ wl_list_for_each(it, &server.monitor.list, link)
+ if(rule->monitor == i++)
+ monitor = it;
+ }
+ }
+
+ attach(client, monitor, tags);
+}
+
+void
+floating(Client *client, int state)
+{
+ wlr_log(WLR_DEBUG, "client %lx, floating = %d", (uintptr)client, state);
+ client->isfloating = state;
+ arrange(client->monitor);
+}
+
+Client *
+selected_client(void)
+{
+ Client *client = wl_container_of(server.client.focus.next, client, focus);
+ if(wl_list_empty(&server.client.focus) || !VISIBLE_ON(client, server.monitor.selected))
+ return nil;
+ return client;
+}
+
+void
+request_activate(struct wl_listener *l, void *data)
+{
+ struct wlr_xdg_activation_v1_request_activate_event *event = data;
+ Client *client;
+
+ if (!wlr_surface_is_xdg_surface(event->surface))
+ return;
+
+ client = wlr_xdg_surface_from_wlr_surface(event->surface)->data;
+ if(client != selected_client())
+ client->isurgent = 1;
+}
diff --git a/src/cmd/wm/config.h b/src/cmd/wm/config.h
new file mode 100644
index 0000000..1f5ba85
--- /dev/null
+++ b/src/cmd/wm/config.h
@@ -0,0 +1,70 @@
+/* appearance */
+CONFIG(int, sloppyfocus, 1);
+CONFIG(int, borderpixel, 1);
+CONFIG(float, rootcolor[], {0.3, 0.3, 0.3, 1.0});
+CONFIG(float, bordercolor[], {0.5, 0.5, 0.5, 1.0});
+CONFIG(float, focuscolor[], {1.0, 0.0, 0.0, 1.0});
+
+/* sampling */
+CONFIG(int, repeat_rate, 25);
+CONFIG(int, repeat_delay, 600);
+
+/* tags */
+CONFIG(char*, tags[], { "1", "2", "3", "4", "5", "6", "7", "8", "9" });
+
+/* application specific rules */
+CONFIG(Rule, rule[], {
+ /* app_id title tags mask isfloating monitor */
+ /* examples:
+ { "Gimp", nil, 0, 1, -1 },
+ { "firefox", nil, 1 << 8, 0, -1 },
+ */
+});
+CONFIG(Rule*, endrule, arrend(cfg·rule));
+
+/* commands */
+CONFIG(char*, termcommand[], { "alacritty", nil });
+CONFIG(char*, menucommand[], { "dmenu-wl_run", nil });
+
+/* layouts */
+CONFIG(Layout, layouts[], {
+ /* symbol arrange */
+ { "[]=", tile },
+ { "><>", nil }, /* no layout function means floating behavior */
+});
+CONFIG(Layout*, endlayout, arrend(cfg·layouts));
+
+/* monitors
+ * The order in which monitors are defined determines their position.
+ * non-configured monitors are always added to the left. */
+CONFIG(MonitorRule, monitorrule[], {
+ /* name layout, x, y, scale, transform master */
+ { nil, &cfg·layouts[0], 0, 0, 1, WL_OUTPUT_TRANSFORM_NORMAL, {0.55, 1} },
+});
+CONFIG(MonitorRule*, endmonitorrule, arrend(cfg·monitorrule));
+
+/* keybindings */
+#define MODKEY WLR_MODIFIER_ALT
+#define MOD(a) WLR_MODIFIER_##a
+#define KEY(a) XKB_KEY_##a
+
+CONFIG(Key, binding[], {
+ /* modifier key function argument */
+ { MODKEY, KEY(Return), spawn, {.v = cfg·termcommand} },
+ { MODKEY, KEY(d), spawn, {.v = cfg·menucommand} },
+ { MODKEY|MOD(SHIFT), KEY(Q), quit, {.v = nil} },
+});
+CONFIG(Key*, endbinding, arrend(cfg·binding));
+
+#undef MOD
+#undef KEY
+
+/* mouse buttons */
+CONFIG(Button, button[], {
+ { MODKEY, BTN_LEFT, move_client, {0} },
+ { MODKEY, BTN_MIDDLE, float_client, {0} },
+ { MODKEY, BTN_RIGHT, resize_client, {0} },
+});
+CONFIG(Button*, endbutton, arrend(cfg·button));
+
+#undef MODKEY
diff --git a/src/cmd/wm/input.c b/src/cmd/wm/input.c
new file mode 100644
index 0000000..4c6bfd4
--- /dev/null
+++ b/src/cmd/wm/input.c
@@ -0,0 +1,316 @@
+#include "wm.h"
+
+// -----------------------------------------------------------------------
+// keyboard
+
+static
+void
+keymodifier(struct wl_listener *l, void *data)
+{
+ Keyboard *keyboard = wl_container_of(l, keyboard, event.modify);
+
+ wlr_seat_set_keyboard(server.input.seat, keyboard->device);
+ wlr_seat_keyboard_notify_modifiers(server.input.seat, &keyboard->device->keyboard->modifiers);
+}
+
+static
+int
+keybinding(uint32 modifier, xkb_keysym_t sym)
+{
+ Key *key;
+
+ for(key=cfg·binding; key!=cfg·endbinding; ++key) {
+ if(modifier == key->modifier && sym == key->sym && key->action){
+ key->action(&key->arg);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static
+void
+keypress(struct wl_listener *l, void *data)
+{
+ int i,h,n;
+ uint32 keycode, modifier;
+ const xkb_keysym_t *syms;
+ struct Keyboard *keyboard = wl_container_of(l, keyboard, event.press);
+ struct wlr_event_keyboard_key *event = data;
+
+ keycode = event->keycode + 8;
+
+ h = 0;
+ n = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, keycode, &syms);
+
+ modifier = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
+ if(event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
+ for(i=0; i<n; i++)
+ h=keybinding(modifier, syms[i]);
+ }
+
+ if(!h) {
+ wlr_seat_set_keyboard(server.input.seat, keyboard->device);
+ wlr_seat_keyboard_notify_key(server.input.seat, event->time_msec, event->keycode, event->state);
+ }
+}
+
+static
+void
+free_keyboard(struct wl_listener *l, void *data)
+{
+ struct wlr_input_device *device = data;
+ Keyboard *keyboard = device->data;
+
+ /* XXX: debug
+ wl_list_remove(&keyboard->link);
+ wl_list_remove(&keyboard->event.modify.link);
+ wl_list_remove(&keyboard->event.press.link);
+ wl_list_remove(&keyboard->event.destroy.link);
+
+ free(keyboard);
+ */
+}
+
+static
+void
+make_keyboard(struct wlr_input_device *device)
+{
+ Keyboard *keyboard;
+ struct xkb_context *context;
+ struct xkb_keymap *keymap;
+
+ keyboard = device->data = calloc(1, sizeof(*keyboard));
+ keyboard->device = device;
+
+ context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+ keymap = xkb_keymap_new_from_names(context, nil, XKB_KEYMAP_COMPILE_NO_FLAGS);
+
+ wlr_keyboard_set_keymap(device->keyboard, keymap);
+
+ xkb_keymap_unref(keymap);
+ xkb_context_unref(context);
+
+ wlr_keyboard_set_repeat_info(device->keyboard, cfg·repeat_rate, cfg·repeat_delay);
+
+ keyboard->event.modify.notify = keymodifier;
+ wl_signal_add(&device->keyboard->events.modifiers, &keyboard->event.modify);
+
+ keyboard->event.press.notify = keypress;
+ wl_signal_add(&device->keyboard->events.key, &keyboard->event.press);
+
+ keyboard->event.destroy.notify = free_keyboard;
+ wl_signal_add(&device->keyboard->events.destroy, &keyboard->event.destroy);
+
+ wlr_seat_set_keyboard(server.input.seat, device);
+
+ wl_list_insert(&server.input.keyboards, &keyboard->link);
+}
+
+// -----------------------------------------------------------------------
+// cursor
+
+static
+void
+focus_surface(Client *client, struct wlr_surface *surface, double sx, double sy, uint32 time)
+{
+ struct timespec now;
+ int lift = time;
+
+ if(client && !surface)
+ surface = client->xdg->surface;
+
+ if(!surface){
+ wlr_seat_pointer_notify_clear_focus(server.input.seat);
+ return;
+ }
+
+ if(!time) {
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ time = now.tv_sec * 1000 + now.tv_nsec / 1000000;
+ }
+
+ if(surface == server.input.seat->pointer_state.focused_surface) {
+ wlr_seat_pointer_notify_motion(server.input.seat, time, sx, sy);
+ return;
+ }
+
+ wlr_seat_pointer_notify_enter(server.input.seat, surface, sx, sy);
+
+ if(cfg·sloppyfocus && lift)
+ focus(client, 0);
+}
+
+void
+notify_move(uint32 time)
+{
+ double sx, sy;
+ Client *client;
+ struct wlr_box box;
+ struct wlr_surface *surface;
+
+ if(time) {
+ wlr_idle_notify_activity(server.input.idle, server.input.seat);
+ if(cfg·sloppyfocus)
+ server.monitor.selected = monitor_at(server.cursor.dot->x, server.cursor.dot->y);
+ }
+
+ if(server.cursor.mode == CursorMove) {
+ resize(server.grab.client,
+ server.cursor.dot->x - server.grab.x,
+ server.cursor.dot->y - server.grab.y,
+ server.grab.client->geometry.width,
+ server.grab.client->geometry.height,
+ 1
+ );
+ return;
+ }
+
+ if(server.cursor.mode == CursorResize) {
+ wlr_xdg_surface_get_geometry(server.grab.client->xdg, &box);
+ resize(server.grab.client,
+ server.grab.box.x - box.x,
+ server.grab.box.y - box.y,
+ server.cursor.dot->x - server.grab.x - server.grab.box.x,
+ server.cursor.dot->y - server.grab.y - server.grab.box.y,
+ 1
+ );
+ return;
+ }
+
+ /* otherwise, find the client under the pointer and send the event along. */
+ client = client_at(server.cursor.dot->x, server.cursor.dot->y);
+ if(!client) {
+ wlr_xcursor_manager_set_cursor_image(server.cursor.manager, "left_ptr", server.cursor.dot);
+ return;
+ }
+
+ surface = client_surface_at(
+ client,
+ server.cursor.dot->x - client->geometry.x - client->border,
+ server.cursor.dot->y - client->geometry.y - client->border,
+ &sx, &sy
+ );
+
+ focus_surface(client, surface, sx, sy, time);
+}
+
+void
+cursor_move(struct wl_listener *l, void *data)
+{
+ struct wlr_event_pointer_motion *event = data;
+ wlr_cursor_move(server.cursor.dot, event->device, event->delta_x, event->delta_y);
+ notify_move(event->time_msec);
+}
+
+void
+cursor_move_abs(struct wl_listener *l, void *data)
+{
+ struct wlr_event_pointer_motion_absolute *event = data;
+ wlr_cursor_warp_absolute(server.cursor.dot, event->device, event->x, event->y);
+ notify_move(event->time_msec);
+}
+
+void
+cursor_button(struct wl_listener *l, void *data)
+{
+ Client *client;
+ uint32 modifier;
+ Button *button;
+ struct wlr_keyboard *keyboard;
+ struct wlr_event_pointer_button *event = data;
+
+ wlr_idle_notify_activity(server.input.idle, server.input.seat);
+
+ switch(event->state) {
+ case WLR_BUTTON_PRESSED:
+ if((client=client_at(server.cursor.dot->x, server.cursor.dot->y)))
+ focus(client,1);
+
+ keyboard = wlr_seat_get_keyboard(server.input.seat);
+ modifier = wlr_keyboard_get_modifiers(keyboard);
+ for(button=cfg·button; button != cfg·endbutton; ++button) {
+ if(modifier == button->modifier && event->button == button->code && button->function) {
+ button->function(&button->arg);
+ return;
+ }
+ }
+ break;
+ case WLR_BUTTON_RELEASED:
+ if(server.cursor.mode != CursorNormal) {
+ wlr_xcursor_manager_set_cursor_image(server.cursor.manager, "left_ptr", server.cursor.dot);
+ server.cursor.mode = CursorNormal;
+ /* Drop the window off on its new monitor */
+ server.monitor.selected = monitor_at(server.cursor.dot->x, server.cursor.dot->y);
+ attach(server.grab.client, server.monitor.selected, 0);
+ return;
+ }
+ }
+
+ wlr_seat_pointer_notify_button(server.input.seat, event->time_msec, event->button, event->state);
+}
+
+void
+cursor_axis(struct wl_listener *l, void *data)
+{
+ struct wlr_event_pointer_axis *event = data;
+ /* Notify the client with pointer focus of the axis event. */
+ wlr_seat_pointer_notify_axis(server.input.seat,
+ event->time_msec, event->orientation, event->delta,
+ event->delta_discrete, event->source);
+}
+
+void
+cursor_frame(struct wl_listener *l, void *data)
+{
+ wlr_seat_pointer_notify_frame(server.input.seat);
+}
+
+void
+request_cursor(struct wl_listener *l, void *data)
+{
+ struct wlr_seat_pointer_request_set_cursor_event *event = data;
+ struct wlr_seat_client *focused = server.input.seat->pointer_state.focused_client;
+ if(focused == event->seat_client)
+ wlr_cursor_set_surface(server.cursor.dot, event->surface, event->hotspot_x, event->hotspot_y);
+}
+
+void
+request_set_selection(struct wl_listener *l, void *data)
+{
+ struct wlr_seat_request_set_selection_event *event = data;
+ wlr_seat_set_selection(server.input.seat, event->source, event->serial);
+}
+
+static
+void
+make_pointer(struct wlr_input_device *device)
+{
+ wlr_cursor_attach_input_device(server.cursor.dot, device);
+}
+
+// -----------------------------------------------------------------------
+// generic input
+
+void
+make_input(struct wl_listener *l, void *data)
+{
+ uint32 capability;
+ struct wlr_input_device *device = data;
+
+ switch(device->type) {
+ case WLR_INPUT_DEVICE_KEYBOARD:
+ make_keyboard(device);
+ break;
+ case WLR_INPUT_DEVICE_POINTER:
+ make_pointer(device);
+ /* fallthrough */
+ default:
+ break;
+ }
+
+ capability = WL_SEAT_CAPABILITY_POINTER;
+ if(!wl_list_empty(&server.input.keyboards))
+ capability |= WL_SEAT_CAPABILITY_KEYBOARD;
+ wlr_seat_set_capabilities(server.input.seat, capability);
+}
diff --git a/src/cmd/wm/layer.c b/src/cmd/wm/layer.c
new file mode 100644
index 0000000..bfac744
--- /dev/null
+++ b/src/cmd/wm/layer.c
@@ -0,0 +1,107 @@
+#include "wm.h"
+
+static
+void
+map(struct wl_listener *l, void *data)
+{
+ Layer *layer = wl_container_of(l, layer, event.map);
+ wlr_surface_send_enter(layer->surface->surface, layer->surface->output);
+ notify_move(0);
+}
+
+static
+void
+finalize(Layer *layer)
+{
+ layer->surface->mapped = 0;
+ if (layer->surface->surface == server.input.seat->keyboard_state.focused_surface)
+ focus(selected_client(), 1);
+ notify_move(0);
+}
+
+static
+void
+unmap(struct wl_listener *l, void *data)
+{
+ Layer *layer = wl_container_of(l, layer, event.unmap);
+ finalize(layer);
+}
+
+static
+void
+destroy(struct wl_listener *l, void *data)
+{
+ Monitor *monitor;
+ Layer *layer = wl_container_of(l, layer, event.destroy);
+
+ if (layer->surface->mapped)
+ finalize(layer);
+
+ wl_list_remove(&layer->link);
+ wl_list_remove(&layer->event.destroy.link);
+ wl_list_remove(&layer->event.map.link);
+ wl_list_remove(&layer->event.unmap.link);
+ wl_list_remove(&layer->event.commit.link);
+
+ if(layer->surface->output) {
+ monitor = layer->surface->output->data;
+ if(monitor)
+ stratify(monitor);
+ layer->surface->output = nil;
+ }
+ free(layer);
+}
+
+static
+void
+commit(struct wl_listener *l, void *data)
+{
+ Monitor *monitor;
+ Layer *layer = wl_container_of(l, layer, event.commit);
+ struct wlr_layer_surface_v1 *surface = layer->surface;
+ struct wlr_output *output = surface->output;
+
+ if(!output)
+ return;
+
+ monitor = output->data;
+ stratify(monitor);
+
+ if (layer->type != surface->current.layer) {
+ wl_list_remove(&layer->link);
+ wl_list_insert(&monitor->layer[surface->current.layer], &layer->link);
+ layer->type = surface->current.layer;
+ }
+}
+
+void
+make_layer_surface(struct wl_listener *l, void *data)
+{
+ Layer *layer;
+ Monitor *monitor;
+ struct wlr_layer_surface_v1_state state;
+ struct wlr_layer_surface_v1 *surface = data;
+
+ if(!surface->output)
+ surface->output = server.monitor.selected->output;
+
+ layer = surface->data = calloc(1, sizeof(*layer));
+ layer->surface = surface;
+
+ layer->event.map.notify = map;
+ wl_signal_add(&surface->events.map, &layer->event.map);
+ layer->event.unmap.notify = unmap;
+ wl_signal_add(&surface->events.unmap, &layer->event.unmap);
+ layer->event.destroy.notify = destroy;
+ wl_signal_add(&surface->events.destroy, &layer->event.destroy);
+ layer->event.commit.notify = commit;
+ wl_signal_add(&surface->surface->events.commit, &layer->event.commit);
+
+ monitor = surface->output->data;
+ wl_list_insert(&monitor->layer[surface->client_pending.layer], &layer->link);
+
+ state = surface->current;
+ surface->current = surface->client_pending;
+ stratify(monitor);
+ surface->current = state;
+}
diff --git a/src/cmd/wm/main.c b/src/cmd/wm/main.c
new file mode 100644
index 0000000..2607801
--- /dev/null
+++ b/src/cmd/wm/main.c
@@ -0,0 +1,177 @@
+#include "wm.h"
+
+Server server = {
+ .event = {
+ .make_input = { .notify = make_input },
+ .make_monitor = { .notify = make_monitor },
+ .make_xdg_surface = { .notify = make_xdg_surface },
+ .make_layer_surface = { .notify = make_layer_surface },
+
+ .monitor_change = { .notify = monitor_change },
+ .monitor_test = { .notify = monitor_test },
+ .monitor_apply = { .notify = monitor_apply },
+
+ .cursor_move = { .notify = cursor_move },
+ .cursor_move_abs = { .notify = cursor_move_abs },
+ .cursor_button = { .notify = cursor_button },
+ .cursor_axis = { .notify = cursor_axis },
+ .cursor_frame = { .notify = cursor_frame },
+
+ .request_activate = { .notify = request_activate },
+ .request_cursor = { .notify = request_cursor },
+ .request_set_selection = { .notify = request_set_selection },
+ },
+};
+
+// -----------------------------------------------------------------------
+// helper functions
+
+static inline
+void
+init(void)
+{
+ /* compositor initialization */
+ server.display = wl_display_create();
+ server.backend = wlr_backend_autocreate(server.display);
+ server.renderer = wlr_backend_get_renderer(server.backend);
+ server.present = wlr_presentation_create(server.display, server.backend);
+
+ wlr_renderer_init_wl_display(server.renderer, server.display);
+
+ wlr_compositor_create(server.display, server.renderer);
+ wlr_export_dmabuf_manager_v1_create(server.display);
+ wlr_screencopy_manager_v1_create(server.display);
+ wlr_data_control_manager_v1_create(server.display);
+ wlr_data_device_manager_create(server.display);
+ wlr_gamma_control_manager_v1_create(server.display);
+ wlr_primary_selection_v1_device_manager_create(server.display);
+ wlr_viewporter_create(server.display);
+
+ server.activate = wlr_xdg_activation_v1_create(server.display);
+ wl_signal_add(&server.activate->events.request_activate, &server.event.request_activate);
+
+ wlr_data_device_manager_create(server.display);
+
+ server.monitor.layout = wlr_output_layout_create();
+ wl_signal_add(&server.monitor.layout->events.change, &server.event.monitor_change);
+ wlr_xdg_output_manager_v1_create(server.display, server.monitor.layout);
+
+ wl_list_init(&server.monitor.list);
+ wl_signal_add(&server.backend->events.new_output, &server.event.make_monitor);
+
+ server.monitor.manager = wlr_output_manager_v1_create(server.display);
+ wl_signal_add(&server.monitor.manager->events.test, &server.event.monitor_test);
+ wl_signal_add(&server.monitor.manager->events.apply, &server.event.monitor_apply);
+
+ /* shell initialization */
+ wl_list_init(&server.client.list);
+ wl_list_init(&server.client.stack);
+ wl_list_init(&server.client.focus);
+
+ server.shell.xdg = wlr_xdg_shell_create(server.display);
+ wl_signal_add(&server.shell.xdg->events.new_surface, &server.event.make_xdg_surface);
+
+ server.shell.layer = wlr_layer_shell_v1_create(server.display);
+ wl_signal_add(&server.shell.layer->events.new_surface, &server.event.make_layer_surface);
+
+ wlr_server_decoration_manager_set_default_mode(
+ wlr_server_decoration_manager_create(server.display),
+ WLR_SERVER_DECORATION_MANAGER_MODE_SERVER
+ );
+ wlr_xdg_decoration_manager_v1_create(server.display);
+
+ /* input initialization */
+ server.cursor.dot = wlr_cursor_create();
+ wlr_cursor_attach_output_layout(server.cursor.dot, server.monitor.layout);
+
+ server.cursor.manager = wlr_xcursor_manager_create(nil, 24);
+ wlr_xcursor_manager_load(server.cursor.manager, 1);
+
+ wl_signal_add(&server.cursor.dot->events.motion, &server.event.cursor_move);
+ wl_signal_add(&server.cursor.dot->events.motion_absolute, &server.event.cursor_move_abs);
+ wl_signal_add(&server.cursor.dot->events.button, &server.event.cursor_button);
+ wl_signal_add(&server.cursor.dot->events.axis, &server.event.cursor_axis);
+ wl_signal_add(&server.cursor.dot->events.frame, &server.event.cursor_frame);
+
+ wl_list_init(&server.input.keyboards);
+ wl_signal_add(&server.backend->events.new_input, &server.event.make_input);
+
+ server.input.idle = wlr_idle_create(server.display);
+ server.input.seat = wlr_seat_create(server.display, "seat0");
+
+ wl_signal_add(&server.input.seat->events.request_set_cursor, &server.event.request_cursor);
+ wl_signal_add(&server.input.seat->events.request_set_selection, &server.event.request_set_selection);
+}
+
+static inline
+void
+fini(void)
+{
+ wl_display_destroy_clients(server.display);
+
+ wlr_backend_destroy(server.backend);
+ wlr_xcursor_manager_destroy(server.cursor.manager);
+ wlr_output_layout_destroy(server.monitor.layout);
+ wlr_seat_destroy(server.input.seat);
+
+ wl_display_destroy(server.display);
+}
+
+// -----------------------------------------------------------------------
+// main point of entry
+
+int
+usage(void)
+{
+ fprintf(stderr, "usage: %s [-s startup command]\n", argv0);
+ return 1;
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ char *socket, *cmd=nil;
+
+ ARGBEGIN{
+ case 's':
+ cmd = ARGF();
+ break;
+ default:
+ return usage();
+ } ARGEND
+
+ if(argc != 0)
+ return usage();
+
+ wlr_log_init(WLR_DEBUG, nil);
+
+ init();
+
+ if(!(socket=(char*)wl_display_add_socket_auto(server.display))) {
+ wlr_backend_destroy(server.backend);
+ return 1;
+ }
+
+ if(!(wlr_backend_start(server.backend))) {
+ wlr_backend_destroy(server.backend);
+ wl_display_destroy(server.display);
+ return 1;
+ }
+
+ setenv("WAYLAND_DISPLAY", socket, true);
+ if(cmd) {
+ if(fork()==0)
+ execl("/bin/sh", "/bin/sh", "-c", cmd, nil);
+ }
+ wlr_log(WLR_INFO, "Running Wayland compositor on WAYLAND_DISPLAY=%s", socket);
+
+ server.monitor.selected = monitor_at(server.cursor.dot->x, server.cursor.dot->y);
+ wlr_cursor_warp_closest(server.cursor.dot, nil, server.cursor.dot->x, server.cursor.dot->y);
+ wlr_xcursor_manager_set_cursor_image(server.cursor.manager, "left_ptr", server.cursor.dot);
+
+ wl_display_run(server.display); /* event loop */
+
+ fini();
+ return 0;
+}
diff --git a/src/cmd/wm/monitor.c b/src/cmd/wm/monitor.c
new file mode 100644
index 0000000..93073f3
--- /dev/null
+++ b/src/cmd/wm/monitor.c
@@ -0,0 +1,386 @@
+#include "wm.h"
+
+/* callbacks */
+void
+monitor_change(struct wl_listener *l, void *data)
+{
+ Monitor *monitor;
+ struct wlr_output_configuration_v1 *config;
+
+ config = wlr_output_configuration_v1_create();
+ server.monitor.geometry = *wlr_output_layout_get_box(server.monitor.layout, nil);
+
+ wl_list_for_each(monitor, &server.monitor.list, link) {
+ struct wlr_output_configuration_head_v1 *head =
+ wlr_output_configuration_head_v1_create(config, monitor->output);
+
+ monitor->geometry = monitor->window = *wlr_output_layout_get_box(server.monitor.layout, monitor->output);
+
+ stratify(monitor);
+ arrange(monitor);
+
+ head->state.enabled = monitor->output->enabled;
+ head->state.mode = monitor->output->current_mode;
+ head->state.x = monitor->geometry.x;
+ head->state.y = monitor->geometry.y;
+ }
+
+ wlr_output_manager_v1_set_configuration(server.monitor.manager, config);
+}
+
+static
+void
+trylayout(struct wlr_output_configuration_v1 *config, int force)
+{
+ int ok;
+ struct wlr_output_configuration_head_v1 *head;
+
+ ok = 1;
+ wl_list_for_each(head, &config->heads, link) {
+ struct wlr_output *output= head->state.output;
+ wlr_output_enable(output, head->state.enabled);
+ if (head->state.enabled) {
+ if (head->state.mode)
+ wlr_output_set_mode(output, head->state.mode);
+ else
+ wlr_output_set_custom_mode(
+ output,
+ head->state.custom_mode.width,
+ head->state.custom_mode.height,
+ head->state.custom_mode.refresh
+ );
+
+ wlr_output_layout_move(server.monitor.layout, output,
+ head->state.x, head->state.y);
+ wlr_output_set_transform(output, head->state.transform);
+ }
+
+ if(!(ok=wlr_output_test(output)))
+ break;
+ }
+
+ wl_list_for_each(head, &config->heads, link) {
+ if(ok && force)
+ wlr_output_commit(head->state.output);
+ else
+ wlr_output_rollback(head->state.output);
+ }
+
+ if(ok)
+ wlr_output_configuration_v1_send_succeeded(config);
+ else
+ wlr_output_configuration_v1_send_failed(config);
+
+ wlr_output_configuration_v1_destroy(config);
+}
+
+void
+monitor_apply(struct wl_listener *l, void *data)
+{
+ struct wlr_output_configuration_v1 *config = data;
+ trylayout(config, 1);
+}
+
+void
+monitor_test(struct wl_listener *l, void *data)
+{
+ struct wlr_output_configuration_v1 *config = data;
+ trylayout(config, 0);
+}
+
+void
+make_monitor(struct wl_listener *l, void *data)
+{
+ int i;
+ Client *client;
+ Monitor *monitor;
+ MonitorRule *rule;
+ struct wlr_output_mode *mode;
+ struct wlr_output *output = data;
+
+ /*
+ * XXX: needed?
+ if (wl_list_empty(&output->modes))
+ return;
+ */
+
+ monitor = output->data = calloc(1, sizeof(*monitor));
+ monitor->output = output;
+
+ for(i=0; i < arrlen(monitor->layer); i++)
+ wl_list_init(&monitor->layer[i]);
+ monitor->tag.set[0] = monitor->tag.set[1] = 1;
+
+ for(rule=cfg·monitorrule; rule != cfg·endmonitorrule; ++rule) {
+ if(!rule->name || strstr(output->name, rule->name)) {
+ monitor->master.len = rule->master.len;
+ monitor->master.frac = rule->master.frac;
+
+ wlr_output_set_scale(output, rule->scale);
+ wlr_xcursor_manager_load(server.cursor.manager, rule->scale);
+ monitor->layouts[0] = monitor->layouts[1] = monitor->layout = rule->layout;
+
+ wlr_output_set_transform(output, rule->transform);
+ break;
+ }
+ }
+
+ mode = wlr_output_preferred_mode(output);
+ wlr_output_set_mode(output, mode);
+ wlr_output_enable_adaptive_sync(output, true);
+
+ monitor->event.render.notify = render_monitor;
+ wl_signal_add(&output->events.frame, &monitor->event.render);
+ monitor->event.destroy.notify = free_monitor;
+ wl_signal_add(&output->events.destroy, &monitor->event.destroy);
+
+ wlr_output_enable(output, true);
+ if(!wlr_output_commit(output))
+ return;
+
+ wl_list_insert(&server.monitor.list, &monitor->link);
+
+ wlr_output_layout_add(server.monitor.layout, output, rule->x, rule->y);
+ server.monitor.geometry = *wlr_output_layout_get_box(server.monitor.layout, nil);
+
+ /* update the geometries of all monitors */
+ wl_list_for_each(monitor, &server.monitor.list, link) {
+ /* first monitor in the list = most recently added */
+ wl_list_for_each(client, &server.client.list, link) {
+ if(client->isfloating)
+ resize(client, client->geometry.x+monitor->window.width, client->geometry.y,
+ client->geometry.width, client->geometry.height, 0);
+ }
+ return;
+ }
+}
+
+void
+free_monitor(struct wl_listener *l, void *data)
+{
+ int i, len;
+ Client *client;
+ struct wlr_output *output = data;
+ Monitor *monitor = output->data;
+
+ wl_list_remove(&monitor->event.destroy.link);
+ wl_list_remove(&monitor->event.render.link);
+ wl_list_remove(&monitor->link);
+
+ wlr_output_layout_remove(server.monitor.layout, monitor->output);
+
+ for(i=0, len=wl_list_length(&server.monitor.list); i < len; i++) {
+ server.monitor.selected = wl_container_of(server.monitor.list.prev, server.monitor.selected, link);
+ if(server.monitor.selected->output->enabled)
+ break;
+ }
+
+ focus(focused_client(server.monitor.selected), 1);
+
+ /* move closed monitor's clients to newly selected one */
+ wl_list_for_each(client, &server.client.list, link) {
+ if(client->isfloating && client->geometry.x > monitor->geometry.width)
+ resize(client,
+ client->geometry.x - monitor->window.width,
+ client->geometry.y,
+ client->geometry.width,
+ client->geometry.height,
+ 0
+ );
+ if(client->monitor == monitor)
+ attach(client, monitor, client->tags);
+ }
+
+ free(monitor);
+}
+
+/* methods */
+void
+arrange(Monitor *monitor)
+{
+ if(monitor->layout->arrange)
+ monitor->layout->arrange(monitor);
+}
+
+void
+stratum(Monitor *monitor, struct wl_list *list, struct wlr_box *area, int exclusive)
+{
+ Layer *layer;
+ struct wlr_box full = monitor->geometry;
+
+ wl_list_for_each(layer, list, link) {
+ struct wlr_layer_surface_v1 *surface = layer->surface;
+ struct wlr_layer_surface_v1_state *state = &surface->current;
+ struct wlr_box bounds;
+ struct wlr_box box = {
+ .width = state->desired_width,
+ .height = state->desired_height
+ };
+ const uint32 horizontal = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
+ const uint32 vertical = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
+
+ if (exclusive != (state->exclusive_zone > 0))
+ continue;
+
+ bounds = state->exclusive_zone == -1 ? full : *area;
+
+ // horizontal axis
+ if((state->anchor & horizontal) && box.width == 0) {
+ box.x = bounds.x;
+ box.width = bounds.width;
+ } else if((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) {
+ box.x = bounds.x;
+ } else if((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) {
+ box.x = bounds.x + (bounds.width - box.width);
+ } else {
+ box.x = bounds.x + ((bounds.width / 2) - (box.width / 2));
+ }
+
+ // vertical axis
+ if((state->anchor & vertical) && box.height == 0) {
+ box.y = bounds.y;
+ box.height = bounds.height;
+ } else if((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) {
+ box.y = bounds.y;
+ } else if((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) {
+ box.y = bounds.y + (bounds.height - box.height);
+ } else {
+ box.y = bounds.y + ((bounds.height / 2) - (box.height / 2));
+ }
+
+ // margin
+ if((state->anchor & horizontal) == horizontal) {
+ box.x += state->margin.left;
+ box.width -= state->margin.left + state->margin.right;
+ } else if((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) {
+ box.x += state->margin.left;
+ } else if((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) {
+ box.x -= state->margin.right;
+ }
+
+ if((state->anchor & vertical) == vertical) {
+ box.y += state->margin.top;
+ box.height -= state->margin.top + state->margin.bottom;
+ } else if((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) {
+ box.y += state->margin.top;
+ } else if((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) {
+ box.y -= state->margin.bottom;
+ }
+ if(box.width < 0 || box.height < 0) {
+ wlr_layer_surface_v1_close(surface);
+ continue;
+ }
+ layer->geometry = box;
+
+ if (state->exclusive_zone > 0)
+ exclude(area,
+ state->anchor, state->exclusive_zone,
+ state->margin.top, state->margin.right,
+ state->margin.bottom, state->margin.left);
+ wlr_layer_surface_v1_configure(surface, box.width, box.height);
+ }
+}
+
+void
+stratify(Monitor *monitor)
+{
+ int i;
+ Layer *layer;
+ struct wlr_box area = monitor->geometry;
+ uint32_t overlays[] = {
+ ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
+ ZWLR_LAYER_SHELL_V1_LAYER_TOP,
+ };
+ struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(server.input.seat);
+
+ // arrange exclusive surfaces from top->bottom
+ stratum(monitor, &monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &area, 1);
+ stratum(monitor, &monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &area, 1);
+ stratum(monitor, &monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &area, 1);
+ stratum(monitor, &monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &area, 1);
+
+ if(memcmp(&area, &monitor->window, sizeof(area))) {
+ monitor->window = area;
+ arrange(monitor);
+ }
+
+ // arrange non-exlusive surfaces from top->bottom
+ stratum(monitor, &monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &area, 0);
+ stratum(monitor, &monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &area, 0);
+ stratum(monitor, &monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &area, 0);
+ stratum(monitor, &monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &area, 0);
+
+ // find topmost keyboard interactive layer, if such a layer exists
+ for(i = 0; i < arrlen(overlays); i++) {
+ wl_list_for_each_reverse(layer, &monitor->layer[overlays[i]], link) {
+ if (layer->surface->current.keyboard_interactive && layer->surface->mapped) {
+ // Deactivate the focused client.
+ focus(nil, 0);
+ wlr_seat_keyboard_notify_enter(
+ server.input.seat,
+ layer->surface->surface,
+ keyboard->keycodes,
+ keyboard->num_keycodes,
+ &keyboard->modifiers
+ );
+ return;
+ }
+ }
+ }
+}
+
+Client *
+focused_client(Monitor *monitor)
+{
+ Client *client;
+ wl_list_for_each(client, &server.client.focus, focus) {
+ if(VISIBLE_ON(client, monitor))
+ return client;
+ }
+
+ return nil;
+}
+
+void
+tile(Monitor *monitor)
+{
+ Client *client;
+ uint i, n, h, mw, my, ty;
+
+ n = 0;
+ wl_list_for_each(client, &server.client.list, link) {
+ if(VISIBLE_ON(client, monitor) && !client->isfloating)
+ n++;
+ }
+ if(!n) return;
+
+ if(n > monitor->master.len)
+ mw = monitor->master.len ? monitor->window.width * monitor->master.frac : 0;
+ else
+ mw = monitor->window.width;
+
+ i = my = ty = 0;
+ wl_list_for_each(client, &server.client.list, link) {
+ if(!VISIBLE_ON(client,monitor) || client->isfloating || client->isfullscreen)
+ continue;
+ if(i < monitor->master.len) {
+ h = (monitor->window.height - my) / (MIN(n, monitor->master.len) - i);
+ resize(client, monitor->window.x, monitor->window.y + my, mw, h, 0);
+ my += client->geometry.height;
+ } else {
+ h = (monitor->window.height - ty) / (n - i);
+ resize(client, monitor->window.x + mw, monitor->window.y + ty, monitor->window.width - mw, h, 0);
+ ty += client->geometry.height;
+ }
+ i++;
+ }
+}
+
+Monitor *
+monitor_at(double x, double y)
+{
+ struct wlr_output *output = wlr_output_layout_output_at(server.monitor.layout, x, y);
+ return output ? output->data : nil;
+}
diff --git a/src/cmd/wm/protocol/sync b/src/cmd/wm/protocol/sync
new file mode 100755
index 0000000..19a728a
--- /dev/null
+++ b/src/cmd/wm/protocol/sync
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+for base in wlr-layer-shell-unstable-v1.xml
+do
+ curl https://raw.githubusercontent.com/swaywm/wlroots/master/protocol/$base --output $base
+done
diff --git a/src/cmd/wm/protocol/wlr-layer-shell-unstable-v1.xml b/src/cmd/wm/protocol/wlr-layer-shell-unstable-v1.xml
new file mode 100644
index 0000000..d62fd51
--- /dev/null
+++ b/src/cmd/wm/protocol/wlr-layer-shell-unstable-v1.xml
@@ -0,0 +1,390 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="wlr_layer_shell_unstable_v1">
+ <copyright>
+ Copyright © 2017 Drew DeVault
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that copyright notice and this permission
+ notice appear in supporting documentation, and that the name of
+ the copyright holders not be used in advertising or publicity
+ pertaining to distribution of the software without specific,
+ written prior permission. The copyright holders make no
+ representations about the suitability of this software for any
+ purpose. It is provided "as is" without express or implied
+ warranty.
+
+ THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ THIS SOFTWARE.
+ </copyright>
+
+ <interface name="zwlr_layer_shell_v1" version="4">
+ <description summary="create surfaces that are layers of the desktop">
+ Clients can use this interface to assign the surface_layer role to
+ wl_surfaces. Such surfaces are assigned to a "layer" of the output and
+ rendered with a defined z-depth respective to each other. They may also be
+ anchored to the edges and corners of a screen and specify input handling
+ semantics. This interface should be suitable for the implementation of
+ many desktop shell components, and a broad number of other applications
+ that interact with the desktop.
+ </description>
+
+ <request name="get_layer_surface">
+ <description summary="create a layer_surface from a surface">
+ Create a layer surface for an existing surface. This assigns the role of
+ layer_surface, or raises a protocol error if another role is already
+ assigned.
+
+ Creating a layer surface from a wl_surface which has a buffer attached
+ or committed is a client error, and any attempts by a client to attach
+ or manipulate a buffer prior to the first layer_surface.configure call
+ must also be treated as errors.
+
+ After creating a layer_surface object and setting it up, the client
+ must perform an initial commit without any buffer attached.
+ The compositor will reply with a layer_surface.configure event.
+ The client must acknowledge it and is then allowed to attach a buffer
+ to map the surface.
+
+ You may pass NULL for output to allow the compositor to decide which
+ output to use. Generally this will be the one that the user most
+ recently interacted with.
+
+ Clients can specify a namespace that defines the purpose of the layer
+ surface.
+ </description>
+ <arg name="id" type="new_id" interface="zwlr_layer_surface_v1"/>
+ <arg name="surface" type="object" interface="wl_surface"/>
+ <arg name="output" type="object" interface="wl_output" allow-null="true"/>
+ <arg name="layer" type="uint" enum="layer" summary="layer to add this surface to"/>
+ <arg name="namespace" type="string" summary="namespace for the layer surface"/>
+ </request>
+
+ <enum name="error">
+ <entry name="role" value="0" summary="wl_surface has another role"/>
+ <entry name="invalid_layer" value="1" summary="layer value is invalid"/>
+ <entry name="already_constructed" value="2" summary="wl_surface has a buffer attached or committed"/>
+ </enum>
+
+ <enum name="layer">
+ <description summary="available layers for surfaces">
+ These values indicate which layers a surface can be rendered in. They
+ are ordered by z depth, bottom-most first. Traditional shell surfaces
+ will typically be rendered between the bottom and top layers.
+ Fullscreen shell surfaces are typically rendered at the top layer.
+ Multiple surfaces can share a single layer, and ordering within a
+ single layer is undefined.
+ </description>
+
+ <entry name="background" value="0"/>
+ <entry name="bottom" value="1"/>
+ <entry name="top" value="2"/>
+ <entry name="overlay" value="3"/>
+ </enum>
+
+ <!-- Version 3 additions -->
+
+ <request name="destroy" type="destructor" since="3">
+ <description summary="destroy the layer_shell object">
+ This request indicates that the client will not use the layer_shell
+ object any more. Objects that have been created through this instance
+ are not affected.
+ </description>
+ </request>
+ </interface>
+
+ <interface name="zwlr_layer_surface_v1" version="4">
+ <description summary="layer metadata interface">
+ An interface that may be implemented by a wl_surface, for surfaces that
+ are designed to be rendered as a layer of a stacked desktop-like
+ environment.
+
+ Layer surface state (layer, size, anchor, exclusive zone,
+ margin, interactivity) is double-buffered, and will be applied at the
+ time wl_surface.commit of the corresponding wl_surface is called.
+
+ Attaching a null buffer to a layer surface unmaps it.
+
+ Unmapping a layer_surface means that the surface cannot be shown by the
+ compositor until it is explicitly mapped again. The layer_surface
+ returns to the state it had right after layer_shell.get_layer_surface.
+ The client can re-map the surface by performing a commit without any
+ buffer attached, waiting for a configure event and handling it as usual.
+ </description>
+
+ <request name="set_size">
+ <description summary="sets the size of the surface">
+ Sets the size of the surface in surface-local coordinates. The
+ compositor will display the surface centered with respect to its
+ anchors.
+
+ If you pass 0 for either value, the compositor will assign it and
+ inform you of the assignment in the configure event. You must set your
+ anchor to opposite edges in the dimensions you omit; not doing so is a
+ protocol error. Both values are 0 by default.
+
+ Size is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="width" type="uint"/>
+ <arg name="height" type="uint"/>
+ </request>
+
+ <request name="set_anchor">
+ <description summary="configures the anchor point of the surface">
+ Requests that the compositor anchor the surface to the specified edges
+ and corners. If two orthogonal edges are specified (e.g. 'top' and
+ 'left'), then the anchor point will be the intersection of the edges
+ (e.g. the top left corner of the output); otherwise the anchor point
+ will be centered on that edge, or in the center if none is specified.
+
+ Anchor is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="anchor" type="uint" enum="anchor"/>
+ </request>
+
+ <request name="set_exclusive_zone">
+ <description summary="configures the exclusive geometry of this surface">
+ Requests that the compositor avoids occluding an area with other
+ surfaces. The compositor's use of this information is
+ implementation-dependent - do not assume that this region will not
+ actually be occluded.
+
+ A positive value is only meaningful if the surface is anchored to one
+ edge or an edge and both perpendicular edges. If the surface is not
+ anchored, anchored to only two perpendicular edges (a corner), anchored
+ to only two parallel edges or anchored to all edges, a positive value
+ will be treated the same as zero.
+
+ A positive zone is the distance from the edge in surface-local
+ coordinates to consider exclusive.
+
+ Surfaces that do not wish to have an exclusive zone may instead specify
+ how they should interact with surfaces that do. If set to zero, the
+ surface indicates that it would like to be moved to avoid occluding
+ surfaces with a positive exclusive zone. If set to -1, the surface
+ indicates that it would not like to be moved to accommodate for other
+ surfaces, and the compositor should extend it all the way to the edges
+ it is anchored to.
+
+ For example, a panel might set its exclusive zone to 10, so that
+ maximized shell surfaces are not shown on top of it. A notification
+ might set its exclusive zone to 0, so that it is moved to avoid
+ occluding the panel, but shell surfaces are shown underneath it. A
+ wallpaper or lock screen might set their exclusive zone to -1, so that
+ they stretch below or over the panel.
+
+ The default value is 0.
+
+ Exclusive zone is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="zone" type="int"/>
+ </request>
+
+ <request name="set_margin">
+ <description summary="sets a margin from the anchor point">
+ Requests that the surface be placed some distance away from the anchor
+ point on the output, in surface-local coordinates. Setting this value
+ for edges you are not anchored to has no effect.
+
+ The exclusive zone includes the margin.
+
+ Margin is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="top" type="int"/>
+ <arg name="right" type="int"/>
+ <arg name="bottom" type="int"/>
+ <arg name="left" type="int"/>
+ </request>
+
+ <enum name="keyboard_interactivity">
+ <description summary="types of keyboard interaction possible for a layer shell surface">
+ Types of keyboard interaction possible for layer shell surfaces. The
+ rationale for this is twofold: (1) some applications are not interested
+ in keyboard events and not allowing them to be focused can improve the
+ desktop experience; (2) some applications will want to take exclusive
+ keyboard focus.
+ </description>
+
+ <entry name="none" value="0">
+ <description summary="no keyboard focus is possible">
+ This value indicates that this surface is not interested in keyboard
+ events and the compositor should never assign it the keyboard focus.
+
+ This is the default value, set for newly created layer shell surfaces.
+
+ This is useful for e.g. desktop widgets that display information or
+ only have interaction with non-keyboard input devices.
+ </description>
+ </entry>
+ <entry name="exclusive" value="1">
+ <description summary="request exclusive keyboard focus">
+ Request exclusive keyboard focus if this surface is above the shell surface layer.
+
+ For the top and overlay layers, the seat will always give
+ exclusive keyboard focus to the top-most layer which has keyboard
+ interactivity set to exclusive. If this layer contains multiple
+ surfaces with keyboard interactivity set to exclusive, the compositor
+ determines the one receiving keyboard events in an implementation-
+ defined manner. In this case, no guarantee is made when this surface
+ will receive keyboard focus (if ever).
+
+ For the bottom and background layers, the compositor is allowed to use
+ normal focus semantics.
+
+ This setting is mainly intended for applications that need to ensure
+ they receive all keyboard events, such as a lock screen or a password
+ prompt.
+ </description>
+ </entry>
+ <entry name="on_demand" value="2" since="4">
+ <description summary="request regular keyboard focus semantics">
+ This requests the compositor to allow this surface to be focused and
+ unfocused by the user in an implementation-defined manner. The user
+ should be able to unfocus this surface even regardless of the layer
+ it is on.
+
+ Typically, the compositor will want to use its normal mechanism to
+ manage keyboard focus between layer shell surfaces with this setting
+ and regular toplevels on the desktop layer (e.g. click to focus).
+ Nevertheless, it is possible for a compositor to require a special
+ interaction to focus or unfocus layer shell surfaces (e.g. requiring
+ a click even if focus follows the mouse normally, or providing a
+ keybinding to switch focus between layers).
+
+ This setting is mainly intended for desktop shell components (e.g.
+ panels) that allow keyboard interaction. Using this option can allow
+ implementing a desktop shell that can be fully usable without the
+ mouse.
+ </description>
+ </entry>
+ </enum>
+
+ <request name="set_keyboard_interactivity">
+ <description summary="requests keyboard events">
+ Set how keyboard events are delivered to this surface. By default,
+ layer shell surfaces do not receive keyboard events; this request can
+ be used to change this.
+
+ This setting is inherited by child surfaces set by the get_popup
+ request.
+
+ Layer surfaces receive pointer, touch, and tablet events normally. If
+ you do not want to receive them, set the input region on your surface
+ to an empty region.
+
+ Keyboard interactivity is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="keyboard_interactivity" type="uint" enum="keyboard_interactivity"/>
+ </request>
+
+ <request name="get_popup">
+ <description summary="assign this layer_surface as an xdg_popup parent">
+ This assigns an xdg_popup's parent to this layer_surface. This popup
+ should have been created via xdg_surface::get_popup with the parent set
+ to NULL, and this request must be invoked before committing the popup's
+ initial state.
+
+ See the documentation of xdg_popup for more details about what an
+ xdg_popup is and how it is used.
+ </description>
+ <arg name="popup" type="object" interface="xdg_popup"/>
+ </request>
+
+ <request name="ack_configure">
+ <description summary="ack a configure event">
+ When a configure event is received, if a client commits the
+ surface in response to the configure event, then the client
+ must make an ack_configure request sometime before the commit
+ request, passing along the serial of the configure event.
+
+ If the client receives multiple configure events before it
+ can respond to one, it only has to ack the last configure event.
+
+ A client is not required to commit immediately after sending
+ an ack_configure request - it may even ack_configure several times
+ before its next surface commit.
+
+ A client may send multiple ack_configure requests before committing, but
+ only the last request sent before a commit indicates which configure
+ event the client really is responding to.
+ </description>
+ <arg name="serial" type="uint" summary="the serial from the configure event"/>
+ </request>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the layer_surface">
+ This request destroys the layer surface.
+ </description>
+ </request>
+
+ <event name="configure">
+ <description summary="suggest a surface change">
+ The configure event asks the client to resize its surface.
+
+ Clients should arrange their surface for the new states, and then send
+ an ack_configure request with the serial sent in this configure event at
+ some point before committing the new surface.
+
+ The client is free to dismiss all but the last configure event it
+ received.
+
+ The width and height arguments specify the size of the window in
+ surface-local coordinates.
+
+ The size is a hint, in the sense that the client is free to ignore it if
+ it doesn't resize, pick a smaller size (to satisfy aspect ratio or
+ resize in steps of NxM pixels). If the client picks a smaller size and
+ is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the
+ surface will be centered on this axis.
+
+ If the width or height arguments are zero, it means the client should
+ decide its own window dimension.
+ </description>
+ <arg name="serial" type="uint"/>
+ <arg name="width" type="uint"/>
+ <arg name="height" type="uint"/>
+ </event>
+
+ <event name="closed">
+ <description summary="surface should be closed">
+ The closed event is sent by the compositor when the surface will no
+ longer be shown. The output may have been destroyed or the user may
+ have asked for it to be removed. Further changes to the surface will be
+ ignored. The client should destroy the resource after receiving this
+ event, and create a new surface if they so choose.
+ </description>
+ </event>
+
+ <enum name="error">
+ <entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
+ <entry name="invalid_size" value="1" summary="size is invalid"/>
+ <entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
+ <entry name="invalid_keyboard_interactivity" value="3" summary="keyboard interactivity is invalid"/>
+ </enum>
+
+ <enum name="anchor" bitfield="true">
+ <entry name="top" value="1" summary="the top edge of the anchor rectangle"/>
+ <entry name="bottom" value="2" summary="the bottom edge of the anchor rectangle"/>
+ <entry name="left" value="4" summary="the left edge of the anchor rectangle"/>
+ <entry name="right" value="8" summary="the right edge of the anchor rectangle"/>
+ </enum>
+
+ <!-- Version 2 additions -->
+
+ <request name="set_layer" since="2">
+ <description summary="change the layer of the surface">
+ Change the layer that the surface is rendered on.
+
+ Layer is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="layer" type="uint" enum="zwlr_layer_shell_v1.layer" summary="layer to move this surface to"/>
+ </request>
+ </interface>
+</protocol>
diff --git a/src/cmd/wm/render.c b/src/cmd/wm/render.c
new file mode 100644
index 0000000..1f51804
--- /dev/null
+++ b/src/cmd/wm/render.c
@@ -0,0 +1,160 @@
+#include "wm.h"
+
+struct Payload
+{
+ Client *client;
+ struct wlr_output *output;
+ struct timespec *when;
+ int x, y;
+};
+
+static
+void
+render(struct wlr_surface *surface, int sx, int sy, void *data)
+{
+ float matrix[9];
+ double x, y;
+ struct Payload *payload;
+
+ struct wlr_box box;
+ struct wlr_output *output;
+ struct wlr_texture *texture;
+
+ enum wl_output_transform transform;
+
+ payload = data;
+ output = payload->output;
+
+ texture = wlr_surface_get_texture(surface);
+ if(!texture)
+ return;
+
+ x = 0, y = 0;
+ wlr_output_layout_output_coords(server.monitor.layout, output, &x, &y);
+
+ box = (struct wlr_box) {
+ .x = x + payload->x + sx,
+ .y = y + payload->y + sy,
+ .width = surface->current.width,
+ .height = surface->current.height,
+ };
+ scale_box(&box, output->scale);
+
+ transform = wlr_output_transform_invert(surface->current.transform);
+ wlr_matrix_project_box(matrix, &box, transform, 0, output->transform_matrix);
+
+ wlr_render_texture_with_matrix(server.renderer, texture, matrix, 1);
+ wlr_surface_send_frame_done(surface, payload->when);
+ wlr_presentation_surface_sampled_on_output(server.present, surface, output);
+}
+
+static
+void
+render_layer(struct wl_list *list, struct timespec *now)
+{
+ Layer *layer;
+ wl_list_for_each(layer, list, link) {
+ struct Payload payload= {
+ .output = layer->surface->output,
+ .x = layer->geometry.x,
+ .y = layer->geometry.y,
+ .when = now,
+ };
+
+ wlr_surface_for_each_surface(layer->surface->surface, render, &payload);
+ }
+}
+
+static
+void
+render_clients(Monitor *monitor, struct timespec *now)
+{
+ double x, y;
+ int i, w, h, bw;
+ float *color;
+
+ Client *client;
+ struct wlr_output *output;
+ struct wlr_box *borders;
+ struct wlr_surface *surface;
+
+ output = monitor->output;
+ wl_list_for_each_reverse(client, &server.client.stack, stack) {
+ if(!VISIBLE_ON(client, client->monitor))
+ continue;
+ if(!wlr_output_layout_intersects(server.monitor.layout, monitor->output, &client->geometry))
+ continue;
+
+ surface = client->xdg->surface;
+
+ x = client->geometry.x, y = client->geometry.y;
+ wlr_output_layout_output_coords(server.monitor.layout, output, &x, &y);
+
+ if((bw=client->border)) {
+ w = surface->current.width;
+ h = surface->current.height;
+ borders = (struct wlr_box[4]) {
+ {x, y, w+2*bw, bw}, /* top */
+ {x, y+bw, bw, h}, /* left */
+ {x+bw+w, y+bw, bw, h}, /* right */
+ {x, y+bw+h, w+2*bw, bw}, /* bottom */
+ };
+
+ color = (client == server.selected) ? cfg·focuscolor : cfg·bordercolor;
+ for(i=0; i<4; i++) {
+ scale_box(&borders[i], output->scale);
+ wlr_render_rect(server.renderer, &borders[i], color, output->transform_matrix);
+ }
+ }
+
+ struct Payload payload = {
+ .output = output,
+ .when = now,
+
+ .x = client->geometry.x + client->border,
+ .y = client->geometry.y + client->border,
+ };
+
+ wlr_xdg_surface_for_each_surface(client->xdg, render, &payload);
+ }
+}
+
+void
+render_monitor(struct wl_listener *l, void *data)
+{
+ int w, h;
+ Client *client;
+ Monitor *monitor;
+ struct timespec now;
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ monitor = wl_container_of(l, monitor, event.render);
+
+ wl_list_for_each(client, &server.client.list, link) {
+ if(client->resize) {
+ wlr_surface_send_frame_done(client->xdg->surface, &now);
+ }
+ }
+
+ if(!wlr_output_attach_render(monitor->output, nil))
+ return;
+
+ wlr_output_effective_resolution(monitor->output, &w, &h);
+
+ /* start of rendering kernel */
+ wlr_renderer_begin(server.renderer, w, h);
+ wlr_renderer_clear(server.renderer, cfg·rootcolor);
+
+ render_layer(&monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &now);
+ render_layer(&monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &now);
+
+ render_clients(monitor, &now);
+
+ render_layer(&monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &now);
+ render_layer(&monitor->layer[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &now);
+
+ wlr_output_render_software_cursors(monitor->output, nil);
+
+ wlr_renderer_end(server.renderer);
+ wlr_output_commit(monitor->output);
+}
diff --git a/src/cmd/wm/rules.mk b/src/cmd/wm/rules.mk
new file mode 100644
index 0000000..30d786d
--- /dev/null
+++ b/src/cmd/wm/rules.mk
@@ -0,0 +1,62 @@
+include share/push.mk
+# Iterate through subdirectory tree
+
+# local sources
+SRCS_$(d):=\
+ $(d)/xdg-shell-protocol.c\
+ $(d)/wlr-layer-shell-unstable-v1-protocol.c\
+ $(d)/util.c\
+ $(d)/input.c\
+ $(d)/render.c\
+ $(d)/layer.c\
+ $(d)/xdg.c\
+ $(d)/client.c\
+ $(d)/monitor.c\
+ $(d)/main.c
+
+# local outputs
+BINS_$(d) := $(d)/wm
+
+include share/paths.mk
+
+# Local rules
+include share/dynamic.mk
+
+$(d)/xdg-shell-protocol.h:
+ @echo "MK $(notdir $@)";\
+ $(WL_SCAN) server-header $(WL_PROTO)/stable/xdg-shell/xdg-shell.xml $@
+
+$(d)/xdg-shell-protocol.c: $(d)/xdg-shell-protocol.h
+ @echo "MK $(notdir $@)";\
+ $(WL_SCAN) private-code $(WL_PROTO)/stable/xdg-shell/xdg-shell.xml $@
+
+$(d)/wlr-layer-shell-unstable-v1-protocol.h:
+ @echo "MK $(notdir $@)";\
+ $(WL_SCAN) server-header $(dir $@)protocol/wlr-layer-shell-unstable-v1.xml $@
+
+$(d)/wlr-layer-shell-unstable-v1-protocol.c: $(d)/wlr-layer-shell-unstable-v1-protocol.h
+ @echo "MK $(notdir $@)";\
+ $(WL_SCAN) private-code $(dir $@)protocol/wlr-layer-shell-unstable-v1.xml $@
+
+GENS+=\
+ $(d)/xdg-shell-protocol.h\
+ $(d)/xdg-shell-protocol.c\
+ $(d)/wlr-layer-shell-unstable-v1-protocol.h\
+ $(d)/wlr-layer-shell-unstable-v1-protocol.c
+
+$(BINS_$(d)): TCINCS=-I cmd/wm
+
+$(BINS_$(d)): TCFLAGS=\
+ `$(PKG) --cflags wlroots`\
+ `$(PKG) --cflags wayland-server`\
+ `$(PKG) --cflags xkbcommon`
+
+$(BINS_$(d)): TCLIBS=\
+ `$(PKG) --libs wlroots`\
+ `$(PKG) --libs wayland-server`\
+ `$(PKG) --libs xkbcommon`\
+
+$(BINS_$(d)): $(OBJS_$(d)) $(OBJ_DIR)/base/base.a
+ $(COMPLINK)
+
+include share/pop.mk
diff --git a/src/cmd/wm/util.c b/src/cmd/wm/util.c
new file mode 100644
index 0000000..7871d15
--- /dev/null
+++ b/src/cmd/wm/util.c
@@ -0,0 +1,99 @@
+#include "wm.h"
+
+typedef struct {
+ uint32 singular_anchor;
+ uint32 anchor_triplet;
+ int *positive_axis;
+ int *negative_axis;
+ int margin;
+} Edge;
+
+// -----------------------------------------------------------------------
+// general purpose function on rectangles
+
+void
+scale_box(struct wlr_box *box, float scale)
+{
+ box->width = ROUND((box->x + box->width) * scale) - ROUND(box->x * scale);
+ box->height = ROUND((box->y + box->height) * scale) - ROUND(box->y * scale);
+ box->x = ROUND(box->x * scale);
+ box->y = ROUND(box->y * scale);
+}
+
+void
+exclude(struct wlr_box *usable_area, uint32 anchor, int32 exclusive,
+ int32 margin_top, int32 margin_right, int32 margin_bottom, int32 margin_left)
+{
+ Edge edges[] = {
+ { // Top
+ .singular_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP,
+ .anchor_triplet = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP,
+ .positive_axis = &usable_area->y,
+ .negative_axis = &usable_area->height,
+ .margin = margin_top,
+ },
+ { // Bottom
+ .singular_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
+ .anchor_triplet = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
+ .positive_axis = NULL,
+ .negative_axis = &usable_area->height,
+ .margin = margin_bottom,
+ },
+ { // Left
+ .singular_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT,
+ .anchor_triplet = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
+ .positive_axis = &usable_area->x,
+ .negative_axis = &usable_area->width,
+ .margin = margin_left,
+ },
+ { // Right
+ .singular_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT,
+ .anchor_triplet = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
+ .positive_axis = NULL,
+ .negative_axis = &usable_area->width,
+ .margin = margin_right,
+ }
+ };
+ for(size_t i = 0; i < arrlen(edges); i++) {
+ if((anchor == edges[i].singular_anchor || anchor == edges[i].anchor_triplet)
+ && exclusive + edges[i].margin > 0) {
+ if(edges[i].positive_axis)
+ *edges[i].positive_axis += exclusive + edges[i].margin;
+ if(edges[i].negative_axis)
+ *edges[i].negative_axis -= exclusive + edges[i].margin;
+ break;
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+// user facing functions
+
+void
+spawn(Arg *arg)
+{
+ wlr_log(WLR_DEBUG, "spawning %s", ((char **)arg->v)[0]);
+ if(!fork()) {
+ dup2(2, 1);
+ setsid();
+ execvp(((char **)arg->v)[0], (char **)arg->v);
+ }
+}
+
+void
+quit(Arg *arg)
+{
+ wl_display_terminate(server.display);
+}
+
+#define CONFIG(a,b,...) a cfg·##b = __VA_ARGS__
+#include "config.h"
+#undef CONFIG
diff --git a/src/cmd/wm/wlr-layer-shell-unstable-v1-protocol.c b/src/cmd/wm/wlr-layer-shell-unstable-v1-protocol.c
new file mode 100644
index 0000000..95ff317
--- /dev/null
+++ b/src/cmd/wm/wlr-layer-shell-unstable-v1-protocol.c
@@ -0,0 +1,93 @@
+/* Generated by wayland-scanner 1.19.0 */
+
+/*
+ * Copyright © 2017 Drew DeVault
+ *
+ * Permission to use, copy, modify, distribute, and sell this
+ * software and its documentation for any purpose is hereby granted
+ * without fee, provided that the above copyright notice appear in
+ * all copies and that both that copyright notice and this permission
+ * notice appear in supporting documentation, and that the name of
+ * the copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include "wayland-util.h"
+
+#ifndef __has_attribute
+# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
+#endif
+
+#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
+#define WL_PRIVATE __attribute__ ((visibility("hidden")))
+#else
+#define WL_PRIVATE
+#endif
+
+extern const struct wl_interface wl_output_interface;
+extern const struct wl_interface wl_surface_interface;
+extern const struct wl_interface xdg_popup_interface;
+extern const struct wl_interface zwlr_layer_surface_v1_interface;
+
+static const struct wl_interface *wlr_layer_shell_unstable_v1_types[] = {
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ &zwlr_layer_surface_v1_interface,
+ &wl_surface_interface,
+ &wl_output_interface,
+ NULL,
+ NULL,
+ &xdg_popup_interface,
+};
+
+static const struct wl_message zwlr_layer_shell_v1_requests[] = {
+ { "get_layer_surface", "no?ous", wlr_layer_shell_unstable_v1_types + 4 },
+ { "destroy", "3", wlr_layer_shell_unstable_v1_types + 0 },
+};
+
+WL_PRIVATE const struct wl_interface zwlr_layer_shell_v1_interface = {
+ "zwlr_layer_shell_v1", 4,
+ 2, zwlr_layer_shell_v1_requests,
+ 0, NULL,
+};
+
+static const struct wl_message zwlr_layer_surface_v1_requests[] = {
+ { "set_size", "uu", wlr_layer_shell_unstable_v1_types + 0 },
+ { "set_anchor", "u", wlr_layer_shell_unstable_v1_types + 0 },
+ { "set_exclusive_zone", "i", wlr_layer_shell_unstable_v1_types + 0 },
+ { "set_margin", "iiii", wlr_layer_shell_unstable_v1_types + 0 },
+ { "set_keyboard_interactivity", "u", wlr_layer_shell_unstable_v1_types + 0 },
+ { "get_popup", "o", wlr_layer_shell_unstable_v1_types + 9 },
+ { "ack_configure", "u", wlr_layer_shell_unstable_v1_types + 0 },
+ { "destroy", "", wlr_layer_shell_unstable_v1_types + 0 },
+ { "set_layer", "2u", wlr_layer_shell_unstable_v1_types + 0 },
+};
+
+static const struct wl_message zwlr_layer_surface_v1_events[] = {
+ { "configure", "uuu", wlr_layer_shell_unstable_v1_types + 0 },
+ { "closed", "", wlr_layer_shell_unstable_v1_types + 0 },
+};
+
+WL_PRIVATE const struct wl_interface zwlr_layer_surface_v1_interface = {
+ "zwlr_layer_surface_v1", 4,
+ 9, zwlr_layer_surface_v1_requests,
+ 2, zwlr_layer_surface_v1_events,
+};
+
diff --git a/src/cmd/wm/wlr-layer-shell-unstable-v1-protocol.h b/src/cmd/wm/wlr-layer-shell-unstable-v1-protocol.h
new file mode 100644
index 0000000..ea2fa9b
--- /dev/null
+++ b/src/cmd/wm/wlr-layer-shell-unstable-v1-protocol.h
@@ -0,0 +1,564 @@
+/* Generated by wayland-scanner 1.19.0 */
+
+#ifndef WLR_LAYER_SHELL_UNSTABLE_V1_SERVER_PROTOCOL_H
+#define WLR_LAYER_SHELL_UNSTABLE_V1_SERVER_PROTOCOL_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include "wayland-server.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct wl_client;
+struct wl_resource;
+
+/**
+ * @page page_wlr_layer_shell_unstable_v1 The wlr_layer_shell_unstable_v1 protocol
+ * @section page_ifaces_wlr_layer_shell_unstable_v1 Interfaces
+ * - @subpage page_iface_zwlr_layer_shell_v1 - create surfaces that are layers of the desktop
+ * - @subpage page_iface_zwlr_layer_surface_v1 - layer metadata interface
+ * @section page_copyright_wlr_layer_shell_unstable_v1 Copyright
+ * <pre>
+ *
+ * Copyright © 2017 Drew DeVault
+ *
+ * Permission to use, copy, modify, distribute, and sell this
+ * software and its documentation for any purpose is hereby granted
+ * without fee, provided that the above copyright notice appear in
+ * all copies and that both that copyright notice and this permission
+ * notice appear in supporting documentation, and that the name of
+ * the copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ * </pre>
+ */
+struct wl_output;
+struct wl_surface;
+struct xdg_popup;
+struct zwlr_layer_shell_v1;
+struct zwlr_layer_surface_v1;
+
+#ifndef ZWLR_LAYER_SHELL_V1_INTERFACE
+#define ZWLR_LAYER_SHELL_V1_INTERFACE
+/**
+ * @page page_iface_zwlr_layer_shell_v1 zwlr_layer_shell_v1
+ * @section page_iface_zwlr_layer_shell_v1_desc Description
+ *
+ * Clients can use this interface to assign the surface_layer role to
+ * wl_surfaces. Such surfaces are assigned to a "layer" of the output and
+ * rendered with a defined z-depth respective to each other. They may also be
+ * anchored to the edges and corners of a screen and specify input handling
+ * semantics. This interface should be suitable for the implementation of
+ * many desktop shell components, and a broad number of other applications
+ * that interact with the desktop.
+ * @section page_iface_zwlr_layer_shell_v1_api API
+ * See @ref iface_zwlr_layer_shell_v1.
+ */
+/**
+ * @defgroup iface_zwlr_layer_shell_v1 The zwlr_layer_shell_v1 interface
+ *
+ * Clients can use this interface to assign the surface_layer role to
+ * wl_surfaces. Such surfaces are assigned to a "layer" of the output and
+ * rendered with a defined z-depth respective to each other. They may also be
+ * anchored to the edges and corners of a screen and specify input handling
+ * semantics. This interface should be suitable for the implementation of
+ * many desktop shell components, and a broad number of other applications
+ * that interact with the desktop.
+ */
+extern const struct wl_interface zwlr_layer_shell_v1_interface;
+#endif
+#ifndef ZWLR_LAYER_SURFACE_V1_INTERFACE
+#define ZWLR_LAYER_SURFACE_V1_INTERFACE
+/**
+ * @page page_iface_zwlr_layer_surface_v1 zwlr_layer_surface_v1
+ * @section page_iface_zwlr_layer_surface_v1_desc Description
+ *
+ * An interface that may be implemented by a wl_surface, for surfaces that
+ * are designed to be rendered as a layer of a stacked desktop-like
+ * environment.
+ *
+ * Layer surface state (layer, size, anchor, exclusive zone,
+ * margin, interactivity) is double-buffered, and will be applied at the
+ * time wl_surface.commit of the corresponding wl_surface is called.
+ *
+ * Attaching a null buffer to a layer surface unmaps it.
+ *
+ * Unmapping a layer_surface means that the surface cannot be shown by the
+ * compositor until it is explicitly mapped again. The layer_surface
+ * returns to the state it had right after layer_shell.get_layer_surface.
+ * The client can re-map the surface by performing a commit without any
+ * buffer attached, waiting for a configure event and handling it as usual.
+ * @section page_iface_zwlr_layer_surface_v1_api API
+ * See @ref iface_zwlr_layer_surface_v1.
+ */
+/**
+ * @defgroup iface_zwlr_layer_surface_v1 The zwlr_layer_surface_v1 interface
+ *
+ * An interface that may be implemented by a wl_surface, for surfaces that
+ * are designed to be rendered as a layer of a stacked desktop-like
+ * environment.
+ *
+ * Layer surface state (layer, size, anchor, exclusive zone,
+ * margin, interactivity) is double-buffered, and will be applied at the
+ * time wl_surface.commit of the corresponding wl_surface is called.
+ *
+ * Attaching a null buffer to a layer surface unmaps it.
+ *
+ * Unmapping a layer_surface means that the surface cannot be shown by the
+ * compositor until it is explicitly mapped again. The layer_surface
+ * returns to the state it had right after layer_shell.get_layer_surface.
+ * The client can re-map the surface by performing a commit without any
+ * buffer attached, waiting for a configure event and handling it as usual.
+ */
+extern const struct wl_interface zwlr_layer_surface_v1_interface;
+#endif
+
+#ifndef ZWLR_LAYER_SHELL_V1_ERROR_ENUM
+#define ZWLR_LAYER_SHELL_V1_ERROR_ENUM
+enum zwlr_layer_shell_v1_error {
+ /**
+ * wl_surface has another role
+ */
+ ZWLR_LAYER_SHELL_V1_ERROR_ROLE = 0,
+ /**
+ * layer value is invalid
+ */
+ ZWLR_LAYER_SHELL_V1_ERROR_INVALID_LAYER = 1,
+ /**
+ * wl_surface has a buffer attached or committed
+ */
+ ZWLR_LAYER_SHELL_V1_ERROR_ALREADY_CONSTRUCTED = 2,
+};
+#endif /* ZWLR_LAYER_SHELL_V1_ERROR_ENUM */
+
+#ifndef ZWLR_LAYER_SHELL_V1_LAYER_ENUM
+#define ZWLR_LAYER_SHELL_V1_LAYER_ENUM
+/**
+ * @ingroup iface_zwlr_layer_shell_v1
+ * available layers for surfaces
+ *
+ * These values indicate which layers a surface can be rendered in. They
+ * are ordered by z depth, bottom-most first. Traditional shell surfaces
+ * will typically be rendered between the bottom and top layers.
+ * Fullscreen shell surfaces are typically rendered at the top layer.
+ * Multiple surfaces can share a single layer, and ordering within a
+ * single layer is undefined.
+ */
+enum zwlr_layer_shell_v1_layer {
+ ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND = 0,
+ ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM = 1,
+ ZWLR_LAYER_SHELL_V1_LAYER_TOP = 2,
+ ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY = 3,
+};
+#endif /* ZWLR_LAYER_SHELL_V1_LAYER_ENUM */
+
+/**
+ * @ingroup iface_zwlr_layer_shell_v1
+ * @struct zwlr_layer_shell_v1_interface
+ */
+struct zwlr_layer_shell_v1_interface {
+ /**
+ * create a layer_surface from a surface
+ *
+ * Create a layer surface for an existing surface. This assigns
+ * the role of layer_surface, or raises a protocol error if another
+ * role is already assigned.
+ *
+ * Creating a layer surface from a wl_surface which has a buffer
+ * attached or committed is a client error, and any attempts by a
+ * client to attach or manipulate a buffer prior to the first
+ * layer_surface.configure call must also be treated as errors.
+ *
+ * After creating a layer_surface object and setting it up, the
+ * client must perform an initial commit without any buffer
+ * attached. The compositor will reply with a
+ * layer_surface.configure event. The client must acknowledge it
+ * and is then allowed to attach a buffer to map the surface.
+ *
+ * You may pass NULL for output to allow the compositor to decide
+ * which output to use. Generally this will be the one that the
+ * user most recently interacted with.
+ *
+ * Clients can specify a namespace that defines the purpose of the
+ * layer surface.
+ * @param layer layer to add this surface to
+ * @param namespace namespace for the layer surface
+ */
+ void (*get_layer_surface)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id,
+ struct wl_resource *surface,
+ struct wl_resource *output,
+ uint32_t layer,
+ const char *namespace);
+ /**
+ * destroy the layer_shell object
+ *
+ * This request indicates that the client will not use the
+ * layer_shell object any more. Objects that have been created
+ * through this instance are not affected.
+ * @since 3
+ */
+ void (*destroy)(struct wl_client *client,
+ struct wl_resource *resource);
+};
+
+
+/**
+ * @ingroup iface_zwlr_layer_shell_v1
+ */
+#define ZWLR_LAYER_SHELL_V1_GET_LAYER_SURFACE_SINCE_VERSION 1
+/**
+ * @ingroup iface_zwlr_layer_shell_v1
+ */
+#define ZWLR_LAYER_SHELL_V1_DESTROY_SINCE_VERSION 3
+
+#ifndef ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ENUM
+#define ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ENUM
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ * request regular keyboard focus semantics
+ *
+ * This requests the compositor to allow this surface to be focused and
+ * unfocused by the user in an implementation-defined manner. The user
+ * should be able to unfocus this surface even regardless of the layer
+ * it is on.
+ *
+ * Typically, the compositor will want to use its normal mechanism to
+ * manage keyboard focus between layer shell surfaces with this setting
+ * and regular toplevels on the desktop layer (e.g. click to focus).
+ * Nevertheless, it is possible for a compositor to require a special
+ * interaction to focus or unfocus layer shell surfaces (e.g. requiring
+ * a click even if focus follows the mouse normally, or providing a
+ * keybinding to switch focus between layers).
+ *
+ * This setting is mainly intended for desktop shell components (e.g.
+ * panels) that allow keyboard interaction. Using this option can allow
+ * implementing a desktop shell that can be fully usable without the
+ * mouse.
+ */
+enum zwlr_layer_surface_v1_keyboard_interactivity {
+ ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE = 0,
+ ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE = 1,
+ /**
+ * @since 4
+ */
+ ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND = 2,
+};
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND_SINCE_VERSION 4
+#endif /* ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ENUM */
+
+#ifndef ZWLR_LAYER_SURFACE_V1_ERROR_ENUM
+#define ZWLR_LAYER_SURFACE_V1_ERROR_ENUM
+enum zwlr_layer_surface_v1_error {
+ /**
+ * provided surface state is invalid
+ */
+ ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SURFACE_STATE = 0,
+ /**
+ * size is invalid
+ */
+ ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE = 1,
+ /**
+ * anchor bitfield is invalid
+ */
+ ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_ANCHOR = 2,
+ /**
+ * keyboard interactivity is invalid
+ */
+ ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_KEYBOARD_INTERACTIVITY = 3,
+};
+#endif /* ZWLR_LAYER_SURFACE_V1_ERROR_ENUM */
+
+#ifndef ZWLR_LAYER_SURFACE_V1_ANCHOR_ENUM
+#define ZWLR_LAYER_SURFACE_V1_ANCHOR_ENUM
+enum zwlr_layer_surface_v1_anchor {
+ /**
+ * the top edge of the anchor rectangle
+ */
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP = 1,
+ /**
+ * the bottom edge of the anchor rectangle
+ */
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM = 2,
+ /**
+ * the left edge of the anchor rectangle
+ */
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT = 4,
+ /**
+ * the right edge of the anchor rectangle
+ */
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT = 8,
+};
+#endif /* ZWLR_LAYER_SURFACE_V1_ANCHOR_ENUM */
+
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ * @struct zwlr_layer_surface_v1_interface
+ */
+struct zwlr_layer_surface_v1_interface {
+ /**
+ * sets the size of the surface
+ *
+ * Sets the size of the surface in surface-local coordinates. The
+ * compositor will display the surface centered with respect to its
+ * anchors.
+ *
+ * If you pass 0 for either value, the compositor will assign it
+ * and inform you of the assignment in the configure event. You
+ * must set your anchor to opposite edges in the dimensions you
+ * omit; not doing so is a protocol error. Both values are 0 by
+ * default.
+ *
+ * Size is double-buffered, see wl_surface.commit.
+ */
+ void (*set_size)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t width,
+ uint32_t height);
+ /**
+ * configures the anchor point of the surface
+ *
+ * Requests that the compositor anchor the surface to the
+ * specified edges and corners. If two orthogonal edges are
+ * specified (e.g. 'top' and 'left'), then the anchor point will be
+ * the intersection of the edges (e.g. the top left corner of the
+ * output); otherwise the anchor point will be centered on that
+ * edge, or in the center if none is specified.
+ *
+ * Anchor is double-buffered, see wl_surface.commit.
+ */
+ void (*set_anchor)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t anchor);
+ /**
+ * configures the exclusive geometry of this surface
+ *
+ * Requests that the compositor avoids occluding an area with
+ * other surfaces. The compositor's use of this information is
+ * implementation-dependent - do not assume that this region will
+ * not actually be occluded.
+ *
+ * A positive value is only meaningful if the surface is anchored
+ * to one edge or an edge and both perpendicular edges. If the
+ * surface is not anchored, anchored to only two perpendicular
+ * edges (a corner), anchored to only two parallel edges or
+ * anchored to all edges, a positive value will be treated the same
+ * as zero.
+ *
+ * A positive zone is the distance from the edge in surface-local
+ * coordinates to consider exclusive.
+ *
+ * Surfaces that do not wish to have an exclusive zone may instead
+ * specify how they should interact with surfaces that do. If set
+ * to zero, the surface indicates that it would like to be moved to
+ * avoid occluding surfaces with a positive exclusive zone. If set
+ * to -1, the surface indicates that it would not like to be moved
+ * to accommodate for other surfaces, and the compositor should
+ * extend it all the way to the edges it is anchored to.
+ *
+ * For example, a panel might set its exclusive zone to 10, so that
+ * maximized shell surfaces are not shown on top of it. A
+ * notification might set its exclusive zone to 0, so that it is
+ * moved to avoid occluding the panel, but shell surfaces are shown
+ * underneath it. A wallpaper or lock screen might set their
+ * exclusive zone to -1, so that they stretch below or over the
+ * panel.
+ *
+ * The default value is 0.
+ *
+ * Exclusive zone is double-buffered, see wl_surface.commit.
+ */
+ void (*set_exclusive_zone)(struct wl_client *client,
+ struct wl_resource *resource,
+ int32_t zone);
+ /**
+ * sets a margin from the anchor point
+ *
+ * Requests that the surface be placed some distance away from
+ * the anchor point on the output, in surface-local coordinates.
+ * Setting this value for edges you are not anchored to has no
+ * effect.
+ *
+ * The exclusive zone includes the margin.
+ *
+ * Margin is double-buffered, see wl_surface.commit.
+ */
+ void (*set_margin)(struct wl_client *client,
+ struct wl_resource *resource,
+ int32_t top,
+ int32_t right,
+ int32_t bottom,
+ int32_t left);
+ /**
+ * requests keyboard events
+ *
+ * Set how keyboard events are delivered to this surface. By
+ * default, layer shell surfaces do not receive keyboard events;
+ * this request can be used to change this.
+ *
+ * This setting is inherited by child surfaces set by the get_popup
+ * request.
+ *
+ * Layer surfaces receive pointer, touch, and tablet events
+ * normally. If you do not want to receive them, set the input
+ * region on your surface to an empty region.
+ *
+ * Keyboard interactivity is double-buffered, see
+ * wl_surface.commit.
+ */
+ void (*set_keyboard_interactivity)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t keyboard_interactivity);
+ /**
+ * assign this layer_surface as an xdg_popup parent
+ *
+ * This assigns an xdg_popup's parent to this layer_surface. This
+ * popup should have been created via xdg_surface::get_popup with
+ * the parent set to NULL, and this request must be invoked before
+ * committing the popup's initial state.
+ *
+ * See the documentation of xdg_popup for more details about what
+ * an xdg_popup is and how it is used.
+ */
+ void (*get_popup)(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *popup);
+ /**
+ * ack a configure event
+ *
+ * When a configure event is received, if a client commits the
+ * surface in response to the configure event, then the client must
+ * make an ack_configure request sometime before the commit
+ * request, passing along the serial of the configure event.
+ *
+ * If the client receives multiple configure events before it can
+ * respond to one, it only has to ack the last configure event.
+ *
+ * A client is not required to commit immediately after sending an
+ * ack_configure request - it may even ack_configure several times
+ * before its next surface commit.
+ *
+ * A client may send multiple ack_configure requests before
+ * committing, but only the last request sent before a commit
+ * indicates which configure event the client really is responding
+ * to.
+ * @param serial the serial from the configure event
+ */
+ void (*ack_configure)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t serial);
+ /**
+ * destroy the layer_surface
+ *
+ * This request destroys the layer surface.
+ */
+ void (*destroy)(struct wl_client *client,
+ struct wl_resource *resource);
+ /**
+ * change the layer of the surface
+ *
+ * Change the layer that the surface is rendered on.
+ *
+ * Layer is double-buffered, see wl_surface.commit.
+ * @param layer layer to move this surface to
+ * @since 2
+ */
+ void (*set_layer)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t layer);
+};
+
+#define ZWLR_LAYER_SURFACE_V1_CONFIGURE 0
+#define ZWLR_LAYER_SURFACE_V1_CLOSED 1
+
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_CONFIGURE_SINCE_VERSION 1
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_CLOSED_SINCE_VERSION 1
+
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_SET_SIZE_SINCE_VERSION 1
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_SET_ANCHOR_SINCE_VERSION 1
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_SET_EXCLUSIVE_ZONE_SINCE_VERSION 1
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_SET_MARGIN_SINCE_VERSION 1
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_SET_KEYBOARD_INTERACTIVITY_SINCE_VERSION 1
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_GET_POPUP_SINCE_VERSION 1
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_ACK_CONFIGURE_SINCE_VERSION 1
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_DESTROY_SINCE_VERSION 1
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ */
+#define ZWLR_LAYER_SURFACE_V1_SET_LAYER_SINCE_VERSION 2
+
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ * Sends an configure event to the client owning the resource.
+ * @param resource_ The client's resource
+ */
+static inline void
+zwlr_layer_surface_v1_send_configure(struct wl_resource *resource_, uint32_t serial, uint32_t width, uint32_t height)
+{
+ wl_resource_post_event(resource_, ZWLR_LAYER_SURFACE_V1_CONFIGURE, serial, width, height);
+}
+
+/**
+ * @ingroup iface_zwlr_layer_surface_v1
+ * Sends an closed event to the client owning the resource.
+ * @param resource_ The client's resource
+ */
+static inline void
+zwlr_layer_surface_v1_send_closed(struct wl_resource *resource_)
+{
+ wl_resource_post_event(resource_, ZWLR_LAYER_SURFACE_V1_CLOSED);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/cmd/wm/wm.h b/src/cmd/wm/wm.h
new file mode 100644
index 0000000..a263804
--- /dev/null
+++ b/src/cmd/wm/wm.h
@@ -0,0 +1,350 @@
+#pragma once
+
+#include <u.h>
+#include <base.h>
+#include <wayland-server-core.h>
+#include <linux/input-event-codes.h>
+
+#define WLR_USE_UNSTABLE
+#include <wlr/backend.h>
+#include <wlr/render/wlr_renderer.h>
+
+#include <wlr/types/wlr_cursor.h>
+#include <wlr/types/wlr_compositor.h>
+#include <wlr/types/wlr_data_control_v1.h>
+#include <wlr/types/wlr_data_device.h>
+#include <wlr/types/wlr_export_dmabuf_v1.h>
+#include <wlr/types/wlr_gamma_control_v1.h>
+#include <wlr/types/wlr_input_device.h>
+#include <wlr/types/wlr_idle.h>
+#include <wlr/types/wlr_layer_shell_v1.h>
+#include <wlr/types/wlr_keyboard.h>
+#include <wlr/types/wlr_matrix.h>
+#include <wlr/types/wlr_output.h>
+#include <wlr/types/wlr_output_layout.h>
+#include <wlr/types/wlr_output_damage.h>
+#include <wlr/types/wlr_output_management_v1.h>
+#include <wlr/types/wlr_primary_selection.h>
+#include <wlr/types/wlr_primary_selection_v1.h>
+#include <wlr/types/wlr_pointer.h>
+#include <wlr/types/wlr_presentation_time.h>
+#include <wlr/types/wlr_screencopy_v1.h>
+#include <wlr/types/wlr_server_decoration.h>
+#include <wlr/types/wlr_seat.h>
+#include <wlr/types/wlr_viewporter.h>
+#include <wlr/types/wlr_xcursor_manager.h>
+#include <wlr/types/wlr_xdg_activation_v1.h>
+#include <wlr/types/wlr_xdg_decoration_v1.h>
+#include <wlr/types/wlr_xdg_output_v1.h>
+#include <wlr/types/wlr_xdg_shell.h>
+
+#include <wlr/util/log.h>
+
+#include <xkbcommon/xkbcommon.h>
+
+// -----------------------------------------------------------------------
+// macros
+
+#define ROUND(x) ((int)((x)+0.5))
+#define VISIBLE_ON(C,M) ((C)->monitor == (M) && ((C)->tags & (M)->tag.set[(M)->tag.selected]))
+
+// -----------------------------------------------------------------------
+// types
+
+enum
+{
+ CursorNormal,
+ CursorMove,
+ CursorResize,
+};
+
+typedef union Arg Arg;
+typedef struct Button Button;
+typedef struct Key Key;
+typedef struct Keyboard Keyboard;
+typedef struct Layer Layer;
+typedef struct Client Client;
+typedef struct Layout Layout;
+typedef struct Monitor Monitor;
+typedef struct Server Server;
+
+typedef struct Rule Rule;
+typedef struct MonitorRule MonitorRule;
+
+struct Rectangle
+{
+ int x, y;
+ int w, h;
+};
+
+union Arg
+{
+ int i;
+ uint ui;
+ float f;
+ void *v;
+};
+
+struct Key
+{
+ uint modifier;
+ xkb_keysym_t sym;
+ void (*action)(Arg *);
+ Arg arg;
+};
+
+struct Button
+{
+ uint modifier;
+ uint code;
+ void (*function)(Arg *);
+ Arg arg;
+};
+
+struct Keyboard
+{
+ struct wl_list link;
+ struct wlr_input_device *device;
+ struct {
+ struct wl_listener press;
+ struct wl_listener modify;
+ struct wl_listener destroy;
+ } event;
+};
+
+struct Layer
+{
+ struct wl_list link;
+ struct wlr_layer_surface_v1 *surface;
+ enum zwlr_layer_shell_v1_layer type;
+
+ struct wlr_box geometry;
+
+ struct {
+ struct wl_listener map;
+ struct wl_listener unmap;
+ struct wl_listener commit;
+ struct wl_listener destroy;
+ } event;
+};
+
+struct Client
+{
+ struct wl_list link;
+ struct wl_list stack;
+ struct wl_list focus;
+
+ struct wlr_xdg_surface *xdg;
+
+ struct {
+ struct wl_listener map;
+ struct wl_listener unmap;
+ struct wl_listener commit;
+ struct wl_listener destroy;
+ struct wl_listener request_move;
+ struct wl_listener request_title;
+ struct wl_listener request_resize;
+ struct wl_listener request_fullscreen;
+ } event;
+
+ struct wlr_box geometry, oldgeometry;
+
+ Monitor *monitor;
+
+ uint tags;
+ int border : 4;
+ int ismapped : 1;
+ int isfloating : 1;
+ int isurgent : 1;
+ int isfullscreen : 1;
+
+ uint32 resize;
+};
+
+struct Layout
+{
+ char *symbol;
+ void (*arrange)(Monitor *);
+};
+
+struct Monitor
+{
+ struct wl_list link;
+ struct wlr_output *output;
+ struct {
+ struct wl_listener render;
+ struct wl_listener destroy;
+ } event;
+
+ struct wlr_box geometry;
+ struct wlr_box window;
+ struct wl_list layer[4];
+
+ Layout *layout, *layouts[2];
+ struct {
+ uint set[2];
+ uint selected;
+ } tag;
+ struct {
+ double frac;
+ int len;
+ } master;
+};
+
+struct MonitorRule
+{
+ char *name;
+ Layout *layout;
+ int x, y;
+ float scale;
+ enum wl_output_transform transform;
+ struct {
+ double frac;
+ int len;
+ } master;
+};
+
+struct Rule
+{
+ char *id;
+ char *title;
+ uint tags;
+ int isfloating;
+ int monitor;
+};
+
+struct Server
+{
+ struct wl_display *display;
+ struct wlr_backend *backend;
+ struct wlr_renderer *renderer;
+ struct wlr_presentation *present;
+ struct wlr_xdg_activation_v1 *activate;
+
+ struct {
+ struct wlr_xdg_shell *xdg;
+ struct wlr_layer_shell_v1 *layer;
+ } shell;
+
+ struct {
+ struct wl_list list;
+ struct wl_list stack;
+ struct wl_list focus;
+ } client;
+ Client *selected;
+
+ struct {
+ Client *client;
+ double x, y;
+ struct wlr_box box;
+ } grab;
+ uint32 resize;
+
+ struct {
+ struct wlr_output_layout *layout;
+ struct wl_list list;
+ struct wlr_box geometry;
+ struct wlr_output_manager_v1 *manager;
+ Monitor *selected;
+ } monitor;
+
+ struct {
+ struct wlr_cursor *dot;
+ struct wlr_xcursor_manager *manager;
+ int mode;
+ } cursor;
+
+ struct {
+ struct wlr_seat *seat;
+ struct wl_list keyboards;
+ struct wlr_idle *idle;
+ } input;
+
+ struct {
+ struct wl_listener make_input;
+ struct wl_listener make_monitor;
+ struct wl_listener make_xdg_surface;
+ struct wl_listener make_layer_surface;
+
+ struct wl_listener monitor_test;
+ struct wl_listener monitor_apply;
+ struct wl_listener monitor_change;
+
+ struct wl_listener cursor_move;
+ struct wl_listener cursor_move_abs;
+ struct wl_listener cursor_button;
+ struct wl_listener cursor_axis;
+ struct wl_listener cursor_frame;
+
+ struct wl_listener request_cursor;
+ struct wl_listener request_activate;
+ struct wl_listener request_set_selection;
+ } event;
+};
+
+extern struct Server server;
+
+// -----------------------------------------------------------------------
+// functions
+
+/* util.c */
+void scale_box(struct wlr_box *, float);
+void exclude(struct wlr_box *, uint32, int32, int32, int32, int32, int32 );
+
+/* render.c */
+void render_monitor(struct wl_listener *, void *);
+
+/* xdg.c */
+void make_xdg_surface(struct wl_listener *, void *);
+
+/* layer.c */
+void make_layer_surface(struct wl_listener *, void *);
+
+/* input.c */
+void make_input(struct wl_listener *, void *);
+void notify_move(uint32 time);
+
+void cursor_axis(struct wl_listener *, void *);
+void cursor_frame(struct wl_listener *, void *);
+void cursor_button(struct wl_listener *, void *);
+void cursor_move(struct wl_listener *, void *);
+void cursor_move_abs(struct wl_listener *, void *);
+
+void request_cursor(struct wl_listener *, void *);
+void request_set_selection(struct wl_listener *, void *);
+
+/* client.c */
+void rules(Client *);
+void focus(Client *, int lift);
+void resize(Client *, int x, int y, int w, int h, int interact);
+void attach(Client *, Monitor *, uint tags);
+void floating(Client *, int);
+
+void move_client(Arg *arg);
+void float_client(Arg *arg);
+void resize_client(Arg *arg);
+
+void request_activate(struct wl_listener *, void *);
+
+Client *selected_client(void);
+Client *client_at(double x, double y);
+struct wlr_surface *client_surface_at(Client *, double cx, double cy, double *sx, double *sy);
+struct wlr_surface *top_surface(Client *);
+
+/* monitor.c */
+void tile(Monitor *);
+void arrange(Monitor *);
+void stratify(Monitor *);
+Client *focused_client(Monitor *);
+Monitor *monitor_at(double x, double y);
+
+void monitor_test(struct wl_listener *, void *);
+void monitor_apply(struct wl_listener *, void *);
+void monitor_change(struct wl_listener *, void *);
+
+void free_monitor(struct wl_listener *, void *);
+void make_monitor(struct wl_listener *, void *);
+
+#define CONFIG(a,b,...) extern a cfg·##b
+#include "config.h"
+#undef CONFIG
diff --git a/src/cmd/wm/xdg-shell-protocol.c b/src/cmd/wm/xdg-shell-protocol.c
new file mode 100644
index 0000000..62a2612
--- /dev/null
+++ b/src/cmd/wm/xdg-shell-protocol.c
@@ -0,0 +1,181 @@
+/* Generated by wayland-scanner 1.19.0 */
+
+/*
+ * Copyright © 2008-2013 Kristian Høgsberg
+ * Copyright © 2013 Rafael Antognolli
+ * Copyright © 2013 Jasper St. Pierre
+ * Copyright © 2010-2013 Intel Corporation
+ * Copyright © 2015-2017 Samsung Electronics Co., Ltd
+ * Copyright © 2015-2017 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include "wayland-util.h"
+
+#ifndef __has_attribute
+# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
+#endif
+
+#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
+#define WL_PRIVATE __attribute__ ((visibility("hidden")))
+#else
+#define WL_PRIVATE
+#endif
+
+extern const struct wl_interface wl_output_interface;
+extern const struct wl_interface wl_seat_interface;
+extern const struct wl_interface wl_surface_interface;
+extern const struct wl_interface xdg_popup_interface;
+extern const struct wl_interface xdg_positioner_interface;
+extern const struct wl_interface xdg_surface_interface;
+extern const struct wl_interface xdg_toplevel_interface;
+
+static const struct wl_interface *xdg_shell_types[] = {
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ &xdg_positioner_interface,
+ &xdg_surface_interface,
+ &wl_surface_interface,
+ &xdg_toplevel_interface,
+ &xdg_popup_interface,
+ &xdg_surface_interface,
+ &xdg_positioner_interface,
+ &xdg_toplevel_interface,
+ &wl_seat_interface,
+ NULL,
+ NULL,
+ NULL,
+ &wl_seat_interface,
+ NULL,
+ &wl_seat_interface,
+ NULL,
+ NULL,
+ &wl_output_interface,
+ &wl_seat_interface,
+ NULL,
+ &xdg_positioner_interface,
+ NULL,
+};
+
+static const struct wl_message xdg_wm_base_requests[] = {
+ { "destroy", "", xdg_shell_types + 0 },
+ { "create_positioner", "n", xdg_shell_types + 4 },
+ { "get_xdg_surface", "no", xdg_shell_types + 5 },
+ { "pong", "u", xdg_shell_types + 0 },
+};
+
+static const struct wl_message xdg_wm_base_events[] = {
+ { "ping", "u", xdg_shell_types + 0 },
+};
+
+WL_PRIVATE const struct wl_interface xdg_wm_base_interface = {
+ "xdg_wm_base", 3,
+ 4, xdg_wm_base_requests,
+ 1, xdg_wm_base_events,
+};
+
+static const struct wl_message xdg_positioner_requests[] = {
+ { "destroy", "", xdg_shell_types + 0 },
+ { "set_size", "ii", xdg_shell_types + 0 },
+ { "set_anchor_rect", "iiii", xdg_shell_types + 0 },
+ { "set_anchor", "u", xdg_shell_types + 0 },
+ { "set_gravity", "u", xdg_shell_types + 0 },
+ { "set_constraint_adjustment", "u", xdg_shell_types + 0 },
+ { "set_offset", "ii", xdg_shell_types + 0 },
+ { "set_reactive", "3", xdg_shell_types + 0 },
+ { "set_parent_size", "3ii", xdg_shell_types + 0 },
+ { "set_parent_configure", "3u", xdg_shell_types + 0 },
+};
+
+WL_PRIVATE const struct wl_interface xdg_positioner_interface = {
+ "xdg_positioner", 3,
+ 10, xdg_positioner_requests,
+ 0, NULL,
+};
+
+static const struct wl_message xdg_surface_requests[] = {
+ { "destroy", "", xdg_shell_types + 0 },
+ { "get_toplevel", "n", xdg_shell_types + 7 },
+ { "get_popup", "n?oo", xdg_shell_types + 8 },
+ { "set_window_geometry", "iiii", xdg_shell_types + 0 },
+ { "ack_configure", "u", xdg_shell_types + 0 },
+};
+
+static const struct wl_message xdg_surface_events[] = {
+ { "configure", "u", xdg_shell_types + 0 },
+};
+
+WL_PRIVATE const struct wl_interface xdg_surface_interface = {
+ "xdg_surface", 3,
+ 5, xdg_surface_requests,
+ 1, xdg_surface_events,
+};
+
+static const struct wl_message xdg_toplevel_requests[] = {
+ { "destroy", "", xdg_shell_types + 0 },
+ { "set_parent", "?o", xdg_shell_types + 11 },
+ { "set_title", "s", xdg_shell_types + 0 },
+ { "set_app_id", "s", xdg_shell_types + 0 },
+ { "show_window_menu", "ouii", xdg_shell_types + 12 },
+ { "move", "ou", xdg_shell_types + 16 },
+ { "resize", "ouu", xdg_shell_types + 18 },
+ { "set_max_size", "ii", xdg_shell_types + 0 },
+ { "set_min_size", "ii", xdg_shell_types + 0 },
+ { "set_maximized", "", xdg_shell_types + 0 },
+ { "unset_maximized", "", xdg_shell_types + 0 },
+ { "set_fullscreen", "?o", xdg_shell_types + 21 },
+ { "unset_fullscreen", "", xdg_shell_types + 0 },
+ { "set_minimized", "", xdg_shell_types + 0 },
+};
+
+static const struct wl_message xdg_toplevel_events[] = {
+ { "configure", "iia", xdg_shell_types + 0 },
+ { "close", "", xdg_shell_types + 0 },
+};
+
+WL_PRIVATE const struct wl_interface xdg_toplevel_interface = {
+ "xdg_toplevel", 3,
+ 14, xdg_toplevel_requests,
+ 2, xdg_toplevel_events,
+};
+
+static const struct wl_message xdg_popup_requests[] = {
+ { "destroy", "", xdg_shell_types + 0 },
+ { "grab", "ou", xdg_shell_types + 22 },
+ { "reposition", "3ou", xdg_shell_types + 24 },
+};
+
+static const struct wl_message xdg_popup_events[] = {
+ { "configure", "iiii", xdg_shell_types + 0 },
+ { "popup_done", "", xdg_shell_types + 0 },
+ { "repositioned", "3u", xdg_shell_types + 0 },
+};
+
+WL_PRIVATE const struct wl_interface xdg_popup_interface = {
+ "xdg_popup", 3,
+ 3, xdg_popup_requests,
+ 3, xdg_popup_events,
+};
+
diff --git a/src/cmd/wm/xdg-shell-protocol.h b/src/cmd/wm/xdg-shell-protocol.h
new file mode 100644
index 0000000..312e5b9
--- /dev/null
+++ b/src/cmd/wm/xdg-shell-protocol.h
@@ -0,0 +1,1676 @@
+/* Generated by wayland-scanner 1.19.0 */
+
+#ifndef XDG_SHELL_SERVER_PROTOCOL_H
+#define XDG_SHELL_SERVER_PROTOCOL_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include "wayland-server.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct wl_client;
+struct wl_resource;
+
+/**
+ * @page page_xdg_shell The xdg_shell protocol
+ * @section page_ifaces_xdg_shell Interfaces
+ * - @subpage page_iface_xdg_wm_base - create desktop-style surfaces
+ * - @subpage page_iface_xdg_positioner - child surface positioner
+ * - @subpage page_iface_xdg_surface - desktop user interface surface base interface
+ * - @subpage page_iface_xdg_toplevel - toplevel surface
+ * - @subpage page_iface_xdg_popup - short-lived, popup surfaces for menus
+ * @section page_copyright_xdg_shell Copyright
+ * <pre>
+ *
+ * Copyright © 2008-2013 Kristian Høgsberg
+ * Copyright © 2013 Rafael Antognolli
+ * Copyright © 2013 Jasper St. Pierre
+ * Copyright © 2010-2013 Intel Corporation
+ * Copyright © 2015-2017 Samsung Electronics Co., Ltd
+ * Copyright © 2015-2017 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ * </pre>
+ */
+struct wl_output;
+struct wl_seat;
+struct wl_surface;
+struct xdg_popup;
+struct xdg_positioner;
+struct xdg_surface;
+struct xdg_toplevel;
+struct xdg_wm_base;
+
+#ifndef XDG_WM_BASE_INTERFACE
+#define XDG_WM_BASE_INTERFACE
+/**
+ * @page page_iface_xdg_wm_base xdg_wm_base
+ * @section page_iface_xdg_wm_base_desc Description
+ *
+ * The xdg_wm_base interface is exposed as a global object enabling clients
+ * to turn their wl_surfaces into windows in a desktop environment. It
+ * defines the basic functionality needed for clients and the compositor to
+ * create windows that can be dragged, resized, maximized, etc, as well as
+ * creating transient windows such as popup menus.
+ * @section page_iface_xdg_wm_base_api API
+ * See @ref iface_xdg_wm_base.
+ */
+/**
+ * @defgroup iface_xdg_wm_base The xdg_wm_base interface
+ *
+ * The xdg_wm_base interface is exposed as a global object enabling clients
+ * to turn their wl_surfaces into windows in a desktop environment. It
+ * defines the basic functionality needed for clients and the compositor to
+ * create windows that can be dragged, resized, maximized, etc, as well as
+ * creating transient windows such as popup menus.
+ */
+extern const struct wl_interface xdg_wm_base_interface;
+#endif
+#ifndef XDG_POSITIONER_INTERFACE
+#define XDG_POSITIONER_INTERFACE
+/**
+ * @page page_iface_xdg_positioner xdg_positioner
+ * @section page_iface_xdg_positioner_desc Description
+ *
+ * The xdg_positioner provides a collection of rules for the placement of a
+ * child surface relative to a parent surface. Rules can be defined to ensure
+ * the child surface remains within the visible area's borders, and to
+ * specify how the child surface changes its position, such as sliding along
+ * an axis, or flipping around a rectangle. These positioner-created rules are
+ * constrained by the requirement that a child surface must intersect with or
+ * be at least partially adjacent to its parent surface.
+ *
+ * See the various requests for details about possible rules.
+ *
+ * At the time of the request, the compositor makes a copy of the rules
+ * specified by the xdg_positioner. Thus, after the request is complete the
+ * xdg_positioner object can be destroyed or reused; further changes to the
+ * object will have no effect on previous usages.
+ *
+ * For an xdg_positioner object to be considered complete, it must have a
+ * non-zero size set by set_size, and a non-zero anchor rectangle set by
+ * set_anchor_rect. Passing an incomplete xdg_positioner object when
+ * positioning a surface raises an error.
+ * @section page_iface_xdg_positioner_api API
+ * See @ref iface_xdg_positioner.
+ */
+/**
+ * @defgroup iface_xdg_positioner The xdg_positioner interface
+ *
+ * The xdg_positioner provides a collection of rules for the placement of a
+ * child surface relative to a parent surface. Rules can be defined to ensure
+ * the child surface remains within the visible area's borders, and to
+ * specify how the child surface changes its position, such as sliding along
+ * an axis, or flipping around a rectangle. These positioner-created rules are
+ * constrained by the requirement that a child surface must intersect with or
+ * be at least partially adjacent to its parent surface.
+ *
+ * See the various requests for details about possible rules.
+ *
+ * At the time of the request, the compositor makes a copy of the rules
+ * specified by the xdg_positioner. Thus, after the request is complete the
+ * xdg_positioner object can be destroyed or reused; further changes to the
+ * object will have no effect on previous usages.
+ *
+ * For an xdg_positioner object to be considered complete, it must have a
+ * non-zero size set by set_size, and a non-zero anchor rectangle set by
+ * set_anchor_rect. Passing an incomplete xdg_positioner object when
+ * positioning a surface raises an error.
+ */
+extern const struct wl_interface xdg_positioner_interface;
+#endif
+#ifndef XDG_SURFACE_INTERFACE
+#define XDG_SURFACE_INTERFACE
+/**
+ * @page page_iface_xdg_surface xdg_surface
+ * @section page_iface_xdg_surface_desc Description
+ *
+ * An interface that may be implemented by a wl_surface, for
+ * implementations that provide a desktop-style user interface.
+ *
+ * It provides a base set of functionality required to construct user
+ * interface elements requiring management by the compositor, such as
+ * toplevel windows, menus, etc. The types of functionality are split into
+ * xdg_surface roles.
+ *
+ * Creating an xdg_surface does not set the role for a wl_surface. In order
+ * to map an xdg_surface, the client must create a role-specific object
+ * using, e.g., get_toplevel, get_popup. The wl_surface for any given
+ * xdg_surface can have at most one role, and may not be assigned any role
+ * not based on xdg_surface.
+ *
+ * A role must be assigned before any other requests are made to the
+ * xdg_surface object.
+ *
+ * The client must call wl_surface.commit on the corresponding wl_surface
+ * for the xdg_surface state to take effect.
+ *
+ * Creating an xdg_surface from a wl_surface which has a buffer attached or
+ * committed is a client error, and any attempts by a client to attach or
+ * manipulate a buffer prior to the first xdg_surface.configure call must
+ * also be treated as errors.
+ *
+ * After creating a role-specific object and setting it up, the client must
+ * perform an initial commit without any buffer attached. The compositor
+ * will reply with an xdg_surface.configure event. The client must
+ * acknowledge it and is then allowed to attach a buffer to map the surface.
+ *
+ * Mapping an xdg_surface-based role surface is defined as making it
+ * possible for the surface to be shown by the compositor. Note that
+ * a mapped surface is not guaranteed to be visible once it is mapped.
+ *
+ * For an xdg_surface to be mapped by the compositor, the following
+ * conditions must be met:
+ * (1) the client has assigned an xdg_surface-based role to the surface
+ * (2) the client has set and committed the xdg_surface state and the
+ * role-dependent state to the surface
+ * (3) the client has committed a buffer to the surface
+ *
+ * A newly-unmapped surface is considered to have met condition (1) out
+ * of the 3 required conditions for mapping a surface if its role surface
+ * has not been destroyed.
+ * @section page_iface_xdg_surface_api API
+ * See @ref iface_xdg_surface.
+ */
+/**
+ * @defgroup iface_xdg_surface The xdg_surface interface
+ *
+ * An interface that may be implemented by a wl_surface, for
+ * implementations that provide a desktop-style user interface.
+ *
+ * It provides a base set of functionality required to construct user
+ * interface elements requiring management by the compositor, such as
+ * toplevel windows, menus, etc. The types of functionality are split into
+ * xdg_surface roles.
+ *
+ * Creating an xdg_surface does not set the role for a wl_surface. In order
+ * to map an xdg_surface, the client must create a role-specific object
+ * using, e.g., get_toplevel, get_popup. The wl_surface for any given
+ * xdg_surface can have at most one role, and may not be assigned any role
+ * not based on xdg_surface.
+ *
+ * A role must be assigned before any other requests are made to the
+ * xdg_surface object.
+ *
+ * The client must call wl_surface.commit on the corresponding wl_surface
+ * for the xdg_surface state to take effect.
+ *
+ * Creating an xdg_surface from a wl_surface which has a buffer attached or
+ * committed is a client error, and any attempts by a client to attach or
+ * manipulate a buffer prior to the first xdg_surface.configure call must
+ * also be treated as errors.
+ *
+ * After creating a role-specific object and setting it up, the client must
+ * perform an initial commit without any buffer attached. The compositor
+ * will reply with an xdg_surface.configure event. The client must
+ * acknowledge it and is then allowed to attach a buffer to map the surface.
+ *
+ * Mapping an xdg_surface-based role surface is defined as making it
+ * possible for the surface to be shown by the compositor. Note that
+ * a mapped surface is not guaranteed to be visible once it is mapped.
+ *
+ * For an xdg_surface to be mapped by the compositor, the following
+ * conditions must be met:
+ * (1) the client has assigned an xdg_surface-based role to the surface
+ * (2) the client has set and committed the xdg_surface state and the
+ * role-dependent state to the surface
+ * (3) the client has committed a buffer to the surface
+ *
+ * A newly-unmapped surface is considered to have met condition (1) out
+ * of the 3 required conditions for mapping a surface if its role surface
+ * has not been destroyed.
+ */
+extern const struct wl_interface xdg_surface_interface;
+#endif
+#ifndef XDG_TOPLEVEL_INTERFACE
+#define XDG_TOPLEVEL_INTERFACE
+/**
+ * @page page_iface_xdg_toplevel xdg_toplevel
+ * @section page_iface_xdg_toplevel_desc Description
+ *
+ * This interface defines an xdg_surface role which allows a surface to,
+ * among other things, set window-like properties such as maximize,
+ * fullscreen, and minimize, set application-specific metadata like title and
+ * id, and well as trigger user interactive operations such as interactive
+ * resize and move.
+ *
+ * Unmapping an xdg_toplevel means that the surface cannot be shown
+ * by the compositor until it is explicitly mapped again.
+ * All active operations (e.g., move, resize) are canceled and all
+ * attributes (e.g. title, state, stacking, ...) are discarded for
+ * an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to
+ * the state it had right after xdg_surface.get_toplevel. The client
+ * can re-map the toplevel by perfoming a commit without any buffer
+ * attached, waiting for a configure event and handling it as usual (see
+ * xdg_surface description).
+ *
+ * Attaching a null buffer to a toplevel unmaps the surface.
+ * @section page_iface_xdg_toplevel_api API
+ * See @ref iface_xdg_toplevel.
+ */
+/**
+ * @defgroup iface_xdg_toplevel The xdg_toplevel interface
+ *
+ * This interface defines an xdg_surface role which allows a surface to,
+ * among other things, set window-like properties such as maximize,
+ * fullscreen, and minimize, set application-specific metadata like title and
+ * id, and well as trigger user interactive operations such as interactive
+ * resize and move.
+ *
+ * Unmapping an xdg_toplevel means that the surface cannot be shown
+ * by the compositor until it is explicitly mapped again.
+ * All active operations (e.g., move, resize) are canceled and all
+ * attributes (e.g. title, state, stacking, ...) are discarded for
+ * an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to
+ * the state it had right after xdg_surface.get_toplevel. The client
+ * can re-map the toplevel by perfoming a commit without any buffer
+ * attached, waiting for a configure event and handling it as usual (see
+ * xdg_surface description).
+ *
+ * Attaching a null buffer to a toplevel unmaps the surface.
+ */
+extern const struct wl_interface xdg_toplevel_interface;
+#endif
+#ifndef XDG_POPUP_INTERFACE
+#define XDG_POPUP_INTERFACE
+/**
+ * @page page_iface_xdg_popup xdg_popup
+ * @section page_iface_xdg_popup_desc Description
+ *
+ * A popup surface is a short-lived, temporary surface. It can be used to
+ * implement for example menus, popovers, tooltips and other similar user
+ * interface concepts.
+ *
+ * A popup can be made to take an explicit grab. See xdg_popup.grab for
+ * details.
+ *
+ * When the popup is dismissed, a popup_done event will be sent out, and at
+ * the same time the surface will be unmapped. See the xdg_popup.popup_done
+ * event for details.
+ *
+ * Explicitly destroying the xdg_popup object will also dismiss the popup and
+ * unmap the surface. Clients that want to dismiss the popup when another
+ * surface of their own is clicked should dismiss the popup using the destroy
+ * request.
+ *
+ * A newly created xdg_popup will be stacked on top of all previously created
+ * xdg_popup surfaces associated with the same xdg_toplevel.
+ *
+ * The parent of an xdg_popup must be mapped (see the xdg_surface
+ * description) before the xdg_popup itself.
+ *
+ * The client must call wl_surface.commit on the corresponding wl_surface
+ * for the xdg_popup state to take effect.
+ * @section page_iface_xdg_popup_api API
+ * See @ref iface_xdg_popup.
+ */
+/**
+ * @defgroup iface_xdg_popup The xdg_popup interface
+ *
+ * A popup surface is a short-lived, temporary surface. It can be used to
+ * implement for example menus, popovers, tooltips and other similar user
+ * interface concepts.
+ *
+ * A popup can be made to take an explicit grab. See xdg_popup.grab for
+ * details.
+ *
+ * When the popup is dismissed, a popup_done event will be sent out, and at
+ * the same time the surface will be unmapped. See the xdg_popup.popup_done
+ * event for details.
+ *
+ * Explicitly destroying the xdg_popup object will also dismiss the popup and
+ * unmap the surface. Clients that want to dismiss the popup when another
+ * surface of their own is clicked should dismiss the popup using the destroy
+ * request.
+ *
+ * A newly created xdg_popup will be stacked on top of all previously created
+ * xdg_popup surfaces associated with the same xdg_toplevel.
+ *
+ * The parent of an xdg_popup must be mapped (see the xdg_surface
+ * description) before the xdg_popup itself.
+ *
+ * The client must call wl_surface.commit on the corresponding wl_surface
+ * for the xdg_popup state to take effect.
+ */
+extern const struct wl_interface xdg_popup_interface;
+#endif
+
+#ifndef XDG_WM_BASE_ERROR_ENUM
+#define XDG_WM_BASE_ERROR_ENUM
+enum xdg_wm_base_error {
+ /**
+ * given wl_surface has another role
+ */
+ XDG_WM_BASE_ERROR_ROLE = 0,
+ /**
+ * xdg_wm_base was destroyed before children
+ */
+ XDG_WM_BASE_ERROR_DEFUNCT_SURFACES = 1,
+ /**
+ * the client tried to map or destroy a non-topmost popup
+ */
+ XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP = 2,
+ /**
+ * the client specified an invalid popup parent surface
+ */
+ XDG_WM_BASE_ERROR_INVALID_POPUP_PARENT = 3,
+ /**
+ * the client provided an invalid surface state
+ */
+ XDG_WM_BASE_ERROR_INVALID_SURFACE_STATE = 4,
+ /**
+ * the client provided an invalid positioner
+ */
+ XDG_WM_BASE_ERROR_INVALID_POSITIONER = 5,
+};
+#endif /* XDG_WM_BASE_ERROR_ENUM */
+
+/**
+ * @ingroup iface_xdg_wm_base
+ * @struct xdg_wm_base_interface
+ */
+struct xdg_wm_base_interface {
+ /**
+ * destroy xdg_wm_base
+ *
+ * Destroy this xdg_wm_base object.
+ *
+ * Destroying a bound xdg_wm_base object while there are surfaces
+ * still alive created by this xdg_wm_base object instance is
+ * illegal and will result in a protocol error.
+ */
+ void (*destroy)(struct wl_client *client,
+ struct wl_resource *resource);
+ /**
+ * create a positioner object
+ *
+ * Create a positioner object. A positioner object is used to
+ * position surfaces relative to some parent surface. See the
+ * interface description and xdg_surface.get_popup for details.
+ */
+ void (*create_positioner)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id);
+ /**
+ * create a shell surface from a surface
+ *
+ * This creates an xdg_surface for the given surface. While
+ * xdg_surface itself is not a role, the corresponding surface may
+ * only be assigned a role extending xdg_surface, such as
+ * xdg_toplevel or xdg_popup. It is illegal to create an
+ * xdg_surface for a wl_surface which already has an assigned role
+ * and this will result in a protocol error.
+ *
+ * This creates an xdg_surface for the given surface. An
+ * xdg_surface is used as basis to define a role to a given
+ * surface, such as xdg_toplevel or xdg_popup. It also manages
+ * functionality shared between xdg_surface based surface roles.
+ *
+ * See the documentation of xdg_surface for more details about what
+ * an xdg_surface is and how it is used.
+ */
+ void (*get_xdg_surface)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id,
+ struct wl_resource *surface);
+ /**
+ * respond to a ping event
+ *
+ * A client must respond to a ping event with a pong request or
+ * the client may be deemed unresponsive. See xdg_wm_base.ping.
+ * @param serial serial of the ping event
+ */
+ void (*pong)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t serial);
+};
+
+#define XDG_WM_BASE_PING 0
+
+/**
+ * @ingroup iface_xdg_wm_base
+ */
+#define XDG_WM_BASE_PING_SINCE_VERSION 1
+
+/**
+ * @ingroup iface_xdg_wm_base
+ */
+#define XDG_WM_BASE_DESTROY_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_wm_base
+ */
+#define XDG_WM_BASE_CREATE_POSITIONER_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_wm_base
+ */
+#define XDG_WM_BASE_GET_XDG_SURFACE_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_wm_base
+ */
+#define XDG_WM_BASE_PONG_SINCE_VERSION 1
+
+/**
+ * @ingroup iface_xdg_wm_base
+ * Sends an ping event to the client owning the resource.
+ * @param resource_ The client's resource
+ * @param serial pass this to the pong request
+ */
+static inline void
+xdg_wm_base_send_ping(struct wl_resource *resource_, uint32_t serial)
+{
+ wl_resource_post_event(resource_, XDG_WM_BASE_PING, serial);
+}
+
+#ifndef XDG_POSITIONER_ERROR_ENUM
+#define XDG_POSITIONER_ERROR_ENUM
+enum xdg_positioner_error {
+ /**
+ * invalid input provided
+ */
+ XDG_POSITIONER_ERROR_INVALID_INPUT = 0,
+};
+#endif /* XDG_POSITIONER_ERROR_ENUM */
+
+#ifndef XDG_POSITIONER_ANCHOR_ENUM
+#define XDG_POSITIONER_ANCHOR_ENUM
+enum xdg_positioner_anchor {
+ XDG_POSITIONER_ANCHOR_NONE = 0,
+ XDG_POSITIONER_ANCHOR_TOP = 1,
+ XDG_POSITIONER_ANCHOR_BOTTOM = 2,
+ XDG_POSITIONER_ANCHOR_LEFT = 3,
+ XDG_POSITIONER_ANCHOR_RIGHT = 4,
+ XDG_POSITIONER_ANCHOR_TOP_LEFT = 5,
+ XDG_POSITIONER_ANCHOR_BOTTOM_LEFT = 6,
+ XDG_POSITIONER_ANCHOR_TOP_RIGHT = 7,
+ XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT = 8,
+};
+#endif /* XDG_POSITIONER_ANCHOR_ENUM */
+
+#ifndef XDG_POSITIONER_GRAVITY_ENUM
+#define XDG_POSITIONER_GRAVITY_ENUM
+enum xdg_positioner_gravity {
+ XDG_POSITIONER_GRAVITY_NONE = 0,
+ XDG_POSITIONER_GRAVITY_TOP = 1,
+ XDG_POSITIONER_GRAVITY_BOTTOM = 2,
+ XDG_POSITIONER_GRAVITY_LEFT = 3,
+ XDG_POSITIONER_GRAVITY_RIGHT = 4,
+ XDG_POSITIONER_GRAVITY_TOP_LEFT = 5,
+ XDG_POSITIONER_GRAVITY_BOTTOM_LEFT = 6,
+ XDG_POSITIONER_GRAVITY_TOP_RIGHT = 7,
+ XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT = 8,
+};
+#endif /* XDG_POSITIONER_GRAVITY_ENUM */
+
+#ifndef XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM
+#define XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM
+/**
+ * @ingroup iface_xdg_positioner
+ * vertically resize the surface
+ *
+ * Resize the surface vertically so that it is completely unconstrained.
+ */
+enum xdg_positioner_constraint_adjustment {
+ XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_NONE = 0,
+ XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X = 1,
+ XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y = 2,
+ XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X = 4,
+ XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y = 8,
+ XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X = 16,
+ XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y = 32,
+};
+#endif /* XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM */
+
+/**
+ * @ingroup iface_xdg_positioner
+ * @struct xdg_positioner_interface
+ */
+struct xdg_positioner_interface {
+ /**
+ * destroy the xdg_positioner object
+ *
+ * Notify the compositor that the xdg_positioner will no longer
+ * be used.
+ */
+ void (*destroy)(struct wl_client *client,
+ struct wl_resource *resource);
+ /**
+ * set the size of the to-be positioned rectangle
+ *
+ * Set the size of the surface that is to be positioned with the
+ * positioner object. The size is in surface-local coordinates and
+ * corresponds to the window geometry. See
+ * xdg_surface.set_window_geometry.
+ *
+ * If a zero or negative size is set the invalid_input error is
+ * raised.
+ * @param width width of positioned rectangle
+ * @param height height of positioned rectangle
+ */
+ void (*set_size)(struct wl_client *client,
+ struct wl_resource *resource,
+ int32_t width,
+ int32_t height);
+ /**
+ * set the anchor rectangle within the parent surface
+ *
+ * Specify the anchor rectangle within the parent surface that
+ * the child surface will be placed relative to. The rectangle is
+ * relative to the window geometry as defined by
+ * xdg_surface.set_window_geometry of the parent surface.
+ *
+ * When the xdg_positioner object is used to position a child
+ * surface, the anchor rectangle may not extend outside the window
+ * geometry of the positioned child's parent surface.
+ *
+ * If a negative size is set the invalid_input error is raised.
+ * @param x x position of anchor rectangle
+ * @param y y position of anchor rectangle
+ * @param width width of anchor rectangle
+ * @param height height of anchor rectangle
+ */
+ void (*set_anchor_rect)(struct wl_client *client,
+ struct wl_resource *resource,
+ int32_t x,
+ int32_t y,
+ int32_t width,
+ int32_t height);
+ /**
+ * set anchor rectangle anchor
+ *
+ * Defines the anchor point for the anchor rectangle. The
+ * specified anchor is used derive an anchor point that the child
+ * surface will be positioned relative to. If a corner anchor is
+ * set (e.g. 'top_left' or 'bottom_right'), the anchor point will
+ * be at the specified corner; otherwise, the derived anchor point
+ * will be centered on the specified edge, or in the center of the
+ * anchor rectangle if no edge is specified.
+ * @param anchor anchor
+ */
+ void (*set_anchor)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t anchor);
+ /**
+ * set child surface gravity
+ *
+ * Defines in what direction a surface should be positioned,
+ * relative to the anchor point of the parent surface. If a corner
+ * gravity is specified (e.g. 'bottom_right' or 'top_left'), then
+ * the child surface will be placed towards the specified gravity;
+ * otherwise, the child surface will be centered over the anchor
+ * point on any axis that had no gravity specified.
+ * @param gravity gravity direction
+ */
+ void (*set_gravity)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t gravity);
+ /**
+ * set the adjustment to be done when constrained
+ *
+ * Specify how the window should be positioned if the originally
+ * intended position caused the surface to be constrained, meaning
+ * at least partially outside positioning boundaries set by the
+ * compositor. The adjustment is set by constructing a bitmask
+ * describing the adjustment to be made when the surface is
+ * constrained on that axis.
+ *
+ * If no bit for one axis is set, the compositor will assume that
+ * the child surface should not change its position on that axis
+ * when constrained.
+ *
+ * If more than one bit for one axis is set, the order of how
+ * adjustments are applied is specified in the corresponding
+ * adjustment descriptions.
+ *
+ * The default adjustment is none.
+ * @param constraint_adjustment bit mask of constraint adjustments
+ */
+ void (*set_constraint_adjustment)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t constraint_adjustment);
+ /**
+ * set surface position offset
+ *
+ * Specify the surface position offset relative to the position
+ * of the anchor on the anchor rectangle and the anchor on the
+ * surface. For example if the anchor of the anchor rectangle is at
+ * (x, y), the surface has the gravity bottom|right, and the offset
+ * is (ox, oy), the calculated surface position will be (x + ox, y
+ * + oy). The offset position of the surface is the one used for
+ * constraint testing. See set_constraint_adjustment.
+ *
+ * An example use case is placing a popup menu on top of a user
+ * interface element, while aligning the user interface element of
+ * the parent surface with some user interface element placed
+ * somewhere in the popup surface.
+ * @param x surface position x offset
+ * @param y surface position y offset
+ */
+ void (*set_offset)(struct wl_client *client,
+ struct wl_resource *resource,
+ int32_t x,
+ int32_t y);
+ /**
+ * continuously reconstrain the surface
+ *
+ * When set reactive, the surface is reconstrained if the
+ * conditions used for constraining changed, e.g. the parent window
+ * moved.
+ *
+ * If the conditions changed and the popup was reconstrained, an
+ * xdg_popup.configure event is sent with updated geometry,
+ * followed by an xdg_surface.configure event.
+ * @since 3
+ */
+ void (*set_reactive)(struct wl_client *client,
+ struct wl_resource *resource);
+ /**
+ *
+ *
+ * Set the parent window geometry the compositor should use when
+ * positioning the popup. The compositor may use this information
+ * to determine the future state the popup should be constrained
+ * using. If this doesn't match the dimension of the parent the
+ * popup is eventually positioned against, the behavior is
+ * undefined.
+ *
+ * The arguments are given in the surface-local coordinate space.
+ * @param parent_width future window geometry width of parent
+ * @param parent_height future window geometry height of parent
+ * @since 3
+ */
+ void (*set_parent_size)(struct wl_client *client,
+ struct wl_resource *resource,
+ int32_t parent_width,
+ int32_t parent_height);
+ /**
+ * set parent configure this is a response to
+ *
+ * Set the serial of an xdg_surface.configure event this
+ * positioner will be used in response to. The compositor may use
+ * this information together with set_parent_size to determine what
+ * future state the popup should be constrained using.
+ * @param serial serial of parent configure event
+ * @since 3
+ */
+ void (*set_parent_configure)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t serial);
+};
+
+
+/**
+ * @ingroup iface_xdg_positioner
+ */
+#define XDG_POSITIONER_DESTROY_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_positioner
+ */
+#define XDG_POSITIONER_SET_SIZE_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_positioner
+ */
+#define XDG_POSITIONER_SET_ANCHOR_RECT_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_positioner
+ */
+#define XDG_POSITIONER_SET_ANCHOR_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_positioner
+ */
+#define XDG_POSITIONER_SET_GRAVITY_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_positioner
+ */
+#define XDG_POSITIONER_SET_CONSTRAINT_ADJUSTMENT_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_positioner
+ */
+#define XDG_POSITIONER_SET_OFFSET_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_positioner
+ */
+#define XDG_POSITIONER_SET_REACTIVE_SINCE_VERSION 3
+/**
+ * @ingroup iface_xdg_positioner
+ */
+#define XDG_POSITIONER_SET_PARENT_SIZE_SINCE_VERSION 3
+/**
+ * @ingroup iface_xdg_positioner
+ */
+#define XDG_POSITIONER_SET_PARENT_CONFIGURE_SINCE_VERSION 3
+
+#ifndef XDG_SURFACE_ERROR_ENUM
+#define XDG_SURFACE_ERROR_ENUM
+enum xdg_surface_error {
+ XDG_SURFACE_ERROR_NOT_CONSTRUCTED = 1,
+ XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED = 2,
+ XDG_SURFACE_ERROR_UNCONFIGURED_BUFFER = 3,
+};
+#endif /* XDG_SURFACE_ERROR_ENUM */
+
+/**
+ * @ingroup iface_xdg_surface
+ * @struct xdg_surface_interface
+ */
+struct xdg_surface_interface {
+ /**
+ * destroy the xdg_surface
+ *
+ * Destroy the xdg_surface object. An xdg_surface must only be
+ * destroyed after its role object has been destroyed.
+ */
+ void (*destroy)(struct wl_client *client,
+ struct wl_resource *resource);
+ /**
+ * assign the xdg_toplevel surface role
+ *
+ * This creates an xdg_toplevel object for the given xdg_surface
+ * and gives the associated wl_surface the xdg_toplevel role.
+ *
+ * See the documentation of xdg_toplevel for more details about
+ * what an xdg_toplevel is and how it is used.
+ */
+ void (*get_toplevel)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id);
+ /**
+ * assign the xdg_popup surface role
+ *
+ * This creates an xdg_popup object for the given xdg_surface and
+ * gives the associated wl_surface the xdg_popup role.
+ *
+ * If null is passed as a parent, a parent surface must be
+ * specified using some other protocol, before committing the
+ * initial state.
+ *
+ * See the documentation of xdg_popup for more details about what
+ * an xdg_popup is and how it is used.
+ */
+ void (*get_popup)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id,
+ struct wl_resource *parent,
+ struct wl_resource *positioner);
+ /**
+ * set the new window geometry
+ *
+ * The window geometry of a surface is its "visible bounds" from
+ * the user's perspective. Client-side decorations often have
+ * invisible portions like drop-shadows which should be ignored for
+ * the purposes of aligning, placing and constraining windows.
+ *
+ * The window geometry is double buffered, and will be applied at
+ * the time wl_surface.commit of the corresponding wl_surface is
+ * called.
+ *
+ * When maintaining a position, the compositor should treat the (x,
+ * y) coordinate of the window geometry as the top left corner of
+ * the window. A client changing the (x, y) window geometry
+ * coordinate should in general not alter the position of the
+ * window.
+ *
+ * Once the window geometry of the surface is set, it is not
+ * possible to unset it, and it will remain the same until
+ * set_window_geometry is called again, even if a new subsurface or
+ * buffer is attached.
+ *
+ * If never set, the value is the full bounds of the surface,
+ * including any subsurfaces. This updates dynamically on every
+ * commit. This unset is meant for extremely simple clients.
+ *
+ * The arguments are given in the surface-local coordinate space of
+ * the wl_surface associated with this xdg_surface.
+ *
+ * The width and height must be greater than zero. Setting an
+ * invalid size will raise an error. When applied, the effective
+ * window geometry will be the set window geometry clamped to the
+ * bounding rectangle of the combined geometry of the surface of
+ * the xdg_surface and the associated subsurfaces.
+ */
+ void (*set_window_geometry)(struct wl_client *client,
+ struct wl_resource *resource,
+ int32_t x,
+ int32_t y,
+ int32_t width,
+ int32_t height);
+ /**
+ * ack a configure event
+ *
+ * When a configure event is received, if a client commits the
+ * surface in response to the configure event, then the client must
+ * make an ack_configure request sometime before the commit
+ * request, passing along the serial of the configure event.
+ *
+ * For instance, for toplevel surfaces the compositor might use
+ * this information to move a surface to the top left only when the
+ * client has drawn itself for the maximized or fullscreen state.
+ *
+ * If the client receives multiple configure events before it can
+ * respond to one, it only has to ack the last configure event.
+ *
+ * A client is not required to commit immediately after sending an
+ * ack_configure request - it may even ack_configure several times
+ * before its next surface commit.
+ *
+ * A client may send multiple ack_configure requests before
+ * committing, but only the last request sent before a commit
+ * indicates which configure event the client really is responding
+ * to.
+ * @param serial the serial from the configure event
+ */
+ void (*ack_configure)(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t serial);
+};
+
+#define XDG_SURFACE_CONFIGURE 0
+
+/**
+ * @ingroup iface_xdg_surface
+ */
+#define XDG_SURFACE_CONFIGURE_SINCE_VERSION 1
+
+/**
+ * @ingroup iface_xdg_surface
+ */
+#define XDG_SURFACE_DESTROY_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_surface
+ */
+#define XDG_SURFACE_GET_TOPLEVEL_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_surface
+ */
+#define XDG_SURFACE_GET_POPUP_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_surface
+ */
+#define XDG_SURFACE_SET_WINDOW_GEOMETRY_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_surface
+ */
+#define XDG_SURFACE_ACK_CONFIGURE_SINCE_VERSION 1
+
+/**
+ * @ingroup iface_xdg_surface
+ * Sends an configure event to the client owning the resource.
+ * @param resource_ The client's resource
+ * @param serial serial of the configure event
+ */
+static inline void
+xdg_surface_send_configure(struct wl_resource *resource_, uint32_t serial)
+{
+ wl_resource_post_event(resource_, XDG_SURFACE_CONFIGURE, serial);
+}
+
+#ifndef XDG_TOPLEVEL_RESIZE_EDGE_ENUM
+#define XDG_TOPLEVEL_RESIZE_EDGE_ENUM
+/**
+ * @ingroup iface_xdg_toplevel
+ * edge values for resizing
+ *
+ * These values are used to indicate which edge of a surface
+ * is being dragged in a resize operation.
+ */
+enum xdg_toplevel_resize_edge {
+ XDG_TOPLEVEL_RESIZE_EDGE_NONE = 0,
+ XDG_TOPLEVEL_RESIZE_EDGE_TOP = 1,
+ XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM = 2,
+ XDG_TOPLEVEL_RESIZE_EDGE_LEFT = 4,
+ XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT = 5,
+ XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_LEFT = 6,
+ XDG_TOPLEVEL_RESIZE_EDGE_RIGHT = 8,
+ XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT = 9,
+ XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_RIGHT = 10,
+};
+#endif /* XDG_TOPLEVEL_RESIZE_EDGE_ENUM */
+
+#ifndef XDG_TOPLEVEL_STATE_ENUM
+#define XDG_TOPLEVEL_STATE_ENUM
+/**
+ * @ingroup iface_xdg_toplevel
+ * the surface is tiled
+ *
+ * The window is currently in a tiled layout and the bottom edge is
+ * considered to be adjacent to another part of the tiling grid.
+ */
+enum xdg_toplevel_state {
+ /**
+ * the surface is maximized
+ */
+ XDG_TOPLEVEL_STATE_MAXIMIZED = 1,
+ /**
+ * the surface is fullscreen
+ */
+ XDG_TOPLEVEL_STATE_FULLSCREEN = 2,
+ /**
+ * the surface is being resized
+ */
+ XDG_TOPLEVEL_STATE_RESIZING = 3,
+ /**
+ * the surface is now activated
+ */
+ XDG_TOPLEVEL_STATE_ACTIVATED = 4,
+ /**
+ * @since 2
+ */
+ XDG_TOPLEVEL_STATE_TILED_LEFT = 5,
+ /**
+ * @since 2
+ */
+ XDG_TOPLEVEL_STATE_TILED_RIGHT = 6,
+ /**
+ * @since 2
+ */
+ XDG_TOPLEVEL_STATE_TILED_TOP = 7,
+ /**
+ * @since 2
+ */
+ XDG_TOPLEVEL_STATE_TILED_BOTTOM = 8,
+};
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_STATE_TILED_LEFT_SINCE_VERSION 2
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION 2
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_STATE_TILED_TOP_SINCE_VERSION 2
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_STATE_TILED_BOTTOM_SINCE_VERSION 2
+#endif /* XDG_TOPLEVEL_STATE_ENUM */
+
+/**
+ * @ingroup iface_xdg_toplevel
+ * @struct xdg_toplevel_interface
+ */
+struct xdg_toplevel_interface {
+ /**
+ * destroy the xdg_toplevel
+ *
+ * This request destroys the role surface and unmaps the surface;
+ * see "Unmapping" behavior in interface section for details.
+ */
+ void (*destroy)(struct wl_client *client,
+ struct wl_resource *resource);
+ /**
+ * set the parent of this surface
+ *
+ * Set the "parent" of this surface. This surface should be
+ * stacked above the parent surface and all other ancestor
+ * surfaces.
+ *
+ * Parent windows should be set on dialogs, toolboxes, or other
+ * "auxiliary" surfaces, so that the parent is raised when the
+ * dialog is raised.
+ *
+ * Setting a null parent for a child window removes any
+ * parent-child relationship for the child. Setting a null parent
+ * for a window which currently has no parent is a no-op.
+ *
+ * If the parent is unmapped then its children are managed as
+ * though the parent of the now-unmapped parent has become the
+ * parent of this surface. If no parent exists for the now-unmapped
+ * parent then the children are managed as though they have no
+ * parent surface.
+ */
+ void (*set_parent)(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *parent);
+ /**
+ * set surface title
+ *
+ * Set a short title for the surface.
+ *
+ * This string may be used to identify the surface in a task bar,
+ * window list, or other user interface elements provided by the
+ * compositor.
+ *
+ * The string must be encoded in UTF-8.
+ */
+ void (*set_title)(struct wl_client *client,
+ struct wl_resource *resource,
+ const char *title);
+ /**
+ * set application ID
+ *
+ * Set an application identifier for the surface.
+ *
+ * The app ID identifies the general class of applications to which
+ * the surface belongs. The compositor can use this to group
+ * multiple surfaces together, or to determine how to launch a new
+ * application.
+ *
+ * For D-Bus activatable applications, the app ID is used as the
+ * D-Bus service name.
+ *
+ * The compositor shell will try to group application surfaces
+ * together by their app ID. As a best practice, it is suggested to
+ * select app ID's that match the basename of the application's
+ * .desktop file. For example, "org.freedesktop.FooViewer" where
+ * the .desktop file is "org.freedesktop.FooViewer.desktop".
+ *
+ * Like other properties, a set_app_id request can be sent after
+ * the xdg_toplevel has been mapped to update the property.
+ *
+ * See the desktop-entry specification [0] for more details on
+ * application identifiers and how they relate to well-known D-Bus
+ * names and .desktop files.
+ *
+ * [0] http://standards.freedesktop.org/desktop-entry-spec/
+ */
+ void (*set_app_id)(struct wl_client *client,
+ struct wl_resource *resource,
+ const char *app_id);
+ /**
+ * show the window menu
+ *
+ * Clients implementing client-side decorations might want to
+ * show a context menu when right-clicking on the decorations,
+ * giving the user a menu that they can use to maximize or minimize
+ * the window.
+ *
+ * This request asks the compositor to pop up such a window menu at
+ * the given position, relative to the local surface coordinates of
+ * the parent surface. There are no guarantees as to what menu
+ * items the window menu contains.
+ *
+ * This request must be used in response to some sort of user
+ * action like a button press, key press, or touch down event.
+ * @param seat the wl_seat of the user event
+ * @param serial the serial of the user event
+ * @param x the x position to pop up the window menu at
+ * @param y the y position to pop up the window menu at
+ */
+ void (*show_window_menu)(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *seat,
+ uint32_t serial,
+ int32_t x,
+ int32_t y);
+ /**
+ * start an interactive move
+ *
+ * Start an interactive, user-driven move of the surface.
+ *
+ * This request must be used in response to some sort of user
+ * action like a button press, key press, or touch down event. The
+ * passed serial is used to determine the type of interactive move
+ * (touch, pointer, etc).
+ *
+ * The server may ignore move requests depending on the state of
+ * the surface (e.g. fullscreen or maximized), or if the passed
+ * serial is no longer valid.
+ *
+ * If triggered, the surface will lose the focus of the device
+ * (wl_pointer, wl_touch, etc) used for the move. It is up to the
+ * compositor to visually indicate that the move is taking place,
+ * such as updating a pointer cursor, during the move. There is no
+ * guarantee that the device focus will return when the move is
+ * completed.
+ * @param seat the wl_seat of the user event
+ * @param serial the serial of the user event
+ */
+ void (*move)(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *seat,
+ uint32_t serial);
+ /**
+ * start an interactive resize
+ *
+ * Start a user-driven, interactive resize of the surface.
+ *
+ * This request must be used in response to some sort of user
+ * action like a button press, key press, or touch down event. The
+ * passed serial is used to determine the type of interactive
+ * resize (touch, pointer, etc).
+ *
+ * The server may ignore resize requests depending on the state of
+ * the surface (e.g. fullscreen or maximized).
+ *
+ * If triggered, the client will receive configure events with the
+ * "resize" state enum value and the expected sizes. See the
+ * "resize" enum value for more details about what is required. The
+ * client must also acknowledge configure events using
+ * "ack_configure". After the resize is completed, the client will
+ * receive another "configure" event without the resize state.
+ *
+ * If triggered, the surface also will lose the focus of the device
+ * (wl_pointer, wl_touch, etc) used for the resize. It is up to the
+ * compositor to visually indicate that the resize is taking place,
+ * such as updating a pointer cursor, during the resize. There is
+ * no guarantee that the device focus will return when the resize
+ * is completed.
+ *
+ * The edges parameter specifies how the surface should be resized,
+ * and is one of the values of the resize_edge enum. The compositor
+ * may use this information to update the surface position for
+ * example when dragging the top left corner. The compositor may
+ * also use this information to adapt its behavior, e.g. choose an
+ * appropriate cursor image.
+ * @param seat the wl_seat of the user event
+ * @param serial the serial of the user event
+ * @param edges which edge or corner is being dragged
+ */
+ void (*resize)(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *seat,
+ uint32_t serial,
+ uint32_t edges);
+ /**
+ * set the maximum size
+ *
+ * Set a maximum size for the window.
+ *
+ * The client can specify a maximum size so that the compositor
+ * does not try to configure the window beyond this size.
+ *
+ * The width and height arguments are in window geometry
+ * coordinates. See xdg_surface.set_window_geometry.
+ *
+ * Values set in this way are double-buffered. They will get
+ * applied on the next commit.
+ *
+ * The compositor can use this information to allow or disallow
+ * different states like maximize or fullscreen and draw accurate
+ * animations.
+ *
+ * Similarly, a tiling window manager may use this information to
+ * place and resize client windows in a more effective way.
+ *
+ * The client should not rely on the compositor to obey the maximum
+ * size. The compositor may decide to ignore the values set by the
+ * client and request a larger size.
+ *
+ * If never set, or a value of zero in the request, means that the
+ * client has no expected maximum size in the given dimension. As a
+ * result, a client wishing to reset the maximum size to an
+ * unspecified state can use zero for width and height in the
+ * request.
+ *
+ * Requesting a maximum size to be smaller than the minimum size of
+ * a surface is illegal and will result in a protocol error.
+ *
+ * The width and height must be greater than or equal to zero.
+ * Using strictly negative values for width and height will result
+ * in a protocol error.
+ */
+ void (*set_max_size)(struct wl_client *client,
+ struct wl_resource *resource,
+ int32_t width,
+ int32_t height);
+ /**
+ * set the minimum size
+ *
+ * Set a minimum size for the window.
+ *
+ * The client can specify a minimum size so that the compositor
+ * does not try to configure the window below this size.
+ *
+ * The width and height arguments are in window geometry
+ * coordinates. See xdg_surface.set_window_geometry.
+ *
+ * Values set in this way are double-buffered. They will get
+ * applied on the next commit.
+ *
+ * The compositor can use this information to allow or disallow
+ * different states like maximize or fullscreen and draw accurate
+ * animations.
+ *
+ * Similarly, a tiling window manager may use this information to
+ * place and resize client windows in a more effective way.
+ *
+ * The client should not rely on the compositor to obey the minimum
+ * size. The compositor may decide to ignore the values set by the
+ * client and request a smaller size.
+ *
+ * If never set, or a value of zero in the request, means that the
+ * client has no expected minimum size in the given dimension. As a
+ * result, a client wishing to reset the minimum size to an
+ * unspecified state can use zero for width and height in the
+ * request.
+ *
+ * Requesting a minimum size to be larger than the maximum size of
+ * a surface is illegal and will result in a protocol error.
+ *
+ * The width and height must be greater than or equal to zero.
+ * Using strictly negative values for width and height will result
+ * in a protocol error.
+ */
+ void (*set_min_size)(struct wl_client *client,
+ struct wl_resource *resource,
+ int32_t width,
+ int32_t height);
+ /**
+ * maximize the window
+ *
+ * Maximize the surface.
+ *
+ * After requesting that the surface should be maximized, the
+ * compositor will respond by emitting a configure event. Whether
+ * this configure actually sets the window maximized is subject to
+ * compositor policies. The client must then update its content,
+ * drawing in the configured state. The client must also
+ * acknowledge the configure when committing the new content (see
+ * ack_configure).
+ *
+ * It is up to the compositor to decide how and where to maximize
+ * the surface, for example which output and what region of the
+ * screen should be used.
+ *
+ * If the surface was already maximized, the compositor will still
+ * emit a configure event with the "maximized" state.
+ *
+ * If the surface is in a fullscreen state, this request has no
+ * direct effect. It may alter the state the surface is returned to
+ * when unmaximized unless overridden by the compositor.
+ */
+ void (*set_maximized)(struct wl_client *client,
+ struct wl_resource *resource);
+ /**
+ * unmaximize the window
+ *
+ * Unmaximize the surface.
+ *
+ * After requesting that the surface should be unmaximized, the
+ * compositor will respond by emitting a configure event. Whether
+ * this actually un-maximizes the window is subject to compositor
+ * policies. If available and applicable, the compositor will
+ * include the window geometry dimensions the window had prior to
+ * being maximized in the configure event. The client must then
+ * update its content, drawing it in the configured state. The
+ * client must also acknowledge the configure when committing the
+ * new content (see ack_configure).
+ *
+ * It is up to the compositor to position the surface after it was
+ * unmaximized; usually the position the surface had before
+ * maximizing, if applicable.
+ *
+ * If the surface was already not maximized, the compositor will
+ * still emit a configure event without the "maximized" state.
+ *
+ * If the surface is in a fullscreen state, this request has no
+ * direct effect. It may alter the state the surface is returned to
+ * when unmaximized unless overridden by the compositor.
+ */
+ void (*unset_maximized)(struct wl_client *client,
+ struct wl_resource *resource);
+ /**
+ * set the window as fullscreen on an output
+ *
+ * Make the surface fullscreen.
+ *
+ * After requesting that the surface should be fullscreened, the
+ * compositor will respond by emitting a configure event. Whether
+ * the client is actually put into a fullscreen state is subject to
+ * compositor policies. The client must also acknowledge the
+ * configure when committing the new content (see ack_configure).
+ *
+ * The output passed by the request indicates the client's
+ * preference as to which display it should be set fullscreen on.
+ * If this value is NULL, it's up to the compositor to choose which
+ * display will be used to map this surface.
+ *
+ * If the surface doesn't cover the whole output, the compositor
+ * will position the surface in the center of the output and
+ * compensate with with border fill covering the rest of the
+ * output. The content of the border fill is undefined, but should
+ * be assumed to be in some way that attempts to blend into the
+ * surrounding area (e.g. solid black).
+ *
+ * If the fullscreened surface is not opaque, the compositor must
+ * make sure that other screen content not part of the same surface
+ * tree (made up of subsurfaces, popups or similarly coupled
+ * surfaces) are not visible below the fullscreened surface.
+ */
+ void (*set_fullscreen)(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *output);
+ /**
+ * unset the window as fullscreen
+ *
+ * Make the surface no longer fullscreen.
+ *
+ * After requesting that the surface should be unfullscreened, the
+ * compositor will respond by emitting a configure event. Whether
+ * this actually removes the fullscreen state of the client is
+ * subject to compositor policies.
+ *
+ * Making a surface unfullscreen sets states for the surface based
+ * on the following: * the state(s) it may have had before becoming
+ * fullscreen * any state(s) decided by the compositor * any
+ * state(s) requested by the client while the surface was
+ * fullscreen
+ *
+ * The compositor may include the previous window geometry
+ * dimensions in the configure event, if applicable.
+ *
+ * The client must also acknowledge the configure when committing
+ * the new content (see ack_configure).
+ */
+ void (*unset_fullscreen)(struct wl_client *client,
+ struct wl_resource *resource);
+ /**
+ * set the window as minimized
+ *
+ * Request that the compositor minimize your surface. There is no
+ * way to know if the surface is currently minimized, nor is there
+ * any way to unset minimization on this surface.
+ *
+ * If you are looking to throttle redrawing when minimized, please
+ * instead use the wl_surface.frame event for this, as this will
+ * also work with live previews on windows in Alt-Tab, Expose or
+ * similar compositor features.
+ */
+ void (*set_minimized)(struct wl_client *client,
+ struct wl_resource *resource);
+};
+
+#define XDG_TOPLEVEL_CONFIGURE 0
+#define XDG_TOPLEVEL_CLOSE 1
+
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_CONFIGURE_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_CLOSE_SINCE_VERSION 1
+
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_DESTROY_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_SET_PARENT_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_SET_TITLE_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_SET_APP_ID_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_SHOW_WINDOW_MENU_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_MOVE_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_RESIZE_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_SET_MAX_SIZE_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_SET_MIN_SIZE_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_SET_MAXIMIZED_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_UNSET_MAXIMIZED_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_SET_FULLSCREEN_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_UNSET_FULLSCREEN_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_toplevel
+ */
+#define XDG_TOPLEVEL_SET_MINIMIZED_SINCE_VERSION 1
+
+/**
+ * @ingroup iface_xdg_toplevel
+ * Sends an configure event to the client owning the resource.
+ * @param resource_ The client's resource
+ */
+static inline void
+xdg_toplevel_send_configure(struct wl_resource *resource_, int32_t width, int32_t height, struct wl_array *states)
+{
+ wl_resource_post_event(resource_, XDG_TOPLEVEL_CONFIGURE, width, height, states);
+}
+
+/**
+ * @ingroup iface_xdg_toplevel
+ * Sends an close event to the client owning the resource.
+ * @param resource_ The client's resource
+ */
+static inline void
+xdg_toplevel_send_close(struct wl_resource *resource_)
+{
+ wl_resource_post_event(resource_, XDG_TOPLEVEL_CLOSE);
+}
+
+#ifndef XDG_POPUP_ERROR_ENUM
+#define XDG_POPUP_ERROR_ENUM
+enum xdg_popup_error {
+ /**
+ * tried to grab after being mapped
+ */
+ XDG_POPUP_ERROR_INVALID_GRAB = 0,
+};
+#endif /* XDG_POPUP_ERROR_ENUM */
+
+/**
+ * @ingroup iface_xdg_popup
+ * @struct xdg_popup_interface
+ */
+struct xdg_popup_interface {
+ /**
+ * remove xdg_popup interface
+ *
+ * This destroys the popup. Explicitly destroying the xdg_popup
+ * object will also dismiss the popup, and unmap the surface.
+ *
+ * If this xdg_popup is not the "topmost" popup, a protocol error
+ * will be sent.
+ */
+ void (*destroy)(struct wl_client *client,
+ struct wl_resource *resource);
+ /**
+ * make the popup take an explicit grab
+ *
+ * This request makes the created popup take an explicit grab. An
+ * explicit grab will be dismissed when the user dismisses the
+ * popup, or when the client destroys the xdg_popup. This can be
+ * done by the user clicking outside the surface, using the
+ * keyboard, or even locking the screen through closing the lid or
+ * a timeout.
+ *
+ * If the compositor denies the grab, the popup will be immediately
+ * dismissed.
+ *
+ * This request must be used in response to some sort of user
+ * action like a button press, key press, or touch down event. The
+ * serial number of the event should be passed as 'serial'.
+ *
+ * The parent of a grabbing popup must either be an xdg_toplevel
+ * surface or another xdg_popup with an explicit grab. If the
+ * parent is another xdg_popup it means that the popups are nested,
+ * with this popup now being the topmost popup.
+ *
+ * Nested popups must be destroyed in the reverse order they were
+ * created in, e.g. the only popup you are allowed to destroy at
+ * all times is the topmost one.
+ *
+ * When compositors choose to dismiss a popup, they may dismiss
+ * every nested grabbing popup as well. When a compositor dismisses
+ * popups, it will follow the same dismissing order as required
+ * from the client.
+ *
+ * The parent of a grabbing popup must either be another xdg_popup
+ * with an active explicit grab, or an xdg_popup or xdg_toplevel,
+ * if there are no explicit grabs already taken.
+ *
+ * If the topmost grabbing popup is destroyed, the grab will be
+ * returned to the parent of the popup, if that parent previously
+ * had an explicit grab.
+ *
+ * If the parent is a grabbing popup which has already been
+ * dismissed, this popup will be immediately dismissed. If the
+ * parent is a popup that did not take an explicit grab, an error
+ * will be raised.
+ *
+ * During a popup grab, the client owning the grab will receive
+ * pointer and touch events for all their surfaces as normal
+ * (similar to an "owner-events" grab in X11 parlance), while the
+ * top most grabbing popup will always have keyboard focus.
+ * @param seat the wl_seat of the user event
+ * @param serial the serial of the user event
+ */
+ void (*grab)(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *seat,
+ uint32_t serial);
+ /**
+ * recalculate the popup's location
+ *
+ * Reposition an already-mapped popup. The popup will be placed
+ * given the details in the passed xdg_positioner object, and a
+ * xdg_popup.repositioned followed by xdg_popup.configure and
+ * xdg_surface.configure will be emitted in response. Any
+ * parameters set by the previous positioner will be discarded.
+ *
+ * The passed token will be sent in the corresponding
+ * xdg_popup.repositioned event. The new popup position will not
+ * take effect until the corresponding configure event is
+ * acknowledged by the client. See xdg_popup.repositioned for
+ * details. The token itself is opaque, and has no other special
+ * meaning.
+ *
+ * If multiple reposition requests are sent, the compositor may
+ * skip all but the last one.
+ *
+ * If the popup is repositioned in response to a configure event
+ * for its parent, the client should send an
+ * xdg_positioner.set_parent_configure and possibly an
+ * xdg_positioner.set_parent_size request to allow the compositor
+ * to properly constrain the popup.
+ *
+ * If the popup is repositioned together with a parent that is
+ * being resized, but not in response to a configure event, the
+ * client should send an xdg_positioner.set_parent_size request.
+ * @param token reposition request token
+ * @since 3
+ */
+ void (*reposition)(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *positioner,
+ uint32_t token);
+};
+
+#define XDG_POPUP_CONFIGURE 0
+#define XDG_POPUP_POPUP_DONE 1
+#define XDG_POPUP_REPOSITIONED 2
+
+/**
+ * @ingroup iface_xdg_popup
+ */
+#define XDG_POPUP_CONFIGURE_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_popup
+ */
+#define XDG_POPUP_POPUP_DONE_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_popup
+ */
+#define XDG_POPUP_REPOSITIONED_SINCE_VERSION 3
+
+/**
+ * @ingroup iface_xdg_popup
+ */
+#define XDG_POPUP_DESTROY_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_popup
+ */
+#define XDG_POPUP_GRAB_SINCE_VERSION 1
+/**
+ * @ingroup iface_xdg_popup
+ */
+#define XDG_POPUP_REPOSITION_SINCE_VERSION 3
+
+/**
+ * @ingroup iface_xdg_popup
+ * Sends an configure event to the client owning the resource.
+ * @param resource_ The client's resource
+ * @param x x position relative to parent surface window geometry
+ * @param y y position relative to parent surface window geometry
+ * @param width window geometry width
+ * @param height window geometry height
+ */
+static inline void
+xdg_popup_send_configure(struct wl_resource *resource_, int32_t x, int32_t y, int32_t width, int32_t height)
+{
+ wl_resource_post_event(resource_, XDG_POPUP_CONFIGURE, x, y, width, height);
+}
+
+/**
+ * @ingroup iface_xdg_popup
+ * Sends an popup_done event to the client owning the resource.
+ * @param resource_ The client's resource
+ */
+static inline void
+xdg_popup_send_popup_done(struct wl_resource *resource_)
+{
+ wl_resource_post_event(resource_, XDG_POPUP_POPUP_DONE);
+}
+
+/**
+ * @ingroup iface_xdg_popup
+ * Sends an repositioned event to the client owning the resource.
+ * @param resource_ The client's resource
+ * @param token reposition request token
+ */
+static inline void
+xdg_popup_send_repositioned(struct wl_resource *resource_, uint32_t token)
+{
+ wl_resource_post_event(resource_, XDG_POPUP_REPOSITIONED, token);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/cmd/wm/xdg.c b/src/cmd/wm/xdg.c
new file mode 100644
index 0000000..6a0c2c8
--- /dev/null
+++ b/src/cmd/wm/xdg.c
@@ -0,0 +1,118 @@
+#include "wm.h"
+
+static
+void
+map(struct wl_listener *l, void *data)
+{
+ Client *client = wl_container_of(l, client, event.map);
+
+ wl_list_insert(&server.client.list, &client->link);
+ wl_list_insert(&server.client.stack, &client->stack);
+ wl_list_insert(&server.client.focus, &client->focus);
+
+ wlr_xdg_surface_get_geometry(client->xdg, &client->geometry);
+ client->geometry.width += 2 * client->border;
+ client->geometry.height += 2 * client->border;
+
+ wlr_xdg_toplevel_set_tiled(client->xdg,
+ WLR_EDGE_TOP|WLR_EDGE_BOTTOM|WLR_EDGE_LEFT|WLR_EDGE_RIGHT
+ );
+
+ rules(client);
+}
+
+static
+void
+unmap(struct wl_listener *l, void *data)
+{
+ Client *client = wl_container_of(l, client, event.unmap);
+
+ wl_list_remove(&client->link);
+ attach(client, nil, 0);
+
+ wl_list_remove(&client->stack);
+ wl_list_remove(&client->focus);
+}
+
+static
+void
+commit(struct wl_listener *l, void *data)
+{
+ Client *client = wl_container_of(l, client, event.commit);
+ if(client->resize && client->resize <= client->xdg->configure_serial)
+ client->resize = 0;
+}
+
+static
+void
+destroy(struct wl_listener *l, void *data)
+{
+ Client *client = wl_container_of(l, client, event.destroy);
+ free(client);
+}
+
+static
+void
+request_move(struct wl_listener *l, void *data)
+{
+ Client *client = wl_container_of(l, client, event.request_move);
+}
+
+static
+void
+request_resize(struct wl_listener *l, void *data)
+{
+ struct wlr_xdg_toplevel_resize_event *event = data;
+ Client *client = wl_container_of(l, client, event.request_resize);
+}
+
+
+static
+void
+request_title(struct wl_listener *l, void *data)
+{
+ Client *client = wl_container_of(l, client, event.request_title);
+}
+
+static
+void
+request_fullscreen(struct wl_listener *l, void *data)
+{
+ Client *client = wl_container_of(l, client, event.request_fullscreen);
+ client->isfullscreen = 1;
+}
+
+void
+make_xdg_surface(struct wl_listener *l, void *data)
+{
+ Client *client;
+ struct wlr_xdg_toplevel *toplevel;
+ struct wlr_xdg_surface *xdg = data;
+
+ if(xdg->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL)
+ return;
+
+ client = xdg->surface->data = calloc(1, sizeof(*client));
+ client->xdg = xdg;
+ client->border = cfg·borderpixel;
+
+ client->event.map.notify = map;
+ wl_signal_add(&xdg->events.map, &client->event.map);
+ client->event.unmap.notify = unmap;
+ wl_signal_add(&xdg->events.unmap, &client->event.unmap);
+ client->event.destroy.notify = destroy;
+ wl_signal_add(&xdg->events.destroy, &client->event.destroy);
+
+ client->event.commit.notify = commit;
+ wl_signal_add(&xdg->surface->events.commit, &client->event.commit);
+
+ toplevel = xdg->toplevel;
+ client->event.request_move.notify = request_move;
+ wl_signal_add(&toplevel->events.request_move, &client->event.request_move);
+ client->event.request_title.notify = request_title;
+ wl_signal_add(&toplevel->events.set_title, &client->event.request_title);
+ client->event.request_resize.notify = request_resize;
+ wl_signal_add(&toplevel->events.request_resize, &client->event.request_resize);
+ client->event.request_fullscreen.notify = request_fullscreen;
+ wl_signal_add(&toplevel->events.request_fullscreen, &client->event.request_fullscreen);
+}