[ALL] make event.c , replace local.h -> wmfs.h

This commit is contained in:
Martin Duquesnoy 2008-09-13 12:44:43 +02:00
parent e98cfee8da
commit a2868e9dda
5 changed files with 355 additions and 309 deletions

View File

@ -16,7 +16,8 @@ project(${PROJECT_NAME} C)
# Definition of the wmfs source # Definition of the wmfs source
set(wmfs_src set(wmfs_src
wmfs.c wmfs.c
config.c) config.c
event.c)
# Set the executable from the wmfs_src # Set the executable from the wmfs_src
add_executable(wmfs ${wmfs_src}) add_executable(wmfs ${wmfs_src})

View File

@ -2,7 +2,7 @@
#include <confuse.h> #include <confuse.h>
#include <string.h> #include <string.h>
#include "local.h" #include "wmfs.h"
#include "config.h" #include "config.h"
#define FILE_NAME ".wmfsrc" #define FILE_NAME ".wmfsrc"
@ -287,5 +287,3 @@ init_conf(void) {
cfg_free(cfg); cfg_free(cfg);
} }

258
event.c Normal file
View File

@ -0,0 +1,258 @@
#include "wmfs.h"
/* BUTTONPRESS */
void
buttonpress(XEvent ev) {
Client *c;
int i, j;
char s[6];
/* Tbar'n'Button */
if(conf.ttbarheight) {
if((c = gettbar(ev.xbutton.window))) {
raiseclient(c);
if(ev.xbutton.button == Button1)
mouseaction(c, ev.xbutton.x_root, ev.xbutton.y_root, Move); /* type 0 for move */
else if(ev.xbutton.button == Button2)
tile_switch(NULL);
else if(ev.xbutton.button == Button3)
mouseaction(c, ev.xbutton.x_root, ev.xbutton.y_root, Resize); /* type 1 for resize */
} else if((c = getbutton(ev.xbutton.window))) {
if(ev.xbutton.button == Button1)
killclient(NULL);
else if(ev.xbutton.button == Button3)
togglemax(NULL);
}
}
/* Window */
if((c = getclient(ev.xbutton.window))) {
raiseclient(c);
if(ev.xbutton.button == Button1)
mouseaction(c, ev.xbutton.x_root, ev.xbutton.y_root, Move); /* type 0 for move */
else if(ev.xbutton.button == Button2)
togglemax(NULL);
else if(ev.xbutton.button == Button3)
mouseaction(c, ev.xbutton.x_root, ev.xbutton.y_root, Resize); /* type 1 for resize */
}
/* Bar */
/* for tag click */
else if(ev.xbutton.window == bar) {
for(i = 0; i < conf.ntag + 1; ++i) {
if(ev.xbutton.x > taglen[i-1]
&& ev.xbutton.x < taglen[i]) {
ITOA(s, i);
if(ev.xbutton.button == Button1)
tag(s);
else if(ev.xbutton.button == Button3)
tagtransfert(s);
}
}
/* tag switch with scroll */
if(ev.xbutton.x < taglen[conf.ntag]) {
if(ev.xbutton.button == Button4)
tag("+1");
else if(ev.xbutton.button == Button5)
tag("-1");
}
/* layout switch */
if(ev.xbutton.x >= taglen[conf.ntag]
&& ev.xbutton.x < taglen[conf.ntag] +
(strlen((getlayoutsym(layout[seltag])))*fonty+3)) {
if(ev.xbutton.button == Button1
|| ev.xbutton.button == Button4)
layoutswitch("+");
else if(ev.xbutton.button == Button3
|| ev.xbutton.button == Button5)
layoutswitch("-");
}
}
/* Root */
/* tag switch */
else if(ev.xbutton.window == root) {
if(ev.xbutton.button == Button4)
tag("+1");
else if(ev.xbutton.button == Button5)
tag("-1");
}
/* Bar Button */
for(i=0; i<conf.nbutton ; ++i)
for(j=0; j<conf.barbutton[i].nmousesec; ++j)
if(ev.xbutton.window == conf.barbutton[i].win
&& ev.xbutton.button == conf.barbutton[i].mouse[j])
if(conf.barbutton[i].func[j])
conf.barbutton[i].func[j](conf.barbutton[i].cmd[j]);
return;
}
/* CONFIGUREREQUEST */
void
configurerequest(XEvent ev) {
Client *c;
XWindowChanges wc;
if((c = getclient(ev.xconfigurerequest.window)))
if(c->tile)
return;
wc.x = ev.xconfigurerequest.x;
wc.y = ev.xconfigurerequest.y;
wc.width = ev.xconfigurerequest.width;
wc.height = ev.xconfigurerequest.height;
wc.border_width = ev.xconfigurerequest.border_width;
wc.sibling = ev.xconfigurerequest.above;
wc.stack_mode = ev.xconfigurerequest.detail;
XConfigureWindow(dpy, ev.xconfigurerequest.window,
ev.xconfigurerequest.value_mask, &wc);
if((c = getclient(ev.xconfigurerequest.window))) {
if(wc.y < mw && wc.x < mh) {
c->free = True;
c->max = False;
c->tile = False;
moveresize(c, wc.x, wc.y, wc.width, wc.height, 1);
arrange();
}
}
return;
}
/* DESTROYNOTIFY */
void
destroynotify(XEvent ev) {
Client *c;
if((c = getclient(ev.xdestroywindow.window)))
unmanage(c);
}
/* ENTERNOTIFY */
void
enternotify(XEvent ev) {
Client *c;
if(ev.xcrossing.mode != NotifyNormal
|| ev.xcrossing.detail == NotifyInferior)
return;
if((c = getclient(ev.xcrossing.window))
|| (c = gettbar(ev.xcrossing.window)))
if(c->win != bar)
focus(c);
return;
}
/* FOCUSIN */
void
focusin(XEvent ev) {
if(sel && ev.xfocus.window != sel->win)
XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
return;
}
/* KEYPRESS */
void
keypress(XEvent ev) {
unsigned int i;
KeySym keysym;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev.xkey.keycode, 0);
for(i = 0; i < conf.nkeybind; i++)
if(keysym == keys[i].keysym
&& (keys[i].mod & ~(numlockmask | LockMask)) ==
(ev.xkey.state & ~(numlockmask | LockMask))
&& keys[i].func)
{
keys[i].func(keys[i].cmd);
updateall();
}
return;
}
/* MAPPINGNOTIFY */
void
mapnotify(XEvent ev) {
if(ev.xmapping.request == MappingKeyboard)
grabkeys();
return;
}
/* MAPREQUEST */
void
maprequest(XEvent ev) {
XWindowAttributes at;
if(!XGetWindowAttributes(dpy, ev.xmaprequest.window, &at)) return;
if(at.override_redirect) return;
if(!getclient(ev.xmaprequest.window))
manage(ev.xmaprequest.window, &at);
return;
}
/* PROPERTYNOTIFY */
void
propertynotify(XEvent ev) {
Client *c;
Window trans;
if(event.xproperty.state == PropertyDelete)
return;
if((c = getclient(event.xproperty.window))) {
switch(event.xproperty.atom) {
default: break;
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &trans);
if((c->tile || c->max) && (c->hint = (getclient(trans) != NULL)))
arrange();
break;
case XA_WM_NORMAL_HINTS:
setsizehints(c);
break;
}
if(ev.xproperty.atom == XA_WM_NAME
|| ev.xproperty.atom == net_atom[NetWMName])
updateall();
}
return;
}
/* UNMAPNOTIFY */
void
unmapnotify(XEvent ev) {
Client *c;
if((c = getclient(ev.xunmap.window)))
if(!c->hide)
unmanage(c);
return;
}
/* Handle */
void
getevent(void) {
struct timeval tv;
if(QLength(dpy) > 0)
XNextEvent(dpy, &event);
else {
XFlush(dpy);
FD_ZERO(&fd);
FD_SET(ConnectionNumber(dpy), &fd);
event.type = LASTEvent;
tv.tv_sec = 60;
tv.tv_usec = 0;
if(select(FD_SETSIZE, &fd, NULL, NULL, &tv) > 0)
XNextEvent(dpy, &event);
}
switch (event.type)
{
case ButtonPress: buttonpress(event); break;
case ConfigureRequest: configurerequest(event); break;
case DestroyNotify: destroynotify(event); break;
case EnterNotify: enternotify(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;
}
return;
}

321
wmfs.c
View File

@ -24,10 +24,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "local.h" #include "wmfs.h"
unsigned int numlockmask = 0;
int taglen[MAXTAG] = {3};
void void
arrange(void) { arrange(void) {
@ -53,99 +50,6 @@ attach(Client *c) {
return; return;
} }
/* will be ameliorated (with conf) */
void
buttonpress(XEvent *event) {
Client *c;
int i, j;
char s[6];
XButtonPressedEvent *ev = &event->xbutton;
/* Tbar'n'Button */
if(conf.ttbarheight) {
if((c = gettbar(ev->window))) {
raiseclient(c);
if(ev->button == Button1)
mouseaction(c, ev->x_root, ev->y_root, Move); /* type 0 for move */
else if(ev->button == Button2)
tile_switch(NULL);
else if(ev->button == Button3)
mouseaction(c, ev->x_root, ev->y_root, Resize); /* type 1 for resize */
} else if((c = getbutton(ev->window))) {
if(ev->button == Button1)
killclient(NULL);
else if(ev->button == Button3)
togglemax(NULL);
}
}
/* Window */
if((c = getclient(ev->window))) {
raiseclient(c);
if(ev->button == Button1)
mouseaction(c, ev->x_root, ev->y_root, Move); /* type 0 for move */
else if(ev->button == Button2)
togglemax(NULL);
else if(ev->button == Button3)
mouseaction(c, ev->x_root, ev->y_root, Resize); /* type 1 for resize */
}
/* Bar */
/* for tag click */
else if(ev->window == bar) {
for(i = 0; i < conf.ntag + 1; ++i) {
if(ev->x > taglen[i-1]
&& ev->x < taglen[i]) {
ITOA(s, i);
if(ev->button == Button1)
tag(s);
else if(ev->button == Button3)
tagtransfert(s);
}
}
/* tag switch with scroll */
if(ev->x < taglen[conf.ntag]) {
if(ev->button == Button4)
tag("+1");
else if(ev->button == Button5)
tag("-1");
}
/* layout switch */
if(ev->x >= taglen[conf.ntag]
&& ev->x < taglen[conf.ntag] +
(strlen((getlayoutsym(layout[seltag])))*fonty+3)) {
if(ev->button == Button1
|| ev->button == Button4)
layoutswitch("+");
else if(ev->button == Button3
|| ev->button == Button5)
layoutswitch("-");
}
}
/* Root */
/* tag switch */
else if(ev->window == root) {
if(ev->button == Button4)
tag("+1");
else if(ev->button == Button5)
tag("-1");
}
/* Bar Button */
for(i=0; i<conf.nbutton ; ++i)
for(j=0; j<conf.barbutton[i].nmousesec; ++j)
if(ev->window == conf.barbutton[i].win
&& ev->button == conf.barbutton[i].mouse[j])
if(conf.barbutton[i].func[j])
conf.barbutton[i].func[j](conf.barbutton[i].cmd[j]);
}
int
clienthintpertag(int tag) {
Client *c;
int i = 0;
for(c = clients; c; c = c->next)
if(c->tag == tag && c->hint)
++i;
return i;
}
int int
clientpertag(int tag) { clientpertag(int tag) {
@ -157,33 +61,6 @@ clientpertag(int tag) {
return i; return i;
} }
void
configurerequest(XEvent event) {
Client *c;
XWindowChanges wc;
if((c = getclient(event.xconfigurerequest.window)))
if(c->tile)
return;
wc.x = event.xconfigurerequest.x;
wc.y = event.xconfigurerequest.y;
wc.width = event.xconfigurerequest.width;
wc.height = event.xconfigurerequest.height;
wc.border_width = event.xconfigurerequest.border_width;
wc.sibling = event.xconfigurerequest.above;
wc.stack_mode = event.xconfigurerequest.detail;
XConfigureWindow(dpy, event.xconfigurerequest.window,
event.xconfigurerequest.value_mask, &wc);
if((c = getclient(event.xconfigurerequest.window))) {
if(wc.y < mw && wc.x < mh) {
c->free = True;
c->max = False;
c->tile = False;
moveresize(c, wc.x, wc.y, wc.width, wc.height, 1);
arrange();
}
}
}
void void
detach(Client *c) { detach(Client *c) {
if(c->prev) c->prev->next = c->next; if(c->prev) c->prev->next = c->next;
@ -213,6 +90,7 @@ errorhandler(Display *d, XErrorEvent *event) {
return(1); return(1);
} }
/* for no-important error */
int int
errorhandlerdummy(Display *d, XErrorEvent *event) { errorhandlerdummy(Display *d, XErrorEvent *event) {
return 0; return 0;
@ -293,21 +171,6 @@ getlayoutsym(int l) {
return t; return t;
} }
void
getstatuscmd(char *cmd, char *buf, size_t bufsize) {
int i;
if(!cmd || !buf || !bufsize)
return;
FILE *f = popen(cmd, "r");
fgets(buf, bufsize, f);
for(i = 0; i< bufsize; ++i)
if(buf[i] == '\n')
buf[i] = '\0';
fclose(f);
return;
}
Client* Client*
gettbar(Window w) { gettbar(Window w) {
Client *c; Client *c;
@ -315,92 +178,6 @@ gettbar(Window w) {
return c; return c;
} }
void
getevent(void) {
XWindowAttributes at;
Window trans;
Client *c;
struct timeval tv;
if(QLength(dpy) > 0)
XNextEvent(dpy, &event);
else {
XFlush(dpy);
FD_ZERO(&fd);
FD_SET(ConnectionNumber(dpy), &fd);
event.type = LASTEvent;
tv.tv_sec = 1;
tv.tv_usec = 0;
if(select(FD_SETSIZE, &fd, NULL, NULL, &tv) > 0)
XNextEvent(dpy, &event);
}
switch (event.type) {
case EnterNotify:
if(event.xcrossing.mode != NotifyNormal
|| event.xcrossing.detail == NotifyInferior)
return;
if((c = getclient(event.xcrossing.window))
|| (c = gettbar(event.xcrossing.window)))
if(c->win != bar)
focus(c);
break;
case MapRequest:
if(!XGetWindowAttributes(dpy, event.xmaprequest.window, &at)) return;
if(at.override_redirect) return;
if(!getclient(event.xmaprequest.window))
manage(event.xmaprequest.window, &at);
break;
case MappingNotify: if(event.xmapping.request == MappingKeyboard) grabkeys(); break;
case PropertyNotify:
if(event.xproperty.state == PropertyDelete)
return;
if((c = getclient(event.xproperty.window))) {
switch(event.xproperty.atom) {
default: break;
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &trans);
if((c->tile || c->max) && (c->hint = (getclient(trans) != NULL)))
arrange();
break;
case XA_WM_NORMAL_HINTS:
setsizehints(c);
break;
}
if(event.xproperty.atom == XA_WM_NAME
|| event.xproperty.atom == net_atom[NetWMName])
updateall();
}
break;
case ConfigureRequest: configurerequest(event); break;
case UnmapNotify:
if((c = getclient(event.xunmap.window)))
if(!c->hide)
unmanage(c);
break;
case DestroyNotify:
if((c = getclient(event.xdestroywindow.window)))
unmanage(c);
break;
case FocusIn:
if(sel && event.xfocus.window != sel->win)
XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
break;
case KeyPress: keypress(&event); break;
case ButtonPress: buttonpress(&event); break;
}
return;
}
void void
grabbuttons(Client *c, Bool focused) { grabbuttons(Client *c, Bool focused) {
int i; int i;
@ -547,7 +324,7 @@ init(void) {
at.cursor = cursor[CurNormal]; at.cursor = cursor[CurNormal];
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &at); XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &at);
/* INIT BAR */ /* INIT BAR / BUTTON */
at.override_redirect = 1; at.override_redirect = 1;
at.background_pixmap = ParentRelative; at.background_pixmap = ParentRelative;
at.event_mask = ButtonPressMask | ExposureMask; at.event_mask = ButtonPressMask | ExposureMask;
@ -556,7 +333,6 @@ init(void) {
CWOverrideRedirect | CWBackPixmap | CWEventMask, &at); CWOverrideRedirect | CWBackPixmap | CWEventMask, &at);
XSetWindowBackground(dpy, bar, conf.colors.bar); XSetWindowBackground(dpy, bar, conf.colors.bar);
XMapRaised(dpy, bar); XMapRaised(dpy, bar);
strncpy(bartext, "WMFS-devel", strlen("WMFS-devel"));
updatebar(); updatebar();
updatebutton(0); updatebutton(0);
@ -577,9 +353,9 @@ ishide(Client *c) {
void void
keymovex(char *cmd) { keymovex(char *cmd) {
int tmp;
if(sel && cmd && !ishide(sel) && !sel->max && !sel->tile) if(sel && cmd && !ishide(sel) && !sel->max && !sel->tile)
{ {
int tmp;
tmp = sel->x + atoi(cmd); tmp = sel->x + atoi(cmd);
moveresize(sel, tmp, sel->y, sel->w, sel->h, 1); moveresize(sel, tmp, sel->y, sel->w, sel->h, 1);
} }
@ -588,39 +364,21 @@ keymovex(char *cmd) {
void void
keymovey(char *cmd) { keymovey(char *cmd) {
int tmp;
if(sel && cmd && !ishide(sel) && !sel->max && !sel->tile) if(sel && cmd && !ishide(sel) && !sel->max && !sel->tile)
{ {
int tmp;
tmp = sel->y + atoi(cmd); tmp = sel->y + atoi(cmd);
moveresize(sel, sel->x, tmp, sel->w, sel->h, 1); moveresize(sel, sel->x, tmp, sel->w, sel->h, 1);
} }
return; return;
} }
void
keypress(XEvent *e) {
unsigned int i;
KeySym keysym;
XKeyEvent *ev;
ev = &e->xkey;
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->state & ~(numlockmask | LockMask))
&& keys[i].func)
{
keys[i].func(keys[i].cmd);
updateall();
}
return;
}
void void
keyresize(char *cmd) { keyresize(char *cmd) {
if(sel && !ishide(sel) && !sel->max && !sel->tile) if(sel && !ishide(sel) && !sel->max && !sel->tile)
{ {
int temph = 0, tempw = 0, modh = 0, modw = 0, tmp = 0; int temph = 0, tempw = 0,
modh = 0, modw = 0, tmp = 0;
switch(cmd[1]) { switch(cmd[1]) {
case 'h': tmp = (cmd[0] == '+') ? 5 : -5; modh = tmp; break; case 'h': tmp = (cmd[0] == '+') ? 5 : -5; modh = tmp; break;
@ -647,7 +405,7 @@ killclient(char *cmd) {
return; return;
/* check is the client can be close /* check is the client can be close
correctly, else i kill with XKillClient */ correctly, else it will be kill with XKillClient */
if(XGetWMProtocols(dpy, sel->win, &a, &n)) if(XGetWMProtocols(dpy, sel->win, &a, &n))
for(i = 0; !r && i < n; i++) for(i = 0; !r && i < n; i++)
if(a[i] == wm_atom[WMDelete]) if(a[i] == wm_atom[WMDelete])
@ -718,6 +476,7 @@ manage(Window w, XWindowAttributes *wa) {
Window trans; Window trans;
Status rettrans; Status rettrans;
XWindowChanges winc; XWindowChanges winc;
XSetWindowAttributes at;
c = emallocz(sizeof(Client)); c = emallocz(sizeof(Client));
c->win = w; c->win = w;
@ -729,25 +488,24 @@ manage(Window w, XWindowAttributes *wa) {
c->tag = seltag; c->tag = seltag;
if(conf.ttbarheight) { if(conf.ttbarheight) {
c->tbar = at.override_redirect = 1;
XCreateSimpleWindow(dpy, root, at.background_pixmap = ParentRelative;
c->x, at.event_mask = ButtonPressMask | ExposureMask;
c->y - conf.ttbarheight,
c->w, c->tbar = XCreateWindow(dpy, root, c->x, c->y - conf.ttbarheight,
conf.ttbarheight, c->w, conf.ttbarheight, 0, DefaultDepth(dpy, screen),
conf.borderheight, CopyFromParent, DefaultVisual(dpy, screen),
conf.colors.bordernormal, CWOverrideRedirect | CWBackPixmap | CWEventMask, &at);
conf.colors.bar); XSetWindowBackground(dpy, c->tbar, conf.colors.bar);
XSelectInput(dpy, c->tbar, ExposureMask | EnterWindowMask); setborder(c->tbar, conf.colors.bordernormal);
c->button =
XCreateSimpleWindow(dpy, root, c->button = XCreateWindow(dpy, root, c->x + c->w - 10, BUTY(c->y),
c->x + c->w - 10, 5, BUTH, 0, DefaultDepth(dpy, screen),
BUTY(c->y), CopyFromParent, DefaultVisual(dpy, screen),
5, CWOverrideRedirect | CWBackPixmap | CWEventMask, &at);
BUTH, XSetWindowBackground(dpy, c->button, conf.colors.borderfocus);
1, XSetWindowBorder(dpy, c->button, conf.colors.bordernormal);
conf.colors.bordernormal, XSetWindowBorderWidth(dpy, c->button, 1);
conf.colors.borderfocus);
} }
XConfigureWindow(dpy, w, CWBorderWidth, &winc); XConfigureWindow(dpy, w, CWBorderWidth, &winc);
@ -768,14 +526,13 @@ manage(Window w, XWindowAttributes *wa) {
raiseclient(c); raiseclient(c);
attach(c); attach(c);
moveresize(c, c->x, c->y, c->w, c->h, 1);
if(c->free) if(c->free)
raiseclient(c); raiseclient(c);
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
mapclient(c); mapclient(c);
arrange(); layoutfunc[seltag]();
return; return;
} }
@ -1246,12 +1003,10 @@ updatebar(void) {
char buf[conf.ntag][100]; char buf[conf.ntag][100];
char p[3]; char p[3];
tm = localtime(&lt); tm = localtime(&lt);
lt = time(NULL); lt = time(NULL);
XClearWindow(dpy, bar); XClearWindow(dpy, bar);
XSetForeground(dpy, gc, conf.colors.text); XSetForeground(dpy, gc, conf.colors.text);
for(i=0; i<conf.ntag; ++i) { for(i=0; i<conf.ntag; ++i) {
@ -1266,7 +1021,6 @@ updatebar(void) {
XSetForeground(dpy, gc, (i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text); XSetForeground(dpy, gc, (i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text);
XDrawString(dpy, bar, gc, taglen[i], fonth, buf[i], strlen(buf[i])); XDrawString(dpy, bar, gc, taglen[i], fonth, buf[i], strlen(buf[i]));
} }
updatebutton(1);
/* Draw layout symbol */ /* Draw layout symbol */
XSetForeground(dpy, gc, conf.colors.tagselfg); XSetForeground(dpy, gc, conf.colors.tagselfg);
@ -1276,7 +1030,6 @@ updatebar(void) {
strlen(getlayoutsym(layout[seltag]))); strlen(getlayoutsym(layout[seltag])));
/* Draw status */ /* Draw status */
sprintf(bartext,"mwfact: %.2f nmaster: %i - %02i:%02i", sprintf(bartext,"mwfact: %.2f nmaster: %i - %02i:%02i",
mwfact[seltag], mwfact[seltag],
nmaster[seltag], nmaster[seltag],
@ -1287,8 +1040,11 @@ updatebar(void) {
XSetForeground(dpy, gc, conf.colors.text); XSetForeground(dpy, gc, conf.colors.text);
XDrawString(dpy, bar, gc, mw - j * fonty, fonth-1 , bartext ,j); XDrawString(dpy, bar, gc, mw - j * fonty, fonth-1 , bartext ,j);
XDrawLine(dpy, bar, gc, mw- j * fonty-5 , 0 , mw - j * fonty-5, barheight); XDrawLine(dpy, bar, gc, mw- j * fonty-5 , 0 , mw - j * fonty-5, barheight);
XSync(dpy, False); XSync(dpy, False);
/* Update Bar Buttons */
updatebutton(1);
return; return;
} }
@ -1325,9 +1081,7 @@ updatebutton(Bool c) {
0, DefaultDepth(dpy, screen), 0, DefaultDepth(dpy, screen),
CopyFromParent, DefaultVisual(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &at); CWOverrideRedirect | CWBackPixmap | CWEventMask, &at);
XSetWindowBackground(dpy, conf.barbutton[i].win, conf.barbutton[i].bg_color); XSetWindowBackground(dpy, conf.barbutton[i].win, conf.barbutton[i].bg_color);
XMapRaised(dpy, conf.barbutton[i].win); XMapRaised(dpy, conf.barbutton[i].win);
XSetForeground(dpy, gc, conf.barbutton[i].fg_color); XSetForeground(dpy, gc, conf.barbutton[i].fg_color);
XDrawString(dpy, conf.barbutton[i].win, gc, 1, fonth_l, conf.barbutton[i].text, p); XDrawString(dpy, conf.barbutton[i].win, gc, 1, fonth_l, conf.barbutton[i].text, p);
@ -1439,12 +1193,19 @@ main(int argc,char **argv) {
} }
} }
if(!dpy) { printf("wmfs: cannot open X server\n"); exit(1); } if(!dpy) {
printf("WMFS: cannot open X server\n");
exit(1);
}
/* Let's Go ! */
init_conf(); init_conf();
init(); init();
scan(); scan();
for(;;) {
while(1) {
updatebar(); updatebar();
getevent(); getevent();
updateall(); updateall();

View File

@ -19,7 +19,7 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "config.h" #include "config.h"
/* DEFINE TYPES */ /* Defines */
#define ButtonMask (ButtonPressMask | ButtonReleaseMask) #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
#define MouseMask (ButtonMask | PointerMotionMask) #define MouseMask (ButtonMask | PointerMotionMask)
#define KeyMask (KeyPressMask | KeyReleaseMask) #define KeyMask (KeyPressMask | KeyReleaseMask)
@ -32,7 +32,10 @@
#define Resize 1 #define Resize 1
#define MAXTAG 36 #define MAXTAG 36
#define NBUTTON 5 #define NBUTTON 5
#define BUTY(y) (y - conf.ttbarheight + 3 + conf.borderheight-1)
#define BUTH (conf.ttbarheight - 6)
/* Client Structure */
typedef struct Client Client; typedef struct Client Client;
struct Client { struct Client {
char *title; /* Client title */ char *title; /* Client title */
@ -49,11 +52,12 @@ struct Client {
Window tbar; /* Titlebar */ Window tbar; /* Titlebar */
Window button; /* Close Button */ Window button; /* Close Button */
Bool max, tile, free; /* Client Info */ Bool max, tile, free; /* Client Info */
Bool hint, hide; /* Client Info² */ Bool hint, hide; /* Client Info² */
Client *next; /* Next client */ Client *next; /* Next client */
Client *prev; /* Previous client */ Client *prev; /* Previous client */
}; };
/* Keybind Structure */
typedef struct { typedef struct {
unsigned long mod; unsigned long mod;
KeySym keysym; KeySym keysym;
@ -61,6 +65,7 @@ typedef struct {
char *cmd; char *cmd;
} Key; } Key;
/* Bar Button */
typedef struct { typedef struct {
char *text; char *text;
Window win; Window win;
@ -73,6 +78,7 @@ typedef struct {
unsigned int mouse[NBUTTON]; unsigned int mouse[NBUTTON];
} BarButton; } BarButton;
/* Tag Structure */
typedef struct { typedef struct {
char *name; char *name;
float mwfact; float mwfact;
@ -80,6 +86,7 @@ typedef struct {
int layout; int layout;
} Tag; } Tag;
/* Configuration structure */
typedef struct { typedef struct {
char *font; char *font;
char *buttonfont; char *buttonfont;
@ -107,18 +114,31 @@ typedef struct {
int nbutton; int nbutton;
} Conf; } Conf;
/* Enum */
enum { CurNormal, CurResize, CurMove, CurInput, CurLast }; enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
enum { WMState, WMProtocols, WMName, WMDelete, WMLast }; enum { WMState, WMProtocols, WMName, WMDelete, WMLast };
enum { NetSupported, NetWMName, NetLast }; enum { NetSupported, NetWMName, NetLast };
enum { Free=0, Tile, Max}; enum { Free = 0, Tile, Max};
/* Functions Prototypes */
/* event.c */
void buttonpress(XEvent ev);
void configurerequest(XEvent ev);
void destroynotify(XEvent ev);
void enternotify(XEvent ev);
void focusin(XEvent ev);
void keypress(XEvent ev);
void mapnotify(XEvent ev);
void maprequest(XEvent ev);
void propertynotify(XEvent ev);
void unmapnotify(XEvent ev);
void getevent(void);
/* wmfs.c */ /* wmfs.c */
void arrange(void); void arrange(void);
void attach(Client *c); void attach(Client *c);
void buttonpress(XEvent *event);
int clienthintpertag(int tag);
int clientpertag(int tag); int clientpertag(int tag);
void configurerequest(XEvent event);
void detach(Client *c); void detach(Client *c);
void *emallocz(unsigned int size); void *emallocz(unsigned int size);
int errorhandler(Display *d, XErrorEvent *event); int errorhandler(Display *d, XErrorEvent *event);
@ -130,7 +150,6 @@ Client* getclient(Window w);
Client* getnext(Client *c); Client* getnext(Client *c);
char* getlayoutsym(int l); char* getlayoutsym(int l);
Client* gettbar(Window w); Client* gettbar(Window w);
void getevent(void);
void grabbuttons(Client *c, Bool focused); void grabbuttons(Client *c, Bool focused);
void grabkeys(void); void grabkeys(void);
void hide(Client *c); void hide(Client *c);
@ -138,7 +157,6 @@ void init(void);
Bool ishide(Client *c); Bool ishide(Client *c);
void keymovex(char *cmd); void keymovex(char *cmd);
void keymovey(char *cmd); void keymovey(char *cmd);
void keypress(XEvent *e);
void keyresize(char *cmd); void keyresize(char *cmd);
void killclient(char *cmd); void killclient(char *cmd);
void layoutswitch(char *cmd); void layoutswitch(char *cmd);
@ -170,40 +188,50 @@ void updateall(void);
void updatetitle(Client *c); void updatetitle(Client *c);
void wswitch(char *cmd); void wswitch(char *cmd);
#define BUTY(y) (y - conf.ttbarheight + 3) /* Variables */
#define BUTH (conf.ttbarheight - 6)
/* Principal */
Display *dpy; Display *dpy;
GC gc;
XEvent event; XEvent event;
XFontStruct *font, *font_b; GC gc;
Conf conf;
int screen;
Window root; Window root;
Window bar; Window bar;
fd_set fd; int screen;
struct tm *tm; int mw, mh;
time_t lt; Conf conf;
Key keys[512]; Key keys[512];
/* Atoms / Cursors */
Atom wm_atom[WMLast]; Atom wm_atom[WMLast];
Atom net_atom[NetLast]; Atom net_atom[NetLast];
Cursor cursor[CurLast]; Cursor cursor[CurLast];
int mw, mh;
int fonth; /* Fonts */
int fonty; XFontStruct *font, *font_b;
int fonth, fonty;
/* Bar / Tags */
Window bar;
int barheight; int barheight;
char bartext[1024];
int seltag; int seltag;
Client *clients; /* First Client */ int taglen[MAXTAG];
Client *sel; /* selected client */
/* Important Client */
Client *clients;
Client *sel;
Client *selbytag[MAXTAG]; Client *selbytag[MAXTAG];
/* layout */ /* Layout/Tile Important variables */
float mwfact[MAXTAG]; float mwfact[MAXTAG];
int nmaster[MAXTAG]; int nmaster[MAXTAG];
int layout[MAXTAG]; int layout[MAXTAG];
void (*layoutfunc[MAXTAG])(void); void (*layoutfunc[MAXTAG])(void);
/**/
char bartext[1024]; /* Other */
unsigned int numlockmask;
fd_set fd;
struct tm *tm;
time_t lt;
#endif /* LOCAL_H */ #endif /* LOCAL_H */