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