diff --git a/.github/README.md b/.github/README.md index f2557e2..099c98a 100644 --- a/.github/README.md +++ b/.github/README.md @@ -5,9 +5,8 @@
-`media-controller` provides a GTK-3 always-on-top window with transparency -support that displays the current volume/brightness right after changing it -accordingly. +`media-controller` provides a GTK always-on-top window with transparency support +that displays the current volume/brightness right after changing it accordingly. It makes use of UNIX sockets so that if another instance is created while the first one is running, it doesn't create another window and simply updates the @@ -18,6 +17,12 @@ content of the existing one providing a smooth experience. [Options used in the demo: `--color=#000000aa --font-description="BigBlueTerm437 Nerd Font Mono"`] +In order to build the binary or the library you must pick a Cargo feature: + +- `regular`: For X11 and other systems, uses GTK3 +- `wayland`: For Wayland systems, uses GTK4 and GTK4 Layer Shell (make sure to + have [`gtk-layer-shell`](https://github.com/wmww/gtk-layer-shell) installed) + ``` media-controller v0.2.1 Nuno David @@ -39,11 +44,11 @@ Format --{option}={value} empty Empty character used in the progress bar. Default: " " ``` -In order to make it work in your system simply create a new cargo project. Add -the library: +In order to make it work in your specific system, simply create a new cargo +project and add the library with the respective feature enabled: ``` -cargo add media-controller +cargo add media-controller --features wayland ``` Then all it takes is implementing some functions. Your `main.rs` should look diff --git a/Cargo.lock b/Cargo.lock index 3609795..db11f45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,28 +1,28 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "atk" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4af014b17dd80e8af9fa689b2d4a211ddba6eb583c1622f35d0cb543f6b17e4" +checksum = "241b621213072e993be4f6f3a9e4b45f65b7e6faad43001be957184b7bb1824b" dependencies = [ "atk-sys", - "glib", + "glib 0.18.5", "libc", ] [[package]] name = "atk-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "251e0b7d90e33e0ba930891a505a9a35ece37b2dd37a14f3ffc306c13b980009" +checksum = "c5e48b684b0ca77d2bbadeef17424c2ea3c897d44d566a1617e7e8f30614d086" dependencies = [ - "glib-sys", - "gobject-sys", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", - "system-deps", + "system-deps 6.2.2", ] [[package]] @@ -33,9 +33,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] name = "cairo-rs" @@ -44,32 +44,65 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ca26ef0159422fb77631dc9d17b102f253b876fe1586b03b803e63a309b4ee2" dependencies = [ "bitflags", - "cairo-sys-rs", - "glib", + "cairo-sys-rs 0.18.2", + "glib 0.18.5", "libc", "once_cell", "thiserror", ] +[[package]] +name = "cairo-rs" +version = "0.20.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e3bd0f4e25afa9cabc157908d14eeef9067d6448c49414d17b3fb55f0eadd0" +dependencies = [ + "bitflags", + "cairo-sys-rs 0.20.10", + "glib 0.20.12", + "libc", +] + [[package]] name = "cairo-sys-rs" version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "685c9fa8e590b8b3d678873528d83411db17242a73fccaed827770ea0fedda51" dependencies = [ - "glib-sys", + "glib-sys 0.18.1", + "libc", + "system-deps 6.2.2", +] + +[[package]] +name = "cairo-sys-rs" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "059cc746549898cbfd9a47754288e5a958756650ef4652bbb6c5f71a6bda4f8b" +dependencies = [ + "glib-sys 0.20.10", "libc", - "system-deps", + "system-deps 7.0.5", ] [[package]] name = "cfg-expr" -version = "0.15.5" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03915af431787e6ffdcc74c645077518c6b6e01f80b761e0fbbfa288536311b3" +checksum = "d067ad48b8650848b989a59a86c6c36a995d02d2bf778d45c3c5d57bc2718f02" dependencies = [ "smallvec", - "target-lexicon", + "target-lexicon 0.12.16", +] + +[[package]] +name = "cfg-expr" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d0390889d58f934f01cd49736275b4c2da15bcfc328c78ff2349907e6cabf22" +dependencies = [ + "smallvec", + "target-lexicon 0.13.2", ] [[package]] @@ -138,7 +171,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.45", + "syn 2.0.104", ] [[package]] @@ -163,17 +196,17 @@ dependencies = [ [[package]] name = "gdk" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5ba081bdef3b75ebcdbfc953699ed2d7417d6bd853347a42a37d76406a33646" +checksum = "d9f245958c627ac99d8e529166f9823fb3b838d1d41fd2b297af3075093c2691" dependencies = [ - "cairo-rs", - "gdk-pixbuf", + "cairo-rs 0.18.5", + "gdk-pixbuf 0.18.5", "gdk-sys", - "gio", - "glib", + "gio 0.18.4", + "glib 0.18.5", "libc", - "pango", + "pango 0.18.3", ] [[package]] @@ -182,41 +215,99 @@ version = "0.18.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50e1f5f1b0bfb830d6ccc8066d18db35c487b1b2b1e8589b5dfe9f07e8defaec" dependencies = [ - "gdk-pixbuf-sys", - "gio", - "glib", + "gdk-pixbuf-sys 0.18.0", + "gio 0.18.4", + "glib 0.18.5", "libc", "once_cell", ] +[[package]] +name = "gdk-pixbuf" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd242894c084f4beed508a56952750bce3e96e85eb68fdc153637daa163e10c" +dependencies = [ + "gdk-pixbuf-sys 0.20.10", + "gio 0.20.12", + "glib 0.20.12", + "libc", +] + [[package]] name = "gdk-pixbuf-sys" version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9839ea644ed9c97a34d129ad56d38a25e6756f99f3a88e15cd39c20629caf7" dependencies = [ - "gio-sys", - "glib-sys", - "gobject-sys", + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", + "libc", + "system-deps 6.2.2", +] + +[[package]] +name = "gdk-pixbuf-sys" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b34f3b580c988bd217e9543a2de59823fafae369d1a055555e5f95a8b130b96" +dependencies = [ + "gio-sys 0.20.10", + "glib-sys 0.20.10", + "gobject-sys 0.20.10", "libc", - "system-deps", + "system-deps 7.0.5", ] [[package]] name = "gdk-sys" -version = "0.18.0" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c2d13f38594ac1e66619e188c6d5a1adb98d11b2fcf7894fc416ad76aa2f3f7" +dependencies = [ + "cairo-sys-rs 0.18.2", + "gdk-pixbuf-sys 0.18.0", + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", + "libc", + "pango-sys 0.18.0", + "pkg-config", + "system-deps 6.2.2", +] + +[[package]] +name = "gdk4" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4850c9d9c1aecd1a3eb14fadc1cdb0ac0a2298037e116264c7473e1740a32d60" +dependencies = [ + "cairo-rs 0.20.12", + "gdk-pixbuf 0.20.10", + "gdk4-sys", + "gio 0.20.12", + "gl", + "glib 0.20.12", + "libc", + "pango 0.20.12", +] + +[[package]] +name = "gdk4-sys" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31ff856cb3386dae1703a920f803abafcc580e9b5f711ca62ed1620c25b51ff2" +checksum = "6f6eb95798e2b46f279cf59005daf297d5b69555428f185650d71974a910473a" dependencies = [ - "cairo-sys-rs", - "gdk-pixbuf-sys", - "gio-sys", - "glib-sys", - "gobject-sys", + "cairo-sys-rs 0.20.10", + "gdk-pixbuf-sys 0.20.10", + "gio-sys 0.20.10", + "glib-sys 0.20.10", + "gobject-sys 0.20.10", "libc", - "pango-sys", + "pango-sys 0.20.10", "pkg-config", - "system-deps", + "system-deps 7.0.5", ] [[package]] @@ -229,8 +320,8 @@ dependencies = [ "futures-core", "futures-io", "futures-util", - "gio-sys", - "glib", + "gio-sys 0.18.1", + "glib 0.18.5", "libc", "once_cell", "pin-project-lite", @@ -238,19 +329,69 @@ dependencies = [ "thiserror", ] +[[package]] +name = "gio" +version = "0.20.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e27e276e7b6b8d50f6376ee7769a71133e80d093bdc363bd0af71664228b831" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys 0.20.10", + "glib 0.20.12", + "libc", + "pin-project-lite", + "smallvec", +] + [[package]] name = "gio-sys" version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37566df850baf5e4cb0dfb78af2e4b9898d817ed9263d1090a2df958c64737d2" dependencies = [ - "glib-sys", - "gobject-sys", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", - "system-deps", + "system-deps 6.2.2", "winapi", ] +[[package]] +name = "gio-sys" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521e93a7e56fc89e84aea9a52cfc9436816a4b363b030260b699950ff1336c83" +dependencies = [ + "glib-sys 0.20.10", + "gobject-sys 0.20.10", + "libc", + "system-deps 7.0.5", + "windows-sys", +] + +[[package]] +name = "gl" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a94edab108827d67608095e269cf862e60d920f144a5026d3dbcfd8b877fb404" +dependencies = [ + "gl_generator", +] + +[[package]] +name = "gl_generator" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" +dependencies = [ + "khronos_api", + "log", + "xml-rs", +] + [[package]] name = "glib" version = "0.18.5" @@ -263,10 +404,10 @@ dependencies = [ "futures-executor", "futures-task", "futures-util", - "gio-sys", - "glib-macros", - "glib-sys", - "gobject-sys", + "gio-sys 0.18.1", + "glib-macros 0.18.5", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", "memchr", "once_cell", @@ -274,18 +415,52 @@ dependencies = [ "thiserror", ] +[[package]] +name = "glib" +version = "0.20.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffc4b6e352d4716d84d7dde562dd9aee2a7d48beb872dd9ece7f2d1515b2d683" +dependencies = [ + "bitflags", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "gio-sys 0.20.10", + "glib-macros 0.20.12", + "glib-sys 0.20.10", + "gobject-sys 0.20.10", + "libc", + "memchr", + "smallvec", +] + [[package]] name = "glib-macros" version = "0.18.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" dependencies = [ - "heck", - "proc-macro-crate 2.0.1", + "heck 0.4.1", + "proc-macro-crate 2.0.0", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.45", + "syn 2.0.104", +] + +[[package]] +name = "glib-macros" +version = "0.20.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8084af62f09475a3f529b1629c10c429d7600ee1398ae12dd3bf175d74e7145" +dependencies = [ + "heck 0.5.0", + "proc-macro-crate 3.3.0", + "proc-macro2", + "quote", + "syn 2.0.104", ] [[package]] @@ -295,7 +470,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "063ce2eb6a8d0ea93d2bf8ba1957e78dbab6be1c2220dd3daca57d5a9d869898" dependencies = [ "libc", - "system-deps", + "system-deps 6.2.2", +] + +[[package]] +name = "glib-sys" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ab79e1ed126803a8fb827e3de0e2ff95191912b8db65cee467edb56fc4cc215" +dependencies = [ + "libc", + "system-deps 7.0.5", ] [[package]] @@ -304,68 +489,213 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0850127b514d1c4a4654ead6dedadb18198999985908e6ffe4436f53c785ce44" dependencies = [ - "glib-sys", + "glib-sys 0.18.1", + "libc", + "system-deps 6.2.2", +] + +[[package]] +name = "gobject-sys" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec9aca94bb73989e3cfdbf8f2e0f1f6da04db4d291c431f444838925c4c63eda" +dependencies = [ + "glib-sys 0.20.10", + "libc", + "system-deps 7.0.5", +] + +[[package]] +name = "graphene-rs" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b86dfad7d14251c9acaf1de63bc8754b7e3b4e5b16777b6f5a748208fe9519b" +dependencies = [ + "glib 0.20.12", + "graphene-sys", + "libc", +] + +[[package]] +name = "graphene-sys" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df583a85ba2d5e15e1797e40d666057b28bc2f60a67c9c24145e6db2cc3861ea" +dependencies = [ + "glib-sys 0.20.10", + "libc", + "pkg-config", + "system-deps 7.0.5", +] + +[[package]] +name = "gsk4" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61f5e72f931c8c9f65fbfc89fe0ddc7746f147f822f127a53a9854666ac1f855" +dependencies = [ + "cairo-rs 0.20.12", + "gdk4", + "glib 0.20.12", + "graphene-rs", + "gsk4-sys", "libc", - "system-deps", + "pango 0.20.12", +] + +[[package]] +name = "gsk4-sys" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "755059de55fa6f85a46bde8caf03e2184c96bfda1f6206163c72fb0ea12436dc" +dependencies = [ + "cairo-sys-rs 0.20.10", + "gdk4-sys", + "glib-sys 0.20.10", + "gobject-sys 0.20.10", + "graphene-sys", + "libc", + "pango-sys 0.20.10", + "system-deps 7.0.5", ] [[package]] name = "gtk" -version = "0.18.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93c4f5e0e20b60e10631a5f06da7fe3dda744b05ad0ea71fee2f47adf865890c" +checksum = "fd56fb197bfc42bd5d2751f4f017d44ff59fbb58140c6b49f9b3b2bdab08506a" dependencies = [ "atk", - "cairo-rs", + "cairo-rs 0.18.5", "field-offset", "futures-channel", "gdk", - "gdk-pixbuf", - "gio", - "glib", + "gdk-pixbuf 0.18.5", + "gio 0.18.4", + "glib 0.18.5", "gtk-sys", "gtk3-macros", "libc", - "pango", + "pango 0.18.3", "pkg-config", ] [[package]] name = "gtk-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771437bf1de2c1c0b496c11505bdf748e26066bbe942dfc8f614c9460f6d7722" +checksum = "8f29a1c21c59553eb7dd40e918be54dccd60c52b049b75119d5d96ce6b624414" dependencies = [ "atk-sys", - "cairo-sys-rs", - "gdk-pixbuf-sys", + "cairo-sys-rs 0.18.2", + "gdk-pixbuf-sys 0.18.0", "gdk-sys", - "gio-sys", - "glib-sys", - "gobject-sys", + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", - "pango-sys", - "system-deps", + "pango-sys 0.18.0", + "system-deps 6.2.2", ] [[package]] name = "gtk3-macros" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6063efb63db582968fb7df72e1ae68aa6360dcfb0a75143f34fc7d616bad75e" +checksum = "52ff3c5b21f14f0736fed6dcfc0bfb4225ebf5725f3c0209edeec181e4d73e9d" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.45", + "syn 2.0.104", +] + +[[package]] +name = "gtk4" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f274dd0102c21c47bbfa8ebcb92d0464fab794a22fad6c3f3d5f165139a326d6" +dependencies = [ + "cairo-rs 0.20.12", + "field-offset", + "futures-channel", + "gdk-pixbuf 0.20.10", + "gdk4", + "gio 0.20.12", + "glib 0.20.12", + "graphene-rs", + "gsk4", + "gtk4-macros", + "gtk4-sys", + "libc", + "pango 0.20.12", +] + +[[package]] +name = "gtk4-layer-shell" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aec4fd3226bb6aa8dda5370142e14a4d15f00bba99bfb355b6ef7bb49d100758" +dependencies = [ + "bitflags", + "gdk4", + "glib 0.20.12", + "glib-sys 0.20.10", + "gtk4", + "gtk4-layer-shell-sys", + "libc", +] + +[[package]] +name = "gtk4-layer-shell-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3057dc117db2d664a9b45f1956568701914e80cf9f2c8cef0a755af4c1c8105" +dependencies = [ + "gdk4-sys", + "glib-sys 0.20.10", + "gtk4-sys", + "libc", + "system-deps 7.0.5", +] + +[[package]] +name = "gtk4-macros" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ed1786c4703dd196baf7e103525ce0cf579b3a63a0570fe653b7ee6bac33999" +dependencies = [ + "proc-macro-crate 3.3.0", + "proc-macro2", + "quote", + "syn 2.0.104", +] + +[[package]] +name = "gtk4-sys" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41e03b01e54d77c310e1d98647d73f996d04b2f29b9121fe493ea525a7ec03d6" +dependencies = [ + "cairo-sys-rs 0.20.10", + "gdk-pixbuf-sys 0.20.10", + "gdk4-sys", + "gio-sys 0.20.10", + "glib-sys 0.20.10", + "gobject-sys 0.20.10", + "graphene-sys", + "gsk4-sys", + "libc", + "pango-sys 0.20.10", + "system-deps 7.0.5", ] [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" [[package]] name = "heck" @@ -373,35 +703,55 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "indexmap" -version = "2.1.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", "hashbrown", ] +[[package]] +name = "khronos_api" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" + [[package]] name = "libc" version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + [[package]] name = "media-controller" -version = "0.2.1" +version = "0.3.0" dependencies = [ "fs2", "gtk", + "gtk4", + "gtk4-layer-shell", ] [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "memoffset" @@ -414,9 +764,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "pango" @@ -424,11 +774,23 @@ version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ca27ec1eb0457ab26f3036ea52229edbdb74dee1edd29063f5b9b010e7ebee4" dependencies = [ - "gio", - "glib", + "gio 0.18.4", + "glib 0.18.5", "libc", "once_cell", - "pango-sys", + "pango-sys 0.18.0", +] + +[[package]] +name = "pango" +version = "0.20.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6576b311f6df659397043a5fa8a021da8f72e34af180b44f7d57348de691ab5c" +dependencies = [ + "gio 0.20.12", + "glib 0.20.12", + "libc", + "pango-sys 0.20.10", ] [[package]] @@ -437,10 +799,22 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "436737e391a843e5933d6d9aa102cb126d501e815b83601365a948a518555dc5" dependencies = [ - "glib-sys", - "gobject-sys", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", - "system-deps", + "system-deps 6.2.2", +] + +[[package]] +name = "pango-sys" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186909673fc09be354555c302c0b3dcf753cd9fa08dcb8077fa663c80fb243fa" +dependencies = [ + "glib-sys 0.20.10", + "gobject-sys 0.20.10", + "libc", + "system-deps 7.0.5", ] [[package]] @@ -457,9 +831,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.28" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "proc-macro-crate" @@ -473,14 +847,22 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" dependencies = [ - "toml_datetime", "toml_edit 0.20.2", ] +[[package]] +name = "proc-macro-crate" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35" +dependencies = [ + "toml_edit 0.22.27", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -507,18 +889,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.73" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.34" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] @@ -555,7 +937,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.45", + "syn 2.0.104", ] [[package]] @@ -578,9 +960,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "syn" @@ -594,9 +976,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.45" +version = "2.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eae3c679c56dc214320b67a1bc04ef3dfbd6411f6443974b5e4893231298e66" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" dependencies = [ "proc-macro2", "quote", @@ -605,12 +987,25 @@ dependencies = [ [[package]] name = "system-deps" -version = "6.2.0" +version = "6.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" +dependencies = [ + "cfg-expr 0.15.8", + "heck 0.5.0", + "pkg-config", + "toml", + "version-compare", +] + +[[package]] +name = "system-deps" +version = "7.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2d580ff6a20c55dfb86be5f9c238f67835d0e81cbdea8bf5680e0897320331" +checksum = "e4be53aa0cba896d2dc615bd42bbc130acdcffa239e0a2d965ea5b3b2a86ffdb" dependencies = [ - "cfg-expr", - "heck", + "cfg-expr 0.20.1", + "heck 0.5.0", "pkg-config", "toml", "version-compare", @@ -618,28 +1013,34 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.12" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "target-lexicon" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" +checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" [[package]] name = "thiserror" -version = "1.0.53" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2cd5904763bad08ad5513ddbb12cf2ae273ca53fa9f68e843e236ec6dfccc09" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.53" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.45", + "syn 2.0.104", ] [[package]] @@ -656,9 +1057,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" dependencies = [ "serde", ] @@ -671,7 +1072,7 @@ checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ "indexmap", "toml_datetime", - "winnow", + "winnow 0.5.31", ] [[package]] @@ -684,7 +1085,18 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.5.31", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow 0.7.12", ] [[package]] @@ -695,15 +1107,15 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "version-compare" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29" +checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "winapi" @@ -727,6 +1139,79 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "winnow" version = "0.5.31" @@ -735,3 +1220,18 @@ checksum = "97a4882e6b134d6c28953a387571f1acdd3496830d5e36c5e3a1075580ea641c" dependencies = [ "memchr", ] + +[[package]] +name = "winnow" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3edebf492c8125044983378ecb5766203ad3b4c2f7a922bd7dd207f6d443e95" +dependencies = [ + "memchr", +] + +[[package]] +name = "xml-rs" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fd8403733700263c6eb89f192880191f1b83e332f7a20371ddcf421c4a337c7" diff --git a/Cargo.toml b/Cargo.toml index 6534f17..4d37794 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "media-controller" -version = "0.2.1" +version = "0.3.0" edition = "2021" authors = ["Nuno David "] license = "MIT" @@ -10,8 +10,12 @@ repository = "https://github.com/ndavd/media-controller" exclude = [".github/workflows"] categories = ["graphics", "visualization", "multimedia::audio"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +regular = ["gtk"] +wayland = ["gtk4", "gtk4-layer-shell"] [dependencies] fs2 = "0.4.3" -gtk = "0.18.1" +gtk = { version = "0.18.1", optional = true } +gtk4 = { version = "0.9.7", optional = true } +gtk4-layer-shell = { version = "0.5.0", optional = true } diff --git a/src/cli.rs b/src/cli.rs index b9db593..32ab5ee 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -138,7 +138,7 @@ impl Cli for MediaController { .max_by(|a, b| a.len().cmp(&b.len())) .unwrap() .len(); - let pad = |s: &str| format!("{:biggest_arg_len$}", s); + let pad = |s: &str| format!("{s:biggest_arg_len$}"); println!( "{TAB}{}{TAB}Lifespan of the window in seconds. {def_str}{}", diff --git a/src/lib.rs b/src/lib.rs index 5910e05..b0bdeb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,16 @@ mod cli; + +#[cfg(feature = "regular")] mod window; +#[cfg(feature = "wayland")] +mod wl_window; use cli::{Cli, NAME}; use fs2::FileExt; use std::io::{Read, Write}; -use window::spawn_window; + +#[cfg(all(feature = "regular", feature = "wayland"))] +compile_error!("Features \"regular\" and \"wayland\" cannot be enabled at the same time"); #[derive(Debug, Default, Clone, Copy)] pub enum Action { @@ -64,7 +70,7 @@ impl Color { return None; } let chars_vec = chars.collect::>(); - let mut chunks = chars_vec.chunks(2).map(|c| String::from_iter(c)); + let mut chunks = chars_vec.chunks(2).map(String::from_iter); let parse_chunk = |chunk: Option| -> Option { if let Some(chunk) = chunk { let integer_representation = u8::from_str_radix(&chunk, 16).ok()?; @@ -160,12 +166,13 @@ impl MediaControllerApp { ); println!("{label_text}"); - let lock_p = format!("/tmp/{}.lock", NAME); - let socket_p = format!("/tmp/{}.sock", NAME); + let lock_p = format!("/tmp/{NAME}.lock"); + let socket_p = format!("/tmp/{NAME}.sock"); let lock = std::fs::OpenOptions::new() .write(true) .create(true) + .truncate(true) .open(lock_p) .unwrap(); @@ -187,23 +194,21 @@ impl MediaControllerApp { std::thread::spawn(move || { let _ = std::fs::remove_file(&socket_p); let listener = std::os::unix::net::UnixListener::bind(socket_p).unwrap(); - for stream in listener.incoming() { - if let Ok(mut stream) = stream { - let mut b = [0; 1024]; - let data_size = stream.read(&mut b).unwrap(); - let data = std::str::from_utf8(&b[..data_size]).unwrap(); - println!("Received from another instance: {}", data); - let mut label = shared_2.lock().unwrap(); - let mut kill_countdown = kill_countdown_2.lock().unwrap(); - *kill_countdown = if *kill_countdown >= 2 { - 2 - } else { - *kill_countdown + 1 - }; - *label = data.to_string(); - stream.shutdown(std::net::Shutdown::Both).unwrap(); - drop(stream); - } + for mut stream in listener.incoming().flatten() { + let mut b = [0; 1024]; + let data_size = stream.read(&mut b).unwrap(); + let data = std::str::from_utf8(&b[..data_size]).unwrap(); + println!("Received from another instance: {data}"); + let mut label = shared_2.lock().unwrap(); + let mut kill_countdown = kill_countdown_2.lock().unwrap(); + *kill_countdown = if *kill_countdown >= 2 { + 2 + } else { + *kill_countdown + 1 + }; + *label = data.to_string(); + stream.shutdown(std::net::Shutdown::Both).unwrap(); + drop(stream); } }); std::thread::spawn(move || { @@ -215,7 +220,11 @@ impl MediaControllerApp { std::process::exit(0); }); - spawn_window(controller.clone(), shared); + #[cfg(feature = "regular")] + window::spawn_window(controller.clone(), shared); + + #[cfg(feature = "wayland")] + wl_window::spawn_wl_window(controller.clone(), shared); } pub fn label(&self, action: Action, full: char, half_full: char, empty: char) -> String { let is_volume = action.is_volume_kind(); @@ -230,7 +239,7 @@ impl MediaControllerApp { return "MUTED".to_string(); } let volume = (self.get_volume)(); - return format!("VOL: {}", Self::_progress(volume, full, half_full, empty)); + format!("VOL: {}", Self::_progress(volume, full, half_full, empty)) } fn _progress(percentage: u8, full: char, half_full: char, empty: char) -> String { assert!(percentage <= 100); @@ -238,17 +247,16 @@ impl MediaControllerApp { let filled_count = progress as usize; let middle_count = (percentage != 100) as usize; let empty_count = 10_usize.saturating_sub(progress as usize).saturating_sub(1); - let progress_str = std::iter::repeat(full) - .take(filled_count) - .chain( - std::iter::repeat(if progress.ceil() - progress >= 0.5 { + let progress_str = std::iter::repeat_n(full, filled_count) + .chain(std::iter::repeat_n( + if progress.ceil() - progress >= 0.5 { half_full } else { empty - }) - .take(middle_count), - ) - .chain(std::iter::repeat(empty).take(empty_count)) + }, + middle_count, + )) + .chain(std::iter::repeat_n(empty, empty_count)) .collect::(); format!("{progress_str}{percentage:>4}%") } diff --git a/src/main.rs b/src/main.rs index c28c826..a3e00f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ fn get_formatted_value(value: i8) -> String { } fn get_mute() -> bool { - run_get_volume_output().find("MUTED").is_some() + run_get_volume_output().contains("MUTED") } fn get_volume() -> u8 { diff --git a/src/wl_window.rs b/src/wl_window.rs new file mode 100644 index 0000000..60d53b0 --- /dev/null +++ b/src/wl_window.rs @@ -0,0 +1,74 @@ +use gtk4::gdk::Display; +use gtk4::glib::ControlFlow; +use gtk4::{prelude::*, CssProvider}; +use gtk4::{Application, ApplicationWindow}; + +use gtk4_layer_shell::LayerShell; + +use crate::MediaController; + +fn build_ui( + app: &Application, + controller: &MediaController, + shared: std::sync::Arc>, +) { + let w = controller.width as i32; + let h = controller.height as i32; + let b = controller.bottom as i32; + + let win = ApplicationWindow::builder() + .application(app) + .default_width(w) + .default_height(h) + .build(); + + win.init_layer_shell(); + win.set_layer(gtk4_layer_shell::Layer::Overlay); + win.set_anchor(gtk4_layer_shell::Edge::Bottom, true); + win.set_margin(gtk4_layer_shell::Edge::Bottom, b); + + let css = format!( + ".media-controller-window {{ background-color: {} }}", + controller.color + ); + let css_provider = CssProvider::new(); + css_provider.load_from_data(css.as_str()); + let display = Display::default().unwrap(); + gtk4::style_context_add_provider_for_display( + &display, + &css_provider, + gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION, + ); + + let label = gtk4::Label::new(None); + + label.set_text(&shared.lock().unwrap()); + let attr = gtk4::pango::AttrList::new(); + attr.insert(gtk4::pango::AttrFontDesc::new( + >k4::pango::FontDescription::from_string(&controller.font_description), + )); + label.set_attributes(Some(&attr)); + win.set_child(Some(&label)); + win.add_css_class("media-controller-window"); + + gtk4::glib::timeout_add_local(std::time::Duration::from_millis(10), move || { + if let Ok(shared) = shared.lock() { + if label.text().as_str() != shared.as_str() { + label.set_text(&shared); + } + } + ControlFlow::Continue + }); + + win.present(); +} + +pub fn spawn_wl_window( + controller: MediaController, + shared: std::sync::Arc>, +) { + gtk4::init().unwrap(); + let app = Application::builder().build(); + app.connect_activate(move |app| build_ui(app, &controller, shared.clone())); + app.run_with_args::<&str>(&[]); +}