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