dbus 概念
--翻遍了google和百度,就这个图对入门帮助最大,dbus的文档真难找
fcitx 概念
dbus-send 命令行
/inputmethod --对象路径
org.freedesktop.DBus.Properties --interface
--dest=org.fcitx.Fcitx //名称
dbus-send --session --dest=org.fcitx.Fcitx --print-reply /inputmethod org.freedesktop.DBus.Properties.GetAll string:org.fcitx.Fcitx.InputMethod method return time=1589505703.719201 sender=:1.4 -> destination=:1.76 serial=218 reply_serial=2 array [ dict entry( string "IMList" variant array [ struct { string "键盘" string "fcitx-keyboard-us" string "en" boolean true } struct { string "拼音" string "pinyin" string "zh_CN" boolean true } struct { string "双拼" string "shuangpin" string "zh_CN" boolean true } struct { string "五笔字型" string "wubi" string "zh_CN" boolean true } struct { string "新酷音" string "chewing" string "zh_TW" boolean true } struct { string "中州韻" string "rime" string "zh_TW" boolean true } struct { string "讯飞输入法" string "iflyime" string "zh_CN" boolean false } struct { string "五笔拼音" string "wbpy" string "zh_CN" boolean false } ] ) dict entry( string "CurrentIM" variant string "fcitx-keyboard-us" ) ]
#获取当前的输入法
uos@uos-PC:~$ dbus-send --session --dest=org.fcitx.Fcitx --print-reply /inputmethod org.fcitx.Fcitx.InputMethod.GetCurrentIM
method return time=1589506396.672512 sender=:1.4 -> destination=:1.81 serial=299 reply_serial=2
string "fcitx-keyboard-us
#设置为chewin 输入法
uos@uos-PC:~$ dbus-send --session --dest=org.fcitx.Fcitx --print-reply /inputmethod org.fcitx.Fcitx.InputMethod.SetCurrentIM string:chewing
method return time=1589506465.397429 sender=:1.4 -> destination=:1.82 serial=317 reply_serial=2
uos@uos-PC:~$
#gdbus 用法
gdbus call --session --dest com.deepin.daemon.Keybinding --object-path /com/deepin/daemon/Keybinding --method com.deepin.daemon.Keybinding.ListAllShortcuts
cmd ==> dbus-send --session --dest=org.fcitx.Fcitx --print-reply /inputmethod org.freedesktop.DBus.Properties.GetAll string:org.fcitx.Fcitx.InputMethod
另一个例子
uos@uos-PC:~/tmp$ dbus-send --session --dest=com.deepin.daemon.InputDevices --print-reply /com/deepin/daemon/InputDevice/Mouse org.freedesktop.DBus.Properties.GetAll string:com.deepin.daemon.InputDevice.Mouse method return time=1612511729.341407 sender=:1.177 -> destination=:1.297 serial=55919 reply_serial=2 array [ dict entry( string "MotionAcceleration" variant double 1 ) dict entry( string "MotionScaling" variant double 10 ) dict entry( string "DoubleClick" variant int32 400 ) dict entry( string "DisableTpad" variant boolean false ) dict entry( string "NaturalScroll" variant boolean false ) dict entry( string "AdaptiveAccelProfile" variant boolean true ) dict entry( string "Exist" variant boolean true ) dict entry( string "LeftHanded" variant boolean true ) dict entry( string "MiddleButtonEmulation" variant boolean false ) dict entry( string "DragThreshold" variant int32 8 ) dict entry( string "MotionThreshold" variant double 1 ) dict entry( string "DeviceList" variant string "[{"Id":7,"Name":"VMware VMware Virtual USB Mouse","TrackPoint":false},{"Id":9,"Name":"VirtualPS/2 VMware VMMouse","TrackPoint":false}]" ) ]
设置鼠标左键
uos@uos-PC:~/tmp$ dbus-send --session --dest=com.deepin.daemon.InputDevices --print-reply /com/deepin/daemon/InputDevice/Mouse org.freedesktop.DBus.Properties.Set string:com.deepin.daemon.InputDevice.Mouse string:LeftHanded variant:boolean:true method return time=1612513318.004456 sender=:1.177 -> destination=:1.311 serial=63883 reply_serial=2
python version
import dbus bus = dbus.SystemBus() hci0 = bus.get_object('org.bluez', '/org/bluez/hci0') props = dbus.Interface(hci0, 'org.freedesktop.DBus.Properties') props.Set('org.bluez.Adapter1', 'Discoverable', True)
dbus signal的处理方法
demo代码参考
https://github.com/sgh/dbus-examples
命令行
signal time=1622515858.073001 sender=:1.719 -> destination=(null destination) serial=77 path=/com/burtonini/dbus/ping; interface=com.burtonini.dbus.Signal; member=Ping
string "Ping!"
dbus-send --type=signal /com/burtonini/dbus/ping com.burtonini.dbus.Signal.Ping string:"Ping"
dbus-monitor | grep -e EntryAdd -e EntryRemove