Fix some bugs. Fix the README.

This commit is contained in:
Kris Maglione 2007-03-23 12:30:50 -04:00
parent 2b39ee548b
commit 95a0ca61ce
18 changed files with 205 additions and 225 deletions

94
9menu.c
View File

@ -30,48 +30,44 @@
* Version using libXg: Matty Farrow (some ideas borrowed)
* This code by: David Hogan and Arnold Robbins
*/
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <X11/X.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
#include <X11/keysymdef.h>
#include <X11/keysym.h>
char version[] = "@(#) 9menu version 1.8";
#define nil ((void*)0)
Display *dpy; /* lovely X stuff */
char version[] = "@(#) wmii9menu version 1.8";
/* lovely X stuff */
Display *dpy;
int screen;
Window root;
Window menuwin;
Colormap defcmap;
XColor color;
XFontStruct *font;
GC gc;
unsigned long selbg;
unsigned long selfg;
unsigned long normbg;
unsigned long normfg;
unsigned long border;
char *sfgname = NULL;
char *sbgname = NULL;
char *nfgname = NULL;
char *nbgname = NULL;
char *brcname = NULL;
Colormap defcmap;
XColor color;
XFontStruct *font;
int g_argc; /* for XSetWMProperties to use */
char *sfgname = nil;
char *sbgname = nil;
char *nfgname = nil;
char *nbgname = nil;
char *brcname = nil;
/* for XSetWMProperties to use */
int g_argc;
char **g_argv;
int f_argc; /* for labels read from files */
/* for labels read from files */
int f_argc;
char **f_argv;
char *initial = "";
int cur;
@ -83,7 +79,7 @@ char *fontlist[] = { /* default font list if no -font */
"9x15",
"lucidasanstypewriter-12",
"fixed",
NULL
nil
};
char *progname; /* my name */
@ -117,9 +113,9 @@ int
args(int argc, char **argv)
{
int i;
if (argc == 0 || argv == NULL || argv[0] == '\0')
if (argc == 0 || argv == nil || argv[0] == '\0')
return -1;
for (i = 0; i < argc && argv[i] != NULL; i++) {
for (i = 0; i < argc && argv[i] != nil; i++) {
if (strcmp(argv[i], "-display") == 0)
displayname = argv[++i];
else if (strcmp(argv[i], "-file") == 0)
@ -164,7 +160,7 @@ main(int argc, char **argv)
g_argv = argv;
/* set default label name */
if ((cp = strrchr(argv[0], '/')) == NULL)
if ((cp = strrchr(argv[0], '/')) == nil)
progname = argv[0];
else
progname = ++cp;
@ -176,7 +172,7 @@ main(int argc, char **argv)
numitems = argc - i;
if (numitems <= 0 && filename == NULL)
if (numitems <= 0 && filename == nil)
usage();
if (filename) {
@ -185,7 +181,7 @@ main(int argc, char **argv)
FILE *fp;
fp = fopen(filename, "r");
if (fp == NULL) {
if (fp == nil) {
fprintf(stderr, "%s: couldn't open '%s'\n", progname,
filename);
exit(1);
@ -200,7 +196,7 @@ main(int argc, char **argv)
if (temp[1]) {
*(temp[1]++) = '\0';
s = malloc(strlen(temp[1]) + 1);
if (s == NULL)
if (s == nil)
memory("temporary argument");
strcpy(s, temp[1]);
temp[1] = s;
@ -229,7 +225,7 @@ main(int argc, char **argv)
f_argc += 5;
}
f_argv[nlabels] = malloc(strlen(s) + 1);
if (f_argv[nlabels] == NULL)
if (f_argv[nlabels] == nil)
memory("temporary text");
strcpy(f_argv[nlabels], s);
++nlabels;
@ -238,12 +234,12 @@ main(int argc, char **argv)
labels = (char **) malloc((numitems + nlabels) * sizeof(char *));
commands = (char **) malloc((numitems + nlabels) * sizeof(char *));
if (commands == NULL || labels == NULL)
if (commands == nil || labels == nil)
memory("command and label arrays");
for (j = 0; j < numitems; j++) {
labels[j] = argv[i + j];
if ((cp = strchr(labels[j], ':')) != NULL) {
if ((cp = strchr(labels[j], ':')) != nil) {
*cp++ = '\0';
commands[j] = cp;
} else
@ -258,7 +254,7 @@ main(int argc, char **argv)
*/
for (i = 0; i < nlabels; i++) {
labels[j] = f_argv[i];
if ((cp = strchr(labels[j], ':')) != NULL) {
if ((cp = strchr(labels[j], ':')) != nil) {
*cp++ = '\0';
commands[j] = cp;
} else
@ -270,9 +266,9 @@ main(int argc, char **argv)
numitems += nlabels;
dpy = XOpenDisplay(displayname);
if (dpy == NULL) {
if (dpy == nil) {
fprintf(stderr, "%s: cannot open display", progname);
if (displayname != NULL)
if (displayname != nil)
fprintf(stderr, " %s", displayname);
fprintf(stderr, "\n");
exit(1);
@ -285,35 +281,35 @@ main(int argc, char **argv)
* white = WhitePixel(dpy, screen);
*/
defcmap = DefaultColormap(dpy, screen);
if (sbgname == NULL
if (sbgname == nil
|| XParseColor(dpy, defcmap, sbgname, &color) == 0
|| XAllocColor(dpy, defcmap, &color) == 0)
selbg = BlackPixel(dpy, screen);
else
selbg = color.pixel;
if (sfgname == NULL
if (sfgname == nil
|| XParseColor(dpy, defcmap, sfgname, &color) == 0
|| XAllocColor(dpy, defcmap, &color) == 0)
selfg = WhitePixel(dpy, screen);
else
selfg = color.pixel;
if (nbgname == NULL
if (nbgname == nil
|| XParseColor(dpy, defcmap, nbgname, &color) == 0
|| XAllocColor(dpy, defcmap, &color) == 0)
normbg = selfg;
else
normbg = color.pixel;
if (nfgname == NULL
if (nfgname == nil
|| XParseColor(dpy, defcmap, nfgname, &color) == 0
|| XAllocColor(dpy, defcmap, &color) == 0)
normfg = selbg;
else
normfg = color.pixel;
if (brcname == NULL
if (brcname == nil
|| XParseColor(dpy, defcmap, brcname, &color) == 0
|| XAllocColor(dpy, defcmap, &color) == 0)
border = selbg;
@ -321,23 +317,23 @@ main(int argc, char **argv)
border = color.pixel;
/* try user's font first */
if (fontname != NULL) {
if (fontname != nil) {
font = XLoadQueryFont(dpy, fontname);
if (font == NULL)
if (font == nil)
fprintf(stderr, "%s: warning: can't load font %s\n",
progname, fontname);
}
/* if no user font, try one of our default fonts */
if (font == NULL) {
for (i = 0; fontlist[i] != NULL; i++) {
if (font == nil) {
for (i = 0; fontlist[i] != nil; i++) {
font = XLoadQueryFont(dpy, fontlist[i]);
if (font != NULL)
if (font != nil)
break;
}
}
if (font == NULL) {
if (font == nil) {
fprintf(stderr, "%s: fatal: cannot load a font\n", progname);
exit(1);
}

19
README
View File

@ -1,6 +1,6 @@
Abstract
--------
window manager improved 2 is a dynamic window manager for X11.
window manager improved-improved is a dynamic window manager for X11.
It supports classic and tiled window management with extended
keyboard, mouse, and 9P-based [2] remote control.
It consists of the wmiiwm(1) window manager and the wmiir(1)
@ -11,7 +11,7 @@ Requirements
------------
In order to build wmii you need the Xlib header files and libixp. Further
dependencies are xmessage and dmenu. libixp and dmenu can be obtained from
[1].
[1]. One of plan9port or 9base is also recommended.
Installation
@ -29,23 +29,28 @@ Running wmii
------------
Add the following line to your .xinitrc to start wmii using startx:
exec wmii
until wmii; do
true
done
In order to connect wmii or wmiir to a specific display, make sure that
the DISPLAY environment variable is set correctly, e.g.:
DISPLAY=foo.bar:1 exec wmii
DISPLAY=foo.bar:1 wmii
This will start wmii on display :1 of the host foo.bar.
Configuration
-------------
The configuration of wmii is done by customizing the sh script wmiirc,
The configuration of wmii is done by customizing the rc script rc.wmii.local,
which remotely controls the window manager and handles various events.
Copy the file from PREFIX/etc/wmii-3.5/ (usually /usr/local/etc/wmii-3.5/)
to $HOME/.wmii-3.5/ and edit it to fit your needs.
The main rc.wmii script lives in PREFIX/etc/wmii-3.5/, while rc.wmii.local
goes in $HOME/.wmii-3.5/.
rc.wmii.local should contain a line containing just: '# Overrides'. You must
set your MODKEY before this line, if you wish to change it, and define most
functions after it.
Credits
-------

9
area.c
View File

@ -1,12 +1,11 @@
/* ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* Copyright ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
* See LICENSE file for license details.
*/
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "wmii.h"
static void place_frame(Frame *f);

25
bar.c
View File

@ -1,10 +1,8 @@
/* ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* Copyright ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
* See LICENSE file for license details.
*/
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "wmii.h"
Bar *free_bars = nil;
@ -68,12 +66,13 @@ draw_bar(WMScreen *s) {
Bar *b, *tb, *largest, **pb;
draw_tile(&s->bbrush);
if(!s->lbar && !s->rbar)
if(!s->bar[BarLeft] && !s->bar[BarRight])
goto MapBar;
largest = b = tb = nil;
tw = width = nb = size = 0;
for(b = s->lbar, nb = 2; nb; --nb && (b = s->rbar))
for(; b; b=b->next) {
for(nb = 0; nb < nelem(s->bar); nb++)
for(b = s->bar[nb]; b; b=b->next) {
b->brush.rect.x = b->brush.rect.y = 0;
b->brush.rect.width = def.font.height & ~1;
if(b->text && strlen(b->text))
@ -83,8 +82,8 @@ draw_bar(WMScreen *s) {
}
/* Not enough room. Shrink bars until they all fit */
if(width > s->brect.width) {
for(b = s->lbar, nb = 2; nb; --nb && (b = s->rbar))
for(; b; b = b->next) {
for(nb = 0; nb < nelem(s->bar); nb++)
for(b = s->bar[nb]; b; b=b->next) {
for(pb = &largest; *pb; pb = &(*pb)->smaller)
if((*pb)->brush.rect.width < b->brush.rect.width)
break;
@ -105,11 +104,11 @@ draw_bar(WMScreen *s) {
width += tw * shrink;
tb = nil;
}
for(b = s->lbar, nb = 2; nb; b = s->rbar, nb--)
for(; b; tb = b, b = b->next) {
if(b == s->rbar) {
for(nb = 0; nb < nelem(s->bar); nb++)
for(b = s->bar[nb]; b; tb=b, b=b->next) {
if(b == s->bar[BarRight]) {
b->brush.align = EAST;
s->rbar->brush.rect.width += (s->brect.width - width);
b->brush.rect.width += (s->brect.width - width);
}else
b->brush.align = CENTER;
if(tb)

View File

@ -1,8 +1,7 @@
/* ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* Copyright ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
* See LICENSE file for license details.
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xatom.h>
@ -120,12 +119,11 @@ destroy_client(Client *c) {
XSetErrorHandler(wmii_error_handler);
XUngrabServer(blz.dpy);
flush_masked_events(EnterWindowMask);
flushevents(EnterWindowMask, False);
while(XCheckMaskEvent(blz.dpy, StructureNotifyMask, &ev))
if(ev.type != UnmapNotify || ev.xunmap.window != c->win)
if(handler[ev.type])
handler[ev.type](&ev);
dispatch_event(&ev);
write_event("DestroyClient 0x%x\n", c->win);
free(c);
@ -158,7 +156,7 @@ manage_client(Client *c) {
if(c->sel->view == screen->sel)
focus(c, True);
flush_masked_events(EnterWindowMask);
flushevents(EnterWindowMask, False);
}
Client *
@ -595,11 +593,7 @@ focus(Client *c, Bool restack) {
void
focus_client(Client *c) {
XEvent ev;
while(XCheckMaskEvent(blz.dpy, FocusChangeMask, &ev))
if(handler[ev.xany.type])
handler[ev.xany.type](&ev);
flushevents(FocusChangeMask, True);
if(verbose)
fprintf(stderr, "focus_client(%p) => %s\n", c, (c ? c->name : nil));
@ -614,15 +608,12 @@ focus_client(Client *c) {
XSetInputFocus(blz.dpy, screen->barwin, RevertToParent, CurrentTime);
}
while(XCheckMaskEvent(blz.dpy, FocusChangeMask, &ev))
if(handler[ev.xany.type])
handler[ev.xany.type](&ev);
flushevents(FocusChangeMask, True);
}
void
resize_client(Client *c, XRectangle *r) {
Frame *f;
XEvent ev;
f = c->sel;
resize_frame(f, r);
@ -658,9 +649,7 @@ resize_client(Client *c, XRectangle *r) {
configure_client(c);
}
while(XCheckMaskEvent(blz.dpy, FocusChangeMask|ExposureMask, &ev))
if(handler[ev.xany.type])
handler[ev.xany.type](&ev);
flushevents(FocusChangeMask|ExposureMask, True);
}
void
@ -685,7 +674,7 @@ newcol_client(Client *c, char *arg) {
}
else
return;
flush_masked_events(EnterWindowMask);
flushevents(EnterWindowMask, False);
}
void
@ -789,7 +778,7 @@ send_frame:
swap_frames(f, tf);
arrange_column(a, False);
flush_masked_events(EnterWindowMask);
flushevents(EnterWindowMask, False);
focus_frame(f, True);
update_views();
return nil;
@ -802,7 +791,7 @@ send_area:
else if(to->sel)
swap_frames(f, to->sel);
flush_masked_events(EnterWindowMask);
flushevents(EnterWindowMask, False);
focus_frame(f, True);
update_views();
return nil;

View File

@ -1,11 +1,9 @@
/* ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* Copyright ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
* See LICENSE file for license details.
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <string.h>
#include "wmii.h"
char *

3
draw.c
View File

@ -1,7 +1,6 @@
/* ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wmii.h"

151
event.c
View File

@ -1,38 +1,46 @@
/* ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* Copyright ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
* See LICENSE file for license details.
*/
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <X11/keysym.h>
#include "wmii.h"
#include "printevent.h"
void
dispatch_event(XEvent *e) {
if(handler[e->type])
handler[e->type](e);
}
uint
flush_masked_events(long event_mask) {
flushevents(long event_mask, Bool dispatch) {
XEvent ev;
uint n = 0;
while(XCheckMaskEvent(blz.dpy, event_mask, &ev)) n++;
while(XCheckMaskEvent(blz.dpy, event_mask, &ev)) {
if(dispatch)
dispatch_event(&ev);
n++;
}
return n;
}
static void
buttonrelease(XEvent *e) {
XButtonPressedEvent *ev;
Frame *f;
Bar *b;
XButtonPressedEvent *ev = &e->xbutton;
ev = &e->xbutton;
if(ev->window == screen->barwin) {
for(b=screen->lbar; b; b=b->next)
if(ispointinrect(ev->x, ev->y, &b->brush.rect)) {
write_event("LeftBarClick %d %s\n",
ev->button, b->name);
for(b=screen->bar[BarRight]; b; b=b->next)
if(ptinrect(ev->x, ev->y, &b->brush.rect)) {
write_event("LeftBarClick %d %s\n", ev->button, b->name);
return;
}
for(b=screen->rbar; b; b=b->next)
if(ispointinrect(ev->x, ev->y, &b->brush.rect)) {
write_event("RightBarClick %d %s\n",
ev->button, b->name);
for(b=screen->bar[BarLeft]; b; b=b->next)
if(ptinrect(ev->x, ev->y, &b->brush.rect)) {
write_event("RightBarClick %d %s\n", ev->button, b->name);
return;
}
}
@ -42,13 +50,11 @@ buttonrelease(XEvent *e) {
static void
buttonpress(XEvent *e) {
Frame *f;
Bool inclient;
XButtonPressedEvent *ev;
Frame *f;
ev = &e->xbutton;
if((f = frame_of_win(ev->window))) {
inclient = (ev->subwindow == f->client->win);
if((ev->state & def.mod) == def.mod) {
switch(ev->button) {
case Button1:
@ -59,7 +65,7 @@ buttonpress(XEvent *e) {
break;
case Button3:
do_mouse_resize(f->client, False,
quadofcoord(&f->rect, ev->x_root, ev->y_root));
quadrant(&f->rect, ev->x_root, ev->y_root));
frame_to_top(f);
focus(f->client, True);
break;
@ -70,20 +76,22 @@ buttonpress(XEvent *e) {
if(ev->button == Button1) {
if(frame_to_top(f))
restack_view(f->view);
if(ispointinrect(ev->x, ev->y, &f->grabbox))
if(ptinrect(ev->x, ev->y, &f->grabbox))
do_mouse_resize(f->client, True, CENTER);
else if(!ev->subwindow
&& !ispointinrect(ev->x, ev->y, &f->titlebar))
do_mouse_resize(f->client, False,
quadofcoord(&f->rect, ev->x_root, ev->y_root));
else if(!ev->subwindow && !ptinrect(ev->x, ev->y, &f->titlebar))
do_mouse_resize(f->client, False, quadrant(&f->rect, ev->x_root, ev->y_root));
if(f->client != sel_client())
focus(f->client, True);
}
if(ev->subwindow)
XAllowEvents(blz.dpy, ReplayPointer, ev->time);
else {
/* Ungrab so a menu can receive events before the button is released */
XUngrabPointer(blz.dpy, ev->time);
XSync(blz.dpy, False);
write_event("ClientMouseDown 0x%x %d\n", f->client->win, ev->button);
}
}
@ -93,14 +101,14 @@ buttonpress(XEvent *e) {
static void
configurerequest(XEvent *e) {
XConfigureRequestEvent *ev = &e->xconfigurerequest;
XConfigureRequestEvent *ev;
XWindowChanges wc;
XRectangle *frect;
Client *c;
Frame *f;
ev = &e->xconfigurerequest;
c = client_of_win(ev->window);
if(c) {
f = c->sel;
gravitate_client(c, True);
@ -158,37 +166,36 @@ configurerequest(XEvent *e) {
static void
destroynotify(XEvent *e) {
XDestroyWindowEvent *ev;
Client *c;
XDestroyWindowEvent *ev = &e->xdestroywindow;
ev = &e->xdestroywindow;
if((c = client_of_win(ev->window)))
destroy_client(c);
}
static void
enternotify(XEvent *e) {
XCrossingEvent *ev = &e->xcrossing;
XCrossingEvent *ev;
Client *c;
Frame *f;
ev = &e->xcrossing;
if(ev->mode != NotifyNormal)
return;
if((c = client_of_win(ev->window))) {
if(ev->detail != NotifyInferior) {
if(screen->focus != c) {
if(verbose)
fprintf(stderr, "enter_notify(c) => %s\n", c->name);
if(verbose) fprintf(stderr, "enter_notify(c) => %s\n", c->name);
focus(c, False);
}
set_cursor(c, cursor[CurNormal]);
}else if(verbose)
fprintf(stderr, "enter_notify(c[NotifyInferior]) => %s\n", c->name);
}else if(verbose) fprintf(stderr, "enter_notify(c[NotifyInferior]) => %s\n", c->name);
}
else if((f = frame_of_win(ev->window))) {
if(screen->focus != c) {
if(verbose)
fprintf(stderr, "enter_notify(f) => %s\n", f->client->name);
if(verbose) fprintf(stderr, "enter_notify(f) => %s\n", f->client->name);
if(f->area->floating || !f->collapsed)
focus(f->client, False);
}
@ -202,8 +209,9 @@ enternotify(XEvent *e) {
static void
leavenotify(XEvent *e) {
XCrossingEvent *ev = &e->xcrossing;
XCrossingEvent *ev;
ev = &e->xcrossing;
if((ev->window == blz.root) && !ev->same_screen) {
sel_screen = True;
draw_frames();
@ -223,10 +231,11 @@ print_focus(Client *c, char *to) {
static void
focusin(XEvent *e) {
XFocusChangeEvent *ev;
Client *c, *old;
XEvent me;
XFocusChangeEvent *ev = &e->xfocus;
ev = &e->xfocus;
/* Yes, we're focusing in on nothing, here. */
if(ev->detail == NotifyDetailNone) {
XSetInputFocus(blz.dpy, screen->barwin, RevertToParent, CurrentTime);
@ -240,11 +249,11 @@ focusin(XEvent *e) {
||(ev->detail == NotifyAncestor)))
return;
if((ev->mode == NotifyWhileGrabbed)
&&(screen->hasgrab != &c_magic))
&& (screen->hasgrab != &c_root))
return;
c = client_of_win(ev->window);
old = screen->focus;
c = client_of_win(ev->window);
if(c) {
print_focus(c, c->name);
if(ev->mode == NotifyGrab)
@ -261,15 +270,15 @@ focusin(XEvent *e) {
print_focus(nil, "<nil>");
screen->focus = nil;
}else if(ev->mode == NotifyGrab) {
if(ev->window == blz.root) {
if(ev->window == blz.root)
if(XCheckMaskEvent(blz.dpy, KeyPressMask, &me)) {
screen->hasgrab = &c_magic;
handler[me.xany.type](&me);
/* wmii has grabbed focus */
screen->hasgrab = &c_root;
dispatch_event(&me);
return;
}
}
/* Some unmanaged window has grabbed focus */
if((c = screen->focus)) {
/* Some unmanaged window has focus */
print_focus(&c_magic, "<magic>");
screen->focus = &c_magic;
if(c->sel)
@ -280,9 +289,10 @@ focusin(XEvent *e) {
static void
focusout(XEvent *e) {
XFocusChangeEvent *ev;
Client *c;
XFocusChangeEvent *ev = &e->xfocus;
ev = &e->xfocus;
if(!((ev->detail == NotifyNonlinear)
||(ev->detail == NotifyNonlinearVirtual)))
return;
@ -292,13 +302,13 @@ focusout(XEvent *e) {
c = client_of_win(ev->window);
if(c) {
if((ev->mode == NotifyWhileGrabbed)
&&(screen->hasgrab != &c_magic)) {
&& (screen->hasgrab != &c_root)) {
if((screen->focus)
&& (screen->hasgrab != screen->focus))
screen->hasgrab = screen->focus;
if(screen->hasgrab == c)
return;
}else if(ev->mode != NotifyGrab && ev->window != blz.root) {
}else if(ev->mode != NotifyGrab) {
if(screen->focus == c) {
print_focus(&c_magic, "<magic>");
screen->focus = &c_magic;
@ -310,46 +320,35 @@ focusout(XEvent *e) {
}
}
static void
expose(XEvent *e) {
XExposeEvent *ev = &e->xexpose;
XExposeEvent *ev;
static Frame *f;
ev = &e->xexpose;
if(ev->count == 0) {
if(ev->window == screen->barwin)
draw_bar(screen);
else if((f = frame_of_win(ev->window)) && f->view == screen->sel)
else if((f = frame_of_win(ev->window)))
draw_frame(f);
}
}
static void
keypress(XEvent *e) {
XKeyEvent *ev = &e->xkey;
Frame *f;
KeySym k = 0;
char buf[32];
int n;
XKeyEvent *ev;
ev = &e->xkey;
ev->state &= valid_mask;
if((f = frame_of_win(ev->window))) {
buf[0] = 0;
n = XLookupString(ev, buf, sizeof(buf), &k, 0);
if(IsFunctionKey(k) || IsKeypadKey(k) || IsMiscFunctionKey(k)
|| IsPFKey(k) || IsPrivateKeypadKey(k))
return;
buf[n] = 0;
}
else {
if(ev->window == blz.root)
kpress(blz.root, ev->state, (KeyCode) ev->keycode);
}
}
static void
mappingnotify(XEvent *e) {
XMappingEvent *ev = &e->xmapping;
XMappingEvent *ev;
ev = &e->xmapping;
XRefreshKeyboardMapping(ev);
if(ev->request == MappingKeyboard)
update_keys();
@ -357,9 +356,10 @@ mappingnotify(XEvent *e) {
static void
maprequest(XEvent *e) {
XMapRequestEvent *ev = &e->xmaprequest;
XMapRequestEvent *ev;
static XWindowAttributes wa;
ev = &e->xmaprequest;
if(!XGetWindowAttributes(blz.dpy, ev->window, &wa))
return;
if(wa.override_redirect) {
@ -373,18 +373,20 @@ maprequest(XEvent *e) {
static void
motionnotify(XEvent *e) {
XMotionEvent *ev = &e->xmotion;
XMotionEvent *ev;
Frame *f;
ev = &e->xmotion;
if((f = frame_of_win(ev->window)))
set_frame_cursor(f, ev->x, ev->y);
}
static void
propertynotify(XEvent *e) {
XPropertyEvent *ev = &e->xproperty;
XPropertyEvent *ev;
Client *c;
ev = &e->xproperty;
if(ev->state == PropertyDelete)
return; /* ignore */
if((c = client_of_win(ev->window)))
@ -393,9 +395,10 @@ propertynotify(XEvent *e) {
static void
mapnotify(XEvent *e) {
XMapEvent *ev;
Client *c;
XMapEvent *ev = &e->xmap;
ev = &e->xmap;
if((c = client_of_win(ev->window)))
if(c == sel_client())
focus_client(c);
@ -403,11 +406,12 @@ mapnotify(XEvent *e) {
static void
unmapnotify(XEvent *e) {
XUnmapEvent *ev;
Client *c;
XUnmapEvent *ev = &e->xunmap;
ev = &e->xunmap;
if((c = client_of_win(ev->window)))
if(!c->unmapped--)
if(ev->send_event || (c->unmapped-- == 0))
destroy_client(c);
}
@ -438,8 +442,7 @@ check_x_event(IXPConn *c) {
XNextEvent(blz.dpy, &ev);
if(verbose)
printevent(&ev);
if(handler[ev.type])
handler[ev.type](&ev);
dispatch_event(&ev);
XPending(blz.dpy);
}
}

13
frame.c
View File

@ -1,8 +1,6 @@
/* ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
/* Copyright ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
* See LICENSE file for license details.
*/
#include <stdlib.h>
#include <string.h>
#include "wmii.h"
Frame *
@ -132,12 +130,12 @@ set_frame_cursor(Frame *f, int x, int y) {
XRectangle r;
Cursor cur;
if(!ispointinrect(x, y, &f->titlebar)
&&!ispointinrect(x, y, &f->crect)) {
if(!ptinrect(x, y, &f->titlebar)
&&!ptinrect(x, y, &f->crect)) {
r = f->rect;
r.x = 0;
r.y = 0;
cur = cursor_of_quad(quadofcoord(&r, x, y));
cur = cursor_of_quad(quadrant(&r, x, y));
set_cursor(f->client, cur);
}else
set_cursor(f->client, cursor[CurNormal]);
@ -248,6 +246,9 @@ draw_frame(Frame *f) {
BlitzBrush br = { 0 };
Frame *tf;
if(f->view != screen->sel)
return;
br.blitz = &blz;
br.font = &def.font;
br.drawable = pmap;

9
fs.c
View File

@ -1,9 +1,8 @@
/* ©2006 Kris Maglione <fbsdaemon at gmail dot com>
/* Copyright ©2006 Kris Maglione <fbsdaemon at gmail dot com>
* See LICENSE file for license details.
*/
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@ -238,7 +237,7 @@ message_root(char *message)
srv.running = 0;
else if(!strncmp(message, "exec ", 5)) {
srv.running = 0;
execstr = strdup(&message[5]);
execstr = estrdup(&message[5]);
message += strlen(message);
}
else if(!strncmp(message, "view ", 5))
@ -469,9 +468,9 @@ lookup_file(FileId *parent, char *name)
switch(file->tab.type) {
case FsDBars:
if(!strcmp(file->tab.name, "lbar"))
file->content.bar_p = &screen[0].lbar;
file->content.bar_p = &screen[0].bar[BarLeft];
else
file->content.bar_p = &screen[0].rbar;
file->content.bar_p = &screen[0].bar[BarRight];
break;
case FsFColRules:
file->content.rule = &def.colrules;

6
geom.c
View File

@ -1,16 +1,16 @@
/* ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include "wmii.h"
Bool
ispointinrect(int x, int y, XRectangle * r) {
ptinrect(int x, int y, XRectangle * r) {
return (x >= r->x) && (x < r_east(r))
&& (y >= r->y) && (y < r_south(r));
}
BlitzAlign
quadofcoord(XRectangle *rect, int x, int y) {
quadrant(XRectangle *rect, int x, int y) {
BlitzAlign ret = 0;
x -= rect->x;
y -= rect->y;

3
key.c
View File

@ -1,9 +1,8 @@
/* ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <string.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include "wmii.h"

14
main.c
View File

@ -1,17 +1,14 @@
/* ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* Copyright ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
* See LICENSE file for license details.
*/
#include <X11/Xatom.h>
#include <X11/Xproto.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <errno.h>
#include <fcntl.h>
#include <locale.h>
#include <pwd.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@ -19,8 +16,6 @@
#include <unistd.h>
#include "wmii.h"
#define nelem(ary) (sizeof(ary) / sizeof(*ary))
static const char
version[] = "wmii - " VERSION ", ©2007 Kris Maglione\n";
@ -381,7 +376,7 @@ spawn_command(const char *cmd) {
fatal("Shell is not an absolute path: %s", shell);
/* Run through the user's shell as a login shell */
p = malloc(sizeof(char*) * (strlen(shell) + 2));
p = malloc((strlen(shell) + 2));
sprintf(p, "-%s", strrchr(shell, '/') + 1);
execl(shell, p, "-c", cmd, nil);
@ -502,9 +497,6 @@ main(int argc, char *argv[]) {
screens = emallocz(num_screens * sizeof(*screens));
for(i = 0; i < num_screens; i++) {
s = &screens[i];
s->lbar = nil;
s->rbar = nil;
s->sel = nil;
init_screen(s);
pmap = XCreatePixmap(
/* display */ blz.dpy,

View File

@ -1,9 +1,8 @@
/* ©2006 Kris Maglione <fbsdaemon@gmail.com>
/* Copyright ©2006 Kris Maglione <fbsdaemon@gmail.com>
* See LICENSE file for license details.
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "wmii.h"
enum {
@ -390,7 +389,7 @@ do_mouse_resize(Client *c, Bool grabbox, BlitzAlign align) {
hr_x = screen->rect.width / 2;
hr_y = screen->rect.height / 2;
XWarpPointer(blz.dpy, None, blz.root, 0, 0, 0, 0, hr_x, hr_y);
while(XCheckMaskEvent(blz.dpy, PointerMotionMask, &ev));
flushevents(PointerMotionMask, False);
}

3
rule.c
View File

@ -1,11 +1,10 @@
/*
* ©2006 Anselm R. Garbe <garbeam at gmail dot com>
* Copyright ©2006 Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include "wmii.h"
/* basic rule matching language /regex/ -> value

9
util.c
View File

@ -2,7 +2,6 @@
/* Public domain */
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -30,7 +29,7 @@ fatal(const char *fmt, ...) {
/* Can't malloc */
void
mfatal(char *name, int size) {
mfatal(char *name, uint size) {
const char
couldnot[] = "wmii: fatal: Could not ",
paren[] = "() ",
@ -40,8 +39,8 @@ mfatal(char *name, int size) {
i = sizeof(sizestr);
do {
sizestr[--i] = '0' + (size&8);
size >>= 8;
sizestr[--i] = '0' + (size%10);
size /= 10;
} while(size > 0);
write(1, couldnot, sizeof(couldnot)-1);
@ -49,6 +48,8 @@ mfatal(char *name, int size) {
write(1, paren, sizeof(paren)-1);
write(1, sizestr+i, sizeof(sizestr)-i);
write(1, bytes, sizeof(bytes)-1);
exit(1);
}
void *

8
view.c
View File

@ -1,10 +1,8 @@
/* ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
* Copyright ©2006-2007 Kris Maglione <fbsdaemon@gmail.com>
* See LICENSE file for license details.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "wmii.h"
@ -130,7 +128,7 @@ focus_view(WMScreen *s, View *v) {
draw_frames();
XSync(blz.dpy, False);
XUngrabServer(blz.dpy);
flush_masked_events(EnterWindowMask);
flushevents(EnterWindowMask, False);
}
void

14
wmii.h
View File

@ -11,6 +11,7 @@
#include <ixp.h>
#define nil ((void*)0)
#define nelem(ary) (sizeof(ary) / sizeof(*ary))
/* Types */
#undef uchar
@ -231,9 +232,10 @@ struct {
int colmode;
} def;
enum { BarLeft, BarRight };
struct WMScreen {
Bar *lbar;
Bar *rbar;
Bar *bar[2];
View *sel;
Client *focus;
Client *hasgrab;
@ -248,6 +250,7 @@ Client *client;
View *view;
Key *key;
Client c_magic;
Client c_root;
enum { BUFFER_SIZE = 8092 };
char buffer[BUFFER_SIZE];
@ -350,8 +353,9 @@ uint labelh(BlitzFont *font);
char *parse_colors(char **buf, int *buflen, BlitzColor *col);
/* event.c */
void dispatch_event(XEvent *e);
void check_x_event(IXPConn *c);
uint flush_masked_events(long even_mask);
uint flushevents(long even_mask, Bool dispatch);
/* frame.c */
Frame *create_frame(Client *c, View *v);
@ -384,8 +388,8 @@ void fs_write(P9Req *r);
void write_event(char *format, ...);
/* geom.c */
Bool ispointinrect(int x, int y, XRectangle * r);
BlitzAlign quadofcoord(XRectangle *rect, int x, int y);
Bool ptinrect(int x, int y, XRectangle * r);
BlitzAlign quadrant(XRectangle *rect, int x, int y);
Cursor cursor_of_quad(BlitzAlign align);
int strtorect(XRectangle *r, const char *val);
BlitzAlign get_sticky(XRectangle *src, XRectangle *dst);