changeset: 2237:6fd2e21d7406
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Jan 19 20:29:58 2008 -0500
summary: Forgot to add div.c, float.c, xext.c.
diff -r 184693ca0dde -r 6fd2e21d7406 cmd/util.c
--- a/cmd/util.c Sat Jan 19 20:05:10 2008 -0500
+++ b/cmd/util.c Sat Jan 19 20:29:58 2008 -0500
@@ -44,6 +44,30 @@ fatal(const char *fmt, ...) {
va_end(fp.args);
exit(1);
+}
+
+char*
+vsxprint(const char *fmt, va_list ap) {
+ static char* bufs[16];
+ static long nbuf;
+ int id;
+
+ id = nbuf++ % nelem(bufs);
+ if(bufs[id])
+ free(bufs[id]);
+ bufs[id] = vsmprint(fmt, ap);
+ return bufs[id];
+}
+
+char*
+sxprint(const char *fmt, ...) {
+ va_list ap;
+ char *ret;
+
+ va_start(ap, fmt);
+ ret = vsxprint(fmt, ap);
+ va_end(ap);
+ return ret;
}
void
@@ -150,13 +174,6 @@ min(int a, int b) {
return b;
}
-char *
-str_nil(char *s) {
- if(s)
- return s;
- return "<nil>";
-}
-
int
utflcpy(char *to, const char *from, int l) {
char *p;
diff -r 184693ca0dde -r 6fd2e21d7406 cmd/wmii/area.c
--- a/cmd/wmii/area.c Sat Jan 19 20:05:10 2008 -0500
+++ b/cmd/wmii/area.c Sat Jan 19 20:29:58 2008 -0500
@@ -28,14 +28,12 @@ area_idx(Area *a) {
char*
area_name(Area *a) {
- static char buf[16];
-
+
if(a == nil)
return "<nil>";
if(a->floating)
return "~";
- snprint(buf, sizeof(buf), "%d", area_idx(a));
- return buf;
+ return sxprint("%d", area_idx(a));
}
Area*
diff -r 184693ca0dde -r 6fd2e21d7406 cmd/wmii/div.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/wmii/div.c Sat Jan 19 20:29:58 2008 -0500
@@ -0,0 +1,163 @@
+/* Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+ * See LICENSE file for license details.
+ */
+#include "dat.h"
+#include "fns.h"
+
+static Image *divimg, *divmask;
+static CTuple divc;
+static Handlers handlers;
+
+static Divide*
+getdiv(Divide **dp) {
+ WinAttr wa;
+ Divide *d;
+
+ if(*dp)
+ return *dp;
+
+ d = emallocz(sizeof *d);
+
+ wa.override_redirect = True;
+ wa.cursor = cursor[CurDHArrow];
+ wa.event_mask =
+ ExposureMask
+ | EnterWindowMask
+ | ButtonPressMask
+ | ButtonReleaseMask;
+ d->w = createwindow(&scr.root, Rect(0, 0, 1, 1), scr.depth, InputOutput, &wa,
+ CWOverrideRedirect
+ | CWEventMask
+ | CWCursor);
+ d->w->aux = d;
+ sethandler(d->w, &handlers);
+
+ *dp = d;
+ return d;
+}
+
+static void
+mapdiv(Divide *d) {
+ mapwin(d->w);
+}
+
+static void
+unmapdiv(Divide *d) {
+ unmapwin(d->w);
+}
+
+void
+div_set(Divide *d, int x) {
+ Rectangle r;
+
+ d->x = x;
+ r = rectaddpt(divimg->r, Pt(x - Dx(divimg->r)/2, 0));
+ r.max.y = screen->brect.min.y;
+
+ reshapewin(d->w, r);
+ mapdiv(d);
+}
+
+static void
+drawimg(Image *img, ulong cbg, ulong cborder) {
+ Point pt[6];
+
+ pt[0] = Pt(0, 0);
+ pt[1] = Pt(Dx(img->r)/2 - 1, Dx(img->r)/2 - 1);
+
+ pt[2] = Pt(pt[1].x, Dy(img->r));
+ pt[3] = Pt(Dx(img->r)/2, pt[2].y);
+
+ pt[4] = Pt(pt[3].x, Dx(img->r)/2 - 1);
+ pt[5] = Pt(Dx(img->r) - 1, 0);
+
+ fillpoly(img, pt, nelem(pt), cbg);
+ drawpoly(img, pt, nelem(pt), CapNotLast, 1, cborder);
+}
+
+static void
+drawdiv(Divide *d) {
+ copyimage(d->w, divimg->r, divimg, ZP);
+ setshapemask(d->w, divmask, ZP);
+}
+
+static void
+update_imgs(void) {
+ Divide *d;
+ int w, h;
+
+ w = 2 * (labelh(def.font) / 3);
+ w = max(w, 10);
+ h = Dy(screen->sel->r);
+
+ if(divimg) {
+ if(w == Dx(divimg->r) && h == Dy(divimg->r)
+ && !memcmp(&divc, &def.normcolor, sizeof(divc)))
+ return;
+ freeimage(divimg);
+ freeimage(divmask);
+ }
+
+ divimg = allocimage(w, h, scr.depth);
+ divmask = allocimage(w, h, 1);
+ divc = def.normcolor;
+
+ fill(divmask, divmask->r, 0);
+ drawimg(divmask, 1, 1);
+ drawimg(divimg, divc.bg, divc.border);
+
+ for(d = divs; d && d->w->mapped; d = d->next)
+ drawdiv(d);
+}
+
+void
+div_update_all(void) {
+ Divide **dp, *d;
+ Area *a;
+ View *v;
+
+ update_imgs();
+
+ v = screen->sel;
+ dp = &divs;
+ for(a = v->area->next; a; a = a->next) {
+ d = getdiv(dp);
+ dp = &d->next;
+ div_set(d, a->r.min.x);
+
+ if(!a->next) {
+ d = getdiv(dp);
+ dp = &d->next;
+ div_set(d, a->r.max.x);
+ }
+ }
+ for(d = *dp; d; d = d->next)
+ unmapdiv(d);
+}
+
+/* Div Handlers */
+static void
+bdown_event(Window *w, XButtonEvent *e) {
+ Divide *d;
+
+ USED(e);
+
+ d = w->aux;
+ mouse_resizecol(d);
+}
+
+static void
+expose_event(Window *w, XExposeEvent *e) {
+ Divide *d;
+
+ USED(e);
+
+ d = w->aux;
+ drawdiv(d);
+}
+
+static Handlers handlers = {
+ .bdown = bdown_event,
+ .expose = expose_event,
+};
+
diff -r 184693ca0dde -r 6fd2e21d7406 cmd/wmii/float.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/wmii/float.c Sat Jan 19 20:29:58 2008 -0500
@@ -0,0 +1,134 @@
+/* Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+ * See LICENSE file for license details.
+ */
+#include "dat.h"
+#include <sys/limits.h>
+#include "fns.h"
+
+static void float_placeframe(Frame*);
+
+void
+float_attach(Area *a, Frame *f) {
+
+ f->client->floating = true;
+
+ float_placeframe(f);
+ frame_insert(f, a->sel);
+
+ if(a->sel == nil)
+ area_setsel(a, f);
+}
+
+void
+float_detach(Frame *f) {
+ Area *a, *sel;
+ View *v;
+
+ v = f->view;
+ a = f->area;
+ sel = view_findarea(v, v->selcol, false);
+
+ frame_remove(f);
+
+ if(v->oldsel)
+ area_focus(v->oldsel);
+ else if(!a->frame)
+ if(sel->frame)
+ area_focus(sel);
+}
+
+static void
+rect_push(Vector_rect *vec, Rectangle r) {
+ Rectangle *rp;
+ int i;
+
+ for(i=0; i < vec->n; i++) {
+ rp = &vec->ary[i];
+ if(rect_contains_p(*rp, r))
+ return;
+ if(rect_contains_p(r, *rp)) {
+ *rp = r;
+ return;
+ }
+ }
+ vector_rpush(vec, r);
+}
+
+static void
+float_placeframe(Frame *f) {
+ static Vector_rect rvec, rvec2;
+ Vector_rect *vp, *vp2, *vptemp;
+ Rectangle *rp;
+ Rectangle r, fr;
+ Point dim, p;
+ Client *c;
+ Frame *ff;
+ Area *a;
+ long area, l;
+ int i;
+
+ a = f->area;
+ c = f->client;
+
+ if(c->trans)
+ return;
+ if(c->fullscreen || c->w.hints->position || starting) {
+ f->r = client_grav(c, c->r);
+ return;
+ }
+
+ dim.x = Dx(f->r);
+ dim.y = Dy(f->r);
+
+ rvec.n = 0;
+ rvec2.n = 0;
+ vp = &rvec;
+ vp2 = &rvec2;
+
+ /* Find all rectangles on the floating layer into which
+ * the new frame would fit. (Please ignore the man behind
+ * the curtain).
+ */
+ vector_rpush(vp, a->r);
+ for(ff=a->frame; ff; ff=ff->anext) {
+ fr = ff->r;
+ vp2->n = 0;
+ for(i=0; i < vp->n; i++) {
+ r = vp->ary[i];
+ if(!rect_intersect_p(fr, r)) {
+ rect_push(vp2, r);
+ continue;
+ }
+ if(r.min.x < fr.min.x && fr.min.x - r.min.x >= dim.x)
+ rect_push(vp2, Rect(r.min.x, r.min.y, fr.min.x, r.max.y));
+ if(r.max.x > fr.max.x && r.max.x - fr.max.x >= dim.x)
+ rect_push(vp2, Rect(fr.max.x, r.min.y, r.max.x, r.max.y));
+ if(r.min.y < fr.min.y && fr.min.y - r.min.y >= dim.y)
+ rect_push(vp2, Rect(r.min.x, r.min.y, r.max.x, fr.min.y));
+ if(r.max.y > fr.max.y && r.max.y - fr.max.y >= dim.y)
+ rect_push(vp2, Rect(r.min.x, fr.max.y, r.max.x, r.max.y));
+ }
+ vptemp = vp;
+ vp = vp2;
+ vp2 = vptemp;
+ }
+
+ if(vp->n == 0) {
+ p.x = random() % max(0, Dx(a->r) - dim.x);
+ p.y = random() % max(0, Dy(a->r) - dim.y);
+ }else {
+ area = LONG_MAX;
+ for(i=0; i < vp->n; i++) {
+ rp = &vp->ary[i];
+ l = Dx(*rp) * Dy(*rp);
+ if(l < area) {
+ area = l;
+ p = rp->min;
+ }
+ }
+ }
+
+ fr = rectsubpt(f->r, f->r.min);
+ f->r = rectaddpt(fr, p);
+}
+
diff -r 184693ca0dde -r 6fd2e21d7406 cmd/wmii/message.c
--- a/cmd/wmii/message.c Sat Jan 19 20:05:10 2008 -0500
+++ b/cmd/wmii/message.c Sat Jan 19 20:29:58 2008 -0500
@@ -433,12 +433,8 @@ msg_debug(IxpMsg *m) {
else
debug &= ~(1<<d);
}
- if(buffer[0] != '\0') {
- opt = smprint("Bad debug options: %s", buffer+2);
- utfecpy(buffer, buffer+sizeof(buffer), opt);
- free(opt);
- return buffer;
- }
+ if(buffer[0] != '\0')
+ return sxprint("Bad debug options: %s", buffer+2);
return nil;
}
diff -r 184693ca0dde -r 6fd2e21d7406 cmd/wmii/xext.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/wmii/xext.c Sat Jan 19 20:29:58 2008 -0500
@@ -0,0 +1,72 @@
+/* Copyright ©2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+ * See LICENSE file for license details.
+ */
+#define _X11_VISIBLE
+#include "dat.h"
+#include "fns.h"
+
+#if RANDR_MAJOR < 1
+# error XRandR versions less than 1.0 are not supported
+#endif
+
+static void randr_screenchange(XRRScreenChangeNotifyEvent*);
+
+bool have_RandR;
+int randr_eventbase;
+
+void
+xext_init(void) {
+ randr_init();
+}
+
+void
+xext_event(XEvent *e) {
+
+ if(have_RandR && (ulong)(e->type - randr_eventbase) < RRNumberEvents) {
+ e->type -= randr_eventbase;
+ randr_event(e);
+ }
+}
+
+void
+randr_init(void) {
+ int errorbase, major, minor;
+
+ have_RandR = XRRQueryExtension(display, &randr_eventbase, &errorbase);
+ if(have_RandR)
+ if(XRRQueryVersion(display, &major, &minor) && major < 1)
+ have_RandR = false;
+ if(!have_RandR)
+ return;
+ XRRSelectInput(display, scr.root.w, RRScreenChangeNotifyMask);
+}
+
+static void
+randr_screenchange(XRRScreenChangeNotifyEvent *ev) {
+ View *v;
+ Point d;
+
+ XRRUpdateConfiguration((XEvent*)ev);
+
+ d.x = ev->width - Dx(screen->r);
+ d.y = ev->height - Dy(screen->r);
+ for(v=view; v; v=v->next) {
+ v->r.max.x += d.x;
+ v->r.max.y += d.y;
+ }
+ screen->r = Rect(0, 0, ev->width, ev->height);
+ bar_resize(screen);
+}
+
+void
+randr_event(XEvent *e) {
+
+ switch(e->type) {
+ default:
+ break;
+ case RRScreenChangeNotify: /* Yuck. */
+ randr_screenchange((XRRScreenChangeNotifyEvent*)e);
+ break;
+ }
+}
+
diff -r 184693ca0dde -r 6fd2e21d7406 include/util.h
--- a/include/util.h Sat Jan 19 20:05:10 2008 -0500
+++ b/include/util.h Sat Jan 19 20:29:58 2008 -0500
@@ -36,10 +36,11 @@ void fatal(const char*, ...);
void fatal(const char*, ...);
int max(int, int);
int min(int, int);
-char* str_nil(char*);
uint strlcat(char*, const char*, uint);
+char* sxprint(const char*, ...);
uint tokenize(char **, uint, char*, char);
int utflcpy(char*, const char*, int);
+char* vsxprint(const char*, va_list);
#define die(x) \
_die(__FILE__, __LINE__, x)
Received on Mon Jan 21 2008 - 00:31:10 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:59:00 UTC