Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • D dbus
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 246
    • Issues 246
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 33
    • Merge requests 33
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • dbus
  • dbus
  • Issues
  • #334

Closed
Open
Created Apr 17, 2021 by Frederik Van Bogaert@fvanbogaert

feature request: dbus-send: add the ability to send variant maps

TL;DR: please apply the following patch:

diff --git a/tools/dbus-send.c b/tools/dbus-send.c
index 343fd75a..f2ed58cf 100644
--- a/tools/dbus-send.c
+++ b/tools/dbus-send.c
@@ -235,6 +235,8 @@ type_from_name (const char *arg)
     type = DBUS_TYPE_BOOLEAN;
   else if (!strcmp (arg, "objpath"))
     type = DBUS_TYPE_OBJECT_PATH;
+  else if (!strcmp (arg, "variant"))
+    type = DBUS_TYPE_VARIANT;
   else
     {
       fprintf (stderr, "%s: Unknown type \"%s\"\n", appname, arg);

Longer story: I recently wanted to add a key binding to quickly open a new tab in my terminal editor (QTerminal) using its D-Bus API. I was unable to do this, however, because of how it's implemented:

frederik@fredevuan-pc:~/dbus$ qdbus | grep QTerminal
 org.lxqt.QTerminal-2715
frederik@fredevuan-pc:~/dbus$ dbus-send --print-reply --dest=org.lxqt.QTerminal-2715 /  org.lxqt.QTerminal.Process.getActiveWindow
method return time=1618697773.286794 sender=:1.33 -> destination=:1.264 serial=139 reply_serial=2
   object path "/windows/8dc2b39f09c549d0b5c467f613ff1c40"
frederik@fredevuan-pc:~/dbus$ dbus-send --session --print-reply --dest=org.lxqt.QTerminal-2715 /windows/8dc2b39f09c549d0b5c467f613ff1c40 org.freedesktop.DBus.Introspectable.Introspect | grep -A4 newTab
    <method name="newTab">
      <annotation value="QHash&lt;QString,QVariant&gt;" name="org.qtproject.QtDBus.QtTypeName.In0"/>
      <arg direction="in" type="a{sv}" name="termArgs"/>
      <arg direction="out" type="o" name="newTerminal"/>
    </method>

The type a{sv} (implemented using QHash<QString,QVariant> in QtDBus) corresponds to a dict of string->variant mappings. It turns out just providing an empty dictionary would work fine in my case. However, neither dbus-send nor qdbus seem to support sending this type of argument.

frederik@fredevuan-pc:~/dbus$ dbus-send --print-reply --dest=org.lxqt.QTerminal-2715 /windows/8dc2b39f09c549d0b5c467f613ff1c40  org.lxqt.QTerminal.Window.newTab 'dict:string:variant:'
dbus-send: Unknown type "variant"

I found some leads, including a 5 year-old patch claiming to add support for this on Stack Overflow: https://stackoverflow.com/questions/8846671/how-to-use-a-variant-dictionary-asv-in-dbus-send

However, I'm not sure it still applies cleanly, so I tried the simpler approach I mentioned at the top of the description. After that, it works, and I can successfully spawn new tabs in QTerminal. Hurray!

frederik@fredevuan-pc:~/dbus$ bin/dbus-send --print-reply -dest=org.lxqt.QTerminal-2715 /windows/8dc2b39f09c549d0b5c467f613ff1c40  org.lxqt.QTerminal.Window.newTab 'dict:string:variant:'
method return time=1618698152.478846 sender=:1.33 -> destination=:1.273 serial=145 reply_serial=2
   object path "/tabs/a7ec38e4bee34ca2890470973fd986a3"

I also tried the procedure specified in your Contributing.md file (forking the repo on the freedesktop.org gitlab, adding the patch on a separate branch there, and opening a MR to https://gitlab.freedesktop.org/dbus/dbus/merge_requests. However, I'm lacking the permissions here to actually open a Merge Request. If this procedure is not correct, perhaps the contributing.md could be updated?

My repo is here: https://gitlab.freedesktop.org/fvanbogaert/dbus-send-variant (branch: https://gitlab.freedesktop.org/fvanbogaert/dbus-send-variant/-/commits/dev_add_variant_type_to_dbus_send)

Thanks 🙂

Fixes: #59

Edited Apr 19, 2021 by Philip Withnall
Assignee
Assign to
Time tracking