]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/x-server-xvnc.c
Update vt ioctl usage
[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 *server = g_object_new (X_SERVER_XVNC_TYPE, NULL);
38
39     x_server_local_set_command (X_SERVER_LOCAL (server), "Xvnc");
40
41     return server;
42 }
43 void
44 x_server_xvnc_set_socket (XServerXVNC *server, int fd)
45 {
46     g_return_if_fail (server != NULL);
47     server->priv->socket_fd = fd;
48 }
49
50 int
51 x_server_xvnc_get_socket (XServerXVNC *server)
52 {
53     g_return_val_if_fail (server != NULL, 0);
54     return server->priv->socket_fd;
55 }
56
57 void
58 x_server_xvnc_set_geometry (XServerXVNC *server, gint width, gint height)
59 {
60     g_return_if_fail (server != NULL);
61     server->priv->width = width;
62     server->priv->height = height;
63 }
64
65 void
66 x_server_xvnc_set_depth (XServerXVNC *server, gint depth)
67 {
68     g_return_if_fail (server != NULL);
69     server->priv->depth = depth;
70 }
71
72 static void
73 x_server_xvnc_run (Process *process, gpointer user_data)
74 {
75     XServerXVNC *server = user_data;
76
77     /* Connect input */
78     dup2 (server->priv->socket_fd, STDIN_FILENO);
79     dup2 (server->priv->socket_fd, STDOUT_FILENO);
80     close (server->priv->socket_fd);
81
82     /* Set SIGUSR1 to ignore so the X server can indicate it when it is ready */
83     signal (SIGUSR1, SIG_IGN);
84 }
85
86 static ProcessRunFunc
87 x_server_xvnc_get_run_function (XServerLocal *server)
88 {
89     return x_server_xvnc_run;
90 }
91
92 static gboolean
93 x_server_xvnc_get_log_stdout (XServerLocal *server)
94 {
95     return FALSE;
96 }
97
98 static gboolean
99 x_server_xvnc_get_can_share (DisplayServer *server)
100 {
101     return TRUE;
102 }
103
104 static void
105 x_server_xvnc_add_args (XServerLocal *x_server, GString *command)
106 {
107     XServerXVNC *server = X_SERVER_XVNC (x_server);
108
109     g_string_append (command, " -inetd");
110
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);
113
114     if (server->priv->depth > 0)
115         g_string_append_printf (command, " -depth %d", server->priv->depth);
116 }
117
118 static void
119 x_server_xvnc_init (XServerXVNC *server)
120 {
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;
125 }
126
127 static void
128 x_server_xvnc_class_init (XServerXVNCClass *klass)
129 {
130     XServerLocalClass *x_server_local_class = X_SERVER_LOCAL_CLASS (klass);
131     DisplayServerClass *display_server_class = DISPLAY_SERVER_CLASS (klass);
132
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;
137
138     g_type_class_add_private (klass, sizeof (XServerXVNCPrivate));
139 }