commit - 89fe2378e3abfb37b9da04e217741cbd48912050
commit + 9b45b37e8940d2b156170ef7b6b9248d5119cd00
blob - 7b605ef4560ffd4f97eb23c3c10a283cedf58c7b
blob + 146d6dd68157d4b1dcf0a8b7383973afe5bcaf55
--- bxhkd.c
+++ bxhkd.c
#include "config.h"
+/* Set macros */
#define LENGTH(arr) (sizeof(arr) / sizeof(arr[0]))
-
#define SOCKET_SUFFIX "/.local/tmp/bxwm.sock"
+
+/* Set global variables */
static Display *dpy;
static Window root;
static volatile sig_atomic_t running = 1;
+/* Set forward function declarations */
static void grabkeys(void);
static void keypress(XKeyEvent *ev);
static void spawn(const char *cmd);
-static void send_cmd(char *cmd)
+static void mappingnotify(XMappingEvent *ev);
+static void send_cmd(char *cmd);
static void sigchld(int sig);
+static void sig_term(int sig);
static void cleanup(void);
+int
+main(void)
+{
+ XEvent ev;
+
+ signal(SIGCHLD, sigchld);
+ signal(SIGINT, sig_term);
+ signal(SIGTERM, sig_term);
+
+ if (!(dpy = XOpenDisplay(NULL))) {
+ fprintf(stderr, "bxhkd: cannot open display\n");
+ return EXIT_FAILURE;
+ }
+ root = DefaultRootWindow(dpy);
+
+ XSelectInput(dpy, root, KeyPressMask|StructureNotifyMask);
+ grabkeys();
+
+ while (running && XNextEvent(dpy, &ev) == 0) {
+ if (ev.type == KeyPress)
+ keypress(&ev.xkey);
+ else if (ev.type == MappingNotify)
+ mappingnotify(&ev.xmapping);
+ }
+
+ cleanup();
+ return EXIT_SUCCESS;
+}
+
static void
grabkeys(void)
{
XCloseDisplay(dpy);
}
-int
-main(void)
-{
- XEvent ev;
-
- signal(SIGCHLD, sigchld);
- signal(SIGINT, sig_term);
- signal(SIGTERM, sig_term);
-
- if (!(dpy = XOpenDisplay(NULL))) {
- fprintf(stderr, "bxhkd: cannot open display\n");
- return EXIT_FAILURE;
- }
- root = DefaultRootWindow(dpy);
-
- XSelectInput(dpy, root, KeyPressMask|StructureNotifyMask);
- grabkeys();
-
- while (running && XNextEvent(dpy, &ev) == 0) {
- if (ev.type == KeyPress)
- keypress(&ev.xkey);
- else if (ev.type == MappingNotify)
- mappingnotify(&ev.xmapping);
- }
-
- cleanup();
- return EXIT_SUCCESS;
-}
-