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
14 #include "seat-xvnc.h"
15 #include "xserver-xvnc.h"
16 #include "configuration.h"
18 G_DEFINE_TYPE (SeatXVNC, seat_xvnc, SEAT_TYPE);
20 struct SeatXVNCPrivate
26 SeatXVNC *seat_xvnc_new (GSocket *connection)
30 seat = g_object_new (SEAT_XVNC_TYPE, NULL);
31 seat->priv->connection = g_object_ref (connection);
36 static DisplayServer *
37 seat_xvnc_create_display_server (Seat *seat, const gchar *session_type)
40 const gchar *command = NULL;
42 if (strcmp (session_type, "x") != 0)
44 g_warning ("XVNC seat only supports X display servers, not '%s'", session_type);
48 xserver = xserver_xvnc_new ();
49 xserver_xvnc_set_socket (xserver, g_socket_get_fd (SEAT_XVNC (seat)->priv->connection));
51 command = config_get_string (config_get_instance (), "VNCServer", "command");
53 xserver_xvnc_set_command (xserver, command);
55 if (config_has_key (config_get_instance (), "VNCServer", "width") &&
56 config_has_key (config_get_instance (), "VNCServer", "height"))
59 width = config_get_integer (config_get_instance (), "VNCServer", "width");
60 height = config_get_integer (config_get_instance (), "VNCServer", "height");
61 if (height > 0 && width > 0)
62 xserver_xvnc_set_geometry (xserver, width, height);
64 if (config_has_key (config_get_instance (), "VNCServer", "depth"))
67 depth = config_get_integer (config_get_instance (), "VNCServer", "depth");
68 if (depth == 8 || depth == 16 || depth == 24 || depth == 32)
69 xserver_xvnc_set_depth (xserver, depth);
72 return DISPLAY_SERVER (xserver);
76 seat_xvnc_run_script (Seat *seat, DisplayServer *display_server, Process *script)
79 GInetSocketAddress *address;
83 xserver = XSERVER_XVNC (display_server);
85 address = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (SEAT_XVNC (seat)->priv->connection, NULL));
86 hostname = g_inet_address_to_string (g_inet_socket_address_get_address (address));
87 path = xserver_xvnc_get_authority_file_path (xserver);
89 process_set_env (script, "REMOTE_HOST", hostname);
90 process_set_env (script, "DISPLAY", xserver_get_address (XSERVER (xserver)));
91 process_set_env (script, "XAUTHORITY", path);
95 SEAT_CLASS (seat_xvnc_parent_class)->run_script (seat, display_server, script);
99 seat_xvnc_init (SeatXVNC *seat)
101 seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_XVNC_TYPE, SeatXVNCPrivate);
105 seat_xdmcp_session_finalize (GObject *object)
109 self = SEAT_XVNC (object);
111 g_object_unref (self->priv->connection);
113 G_OBJECT_CLASS (seat_xvnc_parent_class)->finalize (object);
117 seat_xvnc_class_init (SeatXVNCClass *klass)
119 SeatClass *seat_class = SEAT_CLASS (klass);
120 GObjectClass *object_class = G_OBJECT_CLASS (klass);
122 seat_class->create_display_server = seat_xvnc_create_display_server;
123 seat_class->run_script = seat_xvnc_run_script;
124 object_class->finalize = seat_xdmcp_session_finalize;
126 g_type_class_add_private (klass, sizeof (SeatXVNCPrivate));