添加 Dbus 抑制劑但立即刪除

添加 Dbus 抑制劑但立即刪除

我了解到可以透過以下方式為 GUI 會話創建抑制劑總線。然而,當我嘗試添加抑制劑時,它會立即被刪除。這是一個例子。

我通過此命令調用添加抑製劑(這應該會防止發生註銷):

qdbus org.gnome.SessionManager  /org/gnome/SessionManager org.gnome.SessionManager.Inhibit "x-terminal-emulator" $(xdotool getactivewindow) "TEST REASON" 1

的輸出dbus-monitor表明它已被添加,但隨後立即被刪除。

$ dbus-monitor --profile | grep -i inhibitor
sig 1474613346.596581   156 :1.23   <none>  /org/gnome/SessionManager   org.gnome.SessionManager    InhibitorAdded
sig 1474613346.603137   159 :1.23   <none>  /org/gnome/SessionManager   org.gnome.SessionManager    InhibitorRemoved

我該如何解決這個問題?

使用系統:Ubuntu 16.04、Unity

答案1

抑制劑會立即被刪除,因為它會在 dbus 用戶端斷開連接時自動刪除。

因此,只要抑制有效,您就必須讓客戶端保持運作。

例子:

python3 -c 'import pydbus; pydbus.SessionBus().get(
"org.gnome.SessionManager").Inhibit("what", 0, "why", 1);
import time; time.sleep(2**32-1)'

與測試相關的是D-Bus 介面的IsInhibited和方法,例如:GetInhibitorsorg.gnome.SessionManager

qdbus org.gnome.SessionManager /org/gnome/SessionManager \
    org.gnome.SessionManager.IsInhibited 8

有關如何列出抑制劑的信息,請參見。列表_抑制劑()在我的一個實用程式中。

相關內容