event: Improve event system

This commit is contained in:
Martin Duquesnoy 2008-11-09 03:36:59 +01:00
parent 528a22b75a
commit 0a15b3ba6f
10 changed files with 240 additions and 265 deletions

View File

@ -147,20 +147,47 @@ client_focus(Client *c)
return; return;
} }
Client* /* Get Client with any window Client member {{{ */
client_get(Window w) Client* client_gb_win(Window w)
{ {
Client *c; Client *c;
for(c = clients; c && c->win != w; c = c->next); for(c = clients; c && c->win != w; c = c->next);
return c; return c;
} }
Client* client_gb_frame(Window w)
{
Client *c;
for(c = clients; c && c->frame != w; c = c->next);
return c;
}
Client* client_gb_titlebar(Window w)
{
Client *c;
for(c = clients; c && c->titlebar != w; c = c->next);
return c;
}
Client* client_gb_resize(Window w)
{
Client *c;
for(c = clients; c && c->resize != w; c = c->next);
return c;
}
/* }}} */
void void
client_get_name(Client *c) client_get_name(Client *c)
{ {
XFetchName(dpy, c->win, &(c->title)); XFetchName(dpy, c->win, &(c->title));
if(!c->title) if(!c->title)
c->title = strdup("WMFS"); c->title = strdup("WMFS");

View File

@ -411,7 +411,6 @@ init_conf(void)
conf.titlebar.mouse[i].cmd = strdup(var_to_str(cfg_getstr(cfgtmp2, "cmd"))); conf.titlebar.mouse[i].cmd = strdup(var_to_str(cfg_getstr(cfgtmp2, "cmd")));
} }
/* layout */ /* layout */
conf.colors.layout_fg = strdup(var_to_str(cfg_getstr(cfg_layouts, "fg"))); conf.colors.layout_fg = strdup(var_to_str(cfg_getstr(cfg_layouts, "fg")));
conf.colors.layout_bg = getcolor(var_to_str(cfg_getstr(cfg_layouts, "bg"))); conf.colors.layout_bg = getcolor(var_to_str(cfg_getstr(cfg_layouts, "bg")));
@ -449,7 +448,6 @@ init_conf(void)
} }
} }
/* tag */ /* tag */
/* if there is no tag in the conf or more than /* if there is no tag in the conf or more than
* MAXTAG (32) print an error and create only one. */ * MAXTAG (32) print an error and create only one. */

View File

@ -42,7 +42,8 @@ draw_text(Drawable d, int x, int y, char* fg, uint bg, int pad, char *str)
xftd = XftDrawCreate(dpy, d, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen)); xftd = XftDrawCreate(dpy, d, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen));
/* Color the text font */ /* Color the text font */
draw_rectangle(d, x - pad/2, 0, textw(str) + pad, infobar.geo.height, bg); draw_rectangle(d, x - pad/2, 0, textw(str) + pad, infobar->geo.height, bg);
/* Alloc text color */ /* Alloc text color */
XftColorAllocName(dpy, DefaultVisual(dpy, screen), XftColorAllocName(dpy, DefaultVisual(dpy, screen),
@ -53,6 +54,7 @@ draw_text(Drawable d, int x, int y, char* fg, uint bg, int pad, char *str)
/* Free the text color and XftDraw */ /* Free the text color and XftDraw */
XftColorFree(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &xftcolor); XftColorFree(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &xftcolor);
XftDrawDestroy(xftd); XftDrawDestroy(xftd);

View File

@ -34,83 +34,83 @@
/* BUTTONPRESS */ /* BUTTONPRESS */
void void
buttonpress(XEvent ev) buttonpress(XButtonEvent *ev)
{ {
Client *c; Client *c;
int i; int i;
char s[6]; char s[6];
/* Frame & titlebar */ /* Frame & titlebar */
if((c = frame_get_titlebar(ev.xbutton.window))) if((c = client_gb_titlebar(ev->window)))
for(i = 0; i < conf.titlebar.nmouse; ++i) for(i = 0; i < conf.titlebar.nmouse; ++i)
if(ev.xbutton.button == conf.titlebar.mouse[i].button) if(ev->button == conf.titlebar.mouse[i].button)
if(conf.titlebar.mouse[i].func) if(conf.titlebar.mouse[i].func)
conf.titlebar.mouse[i].func(conf.titlebar.mouse[i].cmd); conf.titlebar.mouse[i].func(conf.titlebar.mouse[i].cmd);
/* Frame Resize Area */ /* Frame Resize Area */
if((c = frame_get_resize(ev.xbutton.window))) if((c = client_gb_resize(ev->window)))
mouse_resize(c); mouse_resize(c);
/* Client */ /* Client */
if((c = client_get(ev.xbutton.window))) if((c = client_gb_win(ev->window)))
for(i = 0; i < conf.client.nmouse; ++i) for(i = 0; i < conf.client.nmouse; ++i)
if(ev.xbutton.button == conf.client.mouse[i].button) if(ev->button == conf.client.mouse[i].button)
if(conf.client.mouse[i].func) if(conf.client.mouse[i].func)
conf.client.mouse[i].func(conf.client.mouse[i].cmd); conf.client.mouse[i].func(conf.client.mouse[i].cmd);
/* Root */ /* Root */
if(ev.xbutton.window == root) if(ev->window == root)
for(i = 0; i < conf.root.nmouse; ++i) for(i = 0; i < conf.root.nmouse; ++i)
if(ev.xbutton.button == conf.root.mouse[i].button) if(ev->button == conf.root.mouse[i].button)
if(conf.root.mouse[i].func) if(conf.root.mouse[i].func)
conf.root.mouse[i].func(conf.root.mouse[i].cmd); conf.root.mouse[i].func(conf.root.mouse[i].cmd);
/* Bar */ /* Bar */
{ {
if(ev.xbutton.window == infobar.bar->win) if(ev->window == infobar->bar->win)
{ {
/* Tag*/ /* Tag*/
for(i = 0; i < conf.ntag + 1; ++i) for(i = 0; i < conf.ntag + 1; ++i)
{ {
if(ev.xbutton.x > taglen[i-1] - 3 if(ev->x > taglen[i-1] - 3
&& ev.xbutton.x < (taglen[i] - 3)) && ev->x < (taglen[i] - 3))
{ {
ITOA(s, i); ITOA(s, i);
if(ev.xbutton.button == Button1) if(ev->button == Button1)
uicb_tag(s); uicb_tag(s);
if(ev.xbutton.button == Button3) if(ev->button == Button3)
uicb_tagtransfert(s); uicb_tagtransfert(s);
} }
} }
if(ev.xbutton.x < taglen[conf.ntag]) if(ev->x < taglen[conf.ntag])
{ {
if(ev.xbutton.button == Button4) if(ev->button == Button4)
uicb_tag("+1"); uicb_tag("+1");
if (ev.xbutton.button == Button5) if (ev->button == Button5)
uicb_tag("-1"); uicb_tag("-1");
} }
} }
/* Layout */ /* Layout */
{ {
if(ev.xbutton.window == infobar.layout_switch->win) if(ev->window == infobar->layout_switch->win)
{ {
if(ev.xbutton.button == Button1 if(ev->button == Button1
|| ev.xbutton.button == Button4) || ev->button == Button4)
layoutswitch(True); layoutswitch(True);
if(ev.xbutton.button == Button3 if(ev->button == Button3
|| ev.xbutton.button == Button5) || ev->button == Button5)
layoutswitch(False); layoutswitch(False);
} }
if(ev.xbutton.window == infobar.layout_type_switch->win) if(ev->window == infobar->layout_type_switch->win)
{ {
if(ev.xbutton.button == Button1 if(ev->button == Button1
|| ev.xbutton.button == Button4) || ev->button == Button4)
layout_tile_switch(True); layout_tile_switch(True);
if(ev.xbutton.button == Button3 if(ev->button == Button3
|| ev.xbutton.button == Button5) || ev->button == Button5)
layout_tile_switch(False); layout_tile_switch(False);
} }
} }
@ -121,29 +121,28 @@ buttonpress(XEvent ev)
/* CONFIGUREREQUEST */ /* CONFIGUREREQUEST */
void void
configurerequest(XEvent ev) configurerequest(XConfigureRequestEvent *ev)
{ {
Client *c; Client *c;
XWindowChanges wc; XWindowChanges wc;
XRectangle geo; XRectangle geo;
if((c = client_get(ev.xconfigurerequest.window))) if((c = client_gb_win(ev->window)))
{ {
CHECK(!c->tile); CHECK(!c->tile);
CHECK(!c->lmax); CHECK(!c->lmax);
} }
geo.x = wc.x = ev.xconfigurerequest.x; geo.x = wc.x = ev->x;
geo.y = wc.y = ev.xconfigurerequest.y; geo.y = wc.y = ev->y;
geo.width = wc.width = ev.xconfigurerequest.width; geo.width = wc.width = ev->width;
geo.height = wc.height = ev.xconfigurerequest.height; geo.height = wc.height = ev->height;
wc.border_width = ev.xconfigurerequest.border_width; wc.border_width = ev->border_width;
wc.sibling = ev.xconfigurerequest.above; wc.sibling = ev->above;
wc.stack_mode = ev.xconfigurerequest.detail; wc.stack_mode = ev->detail;
XConfigureWindow(dpy, ev.xconfigurerequest.window, XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
ev.xconfigurerequest.value_mask, &wc);
if((c = client_get(ev.xconfigurerequest.window))) if((c = client_gb_win(ev->window)))
{ {
client_moveresize(c, geo, True); client_moveresize(c, geo, True);
XReparentWindow(dpy, c->win, c->frame, XReparentWindow(dpy, c->win, c->frame,
@ -157,10 +156,10 @@ configurerequest(XEvent ev)
/* DESTROYNOTIFY */ /* DESTROYNOTIFY */
void void
destroynotify(XEvent ev) destroynotify(XDestroyWindowEvent *ev)
{ {
Client *c; Client *c;
if((c = client_get(ev.xdestroywindow.window))) if((c = client_gb_win(ev->window)))
client_unmanage(c); client_unmanage(c);
return; return;
@ -168,18 +167,18 @@ destroynotify(XEvent ev)
/* ENTERNOTIFY */ /* ENTERNOTIFY */
void void
enternotify(XEvent ev) enternotify(XCrossingEvent *ev)
{ {
Client *c; Client *c;
if(ev.xcrossing.mode != NotifyNormal if(ev->mode != NotifyNormal
|| ev.xcrossing.detail == NotifyInferior) || ev->detail == NotifyInferior)
return; return;
if((c = client_get(ev.xcrossing.window)) if((c = client_gb_win(ev->window))
|| (c = frame_get(ev.xcrossing.window)) || (c = client_gb_frame(ev->window))
|| (c = frame_get_titlebar(ev.xcrossing.window)) || (c = client_gb_titlebar(ev->window))
|| (c = frame_get_resize(ev.xcrossing.window))) || (c = client_gb_resize(ev->window)))
client_focus(c); client_focus(c);
else else
client_focus(NULL); client_focus(NULL);
@ -188,16 +187,16 @@ enternotify(XEvent ev)
/* EXPOSE */ /* EXPOSE */
void void
expose(XEvent ev) expose(XExposeEvent *ev)
{ {
Client *c; Client *c;
if(ev.xexpose.count == 0 if(ev->count == 0
&& (ev.xexpose.window == infobar.bar->win)) && (ev->window == infobar->bar->win))
infobar_draw(); infobar_draw();
for(c = clients; c; c = c->next) for(c = clients; c; c = c->next)
if(ev.xexpose.window == c->titlebar) if(ev->window == c->titlebar)
frame_update(c); frame_update(c);
return; return;
@ -205,9 +204,9 @@ expose(XEvent ev)
/* FOCUSIN */ /* FOCUSIN */
void void
focusin(XEvent ev) focusin(XFocusChangeEvent *ev)
{ {
if(sel && ev.xfocus.window != sel->win) if(sel && ev->window != sel->win)
XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime); XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
return; return;
@ -235,16 +234,16 @@ grabkeys(void)
/* KEYPRESS */ /* KEYPRESS */
void void
keypress(XEvent ev) keypress(XKeyPressedEvent *ev)
{ {
uint i; uint i;
KeySym keysym; KeySym keysym;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev.xkey.keycode, 0); keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
for(i = 0; i < conf.nkeybind; ++i) for(i = 0; i < conf.nkeybind; ++i)
if(keysym == keys[i].keysym if(keysym == keys[i].keysym
&& (keys[i].mod & ~(numlockmask | LockMask)) == && (keys[i].mod & ~(numlockmask | LockMask)) ==
(ev.xkey.state & ~(numlockmask | LockMask)) (ev->state & ~(numlockmask | LockMask))
&& keys[i].func) && keys[i].func)
keys[i].func(keys[i].cmd); keys[i].func(keys[i].cmd);
@ -253,9 +252,9 @@ keypress(XEvent ev)
/* MAPPINGNOTIFY */ /* MAPPINGNOTIFY */
void void
mapnotify(XEvent ev) mapnotify(XMappingEvent *ev)
{ {
if(ev.xmapping.request == MappingKeyboard) if(ev->request == MappingKeyboard)
grabkeys(); grabkeys();
return; return;
@ -263,14 +262,14 @@ mapnotify(XEvent ev)
/* MAPREQUEST */ /* MAPREQUEST */
void void
maprequest(XEvent ev) maprequest(XMapRequestEvent *ev)
{ {
XWindowAttributes at; XWindowAttributes at;
CHECK(XGetWindowAttributes(dpy, ev.xmaprequest.window, &at)); CHECK(XGetWindowAttributes(dpy, ev->window, &at));
CHECK(!at.override_redirect); CHECK(!at.override_redirect);
if(!client_get(ev.xmaprequest.window)) if(!client_gb_win(ev->window))
client_manage(ev.xmaprequest.window, &at); client_manage(ev->window, &at);
return; return;
} }
@ -278,29 +277,29 @@ maprequest(XEvent ev)
/* PROPERTYNOTIFY */ /* PROPERTYNOTIFY */
void void
propertynotify(XEvent ev) propertynotify(XPropertyEvent *ev)
{ {
Client *c; Client *c;
Window trans; Window trans;
if(event.xproperty.state == PropertyDelete) if(ev->state == PropertyDelete)
return; return;
if((c = client_get(event.xproperty.window))) if((c = client_gb_win(ev->window)))
{ {
switch(event.xproperty.atom) switch(ev->atom)
{ {
default: break; default: break;
case XA_WM_TRANSIENT_FOR: case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &trans); XGetTransientForHint(dpy, c->win, &trans);
if((c->tile || c->max) && (c->hint = (client_get(trans) != NULL))) if((c->tile || c->max) && (c->hint = (client_gb_win(trans) != NULL)))
arrange(); arrange();
break; break;
case XA_WM_NORMAL_HINTS: case XA_WM_NORMAL_HINTS:
client_size_hints(c); client_size_hints(c);
break; break;
} }
if(ev.xproperty.atom == XA_WM_NAME if(ev->atom == XA_WM_NAME
|| ev.xproperty.atom == net_atom[NetWMName]) || ev->atom == net_atom[NetWMName])
client_get_name(c); client_get_name(c);
} }
@ -309,13 +308,13 @@ propertynotify(XEvent ev)
void void
unmapnotify(XEvent ev) unmapnotify(XUnmapEvent *ev)
{ {
Client *c; Client *c;
if((c = client_get(event.xunmap.window)) if((c = client_gb_win(ev->window))
&& ev.xunmap.event == root && ev->event == root
&& ev.xunmap.send_event && ev->send_event
&& getwinstate(c->win) == NormalState && getwinstate(c->win) == NormalState
&& !c->hide) && !c->hide)
client_unmanage(c); client_unmanage(c);
@ -325,21 +324,21 @@ unmapnotify(XEvent ev)
/* Handle */ /* Handle */
void void
getevent(void) getevent(XEvent ev)
{ {
switch (event.type) switch (ev.type)
{ {
case ButtonPress: buttonpress(event); break; case ButtonPress: buttonpress(&ev.xbutton); break;
case ConfigureRequest: configurerequest(event); break; case ConfigureRequest: configurerequest(&ev.xconfigurerequest); break;
case DestroyNotify: destroynotify(event); break; case DestroyNotify: destroynotify(&ev.xdestroywindow); break;
case EnterNotify: enternotify(event); break; case EnterNotify: enternotify(&ev.xcrossing); break;
case Expose: expose(event); break; case Expose: expose(&ev.xexpose); break;
case FocusIn: focusin(event); break; case FocusIn: focusin(&ev.xfocus); break;
case KeyPress: keypress(event); break; case KeyPress: keypress(&ev.xkey); break;
case MapRequest: maprequest(event); break; case MapRequest: maprequest(&ev.xmaprequest); break;
case MappingNotify: mapnotify(event); break; case MappingNotify: mapnotify(&ev.xmapping); break;
case PropertyNotify: propertynotify(event); break; case PropertyNotify: propertynotify(&ev.xproperty); break;
case UnmapNotify: unmapnotify(event); break; case UnmapNotify: unmapnotify(&ev.xunmap); break;
} }
return; return;

View File

@ -138,33 +138,4 @@ frame_update(Client *c)
return; return;
} }
Client*
frame_get(Window w)
{
Client *c;
for(c = clients; c && c->frame != w; c = c->next);
return c;
}
Client*
frame_get_titlebar(Window w)
{
Client *c;
for(c = clients; c && c->titlebar != w; c = c->next);
return c;
}
Client*
frame_get_resize(Window w)
{
Client *c;
for(c = clients; c && c->resize != w; c = c->next);
return c;
}

View File

@ -33,27 +33,28 @@
#include "wmfs.h" #include "wmfs.h"
void void
infobar_init(InfoBar *ib) infobar_init(void)
{ {
ib->geo.height = font->height * 1.5; infobar = emalloc(1, sizeof(InfoBar));
ib->geo.y = (conf.bartop) ? 0 : MAXH - ib->geo.height;
infobar->geo.height = font->height * 1.5;
infobar->geo.y = (conf.bartop) ? 0 : MAXH - infobar->geo.height;
/* Create infobar barwindow */ /* Create infobar barwindow */
ib->bar = bar_create(root, 0, ib->geo.y, MAXW, ib->geo.height, 0, conf.colors.bar, False); infobar->bar = bar_create(root, 0, infobar->geo.y, MAXW, infobar->geo.height, 0, conf.colors.bar, False);
/* Create layout switch & layout type switch barwindow */ /* Create layout switch & layout type switch barwindow */
ib->layout_switch = bar_create(ib->bar->win, 0, 0, infobar->layout_switch = bar_create(infobar->bar->win, 0, 0,
1, ib->geo.height - 1, 0, 1, infobar->geo.height - 1, 0,
conf.colors.layout_bg, False); conf.colors.layout_bg, False);
ib->layout_type_switch = bar_create(ib->bar->win, 0, 0, infobar->layout_type_switch = bar_create(infobar->bar->win, 0, 0,
1, ib->geo.height, 1, infobar->geo.height,
0, conf.colors.layout_bg, False); 0, conf.colors.layout_bg, False);
/* Map all */ /* Map all */
bar_map(ib->bar); bar_map(infobar->bar);
bar_map(ib->layout_switch); bar_map(infobar->layout_switch);
strcpy(infobar->statustext, "WMFS-" WMFS_VERSION);
strcpy(ib->statustext, "WMFS-" WMFS_VERSION);
infobar_draw(); infobar_draw();
return; return;
@ -63,12 +64,11 @@ void
infobar_draw(void) infobar_draw(void)
{ {
char buf[256]; char buf[256];
/* Refresh bar color */ /* Refresh bar color */
bar_refresh_color(infobar.bar); bar_refresh_color(infobar->bar);
/* Draw taglist */ /* Draw taglist */
infobar_draw_taglist(infobar.bar->dr); infobar_draw_taglist();
/* Draw layout symbol */ /* Draw layout symbol */
infobar_draw_layout(); infobar_draw_layout();
@ -77,28 +77,28 @@ infobar_draw(void)
sprintf(buf, "mwfact: %.2f - nmaster: %d", sprintf(buf, "mwfact: %.2f - nmaster: %d",
tags[seltag].mwfact, tags[seltag].mwfact,
tags[seltag].nmaster); tags[seltag].nmaster);
draw_text(infobar.bar->dr, infobar.lastsep + PAD/1.5, font->height, conf.colors.text, conf.colors.bar, 0, buf); draw_text(infobar->bar->dr, infobar->lastsep + PAD/1.5, font->height, conf.colors.text, conf.colors.bar, 0, buf);
draw_rectangle(infobar.bar->dr, textw(buf) + infobar.lastsep + PAD, draw_rectangle(infobar->bar->dr, textw(buf) + infobar->lastsep + PAD,
0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord); 0, conf.tagbordwidth, infobar->geo.height, conf.colors.tagbord);
/* Draw status text */ /* Draw status text */
draw_text(infobar.bar->dr, draw_text(infobar->bar->dr,
MAXW - textw(infobar.statustext), MAXW - textw(infobar->statustext),
font->height, font->height,
conf.colors.text, conf.colors.text,
conf.colors.bar, 0, infobar.statustext); conf.colors.bar, 0, infobar->statustext);
/* Bar border */ /* Bar border */
if(conf.tagbordwidth) if(conf.tagbordwidth)
{ {
draw_rectangle(infobar.bar->dr, 0, ((conf.bartop) ? infobar.geo.height - 1: 0), draw_rectangle(infobar->bar->dr, 0, ((conf.bartop) ? infobar->geo.height - 1: 0),
MAXW, 1, conf.colors.tagbord); MAXW, 1, conf.colors.tagbord);
draw_rectangle(infobar.bar->dr, MAXW - textw(infobar.statustext) - 5, draw_rectangle(infobar->bar->dr, MAXW - textw(infobar->statustext) - 5,
0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord); 0, conf.tagbordwidth, infobar->geo.height, conf.colors.tagbord);
} }
/* Refresh the bar */ /* Refresh the bar */
bar_refresh(infobar.bar); bar_refresh(infobar->bar);
return; return;
} }
@ -118,44 +118,45 @@ infobar_draw_layout(void)
strcpy(symbol, conf.tile_symbol); strcpy(symbol, conf.tile_symbol);
/* Draw layout name/symbol */ /* Draw layout name/symbol */
bar_refresh_color(infobar.layout_switch); bar_refresh_color(infobar->layout_switch);
bar_move(infobar.layout_switch, px, 0); bar_move(infobar->layout_switch, px, 0);
bar_resize(infobar.layout_switch, textw(symbol) + PAD, infobar.geo.height); bar_resize(infobar->layout_switch, textw(symbol) + PAD, infobar->geo.height);
draw_text(infobar.layout_switch->dr, PAD/2, font->height, draw_text(infobar->layout_switch->dr, PAD/2, font->height,
conf.colors.layout_fg, conf.colors.layout_fg,
conf.colors.layout_bg, conf.colors.layout_bg,
PAD, symbol); PAD, symbol);
width += textw(symbol) + PAD; width += textw(symbol) + PAD;
bar_refresh(infobar.layout_switch); bar_refresh(infobar->layout_switch);
if(tags[seltag].layout.func != freelayout if(tags[seltag].layout.func != freelayout
&& tags[seltag].layout.func != maxlayout) && tags[seltag].layout.func != maxlayout)
{ {
bar_map(infobar.layout_type_switch); bar_map(infobar->layout_type_switch);
bar_refresh_color(infobar.layout_type_switch); bar_refresh_color(infobar->layout_type_switch);
bar_move(infobar.layout_type_switch, px + infobar.layout_switch->geo.width + PAD/2, py); bar_move(infobar->layout_type_switch, px + infobar->layout_switch->geo.width + PAD/2, py);
bar_resize(infobar.layout_type_switch, textw(tags[seltag].layout.symbol) + PAD, infobar.geo.height); bar_resize(infobar->layout_type_switch, textw(tags[seltag].layout.symbol) + PAD, infobar->geo.height);
draw_text(infobar.layout_type_switch->dr, PAD/2, font->height, draw_text(infobar->layout_type_switch->dr, PAD/2, font->height,
conf.colors.layout_fg, conf.colors.layout_fg,
conf.colors.layout_bg, conf.colors.layout_bg,
PAD, tags[seltag].layout.symbol); PAD, tags[seltag].layout.symbol);
width += textw(tags[seltag].layout.symbol) + PAD * 1.5; width += textw(tags[seltag].layout.symbol) + PAD * 1.5;
bar_refresh(infobar.layout_type_switch); bar_refresh(infobar->layout_type_switch);
} }
else else
bar_unmap(infobar.layout_type_switch); bar_unmap(infobar->layout_type_switch);
/* Draw right separation */ /* Draw right separation */
infobar.lastsep = width + PAD / 2; infobar->lastsep = width + PAD / 2;
draw_rectangle(infobar.bar->dr, infobar.lastsep, 0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord); draw_rectangle(infobar->bar->dr, infobar->lastsep, 0,
conf.tagbordwidth, infobar->geo.height, conf.colors.tagbord);
return; return;
} }
void void
infobar_draw_taglist(Drawable dr) infobar_draw_taglist(void)
{ {
int i; int i;
char buf[conf.ntag][256]; char buf[conf.ntag][256];
@ -167,17 +168,16 @@ infobar_draw_taglist(Drawable dr)
/* Make the tags string */ /* Make the tags string */
ITOA(p, client_pertag(i+1)); ITOA(p, client_pertag(i+1));
sprintf(buf[i], "%s<%s>", tags[i+1].name, (client_pertag(i+1)) ? p : ""); sprintf(buf[i], "%s<%s>", tags[i+1].name, (client_pertag(i+1)) ? p : "");
/* Draw the string */ /* Draw the string */
draw_text(dr, taglen[i], font->height, draw_text(infobar->bar->dr, taglen[i], font->height,
((i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text), ((i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text),
((i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar), PAD, buf[i]); ((i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar), PAD, buf[i]);
/* Draw the tag separation */ /* Draw the tag separation */
draw_rectangle(dr, taglen[i] + textw(buf[i]) + PAD/2, draw_rectangle(infobar->bar->dr, taglen[i] + textw(buf[i]) + PAD/2,
0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord); 0, conf.tagbordwidth, infobar->geo.height, conf.colors.tagbord);
/* Edit taglen[i+1] for the next time */ /* Edit taglen[i+1] for the next time */
taglen[i+1] = taglen[i] + textw(buf[i]) + PAD + conf.tagbordwidth; taglen[i+1] = taglen[i] + textw(buf[i]) + PAD + conf.tagbordwidth;
} }
@ -189,12 +189,12 @@ uicb_infobar_togglepos(uicb_t cmd)
{ {
conf.bartop = !conf.bartop; conf.bartop = !conf.bartop;
if(conf.bartop) if(conf.bartop)
sgeo.y = infobar.geo.height + TBARH; sgeo.y = infobar->geo.height + TBARH;
else else
sgeo.y = TBARH; sgeo.y = TBARH;
infobar.geo.y = (conf.bartop) ? 0 : MAXH - infobar.geo.height; infobar->geo.y = (conf.bartop) ? 0 : MAXH - infobar->geo.height;
bar_move(infobar.bar, 0, infobar.geo.y); bar_move(infobar->bar, 0, infobar->geo.y);
infobar_draw(); infobar_draw();
arrange(); arrange();

View File

@ -36,17 +36,17 @@ void
init(void) init(void)
{ {
/* First init */ /* First init */
gc = DefaultGC (dpy, screen); gc = DefaultGC(dpy, screen);
screen = DefaultScreen (dpy); screen = DefaultScreen(dpy);
init_font(); init_font();
init_cursor(); init_cursor();
init_key(); init_key();
init_atom(); init_atom();
init_root(); init_root();
infobar_init(&infobar); infobar_init();
init_geometry(); init_geometry();
grabkeys(); grabkeys();
XSetErrorHandler(errorhandler);
/* Warning about font */ /* Warning about font */
if(TBARH + BORDH < font->height) if(TBARH + BORDH < font->height)
@ -133,7 +133,7 @@ void
init_geometry(void) init_geometry(void)
{ {
sgeo.x = BORDH; sgeo.x = BORDH;
sgeo.y = infobar.geo.height; sgeo.y = infobar->geo.height;
if(conf.bartop) if(conf.bartop)
sgeo.y += TBARH; sgeo.y += TBARH;
@ -141,7 +141,7 @@ init_geometry(void)
sgeo.y = TBARH; sgeo.y = TBARH;
sgeo.width = MAXW; sgeo.width = MAXW;
sgeo.height = MAXH - infobar.geo.height - TBARH; sgeo.height = MAXH - infobar->geo.height - TBARH;
return; return;
} }

View File

@ -72,7 +72,7 @@ mouse_move(Client *c)
client_moveresize(c, geo, True); client_moveresize(c, geo, True);
} }
else if(ev.type == Expose) else if(ev.type == Expose)
expose(ev); expose(&ev.xexpose);
} }
return; return;
@ -107,12 +107,12 @@ mouse_resize(Client *c)
mx = sgeo.width - (tags[seltag].mwfact * sgeo.width); mx = sgeo.width - (tags[seltag].mwfact * sgeo.width);
else if(tags[seltag].layout.func == tile_top) else if(tags[seltag].layout.func == tile_top)
{ {
mx = event.xmotion.x_root; mx = ev.xmotion.x_root;
my = sgeo.height - (tags[seltag].mwfact * sgeo.height); my = sgeo.height - (tags[seltag].mwfact * sgeo.height);
} }
else if(tags[seltag].layout.func == tile_bottom) else if(tags[seltag].layout.func == tile_bottom)
{ {
mx = event.xmotion.x_root; mx = ev.xmotion.x_root;
my = tags[seltag].mwfact * sgeo.height; my = tags[seltag].mwfact * sgeo.height;
} }
XWarpPointer(dpy, None, root, 0, 0, 0, 0, mx, my); XWarpPointer(dpy, None, root, 0, 0, 0, 0, mx, my);
@ -166,7 +166,7 @@ mouse_resize(Client *c)
client_moveresize(c, geo, True); client_moveresize(c, geo, True);
} }
else if(ev.type == Expose) else if(ev.type == Expose)
expose(ev); expose(&ev.xexpose);
} }

View File

@ -32,39 +32,28 @@
#include "wmfs.h" #include "wmfs.h"
void
checkotherwm(void)
{
owm = False;
XSetErrorHandler(errorhandlerstart);
XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
XSync(dpy, False);
if(owm)
{
fprintf(stderr, "WMFS Error: Another Window Manager is already running.\n");
exit(EXIT_FAILURE);
}
XSetErrorHandler(errorhandler);
XSync(dpy, False);
return;
}
int int
errorhandler(Display *d, XErrorEvent *event) errorhandler(Display *d, XErrorEvent *event)
{ {
char mess[512]; char mess[256];
/* Check if there are another WM running */
if(BadAccess == event->error_code
&& DefaultRootWindow(dpy) == event->resourceid)
{
fprintf(stderr, "WMFS Error: Another Window Manager is already running.\n");
exit(EXIT_FAILURE);
}
XGetErrorText(d, event->error_code, mess, 128); XGetErrorText(d, event->error_code, mess, 128);
fprintf(stderr, "WMFS error: %s(%d) opcodes %d/%d\n resource 0x%lx\n", mess, fprintf(stderr, "WMFS error: %s(%d) opcodes %d/%d\n resource #%lx\n", mess,
event->error_code, event->error_code,
event->request_code, event->request_code,
event->minor_code, event->minor_code,
event->resourceid); event->resourceid);
return 1; return 1;
} }
@ -75,15 +64,6 @@ errorhandlerdummy(Display *d, XErrorEvent *event)
return 0; return 0;
} }
/* Only for check if another WM is already running */
int
errorhandlerstart(Display *d, XErrorEvent *event)
{
owm = True;
return -1;
}
void void
quit(void) quit(void)
{ {
@ -92,9 +72,10 @@ quit(void)
XFreeCursor(dpy, cursor[CurNormal]); XFreeCursor(dpy, cursor[CurNormal]);
XFreeCursor(dpy, cursor[CurMove]); XFreeCursor(dpy, cursor[CurMove]);
XFreeCursor(dpy, cursor[CurResize]); XFreeCursor(dpy, cursor[CurResize]);
bar_delete(infobar.bar); bar_delete(infobar->bar);
bar_delete(infobar.layout_switch); bar_delete(infobar->layout_switch);
bar_delete(infobar.layout_type_switch); bar_delete(infobar->layout_type_switch);
efree(infobar);
efree(keys); efree(keys);
efree(conf.titlebar.mouse); efree(conf.titlebar.mouse);
efree(conf.client.mouse); efree(conf.client.mouse);
@ -108,12 +89,13 @@ void
mainloop(void) mainloop(void)
{ {
fd_set fd; fd_set fd;
char sbuf[sizeof infobar.statustext], *p; char sbuf[sizeof infobar->statustext], *p;
int len, r, offset = 0; int len, r, offset = 0;
Bool readstdin = True; Bool readstdin = True;
XEvent ev;
len = sizeof infobar.statustext - 1; len = sizeof infobar->statustext - 1;
sbuf[len] = infobar.statustext[len] = '\0'; sbuf[len] = infobar->statustext[len] = '\0';
while(!exiting) while(!exiting)
{ {
@ -132,7 +114,7 @@ mainloop(void)
if(*p == '\n') if(*p == '\n')
{ {
*p = '\0'; *p = '\0';
strncpy(infobar.statustext, sbuf, len); strncpy(infobar->statustext, sbuf, len);
p += r - 1; p += r - 1;
for(r = 0; *(p - r) && *(p - r) != '\n'; ++r); for(r = 0; *(p - r) && *(p - r) != '\n'; ++r);
offset = r; offset = r;
@ -144,15 +126,15 @@ mainloop(void)
} }
else else
{ {
strncpy(infobar.statustext, sbuf, strlen(sbuf)); strncpy(infobar->statustext, sbuf, strlen(sbuf));
readstdin = False; readstdin = False;
} }
infobar_draw(); infobar_draw();
} }
while(XPending(dpy)) while(XPending(dpy))
{ {
XNextEvent(dpy, &event); XNextEvent(dpy, &ev);
getevent(); getevent(ev);
} }
} }
@ -172,24 +154,20 @@ void
scan(void) scan(void)
{ {
uint i, num; uint i, num;
Window *wins, d1, d2; Window *wins = NULL, d;
XWindowAttributes wa; XWindowAttributes wa;
wins = NULL; if(XQueryTree(dpy, root, &d, &d, &wins, &num))
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num))
{
for(i = 0; i < num; i++) for(i = 0; i < num; i++)
{ {
if(!XGetWindowAttributes(dpy, wins[i], &wa)) if(wins[i] && wins[i] != infobar->bar->win)
continue; {
if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) XGetWindowAttributes(dpy, wins[i], &wa);
continue; if(wa.override_redirect && wa.map_state == IsViewable)
if(wa.map_state == IsViewable) client_manage(wins[i], &wa);
client_manage(wins[i], &wa); }
} }
} XFree(wins);
if(wins)
XFree(wins);
arrange(); arrange();
@ -244,8 +222,9 @@ main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* Check if an other WM is already running */ /* Check if an other WM is already running; set the error handler */
checkotherwm(); XSetErrorHandler(errorhandler);
XSetErrorHandler(errorhandlerdummy);
/* Let's Go ! */ /* Let's Go ! */
init_conf(); init_conf();

View File

@ -88,10 +88,10 @@ void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color);
ushort textw(const char *text); ushort textw(const char *text);
/* infobar.c */ /* infobar.c */
void infobar_init(InfoBar *ib); void infobar_init(void);
void infobar_draw(void); void infobar_draw(void);
void infobar_draw_layout(void); void infobar_draw_layout(void);
void infobar_draw_taglist(Drawable dr); void infobar_draw_taglist(void);
void uicb_infobar_togglepos(uicb_t cmd); void uicb_infobar_togglepos(uicb_t cmd);
/* client.c */ /* client.c */
@ -99,7 +99,12 @@ int client_pertag(int tag);
void client_attach(Client *c); void client_attach(Client *c);
void client_detach(Client *c); void client_detach(Client *c);
void client_focus(Client *c); void client_focus(Client *c);
Client *client_get(Window w); /* client_gb_*() {{{ */
Client* client_gb_win(Window w);
Client* client_gb_frame(Window w);
Client* client_gb_titlebar(Window w);
Client* client_gb_resize(Window w);
/* }}} */
void client_get_name(Client *c); void client_get_name(Client *c);
void client_hide(Client *c); void client_hide(Client *c);
Bool ishide(Client *c); Bool ishide(Client *c);
@ -119,29 +124,25 @@ void uicb_client_kill(uicb_t);
/* frame.c */ /* frame.c */
void frame_create(Client *c); void frame_create(Client *c);
void frame_moveresize(Client *c, XRectangle geo); void frame_moveresize(Client *c, XRectangle geo);
Client* frame_get(Window w);
void frame_update(Client *c); void frame_update(Client *c);
void frame_set_color(Client *c, uint bg);
Client* frame_get_titlebar(Window w);
Client* frame_get_resize(Window w);
/* config.c */ /* config.c */
void init_conf(void); void init_conf(void);
/* event.c */ /* event.c */
void buttonpress(XEvent ev); void buttonpress(XButtonEvent *ev);
void configurerequest(XEvent ev); void configurerequest(XConfigureRequestEvent *ev);
void destroynotify(XEvent ev); void destroynotify(XDestroyWindowEvent *ev);
void enternotify(XEvent ev); void enternotify(XCrossingEvent *ev);
void expose(XEvent ev); void expose(XExposeEvent *ev);
void focusin(XEvent ev); void focusin(XFocusChangeEvent *ev);
void grabkeys(void); void grabkeys(void);
void keypress(XEvent ev); void keypress(XKeyPressedEvent *ev);
void mapnotify(XEvent ev); void mapnotify(XMappingEvent *ev);
void maprequest(XEvent ev); void maprequest(XMapRequestEvent *ev);
void propertynotify(XEvent ev); void propertynotify(XPropertyEvent *ev);
void unmapnotify(XEvent ev); void unmapnotify(XUnmapEvent *ev);
void getevent(void); void getevent(XEvent ev);
/* mouse.c */ /* mouse.c */
void mouse_move(Client *c); void mouse_move(Client *c);
@ -210,7 +211,6 @@ void uicb_quit(uicb_t);
/* Principal */ /* Principal */
Display *dpy; Display *dpy;
XEvent event;
GC gc; GC gc;
Window root; Window root;
XRectangle sgeo; XRectangle sgeo;
@ -218,7 +218,6 @@ int screen;
Conf conf; Conf conf;
Key *keys; Key *keys;
Bool exiting; Bool exiting;
Bool owm;
/* Atoms / Cursors */ /* Atoms / Cursors */
Atom wm_atom[WMLast]; Atom wm_atom[WMLast];
@ -229,7 +228,7 @@ Cursor cursor[CurLast];
XftFont *font; XftFont *font;
/* InfoBar */ /* InfoBar */
InfoBar infobar; InfoBar *infobar;
Tag tags[MAXTAG]; Tag tags[MAXTAG];
int taglen[MAXTAG]; int taglen[MAXTAG];
int seltag; int seltag;