gdkvisual-x11.c 15 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 31

#include "gdkx.h"
32
#include "gdkprivate-x11.h"
33
#include "gdkscreen-x11.h"
34

35 36 37
#include <X11/Xlib.h>
#include <X11/Xutil.h>

38 39 40 41 42 43 44
typedef struct _GdkVisualX11 GdkVisualX11;
typedef struct _GdkVisualClass GdkVisualX11Class;

#define GDK_TYPE_VISUAL_X11 (gdk_visual_x11_get_type ())
#define GDK_VISUAL_X11(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_VISUAL_X11, GdkVisualX11))

struct _GdkVisualX11
45
{
46 47
  GdkVisual visual;

48
  Visual *xvisual;
49
  Colormap colormap;
50
};
Elliot Lee's avatar
Elliot Lee committed
51

52 53 54 55 56 57 58
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
59 60


61 62
#ifdef G_ENABLE_DEBUG

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

73 74
#endif /* G_ENABLE_DEBUG */

75
G_DEFINE_TYPE (GdkVisualX11, gdk_visual_x11, GDK_TYPE_VISUAL)
76

77
static void
78
gdk_visual_x11_init (GdkVisualX11 *visual_x11)
79
{
80
  visual_x11->colormap = None;
81 82
}

83
static void
84
gdk_visual_x11_finalize (GObject *object)
Alex Larsson's avatar
Alex Larsson committed
85
{
86 87
  GdkVisual *visual = (GdkVisual *)object;
  GdkVisualX11 *visual_x11 = (GdkVisualX11 *)object;
Alex Larsson's avatar
Alex Larsson committed
88

89 90
  if (visual_x11->colormap != None)
    XFreeColormap (GDK_SCREEN_XDISPLAY (visual->screen), visual_x11->colormap);
91

92
  G_OBJECT_CLASS (gdk_visual_x11_parent_class)->finalize (object);
Alex Larsson's avatar
Alex Larsson committed
93 94
}

95
static void
96
gdk_visual_x11_class_init (GdkVisualX11Class *class)
97
{
98
  GObjectClass *object_class = G_OBJECT_CLASS (class);
99

100
  object_class->finalize = gdk_visual_x11_finalize;
101
}
Alex Larsson's avatar
Alex Larsson committed
102

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

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

127 128
  g_return_if_fail (GDK_IS_SCREEN (screen));
  screen_x11 = GDK_SCREEN_X11 (screen);
Elliot Lee's avatar
Elliot Lee committed
129

130
  nxvisuals = 0;
131 132
  visual_template.screen = screen_x11->screen_num;
  visual_list = XGetVisualInfo (screen_x11->xdisplay, VisualScreenMask, &visual_template, &nxvisuals);
133

134
  visuals = g_new (GdkVisual *, nxvisuals);
Alex Larsson's avatar
Alex Larsson committed
135
  for (i = 0; i < nxvisuals; i++)
136
    visuals[i] = g_object_new (GDK_TYPE_VISUAL_X11, NULL);
Elliot Lee's avatar
Elliot Lee committed
137

138
  default_xvisual = DefaultVisual (screen_x11->xdisplay, screen_x11->screen_num);
Elliot Lee's avatar
Elliot Lee committed
139 140 141 142

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

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

173 174
	  visuals[nvisuals]->depth = visual_list[i].depth;
	  visuals[nvisuals]->byte_order =
175
	    (ImageByteOrder(screen_x11->xdisplay) == LSBFirst) ?
Elliot Lee's avatar
Elliot Lee committed
176
	    GDK_LSB_FIRST : GDK_MSB_FIRST;
177 178 179 180 181
	  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;
182
	  GDK_VISUAL_X11 (visuals[nvisuals])->xvisual = visual_list[i].visual;
183 184 185

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

191 192 193
	      gdk_visual_decompose_mask (visuals[nvisuals]->green_mask,
					 &visuals[nvisuals]->green_shift,
					 &visuals[nvisuals]->green_prec);
Elliot Lee's avatar
Elliot Lee committed
194

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

205 206 207
	      visuals[nvisuals]->green_mask = 0;
	      visuals[nvisuals]->green_shift = 0;
	      visuals[nvisuals]->green_prec = 0;
Elliot Lee's avatar
Elliot Lee committed
208

209 210 211
	      visuals[nvisuals]->blue_mask = 0;
	      visuals[nvisuals]->blue_shift = 0;
	      visuals[nvisuals]->blue_prec = 0;
Elliot Lee's avatar
Elliot Lee committed
212
	    }
213

Elliot Lee's avatar
Elliot Lee committed
214 215 216 217
	  nvisuals += 1;
	}
    }

218 219
  if (visual_list)
    XFree (visual_list);
Elliot Lee's avatar
Elliot Lee committed
220 221 222 223 224

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

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

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

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

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

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

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

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

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

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

  screen_x11->visuals = visuals;
  screen_x11->nvisuals = nvisuals;
Elliot Lee's avatar
Elliot Lee committed
332 333 334
}

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

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

GdkVisual *
347
_gdk_screen_x11_get_system_visual (GdkScreen *screen)
348 349 350 351
{
  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
352 353 354
}

GdkVisual*
355
_gdk_screen_x11_visual_get_best (GdkScreen *screen)
Elliot Lee's avatar
Elliot Lee committed
356
{
357
  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
358

359
  return screen_x11->visuals[0];
Elliot Lee's avatar
Elliot Lee committed
360 361 362
}

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

  return return_val;
}

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

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

  return return_val;
}

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

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

  return return_val;
}

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

428 429
  *count = screen_x11->navailable_depths;
  *depths = screen_x11->available_depths;
Elliot Lee's avatar
Elliot Lee committed
430 431 432
}

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

439 440
  *count = screen_x11->navailable_types;
  *visual_types = screen_x11->available_types;
Elliot Lee's avatar
Elliot Lee committed
441 442
}

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

450 451
  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
  screen_x11 = GDK_SCREEN_X11 (screen);
452

453
  list = NULL;
454 455 456

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

  return list;
Elliot Lee's avatar
Elliot Lee committed
459 460
}

461
/**
Matthias Clasen's avatar
Matthias Clasen committed
462
 * gdk_x11_screen_lookup_visual:
463 464 465
 * @screen: a #GdkScreen.
 * @xvisualid: an X Visual ID.
 *
466
 * Looks up the #GdkVisual for a particular screen and X Visual ID.
467
 *
468 469
 * Returns: the #GdkVisual (owned by the screen object), or %NULL
 *   if the visual ID wasn't found.
Matthias Clasen's avatar
Matthias Clasen committed
470 471
 *
 * Since: 2.2
472 473
 */
GdkVisual *
474
gdk_x11_screen_lookup_visual (GdkScreen *screen,
475
                              VisualID   xvisualid)
Elliot Lee's avatar
Elliot Lee committed
476 477
{
  int i;
478 479 480
  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
481

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

  return NULL;
}

Matthias Clasen's avatar
Matthias Clasen committed
489 490 491
/**
 * gdkx_visual_get:
 * @xvisualid: a X visual id.
492 493 494
 *
 * Returns a #GdkVisual corresponding to a X visual.
 *
Matthias Clasen's avatar
Matthias Clasen committed
495 496
 * Return value: the #GdkVisual.
 **/
497 498 499
GdkVisual*
gdkx_visual_get (VisualID xvisualid)
{
500
  return gdk_x11_screen_lookup_visual (gdk_screen_get_default (), xvisualid);
501
}
Elliot Lee's avatar
Elliot Lee committed
502 503 504 505

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

508 509
  if (!screen_x11->visual_hash)
    screen_x11->visual_hash = g_hash_table_new ((GHashFunc) gdk_visual_hash,
510
                                                (GEqualFunc) gdk_visual_equal);
Elliot Lee's avatar
Elliot Lee committed
511

512
  g_hash_table_insert (screen_x11->visual_hash, GDK_VISUAL_X11 (visual)->xvisual, visual);
Elliot Lee's avatar
Elliot Lee committed
513 514 515 516
}

static void
gdk_visual_decompose_mask (gulong  mask,
517 518
                           gint   *shift,
                           gint   *prec)
Elliot Lee's avatar
Elliot Lee committed
519 520 521 522
{
  *shift = 0;
  *prec = 0;

523 524 525 526 527 528
  if (mask == 0)
    {
      g_warning ("Mask is 0 in visual. Server bug ?");
      return;
    }

Elliot Lee's avatar
Elliot Lee committed
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
  while (!(mask & 0x1))
    {
      (*shift)++;
      mask >>= 1;
    }

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

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

548 549
static gboolean
gdk_visual_equal (Visual *a,
550
                  Visual *b)
Elliot Lee's avatar
Elliot Lee committed
551 552 553
{
  return (a->visualid == b->visualid);
}
554

555 556 557 558 559 560 561 562 563 564 565
/**
 * _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)
{
566
  GdkVisualX11 *visual_x11;
567 568 569

  g_return_val_if_fail (GDK_IS_VISUAL (visual), None);

570
  visual_x11 = GDK_VISUAL_X11 (visual);
571

572
  if (visual_x11->colormap == None)
573
    {
574 575 576 577
      visual_x11->colormap = XCreateColormap (GDK_SCREEN_XDISPLAY (visual->screen),
                                              GDK_SCREEN_XROOTWIN (visual->screen),
                                              visual_x11->xvisual,
                                              AllocNone);
578 579
    }

580
  return visual_x11->colormap;
581 582
}

Matthias Clasen's avatar
Matthias Clasen committed
583 584 585
/**
 * gdk_x11_visual_get_xvisual:
 * @visual: a #GdkVisual.
586
 *
Matthias Clasen's avatar
Matthias Clasen committed
587
 * Returns the X visual belonging to a #GdkVisual.
588
 *
Matthias Clasen's avatar
Matthias Clasen committed
589 590
 * Return value: an Xlib <type>Visual*</type>.
 **/
591 592
Visual *
gdk_x11_visual_get_xvisual (GdkVisual *visual)
593 594 595
{
  g_return_val_if_fail (GDK_IS_VISUAL (visual), NULL);

596
  return GDK_VISUAL_X11 (visual)->xvisual;
597
}