gdbus - org.fcitx.Fcitx
說明
這個範例,說明如何利用「gdbus」這個指令,來跟「fcitx」溝通,切換輸入法。
範例
執行
$ gdbus introspect --session --dest org.fcitx.Fcitx --object-path /
顯示
node / {
  node MenuBar {
  };
  node StatusNotifierItem {
  };
  node inputmethod {
  };
  node keyboard {
  };
  node kimpanel {
  };
};
執行
$ gdbus introspect --session --dest org.fcitx.Fcitx --object-path / --xml
顯示
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
  <node name="MenuBar"/>
  <node name="StatusNotifierItem"/>
  <node name="inputmethod"/>
  <node name="keyboard"/>
  <node name="kimpanel"/>
</node>
執行
$ gdbus introspect --session --dest org.fcitx.Fcitx --object-path / --recurse
顯示
...略...
執行
$ gdbus introspect --session --dest org.fcitx.Fcitx --object-path /inputmethod
或是執行
$ gdbus introspect --session --dest org.fcitx.Fcitx --object-path /inputmethod | less
顯示
node /inputmethod {
  interface org.freedesktop.DBus.Introspectable {
    methods:
      Introspect(out s data);
    signals:
    properties:
  };
  interface org.freedesktop.DBus.Properties {
    methods:
      Get(in  s interface_name,
          in  s property_name,
          out v value);
      Set(in  s interface_name,
          in  s property_name,
          in  v value);
      GetAll(in  s interface_name,
             out a{sv} values);
    signals:
      PropertiesChanged(s interface_name,
                        a{sv} changed_properties,
                        as invalidated_properties);
    properties:
  };
  interface org.fcitx.Fcitx.InputMethod {
    methods:
      CreateIC(out i icid,
               out u keyval1,
               out u state1,
               out u keyval2,
               out u state2);
      CreateICv2(in  s appname,
                 out i icid,
                 out b enable,
                 out u keyval1,
                 out u state1,
                 out u keyval2,
                 out u state2);
      CreateICv3(in  s appname,
                 in  i pid,
                 out i icid,
                 out b enable,
                 out u keyval1,
                 out u state1,
                 out u keyval2,
                 out u state2);
      Exit();
      GetCurrentIM(out s im);
      SetCurrentIM(in  s im);
      ReloadConfig();
      ReloadAddonConfig(in  s addon);
      Restart();
      Configure();
      ConfigureAddon(in  s addon);
      ConfigureIM(in  s im);
      GetCurrentUI(out s addon);
      GetIMAddon(in  s im,
                 out s addon);
      ActivateIM();
      InactivateIM();
      ToggleIM();
      ResetIMList();
      GetCurrentState(out i state);
    signals:
    properties:
      @org.freedesktop.DBus.Property.EmitsChangedSignal("true")
...略...
執行
$ gdbus introspect --session --dest org.fcitx.Fcitx --object-path /inputmethod
顯示
...略...
執行
$ gdbus call --session --dest org.fcitx.Fcitx --object-path /inputmethod --method org.fcitx.Fcitx.InputMethod.GetCurrentIM
顯示
('fcitx-keyboard-us',)
執行
$ gdbus call --session --dest org.fcitx.Fcitx --object-path /inputmethod --method org.fcitx.Fcitx.InputMethod.SetCurrentIM chewing
顯示
()
就會把輸入法切換到「fcitx-chewing (新酷音)」。
執行
$ gdbus call --session --dest org.fcitx.Fcitx --object-path /inputmethod --method org.fcitx.Fcitx.InputMethod.GetCurrentIM
顯示
('chewing',)
執行
$ gdbus call --session --dest org.fcitx.Fcitx --object-path /inputmethod --method org.fcitx.Fcitx.InputMethod.SetCurrentIM fcitx-keyboard-us
顯示
()
就會把輸入法切回到「英文輸入」。