/*
* Copyright (C) 2010-2011 Robert Ancell.
* Author: Robert Ancell <robert.ancell@canonical.com>
- *
+ *
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* license.
*/
+#include <string.h>
+
#include "seat-xvnc.h"
-#include "xserver-xvnc.h"
-#include "xsession.h"
+#include "x-server-xvnc.h"
#include "configuration.h"
G_DEFINE_TYPE (SeatXVNC, seat_xvnc, SEAT_TYPE);
}
static DisplayServer *
-seat_xvnc_create_display_server (Seat *seat)
+seat_xvnc_create_display_server (Seat *seat, Session *session)
{
- XServerXVNC *xserver;
-
- xserver = xserver_xvnc_new ();
- xserver_xvnc_set_socket (xserver, g_socket_get_fd (SEAT_XVNC (seat)->priv->connection));
+ XServerXVNC *x_server;
+ gchar *number;
+ XAuthority *cookie;
+ const gchar *command = NULL;
+
+ if (strcmp (session_get_session_type (session), "x") != 0)
+ return NULL;
+
+ x_server = x_server_xvnc_new ();
+ number = g_strdup_printf ("%d", x_server_get_display_number (X_SERVER (x_server)));
+ cookie = x_authority_new_local_cookie (number);
+ x_server_set_authority (X_SERVER (x_server), cookie);
+ g_free (number);
+ g_object_unref (cookie);
+ x_server_xvnc_set_socket (x_server, g_socket_get_fd (SEAT_XVNC (seat)->priv->connection));
+
+ command = config_get_string (config_get_instance (), "VNCServer", "command");
+ if (command)
+ x_server_local_set_command (X_SERVER_LOCAL (x_server), command);
if (config_has_key (config_get_instance (), "VNCServer", "width") &&
config_has_key (config_get_instance (), "VNCServer", "height"))
width = config_get_integer (config_get_instance (), "VNCServer", "width");
height = config_get_integer (config_get_instance (), "VNCServer", "height");
if (height > 0 && width > 0)
- xserver_xvnc_set_geometry (xserver, width, height);
+ x_server_xvnc_set_geometry (x_server, width, height);
}
if (config_has_key (config_get_instance (), "VNCServer", "depth"))
{
gint depth;
depth = config_get_integer (config_get_instance (), "VNCServer", "depth");
if (depth == 8 || depth == 16 || depth == 24 || depth == 32)
- xserver_xvnc_set_depth (xserver, depth);
+ x_server_xvnc_set_depth (x_server, depth);
}
- return DISPLAY_SERVER (xserver);
-}
-
-static Session *
-seat_xvnc_create_session (Seat *seat, Display *display)
-{
- XServerXVNC *xserver;
- XSession *session;
- GInetSocketAddress *address;
- gchar *hostname;
-
- xserver = XSERVER_XVNC (display_get_display_server (display));
-
- session = xsession_new (XSERVER (xserver));
- address = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (SEAT_XVNC (seat)->priv->connection, NULL));
- hostname = g_inet_address_to_string (g_inet_socket_address_get_address (address));
- session_set_console_kit_parameter (SESSION (session), "remote-host-name", g_variant_new_string (hostname));
- g_free (hostname);
- session_set_console_kit_parameter (SESSION (session), "is-local", g_variant_new_boolean (FALSE));
-
- return SESSION (session);
+ return DISPLAY_SERVER (x_server);
}
static void
-seat_xvnc_run_script (Seat *seat, Display *display, Process *script)
+seat_xvnc_run_script (Seat *seat, DisplayServer *display_server, Process *script)
{
- XServerXVNC *xserver;
+ XServerXVNC *x_server;
GInetSocketAddress *address;
gchar *hostname;
- gchar *path;
+ const gchar *path;
- xserver = XSERVER_XVNC (display_get_display_server (display));
+ x_server = X_SERVER_XVNC (display_server);
address = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (SEAT_XVNC (seat)->priv->connection, NULL));
hostname = g_inet_address_to_string (g_inet_socket_address_get_address (address));
- path = xserver_xvnc_get_authority_file_path (xserver);
+ path = x_server_local_get_authority_file_path (X_SERVER_LOCAL (x_server));
process_set_env (script, "REMOTE_HOST", hostname);
- process_set_env (script, "DISPLAY", xserver_get_address (XSERVER (xserver)));
+ process_set_env (script, "DISPLAY", x_server_get_address (X_SERVER (x_server)));
process_set_env (script, "XAUTHORITY", path);
g_free (hostname);
- g_free (path);
- SEAT_CLASS (seat_xvnc_parent_class)->run_script (seat, display, script);
-}
-
-static void
-seat_xvnc_display_removed (Seat *seat, Display *display)
-{
- seat_stop (seat);
+ SEAT_CLASS (seat_xvnc_parent_class)->run_script (seat, display_server, script);
}
static void
}
static void
-seat_xdmcp_session_finalize (GObject *object)
+seat_xvnc_session_finalize (GObject *object)
{
- SeatXVNC *self;
-
- self = SEAT_XVNC (object);
+ SeatXVNC *self = SEAT_XVNC (object);
- g_object_unref (self->priv->connection);
+ g_clear_object (&self->priv->connection);
G_OBJECT_CLASS (seat_xvnc_parent_class)->finalize (object);
}
GObjectClass *object_class = G_OBJECT_CLASS (klass);
seat_class->create_display_server = seat_xvnc_create_display_server;
- seat_class->create_session = seat_xvnc_create_session;
seat_class->run_script = seat_xvnc_run_script;
- seat_class->display_removed = seat_xvnc_display_removed;
- object_class->finalize = seat_xdmcp_session_finalize;
+ object_class->finalize = seat_xvnc_session_finalize;
g_type_class_add_private (klass, sizeof (SeatXVNCPrivate));
}