[hackers] wmix: new tip (= 27)

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Sun, 04 Feb 2007 12:40:06 +0100

changeset: 27:cbd50ff78a63
tag: tip
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Feb 03 18:51:29 2007 +0100
files: wmii.h
description:
#define instead of typedef Column, Floating :P

changeset: 26:9c8b76fcab33
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Feb 03 18:00:18 2007 +0100
files: helpers.c manage.c structures.c update.c wmii.h
description:
rewrite of the rewrite

changeset: 25:fe30a16e0005
user: Denis Grelich <denisg_AT_suckless.org>
date: Fri Feb 02 02:36:59 2007 +0100
files: client.c column.c draw.c event.c frame.c init.c main.c manage.c mouse.c scope.c view.c wmii.h
description:
fixing the whole thing. intermediary commit.

changeset: 24:b68de83d863d
user: Denis Grelich <denisg_AT_suckless.org>
date: Thu Feb 01 18:03:09 2007 +0100
files: event.c wmii.h
description:
cleanup

changeset: 23:4bf4dccf21ca
parent: 19:abfc0fc9f176
parent: 22:a4e186d7f299
user: Denis Grelich <denisg_AT_suckless.org>
date: Wed Jan 31 19:06:50 2007 +0100
files: event.c mouse.c
description:
patches from Maxi. Thanks!

changeset: 22:a4e186d7f299
user: Maximilian Grothusmann <maxi-wmii_AT_own-hero.de>
date: Tue Jan 30 14:49:16 2007 +0100
files: mouse.c
description:
Don't try to draw a destroyed column

changeset: 21:8285eee181ca
user: Maximilian Grothusmann <maxi-wmii_AT_own-hero.de>
date: Tue Jan 30 11:26:09 2007 +0100
files: mouse.c
description:
Don't crash when trying to roll up floating windows

changeset: 20:b66a44e79986
parent: 17:1252cf9c3a5b
user: Maximilian Grothusmann <maxi-wmii_AT_own-hero.de>
date: Tue Jan 30 11:24:51 2007 +0100
files: event.c
description:
Fix show_event()

changeset: 19:abfc0fc9f176
user: Denis Grelich <denisg_AT_suckless.org>
date: Wed Jan 31 19:05:38 2007 +0100
files: event.c frame.c view.c
description:
some proceeding

changeset: 18:e47c00452442
user: Denis Grelich <denisg_AT_suckless.org>
date: Mon Jan 29 20:52:42 2007 +0100
files: client.c column.c event.c frame.c main.c mouse.c scope.c view.c wmii.h
description:
working, with stubs for scopes

changeset: 17:1252cf9c3a5b
user: Denis Grelich <denisg_AT_suckless.org>
date: Mon Jan 29 19:20:08 2007 +0100
files: Makefile client.c column.c config.mk draw.c error.c event.c frame.c init.c main.c mouse.c scope.c view.c wmii.h
description:
restructuring: only one screen per wm

changeset: 16:75a27f1a100b
user: Denis Grelich <denisg_AT_suckless.org>
date: Mon Jan 29 16:41:28 2007 +0100
files: client.c draw.c event.c frame.c mouse.c scope.c wmii.h
description:
proceeding with implementation

changeset: 15:52c52a6a4870
user: Denis Grelich <denisg_AT_suckless.org>
date: Sun Jan 28 15:30:56 2007 +0100
files: client.c error.c event.c main.c mouse.c view.c wmii.h
description:
focus now fixed

changeset: 14:cebf43813fe9
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Jan 27 23:28:20 2007 +0100
files: mouse.c
description:
draw_column before scale_column! stupid me!

changeset: 13:915a7c1ffc42
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Jan 27 23:21:36 2007 +0100
files: client.c column.c event.c frame.c mouse.c view.c wmii.h
description:
floating layer support added (middle click to toggle)

changeset: 12:3808a395ea3c
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Jan 27 20:09:41 2007 +0100
files: event.c main.c mouse.c view.c wmii.h
description:
click-to-focus

changeset: 11:71af80191670
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Jan 27 01:52:59 2007 +0100
files: mouse.c
description:
fixed mousewarp on focus

changeset: 10:aa6d43245f24
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Jan 27 01:34:58 2007 +0100
files: column.c view.c
description:
small bugfix in rollup code

changeset: 9:4fe19f601f49
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Jan 27 01:23:47 2007 +0100
files: column.c frame.c mouse.c scope.c view.c wmii.h
description:
new rollup behaviour

changeset: 8:984d0b8576ed
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Jan 27 00:36:07 2007 +0100
files: mouse.c
description:
left mouse does not unroll anymore

changeset: 7:93470e58c907
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Jan 27 00:31:14 2007 +0100
files: column.c event.c mouse.c
description:
right click to unroll works now too

changeset: 6:b818a271b58a
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Jan 27 00:12:17 2007 +0100
files: client.c event.c main.c mouse.c view.c wmii.h
description:
made rollup with mouse nicer

changeset: 5:42fe5678a383
user: Denis Grelich <denisg_AT_suckless.org>
date: Fri Jan 26 23:21:25 2007 +0100
files: Makefile event.c frame.c mouse.c view.c wmii.h
description:
added mouse handler, rollup code now used

changeset: 4:59c38a420614
user: Denis Grelich <denisg_AT_suckless.org>
date: Fri Jan 26 22:28:25 2007 +0100
files: column.c error.c event.c frame.c main.c view.c
description:
rollup code

changeset: 3:73a4478bd40a
user: Denis Grelich <denisg_AT_suckless.org>
date: Fri Jan 26 17:34:22 2007 +0100
files: column.c
description:
tiny bugfix: now possible to remove first frame in column

changeset: 2:8ac48888ce01
user: Denis Grelich <denisg_AT_suckless.org>
date: Fri Jan 26 17:12:48 2007 +0100
files: Makefile client.c column.c error.c event.c frame.c main.c scope.c view.c wmii.h
description:
now catching some events and managing/unmanaging coming and going clients

changeset: 1:5abc88aacbaa
user: Denis Grelich <denisg_AT_suckless.org>
date: Sat Jan 20 23:33:43 2007 +0100
files: draw.c wmii.h
description:
forgot wmii.h

diff -r 6549b67df47b -r cbd50ff78a63 Makefile
--- a/Makefile Sat Jan 20 23:20:01 2007 +0100
+++ b/Makefile Sat Feb 03 18:51:29 2007 +0100
@@ -3,7 +3,7 @@
 
 include config.mk
 
-SRC = main.c client.c frame.c draw.c error.c scope.c view.c column.c
+SRC = main.c client.c frame.c draw.c init.c scope.c view.c column.c mouse.c event.c
 OBJ = ${SRC:.c=.o}
 
 all: options wmiiwm
diff -r 6549b67df47b -r cbd50ff78a63 client.c
--- a/client.c Sat Jan 20 23:20:01 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#include "wmii.h"
-#include <stdlib.h>
-
-Client *
-create_client(void) {//(Window w, XWindowAttributes *wa) {
- Client *c = ixp_emallocz(sizeof(Client));
-/* c->rect.x = 40;
- c->rect.y = 30;
- c->rect.w = 100;
- c->rect.h = 120;*/
-// c->frames = create_frame(c, c->rect);
- return c;
-}
diff -r 6549b67df47b -r cbd50ff78a63 column.c
--- a/column.c Sat Jan 20 23:20:01 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,107 +0,0 @@
-#include "wmii.h"
-#include <stdlib.h>
-#include <string.h>
-
-Column *
-create_column (View *v, Column *after) {
- Column *c, **cp, *col = ixp_emallocz(sizeof (Column));
- cp = after ? &after->next : &v->col;
- col->next = *cp;
- col->prev = after;
- if(col->next) col->next->prev = col;
- *cp = col;
-
- col->view = v;
- col->f = col->sel = NULL;
- col->frm_cnt = 0;
- ++v->cols_cnt;
- v->sel = col;
-
- uint width = v->rect.w / v->cols_cnt;
- int rest = v->rect.w - width * v->cols_cnt;
- for (c = v->col; c; c = c->next) {
- c->width = width;
- c->x = c->prev ? c->prev->x + c->prev->width : v->rect.x;
- }
- while (rest)
- for (c = v->col; c && rest; ++c->width, c = c->next, --rest);
-
- Frame *f;
- for (c = v->col; c; c = c->next) {
- if(c->next)
- c->next->x = c->x + c->width;
- for (f = c->f; f; f = f->next) {
- f->rect.x = c->x;
- f->rect.w = c->width;
- }
- }
-
- return col;
-}
-
-void
-destroy_column (Column *col) {
- View *v = col->view;
- if (v->sel == col)
- v->sel = col->next ? col->next : col->prev;
- if(col->prev)
- col->prev->next = col->next;
- if(col->next)
- col->next->prev = col->prev;
- --v->cols_cnt;
-}
-
-void
-insert_into_column (Column *col, Frame *frm) {
- Frame **fp;
- fp = col->sel ? &col->sel->next : &col->f;
- frm->next = *fp;
- frm->prev = col->sel;
- if(frm->next) frm->next->prev = frm;
- *fp = frm;
-
- frm->column = col;
- col->sel = frm;
- frm->rect.h = col->frm_cnt ? col->view->rect.h / col->frm_cnt : col->view->rect.h;
- ++col->frm_cnt;
- scale_column(col);
-}
-
-void
-remove_from_column (Frame *frm) {
- Column *col = frm->column;
- if (col->sel == frm)
- col->sel = frm->next ? frm->next : frm->prev;
- if(frm->prev)
- frm->prev->next = frm->next;
- if(frm->next)
- frm->next->prev = frm->prev;
- --col->frm_cnt;
- scale_column(col);
-}
-
-void scale_column (Column *col) {
- double aspect = (double) (max(col->frm_cnt, 2) - 1) / col->frm_cnt;
-// double aspect = (double) col->view->rect.h / (col->view->rect.h + frm->rect.h);
-// printf("aspect: %.2f\n", aspect);
- int rest = col->view->rect.h;
- Frame *f;
- for (f = col->f; f; f = f->next) {
- f->rect.x = col->x;
- f->rect.y = f->prev ? (f->prev->rect.y + f->prev->rect.h) : col->view->rect.y;
- f->rect.w = col->width;
- f->rect.h = f->rect.h * aspect;
- rest -= f->rect.h;
- }
- while (rest)
- for (f = col->f; f && rest; ++f->rect.h, f = f->next, --rest);
- for (f = col->f; f->next; f = f->next)
- f->next->rect.y = f->rect.y + f->rect.h;
-}
-
-
-void draw_column (Column *col) {
- Frame *f;
- for (f = col->f; f; f = f->next)
- draw_frame(f);
-}
diff -r 6549b67df47b -r cbd50ff78a63 config.mk
--- a/config.mk Sat Jan 20 23:20:01 2007 +0100
+++ b/config.mk Sat Feb 03 18:51:29 2007 +0100
@@ -18,7 +18,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
 # flags
 #CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
 #LDFLAGS = ${LIBS}
-CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
+CFLAGS = -g -Wall -O1 ${INCS} -DVERSION=\"${VERSION}\"
 LDFLAGS = -g ${LIBS}
 
 # Solaris
diff -r 6549b67df47b -r cbd50ff78a63 draw.c
--- a/draw.c Sat Jan 20 23:20:01 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-#include "wmii.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-static unsigned long
-xloadcolor(const char *colstr) {
- XColor color;
- char col[8];
-
- strncpy(col, colstr, sizeof(col));
- col[7] = 0;
- XAllocNamedColor(dpy,
- DefaultColormap(dpy, scope->screen), col, &color, &color);
- return color.pixel;
-}
-
-Color *
-parse_colors(const char *colstr, int len, Color *col) {
- uint i;
- if(len < 23 || 3 != sscanf(colstr, "#%06x #%06x #%06x", &i,&i,&i))
- return NULL;
-
- memcpy(col->colstr, colstr, 23);
- col->fg = xloadcolor(&colstr[0]);
- col->bg = xloadcolor(&colstr[8]);
- col->border = xloadcolor(&colstr[16]);
- return col;
-}
-
diff -r 6549b67df47b -r cbd50ff78a63 error.c
--- a/error.c Sat Jan 20 23:20:01 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-
-#include "wmii.h"
-#include <X11/Xproto.h>
-#include <assert.h>
-
-static int other_wm_running = 0;
-static int (*x_error_handler) (Display *, XErrorEvent *);
-
-/*
- * There's no way to check accesses to destroyed windows, thus
- * those cases are ignored (especially on UnmapNotify's).
- * Other types of errors call Xlib's default error handler, which
- * calls exit().
- */
-static int
-wmii_error_handler(Display *dpy, XErrorEvent *error) {
- if(error->error_code == BadWindow
- || (error->request_code == X_SetInputFocus
- && error->error_code == BadMatch)
- || (error->request_code == X_PolyText8
- && error->error_code == BadDrawable)
- || (error->request_code == X_PolyFillRectangle
- && error->error_code == BadDrawable)
- || (error->request_code == X_PolySegment
- && error->error_code == BadDrawable)
- || (error->request_code == X_ConfigureWindow
- && error->error_code == BadMatch)
- || (error->request_code == X_GrabKey
- && error->error_code == BadAccess))
- return 0;
- fprintf(stderr, "wmiiwm: fatal error: Xrequest code=%d, Xerror code=%d\n",
- error->request_code, error->error_code);
- assert(0);
- return x_error_handler(dpy, error); /* calls exit() */
-}
-
-/*
- * Startup Error handler to check if another window manager
- * is already running.
- */
-static int
-startup_error_handler(Display * dpy, XErrorEvent * error) {
- other_wm_running = 1;
- return -1;
-}
-
-void
-error_handling(Scope *s) {
- /* check if another WM is already running */
- XSetErrorHandler(startup_error_handler);
- /* this causes an error if some other WM is running */
- XSelectInput(dpy, s->root, SubstructureRedirectMask | EnterWindowMask);
- XSync(dpy, False);
-// if(other_wm_running)
- ixp_eprint("wmiiwm: another window manager is already running\n");
- XSetErrorHandler(0);
- x_error_handler = XSetErrorHandler(wmii_error_handler);
-}
-
-void
-prect (Rect r) {
- printf("%d %d %d %d\n", r.x, r.y, r.w, r.h);
-}
-
-void
-pint (int i) {
- printf("%d\n", i);
-}
diff -r 6549b67df47b -r cbd50ff78a63 event.c
--- a/event.c Sat Jan 20 23:20:01 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-#include "wmii.h"
-#include <stdlib.h>
-#include <X11/keysym.h>
-
-void (*handler[LASTEvent]) (XEvent *) = {
- [ButtonPress] = buttonpress,
- [ButtonRelease] = buttonrelease/*,
- [ConfigureRequest]= configurerequest,
- [DestroyNotify] = destroynotify,
- [EnterNotify] = enternotify,
- [LeaveNotify] = leavenotify,
- [Expose] = expose,
- [KeyPress] = keypress,
- [MappingNotify] = mappingnotify,
- [MapRequest] = maprequest,
- [PropertyNotify]= propertynotify,
- [UnmapNotify] = unmapnotify*/
-};
-
-void
-check_x_event(IXPConn *c) {
- XEvent ev;
- while(XPending(dpy)) { /* main event loop */
- XNextEvent(dpy, &ev);
- if(handler[ev.type])
- (handler[ev.type]) (&ev); /* call handler */
- }
-}
-
diff -r 6549b67df47b -r cbd50ff78a63 frame.c
--- a/frame.c Sat Jan 20 23:20:01 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-#include "wmii.h"
-#include <stdlib.h>
-
-Frame *
-create_frame (Client* c, View* v) {
- Frame *f = ixp_emallocz(sizeof(Frame));
-
- Scope* scope = v->scope;
- f->view = v;
- f->column = NULL;
-
- f->crect.y = def.barheight;
-// f->cnext = c->f;
-// c->f = f;
- f->rollup = False;
-
- f->rect = def.frame_min;
-
- XSetWindowAttributes fwa;
- fwa.override_redirect = 1;
- fwa.background_pixmap = ParentRelative;
- fwa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | ExposureMask
- | ButtonPressMask | PointerMotionMask | ButtonReleaseMask | KeyPressMask;
- f->win = XCreateWindow(dpy, scope->root, 0, 0, // should happen in Client
- def.frame_min.w, def.frame_min.h, 0,
- DefaultDepth(dpy, scope->screen), CopyFromParent,
- DefaultVisual(dpy, scope->screen),
- CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa);
- f->client = c;
- return f;
-}
-
-void
-destroy_frame (Frame *frm) {
-/* Frame **fp;
- for (fp = &frm->client->f; *fp; fp = &(*fp)->next) {
- if ((*fp)->cnext == frm)
- (*fp)->cnext = frm->cnext;
- }*/
- XUnmapWindow(dpy, frm->win);
- free(frm);
-}
-
-void
-draw_frame (Frame *f) {
- Scope *scope = f->view->scope;
- uint x = f->rect.x, y = f->rect.y;
- uint w = f->rect.w, h = f->rect.h;
- Color* color;
- if (f == f->column->sel)
- if (f->column == f->view->sel)
- color = &def.focuscolor;
- else
- color = &def.selcolor;
- else
- color = &def.normcolor;
- prect(f->rect);
- // TODO: INCREMENT HANDLING GOES HERE
- f->crect.w = w - 2 * def.border;
- f->crect.h = h > def.border + def.barheight ? h - (def.border + def.barheight) : 0;
- // -----------------------------------
- f->crect.x = (w - f->crect.w) / 2;
-
- XMapWindow(dpy, f->win);
- XMoveResizeWindow(dpy, f->win, x, y, w, h);
- /* titlebar */
- GC gc = scope->gc;
- XSetForeground(dpy, gc, color->bg);
- XFillRectangle(dpy, scope->backbuffer, gc, 1, 1, w - 2, def.barheight - 1);
- XCopyArea(dpy, scope->backbuffer, f->win, gc, 0, 0,
- w, def.barheight, 0, 0);
- /* border */
- if (h > def.barheight || f->rollup) {
- XFillRectangle(dpy, f->win, gc, 1, def.barheight, def.border - 1,
- f->crect.h);
- XFillRectangle(dpy, f->win, gc, f->crect.x + f->crect.w, def.barheight,
- def.border - 1, f->crect.h);
- XFillRectangle(dpy, f->win, gc, 1, f->crect.y + f->crect.h,
- w - 2, def.border - 1);
- }
- XSetForeground(dpy, gc, color->border);
- XDrawRectangle(dpy, f->win, gc, 0, 0, w - 1, h - 1);
-}
-
diff -r 6549b67df47b -r cbd50ff78a63 helpers.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/helpers.c Sat Feb 03 18:51:29 2007 +0100
@@ -0,0 +1,82 @@
+#include "wmii.h"
+
+static Frame *
+get_frame_of_area (Area *a, Window win, Client *clnt) {
+ Frame *f;
+ for (f = a->f; f; f = f->next)
+ if ((!win || f->client->framewin == win) && (!clnt || f->client == clnt))
+ return f;
+ return NULL;
+}
+
+Frame *
+get_frame (Scope *scp, View *vw, Area *ar, Window win, Client *clnt) {
+ if (ar)
+ return get_frame_of_view(ar, win, clnt);
+ Scope *s = scp ? scp :
+ (vw ? vw->scope : scope);
+ while (s) {
+ View *v = vw ? vw : s->view;
+ while (v) {
+ Frame *f;
+ if ((f = get_frame_of_view(ar, win, clnt)))
+ return f;
+ Area *a;
+ for (a = v->col; a; a = a->next)
+ if ((f = get_frame_of_view(ar, win, clnt)))
+ return f;
+ v = vw ? NULL : v->next;
+ }
+ s = scp ? NULL : s->next;
+ }
+ return NULL;
+}
+
+Frame *
+sel_of_view (View *v) {
+ if (v->float_selected)
+ return v->flt ? v->flt->sel : NULL;
+ return v->c_sel ? v->c_sel->sel : NULL;
+}
+
+Frame *
+visible_frame_of_client (Client *c) {
+ Frame *f;
+ for (f = c->f; f; f = f->next)
+ if (f->view = scope->sel)
+ return f;
+ return NULL;
+}
+
+void
+attach_frame (Frame *f, Area *a) {
+ Frame **fp;
+ fp = a->sel ? &a->sel->next : &a->f;
+ f->next = *fp;
+ f->prev = a->sel;
+ if (f->next)
+ f->next->prev = f;
+ *fp = f;
+ f->area = a;
+ ++a->f_cnt;
+}
+
+void
+detach_frame (Frame *f) {
+ if (f->prev)
+ f->prev->next = f->next;
+ if (f->next)
+ f->next->prev = f->prev;
+ if (f->area->f == f)
+ f->area->f = f->next;
+ --f->area->f_cnt;
+}
+
+Client *
+client_of_win (Window w) {
+ Client *c;
+ for (c = clients; c; c = c->next)
+ if (c->win == w)
+ return c;
+ return NULL;
+}
diff -r 6549b67df47b -r cbd50ff78a63 init.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/init.c Sat Feb 03 18:51:29 2007 +0100
@@ -0,0 +1,101 @@
+
+#include "wmii.h"
+#include <X11/Xproto.h>
+#include <assert.h>
+
+static int other_wm_running = 0;
+static int (*x_error_handler) (Display *, XErrorEvent *);
+
+
+void
+init_X11_server () {
+ _Xdebug = 1;
+ if (!(dpy = XOpenDisplay(NULL)))
+ ixp_eprint("wmiiwm: cannot open dpy\n");
+ screen = DefaultScreen(dpy);
+ root = RootWindow(dpy, screen);
+}
+
+
+void
+init_graphics () {
+ gc = XCreateGC(dpy, root, 0, NULL);
+ ghost.stipple = XCreateBitmapFromData(dpy, root, "\001\002\001\003", 2, 2);
+ XGCValues gcv;
+ gcv.foreground = def.selcolor.fg;
+ gcv.background = def.selcolor.bg;
+ gcv.plane_mask = AllPlanes;
+ gcv.graphics_exposures = False;
+ gcv.function = GXcopyInverted;
+ gcv.stipple = ghost.stipple;
+ gcv.fill_style = FillOpaqueStippled;
+ ghost.gc = XCreateGC(dpy, root, GCForeground | GCBackground | GCGraphicsExposures |
+ GCFunction | GCFillStyle | GCStipple | GCPlaneMask, &gcv);
+// XCreateWindow(ghost);
+}
+
+void
+deinit_graphics () {
+ // XFreeGC(...
+ // XDestroyWindow(...
+ XFreePixmap(dpy, ghost.stipple);
+}
+
+
+/*
+ * There's no way to check accesses to destroyed windows, thus
+ * those cases are ignored (especially on UnmapNotify's).
+ * Other types of errors call Xlib's default error handler, which
+ * calls exit().
+ */
+int
+wmii_error_handler(Display *dpy, XErrorEvent *error) {
+ if(error->error_code == BadWindow
+ || (error->request_code == X_SetInputFocus
+ && error->error_code == BadMatch)
+ || (error->request_code == X_PolyText8
+ && error->error_code == BadDrawable)
+ || (error->request_code == X_PolyFillRectangle
+ && error->error_code == BadDrawable)
+ || (error->request_code == X_PolySegment
+ && error->error_code == BadDrawable)
+ || (error->request_code == X_ConfigureWindow
+ && error->error_code == BadMatch)
+ || (error->request_code == X_GrabKey
+ && error->error_code == BadAccess))
+ return 0;
+ fprintf(stderr, "wmiiwm: fatal error: Xrequest code=%d, Xerror code=%d\n",
+ error->request_code, error->error_code);
+ assert(0);
+ return x_error_handler(dpy, error); /* calls exit() */
+}
+
+int ignore_error_handler(Display *dpy, XErrorEvent *e)
+{
+ return 0;
+}
+
+/*
+ * Startup Error handler to check if another window manager
+ * is already running.
+ */
+static int
+startup_error_handler(Display * dpy, XErrorEvent * error) {
+ other_wm_running = 1;
+ return -1;
+}
+
+
+
+void
+error_handling() {
+ XSetErrorHandler(startup_error_handler);
+ /* this causes an error if some other WM is running */
+ XSelectInput(dpy, root, SubstructureRedirectMask);
+ XSync(dpy, False);
+ if(other_wm_running)
+ ixp_eprint("wmiiwm: another window manager is already running\n");
+ XSetErrorHandler(0);
+ x_error_handler = XSetErrorHandler(wmii_error_handler);
+}
+
diff -r 6549b67df47b -r cbd50ff78a63 main.c
--- a/main.c Sat Jan 20 23:20:01 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-/* (C)
- */
-
-#include "wmii.h"
-#include <X11/Xlib.h>
-#include <X11/Xproto.h>
-
-
-extern void sleep(int);
-
-int
-main(int argc, char *argv[]) {
- def.barheight = DEFAULT_BARHEIGHT;
- _Xdebug = 1;
- dpy = XOpenDisplay(0);
- if(!dpy)
- ixp_eprint("wmiiwm: cannot open dpy\n");
- scope = init_scope(DefaultScreen(dpy));
-
- /* exits failingly if another WM is already running */
- //error_handling(area);
-
- parse_colors(DEFAULT_NORMCOLORS, 23, &def.normcolor);
- parse_colors(DEFAULT_SELCOLORS, 23, &def.selcolor);
- parse_colors(DEFAULT_FOCUSCOLORS, 23, &def.focuscolor);
- def.border = DEFAULT_BORDERWIDTH;
- def.barheight = DEFAULT_BARHEIGHT;
- def.frame_min.x = def.frame_min.y = 0;
- def.frame_min.w = def.barheight < 2 * def.border ? 2 * def.border : def.barheight;
- def.frame_min.h = def.barheight;
-
- Rect rct;
- rct.x = rct.y = 10;
- rct.w = 480;
- rct.h = 300;
-
-// Client* c = create_client();
-//
- View *v = get_view(scope, "test", rct);
- create_column(v, NULL);
- insert_into_column(v->sel, create_frame(NULL, v));
- insert_into_column(v->sel, create_frame(NULL, v));
- insert_into_column(v->sel, create_frame(NULL, v));
- create_column(v, NULL);
- insert_into_column(v->sel, create_frame(NULL, v));
- insert_into_column(v->sel, create_frame(NULL, v));
- insert_into_column(v->sel, create_frame(NULL, v));
- insert_into_column(v->sel, create_frame(NULL, v));
- create_column(v, NULL);
- insert_into_column(v->sel, create_frame(NULL, v));
- insert_into_column(v->sel, create_frame(NULL, v));
- insert_into_column(v->sel, create_frame(NULL, v));
-// XSync(dpy, False);
-
- draw_view(v);
- sleep(3);
- Frame *f = v->sel->sel;
- remove_from_column(f);
- destroy_frame(f);
- XSync(dpy, False);
- draw_view(v);
- while (True)
- {
- sleep(2);
- draw_view(v);
- }
-}
diff -r 6549b67df47b -r cbd50ff78a63 manage.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/manage.c Sat Feb 03 18:51:29 2007 +0100
@@ -0,0 +1,140 @@
+#include "wmii.h"
+
+void
+manage_window (Window win) {
+ Client *c = create_client (win);
+ /* FIXME: tagging rules and stuff:
+ * for each tag in ... do */
+ tag_client(c, DEFAULT_TAG);
+}
+
+void
+unmanage_client (Client *c) {
+ while (c->tag[0])
+ untag_client(c, c->tag);
+ destroy_client(c);
+}
+
+Bool
+tag_client (Client *c, const char *tag) {
+ int i;
+ for (i = 0; c->tag[i]; ++i)
+ if (i == MAX_VIEW_COUNT)
+ return False;
+ c->tag[i] = ixp_estrdup(tag);
+ View *v = get_view(tag);
+ create_frame(c, v);
+ Column *col = v->c_sel;
+ if (col->f_cnt >= 4)
+ create_column(v, col);
+ attach_frame(f, col);
+ if (col != c_sel) // meaning a new column was created
+ update_view(v);
+ else
+ update_column(col);
+ return True;
+}
+
+void
+untag_client (Client *c, const char *tag) {
+ char **ta = NULL;
+ for (i = 0; c->tag[i] && i < MAX_VIEW_COUNT ; ++i)
+ if (!strcmp(tag, c->tag[i])) {
+ ta = &c->tag[i];
+ break;
+ }
+ if (!ta) return;
+
+ memmove(ta, ta + 1, MAX_VIEW_COUNT - i);
+ c->tag[MAX_VIEW_COUNT] = NULL;
+
+ Area *fa = f->area;
+ View *v = fa->view;
+ if (f == sel_of_view(f->view)) {
+ Frame *sel = f->prev ? f->prev : f->next;
+ detach_frame(f);
+ destroy_frame(f);
+ if (fa->floating) {
+ if (!sel) {
+ v->float_selected = False;
+ update_column(v->c_sel);
+ }
+ else {
+ v->flt->sel = sel;
+ draw_frame(sel);
+ }
+ }
+ else {
+ if (!sel) {
+ destroy_column(fa);
+ update_view(v);
+ }
+ }
+ }
+ else {
+ detach_frame(f);
+ if (fa->f_cnt == 0)
+ destroy_column(fa);
+ destroy_frame(f);
+ update_view(v);
+ }
+
+}
+
+Bool
+move_frame (Frame *f, Area *dest) {
+ Area *fa = f->area;
+ View *v = fa->view;
+ if (f == sel_of_view(f->view)) {
+ Frame *sel = f->prev ? f->prev : f->next;
+ detach_frame(f);
+ attach_frame(f, dest);
+ if (fa->floating) {
+ if (sel) {
+ v->flt->sel = sel;
+ draw_frame(sel);
+ }
+ focus_frame(f);
+ }
+ else {
+ if (!sel) {
+ destroy_column(fa);
+ v->c_sel = f->area;
+ update_view(v);
+ }
+ }
+ }
+ else {
+ detach_frame(f);
+ attach_frame(f, dest);
+ update_area(fa);
+ }
+}
+
+void
+focus_frame (Frame *f) {
+ View *v = f->view;
+ Frame *old = sel_of_view(v);
+ v->float_selected = f->area->floating;
+ f->area->sel = f;
+ if (!f->float_selected)
+ v->c_sel = f->area;
+ if (old && old != f->area)
+ update_area(old->area);
+ update_area(f->area);
+}
+
+
+void
+show_view (View *v) {
+ Frame *f;
+ for (f = scope->sel->flt->f; f; f = f->next)
+ XUnmapWindow(dpy, f->client->framewin);
+ Area *a;
+ for (a = scope->sel->col; a; a = a->next) {
+ for (f = a->f; f; f = f->next)
+ XUnmapWindow(dpy, f->client->framewin);
+ }
+ v->scope->sel = v;
+ update_view(v);
+}
diff -r 6549b67df47b -r cbd50ff78a63 scope.c
--- a/scope.c Sat Jan 20 23:20:01 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-#include "wmii.h"
-#include <X11/Xproto.h>
-
-
-Scope *init_scope (int screen) {
- Scope *s = ixp_emallocz(sizeof (Scope));
-
- s->root = RootWindow(dpy, screen);
- s->screen = screen;
- s->v = NULL;
- s->rect.x = s->rect.y = 0;
- s->rect.w = DisplayWidth(dpy, screen);
- s->rect.h = DisplayHeight(dpy, screen);
-
- s->backbuffer = XCreatePixmap(dpy, s->root, s->rect.w, s->rect.h,
- DefaultDepth(dpy, screen));
-
- XGCValues gcv;
- gcv.foreground = def.selcolor.bg;
- gcv.plane_mask = AllPlanes;
- gcv.graphics_exposures = False;
- gcv.function = GXxor;
- s->gc_xor = XCreateGC(dpy, s->root, GCForeground | GCGraphicsExposures |
- GCFunction | GCSubwindowMode | GCPlaneMask, &gcv);
- s->gc = XCreateGC(dpy, s->root, 0, NULL);
- return s;
-}
-
-Scope *sel_scope () {
- // FIXME: STUB
-// int ret; uint mask;
-// sel_screen = XQueryPointer(dpy, blz.root, &w, &w, &ret, &ret, &ret, &ret, &mask);
- return NULL;
-}
diff -r 6549b67df47b -r cbd50ff78a63 structures.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/structures.c Sat Feb 03 18:51:29 2007 +0100
@@ -0,0 +1,21 @@
+#include "wmii.h"
+
+View *
+get_view (Scope *scope, const char *tag) {
+ View *v;
+ for (v = views; v; v = v->next) {
+ if (!strcmp(v->tag, tag)) {
+ printf("%u\n", (uint) v);
+ return v;
+ }
+ }
+ v = ixp_emallocz(sizeof (View));
+ v->tag = ixp_estrdup(tag);
+ v->scope = scope;
+ scope->view = v;
+ v->fsel = v->flt = NULL;
+ v->sel = v->col = NULL;
+ v->cols_cnt = 0;
+ v->next = views;
+ return (views = v);
+}
diff -r 6549b67df47b -r cbd50ff78a63 update.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/update.c Sat Feb 03 18:51:29 2007 +0100
@@ -0,0 +1,1 @@
+#include "wmii.h"
diff -r 6549b67df47b -r cbd50ff78a63 view.c
--- a/view.c Sat Jan 20 23:20:01 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-#include "wmii.h"
-#include <stdlib.h>
-#include <string.h>
-
-View *
-get_view (Scope *scope, char tag[MAX_TAG_LENGTH], Rect rect) {
- View *v;
- for (v = scope->v; v; v = v->next) {
- if (!strncmp(v->tag, tag, MAX_TAG_LENGTH))
- return v;
- }
- v = ixp_emallocz(sizeof (View));
- strncpy(v->tag, tag, MAX_TAG_LENGTH);
- v->scope = scope;
- v->col = v->sel = NULL;
- v->rect = rect;
- v->next = scope->v;
- return (scope->v = v);
-}
-
-void
-draw_view (View *v) {
- Column *c;
- for (c = v->col; c; c = c->next)
- draw_column(c);
-}
-
-void
-hide_view (View *v) {
- Column *c;
- for (c = v->col; c; c = c->next) {
- Frame *f;
- for (f = c->f; f; f = f->next)
- XUnmapWindow(dpy, f->win);
- }
-}
-
-void
-destroy_view (Scope *scope, char tag[MAX_TAG_LENGTH]) {
- View **vp;
- for (vp = &scope->v; *vp; vp = &(*vp)->next) {
- if (!strncmp((*vp)->tag, tag, MAX_TAG_LENGTH)) {
- *vp = (*vp)->next;
- return;
- }
- }
-}
diff -r 6549b67df47b -r cbd50ff78a63 wmii.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/wmii.h Sat Feb 03 18:51:29 2007 +0100
@@ -0,0 +1,229 @@
+#include <stdio.h>
+#include <regex.h>
+#include <assert.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xlocale.h>
+
+#include <ixp.h>
+
+// there should be no hard-coded default values
+#define DEFAULT_FONT "fixed"
+#define DEFAULT_SELCOLORS "#550000 #AA0000 #FF0000"
+#define DEFAULT_FOCUSCOLORS "#005500 #00AA00 #00FF00"
+#define DEFAULT_NORMCOLORS "#000055 #0000AA #0000FF"
+
+#define DEFAULT_BARHEIGHT 16
+#define DEFAULT_BORDERWIDTH 4
+#define DEFAULT_TAG "test"
+
+#define MAX_VIEW_COUNT 64
+
+#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
+
+typedef unsigned int uint;
+typedef unsigned short ushort;
+
+/* Drawing */
+typedef enum Align Align;
+typedef struct Color Color;
+typedef struct Rect Rect;
+
+enum Align {
+ NORTH = 0x01,
+ EAST = 0x02,
+ SOUTH = 0x04,
+ WEST = 0x08,
+ NEAST = NORTH | EAST,
+ NWEST = NORTH | WEST,
+ SEAST = SOUTH | EAST,
+ SWEST = SOUTH | WEST,
+ CENTER = NEAST | SWEST
+};
+
+struct Color {
+ unsigned long bg;
+ unsigned long fg;
+ unsigned long border;
+};
+
+struct Rect {
+ int x, y;
+ uint w, h;
+};
+
+/* Data structures */
+typedef struct Client Client;
+typedef struct Frame Frame;
+typedef struct Area Area;
+#define Column Area
+#define Floating Area
+typedef struct View View;
+typedef struct Scope Scope;
+
+struct Client {
+ Client *next;
+
+ Frame *f;
+ char *tag[MAX_VIEW_COUNT + 1];
+ Rect rect; // floating layer rectangle for new frames,
+ // should be superseded by some preferred size structure
+
+ Window win;
+ Window framewin;
+ Window trans;
+ XSizeHints size;
+
+ Bool fixedsize;
+};
+
+/* there is exactly one frame per view per client */
+struct Frame {
+ Frame *next, *prev;
+ Frame *cnext;
+
+ Rect rect; // managed rectangle
+ Rect frect; // float rectangle
+ Rect crect; // client rectangle
+
+ Client *client;
+ Bool rollup;
+
+ Area *area;
+ View *view;
+};
+
+struct Area {
+ Column *next;
+ Column *prev;
+ View *view;
+ uint x;
+ uint width;
+ Bool floating;
+ Frame *f;
+ uint f_cnt;
+ Frame *sel;
+};
+
+struct View {
+ char* tag;
+ View* next;
+ Column* col; // list of columns
+ uint c_cnt; // number of columns
+ Column* c_sel; // (last) selected column
+ Floating *flt; // floating layer
+ Bool float_selected; // true if floating layer is focused
+ Scope *scope;
+};
+
+struct Scope {
+ Scope *prev;
+ Scope *next;
+ View *view;
+ View *sel;
+ Rect rect; // monitor resolution
+ Rect mnrect; // managed area
+};
+
+/* Configuration */
+struct {
+ Color normcolor;
+ Color selcolor;
+ Color focuscolor;
+ Color rollupcolor;
+
+ char *tag;
+
+ uint border;
+ uint barheight;
+ Rect frame_min;
+} def;
+
+struct {
+ Window win;
+ Frame *grabbed;
+ GC gc;
+ Pixmap stipple;
+} ghost;
+
+Scope *scope;
+Client *clients;
+View *views;
+View *sel_view;
+
+Display *dpy;
+Window root;
+int screen;
+GC gc;
+
+/* manage.c */
+void manage_window (Window *w);
+void destroy_client (Client *c);
+Bool tag_client (Client *c, const char *tag);
+void untag_client (Client *c, const char *tag);
+Bool move_frame (Frame *f, Area *dest);
+void moveresize_frame (Frame *f, int x, int y, uint w, uint h);
+void resize_column (Column *col, int x, uint w);
+void focus_frame (Frame *f);
+void show_view (View *v);
+
+/* helpers.c */
+Frame *get_frame (Scope *s, View *v, Area *a, Window win, Client *c);
+Frame *sel_of_view (View *v);
+Frame *visible_frame_of_client (Client *c);
+void attach_frame (Frame *f, Area *a);
+void detach_frame (Frame *f);
+Client *client_of_win (Window w);
+
+/* structures.c */
+View *get_view (const char* tag);
+void destroy_view (View *v);
+Column *create_column (View *v, Column *after);
+void destroy_column (Column *col);
+Frame *create_frame (Client *c, View *v);
+void destroy_frame (Frame *f);
+Client *create_client (Window w);
+Scope *init_scope (int x, int y, uint w, uint h);
+
+/* update.c */
+void update_view (View *v);
+void update_area (Area *a);
+void draw_frame (Frame *f);
+
+/* util.c */
+Bool point_in_rect (int x, int y, const Rect rect);
+Bool point_in_rect_xy (int x, int y, int rx, int ry, uint rw, uint rh);
+Color *parse_colors (const char *colstr, int len, Color *col);
+
+/* init.c */
+int wmii_error_handler(Display *dpy, XErrorEvent *error);
+int ignore_error_handler(Display *dpy, XErrorEvent *error);
+void error_handling ();
+void init_X11_server ();
+void init_graphics ();
+void deinit_graphics ();
+
+/* event.c */
+void check_x_event ();
+
+/* mouse.c */
+void mouse_button_press (int button, XButtonEvent *ev);
+void mouse_button_release (int button, XButtonEvent *ev);
+
+
+/* utilities */
+static inline int
+max (const int a, const int b)
+{ return a > b ? a : b; }
+
+static inline int
+min (const int a, const int b)
+{ return a < b ? a : b; }
+
+static inline void
+prect (Rect r)
+{ printf("%d %d %d %d\n", r.x, r.y, r.w, r.h); }
+
+static inline void
+pint (int i)
+{ printf("%d\n", i); }
Received on Sun Feb 04 2007 - 12:40:06 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:54:52 UTC