Class SessionManagerDBus

java.lang.Object
org.eclipse.swt.internal.SessionManagerDBus

public class SessionManagerDBus extends Object
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
  • Field Details

    • listeners

      private List<SessionManagerDBus.IListener> listeners
    • g_signal_callback

      private Callback g_signal_callback
    • g_signal_callbackid

      private long g_signal_callbackid
    • shutdownHook

      private SessionManagerDBus.ShutdownHook shutdownHook
    • sessionManagerProxy

      private long sessionManagerProxy
    • clientProxy

      private long clientProxy
    • clientObjectPath

      private String clientObjectPath
    • isGnome

      private boolean isGnome
    • dbusTimeoutMsec

      private static int dbusTimeoutMsec
    • endSessionResponseCounter

      private long endSessionResponseCounter
      1) 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

      public void addListener(SessionManagerDBus.IListener listener)
      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

      public void removeListener(SessionManagerDBus.IListener listener)
    • 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

      private void sendEndSessionResponse(boolean is_ok, String reason, long responseID)
    • 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

      private static String extractVariantTupleS(long variant)
    • extractFreeGError

      private static String extractFreeGError(long errorPtr)
    • connectSessionManager

      private long connectSessionManager(String dbusName, String objectPath, String interfaceName)
      Creates a connection to the session manager.
      Returns:
      Pointer to dbus proxy, 0 if failed.
    • connectSessionManager

      private boolean connectSessionManager()
    • claimDesktopAutostartID

      private String 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

      private String registerClient(String appID, String clientStartupID)
      Issues 'RegisterClient' dbus request to register with session manager. Saves result to member variable when successful.
      Returns:
      Error string in case of error, null if successful.
    • registerClient

      private boolean registerClient()
    • connectClientSignal

      private boolean connectClientSignal()