loop over array pointers directly

This commit is contained in:
Devin J. Pohly 2020-05-03 00:41:37 -05:00
parent 2e7b5310b4
commit b10ef0e80a

42
dwl.c
View File

@ -34,6 +34,7 @@
#define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS) #define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS)
#define VISIBLEON(C, M) ((C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags])) #define VISIBLEON(C, M) ((C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0]) #define LENGTH(X) (sizeof X / sizeof X[0])
#define END(A) ((A) + LENGTH(A))
#define TAGMASK ((1 << LENGTH(tags)) - 1) #define TAGMASK ((1 << LENGTH(tags)) - 1)
/* enums */ /* enums */
@ -271,7 +272,7 @@ buttonpress(struct wl_listener *listener, void *data)
struct wlr_keyboard *keyboard; struct wlr_keyboard *keyboard;
uint32_t mods; uint32_t mods;
Client *c; Client *c;
int i; const Button *b;
switch (event->state) { switch (event->state) {
case WLR_BUTTON_PRESSED:; case WLR_BUTTON_PRESSED:;
@ -282,11 +283,10 @@ buttonpress(struct wl_listener *listener, void *data)
keyboard = wlr_seat_get_keyboard(seat); keyboard = wlr_seat_get_keyboard(seat);
mods = wlr_keyboard_get_modifiers(keyboard); mods = wlr_keyboard_get_modifiers(keyboard);
for (i = 0; i < LENGTH(buttons); i++) { for (b = buttons; b < END(buttons); b++) {
if (event->button == buttons[i].button && if (CLEANMASK(mods) == CLEANMASK(b->mod) &&
CLEANMASK(mods) == CLEANMASK(buttons[i].mod) && event->button == b->button && b->func) {
buttons[i].func) { b->func(&b->arg);
buttons[i].func(&buttons[i].arg);
return; return;
} }
} }
@ -351,7 +351,7 @@ createmon(struct wl_listener *listener, void *data)
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
struct wlr_output_mode *mode; struct wlr_output_mode *mode;
Monitor *m; Monitor *m;
int i; const MonitorRule *r;
/* Some backends don't have modes. DRM+KMS does, and we need to set a mode /* Some backends don't have modes. DRM+KMS does, and we need to set a mode
* before we can use the output. The mode is a tuple of (width, height, * before we can use the output. The mode is a tuple of (width, height,
@ -370,15 +370,14 @@ createmon(struct wl_listener *listener, void *data)
m = wlr_output->data = calloc(1, sizeof(*m)); m = wlr_output->data = calloc(1, sizeof(*m));
m->wlr_output = wlr_output; m->wlr_output = wlr_output;
m->tagset[0] = m->tagset[1] = 1; m->tagset[0] = m->tagset[1] = 1;
for (i = 0; i < LENGTH(monrules); i++) { for (r = monrules; r < END(monrules); r++) {
if (!monrules[i].name || if (!r->name || !strcmp(wlr_output->name, r->name)) {
!strcmp(wlr_output->name, monrules[i].name)) { m->mfact = r->mfact;
m->mfact = monrules[i].mfact; m->nmaster = r->nmaster;
m->nmaster = monrules[i].nmaster; wlr_output_set_scale(wlr_output, r->scale);
wlr_output_set_scale(wlr_output, monrules[i].scale); wlr_xcursor_manager_load(cursor_mgr, r->scale);
wlr_xcursor_manager_load(cursor_mgr, monrules[i].scale); m->lt[0] = m->lt[1] = r->lt;
m->lt[0] = m->lt[1] = monrules[i].lt; wlr_output_set_transform(wlr_output, r->rr);
wlr_output_set_transform(wlr_output, monrules[i].rr);
break; break;
} }
} }
@ -608,12 +607,11 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
* processing. * processing.
*/ */
int handled = 0; int handled = 0;
int i; const Key *k;
for (i = 0; i < LENGTH(keys); i++) { for (k = keys; k < END(keys); k++) {
if (sym == keys[i].keysym && if (CLEANMASK(mods) == CLEANMASK(k->mod) &&
CLEANMASK(mods) == CLEANMASK(keys[i].mod) && sym == k->keysym && k->func) {
keys[i].func) { k->func(&k->arg);
keys[i].func(&keys[i].arg);
handled = 1; handled = 1;
} }
} }