wmii

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

grav.c (2334B)


      1 #if 0
      2 	set -e
      3 	name=grav
      4 	root=..
      5 	obj=$root/cmd
      6 	lib=$root/lib
      7 	inc=$root/include
      8 	cc -I$inc -I/usr/local/include \
      9 		-o o.$name \
     10 		-Wall \
     11 		$name.c \
     12 		$obj/util.o \
     13 		$obj/wmii/map.o \
     14 		$obj/wmii/x11.o \
     15 		-L$lib -lfmt -lutf -lbio \
     16 		-L/usr/local/lib -lX11 -lXext \
     17 
     18 	exec o.$name
     19 #endif
     20 #include <fmt.h>
     21 #include <stdarg.h>
     22 #include <stdbool.h>
     23 #include <unistd.h>
     24 #include <stuff/util.h>
     25 #include <stuff/x11.h>
     26 
     27 char buffer[8196];
     28 void debug() {}
     29 
     30 static Window*	win;
     31 
     32 static char*	gravity[] = {
     33 	[NorthEastGravity] = "NorthEastGravity",
     34 	[NorthWestGravity] = "NorthWestGravity",
     35 	[SouthEastGravity] = "SouthEastGravity",
     36 	[SouthWestGravity] = "SouthWestGravity",
     37 	[StaticGravity]    = "StaticGravity",
     38 };
     39 
     40 static void
     41 draw(Window *w) {
     42 	Rectangle r;
     43 
     44 	r = w->r;
     45 	r = rectsubpt(r, r.min);
     46 
     47 	fill(w, r, 0UL);
     48 	border(w, Rect(3, 3, 97, 97), 2, ~0UL);
     49 	border(w, Rect(8, 8, 92, 92), 2, ~0UL);
     50 	sync();
     51 }
     52 
     53 static void
     54 setgravity(Window *w, long gravity) {
     55 	XSizeHints wmh;
     56 
     57 	wmh.flags = PWinGravity;
     58 	wmh.win_gravity = gravity;
     59 	XSetWMNormalHints(display, w->w, &wmh);
     60 }
     61 
     62 static void
     63 config(Window *w, long grav, Point p) {
     64 	Rectangle r;
     65 
     66 	r = rectsetorigin(Rect(0, 0, 100, 100), p);
     67 
     68 	print("%s: %R\n", gravity[grav], r);
     69 
     70 	setgravity(w, grav);
     71 	w->r = ZR; /* Kludge. */
     72 	reshapewin(w, r);
     73 	draw(w);
     74 	sleep(1);
     75 }
     76 
     77 int
     78 main(void) {
     79 	XSizeHints wmh;
     80 	WinAttr wa;
     81 	XEvent ev;
     82 
     83 	initdisplay();
     84 
     85 	/* Kludge the bar height. */
     86 	scr.rect.max.y -= 14;
     87 
     88 	wa.background_pixmap = ParentRelative;
     89 	wa.event_mask = ExposureMask|StructureNotifyMask;
     90 	win = createwindow(&scr.root,
     91 				Rect(0, 0, 100, 100), scr.depth, InputOutput,
     92 				&wa, CWEventMask | CWBackPixmap);
     93 	XSelectInput(display, win->w, ExposureMask);
     94 
     95 	wmh.flags = PMinSize|PMaxSize|USPosition;
     96 	wmh.min_width = wmh.max_width = 100;
     97 	wmh.min_height = wmh.max_height = 100;
     98 	XSetWMNormalHints(display, win->w, &wmh);
     99 
    100 	mapwin(win);
    101 	raisewin(win);
    102 	XMaskEvent(display, ExposureMask, &ev);
    103 
    104 	draw(win);
    105 	sleep(2);
    106 
    107 	config(win, StaticGravity, Pt(0, 0));
    108 
    109 	config(win, NorthWestGravity,
    110 		    Pt(0,
    111 		       0));
    112 
    113 	config(win, NorthEastGravity,
    114 		    Pt(Dx(scr.rect) - 100,
    115 		       0));
    116 
    117 	config(win, SouthEastGravity,
    118 		    Pt(Dx(scr.rect) - 100,
    119 		       Dy(scr.rect) - 100));
    120 
    121 	config(win, SouthWestGravity,
    122 		    Pt(0,
    123 		       Dy(scr.rect) - 100));
    124 
    125 	sleep(1);
    126 	return 0;
    127 }
    128