Unified · Split
| @@ -74,12 +74,12 @@ xallocmemimage(Rectangle r, ulong chan, int pmid, XImage **X) · 73 unmodified lines | ||
| 74 | 74 | else |
| 75 | 75 | offset = r.min.x&(31/d); |
| 76 | 76 | r.min.x -= offset; |
| 77 | − | |
| 77 | + | |
| 78 | 78 | assert(wordsperline(r, m->depth) <= m->width); |
| 79 | 79 | |
| 80 | 80 | xi = XCreateImage(xdisplay, xvis, m->depth==32?24:m->depth, ZPixmap, 0, |
| 81 | 81 | (char*)m->data->bdata, Dx(r), Dy(r), 32, m->width*sizeof(ulong)); |
| 82 | − | |
| 82 | + | |
| 83 | 83 | if(xi == nil){ |
| 84 | 84 | freememimage(m); |
| 85 | 85 | return nil; |
| @@ -114,7 +114,7 @@ static uchar map7to8[128][2]; · 28 unmodified lines | ||
| 114 | 114 | static Colormap xcmap; /* Default shared colormap */ |
| 115 | 115 | |
| 116 | 116 | /* for copy/paste, lifted from plan9ports */ |
| 117 | −static Atom clipboard; | |
| 117 | +static Atom clipboard; | |
| 118 | 118 | static Atom utf8string; |
| 119 | 119 | static Atom targets; |
| 120 | 120 | static Atom text; |
| @@ -131,7 +131,7 @@ static void xmapping(XEvent*); · 10 unmodified lines | ||
| 131 | 131 | static void xdestroy(XEvent*); |
| 132 | 132 | static void xselect(XEvent*, XDisplay*); |
| 133 | 133 | static void xproc(void*); |
| 134 | −static void initmap(Window); | |
| 134 | +static void initmap(XDisplay*, int, Visual*); | |
| 135 | 135 | static GC creategc(Drawable); |
| 136 | 136 | static void graphicscmap(XColor*); |
| 137 | 137 | static int xscreendepth; |
| @@ -141,7 +141,6 @@ static XDisplay* xsnarfcon; /* used holding clip.lk */ · 3 unmodified lines | ||
| 141 | 141 | static int putsnarf, assertsnarf; |
| 142 | 142 | |
| 143 | 143 | Memimage *gscreen; |
| 144 | −Screeninfo screen; | |
| 145 | 144 | |
| 146 | 145 | static int |
| 147 | 146 | shutup(XDisplay *d, XErrorEvent *e) |
| @@ -178,7 +177,7 @@ flushmemscreen(Rectangle r) · 30 unmodified lines | ||
| 178 | 177 | for(y=r.min.y; y<r.max.y; y++) |
| 179 | 178 | for(x=r.min.x, p=byteaddr(gscreen, Pt(x,y)); x<r.max.x; x++, p++) |
| 180 | 179 | *p = plan9tox11[*p]; |
| 181 | − | |
| 180 | + | |
| 182 | 181 | XPutImage(xdisplay, xscreenid, xgccopy, xscreenimage, r.min.x, r.min.y, r.min.x, r.min.y, Dx(r), Dy(r)); |
| 183 | 182 | |
| 184 | 183 | if(xtblbit && gscreen->chan == CMAP8) |
| @@ -195,12 +194,10 @@ screeninit(void) · 10 unmodified lines | ||
| 195 | 194 | { |
| 196 | 195 | int i, n, x, y; |
| 197 | 196 | char *argv[2]; |
| 198 | − Window rootwin; | |
| 199 | 197 | Rectangle r; |
| 200 | 198 | XWMHints hints; |
| 201 | − XScreen *screen; | |
| 202 | 199 | XVisualInfo xvi; |
| 203 | − int rootscreennum; | |
| 200 | + int screen; | |
| 204 | 201 | XTextProperty name; |
| 205 | 202 | XClassHint classhints; |
| 206 | 203 | XSizeHints normalhints; |
| @@ -234,24 +231,22 @@ screeninit(void) · 27 unmodified lines | ||
| 234 | 231 | if(xsnarfcon == 0) |
| 235 | 232 | panic("XOpenDisplay: %r [DISPLAY=%s]", getenv("DISPLAY")); |
| 236 | 233 | |
| 237 | − rootscreennum = DefaultScreen(xdisplay); | |
| 238 | − rootwin = DefaultRootWindow(xdisplay); | |
| 239 | − | |
| 240 | − xscreendepth = DefaultDepth(xdisplay, rootscreennum); | |
| 241 | − if(XMatchVisualInfo(xdisplay, rootscreennum, 16, TrueColor, &xvi) | |
| 242 | − || XMatchVisualInfo(xdisplay, rootscreennum, 16, DirectColor, &xvi)){ | |
| 234 | + screen = DefaultScreen(xdisplay); | |
| 235 | + xscreendepth = DefaultDepth(xdisplay, screen); | |
| 236 | + if(XMatchVisualInfo(xdisplay, screen, 16, TrueColor, &xvi) | |
| 237 | + || XMatchVisualInfo(xdisplay, screen, 16, DirectColor, &xvi)){ | |
| 243 | 238 | xvis = xvi.visual; |
| 244 | 239 | xscreendepth = 16; |
| 245 | 240 | xtblbit = 1; |
| 246 | 241 | } |
| 247 | − else if(XMatchVisualInfo(xdisplay, rootscreennum, 24, TrueColor, &xvi) | |
| 248 | − || XMatchVisualInfo(xdisplay, rootscreennum, 24, DirectColor, &xvi)){ | |
| 242 | + else if(XMatchVisualInfo(xdisplay, screen, 24, TrueColor, &xvi) | |
| 243 | + || XMatchVisualInfo(xdisplay, screen, 24, DirectColor, &xvi)){ | |
| 249 | 244 | xvis = xvi.visual; |
| 250 | 245 | xscreendepth = 24; |
| 251 | 246 | xtblbit = 1; |
| 252 | 247 | } |
| 253 | − else if(XMatchVisualInfo(xdisplay, rootscreennum, 8, PseudoColor, &xvi) | |
| 254 | − || XMatchVisualInfo(xdisplay, rootscreennum, 8, StaticColor, &xvi)){ | |
| 248 | + else if(XMatchVisualInfo(xdisplay, screen, 8, PseudoColor, &xvi) | |
| 249 | + || XMatchVisualInfo(xdisplay, screen, 8, StaticColor, &xvi)){ | |
| 255 | 250 | if(xscreendepth > 8) |
| 256 | 251 | panic("can't deal with colormapped depth %d screens", xscreendepth); |
| 257 | 252 | xvis = xvi.visual; |
| @@ -260,7 +255,7 @@ screeninit(void) · 2 unmodified lines | ||
| 260 | 255 | else{ |
| 261 | 256 | if(xscreendepth != 8) |
| 262 | 257 | panic("can't deal with depth %d screens", xscreendepth); |
| 263 | − xvis = DefaultVisual(xdisplay, rootscreennum); | |
| 258 | + xvis = DefaultVisual(xdisplay, screen); | |
| 264 | 259 | } |
| 265 | 260 | |
| 266 | 261 | /* |
| @@ -299,40 +294,34 @@ screeninit(void) · 32 unmodified lines | ||
| 299 | 294 | } |
| 300 | 295 | if(xscreenchan == 0) |
| 301 | 296 | panic("unknown screen pixel format"); |
| 302 | − | |
| 303 | − screen = DefaultScreenOfDisplay(xdisplay); | |
| 304 | − xcmap = DefaultColormapOfScreen(screen); | |
| 305 | 297 | |
| 306 | − if(xvis->class != StaticColor){ | |
| 307 | − graphicscmap(map); | |
| 308 | − initmap(rootwin); | |
| 309 | − } | |
| 298 | + initmap(xdisplay, screen, xvis); | |
| 310 | 299 | |
| 311 | 300 | x = y = 0; |
| 312 | 301 | r = ZR; |
| 313 | 302 | if(geometry != nil) |
| 314 | − XParseGeometry(geometry, &x, &y, &r.max.x, &r.max.y); | |
| 303 | + XParseGeometry(geometry, &x, &y, (unsigned int*)&r.max.x, (unsigned int*)&r.max.y); | |
| 304 | + | |
| 315 | 305 | if(r.max.x == 0) |
| 316 | − r.max.x = WidthOfScreen(screen)*3/4; | |
| 306 | + r.max.x = WidthOfScreen(ScreenOfDisplay(xdisplay, screen))*3/4; | |
| 317 | 307 | if(r.max.y == 0) |
| 318 | − r.max.y = HeightOfScreen(screen)*3/4; | |
| 319 | − | |
| 308 | + r.max.y = HeightOfScreen(ScreenOfDisplay(xdisplay, screen))*3/4; | |
| 309 | + | |
| 320 | 310 | attrs.colormap = xcmap; |
| 321 | 311 | attrs.background_pixel = 0; |
| 322 | 312 | attrs.border_pixel = 0; |
| 323 | 313 | /* attrs.override_redirect = 1;*/ /* WM leave me alone! |CWOverrideRedirect */ |
| 324 | − xdrawable = XCreateWindow(xkmcon, rootwin, x, y, Dx(r), Dy(r), 0, | |
| 314 | + xdrawable = XCreateWindow(xkmcon, RootWindow(xdisplay, screen), x, y, Dx(r), Dy(r), 0, | |
| 325 | 315 | xscreendepth, InputOutput, xvis, CWBackPixel|CWBorderPixel|CWColormap, &attrs); |
| 326 | 316 | |
| 327 | 317 | /* load the given bitmap data and create an X pixmap containing it. */ |
| 328 | − icon_pixmap = XCreateBitmapFromData(xkmcon, | |
| 329 | − rootwin, (char *)glenda_t_bits, | |
| 330 | − glenda_t_width, glenda_t_height); | |
| 318 | + icon_pixmap = XCreateBitmapFromData(xkmcon, RootWindow(xdisplay, screen), | |
| 319 | + (char *)glenda_t_bits, glenda_t_width, glenda_t_height); | |
| 331 | 320 | |
| 332 | 321 | /* |
| 333 | 322 | * set up property as required by ICCCM |
| 334 | 323 | */ |
| 335 | − if((name.value = getenv("WM_NAME")) == nil) | |
| 324 | + if((name.value = (uchar*)getenv("WM_NAME")) == nil) | |
| 336 | 325 | name.value = (uchar*)"drawterm"; |
| 337 | 326 | name.encoding = XA_STRING; |
| 338 | 327 | name.format = 8; |
| @@ -370,7 +359,7 @@ screeninit(void) · 31 unmodified lines | ||
| 370 | 359 | 1); /* int nelements */ |
| 371 | 360 | XFlush(xkmcon); |
| 372 | 361 | } |
| 373 | − | |
| 362 | + | |
| 374 | 363 | /* |
| 375 | 364 | * put the window on the screen |
| 376 | 365 | */ |
| @@ -618,15 +607,20 @@ graphicscmap(XColor *map) · 241 unmodified lines | ||
| 618 | 607 | /* |
| 619 | 608 | * Initialize and install the drawterm colormap as a private colormap for this |
| 620 | 609 | * application. Drawterm gets the best colors here when it has the cursor focus. |
| 621 | − */ | |
| 622 | −static void | |
| 623 | −initmap(Window w) | |
| 610 | + */ | |
| 611 | +static void | |
| 612 | +initmap(XDisplay *xdisplay, int screen, Visual *xvis) | |
| 624 | 613 | { |
| 625 | 614 | XColor c; |
| 626 | 615 | int i; |
| 627 | 616 | ulong p, pp; |
| 628 | 617 | char buf[30]; |
| 629 | 618 | |
| 619 | + xcmap = DefaultColormap(xdisplay, screen); | |
| 620 | + if(xvis->class == StaticColor) | |
| 621 | + return; | |
| 622 | + | |
| 623 | + graphicscmap(map); | |
| 630 | 624 | if(xscreendepth <= 1) |
| 631 | 625 | return; |
| 632 | 626 | |
| @@ -634,16 +628,15 @@ initmap(Window w) · 1 unmodified line | ||
| 634 | 628 | /* The pixel value returned from XGetPixel needs to |
| 635 | 629 | * be converted to RGB so we can call rgb2cmap() |
| 636 | 630 | * to translate between 24 bit X and our color. Unfortunately, |
| 637 | − * the return value appears to be display server endian | |
| 631 | + * the return value appears to be display server endian | |
| 638 | 632 | * dependant. Therefore, we run some heuristics to later |
| 639 | 633 | * determine how to mask the int value correctly. |
| 640 | − * Yeah, I know we can look at xvis->byte_order but | |
| 634 | + * Yeah, I know we can look at xvis->byte_order but | |
| 641 | 635 | * some displays say MSB even though they run on LSB. |
| 642 | 636 | * Besides, this is more anal. |
| 643 | 637 | */ |
| 644 | − if(xscreendepth != DefaultDepth(xdisplay, DefaultScreen(xdisplay))) | |
| 645 | − xcmap = XCreateColormap(xdisplay, w, xvis, AllocNone); | |
| 646 | − | |
| 638 | + if(xvis != DefaultVisual(xdisplay, screen)) | |
| 639 | + xcmap = XCreateColormap(xdisplay, RootWindow(xdisplay, screen), xvis, AllocNone); | |
| 647 | 640 | c = map[19]; |
| 648 | 641 | /* find out index into colormap for our RGB */ |
| 649 | 642 | if(!XAllocColor(xdisplay, xcmap, &c)) |
| @@ -664,7 +657,7 @@ initmap(Window w) · 14 unmodified lines | ||
| 664 | 657 | xscreenchan = XBGR32; |
| 665 | 658 | break; |
| 666 | 659 | default: |
| 667 | − panic("don't know how to byteswap channel %s", | |
| 660 | + panic("don't know how to byteswap channel %s", | |
| 668 | 661 | chantostr(buf, xscreenchan)); |
| 669 | 662 | break; |
| 670 | 663 | } |
| @@ -672,7 +665,7 @@ initmap(Window w) · 1 unmodified line | ||
| 672 | 665 | } else if(xvis->class == TrueColor || xvis->class == DirectColor) { |
| 673 | 666 | } else if(xvis->class == PseudoColor) { |
| 674 | 667 | if(xtblbit == 0){ |
| 675 | − xcmap = XCreateColormap(xdisplay, w, xvis, AllocAll); | |
| 668 | + xcmap = XCreateColormap(xdisplay, RootWindow(xdisplay, screen), xvis, AllocAll); | |
| 676 | 669 | XStoreColors(xdisplay, xcmap, map, 256); |
| 677 | 670 | for(i = 0; i < 256; i++) { |
| 678 | 671 | plan9tox11[i] = i; |
| @@ -859,7 +852,7 @@ xkeyboard(XEvent *e) · 180 unmodified lines | ||
| 859 | 852 | case XK_KP_End: |
| 860 | 853 | k = Kend; |
| 861 | 854 | break; |
| 862 | − case XK_Page_Up: | |
| 855 | + case XK_Page_Up: | |
| 863 | 856 | case XK_KP_Page_Up: |
| 864 | 857 | k = Kpgup; |
| 865 | 858 | break; |
| @@ -959,7 +952,7 @@ xmouse(XEvent *e) · 93 unmodified lines | ||
| 959 | 952 | switch(e->type){ |
| 960 | 953 | case ButtonPress: |
| 961 | 954 | be = (XButtonEvent *)e; |
| 962 | − /* | |
| 955 | + /* | |
| 963 | 956 | * Fake message, just sent to make us announce snarf. |
| 964 | 957 | * Apparently state and button are 16 and 8 bits on |
| 965 | 958 | * the wire, since they are truncated by the time they |
| @@ -1045,7 +1038,7 @@ void · 79 unmodified lines | ||
| 1045 | 1038 | getcolor(ulong i, ulong *r, ulong *g, ulong *b) |
| 1046 | 1039 | { |
| 1047 | 1040 | ulong v; |
| 1048 | − | |
| 1041 | + | |
| 1049 | 1042 | v = cmap2rgb(i); |
| 1050 | 1043 | *r = (v>>16)&0xFF; |
| 1051 | 1044 | *g = (v>>8)&0xFF; |
| @@ -1118,7 +1111,7 @@ _xgetsnarf(XDisplay *xd) · 66 unmodified lines | ||
| 1118 | 1111 | data = nil; |
| 1119 | 1112 | goto out; |
| 1120 | 1113 | } |
| 1121 | − | |
| 1114 | + | |
| 1122 | 1115 | /* |
| 1123 | 1116 | * We should be waiting for SelectionNotify here, but it might never |
| 1124 | 1117 | * come, and we have no way to time out. Instead, we will clear |
| @@ -1144,7 +1137,7 @@ _xgetsnarf(XDisplay *xd) · 19 unmodified lines | ||
| 1144 | 1137 | } |
| 1145 | 1138 | /* get the property */ |
| 1146 | 1139 | data = nil; |
| 1147 | − XGetWindowProperty(xd, xdrawable, prop, 0, SnarfSize/sizeof(unsigned long), 0, | |
| 1140 | + XGetWindowProperty(xd, xdrawable, prop, 0, SnarfSize/sizeof(unsigned long), 0, | |
| 1148 | 1141 | AnyPropertyType, &type, &fmt, &len, &dummy, &xdata); |
| 1149 | 1142 | if((type != XA_STRING && type != utf8string) || len == 0){ |
| 1150 | 1143 | if(xdata) |