diff options
author | okan | 2016-10-18 17:03:30 +0000 |
---|---|---|
committer | okan | 2016-10-18 17:03:30 +0000 |
commit | a10bee93be3f2ad370a6dfc360e1b05cb84e7f5c (patch) | |
tree | 40fc7c400bfe2a07cc92331d68f6cb4a9a2f4c69 /xevents.c | |
parent | 7b0b231bfe9465d7b2f57f5257ea719325b36666 (diff) | |
download | cwm-a10bee93be3f2ad370a6dfc360e1b05cb84e7f5c.tar.gz |
Refactor callbacks to take a void * so as to not try and generalize into
client_ctx in keypress and buttonpress event handlers; pass appropriate *ctx's
based on context.
While here, limit some globals, replace defines with appropriate variables and
fix some naming.
Diffstat (limited to '')
-rw-r--r-- | xevents.c | 52 |
1 files changed, 32 insertions, 20 deletions
@@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: xevents.c,v 1.125 2016/10/06 14:41:19 okan Exp $ + * $OpenBSD: xevents.c,v 1.126 2016/10/18 17:03:30 okan Exp $ */ /* @@ -220,31 +220,37 @@ static void xev_handle_buttonpress(XEvent *ee) { XButtonEvent *e = &ee->xbutton; - struct client_ctx *cc, fakecc; - struct binding *mb; + struct client_ctx *cc; + struct screen_ctx *sc; + struct bind_ctx *mb; e->state &= ~IGNOREMODMASK; - TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { + TAILQ_FOREACH(mb, &Conf.mousebindq, entry) { if (e->button == mb->press.button && e->state == mb->modmask) break; } if (mb == NULL) return; - if (mb->context == CWM_CONTEXT_CLIENT) { + switch (mb->context) { + case CWM_CONTEXT_CC: if (((cc = client_find(e->window)) == NULL) && (cc = client_current()) == NULL) return; - } else { + (*mb->callback)(cc, &mb->argument, CWM_XEV_BTN); + break; + case CWM_CONTEXT_SC: if (e->window != e->root) return; - cc = &fakecc; - if ((cc->sc = screen_find(e->window)) == NULL) + if ((sc = screen_find(e->window)) == NULL) return; + (*mb->callback)(sc, &mb->argument, CWM_XEV_BTN); + break; + case CWM_CONTEXT_NONE: + (*mb->callback)(NULL, &mb->argument, CWM_XEV_BTN); + break; } - - (*mb->callback)(cc, &mb->argument, CWM_BTN); } static void @@ -263,8 +269,9 @@ static void xev_handle_keypress(XEvent *ee) { XKeyEvent *e = &ee->xkey; - struct client_ctx *cc = NULL, fakecc; - struct binding *kb; + struct client_ctx *cc; + struct screen_ctx *sc; + struct bind_ctx *kb; KeySym keysym, skeysym; unsigned int modshift; @@ -273,7 +280,7 @@ xev_handle_keypress(XEvent *ee) e->state &= ~IGNOREMODMASK; - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) { + TAILQ_FOREACH(kb, &Conf.keybindq, entry) { if (keysym != kb->press.keysym && skeysym == kb->press.keysym) modshift = ShiftMask; else @@ -288,17 +295,22 @@ xev_handle_keypress(XEvent *ee) if (kb == NULL) return; - if (kb->context == CWM_CONTEXT_CLIENT) { + switch (kb->context) { + case CWM_CONTEXT_CC: if (((cc = client_find(e->window)) == NULL) && (cc = client_current()) == NULL) return; - } else { - cc = &fakecc; - if ((cc->sc = screen_find(e->window)) == NULL) + (*kb->callback)(cc, &kb->argument, CWM_XEV_KEY); + break; + case CWM_CONTEXT_SC: + if ((sc = screen_find(e->window)) == NULL) return; + (*kb->callback)(sc, &kb->argument, CWM_XEV_KEY); + break; + case CWM_CONTEXT_NONE: + (*kb->callback)(NULL, &kb->argument, CWM_XEV_KEY); + break; } - - (*kb->callback)(cc, &kb->argument, CWM_KEY); } /* @@ -424,7 +436,7 @@ xev_process(void) XEvent e; XNextEvent(X_Dpy, &e); - if (e.type - Randr_ev == RRScreenChangeNotify) + if (e.type - Conf.xrandr_event_base == RRScreenChangeNotify) xev_handle_randr(&e); else if (e.type < LASTEvent && xev_handlers[e.type] != NULL) (*xev_handlers[e.type])(&e); |