From: Michael D. Lowis Date: Wed, 31 Jul 2024 03:40:08 +0000 (-0400) Subject: added atom generator X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=7c0168cebd8e1fe03a3d368e5dce614970adc4b2;p=proto%2Fanvil.git added atom generator --- diff --git a/anvil.c b/anvil.c index 546ce31..9a6455a 100644 --- a/anvil.c +++ b/anvil.c @@ -178,7 +178,7 @@ static void xclientmsg(XEvent* e) { XClientMessageEvent* ev = &(e->xclient); printf("CLIENT_MSG(w: 0x%lx a: '%s')\n", ev->window, XGetAtomName(X.disp, ev->message_type)); - if (ev->message_type == atom("_NET_ACTIVE_WINDOW")) + if (ev->message_type == _NET_ACTIVE_WINDOW) { mons_activate(ev->window); } @@ -295,6 +295,7 @@ int main(void) mons_init(); client_initall(); keys_init(); + atoms_init(); /* setup event handlers */ X.eventfns[ButtonPress] = xbtnpress; diff --git a/anvil.h b/anvil.h index 0444fa9..247943f 100644 --- a/anvil.h +++ b/anvil.h @@ -15,6 +15,7 @@ #include #include #include +#include "atoms.h" #define min(a,b) (a < b ? a : b) #define max(a,b) (a > b ? a : b) @@ -195,7 +196,6 @@ void check(intptr_t stat, char* msg); void die(char* str); void* ecalloc(size_t n, size_t sz); void xfree(void* p); -Atom atom(char* str); void sendmsg(Window win, Atom proto, Atom type); #endif diff --git a/atoms b/atoms new file mode 100644 index 0000000..15ef57f --- /dev/null +++ b/atoms @@ -0,0 +1,13 @@ +WM_NAME +WM_ICON_NAME +WM_NORMAL_HINTS +WM_HINTS +WM_CLASS +WM_TRANSIENT_FOR +WM_PROTOCOLS +WM_COLORMAP_WINDOWS +WM_CLIENT_MACHINE +WM_DELETE_WINDOW +_NET_ACTIVE_WINDOW +_NET_WM_WINDOW_TYPE +_NET_WM_WINDOW_TYPE_DIALOG diff --git a/atoms.c b/atoms.c new file mode 100644 index 0000000..7df75ef --- /dev/null +++ b/atoms.c @@ -0,0 +1,30 @@ +#include "anvil.h" +Atom WM_NAME; +Atom WM_ICON_NAME; +Atom WM_NORMAL_HINTS; +Atom WM_HINTS; +Atom WM_CLASS; +Atom WM_TRANSIENT_FOR; +Atom WM_PROTOCOLS; +Atom WM_COLORMAP_WINDOWS; +Atom WM_CLIENT_MACHINE; +Atom WM_DELETE_WINDOW; +Atom _NET_ACTIVE_WINDOW; +Atom _NET_WM_WINDOW_TYPE; +Atom _NET_WM_WINDOW_TYPE_DIALOG; + +void atoms_init(void) { + WM_NAME = XInternAtom(X.disp, "WM_NAME", False); + WM_ICON_NAME = XInternAtom(X.disp, "WM_ICON_NAME", False); + WM_NORMAL_HINTS = XInternAtom(X.disp, "WM_NORMAL_HINTS", False); + WM_HINTS = XInternAtom(X.disp, "WM_HINTS", False); + WM_CLASS = XInternAtom(X.disp, "WM_CLASS", False); + WM_TRANSIENT_FOR = XInternAtom(X.disp, "WM_TRANSIENT_FOR", False); + WM_PROTOCOLS = XInternAtom(X.disp, "WM_PROTOCOLS", False); + WM_COLORMAP_WINDOWS = XInternAtom(X.disp, "WM_COLORMAP_WINDOWS", False); + WM_CLIENT_MACHINE = XInternAtom(X.disp, "WM_CLIENT_MACHINE", False); + WM_DELETE_WINDOW = XInternAtom(X.disp, "WM_DELETE_WINDOW", False); + _NET_ACTIVE_WINDOW = XInternAtom(X.disp, "_NET_ACTIVE_WINDOW", False); + _NET_WM_WINDOW_TYPE = XInternAtom(X.disp, "_NET_WM_WINDOW_TYPE", False); + _NET_WM_WINDOW_TYPE_DIALOG = XInternAtom(X.disp, "_NET_WM_WINDOW_TYPE_DIALOG", False); +} diff --git a/atoms.h b/atoms.h new file mode 100644 index 0000000..a907d6a --- /dev/null +++ b/atoms.h @@ -0,0 +1,16 @@ + +extern Atom WM_NAME; +extern Atom WM_ICON_NAME; +extern Atom WM_NORMAL_HINTS; +extern Atom WM_HINTS; +extern Atom WM_CLASS; +extern Atom WM_TRANSIENT_FOR; +extern Atom WM_PROTOCOLS; +extern Atom WM_COLORMAP_WINDOWS; +extern Atom WM_CLIENT_MACHINE; +extern Atom WM_DELETE_WINDOW; +extern Atom _NET_ACTIVE_WINDOW; +extern Atom _NET_WM_WINDOW_TYPE; +extern Atom _NET_WM_WINDOW_TYPE_DIALOG; + +void atoms_init(void); diff --git a/client.c b/client.c index 78f6c18..23342e8 100644 --- a/client.c +++ b/client.c @@ -142,7 +142,7 @@ void client_close(Client* c) { if (c->flags & F_WM_DELETE) { - sendmsg(c->win, atom("WM_PROTOCOLS"), atom("WM_DELETE_WINDOW")); + sendmsg(c->win, WM_PROTOCOLS, WM_DELETE_WINDOW); } else { @@ -183,8 +183,8 @@ void client_readprops(Client* c) /* check if the window is a dialog */ XGetWindowProperty( - X.disp, c->win, atom("_NET_WM_WINDOW_TYPE"), 0L, -1, False, XA_ATOM, &actual_type, &format, &n, &extra, (unsigned char **)&wintype); - if (wintype && *wintype == atom("_NET_WM_WINDOW_TYPE_DIALOG")) + X.disp, c->win, _NET_WM_WINDOW_TYPE, 0L, -1, False, XA_ATOM, &actual_type, &format, &n, &extra, (unsigned char **)&wintype); + if (wintype && *wintype == _NET_WM_WINDOW_TYPE_DIALOG) { c->flags |= F_DIALOG|F_FLOATING; } @@ -195,7 +195,7 @@ void client_readprops(Client* c) XGetWMProtocols(X.disp, c->win, &protos, &nprotos); for (int i = 0; i < nprotos; i++) { - if (protos[i] == atom("WM_DELETE_WINDOW")) + if (protos[i] == WM_DELETE_WINDOW) { c->flags |= F_WM_DELETE; } diff --git a/genatoms b/genatoms new file mode 100755 index 0000000..c163acb --- /dev/null +++ b/genatoms @@ -0,0 +1,21 @@ +#!/bin/bash + +hdr="atoms.h" +src="atoms.c" + +echo "" > $hdr +echo -e "#include \"anvil.h\"" > $src + +while IFS= read -r line; do + echo "extern Atom $line;" >> "$hdr" + echo "Atom $line;" >> "$src" +done < atoms +echo "" >> "$hdr" +echo "void atoms_init(void);" >> "$hdr" + +echo "" >> "$src" +echo "void atoms_init(void) {" >> "$src" +while IFS= read -r atom; do + echo " $atom = XInternAtom(X.disp, \"$atom\", False);" >> "$src" +done < atoms +echo "}" >> "$src" \ No newline at end of file diff --git a/util.c b/util.c index af4eba7..e33a086 100644 --- a/util.c +++ b/util.c @@ -32,11 +32,6 @@ void xfree(void* p) } } -Atom atom(char* str) -{ - return XInternAtom(X.disp, str, False); -} - void sendmsg(Window win, Atom proto, Atom type) { XEvent ev;