[wmfs.c,.h, event.c] Add XCopyarea for drawing bar & expose event..

This commit is contained in:
Martin Duquesnoy 2008-09-18 19:29:19 +02:00
parent 996d345be7
commit 3913713328
5 changed files with 59 additions and 23 deletions

View File

@ -47,7 +47,8 @@ func_name_list_t func_list[] =
{"tag", tag},
{"tagtransfert", tagtransfert},
{"set_mwfact", set_mwfact},
{"set_nmaster", set_nmaster}
{"set_nmaster", set_nmaster},
{"quit", quit}
};
key_name_list_t key_list[] =

11
event.c
View File

@ -179,6 +179,16 @@ enternotify(XEvent ev)
return;
}
/* EXPOSE */
void
expose(XEvent ev)
{
if(ev.xexpose.count == 0
&& (ev.xexpose.window == bar))
updatebar();
return;
}
/* FOCUSIN */
void
focusin(XEvent ev)
@ -303,6 +313,7 @@ getevent(void)
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;

View File

@ -33,6 +33,8 @@ DEFAULT KEY BINDINGS
Run a terminal
*Alt + q*::
Quit the selected client
*Control-Alt-Shift + q*::
Exit WMFS
*Control + m *::
Toggle maximize the selected client
*Alt + Tab*::

62
wmfs.c
View File

@ -45,6 +45,7 @@ arrange(void)
focus(NULL);
layoutfunc[seltag]();
updatebar();
}
void
@ -358,6 +359,7 @@ init(void)
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &at);
/* INIT BAR / BUTTON */
dr = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), barheight, DefaultDepth(dpy, screen));
at.override_redirect = 1;
at.background_pixmap = ParentRelative;
at.event_mask = ButtonPressMask | ExposureMask;
@ -460,20 +462,21 @@ layoutswitch(char *cmd)
{
switch(layout[seltag])
{
case Free: tile(); break;
case Tile: maxlayout(); break;
case Max: freelayout(); break;
case Free: layoutfunc[seltag] = tile; break;
case Tile: layoutfunc[seltag] = maxlayout; break;
case Max: layoutfunc[seltag] = freelayout; break;
}
}
else if(cmd[0] == '-')
{
switch(layout[seltag])
{
case Free: maxlayout(); break;
case Tile: freelayout(); break;
case Max: tile(); break;
case Free: layoutfunc[seltag] = maxlayout; break;
case Tile: layoutfunc[seltag] = freelayout; break;
case Max: layoutfunc[seltag] = tile; break;
}
}
arrange();
return;
}
@ -694,9 +697,8 @@ moveresize(Client *c, int x, int y, int w, int h, bool r)
c->x = x; c->y = y;
c->w = w; c->h = h;
if((y-conf.ttbarheight) <= barheight)
y = barheight+conf.ttbarheight;
if((y - conf.ttbarheight) <= barheight)
y = barheight+conf.ttbarheight;
XMoveResizeWindow(dpy, c->win, x, y, w ,h);
@ -718,6 +720,12 @@ nexttiled(Client *c)
return c;
}
void
quit(char *cmd) {
exiting = True;
return;
}
void
raiseclient(Client *c)
{
@ -1078,7 +1086,7 @@ updatebar(void)
lt = time(NULL);
XSetForeground(dpy, gc, conf.colors.bar);
XFillRectangle(dpy, bar, gc, 0, 0, mw, barheight);
XFillRectangle(dpy, dr, gc, 0, 0, mw, barheight);
for(i = 0; i < conf.ntag; ++i)
{
@ -1089,19 +1097,19 @@ updatebar(void)
strlen(buf[i]) - strlen(conf.tag[i].name)) + fonty) - 2;
/* Rectangle for the tag background */
XSetForeground(dpy, gc, (i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar);
XFillRectangle(dpy, bar, gc, taglen[i] - 3, 0, (strlen(buf[i])*fonty) -2, barheight);
XFillRectangle(dpy, dr, gc, taglen[i] - 3, 0, (strlen(buf[i])*fonty) -2, barheight);
/* Draw tag */
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, dr, gc, taglen[i], fonth, buf[i], strlen(buf[i]));
}
/* Draw layout symbol */
XSetForeground(dpy, gc, conf.colors.layout_bg);
XFillRectangle(dpy, bar, gc, taglen[conf.ntag] - 5, 0,
XFillRectangle(dpy, dr, gc, taglen[conf.ntag] - 5, 0,
(strlen(getlayoutsym(layout[seltag]))*fonty) + 1, barheight);
XSetForeground(dpy, gc, conf.colors.layout_fg);
XDrawString(dpy, bar, gc, taglen[conf.ntag] - 4,
XDrawString(dpy, dr, gc, taglen[conf.ntag] - 4,
fonth,
getlayoutsym(layout[seltag]),
strlen(getlayoutsym(layout[seltag])));
@ -1115,15 +1123,14 @@ updatebar(void)
j = strlen(bartext);
XSetForeground(dpy, gc, conf.colors.text);
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);
XDrawString(dpy, dr, gc, mw - j * fonty, fonth-1, bartext ,j);
XDrawLine(dpy, dr, gc, mw- j * fonty-5, 0, mw - j * fonty-5, barheight);
XCopyArea(dpy, dr, bar, gc, 0, 0, mw, barheight, 0, 0);
XSync(dpy, False);
/* Update Bar Buttons */
updatebutton(1);
free(p);
XSync(dpy, False);
}
/* if c is 0, you can execute this function for the first time
@ -1305,14 +1312,25 @@ main(int argc,char **argv)
init_conf();
init();
scan();
while(1)
updatebar();
while(!exiting)
{
updatebar();
// updatebar();
getevent();
updateall();
}
/* exiting WMFS :'( */
XFreeFont(dpy, font);
XFreeFont(dpy, font_b);
XUngrabKey(dpy, AnyKey, AnyModifier, root);
XFreeCursor(dpy, cursor[CurNormal]);
XFreeCursor(dpy, cursor[CurMove]);
XFreeCursor(dpy, cursor[CurResize]);
XDestroyWindow(dpy, bar);
XSync(dpy, False);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
XCloseDisplay(dpy);
return 0;
}

4
wmfs.h
View File

@ -191,6 +191,7 @@ 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 keypress(XEvent ev);
void mapnotify(XEvent ev);
@ -234,6 +235,7 @@ void maxlayout(void);
void mouseaction(Client *c, int x, int y, int type);
void moveresize(Client *c, int x, int y, int w, int h, bool r);
Client *nexttiled(Client *c);
void quit(char *cmd);
void raiseclient(Client *c);
void scan(void);
void setborder(Window win, int color);
@ -267,6 +269,7 @@ int screen;
int mw, mh;
Conf conf;
Key keys[1024];
Bool exiting;
/* Atoms / Cursors */
Atom wm_atom[WMLast];
@ -283,6 +286,7 @@ int barheight;
char bartext[1024];
int seltag;
int taglen[MAXTAG];
Drawable dr;
/* Important Client */
Client *clients;