fixed several stuff (gridwm gets better and better)

keyboard
Anselm R. Garbe 19 years ago
parent 366d81e313
commit 16c67f32d6
  1. 1
      README
  2. 12
      client.c
  3. 4
      config.h
  4. 87
      event.c
  5. 4
      font.c
  6. 17
      key.c
  7. 2
      menu.c
  8. 13
      util.c
  9. 50
      wm.c
  10. 10
      wm.h

@ -2,6 +2,7 @@ gridwm
------ ------
gridwm is an automatic X11 window manager which arranges all windows in a grid. gridwm is an automatic X11 window manager which arranges all windows in a grid.
One goal is not to exceed 3kSLOC.
Requirements Requirements

@ -51,7 +51,6 @@ create_client(Window w, XWindowAttributes *wa)
c->r[RFloat].height = wa->height; c->r[RFloat].height = wa->height;
c->border = wa->border_width; c->border = wa->border_width;
XSetWindowBorderWidth(dpy, c->win, 0); XSetWindowBorderWidth(dpy, c->win, 0);
c->proto = win_proto(c->win);
XGetTransientForHint(dpy, c->win, &c->trans); XGetTransientForHint(dpy, c->win, &c->trans);
if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags) if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
c->size.flags = PSize; c->size.flags = PSize;
@ -59,7 +58,6 @@ create_client(Window w, XWindowAttributes *wa)
(c->size.flags & PMinSize && c->size.flags & PMaxSize (c->size.flags & PMinSize && c->size.flags & PMaxSize
&& c->size.min_width == c->size.max_width && c->size.min_width == c->size.max_width
&& c->size.min_height == c->size.max_height); && c->size.min_height == c->size.max_height);
XAddToSaveSet(dpy, c->win);
update_client_name(c); update_client_name(c);
twa.override_redirect = 1; twa.override_redirect = 1;
twa.background_pixmap = ParentRelative; twa.background_pixmap = ParentRelative;
@ -87,3 +85,13 @@ manage(Client *c)
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
XFlush(dpy); XFlush(dpy);
} }
Client *
getclient(Window w)
{
Client *c;
for(c = clients; c; c = c->next)
if(c->win == w)
return c;
return NULL;
}

@ -10,4 +10,6 @@
#define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \ #define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \
" `acpi | awk '{print $4}' | sed 's/,//'`" " `acpi | awk '{print $4}' | sed 's/,//'`"
#define KEYS \ #define KEYS \
{ Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn -*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*" }, { Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn '-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*'" }, \
{ Mod1Mask | ShiftMask, XK_q, quit, NULL},

@ -16,7 +16,6 @@ static void destroynotify(XEvent *e);
static void enternotify(XEvent *e); static void enternotify(XEvent *e);
static void leavenotify(XEvent *e); static void leavenotify(XEvent *e);
static void expose(XEvent *e); static void expose(XEvent *e);
static void keypress(XEvent *e);
static void keymapnotify(XEvent *e); static void keymapnotify(XEvent *e);
static void maprequest(XEvent *e); static void maprequest(XEvent *e);
static void propertynotify(XEvent *e); static void propertynotify(XEvent *e);
@ -47,80 +46,36 @@ flush_masked_events(long even_mask)
static void static void
configurerequest(XEvent *e) configurerequest(XEvent *e)
{ {
#if 0
XConfigureRequestEvent *ev = &e->xconfigurerequest; XConfigureRequestEvent *ev = &e->xconfigurerequest;
XWindowChanges wc; XWindowChanges wc;
XRectangle *frect;
Client *c; Client *c;
c = client_of_win(ev->window); c = getclient(ev->window);
ev->value_mask &= ~CWSibling; ev->value_mask &= ~CWSibling;
if(c) { if(c) {
gravitate_client(c, True);
if(ev->value_mask & CWX) if(ev->value_mask & CWX)
c->rect.x = ev->x; c->r[RFloat].x = ev->x;
if(ev->value_mask & CWY) if(ev->value_mask & CWY)
c->rect.y = ev->y; c->r[RFloat].y = ev->y;
if(ev->value_mask & CWWidth) if(ev->value_mask & CWWidth)
c->rect.width = ev->width; c->r[RFloat].width = ev->width;
if(ev->value_mask & CWHeight) if(ev->value_mask & CWHeight)
c->rect.height = ev->height; c->r[RFloat].height = ev->height;
if(ev->value_mask & CWBorderWidth) if(ev->value_mask & CWBorderWidth)
c->border = ev->border_width; c->border = ev->border_width;
gravitate_client(c, False);
if(c->frame) {
if(c->sel->area->floating)
frect=&c->sel->rect;
else
frect=&c->sel->revert;
if(c->rect.width >= screen->rect.width && c->rect.height >= screen->rect.height) {
frect->y = wc.y = -height_of_bar();
frect->x = wc.x = -def.border;
}
else {
frect->y = wc.y = c->rect.y - height_of_bar();
frect->x = wc.x = c->rect.x - def.border;
}
frect->width = wc.width = c->rect.width + 2 * def.border;
frect->height = wc.height = c->rect.height + def.border
+ height_of_bar();
wc.border_width = 1;
wc.sibling = None;
wc.stack_mode = ev->detail;
if(c->sel->area->view != screen->sel)
wc.x += 2 * screen->rect.width;
if(c->sel->area->floating) {
XConfigureWindow(dpy, c->framewin, ev->value_mask, &wc);
configure_client(c);
}
}
} }
wc.x = ev->x; wc.x = ev->x;
wc.y = ev->y; wc.y = ev->y;
wc.width = ev->width; wc.width = ev->width;
wc.height = ev->height; wc.height = ev->height;
if(c && c->frame) {
wc.x = def.border;
wc.y = height_of_bar();
wc.width = c->sel->rect.width - 2 * def.border;
wc.height = c->sel->rect.height - def.border - height_of_bar();
}
wc.border_width = 0; wc.border_width = 0;
wc.sibling = None; wc.sibling = None;
wc.stack_mode = Above; wc.stack_mode = Above;
ev->value_mask &= ~CWStackMode; ev->value_mask &= ~CWStackMode;
ev->value_mask |= CWBorderWidth; ev->value_mask |= CWBorderWidth;
XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
XFlush(dpy); XFlush(dpy);
#endif
} }
static void static void
@ -181,32 +136,6 @@ expose(XEvent *e)
} }
} }
static void
keypress(XEvent *e)
{
#if 0
XKeyEvent *ev = &e->xkey;
KeySym k = 0;
char buf[32];
int n;
static Frame *f;
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;
blitz_kpress_input(&f->tagbar, ev->state, k, buf);
}
else
key(root, ev->state, (KeyCode) ev->keycode);
#endif
}
static void static void
keymapnotify(XEvent *e) keymapnotify(XEvent *e)
{ {
@ -231,7 +160,11 @@ maprequest(XEvent *e)
} }
/*if(!client_of_win(ev->window))*/ /*if(!client_of_win(ev->window))*/
manage(create_client(ev->window, &wa)); /*manage(create_client(ev->window, &wa));*/
XMapRaised(dpy, ev->window);
XMoveResizeWindow(dpy, ev->window, rect.x, rect.y, rect.width, rect.height - barrect.height);
XSetInputFocus(dpy, ev->window, RevertToPointerRoot, CurrentTime);
XFlush(dpy);
} }
static void static void

@ -38,7 +38,7 @@ loadfont(Blitz *blitz, BlitzFont *font)
font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def); font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
if(missing) { if(missing) {
while(n--) while(n--)
fprintf(stderr, "liblitz: missing fontset: %s\n", missing[n]); fprintf(stderr, "missing fontset: %s\n", missing[n]);
XFreeStringList(missing); XFreeStringList(missing);
if(font->set) { if(font->set) {
XFreeFontSet(blitz->dpy, font->set); XFreeFontSet(blitz->dpy, font->set);
@ -72,7 +72,7 @@ loadfont(Blitz *blitz, BlitzFont *font)
font->xfont = XLoadQueryFont(blitz->dpy, fontname); font->xfont = XLoadQueryFont(blitz->dpy, fontname);
} }
if (!font->xfont) { if (!font->xfont) {
fprintf(stderr, "%s", "liblitz: error, cannot load 'fixed' font\n"); fprintf(stderr, "%s", "error, cannot load 'fixed' font\n");
exit(1); exit(1);
} }
font->ascent = font->xfont->ascent; font->ascent = font->xfont->ascent;

17
key.c

@ -24,3 +24,20 @@ update_keys()
XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
} }
} }
void
keypress(XEvent *e)
{
XKeyEvent *ev = &e->xkey;
unsigned int i, len;
KeySym keysym;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
len = sizeof(key) / sizeof(key[0]);
for(i = 0; i < len; i++)
if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
if(key[i].func)
key[i].func(key[i].arg);
return;
}
}

@ -358,8 +358,6 @@ main(int argc, char *argv[])
char buf[256]; char buf[256];
fputs(STATUSCMD, stdout);
fputs("\n", stdout);
pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD); pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD);
fputs(buf, stderr); fputs(buf, stderr);

@ -93,11 +93,12 @@ spawn(Display *dpy, const char *cmd)
return; return;
if(fork() == 0) { if(fork() == 0) {
if(fork() == 0) { if(fork() == 0) {
setsid();
if(dpy) if(dpy)
close(ConnectionNumber(dpy)); close(ConnectionNumber(dpy));
execlp(shell, "shell", "-c", cmd, NULL); setsid();
fprintf(stderr, "gridwm: execvp %s", cmd); fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd);
execlp(shell, shell, "-c", cmd, NULL);
fprintf(stderr, "gridwm: execlp %s", cmd);
perror(" failed"); perror(" failed");
} }
exit (0); exit (0);
@ -123,14 +124,14 @@ pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
} }
if(fork() == 0) { if(fork() == 0) {
setsid();
if(dpy) if(dpy)
close(ConnectionNumber(dpy)); close(ConnectionNumber(dpy));
setsid();
dup2(pfd[1], STDOUT_FILENO); dup2(pfd[1], STDOUT_FILENO);
close(pfd[0]); close(pfd[0]);
close(pfd[1]); close(pfd[1]);
execlp(shell, "shell", "-c", cmd, NULL); execlp(shell, shell, "-c", cmd, NULL);
fprintf(stderr, "gridwm: execvp %s", cmd); fprintf(stderr, "gridwm: execlp %s", cmd);
perror(" failed"); perror(" failed");
} }
else { else {

50
wm.c

@ -16,11 +16,11 @@
/* X structs */ /* X structs */
Display *dpy; Display *dpy;
Window root, barwin; Window root, barwin;
Atom wm_atom[WMLast], net_atom[NetLast]; Atom net_atom[NetLast];
Cursor cursor[CurLast]; Cursor cursor[CurLast];
XRectangle rect, barrect; XRectangle rect, barrect;
Bool running = True; Bool running = True;
Client *client = NULL; Client *clients = NULL;
char *bartext, tag[256]; char *bartext, tag[256];
int screen, sel_screen; int screen, sel_screen;
@ -63,46 +63,6 @@ scan_wins()
XFree(wins); XFree(wins);
} }
static int
win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
{
Atom real;
int format;
unsigned long res, extra;
int status;
status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
&res, &extra, prop);
if(status != Success || *prop == NULL) {
return 0;
}
if(res == 0)
free((void *) *prop);
return res;
}
int
win_proto(Window w)
{
Atom *protocols;
long res;
int protos = 0;
int i;
res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L,
((unsigned char **) &protocols));
if(res <= 0) {
return protos;
}
for(i = 0; i < res; i++) {
if(protocols[i] == wm_atom[WMDelete])
protos |= WM_PROTOCOL_DELWIN;
}
free((char *) protocols);
return protos;
}
/* /*
* There's no way to check accesses to destroyed windows, thus * There's no way to check accesses to destroyed windows, thus
* those cases are ignored (especially on UnmapNotify's). * those cases are ignored (especially on UnmapNotify's).
@ -201,9 +161,6 @@ main(int argc, char *argv[])
x_error_handler = XSetErrorHandler(error_handler); x_error_handler = XSetErrorHandler(error_handler);
/* init atoms */ /* init atoms */
wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False);
wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
@ -242,7 +199,8 @@ main(int argc, char *argv[])
XMapRaised(dpy, barwin); XMapRaised(dpy, barwin);
draw_bar(); draw_bar();
wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask; wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
| LeaveWindowMask;
wa.cursor = cursor[CurNormal]; wa.cursor = cursor[CurNormal];
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);

10
wm.h

@ -10,7 +10,6 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
/* atoms */ /* atoms */
enum { WMState, WMProtocols, WMDelete, WMLast };
enum { NetSupported, NetWMName, NetLast }; enum { NetSupported, NetWMName, NetLast };
/* cursor */ /* cursor */
@ -25,7 +24,6 @@ typedef struct Key Key;
struct Client { struct Client {
char name[256]; char name[256];
char tag[256]; char tag[256];
int proto;
unsigned int border; unsigned int border;
Bool fixedsize; Bool fixedsize;
Window win; Window win;
@ -46,7 +44,7 @@ struct Key {
extern Display *dpy; extern Display *dpy;
extern Window root, barwin; extern Window root, barwin;
extern Atom wm_atom[WMLast], net_atom[NetLast]; extern Atom net_atom[NetLast];
extern Cursor cursor[CurLast]; extern Cursor cursor[CurLast];
extern XRectangle rect, barrect; extern XRectangle rect, barrect;
extern Bool running; extern Bool running;
@ -57,20 +55,22 @@ extern int screen, sel_screen;
extern char *bartext, tag[256]; extern char *bartext, tag[256];
extern Brush brush; extern Brush brush;
extern Client *client; extern Client *clients;
/* bar.c */ /* bar.c */
extern void draw_bar(); extern void draw_bar();
/* cmd.c */ /* cmd.c */
extern void run(char *arg); extern void run(char *arg);
extern void quit(char *arg);
/* client.c */ /* client.c */
extern Client *create_client(Window w, XWindowAttributes *wa); extern Client *create_client(Window w, XWindowAttributes *wa);
extern void manage(Client *c); extern void manage(Client *c);
extern Client * getclient(Window w);
/* key.c */ /* key.c */
extern void update_keys(); extern void update_keys();
extern void keypress(XEvent *e);
/* wm.c */ /* wm.c */
extern int win_proto(Window w);

Loading…
Cancel
Save