event: Improve event system
This commit is contained in:
parent
528a22b75a
commit
0a15b3ba6f
43
src/client.c
43
src/client.c
@ -147,20 +147,47 @@ client_focus(Client *c)
|
||||
return;
|
||||
}
|
||||
|
||||
Client*
|
||||
client_get(Window w)
|
||||
{
|
||||
Client *c;
|
||||
/* Get Client with any window Client member {{{ */
|
||||
Client* client_gb_win(Window w)
|
||||
{
|
||||
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
|
||||
client_get_name(Client *c)
|
||||
{
|
||||
|
||||
XFetchName(dpy, c->win, &(c->title));
|
||||
if(!c->title)
|
||||
c->title = strdup("WMFS");
|
||||
|
||||
@ -411,7 +411,6 @@ init_conf(void)
|
||||
conf.titlebar.mouse[i].cmd = strdup(var_to_str(cfg_getstr(cfgtmp2, "cmd")));
|
||||
}
|
||||
|
||||
|
||||
/* layout */
|
||||
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")));
|
||||
@ -449,7 +448,6 @@ init_conf(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* tag */
|
||||
/* if there is no tag in the conf or more than
|
||||
* MAXTAG (32) print an error and create only one. */
|
||||
|
||||
@ -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));
|
||||
|
||||
/* 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 */
|
||||
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 */
|
||||
XftColorFree(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &xftcolor);
|
||||
|
||||
XftDrawDestroy(xftd);
|
||||
|
||||
|
||||
|
||||
173
src/event.c
173
src/event.c
@ -34,83 +34,83 @@
|
||||
|
||||
/* BUTTONPRESS */
|
||||
void
|
||||
buttonpress(XEvent ev)
|
||||
buttonpress(XButtonEvent *ev)
|
||||
{
|
||||
Client *c;
|
||||
int i;
|
||||
char s[6];
|
||||
|
||||
/* 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)
|
||||
if(ev.xbutton.button == conf.titlebar.mouse[i].button)
|
||||
if(ev->button == conf.titlebar.mouse[i].button)
|
||||
if(conf.titlebar.mouse[i].func)
|
||||
conf.titlebar.mouse[i].func(conf.titlebar.mouse[i].cmd);
|
||||
|
||||
/* Frame Resize Area */
|
||||
if((c = frame_get_resize(ev.xbutton.window)))
|
||||
if((c = client_gb_resize(ev->window)))
|
||||
mouse_resize(c);
|
||||
|
||||
/* Client */
|
||||
if((c = client_get(ev.xbutton.window)))
|
||||
if((c = client_gb_win(ev->window)))
|
||||
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)
|
||||
conf.client.mouse[i].func(conf.client.mouse[i].cmd);
|
||||
|
||||
/* Root */
|
||||
if(ev.xbutton.window == root)
|
||||
if(ev->window == root)
|
||||
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)
|
||||
conf.root.mouse[i].func(conf.root.mouse[i].cmd);
|
||||
|
||||
/* Bar */
|
||||
{
|
||||
if(ev.xbutton.window == infobar.bar->win)
|
||||
if(ev->window == infobar->bar->win)
|
||||
{
|
||||
/* Tag*/
|
||||
for(i = 0; i < conf.ntag + 1; ++i)
|
||||
{
|
||||
if(ev.xbutton.x > taglen[i-1] - 3
|
||||
&& ev.xbutton.x < (taglen[i] - 3))
|
||||
if(ev->x > taglen[i-1] - 3
|
||||
&& ev->x < (taglen[i] - 3))
|
||||
{
|
||||
ITOA(s, i);
|
||||
if(ev.xbutton.button == Button1)
|
||||
if(ev->button == Button1)
|
||||
uicb_tag(s);
|
||||
if(ev.xbutton.button == Button3)
|
||||
if(ev->button == Button3)
|
||||
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");
|
||||
if (ev.xbutton.button == Button5)
|
||||
if (ev->button == Button5)
|
||||
uicb_tag("-1");
|
||||
}
|
||||
}
|
||||
/* Layout */
|
||||
{
|
||||
if(ev.xbutton.window == infobar.layout_switch->win)
|
||||
if(ev->window == infobar->layout_switch->win)
|
||||
{
|
||||
if(ev.xbutton.button == Button1
|
||||
|| ev.xbutton.button == Button4)
|
||||
if(ev->button == Button1
|
||||
|| ev->button == Button4)
|
||||
layoutswitch(True);
|
||||
|
||||
if(ev.xbutton.button == Button3
|
||||
|| ev.xbutton.button == Button5)
|
||||
if(ev->button == Button3
|
||||
|| ev->button == Button5)
|
||||
layoutswitch(False);
|
||||
}
|
||||
|
||||
if(ev.xbutton.window == infobar.layout_type_switch->win)
|
||||
if(ev->window == infobar->layout_type_switch->win)
|
||||
{
|
||||
if(ev.xbutton.button == Button1
|
||||
|| ev.xbutton.button == Button4)
|
||||
if(ev->button == Button1
|
||||
|| ev->button == Button4)
|
||||
layout_tile_switch(True);
|
||||
|
||||
if(ev.xbutton.button == Button3
|
||||
|| ev.xbutton.button == Button5)
|
||||
if(ev->button == Button3
|
||||
|| ev->button == Button5)
|
||||
layout_tile_switch(False);
|
||||
}
|
||||
}
|
||||
@ -121,29 +121,28 @@ buttonpress(XEvent ev)
|
||||
|
||||
/* CONFIGUREREQUEST */
|
||||
void
|
||||
configurerequest(XEvent ev)
|
||||
configurerequest(XConfigureRequestEvent *ev)
|
||||
{
|
||||
Client *c;
|
||||
XWindowChanges wc;
|
||||
XRectangle geo;
|
||||
|
||||
if((c = client_get(ev.xconfigurerequest.window)))
|
||||
if((c = client_gb_win(ev->window)))
|
||||
{
|
||||
CHECK(!c->tile);
|
||||
CHECK(!c->lmax);
|
||||
}
|
||||
geo.x = wc.x = ev.xconfigurerequest.x;
|
||||
geo.y = wc.y = ev.xconfigurerequest.y;
|
||||
geo.width = wc.width = ev.xconfigurerequest.width;
|
||||
geo.height = wc.height = ev.xconfigurerequest.height;
|
||||
wc.border_width = ev.xconfigurerequest.border_width;
|
||||
wc.sibling = ev.xconfigurerequest.above;
|
||||
wc.stack_mode = ev.xconfigurerequest.detail;
|
||||
geo.x = wc.x = ev->x;
|
||||
geo.y = wc.y = ev->y;
|
||||
geo.width = wc.width = ev->width;
|
||||
geo.height = wc.height = ev->height;
|
||||
wc.border_width = ev->border_width;
|
||||
wc.sibling = ev->above;
|
||||
wc.stack_mode = ev->detail;
|
||||
|
||||
XConfigureWindow(dpy, ev.xconfigurerequest.window,
|
||||
ev.xconfigurerequest.value_mask, &wc);
|
||||
XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
|
||||
|
||||
if((c = client_get(ev.xconfigurerequest.window)))
|
||||
if((c = client_gb_win(ev->window)))
|
||||
{
|
||||
client_moveresize(c, geo, True);
|
||||
XReparentWindow(dpy, c->win, c->frame,
|
||||
@ -157,10 +156,10 @@ configurerequest(XEvent ev)
|
||||
|
||||
/* DESTROYNOTIFY */
|
||||
void
|
||||
destroynotify(XEvent ev)
|
||||
destroynotify(XDestroyWindowEvent *ev)
|
||||
{
|
||||
Client *c;
|
||||
if((c = client_get(ev.xdestroywindow.window)))
|
||||
if((c = client_gb_win(ev->window)))
|
||||
client_unmanage(c);
|
||||
|
||||
return;
|
||||
@ -168,18 +167,18 @@ destroynotify(XEvent ev)
|
||||
|
||||
/* ENTERNOTIFY */
|
||||
void
|
||||
enternotify(XEvent ev)
|
||||
enternotify(XCrossingEvent *ev)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
if(ev.xcrossing.mode != NotifyNormal
|
||||
|| ev.xcrossing.detail == NotifyInferior)
|
||||
if(ev->mode != NotifyNormal
|
||||
|| ev->detail == NotifyInferior)
|
||||
return;
|
||||
if((c = client_get(ev.xcrossing.window))
|
||||
|| (c = frame_get(ev.xcrossing.window))
|
||||
|| (c = frame_get_titlebar(ev.xcrossing.window))
|
||||
|| (c = frame_get_resize(ev.xcrossing.window)))
|
||||
client_focus(c);
|
||||
if((c = client_gb_win(ev->window))
|
||||
|| (c = client_gb_frame(ev->window))
|
||||
|| (c = client_gb_titlebar(ev->window))
|
||||
|| (c = client_gb_resize(ev->window)))
|
||||
client_focus(c);
|
||||
else
|
||||
client_focus(NULL);
|
||||
|
||||
@ -188,16 +187,16 @@ enternotify(XEvent ev)
|
||||
|
||||
/* EXPOSE */
|
||||
void
|
||||
expose(XEvent ev)
|
||||
expose(XExposeEvent *ev)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
if(ev.xexpose.count == 0
|
||||
&& (ev.xexpose.window == infobar.bar->win))
|
||||
if(ev->count == 0
|
||||
&& (ev->window == infobar->bar->win))
|
||||
infobar_draw();
|
||||
|
||||
for(c = clients; c; c = c->next)
|
||||
if(ev.xexpose.window == c->titlebar)
|
||||
if(ev->window == c->titlebar)
|
||||
frame_update(c);
|
||||
|
||||
return;
|
||||
@ -205,9 +204,9 @@ expose(XEvent ev)
|
||||
|
||||
/* FOCUSIN */
|
||||
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);
|
||||
|
||||
return;
|
||||
@ -235,16 +234,16 @@ grabkeys(void)
|
||||
|
||||
/* KEYPRESS */
|
||||
void
|
||||
keypress(XEvent ev)
|
||||
keypress(XKeyPressedEvent *ev)
|
||||
{
|
||||
uint i;
|
||||
KeySym keysym;
|
||||
|
||||
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev.xkey.keycode, 0);
|
||||
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
|
||||
for(i = 0; i < conf.nkeybind; ++i)
|
||||
if(keysym == keys[i].keysym
|
||||
&& (keys[i].mod & ~(numlockmask | LockMask)) ==
|
||||
(ev.xkey.state & ~(numlockmask | LockMask))
|
||||
(ev->state & ~(numlockmask | LockMask))
|
||||
&& keys[i].func)
|
||||
keys[i].func(keys[i].cmd);
|
||||
|
||||
@ -253,9 +252,9 @@ keypress(XEvent ev)
|
||||
|
||||
/* MAPPINGNOTIFY */
|
||||
void
|
||||
mapnotify(XEvent ev)
|
||||
mapnotify(XMappingEvent *ev)
|
||||
{
|
||||
if(ev.xmapping.request == MappingKeyboard)
|
||||
if(ev->request == MappingKeyboard)
|
||||
grabkeys();
|
||||
|
||||
return;
|
||||
@ -263,14 +262,14 @@ mapnotify(XEvent ev)
|
||||
|
||||
/* MAPREQUEST */
|
||||
void
|
||||
maprequest(XEvent ev)
|
||||
maprequest(XMapRequestEvent *ev)
|
||||
{
|
||||
XWindowAttributes at;
|
||||
|
||||
CHECK(XGetWindowAttributes(dpy, ev.xmaprequest.window, &at));
|
||||
CHECK(XGetWindowAttributes(dpy, ev->window, &at));
|
||||
CHECK(!at.override_redirect);
|
||||
if(!client_get(ev.xmaprequest.window))
|
||||
client_manage(ev.xmaprequest.window, &at);
|
||||
if(!client_gb_win(ev->window))
|
||||
client_manage(ev->window, &at);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -278,29 +277,29 @@ maprequest(XEvent ev)
|
||||
|
||||
/* PROPERTYNOTIFY */
|
||||
void
|
||||
propertynotify(XEvent ev)
|
||||
propertynotify(XPropertyEvent *ev)
|
||||
{
|
||||
Client *c;
|
||||
Window trans;
|
||||
|
||||
if(event.xproperty.state == PropertyDelete)
|
||||
if(ev->state == PropertyDelete)
|
||||
return;
|
||||
if((c = client_get(event.xproperty.window)))
|
||||
if((c = client_gb_win(ev->window)))
|
||||
{
|
||||
switch(event.xproperty.atom)
|
||||
switch(ev->atom)
|
||||
{
|
||||
default: break;
|
||||
case XA_WM_TRANSIENT_FOR:
|
||||
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();
|
||||
break;
|
||||
case XA_WM_NORMAL_HINTS:
|
||||
client_size_hints(c);
|
||||
break;
|
||||
}
|
||||
if(ev.xproperty.atom == XA_WM_NAME
|
||||
|| ev.xproperty.atom == net_atom[NetWMName])
|
||||
if(ev->atom == XA_WM_NAME
|
||||
|| ev->atom == net_atom[NetWMName])
|
||||
client_get_name(c);
|
||||
}
|
||||
|
||||
@ -309,13 +308,13 @@ propertynotify(XEvent ev)
|
||||
|
||||
|
||||
void
|
||||
unmapnotify(XEvent ev)
|
||||
unmapnotify(XUnmapEvent *ev)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
if((c = client_get(event.xunmap.window))
|
||||
&& ev.xunmap.event == root
|
||||
&& ev.xunmap.send_event
|
||||
if((c = client_gb_win(ev->window))
|
||||
&& ev->event == root
|
||||
&& ev->send_event
|
||||
&& getwinstate(c->win) == NormalState
|
||||
&& !c->hide)
|
||||
client_unmanage(c);
|
||||
@ -325,21 +324,21 @@ unmapnotify(XEvent ev)
|
||||
|
||||
/* Handle */
|
||||
void
|
||||
getevent(void)
|
||||
getevent(XEvent ev)
|
||||
{
|
||||
switch (event.type)
|
||||
switch (ev.type)
|
||||
{
|
||||
case ButtonPress: buttonpress(event); break;
|
||||
case ConfigureRequest: configurerequest(event); break;
|
||||
case DestroyNotify: destroynotify(event); break;
|
||||
case EnterNotify: enternotify(event); break;
|
||||
case Expose: expose(event); break;
|
||||
case FocusIn: focusin(event); break;
|
||||
case KeyPress: keypress(event); break;
|
||||
case MapRequest: maprequest(event); break;
|
||||
case MappingNotify: mapnotify(event); break;
|
||||
case PropertyNotify: propertynotify(event); break;
|
||||
case UnmapNotify: unmapnotify(event); break;
|
||||
case ButtonPress: buttonpress(&ev.xbutton); break;
|
||||
case ConfigureRequest: configurerequest(&ev.xconfigurerequest); break;
|
||||
case DestroyNotify: destroynotify(&ev.xdestroywindow); break;
|
||||
case EnterNotify: enternotify(&ev.xcrossing); break;
|
||||
case Expose: expose(&ev.xexpose); break;
|
||||
case FocusIn: focusin(&ev.xfocus); break;
|
||||
case KeyPress: keypress(&ev.xkey); break;
|
||||
case MapRequest: maprequest(&ev.xmaprequest); break;
|
||||
case MappingNotify: mapnotify(&ev.xmapping); break;
|
||||
case PropertyNotify: propertynotify(&ev.xproperty); break;
|
||||
case UnmapNotify: unmapnotify(&ev.xunmap); break;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
29
src/frame.c
29
src/frame.c
@ -138,33 +138,4 @@ frame_update(Client *c)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
100
src/infobar.c
100
src/infobar.c
@ -33,27 +33,28 @@
|
||||
#include "wmfs.h"
|
||||
|
||||
void
|
||||
infobar_init(InfoBar *ib)
|
||||
infobar_init(void)
|
||||
{
|
||||
ib->geo.height = font->height * 1.5;
|
||||
ib->geo.y = (conf.bartop) ? 0 : MAXH - ib->geo.height;
|
||||
infobar = emalloc(1, sizeof(InfoBar));
|
||||
|
||||
infobar->geo.height = font->height * 1.5;
|
||||
infobar->geo.y = (conf.bartop) ? 0 : MAXH - infobar->geo.height;
|
||||
|
||||
/* 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 */
|
||||
ib->layout_switch = bar_create(ib->bar->win, 0, 0,
|
||||
1, ib->geo.height - 1, 0,
|
||||
conf.colors.layout_bg, False);
|
||||
ib->layout_type_switch = bar_create(ib->bar->win, 0, 0,
|
||||
1, ib->geo.height,
|
||||
0, conf.colors.layout_bg, False);
|
||||
infobar->layout_switch = bar_create(infobar->bar->win, 0, 0,
|
||||
1, infobar->geo.height - 1, 0,
|
||||
conf.colors.layout_bg, False);
|
||||
infobar->layout_type_switch = bar_create(infobar->bar->win, 0, 0,
|
||||
1, infobar->geo.height,
|
||||
0, conf.colors.layout_bg, False);
|
||||
|
||||
/* Map all */
|
||||
bar_map(ib->bar);
|
||||
bar_map(ib->layout_switch);
|
||||
|
||||
strcpy(ib->statustext, "WMFS-" WMFS_VERSION);
|
||||
bar_map(infobar->bar);
|
||||
bar_map(infobar->layout_switch);
|
||||
strcpy(infobar->statustext, "WMFS-" WMFS_VERSION);
|
||||
infobar_draw();
|
||||
|
||||
return;
|
||||
@ -63,12 +64,11 @@ void
|
||||
infobar_draw(void)
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
/* Refresh bar color */
|
||||
bar_refresh_color(infobar.bar);
|
||||
bar_refresh_color(infobar->bar);
|
||||
|
||||
/* Draw taglist */
|
||||
infobar_draw_taglist(infobar.bar->dr);
|
||||
infobar_draw_taglist();
|
||||
|
||||
/* Draw layout symbol */
|
||||
infobar_draw_layout();
|
||||
@ -77,28 +77,28 @@ infobar_draw(void)
|
||||
sprintf(buf, "mwfact: %.2f - nmaster: %d",
|
||||
tags[seltag].mwfact,
|
||||
tags[seltag].nmaster);
|
||||
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,
|
||||
0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord);
|
||||
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,
|
||||
0, conf.tagbordwidth, infobar->geo.height, conf.colors.tagbord);
|
||||
|
||||
/* Draw status text */
|
||||
draw_text(infobar.bar->dr,
|
||||
MAXW - textw(infobar.statustext),
|
||||
draw_text(infobar->bar->dr,
|
||||
MAXW - textw(infobar->statustext),
|
||||
font->height,
|
||||
conf.colors.text,
|
||||
conf.colors.bar, 0, infobar.statustext);
|
||||
conf.colors.bar, 0, infobar->statustext);
|
||||
|
||||
/* Bar border */
|
||||
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);
|
||||
draw_rectangle(infobar.bar->dr, MAXW - textw(infobar.statustext) - 5,
|
||||
0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord);
|
||||
draw_rectangle(infobar->bar->dr, MAXW - textw(infobar->statustext) - 5,
|
||||
0, conf.tagbordwidth, infobar->geo.height, conf.colors.tagbord);
|
||||
}
|
||||
|
||||
/* Refresh the bar */
|
||||
bar_refresh(infobar.bar);
|
||||
bar_refresh(infobar->bar);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -118,44 +118,45 @@ infobar_draw_layout(void)
|
||||
strcpy(symbol, conf.tile_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_resize(infobar.layout_switch, textw(symbol) + PAD, infobar.geo.height);
|
||||
draw_text(infobar.layout_switch->dr, PAD/2, font->height,
|
||||
bar_move(infobar->layout_switch, px, 0);
|
||||
bar_resize(infobar->layout_switch, textw(symbol) + PAD, infobar->geo.height);
|
||||
draw_text(infobar->layout_switch->dr, PAD/2, font->height,
|
||||
conf.colors.layout_fg,
|
||||
conf.colors.layout_bg,
|
||||
PAD, symbol);
|
||||
width += textw(symbol) + PAD;
|
||||
bar_refresh(infobar.layout_switch);
|
||||
bar_refresh(infobar->layout_switch);
|
||||
|
||||
if(tags[seltag].layout.func != freelayout
|
||||
&& tags[seltag].layout.func != maxlayout)
|
||||
{
|
||||
bar_map(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_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,
|
||||
bar_map(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_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,
|
||||
conf.colors.layout_fg,
|
||||
conf.colors.layout_bg,
|
||||
PAD, tags[seltag].layout.symbol);
|
||||
width += textw(tags[seltag].layout.symbol) + PAD * 1.5;
|
||||
|
||||
bar_refresh(infobar.layout_type_switch);
|
||||
bar_refresh(infobar->layout_type_switch);
|
||||
}
|
||||
else
|
||||
bar_unmap(infobar.layout_type_switch);
|
||||
bar_unmap(infobar->layout_type_switch);
|
||||
|
||||
/* Draw right separation */
|
||||
infobar.lastsep = width + PAD / 2;
|
||||
draw_rectangle(infobar.bar->dr, infobar.lastsep, 0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord);
|
||||
infobar->lastsep = width + PAD / 2;
|
||||
draw_rectangle(infobar->bar->dr, infobar->lastsep, 0,
|
||||
conf.tagbordwidth, infobar->geo.height, conf.colors.tagbord);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
infobar_draw_taglist(Drawable dr)
|
||||
infobar_draw_taglist(void)
|
||||
{
|
||||
int i;
|
||||
char buf[conf.ntag][256];
|
||||
@ -167,17 +168,16 @@ infobar_draw_taglist(Drawable dr)
|
||||
/* Make the tags string */
|
||||
ITOA(p, client_pertag(i+1));
|
||||
sprintf(buf[i], "%s<%s>", tags[i+1].name, (client_pertag(i+1)) ? p : "");
|
||||
|
||||
/* 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.tagselbg : conf.colors.bar), PAD, buf[i]);
|
||||
|
||||
/* Draw the tag separation */
|
||||
draw_rectangle(dr, taglen[i] + textw(buf[i]) + PAD/2,
|
||||
0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord);
|
||||
draw_rectangle(infobar->bar->dr, taglen[i] + textw(buf[i]) + PAD/2,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -189,12 +189,12 @@ uicb_infobar_togglepos(uicb_t cmd)
|
||||
{
|
||||
conf.bartop = !conf.bartop;
|
||||
if(conf.bartop)
|
||||
sgeo.y = infobar.geo.height + TBARH;
|
||||
sgeo.y = infobar->geo.height + TBARH;
|
||||
else
|
||||
sgeo.y = TBARH;
|
||||
|
||||
infobar.geo.y = (conf.bartop) ? 0 : MAXH - infobar.geo.height;
|
||||
bar_move(infobar.bar, 0, infobar.geo.y);
|
||||
infobar->geo.y = (conf.bartop) ? 0 : MAXH - infobar->geo.height;
|
||||
bar_move(infobar->bar, 0, infobar->geo.y);
|
||||
infobar_draw();
|
||||
arrange();
|
||||
|
||||
|
||||
12
src/init.c
12
src/init.c
@ -36,17 +36,17 @@ void
|
||||
init(void)
|
||||
{
|
||||
/* First init */
|
||||
gc = DefaultGC (dpy, screen);
|
||||
screen = DefaultScreen (dpy);
|
||||
|
||||
gc = DefaultGC(dpy, screen);
|
||||
screen = DefaultScreen(dpy);
|
||||
init_font();
|
||||
init_cursor();
|
||||
init_key();
|
||||
init_atom();
|
||||
init_root();
|
||||
infobar_init(&infobar);
|
||||
infobar_init();
|
||||
init_geometry();
|
||||
grabkeys();
|
||||
XSetErrorHandler(errorhandler);
|
||||
|
||||
/* Warning about font */
|
||||
if(TBARH + BORDH < font->height)
|
||||
@ -133,7 +133,7 @@ void
|
||||
init_geometry(void)
|
||||
{
|
||||
sgeo.x = BORDH;
|
||||
sgeo.y = infobar.geo.height;
|
||||
sgeo.y = infobar->geo.height;
|
||||
|
||||
if(conf.bartop)
|
||||
sgeo.y += TBARH;
|
||||
@ -141,7 +141,7 @@ init_geometry(void)
|
||||
sgeo.y = TBARH;
|
||||
|
||||
sgeo.width = MAXW;
|
||||
sgeo.height = MAXH - infobar.geo.height - TBARH;
|
||||
sgeo.height = MAXH - infobar->geo.height - TBARH;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ mouse_move(Client *c)
|
||||
client_moveresize(c, geo, True);
|
||||
}
|
||||
else if(ev.type == Expose)
|
||||
expose(ev);
|
||||
expose(&ev.xexpose);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -107,12 +107,12 @@ mouse_resize(Client *c)
|
||||
mx = sgeo.width - (tags[seltag].mwfact * sgeo.width);
|
||||
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);
|
||||
}
|
||||
else if(tags[seltag].layout.func == tile_bottom)
|
||||
{
|
||||
mx = event.xmotion.x_root;
|
||||
mx = ev.xmotion.x_root;
|
||||
my = tags[seltag].mwfact * sgeo.height;
|
||||
}
|
||||
XWarpPointer(dpy, None, root, 0, 0, 0, 0, mx, my);
|
||||
@ -166,7 +166,7 @@ mouse_resize(Client *c)
|
||||
client_moveresize(c, geo, True);
|
||||
}
|
||||
else if(ev.type == Expose)
|
||||
expose(ev);
|
||||
expose(&ev.xexpose);
|
||||
|
||||
}
|
||||
|
||||
|
||||
91
src/wmfs.c
91
src/wmfs.c
@ -32,39 +32,28 @@
|
||||
|
||||
#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
|
||||
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);
|
||||
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->request_code,
|
||||
event->minor_code,
|
||||
event->resourceid);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -75,15 +64,6 @@ errorhandlerdummy(Display *d, XErrorEvent *event)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Only for check if another WM is already running */
|
||||
int
|
||||
errorhandlerstart(Display *d, XErrorEvent *event)
|
||||
{
|
||||
owm = True;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
quit(void)
|
||||
{
|
||||
@ -92,9 +72,10 @@ quit(void)
|
||||
XFreeCursor(dpy, cursor[CurNormal]);
|
||||
XFreeCursor(dpy, cursor[CurMove]);
|
||||
XFreeCursor(dpy, cursor[CurResize]);
|
||||
bar_delete(infobar.bar);
|
||||
bar_delete(infobar.layout_switch);
|
||||
bar_delete(infobar.layout_type_switch);
|
||||
bar_delete(infobar->bar);
|
||||
bar_delete(infobar->layout_switch);
|
||||
bar_delete(infobar->layout_type_switch);
|
||||
efree(infobar);
|
||||
efree(keys);
|
||||
efree(conf.titlebar.mouse);
|
||||
efree(conf.client.mouse);
|
||||
@ -108,12 +89,13 @@ void
|
||||
mainloop(void)
|
||||
{
|
||||
fd_set fd;
|
||||
char sbuf[sizeof infobar.statustext], *p;
|
||||
char sbuf[sizeof infobar->statustext], *p;
|
||||
int len, r, offset = 0;
|
||||
Bool readstdin = True;
|
||||
XEvent ev;
|
||||
|
||||
len = sizeof infobar.statustext - 1;
|
||||
sbuf[len] = infobar.statustext[len] = '\0';
|
||||
len = sizeof infobar->statustext - 1;
|
||||
sbuf[len] = infobar->statustext[len] = '\0';
|
||||
|
||||
while(!exiting)
|
||||
{
|
||||
@ -132,7 +114,7 @@ mainloop(void)
|
||||
if(*p == '\n')
|
||||
{
|
||||
*p = '\0';
|
||||
strncpy(infobar.statustext, sbuf, len);
|
||||
strncpy(infobar->statustext, sbuf, len);
|
||||
p += r - 1;
|
||||
for(r = 0; *(p - r) && *(p - r) != '\n'; ++r);
|
||||
offset = r;
|
||||
@ -144,15 +126,15 @@ mainloop(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(infobar.statustext, sbuf, strlen(sbuf));
|
||||
strncpy(infobar->statustext, sbuf, strlen(sbuf));
|
||||
readstdin = False;
|
||||
}
|
||||
infobar_draw();
|
||||
}
|
||||
while(XPending(dpy))
|
||||
{
|
||||
XNextEvent(dpy, &event);
|
||||
getevent();
|
||||
XNextEvent(dpy, &ev);
|
||||
getevent(ev);
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,24 +154,20 @@ void
|
||||
scan(void)
|
||||
{
|
||||
uint i, num;
|
||||
Window *wins, d1, d2;
|
||||
Window *wins = NULL, d;
|
||||
XWindowAttributes wa;
|
||||
|
||||
wins = NULL;
|
||||
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num))
|
||||
{
|
||||
if(XQueryTree(dpy, root, &d, &d, &wins, &num))
|
||||
for(i = 0; i < num; i++)
|
||||
{
|
||||
if(!XGetWindowAttributes(dpy, wins[i], &wa))
|
||||
continue;
|
||||
if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
|
||||
continue;
|
||||
if(wa.map_state == IsViewable)
|
||||
client_manage(wins[i], &wa);
|
||||
if(wins[i] && wins[i] != infobar->bar->win)
|
||||
{
|
||||
XGetWindowAttributes(dpy, wins[i], &wa);
|
||||
if(wa.override_redirect && wa.map_state == IsViewable)
|
||||
client_manage(wins[i], &wa);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(wins)
|
||||
XFree(wins);
|
||||
XFree(wins);
|
||||
|
||||
arrange();
|
||||
|
||||
@ -244,8 +222,9 @@ main(int argc, char **argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Check if an other WM is already running */
|
||||
checkotherwm();
|
||||
/* Check if an other WM is already running; set the error handler */
|
||||
XSetErrorHandler(errorhandler);
|
||||
XSetErrorHandler(errorhandlerdummy);
|
||||
|
||||
/* Let's Go ! */
|
||||
init_conf();
|
||||
|
||||
43
src/wmfs.h
43
src/wmfs.h
@ -88,10 +88,10 @@ void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color);
|
||||
ushort textw(const char *text);
|
||||
|
||||
/* infobar.c */
|
||||
void infobar_init(InfoBar *ib);
|
||||
void infobar_init(void);
|
||||
void infobar_draw(void);
|
||||
void infobar_draw_layout(void);
|
||||
void infobar_draw_taglist(Drawable dr);
|
||||
void infobar_draw_taglist(void);
|
||||
void uicb_infobar_togglepos(uicb_t cmd);
|
||||
|
||||
/* client.c */
|
||||
@ -99,7 +99,12 @@ int client_pertag(int tag);
|
||||
void client_attach(Client *c);
|
||||
void client_detach(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_hide(Client *c);
|
||||
Bool ishide(Client *c);
|
||||
@ -119,29 +124,25 @@ void uicb_client_kill(uicb_t);
|
||||
/* frame.c */
|
||||
void frame_create(Client *c);
|
||||
void frame_moveresize(Client *c, XRectangle geo);
|
||||
Client* frame_get(Window w);
|
||||
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 */
|
||||
void init_conf(void);
|
||||
|
||||
/* event.c */
|
||||
void buttonpress(XEvent ev);
|
||||
void configurerequest(XEvent ev);
|
||||
void destroynotify(XEvent ev);
|
||||
void enternotify(XEvent ev);
|
||||
void expose(XEvent ev);
|
||||
void focusin(XEvent ev);
|
||||
void buttonpress(XButtonEvent *ev);
|
||||
void configurerequest(XConfigureRequestEvent *ev);
|
||||
void destroynotify(XDestroyWindowEvent *ev);
|
||||
void enternotify(XCrossingEvent *ev);
|
||||
void expose(XExposeEvent *ev);
|
||||
void focusin(XFocusChangeEvent *ev);
|
||||
void grabkeys(void);
|
||||
void keypress(XEvent ev);
|
||||
void mapnotify(XEvent ev);
|
||||
void maprequest(XEvent ev);
|
||||
void propertynotify(XEvent ev);
|
||||
void unmapnotify(XEvent ev);
|
||||
void getevent(void);
|
||||
void keypress(XKeyPressedEvent *ev);
|
||||
void mapnotify(XMappingEvent *ev);
|
||||
void maprequest(XMapRequestEvent *ev);
|
||||
void propertynotify(XPropertyEvent *ev);
|
||||
void unmapnotify(XUnmapEvent *ev);
|
||||
void getevent(XEvent ev);
|
||||
|
||||
/* mouse.c */
|
||||
void mouse_move(Client *c);
|
||||
@ -210,7 +211,6 @@ void uicb_quit(uicb_t);
|
||||
|
||||
/* Principal */
|
||||
Display *dpy;
|
||||
XEvent event;
|
||||
GC gc;
|
||||
Window root;
|
||||
XRectangle sgeo;
|
||||
@ -218,7 +218,6 @@ int screen;
|
||||
Conf conf;
|
||||
Key *keys;
|
||||
Bool exiting;
|
||||
Bool owm;
|
||||
|
||||
/* Atoms / Cursors */
|
||||
Atom wm_atom[WMLast];
|
||||
@ -229,7 +228,7 @@ Cursor cursor[CurLast];
|
||||
XftFont *font;
|
||||
|
||||
/* InfoBar */
|
||||
InfoBar infobar;
|
||||
InfoBar *infobar;
|
||||
Tag tags[MAXTAG];
|
||||
int taglen[MAXTAG];
|
||||
int seltag;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user