Skip to content

Commit 6460353

Browse files
committed
fix noise for text/plain;charset=utf-8
1 parent cac8065 commit 6460353

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

emu/port/win-x11a.c

+30-28
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* performance penalty (although it tries to use the X11 shared memory extension
77
* to copy the result to the screen, which might reduce the latter).
88
*
9-
* CraigN
9+
* CraigN
1010
*/
1111

1212
#define _GNU_SOURCE 1
@@ -76,8 +76,9 @@ XColor map7[128]; /* Inferno colormap array */
7676
uchar map7to8[128][2];
7777

7878
/* for copy/paste, lifted from plan9ports via drawterm */
79-
static Atom clipboard;
79+
static Atom clipboard;
8080
static Atom utf8string;
81+
static Atom textplainutf8;
8182
static Atom targets;
8283
static Atom text;
8384
static Atom compoundtext;
@@ -142,10 +143,10 @@ clean_errhandlers(void)
142143
{
143144
/* remove X11 error handler(s) */
144145
if(old_handler)
145-
XSetErrorHandler(old_handler);
146+
XSetErrorHandler(old_handler);
146147
old_handler = 0;
147148
if(old_io_handler)
148-
XSetErrorHandler(old_io_handler);
149+
XSetErrorHandler(old_io_handler);
149150
old_io_handler = 0;
150151
}
151152

@@ -161,14 +162,14 @@ makesharedfb(void)
161162
}
162163

163164
/* setup to catch X11 error(s) */
164-
XSync(xdisplay, 0);
165-
shm_got_x_error = 0;
165+
XSync(xdisplay, 0);
166+
shm_got_x_error = 0;
166167
if(old_handler != shm_ehandler)
167168
old_handler = XSetErrorHandler(shm_ehandler);
168169
if(old_io_handler != shm_ehandler)
169170
old_io_handler = XSetErrorHandler(shm_ehandler);
170171

171-
img = XShmCreateImage(xdisplay, xvis, xscreendepth, ZPixmap,
172+
img = XShmCreateImage(xdisplay, xvis, xscreendepth, ZPixmap,
172173
NULL, shminfo, Xsize, Ysize);
173174
XSync(xdisplay, 0);
174175

@@ -179,12 +180,12 @@ makesharedfb(void)
179180
clean_errhandlers();
180181
return 0;
181182
}
182-
183+
183184
if(img == nil) {
184185
fprint(2, "emu: cannot allocate virtual screen buffer\n");
185186
cleanexit(0);
186187
}
187-
188+
188189
shminfo->shmid = shmget(IPC_PRIVATE, img->bytes_per_line * img->height, IPC_CREAT|0777);
189190
shminfo->shmaddr = img->data = shmat(shminfo->shmid, 0, 0);
190191
shminfo->readOnly = True;
@@ -220,7 +221,7 @@ makesharedfb(void)
220221
cleanexit(0);
221222
}
222223
xscreendata = (uchar*)img->data;
223-
224+
224225
clean_errhandlers();
225226
return 1;
226227
}
@@ -256,27 +257,27 @@ attachscreen(Rectangle *r, ulong *chan, int *d, int *width, int *softscreen)
256257

257258
/* check for X Shared Memory Extension */
258259
is_shm = XShmQueryExtension(xdisplay);
259-
260+
260261
if(!is_shm || !makesharedfb()){
261262
is_shm = 0;
262263
depth = xscreendepth;
263264
if(depth == 24)
264265
depth = 32;
265266

266-
/* allocate virtual screen */
267+
/* allocate virtual screen */
267268
gscreendata = malloc(Xsize * Ysize * (displaydepth >> 3));
268269
xscreendata = malloc(Xsize * Ysize * (depth >> 3));
269270
if(gscreendata == nil || xscreendata == nil) {
270271
fprint(2, "emu: can not allocate virtual screen buffer (%dx%dx%d[%d])\n", Xsize, Ysize, displaydepth, depth);
271272
return 0;
272273
}
273-
img = XCreateImage(xdisplay, xvis, xscreendepth, ZPixmap, 0,
274+
img = XCreateImage(xdisplay, xvis, xscreendepth, ZPixmap, 0,
274275
(char*)xscreendata, Xsize, Ysize, 8, Xsize * (depth >> 3));
275276
if(img == nil) {
276277
fprint(2, "emu: can not allocate virtual screen buffer (%dx%dx%d)\n", Xsize, Ysize, depth);
277278
return 0;
278279
}
279-
280+
280281
}
281282

282283
if(!triedscreen){
@@ -353,7 +354,7 @@ copy8to32(Rectangle r)
353354
ep = gscreendata + r.max.y * Xsize + r.max.x;
354355
while(p < ep) {
355356
lp = p + width;
356-
while(p < lp)
357+
while(p < lp)
357358
*wp++ = infernotox11[*p++];
358359
p += dx;
359360
wp += dx;
@@ -399,7 +400,7 @@ copy8to16(Rectangle r)
399400
ep = gscreendata + r.max.y * Xsize + r.max.x;
400401
while(p < ep) {
401402
lp = p + width;
402-
while(p < lp)
403+
while(p < lp)
403404
*sp++ = infernotox11[*p++];
404405
p += dx;
405406
sp += dx;
@@ -547,7 +548,7 @@ xkbdproc(void *arg)
547548
/* BEWARE: the value of up is not defined for this proc on some systems */
548549

549550
XLockDisplay(xd); /* should be ours alone */
550-
XSelectInput(xd, xdrawable, KeyPressMask | KeyReleaseMask);
551+
XSelectInput(xd, xdrawable, KeyPressMask | KeyReleaseMask);
551552
for(;;){
552553
XNextEvent(xd, &event);
553554
xkeyboard(&event);
@@ -580,7 +581,7 @@ xproc(void *arg)
580581
StructureNotifyMask;
581582

582583
XLockDisplay(xd); /* should be ours alone */
583-
XSelectInput(xd, xdrawable, mask);
584+
XSelectInput(xd, xdrawable, mask);
584585
for(;;){
585586
XNextEvent(xd, &event);
586587
xselect(&event, xd);
@@ -858,7 +859,7 @@ xinitscreen(int xsize, int ysize, ulong reqchan, ulong *chan, int *d)
858859
XSetWindowAttributes attrs;
859860
char buf[30];
860861
int i;
861-
862+
862863
xdrawable = 0;
863864

864865
dispname = getenv("DISPLAY");
@@ -921,7 +922,7 @@ xinitscreen(int xsize, int ysize, ulong reqchan, ulong *chan, int *d)
921922
attrs.background_pixel = 0;
922923
attrs.border_pixel = 0;
923924
/* attrs.override_redirect = 1;*/ /* WM leave me alone! |CWOverrideRedirect */
924-
xdrawable = XCreateWindow(xdisplay, rootwin, 0, 0, xsize, ysize, 0, xscreendepth,
925+
xdrawable = XCreateWindow(xdisplay, rootwin, 0, 0, xsize, ysize, 0, xscreendepth,
925926
InputOutput, xvis, CWBackPixel|CWBorderPixel|CWColormap, &attrs);
926927

927928
/*
@@ -970,6 +971,7 @@ xinitscreen(int xsize, int ysize, ulong reqchan, ulong *chan, int *d)
970971

971972
clipboard = XInternAtom(xmcon, "CLIPBOARD", False);
972973
utf8string = XInternAtom(xmcon, "UTF8_STRING", False);
974+
textplainutf8 = XInternAtom(xmcon, "text/plain;charset=utf-8", False); /* for GNOME, GTK */
973975
targets = XInternAtom(xmcon, "TARGETS", False);
974976
text = XInternAtom(xmcon, "TEXT", False);
975977
compoundtext = XInternAtom(xmcon, "COMPOUND_TEXT", False);
@@ -1075,8 +1077,8 @@ graphicsrgbmap(XColor *mapr, XColor *mapg, XColor *mapb)
10751077
/*
10761078
* Initialize and install the Inferno colormap as a private colormap for this
10771079
* application. Inferno gets the best colors here when it has the cursor focus.
1078-
*/
1079-
static void
1080+
*/
1081+
static void
10801082
initxcmap(XWindow w)
10811083
{
10821084
XColor c;
@@ -1114,7 +1116,7 @@ if(0){int i, j; for(i=0;i<256; i+=16){print("%3d", i); for(j=i; j<i+16; j++)prin
11141116

11151117
case PseudoColor:
11161118
if(xtblbit == 0){
1117-
xcmap = XCreateColormap(xdisplay, w, xvis, AllocAll);
1119+
xcmap = XCreateColormap(xdisplay, w, xvis, AllocAll);
11181120
XStoreColors(xdisplay, xcmap, map, 256);
11191121
for(i = 0; i < 256; i++)
11201122
infernotox11[i] = i;
@@ -1275,7 +1277,7 @@ xkeyboard(XEvent *e)
12751277
case XK_KP_End:
12761278
k = End;
12771279
break;
1278-
case XK_Page_Up:
1280+
case XK_Page_Up:
12791281
case XK_KP_Page_Up:
12801282
k = Pgup;
12811283
break;
@@ -1356,7 +1358,7 @@ xmouse(XEvent *e)
13561358
switch(e->type){
13571359
case ButtonPress:
13581360
be = (XButtonEvent *)e;
1359-
/*
1361+
/*
13601362
* Fake message, just sent to make us announce snarf.
13611363
* Apparently state and button are 16 and 8 bits on
13621364
* the wire, since they are truncated by the time they
@@ -1511,7 +1513,7 @@ _xgetsnarf(XDisplay *xd)
15111513
data = nil;
15121514
goto out;
15131515
}
1514-
1516+
15151517
/*
15161518
* We should be waiting for SelectionNotify here, but it might never
15171519
* come, and we have no way to time out. Instead, we will clear
@@ -1540,7 +1542,7 @@ _xgetsnarf(XDisplay *xd)
15401542
}
15411543
/* get the property */
15421544
data = nil;
1543-
XGetWindowProperty(xd, xdrawable, prop, 0, SnarfSize/sizeof(unsigned long), 0,
1545+
XGetWindowProperty(xd, xdrawable, prop, 0, SnarfSize/sizeof(unsigned long), 0,
15441546
AnyPropertyType, &type, &fmt, &len, &dummy, &xdata);
15451547
if((type != XA_STRING && type != utf8string) || len == 0){
15461548
if(xdata)
@@ -1606,7 +1608,7 @@ if(0) iprint("xselect target=%d requestor=%d property=%d selection=%d\n",
16061608

16071609
XChangeProperty(xd, xe->requestor, xe->property, xe->target,
16081610
8, PropModeReplace, (uchar*)a, sizeof a);
1609-
}else if(xe->target == XA_STRING || xe->target == utf8string || xe->target == text || xe->target == compoundtext){
1611+
}else if(xe->target == XA_STRING || xe->target == utf8string || xe->target == textplainutf8 || xe->target == text || xe->target == compoundtext){
16101612
/* if the target is STRING we're supposed to reply with Latin1 XXX */
16111613
qlock(&clip.lk);
16121614
XChangeProperty(xd, xe->requestor, xe->property, xe->target,

0 commit comments

Comments
 (0)