gdkvisual-x11.c 14.5 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4
/* GDK - The GIMP Drawing Kit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10 11
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19 20

/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

27
#include "config.h"
Elliot Lee's avatar
Elliot Lee committed
28

29
#include "gdkvisualprivate.h"
30
#include "gdkprivate-x11.h"
31
#include "gdkscreen-x11.h"
32

33 34 35
#include <X11/Xlib.h>
#include <X11/Xutil.h>

36
struct _GdkX11Visual
37
{
38 39
  GdkVisual visual;

40
  Visual *xvisual;
41
  Colormap colormap;
42
};
Elliot Lee's avatar
Elliot Lee committed
43

44
struct _GdkX11VisualClass
45 46 47 48
{
  GdkVisualClass visual_class;
};

49 50 51 52 53 54 55
static void     gdk_visual_add            (GdkVisual *visual);
static void     gdk_visual_decompose_mask (gulong     mask,
					   gint      *shift,
					   gint      *prec);
static guint    gdk_visual_hash           (Visual    *key);
static gboolean gdk_visual_equal          (Visual    *a,
					   Visual    *b);
Elliot Lee's avatar
Elliot Lee committed
56 57


58 59
#ifdef G_ENABLE_DEBUG

60
static const gchar *const visual_names[] =
Elliot Lee's avatar
Elliot Lee committed
61 62 63 64 65 66 67 68 69
{
  "static gray",
  "grayscale",
  "static color",
  "pseudo color",
  "true color",
  "direct color",
};

70 71
#endif /* G_ENABLE_DEBUG */

72
G_DEFINE_TYPE (GdkX11Visual, gdk_x11_visual, GDK_TYPE_VISUAL)
73

74
static void
75
gdk_x11_visual_init (GdkX11Visual *x11_visual)
76
{
77
  x11_visual->colormap = None;
78 79
}

80
static void
81
gdk_x11_visual_finalize (GObject *object)
Alex Larsson's avatar
Alex Larsson committed
82
{
83
  GdkVisual *visual = (GdkVisual *)object;
84
  GdkX11Visual *x11_visual = (GdkX11Visual *)object;
Alex Larsson's avatar
Alex Larsson committed
85

86 87
  if (x11_visual->colormap != None)
    XFreeColormap (GDK_SCREEN_XDISPLAY (visual->screen), x11_visual->colormap);
88

89
  G_OBJECT_CLASS (gdk_x11_visual_parent_class)->finalize (object);
Alex Larsson's avatar
Alex Larsson committed
90 91
}

92
static void
93
gdk_x11_visual_class_init (GdkX11VisualClass *class)
94
{
95
  GObjectClass *object_class = G_OBJECT_CLASS (class);
96

97
  object_class->finalize = gdk_x11_visual_finalize;
98
}
Alex Larsson's avatar
Alex Larsson committed
99

Elliot Lee's avatar
Elliot Lee committed
100
void
101
_gdk_x11_screen_init_visuals (GdkScreen *screen)
Elliot Lee's avatar
Elliot Lee committed
102
{
103
  static const gint possible_depths[8] = { 32, 30, 24, 16, 15, 8, 4, 1 };
104
  static const GdkVisualType possible_types[6] =
Elliot Lee's avatar
Elliot Lee committed
105 106 107 108 109 110 111 112 113
    {
      GDK_VISUAL_DIRECT_COLOR,
      GDK_VISUAL_TRUE_COLOR,
      GDK_VISUAL_PSEUDO_COLOR,
      GDK_VISUAL_STATIC_COLOR,
      GDK_VISUAL_GRAYSCALE,
      GDK_VISUAL_STATIC_GRAY
    };

114
  GdkScreenX11 *screen_x11;
Elliot Lee's avatar
Elliot Lee committed
115 116
  XVisualInfo *visual_list;
  XVisualInfo visual_template;
117
  GdkVisual *temp_visual;
Elliot Lee's avatar
Elliot Lee committed
118
  Visual *default_xvisual;
119
  GdkVisual **visuals;
Elliot Lee's avatar
Elliot Lee committed
120
  int nxvisuals;
121
  int nvisuals;
Elliot Lee's avatar
Elliot Lee committed
122
  int i, j;
123

124 125
  g_return_if_fail (GDK_IS_SCREEN (screen));
  screen_x11 = GDK_SCREEN_X11 (screen);
Elliot Lee's avatar
Elliot Lee committed
126

127
  nxvisuals = 0;
128 129
  visual_template.screen = screen_x11->screen_num;
  visual_list = XGetVisualInfo (screen_x11->xdisplay, VisualScreenMask, &visual_template, &nxvisuals);
130

131
  visuals = g_new (GdkVisual *, nxvisuals);
Alex Larsson's avatar
Alex Larsson committed
132
  for (i = 0; i < nxvisuals; i++)
133
    visuals[i] = g_object_new (GDK_TYPE_X11_VISUAL, NULL);
Elliot Lee's avatar
Elliot Lee committed
134

135
  default_xvisual = DefaultVisual (screen_x11->xdisplay, screen_x11->screen_num);
Elliot Lee's avatar
Elliot Lee committed
136 137 138 139

  nvisuals = 0;
  for (i = 0; i < nxvisuals; i++)
    {
140 141
      visuals[nvisuals]->screen = screen;

142
      if (visual_list[i].depth >= 1)
Elliot Lee's avatar
Elliot Lee committed
143 144 145 146 147 148 149 150
	{
#ifdef __cplusplus
	  switch (visual_list[i].c_class)
#else /* __cplusplus */
	  switch (visual_list[i].class)
#endif /* __cplusplus */
	    {
	    case StaticGray:
151
	      visuals[nvisuals]->type = GDK_VISUAL_STATIC_GRAY;
Elliot Lee's avatar
Elliot Lee committed
152 153
	      break;
	    case GrayScale:
154
	      visuals[nvisuals]->type = GDK_VISUAL_GRAYSCALE;
Elliot Lee's avatar
Elliot Lee committed
155 156
	      break;
	    case StaticColor:
157
	      visuals[nvisuals]->type = GDK_VISUAL_STATIC_COLOR;
Elliot Lee's avatar
Elliot Lee committed
158 159
	      break;
	    case PseudoColor:
160
	      visuals[nvisuals]->type = GDK_VISUAL_PSEUDO_COLOR;
Elliot Lee's avatar
Elliot Lee committed
161 162
	      break;
	    case TrueColor:
163
	      visuals[nvisuals]->type = GDK_VISUAL_TRUE_COLOR;
Elliot Lee's avatar
Elliot Lee committed
164 165
	      break;
	    case DirectColor:
166
	      visuals[nvisuals]->type = GDK_VISUAL_DIRECT_COLOR;
Elliot Lee's avatar
Elliot Lee committed
167 168 169
	      break;
	    }

170 171
	  visuals[nvisuals]->depth = visual_list[i].depth;
	  visuals[nvisuals]->byte_order =
172
	    (ImageByteOrder(screen_x11->xdisplay) == LSBFirst) ?
Elliot Lee's avatar
Elliot Lee committed
173
	    GDK_LSB_FIRST : GDK_MSB_FIRST;
174 175 176 177 178
	  visuals[nvisuals]->red_mask = visual_list[i].red_mask;
	  visuals[nvisuals]->green_mask = visual_list[i].green_mask;
	  visuals[nvisuals]->blue_mask = visual_list[i].blue_mask;
	  visuals[nvisuals]->colormap_size = visual_list[i].colormap_size;
	  visuals[nvisuals]->bits_per_rgb = visual_list[i].bits_per_rgb;
179
	  GDK_X11_VISUAL (visuals[nvisuals])->xvisual = visual_list[i].visual;
180 181 182

	  if ((visuals[nvisuals]->type == GDK_VISUAL_TRUE_COLOR) ||
	      (visuals[nvisuals]->type == GDK_VISUAL_DIRECT_COLOR))
Elliot Lee's avatar
Elliot Lee committed
183
	    {
184 185 186
	      gdk_visual_decompose_mask (visuals[nvisuals]->red_mask,
					 &visuals[nvisuals]->red_shift,
					 &visuals[nvisuals]->red_prec);
Elliot Lee's avatar
Elliot Lee committed
187

188 189 190
	      gdk_visual_decompose_mask (visuals[nvisuals]->green_mask,
					 &visuals[nvisuals]->green_shift,
					 &visuals[nvisuals]->green_prec);
Elliot Lee's avatar
Elliot Lee committed
191

192 193 194
	      gdk_visual_decompose_mask (visuals[nvisuals]->blue_mask,
					 &visuals[nvisuals]->blue_shift,
					 &visuals[nvisuals]->blue_prec);
Elliot Lee's avatar
Elliot Lee committed
195 196 197
	    }
	  else
	    {
198 199 200
	      visuals[nvisuals]->red_mask = 0;
	      visuals[nvisuals]->red_shift = 0;
	      visuals[nvisuals]->red_prec = 0;
Elliot Lee's avatar
Elliot Lee committed
201

202 203 204
	      visuals[nvisuals]->green_mask = 0;
	      visuals[nvisuals]->green_shift = 0;
	      visuals[nvisuals]->green_prec = 0;
Elliot Lee's avatar
Elliot Lee committed
205

206 207 208
	      visuals[nvisuals]->blue_mask = 0;
	      visuals[nvisuals]->blue_shift = 0;
	      visuals[nvisuals]->blue_prec = 0;
Elliot Lee's avatar
Elliot Lee committed
209
	    }
210

Elliot Lee's avatar
Elliot Lee committed
211 212 213 214
	  nvisuals += 1;
	}
    }

215 216
  if (visual_list)
    XFree (visual_list);
Elliot Lee's avatar
Elliot Lee committed
217 218 219 220 221

  for (i = 0; i < nvisuals; i++)
    {
      for (j = i+1; j < nvisuals; j++)
	{
222
	  if (visuals[j]->depth >= visuals[i]->depth)
Elliot Lee's avatar
Elliot Lee committed
223
	    {
224
	      if ((visuals[j]->depth == 8) && (visuals[i]->depth == 8))
Elliot Lee's avatar
Elliot Lee committed
225
		{
226
		  if (visuals[j]->type == GDK_VISUAL_PSEUDO_COLOR)
Elliot Lee's avatar
Elliot Lee committed
227 228 229 230 231
		    {
		      temp_visual = visuals[j];
		      visuals[j] = visuals[i];
		      visuals[i] = temp_visual;
		    }
232 233
		  else if ((visuals[i]->type != GDK_VISUAL_PSEUDO_COLOR) &&
			   visuals[j]->type > visuals[i]->type)
Elliot Lee's avatar
Elliot Lee committed
234 235 236 237 238 239
		    {
		      temp_visual = visuals[j];
		      visuals[j] = visuals[i];
		      visuals[i] = temp_visual;
		    }
		}
240 241 242
	      else if ((visuals[j]->depth > visuals[i]->depth) ||
		       ((visuals[j]->depth == visuals[i]->depth) &&
			(visuals[j]->type > visuals[i]->type)))
Elliot Lee's avatar
Elliot Lee committed
243 244 245 246 247 248 249 250 251 252
		{
		  temp_visual = visuals[j];
		  visuals[j] = visuals[i];
		  visuals[i] = temp_visual;
		}
	    }
	}
    }

  for (i = 0; i < nvisuals; i++)
253
    {
254
      if (default_xvisual->visualid == GDK_X11_VISUAL (visuals[i])->xvisual->visualid)
255
         {
256
           screen_x11->system_visual = visuals[i];
257
           GDK_X11_VISUAL (visuals[i])->colormap =
258
               DefaultColormap (screen_x11->xdisplay, screen_x11->screen_num);
259
         }
260 261 262 263 264

      /* For now, we only support 8888 ARGB for the "rgba visual".
       * Additional formats (like ABGR) could be added later if they
       * turn up.
       */
265 266 267 268
      if (visuals[i]->depth == 32 &&
	  (visuals[i]->red_mask   == 0xff0000 &&
	   visuals[i]->green_mask == 0x00ff00 &&
	   visuals[i]->blue_mask  == 0x0000ff))
269
	{
270 271
	  screen_x11->rgba_visual = visuals[i];
        }
272
    }
Elliot Lee's avatar
Elliot Lee committed
273

274
#ifdef G_ENABLE_DEBUG
275
  if (_gdk_debug_flags & GDK_DEBUG_MISC)
Benjamin Otte's avatar
Benjamin Otte committed
276 277 278 279 280 281 282 283 284 285 286 287
    {
      static const gchar *const visual_names[] =
      {
        "static gray",
        "grayscale",
        "static color",
        "pseudo color",
        "true color",
        "direct color",
      };

      for (i = 0; i < nvisuals; i++)
288
        g_message ("visual: %s: %d", visual_names[visuals[i]->type], visuals[i]->depth);
Benjamin Otte's avatar
Benjamin Otte committed
289
    }
Owen Taylor's avatar
Owen Taylor committed
290
#endif /* G_ENABLE_DEBUG */
Elliot Lee's avatar
Elliot Lee committed
291

292 293
  screen_x11->navailable_depths = 0;
  for (i = 0; i < G_N_ELEMENTS (possible_depths); i++)
Elliot Lee's avatar
Elliot Lee committed
294 295 296
    {
      for (j = 0; j < nvisuals; j++)
	{
297
	  if (visuals[j]->depth == possible_depths[i])
Elliot Lee's avatar
Elliot Lee committed
298
	    {
299
	      screen_x11->available_depths[screen_x11->navailable_depths++] = visuals[j]->depth;
Elliot Lee's avatar
Elliot Lee committed
300 301 302 303 304
	      break;
	    }
	}
    }

305
  if (screen_x11->navailable_depths == 0)
Elliot Lee's avatar
Elliot Lee committed
306 307
    g_error ("unable to find a usable depth");

308 309
  screen_x11->navailable_types = 0;
  for (i = 0; i < G_N_ELEMENTS (possible_types); i++)
Elliot Lee's avatar
Elliot Lee committed
310 311 312
    {
      for (j = 0; j < nvisuals; j++)
	{
313
	  if (visuals[j]->type == possible_types[i])
Elliot Lee's avatar
Elliot Lee committed
314
	    {
315
	      screen_x11->available_types[screen_x11->navailable_types++] = visuals[j]->type;
Elliot Lee's avatar
Elliot Lee committed
316 317 318 319 320 321
	      break;
	    }
	}
    }

  for (i = 0; i < nvisuals; i++)
322
    gdk_visual_add (visuals[i]);
Elliot Lee's avatar
Elliot Lee committed
323

324
  if (screen_x11->navailable_types == 0)
Elliot Lee's avatar
Elliot Lee committed
325
    g_error ("unable to find a usable visual type");
326 327 328

  screen_x11->visuals = visuals;
  screen_x11->nvisuals = nvisuals;
Elliot Lee's avatar
Elliot Lee committed
329 330 331
}

gint
332
_gdk_screen_x11_visual_get_best_depth (GdkScreen *screen)
Elliot Lee's avatar
Elliot Lee committed
333
{
334
  return GDK_SCREEN_X11 (screen)->available_depths[0];
Elliot Lee's avatar
Elliot Lee committed
335 336 337
}

GdkVisualType
338
_gdk_screen_x11_visual_get_best_type (GdkScreen *screen)
Elliot Lee's avatar
Elliot Lee committed
339
{
340 341 342 343
  return GDK_SCREEN_X11 (screen)->available_types[0];
}

GdkVisual *
344
_gdk_screen_x11_get_system_visual (GdkScreen *screen)
345 346 347 348
{
  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);

  return ((GdkVisual *) GDK_SCREEN_X11 (screen)->system_visual);
Elliot Lee's avatar
Elliot Lee committed
349 350 351
}

GdkVisual*
352
_gdk_screen_x11_visual_get_best (GdkScreen *screen)
Elliot Lee's avatar
Elliot Lee committed
353
{
354
  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
355

356
  return screen_x11->visuals[0];
Elliot Lee's avatar
Elliot Lee committed
357 358 359
}

GdkVisual*
360
_gdk_screen_x11_visual_get_best_with_depth (GdkScreen *screen,
361
                                            gint       depth)
Elliot Lee's avatar
Elliot Lee committed
362
{
363
  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
Elliot Lee's avatar
Elliot Lee committed
364 365
  GdkVisual *return_val;
  int i;
366
  
Elliot Lee's avatar
Elliot Lee committed
367
  return_val = NULL;
368
  for (i = 0; i < screen_x11->nvisuals; i++)
369
    if (depth == screen_x11->visuals[i]->depth)
Elliot Lee's avatar
Elliot Lee committed
370
      {
371
	return_val = screen_x11->visuals[i];
Elliot Lee's avatar
Elliot Lee committed
372 373 374 375 376 377 378
	break;
      }

  return return_val;
}

GdkVisual*
379 380
_gdk_screen_x11_visual_get_best_with_type (GdkScreen     *screen,
                                           GdkVisualType  visual_type)
Elliot Lee's avatar
Elliot Lee committed
381
{
382
  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
Elliot Lee's avatar
Elliot Lee committed
383 384 385 386
  GdkVisual *return_val;
  int i;

  return_val = NULL;
387
  for (i = 0; i < screen_x11->nvisuals; i++)
388
    if (visual_type == screen_x11->visuals[i]->type)
Elliot Lee's avatar
Elliot Lee committed
389
      {
390
	return_val = screen_x11->visuals[i];
Elliot Lee's avatar
Elliot Lee committed
391 392 393 394 395 396 397
	break;
      }

  return return_val;
}

GdkVisual*
398 399 400
_gdk_screen_x11_visual_get_best_with_both (GdkScreen     *screen,
                                           gint           depth,
                                           GdkVisualType  visual_type)
Elliot Lee's avatar
Elliot Lee committed
401
{
402
  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
Elliot Lee's avatar
Elliot Lee committed
403 404 405 406
  GdkVisual *return_val;
  int i;

  return_val = NULL;
407
  for (i = 0; i < screen_x11->nvisuals; i++)
408 409
    if ((depth == screen_x11->visuals[i]->depth) &&
	(visual_type == screen_x11->visuals[i]->type))
Elliot Lee's avatar
Elliot Lee committed
410
      {
411
	return_val = screen_x11->visuals[i];
Elliot Lee's avatar
Elliot Lee committed
412 413 414 415 416 417 418
	break;
      }

  return return_val;
}

void
419 420 421
_gdk_screen_x11_query_depths  (GdkScreen  *screen,
                               gint      **depths,
                               gint       *count)
Elliot Lee's avatar
Elliot Lee committed
422
{
423 424
  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);

425 426
  *count = screen_x11->navailable_depths;
  *depths = screen_x11->available_depths;
Elliot Lee's avatar
Elliot Lee committed
427 428 429
}

void
430 431 432
_gdk_screen_x11_query_visual_types (GdkScreen      *screen,
                                    GdkVisualType **visual_types,
                                    gint           *count)
Elliot Lee's avatar
Elliot Lee committed
433
{
434
  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
435

436 437
  *count = screen_x11->navailable_types;
  *visual_types = screen_x11->available_types;
Elliot Lee's avatar
Elliot Lee committed
438 439
}

440
GList *
441
_gdk_screen_x11_list_visuals (GdkScreen *screen)
Elliot Lee's avatar
Elliot Lee committed
442
{
443
  GList *list;
444
  GdkScreenX11 *screen_x11;
445 446
  guint i;

447 448
  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
  screen_x11 = GDK_SCREEN_X11 (screen);
449

450
  list = NULL;
451 452 453

  for (i = 0; i < screen_x11->nvisuals; ++i)
    list = g_list_append (list, screen_x11->visuals[i]);
454 455

  return list;
Elliot Lee's avatar
Elliot Lee committed
456 457
}

458
/**
Matthias Clasen's avatar
Matthias Clasen committed
459
 * gdk_x11_screen_lookup_visual:
460 461 462
 * @screen: a #GdkScreen.
 * @xvisualid: an X Visual ID.
 *
463
 * Looks up the #GdkVisual for a particular screen and X Visual ID.
464
 *
465 466
 * Returns: the #GdkVisual (owned by the screen object), or %NULL
 *   if the visual ID wasn't found.
Matthias Clasen's avatar
Matthias Clasen committed
467 468
 *
 * Since: 2.2
469 470
 */
GdkVisual *
471
gdk_x11_screen_lookup_visual (GdkScreen *screen,
472
                              VisualID   xvisualid)
Elliot Lee's avatar
Elliot Lee committed
473 474
{
  int i;
475 476 477
  GdkScreenX11 *screen_x11;
  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
  screen_x11 = GDK_SCREEN_X11 (screen);
Elliot Lee's avatar
Elliot Lee committed
478

479
  for (i = 0; i < screen_x11->nvisuals; i++)
480
    if (xvisualid == GDK_X11_VISUAL (screen_x11->visuals[i])->xvisual->visualid)
481
      return screen_x11->visuals[i];
Elliot Lee's avatar
Elliot Lee committed
482 483 484 485 486 487 488

  return NULL;
}

static void
gdk_visual_add (GdkVisual *visual)
{
489 490
  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (visual->screen);

491 492
  if (!screen_x11->visual_hash)
    screen_x11->visual_hash = g_hash_table_new ((GHashFunc) gdk_visual_hash,
493
                                                (GEqualFunc) gdk_visual_equal);
Elliot Lee's avatar
Elliot Lee committed
494

495
  g_hash_table_insert (screen_x11->visual_hash, GDK_X11_VISUAL (visual)->xvisual, visual);
Elliot Lee's avatar
Elliot Lee committed
496 497 498 499
}

static void
gdk_visual_decompose_mask (gulong  mask,
500 501
                           gint   *shift,
                           gint   *prec)
Elliot Lee's avatar
Elliot Lee committed
502 503 504 505
{
  *shift = 0;
  *prec = 0;

506 507 508 509 510 511
  if (mask == 0)
    {
      g_warning ("Mask is 0 in visual. Server bug ?");
      return;
    }

Elliot Lee's avatar
Elliot Lee committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
  while (!(mask & 0x1))
    {
      (*shift)++;
      mask >>= 1;
    }

  while (mask & 0x1)
    {
      (*prec)++;
      mask >>= 1;
    }
}

static guint
gdk_visual_hash (Visual *key)
{
  return key->visualid;
}

531 532
static gboolean
gdk_visual_equal (Visual *a,
533
                  Visual *b)
Elliot Lee's avatar
Elliot Lee committed
534 535 536
{
  return (a->visualid == b->visualid);
}
537

538 539 540 541 542 543 544 545 546 547 548
/**
 * _gdk_visual_get_x11_colormap:
 * @visual: the visual to get the colormap from
 *
 * Gets the colormap to use
 *
 * Returns: the X Colormap to use for new windows using @visual
 **/
Colormap
_gdk_visual_get_x11_colormap (GdkVisual *visual)
{
549
  GdkX11Visual *x11_visual;
550 551 552

  g_return_val_if_fail (GDK_IS_VISUAL (visual), None);

553
  x11_visual = GDK_X11_VISUAL (visual);
554

555
  if (x11_visual->colormap == None)
556
    {
557
      x11_visual->colormap = XCreateColormap (GDK_SCREEN_XDISPLAY (visual->screen),
558
                                              GDK_SCREEN_XROOTWIN (visual->screen),
559
                                              x11_visual->xvisual,
560
                                              AllocNone);
561 562
    }

563
  return x11_visual->colormap;
564 565
}

Matthias Clasen's avatar
Matthias Clasen committed
566 567 568
/**
 * gdk_x11_visual_get_xvisual:
 * @visual: a #GdkVisual.
569
 *
Matthias Clasen's avatar
Matthias Clasen committed
570
 * Returns the X visual belonging to a #GdkVisual.
571
 *
Matthias Clasen's avatar
Matthias Clasen committed
572 573
 * Return value: an Xlib <type>Visual*</type>.
 **/
574 575
Visual *
gdk_x11_visual_get_xvisual (GdkVisual *visual)
576 577 578
{
  g_return_val_if_fail (GDK_IS_VISUAL (visual), NULL);

579
  return GDK_X11_VISUAL (visual)->xvisual;
580
}