Unified · Split
| @@ -181,6 +181,7 @@ struct Reqbuf · 180 unmodified lines | |||
| 181 | struct Window | 181 | struct Window |
| 182 | { | 182 | { |
| 183 | int id; | 183 | int id; |
| 184 | int fullscreen; | ||
| 184 | int deleted; | 185 | int deleted; |
| 185 | char *label; | 186 | char *label; |
| 186 | Draw draw; | 187 | Draw draw; |
| @@ -188,7 +189,8 @@ struct Window · 1 unmodified line | |||
| 188 | Mousebuf mouse; | 189 | Mousebuf mouse; |
| 189 | Reqbuf kbdreqs; | 190 | Reqbuf kbdreqs; |
| 190 | Reqbuf mousereqs; | 191 | Reqbuf mousereqs; |
| 191 | Rectangle r; | 192 | Rectangle screenr; |
| 193 | Rectangle newscreenr; | ||
| 192 | void *x; | 194 | void *x; |
| 193 | }; | 195 | }; |
| 194 | 196 | ||
| @@ -52,6 +52,35 @@ drawnewclient(Draw *draw) · 51 unmodified lines | |||
| 52 | return cl; | 52 | return cl; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 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 | |||
| 55 | static | 84 | static |
| 56 | void | 85 | void |
| 57 | drawrefreshscreen(DImage *l, Client *client) | 86 | drawrefreshscreen(DImage *l, Client *client) |
| @@ -266,7 +295,7 @@ drawfreedimage(Draw *draw, DImage *dimage) · 208 unmodified lines | |||
| 266 | return; | 295 | return; |
| 267 | 296 | ||
| 268 | /* any names? */ | 297 | /* any names? */ |
| 269 | for(i=0; i<draw->nname; ) | 298 | for(i=0; draw && i<draw->nname; ) |
| 270 | if(draw->name[i].dimage == dimage) | 299 | if(draw->name[i].dimage == dimage) |
| 271 | drawdelname(draw, draw->name+i); | 300 | drawdelname(draw, draw->name+i); |
| 272 | else | 301 | else |
| @@ -463,7 +492,7 @@ drawfree(Client *cl) · 190 unmodified lines | |||
| 463 | free(r); | 492 | free(r); |
| 464 | } | 493 | } |
| 465 | /* free names */ | 494 | /* free names */ |
| 466 | for(i=0; i<draw->nname; ) | 495 | for(i=0; draw && i<draw->nname; ) |
| 467 | if(draw->name[i].client == cl) | 496 | if(draw->name[i].client == cl) |
| 468 | drawdelname(draw, draw->name+i); | 497 | drawdelname(draw, draw->name+i); |
| 469 | else | 498 | else |
| @@ -727,18 +756,19 @@ drawmesg(Client *client, void *av, int n) · 257 unmodified lines | |||
| 727 | Rectangle clipr, r; | 756 | Rectangle clipr, r; |
| 728 | Refreshfn reffn; | 757 | Refreshfn reffn; |
| 729 | Refx *refx; | 758 | Refx *refx; |
| 759 | Window *w; | ||
| 730 | 760 | ||
| 731 | // qlock(&sdraw.lk); | 761 | // qlock(&sdraw.lk); |
| 732 | a = av; | 762 | a = av; |
| 733 | m = 0; | 763 | m = 0; |
| 734 | oldn = n; | 764 | oldn = n; |
| 735 | draw = client->draw; | 765 | draw = client->draw; |
| 766 | w = draw->window; | ||
| 736 | 767 | ||
| 737 | while((n-=m) > 0){ | 768 | while((n-=m) > 0){ |
| 738 | a += m; | 769 | a += m; |
| 739 | /*fprint(2, "msgwrite %d(%d)...", n, *a); */ | 770 | /*fprint(2, "XXX msgwrite %d(%d): %c\n", n, *a, *a); */ |
| 740 | switch(*a){ | 771 | switch(*a){ |
| 741 | default: | ||
| 742 | /*fprint(2, "bad command %d\n", *a); */ | 772 | /*fprint(2, "bad command %d\n", *a); */ |
| 743 | err = "bad draw command"; | 773 | err = "bad draw command"; |
| 744 | goto error; | 774 | goto error; |
| @@ -810,7 +840,7 @@ drawmesg(Client *client, void *av, int n) · 65 unmodified lines | |||
| 810 | } | 840 | } |
| 811 | continue; | 841 | continue; |
| 812 | } | 842 | } |
| 813 | i = allocmemimage(r, chan); | 843 | i = xallocmemimage(w, r, chan, PMundef); |
| 814 | if(i == 0) | 844 | if(i == 0) |
| 815 | goto Edrawmem; | 845 | goto Edrawmem; |
| 816 | if(repl) | 846 | if(repl) |
| @@ -43,4 +43,6 @@ Memimage* xallocmemimage(Window*, Rectangle, ulong, int); · 42 unmodified lines | |||
| 43 | void xattach(Window*, char*); | 43 | void xattach(Window*, char*); |
| 44 | void xdeletewin(Window*); | 44 | void xdeletewin(Window*); |
| 45 | void xflushmemscreen(Window*, Rectangle); | 45 | void xflushmemscreen(Window*, Rectangle); |
| 46 | int xreplacescreenimage(Window*); | ||
| 46 | int xupdatelabel(Window*); | 47 | int xupdatelabel(Window*); |
| 48 | void xmovewindow(Window*, Rectangle); | ||
| @@ -9,6 +9,7 @@ XFILES=\ · 8 unmodified lines | |||
| 9 | itrans.$O\ | 9 | itrans.$O\ |
| 10 | keysym2ucs.$O\ | 10 | keysym2ucs.$O\ |
| 11 | window.$O\ | 11 | window.$O\ |
| 12 | wsys.$O\ | ||
| 12 | 13 | ||
| 13 | OFILES=\ | 14 | OFILES=\ |
| 14 | alloc.$O\ | 15 | alloc.$O\ |
| @@ -22,6 +22,7 @@ newwin(char *label, char *winsize) · 21 unmodified lines | |||
| 22 | 22 | ||
| 23 | w->id = id++; | 23 | w->id = id++; |
| 24 | w->label = label; | 24 | w->label = label; |
| 25 | w->draw.window = w; | ||
| 25 | xattach(w, winsize); | 26 | xattach(w, winsize); |
| 26 | 27 | ||
| 27 | return w; | 28 | return w; |
| @@ -9,9 +9,10 @@ · 8 unmodified lines | |||
| 9 | 9 | ||
| 10 | #define debugev(...) if(0) debug(__VA_ARGS__) | 10 | #define debugev(...) if(0) debug(__VA_ARGS__) |
| 11 | 11 | ||
| 12 | void configevent(Window *w, XEvent); | 12 | void configevent(Window*, XEvent); |
| 13 | void kbdevent(Window *w, XEvent); | 13 | void exposeevent(Window*, XEvent); |
| 14 | void mouseevent(Window *w, XEvent); | 14 | void kbdevent(Window*, XEvent); |
| 15 | void mouseevent(Window*, XEvent); | ||
| 15 | 16 | ||
| 16 | void | 17 | void |
| 17 | xnextevent(void) { | 18 | xnextevent(void) { |
| @@ -41,7 +42,7 @@ xnextevent(void) { · 23 unmodified lines | |||
| 41 | break; | 42 | break; |
| 42 | 43 | ||
| 43 | case Expose: | 44 | case Expose: |
| 44 | //xexpose(w, xev); | 45 | exposeevent(w, xev); |
| 45 | break; | 46 | break; |
| 46 | 47 | ||
| 47 | case DestroyNotify: | 48 | case DestroyNotify: |
| @@ -75,15 +76,63 @@ void · 27 unmodified lines | |||
| 75 | configevent(Window *w, XEvent xev) | 76 | configevent(Window *w, XEvent xev) |
| 76 | { | 77 | { |
| 77 | Mouse m; | 78 | 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; | ||
| 78 | 104 | ||
| 79 | // TODO: plan9port/src/cmd/devdraw/x11-init.c:686 | 105 | m.xy.x = xe->width; |
| 80 | m.xy.x = xev.xconfigure.width; | 106 | m.xy.y = xe->height; |
| 81 | m.xy.y = xev.xconfigure.height; | 107 | xreplacescreenimage(w); |
| 82 | // _xreplacescreenimage(); | ||
| 83 | debugev("Configure event at window %d: w=%d h=%d\n", w->id, m.xy.x, m.xy.y); | 108 | debugev("Configure event at window %d: w=%d h=%d\n", w->id, m.xy.x, m.xy.y); |
| 84 | writemouse(w, m, 1); | 109 | writemouse(w, m, 1); |
| 85 | } | 110 | } |
| 86 | 111 | ||
| 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 | |||
| 87 | void | 136 | void |
| 88 | kbdevent(Window *w, XEvent xev) | 137 | kbdevent(Window *w, XEvent xev) |
| 89 | { | 138 | { |
| @@ -91,10 +140,8 @@ kbdevent(Window *w, XEvent xev) · 1 unmodified line | |||
| 91 | 140 | ||
| 92 | XLookupString((XKeyEvent*)&xev, NULL, 0, &k, NULL); | 141 | XLookupString((XKeyEvent*)&xev, NULL, 0, &k, NULL); |
| 93 | if(k == XK_F11){ | 142 | if(k == XK_F11){ |
| 94 | /* TODO | 143 | w->fullscreen = !w->fullscreen; |
| 95 | fullscreen = !fullscreen; | 144 | xmovewindow(w, w->fullscreen ? xconn.screenrect : w->screenr); |
| 96 | _xmovewindow(fullscreen ? screenrect : windowrect); | ||
| 97 | */ | ||
| 98 | return; | 145 | return; |
| 99 | } | 146 | } |
| 100 | 147 | ||
| @@ -29,11 +29,11 @@ xattach(Window *w, char *winsize) · 28 unmodified lines | |||
| 29 | int havemin; | 29 | int havemin; |
| 30 | Xwin *xw; | 30 | Xwin *xw; |
| 31 | 31 | ||
| 32 | w->r = xwinrectangle(w->label, winsize, &havemin); | 32 | w->screenr = xwinrectangle(w->label, winsize, &havemin); |
| 33 | xw = xcreatewin(w->label, winsize, w->r); | 33 | xw = xcreatewin(w->label, winsize, w->screenr); |
| 34 | w->r = xmapwin(xw, havemin, w->r); | 34 | w->screenr = xmapwin(xw, havemin, w->screenr); |
| 35 | w->x = xw; | 35 | 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); |
| 37 | // initscreenimage(w); | 37 | // initscreenimage(w); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| @@ -48,6 +48,27 @@ xdeletewin(Window *w) · 8 unmodified lines | |||
| 48 | XSync(xconn.display, False); | 48 | XSync(xconn.display, False); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 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 | |||
| 51 | int | 72 | int |
| 52 | xupdatelabel(Window *w) | 73 | xupdatelabel(Window *w) |
| 53 | { | 74 | { |
| @@ -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 | } | ||