This is some helpful utilities for sway (and other wayland compositors, like jay) and toggl track, namely it does:
- Send a tracking reminder at a regular interval if you're not tracking your time. By default this is every 5 minutes but can be configured (see below)
- Send timeline data to toggl's API, based on what you've got focused in your compositor. So in case you forgot to track you can figure it out based on what you were doing on your computer.
- Print waybar custom module compatible json so you can show if/what you're
tracking.
Example module:
and suggested css:
{ "custom/toggl": { "format": "", "return-type": "json", "exec": "node /home/sbe/test/sway-toggl/dist/index.js", "on-click": "xdg-open https://track.toggl.com", "escape": true }, }#custom-toggl { padding: 0 10px 0 8px; margin: 0 0px; color: @cl_fore; } #custom-toggl.disabled { background-color: @cl_urge; color: @cl_fore; }
There are two backends for figuring out what you have focused, selected with
--backend:
swayuses the sway IPC socket, and works on sway (and anything else that implements its IPC protocol).wlrtalks the waylandzwlr_foreign_toplevel_manager_v1protocol directly to the compositor, and works on jay and most other wlroots-based compositors.
The default is --backend auto which picks sway if SWAYSOCK is set and
wlr otherwise, so usually you don't need to pass anything.
Idle detection is done with swayidle in both cases, which despite the name is
compositor agnostic: it uses the ext-idle-notify-v1 wayland protocol
(swayidle >= 1.8), which jay implements.
Jay only advertises the foreign-toplevel and idle-notify protocols to clients
that have been granted the corresponding capabilities. Add client rules to your
jay config (~/.config/jay/config.toml):
[[clients]]
match.comm = "node"
capabilities = ["foreign-toplevel-manager"]
[[clients]]
match.comm = "swayidle"
capabilities = ["idle-notifier"]Note that match.comm = "node" grants this to every node process; you can
narrow it down with e.g. match.exe-regex or a dedicated wrapper script if
you prefer. Alternatively you can start the whole thing through
jay run-privileged, which grants all capabilities.
This module uses the same .togglrc as https://toggl.uhlir.dev/, placed
either in ~/.togglrc or in the XDG config directory (most likely
~/.config/.togglrc).
You need to set an authentication method in the [auth] section, either
api_token, or username and password. This can also be provided with ENV
variables TOGGL_API_TOKEN, TOGGL_USERNAME, and TOGGL_PASSWORD
respectively.
You can also configure idle_notify_interval_seconds and under the [options]
section to tweak how often the notification is sent when you're not tracking.
This script will also add a desktop_id UUID under the [options] section,
this is needed to attribute your timeline data to the right device.
So, for example
[auth]
api_token = asdasdasda
[options]
desktop_id = 733a53e7-9311-4975-a276-bdacff742f57
idle_notify_interval_seconds = 300