Skip to content

CLI usage without Gnome environment

JingMatrix edited this page Jun 16, 2023 · 13 revisions

We can use gsconnect without Gnome installed, this page explains how to do it for general wayland environment.

Preparations

  1. Build libgnome-volume-control, which is a subproject of gnome-shell but can be built independently;
  2. Install ydotool, and start its service: systemctl start --user ydotool.service;
  3. Install wl-type and wl-clipboard.

Install gsconnect

  1. Clone this repo;
  2. Build and install it: meson build, ninja -C build install-zip;
  3. Creat symbolic link gsconnect, for example: ln -s $HOME/.local/share/gnome-shell/extensions/[email protected]/service/daemon.js gsconnect;
  4. Put gsconnect into your PATH.

Indicator of gsconnect

For example, with waybar and hack nerd font, one can do the following steps.

Script to fetch gsconnect status

Save the following script as to ~/.config/waybar/gsconnect-status.py.

#! python3
from pydbus import SessionBus
import json

session_bus = SessionBus()
proxy_gsconnect = session_bus.get(
    'org.gnome.Shell.Extensions.GSConnect',
    '/org/gnome/Shell/Extensions/GSConnect')
gsconnect = proxy_gsconnect[
    'org.freedesktop.DBus.ObjectManager']

waybar = {'text': "", 'tooltip': "", "class": "GSdevices", "types": ""}

icons = {'smartphone-symbolic': "󰄜", "tablet-symbolic": "",
         'tv-symbolic': "", 'computer-symbolic': ""}

types = []
devices = gsconnect.GetManagedObjects()
for dev in devices:
    devinfo = devices[dev]['org.gnome.Shell.Extensions.GSConnect.Device']
    if devinfo['Connected']:
        if devinfo['Paired']:
            types.append(devinfo['Type'])
            waybar['text'] += icons[devinfo['IconName']] + ' '
            waybar['tooltip'] += devinfo['Name'] + '\n'
        if not devinfo['Paired']:
            types.append(devinfo['Type'])
            waybar['text'] += ' ' + ' '
            waybar['tooltip'] += devinfo['Name'] + '\n'

waybar['types'] = '+'.join(types)
for key in waybar:
    waybar[key] = waybar[key].strip()

print(json.dumps(waybar))

Install pydbus and test the above script (run gsconnect first) to ensure there is no problem.

Add waybar module

In this step, we assume that you know how to config waybar custom module. If not, see the waybar manual page for instructions`

  1. Create symbolic link: ln -s $HOME/.local/share/gnome-shell/extensions/[email protected]/gsconnect-preferences gsconnect-preferences;
  2. Put gsconnect-preferences into your PATH;
  3. Add waybar custom module:
"custom/gsconnect" : {
   "format": "{}",
  "escape": true,
  "exec": "python3 $HOME/.config/waybar/gsconnect-status.py",
  "return-type": "json",
  "tooltip": "{tooltip}",
  "interval": 30,
  "on-click": "gsconnect-preferences",
}