6
6
* performance penalty (although it tries to use the X11 shared memory extension
7
7
* to copy the result to the screen, which might reduce the latter).
8
8
*
9
- * CraigN
9
+ * CraigN
10
10
*/
11
11
12
12
#define _GNU_SOURCE 1
@@ -76,8 +76,9 @@ XColor map7[128]; /* Inferno colormap array */
76
76
uchar map7to8 [128 ][2 ];
77
77
78
78
/* for copy/paste, lifted from plan9ports via drawterm */
79
- static Atom clipboard ;
79
+ static Atom clipboard ;
80
80
static Atom utf8string ;
81
+ static Atom textplainutf8 ;
81
82
static Atom targets ;
82
83
static Atom text ;
83
84
static Atom compoundtext ;
@@ -142,10 +143,10 @@ clean_errhandlers(void)
142
143
{
143
144
/* remove X11 error handler(s) */
144
145
if (old_handler )
145
- XSetErrorHandler (old_handler );
146
+ XSetErrorHandler (old_handler );
146
147
old_handler = 0 ;
147
148
if (old_io_handler )
148
- XSetErrorHandler (old_io_handler );
149
+ XSetErrorHandler (old_io_handler );
149
150
old_io_handler = 0 ;
150
151
}
151
152
@@ -161,14 +162,14 @@ makesharedfb(void)
161
162
}
162
163
163
164
/* 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 ;
166
167
if (old_handler != shm_ehandler )
167
168
old_handler = XSetErrorHandler (shm_ehandler );
168
169
if (old_io_handler != shm_ehandler )
169
170
old_io_handler = XSetErrorHandler (shm_ehandler );
170
171
171
- img = XShmCreateImage (xdisplay , xvis , xscreendepth , ZPixmap ,
172
+ img = XShmCreateImage (xdisplay , xvis , xscreendepth , ZPixmap ,
172
173
NULL , shminfo , Xsize , Ysize );
173
174
XSync (xdisplay , 0 );
174
175
@@ -179,12 +180,12 @@ makesharedfb(void)
179
180
clean_errhandlers ();
180
181
return 0 ;
181
182
}
182
-
183
+
183
184
if (img == nil ) {
184
185
fprint (2 , "emu: cannot allocate virtual screen buffer\n" );
185
186
cleanexit (0 );
186
187
}
187
-
188
+
188
189
shminfo -> shmid = shmget (IPC_PRIVATE , img -> bytes_per_line * img -> height , IPC_CREAT |0777 );
189
190
shminfo -> shmaddr = img -> data = shmat (shminfo -> shmid , 0 , 0 );
190
191
shminfo -> readOnly = True ;
@@ -220,7 +221,7 @@ makesharedfb(void)
220
221
cleanexit (0 );
221
222
}
222
223
xscreendata = (uchar * )img -> data ;
223
-
224
+
224
225
clean_errhandlers ();
225
226
return 1 ;
226
227
}
@@ -256,27 +257,27 @@ attachscreen(Rectangle *r, ulong *chan, int *d, int *width, int *softscreen)
256
257
257
258
/* check for X Shared Memory Extension */
258
259
is_shm = XShmQueryExtension (xdisplay );
259
-
260
+
260
261
if (!is_shm || !makesharedfb ()){
261
262
is_shm = 0 ;
262
263
depth = xscreendepth ;
263
264
if (depth == 24 )
264
265
depth = 32 ;
265
266
266
- /* allocate virtual screen */
267
+ /* allocate virtual screen */
267
268
gscreendata = malloc (Xsize * Ysize * (displaydepth >> 3 ));
268
269
xscreendata = malloc (Xsize * Ysize * (depth >> 3 ));
269
270
if (gscreendata == nil || xscreendata == nil ) {
270
271
fprint (2 , "emu: can not allocate virtual screen buffer (%dx%dx%d[%d])\n" , Xsize , Ysize , displaydepth , depth );
271
272
return 0 ;
272
273
}
273
- img = XCreateImage (xdisplay , xvis , xscreendepth , ZPixmap , 0 ,
274
+ img = XCreateImage (xdisplay , xvis , xscreendepth , ZPixmap , 0 ,
274
275
(char * )xscreendata , Xsize , Ysize , 8 , Xsize * (depth >> 3 ));
275
276
if (img == nil ) {
276
277
fprint (2 , "emu: can not allocate virtual screen buffer (%dx%dx%d)\n" , Xsize , Ysize , depth );
277
278
return 0 ;
278
279
}
279
-
280
+
280
281
}
281
282
282
283
if (!triedscreen ){
@@ -353,7 +354,7 @@ copy8to32(Rectangle r)
353
354
ep = gscreendata + r .max .y * Xsize + r .max .x ;
354
355
while (p < ep ) {
355
356
lp = p + width ;
356
- while (p < lp )
357
+ while (p < lp )
357
358
* wp ++ = infernotox11 [* p ++ ];
358
359
p += dx ;
359
360
wp += dx ;
@@ -399,7 +400,7 @@ copy8to16(Rectangle r)
399
400
ep = gscreendata + r .max .y * Xsize + r .max .x ;
400
401
while (p < ep ) {
401
402
lp = p + width ;
402
- while (p < lp )
403
+ while (p < lp )
403
404
* sp ++ = infernotox11 [* p ++ ];
404
405
p += dx ;
405
406
sp += dx ;
@@ -547,7 +548,7 @@ xkbdproc(void *arg)
547
548
/* BEWARE: the value of up is not defined for this proc on some systems */
548
549
549
550
XLockDisplay (xd ); /* should be ours alone */
550
- XSelectInput (xd , xdrawable , KeyPressMask | KeyReleaseMask );
551
+ XSelectInput (xd , xdrawable , KeyPressMask | KeyReleaseMask );
551
552
for (;;){
552
553
XNextEvent (xd , & event );
553
554
xkeyboard (& event );
@@ -580,7 +581,7 @@ xproc(void *arg)
580
581
StructureNotifyMask ;
581
582
582
583
XLockDisplay (xd ); /* should be ours alone */
583
- XSelectInput (xd , xdrawable , mask );
584
+ XSelectInput (xd , xdrawable , mask );
584
585
for (;;){
585
586
XNextEvent (xd , & event );
586
587
xselect (& event , xd );
@@ -858,7 +859,7 @@ xinitscreen(int xsize, int ysize, ulong reqchan, ulong *chan, int *d)
858
859
XSetWindowAttributes attrs ;
859
860
char buf [30 ];
860
861
int i ;
861
-
862
+
862
863
xdrawable = 0 ;
863
864
864
865
dispname = getenv ("DISPLAY" );
@@ -921,7 +922,7 @@ xinitscreen(int xsize, int ysize, ulong reqchan, ulong *chan, int *d)
921
922
attrs .background_pixel = 0 ;
922
923
attrs .border_pixel = 0 ;
923
924
/* 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 ,
925
926
InputOutput , xvis , CWBackPixel |CWBorderPixel |CWColormap , & attrs );
926
927
927
928
/*
@@ -970,6 +971,7 @@ xinitscreen(int xsize, int ysize, ulong reqchan, ulong *chan, int *d)
970
971
971
972
clipboard = XInternAtom (xmcon , "CLIPBOARD" , False );
972
973
utf8string = XInternAtom (xmcon , "UTF8_STRING" , False );
974
+ textplainutf8 = XInternAtom (xmcon , "text/plain;charset=utf-8" , False ); /* for GNOME, GTK */
973
975
targets = XInternAtom (xmcon , "TARGETS" , False );
974
976
text = XInternAtom (xmcon , "TEXT" , False );
975
977
compoundtext = XInternAtom (xmcon , "COMPOUND_TEXT" , False );
@@ -1075,8 +1077,8 @@ graphicsrgbmap(XColor *mapr, XColor *mapg, XColor *mapb)
1075
1077
/*
1076
1078
* Initialize and install the Inferno colormap as a private colormap for this
1077
1079
* application. Inferno gets the best colors here when it has the cursor focus.
1078
- */
1079
- static void
1080
+ */
1081
+ static void
1080
1082
initxcmap (XWindow w )
1081
1083
{
1082
1084
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
1114
1116
1115
1117
case PseudoColor :
1116
1118
if (xtblbit == 0 ){
1117
- xcmap = XCreateColormap (xdisplay , w , xvis , AllocAll );
1119
+ xcmap = XCreateColormap (xdisplay , w , xvis , AllocAll );
1118
1120
XStoreColors (xdisplay , xcmap , map , 256 );
1119
1121
for (i = 0 ; i < 256 ; i ++ )
1120
1122
infernotox11 [i ] = i ;
@@ -1275,7 +1277,7 @@ xkeyboard(XEvent *e)
1275
1277
case XK_KP_End :
1276
1278
k = End ;
1277
1279
break ;
1278
- case XK_Page_Up :
1280
+ case XK_Page_Up :
1279
1281
case XK_KP_Page_Up :
1280
1282
k = Pgup ;
1281
1283
break ;
@@ -1356,7 +1358,7 @@ xmouse(XEvent *e)
1356
1358
switch (e -> type ){
1357
1359
case ButtonPress :
1358
1360
be = (XButtonEvent * )e ;
1359
- /*
1361
+ /*
1360
1362
* Fake message, just sent to make us announce snarf.
1361
1363
* Apparently state and button are 16 and 8 bits on
1362
1364
* the wire, since they are truncated by the time they
@@ -1511,7 +1513,7 @@ _xgetsnarf(XDisplay *xd)
1511
1513
data = nil ;
1512
1514
goto out ;
1513
1515
}
1514
-
1516
+
1515
1517
/*
1516
1518
* We should be waiting for SelectionNotify here, but it might never
1517
1519
* come, and we have no way to time out. Instead, we will clear
@@ -1540,7 +1542,7 @@ _xgetsnarf(XDisplay *xd)
1540
1542
}
1541
1543
/* get the property */
1542
1544
data = nil ;
1543
- XGetWindowProperty (xd , xdrawable , prop , 0 , SnarfSize /sizeof (unsigned long ), 0 ,
1545
+ XGetWindowProperty (xd , xdrawable , prop , 0 , SnarfSize /sizeof (unsigned long ), 0 ,
1544
1546
AnyPropertyType , & type , & fmt , & len , & dummy , & xdata );
1545
1547
if ((type != XA_STRING && type != utf8string ) || len == 0 ){
1546
1548
if (xdata )
@@ -1606,7 +1608,7 @@ if(0) iprint("xselect target=%d requestor=%d property=%d selection=%d\n",
1606
1608
1607
1609
XChangeProperty (xd , xe -> requestor , xe -> property , xe -> target ,
1608
1610
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 ){
1610
1612
/* if the target is STRING we're supposed to reply with Latin1 XXX */
1611
1613
qlock (& clip .lk );
1612
1614
XChangeProperty (xd , xe -> requestor , xe -> property , xe -> target ,
0 commit comments