all: Simplify atom management

This commit is contained in:
Martin Duquesnoy 2008-12-13 13:48:57 +01:00
parent dde207ebf8
commit 199a148689
6 changed files with 28 additions and 63 deletions

View File

@ -286,16 +286,16 @@ client_kill(Client *c)
if(XGetWMProtocols(dpy, c->win, &atom, &proto) && atom)
{
while(proto--)
if(atom[proto] == wm_atom[WMDelete])
if(atom[proto] == ATOM("WM_DELETE_WINDOW"))
++canbedel;
XFree(atom);
if(canbedel)
{
ev.type = ClientMessage;
ev.xclient.window = c->win;
ev.xclient.message_type = wm_atom[WMProtocols];
ev.xclient.message_type = ATOM("WM_PROTOCOLS");
ev.xclient.format = 32;
ev.xclient.data.l[0] = wm_atom[WMDelete];
ev.xclient.data.l[0] = ATOM("WM_DELETE_WINDOW");
ev.xclient.data.l[1] = CurrentTime;
ev.xclient.data.l[2] = 0;
ev.xclient.data.l[3] = 0;
@ -355,7 +355,7 @@ client_manage(Window w, XWindowAttributes *wa)
Window trans;
Status rettrans;
XSetWindowAttributes at;
int mx, my, s;
int mx, my;
screen_get_sel();
@ -385,9 +385,9 @@ client_manage(Window w, XWindowAttributes *wa)
mx = wa->x + BORDH;
my = wa->y + TBARH + INFOBARH;
s = screen_get_with_geo(mx, my);
if(s != selscreen)
/* Check if the client is already in the selected
* screen, else place the client in it */
if(screen_get_with_geo(mx, my) != selscreen)
{
mx += sgeo[selscreen].x - BORDH;
my += sgeo[selscreen].y - TBARH - INFOBARH;

View File

@ -334,7 +334,7 @@ propertynotify(XPropertyEvent *ev)
break;
}
if(ev->atom == XA_WM_NAME
|| ev->atom == net_atom[NetWMName])
|| ev->atom == ATOM("_NET_WM_NAME"))
client_get_name(c);
}

View File

@ -44,7 +44,6 @@ init(void)
init_cursor();
init_key();
init_root();
init_atom();
screen_init_geo();
infobar_init();
grabkeys();
@ -106,6 +105,7 @@ void
init_root(void)
{
XSetWindowAttributes at;
Atom data[] = { ATOM("_NET_SUPPORTED"), ATOM("_NET_WM_NAME") };
root = RootWindow(dpy, screen);
@ -118,24 +118,10 @@ init_root(void)
if(conf.root.background_command)
uicb_spawn(conf.root.background_command);
return;
}
/** Init atoms
*/
void
init_atom(void)
{
wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False);
wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
wm_atom[WMName] = XInternAtom(dpy, "WM_NAME", False);
net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
PropModeReplace, (unsigned char *) net_atom, NetLast);
XChangeProperty(dpy, root, ATOM("_NET_SUPPORTED"), XA_ATOM, 32,
PropModeReplace, (uchar*)data, NetLast);
return;
}

View File

@ -62,23 +62,13 @@ void
freelayout(void)
{
Client *c;
XRectangle geo;
for(c = clients; c; c = c->next)
{
if(!ishide(c) && c->screen == screen_get_sel())
{
if(c->tile || c->lmax)
{
geo.x = c->ogeo.x;
geo.y = c->ogeo.y;
geo.width = c->ogeo.width;
geo.height = c->ogeo.height;
client_moveresize(c, geo, True);
c->tile = c->lmax = False;
}
client_moveresize(c, c->ogeo, True);
c->tile = c->lmax = False;
}
}
return;
}
@ -90,9 +80,17 @@ void
layoutswitch(Bool b)
{
int i;
Client *c;
screen_get_sel();
if(tags[selscreen][seltag[selscreen]].layout.func == freelayout)
{
deb(666);
for(c = clients; c && (c->tag != seltag[selscreen] && c->screen != selscreen); c = c->next)
c->ogeo = c->geo;
}
for(i = 0; i < conf.nlayout; ++i)
{
if(tags[selscreen][seltag[selscreen]].layout.func == conf.layout[i].func
@ -146,11 +144,6 @@ maxlayout(void)
{
c->tile = False;
c->lmax = True;
c->ogeo.x = c->geo.x;
c->ogeo.y = c->geo.y;
c->ogeo.width = c->geo.width;
c->ogeo.height = c->geo.height;
geo.x = sg.x;
geo.y = sg.y;
geo.width = sg.width - BORDH * 2;
@ -247,9 +240,6 @@ grid(void)
/* Set client property */
c->max = c->lmax = False;
c->tile = True;
c->ogeo.x = c->geo.x; c->ogeo.y = c->geo.y;
c->ogeo.width = c->geo.width; c->ogeo.height = c->geo.height;
++cpcols;
cgeo.width = (sg.width / cols) - border;
cgeo.height = (sg.height / rows) - border;
@ -333,8 +323,6 @@ multi_tile(Position type)
/* Set client property */
c->max = c->lmax = False;
c->tile = True;
c->ogeo.x = c->geo.x; c->ogeo.y = c->geo.y;
c->ogeo.width = c->geo.width; c->ogeo.height = c->geo.height;
/* MASTER */
if(i < nmaster)
@ -506,11 +494,6 @@ uicb_togglemax(uicb_t cmd)
return;
if(!sel->max)
{
sel->ogeo.x = sel->geo.x;
sel->ogeo.y = sel->geo.y;
sel->ogeo.width = sel->geo.width;
sel->ogeo.height = sel->geo.height;
geo.x = sg.x;
geo.y = sg.y;
geo.width = sg.width - BORDH * 2;

View File

@ -91,13 +91,13 @@ getwinstate(Window win)
uchar *p = NULL;
Atom at;
if(XGetWindowProperty(dpy, win, wm_atom[WMState], 0L, 2L, False, wm_atom[WMState],
&at, &f, &n, &e, (uchar **)&p) != Success)
if(XGetWindowProperty(dpy, win, ATOM("WM_STATE"), 0L, 2L, False,
ATOM("WM_STATE"), &at, &f, &n, &e, (uchar **)&p) != Success)
return -1;
if(n != 0)
ret = *p;
free(p);
XFree(p);
return ret;
}
@ -121,8 +121,8 @@ setwinstate(Window win, long state)
{
long data[] = {state, None};
XChangeProperty(dpy, win, wm_atom[WMState], wm_atom[WMState], 32,
PropModeReplace, (unsigned char *)data, 2);
XChangeProperty(dpy, win, ATOM("WM_STATE"), ATOM("WM_STATE"), 32,
PropModeReplace, (uchar *)data, 2);
return;
}

View File

@ -68,6 +68,7 @@
#define MAXH DisplayHeight(dpy, screen)
#define MAXW DisplayWidth(dpy, screen)
#define ATOM(a) XInternAtom(dpy, a, False)
#define INFOBARH font->height * 1.5
#define SHADH 1
#define SHADC 0x000000 /* 'Cause i don't know how darken a color yet */
@ -226,7 +227,6 @@ void uicb_set_nmaster(uicb_t);
/* init.c */
void init(void);
void init_root(void);
void init_atom(void);
void init_font(void);
void init_cursor(void);
void init_key(void);
@ -255,10 +255,6 @@ Key *keys;
Bool exiting;
char statustext[1024];
XRectangle *sgeo;
/* Atoms / Cursors */
Atom wm_atom[WMLast];
Atom net_atom[NetLast];
Cursor cursor[CurLast];
/* Fonts */