When I want to log out of my Plasma session, I run a command:
Please don’t use that.
qdbus org.kde.LogoutPrompt /LogoutPrompt org.kde.LogoutPrompt.promptLogout
qdbus org.kde.LogoutPrompt /LogoutPrompt promptReboot
qdbus org.kde.LogoutPrompt /LogoutPrompt promptShutdown
to get a prompt
or
qdbus org.kde.Shutdown /Shutdown org.kde.Shutdown.logout
logoutAndReboot
logoutAndShutdown
to perform an action without prompt
This works in Plasma 5 since a few years, the ksmserver API will be gone in Plasma 6. I didn’t get rid of it at the time given how much the old API has been copy pasted about the internet.