aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGerd Moellmann2000-03-05 10:25:26 +0000
committerGerd Moellmann2000-03-05 10:25:26 +0000
commita6ad00c02a925972fb1e449ca22c69bb96f1e3fa (patch)
tree93e94dd91fd49d62f0098b775b37f8d81b92185e /src
parent3997f048b2d5846db4de64e138d83e6c9507d5ee (diff)
downloademacs-a6ad00c02a925972fb1e449ca22c69bb96f1e3fa.tar.gz
emacs-a6ad00c02a925972fb1e449ca22c69bb96f1e3fa.zip
(select_visual): Rewritten. Recognize user-specified
visual classes. (visual_classes): New variable.
Diffstat (limited to 'src')
-rw-r--r--src/xfns.c159
1 files changed, 117 insertions, 42 deletions
diff --git a/src/xfns.c b/src/xfns.c
index a5f8ac3ba54..3e9ebb7b374 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -5453,71 +5453,145 @@ See the documentation of `x-rebind-key' for more information.")
5453} 5453}
5454#endif /* HAVE_X11 */ 5454#endif /* HAVE_X11 */
5455#endif /* 0 */ 5455#endif /* 0 */
5456
5457
5458/************************************************************************
5459 X Displays
5460 ************************************************************************/
5461
5456 5462
5463/* Mapping visual names to visuals. */
5464
5465static struct visual_class
5466{
5467 char *name;
5468 int class;
5469}
5470visual_classes[] =
5471{
5472 {"StaticGray", StaticGray},
5473 {"GrayScale", GrayScale},
5474 {"StaticColor", StaticColor},
5475 {"PseudoColor", PseudoColor},
5476 {"TrueColor", TrueColor},
5477 {"DirectColor", DirectColor},
5478 NULL
5479};
5480
5481
5457#ifndef HAVE_XSCREENNUMBEROFSCREEN 5482#ifndef HAVE_XSCREENNUMBEROFSCREEN
5483
5484/* Value is the screen number of screen SCR. This is a substitute for
5485 the X function with the same name when that doesn't exist. */
5486
5458int 5487int
5459XScreenNumberOfScreen (scr) 5488XScreenNumberOfScreen (scr)
5460 register Screen *scr; 5489 register Screen *scr;
5461{ 5490{
5462 register Display *dpy; 5491 Display *dpy = scr->display;
5463 register Screen *dpyscr; 5492 int i;
5464 register int i;
5465
5466 dpy = scr->display;
5467 dpyscr = dpy->screens;
5468 5493
5469 for (i = 0; i < dpy->nscreens; i++, dpyscr++) 5494 for (i = 0; i < dpy->nscreens; ++i)
5470 if (scr == dpyscr) 5495 if (scr == dpy->screens[i])
5471 return i; 5496 break;
5472 5497
5473 return -1; 5498 return i;
5474} 5499}
5500
5475#endif /* not HAVE_XSCREENNUMBEROFSCREEN */ 5501#endif /* not HAVE_XSCREENNUMBEROFSCREEN */
5476 5502
5477Visual *
5478select_visual (dpy, screen, depth)
5479 Display *dpy;
5480 Screen *screen;
5481 unsigned int *depth;
5482{
5483 Visual *v;
5484 XVisualInfo *vinfo, vinfo_template;
5485 int n_visuals;
5486 5503
5487 v = DefaultVisualOfScreen (screen); 5504/* Select the visual that should be used on display DPYINFO. Set
5505 members of DPYINFO appropriately. Called from x_term_init. */
5488 5506
5489#ifdef HAVE_X11R4 5507void
5490 vinfo_template.visualid = XVisualIDFromVisual (v); 5508select_visual (dpyinfo)
5491#else 5509 struct x_display_info *dpyinfo;
5492 vinfo_template.visualid = v->visualid; 5510{
5493#endif 5511 Display *dpy = dpyinfo->display;
5512 Screen *screen = dpyinfo->screen;
5513 Lisp_Object value;
5494 5514
5495 vinfo_template.screen = XScreenNumberOfScreen (screen); 5515 /* See if a visual is specified. */
5516 value = display_x_get_resource (dpyinfo,
5517 build_string ("visualClass"),
5518 build_string ("VisualClass"),
5519 Qnil, Qnil);
5520 if (STRINGP (value))
5521 {
5522 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
5523 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
5524 depth, a decimal number. NAME is compared with case ignored. */
5525 char *s = (char *) alloca (STRING_BYTES (XSTRING (value)) + 1);
5526 char *dash;
5527 int i, class = -1;
5528 XVisualInfo vinfo;
5529
5530 strcpy (s, XSTRING (value)->data);
5531 dash = index (s, '-');
5532 if (dash)
5533 {
5534 dpyinfo->n_planes = atoi (dash + 1);
5535 *dash = '\0';
5536 }
5537 else
5538 /* We won't find a matching visual with depth 0, so that
5539 an error will be printed below. */
5540 dpyinfo->n_planes = 0;
5496 5541
5497 vinfo = XGetVisualInfo (dpy, 5542 /* Determine the visual class. */
5498 VisualIDMask | VisualScreenMask, &vinfo_template, 5543 for (i = 0; visual_classes[i].name; ++i)
5499 &n_visuals); 5544 if (xstricmp (s, visual_classes[i].name) == 0)
5500 if (n_visuals != 1) 5545 {
5501 fatal ("Can't get proper X visual info"); 5546 class = visual_classes[i].class;
5547 break;
5548 }
5502 5549
5503 if ((1 << vinfo->depth) == vinfo->colormap_size) 5550 /* Look up a matching visual for the specified class. */
5504 *depth = vinfo->depth; 5551 if (class == -1
5552 || !XMatchVisualInfo (dpy, XScreenNumberOfScreen (screen),
5553 dpyinfo->n_planes, class, &vinfo))
5554 fatal ("Invalid visual specification `%s'", XSTRING (value)->data);
5555
5556 dpyinfo->visual = vinfo.visual;
5557 }
5505 else 5558 else
5506 { 5559 {
5507 int i = 0; 5560 int n_visuals;
5508 int n = vinfo->colormap_size - 1; 5561 XVisualInfo *vinfo, vinfo_template;
5509 while (n) 5562
5563 dpyinfo->visual = DefaultVisualOfScreen (screen);
5564
5565#ifdef HAVE_X11R4
5566 vinfo_template.visualid = XVisualIDFromVisual (dpyinfo->visual);
5567#else
5568 vinfo_template.visualid = dpyinfo->visual->visualid;
5569#endif
5570 vinfo_template.screen = XScreenNumberOfScreen (screen);
5571 vinfo = XGetVisualInfo (dpy, VisualIDMask | VisualScreenMask,
5572 &vinfo_template, &n_visuals);
5573 if (n_visuals != 1)
5574 fatal ("Can't get proper X visual info");
5575
5576 if ((1 << vinfo->depth) == vinfo->colormap_size)
5577 dpyinfo->n_planes = vinfo->depth;
5578 else
5510 { 5579 {
5511 n = n >> 1; 5580 int i = 0;
5512 i++; 5581 int n = vinfo->colormap_size - 1;
5582 while (n)
5583 {
5584 n = n >> 1;
5585 i++;
5586 }
5587 dpyinfo->n_planes = i;
5513 } 5588 }
5514 *depth = i;
5515 }
5516 5589
5517 XFree ((char *) vinfo); 5590 XFree ((char *) vinfo);
5518 return v; 5591 }
5519} 5592}
5520 5593
5594
5521/* Return the X display structure for the display named NAME. 5595/* Return the X display structure for the display named NAME.
5522 Open a new connection if necessary. */ 5596 Open a new connection if necessary. */
5523 5597
@@ -5560,6 +5634,7 @@ x_display_info_for_name (name)
5560 return dpyinfo; 5634 return dpyinfo;
5561} 5635}
5562 5636
5637
5563DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection, 5638DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
5564 1, 3, 0, "Open a connection to an X server.\n\ 5639 1, 3, 0, "Open a connection to an X server.\n\
5565DISPLAY is the name of the display to connect to.\n\ 5640DISPLAY is the name of the display to connect to.\n\