]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/x-server-xvnc.c
Allow XMir to run on the xlocal seat using the new x-server-backend=mir option
[sojka/lightdm.git] / src / x-server-xvnc.c
1 /*
2  * Copyright (C) 2010-2011 Robert Ancell.
3  * Author: Robert Ancell <robert.ancell@canonical.com>
4  *
5  * This program is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9  * license.
10  */
11
12 #include <config.h>
13 #include <string.h>
14 #include <fcntl.h>
15 #include <sys/stat.h>
16 #include <errno.h>
17 #include <glib/gstdio.h>
18
19 #include "x-server-xvnc.h"
20 #include "configuration.h"
21 #include "process.h"
22
23 struct XServerXVNCPrivate
24 {
25     /* File descriptor to use for standard input */
26     gint socket_fd;
27
28     /* Geometry and colour depth */
29     gint width, height, depth;
30 };
31
32 G_DEFINE_TYPE (XServerXVNC, x_server_xvnc, X_SERVER_LOCAL_TYPE);
33
34 XServerXVNC *
35 x_server_xvnc_new (void)
36 {
37     XServerXVNC *self = g_object_new (X_SERVER_XVNC_TYPE, NULL);
38     gchar *name;
39
40     name = g_strdup_printf ("xvnc-%d", x_server_get_display_number (X_SERVER (self)));
41     display_server_set_name (DISPLAY_SERVER (self), name);
42     g_free (name);
43   
44     x_server_local_set_command (X_SERVER_LOCAL (self), "Xvnc");
45
46     return self;
47 }
48 void
49 x_server_xvnc_set_socket (XServerXVNC *server, int fd)
50 {
51     g_return_if_fail (server != NULL);
52     server->priv->socket_fd = fd;
53 }
54
55 int
56 x_server_xvnc_get_socket (XServerXVNC *server)
57 {
58     g_return_val_if_fail (server != NULL, 0);
59     return server->priv->socket_fd;
60 }
61
62 void
63 x_server_xvnc_set_geometry (XServerXVNC *server, gint width, gint height)
64 {
65     g_return_if_fail (server != NULL);
66     server->priv->width = width;
67     server->priv->height = height;
68 }
69
70 void
71 x_server_xvnc_set_depth (XServerXVNC *server, gint depth)
72 {
73     g_return_if_fail (server != NULL);
74     server->priv->depth = depth;
75 }
76
77 static void
78 x_server_xvnc_run (Process *process, gpointer user_data)
79 {
80     XServerXVNC *server = user_data;
81
82     /* Connect input */
83     dup2 (server->priv->socket_fd, STDIN_FILENO);
84     dup2 (server->priv->socket_fd, STDOUT_FILENO);
85     close (server->priv->socket_fd);
86
87     /* Set SIGUSR1 to ignore so the X server can indicate it when it is ready */
88     signal (SIGUSR1, SIG_IGN);
89 }
90
91 static ProcessRunFunc
92 x_server_xvnc_get_run_function (XServerLocal *server)
93 {
94     return x_server_xvnc_run;
95 }
96
97 static gboolean
98 x_server_xvnc_get_log_stdout (XServerLocal *server)
99 {
100     return FALSE;
101 }
102
103 static gboolean
104 x_server_xvnc_get_can_share (DisplayServer *server)
105 {
106     return TRUE;
107 }
108
109 static void
110 x_server_xvnc_add_args (XServerLocal *x_server, GString *command)
111 {
112     XServerXVNC *server = X_SERVER_XVNC (x_server);
113
114     g_string_append (command, " -inetd");
115
116     if (server->priv->width > 0 && server->priv->height > 0)
117         g_string_append_printf (command, " -geometry %dx%d", server->priv->width, server->priv->height);
118
119     if (server->priv->depth > 0)
120         g_string_append_printf (command, " -depth %d", server->priv->depth);
121 }
122
123 static void
124 x_server_xvnc_init (XServerXVNC *server)
125 {
126     server->priv = G_TYPE_INSTANCE_GET_PRIVATE (server, X_SERVER_XVNC_TYPE, XServerXVNCPrivate);
127     server->priv->width = 1024;
128     server->priv->height = 768;
129     server->priv->depth = 8;
130 }
131
132 static void
133 x_server_xvnc_class_init (XServerXVNCClass *klass)
134 {
135     XServerLocalClass *x_server_local_class = X_SERVER_LOCAL_CLASS (klass);
136     DisplayServerClass *display_server_class = DISPLAY_SERVER_CLASS (klass);
137
138     x_server_local_class->get_run_function = x_server_xvnc_get_run_function;
139     x_server_local_class->get_log_stdout = x_server_xvnc_get_log_stdout;
140     x_server_local_class->add_args = x_server_xvnc_add_args;
141     display_server_class->get_can_share = x_server_xvnc_get_can_share;
142
143     g_type_class_add_private (klass, sizeof (XServerXVNCPrivate));
144 }