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 *server = g_object_new (X_SERVER_XVNC_TYPE, NULL);
39 x_server_local_set_command (X_SERVER_LOCAL (server), "Xvnc");
44 x_server_xvnc_set_socket (XServerXVNC *server, int fd)
46 g_return_if_fail (server != NULL);
47 server->priv->socket_fd = fd;
51 x_server_xvnc_get_socket (XServerXVNC *server)
53 g_return_val_if_fail (server != NULL, 0);
54 return server->priv->socket_fd;
58 x_server_xvnc_set_geometry (XServerXVNC *server, gint width, gint height)
60 g_return_if_fail (server != NULL);
61 server->priv->width = width;
62 server->priv->height = height;
66 x_server_xvnc_set_depth (XServerXVNC *server, gint depth)
68 g_return_if_fail (server != NULL);
69 server->priv->depth = depth;
73 x_server_xvnc_run (Process *process, gpointer user_data)
75 XServerXVNC *server = user_data;
78 dup2 (server->priv->socket_fd, STDIN_FILENO);
79 dup2 (server->priv->socket_fd, STDOUT_FILENO);
80 close (server->priv->socket_fd);
82 /* Set SIGUSR1 to ignore so the X server can indicate it when it is ready */
83 signal (SIGUSR1, SIG_IGN);
87 x_server_xvnc_get_run_function (XServerLocal *server)
89 return x_server_xvnc_run;
93 x_server_xvnc_get_log_stdout (XServerLocal *server)
99 x_server_xvnc_get_can_share (DisplayServer *server)
105 x_server_xvnc_add_args (XServerLocal *x_server, GString *command)
107 XServerXVNC *server = X_SERVER_XVNC (x_server);
109 g_string_append (command, " -inetd");
111 if (server->priv->width > 0 && server->priv->height > 0)
112 g_string_append_printf (command, " -geometry %dx%d", server->priv->width, server->priv->height);
114 if (server->priv->depth > 0)
115 g_string_append_printf (command, " -depth %d", server->priv->depth);
119 x_server_xvnc_init (XServerXVNC *server)
121 server->priv = G_TYPE_INSTANCE_GET_PRIVATE (server, X_SERVER_XVNC_TYPE, XServerXVNCPrivate);
122 server->priv->width = 1024;
123 server->priv->height = 768;
124 server->priv->depth = 8;
128 x_server_xvnc_class_init (XServerXVNCClass *klass)
130 XServerLocalClass *x_server_local_class = X_SERVER_LOCAL_CLASS (klass);
131 DisplayServerClass *display_server_class = DISPLAY_SERVER_CLASS (klass);
133 x_server_local_class->get_run_function = x_server_xvnc_get_run_function;
134 x_server_local_class->get_log_stdout = x_server_xvnc_get_log_stdout;
135 x_server_local_class->add_args = x_server_xvnc_add_args;
136 display_server_class->get_can_share = x_server_xvnc_get_can_share;
138 g_type_class_add_private (klass, sizeof (XServerXVNCPrivate));