swim.git
grab.c
/* swim - window manager
* Copyright (C) 2022-2023 ArcNyxx
* see LICENCE file for licensing information */
#include <stdbool.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include "grab.h"
#include "swim.h"
#include "util.h"
#define MASK (ButtonPressMask | ButtonReleaseMask)
#define ASYNC GrabModeAsync
#define SYNC GrabModeSync
void
grabbuttons(cli_t *cli, bool focused)
{
extern const but_t buts[6];
XUngrabButton(dpy, AnyButton, AnyModifier, cli->win);
if (!focused)
XGrabButton(dpy, AnyButton, AnyModifier, cli->win, false,
MASK, SYNC, SYNC, 0, 0);
for (size_t i = 0; i < LENGTH(buts); ++i) {
if (buts[i].clk != CLK_CLI)
continue;
for (int ig = 0; ig <= IGMASK; ++ig)
if (!(ig & ~IGMASK))
XGrabButton(dpy, buts[i].but, buts[i].mask |
ig, cli->win, false, MASK,
ASYNC, SYNC, 0, 0);
}
}
void
grabkeys(void)
{
extern const keyp_t keys[63];
XUngrabKey(dpy, AnyKey, AnyModifier, ROOT);
for (size_t i = 0; i < LENGTH(keys); ++i) {
KeyCode kc;
if ((kc = XKeysymToKeycode(dpy, keys[i].keysym)) == 0)
continue;
for (int ig = 0; ig <= IGMASK; ++ig)
if (!(ig & ~IGMASK))
XGrabKey(dpy, kc, keys[i].mod | ig, ROOT, true,
ASYNC, ASYNC);
}
}