Class SessionManagerDBus
java.lang.Object
org.eclipse.swt.internal.SessionManagerDBus
Communicates with session manager to receive logoff/shutdown events.
GTK also has an implementation (see gtk_application_impl_dbus_startup)
However, it requires GtkApplication, and SWT doesn't use that.
Current session manager clients can be seen in:
Gnome:
dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.GetClients
XFCE:
dbus-send --print-reply --dest=org.xfce.SessionManager /org/xfce/SessionManager org.xfce.Session.Manager.ListClients
If you know clientObjectPath, you can send Stop signal with:
dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager/ClientXX org.gnome.SessionManager.Client.Stop
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate longprivate static intprivate long1) Prevents old answers to new signals.private longprivate Callbackprivate longprivate booleanprivate List<SessionManagerDBus.IListener> private longprivate SessionManagerDBus.ShutdownHook -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(SessionManagerDBus.IListener listener) Subscribes display for session manager events.private StringGets the value of 'DESKTOP_AUTOSTART_ID'.private booleanprivate booleanprivate longconnectSessionManager(String dbusName, String objectPath, String interfaceName) Creates a connection to the session manager.voiddispose()private static StringextractFreeGError(long errorPtr) private static StringextractVariantTupleS(long variant) private longg_signal_handler(long proxy, long sender_name, long signal_name, long parameters, long user_data) Receives events from session manager.private voidprivate voidprivate voidprivate booleanprivate booleanprivate StringregisterClient(String appID, String clientStartupID) Issues 'RegisterClient' dbus request to register with session manager.voidremoveListener(SessionManagerDBus.IListener listener) private voidsendEndSessionResponse(boolean is_ok, String reason, long responseID) private booleanstart()private voidstop()Un-subscribes from session manager events.private long
-
Field Details
-
listeners
-
g_signal_callback
-
g_signal_callbackid
private long g_signal_callbackid -
shutdownHook
-
sessionManagerProxy
private long sessionManagerProxy -
clientProxy
private long clientProxy -
clientObjectPath
-
isGnome
private boolean isGnome -
dbusTimeoutMsec
private static int dbusTimeoutMsec -
endSessionResponseCounter
private long endSessionResponseCounter1) Prevents old answers to new signals. For example, if signal's handler asks user, it can stay for a while and when it's closed it could be the other signal already. 2) Makes sure answer is given on System.exit() -
endSessionResponseWanted
private long endSessionResponseWanted
-
-
Constructor Details
-
SessionManagerDBus
public SessionManagerDBus()
-
-
Method Details
-
dispose
public void dispose() -
addListener
Subscribes display for session manager events. Display will receive SWT.Close and will be able to hint that the session should not end. Please note that time limit imposed by session manager is 1 second. Final cleanup should happen at Display.dispose(). Display will be disposed before session ends, allowing final cleanup to happen. Please note that time limit imposed by session manager is 10 seconds. -
removeListener
-
start
private boolean start() -
stop
private void stop()Un-subscribes from session manager events. NOTE: Both Gnome and XFCE will automatically remove client record when client's process ends, so it's not a big deal if this is not called at all. See comments for this class to find 'dbus-send' commands to verify that. 'synchronized' guards against the rare possible case where some thread calls System.exit() while main thread is in Display.dispose() and both main thread and my 'ShutdownHook' try to run .stop(). -
wantEndSessionResponse
private long wantEndSessionResponse() -
sendEndSessionResponse
-
queryReadyToExit
private boolean queryReadyToExit() -
handleQueryEndSession
private void handleQueryEndSession() -
handleEndSession
private void handleEndSession() -
handleStop
private void handleStop() -
g_signal_handler
private long g_signal_handler(long proxy, long sender_name, long signal_name, long parameters, long user_data) Receives events from session manager. Docs: https://developer.gnome.org/gio/stable/GDBusProxy.html#GDBusProxy-g-signal NOTE: Will be called through native callback.- Returns:
- Error string in case of error, null if successful.
-
extractVariantTupleS
-
extractFreeGError
-
connectSessionManager
-
connectSessionManager
private boolean connectSessionManager() -
claimDesktopAutostartID
Gets the value of 'DESKTOP_AUTOSTART_ID'. This environment variable is set by session manager if the application was auto started (because it is configured to run automatically for every session). The variable helps session manager to match autostart settings with actual applications. For applications that were not started automatically, the variable is expected to be absent. Once used, 'DESKTOP_AUTOSTART_ID' must not leak into child processes, or they will fail to 'RegisterClient'. NOTE: calling this function twice will give empty ID on second call. I think this is reasonable. If second object is created for whatever reason, it's OK to consider it to be a separate client. -
registerClient
-
registerClient
private boolean registerClient() -
connectClientSignal
private boolean connectClientSignal()
-