give types some more dwm-like typedef names

This commit is contained in:
Devin J. Pohly 2020-04-21 14:47:59 -05:00
parent bf58f7c0d2
commit 1d2b0a7b35

306
dwl.c
View file

@ -35,13 +35,21 @@
/* enums */ /* enums */
enum { CurNormal, CurMove, CurResize }; /* cursor */ enum { CurNormal, CurMove, CurResize }; /* cursor */
struct dwl_output { typedef union {
struct wl_list link; int i;
struct wlr_output *wlr_output; unsigned int ui;
struct wl_listener frame; float f;
}; const void *v;
} Arg;
struct dwl_view { typedef struct {
unsigned int mod;
unsigned int button;
void (*func)(const Arg *);
const Arg arg;
} Button;
typedef struct {
struct wl_list link; struct wl_list link;
struct wlr_xdg_surface *xdg_surface; struct wlr_xdg_surface *xdg_surface;
struct wl_listener map; struct wl_listener map;
@ -51,22 +59,7 @@ struct dwl_view {
struct wl_listener request_resize; struct wl_listener request_resize;
bool mapped; bool mapped;
int x, y; int x, y;
}; } Client;
struct dwl_keyboard {
struct wl_list link;
struct wlr_input_device *device;
struct wl_listener modifiers;
struct wl_listener key;
};
typedef union {
int i;
unsigned int ui;
float f;
const void *v;
} Arg;
typedef struct { typedef struct {
uint32_t mod; uint32_t mod;
@ -76,22 +69,37 @@ typedef struct {
} Key; } Key;
typedef struct { typedef struct {
unsigned int mod; struct wl_list link;
unsigned int button; struct wlr_input_device *device;
void (*func)(const Arg *);
const Arg arg; struct wl_listener modifiers;
} Button; struct wl_listener key;
} Keyboard;
typedef struct {
struct wl_list link;
struct wlr_output *wlr_output;
struct wl_listener frame;
} Monitor;
/* Used to move all of the data necessary to render a surface from the top-level
* frame handler to the per-surface render function. */
struct render_data {
struct wlr_output *output;
Client *client;
struct timespec *when;
};
/* function declarations */ /* function declarations */
static void axisnotify(struct wl_listener *listener, void *data); static void axisnotify(struct wl_listener *listener, void *data);
static void buttonpress(struct wl_listener *listener, void *data); static void buttonpress(struct wl_listener *listener, void *data);
static void createkeyboard(struct wlr_input_device *device); static void createkeyboard(struct wlr_input_device *device);
static void createnotify(struct wl_listener *listener, void *data); static void createnotify(struct wl_listener *listener, void *data);
static void createoutput(struct wl_listener *listener, void *data); static void createmon(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_input_device *device); static void createpointer(struct wlr_input_device *device);
static void cursorframe(struct wl_listener *listener, void *data); static void cursorframe(struct wl_listener *listener, void *data);
static void destroynotify(struct wl_listener *listener, void *data); static void destroynotify(struct wl_listener *listener, void *data);
static void focus(struct dwl_view *view, struct wlr_surface *surface); static void focus(Client *c, struct wlr_surface *surface);
static void focusnext(const Arg *arg); static void focusnext(const Arg *arg);
static void handlemove(uint32_t time); static void handlemove(uint32_t time);
static void handleresize(uint32_t time); static void handleresize(uint32_t time);
@ -104,17 +112,17 @@ static void motionabsolute(struct wl_listener *listener, void *data);
static void motionnotify(uint32_t time); static void motionnotify(uint32_t time);
static void motionrelative(struct wl_listener *listener, void *data); static void motionrelative(struct wl_listener *listener, void *data);
static void movemouse(const Arg *arg); static void movemouse(const Arg *arg);
static void moveresize(struct dwl_view *view, unsigned int mode); static void moveresize(Client *c, unsigned int mode);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static void render(struct wlr_surface *surface, int sx, int sy, void *data); static void render(struct wlr_surface *surface, int sx, int sy, void *data);
static void renderoutput(struct wl_listener *listener, void *data); static void rendermon(struct wl_listener *listener, void *data);
static void resizemouse(const Arg *arg); static void resizemouse(const Arg *arg);
static void setcursor(struct wl_listener *listener, void *data); static void setcursor(struct wl_listener *listener, void *data);
static void spawn(const Arg *arg); static void spawn(const Arg *arg);
static void unmapnotify(struct wl_listener *listener, void *data); static void unmapnotify(struct wl_listener *listener, void *data);
static bool xytosurface(struct dwl_view *view, double lx, double ly, static bool xytosurface(Client *c, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy); struct wlr_surface **surface, double *sx, double *sy);
static struct dwl_view * xytoview(double lx, double ly, static Client * xytoclient(double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy); struct wlr_surface **surface, double *sx, double *sy);
/* variables */ /* variables */
@ -124,7 +132,7 @@ static struct wlr_renderer *renderer;
static struct wlr_xdg_shell *xdg_shell; static struct wlr_xdg_shell *xdg_shell;
static struct wl_listener new_xdg_surface; static struct wl_listener new_xdg_surface;
static struct wl_list views; static struct wl_list clients;
static struct wlr_cursor *cursor; static struct wlr_cursor *cursor;
static struct wlr_xcursor_manager *cursor_mgr; static struct wlr_xcursor_manager *cursor_mgr;
@ -139,24 +147,16 @@ static struct wl_listener new_input;
static struct wl_listener request_cursor; static struct wl_listener request_cursor;
static struct wl_list keyboards; static struct wl_list keyboards;
static unsigned int cursor_mode; static unsigned int cursor_mode;
static struct dwl_view *grabbed_view; static Client *grabbed_client;
static double grab_x, grab_y; static double grab_x, grab_y;
static int grab_width, grab_height; static int grab_width, grab_height;
static struct wlr_output_layout *output_layout; static struct wlr_output_layout *output_layout;
static struct wl_list outputs; static struct wl_list mons;
static struct wl_listener new_output; static struct wl_listener new_output;
#include "config.h" #include "config.h"
/* Used to move all of the data necessary to render a surface from the top-level
* frame handler to the per-surface render function. */
struct render_data {
struct wlr_output *output;
struct dwl_view *view;
struct timespec *when;
};
void void
axisnotify(struct wl_listener *listener, void *data) axisnotify(struct wl_listener *listener, void *data)
{ {
@ -180,14 +180,14 @@ buttonpress(struct wl_listener *listener, void *data)
event->time_msec, event->button, event->state); event->time_msec, event->button, event->state);
double sx, sy; double sx, sy;
struct wlr_surface *surface; struct wlr_surface *surface;
struct dwl_view *view = xytoview(cursor->x, cursor->y, Client *c = xytoclient(cursor->x, cursor->y,
&surface, &sx, &sy); &surface, &sx, &sy);
if (event->state == WLR_BUTTON_RELEASED) { if (event->state == WLR_BUTTON_RELEASED) {
/* If you released any buttons, we exit interactive move/resize mode. */ /* If you released any buttons, we exit interactive move/resize mode. */
cursor_mode = CurNormal; cursor_mode = CurNormal;
} else { } else {
/* Focus that client if the button was _pressed_ */ /* Focus that client if the button was _pressed_ */
focus(view, surface); focus(c, surface);
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat); struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
uint32_t mods = wlr_keyboard_get_modifiers(keyboard); uint32_t mods = wlr_keyboard_get_modifiers(keyboard);
@ -204,7 +204,7 @@ buttonpress(struct wl_listener *listener, void *data)
void void
createkeyboard(struct wlr_input_device *device) createkeyboard(struct wlr_input_device *device)
{ {
struct dwl_keyboard *keyboard = calloc(1, sizeof(*keyboard)); Keyboard *keyboard = calloc(1, sizeof(*keyboard));
keyboard->device = device; keyboard->device = device;
/* We need to prepare an XKB keymap and assign it to the keyboard. This /* We need to prepare an XKB keymap and assign it to the keyboard. This
@ -240,24 +240,24 @@ createnotify(struct wl_listener *listener, void *data)
return; return;
} }
/* Allocate a dwl_view for this surface */ /* Allocate a Client for this surface */
struct dwl_view *view = calloc(1, sizeof(*view)); Client *c = calloc(1, sizeof(*c));
view->xdg_surface = xdg_surface; c->xdg_surface = xdg_surface;
/* Listen to the various events it can emit */ /* Listen to the various events it can emit */
view->map.notify = maprequest; c->map.notify = maprequest;
wl_signal_add(&xdg_surface->events.map, &view->map); wl_signal_add(&xdg_surface->events.map, &c->map);
view->unmap.notify = unmapnotify; c->unmap.notify = unmapnotify;
wl_signal_add(&xdg_surface->events.unmap, &view->unmap); wl_signal_add(&xdg_surface->events.unmap, &c->unmap);
view->destroy.notify = destroynotify; c->destroy.notify = destroynotify;
wl_signal_add(&xdg_surface->events.destroy, &view->destroy); wl_signal_add(&xdg_surface->events.destroy, &c->destroy);
/* Add it to the list of views. */ /* Add it to the list of clients. */
wl_list_insert(&views, &view->link); wl_list_insert(&clients, &c->link);
} }
void void
createoutput(struct wl_listener *listener, void *data) createmon(struct wl_listener *listener, void *data)
{ {
/* This event is rasied by the backend when a new output (aka a display or /* This event is rasied by the backend when a new output (aka a display or
* monitor) becomes available. */ * monitor) becomes available. */
@ -278,12 +278,12 @@ createoutput(struct wl_listener *listener, void *data)
} }
/* Allocates and configures our state for this output */ /* Allocates and configures our state for this output */
struct dwl_output *output = calloc(1, sizeof(*output)); Monitor *m = calloc(1, sizeof(*m));
output->wlr_output = wlr_output; m->wlr_output = wlr_output;
/* Sets up a listener for the frame notify event. */ /* Sets up a listener for the frame notify event. */
output->frame.notify = renderoutput; m->frame.notify = rendermon;
wl_signal_add(&wlr_output->events.frame, &output->frame); wl_signal_add(&wlr_output->events.frame, &m->frame);
wl_list_insert(&outputs, &output->link); wl_list_insert(&mons, &m->link);
/* Adds this to the output layout. The add_auto function arranges outputs /* Adds this to the output layout. The add_auto function arranges outputs
* from left-to-right in the order they appear. A more sophisticated * from left-to-right in the order they appear. A more sophisticated
@ -322,16 +322,16 @@ void
destroynotify(struct wl_listener *listener, void *data) destroynotify(struct wl_listener *listener, void *data)
{ {
/* Called when the surface is destroyed and should never be shown again. */ /* Called when the surface is destroyed and should never be shown again. */
struct dwl_view *view = wl_container_of(listener, view, destroy); Client *c = wl_container_of(listener, c, destroy);
wl_list_remove(&view->link); wl_list_remove(&c->link);
free(view); free(c);
} }
void void
focus(struct dwl_view *view, struct wlr_surface *surface) focus(Client *c, struct wlr_surface *surface)
{ {
/* Note: this function only deals with keyboard focus. */ /* Note: this function only deals with keyboard focus. */
if (view == NULL) { if (c == NULL) {
return; return;
} }
struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface; struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface;
@ -350,43 +350,41 @@ focus(struct dwl_view *view, struct wlr_surface *surface)
wlr_xdg_toplevel_set_activated(previous, false); wlr_xdg_toplevel_set_activated(previous, false);
} }
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat); struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
/* Move the view to the front */ /* Move the client to the front */
wl_list_remove(&view->link); wl_list_remove(&c->link);
wl_list_insert(&views, &view->link); wl_list_insert(&clients, &c->link);
/* Activate the new surface */ /* Activate the new surface */
wlr_xdg_toplevel_set_activated(view->xdg_surface, true); wlr_xdg_toplevel_set_activated(c->xdg_surface, true);
/* /*
* Tell the seat to have the keyboard enter this surface. wlroots will keep * Tell the seat to have the keyboard enter this surface. wlroots will keep
* track of this and automatically send key events to the appropriate * track of this and automatically send key events to the appropriate
* clients without additional work on your part. * clients without additional work on your part.
*/ */
wlr_seat_keyboard_notify_enter(seat, view->xdg_surface->surface, wlr_seat_keyboard_notify_enter(seat, c->xdg_surface->surface,
keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers); keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
} }
void void
focusnext(const Arg *arg) focusnext(const Arg *arg)
{ {
/* Cycle to the next view */ /* Cycle to the next client */
if (wl_list_length(&views) < 2) { if (wl_list_length(&clients) < 2) {
return; return;
} }
struct dwl_view *current_view = wl_container_of( Client *c = wl_container_of(clients.next, c, link);
views.next, current_view, link); Client *n = wl_container_of(c->link.next, n, link);
struct dwl_view *next_view = wl_container_of( focus(n, n->xdg_surface->surface);
current_view->link.next, next_view, link); /* Move the previous client to the end of the list */
focus(next_view, next_view->xdg_surface->surface); wl_list_remove(&c->link);
/* Move the previous view to the end of the list */ wl_list_insert(clients.prev, &c->link);
wl_list_remove(&current_view->link);
wl_list_insert(views.prev, &current_view->link);
} }
void void
handlemove(uint32_t time) handlemove(uint32_t time)
{ {
/* Move the grabbed view to the new position. */ /* Move the grabbed client to the new position. */
grabbed_view->x = cursor->x - grab_x; grabbed_client->x = cursor->x - grab_x;
grabbed_view->y = cursor->y - grab_y; grabbed_client->y = cursor->y - grab_y;
} }
void void
@ -399,7 +397,7 @@ handleresize(uint32_t time)
*/ */
double dx = cursor->x - grab_x; double dx = cursor->x - grab_x;
double dy = cursor->y - grab_y; double dy = cursor->y - grab_y;
wlr_xdg_toplevel_set_size(grabbed_view->xdg_surface, wlr_xdg_toplevel_set_size(grabbed_client->xdg_surface,
grab_width + dx, grab_height + dy); grab_width + dx, grab_height + dy);
} }
@ -453,7 +451,7 @@ void
keypress(struct wl_listener *listener, void *data) keypress(struct wl_listener *listener, void *data)
{ {
/* This event is raised when a key is pressed or released. */ /* This event is raised when a key is pressed or released. */
struct dwl_keyboard *keyboard = Keyboard *keyboard =
wl_container_of(listener, keyboard, key); wl_container_of(listener, keyboard, key);
struct wlr_event_keyboard_key *event = data; struct wlr_event_keyboard_key *event = data;
@ -486,8 +484,7 @@ keypressmod(struct wl_listener *listener, void *data)
{ {
/* This event is raised when a modifier key, such as shift or alt, is /* This event is raised when a modifier key, such as shift or alt, is
* pressed. We simply communicate this to the client. */ * pressed. We simply communicate this to the client. */
struct dwl_keyboard *keyboard = Keyboard *keyboard = wl_container_of(listener, keyboard, modifiers);
wl_container_of(listener, keyboard, modifiers);
/* /*
* A seat can only have one keyboard, but this is a limitation of the * A seat can only have one keyboard, but this is a limitation of the
* Wayland protocol - not wlroots. We assign all connected keyboards to the * Wayland protocol - not wlroots. We assign all connected keyboards to the
@ -504,9 +501,9 @@ void
maprequest(struct wl_listener *listener, void *data) maprequest(struct wl_listener *listener, void *data)
{ {
/* Called when the surface is mapped, or ready to display on-screen. */ /* Called when the surface is mapped, or ready to display on-screen. */
struct dwl_view *view = wl_container_of(listener, view, map); Client *c = wl_container_of(listener, c, map);
view->mapped = true; c->mapped = true;
focus(view, view->xdg_surface->surface); focus(c, c->xdg_surface->surface);
} }
void void
@ -535,15 +532,15 @@ motionnotify(uint32_t time)
return; return;
} }
/* Otherwise, find the view under the pointer and send the event along. */ /* Otherwise, find the client under the pointer and send the event along. */
double sx, sy; double sx, sy;
struct wlr_surface *surface = NULL; struct wlr_surface *surface = NULL;
struct dwl_view *view = xytoview(cursor->x, cursor->y, Client *c = xytoclient(cursor->x, cursor->y,
&surface, &sx, &sy); &surface, &sx, &sy);
if (!view) { if (!c) {
/* If there's no view under the cursor, set the cursor image to a /* If there's no client under the cursor, set the cursor image to a
* default. This is what makes the cursor image appear when you move it * default. This is what makes the cursor image appear when you move it
* around the screen, not over any views. */ * around the screen, not over any clients. */
wlr_xcursor_manager_set_cursor_image( wlr_xcursor_manager_set_cursor_image(
cursor_mgr, "left_ptr", cursor); cursor_mgr, "left_ptr", cursor);
} }
@ -591,33 +588,33 @@ movemouse(const Arg *arg)
{ {
double sx, sy; double sx, sy;
struct wlr_surface *surface; struct wlr_surface *surface;
struct dwl_view *view = xytoview(cursor->x, cursor->y, Client *c = xytoclient(cursor->x, cursor->y,
&surface, &sx, &sy); &surface, &sx, &sy);
if (!view) { if (!c) {
return; return;
} }
moveresize(view, CurMove); moveresize(c, CurMove);
} }
void void
moveresize(struct dwl_view *view, unsigned int mode) moveresize(Client *c, unsigned int mode)
{ {
/* This function sets up an interactive move or resize operation, where the /* This function sets up an interactive move or resize operation, where the
* compositor stops propagating pointer events to clients and instead * compositor stops propagating pointer events to clients and instead
* consumes them itself, to move or resize windows. */ * consumes them itself, to move or resize windows. */
struct wlr_surface *focused_surface = struct wlr_surface *focused_surface =
seat->pointer_state.focused_surface; seat->pointer_state.focused_surface;
if (view->xdg_surface->surface != focused_surface) { if (c->xdg_surface->surface != focused_surface) {
/* Deny move/resize requests from unfocused clients. */ /* Deny move/resize requests from unfocused clients. */
return; return;
} }
grabbed_view = view; grabbed_client = c;
cursor_mode = mode; cursor_mode = mode;
struct wlr_box geo_box; struct wlr_box geo_box;
wlr_xdg_surface_get_geometry(view->xdg_surface, &geo_box); wlr_xdg_surface_get_geometry(c->xdg_surface, &geo_box);
if (mode == CurMove) { if (mode == CurMove) {
grab_x = cursor->x - view->x; grab_x = cursor->x - c->x;
grab_y = cursor->y - view->y; grab_y = cursor->y - c->y;
} else { } else {
grab_x = cursor->x + geo_box.x; grab_x = cursor->x + geo_box.x;
grab_y = cursor->y + geo_box.y; grab_y = cursor->y + geo_box.y;
@ -637,7 +634,7 @@ render(struct wlr_surface *surface, int sx, int sy, void *data)
{ {
/* This function is called for every surface that needs to be rendered. */ /* This function is called for every surface that needs to be rendered. */
struct render_data *rdata = data; struct render_data *rdata = data;
struct dwl_view *view = rdata->view; Client *c = rdata->client;
struct wlr_output *output = rdata->output; struct wlr_output *output = rdata->output;
/* We first obtain a wlr_texture, which is a GPU resource. wlroots /* We first obtain a wlr_texture, which is a GPU resource. wlroots
@ -650,14 +647,14 @@ render(struct wlr_surface *surface, int sx, int sy, void *data)
return; return;
} }
/* The view has a position in layout coordinates. If you have two displays, /* The client has a position in layout coordinates. If you have two displays,
* one next to the other, both 1080p, a view on the rightmost display might * one next to the other, both 1080p, a client on the rightmost display might
* have layout coordinates of 2000,100. We need to translate that to * have layout coordinates of 2000,100. We need to translate that to
* output-local coordinates, or (2000 - 1920). */ * output-local coordinates, or (2000 - 1920). */
double ox = 0, oy = 0; double ox = 0, oy = 0;
wlr_output_layout_output_coords( wlr_output_layout_output_coords(
output_layout, output, &ox, &oy); output_layout, output, &ox, &oy);
ox += view->x + sx, oy += view->y + sy; ox += c->x + sx, oy += c->y + sy;
/* We also have to apply the scale factor for HiDPI outputs. This is only /* We also have to apply the scale factor for HiDPI outputs. This is only
* part of the puzzle, dwl does not fully support HiDPI. */ * part of the puzzle, dwl does not fully support HiDPI. */
@ -670,10 +667,10 @@ render(struct wlr_surface *surface, int sx, int sy, void *data)
/* /*
* Those familiar with OpenGL are also familiar with the role of matricies * Those familiar with OpenGL are also familiar with the role of matricies
* in graphics programming. We need to prepare a matrix to render the view * in graphics programming. We need to prepare a matrix to render the
* with. wlr_matrix_project_box is a helper which takes a box with a desired * client with. wlr_matrix_project_box is a helper which takes a box with
* x, y coordinates, width and height, and an output geometry, then * a desired x, y coordinates, width and height, and an output geometry,
* prepares an orthographic projection and multiplies the necessary * then prepares an orthographic projection and multiplies the necessary
* transforms to produce a model-view-projection matrix. * transforms to produce a model-view-projection matrix.
* *
* Naturally you can do this any way you like, for example to make a 3D * Naturally you can do this any way you like, for example to make a 3D
@ -695,23 +692,22 @@ render(struct wlr_surface *surface, int sx, int sy, void *data)
} }
void void
renderoutput(struct wl_listener *listener, void *data) rendermon(struct wl_listener *listener, void *data)
{ {
/* This function is called every time an output is ready to display a frame, /* This function is called every time an output is ready to display a frame,
* generally at the output's refresh rate (e.g. 60Hz). */ * generally at the output's refresh rate (e.g. 60Hz). */
struct dwl_output *output = Monitor *m = wl_container_of(listener, m, frame);
wl_container_of(listener, output, frame);
struct timespec now; struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
/* wlr_output_attach_render makes the OpenGL context current. */ /* wlr_output_attach_render makes the OpenGL context current. */
if (!wlr_output_attach_render(output->wlr_output, NULL)) { if (!wlr_output_attach_render(m->wlr_output, NULL)) {
return; return;
} }
/* The "effective" resolution can change if you rotate your outputs. */ /* The "effective" resolution can change if you rotate your outputs. */
int width, height; int width, height;
wlr_output_effective_resolution(output->wlr_output, &width, &height); wlr_output_effective_resolution(m->wlr_output, &width, &height);
/* Begin the renderer (calls glViewport and some other GL sanity checks) */ /* Begin the renderer (calls glViewport and some other GL sanity checks) */
wlr_renderer_begin(renderer, width, height); wlr_renderer_begin(renderer, width, height);
@ -719,21 +715,21 @@ renderoutput(struct wl_listener *listener, void *data)
wlr_renderer_clear(renderer, color); wlr_renderer_clear(renderer, color);
/* Each subsequent window we render is rendered on top of the last. Because /* Each subsequent window we render is rendered on top of the last. Because
* our view list is ordered front-to-back, we iterate over it backwards. */ * our client list is ordered front-to-back, we iterate over it backwards. */
struct dwl_view *view; Client *c;
wl_list_for_each_reverse(view, &views, link) { wl_list_for_each_reverse(c, &clients, link) {
if (!view->mapped) { if (!c->mapped) {
/* An unmapped view should not be rendered. */ /* An unmapped client should not be rendered. */
continue; continue;
} }
struct render_data rdata = { struct render_data rdata = {
.output = output->wlr_output, .output = m->wlr_output,
.view = view, .client = c,
.when = &now, .when = &now,
}; };
/* This calls our render function for each surface among the /* This calls our render function for each surface among the
* xdg_surface's toplevel and popups. */ * xdg_surface's toplevel and popups. */
wlr_xdg_surface_for_each_surface(view->xdg_surface, wlr_xdg_surface_for_each_surface(c->xdg_surface,
render, &rdata); render, &rdata);
} }
@ -743,12 +739,12 @@ renderoutput(struct wl_listener *listener, void *data)
* reason, wlroots provides a software fallback, which we ask it to render * reason, wlroots provides a software fallback, which we ask it to render
* here. wlr_cursor handles configuring hardware vs software cursors for you, * here. wlr_cursor handles configuring hardware vs software cursors for you,
* and this function is a no-op when hardware cursors are in use. */ * and this function is a no-op when hardware cursors are in use. */
wlr_output_render_software_cursors(output->wlr_output, NULL); wlr_output_render_software_cursors(m->wlr_output, NULL);
/* Conclude rendering and swap the buffers, showing the final frame /* Conclude rendering and swap the buffers, showing the final frame
* on-screen. */ * on-screen. */
wlr_renderer_end(renderer); wlr_renderer_end(renderer);
wlr_output_commit(output->wlr_output); wlr_output_commit(m->wlr_output);
} }
void void
@ -756,17 +752,17 @@ resizemouse(const Arg *arg)
{ {
double sx, sy; double sx, sy;
struct wlr_surface *surface; struct wlr_surface *surface;
struct dwl_view *view = xytoview(cursor->x, cursor->y, Client *c = xytoclient(cursor->x, cursor->y,
&surface, &sx, &sy); &surface, &sx, &sy);
if (!view) { if (!c) {
return; return;
} }
struct wlr_box geo_box; struct wlr_box geo_box;
wlr_xdg_surface_get_geometry(view->xdg_surface, &geo_box); wlr_xdg_surface_get_geometry(c->xdg_surface, &geo_box);
wlr_cursor_warp_closest(cursor, NULL, wlr_cursor_warp_closest(cursor, NULL,
view->x + geo_box.x + geo_box.width, c->x + geo_box.x + geo_box.width,
view->y + geo_box.y + geo_box.height); c->y + geo_box.y + geo_box.height);
moveresize(view, CurResize); moveresize(c, CurResize);
} }
void void
@ -804,12 +800,12 @@ void
unmapnotify(struct wl_listener *listener, void *data) unmapnotify(struct wl_listener *listener, void *data)
{ {
/* Called when the surface is unmapped, and should no longer be shown. */ /* Called when the surface is unmapped, and should no longer be shown. */
struct dwl_view *view = wl_container_of(listener, view, unmap); Client *c = wl_container_of(listener, c, unmap);
view->mapped = false; c->mapped = false;
} }
bool bool
xytosurface(struct dwl_view *view, double lx, double ly, xytosurface(Client *c, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy) struct wlr_surface **surface, double *sx, double *sy)
{ {
/* /*
@ -819,15 +815,15 @@ xytosurface(struct dwl_view *view, double lx, double ly,
* surface pointer to that wlr_surface and the sx and sy coordinates to the * surface pointer to that wlr_surface and the sx and sy coordinates to the
* coordinates relative to that surface's top-left corner. * coordinates relative to that surface's top-left corner.
*/ */
double view_sx = lx - view->x; double client_sx = lx - c->x;
double view_sy = ly - view->y; double client_sy = ly - c->y;
struct wlr_surface_state *state = &view->xdg_surface->surface->current; struct wlr_surface_state *state = &c->xdg_surface->surface->current;
double _sx, _sy; double _sx, _sy;
struct wlr_surface *_surface = NULL; struct wlr_surface *_surface = NULL;
_surface = wlr_xdg_surface_surface_at( _surface = wlr_xdg_surface_surface_at(
view->xdg_surface, view_sx, view_sy, &_sx, &_sy); c->xdg_surface, client_sx, client_sy, &_sx, &_sy);
if (_surface != NULL) { if (_surface != NULL) {
*sx = _sx; *sx = _sx;
@ -839,16 +835,16 @@ xytosurface(struct dwl_view *view, double lx, double ly,
return false; return false;
} }
struct dwl_view * Client *
xytoview(double lx, double ly, xytoclient(double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy) struct wlr_surface **surface, double *sx, double *sy)
{ {
/* This iterates over all of our surfaces and attempts to find one under the /* This iterates over all of our surfaces and attempts to find one under the
* cursor. This relies on views being ordered from top-to-bottom. */ * cursor. This relies on clients being ordered from top-to-bottom. */
struct dwl_view *view; Client *c;
wl_list_for_each(view, &views, link) { wl_list_for_each(c, &clients, link) {
if (xytosurface(view, lx, ly, surface, sx, sy)) { if (xytosurface(c, lx, ly, surface, sx, sy)) {
return view; return c;
} }
} }
return NULL; return NULL;
@ -909,17 +905,17 @@ main(int argc, char *argv[])
/* Configure a listener to be notified when new outputs are available on the /* Configure a listener to be notified when new outputs are available on the
* backend. */ * backend. */
wl_list_init(&outputs); wl_list_init(&mons);
new_output.notify = createoutput; new_output.notify = createmon;
wl_signal_add(&backend->events.new_output, &new_output); wl_signal_add(&backend->events.new_output, &new_output);
/* Set up our list of views and the xdg-shell. The xdg-shell is a Wayland /* Set up our list of clients and the xdg-shell. The xdg-shell is a Wayland
* protocol which is used for application windows. For more detail on * protocol which is used for application windows. For more detail on
* shells, refer to my article: * shells, refer to my article:
* *
* https://drewdevault.com/2018/07/29/Wayland-shells.html * https://drewdevault.com/2018/07/29/Wayland-shells.html
*/ */
wl_list_init(&views); wl_list_init(&clients);
xdg_shell = wlr_xdg_shell_create(wl_display); xdg_shell = wlr_xdg_shell_create(wl_display);
new_xdg_surface.notify = createnotify; new_xdg_surface.notify = createnotify;
wl_signal_add(&xdg_shell->events.new_surface, wl_signal_add(&xdg_shell->events.new_surface,