devdraw: add F11 for full-screen toggle

This commit is contained in:
Russ Cox 2008-01-30 12:01:43 -05:00
parent 54dd92bebc
commit 35288690ce
6 changed files with 78 additions and 7 deletions

View file

@ -294,11 +294,18 @@ static
void
drawflush(void)
{
if(flushrect.min.x < flushrect.max.x)
_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); */

View file

@ -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

View file

@ -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;
@ -687,9 +689,25 @@ _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);

View file

@ -111,3 +111,6 @@ extern int _xreplacescreenimage(void);
Button2MotionMask|\
Button3MotionMask)
extern Rectangle screenrect;
extern Rectangle windowrect;
extern int fullscreen;

View file

@ -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,6 +92,10 @@ int fdnoblock(int);
int chatty;
int drawsleep;
int fullscreen;
Rectangle windowrect;
Rectangle screenrect;
void
usage(void)
@ -121,6 +131,9 @@ main(int argc, char **argv)
open("/dev/null", OREAD);
open("/dev/null", OWRITE);
/* reopens stdout if debugging */
runxevent(0);
fmtinstall('W', drawfcallfmt);
ARGBEGIN{
@ -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;

View file

@ -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);
}