[134] | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
| 2 | * |
---|
| 3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> |
---|
| 4 | * |
---|
| 5 | * This program is free software; you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 8 | * (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with this program; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 18 | * |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include "config.h" |
---|
| 22 | |
---|
| 23 | #include <stdlib.h> |
---|
| 24 | #include <stdio.h> |
---|
| 25 | #include <unistd.h> |
---|
| 26 | #include <string.h> |
---|
| 27 | |
---|
| 28 | #include <glib.h> |
---|
| 29 | #include <glib/gi18n.h> |
---|
| 30 | #include <glib-object.h> |
---|
| 31 | |
---|
| 32 | #include "gdm-chooser-session.h" |
---|
| 33 | #include "gdm-chooser-client.h" |
---|
| 34 | |
---|
| 35 | #include "gdm-host-chooser-dialog.h" |
---|
| 36 | |
---|
| 37 | #define GDM_CHOOSER_SESSION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_CHOOSER_SESSION, GdmChooserSessionPrivate)) |
---|
| 38 | |
---|
| 39 | struct GdmChooserSessionPrivate |
---|
| 40 | { |
---|
| 41 | GdmChooserClient *client; |
---|
| 42 | GtkWidget *chooser_dialog; |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | enum { |
---|
| 46 | PROP_0, |
---|
| 47 | }; |
---|
| 48 | |
---|
| 49 | static void gdm_chooser_session_class_init (GdmChooserSessionClass *klass); |
---|
| 50 | static void gdm_chooser_session_init (GdmChooserSession *chooser_session); |
---|
| 51 | static void gdm_chooser_session_finalize (GObject *object); |
---|
| 52 | |
---|
| 53 | G_DEFINE_TYPE (GdmChooserSession, gdm_chooser_session, G_TYPE_OBJECT) |
---|
| 54 | |
---|
| 55 | static gpointer session_object = NULL; |
---|
| 56 | |
---|
| 57 | static gboolean |
---|
| 58 | launch_compiz (GdmChooserSession *session) |
---|
| 59 | { |
---|
| 60 | GError *error; |
---|
| 61 | gboolean ret; |
---|
| 62 | |
---|
| 63 | g_debug ("GdmChooserSession: Launching compiz"); |
---|
| 64 | |
---|
| 65 | ret = FALSE; |
---|
| 66 | |
---|
| 67 | error = NULL; |
---|
| 68 | g_spawn_command_line_async ("gtk-window-decorator --replace", &error); |
---|
| 69 | if (error != NULL) { |
---|
| 70 | g_warning ("Error starting WM: %s", error->message); |
---|
| 71 | g_error_free (error); |
---|
| 72 | goto out; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | error = NULL; |
---|
| 76 | g_spawn_command_line_async ("compiz --replace", &error); |
---|
| 77 | if (error != NULL) { |
---|
| 78 | g_warning ("Error starting WM: %s", error->message); |
---|
| 79 | g_error_free (error); |
---|
| 80 | goto out; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | ret = TRUE; |
---|
| 84 | |
---|
| 85 | /* FIXME: should try to detect if it actually works */ |
---|
| 86 | |
---|
| 87 | out: |
---|
| 88 | return ret; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | static gboolean |
---|
| 92 | launch_metacity (GdmChooserSession *session) |
---|
| 93 | { |
---|
| 94 | GError *error; |
---|
| 95 | gboolean ret; |
---|
| 96 | |
---|
| 97 | g_debug ("GdmChooserSession: Launching metacity"); |
---|
| 98 | |
---|
| 99 | ret = FALSE; |
---|
| 100 | |
---|
| 101 | error = NULL; |
---|
| 102 | g_spawn_command_line_async ("metacity --replace", &error); |
---|
| 103 | if (error != NULL) { |
---|
| 104 | g_warning ("Error starting WM: %s", error->message); |
---|
| 105 | g_error_free (error); |
---|
| 106 | goto out; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | ret = TRUE; |
---|
| 110 | |
---|
| 111 | out: |
---|
| 112 | return ret; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | static void |
---|
| 116 | start_window_manager (GdmChooserSession *session) |
---|
| 117 | { |
---|
| 118 | if (! launch_metacity (session)) { |
---|
| 119 | launch_compiz (session); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | static gboolean |
---|
| 124 | start_settings_daemon (GdmChooserSession *session) |
---|
| 125 | { |
---|
| 126 | GError *error; |
---|
| 127 | gboolean ret; |
---|
| 128 | |
---|
| 129 | g_debug ("GdmChooserSession: Launching settings daemon"); |
---|
| 130 | |
---|
| 131 | ret = FALSE; |
---|
| 132 | |
---|
| 133 | error = NULL; |
---|
| 134 | g_spawn_command_line_async (LIBEXECDIR "/gnome-settings-daemon --gconf-prefix=/apps/gdm/simple-chooser/settings-manager-plugins", &error); |
---|
| 135 | if (error != NULL) { |
---|
| 136 | g_warning ("Error starting settings daemon: %s", error->message); |
---|
| 137 | g_error_free (error); |
---|
| 138 | goto out; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | ret = TRUE; |
---|
| 142 | |
---|
| 143 | out: |
---|
| 144 | return ret; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | static void |
---|
| 148 | on_dialog_response (GtkDialog *dialog, |
---|
| 149 | int response_id, |
---|
| 150 | GdmChooserSession *session) |
---|
| 151 | { |
---|
| 152 | GdmChooserHost *host; |
---|
| 153 | |
---|
| 154 | host = NULL; |
---|
| 155 | switch (response_id) { |
---|
| 156 | case GTK_RESPONSE_OK: |
---|
| 157 | host = gdm_host_chooser_dialog_get_host (GDM_HOST_CHOOSER_DIALOG (dialog)); |
---|
| 158 | case GTK_RESPONSE_NONE: |
---|
| 159 | /* delete event */ |
---|
| 160 | default: |
---|
| 161 | break; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | if (host != NULL) { |
---|
| 165 | char *hostname; |
---|
| 166 | |
---|
| 167 | /* only support XDMCP hosts in remote chooser */ |
---|
| 168 | g_assert (gdm_chooser_host_get_kind (host) == GDM_CHOOSER_HOST_KIND_XDMCP); |
---|
| 169 | |
---|
| 170 | hostname = NULL; |
---|
| 171 | gdm_address_get_hostname (gdm_chooser_host_get_address (host), &hostname); |
---|
| 172 | /* FIXME: fall back to numerical address? */ |
---|
| 173 | if (hostname != NULL) { |
---|
| 174 | g_debug ("GdmChooserSession: Selected hostname '%s'", hostname); |
---|
| 175 | gdm_chooser_client_call_select_hostname (session->priv->client, hostname); |
---|
| 176 | g_free (hostname); |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | gdm_chooser_client_call_disconnect (session->priv->client); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | gboolean |
---|
| 184 | gdm_chooser_session_start (GdmChooserSession *session, |
---|
| 185 | GError **error) |
---|
| 186 | { |
---|
| 187 | gboolean res; |
---|
| 188 | |
---|
| 189 | g_return_val_if_fail (GDM_IS_CHOOSER_SESSION (session), FALSE); |
---|
| 190 | |
---|
| 191 | res = gdm_chooser_client_start (session->priv->client, error); |
---|
| 192 | |
---|
| 193 | if (res) { |
---|
| 194 | start_settings_daemon (session); |
---|
| 195 | start_window_manager (session); |
---|
| 196 | |
---|
| 197 | /* Only support XDMCP on remote choosers */ |
---|
| 198 | session->priv->chooser_dialog = gdm_host_chooser_dialog_new (GDM_CHOOSER_HOST_KIND_XDMCP); |
---|
| 199 | g_signal_connect (session->priv->chooser_dialog, |
---|
| 200 | "response", |
---|
| 201 | G_CALLBACK (on_dialog_response), |
---|
| 202 | session); |
---|
| 203 | gtk_widget_show (session->priv->chooser_dialog); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | return res; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | void |
---|
| 210 | gdm_chooser_session_stop (GdmChooserSession *session) |
---|
| 211 | { |
---|
| 212 | g_return_if_fail (GDM_IS_CHOOSER_SESSION (session)); |
---|
| 213 | |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | static void |
---|
| 217 | gdm_chooser_session_set_property (GObject *object, |
---|
| 218 | guint prop_id, |
---|
| 219 | const GValue *value, |
---|
| 220 | GParamSpec *pspec) |
---|
| 221 | { |
---|
| 222 | switch (prop_id) { |
---|
| 223 | default: |
---|
| 224 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
| 225 | break; |
---|
| 226 | } |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | static void |
---|
| 230 | gdm_chooser_session_get_property (GObject *object, |
---|
| 231 | guint prop_id, |
---|
| 232 | GValue *value, |
---|
| 233 | GParamSpec *pspec) |
---|
| 234 | { |
---|
| 235 | switch (prop_id) { |
---|
| 236 | default: |
---|
| 237 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
| 238 | break; |
---|
| 239 | } |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | static GObject * |
---|
| 243 | gdm_chooser_session_constructor (GType type, |
---|
| 244 | guint n_construct_properties, |
---|
| 245 | GObjectConstructParam *construct_properties) |
---|
| 246 | { |
---|
| 247 | GdmChooserSession *chooser_session; |
---|
| 248 | |
---|
| 249 | chooser_session = GDM_CHOOSER_SESSION (G_OBJECT_CLASS (gdm_chooser_session_parent_class)->constructor (type, |
---|
| 250 | n_construct_properties, |
---|
| 251 | construct_properties)); |
---|
| 252 | |
---|
| 253 | return G_OBJECT (chooser_session); |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | static void |
---|
| 257 | gdm_chooser_session_dispose (GObject *object) |
---|
| 258 | { |
---|
| 259 | g_debug ("GdmChooserSession: Disposing chooser_session"); |
---|
| 260 | |
---|
| 261 | G_OBJECT_CLASS (gdm_chooser_session_parent_class)->dispose (object); |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | static void |
---|
| 265 | gdm_chooser_session_class_init (GdmChooserSessionClass *klass) |
---|
| 266 | { |
---|
| 267 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
---|
| 268 | |
---|
| 269 | object_class->get_property = gdm_chooser_session_get_property; |
---|
| 270 | object_class->set_property = gdm_chooser_session_set_property; |
---|
| 271 | object_class->constructor = gdm_chooser_session_constructor; |
---|
| 272 | object_class->dispose = gdm_chooser_session_dispose; |
---|
| 273 | object_class->finalize = gdm_chooser_session_finalize; |
---|
| 274 | |
---|
| 275 | g_type_class_add_private (klass, sizeof (GdmChooserSessionPrivate)); |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | static void |
---|
| 279 | gdm_chooser_session_init (GdmChooserSession *session) |
---|
| 280 | { |
---|
| 281 | |
---|
| 282 | session->priv = GDM_CHOOSER_SESSION_GET_PRIVATE (session); |
---|
| 283 | |
---|
| 284 | session->priv->client = gdm_chooser_client_new (); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | static void |
---|
| 288 | gdm_chooser_session_finalize (GObject *object) |
---|
| 289 | { |
---|
| 290 | GdmChooserSession *chooser_session; |
---|
| 291 | |
---|
| 292 | g_return_if_fail (object != NULL); |
---|
| 293 | g_return_if_fail (GDM_IS_CHOOSER_SESSION (object)); |
---|
| 294 | |
---|
| 295 | chooser_session = GDM_CHOOSER_SESSION (object); |
---|
| 296 | |
---|
| 297 | g_return_if_fail (chooser_session->priv != NULL); |
---|
| 298 | |
---|
| 299 | G_OBJECT_CLASS (gdm_chooser_session_parent_class)->finalize (object); |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | GdmChooserSession * |
---|
| 303 | gdm_chooser_session_new (void) |
---|
| 304 | { |
---|
| 305 | if (session_object != NULL) { |
---|
| 306 | g_object_ref (session_object); |
---|
| 307 | } else { |
---|
| 308 | session_object = g_object_new (GDM_TYPE_CHOOSER_SESSION, NULL); |
---|
| 309 | g_object_add_weak_pointer (session_object, |
---|
| 310 | (gpointer *) &session_object); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | return GDM_CHOOSER_SESSION (session_object); |
---|
| 314 | } |
---|