Because it's 2020. Passing integers to wlroots variables and functions
with bool in their signature is silly.
main
Guido Cella 2020-12-20 13:51:40 +01:00
parent 0b2f4f213d
commit 6b47e2bb62
2 changed files with 56 additions and 54 deletions

View File

@ -1,5 +1,5 @@
/* appearance */ /* appearance */
static const int sloppyfocus = 1; /* focus follows mouse */ static const bool sloppyfocus = true; /* focus follows mouse */
static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int borderpx = 1; /* border pixel of windows */
static const float rootcolor[] = {0.3, 0.3, 0.3, 1.0}; static const float rootcolor[] = {0.3, 0.3, 0.3, 1.0};
static const float bordercolor[] = {0.5, 0.5, 0.5, 1.0}; static const float bordercolor[] = {0.5, 0.5, 0.5, 1.0};
@ -46,8 +46,8 @@ static const int repeat_rate = 25;
static const int repeat_delay = 600; static const int repeat_delay = 600;
/* Trackpad */ /* Trackpad */
static const int tap_to_click = 1; static const bool tap_to_click = true;
static const int natural_scrolling = 1; static const bool natural_scrolling = true;
#define MODKEY WLR_MODIFIER_ALT #define MODKEY WLR_MODIFIER_ALT
#define TAGKEYS(KEY,SKEY,TAG) \ #define TAGKEYS(KEY,SKEY,TAG) \

104
dwl.c
View File

@ -113,13 +113,13 @@ typedef struct {
#endif #endif
int bw; int bw;
unsigned int tags; unsigned int tags;
int isfloating; bool isfloating;
uint32_t resize; /* configure serial of a pending resize */ uint32_t resize; /* configure serial of a pending resize */
int oldx; int oldx;
int oldy; int oldy;
int oldwidth; int oldwidth;
int oldheight; int oldheight;
int isfullscreen; bool isfullscreen;
} Client; } Client;
typedef struct { typedef struct {
@ -190,7 +190,7 @@ typedef struct {
const char *id; const char *id;
const char *title; const char *title;
unsigned int tags; unsigned int tags;
int isfloating; bool isfloating;
int monitor; int monitor;
} Rule; } Rule;
@ -232,7 +232,7 @@ static void destroylayersurfacenotify(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 destroyxdeco(struct wl_listener *listener, void *data); static void destroyxdeco(struct wl_listener *listener, void *data);
static Monitor *dirtomon(int dir); static Monitor *dirtomon(int dir);
static void focusclient(Client *c, int lift); static void focusclient(Client *c, bool lift);
static void focusmon(const Arg *arg); static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg); static void focusstack(const Arg *arg);
static void fullscreennotify(struct wl_listener *listener, void *data); static void fullscreennotify(struct wl_listener *listener, void *data);
@ -240,7 +240,7 @@ static Client *focustop(Monitor *m);
static void getxdecomode(struct wl_listener *listener, void *data); static void getxdecomode(struct wl_listener *listener, void *data);
static void incnmaster(const Arg *arg); static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data); static void inputdevice(struct wl_listener *listener, void *data);
static int keybinding(uint32_t mods, xkb_keysym_t sym); static bool keybinding(uint32_t mods, xkb_keysym_t sym);
static void keypress(struct wl_listener *listener, void *data); static void keypress(struct wl_listener *listener, void *data);
static void keypressmod(struct wl_listener *listener, void *data); static void keypressmod(struct wl_listener *listener, void *data);
static void killclient(const Arg *arg); static void killclient(const Arg *arg);
@ -261,15 +261,15 @@ static void render(struct wlr_surface *surface, int sx, int sy, void *data);
static void renderclients(Monitor *m, struct timespec *now); static void renderclients(Monitor *m, struct timespec *now);
static void renderlayer(struct wl_list *layer_surfaces, struct timespec *now); static void renderlayer(struct wl_list *layer_surfaces, struct timespec *now);
static void rendermon(struct wl_listener *listener, void *data); static void rendermon(struct wl_listener *listener, void *data);
static void resize(Client *c, int x, int y, int w, int h, int interact); static void resize(Client *c, int x, int y, int w, int h, bool interact);
static void run(char *startup_cmd); static void run(char *startup_cmd);
static void scalebox(struct wlr_box *box, float scale); static void scalebox(struct wlr_box *box, float scale);
static Client *selclient(void); static Client *selclient(void);
static void setcursor(struct wl_listener *listener, void *data); static void setcursor(struct wl_listener *listener, void *data);
static void setpsel(struct wl_listener *listener, void *data); static void setpsel(struct wl_listener *listener, void *data);
static void setsel(struct wl_listener *listener, void *data); static void setsel(struct wl_listener *listener, void *data);
static void setfloating(Client *c, int floating); static void setfloating(Client *c, bool floating);
static void setfullscreen(Client *c, int fullscreen); static void setfullscreen(Client *c, bool fullscreen);
static void setlayout(const Arg *arg); static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg); static void setmfact(const Arg *arg);
static void setmon(Client *c, Monitor *m, unsigned int newtags); static void setmon(Client *c, Monitor *m, unsigned int newtags);
@ -655,7 +655,7 @@ buttonpress(struct wl_listener *listener, void *data)
/* Change focus if the button was _pressed_ over a client */ /* Change focus if the button was _pressed_ over a client */
Client *c; Client *c;
if ((c = xytoclient(cursor->x, cursor->y))) if ((c = xytoclient(cursor->x, cursor->y)))
focusclient(c, 1); focusclient(c, true);
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);
@ -737,7 +737,7 @@ cleanupmon(struct wl_listener *listener, void *data)
do // don't switch to disabled mons do // don't switch to disabled mons
selmon = wl_container_of(mons.prev, selmon, link); selmon = wl_container_of(mons.prev, selmon, link);
while (!selmon->wlr_output->enabled && i++ < nmons); while (!selmon->wlr_output->enabled && i++ < nmons);
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), true);
closemon(m); closemon(m);
free(m); free(m);
} }
@ -751,7 +751,7 @@ closemon(Monitor *m)
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
if (c->isfloating && c->geom.x > m->m.width) if (c->isfloating && c->geom.x > m->m.width)
resize(c, c->geom.x - m->w.width, c->geom.y, resize(c, c->geom.x - m->w.width, c->geom.y,
c->geom.width, c->geom.height, 0); c->geom.width, c->geom.height, false);
if (c->mon == m) if (c->mon == m)
setmon(c, selmon, c->tags); setmon(c, selmon, c->tags);
} }
@ -856,7 +856,7 @@ createmon(struct wl_listener *listener, void *data)
wl_list_insert(&mons, &m->link); wl_list_insert(&mons, &m->link);
wlr_output_enable(wlr_output, 1); wlr_output_enable(wlr_output, true);
if (!wlr_output_commit(wlr_output)) if (!wlr_output_commit(wlr_output))
return; return;
@ -883,7 +883,7 @@ createmon(struct wl_listener *listener, void *data)
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
if (c->isfloating) if (c->isfloating)
resize(c, c->geom.x + m->w.width, c->geom.y, resize(c, c->geom.x + m->w.width, c->geom.y,
c->geom.width, c->geom.height, 0); c->geom.width, c->geom.height, false);
} }
return; return;
} }
@ -901,7 +901,7 @@ createnotify(struct wl_listener *listener, void *data)
return; return;
wl_list_for_each(c, &clients, link) wl_list_for_each(c, &clients, link)
if (c->isfullscreen && VISIBLEON(c, c->mon)) if (c->isfullscreen && VISIBLEON(c, c->mon))
setfullscreen(c, 0); setfullscreen(c, false);
/* Allocate a Client for this surface */ /* Allocate a Client for this surface */
c = xdg_surface->data = calloc(1, sizeof(*c)); c = xdg_surface->data = calloc(1, sizeof(*c));
@ -924,7 +924,7 @@ createnotify(struct wl_listener *listener, void *data)
c->fullscreen.notify = fullscreennotify; c->fullscreen.notify = fullscreennotify;
wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen, &c->fullscreen); wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen, &c->fullscreen);
c->isfullscreen = 0; c->isfullscreen = false;
} }
void void
@ -1059,7 +1059,7 @@ destroyxdeco(struct wl_listener *listener, void *data)
} }
void void
setfullscreen(Client *c, int fullscreen) setfullscreen(Client *c, bool fullscreen)
{ {
c->isfullscreen = fullscreen; c->isfullscreen = fullscreen;
c->bw = (1 - fullscreen) * borderpx; c->bw = (1 - fullscreen) * borderpx;
@ -1077,9 +1077,10 @@ setfullscreen(Client *c, int fullscreen)
c->oldy = c->geom.y; c->oldy = c->geom.y;
c->oldheight = c->geom.height; c->oldheight = c->geom.height;
c->oldwidth = c->geom.width; c->oldwidth = c->geom.width;
resize(c, c->mon->m.x, c->mon->m.y, c->mon->m.width, c->mon->m.height, 0); resize(c, c->mon->m.x, c->mon->m.y,
c->mon->m.width, c->mon->m.height, false);
} else { } else {
resize(c, c->oldx, c->oldy, c->oldwidth, c->oldheight, 0); resize(c, c->oldx, c->oldy, c->oldwidth, c->oldheight, false);
} }
} }
@ -1107,7 +1108,7 @@ dirtomon(int dir)
} }
void void
focusclient(Client *c, int lift) focusclient(Client *c, bool lift)
{ {
/* Raise client in stacking order if requested */ /* Raise client in stacking order if requested */
if (c && lift) { if (c && lift) {
@ -1154,10 +1155,10 @@ focusclient(Client *c, int lift)
/* Activate the new client */ /* Activate the new client */
#ifdef XWAYLAND #ifdef XWAYLAND
if (c->type != XDGShell) if (c->type != XDGShell)
wlr_xwayland_surface_activate(c->surface.xwayland, 1); wlr_xwayland_surface_activate(c->surface.xwayland, true);
else else
#endif #endif
wlr_xdg_toplevel_set_activated(c->surface.xdg, 1); wlr_xdg_toplevel_set_activated(c->surface.xdg, true);
} }
void void
@ -1166,7 +1167,7 @@ focusmon(const Arg *arg)
do do
selmon = dirtomon(arg->i); selmon = dirtomon(arg->i);
while (!selmon->wlr_output->enabled); while (!selmon->wlr_output->enabled);
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), true);
} }
void void
@ -1192,7 +1193,7 @@ focusstack(const Arg *arg)
} }
} }
/* If only one client is visible on selmon, then c == sel */ /* If only one client is visible on selmon, then c == sel */
focusclient(c, 1); focusclient(c, true);
} }
Client * Client *
@ -1247,7 +1248,7 @@ inputdevice(struct wl_listener *listener, void *data)
wlr_seat_set_capabilities(seat, caps); wlr_seat_set_capabilities(seat, caps);
} }
int bool
keybinding(uint32_t mods, xkb_keysym_t sym) keybinding(uint32_t mods, xkb_keysym_t sym)
{ {
/* /*
@ -1255,13 +1256,13 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
* processing keys, rather than passing them on to the client for its own * processing keys, rather than passing them on to the client for its own
* processing. * processing.
*/ */
int handled = 0; bool handled = false;
const Key *k; const Key *k;
for (k = keys; k < END(keys); k++) { for (k = keys; k < END(keys); k++) {
if (CLEANMASK(mods) == CLEANMASK(k->mod) && if (CLEANMASK(mods) == CLEANMASK(k->mod) &&
sym == k->keysym && k->func) { sym == k->keysym && k->func) {
k->func(&k->arg); k->func(&k->arg);
handled = 1; handled = true;
} }
} }
return handled; return handled;
@ -1281,7 +1282,7 @@ keypress(struct wl_listener *listener, void *data)
int nsyms = xkb_state_key_get_syms( int nsyms = xkb_state_key_get_syms(
kb->device->keyboard->xkb_state, keycode, &syms); kb->device->keyboard->xkb_state, keycode, &syms);
int handled = 0; bool handled = false;
uint32_t mods = wlr_keyboard_get_modifiers(kb->device->keyboard); uint32_t mods = wlr_keyboard_get_modifiers(kb->device->keyboard);
wlr_idle_notify_activity(idle, seat); wlr_idle_notify_activity(idle, seat);
@ -1386,10 +1387,10 @@ monocle(Monitor *m)
if (!VISIBLEON(c, m) || c->isfloating) if (!VISIBLEON(c, m) || c->isfloating)
continue; continue;
if (c->isfullscreen) { if (c->isfullscreen) {
resize(c, c->mon->m.x, c->mon->m.y, c->mon->m.width, c->mon->m.height, 0); resize(c, c->mon->m.x, c->mon->m.y, c->mon->m.width, c->mon->m.height, false);
return; return;
} }
resize(c, m->w.x, m->w.y, m->w.width, m->w.height, 0); resize(c, m->w.x, m->w.y, m->w.width, m->w.height, false);
} }
} }
@ -1426,12 +1427,12 @@ motionnotify(uint32_t time)
if (cursor_mode == CurMove) { if (cursor_mode == CurMove) {
/* Move the grabbed client to the new position. */ /* Move the grabbed client to the new position. */
resize(grabc, cursor->x - grabcx, cursor->y - grabcy, resize(grabc, cursor->x - grabcx, cursor->y - grabcy,
grabc->geom.width, grabc->geom.height, 1); grabc->geom.width, grabc->geom.height, true);
return; return;
} else if (cursor_mode == CurResize) { } else if (cursor_mode == CurResize) {
resize(grabc, grabc->geom.x, grabc->geom.y, resize(grabc, grabc->geom.x, grabc->geom.y,
cursor->x - grabc->geom.x, cursor->x - grabc->geom.x,
cursor->y - grabc->geom.y, 1); cursor->y - grabc->geom.y, true);
return; return;
} }
@ -1507,7 +1508,7 @@ moveresize(const Arg *arg)
return; return;
/* Float the window and tell motionnotify to grab it */ /* Float the window and tell motionnotify to grab it */
setfloating(grabc, 1); setfloating(grabc, true);
switch (cursor_mode = arg->ui) { switch (cursor_mode = arg->ui) {
case CurMove: case CurMove:
grabcx = cursor->x - grabc->geom.x; grabcx = cursor->x - grabc->geom.x;
@ -1625,7 +1626,7 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
#endif #endif
if (sloppyfocus) if (sloppyfocus)
focusclient(c, 0); focusclient(c, false);
} }
void void
@ -1773,11 +1774,11 @@ rendermon(struct wl_listener *listener, void *data)
/* Do not render if any XDG clients have an outstanding resize. */ /* Do not render if any XDG clients have an outstanding resize. */
Client *c; Client *c;
int render = 1; bool render = true;
wl_list_for_each(c, &stack, slink) { wl_list_for_each(c, &stack, slink) {
if (c->resize) { if (c->resize) {
wlr_surface_send_frame_done(WLR_SURFACE(c), &now); wlr_surface_send_frame_done(WLR_SURFACE(c), &now);
render = 0; render = false;
} }
} }
@ -1816,7 +1817,7 @@ rendermon(struct wl_listener *listener, void *data)
} }
void void
resize(Client *c, int x, int y, int w, int h, int interact) resize(Client *c, int x, int y, int w, int h, bool interact)
{ {
/* /*
* Note that I took some shortcuts here. In a more fleshed-out * Note that I took some shortcuts here. In a more fleshed-out
@ -1930,7 +1931,7 @@ setcursor(struct wl_listener *listener, void *data)
} }
void void
setfloating(Client *c, int floating) setfloating(Client *c, bool floating)
{ {
if (c->isfloating == floating) if (c->isfloating == floating)
return; return;
@ -1983,7 +1984,7 @@ setmon(Client *c, Monitor *m, unsigned int newtags)
c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */ c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */
arrange(m); arrange(m);
} }
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), true);
} }
void void
@ -2196,7 +2197,7 @@ tag(const Arg *arg)
Client *sel = selclient(); Client *sel = selclient();
if (sel && arg->ui & TAGMASK) { if (sel && arg->ui & TAGMASK) {
sel->tags = arg->ui & TAGMASK; sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), true);
arrange(selmon); arrange(selmon);
} }
} }
@ -2231,16 +2232,17 @@ tile(Monitor *m)
if (!VISIBLEON(c, m) || c->isfloating) if (!VISIBLEON(c, m) || c->isfloating)
continue; continue;
if (c->isfullscreen) { if (c->isfullscreen) {
resize(c, c->mon->m.x, c->mon->m.y, c->mon->m.width, c->mon->m.height, 0); resize(c, c->mon->m.x, c->mon->m.y,
c->mon->m.width, c->mon->m.height, false);
return; return;
} }
if (i < m->nmaster) { if (i < m->nmaster) {
h = (m->w.height - my) / (MIN(n, m->nmaster) - i); h = (m->w.height - my) / (MIN(n, m->nmaster) - i);
resize(c, m->w.x, m->w.y + my, mw, h, 0); resize(c, m->w.x, m->w.y + my, mw, h, false);
my += c->geom.height; my += c->geom.height;
} else { } else {
h = (m->w.height - ty) / (n - i); h = (m->w.height - ty) / (n - i);
resize(c, m->w.x + mw, m->w.y + ty, m->w.width - mw, h, 0); resize(c, m->w.x + mw, m->w.y + ty, m->w.width - mw, h, false);
ty += c->geom.height; ty += c->geom.height;
} }
i++; i++;
@ -2266,7 +2268,7 @@ toggletag(const Arg *arg)
unsigned int newtags = sel->tags ^ (arg->ui & TAGMASK); unsigned int newtags = sel->tags ^ (arg->ui & TAGMASK);
if (newtags) { if (newtags) {
sel->tags = newtags; sel->tags = newtags;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), true);
arrange(selmon); arrange(selmon);
} }
} }
@ -2278,7 +2280,7 @@ toggleview(const Arg *arg)
if (newtagset) { if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset; selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), true);
arrange(selmon); arrange(selmon);
} }
} }
@ -2289,7 +2291,7 @@ unmaplayersurface(LayerSurface *layersurface)
layersurface->layer_surface->mapped = false; layersurface->layer_surface->mapped = false;
if (layersurface->layer_surface->surface == if (layersurface->layer_surface->surface ==
seat->keyboard_state.focused_surface) seat->keyboard_state.focused_surface)
focusclient(selclient(), 1); focusclient(selclient(), true);
motionnotify(0); motionnotify(0);
} }
@ -2350,7 +2352,7 @@ view(const Arg *arg)
selmon->seltags ^= 1; /* toggle sel tagset */ selmon->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK) if (arg->ui & TAGMASK)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), true);
arrange(selmon); arrange(selmon);
} }
@ -2430,7 +2432,7 @@ zoom(const Arg *arg)
wl_list_remove(&sel->link); wl_list_remove(&sel->link);
wl_list_insert(&clients, &sel->link); wl_list_insert(&clients, &sel->link);
focusclient(sel, 1); focusclient(sel, true);
arrange(selmon); arrange(selmon);
} }
@ -2442,7 +2444,7 @@ activatex11(struct wl_listener *listener, void *data)
/* Only "managed" windows can be activated */ /* Only "managed" windows can be activated */
if (c->type == X11Managed) if (c->type == X11Managed)
wlr_xwayland_surface_activate(c->surface.xwayland, 1); wlr_xwayland_surface_activate(c->surface.xwayland, true);
} }
void void
@ -2460,7 +2462,7 @@ createnotifyx11(struct wl_listener *listener, void *data)
Client *c; Client *c;
wl_list_for_each(c, &clients, link) wl_list_for_each(c, &clients, link)
if (c->isfullscreen && VISIBLEON(c, c->mon)) if (c->isfullscreen && VISIBLEON(c, c->mon))
setfullscreen(c, 0); setfullscreen(c, false);
/* Allocate a Client for this surface */ /* Allocate a Client for this surface */
struct wlr_xwayland_surface *xwayland_surface = data; struct wlr_xwayland_surface *xwayland_surface = data;
@ -2483,7 +2485,7 @@ createnotifyx11(struct wl_listener *listener, void *data)
c->fullscreen.notify = fullscreennotify; c->fullscreen.notify = fullscreennotify;
wl_signal_add(&xwayland_surface->events.request_fullscreen, &c->fullscreen); wl_signal_add(&xwayland_surface->events.request_fullscreen, &c->fullscreen);
c->isfullscreen = 0; c->isfullscreen = false;
} }
Atom Atom
@ -2535,7 +2537,7 @@ updatewindowtype(Client *c)
c->surface.xwayland->window_type[i] == netatom[NetWMWindowTypeSplash] || c->surface.xwayland->window_type[i] == netatom[NetWMWindowTypeSplash] ||
c->surface.xwayland->window_type[i] == netatom[NetWMWindowTypeToolbar] || c->surface.xwayland->window_type[i] == netatom[NetWMWindowTypeToolbar] ||
c->surface.xwayland->window_type[i] == netatom[NetWMWindowTypeUtility]) c->surface.xwayland->window_type[i] == netatom[NetWMWindowTypeUtility])
c->isfloating = 1; c->isfloating = true;
} }
void void