This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Plasma: Shutdown Suspend Resume and session-end DBus signals

Tags: None
(comma "," separated)
remia
Registered Member
Posts
2
Karma
0
Hi All,

I'm sorry to ask this here because I guess it's not the right place, but I failed to find what I'm looking for.

I developing a python application and I would need some support on KDE, especially on how KDE is using D-Bus. I'm looking to catch end session events among other things.

Is there a dedicated place where I can find help/ ask questions on a subject like this one?

Thank you for your help.

Last edited by remia on Tue Aug 10, 2021 5:38 am, edited 1 time in total.
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS

Re: KDE Development Support

Mon Aug 09, 2021 9:56 am
Hi!

You can start reading at Techbase: D-Bus. For logout-stuff you should have a look at freedesktop.org, as systemd or elogind is the current standard on most systems, so you can logout via
Code: Select all
qdbus org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.TerminateSession $sessionID
# or
loginctl terminate-session $sessionID

On Plasma the ksmserver should be used.
Code: Select all
qdbus org.kde.ksmserver /KSMServer logout $x $y $z

where x=ask (0/1), y=method (0=none, 1=reboot, 2=halt, 3=logout), z=mode (0=wait, 1=try, 2=force, 3=user popup).
remia
Registered Member
Posts
2
Karma
0
Thank you for your help. I should have mentioned that I'm on CentOS 7.9 and Plasma.

More precisely, I'm not trying to manage the session, I'm trying to catch end session signals, and also Shutdown, Suspend and Resume ones.

Here is what I do for Gnome desktop manager, which is working well, I'm trying now to do the equivalent on Plasma:

Code: Select all
# Shutdown, Suspend and Resume
#
# create inhibit delay lock
QtDBus.QDBusInterface("",  "/org/freedesktop/login1",   "org.freedesktop.DBus.Properties", QtDBus.QDBusConnection.systemBus()).call(
        "sleep", "Bernard", "Update db...", "delay")

# register to signals
QtDBus.QDBusConnection.systemBus().connect("",  "/org/freedesktop/login1",  "org.freedesktop.login1.Manager",  "PrepareForShutdown",  self.OnPrepareForShutdownLin)
QtDBus.QDBusConnection.systemBus().connect("",  "/org/freedesktop/login1",  "org.freedesktop.login1.Manager",  "PrepareForSleep",  self.OnPrepareForSleepLin)

# Session end
#
# register to session bus signals for session end
sessionBus = QtDBus.QDBusConnection.sessionBus()

# get the session manager interface
sessionManager = QtDBus.QDBusInterface("org.gnome.SessionManager",  "/org/gnome/SessionManager",  "org.gnome.SessionManager", sessionBus)
# create a client
clientId = sessionManager.call("RegisterClient","","")
if clientId.type() == 3:
    raise Exception("Couldn't create client to org.gnome.SessionManager. KDE session present instead ?")

# signal connection to slots
path = clientId.arguments()[0]
sessionBus.connect(clientId.service(), path, "org.gnome.SessionManager.ClientPrivate", "EndSession", self.OnEndSessionLin)
sessionBus.connect(clientId.service(), path, "org.gnome.SessionManager.ClientPrivate", "Stop", self.OnStopLin)


I failed to find resources on the Plasma DBus configuration, I don't know how to catch the signals. I tried to use d-feet and dbus-monitor to analyse the org.kde.ksmserver service, but this is an hassle, as each time I close the session or trigger a shutdown I need to wait the OS to restart.

If you could you give me a some hits, or help, that would be much appreciated.
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
So you do not want to trigger a logout, instead you want to catch it?

This should work using org.freedesktop-stuff, I think org.freedesktop.DBus /org/freedesktop/DBus NameOwnerChanged. But as you need more general hints: use the monitor tool:
Code: Select all
dbus-monitor --user
will show everything running in user context, but you can also watch for --system, for expressions, addresses, … So that should be the tool you were missing, I think.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]