Mercurial > audlegacy
annotate src/libeggsmclient/eggsmclient-win32.c @ 4326:3af534ed9d20
cleaning up some cruft
author | mf0102 <0102@gmx.at> |
---|---|
date | Thu, 13 Mar 2008 16:41:48 +0100 |
parents | c942eaef7bc6 |
children |
rev | line source |
---|---|
4315
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
1 /* |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
2 * Copyright (C) 2007 Novell, Inc. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
3 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
4 * This library is free software; you can redistribute it and/or |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
5 * modify it under the terms of the GNU Library General Public |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
6 * License as published by the Free Software Foundation; either |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
7 * version 2 of the License, or (at your option) any later version. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
8 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
9 * This library is distributed in the hope that it will be useful, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
12 * Library General Public License for more details. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
13 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
14 * You should have received a copy of the GNU Library General Public |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
15 * License along with this library; if not, write to the |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
17 * Boston, MA 02111-1307, USA. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
18 */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
19 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
20 #include "config.h" |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
21 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
22 #include "eggsmclient-private.h" |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
23 #include <gdk/gdk.h> |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
24 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
25 #define WIN32_LEAN_AND_MEAN |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
26 #define UNICODE |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
27 #include <windows.h> |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
28 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
29 #define EGG_TYPE_SM_CLIENT_WIN32 (egg_sm_client_win32_get_type ()) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
30 #define EGG_SM_CLIENT_WIN32(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_SM_CLIENT_WIN32, EggSMClientWin32)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
31 #define EGG_SM_CLIENT_WIN32_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_SM_CLIENT_WIN32, EggSMClientWin32Class)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
32 #define EGG_IS_SM_CLIENT_WIN32(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EGG_TYPE_SM_CLIENT_WIN32)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
33 #define EGG_IS_SM_CLIENT_WIN32_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_SM_CLIENT_WIN32)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
34 #define EGG_SM_CLIENT_WIN32_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_SM_CLIENT_WIN32, EggSMClientWin32Class)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
35 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
36 typedef struct _EggSMClientWin32 EggSMClientWin32; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
37 typedef struct _EggSMClientWin32Class EggSMClientWin32Class; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
38 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
39 struct _EggSMClientWin32 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
40 EggSMClient parent; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
41 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
42 GAsyncQueue *msg_queue; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
43 }; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
44 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
45 struct _EggSMClientWin32Class |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
46 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
47 EggSMClientClass parent_class; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
48 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
49 }; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
50 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
51 static void sm_client_win32_startup (EggSMClient *client, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
52 const char *client_id); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
53 static void sm_client_win32_will_quit (EggSMClient *client, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
54 gboolean will_quit); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
55 static gboolean sm_client_win32_end_session (EggSMClient *client, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
56 EggSMClientEndStyle style, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
57 gboolean request_confirmation); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
58 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
59 static gpointer sm_client_thread (gpointer data); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
60 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
61 G_DEFINE_TYPE (EggSMClientWin32, egg_sm_client_win32, EGG_TYPE_SM_CLIENT) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
62 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
63 static void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
64 egg_sm_client_win32_init (EggSMClientWin32 *win32) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
65 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
66 ; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
67 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
68 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
69 static void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
70 egg_sm_client_win32_class_init (EggSMClientWin32Class *klass) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
71 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
72 EggSMClientClass *sm_client_class = EGG_SM_CLIENT_CLASS (klass); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
73 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
74 sm_client_class->startup = sm_client_win32_startup; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
75 sm_client_class->will_quit = sm_client_win32_will_quit; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
76 sm_client_class->end_session = sm_client_win32_end_session; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
77 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
78 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
79 EggSMClient * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
80 egg_sm_client_win32_new (void) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
81 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
82 return g_object_new (EGG_TYPE_SM_CLIENT_WIN32, NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
83 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
84 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
85 static void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
86 sm_client_win32_startup (EggSMClient *client, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
87 const char *client_id) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
88 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
89 EggSMClientWin32 *win32 = (EggSMClientWin32 *)client; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
90 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
91 /* spawn another thread to listen for logout signals on */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
92 win32->msg_queue = g_async_queue_new (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
93 g_thread_create (sm_client_thread, client, FALSE, NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
94 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
95 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
96 static void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
97 sm_client_win32_will_quit (EggSMClient *client, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
98 gboolean will_quit) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
99 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
100 EggSMClientWin32 *win32 = (EggSMClientWin32 *)client; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
101 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
102 /* Can't push NULL onto a GAsyncQueue, so we add 1 to the value... */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
103 g_async_queue_push (win32->msg_queue, GINT_TO_POINTER (will_quit + 1)); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
104 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
105 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
106 static gboolean |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
107 sm_client_win32_end_session (EggSMClient *client, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
108 EggSMClientEndStyle style, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
109 gboolean request_confirmation) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
110 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
111 UINT uFlags = EWX_LOGOFF; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
112 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
113 switch (style) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
114 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
115 case EGG_SM_CLIENT_END_SESSION_DEFAULT: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
116 case EGG_SM_CLIENT_LOGOUT: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
117 uFlags = EWX_LOGOFF; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
118 break; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
119 case EGG_SM_CLIENT_REBOOT: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
120 uFlags = EWX_REBOOT; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
121 break; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
122 case EGG_SM_CLIENT_SHUTDOWN: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
123 uFlags = EWX_POWEROFF; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
124 break; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
125 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
126 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
127 /* There's no way to make ExitWindowsEx() show a logout dialog, so |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
128 * we ignore @request_confirmation. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
129 */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
130 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
131 #ifdef SHTDN_REASON_FLAG_PLANNED |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
132 ExitWindowsEx (uFlags, SHTDN_REASON_FLAG_PLANNED); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
133 #else |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
134 ExitWindowsEx (uFlags, 0); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
135 #endif |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
136 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
137 return TRUE; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
138 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
139 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
140 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
141 /* callbacks from logout-listener thread */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
142 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
143 static gboolean |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
144 emit_quit_requested (gpointer smclient) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
145 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
146 gdk_threads_enter (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
147 egg_sm_client_quit_requested (smclient); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
148 gdk_threads_leave (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
149 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
150 return FALSE; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
151 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
152 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
153 static gboolean |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
154 emit_quit (gpointer smclient) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
155 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
156 EggSMClientWin32 *win32 = smclient; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
157 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
158 gdk_threads_enter (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
159 egg_sm_client_quit (smclient); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
160 gdk_threads_leave (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
161 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
162 g_async_queue_push (win32->msg_queue, GINT_TO_POINTER (1)); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
163 return FALSE; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
164 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
165 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
166 static gboolean |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
167 emit_quit_cancelled (gpointer smclient) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
168 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
169 EggSMClientWin32 *win32 = smclient; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
170 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
171 gdk_threads_enter (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
172 egg_sm_client_quit_cancelled (smclient); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
173 gdk_threads_leave (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
174 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
175 g_async_queue_push (win32->msg_queue, GINT_TO_POINTER (1)); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
176 return FALSE; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
177 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
178 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
179 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
180 /* logout-listener thread */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
181 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
182 static int |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
183 async_emit (EggSMClientWin32 *win32, GSourceFunc emitter) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
184 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
185 /* ensure message queue is empty */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
186 while (g_async_queue_try_pop (win32->msg_queue)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
187 ; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
188 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
189 /* Emit signal in the main thread and wait for a response */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
190 g_idle_add (emitter, win32); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
191 return GPOINTER_TO_INT (g_async_queue_pop (win32->msg_queue)) - 1; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
192 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
193 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
194 LRESULT CALLBACK |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
195 sm_client_win32_window_procedure (HWND hwnd, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
196 UINT message, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
197 WPARAM wParam, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
198 LPARAM lParam) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
199 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
200 EggSMClientWin32 *win32 = |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
201 (EggSMClientWin32 *)GetWindowLongPtr (hwnd, GWLP_USERDATA); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
202 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
203 switch (message) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
204 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
205 case WM_QUERYENDSESSION: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
206 return async_emit (win32, emit_quit_requested); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
207 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
208 case WM_ENDSESSION: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
209 if (wParam) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
210 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
211 /* The session is ending */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
212 async_emit (win32, emit_quit); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
213 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
214 else |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
215 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
216 /* Nope, the session *isn't* ending */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
217 async_emit (win32, emit_quit_cancelled); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
218 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
219 return 0; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
220 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
221 default: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
222 return DefWindowProc (hwnd, message, wParam, lParam); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
223 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
224 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
225 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
226 static gpointer |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
227 sm_client_thread (gpointer smclient) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
228 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
229 HINSTANCE instance; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
230 WNDCLASSEXW wcl; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
231 ATOM klass; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
232 HWND window; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
233 MSG msg; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
234 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
235 instance = GetModuleHandle (NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
236 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
237 memset (&wcl, 0, sizeof (WNDCLASSEX)); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
238 wcl.cbSize = sizeof (WNDCLASSEX); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
239 wcl.lpfnWndProc = sm_client_win32_window_procedure; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
240 wcl.hInstance = instance; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
241 wcl.lpszClassName = L"EggSmClientWindow"; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
242 klass = RegisterClassEx (&wcl); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
243 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
244 window = CreateWindowEx (0, MAKEINTRESOURCE (klass), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
245 L"EggSmClientWindow", 0, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
246 10, 10, 50, 50, GetDesktopWindow (), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
247 NULL, instance, NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
248 SetWindowLongPtr (window, GWLP_USERDATA, (LONG_PTR)smclient); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
249 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
250 /* main loop */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
251 while (GetMessage (&msg, NULL, 0, 0)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
252 DispatchMessage (&msg); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
253 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
254 return NULL; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
255 } |