97
41
GIOChannel *channel;
100
guint16 sequence_number;
103
struct XScreenPrivate
107
guint32 current_input_masks;
108
guint16 width_in_pixels;
109
guint16 height_in_pixels;
110
guint16 width_in_millimeters;
111
guint16 height_in_millimeters;
115
struct XVisualPrivate
120
guint8 bits_per_rgb_value;
121
guint16 colormap_entries;
130
46
X_CLIENT_DISCONNECTED,
131
47
X_CLIENT_LAST_SIGNAL
133
49
static guint x_client_signals[X_CLIENT_LAST_SIGNAL] = { 0 };
136
x_client_get_address (XClient *client)
138
GSocketAddress *socket_address;
139
GError *error = NULL;
141
socket_address = g_socket_get_remote_address (client->priv->socket, &error);
143
g_warning ("Error getting remote socket address");
144
g_clear_error (&error);
148
if (G_IS_INET_SOCKET_ADDRESS (socket_address))
149
return g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (socket_address));
155
52
x_client_send_failed (XClient *client, const gchar *reason)
157
guint8 buffer[MAXIMUM_REQUEST_LENGTH];
158
gsize n_written = 0, length_offset;
160
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, Failed, &n_written);
161
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, strlen (reason), &n_written);
162
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, X_PROTOCOL_MAJOR_VERSION, &n_written);
163
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, X_PROTOCOL_MINOR_VERSION, &n_written);
164
length_offset = n_written;
165
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0, &n_written);
166
write_padded_string (buffer, MAXIMUM_REQUEST_LENGTH, reason, &n_written);
168
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, (n_written - length_offset) / 4, &length_offset);
170
send (g_io_channel_unix_get_fd (client->priv->channel), buffer, n_written, 0);
56
message = g_strdup_printf ("FAILED:%s", reason);
57
send (g_io_channel_unix_get_fd (client->priv->channel), message, strlen (message), 0);
174
62
x_client_send_success (XClient *client)
176
XServer *server = client->priv->server;
177
guint8 buffer[MAXIMUM_REQUEST_LENGTH];
178
gsize n_written = 0, length_offset;
181
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, Success, &n_written);
182
write_padding (buffer, MAXIMUM_REQUEST_LENGTH, 1, &n_written);
183
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, X_PROTOCOL_MAJOR_VERSION, &n_written);
184
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, X_PROTOCOL_MINOR_VERSION, &n_written);
185
length_offset = n_written;
186
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0, &n_written);
187
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, X_RELEASE_NUMBER, &n_written);
188
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0x00a00000, &n_written); // resource-id-base
189
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0x001fffff, &n_written); // resource-id-mask
190
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, server->priv->motion_buffer_size, &n_written);
191
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, strlen (client->priv->server->priv->vendor), &n_written);
192
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, MAXIMUM_REQUEST_LENGTH, &n_written);
193
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, g_list_length (server->priv->screens), &n_written);
194
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, g_list_length (server->priv->pixmap_formats), &n_written);
195
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, server->priv->image_byte_order, &n_written);
196
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, server->priv->bitmap_format_bit_order, &n_written);
197
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, 32, &n_written); // bitmap-format-scanline-unit
198
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, 32, &n_written); // bitmap-format-scanline-pad
199
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, server->priv->min_keycode, &n_written);
200
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, server->priv->max_keycode, &n_written);
201
write_padding (buffer, MAXIMUM_REQUEST_LENGTH, 4, &n_written);
202
write_padded_string (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->server->priv->vendor, &n_written);
204
for (link = server->priv->pixmap_formats; link; link = link->next)
206
PixmapFormat *format = link->data;
207
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, format->depth, &n_written);
208
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, format->bits_per_pixel, &n_written);
209
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, format->scanline_pad, &n_written);
210
write_padding (buffer, MAXIMUM_REQUEST_LENGTH, 5, &n_written);
213
for (link = server->priv->screens; link; link = link->next)
215
XScreen *screen = link->data;
216
guint8 depth, n_depths = 0;
217
gsize n_depths_offset;
219
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 87, &n_written); // root
220
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 32, &n_written); // default-colormap
221
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, screen->priv->white_pixel, &n_written);
222
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, screen->priv->black_pixel, &n_written);
223
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, screen->priv->current_input_masks, &n_written);
224
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, screen->priv->width_in_pixels, &n_written);
225
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, screen->priv->height_in_pixels, &n_written);
226
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, screen->priv->width_in_millimeters, &n_written);
227
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, screen->priv->height_in_millimeters, &n_written);
228
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 1, &n_written); // min-installed-maps
229
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 1, &n_written); // max-installed-maps
230
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 34, &n_written); // root-visual
231
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, 0, &n_written); // backing-stores
232
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, 0, &n_written); // save-unders
233
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, 24, &n_written); // root-depth
234
n_depths_offset = n_written;
235
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, 0, &n_written);
241
guint16 n_visuals = 0;
243
/* Find the next depth to this one */
244
guint8 next_depth = 255;
245
for (visual_link = screen->priv->visuals; visual_link; visual_link = visual_link->next)
247
XVisual *visual = visual_link->data;
248
if (visual->priv->depth > depth && visual->priv->depth < next_depth)
249
next_depth = visual->priv->depth;
251
if (next_depth == 255)
256
for (visual_link = screen->priv->visuals; visual_link; visual_link = visual_link->next)
258
XVisual *visual = visual_link->data;
259
if (visual->priv->depth == depth)
263
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, depth, &n_written);
264
write_padding (buffer, MAXIMUM_REQUEST_LENGTH, 1, &n_written);
265
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, n_visuals, &n_written);
266
write_padding (buffer, MAXIMUM_REQUEST_LENGTH, 4, &n_written);
268
for (visual_link = screen->priv->visuals; visual_link; visual_link = visual_link->next)
270
XVisual *visual = visual_link->data;
272
if (visual->priv->depth != depth)
275
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, visual->priv->id, &n_written);
276
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, visual->priv->class, &n_written);
277
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, visual->priv->bits_per_rgb_value, &n_written);
278
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, visual->priv->colormap_entries, &n_written);
279
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, visual->priv->red_mask, &n_written);
280
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, visual->priv->green_mask, &n_written);
281
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, visual->priv->blue_mask, &n_written);
282
write_padding (buffer, MAXIMUM_REQUEST_LENGTH, 4, &n_written);
286
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, n_depths, &n_depths_offset);
289
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, (n_written - length_offset) / 4, &length_offset);
291
send (g_io_channel_unix_get_fd (client->priv->channel), buffer, n_written, 0);
295
x_client_send_error (XClient *client, int type, int major, int minor)
297
guint8 buffer[MAXIMUM_REQUEST_LENGTH];
300
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, Error, &n_written);
301
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, type, &n_written);
302
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, client->priv->sequence_number, &n_written);
303
write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0, &n_written); /* resourceID */
304
write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, minor, &n_written);
305
write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, major, &n_written);
306
write_padding (buffer, MAXIMUM_REQUEST_LENGTH, 21, &n_written);
308
send (g_io_channel_unix_get_fd (client->priv->channel), buffer, n_written, 0);
66
message = g_strdup ("SUCCESS");
67
send (g_io_channel_unix_get_fd (client->priv->channel), message, strlen (message), 0);
350
101
XServer *server = g_object_new (x_server_get_type (), NULL);
351
102
server->priv->display_number = display_number;
352
server->priv->tcp_port = 6000 + display_number;
357
x_server_add_screen (XServer *server, guint32 white_pixel, guint32 black_pixel, guint32 current_input_masks, guint16 width_in_pixels, guint16 height_in_pixels, guint16 width_in_millimeters, guint16 height_in_millimeters)
361
screen = g_object_new (x_screen_get_type (), NULL);
363
screen->priv->white_pixel = white_pixel;
364
screen->priv->black_pixel = black_pixel;
365
screen->priv->current_input_masks = current_input_masks;
366
screen->priv->width_in_pixels = width_in_pixels;
367
screen->priv->height_in_pixels = height_in_pixels;
368
screen->priv->width_in_millimeters = width_in_millimeters;
369
screen->priv->height_in_millimeters = height_in_millimeters;
371
server->priv->screens = g_list_append (server->priv->screens, screen);
377
x_server_add_pixmap_format (XServer *server, guint8 depth, guint8 bits_per_pixel, guint8 scanline_pad)
379
PixmapFormat *format;
381
format = g_malloc0 (sizeof (PixmapFormat));
382
format->depth = depth;
383
format->bits_per_pixel = bits_per_pixel;
384
format->scanline_pad = scanline_pad;
385
server->priv->pixmap_formats = g_list_append (server->priv->pixmap_formats, format);
389
x_server_set_listen_unix (XServer *server, gboolean listen_unix)
391
server->priv->listen_unix = listen_unix;
395
x_server_set_listen_tcp (XServer *server, gboolean listen_tcp)
397
server->priv->listen_tcp = listen_tcp;
401
x_screen_add_visual (XScreen *screen, guint8 depth, guint8 class, guint8 bits_per_rgb_value, guint16 colormap_entries, guint32 red_mask, guint32 green_mask, guint32 blue_mask)
405
visual = g_object_new (x_visual_get_type (), NULL);
406
visual->priv->id = 0; // FIXME
407
visual->priv->depth = depth;
408
visual->priv->class = class;
409
visual->priv->bits_per_rgb_value = bits_per_rgb_value;
410
visual->priv->colormap_entries = colormap_entries;
411
visual->priv->red_mask = red_mask;
412
visual->priv->green_mask = green_mask;
413
visual->priv->blue_mask = blue_mask;
419
decode_connection_request (XClient *client, const guint8 *buffer, gssize buffer_length)
426
byte_order = read_card8 (buffer, buffer_length, &offset);
427
if (!(byte_order == 'B' || byte_order == 'l'))
429
g_warning ("Invalid byte order");
433
message = g_malloc0 (sizeof (XConnect));
435
message->byte_order = byte_order == 'B' ? X_BYTE_ORDER_MSB : X_BYTE_ORDER_LSB;
436
read_padding (1, &offset);
437
message->protocol_major_version = read_card16 (buffer, buffer_length, message->byte_order, &offset);
438
message->protocol_minor_version = read_card16 (buffer, buffer_length, message->byte_order, &offset);
439
n = read_card16 (buffer, buffer_length, message->byte_order, &offset);
440
message->authorization_protocol_data_length = read_card16 (buffer, buffer_length, message->byte_order, &offset);
441
read_padding (2, &offset);
442
message->authorization_protocol_name = read_padded_string (buffer, buffer_length, n, &offset);
443
message->authorization_protocol_data = read_string8 (buffer, buffer_length, message->authorization_protocol_data_length, &offset);
444
read_padding (pad (message->authorization_protocol_data_length), &offset);
446
/* Store information about the client */
447
client->priv->byte_order = message->byte_order;
448
client->priv->connected = TRUE;
450
g_signal_emit (client, x_client_signals[X_CLIENT_CONNECT], 0, message);
452
g_free (message->authorization_protocol_name);
453
g_free (message->authorization_protocol_data);
458
process_intern_atom (XClient *client, const guint8 *buffer, gssize buffer_length)
468
read_padding (1, &offset); /* reqType */
469
onlyIfExists = read_card8 (buffer, buffer_length, &offset);
470
read_padding (2, &offset); /* length */
471
n = read_card16 (buffer, buffer_length, client->priv->byte_order, &offset);
472
read_padding (2, &offset);
473
name = read_padded_string (buffer, buffer_length, n, &offset);
477
atom = client->priv->server->priv->next_atom_index++;
482
if (!g_hash_table_lookup (client->priv->server->priv->atoms, GINT_TO_POINTER (atom)))
484
x_client_send_error (client, BadAtom, InternAtom, 0);
489
g_hash_table_insert (client->priv->server->priv->atoms, GINT_TO_POINTER (atom), name);
493
guint8 outBuffer[MAXIMUM_REQUEST_LENGTH];
496
write_card8 (outBuffer, MAXIMUM_REQUEST_LENGTH, Reply, &n_written);
497
write_padding (outBuffer, MAXIMUM_REQUEST_LENGTH, 1, &n_written);
498
write_card16 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, client->priv->sequence_number, &n_written);
499
write_card32 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0, &n_written); /* length */
500
write_card32 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, atom, &n_written);
501
write_padding (outBuffer, MAXIMUM_REQUEST_LENGTH, 20, &n_written);
503
send (g_io_channel_unix_get_fd (client->priv->channel), outBuffer, n_written, 0);
507
process_get_property (XClient *client, const guint8 *buffer, gssize buffer_length)
516
read_padding (1, &offset); /* reqType */
517
delete = read_card8 (buffer, buffer_length, &offset);
518
read_padding (2, &offset); /* length */
519
read_padding (4, &offset); /* window */
520
property = read_card32 (buffer, buffer_length, client->priv->byte_order, &offset);
521
type = read_card32 (buffer, buffer_length, client->priv->byte_order, &offset);
522
read_padding (4, &offset); /* longOffset */
523
read_padding (4, &offset); /* longLength */
527
gchar *name = g_hash_table_lookup (client->priv->server->priv->atoms, GINT_TO_POINTER (property));
528
GString *reply = NULL;
531
if (g_strcmp0 (name, "_XKB_RULES_NAMES") == 0)
535
config = g_key_file_new ();
536
g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL);
538
reply = g_string_new ("");
540
g_string_append (reply, "evdev"); /* rules file */
541
g_string_append_c (reply, 0); /* embedded null byte */
543
g_string_append (reply, "pc105"); /* model name */
544
g_string_append_c (reply, 0); /* embedded null byte */
546
if (g_key_file_has_key (config, "test-xserver-config", "keyboard-layout", NULL))
547
g_string_append (reply, g_key_file_get_string (config, "test-xserver-config", "keyboard-layout", NULL));
549
g_string_append (reply, "us");
550
g_string_append_c (reply, 0); /* embedded null byte */
552
if (g_key_file_has_key (config, "test-xserver-config", "keyboard-variant", NULL))
553
g_string_append (reply, g_key_file_get_string (config, "test-xserver-config", "keyboard-variant", NULL));
554
g_string_append_c (reply, 0); /* embedded null byte */
557
g_string_append_c (reply, 0); /* embedded null byte */
559
g_key_file_free (config);
563
g_hash_table_remove (client->priv->server->priv->atoms, GINT_TO_POINTER (property));
569
x_client_send_error (client, BadImplementation, GetProperty, 0);
573
guint8 outBuffer[MAXIMUM_REQUEST_LENGTH];
574
gsize n_written = 0, length_offset, packet_start;
576
write_card8 (outBuffer, MAXIMUM_REQUEST_LENGTH, Reply, &n_written);
577
write_card8 (outBuffer, MAXIMUM_REQUEST_LENGTH, format, &n_written);
578
write_card16 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, client->priv->sequence_number, &n_written);
579
length_offset = n_written;
580
write_card32 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0, &n_written); /* length */
581
write_card32 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, type, &n_written);
582
write_card32 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0, &n_written); /* bytesAfter */
583
write_card32 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, reply->len, &n_written);
584
write_padding (outBuffer, MAXIMUM_REQUEST_LENGTH, 12, &n_written);
585
packet_start = n_written;
587
write_string8 (outBuffer, MAXIMUM_REQUEST_LENGTH, (guint8 *) reply->str, reply->len, &n_written);
588
write_padding (outBuffer, MAXIMUM_REQUEST_LENGTH, pad (reply->len), &n_written);
590
write_card32 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, (n_written - packet_start) / 4, &length_offset);
592
send (g_io_channel_unix_get_fd (client->priv->channel), outBuffer, n_written, 0);
596
g_string_free (reply, TRUE);
600
process_query_extension (XClient *client, const guint8 *buffer, gssize buffer_length)
608
read_padding (1, &offset); /* reqType */
609
read_padding (1, &offset); /* pad */
610
read_padding (2, &offset); /* length */
611
n = read_card16 (buffer, buffer_length, client->priv->byte_order, &offset);
612
read_padding (2, &offset); /* pad */
613
name = read_padded_string (buffer, buffer_length, n, &offset);
618
if (g_strcmp0 (name, "XKEYBOARD") == 0)
623
guint8 outBuffer[MAXIMUM_REQUEST_LENGTH];
626
write_card8 (outBuffer, MAXIMUM_REQUEST_LENGTH, Reply, &n_written);
627
write_padding (outBuffer, MAXIMUM_REQUEST_LENGTH, 1, &n_written);
628
write_card16 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, client->priv->sequence_number, &n_written);
629
write_card32 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0, &n_written); /* length */
630
write_card8 (outBuffer, MAXIMUM_REQUEST_LENGTH, present, &n_written);
631
write_card8 (outBuffer, MAXIMUM_REQUEST_LENGTH, kbUseExtension, &n_written); /* major_opcode */
632
write_card8 (outBuffer, MAXIMUM_REQUEST_LENGTH, 0, &n_written); /* first_event */
633
write_card8 (outBuffer, MAXIMUM_REQUEST_LENGTH, 0, &n_written); /* first_error */
634
write_padding (outBuffer, MAXIMUM_REQUEST_LENGTH, 20, &n_written);
636
send (g_io_channel_unix_get_fd (client->priv->channel), outBuffer, n_written, 0);
644
process_kb_use_extension (XClient *client, const guint8 *buffer, gssize buffer_length)
646
/* Nothing to decode, we don't care about parameters */
650
guint8 outBuffer[MAXIMUM_REQUEST_LENGTH];
653
write_card8 (outBuffer, MAXIMUM_REQUEST_LENGTH, Reply, &n_written);
654
write_card8 (outBuffer, MAXIMUM_REQUEST_LENGTH, 1, &n_written); /* supported */
655
write_card16 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, client->priv->sequence_number, &n_written);
656
write_card32 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0, &n_written); /* length */
657
write_card16 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 1, &n_written); /* serverMajor */
658
write_card16 (outBuffer, MAXIMUM_REQUEST_LENGTH, client->priv->byte_order, 0, &n_written); /* serverMinor */
659
write_padding (outBuffer, MAXIMUM_REQUEST_LENGTH, 20, &n_written);
661
send (g_io_channel_unix_get_fd (client->priv->channel), outBuffer, n_written, 0);
665
decode_request (XClient *client, const guint8 *buffer, gssize buffer_length)
670
while (offset < buffer_length)
675
start_offset = offset;
676
opcode = read_card8 (buffer, buffer_length, &offset);
677
read_card8 (buffer, buffer_length, &offset);
678
length = read_card16 (buffer, buffer_length, client->priv->byte_order, &offset) * 4;
680
g_debug ("Got opcode=%d length=%d", opcode, length);
681
offset = start_offset + length;
686
process_intern_atom (client, buffer + start_offset, length);
689
process_get_property (client, buffer + start_offset, length);
692
process_query_extension (client, buffer + start_offset, length);
695
process_kb_use_extension (client, buffer + start_offset, length);
698
/* Send an error because we don't understand the opcode yet */
699
x_client_send_error (client, BadImplementation, opcode, 0);
703
client->priv->sequence_number++;
708
socket_data_cb (GIOChannel *channel, GIOCondition condition, gpointer data)
710
XClient *client = data;
711
guint8 buffer[MAXIMUM_REQUEST_LENGTH];
714
n_read = recv (g_io_channel_unix_get_fd (channel), buffer, MAXIMUM_REQUEST_LENGTH, 0);
716
g_warning ("Error reading from socket: %s", strerror (errno));
717
else if (n_read == 0)
719
g_signal_emit (client, x_client_signals[X_CLIENT_DISCONNECTED], 0);
724
if (client->priv->connected)
725
decode_request (client, buffer, n_read);
727
decode_connection_request (client, buffer, n_read);
734
107
x_client_disconnected_cb (XClient *client, XServer *server)
819
172
x_server_init (XServer *server)
821
174
server->priv = G_TYPE_INSTANCE_GET_PRIVATE (server, x_server_get_type (), XServerPrivate);
822
server->priv->vendor = g_strdup ("");
823
server->priv->min_keycode = 8;
824
server->priv->min_keycode = 255;
825
server->priv->screens = NULL;
826
server->priv->listen_unix = TRUE;
827
server->priv->listen_tcp = TRUE;
828
175
server->priv->clients = g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify) g_io_channel_unref, g_object_unref);
829
server->priv->atoms = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
830
server->priv->next_atom_index = 1;
831
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("PRIMARY"));
832
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("SECONDARY"));
833
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("ARC"));
834
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("ATOM"));
835
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("BITMAP"));
836
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CARDINAL"));
837
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("COLORMAP"));
838
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CURSOR"));
839
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CUT_BUFFER0"));
840
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CUT_BUFFER1"));
841
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CUT_BUFFER2"));
842
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CUT_BUFFER3"));
843
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CUT_BUFFER4"));
844
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CUT_BUFFER5"));
845
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CUT_BUFFER6"));
846
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CUT_BUFFER7"));
847
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("DRAWABLE"));
848
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("FONT"));
849
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("INTEGER"));
850
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("PIXMAP"));
851
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("POINT"));
852
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("RECTANGLE"));
853
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("RESOURCE_MANAGER"));
854
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("RGB_COLOR_MAP"));
855
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("RGB_BEST_MAP"));
856
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("RGB_BLUE_MAP"));
857
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("RGB_DEFAULT_MAP"));
858
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("RGB_GRAY_MAP"));
859
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("RGB_GREEN_MAP"));
860
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("RGB_RED_MAP"));
861
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("STRING"));
862
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("VISUALID"));
863
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WINDOW"));
864
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_COMMAND"));
865
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_HINTS"));
866
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_CLIENT_MACHINE"));
867
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_ICON_NAME"));
868
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_ICON_SIZE"));
869
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_NAME"));
870
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_NORMAL_HINTS"));
871
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_SIZE_HINTS"));
872
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_ZOOM_HINTS"));
873
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("MIN_SPACE"));
874
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("NORM_SPACE"));
875
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("MAX_SPACE"));
876
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("END_SPACE"));
877
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("SUPERSCRIPT_X"));
878
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("SUPERSCRIPT_Y"));
879
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("SUBSCRIPT_X"));
880
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("SUBSCRIPT_Y"));
881
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("UNDERLINE_POSITION"));
882
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("UNDERLINE_THICKNESS"));
883
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("STRIKEOUT_ASCENT"));
884
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("STRIKEOUT_DESCENT"));
885
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("ITALIC_ANGLE"));
886
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("X_HEIGHT"));
887
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("QUAD_WIDTH"));
888
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WEIGHT"));
889
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("POINT_SIZE"));
890
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("RESOLUTION"));
891
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("COPYRIGHT"));
892
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("NOTICE"));
893
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("FONT_NAME"));
894
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("FAMILY_NAME"));
895
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("FULL_NAME"));
896
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("CAP_HEIGHT"));
897
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_CLASS"));
898
g_hash_table_insert (server->priv->atoms, GINT_TO_POINTER (server->priv->next_atom_index++), g_strdup ("WM_TRANSIENT_FOR"));
902
179
x_server_finalize (GObject *object)
904
181
XServer *server = (XServer *) object;
905
g_free (server->priv->vendor);
906
182
if (server->priv->socket_path)
907
183
unlink (server->priv->socket_path);
908
g_hash_table_unref (server->priv->atoms);
909
184
G_OBJECT_CLASS (x_server_parent_class)->finalize (object);