Commit Diff


commit - 54dd92bebc97da7efb955f703c20cac8f4cbbb9f
commit + 35288690ce41267ae9c6341e1d73f74c56726297
blob - 0e2226cdf1aafa116be199d138a138f8bc2f2371
blob + ac69423ad87725c951699d219c687653fa5c2dca
--- src/cmd/devdraw/devdraw.c
+++ src/cmd/devdraw/devdraw.c
@@ -294,11 +294,18 @@ static
 void
 drawflush(void)
 {
-	if(flushrect.min.x < flushrect.max.x)
-		_flushmemscreen(flushrect);
+	_flushmemscreen(flushrect);
 	flushrect = Rect(10000, 10000, -10000, -10000);
 }
 
+void
+xdrawflush(void)
+{
+	qlock(&sdraw.lk);
+	drawflush();
+	qunlock(&sdraw.lk);
+}
+
 static
 int
 drawcmp(char *a, char *b, int n)
@@ -791,7 +798,7 @@ _drawmsgwrite(void *v, int n)
 
 	while((n-=m) > 0){
 		a += m;
-/*fprint(2, "msgwrite %d(%d)...", n, *a); */
+/* print("msgwrite %d(%c)...", n, *a); */
 		switch(*a){
 		default:
 /*fprint(2, "bad command %d\n", *a); */
blob - 4baf4b1afca1b06cee1cbe12d5a32c2b33449bc5
blob + 5371eacb6326773169771726a8ac4b393e73e4d0
--- src/cmd/devdraw/x11-inc.h
+++ src/cmd/devdraw/x11-inc.h
@@ -16,6 +16,9 @@
 #include <X11/keysym.h>
 #include <X11/IntrinsicP.h>
 #include <X11/StringDefs.h>
+#ifdef SHOWEVENT
+#include "../rio/showevent/ShowEvent.c"
+#endif
 
 #undef Colormap
 #undef Cursor
blob - 9ad6054f06557163db683e6cf061f58c3e8339c7
blob + 4d9074937866c66506da05243f5b78c9d56b7a01
--- src/cmd/devdraw/x11-init.c
+++ src/cmd/devdraw/x11-init.c
@@ -253,6 +253,8 @@ _xattach(char *label, char *winsize)
 		}
 		havemin = 0;
 	}
+	screenrect = Rect(0, 0, WidthOfScreen(xscreen), HeightOfScreen(xscreen));
+	windowrect = r;
 
 	memset(&attr, 0, sizeof attr);
 	attr.colormap = _x.cmap;
@@ -686,10 +688,26 @@ _xconfigure(XEvent *e)
 {
 	Rectangle r;
 	XConfigureEvent *xe = (XConfigureEvent*)e;
+
+	if(!fullscreen){
+		// I can't figure this out: apparently window managers
+		// (e.g., rio, twm) send ConfigureEvents using absolute
+		// screen coordinates, but X sends events using coordinates
+		// relative to the parent window.  
+		if(xe->send_event)
+			windowrect = Rect(xe->x, xe->y, xe->x+xe->width, xe->y+xe->height);
+		else{
+			int rx, ry;
+			XWindow w;
+			if(XTranslateCoordinates(_x.display, _x.drawable, DefaultRootWindow(_x.display), xe->x, xe->y, &rx, &ry, &w))
+				windowrect = Rect(rx, ry, rx+xe->width, ry+xe->height);
+		}
+	}
 
 	if(xe->width == Dx(_x.screenr) && xe->height == Dy(_x.screenr))
 		return 0;
 	r = Rect(0, 0, xe->width, xe->height);
+
 	qlock(&_x.screenlock);
 	if(_x.screenpm != _x.nextscreenpm){
 		XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y,
@@ -709,8 +727,6 @@ _xreplacescreenimage(void)
 	Rectangle r;
 
 	r = _x.newscreenr;
-	if(eqrect(_x.screenr, r))
-		return 0;
 
 	pixmap = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth);
 	m = _xallocmemimage(r, _x.chan, pixmap);
blob - eba9e0dbfa45afa9beaed5d4633807b621183e77
blob + a5b406718762d3f49d9118b146fa31c7cf333f92
--- src/cmd/devdraw/x11-memdraw.h
+++ src/cmd/devdraw/x11-memdraw.h
@@ -111,3 +111,6 @@ extern int		_xreplacescreenimage(void);
 	Button2MotionMask|\
 	Button3MotionMask)
 
+extern Rectangle screenrect;
+extern Rectangle windowrect;
+extern int fullscreen;
blob - 7dd3f39b02a7ce066de0a6035c07ebed94117937
blob + 071cbc76e303c4f9e77daec9195e6bd93b56db27
--- src/cmd/devdraw/x11-srv.c
+++ src/cmd/devdraw/x11-srv.c
@@ -5,10 +5,16 @@
  * subtle and quick to anger.
  */
 
+// #define SHOWEVENT
+
 #include <u.h>
 #include <sys/select.h>
 #include <errno.h>
+#ifdef SHOWEVENT
+#include <stdio.h>
+#endif
 #include "x11-inc.h"
+
 #include <libc.h>
 #include <draw.h>
 #include <memdraw.h>
@@ -86,11 +92,15 @@ int fdnoblock(int);
 
 int chatty;
 int drawsleep;
+int fullscreen;
+
+Rectangle windowrect;
+Rectangle screenrect;
 
 void
 usage(void)
 {
-	fprint(2, "usage: devdraw (don't run  directly)\n");
+	fprint(2, "usage: devdraw (don't run directly)\n");
 	exits("usage");
 }
 
@@ -120,6 +130,9 @@ main(int argc, char **argv)
 	close(1);
 	open("/dev/null", OREAD);
 	open("/dev/null", OWRITE);
+
+	/* reopens stdout if debugging */
+	runxevent(0);
 
 	fmtinstall('W', drawfcallfmt);
 
@@ -271,6 +284,8 @@ replyerror(Wsysmsg *m)
 	replymsg(m);
 }
 
+
+
 /* 
  * Handle a single wsysmsg. 
  * Might queue for later (kbd, mouse read)
@@ -455,8 +470,26 @@ void
 runxevent(XEvent *xev)
 {
 	int c;
+	KeySym k;
 	static Mouse m;
 
+#ifdef SHOWEVENT
+	static int first = 1;
+	if(first){
+		dup(create("/tmp/devdraw.out", OWRITE, 0666), 1);
+		setbuf(stdout, 0);
+		first = 0;
+	}
+#endif
+
+	if(xev == 0)
+		return;
+
+#ifdef SHOWEVENT
+	print("\n");
+	ShowEvent(xev);
+#endif
+
 	switch(xev->type){
 	case Expose:
 		_xexpose(xev);
@@ -500,6 +533,12 @@ runxevent(XEvent *xev)
 	case KeyPress:
 		if(kbd.stall)
 			return;
+		XLookupString((XKeyEvent*)xev, NULL, 0, &k, NULL);
+		if(k == XK_F11){
+			fullscreen = !fullscreen;
+			_xresizewindow(fullscreen ? screenrect : windowrect);
+			return;
+		}
 		if((c = _xtoplan9kbd(xev)) < 0)
 			return;
 		kbd.r[kbd.wi++] = c;
blob - fcb40fdf764687f835b958fd64152f681e6a07c9
blob + bba7c35080f9d042873b848a5f2339521554a8de
--- src/cmd/devdraw/x11-wsys.c
+++ src/cmd/devdraw/x11-wsys.c
@@ -21,9 +21,12 @@ _xresizewindow(Rectangle r)
 	int value_mask;
 
 	memset(&e, 0, sizeof e);
-	value_mask = CWWidth|CWHeight;
+	value_mask = CWX|CWY|CWWidth|CWHeight;
+	e.x = r.min.x;
+	e.y = r.min.y;
 	e.width = Dx(r);
 	e.height = Dy(r);
 	XConfigureWindow(_x.display, _x.drawable, value_mask, &e);
 	XFlush(_x.display);
 }
+