]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/seat-xvnc.c
Don't subclass Session - we can't know the type until it has authenticated
[sojka/lightdm.git] / src / seat-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 "seat-xvnc.h"
13 #include "x-server-xvnc.h"
14 #include "configuration.h"
15
16 G_DEFINE_TYPE (SeatXVNC, seat_xvnc, SEAT_TYPE);
17
18 struct SeatXVNCPrivate
19 {
20     /* VNC connection */
21     GSocket *connection;
22 };
23
24 SeatXVNC *seat_xvnc_new (GSocket *connection)
25 {
26     SeatXVNC *seat;
27
28     seat = g_object_new (SEAT_XVNC_TYPE, NULL);
29     seat->priv->connection = g_object_ref (connection);
30
31     return seat;
32 }
33
34 static DisplayServer *
35 seat_xvnc_create_display_server (Seat *seat)
36 {
37     XServerXVNC *x_server;
38     const gchar *command = NULL;
39
40     x_server = x_server_xvnc_new ();
41     x_server_xvnc_set_socket (x_server, g_socket_get_fd (SEAT_XVNC (seat)->priv->connection));
42
43     command = config_get_string (config_get_instance (), "VNCServer", "command");
44     if (command)
45         x_server_xvnc_set_command (x_server, command);
46
47     if (config_has_key (config_get_instance (), "VNCServer", "width") &&
48         config_has_key (config_get_instance (), "VNCServer", "height"))
49     {
50         gint width, height;
51         width = config_get_integer (config_get_instance (), "VNCServer", "width");
52         height = config_get_integer (config_get_instance (), "VNCServer", "height");
53         if (height > 0 && width > 0)
54             x_server_xvnc_set_geometry (x_server, width, height);
55     }
56     if (config_has_key (config_get_instance (), "VNCServer", "depth"))
57     {
58         gint depth;
59         depth = config_get_integer (config_get_instance (), "VNCServer", "depth");
60         if (depth == 8 || depth == 16 || depth == 24 || depth == 32)
61             x_server_xvnc_set_depth (x_server, depth);
62     }
63
64     return DISPLAY_SERVER (x_server);
65 }
66
67 static void
68 seat_xvnc_run_script (Seat *seat, DisplayServer *display_server, Process *script)
69 {
70     XServerXVNC *x_server;
71     GInetSocketAddress *address;
72     gchar *hostname;
73     const gchar *path;
74
75     x_server = X_SERVER_XVNC (display_server);
76
77     address = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (SEAT_XVNC (seat)->priv->connection, NULL));
78     hostname = g_inet_address_to_string (g_inet_socket_address_get_address (address));
79     path = x_server_xvnc_get_authority_file_path (x_server);
80
81     process_set_env (script, "REMOTE_HOST", hostname);
82     process_set_env (script, "DISPLAY", x_server_get_address (X_SERVER (x_server)));
83     process_set_env (script, "XAUTHORITY", path);
84
85     g_free (hostname);
86
87     SEAT_CLASS (seat_xvnc_parent_class)->run_script (seat, display_server, script);
88 }
89
90 static void
91 seat_xvnc_init (SeatXVNC *seat)
92 {
93     seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_XVNC_TYPE, SeatXVNCPrivate);
94 }
95
96 static void
97 seat_xdmcp_session_finalize (GObject *object)
98 {
99     SeatXVNC *self;
100
101     self = SEAT_XVNC (object);
102
103     g_object_unref (self->priv->connection);
104
105     G_OBJECT_CLASS (seat_xvnc_parent_class)->finalize (object);
106 }
107
108 static void
109 seat_xvnc_class_init (SeatXVNCClass *klass)
110 {
111     SeatClass *seat_class = SEAT_CLASS (klass);
112     GObjectClass *object_class = G_OBJECT_CLASS (klass);
113
114     seat_class->create_display_server = seat_xvnc_create_display_server;
115     seat_class->run_script = seat_xvnc_run_script;
116     object_class->finalize = seat_xdmcp_session_finalize;
117
118     g_type_class_add_private (klass, sizeof (SeatXVNCPrivate));
119 }