I need to access the session bus of the currently logged user. Technically that could be the user that created /tmp/.X11-unix/X($DISPLAY) (ignore the colon in $DISPLAY for now but you get it).
I actually need to be able to lock my computer screen and check if its already locked from a background service (running as root) using dbus (there is an interface for that).
My current, hard-coded approach is to os.seteuid(1000) before calling dbus.SessionBus() in my code but this approach won’t work when my snap is fully confined. https://github.com/om26er/screen-brightness-server/blob/e16206de0ebce5646b11e5c96c85e21877337136/sbs/controller.py#L167