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-local.h"
15 #include "configuration.h"
19 struct SeatLocalPrivate
21 /* The section in the config for this seat */
22 gchar *config_section;
25 G_DEFINE_TYPE (SeatLocal, seat_local, SEAT_TYPE);
28 seat_local_new (const gchar *config_section)
32 seat = g_object_new (SEAT_LOCAL_TYPE, NULL);
33 seat->priv->config_section = g_strdup (config_section);
34 seat_load_config (SEAT (seat), config_section);
35 seat_set_can_switch (SEAT (seat), TRUE);
41 seat_local_add_display (Seat *seat)
44 XAuthorization *authorization = NULL;
45 gchar *dir, *filename, *path;
50 g_debug ("Starting display");
52 xserver = xserver_new (SEAT_LOCAL (seat)->priv->config_section, XSERVER_TYPE_LOCAL, NULL, xserver_get_free_display_number ());
53 number = g_strdup_printf ("%d", xserver_get_display_number (xserver));
54 gethostname (hostname, 1024);
55 authorization = xauth_new_cookie (XAUTH_FAMILY_LOCAL, hostname, number);
58 xserver_set_authorization (xserver, authorization);
59 g_object_unref (authorization);
61 filename = g_strdup_printf ("%s.log", xserver_get_address (xserver));
62 dir = config_get_string (config_get_instance (), "Directories", "log-directory");
63 path = g_build_filename (dir, filename, NULL);
64 g_debug ("Logging to %s", path);
65 child_process_set_log_file (CHILD_PROCESS (xserver), path);
70 display = display_new (SEAT_LOCAL (seat)->priv->config_section, xserver);
71 g_object_unref (xserver);
77 seat_local_set_active_display (Seat *seat, Display *display)
79 gint number = xserver_get_vt (display_get_xserver (display));
81 vt_set_active (number);
85 seat_local_init (SeatLocal *seat)
87 seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_LOCAL_TYPE, SeatLocalPrivate);
91 seat_local_finalize (GObject *object)
95 self = SEAT_LOCAL (object);
97 g_free (self->priv->config_section);
99 G_OBJECT_CLASS (seat_local_parent_class)->finalize (object);
103 seat_local_class_init (SeatLocalClass *klass)
105 GObjectClass *object_class = G_OBJECT_CLASS (klass);
106 SeatClass *seat_class = SEAT_CLASS (klass);
108 seat_class->add_display = seat_local_add_display;
109 seat_class->set_active_display = seat_local_set_active_display;
110 object_class->finalize = seat_local_finalize;
112 g_type_class_add_private (klass, sizeof (SeatLocalPrivate));