History

revert accidental x11.c change

cinap_lenrek committed 3 years ago

Commit 06d141d1 parent 4d5e1e71 file · +45 −52Browse files

Unified · Split

gui-x11/x11.c+45−52
@@ -74,12 +74,12 @@ xallocmemimage(Rectangle r, ulong chan, int pmid, XImage **X) · 73 unmodified lines
7474 else
7575 offset = r.min.x&(31/d);
7676 r.min.x -= offset;
77−
77+
7878 assert(wordsperline(r, m->depth) <= m->width);
7979
8080 xi = XCreateImage(xdisplay, xvis, m->depth==32?24:m->depth, ZPixmap, 0,
8181 (char*)m->data->bdata, Dx(r), Dy(r), 32, m->width*sizeof(ulong));
82−
82+
8383 if(xi == nil){
8484 freememimage(m);
8585 return nil;
@@ -114,7 +114,7 @@ static uchar map7to8[128][2]; · 28 unmodified lines
114114 static Colormap xcmap; /* Default shared colormap */
115115
116116 /* for copy/paste, lifted from plan9ports */
117−static Atom clipboard;
117+static Atom clipboard;
118118 static Atom utf8string;
119119 static Atom targets;
120120 static Atom text;
@@ -131,7 +131,7 @@ static void xmapping(XEvent*); · 10 unmodified lines
131131 static void xdestroy(XEvent*);
132132 static void xselect(XEvent*, XDisplay*);
133133 static void xproc(void*);
134−static void initmap(Window);
134+static void initmap(XDisplay*, int, Visual*);
135135 static GC creategc(Drawable);
136136 static void graphicscmap(XColor*);
137137 static int xscreendepth;
@@ -141,7 +141,6 @@ static XDisplay* xsnarfcon; /* used holding clip.lk */ · 3 unmodified lines
141141 static int putsnarf, assertsnarf;
142142
143143 Memimage *gscreen;
144−Screeninfo screen;
145144
146145 static int
147146 shutup(XDisplay *d, XErrorEvent *e)
@@ -178,7 +177,7 @@ flushmemscreen(Rectangle r) · 30 unmodified lines
178177 for(y=r.min.y; y<r.max.y; y++)
179178 for(x=r.min.x, p=byteaddr(gscreen, Pt(x,y)); x<r.max.x; x++, p++)
180179 *p = plan9tox11[*p];
181−
180+
182181 XPutImage(xdisplay, xscreenid, xgccopy, xscreenimage, r.min.x, r.min.y, r.min.x, r.min.y, Dx(r), Dy(r));
183182
184183 if(xtblbit && gscreen->chan == CMAP8)
@@ -195,12 +194,10 @@ screeninit(void) · 10 unmodified lines
195194 {
196195 int i, n, x, y;
197196 char *argv[2];
198− Window rootwin;
199197 Rectangle r;
200198 XWMHints hints;
201− XScreen *screen;
202199 XVisualInfo xvi;
203− int rootscreennum;
200+ int screen;
204201 XTextProperty name;
205202 XClassHint classhints;
206203 XSizeHints normalhints;
@@ -234,24 +231,22 @@ screeninit(void) · 27 unmodified lines
234231 if(xsnarfcon == 0)
235232 panic("XOpenDisplay: %r [DISPLAY=%s]", getenv("DISPLAY"));
236233
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)){
243238 xvis = xvi.visual;
244239 xscreendepth = 16;
245240 xtblbit = 1;
246241 }
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)){
249244 xvis = xvi.visual;
250245 xscreendepth = 24;
251246 xtblbit = 1;
252247 }
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)){
255250 if(xscreendepth > 8)
256251 panic("can't deal with colormapped depth %d screens", xscreendepth);
257252 xvis = xvi.visual;
@@ -260,7 +255,7 @@ screeninit(void) · 2 unmodified lines
260255 else{
261256 if(xscreendepth != 8)
262257 panic("can't deal with depth %d screens", xscreendepth);
263− xvis = DefaultVisual(xdisplay, rootscreennum);
258+ xvis = DefaultVisual(xdisplay, screen);
264259 }
265260
266261 /*
@@ -299,40 +294,34 @@ screeninit(void) · 32 unmodified lines
299294 }
300295 if(xscreenchan == 0)
301296 panic("unknown screen pixel format");
302−
303− screen = DefaultScreenOfDisplay(xdisplay);
304− xcmap = DefaultColormapOfScreen(screen);
305297
306− if(xvis->class != StaticColor){
307− graphicscmap(map);
308− initmap(rootwin);
309− }
298+ initmap(xdisplay, screen, xvis);
310299
311300 x = y = 0;
312301 r = ZR;
313302 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+
315305 if(r.max.x == 0)
316− r.max.x = WidthOfScreen(screen)*3/4;
306+ r.max.x = WidthOfScreen(ScreenOfDisplay(xdisplay, screen))*3/4;
317307 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+
320310 attrs.colormap = xcmap;
321311 attrs.background_pixel = 0;
322312 attrs.border_pixel = 0;
323313 /* 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,
325315 xscreendepth, InputOutput, xvis, CWBackPixel|CWBorderPixel|CWColormap, &attrs);
326316
327317 /* 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);
331320
332321 /*
333322 * set up property as required by ICCCM
334323 */
335− if((name.value = getenv("WM_NAME")) == nil)
324+ if((name.value = (uchar*)getenv("WM_NAME")) == nil)
336325 name.value = (uchar*)"drawterm";
337326 name.encoding = XA_STRING;
338327 name.format = 8;
@@ -370,7 +359,7 @@ screeninit(void) · 31 unmodified lines
370359 1); /* int nelements */
371360 XFlush(xkmcon);
372361 }
373−
362+
374363 /*
375364 * put the window on the screen
376365 */
@@ -618,15 +607,20 @@ graphicscmap(XColor *map) · 241 unmodified lines
618607 /*
619608 * Initialize and install the drawterm colormap as a private colormap for this
620609 * 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)
624613 {
625614 XColor c;
626615 int i;
627616 ulong p, pp;
628617 char buf[30];
629618
619+ xcmap = DefaultColormap(xdisplay, screen);
620+ if(xvis->class == StaticColor)
621+ return;
622+
623+ graphicscmap(map);
630624 if(xscreendepth <= 1)
631625 return;
632626
@@ -634,16 +628,15 @@ initmap(Window w) · 1 unmodified line
634628 /* The pixel value returned from XGetPixel needs to
635629 * be converted to RGB so we can call rgb2cmap()
636630 * 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
638632 * dependant. Therefore, we run some heuristics to later
639633 * 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
641635 * some displays say MSB even though they run on LSB.
642636 * Besides, this is more anal.
643637 */
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);
647640 c = map[19];
648641 /* find out index into colormap for our RGB */
649642 if(!XAllocColor(xdisplay, xcmap, &c))
@@ -664,7 +657,7 @@ initmap(Window w) · 14 unmodified lines
664657 xscreenchan = XBGR32;
665658 break;
666659 default:
667− panic("don't know how to byteswap channel %s",
660+ panic("don't know how to byteswap channel %s",
668661 chantostr(buf, xscreenchan));
669662 break;
670663 }
@@ -672,7 +665,7 @@ initmap(Window w) · 1 unmodified line
672665 } else if(xvis->class == TrueColor || xvis->class == DirectColor) {
673666 } else if(xvis->class == PseudoColor) {
674667 if(xtblbit == 0){
675− xcmap = XCreateColormap(xdisplay, w, xvis, AllocAll);
668+ xcmap = XCreateColormap(xdisplay, RootWindow(xdisplay, screen), xvis, AllocAll);
676669 XStoreColors(xdisplay, xcmap, map, 256);
677670 for(i = 0; i < 256; i++) {
678671 plan9tox11[i] = i;
@@ -859,7 +852,7 @@ xkeyboard(XEvent *e) · 180 unmodified lines
859852 case XK_KP_End:
860853 k = Kend;
861854 break;
862− case XK_Page_Up:
855+ case XK_Page_Up:
863856 case XK_KP_Page_Up:
864857 k = Kpgup;
865858 break;
@@ -959,7 +952,7 @@ xmouse(XEvent *e) · 93 unmodified lines
959952 switch(e->type){
960953 case ButtonPress:
961954 be = (XButtonEvent *)e;
962− /*
955+ /*
963956 * Fake message, just sent to make us announce snarf.
964957 * Apparently state and button are 16 and 8 bits on
965958 * the wire, since they are truncated by the time they
@@ -1045,7 +1038,7 @@ void · 79 unmodified lines
10451038 getcolor(ulong i, ulong *r, ulong *g, ulong *b)
10461039 {
10471040 ulong v;
1048−
1041+
10491042 v = cmap2rgb(i);
10501043 *r = (v>>16)&0xFF;
10511044 *g = (v>>8)&0xFF;
@@ -1118,7 +1111,7 @@ _xgetsnarf(XDisplay *xd) · 66 unmodified lines
11181111 data = nil;
11191112 goto out;
11201113 }
1121−
1114+
11221115 /*
11231116 * We should be waiting for SelectionNotify here, but it might never
11241117 * come, and we have no way to time out. Instead, we will clear
@@ -1144,7 +1137,7 @@ _xgetsnarf(XDisplay *xd) · 19 unmodified lines
11441137 }
11451138 /* get the property */
11461139 data = nil;
1147− XGetWindowProperty(xd, xdrawable, prop, 0, SnarfSize/sizeof(unsigned long), 0,
1140+ XGetWindowProperty(xd, xdrawable, prop, 0, SnarfSize/sizeof(unsigned long), 0,
11481141 AnyPropertyType, &type, &fmt, &len, &dummy, &xdata);
11491142 if((type != XA_STRING && type != utf8string) || len == 0){
11501143 if(xdata)

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