[hackers] [wmii] Preliminary work on new grab box handling. Added x11.[ch], removed unused draw.c.

From: Kris Maglione <jg_AT_suckless.org>
Date: Fri, 01 Jun 2007 01:09:22 -0000

changeset: 2090:abd8d21b6f92
user: Kris Maglione <jg_AT_suckless.org>
date: Tue Apr 17 14:00:15 2007 -0400
summary: Preliminary work on new grab box handling. Added x11.[ch], removed unused draw.c.

diff -r 6b739aab2a50 -r abd8d21b6f92 cmd/wmii/dat.h
--- a/cmd/wmii/dat.h Tue Apr 17 01:19:53 2007 -0400
+++ b/cmd/wmii/dat.h Tue Apr 17 14:00:15 2007 -0400
@@ -47,7 +47,7 @@ enum {
 enum {
         CurNormal,
         CurNECorner, CurNWCorner, CurSECorner, CurSWCorner,
- CurDHArrow, CurMove, CurInput, CurSizing,
+ CurDHArrow, CurMove, CurInput, CurSizing, CurIcon,
         CurInvisible,
         CurLast
 };
diff -r 6b739aab2a50 -r abd8d21b6f92 cmd/wmii/draw.c
--- a/cmd/wmii/draw.c Tue Apr 17 01:19:53 2007 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,215 +0,0 @@
-/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
- * See LICENSE file for license details.
- */
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <util.h>
-#include "dat.h"
-#include "fns.h"
-
-uint
-textwidth_l(BlitzFont *font, char *text, uint len) {
- if(font->set) {
- Rectangle r;
- XmbTextExtents(font->set, text, len, &r, nil);
- return r.width;
- }
- return XTextWidth(font->xfont, text, len);
-}
-
-uint
-textwidth(BlitzFont *font, char *text) {
- return textwidth_l(font, text, strlen(text));
-}
-
-void
-loadfont(Blitz *blitz, BlitzFont *font) {
- char *fontname = font->fontstr;
- char **missing = nil, *def = "?";
- int n, i;
-
- if(font->set)
- XFreeFontSet(blitz->dpy, font->set);
- font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
- if(missing) {
- fprintf(stderr, "%s: missing fontset%s for '%s':", argv0,
- (n > 1 ? "s":""), fontname);
- for(i = 0; i < n; i++)
- fprintf(stderr, "%s %s", (i ? ",":""), missing[i]);
- fprintf(stderr, "\n");
- XFreeStringList(missing);
- }
- if(font->set) {
- XFontSetExtents *font_extents;
- XFontStruct **xfonts;
- char **font_names;
-
- font->ascent = font->descent = 0;
- font_extents = XExtentsOfFontSet(font->set);
- XFontsOfFontSet(font->set, &xfonts, &font_names);
- font->ascent = xfonts[0]->ascent;
- font->descent = xfonts[0]->descent;
- }
- else {
- if(font->xfont)
- XFreeFont(blitz->dpy, font->xfont);
- font->xfont = nil;
- font->xfont = XLoadQueryFont(blitz->dpy, fontname);
- fprintf(stderr, "%s: cannot load font: %s\n", argv0, fontname);
- if(!font->xfont) {
- if(!strcmp(fontname, BLITZ_FONT))
- fatal("cannot load font: %s", BLITZ_FONT);
- free(font->fontstr);
- font->fontstr = estrdup(BLITZ_FONT);
- loadfont(blitz, font);
- return;
- }
- font->ascent = font->xfont->ascent;
- font->descent = font->xfont->descent;
- }
- font->height = font->ascent + font->descent;
-}
-
-uint
-labelh(BlitzFont *font) {
- return font->height + 2;
-}
-
-void
-draw_tile(BlitzBrush *b) {
- drawbg(b->blitz->dpy, b->drawable, b->gc, &b->rect,
- b->color, True, b->border);
-}
-
-void
-draw_border(BlitzBrush *b) {
- drawbg(b->blitz->dpy, b->drawable, b->gc, &b->rect,
- b->color, False, b->border);
-}
-
-void
-draw_label(BlitzBrush *b, char *text) {
- uint x, y, w, h, len;
- Bool shortened = False;
- static char buf[2048];
- Rectangle r = {0};
- XGCValues gcv;
-
- draw_tile(b);
- if(!text)
- return;
- shortened = 0;
- strncpy(buf, text, sizeof(buf));
- len = strlen(buf);
- gcv.foreground = b->color.fg;
- gcv.background = b->color.bg;
- h = b->font->ascent + b->font->descent;
- y = b->rect.y + b->rect.height / 2 - h / 2 + b->font->ascent;
- /* shorten text if necessary */
- while(len
- && (w = textwidth(b->font, buf)) > b->rect.width - (b->font->height & ~1)) {
- buf[--len] = 0;
- shortened = True;
- }
- if(!len)
- return;
- if(w > b->rect.width)
- return;
- /* mark shortened info in the string */
- if(shortened) {
- if (len > 3)
- buf[len - 3] = '.';
- if (len > 2)
- buf[len - 2] = '.';
- if (len > 1)
- buf[len - 1] = '.';
- }
-
- if(b->font->set)
- XmbTextExtents(b->font->set, text, len, &r, nil);
-
- switch (b->align) {
- case EAST:
- x = b->rect.x + b->rect.width - (w + (b->font->height / 2));
- break;
- default:
- x = b->rect.x + (b->font->height / 2) - r.x;
- break;
- }
- if(b->font->set) {
- XChangeGC(b->blitz->dpy, b->gc, GCForeground | GCBackground, &gcv);
- XmbDrawImageString(b->blitz->dpy, b->drawable, b->font->set, b->gc,
- x, y, buf, len);
- }
- else {
- gcv.font = b->font->xfont->fid;
- XChangeGC(b->blitz->dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv);
- XDrawImageString(b->blitz->dpy, b->drawable, b->gc, x, y, buf, len);
- }
-}
-
-void
-drawbg(Display *dpy, Drawable drawable, GC gc, Rectangle *rect,
- BlitzColor c, Bool fill, int border)
-{
- if(fill) {
- XSetForeground(dpy, gc, c.bg);
- XFillRectangles(dpy, drawable, gc, rect, 1);
- }
- if(border) {
- XSetLineAttributes(dpy, gc, border, LineSolid, CapButt, JoinMiter);
- XSetForeground(dpy, gc, c.border);
- XDrawRectangle(dpy, drawable, gc, rect->x + border / 2, rect->y + border / 2,
- rect->width - border, rect->height - border);
- }
-}
-
-static ulong
-xloadcolor(Blitz *blitz, char *colstr) {
- XColor color;
- char col[8];
-
- strncpy(col, colstr, sizeof(col));
- col[7] = 0;
- XAllocNamedColor(blitz->dpy,
- DefaultColormap(blitz->dpy, blitz->screen), col, &color, &color);
- return color.pixel;
-}
-
-int
-loadcolor(Blitz *blitz, BlitzColor *c) {
- if(!c->colstr || strlen(c->colstr) != 23)
- return -1;
- c->fg = xloadcolor(blitz, &c->colstr[0]);
- c->bg = xloadcolor(blitz, &c->colstr[8]);
- c->border = xloadcolor(blitz, &c->colstr[16]);
- return 0;
-}
-
-char *
-parse_colors(char **buf, int *buflen, BlitzColor *col) {
- static regex_t reg;
- static Bool compiled;
-
- if(!compiled) {
- compiled = 1;
- regcomp(&reg, "^#[0-9a-f]{6} #[0-9a-f]{6} #[0-9a-f]{6}",
- REG_EXTENDED|REG_NOSUB|REG_ICASE);
- }
-
- if(*buflen < 23 || regexec(&reg, *buf, 0, 0, 0))
- return "bad value";
-
- memcpy(col->colstr, *buf, 23);
- loadcolor(&blz, col);
-
- *buf += 23;
- *buflen -= 23;
- if(isspace(**buf)) {
- (*buf)++;
- (*buflen)--;
- }
- return nil;
-}
diff -r 6b739aab2a50 -r abd8d21b6f92 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Tue Apr 17 01:19:53 2007 -0400
+++ b/cmd/wmii/fns.h Tue Apr 17 14:00:15 2007 -0400
@@ -55,6 +55,7 @@ void apply_tags(Client*, const char*);
 /* column.c */
 void update_divs();
 void draw_div(Divide*);
+void setdiv(Divide*, int x);
 void arrange_column(Area*, Bool dirty);
 void resize_column(Area*, int w);
 void resize_colframe(Frame*, Rectangle*);
@@ -146,41 +147,47 @@ int win_proto(Window);
 int win_proto(Window);
 
 /* x11.c */
-XRectangle XRect(Rectangle r);
-int eqrect(Rectangle a, Rectangle b);
-Point addpt(Point p, Point q);
-Point subpt(Point p, Point q);
-Point divpt(Point p, Point q);
-Rectangle insetrect(Rectangle r, int n);
-Rectangle rectaddpt(Rectangle r, Point p);
-Rectangle rectsubpt(Rectangle r, Point p);
+XRectangle XRect(Rectangle);
+int eqrect(Rectangle, Rectangle);
+Point addpt(Point, Point);
+Point subpt(Point, Point);
+Point divpt(Point, Point);
+Rectangle insetrect(Rectangle, int);
+Rectangle rectaddpt(Rectangle, Point);
+Rectangle rectsubpt(Rectangle, Point);
 void initdisplay();
 Image * allocimage(int w, int h, int depth);
-void freeimage(Image *img);
-Window *createwindow(Window *parent, Rectangle r, int depth, uint class, WinAttr *wa, int valuemask);
-void destroywindow(Window *w);
-void setwinattr(Window *w, WinAttr *wa, int valmask);
-void reshapewin(Window *w, Rectangle r);
-void movewin(Window *w, Point pt);
-int mapwin(Window *w);
-int unmapwin(Window *w);
+void freeimage(Image *);
+Window *createwindow(Window *parent, Rectangle, int depth, uint class, WinAttr*, int valuemask);
+void destroywindow(Window*);
+void setwinattr(Window*, WinAttr*, int valmask);
+void reshapewin(Window*, Rectangle);
+void movewin(Window*, Point);
+int mapwin(Window*);
+int unmapwin(Window*);
+void lowerwin(Window*);
+void raisewin(Window*);
 Handlers* sethandler(Window*, Handlers*);
-Window* findwin(XWindow w);
-uint winprotocols(Window *w);
-void setshapemask(Window *dst, Image *src, Point pt);
-void border(Image *dst, Rectangle r, int w, ulong col);
-void fill(Image *dst, Rectangle r, ulong col);
+Window* findwin(XWindow);
+uint winprotocols(Window*);
+void setshapemask(Window *dst, Image *src, Point);
+void border(Image *dst, Rectangle, int w, ulong col);
+void fill(Image *dst, Rectangle, ulong col);
 void drawpoly(Image *dst, Point *pt, int np, int cap, int w, ulong col);
 void fillpoly(Image *dst, Point *pt, int np, ulong col);
 void drawline(Image *dst, Point p1, Point p2, int cap, int w, ulong col);
-void drawstring(Image *dst, Font *font, Rectangle r, Align align, char *text, ulong col);
-void copyimage(Image *dst, Rectangle r, Image *src, Point p);
-Bool namedcolor(char *name, ulong *ret);
-Bool loadcolor(CTuple *c, char *str);
-Font * loadfont(char *name);
-void freefont(Font *f);
-uint textwidth_l(Font *font, char *text, uint len);
-uint textwidth(Font *font, char *text);
-uint labelh(Font *font);
-Atom xatom(char *name);
-int grabpointer(Window *w, Window *confine, Cursor cur, int mask);
+void drawstring(Image *dst, Font *font, Rectangle, Align align, char *text, ulong col);
+void copyimage(Image *dst, Rectangle, Image *src, Point p);
+Bool namedcolor(char *name, ulong*);
+Bool loadcolor(CTuple*, char*);
+Font * loadfont(char*);
+void freefont(Font*);
+uint textwidth_l(Font*, char*, uint len);
+uint textwidth(Font*, char*);
+uint labelh(Font*);
+Atom xatom(char*);
+Point querypointer(Window*);
+void warppointer(Point);
+Point translate(Window*, Window*, Point);
+int grabpointer(Window*, Window *confine, Cursor cur, int mask);
+void ungrabpointer();
diff -r 6b739aab2a50 -r abd8d21b6f92 cmd/wmii/main.c
--- a/cmd/wmii/main.c Tue Apr 17 01:19:53 2007 -0400
+++ b/cmd/wmii/main.c Tue Apr 17 14:00:15 2007 -0400
@@ -175,6 +175,7 @@ init_cursors() {
         create_cursor(CurDHArrow, XC_sb_h_double_arrow);
         create_cursor(CurInput, XC_xterm);
         create_cursor(CurSizing, XC_sizing);
+ create_cursor(CurIcon, XC_icon);
 
         XAllocNamedColor(display, scr.colormap,
                         "black", &black,
diff -r 6b739aab2a50 -r abd8d21b6f92 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Tue Apr 17 01:19:53 2007 -0400
+++ b/cmd/wmii/mouse.c Tue Apr 17 14:00:15 2007 -0400
@@ -16,6 +16,260 @@ enum {
                 ButtonMask | PointerMotionMask
 };
 
+static Handlers handlers;
+
+enum { OHoriz, OVert };
+typedef struct Framewin Framewin;
+struct Framewin {
+ Window *w;
+ Frame *f;
+ Frame *rf;
+ Area *ra;
+ Rectangle gb;
+ Point pt;
+ int or;
+ int n;
+};
+
+static Rectangle
+framerect(Framewin *f) {
+ Rectangle r;
+ Point p;
+
+ r.min = ZP;
+ if(f->or == OHoriz) {
+ r.max.x = f->n;
+ r.max.y = f->gb.max.y + f->gb.min.y;
+ r = rectsubpt(r, Pt(0, Dy(r)/2));
+ }else {
+ r.max.x = f->gb.max.x + f->gb.min.x;
+ r.max.y = f->n;
+ r = rectsubpt(r, Pt(Dx(r)/2, 0));
+ }
+ r = rectaddpt(r, f->pt);
+
+ /* Keep onscreen */
+ p = ZP;
+ p.x -= min(r.min.x, 0);
+ p.x -= max(r.max.x - screen->rect.max.x, 0);
+ p.y -= min(r.min.y, 0);
+ p.y -= max(r.max.y - screen->brect.min.y, 0);
+ return rectaddpt(r, p);;
+}
+
+static void
+frameadjust(Framewin *f, Point pt, int or, int n) {
+ f->or = or;
+ f->n = n;
+ f->pt = pt;
+ reshapewin(f->w, framerect(f));
+}
+
+static Framewin*
+framewin(Frame *f, Point pt, int or, int n) {
+ WinAttr wa;
+ Framewin *fw;
+
+ fw = emallocz(sizeof *fw);
+ wa.override_redirect = True;
+ wa.event_mask = ExposureMask;
+ fw->w = createwindow(&scr.root, Rect(0, 0, 1, 1), scr.depth, InputOutput, &wa, CWEventMask);
+ fw->w->aux = fw;
+ sethandler(fw->w, &handlers);
+
+ fw->f = f;
+ fw->gb = f->grabbox;
+ frameadjust(fw, pt, or, n);
+
+ mapwin(fw->w);
+ raisewin(fw->w);
+
+ return fw;
+}
+
+static void
+framedestroy(Framewin *f) {
+ destroywindow(f->w);
+ free(f);
+}
+
+static void
+expose_event(Window *w, XExposeEvent *e) {
+ Rectangle r;
+ Framewin *f;
+ Image *buf;
+ CTuple *c;
+
+ f = w->aux;
+ c = &def.focuscolor;
+ buf = screen->ibuf;
+
+ r = rectsubpt(w->r, w->r.min);
+ fill(buf, r, c->bg);
+ border(buf, r, 1, c->border);
+ border(buf, f->gb, 1, c->border);
+ border(buf, insetrect(f->gb, -f->gb.min.x), 1, c->border);
+
+ copyimage(w, r, buf, ZP);
+}
+
+static Handlers handlers = {
+ .expose = expose_event,
+};
+
+static void
+vplace(Framewin *fw, Point pt) {
+ Frame *f;
+ Area *a;
+ View *v;
+
+ v = screen->sel;
+
+ for(a = v->area->next; a->next; a = a->next)
+ if(pt.x < a->rect.max.x)
+ break;
+
+ for(f = a->frame; f->anext; f = f->anext)
+ if(pt.y < f->rect.max.y)
+ break;
+
+ if(abs(pt.y - f->rect.min.y) < labelh(def.font)) {
+ pt.y = f->rect.min.y;
+ if(f == fw->f)
+ pt.y += Dy(fw->w->r)/2;
+ else if(f->aprev == fw->f)
+ pt.y += labelh(def.font);
+ }
+ else if(abs(pt.y - f->rect.max.y) < labelh(def.font)) {
+ if(f != fw->f) {
+ pt.y = f->rect.max.y;
+ if(f->anext == fw->f)
+ pt.y += Dy(fw->w->r)/2;
+ }
+ }
+
+ pt.x = a->rect.min.x;
+ frameadjust(fw, pt, OHoriz, Dx(a->rect));
+}
+
+static void
+hplace(Framewin *fw, Point pt) {
+ Area *a;
+ View *v;
+
+ v = screen->sel;
+
+ for(a = v->area->next; a->next; a = a->next)
+ if(pt.x < a->rect.max.x)
+ break;
+
+ if(pt.x - a->rect.min.x < Dx(a->rect)/2)
+ pt.x = a->rect.min.x;
+ else
+ pt.x = a->rect.max.x;
+
+ pt.y = a->rect.min.y;
+ frameadjust(fw, pt, OVert, Dy(a->rect));
+}
+
+static void
+do_managed_move(Client *c) {
+ Rectangle r;
+ WinAttr wa;
+ XEvent ev;
+ Framewin *fw;
+ Window *cwin;
+ Frame *f;
+ Point pt;
+ int y;
+
+ focus(c, False);
+ f = c->sel;
+
+ pt = querypointer(&scr.root);
+
+ pt.x = f->area->rect.min.x;
+ fw = framewin(f, pt, OHoriz, Dx(f->area->rect));
+
+ r = screen->rect;
+ r.min.y += fw->gb.min.y + Dy(fw->gb)/2;
+ r.max.y = r.min.y + 1;
+ cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
+ mapwin(cwin);
+
+horiz:
+ XUngrabPointer(display, CurrentTime);
+ if(!grabpointer(&scr.root, nil, cursor[CurIcon], MouseMask))
+ goto done;
+ warppointer(pt);
+ vplace(fw, pt);
+ for(;;) {
+ XMaskEvent(display, MouseMask | ExposureMask, &ev);
+ switch (ev.type) {
+ default:
+ break;
+ case Expose:
+ dispatch_event(&ev);
+ break;
+ case MotionNotify:
+ pt.x = ev.xmotion.x_root;
+ pt.y = ev.xmotion.y_root;
+
+ vplace(fw, pt);
+ break;
+ case ButtonPress:
+ switch(ev.xbutton.button) {
+ case 2:
+ goto vert;
+ }
+ break;
+ case ButtonRelease:
+ switch(ev.xbutton.button) {
+ case 1:
+ /* Move window */
+ goto done;
+ }
+ break;
+ }
+ }
+vert:
+ y = pt.y;
+ XUngrabPointer(display, CurrentTime);
+ if(!grabpointer(&scr.root, cwin, cursor[CurIcon], MouseMask))
+ goto done;
+ hplace(fw, pt);
+ for(;;) {
+ XMaskEvent(display, MouseMask | ExposureMask, &ev);
+ switch (ev.type) {
+ default:
+ break;
+ case Expose:
+ dispatch_event(&ev);
+ break;
+ case MotionNotify:
+ pt.x = ev.xmotion.x_root;
+ pt.y = ev.xmotion.y_root;
+
+ hplace(fw, pt);
+ break;
+ case ButtonRelease:
+ switch(ev.xbutton.button) {
+ case 1:
+ /* Move window */
+ goto done;
+ case 2:
+ pt.y = y;
+ goto horiz;
+ }
+ break;
+ }
+ }
+done:
+ XUngrabPointer(display, CurrentTime);
+ framedestroy(fw);
+ destroywindow(cwin);
+}
+
 static Window *
 gethsep(Rectangle r) {
         Window *w;
@@ -24,319 +278,8 @@ gethsep(Rectangle r) {
         wa.background_pixel = def.normcolor.border;
         w = createwindow(&scr.root, r, scr.depth, InputOutput, &wa, CWBackPixel);
         mapwin(w);
- XRaiseWindow(display, w->w);
+ raisewin(w);
         return w;
-}
-
-static void
-rect_morph_xy(Rectangle *r, Point d, Align *mask) {
- int n;
-
- if(*mask & NORTH)
- r->min.y += d.y;
- if(*mask & WEST)
- r->min.x += d.x;
- if(*mask & SOUTH)
- r->max.y += d.y;
- if(*mask & EAST)
- r->max.x += d.x;
-
- if(r->min.x > r->max.x) {
- n = r->min.x;
- r->min.x = r->max.x;
- r->max.x = n;
- *mask ^= EAST|WEST;
- }
- if(r->min.y > r->max.y) {
- n = r->min.y;
- r->min.y = r->max.y;
- r->max.y = n;
- *mask ^= NORTH|SOUTH;
- }
-}
-
-typedef struct {
- Rectangle *rects;
- int num;
- Rectangle r;
- int x, y;
- int dx, dy;
- Align mask;
-} SnapArgs;
-
-static void
-snap_line(SnapArgs *a) {
- Rectangle *r;
- int i, x, y;
-
- if(a->mask & (NORTH|SOUTH)) {
- for(i=0; i < a->num; i++) {
- r = &a->rects[i];
- if((r->min.x <= a->r.max.x) && (r->max.x >= a->r.min.x)) {
- y = r->min.y;
- if(abs(y - a->y) <= abs(a->dy))
- a->dy = y - a->y;
-
- y = r->max.y;
- if(abs(y - a->y) <= abs(a->dy))
- a->dy = y - a->y;
- }
- }
- }else {
- for(i=0; i < a->num; i++) {
- r = &a->rects[i];
- if((r->min.y <= a->r.max.y) && (r->max.y >= a->r.min.y)) {
- x = r->min.x;
- if(abs(x - a->x) <= abs(a->dx))
- a->dx = x - a->x;
-
- x = r->max.x;
- if(abs(x - a->x) <= abs(a->dx))
- a->dx = x - a->x;
- }
- }
- }
-}
-
-/* Returns a gravity for increment handling. It's normally the opposite of the mask
- * (the directions that we're resizing in), unless a snap occurs, in which case, it's the
- * direction of the snap.
- */
-Align
-snap_rect(Rectangle *rects, int num, Rectangle *r, Align *mask, int snap) {
- SnapArgs a = { 0, };
- Align ret;
-
- a.rects = rects;
- a.num = num;
- a.dx = snap + 1;
- a.dy = snap + 1;
- a.r = *r;
-
- a.mask = NORTH|SOUTH;
- if(*mask & NORTH) {
- a.y = r->min.y;
- snap_line(&a);
- }
- if(*mask & SOUTH) {
- a.y = r->max.y;
- snap_line(&a);
- }
-
- a.mask = EAST|WEST;
- if(*mask & EAST) {
- a.x = r->max.x;
- snap_line(&a);
- }
- if(*mask & WEST) {
- a.x = r->min.x;
- snap_line(&a);
- }
-
- ret = CENTER;
- if(abs(a.dx) <= snap)
- ret ^= EAST|WEST;
- else
- a.dx = 0;
-
- if(abs(a.dy) <= snap)
- ret ^= NORTH|SOUTH;
- else
- a.dy = 0;
-
- rect_morph_xy(r, Pt(a.dx, a.dy), mask);
- return ret ^ *mask;
-}
-
-static void
-xorborder(Rectangle r) {
- Rectangle r2;
- ulong col;
-
- col = def.focuscolor.bg;
-
- r2 = insetrect(r, 4);
-
- if(Dy(r) > 4 && Dx(r) > 2)
- drawline(&xor,
- Pt(r2.min.x, r2.min.y + Dy(r2)/2),
- Pt(r2.max.x, r2.min.y + Dy(r2)/2),
- CapNotLast, 1, col);
- if(Dx(r) > 4 && Dy(r) > 2)
- drawline(&xor,
- Pt(r2.min.x + Dx(r2)/2, r.min.y),
- Pt(r2.min.x + Dx(r2)/2, r.max.y),
- CapNotLast, 1, col);
- border(&xor, r, 4, col);
-}
-
-static void
-xorrect(Rectangle r) {
- fill(&xor, r, 0x00888888L);
-}
-
-static void
-find_droppoint(Frame *frame, Point pt, Rectangle *r, Bool do_move) {
- enum { Delta = 5 };
- View *v;
- Area *a, *a_prev;
- Frame *f;
- Bool before;
-
- v = frame->view;
-
- /* New column? */
- a_prev = v->area;
- for(a = a_prev->next; a && a->next; a = a->next) {
- if(pt.x < a->rect.max.x)
- break;
- a_prev = a;
- }
-
- r->min.y = screen->rect.min.y;
- r->max.y = screen->brect.min.y;
- if(pt.x < (a->rect.min.x + labelh(def.font))) {
- r->min.x = a->rect.min.x - Delta;
- r->max.x = a->rect.min.x + Delta;
- if(do_move) {
- a = new_column(v, a_prev, 0);
- send_to_area(a, frame);
- focus(frame->client, False);
- }
- return;
- }
- if(pt.x > (a->rect.max.x - labelh(def.font))) {
- r->min.x = a->rect.max.x - Delta;
- r->max.x = a->rect.max.x + Delta;
- if(do_move) {
- a = new_column(v, a, 0);
- send_to_area(a, frame);
- focus(frame->client, False);
- }
- return;
- }
-
- /* Over/under frame? */
- for(f = a->frame; f; f = f->anext)
- if(pt.y < f->rect.max.y || f->anext == nil)
- break;
-
- *r = a->rect;
- if(pt.y < (f->rect.min.y + labelh(def.font))) {
- before = True;
- r->min.y = f->rect.min.y - Delta;
- r->max.y = f->rect.min.y + Delta;
- if(do_move)
- goto do_move;
- return;
- }
- if(pt.y > f->rect.max.y - labelh(def.font)) {
- before = False;
- r->min.y = f->rect.max.y - Delta;
- r->max.y = f->rect.max.y + Delta;
- if(do_move)
- goto do_move;
- return;
- }
-
- /* No? Swap. */
- *r = f->rect;
- if(do_move) {
- swap_frames(frame, f);
- focus(frame->client, False);
- focus_view(screen, f->view);
- }
- return;
-
-do_move:
- if(frame == f)
- return;
- if(a != frame->area)
- send_to_area(a, frame);
- remove_frame(frame);
- insert_frame(f, frame, before);
- arrange_column(f->area, False);
- focus(frame->client, True);
-}
-
-Point
-querypointer(Window *w) {
- XWindow dummy;
- Point pt;
- uint ui;
- int i;
-
- XQueryPointer(display, w->w, &dummy, &dummy, &i, &i, &pt.x, &pt.y, &ui);
- return pt;
-}
-
-void
-warppointer(Point pt) {
- XWarpPointer(display,
- /* src, dest w */ None, scr.root.w,
- /* src_rect */ 0, 0, 0, 0,
- /* target */ pt.x, pt.y);
-}
-
-Point
-translate(Window *src, Window *dst, Point sp) {
- Point pt;
- XWindow w;
-
- XTranslateCoordinates(display, src->w, dst->w, sp.x, sp.y, &pt.x, &pt.y, &w);
- return pt;
-}
-
-static void
-do_managed_move(Client *c) {
- Rectangle frect, ofrect;
- XEvent ev;
- Frame *f;
- Point pt;
-
- focus(c, False);
- f = c->sel;
-
- XSync(display, False);
- if(!grabpointer(c->framewin, nil, cursor[CurMove], MouseMask))
- return;
- XGrabServer(display);
-
- pt = querypointer(&scr.root);
-
- find_droppoint(f, pt, &frect, False);
- xorrect(frect);
- for(;;) {
- XMaskEvent(display, MouseMask | ExposureMask, &ev);
- switch (ev.type) {
- default:
- break;
- case Expose:
- dispatch_event(&ev);
- break;
- case MotionNotify:
- ofrect = frect;
- pt.x = ev.xmotion.x_root;
- pt.y = ev.xmotion.y_root;
-
- find_droppoint(f, pt, &frect, False);
-
- if(!eqrect(frect, ofrect)) {
- xorrect(ofrect);
- xorrect(frect);
- }
- break;
- case ButtonRelease:
- xorrect(frect);
-
- find_droppoint(f, pt, &frect, True);
-
- XUngrabServer(display);
- XUngrabPointer(display, CurrentTime);
- XSync(display, False);
- return;
- }
- }
 }
 
 void
@@ -509,6 +452,148 @@ done:
         destroywindow(cwin);
 }
 
+static void
+xorborder(Rectangle r) {
+ Rectangle r2;
+ ulong col;
+
+ col = def.focuscolor.bg;
+
+ r2 = insetrect(r, 4);
+
+ if(Dy(r) > 4 && Dx(r) > 2)
+ drawline(&xor,
+ Pt(r2.min.x, r2.min.y + Dy(r2)/2),
+ Pt(r2.max.x, r2.min.y + Dy(r2)/2),
+ CapNotLast, 1, col);
+ if(Dx(r) > 4 && Dy(r) > 2)
+ drawline(&xor,
+ Pt(r2.min.x + Dx(r2)/2, r.min.y),
+ Pt(r2.min.x + Dx(r2)/2, r.max.y),
+ CapNotLast, 1, col);
+ border(&xor, r, 4, col);
+}
+
+static void
+rect_morph_xy(Rectangle *r, Point d, Align *mask) {
+ int n;
+
+ if(*mask & NORTH)
+ r->min.y += d.y;
+ if(*mask & WEST)
+ r->min.x += d.x;
+ if(*mask & SOUTH)
+ r->max.y += d.y;
+ if(*mask & EAST)
+ r->max.x += d.x;
+
+ if(r->min.x > r->max.x) {
+ n = r->min.x;
+ r->min.x = r->max.x;
+ r->max.x = n;
+ *mask ^= EAST|WEST;
+ }
+ if(r->min.y > r->max.y) {
+ n = r->min.y;
+ r->min.y = r->max.y;
+ r->max.y = n;
+ *mask ^= NORTH|SOUTH;
+ }
+}
+
+typedef struct {
+ Rectangle *rects;
+ int num;
+ Rectangle r;
+ int x, y;
+ int dx, dy;
+ Align mask;
+} SnapArgs;
+
+static void
+snap_line(SnapArgs *a) {
+ Rectangle *r;
+ int i, x, y;
+
+ if(a->mask & (NORTH|SOUTH)) {
+ for(i=0; i < a->num; i++) {
+ r = &a->rects[i];
+ if((r->min.x <= a->r.max.x) && (r->max.x >= a->r.min.x)) {
+ y = r->min.y;
+ if(abs(y - a->y) <= abs(a->dy))
+ a->dy = y - a->y;
+
+ y = r->max.y;
+ if(abs(y - a->y) <= abs(a->dy))
+ a->dy = y - a->y;
+ }
+ }
+ }else {
+ for(i=0; i < a->num; i++) {
+ r = &a->rects[i];
+ if((r->min.y <= a->r.max.y) && (r->max.y >= a->r.min.y)) {
+ x = r->min.x;
+ if(abs(x - a->x) <= abs(a->dx))
+ a->dx = x - a->x;
+
+ x = r->max.x;
+ if(abs(x - a->x) <= abs(a->dx))
+ a->dx = x - a->x;
+ }
+ }
+ }
+}
+
+/* Returns a gravity for increment handling. It's normally the opposite of the mask
+ * (the directions that we're resizing in), unless a snap occurs, in which case, it's the
+ * direction of the snap.
+ */
+Align
+snap_rect(Rectangle *rects, int num, Rectangle *r, Align *mask, int snap) {
+ SnapArgs a = { 0, };
+ Align ret;
+
+ a.rects = rects;
+ a.num = num;
+ a.dx = snap + 1;
+ a.dy = snap + 1;
+ a.r = *r;
+
+ a.mask = NORTH|SOUTH;
+ if(*mask & NORTH) {
+ a.y = r->min.y;
+ snap_line(&a);
+ }
+ if(*mask & SOUTH) {
+ a.y = r->max.y;
+ snap_line(&a);
+ }
+
+ a.mask = EAST|WEST;
+ if(*mask & EAST) {
+ a.x = r->max.x;
+ snap_line(&a);
+ }
+ if(*mask & WEST) {
+ a.x = r->min.x;
+ snap_line(&a);
+ }
+
+ ret = CENTER;
+ if(abs(a.dx) <= snap)
+ ret ^= EAST|WEST;
+ else
+ a.dx = 0;
+
+ if(abs(a.dy) <= snap)
+ ret ^= NORTH|SOUTH;
+ else
+ a.dy = 0;
+
+ rect_morph_xy(r, Pt(a.dx, a.dy), mask);
+ return ret ^ *mask;
+}
+
 void
 do_mouse_resize(Client *c, Bool opaque, Align align) {
         XEvent ev;
diff -r 6b739aab2a50 -r abd8d21b6f92 cmd/wmii/x11.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/wmii/x11.c Tue Apr 17 14:00:15 2007 -0400
@@ -0,0 +1,575 @@
+/* Copyright ©2007 Kris Maglione <fbsdaemon_AT_gmail.com>
+ * See LICENSE file for license details.
+ */
+#include <assert.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <util.h>
+#include "dat.h"
+#include "fns.h"
+
+Point ZP = {0, 0};
+Rectangle ZR = {{0, 0}, {0, 0}};
+
+Window wlist;
+
+XRectangle
+XRect(Rectangle r) {
+ XRectangle xr;
+
+ xr.x = r.min.x;
+ xr.y = r.min.y;
+ xr.width = Dx(r);
+ xr.height = Dy(r);
+ return xr;
+}
+
+int
+eqrect(Rectangle a, Rectangle b) {
+ return a.min.x==b.min.x && a.max.x==b.max.x
+ && a.min.y==b.min.y && a.max.y==b.max.y;
+}
+
+Point
+addpt(Point p, Point q) {
+ p.x += q.x;
+ p.y += q.y;
+ return p;
+}
+
+Point
+subpt(Point p, Point q) {
+ p.x -= q.x;
+ p.y -= q.y;
+ return p;
+}
+
+Point
+divpt(Point p, Point q) {
+ p.x *= q.x;
+ p.y *= q.y;
+ return p;
+}
+
+Rectangle
+insetrect(Rectangle r, int n) {
+ r.min.x += n;
+ r.min.y += n;
+ r.max.x -= n;
+ r.max.y -= n;
+ return r;
+}
+
+Rectangle
+rectaddpt(Rectangle r, Point p) {
+ r.min.x += p.x;
+ r.max.x += p.x;
+ r.min.y += p.y;
+ r.max.y += p.y;
+ return r;
+}
+
+Rectangle
+rectsubpt(Rectangle r, Point p) {
+ r.min.x -= p.x;
+ r.max.x -= p.x;
+ r.min.y -= p.y;
+ r.max.y -= p.y;
+ return r;
+}
+
+/* Init */
+void
+initdisplay() {
+ display = XOpenDisplay(nil);
+ scr.screen = DefaultScreen(display);
+ scr.colormap = DefaultColormap(display, scr.screen);
+ scr.visual = DefaultVisual(display, scr.screen);
+ scr.gc = DefaultGC(display, scr.screen);
+ scr.depth = DefaultDepth(display, scr.screen);
+
+ scr.white = WhitePixel(display, scr.screen);
+ scr.black = BlackPixel(display, scr.screen);
+
+ scr.root.w = RootWindow(display, scr.screen);
+ scr.root.r = Rect(0, 0, DisplayWidth(display, scr.screen), DisplayHeight(display, scr.screen));
+ scr.rect = scr.root.r;
+
+ wlist.next = wlist.prev = &wlist;
+}
+
+/* Images */
+Image *
+allocimage(int w, int h, int depth) {
+ Image *img;
+
+ img = emallocz(sizeof *img);
+ img->type = WImage;
+ img->image = XCreatePixmap(display, scr.root.w,
+ w, h, depth);
+ img->gc = XCreateGC(display, img->image, 0, nil);
+ img->depth = depth;
+ img->r = Rect(0, 0, w, h);
+ return img;
+}
+
+void
+freeimage(Image *img) {
+ assert(img->type == WImage);
+
+ XFreePixmap(display, img->image);
+ XFreeGC(display, img->gc);
+}
+
+/* Windows */
+Window *
+createwindow(Window *parent, Rectangle r, int depth, uint class,
+ WinAttr *wa, int valmask)
+ {
+ Window *w;
+
+ assert(parent->type == WWindow);
+
+ w = emallocz(sizeof *w);
+ w->type = WWindow;
+
+ w->w = XCreateWindow(display, parent->w, r.min.x, r.min.y, Dx(r), Dy(r),
+ 0 /* border */, depth, class, scr.visual, valmask, wa);
+
+ if(class != InputOnly) {
+ w->gc = XCreateGC(display, w->w, 0, nil);
+ w->image = w->w;
+ }
+
+ w->r = r;
+ w->depth = depth;
+ return w;
+}
+
+void
+destroywindow(Window *w) {
+ assert(w->type == WWindow);
+ if(w->gc)
+ XFreeGC(display, w->gc);
+ XDestroyWindow(display, w->w);
+ sethandler(w, nil);
+}
+
+void
+setwinattr(Window *w, WinAttr *wa, int valmask) {
+ assert(w->type == WWindow);
+ XChangeWindowAttributes(display, w->w, valmask, wa);
+}
+
+void
+reshapewin(Window *w, Rectangle r) {
+ assert(w->type == WWindow);
+ if(!eqrect(r, w->r))
+ XMoveResizeWindow(display, w->w, r.min.x, r.min.y, Dx(r), Dy(r));
+ w->r = r;
+}
+
+void
+movewin(Window *w, Point pt) {
+ Rectangle r;
+
+ assert(w->type == WWindow);
+ r = rectsubpt(w->r, w->r.min);
+ r = rectaddpt(w->r, pt);
+ reshapewin(w, r);
+}
+
+int
+mapwin(Window *w) {
+ if(!w->mapped) {
+ XMapWindow(display, w->w);
+ w->mapped = 1;
+ return 1;
+ }
+ return 0;
+}
+
+int
+unmapwin(Window *w) {
+ if(w->mapped) {
+ XUnmapWindow(display, w->w);
+ w->mapped = 0;
+ w->unmapped++;
+ return 1;
+ }
+ return 0;
+}
+
+void
+raisewin(Window *w) {
+ XRaiseWindow(display, w->w);
+}
+
+void
+lowerwin(Window *w) {
+ XLowerWindow(display, w->w);
+}
+
+Handlers*
+sethandler(Window *w, Handlers *new) {
+ Handlers *old;
+ Window *wp;
+
+ assert(w->type == WWindow);
+
+ old = w->handler;
+ if(new == nil && w->prev) {
+ w->prev->next = w->next;
+ w->next->prev = w->prev;
+ w->next = w->prev = nil;
+ }else {
+ for(wp = wlist.next; wp != &wlist; wp = wp->next)
+ if(w->w <= wp->w) break;
+ if(wp->w != w->w) {
+ w->next = wp;
+ w->prev = wp->prev;
+ wp->prev = w;
+ w->prev->next = w;
+ }
+ }
+ w->handler = new;
+ return old;
+}
+
+Window*
+findwin(XWindow w) {
+ Window *wp;
+
+ for(wp = wlist.next; wp != &wlist; wp=wp->next)
+ if(wp->w >= w) break;
+ if(wp->w == w)
+ return wp;
+ return nil;
+}
+
+uint
+winprotocols(Window *w) {
+ Atom *protocols;
+ Atom real;
+ ulong nitems, extra;
+ int i, format, status, protos;
+
+ status = XGetWindowProperty(
+ display, w->w, atom[WMProtocols],
+ /* offset, length, delete, req_type */
+ 0L, 20L, False, XA_ATOM,
+ /* type, format, nitems, extra bytes returns */
+ &real, &format, &nitems, &extra,
+ /* property return */
+ (uchar**)&protocols);
+
+ if(status != Success || protocols == nil)
+ return 0;
+
+ if(nitems == 0) {
+ XFree(protocols);
+ return 0;
+ }
+
+ protos = 0;
+ for(i = 0; i < nitems; i++) {
+ if(protocols[i] == atom[WMDelete])
+ protos |= WM_PROTOCOL_DELWIN;
+ }
+
+ XFree(protocols);
+ return protos;
+}
+
+/* Shape */
+void
+setshapemask(Window *dst, Image *src, Point pt) {
+ XShapeCombineMask (display, dst->w,
+ ShapeBounding, pt.x, pt.y, src->image, ShapeSet);
+}
+
+/* Drawing */
+void
+border(Image *dst, Rectangle r, int w, ulong col) {
+ if(w == 0)
+ return;
+
+ r = insetrect(r, w/2);
+ r.max.x -= w%2;
+ r.max.y -= w%2;
+
+ XSetLineAttributes(display, dst->gc, w, LineSolid, CapButt, JoinMiter);
+ XSetForeground(display, dst->gc, col);
+ XDrawRectangle(display, dst->image, dst->gc,
+ r.min.x, r.min.y, Dx(r), Dy(r));
+}
+
+void
+fill(Image *dst, Rectangle r, ulong col) {
+ XSetForeground(display, dst->gc, col);
+ XFillRectangle(display, dst->image, dst->gc,
+ r.min.x, r.min.y, Dx(r), Dy(r));
+}
+
+static XPoint*
+convpts(Point *pt, int np) {
+ XPoint *rp;
+ int i;
+
+ rp = emalloc(np * sizeof(*rp));
+ for(i = 0; i < np; i++) {
+ rp[i].x = pt[i].x;
+ rp[i].y = pt[i].y;
+ }
+ return rp;
+}
+
+void
+drawpoly(Image *dst, Point *pt, int np, int cap, int w, ulong col) {
+ XPoint *xp;
+
+ xp = convpts(pt, np);
+ XSetLineAttributes(display, dst->gc, w, LineSolid, cap, JoinMiter);
+ XSetForeground(display, dst->gc, col);
+ XDrawLines(display, dst->image, dst->gc, xp, np, CoordModeOrigin);
+ free(xp);
+}
+
+void
+fillpoly(Image *dst, Point *pt, int np, ulong col) {
+ XPoint *xp;
+
+ xp = convpts(pt, np);
+ XSetForeground(display, dst->gc, col);
+ XFillPolygon(display, dst->image, dst->gc, xp, np, Complex, CoordModeOrigin);
+ free(xp);
+}
+
+void
+drawline(Image *dst, Point p1, Point p2, int cap, int w, ulong col) {
+ XSetLineAttributes(display, dst->gc, w, LineSolid, cap, JoinMiter);
+ XSetForeground(display, dst->gc, col);
+ XDrawLine(display, dst->image, dst->gc, p1.x, p1.y, p2.x, p2.y);
+}
+
+void
+drawstring(Image *dst, Font *font,
+ Rectangle r, Align align,
+ char *text, ulong col) {
+ char *buf;
+ uint x, y, w, h, len;
+ Bool shortened;
+
+ shortened = 0;
+
+ len = strlen(text);
+ buf = emalloc(len+1);
+ memcpy(buf, text, len+1);
+
+ h = font->ascent + font->descent;
+ y = r.min.y + Dy(r) / 2 - h / 2 + font->ascent;
+
+ /* shorten text if necessary */
+ while(len > 0) {
+ w = textwidth_l(font, buf, len + min(shortened, 3));
+ if(w <= Dx(r) - (font->height & ~1))
+ break;
+
+ buf[--len] = '.';
+ shortened++;
+ }
+
+ if(len == 0 || w > Dx(r))
+ goto done;
+
+ /* mark shortened info in the string */
+ if(shortened)
+ len += min(shortened, 3);
+
+ switch (align) {
+ case EAST:
+ x = r.max.x - (w + (font->height / 2));
+ break;
+ default:
+ x = r.min.x + (font->height / 2);
+ break;
+ }
+
+ XSetForeground(display, dst->gc, col);
+ if(font->set)
+ XmbDrawString(display, dst->image,
+ font->set, dst->gc,
+ x, y,
+ buf, len);
+ else {
+ XSetFont(display, dst->gc, font->xfont->fid);
+ XDrawString(display, dst->image, dst->gc,
+ x, y,
+ buf, len);
+ }
+
+done:
+ free(buf);
+}
+
+void
+copyimage(Image *dst, Rectangle r, Image *src, Point p) {
+ XCopyArea(display,
+ src->image, dst->image,
+ dst->gc,
+ r.min.x, r.min.y, Dx(r), Dy(r),
+ p.x, p.y);
+}
+
+/* Colors */
+Bool
+namedcolor(char *name, ulong *ret) {
+ XColor c, c2;
+
+ if(XAllocNamedColor(display, scr.colormap, name, &c, &c2)) {
+ *ret = c.pixel;
+ return 1;
+ }
+ return 0;
+}
+
+Bool
+loadcolor(CTuple *c, char *str) {
+ char buf[24];
+
+ strncpy(buf, str, sizeof buf);
+ memcpy(c->colstr, str, sizeof c->colstr);
+
+ buf[7] = buf[15] = buf[23] = '\0';
+ return namedcolor(buf, &c->fg)
+ && namedcolor(buf+8, &c->bg)
+ && namedcolor(buf+16, &c->border);
+}
+
+/* Fonts */
+Font *
+loadfont(char *name) {
+ Font *f;
+ char **missing = nil, *def = "?";
+ int n, i;
+
+ f = emallocz(sizeof *f);
+ f->name = estrdup(name);
+
+ f->set = XCreateFontSet(display, name, &missing, &n, &def);
+ if(missing) {
+ fprintf(stderr, "%s: missing fontset%s for '%s':", argv0,
+ (n > 1 ? "s":""), name);
+ for(i = 0; i < n; i++)
+ fprintf(stderr, "%s %s", (i ? ",":""), missing[i]);
+ fprintf(stderr, "\n");
+ XFreeStringList(missing);
+ }
+
+ if(f->set) {
+ XFontStruct **xfonts;
+ char **font_names;
+
+ XFontsOfFontSet(f->set, &xfonts, &font_names);
+ f->ascent = xfonts[0]->ascent;
+ f->descent = xfonts[0]->descent;
+ }
+ else {
+ f->xfont = XLoadQueryFont(display, name);
+ if(!f->xfont) {
+ fprintf(stderr, "%s: cannot load font: %s\n", argv0, name);
+ freefont(f);
+ return nil;
+ }
+
+ f->ascent = f->xfont->ascent;
+ f->descent = f->xfont->descent;
+ }
+ f->height = f->ascent + f->descent;
+ return f;
+}
+
+void
+freefont(Font *f) {
+ if(f->set)
+ XFreeFontSet(display, f->set);
+ if(f->xfont)
+ XFreeFont(display, f->xfont);
+ free(f->name);
+ free(f);
+}
+
+uint
+textwidth_l(Font *font, char *text, uint len) {
+ XRectangle r;
+
+ if(font->set) {
+ XmbTextExtents(font->set, text, len, &r, nil);
+ return r.width;
+ }
+ return XTextWidth(font->xfont, text, len);
+}
+
+uint
+textwidth(Font *font, char *text) {
+ return textwidth_l(font, text, strlen(text));
+}
+
+uint
+labelh(Font *font) {
+ return font->height + 2;
+}
+
+/* Misc */
+Atom
+xatom(char *name) {
+ return XInternAtom(display, name, False);
+}
+
+/* Mouse */
+Point
+querypointer(Window *w) {
+ XWindow dummy;
+ Point pt;
+ uint ui;
+ int i;
+
+ XQueryPointer(display, w->w, &dummy, &dummy, &i, &i, &pt.x, &pt.y, &ui);
+ return pt;
+}
+
+void
+warppointer(Point pt) {
+ XWarpPointer(display,
+ /* src, dest w */ None, scr.root.w,
+ /* src_rect */ 0, 0, 0, 0,
+ /* target */ pt.x, pt.y);
+}
+
+Point
+translate(Window *src, Window *dst, Point sp) {
+ Point pt;
+ XWindow w;
+
+ XTranslateCoordinates(display, src->w, dst->w, sp.x, sp.y, &pt.x, &pt.y, &w);
+ return pt;
+}
+
+int
+grabpointer(Window *w, Window *confine, Cursor cur, int mask) {
+ XWindow cw;
+
+ cw = None;
+ if(confine)
+ cw = confine->w;
+ return XGrabPointer(display, w->w, False /* owner events */, mask,
+ GrabModeAsync, GrabModeAsync, cw, cur, CurrentTime
+ ) == GrabSuccess;
+}
+
+void
+ungrabpointer() {
+ XUngrabPointer(display, CurrentTime);
+}
diff -r 6b739aab2a50 -r abd8d21b6f92 cmd/wmii/x11.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/wmii/x11.h Tue Apr 17 14:00:15 2007 -0400
@@ -0,0 +1,102 @@
+#define Window XWindow
+#define Font XFont
+#define Screen XScreen
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+#include <X11/extensions/shape.h>
+#undef Window
+#undef Font
+#undef Screen
+
+typedef struct Point Point;
+typedef struct Rectangle Rectangle;
+typedef struct Screen Screen;
+typedef struct Window Window;
+typedef struct Handlers Handlers;
+typedef struct Window Image;
+typedef struct Font Font;
+typedef XSetWindowAttributes WinAttr;
+
+struct Point {
+ int x, y;
+};
+
+struct Rectangle {
+ Point min, max;
+};
+
+struct Window {
+ int type;
+ XWindow w;
+ Drawable image;
+ GC gc;
+ Rectangle r;
+ void *aux;
+ Handlers *handler;
+ Window *next, *prev;
+ Bool mapped;
+ int unmapped;
+ int depth;
+};
+
+struct Handlers {
+ void (*bdown)(Window*, XButtonEvent*);
+ void (*bup)(Window*, XButtonEvent*);
+ void (*kdown)(Window*, XKeyEvent*);
+ void (*kup)(Window*, XKeyEvent*);
+ void (*focusin)(Window*, XFocusChangeEvent*);
+ void (*focusout)(Window*, XFocusChangeEvent*);
+ void (*enter)(Window*, XCrossingEvent*);
+ void (*leave)(Window*, XCrossingEvent*);
+ void (*motion)(Window*, XMotionEvent*);
+ void (*destroy)(Window*, XDestroyWindowEvent*);
+ void (*configreq)(Window*, XConfigureRequestEvent*);
+ void (*map)(Window*, XMapEvent*);
+ void (*unmap)(Window*, XUnmapEvent*);
+ void (*property)(Window*, XPropertyEvent*);
+ void (*expose)(Window*, XExposeEvent*);
+};
+
+struct Screen {
+ int screen;
+ Window root;
+ Colormap colormap;
+ Visual *visual;
+ Rectangle rect;
+ GC gc;
+ int depth;
+ int fd;
+ ulong black, white;
+};
+
+enum { WWindow, WImage };
+
+struct Font {
+ XFontStruct *xfont;
+ XFontSet set;
+ int ascent;
+ int descent;
+ uint height;
+ char *name;
+};
+
+Display *display;
+Screen scr;
+
+extern Point ZP;
+extern Rectangle ZR;
+
+Rectangle insetrect(Rectangle r, int n);
+
+Point Pt(int x, int y);
+Rectangle Rect(int x0, int y0, int x1, int y1);
+Rectangle Rpt(Point min, Point max);
+
+XRectangle XRect(Rectangle r);
+
+#define Dx(r) ((r).max.x - (r).min.x)
+#define Dy(r) ((r).max.y - (r).min.y)
+#define Pt(x, y) ((Point){(x), (y)})
+#define Rpt(p, q) ((Rectangle){p, q})
+#define Rect(x0, y0, x1, y1) ((Rectangle){Pt(x0, y0), Pt(x1, y1)})
Received on Fri Jun 01 2007 - 03:09:21 UTC

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