2 * Copyright (C) 2010-2011 Robert Ancell.
3 * Author: Robert Ancell <robert.ancell@canonical.com>
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
17 #include <glib/gstdio.h>
19 #include "x-server-xvnc.h"
20 #include "configuration.h"
23 struct XServerXVNCPrivate
25 /* File descriptor to use for standard input */
28 /* Geometry and colour depth */
29 gint width, height, depth;
32 G_DEFINE_TYPE (XServerXVNC, x_server_xvnc, X_SERVER_LOCAL_TYPE);
35 x_server_xvnc_new (void)
37 XServerXVNC *self = g_object_new (X_SERVER_XVNC_TYPE, NULL);
40 name = g_strdup_printf ("xvnc-%d", x_server_get_display_number (X_SERVER (self)));
41 display_server_set_name (DISPLAY_SERVER (self), name);
44 x_server_local_set_command (X_SERVER_LOCAL (self), "Xvnc");
49 x_server_xvnc_set_socket (XServerXVNC *server, int fd)
51 g_return_if_fail (server != NULL);
52 server->priv->socket_fd = fd;
56 x_server_xvnc_get_socket (XServerXVNC *server)
58 g_return_val_if_fail (server != NULL, 0);
59 return server->priv->socket_fd;
63 x_server_xvnc_set_geometry (XServerXVNC *server, gint width, gint height)
65 g_return_if_fail (server != NULL);
66 server->priv->width = width;
67 server->priv->height = height;
71 x_server_xvnc_set_depth (XServerXVNC *server, gint depth)
73 g_return_if_fail (server != NULL);
74 server->priv->depth = depth;
78 x_server_xvnc_run (Process *process, gpointer user_data)
80 XServerXVNC *server = user_data;
83 dup2 (server->priv->socket_fd, STDIN_FILENO);
84 dup2 (server->priv->socket_fd, STDOUT_FILENO);
85 close (server->priv->socket_fd);
87 /* Set SIGUSR1 to ignore so the X server can indicate it when it is ready */
88 signal (SIGUSR1, SIG_IGN);
92 x_server_xvnc_get_run_function (XServerLocal *server)
94 return x_server_xvnc_run;
98 x_server_xvnc_get_log_stdout (XServerLocal *server)
104 x_server_xvnc_get_can_share (DisplayServer *server)
110 x_server_xvnc_add_args (XServerLocal *x_server, GString *command)
112 XServerXVNC *server = X_SERVER_XVNC (x_server);
114 g_string_append (command, " -inetd");
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);
119 if (server->priv->depth > 0)
120 g_string_append_printf (command, " -depth %d", server->priv->depth);
124 x_server_xvnc_init (XServerXVNC *server)
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;
133 x_server_xvnc_class_init (XServerXVNCClass *klass)
135 XServerLocalClass *x_server_local_class = X_SERVER_LOCAL_CLASS (klass);
136 DisplayServerClass *display_server_class = DISPLAY_SERVER_CLASS (klass);
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;
143 g_type_class_add_private (klass, sizeof (XServerXVNCPrivate));