From ce05175372a9ddca1a225db0765ace1127a39293 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Fri, 12 Nov 2021 09:22:01 -0800 Subject: chore: simplified organizational structure --- sys/cmd/wm/arg.c | 0 sys/cmd/wm/client.c | 274 --------------------------------- sys/cmd/wm/config.h | 70 --------- sys/cmd/wm/input.c | 316 -------------------------------------- sys/cmd/wm/layer.c | 107 ------------- sys/cmd/wm/main.c | 177 ---------------------- sys/cmd/wm/monitor.c | 386 ----------------------------------------------- sys/cmd/wm/protocol/sync | 6 - sys/cmd/wm/render.c | 160 -------------------- sys/cmd/wm/rules.mk | 61 -------- sys/cmd/wm/util.c | 99 ------------ sys/cmd/wm/wm.h | 350 ------------------------------------------ sys/cmd/wm/xdg.c | 118 --------------- 13 files changed, 2124 deletions(-) delete mode 100644 sys/cmd/wm/arg.c delete mode 100644 sys/cmd/wm/client.c delete mode 100644 sys/cmd/wm/config.h delete mode 100644 sys/cmd/wm/input.c delete mode 100644 sys/cmd/wm/layer.c delete mode 100644 sys/cmd/wm/main.c delete mode 100644 sys/cmd/wm/monitor.c delete mode 100755 sys/cmd/wm/protocol/sync delete mode 100644 sys/cmd/wm/render.c delete mode 100644 sys/cmd/wm/rules.mk delete mode 100644 sys/cmd/wm/util.c delete mode 100644 sys/cmd/wm/wm.h delete mode 100644 sys/cmd/wm/xdg.c (limited to 'sys/cmd/wm') diff --git a/sys/cmd/wm/arg.c b/sys/cmd/wm/arg.c deleted file mode 100644 index e69de29..0000000 diff --git a/sys/cmd/wm/client.c b/sys/cmd/wm/client.c deleted file mode 100644 index 5e0927a..0000000 --- a/sys/cmd/wm/client.c +++ /dev/null @@ -1,274 +0,0 @@ -#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/sys/cmd/wm/config.h b/sys/cmd/wm/config.h deleted file mode 100644 index 1f5ba85..0000000 --- a/sys/cmd/wm/config.h +++ /dev/null @@ -1,70 +0,0 @@ -/* 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/sys/cmd/wm/input.c b/sys/cmd/wm/input.c deleted file mode 100644 index 4c6bfd4..0000000 --- a/sys/cmd/wm/input.c +++ /dev/null @@ -1,316 +0,0 @@ -#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; idevice); - 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/sys/cmd/wm/layer.c b/sys/cmd/wm/layer.c deleted file mode 100644 index bfac744..0000000 --- a/sys/cmd/wm/layer.c +++ /dev/null @@ -1,107 +0,0 @@ -#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/sys/cmd/wm/main.c b/sys/cmd/wm/main.c deleted file mode 100644 index 2607801..0000000 --- a/sys/cmd/wm/main.c +++ /dev/null @@ -1,177 +0,0 @@ -#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/sys/cmd/wm/monitor.c b/sys/cmd/wm/monitor.c deleted file mode 100644 index 93073f3..0000000 --- a/sys/cmd/wm/monitor.c +++ /dev/null @@ -1,386 +0,0 @@ -#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/sys/cmd/wm/protocol/sync b/sys/cmd/wm/protocol/sync deleted file mode 100755 index 19a728a..0000000 --- a/sys/cmd/wm/protocol/sync +++ /dev/null @@ -1,6 +0,0 @@ -#!/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/sys/cmd/wm/render.c b/sys/cmd/wm/render.c deleted file mode 100644 index 1f51804..0000000 --- a/sys/cmd/wm/render.c +++ /dev/null @@ -1,160 +0,0 @@ -#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/sys/cmd/wm/rules.mk b/sys/cmd/wm/rules.mk deleted file mode 100644 index 5a36b6f..0000000 --- a/sys/cmd/wm/rules.mk +++ /dev/null @@ -1,61 +0,0 @@ -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 -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 sys/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)/sys/base/base.a - $(COMPLINK) - -include share/pop.mk diff --git a/sys/cmd/wm/util.c b/sys/cmd/wm/util.c deleted file mode 100644 index 7871d15..0000000 --- a/sys/cmd/wm/util.c +++ /dev/null @@ -1,99 +0,0 @@ -#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/sys/cmd/wm/wm.h b/sys/cmd/wm/wm.h deleted file mode 100644 index a263804..0000000 --- a/sys/cmd/wm/wm.h +++ /dev/null @@ -1,350 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#define WLR_USE_UNSTABLE -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -// ----------------------------------------------------------------------- -// 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/sys/cmd/wm/xdg.c b/sys/cmd/wm/xdg.c deleted file mode 100644 index 6a0c2c8..0000000 --- a/sys/cmd/wm/xdg.c +++ /dev/null @@ -1,118 +0,0 @@ -#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); -} -- cgit v1.2.1