mirror of
https://codeberg.org/dwl/dwl.git
synced 2024-12-27 11:46:31 +00:00
macroize event handlers
This was a prime candidate for reducing the verbosity of some of our code
This commit is contained in:
parent
7ed4956b23
commit
7b320a195c
1 changed files with 33 additions and 51 deletions
84
dwl.c
84
dwl.c
|
@ -58,6 +58,7 @@
|
||||||
#define END(A) ((A) + LENGTH(A))
|
#define END(A) ((A) + LENGTH(A))
|
||||||
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
||||||
#define ROUND(X) ((int)((X)+0.5))
|
#define ROUND(X) ((int)((X)+0.5))
|
||||||
|
#define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
|
||||||
|
|
||||||
/* enums */
|
/* enums */
|
||||||
enum { CurNormal, CurMove, CurResize }; /* cursor */
|
enum { CurNormal, CurMove, CurResize }; /* cursor */
|
||||||
|
@ -795,12 +796,9 @@ createkeyboard(struct wlr_input_device *device)
|
||||||
wlr_keyboard_set_repeat_info(device->keyboard, repeat_rate, repeat_delay);
|
wlr_keyboard_set_repeat_info(device->keyboard, repeat_rate, repeat_delay);
|
||||||
|
|
||||||
/* Here we set up listeners for keyboard events. */
|
/* Here we set up listeners for keyboard events. */
|
||||||
kb->modifiers.notify = keypressmod;
|
LISTEN(&device->keyboard->events.modifiers, &kb->modifiers, keypressmod);
|
||||||
wl_signal_add(&device->keyboard->events.modifiers, &kb->modifiers);
|
LISTEN(&device->keyboard->events.key, &kb->key, keypress);
|
||||||
kb->key.notify = keypress;
|
LISTEN(&device->events.destroy, &kb->destroy, cleanupkeyboard);
|
||||||
wl_signal_add(&device->keyboard->events.key, &kb->key);
|
|
||||||
kb->destroy.notify = cleanupkeyboard;
|
|
||||||
wl_signal_add(&device->events.destroy, &kb->destroy);
|
|
||||||
|
|
||||||
wlr_seat_set_keyboard(seat, device);
|
wlr_seat_set_keyboard(seat, device);
|
||||||
|
|
||||||
|
@ -846,10 +844,8 @@ createmon(struct wl_listener *listener, void *data)
|
||||||
}
|
}
|
||||||
wlr_output_enable_adaptive_sync(wlr_output, 1);
|
wlr_output_enable_adaptive_sync(wlr_output, 1);
|
||||||
/* Set up event listeners */
|
/* Set up event listeners */
|
||||||
m->frame.notify = rendermon;
|
LISTEN(&wlr_output->events.frame, &m->frame, rendermon);
|
||||||
wl_signal_add(&wlr_output->events.frame, &m->frame);
|
LISTEN(&wlr_output->events.destroy, &m->destroy, cleanupmon);
|
||||||
m->destroy.notify = cleanupmon;
|
|
||||||
wl_signal_add(&wlr_output->events.destroy, &m->destroy);
|
|
||||||
|
|
||||||
wl_list_for_each(moni, &mons, link)
|
wl_list_for_each(moni, &mons, link)
|
||||||
if (m->position > moni->position)
|
if (m->position > moni->position)
|
||||||
|
@ -921,18 +917,12 @@ createnotify(struct wl_listener *listener, void *data)
|
||||||
wlr_xdg_toplevel_set_tiled(c->surface.xdg, WLR_EDGE_TOP |
|
wlr_xdg_toplevel_set_tiled(c->surface.xdg, WLR_EDGE_TOP |
|
||||||
WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT);
|
WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT);
|
||||||
|
|
||||||
/* Listen to the various events it can emit */
|
LISTEN(&xdg_surface->surface->events.commit, &c->commit, commitnotify);
|
||||||
c->commit.notify = commitnotify;
|
LISTEN(&xdg_surface->events.map, &c->map, mapnotify);
|
||||||
wl_signal_add(&xdg_surface->surface->events.commit, &c->commit);
|
LISTEN(&xdg_surface->events.unmap, &c->unmap, unmapnotify);
|
||||||
c->map.notify = mapnotify;
|
LISTEN(&xdg_surface->events.destroy, &c->destroy, destroynotify);
|
||||||
wl_signal_add(&xdg_surface->events.map, &c->map);
|
LISTEN(&xdg_surface->toplevel->events.request_fullscreen, &c->fullscreen,
|
||||||
c->unmap.notify = unmapnotify;
|
fullscreennotify);
|
||||||
wl_signal_add(&xdg_surface->events.unmap, &c->unmap);
|
|
||||||
c->destroy.notify = destroynotify;
|
|
||||||
wl_signal_add(&xdg_surface->events.destroy, &c->destroy);
|
|
||||||
|
|
||||||
c->fullscreen.notify = fullscreennotify;
|
|
||||||
wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen, &c->fullscreen);
|
|
||||||
c->isfullscreen = 0;
|
c->isfullscreen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -949,15 +939,14 @@ createlayersurface(struct wl_listener *listener, void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
layersurface = calloc(1, sizeof(LayerSurface));
|
layersurface = calloc(1, sizeof(LayerSurface));
|
||||||
layersurface->surface_commit.notify = commitlayersurfacenotify;
|
LISTEN(&wlr_layer_surface->surface->events.commit,
|
||||||
wl_signal_add(&wlr_layer_surface->surface->events.commit,
|
&layersurface->surface_commit, commitlayersurfacenotify);
|
||||||
&layersurface->surface_commit);
|
LISTEN(&wlr_layer_surface->events.destroy, &layersurface->destroy,
|
||||||
layersurface->destroy.notify = destroylayersurfacenotify;
|
destroylayersurfacenotify);
|
||||||
wl_signal_add(&wlr_layer_surface->events.destroy, &layersurface->destroy);
|
LISTEN(&wlr_layer_surface->events.map, &layersurface->map,
|
||||||
layersurface->map.notify = maplayersurfacenotify;
|
maplayersurfacenotify);
|
||||||
wl_signal_add(&wlr_layer_surface->events.map, &layersurface->map);
|
LISTEN(&wlr_layer_surface->events.unmap, &layersurface->unmap,
|
||||||
layersurface->unmap.notify = unmaplayersurfacenotify;
|
unmaplayersurfacenotify);
|
||||||
wl_signal_add(&wlr_layer_surface->events.unmap, &layersurface->unmap);
|
|
||||||
|
|
||||||
layersurface->layer_surface = wlr_layer_surface;
|
layersurface->layer_surface = wlr_layer_surface;
|
||||||
wlr_layer_surface->data = layersurface;
|
wlr_layer_surface->data = layersurface;
|
||||||
|
@ -1001,10 +990,8 @@ createxdeco(struct wl_listener *listener, void *data)
|
||||||
struct wlr_xdg_toplevel_decoration_v1 *wlr_deco = data;
|
struct wlr_xdg_toplevel_decoration_v1 *wlr_deco = data;
|
||||||
Decoration *d = wlr_deco->data = calloc(1, sizeof(*d));
|
Decoration *d = wlr_deco->data = calloc(1, sizeof(*d));
|
||||||
|
|
||||||
wl_signal_add(&wlr_deco->events.request_mode, &d->request_mode);
|
LISTEN(&wlr_deco->events.request_mode, &d->request_mode, getxdecomode);
|
||||||
d->request_mode.notify = getxdecomode;
|
LISTEN(&wlr_deco->events.destroy, &d->destroy, destroyxdeco);
|
||||||
wl_signal_add(&wlr_deco->events.destroy, &d->destroy);
|
|
||||||
d->destroy.notify = destroyxdeco;
|
|
||||||
|
|
||||||
getxdecomode(&d->request_mode, wlr_deco);
|
getxdecomode(&d->request_mode, wlr_deco);
|
||||||
}
|
}
|
||||||
|
@ -2117,8 +2104,7 @@ setup(void)
|
||||||
* And more comments are sprinkled throughout the notify functions above.
|
* And more comments are sprinkled throughout the notify functions above.
|
||||||
*/
|
*/
|
||||||
wl_signal_add(&cursor->events.motion, &cursor_motion);
|
wl_signal_add(&cursor->events.motion, &cursor_motion);
|
||||||
wl_signal_add(&cursor->events.motion_absolute,
|
wl_signal_add(&cursor->events.motion_absolute, &cursor_motion_absolute);
|
||||||
&cursor_motion_absolute);
|
|
||||||
wl_signal_add(&cursor->events.button, &cursor_button);
|
wl_signal_add(&cursor->events.button, &cursor_button);
|
||||||
wl_signal_add(&cursor->events.axis, &cursor_axis);
|
wl_signal_add(&cursor->events.axis, &cursor_axis);
|
||||||
wl_signal_add(&cursor->events.frame, &cursor_frame);
|
wl_signal_add(&cursor->events.frame, &cursor_frame);
|
||||||
|
@ -2472,22 +2458,18 @@ createnotifyx11(struct wl_listener *listener, void *data)
|
||||||
c->surface.xwayland = xwayland_surface;
|
c->surface.xwayland = xwayland_surface;
|
||||||
c->type = xwayland_surface->override_redirect ? X11Unmanaged : X11Managed;
|
c->type = xwayland_surface->override_redirect ? X11Unmanaged : X11Managed;
|
||||||
c->bw = borderpx;
|
c->bw = borderpx;
|
||||||
|
c->isfullscreen = 0;
|
||||||
|
|
||||||
/* Listen to the various events it can emit */
|
/* Listen to the various events it can emit */
|
||||||
c->map.notify = mapnotify;
|
LISTEN(&xwayland_surface->events.map, &c->map, mapnotify);
|
||||||
wl_signal_add(&xwayland_surface->events.map, &c->map);
|
LISTEN(&xwayland_surface->events.unmap, &c->unmap, unmapnotify);
|
||||||
c->unmap.notify = unmapnotify;
|
LISTEN(&xwayland_surface->events.request_activate, &c->activate,
|
||||||
wl_signal_add(&xwayland_surface->events.unmap, &c->unmap);
|
activatex11);
|
||||||
c->activate.notify = activatex11;
|
LISTEN(&xwayland_surface->events.request_configure, &c->configure,
|
||||||
wl_signal_add(&xwayland_surface->events.request_activate, &c->activate);
|
configurex11);
|
||||||
c->configure.notify = configurex11;
|
LISTEN(&xwayland_surface->events.destroy, &c->destroy, destroynotify);
|
||||||
wl_signal_add(&xwayland_surface->events.request_configure, &c->configure);
|
LISTEN(&xwayland_surface->events.request_fullscreen, &c->fullscreen,
|
||||||
c->destroy.notify = destroynotify;
|
fullscreennotify);
|
||||||
wl_signal_add(&xwayland_surface->events.destroy, &c->destroy);
|
|
||||||
|
|
||||||
c->fullscreen.notify = fullscreennotify;
|
|
||||||
wl_signal_add(&xwayland_surface->events.request_fullscreen, &c->fullscreen);
|
|
||||||
c->isfullscreen = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Atom
|
Atom
|
||||||
|
|
Loading…
Reference in a new issue