From 73691143af084a95e0f032cc7106127dda6d00b7 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 27 Dec 2007 17:27:20 +0100 Subject: [PATCH] externalize EWMH handling --- Makefile | 2 +- awesome.c | 11 ++------ ewmh.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ ewmh.h | 29 +++++++++++++++++++ 4 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 ewmh.c create mode 100644 ewmh.h diff --git a/Makefile b/Makefile index 8d8b0e36..d9e0b8a3 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config.mk -SRC = focus.c client.c draw.c event.c layout.c awesome.c tag.c util.c xutil.c config.c screen.c statusbar.c uicb.c window.c rules.c mouse.c awesome-client-common.c widget.c +SRC = focus.c client.c draw.c event.c layout.c awesome.c tag.c util.c xutil.c config.c screen.c statusbar.c uicb.c window.c rules.c mouse.c awesome-client-common.c widget.c ewmh.c OBJ = ${SRC:.c=.o} ${LAYOUTS:.c=.o} ${WIDGETS:.c=.o} DOCS = awesome.1.txt awesome-client.1.txt awesomerc.1.txt diff --git a/awesome.c b/awesome.c index 3e4d5791..d615fb53 100644 --- a/awesome.c +++ b/awesome.c @@ -48,6 +48,7 @@ #include "window.h" #include "client.h" #include "focus.h" +#include "ewmh.h" #include "awesome-client.h" static int (*xerrorxlib) (Display *, XErrorEvent *); @@ -289,8 +290,6 @@ main(int argc, char *argv[]) Display * dpy; int shape_event, randr_event_base; int screen; - enum { NetSupported, NetWMName, NetWMIcon, NetClientList, NetLast }; /* EWMH atoms */ - Atom netatom[NetLast]; event_handler **handler; struct sockaddr_un *addr; @@ -345,17 +344,13 @@ main(int argc, char *argv[]) statusbar_draw(screen); } - netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); - netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); - netatom[NetWMIcon] = XInternAtom(dpy, "_NET_WM_ICON", False); - netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); + ewmh_init_atoms(); /* do this only for real screen */ for(screen = 0; screen < ScreenCount(dpy); screen++) { loadawesomeprops(screen); - XChangeProperty(dpy, RootWindow(dpy, screen), netatom[NetSupported], - XA_ATOM, 32, PropModeReplace, (unsigned char *) netatom, NetLast); + ewmh_set_supported_hints(screen); } handler = p_new(event_handler *, LASTEvent); diff --git a/ewmh.c b/ewmh.c new file mode 100644 index 00000000..2a7f0bce --- /dev/null +++ b/ewmh.c @@ -0,0 +1,84 @@ +/* + * ewmh.c - EWMH support functions + * + * Copyright © 2007 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include + +#include "ewmh.h" +#include "config.h" + +extern AwesomeConf globalconf; + +static Atom net_supported; +static Atom net_client_list; + +static Atom net_wm_name; +static Atom net_wm_icon; + +typedef struct +{ + const char *name; + Atom *atom; +} AtomItem; + +static AtomItem AtomNames[] = +{ + { "_NET_SUPPORTED", &net_supported }, + { "_NET_CLIENT_LIST", &net_client_list }, + + { "_NET_WM_NAME", &net_wm_name }, + { "_NET_WM_ICON", &net_wm_icon }, +}; + +#define ATOM_NUMBER (sizeof(AtomNames)/sizeof(AtomItem)) + +void +ewmh_init_atoms(void) +{ + unsigned int i; + char *names[ATOM_NUMBER]; + Atom atoms[ATOM_NUMBER]; + + for(i = 0; i < ATOM_NUMBER; i++) + names[i] = (char *) AtomNames[i].name; + XInternAtoms(globalconf.display, names, ATOM_NUMBER, False, atoms); + for(i = 0; i < ATOM_NUMBER; i++) + *AtomNames[i].atom = atoms[i]; +} + +void +ewmh_set_supported_hints(int phys_screen) +{ + Atom atom[ATOM_NUMBER]; + int i = 0; + + atom[i++] = net_supported; + atom[i++] = net_client_list; + + atom[i++] = net_wm_name; + atom[i++] = net_wm_icon; + + XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen), + net_supported, XA_ATOM, 32, + PropModeReplace, (unsigned char *) atom, i); +} + + +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/ewmh.h b/ewmh.h new file mode 100644 index 00000000..bef1fd79 --- /dev/null +++ b/ewmh.h @@ -0,0 +1,29 @@ +/* + * ewmh.h - EWMH header + * + * Copyright © 2007 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef AWESOME_EWMH_H +#define AWESOME_EWMH_H + +void ewmh_init_atoms(void); +void ewmh_set_supported_hints(int); + +#endif +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80