24 Commits

Author SHA1 Message Date
Abdallah Gamal
d8e9bdea83 fix: not resolving flatpak application icons 2023-06-29 19:55:24 +01:00
Jake Stanger
6db7742e06 fix: crash on startup introduced by recent refactors 2023-06-29 18:02:51 +01:00
Jake Stanger
4b88079561 docs: fix header 2023-06-29 17:38:41 +01:00
Jake Stanger
9a68dc99bd build: fix error 2023-06-29 17:37:10 +01:00
Jake Stanger
cc181a8b6d refactor: fix new clippy warnings 2023-06-29 16:57:47 +01:00
Jake Stanger
27f920d012 feat(launcher): slightly improve focus logic when clicking item with multiple windows 2023-06-29 16:42:03 +01:00
Jake Stanger
4a9410abac Merge pull request #199 from JakeStanger/feat/cli-ipc
IPC, CLI and Dynamic Variables
2023-06-29 16:39:56 +01:00
Jake Stanger
607c7285d7 docs: update for ipc/cli, tidy a bit 2023-06-29 16:26:55 +01:00
Jake Stanger
c6319b78fd feat(ipc): support for injecting additional stylesheets 2023-06-29 16:26:55 +01:00
Jake Stanger
ded50cca6f feat: support for 'ironvar' dynamic variables 2023-06-29 16:26:54 +01:00
Jake Stanger
f5bdc5a027 feat: ipc server and cli 2023-06-29 16:19:19 +01:00
Jake Stanger
44313bfc75 Merge pull request #203 from JakeStanger/dependabot/cargo/notify-6.0.1
build(deps): bump notify from 6.0.0 to 6.0.1
2023-06-26 17:16:05 +01:00
Jake Stanger
9e5f72087f Merge pull request #201 from JakeStanger/dependabot/cargo/indexmap-2.0.0
build(deps): bump indexmap from 1.9.3 to 2.0.0
2023-06-26 17:15:44 +01:00
Jake Stanger
449795b4e9 Merge pull request #200 from JakeStanger/dependabot/cargo/mpris-2.0.1
build(deps): bump mpris from 2.0.0 to 2.0.1
2023-06-26 17:14:31 +01:00
dependabot[bot]
a67bf38faa build(deps): bump notify from 6.0.0 to 6.0.1
Bumps [notify](https://github.com/notify-rs/notify) from 6.0.0 to 6.0.1.
- [Release notes](https://github.com/notify-rs/notify/releases)
- [Changelog](https://github.com/notify-rs/notify/blob/main/CHANGELOG.md)
- [Commits](https://github.com/notify-rs/notify/compare/notify-6.0.0...notify-6.0.1)

---
updated-dependencies:
- dependency-name: notify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-26 15:06:12 +00:00
dependabot[bot]
e539eadd8d build(deps): bump indexmap from 1.9.3 to 2.0.0
Bumps [indexmap](https://github.com/bluss/indexmap) from 1.9.3 to 2.0.0.
- [Changelog](https://github.com/bluss/indexmap/blob/master/RELEASES.md)
- [Commits](https://github.com/bluss/indexmap/compare/1.9.3...2.0.0)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-26 15:05:37 +00:00
dependabot[bot]
592213d8af build(deps): bump mpris from 2.0.0 to 2.0.1
Bumps [mpris](https://github.com/Mange/mpris-rs) from 2.0.0 to 2.0.1.
- [Changelog](https://github.com/Mange/mpris-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Mange/mpris-rs/compare/v2.0.0...v2.0.1)

---
updated-dependencies:
- dependency-name: mpris
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-26 15:05:17 +00:00
Jake Stanger
d121dc3d1e refactor: fix unused var warning 2023-06-22 23:21:02 +01:00
Jake Stanger
0e8c8a1770 chore: bump version to 0.13.0 2023-06-18 23:10:15 +01:00
Jake Stanger
93baf8f568 Merge pull request #197 from JakeStanger/ci/cache
ci: add caching support
2023-06-18 17:51:32 +01:00
Jake Stanger
1ef32059da ci: add caching support 2023-06-18 17:41:10 +01:00
Jake Stanger
5be0750792 Merge pull request #160 from JakeStanger/feat/upower-icon-size
feat(upower): icon size option
2023-06-18 17:01:57 +01:00
JakeStanger
aea8de2552 docs: update CHANGELOG.md for v0.12.1 [skip ci] 2023-06-18 15:44:32 +00:00
Jake Stanger
c3e9654cd3 feat(upower): icon size option
Adds missing `icon_size` config option to upower module.
2023-05-26 19:41:02 +01:00
54 changed files with 1664 additions and 427 deletions

View File

@@ -22,6 +22,9 @@ jobs:
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v2
name: Cache dependencies
- name: Install build deps
run: |
sudo apt-get update

View File

@@ -4,6 +4,41 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v0.12.1] - 2023-06-18
### :boom: BREAKING CHANGES
- due to [`e11177f`](https://github.com/JakeStanger/ironbar/commit/e11177fea3095560057278d71cebca01bed295d6) - add sensible class names for icon labels *(commit by [@JakeStanger](https://github.com/JakeStanger))*:
Where both textual and image icons are supported, CSS classes have changed to better reflect their targets. `.icon` has changed to `.icon-box` and `.icon` now targets the underlying element. `.label` has been changed to `.icon.text-icon`. This affects icons on the **music**, **workspaces**, and **clipboard** modules.
### :bug: Bug Fixes
- [`31a57ae`](https://github.com/JakeStanger/ironbar/commit/31a57ae637fa5918f163c8b191916867395912f3) - scripts don't work while running ironbar under a systemd service *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`f82f897`](https://github.com/JakeStanger/ironbar/commit/f82f897982e87906e2c9156d4115013bc8e99763) - **upower**: popup always empty *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`9012fee`](https://github.com/JakeStanger/ironbar/commit/9012feee4f9b60b2c22a956de732847892331222) - **image**: still blurry on hidpi *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`0e65f93`](https://github.com/JakeStanger/ironbar/commit/0e65f93a230cb5ab010b43962fd2e829945c291b) - excess popup windows *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`87ca399`](https://github.com/JakeStanger/ironbar/commit/87ca399220e5d48eefe2f295d1dba1b9452c4472) - poor error handling for missing images *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`22b630a`](https://github.com/JakeStanger/ironbar/commit/22b630a10b9836531a8b03eb904e6f9fcf839fe6) - broken nerd font icons *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`48d6af0`](https://github.com/JakeStanger/ironbar/commit/48d6af0281f460d3ed3745a2ffb2b61848430ecb) - **music**: showing when no mpris player found *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`b9740cb`](https://github.com/JakeStanger/ironbar/commit/b9740cba8f2fa9dfa18a57345027283610f6487e) - upower icon too large *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`a6b6866`](https://github.com/JakeStanger/ironbar/commit/a6b686624b750863aa1c26ca4f1688dfa8c81a61) - **upower**: icon outside button *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`a5ecb36`](https://github.com/JakeStanger/ironbar/commit/a5ecb363fdb2eb3ab543ad56c55c186414500469) - popups occasionally getting jumbled with multiple bars *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`e11177f`](https://github.com/JakeStanger/ironbar/commit/e11177fea3095560057278d71cebca01bed295d6) - add sensible class names for icon labels *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`ac34c05`](https://github.com/JakeStanger/ironbar/commit/ac34c05d2ecb07fd871ed03ef6ee545dc2e6743d) - **focused**: empty icon rendered when `show_icon = false` *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`de3aa5d`](https://github.com/JakeStanger/ironbar/commit/de3aa5d7b10e0bf6d5ff3a39b009ff53a3316a5e) - **focused**: previous icon does not clear if new icon fails to load *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`de98cf3`](https://github.com/JakeStanger/ironbar/commit/de98cf3daee816a0ff72d1f6ba6bc0e15ec53fca) - **tray**: (maybe?) sometimes bus name is taken *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`103a224`](https://github.com/JakeStanger/ironbar/commit/103a224355e8f700904a2b8fbc87cd7be4f64566) - **launcher**: crash when focusing newly opened window in popup *(commit by [@JakeStanger](https://github.com/JakeStanger))*
### :memo: Documentation Changes
- [`d116a51`](https://github.com/JakeStanger/ironbar/commit/d116a510830be59f4ebaba4fe06f9f4489da7ebc) - update CHANGELOG.md for v0.12.0 [skip ci] *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`327e345`](https://github.com/JakeStanger/ironbar/commit/327e345630a5a89a6f7e464d873c16666d929c0f) - **examples**: fix css button styles *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`13d3923`](https://github.com/JakeStanger/ironbar/commit/13d39235ad032623745baecb6911057ec057ff11) - **examples**: fix casing of steam in launcher favourites *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`cdeafbd`](https://github.com/JakeStanger/ironbar/commit/cdeafbdc7245d37120e3e8338b6f933a39d4e428) - **sys info**: add typical temperature sensors for intel/amd cpus *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`ff315ff`](https://github.com/JakeStanger/ironbar/commit/ff315ff5dbd545d8b72b6aa10087c940cb8a5eee) - **music**: fix incorrect type for `host`/`music_dir` options *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`bd144e8`](https://github.com/JakeStanger/ironbar/commit/bd144e87a8f6668c877d42697ebbedbe5a374c3d) - **readme**: make prettier *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`242b70e`](https://github.com/JakeStanger/ironbar/commit/242b70ed3988b85455b0dbbcb3243b31f89d2ee1) - **contributing**: enforce conventional commits *(commit by [@JakeStanger](https://github.com/JakeStanger))*
- [`96d36c4`](https://github.com/JakeStanger/ironbar/commit/96d36c43d43ba2f9e9d9441ae01c0743cc56f627) - add missing icon/image selectors *(commit by [@JakeStanger](https://github.com/JakeStanger))*
## [v0.12.0] - 2023-05-06
### :boom: BREAKING CHANGES
- due to [`dea6641`](https://github.com/JakeStanger/ironbar/commit/dea66415c2e11e34ba44d016aaa6cfb4ef7b9f9b) - module-level `name` and `class` options *(commit by [@JakeStanger](https://github.com/JakeStanger))*:
@@ -336,4 +371,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[v0.9.0]: https://github.com/JakeStanger/ironbar/compare/v0.8.0...v0.9.0
[v0.10.0]: https://github.com/JakeStanger/ironbar/compare/v0.9.0...v0.10.0
[v0.11.0]: https://github.com/JakeStanger/ironbar/compare/v0.10.0...v0.11.0
[v0.12.0]: https://github.com/JakeStanger/ironbar/compare/v0.11.0...v0.12.0
[v0.12.0]: https://github.com/JakeStanger/ironbar/compare/v0.11.0...v0.12.0
[v0.12.1]: https://github.com/JakeStanger/ironbar/compare/v0.12.0...v0.12.1

164
Cargo.lock generated
View File

@@ -52,6 +52,55 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is-terminal",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
[[package]]
name = "anstyle-parse"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "anstyle-wincon"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
dependencies = [
"anstyle",
"windows-sys 0.48.0",
]
[[package]]
name = "anyhow"
version = "1.0.71"
@@ -395,6 +444,48 @@ dependencies = [
"winapi",
]
[[package]]
name = "clap"
version = "4.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80672091db20273a15cf9fdd4e47ed43b5091ec9841bf4c6145c9dfbbcae09ed"
dependencies = [
"clap_builder",
"clap_derive",
"once_cell",
]
[[package]]
name = "clap_builder"
version = "4.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1458a1df40e1e2afebb7ab60ce55c1fa8f431146205aa5f4887e0b111c27636"
dependencies = [
"anstream",
"anstyle",
"bitflags 1.3.2",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f"
dependencies = [
"heck 0.4.1",
"proc-macro2",
"quote 1.0.28",
"syn 2.0.18",
]
[[package]]
name = "clap_lex"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
[[package]]
name = "color-eyre"
version = "0.6.2"
@@ -422,6 +513,12 @@ dependencies = [
"tracing-error",
]
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "concurrent-queue"
version = "2.2.0"
@@ -515,6 +612,16 @@ dependencies = [
"typenum",
]
[[package]]
name = "ctrlc"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a011bbe2c35ce9c1f143b7af6f94f29a167beb4cd1d29e6740ce836f723120e"
dependencies = [
"nix 0.26.2",
"windows-sys 0.48.0",
]
[[package]]
name = "darling"
version = "0.14.4"
@@ -695,6 +802,12 @@ dependencies = [
"syn 2.0.18",
]
[[package]]
name = "equivalent"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1"
[[package]]
name = "errno"
version = "0.3.1"
@@ -1192,7 +1305,7 @@ dependencies = [
"futures-sink",
"futures-util",
"http",
"indexmap",
"indexmap 1.9.3",
"slab",
"tokio",
"tokio-util",
@@ -1205,6 +1318,12 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hashbrown"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
[[package]]
name = "heck"
version = "0.3.3"
@@ -1397,7 +1516,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown",
"hashbrown 0.12.3",
]
[[package]]
name = "indexmap"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
dependencies = [
"equivalent",
"hashbrown 0.14.0",
]
[[package]]
@@ -1448,12 +1577,14 @@ checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f"
[[package]]
name = "ironbar"
version = "0.12.1"
version = "0.13.0"
dependencies = [
"async_once",
"cfg-if",
"chrono",
"clap",
"color-eyre",
"ctrlc",
"dirs",
"futures-lite",
"futures-util",
@@ -1461,7 +1592,7 @@ dependencies = [
"gtk",
"gtk-layer-shell",
"hyprland",
"indexmap",
"indexmap 2.0.0",
"lazy_static",
"mpd_client",
"mpris",
@@ -1470,6 +1601,7 @@ dependencies = [
"regex",
"reqwest",
"serde",
"serde_json",
"smithay-client-toolkit",
"stray",
"strip-ansi-escapes",
@@ -1489,6 +1621,18 @@ dependencies = [
"zbus",
]
[[package]]
name = "is-terminal"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f"
dependencies = [
"hermit-abi 0.3.1",
"io-lifetimes",
"rustix",
"windows-sys 0.48.0",
]
[[package]]
name = "itoa"
version = "1.0.6"
@@ -1701,9 +1845,9 @@ dependencies = [
[[package]]
name = "mpris"
version = "2.0.0"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e3d377fd27d9d5c7145341cd3affcb83839c24c73e7460488b3ae0a3f9c5166"
checksum = "55cef955a7826b1e00e901a3652e7a895abd221fb4ab61547e7d0e4c235d7feb"
dependencies = [
"dbus",
"derive_is_enum_variant",
@@ -1769,9 +1913,9 @@ dependencies = [
[[package]]
name = "notify"
version = "6.0.0"
version = "6.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d9ba6c734de18ca27c8cef5cd7058aa4ac9f63596131e4c7e41e579319032a2"
checksum = "5738a2795d57ea20abec2d6d76c6081186709c0024187cd5977265eda6598b51"
dependencies = [
"bitflags 1.3.2",
"filetime",
@@ -2456,7 +2600,7 @@ version = "0.9.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9d684e3ec7de3bf5466b32bd75303ac16f0736426e5a4e0d6e489559ce1249c"
dependencies = [
"indexmap",
"indexmap 1.9.3",
"itoa",
"ryu",
"serde",
@@ -2929,7 +3073,7 @@ version = "0.19.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13"
dependencies = [
"indexmap",
"indexmap 1.9.3",
"serde",
"serde_spanned",
"toml_datetime",

View File

@@ -1,12 +1,15 @@
[package]
name = "ironbar"
version = "0.12.1"
version = "0.13.0"
edition = "2021"
license = "MIT"
description = "Customisable GTK Layer Shell wlroots/sway bar"
repository = "https://github.com/jakestanger/ironbar"
[features]
default = [
"cli",
"ipc",
"http",
"config+all",
"clipboard",
@@ -17,10 +20,19 @@ default = [
"upower",
"workspaces+all"
]
http = ["dep:reqwest"]
upower = ["upower_dbus", "zbus", "futures-lite"]
"config+all" = ["config+json", "config+yaml", "config+toml", "config+corn", "config+ron"]
cli = ["dep:clap", "ipc"]
ipc = ["dep:serde_json"]
http = ["dep:reqwest"]
"config+all" = [
"config+json",
"config+yaml",
"config+toml",
"config+corn",
"config+ron",
]
"config+json" = ["universal-config/json"]
"config+yaml" = ["universal-config/yaml"]
"config+toml" = ["universal-config/toml"]
@@ -40,6 +52,8 @@ sys_info = ["sysinfo", "regex"]
tray = ["stray"]
upower = ["upower_dbus", "zbus", "futures-lite"]
workspaces = ["futures-util"]
"workspaces+all" = ["workspaces", "workspaces+sway", "workspaces+hyprland"]
"workspaces+sway" = ["workspaces", "swayipc-async"]
@@ -50,7 +64,15 @@ workspaces = ["futures-util"]
gtk = "0.17.0"
gtk-layer-shell = "0.6.0"
glib = "0.17.10"
tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread", "time", "process", "sync", "io-util", "net"] }
tokio = { version = "1.28.2", features = [
"macros",
"rt-multi-thread",
"time",
"process",
"sync",
"io-util",
"net",
] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing-error = "0.2.0"
@@ -58,20 +80,29 @@ tracing-appender = "0.2.2"
strip-ansi-escapes = "0.1.1"
color-eyre = "0.6.2"
serde = { version = "1.0.164", features = ["derive"] }
indexmap = "1.9.1"
indexmap = "2.0.0"
dirs = "5.0.1"
walkdir = "2.3.2"
notify = { version = "6.0.0", default-features = false }
notify = { version = "6.0.1", default-features = false }
wayland-client = "0.30.2"
wayland-protocols = { version = "0.30.0", features = ["unstable", "client"] }
wayland-protocols-wlr = { version = "0.1.0", features = ["client"] }
smithay-client-toolkit = { version = "0.17.0", default-features = false, features = ["calloop"] }
smithay-client-toolkit = { version = "0.17.0", default-features = false, features = [
"calloop",
] }
universal-config = { version = "0.4.0", default_features = false }
ctrlc = "3.4.0"
lazy_static = "1.4.0"
async_once = "0.2.6"
cfg-if = "1.0.0"
# cli
clap = { version = "4.2.7", optional = true, features = ["derive"] }
# ipc
serde_json = { version = "1.0.96", optional = true }
# http
reqwest = { version = "0.11.18", optional = true }
@@ -83,7 +114,7 @@ chrono = { version = "0.4.26", optional = true }
# music
mpd_client = { version = "1.0.0", optional = true }
mpris = { version = "2.0.0", optional = true }
mpris = { version = "2.0.1", optional = true }
# sys_info
sysinfo = { version = "0.29.2", optional = true }
@@ -102,7 +133,9 @@ hyprland = { version = "=0.3.1", optional = true }
futures-util = { version = "0.3.21", optional = true }
# shared
regex = { version = "1.8.4", default-features = false, features = ["std"], optional = true } # music, sys_info
regex = { version = "1.8.4", default-features = false, features = [
"std",
], optional = true } # music, sys_info
[patch.crates-io]
stray = { git = "https://github.com/jakestanger/stray", branch = "fix/connection-errors" }
stray = { git = "https://github.com/jakestanger/stray", branch = "fix/connection-errors" }

View File

@@ -58,6 +58,8 @@ cargo build --release --no-default-features \
|---------------------|-----------------------------------------------------------------------------------|
| **Core** | |
| http | Enables HTTP features. Currently this includes the ability to load remote images. |
| ipc | Enables the IPC server. |
| cli | Enables the CLI. Will also enable `ipc`. |
| config+all | Enables support for all configuration languages. |
| config+json | Enables configuration support for JSON. |
| config+yaml | Enables configuration support for YAML. |

View File

@@ -267,20 +267,21 @@ Check [here](config) for an example config file for a fully configured bar in ea
The following table lists each of the top-level bar config options:
| Name | Type | Default | Description |
|-------------------|----------------------------------------|----------|-----------------------------------------------------------------------------------------|
| `position` | `top` or `bottom` or `left` or `right` | `bottom` | The bar's position on screen. |
| `anchor_to_edges` | `boolean` | `false` | Whether to anchor the bar to the edges of the screen. Setting to false centres the bar. |
| `height` | `integer` | `42` | The bar's height in pixels. |
| `popup_gap` | `integer` | `5` | The gap between the bar and popup window. |
| `margin.top` | `integer` | `0` | The margin on the top of the bar |
| `margin.bottom` | `integer` | `0` | The margin on the bottom of the bar |
| `margin.left` | `integer` | `0` | The margin on the left of the bar |
| `margin.right` | `integer` | `0` | The margin on the right of the bar |
| `icon_theme` | `string` | `null` | Name of the GTK icon theme to use. Leave blank to use default. |
| `start` | `Module[]` | `[]` | Array of left or top modules. |
| `center` | `Module[]` | `[]` | Array of center modules. |
| `end` | `Module[]` | `[]` | Array of right or bottom modules. |
| Name | Type | Default | Description |
|--------------------|----------------------------------------|-----------|-----------------------------------------------------------------------------------------|
| `position` | `top` or `bottom` or `left` or `right` | `bottom` | The bar's position on screen. |
| `anchor_to_edges` | `boolean` | `false` | Whether to anchor the bar to the edges of the screen. Setting to false centres the bar. |
| `height` | `integer` | `42` | The bar's height in pixels. |
| `popup_gap` | `integer` | `5` | The gap between the bar and popup window. |
| `margin.top` | `integer` | `0` | The margin on the top of the bar |
| `margin.bottom` | `integer` | `0` | The margin on the bottom of the bar |
| `margin.left` | `integer` | `0` | The margin on the left of the bar |
| `margin.right` | `integer` | `0` | The margin on the right of the bar |
| `icon_theme` | `string` | `null` | Name of the GTK icon theme to use. Leave blank to use default. |
| `ironvar_defaults` | `Map<string, string>` | `{}` | Map of [ironvar](ironvars) keys against their default values. |
| `start` | `Module[]` | `[]` | Array of left or top modules. |
| `center` | `Module[]` | `[]` | Array of center modules. |
| `end` | `Module[]` | `[]` | Array of right or bottom modules. |
### 3.2 Module-level options
@@ -306,9 +307,9 @@ For information on the `Script` type, and embedding scripts in strings, see [her
| Name | Type | Default | Description |
|-----------------------|-------------------------------------------------------|---------------|--------------------------------------------------------------------------------------------------------------------|
| `show_if` | `Script [polling]` | `null` | Polls the script to check its exit code. If exit code is zero, the module is shown. For other codes, it is hidden. |
| `show_if` | [Dynamic Boolean](dynamic-values#dynamic-boolean) | `null` | Polls the script to check its exit code. If exit code is zero, the module is shown. For other codes, it is hidden. |
| `transition_type` | `slide_start` or `slide_end` or `crossfade` or `none` | `slide_start` | The transition animation to use when showing/hiding the widget. |
| `transition_duration` | `Integer` | `250` | The length of the transition animation to use when showing/hiding the widget. |
| `transition_duration` | `integer` | `250` | The length of the transition animation to use when showing/hiding the widget. |
#### Appearance

134
docs/Controlling Ironbar.md Normal file
View File

@@ -0,0 +1,134 @@
Ironbar includes a simple IPC server which can be used to control it programmatically at runtime.
It also includes a command line interface, which can be used for interacting with the IPC server.
# CLI
This is shipped as part of the `ironbar` binary. To view commands, you can use `ironbar --help`.
You can also view help per-command, for example using `ironbar set --help`.
Responses are handled by writing their type to stdout, followed by any value starting on the next line.
Error responses are written to stderr in the same format.
Example:
```shell
$ ironbar set subject world
ok
$ ironbar get subject
ok
world
```
# IPC
The server listens on a Unix socket.
This can usually be found at `/run/user/$UID/ironbar-ipc.sock`.
Commands and responses are sent as JSON objects, denoted by their `type` key.
The message buffer is currently limited to `1024` bytes.
Particularly large messages will be truncated or cause an error.
## Commands
### `ping`
Sends a ping request to the IPC.
Responds with `ok`.
```json
{
"type": "ping"
}
```
### `inspect`
Opens the GTK inspector window.
Responds with `ok`.
```json
{
"type": "inspect"
}
```
### `get`
Gets an [ironvar](ironvars) value.
Responds with `ok_value` if the value exists, otherwise `error`.
```json
{
"type": "get",
"key": "foo"
}
```
### `set`
Sets an [ironvar](ironvars) value.
Responds with `ok`.
```json
{
"type": "set",
"key": "foo",
"value": "bar"
}
```
### `load_css`
Loads an additional CSS stylesheet, with hot-reloading enabled.
Responds with `ok` if the stylesheet exists, otherwise `error`.
```json
{
"type": "load_css",
"path": "/path/to/style.css"
}
```
## Responses
### `ok`
The operation completed successfully, with no response data.
```json
{
"type": "ok"
}
```
### `ok_value`
The operation completed successfully, with response data.
```json
{
"type": "ok_value",
"value": "lorem ipsum"
}
```
### `error`
The operation failed.
Message is optional.
```json
{
"type": "error",
"message": "lorem ipsum"
}
```

39
docs/Dynamic values.md Normal file
View File

@@ -0,0 +1,39 @@
In some configuration locations, Ironbar supports dynamic values,
meaning you can inject content into the bar from an external source.
Currently two dynamic content sources are supported - scripts and ironvars.
## Dynamic String
Dynamic strings can contain any mixture of static string elements, scripts and variables.
Scripts should be placed inside `{{double braces}}`. Both polling and watching scripts are supported.
Variables use the standard `#name` syntax. Variables cannot be placed inside scripts.
To use a literal hash, use `##`. This is only necessary outside of scripts.
Example:
```toml
label = "{{cat greeting.txt}}, #subject"
```
## Dynamic Boolean
Dynamic booleans can use a single source of either a script or variable to control a true/false value.
For scripts, you can just write these directly with no notation.
Only polling scripts are supported.
The script exit code is used, where `0` is `true` and any other code is `false.
For variables, use the standard `#name` notation.
An empty string, `0` and `false` are treated as false.
Any other value is true.
Example:
```toml
show_if = "exit 0" # script
show_if = "#show_module" # variable
```

9
docs/Ironvars.md Normal file
View File

@@ -0,0 +1,9 @@
Ironvars are runtime variables that can be referenced in several places in your config,
then set using the IPC server (such as via the CLI) using the `set` command.
Any UTF-8 string *without whitespace* is a valid key.
Any UTF-8 string is a valid value.
Reference values using `#my_variable`. These update as soon as the value changes.
You can set defaults using the `ironvar_defaults` key in your top-level config.

View File

@@ -2,10 +2,16 @@
- [Compiling from source](compiling)
- [Configuration guide](configuration-guide)
- [Scripts](scripts)
- [Images](images)
- [Styling guide](styling-guide)
# Dynamic content
- [Controlling Ironbar](controlling-ironbar)
- [Dynamic values](dynamic-values)
- [Scripts](scripts)
- [Ironvars](ironvars)
# Examples
- [Config](config)
@@ -28,4 +34,4 @@
- [Sys_Info](sys-info)
- [Tray](tray)
- [Upower](upower)
- [Workspaces](workspaces)
- [Workspaces](workspaces)

View File

@@ -9,17 +9,15 @@ Supports plain text and images.
> Type: `clipboard`
| Name | Type | Default | Description |
|-----------------------|---------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `icon` | `string/image` | `󰨸` | Icon to show on the widget button. |
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
| `max_items` | `integer` | `10` | Maximum number of items to show in the popup. |
| `truncate` | `start` or `middle` or `end` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. |
| `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
See [here](images) for information on images.
| Name | Type | Default | Description |
|-----------------------|---------------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `icon` | `string` or [image](images) | `󰨸` | Icon to show on the widget button. |
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
| `max_items` | `integer` | `10` | Maximum number of items to show in the popup. |
| `truncate` | `'start'` or `'middle'` or `'end'` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. |
| `truncate.mode` | `'start'` or `'middle'` or `'end'` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
<details>
<summary>JSON</summary>

View File

@@ -1,6 +1,9 @@
Allows you to compose custom modules consisting of multiple widgets, including popups.
Labels can display dynamic content from scripts, and buttons can interact with the bar or execute commands on click.
If you only intend to run a single script, prefer the [script](script) module,
or [label](label) if you only need a single text label.
![Custom module with a button on the bar, and the popup open. The popup contains a header, shutdown button and restart button.](https://f.jstanger.dev/github/ironbar/custom-power-menu.png?raw)
## Configuration
@@ -18,11 +21,11 @@ You can think of these like HTML elements and their attributes.
Every widget has the following options available; `type` is mandatory.
You can also add common [module-level options](https://github.com/JakeStanger/ironbar/wiki/configuration-guide#32-module-level-options) on a widget.
| Name | Type | Default | Description |
|---------|-------------------------------------------------------------------|---------|-------------------------------|
| `type` | `box` or `label` or `button` or `image` or `slider` or `progress` | `null` | Type of GTK widget to create. |
| `name` | `string` | `null` | Widget name. |
| `class` | `string` | `null` | Widget class name. |
| Name | Type | Default | Description |
|---------|-------------------------------------------------------------------------------|---------|-------------------------------|
| `type` | `'box'` or `'label'` or `'button'` or `'image'` or `'slider'` or `'progress'` | `null` | Type of GTK widget to create. |
| `name` | `string` | `null` | Widget name. |
| `class` | `string` | `null` | Widget class name. |
#### Box
@@ -30,20 +33,20 @@ A container to place nested widgets inside.
> Type: `box`
| Name | Type | Default | Description |
|---------------|----------------------------------------------------|--------------|-------------------------------------------------------------------|
| `orientation` | `horizontal` or `vertical` (shorthand: `h` or `v`) | `horizontal` | Whether child widgets should be horizontally or vertically added. |
| `widgets` | `Widget[]` | `[]` | List of widgets to add to this box. |
| Name | Type | Default | Description |
|---------------|------------------------------------------------------------|----------------|-------------------------------------------------------------------|
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Whether child widgets should be horizontally or vertically added. |
| `widgets` | `Widget[]` | `[]` | List of widgets to add to this box. |
#### Label
A text label. Pango markup and embedded scripts are supported.
A text label. Pango markup is supported.
> Type `label`
| Name | Type | Default | Description |
|---------|----------|--------------|---------------------------------------------------------------------|
| `label` | `string` | `horizontal` | Widget text label. Pango markup and embedded scripts are supported. |
| Name | Type | Default | Description |
|---------|-------------------------------------------------|---------|---------------------------------------------------------------------|
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. |
#### Button
@@ -51,10 +54,10 @@ A clickable button, which can run a command when clicked.
> Type `button`
| Name | Type | Default | Description |
|------------|--------------------|--------------|---------------------------------------------------------------------|
| `label` | `string` | `horizontal` | Widget text label. Pango markup and embedded scripts are supported. |
| `on_click` | `string [command]` | `null` | Command to execute. More on this [below](#commands). |
| Name | Type | Default | Description |
|------------|-------------------------------------------------|---------|---------------------------------------------------------------------|
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. |
| `on_click` | `string [command]` | `null` | Command to execute. More on this [below](#commands). |
#### Image
@@ -62,10 +65,10 @@ An image or icon from disk or http.
> Type `image`
| Name | Type | Default | Description |
|--------|-----------|---------|---------------------------------------------------------------------------------------------|
| `src` | `image` | `null` | Image source. See [here](images) for information on images. Embedded scripts are supported. |
| `size` | `integer` | `null` | Width/height of the image. Aspect ratio is preserved. |
| Name | Type | Default | Description |
|--------|---------------------------------------------------------------------|---------|-------------------------------------------------------|
| `src` | [image](images) via [Dynamic String](dynamic-values#dynamic-string) | `null` | Image source. |
| `size` | `integer` | `null` | Width/height of the image. Aspect ratio is preserved. |
#### Slider
@@ -76,18 +79,16 @@ A draggable slider.
Note that `on_change` will provide the **floating point** value as an argument.
If your input program requires an integer, you will need to round it.
| Name | Type | Default | Description |
|---------------|----------------------------------------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------|
| `src` | `image` | `null` | Image source. See [here](images) for information on images. |
| `size` | `integer` | `null` | Width/height of the image. Aspect ratio is preserved. |
| `orientation` | `horizontal` or `vertical` (shorthand: `h` or `v`) | `horizontal` | Orientation of the slider. |
| `value` | `Script` | `null` | Script to run to get the slider value. Output must be a valid number. |
| `on_change` | `string [command]` | `null` | Command to execute when the slider changes. More on this [below](#commands). |
| `min` | `float` | `0` | Minimum slider value. |
| `max` | `float` | `100` | Maximum slider value. |
| `step` | `float` | - | The increment to change when scrolling with the mouse wheel. If left blank, will use the default determined by the environment. |
| `length` | `integer` | `null` | Slider length. GTK will automatically size if left unset. |
| `show_label` | `boolean` | `true` | Whether to show the value label above the slider. |
| Name | Type | Default | Description |
|---------------|------------------------------------------------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------|
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the slider. |
| `value` | `Script` | `null` | Script to run to get the slider value. Output must be a valid number. |
| `on_change` | `string [command]` | `null` | Command to execute when the slider changes. More on this [below](#commands). |
| `min` | `float` | `0` | Minimum slider value. |
| `max` | `float` | `100` | Maximum slider value. |
| `step` | `float` | - | The increment to change when scrolling with the mouse wheel. If left blank, will use the default determined by the environment. |
| `length` | `integer` | `null` | Slider length. GTK will automatically size if left unset. |
| `show_label` | `boolean` | `true` | Whether to show the value label above the slider. |
The example slider widget below shows a volume control for MPC,
which updates the server when changed, and polls the server for volume changes to keep the slider in sync.
@@ -115,14 +116,12 @@ A progress bar.
Note that `value` expects a numeric value **between 0-`max`** as output.
| Name | Type | Default | Description |
|---------------|----------------------------------------------------|--------------|---------------------------------------------------------------------------------|
| `src` | `image` | `null` | Image source. See [here](images) for information on images. |
| `size` | `integer` | `null` | Width/height of the image. Aspect ratio is preserved. |
| `orientation` | `horizontal` or `vertical` (shorthand: `h` or `v`) | `horizontal` | Orientation of the slider. |
| `value` | `Script` | `null` | Script to run to get the progress bar value. Output must be a valid percentage. |
| `max` | `float` | `100` | Maximum progress bar value. |
| `length` | `integer` | `null` | Slider length. GTK will automatically size if left unset. |
| Name | Type | Default | Description |
|---------------|------------------------------------------------------------|--------------|---------------------------------------------------------------------------------|
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `horizontal` | Orientation of the progress bar. |
| `value` | `Script` | `null` | Script to run to get the progress bar value. Output must be a valid percentage. |
| `max` | `float` | `100` | Maximum progress bar value. |
| `length` | `integer` | `null` | Slider length. GTK will automatically size if left unset. |
The example below shows progress for the current playing song in MPD,
and displays the elapsed/length timestamps as a label above:

View File

@@ -7,15 +7,15 @@ Displays the title and/or icon of the currently focused window.
> Type: `focused`
| Name | Type | Default | Description |
|-----------------------|---------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `show_icon` | `boolean` | `true` | Whether to show the app's icon |
| `show_title` | `boolean` | `true` | Whether to show the app's title |
| `icon_size` | `integer` | `32` | Size of icon in pixels |
| `truncate` | `start` or `middle` or `end` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. |
| `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
| Name | Type | Default | Description |
|-----------------------|---------------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `show_icon` | `boolean` | `true` | Whether to show the app's icon. |
| `show_title` | `boolean` | `true` | Whether to show the app's title. |
| `icon_size` | `integer` | `32` | Size of icon in pixels. |
| `truncate` | `'start'` or `'middle'` or `'end'` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. |
| `truncate.mode` | `'start'` or `'middle'` or `'end'` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
<details>
<summary>JSON</summary>

View File

@@ -1,12 +1,15 @@
Displays custom text, with the ability to embed [scripts](https://github.com/JakeStanger/ironbar/wiki/scripts#embedding).
Displays custom text, with markup support.
If you only intend to run a single script, prefer the [script](script) module.
For more advanced use-cases, use [custom](custom).
## Configuration
> Type: `label`
| Name | Type | Default | Description |
|---------|----------|---------|-----------------------------------------|
| `label` | `string` | `null` | Text, optionally with embedded scripts. |
| Name | Type | Default | Description |
|---------|-------------------------------------------------|---------|------------------------|
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Text to show on label. |
<details>
<summary>JSON</summary>

View File

@@ -11,27 +11,27 @@ in MPRIS mode, the widget will listen to all players and automatically detect/di
> Type: `music`
| | Type | Default | Description |
|-----------------------|---------------------------------------|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `player_type` | `mpris` or `mpd` | `mpris` | Whether to connect to MPRIS players or an MPD server. |
| `format` | `string` | `{title} / {artist}` | Format string for the widget. More info below. |
| `truncate` | `start` or `middle` or `end` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. |
| `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
| `icons.play` | `string/image` | `` | Icon to show when playing. |
| `icons.pause` | `string/image` | `` | Icon to show when paused. |
| `icons.prev` | `string/image` | `玲` | Icon to show on previous button. |
| `icons.next` | `string/image` | `怜` | Icon to show on next button. |
| `icons.volume` | `string/image` | `墳` | Icon to show under popup volume slider. |
| `icons.track` | `string/image` | `` | Icon to show next to track title. |
| `icons.album` | `string/image` | `` | Icon to show next to album name. |
| `icons.artist` | `string/image` | `ﴁ` | Icon to show next to artist name. |
| `show_status_icon` | `boolean` | `true` | Whether to show the play/pause icon on the widget. |
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
| `cover_image_size` | `integer` | `128` | Size to render album art image at inside popup. |
| `host` | `string` | `localhost:6600` | [MPD Only] TCP or Unix socket for the MPD server. |
| `music_dir` | `string` | `$HOME/Music` | [MPD Only] Path to MPD server's music directory on disc. Required for album art. |
| | Type | Default | Description |
|-----------------------|---------------------------------------------|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `player_type` | `'mpris'` or `'mpd'` | `mpris` | Whether to connect to MPRIS players or an MPD server. |
| `format` | `string` | `{title} / {artist}` | Format string for the widget. More info below. |
| `truncate` | `'start'` or `'middle'` or `'end'` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. |
| `truncate.mode` | `'start'` or `'middle'` or `'end'` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
| `icons.play` | `string` or [image](images) | `` | Icon to show when playing. |
| `icons.pause` | `string` or [image](images) | `` | Icon to show when paused. |
| `icons.prev` | `string` or [image](images) | `玲` | Icon to show on previous button. |
| `icons.next` | `string` or [image](images) | `怜` | Icon to show on next button. |
| `icons.volume` | `string` or [image](images) | `墳` | Icon to show under popup volume slider. |
| `icons.track` | `string` or [image](images) | `` | Icon to show next to track title. |
| `icons.album` | `string` or [image](images) | `` | Icon to show next to album name. |
| `icons.artist` | `string` or [image](images) | `ﴁ` | Icon to show next to artist name. |
| `show_status_icon` | `boolean` | `true` | Whether to show the play/pause icon on the widget. |
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
| `cover_image_size` | `integer` | `128` | Size to render album art image at inside popup. |
| `host` | `string` | `localhost:6600` | [MPD Only] TCP or Unix socket for the MPD server. |
| `music_dir` | `string` | `$HOME/Music` | [MPD Only] Path to MPD server's music directory on disc. Required for album art. |
See [here](images) for information on images.

View File

@@ -1,6 +1,9 @@
Executes a script and shows the result of `stdout` on a label.
Pango markup is supported.
If you want to be able to embed multiple scripts and/or variables, prefer the [label](label) module.
For more advanced use-cases, use [custom](custom).
## Configuration
> Type: `script`

View File

@@ -9,9 +9,10 @@ Displays system power information such as the battery percentage, and estimated
> Type: `upower`
| Name | Type | Default | Description |
|----------|----------|-----------------|---------------------------------------------------|
| `format` | `string` | `{percentage}%` | Format string to use for the widget button label. |
| Name | Type | Default | Description |
|-------------|-----------|-----------------|---------------------------------------------------|
| `format` | `string` | `{percentage}%` | Format string to use for the widget button label. |
| `icon_size` | `integer` | `24` | Size to render icon at. |
<details>
<summary>JSON</summary>

View File

@@ -8,12 +8,12 @@ Shows all current workspaces. Clicking a workspace changes focus to it.
> Type: `workspaces`
| Name | Type | Default | Description |
|----------------|-----------------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `name_map` | `Map<string, string/image>` | `{}` | A map of actual workspace names to their display labels/images. Workspaces use their actual name if not present in the map. See [here](images) for information on images. |
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
| `all_monitors` | `boolean` | `false` | Whether to display workspaces from all monitors. When `false`, only shows workspaces on the current monitor. |
| `sort` | `added` or `alphanumeric` | `alphanumeric` | The method used for sorting workspaces. `added` always appends to the end, `alphanumeric` sorts by number/name. |
| Name | Type | Default | Description |
|----------------|--------------------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `name_map` | `Map<string, string or image>` | `{}` | A map of actual workspace names to their display labels/images. Workspaces use their actual name if not present in the map. See [here](images) for information on images. |
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
| `all_monitors` | `boolean` | `false` | Whether to display workspaces from all monitors. When `false`, only shows workspaces on the current monitor. |
| `sort` | `'added'` or `'alphanumeric'` | `alphanumeric` | The method used for sorting workspaces. `added` always appends to the end, `alphanumeric` sorts by number/name. |
<details>
<summary>JSON</summary>

View File

@@ -207,7 +207,7 @@ fn add_modules(
}};
}
for config in modules.into_iter() {
for config in modules {
let id = get_unique_usize();
match config {
#[cfg(feature = "clipboard")]

View File

@@ -2,7 +2,7 @@ use crate::send;
use tokio::spawn;
use tokio::sync::mpsc;
/// MPSC async -> sync channel.
/// MPSC async -> GTK sync channel.
/// The sender uses `tokio::sync::mpsc`
/// while the receiver uses `glib::MainContext::channel`.
///

19
src/cli/mod.rs Normal file
View File

@@ -0,0 +1,19 @@
use crate::ipc::commands::Command;
use crate::ipc::responses::Response;
use clap::Parser;
use serde::{Deserialize, Serialize};
#[derive(Parser, Debug, Serialize, Deserialize)]
#[command(version)]
pub struct Args {
#[command(subcommand)]
pub command: Option<Command>,
}
pub fn handle_response(response: Response) {
match response {
Response::Ok => println!("ok"),
Response::OkValue { value } => println!("ok\n{value}"),
Response::Err { message } => eprintln!("error\n{}", message.unwrap_or_default()),
}
}

View File

@@ -38,7 +38,8 @@ impl ClipboardClient {
spawn(async move {
let (mut rx, item) = {
let wl = wayland::get_client().await;
let wl = wayland::get_client();
let wl = lock!(wl);
wl.subscribe_clipboard()
};
@@ -111,7 +112,7 @@ impl ClipboardClient {
rx
}
pub async fn copy(&self, id: usize) {
pub fn copy(&self, id: usize) {
debug!("Copying item with id {id}");
let item = {
@@ -120,7 +121,8 @@ impl ClipboardClient {
};
if let Some(item) = item {
let wl = wayland::get_client().await;
let wl = wayland::get_client();
let wl = lock!(wl);
wl.copy_to_clipboard(item);
}

View File

@@ -31,7 +31,7 @@ impl TrayEventReceiver {
let (b_tx, b_rx) = broadcast::channel(16);
let tray = StatusNotifierWatcher::new(rx).await?;
let mut host = tray.create_notifier_host(&id).await?;
let mut host = Box::pin(tray.create_notifier_host(&id)).await?;
let tray = Arc::new(Mutex::new(BTreeMap::new()));
@@ -106,7 +106,7 @@ lazy_static! {
let value = loop {
retries += 1;
let tray = TrayEventReceiver::new().await;
let tray = Box::pin(TrayEventReceiver::new()).await;
match tray {
Ok(tray) => break Some(tray),

View File

@@ -6,7 +6,7 @@ use zbus::fdo::PropertiesProxy;
lazy_static! {
static ref DISPLAY_PROXY: AsyncOnce<Arc<PropertiesProxy<'static>>> = AsyncOnce::new(async {
let dbus = zbus::Connection::system()
let dbus = Box::pin(zbus::Connection::system())
.await
.expect("failed to create connection to system bus");

View File

@@ -71,7 +71,7 @@ pub struct WaylandClient {
}
impl WaylandClient {
pub(super) async fn new() -> Self {
pub(super) fn new() -> Self {
let (toplevel_tx, toplevel_rx) = broadcast::channel(32);
let (toplevel_init_tx, toplevel_init_rx) = mpsc::channel();

View File

@@ -1,6 +1,6 @@
/// It is necessary to store macros in a separate file due to a compilation error.
/// I believe this stems from the feature flags.
/// Related issue: https://github.com/rust-lang/rust/issues/81066
/// Related issue: <https://github.com/rust-lang/rust/issues/81066>
// --- Data Control Device --- \\

View File

@@ -7,7 +7,6 @@ mod wlr_foreign_toplevel;
use self::wlr_foreign_toplevel::manager::ToplevelManagerState;
use crate::{delegate_foreign_toplevel_handle, delegate_foreign_toplevel_manager};
use async_once::AsyncOnce;
use cfg_if::cfg_if;
use lazy_static::lazy_static;
use smithay_client_toolkit::output::OutputState;
@@ -18,6 +17,7 @@ use smithay_client_toolkit::{
delegate_output, delegate_registry, delegate_seat, registry_handlers,
};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use tokio::sync::broadcast;
use wayland_client::protocol::wl_seat::WlSeat;
@@ -33,7 +33,6 @@ cfg_if! {
use self::wlr_data_control::manager::DataControlDeviceManagerState;
use self::wlr_data_control::source::CopyPasteSource;
use self::wlr_data_control::SelectionOfferItem;
use std::sync::{Arc, Mutex};
pub use wlr_data_control::{ClipboardItem, ClipboardValue};
@@ -106,10 +105,9 @@ impl ProvidesRegistryState for Environment {
}
lazy_static! {
static ref CLIENT: AsyncOnce<WaylandClient> =
AsyncOnce::new(async { WaylandClient::new().await });
static ref CLIENT: Arc<Mutex<WaylandClient>> = Arc::new(Mutex::new(WaylandClient::new()));
}
pub async fn get_client() -> &'static WaylandClient {
CLIENT.get().await
pub fn get_client() -> Arc<Mutex<WaylandClient>> {
CLIENT.clone()
}

View File

@@ -291,14 +291,14 @@ impl DataControlSourceHandler for Environment {
let mut events = (0..16).map(|_| EpollEvent::empty()).collect::<Vec<_>>();
let mut epoll_event = EpollEvent::new(EpollFlags::EPOLLOUT, 0);
let epoll_fd = epoll_create().unwrap();
let epoll_fd = epoll_create().expect("to get valid file descriptor");
epoll_ctl(
epoll_fd,
EpollOp::EpollCtlAdd,
fd.as_raw_fd(),
&mut epoll_event,
)
.unwrap();
.expect("to send valid epoll operation");
while !bytes.is_empty() {
let chunk = &bytes[..min(pipe_size as usize, bytes.len())];

View File

@@ -151,9 +151,8 @@ where
lock!(data.inner).current_info = Some(pending_info);
}
if !lock!(data.inner).initial_done {
lock!(data.inner).initial_done = true;
state.new_handle(
if lock!(data.inner).initial_done {
state.update_handle(
conn,
qh,
ToplevelHandle {
@@ -161,7 +160,8 @@ where
},
);
} else {
state.update_handle(
lock!(data.inner).initial_done = true;
state.new_handle(
conn,
qh,
ToplevelHandle {

View File

@@ -1,11 +1,9 @@
use crate::dynamic_string::DynamicString;
use crate::dynamic_value::{dynamic_string, DynamicBool};
use crate::script::{Script, ScriptInput};
use crate::send;
use gtk::gdk::ScrollDirection;
use gtk::prelude::*;
use gtk::{EventBox, Orientation, Revealer, RevealerTransitionType};
use serde::Deserialize;
use tokio::spawn;
use tracing::trace;
/// Common configuration options
@@ -15,7 +13,7 @@ pub struct CommonConfig {
pub class: Option<String>,
pub name: Option<String>,
pub show_if: Option<ScriptInput>,
pub show_if: Option<DynamicBool>,
pub transition_type: Option<TransitionType>,
pub transition_duration: Option<u32>,
@@ -114,7 +112,7 @@ impl CommonConfig {
if let Some(tooltip) = self.tooltip {
let container = container.clone();
DynamicString::new(&tooltip, move |string| {
dynamic_string(&tooltip, move |string| {
container.set_tooltip_text(Some(&string));
Continue(true)
});
@@ -127,23 +125,13 @@ impl CommonConfig {
container.show_all();
},
|show_if| {
let script = Script::new_polling(show_if);
let container = container.clone();
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
spawn(async move {
script
.run(None, |_, success| {
send!(tx, success);
})
.await;
});
{
let revealer = revealer.clone();
let container = container.clone();
rx.attach(None, move |success| {
show_if.subscribe(move |success| {
if success {
container.show_all();
}

View File

@@ -100,6 +100,8 @@ pub struct Config {
/// GTK icon theme to use.
pub icon_theme: Option<String>,
pub ironvar_defaults: Option<HashMap<Box<str>, String>>,
pub start: Option<Vec<ModuleConfig>>,
pub center: Option<Vec<ModuleConfig>>,
pub end: Option<Vec<ModuleConfig>>,

View File

@@ -1,16 +1,35 @@
use std::collections::HashMap;
use lazy_static::lazy_static;
use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::io;
use std::io::BufRead;
use std::path::PathBuf;
use walkdir::WalkDir;
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use tracing::warn;
use walkdir::{DirEntry, WalkDir};
/// Gets directories that should contain `.desktop` files
use crate::lock;
type DesktopFile = HashMap<String, Vec<String>>;
lazy_static! {
static ref DESKTOP_FILES: Mutex<HashMap<PathBuf, DesktopFile>> =
Mutex::new(HashMap::new());
/// These are the keys that in the cache
static ref DESKTOP_FILES_LOOK_OUT_KEYS: HashSet<&'static str> =
HashSet::from(["Name", "StartupWMClass", "Exec", "Icon"]);
}
/// Finds directories that should contain `.desktop` files
/// and exist on the filesystem.
fn find_application_dirs() -> Vec<PathBuf> {
let mut dirs = vec![PathBuf::from("/usr/share/applications")];
let user_dir = dirs::data_local_dir();
let mut dirs = vec![
PathBuf::from("/usr/share/applications"), // system installed apps
PathBuf::from("/var/lib/flatpak/exports/share/applications"), // flatpak apps
];
let user_dir = dirs::data_local_dir(); // user installed apps
if let Some(mut user_dir) = user_dir {
user_dir.push("applications");
dirs.push(user_dir);
@@ -19,55 +38,126 @@ fn find_application_dirs() -> Vec<PathBuf> {
dirs.into_iter().filter(|dir| dir.exists()).collect()
}
/// Attempts to locate a `.desktop` file for an app id
/// (or app class).
///
/// A simple case-insensitive check is performed on filename == `app_id`.
pub fn find_desktop_file(app_id: &str) -> Option<PathBuf> {
/// Finds all the desktop files
fn find_desktop_files() -> Vec<PathBuf> {
let dirs = find_application_dirs();
for dir in dirs {
let mut walker = WalkDir::new(dir).max_depth(5).into_iter();
let entry = walker.find(|entry| {
entry.as_ref().map_or(false, |entry| {
let file_name = entry.file_name().to_string_lossy().to_lowercase();
let test_name = format!("{}.desktop", app_id.to_lowercase());
file_name == test_name
})
});
if let Some(Ok(entry)) = entry {
let path = entry.path().to_owned();
return Some(path);
}
}
None
dirs.into_iter()
.flat_map(|dir| {
WalkDir::new(dir)
.max_depth(5)
.into_iter()
.filter_map(Result::ok)
.map(DirEntry::into_path)
.filter(|file| file.is_file() && file.extension().unwrap_or_default() == "desktop")
})
.collect()
}
/// Parses a desktop file into a flat hashmap of keys/values.
fn parse_desktop_file(path: PathBuf) -> io::Result<HashMap<String, String>> {
let file = File::open(path)?;
let lines = io::BufReader::new(file).lines();
/// Attempts to locate a `.desktop` file for an app id
pub fn find_desktop_file(app_id: &str) -> Option<PathBuf> {
// this is necessary to invalidate the cache
let files = find_desktop_files();
let mut map = HashMap::new();
for line in lines.flatten() {
if let Some((key, value)) = line.split_once('=') {
map.insert(key.to_string(), value.to_string());
}
if let Some(path) = find_desktop_file_by_filename(app_id, &files) {
return Some(path);
}
Ok(map)
find_desktop_file_by_filedata(app_id, &files)
}
/// Finds the correct desktop file using a simple condition check
fn find_desktop_file_by_filename(app_id: &str, files: &[PathBuf]) -> Option<PathBuf> {
let app_id = app_id.to_lowercase();
files
.iter()
.find(|file| {
let file_name: String = file
.file_name()
.expect("file name doesn't end with ...")
.to_string_lossy()
.to_lowercase();
file_name.contains(&app_id)
|| app_id
.split(&['-', ' ', ':', '@', '.', '_'][..])
.any(|part| file_name.contains(part)) // this will attempt to find flatpak apps that are like this
// `com.company.app` or `com.app.something`
})
.map(ToOwned::to_owned)
}
/// Finds the correct desktop file using the keys in `DESKTOP_FILES_LOOK_OUT_KEYS`
fn find_desktop_file_by_filedata(app_id: &str, files: &[PathBuf]) -> Option<PathBuf> {
let app_id = &app_id.to_lowercase();
let mut desktop_files_cache = lock!(DESKTOP_FILES);
files
.iter()
.filter_map(|file| {
let Some(parsed_desktop_file) = parse_desktop_file(file) else { return None };
desktop_files_cache.insert(file.clone(), parsed_desktop_file.clone());
Some((file.clone(), parsed_desktop_file))
})
.find(|(_, desktop_file)| {
desktop_file
.values()
.flatten()
.any(|value| value.to_lowercase().contains(app_id))
})
.map(|(path, _)| path)
}
/// Parses a desktop file into a hashmap of keys/vector(values).
fn parse_desktop_file(path: &Path) -> Option<DesktopFile> {
let Ok(file) = File::open(path) else {
warn!("Couldn't Open File: {}", path.display());
return None;
};
let lines = io::BufReader::new(file).lines();
let mut desktop_file: DesktopFile = DesktopFile::new();
let _ = lines.flatten().map(|line| {
line.split_once('=')
.iter()
.filter_map(|(key, value)| {
let key = key.trim();
let value = value.trim();
if DESKTOP_FILES_LOOK_OUT_KEYS.contains(key) {
Some((key, value))
} else {
None
}
})
.for_each(|(key, value)| {
desktop_file
.entry(key.to_string())
.or_insert_with(Vec::new)
.push(value.to_string());
});
});
Some(desktop_file)
}
/// Attempts to get the icon name from the app's `.desktop` file.
pub fn get_desktop_icon_name(app_id: &str) -> Option<String> {
find_desktop_file(app_id).and_then(|file| {
let map = parse_desktop_file(file);
map.map_or(None, |map| {
map.get("Icon").map(std::string::ToString::to_string)
})
})
let Some(path) = find_desktop_file(app_id) else { return None };
let mut desktop_files_cache = lock!(DESKTOP_FILES);
let desktop_file = match desktop_files_cache.get(&path) {
Some(desktop_file) => desktop_file,
_ => desktop_files_cache
.entry(path.clone())
.or_insert_with(|| parse_desktop_file(&path).expect("desktop_file")),
};
let mut icons = desktop_file.get("Icon").into_iter().flatten();
icons.next().map(std::string::ToString::to_string)
}

View File

@@ -1,160 +0,0 @@
use crate::script::{OutputStream, Script};
use crate::{lock, send};
use gtk::prelude::*;
use std::sync::{Arc, Mutex};
use tokio::spawn;
/// A segment of a dynamic string,
/// containing either a static string
/// or a script.
#[derive(Debug)]
enum DynamicStringSegment {
Static(String),
Dynamic(Script),
}
/// A string with embedded scripts for dynamic content.
pub struct DynamicString;
impl DynamicString {
/// Creates a new dynamic string, based off the input template.
/// Runs `f` with the compiled string each time one of the scripts updates.
///
/// # Example
///
/// ```rs
/// DynamicString::new(&text, move |string| {
/// label.set_markup(&string);
/// Continue(true)
/// });
/// ```
pub fn new<F>(input: &str, f: F) -> Self
where
F: FnMut(String) -> Continue + 'static,
{
let segments = Self::parse_input(input);
let label_parts = Arc::new(Mutex::new(Vec::new()));
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
for (i, segment) in segments.into_iter().enumerate() {
match segment {
DynamicStringSegment::Static(str) => {
lock!(label_parts).push(str);
}
DynamicStringSegment::Dynamic(script) => {
let tx = tx.clone();
let label_parts = label_parts.clone();
// insert blank value to preserve segment order
lock!(label_parts).push(String::new());
spawn(async move {
script
.run(None, |out, _| {
if let OutputStream::Stdout(out) = out {
let mut label_parts = lock!(label_parts);
let _: String = std::mem::replace(&mut label_parts[i], out);
let string = label_parts.join("");
send!(tx, string);
}
})
.await;
});
}
}
}
// initialize
{
let label_parts = lock!(label_parts).join("");
send!(tx, label_parts);
}
rx.attach(None, f);
Self
}
/// Parses the input string into static and dynamic segments
fn parse_input(input: &str) -> Vec<DynamicStringSegment> {
if !input.contains("{{") {
return vec![DynamicStringSegment::Static(input.to_string())];
}
let mut segments = vec![];
let mut chars = input.chars().collect::<Vec<_>>();
while !chars.is_empty() {
let char_pair = if chars.len() > 1 {
Some(&chars[..=1])
} else {
None
};
let (token, skip) = if let Some(['{', '{']) = char_pair {
const SKIP_BRACKETS: usize = 4; // two braces either side
let str = chars
.windows(2)
.skip(2)
.take_while(|win| win != &['}', '}'])
.map(|w| w[0])
.collect::<String>();
let len = str.len();
(
DynamicStringSegment::Dynamic(Script::from(str.as_str())),
len + SKIP_BRACKETS,
)
} else {
let mut str = chars
.windows(2)
.take_while(|win| win != &['{', '{'])
.map(|w| w[0])
.collect::<String>();
// if segment is at end of string, last char gets missed above due to uneven window.
if chars.len() == str.len() + 1 {
let remaining_char = *chars.get(str.len()).expect("Failed to find last char");
str.push(remaining_char);
}
let len = str.len();
(DynamicStringSegment::Static(str), len)
};
// quick runtime check to make sure the parser is working as expected
assert_ne!(skip, 0);
segments.push(token);
chars.drain(..skip);
}
segments
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test() {
// TODO: see if we can run gtk tests in ci
if gtk::init().is_ok() {
let label = gtk::Label::new(None);
DynamicString::new(
"Uptime: {{1000:uptime -p | cut -d ' ' -f2-}}",
move |string| {
label.set_label(&string);
Continue(true)
},
);
}
}
}

View File

@@ -0,0 +1,78 @@
#[cfg(feature = "ipc")]
use crate::ironvar::get_variable_manager;
use crate::script::Script;
use crate::send;
use cfg_if::cfg_if;
use glib::Continue;
use serde::Deserialize;
use tokio::spawn;
#[derive(Debug, Deserialize, Clone)]
#[serde(untagged)]
pub enum DynamicBool {
/// Either a script or variable, to be determined.
Unknown(String),
Script(Script),
#[cfg(feature = "ipc")]
Variable(Box<str>),
}
impl DynamicBool {
pub fn subscribe<F>(self, f: F)
where
F: FnMut(bool) -> Continue + 'static,
{
let value = match self {
Self::Unknown(input) => {
if input.starts_with('#') {
cfg_if! {
if #[cfg(feature = "ipc")] {
Self::Variable(input.into())
} else {
Self::Unknown(input)
}
}
} else {
let script = Script::from(input.as_str());
Self::Script(script)
}
}
_ => self,
};
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
rx.attach(None, f);
spawn(async move {
match value {
DynamicBool::Script(script) => {
script
.run(None, |_, success| {
send!(tx, success);
})
.await;
}
#[cfg(feature = "ipc")]
DynamicBool::Variable(variable) => {
let variable_manager = get_variable_manager();
let variable_name = variable[1..].into(); // remove hash
let mut rx = crate::write_lock!(variable_manager).subscribe(variable_name);
while let Ok(value) = rx.recv().await {
let has_value = value.map(|s| is_truthy(&s)).unwrap_or_default();
send!(tx, has_value);
}
}
DynamicBool::Unknown(_) => unreachable!(),
}
});
}
}
/// Check if a string ironvar is 'truthy'
#[cfg(feature = "ipc")]
fn is_truthy(string: &str) -> bool {
!(string.is_empty() || string == "0" || string == "false")
}

View File

@@ -0,0 +1,321 @@
#[cfg(feature = "ipc")]
use crate::ironvar::get_variable_manager;
use crate::script::{OutputStream, Script};
use crate::{lock, send};
use gtk::prelude::*;
use std::sync::{Arc, Mutex};
use tokio::spawn;
/// A segment of a dynamic string,
/// containing either a static string
/// or a script.
#[derive(Debug)]
enum DynamicStringSegment {
Static(String),
Script(Script),
#[cfg(feature = "ipc")]
Variable(Box<str>),
}
/// Creates a new dynamic string, based off the input template.
/// Runs `f` with the compiled string each time one of the scripts or variables updates.
///
/// # Example
///
/// ```rs
/// dynamic_string(&text, move |string| {
/// label.set_markup(&string);
/// Continue(true)
/// });
/// ```
pub fn dynamic_string<F>(input: &str, f: F)
where
F: FnMut(String) -> Continue + 'static,
{
let tokens = parse_input(input);
let label_parts = Arc::new(Mutex::new(Vec::new()));
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
for (i, segment) in tokens.into_iter().enumerate() {
match segment {
DynamicStringSegment::Static(str) => {
lock!(label_parts).push(str);
}
DynamicStringSegment::Script(script) => {
let tx = tx.clone();
let label_parts = label_parts.clone();
// insert blank value to preserve segment order
lock!(label_parts).push(String::new());
spawn(async move {
script
.run(None, |out, _| {
if let OutputStream::Stdout(out) = out {
let mut label_parts = lock!(label_parts);
let _: String = std::mem::replace(&mut label_parts[i], out);
let string = label_parts.join("");
send!(tx, string);
}
})
.await;
});
}
#[cfg(feature = "ipc")]
DynamicStringSegment::Variable(name) => {
let tx = tx.clone();
let label_parts = label_parts.clone();
// insert blank value to preserve segment order
lock!(label_parts).push(String::new());
spawn(async move {
let variable_manager = get_variable_manager();
let mut rx = crate::write_lock!(variable_manager).subscribe(name);
while let Ok(value) = rx.recv().await {
if let Some(value) = value {
let mut label_parts = lock!(label_parts);
let _: String = std::mem::replace(&mut label_parts[i], value);
let string = label_parts.join("");
send!(tx, string);
}
}
});
}
}
}
rx.attach(None, f);
// initialize
{
let label_parts = lock!(label_parts).join("");
send!(tx, label_parts);
}
}
/// Parses the input string into static and dynamic segments
fn parse_input(input: &str) -> Vec<DynamicStringSegment> {
// short-circuit parser if it's all static
if !input.contains("{{") && !input.contains('#') {
return vec![DynamicStringSegment::Static(input.to_string())];
}
let mut tokens = vec![];
let mut chars = input.chars().collect::<Vec<_>>();
while !chars.is_empty() {
let char_pair = if chars.len() > 1 {
Some(&chars[..=1])
} else {
None
};
let (token, skip) = match char_pair {
Some(['{', '{']) => parse_script(&chars),
Some(['#', '#']) => (DynamicStringSegment::Static("#".to_string()), 2),
#[cfg(feature = "ipc")]
Some(['#', _]) => parse_variable(&chars),
_ => parse_static(&chars),
};
// quick runtime check to make sure the parser is working as expected
assert_ne!(skip, 0);
tokens.push(token);
chars.drain(..skip);
}
tokens
}
fn parse_script(chars: &[char]) -> (DynamicStringSegment, usize) {
const SKIP_BRACKETS: usize = 4; // two braces either side
let str = chars
.windows(2)
.skip(2)
.take_while(|win| win != &['}', '}'])
.map(|w| w[0])
.collect::<String>();
let len = str.len() + SKIP_BRACKETS;
let script = Script::from(str.as_str());
(DynamicStringSegment::Script(script), len)
}
#[cfg(feature = "ipc")]
fn parse_variable(chars: &[char]) -> (DynamicStringSegment, usize) {
const SKIP_HASH: usize = 1;
let str = chars
.iter()
.skip(1)
.take_while(|&c| !c.is_whitespace())
.collect::<String>();
let len = str.len() + SKIP_HASH;
let value = str.into();
(DynamicStringSegment::Variable(value), len)
}
fn parse_static(chars: &[char]) -> (DynamicStringSegment, usize) {
let mut str = chars
.windows(2)
.take_while(|&win| win != ['{', '{'] && win[0] != '#')
.map(|w| w[0])
.collect::<String>();
// if segment is at end of string, last char gets missed above due to uneven window.
if chars.len() == str.len() + 1 {
let remaining_char = *chars.get(str.len()).expect("Failed to find last char");
str.push(remaining_char);
}
let len = str.len();
(DynamicStringSegment::Static(str), len)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_static() {
const INPUT: &str = "hello world";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 1);
assert!(matches!(&tokens[0], DynamicStringSegment::Static(value) if value == INPUT))
}
#[test]
fn test_static_odd_char_count() {
const INPUT: &str = "hello";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 1);
assert!(matches!(&tokens[0], DynamicStringSegment::Static(value) if value == INPUT))
}
#[test]
fn test_script() {
const INPUT: &str = "{{echo hello}}";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 1);
assert!(
matches!(&tokens[0], DynamicStringSegment::Script(script) if script.cmd == "echo hello")
);
}
#[test]
fn test_variable() {
const INPUT: &str = "#variable";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 1);
assert!(
matches!(&tokens[0], DynamicStringSegment::Variable(name) if name.to_string() == "variable")
);
}
#[test]
fn test_static_script() {
const INPUT: &str = "hello {{echo world}}";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 2);
assert!(matches!(&tokens[0], DynamicStringSegment::Static(str) if str == "hello "));
assert!(
matches!(&tokens[1], DynamicStringSegment::Script(script) if script.cmd == "echo world")
);
}
#[test]
fn test_static_variable() {
const INPUT: &str = "hello #subject";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 2);
assert!(matches!(&tokens[0], DynamicStringSegment::Static(str) if str == "hello "));
assert!(
matches!(&tokens[1], DynamicStringSegment::Variable(name) if name.to_string() == "subject")
);
}
#[test]
fn test_static_script_static() {
const INPUT: &str = "hello {{echo world}} foo";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 3);
assert!(matches!(&tokens[0], DynamicStringSegment::Static(str) if str == "hello "));
assert!(
matches!(&tokens[1], DynamicStringSegment::Script(script) if script.cmd == "echo world")
);
assert!(matches!(&tokens[2], DynamicStringSegment::Static(str) if str == " foo"));
}
#[test]
fn test_static_variable_static() {
const INPUT: &str = "hello #subject foo";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 3);
assert!(matches!(&tokens[0], DynamicStringSegment::Static(str) if str == "hello "));
assert!(
matches!(&tokens[1], DynamicStringSegment::Variable(name) if name.to_string() == "subject")
);
assert!(matches!(&tokens[2], DynamicStringSegment::Static(str) if str == " foo"));
}
#[test]
fn test_static_script_variable() {
const INPUT: &str = "hello {{echo world}} #foo";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 4);
assert!(matches!(&tokens[0], DynamicStringSegment::Static(str) if str == "hello "));
assert!(
matches!(&tokens[1], DynamicStringSegment::Script(script) if script.cmd == "echo world")
);
assert!(matches!(&tokens[2], DynamicStringSegment::Static(str) if str == " "));
assert!(
matches!(&tokens[3], DynamicStringSegment::Variable(name) if name.to_string() == "foo")
);
}
#[test]
fn test_escape_hash() {
const INPUT: &str = "number ###num";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 3);
assert!(matches!(&tokens[0], DynamicStringSegment::Static(str) if str == "number "));
assert!(matches!(&tokens[1], DynamicStringSegment::Static(str) if str == "#"));
assert!(
matches!(&tokens[2], DynamicStringSegment::Variable(name) if name.to_string() == "num")
);
}
#[test]
fn test_script_with_hash() {
const INPUT: &str = "{{echo #hello}}";
let tokens = parse_input(INPUT);
assert_eq!(tokens.len(), 1);
assert!(
matches!(&tokens[0], DynamicStringSegment::Script(script) if script.cmd == "echo #hello")
);
}
}

7
src/dynamic_value/mod.rs Normal file
View File

@@ -0,0 +1,7 @@
#![doc = include_str!("../../docs/Dynamic values.md")]
mod dynamic_bool;
mod dynamic_string;
pub use dynamic_bool::DynamicBool;
pub use dynamic_string::dynamic_string;

28
src/ipc/client.rs Normal file
View File

@@ -0,0 +1,28 @@
use super::Ipc;
use crate::ipc::{Command, Response};
use color_eyre::Result;
use color_eyre::{Help, Report};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::UnixStream;
impl Ipc {
/// Sends a command to the IPC server.
/// The server response is returned.
pub async fn send(&self, command: Command) -> Result<Response> {
let mut stream = match UnixStream::connect(&self.path).await {
Ok(stream) => Ok(stream),
Err(err) => Err(Report::new(err)
.wrap_err("Failed to connect to Ironbar IPC server")
.suggestion("Is Ironbar running?")),
}?;
let write_buffer = serde_json::to_vec(&command)?;
stream.write_all(&write_buffer).await?;
let mut read_buffer = vec![0; 1024];
let bytes = stream.read(&mut read_buffer).await?;
let response = serde_json::from_slice(&read_buffer[..bytes])?;
Ok(response)
}
}

37
src/ipc/commands.rs Normal file
View File

@@ -0,0 +1,37 @@
use clap::Subcommand;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Subcommand, Debug, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum Command {
/// Return "ok"
Ping,
/// Open the GTK inspector
Inspect,
/// Set an `ironvar` value.
/// This creates it if it does not already exist, and updates it if it does.
/// Any references to this variable are automatically and immediately updated.
/// Keys and values can be any valid UTF-8 string.
Set {
/// Variable key. Can be any valid UTF-8 string.
key: Box<str>,
/// Variable value. Can be any valid UTF-8 string.
value: String,
},
/// Get the current value of an `ironvar`.
Get {
/// Variable key.
key: Box<str>,
},
/// Load an additional CSS stylesheet.
/// The sheet is automatically hot-reloaded.
LoadCss {
/// The path to the sheet.
path: PathBuf,
},
}

33
src/ipc/mod.rs Normal file
View File

@@ -0,0 +1,33 @@
mod client;
pub mod commands;
pub mod responses;
mod server;
use std::path::PathBuf;
use tracing::warn;
pub use commands::Command;
pub use responses::Response;
#[derive(Debug)]
pub struct Ipc {
path: PathBuf,
}
impl Ipc {
/// Creates a new IPC instance.
/// This can be used as both a server and client.
pub fn new() -> Self {
let ipc_socket_file = std::env::var("XDG_RUNTIME_DIR")
.map_or_else(|_| PathBuf::from("/tmp"), PathBuf::from)
.join("ironbar-ipc.sock");
if format!("{}", ipc_socket_file.display()).len() > 100 {
warn!("The IPC socket file's absolute path exceeds 100 bytes, the socket may fail to create.");
}
Self {
path: ipc_socket_file,
}
}
}

18
src/ipc/responses.rs Normal file
View File

@@ -0,0 +1,18 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum Response {
Ok,
OkValue { value: String },
Err { message: Option<String> },
}
impl Response {
/// Creates a new `Response::Error`.
pub fn error(message: &str) -> Self {
Self::Err {
message: Some(message.to_string()),
}
}
}

144
src/ipc/server.rs Normal file
View File

@@ -0,0 +1,144 @@
use super::Ipc;
use crate::bridge_channel::BridgeChannel;
use crate::ipc::{Command, Response};
use crate::ironvar::get_variable_manager;
use crate::style::load_css;
use crate::{read_lock, send_async, try_send, write_lock};
use color_eyre::{Report, Result};
use glib::Continue;
use std::fs;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{UnixListener, UnixStream};
use tokio::spawn;
use tokio::sync::mpsc;
use tokio::sync::mpsc::{Receiver, Sender};
use tracing::{debug, error, info, warn};
impl Ipc {
/// Starts the IPC server on its socket.
///
/// Once started, the server will begin accepting connections.
pub fn start(&self) {
let bridge = BridgeChannel::<Command>::new();
let cmd_tx = bridge.create_sender();
let (res_tx, mut res_rx) = mpsc::channel(32);
let path = self.path.clone();
if path.exists() {
warn!("Socket already exists. Did Ironbar exit abruptly?");
warn!("Attempting IPC shutdown to allow binding to address");
self.shutdown();
}
spawn(async move {
info!("Starting IPC on {}", path.display());
let listener = match UnixListener::bind(&path) {
Ok(listener) => listener,
Err(err) => {
error!(
"{:?}",
Report::new(err).wrap_err("Unable to start IPC server")
);
return;
}
};
loop {
match listener.accept().await {
Ok((stream, _addr)) => {
if let Err(err) =
Self::handle_connection(stream, &cmd_tx, &mut res_rx).await
{
error!("{err:?}");
}
}
Err(err) => {
error!("{err:?}");
}
}
}
});
bridge.recv(move |command| {
let res = Self::handle_command(command);
try_send!(res_tx, res);
Continue(true)
});
}
/// Takes an incoming connections,
/// reads the command message, and sends the response.
///
/// The connection is closed once the response has been written.
async fn handle_connection(
mut stream: UnixStream,
cmd_tx: &Sender<Command>,
res_rx: &mut Receiver<Response>,
) -> Result<()> {
let (mut stream_read, mut stream_write) = stream.split();
let mut read_buffer = vec![0; 1024];
let bytes = stream_read.read(&mut read_buffer).await?;
let command = serde_json::from_slice::<Command>(&read_buffer[..bytes])?;
debug!("Received command: {command:?}");
send_async!(cmd_tx, command);
let res = res_rx
.recv()
.await
.unwrap_or(Response::Err { message: None });
let res = serde_json::to_vec(&res)?;
stream_write.write_all(&res).await?;
stream_write.shutdown().await?;
Ok(())
}
/// Takes an input command, runs it and returns with the appropriate response.
///
/// This runs on the main thread, allowing commands to interact with GTK.
fn handle_command(command: Command) -> Response {
match command {
Command::Inspect => {
gtk::Window::set_interactive_debugging(true);
Response::Ok
}
Command::Set { key, value } => {
let variable_manager = get_variable_manager();
let mut variable_manager = write_lock!(variable_manager);
match variable_manager.set(key, value) {
Ok(_) => Response::Ok,
Err(err) => Response::error(&format!("{err}")),
}
}
Command::Get { key } => {
let variable_manager = get_variable_manager();
let value = read_lock!(variable_manager).get(&key);
match value {
Some(value) => Response::OkValue { value },
None => Response::error("Variable not found"),
}
}
Command::LoadCss { path } => {
if path.exists() {
load_css(path);
Response::Ok
} else {
Response::error("File not found")
}
}
Command::Ping => Response::Ok,
}
}
/// Shuts down the IPC server,
/// removing the socket file in the process.
pub fn shutdown(&self) {
fs::remove_file(&self.path).ok();
}
}

107
src/ironvar.rs Normal file
View File

@@ -0,0 +1,107 @@
#![doc = include_str!("../docs/Ironvars.md")]
use crate::{arc_rw, send};
use color_eyre::{Report, Result};
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use tokio::sync::broadcast;
lazy_static! {
static ref VARIABLE_MANAGER: Arc<RwLock<VariableManager>> = arc_rw!(VariableManager::new());
}
pub fn get_variable_manager() -> Arc<RwLock<VariableManager>> {
VARIABLE_MANAGER.clone()
}
/// Global singleton manager for `IronVar` variables.
pub struct VariableManager {
variables: HashMap<Box<str>, IronVar>,
}
impl VariableManager {
pub fn new() -> Self {
Self {
variables: HashMap::new(),
}
}
/// Sets the value for a variable,
/// creating it if it does not exist.
pub fn set(&mut self, key: Box<str>, value: String) -> Result<()> {
if Self::key_is_valid(&key) {
if let Some(var) = self.variables.get_mut(&key) {
var.set(Some(value));
} else {
let var = IronVar::new(Some(value));
self.variables.insert(key, var);
}
Ok(())
} else {
Err(Report::msg("Invalid key"))
}
}
/// Gets the current value of an `ironvar`.
/// Prefer to use `subscribe` where possible.
pub fn get(&self, key: &str) -> Option<String> {
self.variables.get(key).and_then(IronVar::get)
}
/// Subscribes to an `ironvar`, creating it if it does not exist.
/// Any time the var is set, its value is sent on the channel.
pub fn subscribe(&mut self, key: Box<str>) -> broadcast::Receiver<Option<String>> {
self.variables
.entry(key)
.or_insert_with(|| IronVar::new(None))
.subscribe()
}
fn key_is_valid(key: &str) -> bool {
!key.is_empty()
&& key
.chars()
.all(|char| char.is_alphanumeric() || char == '_' || char == '-')
}
}
/// Ironbar dynamic variable representation.
/// Interact with them through the `VARIABLE_MANAGER` `VariableManager` singleton.
#[derive(Debug)]
struct IronVar {
value: Option<String>,
tx: broadcast::Sender<Option<String>>,
_rx: broadcast::Receiver<Option<String>>,
}
impl IronVar {
/// Creates a new variable.
fn new(value: Option<String>) -> Self {
let (tx, rx) = broadcast::channel(32);
Self { value, tx, _rx: rx }
}
/// Gets the current variable value.
/// Prefer to subscribe to changes where possible.
fn get(&self) -> Option<String> {
self.value.clone()
}
/// Sets the current variable value.
/// The change is broadcast to all receivers.
fn set(&mut self, value: Option<String>) {
self.value = value.clone();
send!(self.tx, value);
}
/// Subscribes to the variable.
/// The latest value is immediately sent to all receivers.
fn subscribe(&self) -> broadcast::Receiver<Option<String>> {
let rx = self.tx.subscribe();
send!(self.tx, self.value.clone());
rx
}
}

View File

@@ -1,7 +1,7 @@
/// Sends a message on an asynchronous `Sender` using `send()`
/// Panics if the message cannot be sent.
///
/// Usage:
/// # Usage:
///
/// ```rs
/// send_async!(tx, "my message");
@@ -16,7 +16,7 @@ macro_rules! send_async {
/// Sends a message on an synchronous `Sender` using `send()`
/// Panics if the message cannot be sent.
///
/// Usage:
/// # Usage:
///
/// ```rs
/// send!(tx, "my message");
@@ -31,7 +31,7 @@ macro_rules! send {
/// Sends a message on an synchronous `Sender` using `try_send()`
/// Panics if the message cannot be sent.
///
/// Usage:
/// # Usage:
///
/// ```rs
/// try_send!(tx, "my message");
@@ -46,7 +46,7 @@ macro_rules! try_send {
/// Locks a `Mutex`.
/// Panics if the `Mutex` cannot be locked.
///
/// Usage:
/// # Usage:
///
/// ```rs
/// let mut val = lock!(my_mutex);
@@ -62,7 +62,7 @@ macro_rules! lock {
/// Gets a read lock on a `RwLock`.
/// Panics if the `RwLock` cannot be locked.
///
/// Usage:
/// # Usage:
///
/// ```rs
/// let val = read_lock!(my_rwlock);
@@ -77,7 +77,7 @@ macro_rules! read_lock {
/// Gets a write lock on a `RwLock`.
/// Panics if the `RwLock` cannot be locked.
///
/// Usage:
/// # Usage:
///
/// ```rs
/// let mut val = write_lock!(my_rwlock);
@@ -88,3 +88,33 @@ macro_rules! write_lock {
$rwlock.write().expect($crate::error::ERR_WRITE_LOCK)
};
}
/// Wraps `val` in a new `Arc<Mutex<T>>`.
///
/// # Usage:
///
/// ```rs
/// let val = arc_mut!(MyService::new());
/// ```
///
#[macro_export]
macro_rules! arc_mut {
($val:expr) => {
std::sync::Arc::new(std::Sync::Mutex::new($val))
};
}
/// Wraps `val` in a new `Arc<RwLock<T>>`.
///
/// # Usage:
///
/// ```rs
/// let val = arc_rw!(MyService::new());
/// ```
///
#[macro_export]
macro_rules! arc_rw {
($val:expr) => {
std::sync::Arc::new(std::sync::RwLock::new($val))
};
}

View File

@@ -2,13 +2,19 @@
mod bar;
mod bridge_channel;
#[cfg(feature = "cli")]
mod cli;
mod clients;
mod config;
mod desktop_file;
mod dynamic_string;
mod dynamic_value;
mod error;
mod gtk_helpers;
mod image;
#[cfg(feature = "ipc")]
mod ipc;
#[cfg(feature = "ipc")]
mod ironvar;
mod logging;
mod macros;
mod modules;
@@ -20,6 +26,9 @@ mod unique_id;
use crate::bar::create_bar;
use crate::config::{Config, MonitorConfig};
use crate::style::load_css;
use cfg_if::cfg_if;
#[cfg(feature = "cli")]
use clap::Parser;
use color_eyre::eyre::Result;
use color_eyre::Report;
use dirs::config_dir;
@@ -32,11 +41,12 @@ use std::future::Future;
use std::path::PathBuf;
use std::process::exit;
use std::rc::Rc;
use std::sync::mpsc;
use tokio::runtime::Handle;
use tokio::task::block_in_place;
use tokio::task::{block_in_place, spawn_blocking};
use crate::error::ExitCode;
use clients::wayland::{self, WaylandClient};
use clients::wayland;
use tracing::{debug, error, info};
use universal_config::ConfigLoader;
@@ -47,12 +57,37 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
async fn main() {
let _guard = logging::install_logging();
cfg_if! {
if #[cfg(feature = "cli")] {
run_with_args().await;
} else {
start_ironbar();
}
}
}
#[cfg(feature = "cli")]
async fn run_with_args() {
let args = cli::Args::parse();
match args.command {
Some(command) => {
let ipc = ipc::Ipc::new();
match ipc.send(command).await {
Ok(res) => cli::handle_response(res),
Err(err) => error!("{err:?}"),
};
}
None => start_ironbar(),
}
}
fn start_ironbar() {
info!("Ironbar version {}", VERSION);
info!("Starting application");
let wayland_client = wayland::get_client().await;
let app = Application::builder().application_id(GTK_APP_ID).build();
let _ = wayland::get_client(); // force-init
let running = Rc::new(Cell::new(false));
@@ -64,6 +99,13 @@ async fn main() {
running.set(true);
cfg_if! {
if #[cfg(feature = "ipc")] {
let ipc = ipc::Ipc::new();
ipc.start();
}
}
let display = Display::default().map_or_else(
|| {
let report = Report::msg("Failed to get default GTK display");
@@ -78,7 +120,7 @@ async fn main() {
ConfigLoader::load,
);
let config = match config_res {
let mut config: Config = match config_res {
Ok(config) => config,
Err(err) => {
error!("{:?}", err);
@@ -88,7 +130,17 @@ async fn main() {
debug!("Loaded config file");
if let Err(err) = create_bars(app, &display, wayland_client, &config) {
#[cfg(feature = "ipc")]
if let Some(ironvars) = config.ironvar_defaults.take() {
let variable_manager = ironvar::get_variable_manager();
for (k, v) in ironvars {
if write_lock!(variable_manager).set(k.clone(), v).is_err() {
tracing::warn!("Ignoring invalid ironvar: '{k}'");
}
}
}
if let Err(err) = create_bars(app, &display, &config) {
error!("{:?}", err);
exit(ExitCode::CreateBars as i32);
}
@@ -112,24 +164,33 @@ async fn main() {
if style_path.exists() {
load_css(style_path);
}
let (tx, rx) = mpsc::channel();
spawn_blocking(move || {
rx.recv().expect("to receive from channel");
info!("Shutting down");
#[cfg(feature = "ipc")]
ipc.shutdown();
exit(0);
});
ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel."))
.expect("Error setting Ctrl-C handler");
});
// Ignore CLI args
// Some are provided by swaybar_config but not currently supported
app.run_with_args(&Vec::<&str>::new());
info!("Shutting down");
exit(0);
}
/// Creates each of the bars across each of the (configured) outputs.
fn create_bars(
app: &Application,
display: &Display,
wl: &WaylandClient,
config: &Config,
) -> Result<()> {
let outputs = wl.get_outputs();
fn create_bars(app: &Application, display: &Display, config: &Config) -> Result<()> {
let wl = wayland::get_client();
let outputs = lock!(wl).get_outputs();
debug!("Received {} outputs from Wayland", outputs.len());
debug!("Outputs: {:?}", outputs);

View File

@@ -111,7 +111,7 @@ impl Module<Button> for ClipboardModule {
while let Some(event) = rx.recv().await {
let client = clipboard::get_client();
match event {
UIEvent::Copy(id) => client.copy(id).await,
UIEvent::Copy(id) => client.copy(id),
UIEvent::Remove(id) => client.remove(id),
}
}

View File

@@ -1,5 +1,5 @@
use super::{CustomWidget, CustomWidgetContext, ExecEvent};
use crate::dynamic_string::DynamicString;
use crate::dynamic_value::dynamic_string;
use crate::popup::Popup;
use crate::{build, try_send};
use gtk::prelude::*;
@@ -25,7 +25,7 @@ impl CustomWidget for ButtonWidget {
label.set_use_markup(true);
button.add(&label);
DynamicString::new(&text, move |string| {
dynamic_string(&text, move |string| {
label.set_markup(&string);
Continue(true)
});

View File

@@ -1,6 +1,6 @@
use super::{CustomWidget, CustomWidgetContext};
use crate::build;
use crate::dynamic_string::DynamicString;
use crate::dynamic_value::dynamic_string;
use crate::image::ImageProvider;
use gtk::prelude::*;
use gtk::Image;
@@ -29,7 +29,7 @@ impl CustomWidget for ImageWidget {
let gtk_image = gtk_image.clone();
let icon_theme = context.icon_theme.clone();
DynamicString::new(&self.src, move |src| {
dynamic_string(&self.src, move |src| {
ImageProvider::parse(&src, &icon_theme, self.size)
.map(|image| image.load_into_image(gtk_image.clone()));

View File

@@ -1,6 +1,6 @@
use super::{CustomWidget, CustomWidgetContext};
use crate::build;
use crate::dynamic_string::DynamicString;
use crate::dynamic_value::dynamic_string;
use gtk::prelude::*;
use gtk::Label;
use serde::Deserialize;
@@ -22,7 +22,7 @@ impl CustomWidget for LabelWidget {
{
let label = label.clone();
DynamicString::new(&self.label, move |string| {
dynamic_string(&self.label, move |string| {
label.set_markup(&string);
Continue(true)
});

View File

@@ -1,5 +1,5 @@
use super::{try_get_orientation, CustomWidget, CustomWidgetContext};
use crate::dynamic_string::DynamicString;
use crate::dynamic_value::dynamic_string;
use crate::modules::custom::set_length;
use crate::script::{OutputStream, Script, ScriptInput};
use crate::{build, send};
@@ -69,7 +69,7 @@ impl CustomWidget for ProgressWidget {
let progress = progress.clone();
progress.set_show_text(true);
DynamicString::new(&text, move |string| {
dynamic_string(&text, move |string| {
progress.set_text(Some(&string));
Continue(true)
});

View File

@@ -3,7 +3,7 @@ use crate::config::{CommonConfig, TruncateMode};
use crate::gtk_helpers::add_class;
use crate::image::ImageProvider;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::{send_async, try_send};
use crate::{lock, send_async, try_send};
use color_eyre::Result;
use glib::Continue;
use gtk::prelude::*;
@@ -52,7 +52,8 @@ impl Module<gtk::Box> for FocusedModule {
) -> Result<()> {
spawn(async move {
let (mut wlrx, handles) = {
let wl = wayland::get_client().await;
let wl = wayland::get_client();
let wl = lock!(wl);
wl.subscribe_toplevels()
};

View File

@@ -1,5 +1,5 @@
use crate::config::CommonConfig;
use crate::dynamic_string::DynamicString;
use crate::dynamic_value::dynamic_string;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::try_send;
use color_eyre::Result;
@@ -31,7 +31,7 @@ impl Module<Label> for LabelModule {
tx: mpsc::Sender<ModuleUpdateEvent<Self::SendMessage>>,
_rx: mpsc::Receiver<Self::ReceiveMessage>,
) -> Result<()> {
DynamicString::new(&self.label, move |string| {
dynamic_string(&self.label, move |string| {
try_send!(tx, ModuleUpdateEvent::Update(string));
Continue(true)
});

View File

@@ -117,7 +117,8 @@ impl Module<gtk::Box> for LauncherModule {
let tx = tx2;
let (mut wlrx, handles) = {
let wl = wayland::get_client().await;
let wl = wayland::get_client();
let wl = lock!(wl);
wl.subscribe_toplevels()
};
@@ -270,14 +271,18 @@ impl Module<gtk::Box> for LauncherModule {
} else {
send_async!(tx, ModuleUpdateEvent::ClosePopup);
let wl = wayland::get_client().await;
let wl = wayland::get_client();
let items = lock!(items);
let id = match event {
ItemEvent::FocusItem(app_id) => items
.get(&app_id)
.and_then(|item| item.windows.first().map(|(_, win)| win.id)),
ItemEvent::FocusWindow(id) => Some(id), // FIXME: Broken on wlroots-git
ItemEvent::FocusItem(app_id) => items.get(&app_id).and_then(|item| {
item.windows
.iter()
.find(|(_, win)| !win.open_state.is_focused())
.or_else(|| item.windows.first())
.map(|(_, win)| win.id)
}),
ItemEvent::FocusWindow(id) => Some(id),
ItemEvent::OpenItem(_) => unreachable!(),
};
@@ -285,13 +290,18 @@ impl Module<gtk::Box> for LauncherModule {
if let Some(window) =
items.iter().find_map(|(_, item)| item.windows.get(&id))
{
let seat = wl.get_seats().pop().expect("Failed to get Wayland seat");
debug!("Focusing window {id}: {}", window.name);
let seat = lock!(wl)
.get_seats()
.pop()
.expect("Failed to get Wayland seat");
window.focus(&seat);
}
}
// roundtrip to immediately send activate event
wl.roundtrip();
lock!(wl).roundtrip();
}
}
});
@@ -466,7 +476,7 @@ impl Module<gtk::Box> for LauncherModule {
{
let tx = controller_tx.clone();
button.connect_clicked(move |button| {
button.connect_clicked(move |_button| {
try_send!(tx, ItemEvent::FocusWindow(win.id));
});
}

View File

@@ -24,6 +24,9 @@ pub struct UpowerModule {
#[serde(default = "default_format")]
format: String,
#[serde(default = "default_icon_size")]
icon_size: i32,
#[serde(flatten)]
pub common: Option<CommonConfig>,
}
@@ -32,6 +35,10 @@ fn default_format() -> String {
String::from("{percentage}%")
}
const fn default_icon_size() -> i32 {
24
}
#[derive(Clone, Debug)]
pub struct UpowerProperties {
percentage: f64,
@@ -180,7 +187,7 @@ impl Module<gtk::Button> for UpowerModule {
.attach(None, move |properties: UpowerProperties| {
let format = format.replace("{percentage}", &properties.percentage.to_string());
let icon_name = String::from("icon:") + &properties.icon_name;
ImageProvider::parse(&icon_name, &icon_theme, 24)
ImageProvider::parse(&icon_name, &icon_theme, self.icon_size)
.map(|provider| provider.load_into_image(icon.clone()));
label.set_markup(format.as_ref());
Continue(true)

View File

@@ -1,6 +1,7 @@
use crate::send;
use color_eyre::{Help, Report};
use glib::Continue;
use gtk::ffi::GTK_STYLE_PROVIDER_PRIORITY_USER;
use gtk::prelude::CssProviderExt;
use gtk::{gdk, gio, CssProvider, StyleContext};
use notify::event::{DataChange, ModifyKind};
@@ -29,7 +30,11 @@ pub fn load_css(style_path: PathBuf) {
};
let screen = gdk::Screen::default().expect("Failed to get default GTK screen");
StyleContext::add_provider_for_screen(&screen, &provider, 800);
StyleContext::add_provider_for_screen(
&screen,
&provider,
GTK_STYLE_PROVIDER_PRIORITY_USER as u32,
);
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);