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