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