History

wsys, xexpose

yiyus committed 15 years ago

Commit 8a342c81 parent 161236e8 files · +181 −22Browse files

Unified · Split

8 files
  1. devwsys/dat.h +3 −1
  2. devwsys/devdraw.c +35 −5
  3. devwsys/fns.h +2 −0
  4. devwsys/mkfile +1 −0
  5. devwsys/window.c +1 −0
  6. devwsys/x11/event.c +59 −12
  7. devwsys/x11/window.c +25 −4
  8. devwsys/x11/wsys.c +55 −0
devwsys/dat.h+3−1
@@ -181,6 +181,7 @@ struct Reqbuf · 180 unmodified lines
181181 struct Window
182182 {
183183 int id;
184+ int fullscreen;
184185 int deleted;
185186 char *label;
186187 Draw draw;
@@ -188,7 +189,8 @@ struct Window · 1 unmodified line
188189 Mousebuf mouse;
189190 Reqbuf kbdreqs;
190191 Reqbuf mousereqs;
191− Rectangle r;
192+ Rectangle screenr;
193+ Rectangle newscreenr;
192194 void *x;
193195 };
194196
devwsys/devdraw.c+35−5
@@ -52,6 +52,35 @@ drawnewclient(Draw *draw) · 51 unmodified lines
5252 return cl;
5353 }
5454
55+void
56+drawreplacescreenimage(Client *cl, Memimage *m)
57+{
58+ /*
59+ * Replace the screen image because the screen
60+ * was resized.
61+ *
62+ * In theory there should only be one reference
63+ * to the current screen image, and that's through
64+ * client0's image 0, installed a few lines above.
65+ * Once the client drops the image, the underlying backing
66+ * store freed properly. The client is being notified
67+ * about the resize through external means, so all we
68+ * need to do is this assignment.
69+ */
70+ Memimage *om;
71+ Memimage *screenimage;
72+
73+ screenimage = cl->draw->screenimage;
74+ // qlock(&sdraw.lk);
75+ om = screenimage;
76+ cl->draw->screenimage = m;
77+ // m->screenref = 1;
78+ // if(om && --om->screenref == 0){
79+ // freememimage(om);
80+ // }
81+ // qunlock(&sdraw.lk);
82+}
83+
5584 static
5685 void
5786 drawrefreshscreen(DImage *l, Client *client)
@@ -266,7 +295,7 @@ drawfreedimage(Draw *draw, DImage *dimage) · 208 unmodified lines
266295 return;
267296
268297 /* any names? */
269− for(i=0; i<draw->nname; )
298+ for(i=0; draw && i<draw->nname; )
270299 if(draw->name[i].dimage == dimage)
271300 drawdelname(draw, draw->name+i);
272301 else
@@ -463,7 +492,7 @@ drawfree(Client *cl) · 190 unmodified lines
463492 free(r);
464493 }
465494 /* free names */
466− for(i=0; i<draw->nname; )
495+ for(i=0; draw && i<draw->nname; )
467496 if(draw->name[i].client == cl)
468497 drawdelname(draw, draw->name+i);
469498 else
@@ -727,18 +756,19 @@ drawmesg(Client *client, void *av, int n) · 257 unmodified lines
727756 Rectangle clipr, r;
728757 Refreshfn reffn;
729758 Refx *refx;
759+ Window *w;
730760
731761 // qlock(&sdraw.lk);
732762 a = av;
733763 m = 0;
734764 oldn = n;
735765 draw = client->draw;
766+ w = draw->window;
736767
737768 while((n-=m) > 0){
738769 a += m;
739−/*fprint(2, "msgwrite %d(%d)...", n, *a); */
770+/*fprint(2, "XXX msgwrite %d(%d): %c\n", n, *a, *a); */
740771 switch(*a){
741− default:
742772 /*fprint(2, "bad command %d\n", *a); */
743773 err = "bad draw command";
744774 goto error;
@@ -810,7 +840,7 @@ drawmesg(Client *client, void *av, int n) · 65 unmodified lines
810840 }
811841 continue;
812842 }
813− i = allocmemimage(r, chan);
843+ i = xallocmemimage(w, r, chan, PMundef);
814844 if(i == 0)
815845 goto Edrawmem;
816846 if(repl)
devwsys/fns.h+2−0
@@ -43,4 +43,6 @@ Memimage* xallocmemimage(Window*, Rectangle, ulong, int); · 42 unmodified lines
4343 void xattach(Window*, char*);
4444 void xdeletewin(Window*);
4545 void xflushmemscreen(Window*, Rectangle);
46+int xreplacescreenimage(Window*);
4647 int xupdatelabel(Window*);
48+void xmovewindow(Window*, Rectangle);
devwsys/mkfile+1−0
@@ -9,6 +9,7 @@ XFILES=\ · 8 unmodified lines
99 itrans.$O\
1010 keysym2ucs.$O\
1111 window.$O\
12+ wsys.$O\
1213
1314 OFILES=\
1415 alloc.$O\
devwsys/window.c+1−0
@@ -22,6 +22,7 @@ newwin(char *label, char *winsize) · 21 unmodified lines
2222
2323 w->id = id++;
2424 w->label = label;
25+ w->draw.window = w;
2526 xattach(w, winsize);
2627
2728 return w;
devwsys/x11/event.c+59−12
@@ -9,9 +9,10 @@ · 8 unmodified lines
99
1010 #define debugev(...) if(0) debug(__VA_ARGS__)
1111
12−void configevent(Window *w, XEvent);
13−void kbdevent(Window *w, XEvent);
14−void mouseevent(Window *w, XEvent);
12+void configevent(Window*, XEvent);
13+void exposeevent(Window*, XEvent);
14+void kbdevent(Window*, XEvent);
15+void mouseevent(Window*, XEvent);
1516
1617 void
1718 xnextevent(void) {
@@ -41,7 +42,7 @@ xnextevent(void) { · 23 unmodified lines
4142 break;
4243
4344 case Expose:
44− //xexpose(w, xev);
45+ exposeevent(w, xev);
4546 break;
4647
4748 case DestroyNotify:
@@ -75,15 +76,63 @@ void · 27 unmodified lines
7576 configevent(Window *w, XEvent xev)
7677 {
7778 Mouse m;
79+ Rectangle r;
80+ Xwin *xw;
81+ XConfigureEvent *xe;
82+
83+ xe = (XConfigureEvent*)&xev;
84+ xw = w->x;
85+ if(!w->fullscreen){
86+ int rx, ry;
87+ XWindow xwin;
88+ if(XTranslateCoordinates(xconn.display, xw->drawable, DefaultRootWindow(xconn.display), 0, 0, &rx, &ry, &xwin))
89+ w->screenr = Rect(rx, ry, rx+xe->width, ry+xe->height);
90+ }
91+
92+ if(xe->width == Dx(w->screenr) && xe->height == Dy(w->screenr))
93+ return;
94+ r = Rect(0, 0, xe->width, xe->height);
95+
96+ // qlock(&_x.screenlock);
97+ if(xw->screenpm != xw->nextscreenpm){
98+ XCopyArea(xconn.display, xw->screenpm, xw->drawable, xw->gccopy, r.min.x, r.min.y,
99+ Dx(r), Dy(r), r.min.x, r.min.y);
100+ XSync(xconn.display, False);
101+ }
102+ // qunlock(&_x.screenlock);
103+ w->newscreenr = r;
78104
79− // TODO: plan9port/src/cmd/devdraw/x11-init.c:686
80− m.xy.x = xev.xconfigure.width;
81− m.xy.y = xev.xconfigure.height;
82− // _xreplacescreenimage();
105+ m.xy.x = xe->width;
106+ m.xy.y = xe->height;
107+ xreplacescreenimage(w);
83108 debugev("Configure event at window %d: w=%d h=%d\n", w->id, m.xy.x, m.xy.y);
84109 writemouse(w, m, 1);
85110 }
86111
112+void
113+exposeevent(Window *w, XEvent xev)
114+{
115+ XExposeEvent *xe;
116+ Rectangle r;
117+ Xwin *xw;
118+
119+ xw = w->x;
120+ // qlock(&_x.screenlock);
121+ if(xw->screenpm != xw->nextscreenpm){
122+ // qunlock(&_x.screenlock);
123+ return;
124+ }
125+ xe = (XExposeEvent*)&xev;
126+ r.min.x = xe->x;
127+ r.min.y = xe->y;
128+ r.max.x = xe->x+xe->width;
129+ r.max.y = xe->y+xe->height;
130+ XCopyArea(xconn.display, xw->screenpm, xw->drawable, xw->gccopy, r.min.x, r.min.y,
131+ Dx(r), Dy(r), r.min.x, r.min.y);
132+ XSync(xconn.display, False);
133+ // qunlock(&_x.screenlock);
134+}
135+
87136 void
88137 kbdevent(Window *w, XEvent xev)
89138 {
@@ -91,10 +140,8 @@ kbdevent(Window *w, XEvent xev) · 1 unmodified line
91140
92141 XLookupString((XKeyEvent*)&xev, NULL, 0, &k, NULL);
93142 if(k == XK_F11){
94− /* TODO
95− fullscreen = !fullscreen;
96− _xmovewindow(fullscreen ? screenrect : windowrect);
97− */
143+ w->fullscreen = !w->fullscreen;
144+ xmovewindow(w, w->fullscreen ? xconn.screenrect : w->screenr);
98145 return;
99146 }
100147
devwsys/x11/window.c+25−4
@@ -29,11 +29,11 @@ xattach(Window *w, char *winsize) · 28 unmodified lines
2929 int havemin;
3030 Xwin *xw;
3131
32− w->r = xwinrectangle(w->label, winsize, &havemin);
33− xw = xcreatewin(w->label, winsize, w->r);
34− w->r = xmapwin(xw, havemin, w->r);
32+ w->screenr = xwinrectangle(w->label, winsize, &havemin);
33+ xw = xcreatewin(w->label, winsize, w->screenr);
34+ w->screenr = xmapwin(xw, havemin, w->screenr);
3535 w->x = xw;
36− w->draw.screenimage = xallocmemimage(w, w->r, xconn.chan, xw->screenpm);
36+ w->draw.screenimage = xallocmemimage(w, w->screenr, xconn.chan, xw->screenpm);
3737 // initscreenimage(w);
3838 }
3939
@@ -48,6 +48,27 @@ xdeletewin(Window *w) · 8 unmodified lines
4848 XSync(xconn.display, False);
4949 }
5050
51+int
52+xreplacescreenimage(Window *w)
53+{
54+ Memimage *m;
55+ XDrawable pixmap;
56+ Rectangle r;
57+ Xwin *xw;
58+
59+ xw = w->x;
60+ r = w->newscreenr;
61+
62+ pixmap = XCreatePixmap(xconn.display, xw->drawable, Dx(r), Dy(r), xconn.depth);
63+ m = xallocmemimage(w, r, xconn.chan, pixmap);
64+ if(xw->nextscreenpm != xw->screenpm)
65+ XFreePixmap(xconn.display, xw->nextscreenpm);
66+ xw->nextscreenpm = pixmap;
67+ w->screenr = r;
68+ drawreplacescreenimage(w, m);
69+ return 1;
70+}
71+
5172 int
5273 xupdatelabel(Window *w)
5374 {
devwsys/x11/wsys.c+55−0
@@ -0,0 +1,55 @@
1+#include <lib9.h>
2+#include <kern.h>
3+#include <draw.h>
4+#include <memdraw.h>
5+#include <memlayer.h>
6+#include "dat.h"
7+#include "fns.h"
8+#include "inc.h"
9+#include "x.h"
10+
11+void
12+xtopwindow(Window *w)
13+{
14+ Xwin *xw;
15+
16+ xw = w->x;
17+ XMapRaised(xconn.display, xw->drawable);
18+ XSetInputFocus(xconn.display, xw->drawable, RevertToPointerRoot,
19+ CurrentTime);
20+ XFlush(xconn.display);
21+}
22+
23+void
24+xresizewindow(Window *w, Rectangle r)
25+{
26+ XWindowChanges e;
27+ int value_mask;
28+ Xwin *xw;
29+
30+ xw = w->x;
31+ memset(&e, 0, sizeof e);
32+ value_mask = CWX|CWY|CWWidth|CWHeight;
33+ e.width = Dx(r);
34+ e.height = Dy(r);
35+ XConfigureWindow(xconn.display, xw->drawable, value_mask, &e);
36+ XFlush(xconn.display);
37+}
38+
39+void
40+xmovewindow(Window *w, Rectangle r)
41+{
42+ XWindowChanges e;
43+ int value_mask;
44+ Xwin *xw;
45+
46+ xw = w->x;
47+ memset(&e, 0, sizeof e);
48+ value_mask = CWX|CWY|CWWidth|CWHeight;
49+ e.x = r.min.x;
50+ e.y = r.min.y;
51+ e.width = Dx(r);
52+ e.height = Dy(r);
53+ XConfigureWindow(xconn.display, xw->drawable, value_mask, &e);
54+ XFlush(xconn.display);
55+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t