1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/* cdkvisual-quartz.c
 *
 * Copyright (C) 2005 Imendio AB
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include "cdkvisualprivate.h"
#include "cdkquartzvisual.h"
#include "cdkprivate-quartz.h"


struct _CdkQuartzVisual
{
  CdkVisual visual;
};

struct _CdkQuartzVisualClass
{
  CdkVisualClass visual_class;
};


static CdkVisual *system_visual;
static CdkVisual *rgba_visual;
static CdkVisual *gray_visual;

static CdkVisual *
create_standard_visual (CdkScreen *screen,
                        gint       depth)
{
  CdkVisual *visual = g_object_new (CDK_TYPE_QUARTZ_VISUAL, NULL);

  visual->screen = screen;

  visual->depth = depth;
  visual->byte_order = CDK_MSB_FIRST; /* FIXME: Should this be different on intel macs? */
  visual->colormap_size = 0;

  visual->type = CDK_VISUAL_TRUE_COLOR;

  visual->red_mask = 0xff0000;
  visual->green_mask = 0xff00;
  visual->blue_mask = 0xff;

  return visual;
}

static CdkVisual *
create_gray_visual (CdkScreen *screen)
{
  CdkVisual *visual = g_object_new (CDK_TYPE_QUARTZ_VISUAL, NULL);

  visual->screen = screen;

  visual->depth = 1;
  visual->byte_order = CDK_MSB_FIRST;
  visual->colormap_size = 0;

  visual->type = CDK_VISUAL_STATIC_GRAY;

  return visual;
}


G_DEFINE_TYPE (CdkQuartzVisual, cdk_quartz_visual, CDK_TYPE_VISUAL)<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE is a macro then please configure it.

static void
cdk_quartz_visual_init (CdkQuartzVisual *quartz_visual)
{
}

static void
cdk_quartz_visual_class_init (CdkQuartzVisualClass *class)
{
}

/* We prefer the system visual for now ... */
gint
_cdk_quartz_screen_visual_get_best_depth (CdkScreen *screen)
{
  return system_visual->depth;
}

CdkVisualType
_cdk_quartz_screen_visual_get_best_type (CdkScreen *screen)
{
  return system_visual->type;
}

CdkVisual *
_cdk_quartz_screen_get_rgba_visual (CdkScreen *screen)
{
  return rgba_visual;
}

CdkVisual*
_cdk_quartz_screen_get_system_visual (CdkScreen *screen)
{
  return system_visual;
}

CdkVisual*
_cdk_quartz_screen_visual_get_best (CdkScreen *screen)
{
  return system_visual;
}

CdkVisual*
_cdk_quartz_screen_visual_get_best_with_depth (CdkScreen *screen,
                                               gint       depth)
{
  CdkVisual *visual = NULL;

  switch (depth)
    {
      case 32:
        visual = rgba_visual;
        break;

      case 24:
        visual = system_visual;
        break;

      case 1:
        visual = gray_visual;
        break;

      default:
        visual = NULL;
    }

  return visual;
}

CdkVisual*
_cdk_quartz_screen_visual_get_best_with_type (CdkScreen     *screen,
                                              CdkVisualType  visual_type)
{
  if (system_visual->type == visual_type)
    return system_visual;
  else if (gray_visual->type == visual_type)
    return gray_visual;

  return NULL;
}

CdkVisual*
_cdk_quartz_screen_visual_get_best_with_both (CdkScreen     *screen,
                                              gint           depth,
                                              CdkVisualType  visual_type)
{
  if (system_visual->depth == depth
      && system_visual->type == visual_type)
    return system_visual;
  else if (rgba_visual->depth == depth
           && rgba_visual->type == visual_type)
    return rgba_visual;
  else if (gray_visual->depth == depth
           && gray_visual->type == visual_type)
    return gray_visual;

  return NULL;
}

/* For these, we also prefer the system visual */
void
_cdk_quartz_screen_query_depths  (CdkScreen  *screen,
                                  gint      **depths,
                                  gint       *count)
{
  *count = 1;
  *depths = &system_visual->depth;
}

void
_cdk_quartz_screen_query_visual_types (CdkScreen      *screen,
                                       CdkVisualType **visual_types,
                                       gint           *count)
{
  *count = 1;
  *visual_types = &system_visual->type;
}

void
_cdk_quartz_screen_init_visuals (CdkScreen *screen)
{
  system_visual = create_standard_visual (screen, 24);
  rgba_visual = create_standard_visual (screen, 32);
  gray_visual = create_gray_visual (screen);
}

GList*
_cdk_quartz_screen_list_visuals (CdkScreen *screen)
{
  GList *visuals = NULL;

  visuals = g_list_append (visuals, system_visual);
  visuals = g_list_append (visuals, rgba_visual);
  visuals = g_list_append (visuals, gray_visual);

  return visuals;
}