wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit f398f6970af6ee0c16e903a16cc8b6f53fec396c
parent 185ed448a6c709c569d61f63adba2f4ead6cd000
Author: Mikhail Gusarov <mag@wmii.de>
Date:   Mon, 12 Jun 2006 18:39:54 +0700

merge


Diffstat:
cmd/wm/Makefile | 4++--
cmd/wm/client.c | 2+-
cmd/wm/column.c | 6+++---
cmd/wm/event.c | 4++--
cmd/wm/fs.c | 2+-
cmd/wm/geom.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
cmd/wm/wm.h | 5+++++
liblitz/Makefile | 2+-
liblitz/blitz.c | 20++++++++++++++++++++
liblitz/blitz.h | 44++++++++++++++++++++++++++------------------
liblitz/draw.c | 2+-
liblitz/font.c | 2+-
liblitz/geometry.c | 51---------------------------------------------------
liblitz/window.c | 43+++++++++++++++++++++++++++++++++++++++++++
14 files changed, 155 insertions(+), 81 deletions(-)

diff --git a/cmd/wm/Makefile b/cmd/wm/Makefile @@ -9,8 +9,8 @@ LDFLAGS += -L../../liblitz -llitz -L../../libixp -lixp -L../../libcext -lcext - # Solaris # LDFLAGS += -lsocket -SRC = area.c bar.c client.c column.c event.c frame.c fs.c key.c mouse.c \ - rule.c view.c wm.c +SRC = area.c bar.c client.c column.c event.c frame.c fs.c geom.c \ + key.c mouse.c rule.c view.c wm.c OBJ = ${SRC:.c=.o} all: wmiiwm diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -29,7 +29,7 @@ update_client_name(Client *c) if(name.encoding == XA_STRING) cext_strlcpy(c->name, (char *)name.value, sizeof(c->name)); else { - if(Xi18nTextPropertyToTextList(dpy, &name, &list, &n) >= Success + if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) { cext_strlcpy(c->name, *list, sizeof(c->name)); diff --git a/cmd/wm/column.c b/cmd/wm/column.c @@ -330,10 +330,10 @@ frame_of_point(XPoint *pt) if(!v) return nil; - for(a=v->area->next; a && !blitz_ispointinrect(pt->x, pt->y, &a->rect); + for(a=v->area->next; a && !ispointinrect(pt->x, pt->y, &a->rect); a=a->next); if(a) - for(f=a->frame; f && !blitz_ispointinrect(pt->x, pt->y, &f->rect); + for(f=a->frame; f && !ispointinrect(pt->x, pt->y, &f->rect); f=f->anext); return f; } @@ -348,7 +348,7 @@ drop_move(Frame *f, XRectangle *new, XPoint *pt) if(!pt) return; - for(tgt=v->area->next; tgt && !blitz_ispointinrect(pt->x, pt->y, &tgt->rect); + for(tgt=v->area->next; tgt && !ispointinrect(pt->x, pt->y, &tgt->rect); tgt=tgt->next); if(tgt) { if(pt->x < 16) { diff --git a/cmd/wm/event.c b/cmd/wm/event.c @@ -72,7 +72,7 @@ handle_buttonrelease(XEvent *e) static char buf[32]; if(ev->window == barwin) { for(b=bar; b; b=b->next) - if(blitz_ispointinrect(ev->x, ev->y, &b->rect)) { + if(ispointinrect(ev->x, ev->y, &b->rect)) { snprintf(buf, sizeof(buf), "BarClick %s %d\n", b->name, ev->button); write_event(buf); @@ -101,7 +101,7 @@ handle_buttonpress(XEvent *e) do_mouse_resize(c, CENTER); break; case Button3: - do_mouse_resize(c, blitz_quadofcoord(&c->rect, ev->x, ev->y)); + do_mouse_resize(c, quadofcoord(&c->rect, ev->x, ev->y)); default: break; } diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c @@ -1437,7 +1437,7 @@ xwrite(IXPConn *c, Fcall *fcall) XRectangle new; f = FRAME(i3); new = f->rect; - blitz_strtorect(&new, buf); + strtorect(&new, buf); if(new.width == 0) new.width = rect.width; if(new.height == 0) diff --git a/cmd/wm/geom.c b/cmd/wm/geom.c @@ -0,0 +1,49 @@ +/* + * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> + * See LICENSE file for license details. + */ + +#include <math.h> + +#include "wm.h" + +BlitzAlign +quadofcoord(XRectangle *rect, int x, int y) +{ + BlitzAlign ret = 0; + x -= rect->x; + y -= rect->y; + + if(x >= rect->width * .5) + ret |= EAST; + if(x <= rect->width * .5) + ret |= WEST; + if(y <= rect->height * .5) + ret |= NORTH; + if(y >= rect->height * .5) + ret |= SOUTH; + + return ret; +} + +Bool +ispointinrect(int x, int y, XRectangle * r) +{ + return (x >= r->x) && (x <= r->x + r->width) + && (y >= r->y) && (y <= r->y + r->height); +} + +/* Syntax: <x> <y> <width> <height> */ +int +strtorect(XRectangle *r, const char *val) +{ + XRectangle new; + if (!val) + return -1; + + if(sscanf(val, "%hd %hd %hu %hu", &new.x, &new.y, &new.width, &new.height) != 4) + return -1; + + *r = new; + return 0; +} diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -322,6 +322,11 @@ unsigned long long pack_qpath(unsigned char type, unsigned short i1, void write_event(char *event); void new_ixp_conn(IXPConn *c); +/* geom.c */ +BlitzAlign quadofcoord(XRectangle *rect, int x, int y); +Bool ispointinrect(int x, int y, XRectangle * r); +int strtorect(XRectangle *r, const char *val); + /* key.c */ void handle_key(Window w, unsigned long mod, KeyCode keycode); void update_keys(); diff --git a/liblitz/Makefile b/liblitz/Makefile @@ -6,7 +6,7 @@ include ../config.mk CFLAGS += -I../libixp -I../libcext LDFLAGS += -L../libixp -lixp -L../libcext -lcext -SRC = color.c font.c draw.c geometry.c +SRC = blitz.c color.c font.c draw.c window.c OBJ = ${SRC:.c=.o} all: liblitz.a diff --git a/liblitz/blitz.c b/liblitz/blitz.c @@ -0,0 +1,20 @@ +/* + * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> + * See LICENSE file for license details. + */ + +#include "blitz.h" + +/* blitz.c */ +void +blitz_init(Blitz *blitz, Display *dpy) +{ + blitz->display = dpy; + blitz->screen = DefaultScreen(dpy); + blitz->root = DefaultRootWindow(dpy); +} + +void +blitz_deinit(Blitz *blitz) +{ +} diff --git a/liblitz/blitz.h b/liblitz/blitz.h @@ -9,20 +9,8 @@ #define BLITZ_FONT "fixed" #define BLITZ_SELCOLORS "#ffffff #335577 #447799" #define BLITZ_NORMCOLORS "#222222 #eeeeee #666666" - -/* -#ifdef X_HAVE_UTF8_STRING -#define Xi18nTextPropertyToTextList Xutf8TextPropertyToTextList -#define Xi18nDrawString Xutf8DrawString -#define Xi18nTextExtents Xutf8TextExtents -#else -*/ -#define Xi18nTextPropertyToTextList XmbTextPropertyToTextList -#define Xi18nDrawString XmbDrawString -#define Xi18nTextExtents XmbTextExtents -/* -#endif -*/ +#define BLITZ_FRAME_MASK SubstructureRedirectMask | SubstructureNotifyMask \ + | ExposureMask | ButtonPressMask | ButtonReleaseMask; typedef enum { NORTH = 0x01, @@ -71,7 +59,27 @@ int blitz_loadcolor(Display *dpy, BlitzColor *c, int mon, char *colstr); void blitz_drawlabel(Display *dpy, BlitzDraw *d); void blitz_drawborder(Display *dpy, BlitzDraw *d); -/* geometry.c */ -int blitz_strtorect(XRectangle *r, const char *val); -BlitzAlign blitz_quadofcoord(XRectangle *rect, int x, int y); -Bool blitz_ispointinrect(int x, int y, XRectangle *r); +/* new stuff */ + +typedef struct { + Display *display; + int screen; + Window root; +} Blitz; + +typedef struct { + Drawable drawable; + GC gc; + XRectangle rect; +} BlitzWindow; + +/* blitz.c */ +void blitz_init(Blitz *blitz, Display *dpy); +void blitz_deinit(Blitz *blitz); + +/* window.c */ +void blitz_create_win(Blitz *blitz, BlitzWindow *win, unsigned long mask, + int x, int y, int w, int h); +void blitz_resize_win(Blitz *blitz, BlitzWindow *win, + int x, int y, int w, int h); +void blitz_destroy_win(Blitz *blitz, BlitzWindow *win); diff --git a/liblitz/draw.c b/liblitz/draw.c @@ -110,7 +110,7 @@ xdrawtext(Display *dpy, BlitzDraw *d) break; } if(d->font.set) - Xi18nDrawString(dpy, d->drawable, d->font.set, d->gc, x, y, text, len); + XmbDrawString(dpy, d->drawable, d->font.set, d->gc, x, y, text, len); else XDrawString(dpy, d->drawable, d->gc, x, y, text, len); } diff --git a/liblitz/font.c b/liblitz/font.c @@ -16,7 +16,7 @@ blitz_textwidth(Display *dpy, BlitzFont *font, char *text) { if(font->set) { XRectangle r; - Xi18nTextExtents(font->set, text, strlen(text), nil, &r); + XmbTextExtents(font->set, text, strlen(text), nil, &r); return r.width; } return XTextWidth(font->xfont, text, strlen(text)); diff --git a/liblitz/geometry.c b/liblitz/geometry.c @@ -1,51 +0,0 @@ -/* - * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> - * See LICENSE file for license details. - */ - -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <cext.h> - -#include "blitz.h" - -BlitzAlign -blitz_quadofcoord(XRectangle *rect, int x, int y) -{ - BlitzAlign ret = 0; - x -= rect->x; - y -= rect->y; - - if(x >= rect->width * .5) - ret |= EAST; - if(x <= rect->width * .5) - ret |= WEST; - if(y <= rect->height * .5) - ret |= NORTH; - if(y >= rect->height * .5) - ret |= SOUTH; - - return ret; -} - -Bool blitz_ispointinrect(int x, int y, XRectangle * r) -{ - return (x >= r->x) && (x <= r->x + r->width) - && (y >= r->y) && (y <= r->y + r->height); -} - - -/* Syntax: <x> <y> <width> <height> */ -int blitz_strtorect(XRectangle *r, const char *val) -{ - XRectangle new; - if (!val) - return -1; - - if(sscanf(val, "%hd %hd %hu %hu", &new.x, &new.y, &new.width, &new.height) != 4) - return -1; - - *r = new; - return 0; -} diff --git a/liblitz/window.c b/liblitz/window.c @@ -0,0 +1,43 @@ +/* + * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> + * See LICENSE file for license details. + */ + +#include <stdlib.h> +#include <cext.h> + +#include "blitz.h" + +void +blitz_create_win(Blitz *blitz, BlitzWindow *win, unsigned long mask, + int x, int y, int w, int h) +{ + XSetWindowAttributes wa; + wa.override_redirect = 1; + wa.background_pixmap = ParentRelative; + wa.event_mask = mask; + + win->drawable = XCreateWindow(blitz->display, blitz->root, + x, y, w, h, 0, DefaultDepth(blitz->display, blitz->screen), + CopyFromParent, DefaultVisual(blitz->display, blitz->screen), + CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); + win->gc = XCreateGC(blitz->display, win->drawable, 0, 0); + win->rect.x = x; + win->rect.y = y; + win->rect.width = w; + win->rect.height = h; +} + +void +blitz_resize_win(Blitz *blitz, BlitzWindow *win, int x, int y, int w, int h) +{ + XMoveResizeWindow(blitz->display, win->drawable, x, y, w, h); +} + +void +blitz_destroy_win(Blitz *blitz, BlitzWindow *win) +{ + XFreeGC(blitz->display, win->gc); + XDestroyWindow(blitz->display, win->drawable); + free(win); +}