comparison src/device-x.c @ 219:262b8bb4a523 r20-4b8

Import from CVS: tag r20-4b8
author cvs
date Mon, 13 Aug 2007 10:09:35 +0200
parents 41ff10fd062f
children 0e522484dd2a
comparison
equal deleted inserted replaced
218:c9f226976f56 219:262b8bb4a523
75 {"-internal-border-width", "*EmacsFrame.internalBorderWidth", XrmoptionSepArg, NULL}, 75 {"-internal-border-width", "*EmacsFrame.internalBorderWidth", XrmoptionSepArg, NULL},
76 {"-ib", "*EmacsFrame.internalBorderWidth", XrmoptionSepArg, NULL}, 76 {"-ib", "*EmacsFrame.internalBorderWidth", XrmoptionSepArg, NULL},
77 {"-scrollbar-width", "*EmacsFrame.scrollBarWidth", XrmoptionSepArg, NULL}, 77 {"-scrollbar-width", "*EmacsFrame.scrollBarWidth", XrmoptionSepArg, NULL},
78 {"-scrollbar-height", "*EmacsFrame.scrollBarHeight", XrmoptionSepArg, NULL}, 78 {"-scrollbar-height", "*EmacsFrame.scrollBarHeight", XrmoptionSepArg, NULL},
79 79
80 {"-privatecolormap", ".privateColormap", XrmoptionNoArg, "yes"},
81 {"-visual", ".EmacsVisual", XrmoptionSepArg, NULL},
82
80 /* #### Beware! If the type of the shell changes, update this. */ 83 /* #### Beware! If the type of the shell changes, update this. */
81 {"-T", "*TopLevelEmacsShell.title", XrmoptionSepArg, NULL}, 84 {"-T", "*TopLevelEmacsShell.title", XrmoptionSepArg, NULL},
82 {"-wn", "*TopLevelEmacsShell.title", XrmoptionSepArg, NULL}, 85 {"-wn", "*TopLevelEmacsShell.title", XrmoptionSepArg, NULL},
83 {"-title", "*TopLevelEmacsShell.title", XrmoptionSepArg, NULL}, 86 {"-title", "*TopLevelEmacsShell.title", XrmoptionSepArg, NULL},
84 87
98 101
99 /************************************************************************/ 102 /************************************************************************/
100 /* helper functions */ 103 /* helper functions */
101 /************************************************************************/ 104 /************************************************************************/
102 105
103 static struct device * 106 /* JH 97/11/25 removed the static declaration because I need it during setup in event-Xt... */
107 struct device *
104 get_device_from_display_1 (Display *dpy) 108 get_device_from_display_1 (Display *dpy)
105 { 109 {
106 Lisp_Object devcons, concons; 110 Lisp_Object devcons, concons;
107 111
108 DEVICE_LOOP_NO_BREAK (devcons, concons) 112 DEVICE_LOOP_NO_BREAK (devcons, concons)
200 } 204 }
201 205
202 static void 206 static void
203 x_init_device_class (struct device *d) 207 x_init_device_class (struct device *d)
204 { 208 {
205 Display *dpy = DEVICE_X_DISPLAY (d); 209 if (DEVICE_X_DEPTH(d) > 2)
206 if (DisplayCells (dpy, DefaultScreen (dpy)) > 2) 210 {
207 { 211 switch (DEVICE_X_VISUAL(d)->class)
208 switch (DefaultVisualOfScreen (DefaultScreenOfDisplay (dpy))->class)
209 { 212 {
210 case StaticGray: 213 case StaticGray:
211 case GrayScale: 214 case GrayScale:
212 DEVICE_CLASS (d) = Qgrayscale; 215 DEVICE_CLASS (d) = Qgrayscale;
213 break; 216 break;
223 x_init_device (struct device *d, Lisp_Object props) 226 x_init_device (struct device *d, Lisp_Object props)
224 { 227 {
225 Lisp_Object display; 228 Lisp_Object display;
226 Lisp_Object device; 229 Lisp_Object device;
227 Display *dpy; 230 Display *dpy;
231 Widget app_shell;
228 int argc; 232 int argc;
229 char **argv; 233 char **argv;
230 CONST char *app_class; 234 CONST char *app_class, *app_name;
231 CONST char *disp_name; 235 CONST char *disp_name;
236 Arg xargs[6];
237 Cardinal numargs;
238 Visual *visual = NULL;
239 int depth = 8; /* shut up the compiler */
240 Colormap cmap;
241 int screen;
232 242
233 XSETDEVICE (device, d); 243 XSETDEVICE (device, d);
234 display = DEVICE_CONNECTION (d); 244 display = DEVICE_CONNECTION (d);
235 245
236 allocate_x_device_struct (d); 246 allocate_x_device_struct (d);
256 { 266 {
257 suppress_early_backtrace = 1; 267 suppress_early_backtrace = 1;
258 signal_simple_error ("X server not responding\n", display); 268 signal_simple_error ("X server not responding\n", display);
259 } 269 }
260 270
271 screen = DefaultScreen(dpy);
261 if (NILP (Vdefault_x_device)) 272 if (NILP (Vdefault_x_device))
262 Vdefault_x_device = device; 273 Vdefault_x_device = device;
263 274
264 #ifdef MULE 275 #ifdef MULE
265 #if defined(LWLIB_MENUBARS_MOTIF) || defined(HAVE_XIM) || defined (USE_XFONTSET) 276 #if defined(LWLIB_MENUBARS_MOTIF) || defined(HAVE_XIM) || defined (USE_XFONTSET)
289 300
290 /* We're going to modify the string in-place, so be a nice XEmacs */ 301 /* We're going to modify the string in-place, so be a nice XEmacs */
291 DEVICE_NAME (d) = Fcopy_sequence (DEVICE_NAME (d)); 302 DEVICE_NAME (d) = Fcopy_sequence (DEVICE_NAME (d));
292 /* colons and periods can't appear in individual elements of resource 303 /* colons and periods can't appear in individual elements of resource
293 strings */ 304 strings */
305
306 XtGetApplicationNameAndClass (dpy, &app_name, &app_class);
307 /* search for a matching visual if requested by the user, or setup the display default */
308 numargs = 0;
309 {
310 char buf1[100],buf2[100];
311 char *type;
312 XrmValue value;
313
314 sprintf (buf1, "%s.emacsVisual", app_name);
315 sprintf (buf2, "%s.EmacsVisual", app_class);
316 if (XrmGetResource (XtDatabase (dpy), buf1, buf2, &type, &value) == True)
317 {
318 int cnt = 0, vis_class= PseudoColor;
319 XVisualInfo vinfo;
320 char *res, *str = (char*)value.addr;
321
322 if (strncmp(str, "StaticGray", 10) == 0) cnt = 10, vis_class = StaticGray;
323 else if (strncmp(str, "StaticColor", 11) == 0) cnt = 11, vis_class = StaticColor;
324 else if (strncmp(str, "TrueColor", 9) == 0) cnt = 9, vis_class = TrueColor;
325 else if (strncmp(str, "GrayScale", 9) == 0) cnt = 9, vis_class = GrayScale;
326 else if (strncmp(str, "PseudoColor", 11) == 0) cnt = 11, vis_class = PseudoColor;
327 else if (strncmp(str, "DirectColor", 11) == 0) cnt = 11, vis_class = DirectColor;
328 if (cnt)
329 {
330 res = str + cnt;
331 depth = atoi(res);
332 if (depth == 0)
333 {
334 stderr_out("Invalid Depth specification in %s... ignoring...\n",(char*)str);
335 }
336 else
337 {
338 if (XMatchVisualInfo(dpy, screen, depth, vis_class, &vinfo))
339 {
340 visual = vinfo.visual;
341 }
342 else
343 {
344 stderr_out("Can't match the requested visual %s... using defaults\n",str);
345 }
346 }
347 }
348 else
349 {
350 stderr_out("Invalid Visual specification in %s... ignoring.\n",(char*)str);
351 }
352 }
353 if (visual == NULL)
354 {
355 visual = DefaultVisual(dpy, screen);
356 depth = DefaultDepth(dpy, screen);
357 }
358
359 /* If we've got the same visual as the default and its PseudoColor, check to see if the user
360 specified that we need a private colormap */
361 if (visual == DefaultVisual(dpy, screen))
362 {
363 sprintf (buf1, "%s.privateColormap", app_name);
364 sprintf (buf2, "%s.PrivateColormap", app_class);
365 if ((visual->class == PseudoColor) &&
366 (XrmGetResource (XtDatabase (dpy), buf1, buf2, &type, &value) == True))
367 {
368 cmap = XCopyColormapAndFree(dpy, DefaultColormap(dpy, screen));
369 }
370 else
371 {
372 cmap = DefaultColormap(dpy, screen);
373 }
374 }
375 else
376 {
377 /* We have to create a matching colormap anyway...
378 ### think about using standard colormaps (need the Xmu libs?) */
379 cmap = XCreateColormap(dpy, RootWindow(dpy, screen), visual, AllocNone);
380 XInstallColormap(dpy, cmap);
381 }
382 }
383 XtSetArg(xargs[numargs],XtNvisual, visual); numargs++;
384 XtSetArg(xargs[numargs],XtNdepth, depth); numargs++;
385 XtSetArg(xargs[numargs],XtNcolormap, cmap); numargs++;
386 DEVICE_X_VISUAL (d) = visual;
387 DEVICE_X_COLORMAP (d) = cmap;
388 DEVICE_X_DEPTH (d) = depth;
389
294 validify_resource_string ((char *) XSTRING_DATA (DEVICE_NAME (d))); 390 validify_resource_string ((char *) XSTRING_DATA (DEVICE_NAME (d)));
295 DEVICE_XT_APP_SHELL (d) = XtAppCreateShell (NULL, app_class, 391 app_shell = XtAppCreateShell (NULL, app_class,
296 applicationShellWidgetClass, 392 applicationShellWidgetClass,
297 dpy, NULL, 0); 393 dpy, xargs, numargs);
298 394
395 DEVICE_XT_APP_SHELL (d) = app_shell;
299 #ifdef HAVE_XIM 396 #ifdef HAVE_XIM
300 XIM_init_device(d); 397 XIM_init_device(d);
301 #endif /* HAVE_XIM */ 398 #endif /* HAVE_XIM */
302 399
400 /* Realize the app_shell so that it's window exists for GC creation purposes,
401 and set it to the size of the root window for child placement purposes */
402 {
403 Screen *scrn = ScreenOfDisplay(dpy, screen);
404 int screen_width, screen_height;
405 screen_width = WidthOfScreen(scrn);
406 screen_height = HeightOfScreen(scrn);
407 numargs = 0;
408 XtSetArg (xargs[numargs], XtNmappedWhenManaged, False); numargs++;
409 XtSetArg (xargs[numargs], XtNx, 0); numargs++;
410 XtSetArg (xargs[numargs], XtNy, 0); numargs++;
411 XtSetArg (xargs[numargs], XtNwidth, screen_width); numargs++;
412 XtSetArg (xargs[numargs], XtNheight, screen_height); numargs++;
413 XtSetValues (app_shell, xargs, numargs);
414 XtRealizeWidget (app_shell);
415 }
303 #ifdef HAVE_SESSION 416 #ifdef HAVE_SESSION
304 { 417 {
305 Arg al[3]; 418 int new_argc;
306 Widget shell = DEVICE_XT_APP_SHELL (d); 419 char **new_argv;
307 420 make_argc_argv (Vcommand_line_args, &new_argc, &new_argv);
308 XtSetArg (al [0], XtNmappedWhenManaged, False); 421 XSetCommand (XtDisplay (app_shell), XtWindow (app_shell), new_argv, new_argc);
309 XtSetArg (al [1], XtNwidth, 1); 422 free_argc_argv (new_argv);
310 XtSetArg (al [2], XtNheight, 1);
311 XtSetValues (shell, al, 3);
312 XtRealizeWidget (shell);
313
314 {
315 int new_argc;
316 char **new_argv;
317 make_argc_argv (Vcommand_line_args, &new_argc, &new_argv);
318 XSetCommand (XtDisplay (shell), XtWindow (shell), new_argv, new_argc);
319 free_argc_argv (new_argv);
320 }
321
322 } 423 }
323 #endif /* HAVE_SESSION */ 424 #endif /* HAVE_SESSION */
324 425
426
325 #ifdef HAVE_OFFIX_DND 427 #ifdef HAVE_OFFIX_DND
326 DndInitialize ( DEVICE_XT_APP_SHELL (d) ); 428 DndInitialize ( app_shell );
327 #endif 429 #endif
328 430
329 Vx_initial_argv_list = make_arg_list (argc, argv); 431 Vx_initial_argv_list = make_arg_list (argc, argv);
330 free_argc_argv (argv); 432 free_argc_argv (argv);
331 433
338 440
339 DEVICE_INFD (d) = DEVICE_OUTFD (d) = ConnectionNumber (dpy); 441 DEVICE_INFD (d) = DEVICE_OUTFD (d) = ConnectionNumber (dpy);
340 init_baud_rate (d); 442 init_baud_rate (d);
341 init_one_device (d); 443 init_one_device (d);
342 444
343 DEVICE_X_GC_CACHE (d) = 445 DEVICE_X_GC_CACHE (d) = make_gc_cache (dpy, XtWindow(app_shell));
344 make_gc_cache (dpy, RootWindow (dpy, DefaultScreen (dpy)));
345 DEVICE_X_GRAY_PIXMAP (d) = None; 446 DEVICE_X_GRAY_PIXMAP (d) = None;
346 Xatoms_of_device_x (d); 447 Xatoms_of_device_x (d);
347 Xatoms_of_xselect (d); 448 Xatoms_of_xselect (d);
348 Xatoms_of_objects_x (d); 449 Xatoms_of_objects_x (d);
349 x_init_device_class (d); 450 x_init_device_class (d);
1133 { 1234 {
1134 return Vdefault_x_device; 1235 return Vdefault_x_device;
1135 } 1236 }
1136 1237
1137 DEFUN ("x-display-visual-class", Fx_display_visual_class, 0, 1, 0, /* 1238 DEFUN ("x-display-visual-class", Fx_display_visual_class, 0, 1, 0, /*
1138 Return the visual class of the X display `device' is on. 1239 Return the visual class of the X display `device' is using.
1240 This can be altered from the default at startup using the XResource "EmacsVisual".
1139 The returned value will be one of the symbols `static-gray', `gray-scale', 1241 The returned value will be one of the symbols `static-gray', `gray-scale',
1140 `static-color', `pseudo-color', `true-color', or `direct-color'. 1242 `static-color', `pseudo-color', `true-color', or `direct-color'.
1141 */ 1243 */
1142 (device)) 1244 (device))
1143 { 1245 {
1144 switch (DefaultVisualOfScreen 1246 Visual *vis = DEVICE_X_VISUAL (decode_x_device (device));
1145 (DefaultScreenOfDisplay (get_x_display (device)))->class) 1247 switch (vis->class)
1146 { 1248 {
1147 case StaticGray: return intern ("static-gray"); 1249 case StaticGray: return intern ("static-gray");
1148 case GrayScale: return intern ("gray-scale"); 1250 case GrayScale: return intern ("gray-scale");
1149 case StaticColor: return intern ("static-color"); 1251 case StaticColor: return intern ("static-color");
1150 case PseudoColor: return intern ("pseudo-color"); 1252 case PseudoColor: return intern ("pseudo-color");
1153 default: 1255 default:
1154 error ("display has an unknown visual class"); 1256 error ("display has an unknown visual class");
1155 } 1257 }
1156 1258
1157 return Qnil; /* suppress compiler warning */ 1259 return Qnil; /* suppress compiler warning */
1260 }
1261
1262 DEFUN ("x-display-visual-depth", Fx_display_visual_depth, 0, 1, 0, /*
1263 Return the bitplane depth of the visual the X display `device' is using.
1264 */
1265 (device))
1266 {
1267 return make_int (DEVICE_X_DEPTH (decode_x_device (device)));
1158 } 1268 }
1159 1269
1160 static int 1270 static int
1161 x_device_pixel_width (struct device *d) 1271 x_device_pixel_width (struct device *d)
1162 { 1272 {
1441 DEFSUBR (Fx_get_resource_prefix); 1551 DEFSUBR (Fx_get_resource_prefix);
1442 DEFSUBR (Fx_put_resource); 1552 DEFSUBR (Fx_put_resource);
1443 1553
1444 DEFSUBR (Fdefault_x_device); 1554 DEFSUBR (Fdefault_x_device);
1445 DEFSUBR (Fx_display_visual_class); 1555 DEFSUBR (Fx_display_visual_class);
1556 DEFSUBR (Fx_display_visual_depth);
1446 DEFSUBR (Fx_server_vendor); 1557 DEFSUBR (Fx_server_vendor);
1447 DEFSUBR (Fx_server_version); 1558 DEFSUBR (Fx_server_version);
1448 DEFSUBR (Fx_valid_keysym_name_p); 1559 DEFSUBR (Fx_valid_keysym_name_p);
1449 DEFSUBR (Fx_keysym_hashtable); 1560 DEFSUBR (Fx_keysym_hashtable);
1450 DEFSUBR (Fx_keysym_on_keyboard_p); 1561 DEFSUBR (Fx_keysym_on_keyboard_p);