Move Cosmic Applets into new Dir & remove old applets
3922
applets/cosmic-app-list/Cargo.lock
generated
|
|
@ -1,29 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-app-list"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[dependencies]
|
||||
cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-client-toolkit" }
|
||||
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = ["client"] }
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet", "tokio"] }
|
||||
ron = "0.8"
|
||||
futures = "0.3"
|
||||
futures-util = "0.3"
|
||||
once_cell = "1.9"
|
||||
xdg = "2.4"
|
||||
pretty_env_logger = "0.4"
|
||||
calloop = "0.10"
|
||||
nix = "0.26"
|
||||
shlex = "1.1.0"
|
||||
anyhow = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
log = "0.4"
|
||||
tokio = { version = "1.17.0", features = ["sync", "rt", "rt-multi-thread", "macros", "process"] }
|
||||
itertools = "*"
|
||||
freedesktop-desktop-entry = "0.5.0"
|
||||
freedesktop-icons = { git = "https://github.com/wash2/freedestkop-icons" }
|
||||
i18n-embed = { version = "0.13", features = ["fluent-system", "desktop-requester"] }
|
||||
i18n-embed-fl = "0.6"
|
||||
rust-embed = "6.3"
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Dock App List
|
||||
Comment=Write a GTK + Rust application
|
||||
Type=Application
|
||||
Exec=cosmic-app-list
|
||||
Terminal=false
|
||||
Categories=GNOME;GTK;
|
||||
Keywords=Gnome;GTK;
|
||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||
Icon=com.system76.CosmicAppList.svg
|
||||
StartupNotify=true
|
||||
NoDisplay=true
|
||||
X-HostWaylandDisplay=true
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Ashley Wulber 2019 <ashley@system76.com> -->
|
||||
<component type="desktop-application">
|
||||
<id>"com.system76.CosmicAppList"</id>
|
||||
<metadata_license>CC0</metadata_license>
|
||||
<project_license>MPL</project_license>
|
||||
<name>Cosmic Dock App List</name>
|
||||
<summary>Write a GTK + Rust application</summary>
|
||||
<description>
|
||||
<p>A boilerplate template for GTK + Rust. It uses Meson as a build system and has flatpak support by default.</p>
|
||||
</description>
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
<image>https://gitlab.gnome.org/bilelmoussaoui/cosmic-app-list/raw/master/data/resources/screenshots/screenshot1.png</image>
|
||||
<caption>Main window</caption>
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
<url type="homepage">https://gitlab.gnome.org/bilelmoussaoui/cosmic-app-list</url>
|
||||
<url type="bugtracker">https://gitlab.gnome.org/bilelmoussaoui/cosmic-app-list/issues</url>
|
||||
<content_rating type="oars-1.0" />
|
||||
<releases>
|
||||
<release version="0.0.1" date="2019-07-11" />
|
||||
</releases>
|
||||
<kudos>
|
||||
<!--
|
||||
GNOME Software kudos:
|
||||
https://gitlab.gnome.org/GNOME/gnome-software/blob/master/doc/kudos.md
|
||||
-->
|
||||
<kudo>ModernToolkit</kudo>
|
||||
<kudo>HiDpiIcon</kudo>
|
||||
</kudos>
|
||||
<developer_name>Ashley Wulber</developer_name>
|
||||
<update_contact>ashley@system76.com</update_contact>
|
||||
<launchable type="desktop-id">"com.System76.CosmicAppList".desktop</launchable>
|
||||
</component>
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16px" height="16px" viewBox="0 0 16 16" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="16" height="16" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10818" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="16" height="16" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10821" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="16" height="16" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10824" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="16" height="16" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10827" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10764">
|
||||
<rect x="0" y="0" width="16" height="16" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10818" transform="matrix(1,0,0,1,-168,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10821" transform="matrix(1,0,0,1,-168,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10824" transform="matrix(1,0,0,1,-168,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10827" transform="matrix(1,0,0,1,-168,-16)" mask="url(#mask3)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.3 KiB |
|
|
@ -1,147 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10726" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10729" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10732" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10735" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask5">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip7">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10726" clip-path="url(#clip7)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask6">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip8">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10729" clip-path="url(#clip8)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask7">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip9">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10732" clip-path="url(#clip9)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask8">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip10">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10735" clip-path="url(#clip10)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<clipPath id="clip6">
|
||||
<rect x="0" y="0" width="128" height="128"/>
|
||||
</clipPath>
|
||||
<g id="surface10750" clip-path="url(#clip6)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10726" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask5)"/>
|
||||
<use xlink:href="#surface10729" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask6)"/>
|
||||
<use xlink:href="#surface10732" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask7)"/>
|
||||
<use xlink:href="#surface10735" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask8)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
<clipPath id="clip5">
|
||||
<rect x="0" y="0" width="128" height="128"/>
|
||||
</clipPath>
|
||||
<g id="surface10753" clip-path="url(#clip5)" filter="url(#alpha)">
|
||||
<use xlink:href="#surface10750"/>
|
||||
</g>
|
||||
<mask id="mask4">
|
||||
<use xlink:href="#surface10753"/>
|
||||
</mask>
|
||||
<mask id="mask9">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.8;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<linearGradient id="linear0" gradientUnits="userSpaceOnUse" x1="300" y1="235" x2="428" y2="235" gradientTransform="matrix(0.000000000000000023,0.37,-0.98462,0.00000000000000006,295.38501,-30.360001)">
|
||||
<stop offset="0" style="stop-color:rgb(97.647059%,94.117647%,41.960785%);stop-opacity:1;"/>
|
||||
<stop offset="1" style="stop-color:rgb(96.078432%,76.078433%,6.666667%);stop-opacity:1;"/>
|
||||
</linearGradient>
|
||||
<clipPath id="clip12">
|
||||
<rect x="0" y="0" width="128" height="128"/>
|
||||
</clipPath>
|
||||
<g id="surface10747" clip-path="url(#clip12)">
|
||||
<path style=" stroke:none;fill-rule:nonzero;fill:url(#linear0);" d="M 128 80.640625 L 128 128 L 0 128 L 0 80.640625 Z M 128 80.640625 "/>
|
||||
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(0%,0%,0%);fill-opacity:1;" d="M 13.308594 80.640625 L 60.664062 128 L 81.878906 128 L 34.519531 80.640625 Z M 55.730469 80.640625 L 103.09375 128 L 124.308594 128 L 76.945312 80.640625 Z M 98.160156 80.640625 L 128 110.480469 L 128 89.269531 L 119.371094 80.640625 Z M 0 88.546875 L 0 109.761719 L 18.238281 128 L 39.453125 128 Z M 0 88.546875 "/>
|
||||
</g>
|
||||
<clipPath id="clip11">
|
||||
<rect x="0" y="0" width="128" height="128"/>
|
||||
</clipPath>
|
||||
<g id="surface10752" clip-path="url(#clip11)">
|
||||
<use xlink:href="#surface10747" mask="url(#mask9)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10672">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10726" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10729" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10732" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10735" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
<use xlink:href="#surface10752" mask="url(#mask4)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 10 KiB |
|
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10632" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10635" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10638" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10641" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10578">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
|
@ -1,4 +0,0 @@
|
|||
fallback_language = "en"
|
||||
|
||||
[fluent]
|
||||
assets_dir = "i18n"
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
cosmic-app-list = Cosmic Dock App List
|
||||
favorite = Favorite
|
||||
unfavorite = Un-Favorite
|
||||
quit = Quit
|
||||
quit-all = Quit All
|
||||
new-window = New Window
|
||||
|
|
@ -1 +0,0 @@
|
|||
cosmic-app-list = Liste des applictions COSMIC
|
||||
|
|
@ -1 +0,0 @@
|
|||
cosmic-app-list = 코스믹 독 프로그램 목록
|
||||
|
|
@ -1,613 +0,0 @@
|
|||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::config;
|
||||
use crate::config::AppListConfig;
|
||||
use crate::fl;
|
||||
use crate::toplevel_subscription::toplevel_subscription;
|
||||
use crate::toplevel_subscription::ToplevelRequest;
|
||||
use crate::toplevel_subscription::ToplevelUpdate;
|
||||
use calloop::channel::Sender;
|
||||
use cctk::toplevel_info::ToplevelInfo;
|
||||
use cctk::wayland_client::protocol::wl_seat::WlSeat;
|
||||
use cosmic::applet::cosmic_panel_config::PanelAnchor;
|
||||
use cosmic::applet::CosmicAppletHelper;
|
||||
use cosmic::iced;
|
||||
use cosmic::iced::wayland::popup::destroy_popup;
|
||||
use cosmic::iced::wayland::popup::get_popup;
|
||||
use cosmic::iced::wayland::SurfaceIdWrapper;
|
||||
use cosmic::iced::widget::mouse_listener;
|
||||
use cosmic::iced::widget::{column, row};
|
||||
use cosmic::iced::{executor, window, Application, Command, Subscription};
|
||||
use cosmic::iced_native::alignment::Horizontal;
|
||||
use cosmic::iced_native::subscription::events_with;
|
||||
use cosmic::iced_style::application::{self, Appearance};
|
||||
use cosmic::iced_style::Color;
|
||||
use cosmic::theme::Button;
|
||||
use cosmic::widget::rectangle_tracker::rectangle_tracker_subscription;
|
||||
use cosmic::widget::rectangle_tracker::RectangleTracker;
|
||||
use cosmic::widget::rectangle_tracker::RectangleUpdate;
|
||||
use cosmic::widget::{horizontal_rule, vertical_rule};
|
||||
use cosmic::{Element, Theme};
|
||||
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;
|
||||
use freedesktop_desktop_entry::DesktopEntry;
|
||||
use iced::wayland::window::resize_window;
|
||||
use iced::widget::container;
|
||||
use iced::widget::horizontal_space;
|
||||
use iced::widget::svg;
|
||||
use iced::widget::Image;
|
||||
use iced::Alignment;
|
||||
use iced::Background;
|
||||
use iced::Length;
|
||||
use itertools::Itertools;
|
||||
|
||||
pub fn run() -> cosmic::iced::Result {
|
||||
let helper = CosmicAppletHelper::default();
|
||||
CosmicAppList::run(helper.window_settings())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
struct Toplevel {
|
||||
id: u32,
|
||||
toplevels: Vec<(ZcosmicToplevelHandleV1, ToplevelInfo)>,
|
||||
desktop_info: DesktopInfo,
|
||||
popup: Option<window::Id>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct CosmicAppList {
|
||||
theme: Theme,
|
||||
popup: Option<window::Id>,
|
||||
surface_id_ctr: u32,
|
||||
subscription_ctr: u32,
|
||||
toplevel_ctr: u32,
|
||||
toplevel_list: Vec<Toplevel>,
|
||||
config: AppListConfig,
|
||||
toplevel_sender: Option<Sender<ToplevelRequest>>,
|
||||
applet_helper: CosmicAppletHelper,
|
||||
seat: Option<WlSeat>,
|
||||
rectangle_tracker: Option<RectangleTracker<u32>>,
|
||||
rectangles: HashMap<u32, iced::Rectangle>,
|
||||
}
|
||||
|
||||
impl CosmicAppList {
|
||||
fn window_size(&self) -> (u32, u32) {
|
||||
let pixel_size = self.applet_helper.suggested_size().0;
|
||||
let padding = 8;
|
||||
let dot_size = 4;
|
||||
let spacing = 4;
|
||||
let mut length = self
|
||||
.toplevel_list
|
||||
.iter()
|
||||
.map(|t| {
|
||||
(pixel_size + 2 * padding).max((dot_size + spacing) * t.toplevels.len() as u16)
|
||||
as u32
|
||||
+ spacing as u32
|
||||
})
|
||||
.sum();
|
||||
length += spacing as u32 * 2 + 2;
|
||||
let thickness = (pixel_size + 2 * padding + dot_size + spacing) as u32;
|
||||
match self.applet_helper.anchor {
|
||||
PanelAnchor::Left | PanelAnchor::Right => (thickness, length),
|
||||
PanelAnchor::Top | PanelAnchor::Bottom => (length, thickness),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO DnD after sctk merges DnD
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
Toplevel(ToplevelUpdate),
|
||||
Favorite(String),
|
||||
UnFavorite(String),
|
||||
Popup(String),
|
||||
ClosePopup,
|
||||
Activate(ZcosmicToplevelHandleV1),
|
||||
Exec(String),
|
||||
Quit(String),
|
||||
Errored(String),
|
||||
Ignore,
|
||||
NewSeat(WlSeat),
|
||||
RemovedSeat(WlSeat),
|
||||
Rectangle(RectangleUpdate<u32>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
struct DesktopInfo {
|
||||
id: String,
|
||||
icon: PathBuf,
|
||||
exec: String,
|
||||
name: String,
|
||||
}
|
||||
|
||||
fn desktop_info_for_app_ids(mut app_ids: Vec<String>) -> Vec<DesktopInfo> {
|
||||
let mut ret = freedesktop_desktop_entry::Iter::new(freedesktop_desktop_entry::default_paths())
|
||||
.filter_map(|path| {
|
||||
std::fs::read_to_string(&path).ok().and_then(|input| {
|
||||
DesktopEntry::decode(&path, &input).ok().and_then(|de| {
|
||||
if let Some(i) = app_ids
|
||||
.iter()
|
||||
.position(|s| s == de.appid || s.eq(&de.name(None).unwrap_or_default()))
|
||||
{
|
||||
let id = app_ids.remove(i);
|
||||
freedesktop_icons::lookup(de.icon().unwrap_or(de.appid))
|
||||
.with_size(128)
|
||||
.with_cache()
|
||||
.find()
|
||||
.map(|buf| DesktopInfo {
|
||||
id,
|
||||
icon: buf,
|
||||
exec: de.exec().unwrap_or_default().to_string(),
|
||||
name: de.name(None).unwrap_or_default().to_string(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
.collect_vec();
|
||||
ret.append(
|
||||
&mut app_ids
|
||||
.into_iter()
|
||||
.map(|id| DesktopInfo {
|
||||
id,
|
||||
..Default::default()
|
||||
})
|
||||
.collect_vec(),
|
||||
);
|
||||
ret
|
||||
}
|
||||
|
||||
impl Application for CosmicAppList {
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Executor = executor::Default;
|
||||
type Flags = ();
|
||||
|
||||
fn new(_flags: ()) -> (Self, Command<Message>) {
|
||||
let config = config::AppListConfig::load().unwrap_or_default();
|
||||
let mut toplevel_ctr = 0;
|
||||
let self_ = CosmicAppList {
|
||||
toplevel_list: desktop_info_for_app_ids(config.favorites.clone())
|
||||
.into_iter()
|
||||
.map(|e| {
|
||||
toplevel_ctr += 1;
|
||||
Toplevel {
|
||||
id: toplevel_ctr,
|
||||
toplevels: Default::default(),
|
||||
desktop_info: e,
|
||||
popup: None,
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
config,
|
||||
toplevel_ctr,
|
||||
..Default::default()
|
||||
};
|
||||
let (w, h) = self_.window_size();
|
||||
|
||||
(self_, resize_window(window::Id::new(0), w, h))
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
config::APP_ID.to_string()
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::Errored(_) => {
|
||||
// TODO log errors
|
||||
}
|
||||
Message::Popup(id) => {
|
||||
if let Some(toplevel_group) = self
|
||||
.toplevel_list
|
||||
.iter_mut()
|
||||
.find(|t| t.desktop_info.id == id)
|
||||
{
|
||||
if let Some(p) = self.popup.take() {
|
||||
toplevel_group.popup.take();
|
||||
return destroy_popup(p);
|
||||
}
|
||||
let rectangle = match self.rectangles.get(&toplevel_group.id) {
|
||||
Some(r) => r,
|
||||
None => return Command::none(),
|
||||
};
|
||||
|
||||
self.surface_id_ctr += 1;
|
||||
let new_id = window::Id::new(self.surface_id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
toplevel_group.popup.replace(new_id);
|
||||
|
||||
let mut popup_settings = self.applet_helper.get_popup_settings(
|
||||
window::Id::new(0),
|
||||
new_id,
|
||||
(240, 240 + toplevel_group.toplevels.len() as u32 * 24),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
let iced::Rectangle {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
} = *rectangle;
|
||||
popup_settings.positioner.anchor_rect = iced::Rectangle::<i32> {
|
||||
x: x as i32,
|
||||
y: y as i32,
|
||||
width: width as i32,
|
||||
height: height as i32,
|
||||
};
|
||||
return get_popup(popup_settings);
|
||||
}
|
||||
}
|
||||
Message::Favorite(id) => {
|
||||
let _ = self.config.add_favorite(id);
|
||||
}
|
||||
Message::UnFavorite(id) => {
|
||||
let _ = self.config.remove_favorite(id);
|
||||
self.toplevel_list.retain(|t| {
|
||||
self.config.favorites.contains(&t.desktop_info.id)
|
||||
|| self.config.favorites.contains(&t.desktop_info.name)
|
||||
})
|
||||
}
|
||||
Message::Activate(handle) => {
|
||||
if let (Some(tx), Some(seat)) = (self.toplevel_sender.as_ref(), self.seat.as_ref())
|
||||
{
|
||||
let _ = tx.send(ToplevelRequest::Activate(handle, seat.clone()));
|
||||
}
|
||||
}
|
||||
Message::Quit(id) => {
|
||||
if let Some(toplevel_group) =
|
||||
self.toplevel_list.iter().find(|t| t.desktop_info.id == id)
|
||||
{
|
||||
for (handle, _) in &toplevel_group.toplevels {
|
||||
if let Some(tx) = self.toplevel_sender.as_ref() {
|
||||
let _ = tx.send(ToplevelRequest::Quit(handle.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::Toplevel(event) => {
|
||||
match event {
|
||||
ToplevelUpdate::AddToplevel(handle, info) => {
|
||||
if info.app_id == "" {
|
||||
return Command::none();
|
||||
}
|
||||
if let Some(i) = self.toplevel_list.iter().position(
|
||||
|Toplevel { desktop_info, .. }| &desktop_info.id == &info.app_id,
|
||||
) {
|
||||
self.toplevel_list[i].toplevels.push((handle, info));
|
||||
} else {
|
||||
let desktop_info =
|
||||
desktop_info_for_app_ids(vec![info.app_id.clone()]).remove(0);
|
||||
self.toplevel_ctr += 1;
|
||||
self.toplevel_list.push(Toplevel {
|
||||
id: self.toplevel_ctr,
|
||||
toplevels: vec![(handle, info)],
|
||||
desktop_info,
|
||||
popup: None,
|
||||
});
|
||||
|
||||
let (w, h) = self.window_size();
|
||||
return resize_window(window::Id::new(0), w, h);
|
||||
}
|
||||
}
|
||||
ToplevelUpdate::Init(tx) => {
|
||||
self.toplevel_sender.replace(tx);
|
||||
}
|
||||
ToplevelUpdate::Finished => {
|
||||
self.subscription_ctr += 1;
|
||||
for t in &mut self.toplevel_list {
|
||||
t.toplevels.clear();
|
||||
}
|
||||
}
|
||||
ToplevelUpdate::RemoveToplevel(handle) => {
|
||||
if let Some(i) = self.toplevel_list.iter_mut().position(
|
||||
|Toplevel {
|
||||
toplevels,
|
||||
desktop_info,
|
||||
..
|
||||
}| {
|
||||
if let Some(ret) = toplevels.iter().position(|t| &t.0 == &handle) {
|
||||
toplevels.remove(ret);
|
||||
toplevels.is_empty()
|
||||
&& !self.config.favorites.contains(&desktop_info.id)
|
||||
&& !self.config.favorites.contains(&desktop_info.name)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
) {
|
||||
self.toplevel_list.remove(i);
|
||||
}
|
||||
let (w, h) = self.window_size();
|
||||
return resize_window(window::Id::new(0), w, h);
|
||||
}
|
||||
ToplevelUpdate::UpdateToplevel(handle, info) => {
|
||||
// TODO probably want to make sure it is removed
|
||||
if info.app_id == "" {
|
||||
return Command::none();
|
||||
}
|
||||
'toplevel_loop: for toplevel_list in &mut self.toplevel_list {
|
||||
for (t_handle, t_info) in &mut toplevel_list.toplevels {
|
||||
if &handle == t_handle {
|
||||
*t_info = info;
|
||||
break 'toplevel_loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
let (w, h) = self.window_size();
|
||||
return resize_window(window::Id::new(0), w, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::NewSeat(s) => {
|
||||
self.seat.replace(s);
|
||||
}
|
||||
Message::RemovedSeat(_) => {
|
||||
self.seat.take();
|
||||
}
|
||||
Message::Exec(exec_str) => {
|
||||
let mut exec = shlex::Shlex::new(&exec_str);
|
||||
let mut cmd = match exec.next() {
|
||||
Some(cmd) if !cmd.contains("=") => tokio::process::Command::new(cmd),
|
||||
_ => return Command::none(),
|
||||
};
|
||||
for arg in exec {
|
||||
// TODO handle "%" args here if necessary?
|
||||
if !arg.starts_with("%") {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
}
|
||||
let _ = cmd.spawn();
|
||||
}
|
||||
Message::Rectangle(u) => match u {
|
||||
RectangleUpdate::Rectangle(r) => {
|
||||
self.rectangles.insert(r.0, r.1);
|
||||
}
|
||||
RectangleUpdate::Init(tracker) => {
|
||||
self.rectangle_tracker.replace(tracker);
|
||||
}
|
||||
},
|
||||
Message::Ignore => {}
|
||||
Message::ClosePopup => {
|
||||
if let Some(p) = self.popup.take() {
|
||||
if let Some(toplevel_group) =
|
||||
self.toplevel_list.iter_mut().find(|t| t.popup == Some(p))
|
||||
{
|
||||
toplevel_group.popup.take();
|
||||
}
|
||||
return destroy_popup(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
Command::none()
|
||||
}
|
||||
|
||||
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Window(_) => {
|
||||
let (favorites, running) = self.toplevel_list.iter().fold(
|
||||
(Vec::new(), Vec::new()),
|
||||
|(mut favorites, mut running),
|
||||
Toplevel {
|
||||
id,
|
||||
toplevels,
|
||||
desktop_info,
|
||||
..
|
||||
}| {
|
||||
let icon = if desktop_info.icon.extension() == Some(&OsStr::new("svg")) {
|
||||
let handle = svg::Handle::from_path(&desktop_info.icon);
|
||||
svg::Svg::new(handle)
|
||||
.width(Length::Units(self.applet_helper.suggested_size().0))
|
||||
.height(Length::Units(self.applet_helper.suggested_size().0))
|
||||
.into()
|
||||
} else {
|
||||
Image::new(&desktop_info.icon)
|
||||
.width(Length::Units(self.applet_helper.suggested_size().0))
|
||||
.height(Length::Units(self.applet_helper.suggested_size().0))
|
||||
.into()
|
||||
};
|
||||
let dot_radius = 2;
|
||||
let dots = (0..toplevels.len())
|
||||
.into_iter()
|
||||
.map(|_| {
|
||||
container(horizontal_space(Length::Units(0)))
|
||||
.padding(dot_radius)
|
||||
.style(<Self::Theme as container::StyleSheet>::Style::Custom(
|
||||
|theme| container::Appearance {
|
||||
text_color: Some(Color::TRANSPARENT),
|
||||
background: Some(Background::Color(
|
||||
theme.cosmic().on_bg_color().into(),
|
||||
)),
|
||||
border_radius: 4.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
))
|
||||
.into()
|
||||
})
|
||||
.collect_vec();
|
||||
|
||||
let icon_wrapper = match &self.applet_helper.anchor {
|
||||
PanelAnchor::Left => row(vec![column(dots).spacing(4).into(), icon])
|
||||
.align_items(iced::Alignment::Center)
|
||||
.spacing(4)
|
||||
.into(),
|
||||
PanelAnchor::Right => row(vec![icon, column(dots).spacing(4).into()])
|
||||
.align_items(iced::Alignment::Center)
|
||||
.spacing(4)
|
||||
.into(),
|
||||
PanelAnchor::Top => column(vec![row(dots).spacing(4).into(), icon])
|
||||
.align_items(iced::Alignment::Center)
|
||||
.spacing(4)
|
||||
.into(),
|
||||
PanelAnchor::Bottom => column(vec![icon, row(dots).spacing(4).into()])
|
||||
.align_items(iced::Alignment::Center)
|
||||
.spacing(4)
|
||||
.into(),
|
||||
};
|
||||
let mut icon_button = cosmic::widget::button(Button::Text)
|
||||
.custom(vec![icon_wrapper])
|
||||
.padding(8);
|
||||
if self.popup.is_none() {
|
||||
icon_button = icon_button.on_press(
|
||||
toplevels
|
||||
.first()
|
||||
.map(|t| Message::Activate(t.0.clone()))
|
||||
.unwrap_or_else(|| Message::Exec(desktop_info.exec.clone())),
|
||||
);
|
||||
}
|
||||
|
||||
// TODO tooltip on hover
|
||||
let icon_button = mouse_listener(icon_button.width(Length::Shrink).height(Length::Shrink))
|
||||
.on_right_release(Message::Popup(desktop_info.id.clone()));
|
||||
let icon_button = if let Some(tracker) = self.rectangle_tracker.as_ref() {
|
||||
tracker.container(*id, icon_button).into()
|
||||
} else {
|
||||
icon_button.into()
|
||||
};
|
||||
if self.config.favorites.contains(&desktop_info.id)
|
||||
|| self.config.favorites.contains(&desktop_info.name)
|
||||
{
|
||||
favorites.push(icon_button)
|
||||
} else {
|
||||
running.push(icon_button);
|
||||
}
|
||||
(favorites, running)
|
||||
},
|
||||
);
|
||||
|
||||
let content = match &self.applet_helper.anchor {
|
||||
PanelAnchor::Left | PanelAnchor::Right => container(
|
||||
column![column(favorites), horizontal_rule(1), column(running)]
|
||||
.spacing(4)
|
||||
.align_items(Alignment::Center)
|
||||
.height(Length::Fill)
|
||||
.width(Length::Fill),
|
||||
),
|
||||
PanelAnchor::Top | PanelAnchor::Bottom => container(
|
||||
row![row(favorites), vertical_rule(1), row(running)]
|
||||
.spacing(4)
|
||||
.align_items(Alignment::Center)
|
||||
.height(Length::Fill)
|
||||
.width(Length::Fill),
|
||||
).height(Length::Fill).width(Length::Fill),
|
||||
};
|
||||
if self.popup.is_some() {
|
||||
mouse_listener(content)
|
||||
.on_right_press(Message::ClosePopup)
|
||||
.on_press(Message::ClosePopup)
|
||||
.into()
|
||||
} else {
|
||||
content.into()
|
||||
}
|
||||
}
|
||||
SurfaceIdWrapper::Popup(p) => {
|
||||
if let Some(Toplevel {
|
||||
toplevels,
|
||||
desktop_info,
|
||||
..
|
||||
}) = self.toplevel_list.iter().find(|t| t.popup == Some(p))
|
||||
{
|
||||
let is_favorite = self.config.favorites.contains(&desktop_info.id)
|
||||
|| self.config.favorites.contains(&desktop_info.name);
|
||||
|
||||
let mut content = column![
|
||||
iced::widget::text(&desktop_info.name)
|
||||
.horizontal_alignment(Horizontal::Center),
|
||||
cosmic::widget::button(Button::Text)
|
||||
.custom(vec![iced::widget::text(fl!("new-window")).into()])
|
||||
.on_press(Message::Exec(desktop_info.exec.clone())),
|
||||
]
|
||||
.padding(8)
|
||||
.spacing(4)
|
||||
.align_items(Alignment::Center);
|
||||
if !toplevels.is_empty() {
|
||||
let mut list_col = column![];
|
||||
for (handle, info) in toplevels {
|
||||
let title = if info.title.len() > 20 {
|
||||
format!("{:.24}...", &info.title)
|
||||
} else {
|
||||
info.title.clone()
|
||||
};
|
||||
list_col = list_col.push(
|
||||
cosmic::widget::button(Button::Text)
|
||||
.custom(vec![iced::widget::text(title).into()])
|
||||
.on_press(Message::Activate(handle.clone())),
|
||||
);
|
||||
}
|
||||
content = content.push(horizontal_rule(1));
|
||||
content = content.push(list_col);
|
||||
content = content.push(horizontal_rule(1));
|
||||
}
|
||||
content = content.push(if is_favorite {
|
||||
cosmic::widget::button(Button::Text)
|
||||
.custom(vec![iced::widget::text(fl!("unfavorite")).into()])
|
||||
.on_press(Message::UnFavorite(desktop_info.id.clone()))
|
||||
} else {
|
||||
cosmic::widget::button(Button::Text)
|
||||
.custom(vec![iced::widget::text(fl!("favorite")).into()])
|
||||
.on_press(Message::Favorite(desktop_info.id.clone()))
|
||||
});
|
||||
|
||||
if toplevels.len() == 1 {
|
||||
content = content.push(
|
||||
cosmic::widget::button(Button::Text)
|
||||
.custom(vec![iced::widget::text(fl!("quit")).into()])
|
||||
.on_press(Message::Quit(desktop_info.id.clone())),
|
||||
)
|
||||
} else if toplevels.len() > 1 {
|
||||
content = content.push(
|
||||
cosmic::widget::button(Button::Text)
|
||||
.custom(vec![iced::widget::text(&fl!("quit-all")).into()])
|
||||
.on_press(Message::Quit(desktop_info.id.clone())),
|
||||
)
|
||||
}
|
||||
return self.applet_helper.popup_container(content).into();
|
||||
}
|
||||
return horizontal_space(Length::Units(1)).into();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
Subscription::batch(vec![
|
||||
toplevel_subscription(self.subscription_ctr).map(|(_, event)| Message::Toplevel(event)),
|
||||
events_with(|e, _| match e {
|
||||
cosmic::iced_native::Event::PlatformSpecific(
|
||||
cosmic::iced_native::event::PlatformSpecific::Wayland(
|
||||
cosmic::iced_native::event::wayland::Event::Seat(e, seat),
|
||||
),
|
||||
) => match e {
|
||||
cosmic::iced_native::event::wayland::SeatEvent::Enter => {
|
||||
Some(Message::NewSeat(seat))
|
||||
}
|
||||
cosmic::iced_native::event::wayland::SeatEvent::Leave => {
|
||||
Some(Message::RemovedSeat(seat))
|
||||
}
|
||||
},
|
||||
_ => None,
|
||||
}),
|
||||
rectangle_tracker_subscription(0).map(|(_, update)| Message::Rectangle(update)),
|
||||
])
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
}
|
||||
|
||||
fn close_requested(&self, _id: SurfaceIdWrapper) -> Self::Message {
|
||||
Message::Ignore
|
||||
}
|
||||
|
||||
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
|
||||
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||
text_color: theme.cosmic().on_bg_color().into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
(
|
||||
filter_top_levels: None,
|
||||
favorites: [],
|
||||
)
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
use anyhow::anyhow;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Debug;
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use xdg::BaseDirectories;
|
||||
|
||||
pub const APP_ID: &str = "com.system76.CosmicAppList";
|
||||
pub const VERSION: &str = "0.1.0";
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
|
||||
pub enum TopLevelFilter {
|
||||
#[default]
|
||||
ActiveWorkspace,
|
||||
ConfiguredOutput,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
pub struct AppListConfig {
|
||||
pub filter_top_levels: Option<TopLevelFilter>,
|
||||
pub favorites: Vec<String>,
|
||||
}
|
||||
|
||||
impl AppListConfig {
|
||||
// TODO async?
|
||||
/// load config with the provided name
|
||||
pub fn load() -> anyhow::Result<AppListConfig> {
|
||||
let mut relative_path = PathBuf::from(APP_ID);
|
||||
relative_path.push("config.ron");
|
||||
let file = match BaseDirectories::new()
|
||||
.ok()
|
||||
.and_then(|dirs| dirs.find_config_file(relative_path))
|
||||
.and_then(|p| File::open(p).ok())
|
||||
{
|
||||
Some(path) => path,
|
||||
_ => {
|
||||
anyhow::bail!("Failed to load config");
|
||||
}
|
||||
};
|
||||
|
||||
ron::de::from_reader::<_, AppListConfig>(file)
|
||||
.map_err(|err| anyhow!("Failed to parse config file: {}", err))
|
||||
}
|
||||
|
||||
pub fn add_favorite(&mut self, id: String) -> anyhow::Result<()> {
|
||||
if !self.favorites.contains(&id) {
|
||||
self.favorites.push(id);
|
||||
}
|
||||
self.save()
|
||||
}
|
||||
|
||||
pub fn remove_favorite(&mut self, id: String) -> anyhow::Result<()> {
|
||||
self.favorites.retain(|e| e != &id);
|
||||
self.save()
|
||||
}
|
||||
|
||||
// TODO async?
|
||||
pub fn save(&self) -> anyhow::Result<()> {
|
||||
let bd = BaseDirectories::new()?;
|
||||
let mut relative_path = PathBuf::from(APP_ID);
|
||||
relative_path.push("config.ron");
|
||||
let config_path = bd.place_config_file(relative_path)?;
|
||||
let f = File::create(config_path)?;
|
||||
ron::ser::to_writer_pretty(f, self, Default::default())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
// SPDX-License-Identifier: MPL-2.0-only
|
||||
|
||||
use i18n_embed::{
|
||||
fluent::{fluent_language_loader, FluentLanguageLoader},
|
||||
DefaultLocalizer, LanguageLoader, Localizer,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "i18n/"]
|
||||
struct Localizations;
|
||||
|
||||
pub static LANGUAGE_LOADER: Lazy<FluentLanguageLoader> = Lazy::new(|| {
|
||||
let loader: FluentLanguageLoader = fluent_language_loader!();
|
||||
|
||||
loader
|
||||
.load_fallback_language(&Localizations)
|
||||
.expect("Error while loading fallback language");
|
||||
|
||||
loader
|
||||
});
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! fl {
|
||||
($message_id:literal) => {{
|
||||
i18n_embed_fl::fl!($crate::localize::LANGUAGE_LOADER, $message_id)
|
||||
}};
|
||||
|
||||
($message_id:literal, $($args:expr),*) => {{
|
||||
i18n_embed_fl::fl!($crate::localize::LANGUAGE_LOADER, $message_id, $($args), *)
|
||||
}};
|
||||
}
|
||||
|
||||
// Get the `Localizer` to be used for localizing this library.
|
||||
pub fn localizer() -> Box<dyn Localizer> {
|
||||
Box::from(DefaultLocalizer::new(&*LANGUAGE_LOADER, &Localizations))
|
||||
}
|
||||
|
||||
pub fn localize() {
|
||||
let localizer = crate::localize::localizer();
|
||||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// SPDX-License-Identifier: MPL-2.0-only
|
||||
mod app;
|
||||
mod config;
|
||||
mod localize;
|
||||
mod toplevel_handler;
|
||||
mod toplevel_subscription;
|
||||
|
||||
use log::info;
|
||||
|
||||
use localize::localize;
|
||||
|
||||
use crate::config::{APP_ID, VERSION};
|
||||
|
||||
fn main() -> cosmic::iced::Result {
|
||||
// Initialize logger
|
||||
pretty_env_logger::init();
|
||||
info!("Iced Workspaces Applet ({})", APP_ID);
|
||||
info!("Version: {}", VERSION);
|
||||
// Prepare i18n
|
||||
localize();
|
||||
|
||||
app::run()
|
||||
}
|
||||
|
|
@ -1,187 +0,0 @@
|
|||
use crate::toplevel_subscription::{ToplevelRequest, ToplevelUpdate};
|
||||
use cctk::{
|
||||
sctk::{
|
||||
self,
|
||||
event_loop::WaylandSource,
|
||||
reexports::client::protocol::wl_seat::WlSeat,
|
||||
seat::{SeatHandler, SeatState},
|
||||
},
|
||||
toplevel_info::{ToplevelInfoHandler, ToplevelInfoState},
|
||||
toplevel_management::{ToplevelManagerHandler, ToplevelManagerState},
|
||||
wayland_client::{self, WEnum},
|
||||
};
|
||||
use cosmic_protocols::{
|
||||
toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
|
||||
toplevel_management::v1::client::zcosmic_toplevel_manager_v1,
|
||||
};
|
||||
use futures::channel::mpsc::UnboundedSender;
|
||||
use sctk::registry::{ProvidesRegistryState, RegistryState};
|
||||
use wayland_client::{globals::registry_queue_init, Connection, QueueHandle};
|
||||
|
||||
struct AppData {
|
||||
exit: bool,
|
||||
tx: UnboundedSender<ToplevelUpdate>,
|
||||
registry_state: RegistryState,
|
||||
toplevel_info_state: ToplevelInfoState,
|
||||
toplevel_manager_state: ToplevelManagerState,
|
||||
seat_state: SeatState,
|
||||
}
|
||||
|
||||
impl ProvidesRegistryState for AppData {
|
||||
fn registry(&mut self) -> &mut RegistryState {
|
||||
&mut self.registry_state
|
||||
}
|
||||
|
||||
sctk::registry_handlers!();
|
||||
}
|
||||
|
||||
impl SeatHandler for AppData {
|
||||
fn seat_state(&mut self) -> &mut sctk::seat::SeatState {
|
||||
&mut self.seat_state
|
||||
}
|
||||
|
||||
fn new_seat(&mut self, _: &Connection, _: &QueueHandle<Self>, _: WlSeat) {}
|
||||
|
||||
fn new_capability(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
_: WlSeat,
|
||||
_: sctk::seat::Capability,
|
||||
) {
|
||||
}
|
||||
|
||||
fn remove_capability(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
_: WlSeat,
|
||||
_: sctk::seat::Capability,
|
||||
) {
|
||||
}
|
||||
|
||||
fn remove_seat(&mut self, _: &Connection, _: &QueueHandle<Self>, _: WlSeat) {}
|
||||
}
|
||||
|
||||
impl ToplevelManagerHandler for AppData {
|
||||
fn toplevel_manager_state(&mut self) -> &mut cctk::toplevel_management::ToplevelManagerState {
|
||||
&mut self.toplevel_manager_state
|
||||
}
|
||||
|
||||
fn capabilities(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
_: Vec<WEnum<zcosmic_toplevel_manager_v1::ZcosmicToplelevelManagementCapabilitiesV1>>,
|
||||
) {
|
||||
// TODO capabilities could affect the options in the applet
|
||||
}
|
||||
}
|
||||
|
||||
impl ToplevelInfoHandler for AppData {
|
||||
fn toplevel_info_state(&mut self) -> &mut ToplevelInfoState {
|
||||
&mut self.toplevel_info_state
|
||||
}
|
||||
|
||||
fn new_toplevel(
|
||||
&mut self,
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
||||
) {
|
||||
if let Some(info) = self.toplevel_info_state.info(toplevel) {
|
||||
let _ = self
|
||||
.tx
|
||||
.unbounded_send(ToplevelUpdate::AddToplevel(toplevel.clone(), info.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
fn update_toplevel(
|
||||
&mut self,
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
||||
) {
|
||||
if let Some(info) = self.toplevel_info_state.info(toplevel) {
|
||||
let _ = self.tx.unbounded_send(ToplevelUpdate::UpdateToplevel(
|
||||
toplevel.clone(),
|
||||
info.clone(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn toplevel_closed(
|
||||
&mut self,
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
||||
) {
|
||||
let _ = self
|
||||
.tx
|
||||
.unbounded_send(ToplevelUpdate::RemoveToplevel(toplevel.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn toplevel_handler(
|
||||
tx: UnboundedSender<ToplevelUpdate>,
|
||||
rx: calloop::channel::Channel<ToplevelRequest>,
|
||||
) {
|
||||
let conn = Connection::connect_to_env().unwrap();
|
||||
let (globals, event_queue) = registry_queue_init(&conn).unwrap();
|
||||
let mut event_loop = calloop::EventLoop::<AppData>::try_new().unwrap();
|
||||
let qh = event_queue.handle();
|
||||
let wayland_source = WaylandSource::new(event_queue).unwrap();
|
||||
let handle = event_loop.handle();
|
||||
|
||||
if handle
|
||||
.insert_source(wayland_source, |_, q, state| q.dispatch_pending(state))
|
||||
.is_err()
|
||||
{
|
||||
return;
|
||||
};
|
||||
|
||||
if handle
|
||||
.insert_source(rx, |event, _, state| match event {
|
||||
calloop::channel::Event::Msg(req) => match req {
|
||||
ToplevelRequest::Activate(handle, seat) => {
|
||||
let manager = &state.toplevel_manager_state.manager;
|
||||
manager.activate(&handle, &seat);
|
||||
}
|
||||
ToplevelRequest::Quit(handle) => {
|
||||
let manager = &state.toplevel_manager_state.manager;
|
||||
manager.close(&handle);
|
||||
}
|
||||
ToplevelRequest::Exit => {
|
||||
state.exit = true;
|
||||
}
|
||||
},
|
||||
calloop::channel::Event::Closed => {
|
||||
state.exit = true;
|
||||
}
|
||||
})
|
||||
.is_err()
|
||||
{
|
||||
return;
|
||||
}
|
||||
let registry_state = RegistryState::new(&globals);
|
||||
let mut app_data = AppData {
|
||||
exit: false,
|
||||
tx,
|
||||
seat_state: SeatState::new(&globals, &qh),
|
||||
toplevel_info_state: ToplevelInfoState::new(®istry_state, &qh),
|
||||
toplevel_manager_state: ToplevelManagerState::new(®istry_state, &qh),
|
||||
registry_state,
|
||||
};
|
||||
|
||||
loop {
|
||||
if app_data.exit {
|
||||
break;
|
||||
}
|
||||
event_loop.dispatch(None, &mut app_data).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
sctk::delegate_seat!(AppData);
|
||||
sctk::delegate_registry!(AppData);
|
||||
cctk::delegate_toplevel_info!(AppData);
|
||||
cctk::delegate_toplevel_manager!(AppData);
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
//! # DBus interface proxy for: `org.freedesktop.UPower.KbdBacklight`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/UPower/KbdBacklight' from service 'org.freedesktop.UPower' on system bus`.
|
||||
use cctk::sctk::reexports::client::protocol::wl_seat::WlSeat;
|
||||
use cctk::toplevel_info::ToplevelInfo;
|
||||
use cosmic::iced;
|
||||
use cosmic::iced::subscription;
|
||||
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;
|
||||
use futures::{
|
||||
channel::mpsc::{unbounded, UnboundedReceiver},
|
||||
StreamExt,
|
||||
};
|
||||
use std::{fmt::Debug, hash::Hash};
|
||||
|
||||
use crate::toplevel_handler::toplevel_handler;
|
||||
|
||||
pub fn toplevel_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
||||
id: I,
|
||||
) -> iced::Subscription<(I, ToplevelUpdate)> {
|
||||
subscription::unfold(id, State::Ready, move |state| start_listening(id, state))
|
||||
}
|
||||
|
||||
pub enum State {
|
||||
Ready,
|
||||
Waiting(
|
||||
UnboundedReceiver<ToplevelUpdate>,
|
||||
calloop::channel::Sender<ToplevelRequest>,
|
||||
),
|
||||
Finished,
|
||||
}
|
||||
|
||||
async fn start_listening<I: Copy>(id: I, state: State) -> (Option<(I, ToplevelUpdate)>, State) {
|
||||
match state {
|
||||
State::Ready => {
|
||||
let (calloop_tx, calloop_rx) = calloop::channel::channel();
|
||||
let (toplevel_tx, toplevel_rx) = unbounded();
|
||||
std::thread::spawn(move || {
|
||||
toplevel_handler(toplevel_tx, calloop_rx);
|
||||
});
|
||||
return (
|
||||
Some((id, ToplevelUpdate::Init(calloop_tx.clone()))),
|
||||
State::Waiting(toplevel_rx, calloop_tx),
|
||||
);
|
||||
}
|
||||
State::Waiting(mut rx, tx) => match rx.next().await {
|
||||
Some(u) => (Some((id, u)), State::Waiting(rx, tx)),
|
||||
None => {
|
||||
let _ = tx.send(ToplevelRequest::Exit);
|
||||
(Some((id, ToplevelUpdate::Finished)), State::Finished)
|
||||
}
|
||||
},
|
||||
State::Finished => iced::futures::future::pending().await,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ToplevelUpdate {
|
||||
Finished,
|
||||
AddToplevel(ZcosmicToplevelHandleV1, ToplevelInfo),
|
||||
UpdateToplevel(ZcosmicToplevelHandleV1, ToplevelInfo),
|
||||
RemoveToplevel(ZcosmicToplevelHandleV1),
|
||||
Init(calloop::channel::Sender<ToplevelRequest>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ToplevelRequest {
|
||||
Activate(ZcosmicToplevelHandleV1, WlSeat),
|
||||
Quit(ZcosmicToplevelHandleV1),
|
||||
Exit,
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
// SPDX-License-Identifier: MPL-2.0-only
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use gtk4::glib;
|
||||
use std::future::Future;
|
||||
|
||||
use crate::wayland::Toplevel;
|
||||
|
||||
pub const DEST: &str = "com.System76.PopShell";
|
||||
pub const PATH: &str = "/com/System76/PopShell";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AppListEvent {
|
||||
WindowList(Vec<Toplevel>),
|
||||
Add(Toplevel),
|
||||
Remove(Toplevel),
|
||||
Favorite((String, bool)),
|
||||
Refresh,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, glib::Boxed)]
|
||||
#[boxed_type(name = "BoxedWindowList")]
|
||||
pub struct BoxedWindowList(pub Vec<Toplevel>);
|
||||
|
||||
pub fn data_path() -> PathBuf {
|
||||
let mut path = glib::user_data_dir();
|
||||
path.push(crate::ID);
|
||||
std::fs::create_dir_all(&path).expect("Could not create directory.");
|
||||
path.push("data.json");
|
||||
path
|
||||
}
|
||||
|
||||
pub fn thread_context() -> glib::MainContext {
|
||||
glib::MainContext::thread_default().unwrap_or_else(|| {
|
||||
let ctx = glib::MainContext::new();
|
||||
ctx
|
||||
})
|
||||
}
|
||||
|
||||
pub fn block_on<F>(future: F) -> F::Output
|
||||
where
|
||||
F: Future,
|
||||
{
|
||||
let ctx = thread_context();
|
||||
ctx.with_thread_default(|| ctx.block_on(future)).unwrap()
|
||||
}
|
||||
3165
applets/cosmic-applet-audio/Cargo.lock
generated
|
|
@ -1,33 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-applet-audio"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
icon-loader = { version = "0.3.6", features = ["gtk"] }
|
||||
libpulse-binding = "2.26.0"
|
||||
libpulse-glib-binding = "2.25.0"
|
||||
tokio = { version = "1.20.1", features=["full"] }
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
||||
iced_sctk = { git = "https://github.com/pop-os/iced-sctk" }
|
||||
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", version = "0.16" }
|
||||
|
||||
[workspace]
|
||||
resolved = "2"
|
||||
|
||||
[dependencies.iced]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
# path = "../iced"
|
||||
default-features = false
|
||||
features = ["image", "svg", "tokio", "wayland"]
|
||||
|
||||
[dependencies.iced_native]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
|
||||
[dependencies.iced_futures]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Applet Audio
|
||||
Comment=Write a GTK + Rust application
|
||||
Type=Application
|
||||
Exec=cosmic-applet-audio
|
||||
Terminal=false
|
||||
Categories=GNOME;GTK;
|
||||
Keywords=Gnome;GTK;
|
||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||
Icon=com.system76.CosmicAppletAudio.svg
|
||||
StartupNotify=true
|
||||
NoDisplay=true
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10632" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10635" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10638" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10641" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10578">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/com/System76/CosmicAppletAudio/">
|
||||
<!-- see https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Application.html#automatic-resources -->
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
@ -1,372 +0,0 @@
|
|||
use iced::widget::Space;
|
||||
|
||||
use cosmic::widget::{icon, toggler, horizontal_rule};
|
||||
use cosmic::applet::CosmicAppletHelper;
|
||||
use cosmic::Renderer;
|
||||
|
||||
use cosmic::iced_native::window::Settings;
|
||||
use cosmic::iced_style::application::{self, Appearance};
|
||||
use cosmic::iced_style::svg;
|
||||
use cosmic::theme::{self, Svg};
|
||||
use cosmic::{iced_style, settings, Element, Theme};
|
||||
use cosmic::iced::{
|
||||
executor,
|
||||
widget::{button, column, row, text, slider},
|
||||
window, Alignment, Application, Command, Length, Subscription,
|
||||
};
|
||||
|
||||
use iced_sctk::application::SurfaceIdWrapper;
|
||||
use iced_sctk::command::platform_specific::wayland::window::SctkWindowSettings;
|
||||
use iced_sctk::commands::popup::{destroy_popup, get_popup};
|
||||
use iced_sctk::settings::InitialSurface;
|
||||
use iced_sctk::Color;
|
||||
use iced_sctk::widget::container;
|
||||
|
||||
mod pulse;
|
||||
use crate::pulse::DeviceInfo;
|
||||
use libpulse_binding::volume::{Volume, VolumeLinear};
|
||||
|
||||
pub fn main() -> cosmic::iced::Result {
|
||||
let helper = CosmicAppletHelper::default();
|
||||
Audio::run(helper.window_settings())
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Audio {
|
||||
is_open: IsOpen,
|
||||
current_output: Option<DeviceInfo>,
|
||||
current_input: Option<DeviceInfo>,
|
||||
outputs: Vec<DeviceInfo>,
|
||||
inputs: Vec<DeviceInfo>,
|
||||
pulse_state: PulseState,
|
||||
applet_helper: CosmicAppletHelper,
|
||||
icon_name: String,
|
||||
theme: Theme,
|
||||
popup: Option<window::Id>,
|
||||
id_ctr: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum IsOpen {
|
||||
None,
|
||||
Output,
|
||||
Input,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
SetOutputVolume(f64),
|
||||
SetInputVolume(f64),
|
||||
OutputToggle,
|
||||
InputToggle,
|
||||
OutputChanged(String),
|
||||
InputChanged(String),
|
||||
Pulse(pulse::Event),
|
||||
Ignore,
|
||||
TogglePopup,
|
||||
}
|
||||
|
||||
impl Application for Audio {
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Executor = executor::Default;
|
||||
type Flags = ();
|
||||
|
||||
fn new(_flags: ()) -> (Audio, Command<Message>) {
|
||||
(
|
||||
Audio {
|
||||
is_open: IsOpen::None,
|
||||
current_output: None,
|
||||
current_input: None,
|
||||
outputs: vec![],
|
||||
inputs: vec![],
|
||||
pulse_state: PulseState::Disconnected,
|
||||
icon_name: "audio-volume-high-symbolic".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Audio")
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
}
|
||||
|
||||
fn close_requested(&self, _id: iced_sctk::application::SurfaceIdWrapper) -> Self::Message {
|
||||
Message::Ignore
|
||||
}
|
||||
|
||||
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
|
||||
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||
text_color: theme.cosmic().on_bg_color().into(),
|
||||
})
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::TogglePopup => {
|
||||
if let Some(p) = self.popup.take() {
|
||||
return destroy_popup(p);
|
||||
} else {
|
||||
self.id_ctr += 1;
|
||||
let new_id = window::Id::new(self.id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
|
||||
let popup_settings =
|
||||
self.applet_helper.get_popup_settings(window::Id::new(0), new_id, (400, 300), None, None);
|
||||
return get_popup(popup_settings);
|
||||
}
|
||||
}
|
||||
Message::SetOutputVolume(vol) => {
|
||||
self.current_output.as_mut().map(|o| {
|
||||
o.volume
|
||||
.set(o.volume.len(), VolumeLinear(vol / 100.0).into())
|
||||
});
|
||||
if let PulseState::Connected(connection) = &mut self.pulse_state {
|
||||
if let Some(device) = &self.current_output {
|
||||
if let Some(name) = &device.name {
|
||||
connection.send(pulse::Message::SetSinkVolumeByName(
|
||||
name.clone().to_string(),
|
||||
device.volume,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::SetInputVolume(vol) => {
|
||||
self.current_input.as_mut().map(|i| {
|
||||
i.volume
|
||||
.set(i.volume.len(), VolumeLinear(vol / 100.0).into())
|
||||
});
|
||||
if let PulseState::Connected(connection) = &mut self.pulse_state {
|
||||
if let Some(device) = &self.current_input {
|
||||
if let Some(name) = &device.name {
|
||||
println!("increasing volume of {}", name);
|
||||
connection.send(pulse::Message::SetSourceVolumeByName(
|
||||
name.clone().to_string(),
|
||||
device.volume,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::OutputChanged(val) => println!("changed output {}", val),
|
||||
Message::InputChanged(val) => println!("changed input {}", val),
|
||||
Message::OutputToggle => {
|
||||
self.is_open = if self.is_open == IsOpen::Output {
|
||||
IsOpen::None
|
||||
} else {
|
||||
IsOpen::Output
|
||||
}
|
||||
}
|
||||
Message::InputToggle => {
|
||||
self.is_open = if self.is_open == IsOpen::Input {
|
||||
IsOpen::None
|
||||
} else {
|
||||
IsOpen::Input
|
||||
}
|
||||
}
|
||||
Message::Pulse(event) => match event {
|
||||
pulse::Event::Connected(mut connection) => {
|
||||
connection.send(pulse::Message::GetSinks);
|
||||
connection.send(pulse::Message::GetSources);
|
||||
connection.send(pulse::Message::GetDefaultSink);
|
||||
connection.send(pulse::Message::GetDefaultSource);
|
||||
self.pulse_state = PulseState::Connected(connection);
|
||||
}
|
||||
pulse::Event::MessageReceived(msg) => {
|
||||
match msg {
|
||||
// This is where we match messages from the subscription to app state
|
||||
pulse::Message::SetSinks(sinks) => self.outputs = sinks,
|
||||
pulse::Message::SetSources(sources) => {
|
||||
self.inputs = sources
|
||||
.into_iter()
|
||||
.filter(|source| {
|
||||
!source
|
||||
.name
|
||||
.as_ref()
|
||||
.unwrap_or(&String::from("Generic"))
|
||||
.contains("monitor")
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
pulse::Message::SetDefaultSink(sink) => {
|
||||
self.current_output = Some(sink);
|
||||
}
|
||||
pulse::Message::SetDefaultSource(source) => {
|
||||
self.current_input = Some(source)
|
||||
}
|
||||
pulse::Message::Disconnected => {
|
||||
panic!("Subscriton error handling is bad. This should never happen.")
|
||||
}
|
||||
_ => {
|
||||
println!("Received misc message")
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: view() should gray out buttons/slider when state is disconnected
|
||||
pulse::Event::Disconnected => {
|
||||
println!("setting state to disconnected");
|
||||
self.pulse_state = PulseState::Disconnected
|
||||
}
|
||||
},
|
||||
Message::Ignore => {},
|
||||
};
|
||||
|
||||
Command::none()
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
pulse::connect().map(Message::Pulse)
|
||||
}
|
||||
|
||||
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Window(_) => self.applet_helper.icon_button(
|
||||
&self.icon_name,
|
||||
)
|
||||
.on_press(Message::TogglePopup)
|
||||
.into(),
|
||||
SurfaceIdWrapper::Popup(_) => {
|
||||
let out_f64 = VolumeLinear::from(
|
||||
self.current_output
|
||||
.as_ref()
|
||||
.map(|o| o.volume.avg())
|
||||
.unwrap_or(Volume::default()),
|
||||
)
|
||||
.0 * 100.0;
|
||||
let in_f64 = VolumeLinear::from(
|
||||
self.current_input
|
||||
.as_ref()
|
||||
.map(|o| o.volume.avg())
|
||||
.unwrap_or(Volume::default()),
|
||||
)
|
||||
.0 * 100.0;
|
||||
|
||||
let sink = row![
|
||||
icon("status/audio-volume-high-symbolic", 24),
|
||||
slider(0.0..=100.0, out_f64, Message::SetOutputVolume),
|
||||
text(format!("{}%", out_f64.round()))
|
||||
]
|
||||
.spacing(10)
|
||||
.padding(10);
|
||||
let source = row![
|
||||
icon("devices/audio-input-microphone-symbolic", 24),
|
||||
slider(0.0..=100.0, in_f64, Message::SetInputVolume),
|
||||
text(format!("{}%", in_f64.round()))
|
||||
]
|
||||
.spacing(10)
|
||||
.padding(10);
|
||||
|
||||
// TODO change these from helper functions to iced components for improved reusability
|
||||
let output_drop = revealer(
|
||||
self.is_open == IsOpen::Output,
|
||||
"Output",
|
||||
match &self.current_output {
|
||||
Some(output) => pretty_name(output.description.clone()),
|
||||
None => String::from("No device selected"),
|
||||
},
|
||||
self.outputs
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|output| pretty_name(output.description))
|
||||
.collect(),
|
||||
Message::OutputToggle,
|
||||
Message::OutputChanged(String::from("test")),
|
||||
);
|
||||
let input_drop = revealer(
|
||||
self.is_open == IsOpen::Input,
|
||||
"Input",
|
||||
match &self.current_input {
|
||||
Some(input) => pretty_name(input.description.clone()),
|
||||
None => String::from("No device selected"),
|
||||
},
|
||||
self.inputs
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|input| pretty_name(input.description))
|
||||
.collect(),
|
||||
Message::InputToggle,
|
||||
Message::InputChanged(String::from("test")),
|
||||
);
|
||||
|
||||
let content = column![]
|
||||
.align_items(Alignment::Start)
|
||||
.spacing(20)
|
||||
.push(sink)
|
||||
.push(source)
|
||||
.push(spacer())
|
||||
.push(output_drop)
|
||||
.push(input_drop);
|
||||
|
||||
self.applet_helper.popup_container(
|
||||
container(content)
|
||||
).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make this a themeable widget like the mock-ups
|
||||
fn spacer() -> iced::widget::Space {
|
||||
Space::with_width(Length::Fill)
|
||||
}
|
||||
|
||||
fn revealer<'a>(
|
||||
open: bool,
|
||||
title: &'a str,
|
||||
selected: String,
|
||||
options: Vec<String>,
|
||||
toggle: Message,
|
||||
_change: Message,
|
||||
) -> iced_sctk::widget::Column<'a, Message, Renderer> {
|
||||
if open {
|
||||
options.iter().fold(
|
||||
column![revealer_head(open, title, selected, toggle)].width(Length::Fill),
|
||||
|col, device| col.push(text(device)),
|
||||
)
|
||||
} else {
|
||||
column![revealer_head(open, title, selected, toggle)]
|
||||
}
|
||||
}
|
||||
|
||||
fn revealer_head<'a>(
|
||||
_open: bool,
|
||||
title: &'a str,
|
||||
selected: String,
|
||||
toggle: Message,
|
||||
) -> iced_sctk::widget::Button<Message, Renderer> {
|
||||
button(row![row![title].width(Length::Fill), text(selected)])
|
||||
.width(Length::Fill)
|
||||
.on_press(toggle)
|
||||
}
|
||||
|
||||
fn pretty_name(name: Option<String>) -> String {
|
||||
match name {
|
||||
Some(n) => n,
|
||||
None => String::from("Generic"),
|
||||
}
|
||||
}
|
||||
|
||||
enum PulseState {
|
||||
Disconnected,
|
||||
Connected(pulse::Connection),
|
||||
}
|
||||
|
||||
impl Default for PulseState {
|
||||
fn default() -> Self {
|
||||
Self::Disconnected
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for IsOpen {
|
||||
fn default() -> Self {
|
||||
IsOpen::None
|
||||
}
|
||||
}
|
||||
|
|
@ -1,521 +0,0 @@
|
|||
use iced_native::subscription::{self, Subscription};
|
||||
use std::cell::RefCell;
|
||||
use std::{rc::Rc, thread};
|
||||
|
||||
extern crate libpulse_binding as pulse;
|
||||
//use futures::channel::mpsc;
|
||||
use libpulse_binding::{
|
||||
callbacks::ListResult,
|
||||
context::{
|
||||
introspect::{Introspector, SinkInfo, SourceInfo},
|
||||
subscribe::{Facility, InterestMaskSet, Operation},
|
||||
Context,
|
||||
},
|
||||
error::PAErr,
|
||||
mainloop::standard::{IterateResult, Mainloop},
|
||||
proplist::Proplist,
|
||||
volume::ChannelVolumes,
|
||||
};
|
||||
pub fn connect() -> Subscription<Event> {
|
||||
struct Connect;
|
||||
|
||||
subscription::unfold(
|
||||
std::any::TypeId::of::<Connect>(),
|
||||
State::Disconnected,
|
||||
|state| async move {
|
||||
match state {
|
||||
// if app just started, or we are re-trying match here. Returns coenncting
|
||||
// message. We should store this in our app's state, but it isn't safe to
|
||||
// send messages until we get a conencted message. Which will be received
|
||||
// by the `State::Connecting` message below
|
||||
State::Disconnected => match PulseHandle::create() {
|
||||
Ok(pulse_handle) => (None, State::Connecting(pulse_handle)),
|
||||
Err(_) => (Some(Event::Disconnected), State::Disconnected),
|
||||
},
|
||||
// Just a buffer to make sure the GUI doesn't send messages until pulse is ready
|
||||
// The GUI doesn't have to monitor this state, as it is never sent to the GUI
|
||||
State::Connecting(mut pulse_handle) => {
|
||||
match pulse_handle.from_pulse.recv().await {
|
||||
Some(Message::Connected) => {(
|
||||
Some(Event::Connected(Connection(pulse_handle.to_pulse))),
|
||||
State::Connected(pulse_handle.from_pulse),
|
||||
)}
|
||||
Some(Message::Disconnected) => (Some(Event::Disconnected), State::Disconnected),
|
||||
_ => panic!("Pulse subscription logic is faulty as the PulseServer shouldn't send unique messages until connection is successful")
|
||||
}
|
||||
},
|
||||
State::Connected(mut from_pulse) => {
|
||||
// This is where we match messages from the pulse server to pass to the gui
|
||||
match from_pulse.recv().await {
|
||||
Some(Message::SetSinks(sinks)) => (Some(Event::MessageReceived(Message::SetSinks(sinks))), State::Connected(from_pulse)),
|
||||
Some(Message::SetSources(sources)) => (Some(Event::MessageReceived(Message::SetSources(sources))), State::Connected(from_pulse)),
|
||||
Some(Message::SetDefaultSink(sink)) => (Some(Event::MessageReceived(Message::SetDefaultSink(sink))), State::Connected(from_pulse)),
|
||||
Some(Message::SetDefaultSource(source)) => (Some(Event::MessageReceived(Message::SetDefaultSource(source))), State::Connected(from_pulse)),
|
||||
Some(Message::Disconnected) => (Some(Event::Disconnected), State::Disconnected),
|
||||
None => (Some(Event::Disconnected), State::Disconnected),
|
||||
_ => (None, State::Connected(from_pulse)),
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// #[derive(Debug)]
|
||||
enum State {
|
||||
Disconnected,
|
||||
Connecting(PulseHandle),
|
||||
Connected(tokio::sync::mpsc::Receiver<Message>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Event {
|
||||
Connected(Connection),
|
||||
Disconnected,
|
||||
MessageReceived(Message),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Connection(tokio::sync::mpsc::Sender<Message>);
|
||||
|
||||
impl Connection {
|
||||
pub fn send(&mut self, message: Message) {
|
||||
let _ = self
|
||||
.0
|
||||
.try_send(message)
|
||||
.expect("Send message to PulseAudio server");
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Message {
|
||||
Connected,
|
||||
Disconnected,
|
||||
GetSinks,
|
||||
GetSources,
|
||||
SetSinks(Vec<DeviceInfo>),
|
||||
SetSources(Vec<DeviceInfo>),
|
||||
GetDefaultSink,
|
||||
GetDefaultSource,
|
||||
SetDefaultSink(DeviceInfo),
|
||||
SetDefaultSource(DeviceInfo),
|
||||
SetSinkVolumeByName(String, ChannelVolumes),
|
||||
SetSourceVolumeByName(String, ChannelVolumes),
|
||||
}
|
||||
|
||||
struct PulseHandle {
|
||||
to_pulse: tokio::sync::mpsc::Sender<Message>,
|
||||
from_pulse: tokio::sync::mpsc::Receiver<Message>,
|
||||
}
|
||||
|
||||
impl PulseHandle {
|
||||
// Create pulse server thread, and bidirectional comms
|
||||
pub fn create() -> Result<PulseHandle, PAErr> {
|
||||
let (to_pulse, mut to_pulse_recv) = tokio::sync::mpsc::channel(10);
|
||||
let (mut from_pulse_send, from_pulse) = tokio::sync::mpsc::channel(10);
|
||||
//let from_pulse = Arc::new(Mutex::new(vec![]));
|
||||
//let mut from_pulse2 = from_pulse.clone();
|
||||
// this thread should complete by pushing a completed message,
|
||||
// or fail message. This should never complete/fail without pushing
|
||||
// a message. This lets the iced subscription go to sleep while init
|
||||
// finishes. TLDR: be very careful with error handling
|
||||
thread::spawn(move || {
|
||||
if let Ok(mut server) = PulseServer::connect().and_then(|server| server.init()) {
|
||||
PulseHandle::blocking_send_connected(&mut from_pulse_send);
|
||||
|
||||
// take `PulseServer` and handle reciver into async context
|
||||
// to listen for messages that need to be passed to the pulseserver
|
||||
// this lets us put the thread to sleep, but keep hold a single
|
||||
// thread, because pulse audio's API is not multithreaded... at all
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
rt.block_on(async {
|
||||
loop {
|
||||
// This is where the we match messages from the GUI to pass to the pulse server
|
||||
if let Some(msg) = to_pulse_recv.recv().await {
|
||||
match msg {
|
||||
Message::GetDefaultSink => match server.get_default_sink() {
|
||||
Ok(sink) => from_pulse_send
|
||||
.send(Message::SetDefaultSink(sink))
|
||||
.await
|
||||
.unwrap(),
|
||||
Err(_) => {
|
||||
PulseHandle::send_disconnected(&mut from_pulse_send).await
|
||||
}
|
||||
},
|
||||
Message::GetDefaultSource => match server.get_default_source() {
|
||||
Ok(source) => from_pulse_send
|
||||
.send(Message::SetDefaultSource(source))
|
||||
.await
|
||||
.unwrap(),
|
||||
Err(e) => {
|
||||
println!("ERROR! {:?}", e);
|
||||
PulseHandle::send_disconnected(&mut from_pulse_send).await;
|
||||
}
|
||||
},
|
||||
Message::GetSinks => match server.get_sinks() {
|
||||
Ok(sinks) => from_pulse_send
|
||||
.send(Message::SetSinks(sinks))
|
||||
.await
|
||||
.unwrap(),
|
||||
Err(_) => {
|
||||
PulseHandle::send_disconnected(&mut from_pulse_send).await
|
||||
}
|
||||
},
|
||||
Message::GetSources => match server.get_sources() {
|
||||
Ok(sinks) => from_pulse_send
|
||||
.send(Message::SetSources(sinks))
|
||||
.await
|
||||
.unwrap(),
|
||||
Err(_) => {
|
||||
PulseHandle::send_disconnected(&mut from_pulse_send).await
|
||||
}
|
||||
},
|
||||
Message::SetSinkVolumeByName(name, channel_volumes) => {
|
||||
server.set_sink_volume_by_name(&name, &channel_volumes)
|
||||
}
|
||||
Message::SetSourceVolumeByName(name, channel_volumes) => {
|
||||
server.set_source_volume_by_name(&name, &channel_volumes)
|
||||
}
|
||||
_ => {
|
||||
println!("message doesn't match")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Always report that server is disconnected
|
||||
PulseHandle::blocking_send_disconnected(&mut from_pulse_send);
|
||||
});
|
||||
Ok(PulseHandle {
|
||||
to_pulse,
|
||||
from_pulse,
|
||||
})
|
||||
}
|
||||
|
||||
fn blocking_send_disconnected(sender: &mut tokio::sync::mpsc::Sender<Message>) {
|
||||
sender.blocking_send(Message::Disconnected);
|
||||
}
|
||||
|
||||
fn blocking_send_connected(sender: &mut tokio::sync::mpsc::Sender<Message>) {
|
||||
sender.blocking_send(Message::Connected).unwrap()
|
||||
}
|
||||
|
||||
async fn send_disconnected(sender: &mut tokio::sync::mpsc::Sender<Message>) {
|
||||
sender.send(Message::Disconnected).await.unwrap()
|
||||
}
|
||||
|
||||
async fn send_connected(sender: &mut tokio::sync::mpsc::Sender<Message>) {
|
||||
sender.send(Message::Connected).await.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
struct PulseServer {
|
||||
mainloop: Rc<RefCell<Mainloop>>,
|
||||
context: Rc<RefCell<Context>>,
|
||||
introspector: Introspector,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
enum PulseServerError<'a> {
|
||||
IterateErr(IterateResult),
|
||||
ContextErr(pulse::context::State),
|
||||
OperationErr(pulse::operation::State),
|
||||
PAErr(PAErr),
|
||||
Connect,
|
||||
Misc(&'a str),
|
||||
}
|
||||
|
||||
// `PulseServer` code is heavily inspired by Dave Patrick Caberto's pulsectl-rs (SeaDve)
|
||||
// https://crates.io/crates/pulsectl-rs
|
||||
impl PulseServer {
|
||||
// connect() requires init() to be run after
|
||||
pub fn connect() -> Result<PulseServer, PulseServerError<'static>> {
|
||||
// TODO: fix app name, should be variable
|
||||
let mut proplist = Proplist::new().unwrap();
|
||||
proplist
|
||||
.set_str(
|
||||
pulse::proplist::properties::APPLICATION_NAME,
|
||||
"com.system76",
|
||||
)
|
||||
.or(Err(PulseServerError::Connect))?;
|
||||
|
||||
let mainloop = Rc::new(RefCell::new(
|
||||
pulse::mainloop::standard::Mainloop::new().ok_or(PulseServerError::Connect)?,
|
||||
));
|
||||
|
||||
let context = Rc::new(RefCell::new(
|
||||
Context::new_with_proplist(&*mainloop.borrow(), "MainConn", &proplist)
|
||||
.ok_or(PulseServerError::Connect)?,
|
||||
));
|
||||
|
||||
let introspector = context.borrow_mut().introspect();
|
||||
|
||||
context
|
||||
.borrow_mut()
|
||||
.connect(None, pulse::context::FlagSet::NOFLAGS, None)
|
||||
.map_err(|e| PulseServerError::PAErr(e))?;
|
||||
|
||||
Ok(PulseServer {
|
||||
mainloop,
|
||||
context,
|
||||
introspector,
|
||||
})
|
||||
}
|
||||
|
||||
// Wait for pulse audio connection to complete
|
||||
pub fn init(self) -> Result<Self, PulseServerError<'static>> {
|
||||
loop {
|
||||
match self.mainloop.borrow_mut().iterate(false) {
|
||||
IterateResult::Success(_) => {}
|
||||
IterateResult::Err(e) => {
|
||||
return Err(PulseServerError::IterateErr(IterateResult::Err(e)))
|
||||
}
|
||||
IterateResult::Quit(e) => {
|
||||
return Err(PulseServerError::IterateErr(IterateResult::Quit(e)))
|
||||
}
|
||||
}
|
||||
|
||||
match self.context.borrow().get_state() {
|
||||
pulse::context::State::Ready => break,
|
||||
pulse::context::State::Failed => {
|
||||
return Err(PulseServerError::ContextErr(pulse::context::State::Failed))
|
||||
}
|
||||
pulse::context::State::Terminated => {
|
||||
return Err(PulseServerError::ContextErr(
|
||||
pulse::context::State::Terminated,
|
||||
))
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
// Get a list of output devices
|
||||
pub fn get_sinks(&self) -> Result<Vec<DeviceInfo>, PulseServerError> {
|
||||
let list: Rc<RefCell<Option<Vec<DeviceInfo>>>> = Rc::new(RefCell::new(Some(Vec::new())));
|
||||
let list_ref = list.clone();
|
||||
|
||||
let operation = self.introspector.get_sink_info_list(
|
||||
move |sink_list: ListResult<&pulse::context::introspect::SinkInfo>| {
|
||||
if let ListResult::Item(item) = sink_list {
|
||||
list_ref.borrow_mut().as_mut().unwrap().push(item.into());
|
||||
}
|
||||
},
|
||||
);
|
||||
self.wait_for_result(operation)
|
||||
.and_then(|_| {
|
||||
list.borrow_mut().take().ok_or(PulseServerError::Misc(
|
||||
"get_sinks(): failed to wait for operation",
|
||||
))
|
||||
})
|
||||
.and_then(|result| Ok(result))
|
||||
}
|
||||
|
||||
// Get a list of input devices
|
||||
pub fn get_sources(&self) -> Result<Vec<DeviceInfo>, PulseServerError> {
|
||||
let list: Rc<RefCell<Option<Vec<DeviceInfo>>>> = Rc::new(RefCell::new(Some(Vec::new())));
|
||||
let list_ref = list.clone();
|
||||
|
||||
let operation = self.introspector.get_source_info_list(
|
||||
move |sink_list: ListResult<&pulse::context::introspect::SourceInfo>| {
|
||||
if let ListResult::Item(item) = sink_list {
|
||||
list_ref.borrow_mut().as_mut().unwrap().push(item.into());
|
||||
}
|
||||
},
|
||||
);
|
||||
self.wait_for_result(operation)
|
||||
.and_then(|_| {
|
||||
list.borrow_mut().take().ok_or(PulseServerError::Misc(
|
||||
"get_sources(): Failed to wait for operation",
|
||||
))
|
||||
})
|
||||
.and_then(|result| Ok(result))
|
||||
}
|
||||
|
||||
pub fn get_server_info(&mut self) -> Result<ServerInfo, PulseServerError> {
|
||||
let info = Rc::new(RefCell::new(Some(None)));
|
||||
let info_ref = info.clone();
|
||||
|
||||
let op = self.introspector.get_server_info(move |res| {
|
||||
info_ref.borrow_mut().as_mut().unwrap().replace(res.into());
|
||||
});
|
||||
self.wait_for_result(op)?;
|
||||
info.take()
|
||||
.flatten()
|
||||
.ok_or(PulseServerError::Misc("get_server_info(): failed"))
|
||||
}
|
||||
|
||||
fn get_default_sink(&mut self) -> Result<DeviceInfo, PulseServerError> {
|
||||
let server_info = self.get_server_info();
|
||||
match server_info {
|
||||
Ok(info) => {
|
||||
let name = &info.default_sink_name.unwrap_or(String::new());
|
||||
let device = Rc::new(RefCell::new(Some(None)));
|
||||
let dev_ref = device.clone();
|
||||
let op = self.introspector.get_sink_info_by_name(
|
||||
name,
|
||||
move |sink_list: ListResult<&SinkInfo>| {
|
||||
if let ListResult::Item(item) = sink_list {
|
||||
dev_ref.borrow_mut().as_mut().unwrap().replace(item.into());
|
||||
}
|
||||
},
|
||||
);
|
||||
self.wait_for_result(op)?;
|
||||
let mut result = device.borrow_mut();
|
||||
result.take().unwrap().ok_or_else(|| {
|
||||
PulseServerError::Misc("get_default_sink(): Error getting requested device")
|
||||
})
|
||||
}
|
||||
Err(_) => Err(PulseServerError::Misc("get_default_sink() failed")),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_default_source(&mut self) -> Result<DeviceInfo, PulseServerError> {
|
||||
let server_info = self.get_server_info();
|
||||
match server_info {
|
||||
Ok(info) => {
|
||||
let name = &info.default_source_name.unwrap_or(String::new());
|
||||
let device = Rc::new(RefCell::new(Some(None)));
|
||||
let dev_ref = device.clone();
|
||||
let op = self.introspector.get_source_info_by_name(
|
||||
name,
|
||||
move |sink_list: ListResult<&SourceInfo>| {
|
||||
if let ListResult::Item(item) = sink_list {
|
||||
dev_ref.borrow_mut().as_mut().unwrap().replace(item.into());
|
||||
}
|
||||
},
|
||||
);
|
||||
self.wait_for_result(op)?;
|
||||
let mut result = device.borrow_mut();
|
||||
result.take().unwrap().ok_or_else(|| {
|
||||
PulseServerError::Misc("get_default_source(): Error getting requested device")
|
||||
})
|
||||
}
|
||||
Err(_) => Err(PulseServerError::Misc("get_default_source() failed")),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_sink_volume_by_name(&mut self, name: &str, volume: &ChannelVolumes) {
|
||||
let op = self
|
||||
.introspector
|
||||
.set_sink_volume_by_name(name, volume, None);
|
||||
self.wait_for_result(op).ok();
|
||||
}
|
||||
|
||||
fn set_source_volume_by_name(&mut self, name: &str, volume: &ChannelVolumes) {
|
||||
let op = self
|
||||
.introspector
|
||||
.set_source_volume_by_name(name, volume, None);
|
||||
self.wait_for_result(op).ok();
|
||||
}
|
||||
|
||||
// after building an operation such as get_devices() we need to keep polling
|
||||
// the pulse audio server to "wait" for the operation to complete
|
||||
fn wait_for_result<G: ?Sized>(
|
||||
&self,
|
||||
operation: pulse::operation::Operation<G>,
|
||||
) -> Result<(), PulseServerError> {
|
||||
// TODO: make this loop async. It is already in an async context, so
|
||||
// we could make this thread sleep while waiting for the pulse server's
|
||||
// response.
|
||||
loop {
|
||||
match self.mainloop.borrow_mut().iterate(false) {
|
||||
IterateResult::Err(e) => {
|
||||
return Err(PulseServerError::IterateErr(IterateResult::Err(e)))
|
||||
}
|
||||
IterateResult::Quit(e) => {
|
||||
return Err(PulseServerError::IterateErr(IterateResult::Quit(e)))
|
||||
}
|
||||
IterateResult::Success(_) => {}
|
||||
}
|
||||
match operation.get_state() {
|
||||
pulse::operation::State::Done => return Ok(()),
|
||||
pulse::operation::State::Running => {}
|
||||
pulse::operation::State::Cancelled => {
|
||||
return Err(PulseServerError::OperationErr(
|
||||
pulse::operation::State::Cancelled,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DeviceInfo {
|
||||
pub name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub volume: ChannelVolumes,
|
||||
pub mute: bool,
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
impl<'a> From<&SinkInfo<'a>> for DeviceInfo {
|
||||
fn from(info: &SinkInfo<'a>) -> Self {
|
||||
Self {
|
||||
name: info.name.clone().map(|x| x.into_owned()),
|
||||
description: info.description.clone().map(|x| x.into_owned()),
|
||||
volume: info.volume,
|
||||
mute: info.mute,
|
||||
index: info.index,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&SourceInfo<'a>> for DeviceInfo {
|
||||
fn from(info: &SourceInfo<'a>) -> Self {
|
||||
Self {
|
||||
name: info.name.clone().map(|x| x.into_owned()),
|
||||
description: info.description.clone().map(|x| x.into_owned()),
|
||||
volume: info.volume,
|
||||
mute: info.mute,
|
||||
index: info.index,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for DeviceInfo {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ServerInfo {
|
||||
/// User name of the daemon process.
|
||||
pub user_name: Option<String>,
|
||||
/// Host name the daemon is running on.
|
||||
pub host_name: Option<String>,
|
||||
/// Version string of the daemon.
|
||||
pub server_version: Option<String>,
|
||||
/// Server package name (usually “pulseaudio”).
|
||||
pub server_name: Option<String>,
|
||||
// Default sample specification.
|
||||
//pub sample_spec: sample::Spec,
|
||||
/// Name of default sink.
|
||||
pub default_sink_name: Option<String>,
|
||||
/// Name of default source.
|
||||
pub default_source_name: Option<String>,
|
||||
/// A random cookie for identifying this instance of PulseAudio.
|
||||
pub cookie: u32,
|
||||
// Default channel map.
|
||||
//pub channel_map: channelmap::Map,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a pulse::context::introspect::ServerInfo<'a>> for ServerInfo {
|
||||
fn from(info: &'a pulse::context::introspect::ServerInfo<'a>) -> Self {
|
||||
ServerInfo {
|
||||
user_name: info.user_name.as_ref().map(|cow| cow.to_string()),
|
||||
host_name: info.host_name.as_ref().map(|cow| cow.to_string()),
|
||||
server_version: info.server_version.as_ref().map(|cow| cow.to_string()),
|
||||
server_name: info.server_name.as_ref().map(|cow| cow.to_string()),
|
||||
//sample_spec: info.sample_spec,
|
||||
default_sink_name: info.default_sink_name.as_ref().map(|cow| cow.to_string()),
|
||||
default_source_name: info.default_source_name.as_ref().map(|cow| cow.to_string()),
|
||||
cookie: info.cookie,
|
||||
//channel_map: info.channel_map,
|
||||
}
|
||||
}
|
||||
}
|
||||
3772
applets/cosmic-applet-battery/Cargo.lock
generated
|
|
@ -1,27 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-applet-battery"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
once_cell = "1.16.0"
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
||||
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", default-features = false }
|
||||
iced_sctk = { git = "https://github.com/pop-os/iced-sctk" }
|
||||
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", version = "0.16" }
|
||||
futures = "0.3"
|
||||
zbus = { version = "3.5", no-default-features = true }
|
||||
log = "0.4"
|
||||
pretty_env_logger = "0.4"
|
||||
# Application i18n
|
||||
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
|
||||
i18n-embed-fl = "0.6.4"
|
||||
rust-embed = "6.3.0"
|
||||
tokio = { version = "1.17.0", features = ["sync", "rt", "rt-multi-thread", "fs"] }
|
||||
|
||||
[dependencies.iced]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
# path = "../iced"
|
||||
default-features = false
|
||||
features = ["image", "svg", "tokio", "wayland"]
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Applet Battery
|
||||
Comment=Write a GTK + Rust application
|
||||
Type=Application
|
||||
Exec=cosmic-applet-battery
|
||||
Terminal=false
|
||||
Categories=GNOME;GTK;
|
||||
Keywords=Gnome;GTK;
|
||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||
Icon=com.system76.CosmicAppletBattery.svg
|
||||
StartupNotify=true
|
||||
NoDisplay=true
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10632" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10635" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10638" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10641" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10578">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
|
@ -1,4 +0,0 @@
|
|||
fallback_language = "en"
|
||||
|
||||
[fluent]
|
||||
assets_dir = "i18n"
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
cosmic-applet-button = Cosmic Button
|
||||
battery = Battery
|
||||
max-charge = Increase the lifespan of your battery by setting a maximum charge value of 80%
|
||||
seconds = s
|
||||
minutes = m
|
||||
hours = h
|
||||
until-empty = until empty
|
||||
power-settings = Power Settings...
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
cosmic-applet-button = Bouton Cosmic
|
||||
battery = Batterie
|
||||
max-charge = Augmenter la durée de vie de votre batterie en mettant la charge maximale à 80%
|
||||
seconds = s
|
||||
minutes = m
|
||||
hours = h
|
||||
until-empty = Avant la décharge totale
|
||||
power-settings = Paramètres d'alimentation...
|
||||
|
|
@ -1,324 +0,0 @@
|
|||
use crate::backlight::{
|
||||
screen_backlight_subscription, ScreenBacklightRequest, ScreenBacklightUpdate,
|
||||
};
|
||||
use crate::config;
|
||||
use crate::fl;
|
||||
use crate::upower_device::{device_subscription, DeviceDbusEvent};
|
||||
use crate::upower_kbdbacklight::{
|
||||
kbd_backlight_subscription, KeyboardBacklightRequest, KeyboardBacklightUpdate,
|
||||
};
|
||||
use cosmic::applet::CosmicAppletHelper;
|
||||
use cosmic::iced::alignment::Horizontal;
|
||||
use cosmic::iced::{
|
||||
executor,
|
||||
widget::{button, column, row, text, slider},
|
||||
window, Alignment, Application, Command, Length, Subscription,
|
||||
};
|
||||
use cosmic::iced_native::window::Settings;
|
||||
use cosmic::iced_style::application::{self, Appearance};
|
||||
use cosmic::iced_style::svg;
|
||||
use cosmic::theme::{self, Svg};
|
||||
use cosmic::widget::{icon, toggler, horizontal_rule};
|
||||
use cosmic::{iced_style, settings, Element, Theme};
|
||||
use cosmic_panel_config::{PanelAnchor, PanelSize};
|
||||
use iced_sctk::application::SurfaceIdWrapper;
|
||||
use iced_sctk::command::platform_specific::wayland::window::SctkWindowSettings;
|
||||
use iced_sctk::commands::popup::{destroy_popup, get_popup};
|
||||
use iced_sctk::settings::InitialSurface;
|
||||
use iced_sctk::Color;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
// XXX improve
|
||||
// TODO: time to empty varies? needs averaging?
|
||||
fn format_duration(duration: Duration) -> String {
|
||||
let secs = duration.as_secs();
|
||||
if secs > 60 {
|
||||
let min = secs / 60;
|
||||
if min > 60 {
|
||||
format!("{}:{:02}", min / 60, min % 60)
|
||||
} else {
|
||||
format!("{}{}", min, fl!("minutes"))
|
||||
}
|
||||
} else {
|
||||
format!("{}{}", secs, fl!("seconds"))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run() -> cosmic::iced::Result {
|
||||
let helper = CosmicAppletHelper::default();
|
||||
CosmicBatteryApplet::run(helper.window_settings())
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct CosmicBatteryApplet {
|
||||
icon_name: String,
|
||||
theme: Theme,
|
||||
charging_limit: bool,
|
||||
battery_percent: f64,
|
||||
time_remaining: Duration,
|
||||
kbd_brightness: f64,
|
||||
screen_brightness: f64,
|
||||
popup: Option<window::Id>,
|
||||
id_ctr: u32,
|
||||
screen_sender: Option<UnboundedSender<ScreenBacklightRequest>>,
|
||||
kbd_sender: Option<UnboundedSender<KeyboardBacklightRequest>>,
|
||||
applet_helper: CosmicAppletHelper,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
TogglePopup,
|
||||
Update {
|
||||
icon_name: String,
|
||||
percent: f64,
|
||||
time_to_empty: i64,
|
||||
},
|
||||
SetKbdBrightness(i32),
|
||||
SetScreenBrightness(i32),
|
||||
SetChargingLimit(bool),
|
||||
UpdateKbdBrightness(f64),
|
||||
UpdateScreenBrightness(f64),
|
||||
OpenBatterySettings,
|
||||
InitKbdBacklight(UnboundedSender<KeyboardBacklightRequest>, f64),
|
||||
InitScreenBacklight(UnboundedSender<ScreenBacklightRequest>, f64),
|
||||
Errored(String),
|
||||
Ignore,
|
||||
}
|
||||
|
||||
impl Application for CosmicBatteryApplet {
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Executor = executor::Default;
|
||||
type Flags = ();
|
||||
|
||||
fn new(_flags: ()) -> (Self, Command<Message>) {
|
||||
(
|
||||
CosmicBatteryApplet {
|
||||
icon_name: "battery-symbolic".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
config::APP_ID.to_string()
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::SetKbdBrightness(brightness) => {
|
||||
self.kbd_brightness = (brightness as f64 / 100.0).clamp(0., 1.);
|
||||
if let Some(tx) = &self.kbd_sender {
|
||||
let _ = tx.send(KeyboardBacklightRequest::Set(self.kbd_brightness));
|
||||
}
|
||||
}
|
||||
Message::SetScreenBrightness(brightness) => {
|
||||
self.screen_brightness = brightness as f64 / 100.0;
|
||||
if let Some(tx) = &self.screen_sender {
|
||||
let _ = tx.send(ScreenBacklightRequest::Set(self.screen_brightness));
|
||||
}
|
||||
}
|
||||
Message::SetChargingLimit(enable_charging_limit) => {
|
||||
self.charging_limit = enable_charging_limit;
|
||||
}
|
||||
Message::OpenBatterySettings => {
|
||||
// TODO Ashley
|
||||
}
|
||||
Message::Errored(_) => {
|
||||
// TODO log errors
|
||||
}
|
||||
Message::TogglePopup => {
|
||||
if let Some(p) = self.popup.take() {
|
||||
return destroy_popup(p);
|
||||
} else {
|
||||
if let Some(tx) = &self.kbd_sender {
|
||||
let _ = tx.send(KeyboardBacklightRequest::Get);
|
||||
}
|
||||
if let Some(tx) = &self.screen_sender {
|
||||
let _ = tx.send(ScreenBacklightRequest::Get);
|
||||
}
|
||||
|
||||
self.id_ctr += 1;
|
||||
let new_id = window::Id::new(self.id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
|
||||
let popup_settings =
|
||||
self.applet_helper.get_popup_settings(window::Id::new(0), new_id, (400, 240), None, None);
|
||||
return get_popup(popup_settings);
|
||||
}
|
||||
}
|
||||
Message::Update {
|
||||
icon_name,
|
||||
percent,
|
||||
time_to_empty,
|
||||
} => {
|
||||
self.icon_name = icon_name;
|
||||
self.battery_percent = percent;
|
||||
self.time_remaining = Duration::from_secs(time_to_empty as u64);
|
||||
}
|
||||
Message::UpdateKbdBrightness(b) => {
|
||||
self.kbd_brightness = b;
|
||||
}
|
||||
Message::Ignore => {}
|
||||
Message::InitKbdBacklight(tx, brightness) => {
|
||||
let _ = tx.send(KeyboardBacklightRequest::Get);
|
||||
self.kbd_sender = Some(tx);
|
||||
self.kbd_brightness = brightness;
|
||||
}
|
||||
Message::InitScreenBacklight(tx, brightness) => {
|
||||
let _ = tx.send(ScreenBacklightRequest::Get);
|
||||
self.screen_sender = Some(tx);
|
||||
self.screen_brightness = brightness;
|
||||
}
|
||||
Message::UpdateScreenBrightness(b) => {
|
||||
self.screen_brightness = b;
|
||||
}
|
||||
}
|
||||
Command::none()
|
||||
}
|
||||
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Window(_) => self.applet_helper.icon_button(
|
||||
&self.icon_name,
|
||||
)
|
||||
.on_press(Message::TogglePopup)
|
||||
.into(),
|
||||
SurfaceIdWrapper::Popup(_) => {
|
||||
let name = text(fl!("battery")).size(18);
|
||||
let description = text(
|
||||
if "battery-full-charging-symbolic" == self.icon_name
|
||||
|| "battery-full-charged-symbolic" == self.icon_name
|
||||
{
|
||||
format!("{}%", self.battery_percent)
|
||||
} else {
|
||||
format!(
|
||||
"{} {} ({:.0}%)",
|
||||
format_duration(self.time_remaining),
|
||||
fl!("until-empty"),
|
||||
self.battery_percent
|
||||
)
|
||||
},
|
||||
)
|
||||
.size(12);
|
||||
self.applet_helper.popup_container(
|
||||
column![
|
||||
row![
|
||||
icon(&self.icon_name, 24)
|
||||
.style(Svg::Custom(|theme| {
|
||||
svg::Appearance {
|
||||
fill: Some(theme.palette().text),
|
||||
}
|
||||
}))
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24)),
|
||||
column![name, description]
|
||||
]
|
||||
.spacing(8)
|
||||
.align_items(Alignment::Center),
|
||||
horizontal_rule(1),
|
||||
// text{"Limit Battery Charging"},
|
||||
toggler(fl!("max-charge"), self.charging_limit, |_| {
|
||||
Message::SetChargingLimit(!self.charging_limit)
|
||||
}),
|
||||
horizontal_rule(1),
|
||||
row![
|
||||
icon("display-brightness-symbolic", 24)
|
||||
.style(Svg::Custom(|theme| {
|
||||
svg::Appearance {
|
||||
fill: Some(theme.palette().text),
|
||||
}
|
||||
}))
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24)),
|
||||
slider(
|
||||
0..=100,
|
||||
(self.screen_brightness * 100.0) as i32,
|
||||
Message::SetScreenBrightness
|
||||
),
|
||||
text(format!("{:.0}%", self.screen_brightness * 100.0))
|
||||
.width(Length::Units(40))
|
||||
.horizontal_alignment(Horizontal::Right)
|
||||
]
|
||||
.spacing(12),
|
||||
row![
|
||||
icon("keyboard-brightness-symbolic", 24)
|
||||
.style(Svg::Custom(|theme| {
|
||||
svg::Appearance {
|
||||
fill: Some(theme.palette().text),
|
||||
}
|
||||
}))
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24)),
|
||||
slider(
|
||||
0..=100,
|
||||
(self.kbd_brightness * 100.0) as i32,
|
||||
Message::SetKbdBrightness
|
||||
),
|
||||
text(format!("{:.0}%", self.kbd_brightness * 100.0))
|
||||
.width(Length::Units(40))
|
||||
.horizontal_alignment(Horizontal::Right)
|
||||
]
|
||||
.spacing(12),
|
||||
button(
|
||||
text(fl!("power-settings"))
|
||||
.horizontal_alignment(Horizontal::Center)
|
||||
.width(Length::Fill)
|
||||
.style(theme::Text::Custom(|theme| {
|
||||
let cosmic = theme.cosmic();
|
||||
iced_style::text::Appearance {
|
||||
color: Some(cosmic.accent.on.into()),
|
||||
}
|
||||
}))
|
||||
)
|
||||
.width(Length::Fill)
|
||||
]
|
||||
.spacing(4)
|
||||
.padding(8),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
Subscription::batch(vec![
|
||||
device_subscription(0).map(|(_, event)| match event {
|
||||
DeviceDbusEvent::Update {
|
||||
icon_name,
|
||||
percent,
|
||||
time_to_empty,
|
||||
} => Message::Update {
|
||||
icon_name,
|
||||
percent,
|
||||
time_to_empty,
|
||||
},
|
||||
}),
|
||||
kbd_backlight_subscription(0).map(|(_, event)| match event {
|
||||
KeyboardBacklightUpdate::Update(b) => Message::UpdateKbdBrightness(b),
|
||||
KeyboardBacklightUpdate::Init(tx, b) => Message::InitKbdBacklight(tx, b),
|
||||
}),
|
||||
screen_backlight_subscription(0).map(|(_, event)| match event {
|
||||
ScreenBacklightUpdate::Update(b) => Message::UpdateScreenBrightness(b),
|
||||
ScreenBacklightUpdate::Init(tx, b) => Message::InitScreenBacklight(tx, b),
|
||||
}),
|
||||
])
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
}
|
||||
|
||||
fn close_requested(&self, _id: iced_sctk::application::SurfaceIdWrapper) -> Self::Message {
|
||||
Message::Ignore
|
||||
}
|
||||
|
||||
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
|
||||
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||
text_color: theme.cosmic().on_bg_color().into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,180 +0,0 @@
|
|||
// TODO: use udev to monitor for brightness changes?
|
||||
// How should key bindings be handled? Need something like gnome-settings-daemon?
|
||||
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{self, Read},
|
||||
os::unix::ffi::OsStrExt,
|
||||
path::Path,
|
||||
str::{self, FromStr},
|
||||
hash::Hash,
|
||||
fmt::Debug
|
||||
};
|
||||
|
||||
use cosmic::iced;
|
||||
use iced_sctk::subscription;
|
||||
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel};
|
||||
|
||||
const BACKLIGHT_SYSDIR: &str = "/sys/class/backlight";
|
||||
|
||||
#[zbus::dbus_proxy(
|
||||
default_service = "org.freedesktop.login1",
|
||||
interface = "org.freedesktop.login1.Session",
|
||||
default_path = "/org/freedesktop/login1/session/auto"
|
||||
)]
|
||||
trait LogindSession {
|
||||
fn set_brightness(&self, subsystem: &str, name: &str, brightness: u32) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Backlight(String);
|
||||
|
||||
impl Backlight {
|
||||
pub async fn brightness(&self) -> Option<u32> {
|
||||
self.prop("brightness").await
|
||||
}
|
||||
|
||||
// XXX cache value. Async?
|
||||
pub async fn max_brightness(&self) -> Option<u32> {
|
||||
self.prop("max_brightness").await
|
||||
}
|
||||
|
||||
pub async fn set_brightness(
|
||||
&self,
|
||||
session: &LogindSessionProxy<'_>,
|
||||
value: u32,
|
||||
) -> zbus::Result<()> {
|
||||
session.set_brightness("backlight", &self.0, value).await
|
||||
}
|
||||
|
||||
async fn prop<T: FromStr>(&self, name: &str) -> Option<T> {
|
||||
let path = Path::new(BACKLIGHT_SYSDIR).join(&self.0).join(name);
|
||||
let mut file = File::open(path).ok()?;
|
||||
let mut s = String::new();
|
||||
file.read_to_string(&mut s).ok()?;
|
||||
s.trim().parse().ok()
|
||||
}
|
||||
}
|
||||
|
||||
// Choose backlight with most "precision". This is what `light` does.
|
||||
pub async fn backlight() -> io::Result<Option<Backlight>> {
|
||||
let mut best_backlight = None;
|
||||
let mut best_max_brightness = 0;
|
||||
let mut dir_stream = tokio::fs::read_dir(BACKLIGHT_SYSDIR).await?;
|
||||
while let Ok(Some(entry)) = dir_stream.next_entry().await {
|
||||
if let Ok(filename) = str::from_utf8(entry.file_name().as_bytes()) {
|
||||
let backlight = Backlight(filename.to_string());
|
||||
if let Some(max_brightness) = backlight.max_brightness().await {
|
||||
if max_brightness > best_max_brightness {
|
||||
best_backlight = Some(backlight);
|
||||
best_max_brightness = max_brightness;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(best_backlight)
|
||||
}
|
||||
|
||||
|
||||
pub fn screen_backlight_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
||||
id: I,
|
||||
) -> iced::Subscription<(I, ScreenBacklightUpdate)> {
|
||||
subscription::unfold(id, State::Ready, move |state| start_listening(id, state))
|
||||
}
|
||||
|
||||
pub enum State {
|
||||
Ready,
|
||||
Waiting(Backlight, LogindSessionProxy<'static>, UnboundedReceiver<ScreenBacklightRequest>),
|
||||
Finished,
|
||||
}
|
||||
|
||||
async fn start_listening<I: Copy>(id: I, state: State) -> (Option<(I, ScreenBacklightUpdate)>, State) {
|
||||
match state {
|
||||
State::Ready => {
|
||||
let conn = match zbus::Connection::system().await {
|
||||
Ok(conn) => conn,
|
||||
Err(_) => return (None, State::Finished),
|
||||
};
|
||||
let screen_proxy = match LogindSessionProxy::builder(&conn).build().await {
|
||||
Ok(p) => p,
|
||||
Err(_) => return (None, State::Finished),
|
||||
};
|
||||
let backlight = match backlight().await {
|
||||
Ok(Some(b)) => b,
|
||||
_ => return (None, State::Finished),
|
||||
};
|
||||
let (tx, rx) = unbounded_channel();
|
||||
|
||||
return (
|
||||
Some((
|
||||
id,
|
||||
ScreenBacklightUpdate::Init(tx, backlight.brightness().await.unwrap_or_default() as f64)
|
||||
)),
|
||||
State::Waiting(backlight, screen_proxy, rx),
|
||||
);
|
||||
|
||||
}
|
||||
State::Waiting(backlight, proxy, mut rx) => {
|
||||
match rx.recv().await {
|
||||
Some(req) => match req {
|
||||
ScreenBacklightRequest::Get => {
|
||||
let msg = if let Some(max_brightness) = backlight.max_brightness().await {
|
||||
let value = (backlight.brightness().await.unwrap_or_default() as f64 / max_brightness as f64).clamp(0., 1.);
|
||||
Some((
|
||||
id,
|
||||
ScreenBacklightUpdate::Update(value)
|
||||
))
|
||||
} else { None };
|
||||
(msg, State::Waiting(backlight, proxy, rx))
|
||||
}
|
||||
,
|
||||
ScreenBacklightRequest::Set(value) => {
|
||||
if let Some(max_brightness) = backlight.max_brightness().await {
|
||||
let value = value.clamp(0., 1.) * (max_brightness as f64);
|
||||
let value = value.round() as u32;
|
||||
let _ = backlight.set_brightness(&proxy, value).await;
|
||||
}
|
||||
(
|
||||
None,
|
||||
State::Waiting(backlight, proxy, rx),
|
||||
)
|
||||
},
|
||||
},
|
||||
None => (None, State::Finished),
|
||||
}
|
||||
}
|
||||
State::Finished => iced::futures::future::pending().await,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ScreenBacklightUpdate {
|
||||
Update(f64),
|
||||
Init(UnboundedSender<ScreenBacklightRequest>, f64)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ScreenBacklightRequest {
|
||||
Get,
|
||||
Set(f64),
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// TODO: Cache device, max_brightness, etc.
|
||||
async fn set_display_brightness(brightness: f64) -> io::Result<()> {
|
||||
if let Some(backlight) = backlight()? {
|
||||
if let Some(max_brightness) = backlight.max_brightness() {
|
||||
let value = brightness.clamp(0., 1.) * (max_brightness as f64);
|
||||
let value = value.round() as u32;
|
||||
let connection = zbus::Connection::system().await?;
|
||||
if let Ok(session) = LogindSessionProxy::builder(&connection).build().await {
|
||||
backlight.set_brightness(&session, value).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: keyboard backlight
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
pub const APP_ID: &str = "com.system76.CosmicAppletButton";
|
||||
pub const PROFILE: &str = "";
|
||||
pub const VERSION: &str = "0.1.0";
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
// SPDX-License-Identifier: MPL-2.0-only
|
||||
|
||||
use i18n_embed::{
|
||||
fluent::{fluent_language_loader, FluentLanguageLoader},
|
||||
DefaultLocalizer, LanguageLoader, Localizer,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "i18n/"]
|
||||
struct Localizations;
|
||||
|
||||
pub static LANGUAGE_LOADER: Lazy<FluentLanguageLoader> = Lazy::new(|| {
|
||||
let loader: FluentLanguageLoader = fluent_language_loader!();
|
||||
|
||||
loader
|
||||
.load_fallback_language(&Localizations)
|
||||
.expect("Error while loading fallback language");
|
||||
|
||||
loader
|
||||
});
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! fl {
|
||||
($message_id:literal) => {{
|
||||
i18n_embed_fl::fl!($crate::localize::LANGUAGE_LOADER, $message_id)
|
||||
}};
|
||||
|
||||
($message_id:literal, $($args:expr),*) => {{
|
||||
i18n_embed_fl::fl!($crate::localize::LANGUAGE_LOADER, $message_id, $($args), *)
|
||||
}};
|
||||
}
|
||||
|
||||
// Get the `Localizer` to be used for localizing this library.
|
||||
pub fn localizer() -> Box<dyn Localizer> {
|
||||
Box::from(DefaultLocalizer::new(&*LANGUAGE_LOADER, &Localizations))
|
||||
}
|
||||
|
||||
pub fn localize() {
|
||||
let localizer = localizer();
|
||||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
#[rustfmt::skip]
|
||||
mod backlight;
|
||||
mod app;
|
||||
mod config;
|
||||
mod localize;
|
||||
mod power_daemon;
|
||||
mod upower;
|
||||
|
||||
mod upower_device;
|
||||
mod upower_kbdbacklight;
|
||||
use config::APP_ID;
|
||||
use log::info;
|
||||
|
||||
use localize::localize;
|
||||
|
||||
use crate::config::{PROFILE, VERSION};
|
||||
|
||||
fn main() -> cosmic::iced::Result {
|
||||
// Initialize logger
|
||||
pretty_env_logger::init();
|
||||
info!("Iced Workspaces Applet ({})", APP_ID);
|
||||
info!("Version: {} ({})", VERSION, PROFILE);
|
||||
|
||||
// Prepare i18n
|
||||
localize();
|
||||
|
||||
app::run()
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
//! # DBus interface proxy for: `com.system76.PowerDaemon`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/com/system76/PowerDaemon' from service 'com.system76.PowerDaemon' on system bus`.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(
|
||||
default_service = "com.system76.PowerDaemon",
|
||||
interface = "com.system76.PowerDaemon",
|
||||
default_path = "/com/system76/PowerDaemon"
|
||||
)]
|
||||
trait PowerDaemon {
|
||||
/// Balanced method
|
||||
fn balanced(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Battery method
|
||||
fn battery(&self) -> zbus::Result<()>;
|
||||
|
||||
/// GetChargeProfiles method
|
||||
fn get_charge_profiles(
|
||||
&self,
|
||||
) -> zbus::Result<Vec<std::collections::HashMap<String, zbus::zvariant::OwnedValue>>>;
|
||||
|
||||
/// GetChargeThresholds method
|
||||
fn get_charge_thresholds(&self) -> zbus::Result<(u8, u8)>;
|
||||
|
||||
/// GetDefaultGraphics method
|
||||
fn get_default_graphics(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetExternalDisplaysRequireDGPU method
|
||||
fn get_external_displays_require_dgpu(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// GetGraphics method
|
||||
fn get_graphics(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetGraphicsPower method
|
||||
fn get_graphics_power(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// GetProfile method
|
||||
fn get_profile(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetSwitchable method
|
||||
fn get_switchable(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Performance method
|
||||
fn performance(&self) -> zbus::Result<()>;
|
||||
|
||||
/// SetChargeThresholds method
|
||||
fn set_charge_thresholds(&self, thresholds: &(u8, u8)) -> zbus::Result<()>;
|
||||
|
||||
/// SetGraphics method
|
||||
fn set_graphics(&self, vendor: &str) -> zbus::Result<()>;
|
||||
|
||||
/// SetGraphicsPower method
|
||||
fn set_graphics_power(&self, power: bool) -> zbus::Result<()>;
|
||||
|
||||
/// HotPlugDetect signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn hot_plug_detect(&self, port: u64) -> zbus::Result<()>;
|
||||
|
||||
/// PowerProfileSwitch signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn power_profile_switch(&self, profile: &str) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
// TODO power subscription
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
//! # DBus interface proxy for: `org.freedesktop.UPower`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/UPower' from service 'org.freedesktop.UPower' on system bus`.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(
|
||||
default_service = "org.freedesktop.UPower",
|
||||
interface = "org.freedesktop.UPower"
|
||||
)]
|
||||
trait UPower {
|
||||
/// EnumerateDevices method
|
||||
fn enumerate_devices(&self) -> zbus::Result<Vec<zbus::zvariant::OwnedObjectPath>>;
|
||||
|
||||
/// GetCriticalAction method
|
||||
fn get_critical_action(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetDisplayDevice method
|
||||
fn get_display_device(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||
|
||||
/// DeviceAdded signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn device_added(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// DeviceRemoved signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn device_removed(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// DaemonVersion property
|
||||
#[dbus_proxy(property)]
|
||||
fn daemon_version(&self) -> zbus::Result<String>;
|
||||
|
||||
/// LidIsClosed property
|
||||
#[dbus_proxy(property)]
|
||||
fn lid_is_closed(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// LidIsPresent property
|
||||
#[dbus_proxy(property)]
|
||||
fn lid_is_present(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// OnBattery property
|
||||
#[dbus_proxy(property)]
|
||||
fn on_battery(&self) -> zbus::Result<bool>;
|
||||
}
|
||||
|
|
@ -1,245 +0,0 @@
|
|||
//! # DBus interface proxy for: `org.freedesktop.UPower.Device`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/UPower/devices/DisplayDevice' from service 'org.freedesktop.UPower' on system bus`.
|
||||
|
||||
use cosmic::iced::{self, subscription};
|
||||
|
||||
use futures::StreamExt;
|
||||
use std::{fmt::Debug, hash::Hash};
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
use crate::upower::UPowerProxy;
|
||||
#[dbus_proxy(
|
||||
default_service = "org.freedesktop.UPower",
|
||||
interface = "org.freedesktop.UPower.Device"
|
||||
)]
|
||||
trait Device {
|
||||
/// GetHistory method
|
||||
fn get_history(
|
||||
&self,
|
||||
type_: &str,
|
||||
timespan: u32,
|
||||
resolution: u32,
|
||||
) -> zbus::Result<Vec<(u32, f64, u32)>>;
|
||||
|
||||
/// GetStatistics method
|
||||
fn get_statistics(&self, type_: &str) -> zbus::Result<Vec<(f64, f64)>>;
|
||||
|
||||
/// Refresh method
|
||||
fn refresh(&self) -> zbus::Result<()>;
|
||||
|
||||
/// BatteryLevel property
|
||||
#[dbus_proxy(property)]
|
||||
fn battery_level(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// Capacity property
|
||||
#[dbus_proxy(property)]
|
||||
fn capacity(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// ChargeCycles property
|
||||
#[dbus_proxy(property)]
|
||||
fn charge_cycles(&self) -> zbus::Result<i32>;
|
||||
|
||||
/// Energy property
|
||||
#[dbus_proxy(property)]
|
||||
fn energy(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// EnergyEmpty property
|
||||
#[dbus_proxy(property)]
|
||||
fn energy_empty(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// EnergyFull property
|
||||
#[dbus_proxy(property)]
|
||||
fn energy_full(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// EnergyFullDesign property
|
||||
#[dbus_proxy(property)]
|
||||
fn energy_full_design(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// EnergyRate property
|
||||
#[dbus_proxy(property)]
|
||||
fn energy_rate(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// HasHistory property
|
||||
#[dbus_proxy(property)]
|
||||
fn has_history(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// HasStatistics property
|
||||
#[dbus_proxy(property)]
|
||||
fn has_statistics(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// IconName property
|
||||
#[dbus_proxy(property)]
|
||||
fn icon_name(&self) -> zbus::Result<String>;
|
||||
|
||||
/// IsPresent property
|
||||
#[dbus_proxy(property)]
|
||||
fn is_present(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// IsRechargeable property
|
||||
#[dbus_proxy(property)]
|
||||
fn is_rechargeable(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Luminosity property
|
||||
#[dbus_proxy(property)]
|
||||
fn luminosity(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// Model property
|
||||
#[dbus_proxy(property)]
|
||||
fn model(&self) -> zbus::Result<String>;
|
||||
|
||||
/// NativePath property
|
||||
#[dbus_proxy(property)]
|
||||
fn native_path(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Online property
|
||||
#[dbus_proxy(property)]
|
||||
fn online(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Percentage property
|
||||
#[dbus_proxy(property)]
|
||||
fn percentage(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// PowerSupply property
|
||||
#[dbus_proxy(property)]
|
||||
fn power_supply(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Serial property
|
||||
#[dbus_proxy(property)]
|
||||
fn serial(&self) -> zbus::Result<String>;
|
||||
|
||||
/// State property
|
||||
#[dbus_proxy(property)]
|
||||
fn state(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// Technology property
|
||||
#[dbus_proxy(property)]
|
||||
fn technology(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// Temperature property
|
||||
#[dbus_proxy(property)]
|
||||
fn temperature(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// TimeToEmpty property
|
||||
#[dbus_proxy(property)]
|
||||
fn time_to_empty(&self) -> zbus::Result<i64>;
|
||||
|
||||
/// TimeToFull property
|
||||
#[dbus_proxy(property)]
|
||||
fn time_to_full(&self) -> zbus::Result<i64>;
|
||||
|
||||
/// Type property
|
||||
#[dbus_proxy(property)]
|
||||
fn type_(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// UpdateTime property
|
||||
#[dbus_proxy(property)]
|
||||
fn update_time(&self) -> zbus::Result<u64>;
|
||||
|
||||
/// Vendor property
|
||||
#[dbus_proxy(property)]
|
||||
fn vendor(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Voltage property
|
||||
#[dbus_proxy(property)]
|
||||
fn voltage(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// WarningLevel property
|
||||
#[dbus_proxy(property)]
|
||||
fn warning_level(&self) -> zbus::Result<u32>;
|
||||
}
|
||||
|
||||
pub fn device_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
||||
id: I,
|
||||
) -> iced::Subscription<(I, DeviceDbusEvent)> {
|
||||
subscription::unfold(id, State::Ready, move |state| start_listening(id, state))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum State {
|
||||
Ready,
|
||||
Waiting(DeviceProxy<'static>),
|
||||
Finished,
|
||||
}
|
||||
|
||||
async fn display_device() -> zbus::Result<DeviceProxy<'static>> {
|
||||
let connection = zbus::Connection::system().await?;
|
||||
let upower = UPowerProxy::new(&connection).await?;
|
||||
let device_path = upower.get_display_device().await?;
|
||||
DeviceProxy::builder(&connection)
|
||||
.path(device_path)?
|
||||
.cache_properties(zbus::CacheProperties::Yes)
|
||||
.build()
|
||||
.await
|
||||
}
|
||||
|
||||
async fn start_listening<I: Copy>(id: I, state: State) -> (Option<(I, DeviceDbusEvent)>, State) {
|
||||
match state {
|
||||
State::Ready => {
|
||||
if let Ok(device) = display_device().await {
|
||||
return (
|
||||
Some((
|
||||
id,
|
||||
DeviceDbusEvent::Update {
|
||||
icon_name: device
|
||||
.cached_icon_name()
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default(),
|
||||
percent: device
|
||||
.cached_percentage()
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default(),
|
||||
time_to_empty: device
|
||||
.cached_time_to_empty()
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default(),
|
||||
},
|
||||
)),
|
||||
State::Waiting(device),
|
||||
);
|
||||
}
|
||||
return (None, State::Finished);
|
||||
}
|
||||
State::Waiting(device) => {
|
||||
let mut stream = futures::stream_select!(
|
||||
device.receive_icon_name_changed().await.map(|_| ()),
|
||||
device.receive_percentage_changed().await.map(|_| ()),
|
||||
device.receive_time_to_empty_changed().await.map(|_| ()),
|
||||
);
|
||||
match stream.next().await {
|
||||
Some(_) => (
|
||||
Some((
|
||||
id,
|
||||
DeviceDbusEvent::Update {
|
||||
icon_name: device
|
||||
.cached_icon_name()
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default(),
|
||||
percent: device
|
||||
.cached_percentage()
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default(),
|
||||
time_to_empty: device
|
||||
.cached_time_to_empty()
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default(),
|
||||
},
|
||||
)),
|
||||
State::Waiting(device),
|
||||
),
|
||||
None => (None, State::Finished),
|
||||
}
|
||||
}
|
||||
State::Finished => iced::futures::future::pending().await,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum DeviceDbusEvent {
|
||||
Update {
|
||||
icon_name: String,
|
||||
percent: f64,
|
||||
time_to_empty: i64,
|
||||
},
|
||||
}
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
//! # DBus interface proxy for: `org.freedesktop.UPower.KbdBacklight`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/UPower/KbdBacklight' from service 'org.freedesktop.UPower' on system bus`.
|
||||
|
||||
use cosmic::iced;
|
||||
use iced::subscription;
|
||||
use std::{fmt::Debug, hash::Hash};
|
||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
||||
use zbus::dbus_proxy;
|
||||
#[dbus_proxy(
|
||||
default_service = "org.freedesktop.UPower",
|
||||
interface = "org.freedesktop.UPower.KbdBacklight",
|
||||
default_path = "/org/freedesktop/UPower/KbdBacklight"
|
||||
)]
|
||||
trait KbdBacklight {
|
||||
/// GetBrightness method
|
||||
fn get_brightness(&self) -> zbus::Result<i32>;
|
||||
|
||||
/// GetMaxBrightness method
|
||||
fn get_max_brightness(&self) -> zbus::Result<i32>;
|
||||
|
||||
/// SetBrightness method
|
||||
fn set_brightness(&self, value: i32) -> zbus::Result<()>;
|
||||
|
||||
/// BrightnessChanged signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn brightness_changed(&self, value: i32) -> zbus::Result<()>;
|
||||
|
||||
/// BrightnessChangedWithSource signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn brightness_changed_with_source(&self, value: i32, source: &str) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
pub fn kbd_backlight_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
||||
id: I,
|
||||
) -> iced::Subscription<(I, KeyboardBacklightUpdate)> {
|
||||
subscription::unfold(id, State::Ready, move |state| start_listening(id, state))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum State {
|
||||
Ready,
|
||||
Waiting(
|
||||
KbdBacklightProxy<'static>,
|
||||
UnboundedReceiver<KeyboardBacklightRequest>,
|
||||
),
|
||||
Finished,
|
||||
}
|
||||
|
||||
async fn start_listening<I: Copy>(
|
||||
id: I,
|
||||
state: State,
|
||||
) -> (Option<(I, KeyboardBacklightUpdate)>, State) {
|
||||
match state {
|
||||
State::Ready => {
|
||||
let conn = match zbus::Connection::system().await {
|
||||
Ok(conn) => conn,
|
||||
Err(_) => return (None, State::Finished),
|
||||
};
|
||||
let kbd_proxy = match KbdBacklightProxy::builder(&conn).build().await {
|
||||
Ok(p) => p,
|
||||
Err(_) => return (None, State::Finished),
|
||||
};
|
||||
let (tx, rx) = unbounded_channel();
|
||||
|
||||
return (
|
||||
Some((
|
||||
id,
|
||||
KeyboardBacklightUpdate::Init(
|
||||
tx,
|
||||
kbd_proxy.get_brightness().await.unwrap_or_default() as f64,
|
||||
),
|
||||
)),
|
||||
State::Waiting(kbd_proxy, rx),
|
||||
);
|
||||
}
|
||||
State::Waiting(proxy, mut rx) => match rx.recv().await {
|
||||
Some(req) => match req {
|
||||
KeyboardBacklightRequest::Get => (
|
||||
Some((
|
||||
id,
|
||||
KeyboardBacklightUpdate::Update(
|
||||
proxy.get_brightness().await.unwrap_or_default() as f64,
|
||||
),
|
||||
)),
|
||||
State::Waiting(proxy, rx),
|
||||
),
|
||||
KeyboardBacklightRequest::Set(value) => {
|
||||
if let Ok(max_brightness) = proxy.get_max_brightness().await {
|
||||
let value = value.clamp(0., 1.) * (max_brightness as f64);
|
||||
let value = value.round() as i32;
|
||||
let _ = proxy.set_brightness(value).await;
|
||||
}
|
||||
|
||||
(None, State::Waiting(proxy, rx))
|
||||
}
|
||||
},
|
||||
None => (None, State::Finished),
|
||||
},
|
||||
State::Finished => iced::futures::future::pending().await,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum KeyboardBacklightUpdate {
|
||||
Update(f64),
|
||||
Init(UnboundedSender<KeyboardBacklightRequest>, f64),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum KeyboardBacklightRequest {
|
||||
Get,
|
||||
Set(f64),
|
||||
}
|
||||
3398
applets/cosmic-applet-graphics/Cargo.lock
generated
|
|
@ -1,14 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-applet-graphics"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
zbus = "3.4"
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
||||
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", default-features = false }
|
||||
iced_sctk = { git = "https://github.com/pop-os/iced-sctk" }
|
||||
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit" }
|
||||
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Applet Graphics
|
||||
Comment=Write a GTK + Rust application
|
||||
Type=Application
|
||||
Exec=cosmic-applet-graphics
|
||||
Terminal=false
|
||||
Categories=GNOME;GTK;
|
||||
Keywords=Gnome;GTK;
|
||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||
Icon=com.system76.CosmicAppletGraphics.svg
|
||||
StartupNotify=true
|
||||
NoDisplay=true
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10632" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10635" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10638" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10641" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10578">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/com/System76/CosmicDockAppList/">
|
||||
<!-- see https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Application.html#automatic-resources -->
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//! # DBus interface proxy for: `com.system76.PowerDaemon`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `3.0.0` from DBus introspection data.
|
||||
//! Source: `Interface '/com/system76/PowerDaemon' from service 'com.system76.PowerDaemon' on system bus`.
|
||||
//!
|
||||
//! You may prefer to adapt it, instead of using it verbatim.
|
||||
//!
|
||||
//! More information can be found in the
|
||||
//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html)
|
||||
//! section of the zbus documentation.
|
||||
//!
|
||||
//! This DBus object implements
|
||||
//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html),
|
||||
//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used:
|
||||
//!
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use zbus::{dbus_proxy, Connection};
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "com.system76.PowerDaemon",
|
||||
default_path = "/com/system76/PowerDaemon"
|
||||
)]
|
||||
trait PowerDaemon {
|
||||
/// Balanced method
|
||||
fn balanced(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Battery method
|
||||
fn battery(&self) -> zbus::Result<()>;
|
||||
|
||||
/// GetChargeProfiles method
|
||||
fn get_charge_profiles(
|
||||
&self,
|
||||
) -> zbus::Result<Vec<std::collections::HashMap<String, zbus::zvariant::OwnedValue>>>;
|
||||
|
||||
/// GetChargeThresholds method
|
||||
fn get_charge_thresholds(&self) -> zbus::Result<(u8, u8)>;
|
||||
|
||||
/// GetDefaultGraphics method
|
||||
fn get_default_graphics(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetExternalDisplaysRequireDGPU method
|
||||
fn get_external_displays_require_dgpu(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// GetGraphics method
|
||||
fn get_graphics(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetGraphicsPower method
|
||||
fn get_graphics_power(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// GetProfile method
|
||||
fn get_profile(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetSwitchable method
|
||||
fn get_switchable(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Performance method
|
||||
fn performance(&self) -> zbus::Result<()>;
|
||||
|
||||
/// SetChargeThresholds method
|
||||
fn set_charge_thresholds(&self, thresholds: &(u8, u8)) -> zbus::Result<()>;
|
||||
|
||||
/// SetGraphics method
|
||||
fn set_graphics(&self, vendor: &str) -> zbus::Result<()>;
|
||||
|
||||
/// SetGraphicsPower method
|
||||
fn set_graphics_power(&self, power: bool) -> zbus::Result<()>;
|
||||
|
||||
/// HotPlugDetect signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn hot_plug_detect(&self, port: u64) -> zbus::Result<()>;
|
||||
|
||||
/// PowerProfileSwitch signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn power_profile_switch(&self, profile: &str) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
pub async fn init() -> Option<(Connection, PowerDaemonProxy<'static>)> {
|
||||
let conn = match Connection::system().await {
|
||||
Ok(conn) => conn,
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
let proxy = match PowerDaemonProxy::new(&conn).await {
|
||||
Ok(p) => p,
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
Some((conn, proxy))
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
use crate::dbus::PowerDaemonProxy;
|
||||
use zbus::Result;
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
pub enum Graphics {
|
||||
Integrated,
|
||||
Hybrid,
|
||||
Nvidia,
|
||||
Compute,
|
||||
}
|
||||
|
||||
pub async fn get_current_graphics(daemon: PowerDaemonProxy<'_>) -> Result<Graphics> {
|
||||
let graphics = daemon.get_graphics().await?;
|
||||
match graphics.as_str() {
|
||||
"integrated" => Ok(Graphics::Integrated),
|
||||
"hybrid" => Ok(Graphics::Hybrid),
|
||||
"nvidia" => Ok(Graphics::Nvidia),
|
||||
"compute" => Ok(Graphics::Compute),
|
||||
_ => panic!("Unknown graphics profile: {}", graphics),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn set_graphics(daemon: PowerDaemonProxy<'_>, graphics: Graphics) -> Result<()> {
|
||||
let graphics_str = match graphics {
|
||||
Graphics::Integrated => "integrated",
|
||||
Graphics::Hybrid => "hybrid",
|
||||
Graphics::Nvidia => "nvidia",
|
||||
Graphics::Compute => "compute",
|
||||
};
|
||||
daemon.set_graphics(graphics_str).await
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
mod dbus;
|
||||
mod graphics;
|
||||
mod window;
|
||||
|
||||
use cosmic::{
|
||||
iced::{sctk_settings::InitialSurface, Application},
|
||||
iced_native::command::platform_specific::wayland::window::SctkWindowSettings,
|
||||
iced_native::window::Settings,
|
||||
settings, applet::CosmicAppletHelper,
|
||||
};
|
||||
use cosmic_panel_config::PanelSize;
|
||||
use window::*;
|
||||
|
||||
pub fn main() -> cosmic::iced::Result {
|
||||
let helper = CosmicAppletHelper::default();
|
||||
Window::run(helper.window_settings())
|
||||
}
|
||||
|
|
@ -1,290 +0,0 @@
|
|||
use crate::dbus::{self, PowerDaemonProxy};
|
||||
use crate::graphics::{get_current_graphics, set_graphics, Graphics};
|
||||
use cosmic::applet::{CosmicAppletHelper};
|
||||
use cosmic::iced_style::application::{self, Appearance};
|
||||
use cosmic::theme::Button;
|
||||
use cosmic::{
|
||||
iced::widget::{column, radio, text},
|
||||
iced::{self, Application, Command, Length},
|
||||
iced_native::window,
|
||||
theme::Theme,
|
||||
widget::{horizontal_rule},
|
||||
Element,
|
||||
};
|
||||
use cosmic_panel_config::{PanelAnchor, PanelSize};
|
||||
use iced_sctk::alignment::Horizontal;
|
||||
use iced_sctk::application::SurfaceIdWrapper;
|
||||
use iced_sctk::commands::popup::{destroy_popup, get_popup};
|
||||
use iced_sctk::Color;
|
||||
use zbus::Connection;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum State {
|
||||
SelectGraphicsMode(bool),
|
||||
SettingGraphicsMode(Graphics),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum GraphicsMode {
|
||||
SelectedGraphicsMode(Graphics),
|
||||
CurrentGraphicsMode(Graphics),
|
||||
}
|
||||
|
||||
impl GraphicsMode {
|
||||
fn inner(&self) -> Graphics {
|
||||
match self {
|
||||
GraphicsMode::SelectedGraphicsMode(g) => *g,
|
||||
GraphicsMode::CurrentGraphicsMode(g) => *g,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self::SelectGraphicsMode(false)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Window {
|
||||
popup: Option<window::Id>,
|
||||
graphics_mode: Option<GraphicsMode>,
|
||||
id_ctr: u32,
|
||||
icon_size: u16,
|
||||
anchor: PanelAnchor,
|
||||
theme: Theme,
|
||||
dbus: Option<(Connection, PowerDaemonProxy<'static>)>,
|
||||
state: State,
|
||||
applet_helper: CosmicAppletHelper,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Message {
|
||||
CurrentGraphics(Option<Graphics>),
|
||||
SelectedGraphicsMode(Option<Graphics>),
|
||||
DBusInit(Option<(Connection, PowerDaemonProxy<'static>)>),
|
||||
SelectGraphicsMode(Graphics),
|
||||
TogglePopup,
|
||||
PopupClosed(window::Id),
|
||||
}
|
||||
|
||||
impl Application for Window {
|
||||
type Executor = iced::executor::Default;
|
||||
type Flags = ();
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
|
||||
fn new(_flags: ()) -> (Self, Command<Self::Message>) {
|
||||
let mut window = Window::default();
|
||||
let pixels = std::env::var("COSMIC_PANEL_SIZE")
|
||||
.ok()
|
||||
.and_then(|size| match size.parse::<PanelSize>() {
|
||||
Ok(PanelSize::XL) => Some(64),
|
||||
Ok(PanelSize::L) => Some(36),
|
||||
Ok(PanelSize::M) => Some(24),
|
||||
Ok(PanelSize::S) => Some(16),
|
||||
Ok(PanelSize::XS) => Some(12),
|
||||
Err(_) => Some(12),
|
||||
})
|
||||
.unwrap_or(16);
|
||||
window.icon_size = pixels;
|
||||
window.anchor = std::env::var("COSMIC_PANEL_ANCHOR")
|
||||
.ok()
|
||||
.map(|size| match size.parse::<PanelAnchor>() {
|
||||
Ok(p) => p,
|
||||
Err(_) => PanelAnchor::Top,
|
||||
})
|
||||
.unwrap_or(PanelAnchor::Top);
|
||||
(
|
||||
window,
|
||||
Command::perform(dbus::init(), |dbus_init| Message::DBusInit(dbus_init)),
|
||||
)
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Cosmic Graphics Applet")
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> iced::Command<Self::Message> {
|
||||
match message {
|
||||
Message::SelectGraphicsMode(new_graphics_mode) => {
|
||||
if let Some((_, proxy)) = self.dbus.as_ref() {
|
||||
self.state = State::SettingGraphicsMode(new_graphics_mode);
|
||||
return Command::perform(
|
||||
set_graphics(proxy.clone(), new_graphics_mode),
|
||||
move |success| {
|
||||
Message::SelectedGraphicsMode(success.ok().map(|_| new_graphics_mode))
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Message::SelectedGraphicsMode(g) => {
|
||||
if let Some(g) = g {
|
||||
self.graphics_mode
|
||||
.replace(GraphicsMode::SelectedGraphicsMode(g));
|
||||
self.state = State::SelectGraphicsMode(true);
|
||||
}
|
||||
}
|
||||
Message::TogglePopup => {
|
||||
if let Some(p) = self.popup.take() {
|
||||
return destroy_popup(p);
|
||||
} else {
|
||||
self.id_ctr += 1;
|
||||
let new_id = window::Id::new(self.id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
let mut commands = Vec::new();
|
||||
if let Some((_, proxy)) = self.dbus.as_ref() {
|
||||
commands.push(Command::perform(
|
||||
get_current_graphics(proxy.clone()),
|
||||
|cur_graphics| Message::CurrentGraphics(cur_graphics.ok()),
|
||||
));
|
||||
}
|
||||
let popup_settings =
|
||||
self.applet_helper.get_popup_settings(window::Id::new(0), new_id, (200, 240), None, None);
|
||||
commands.push(get_popup(popup_settings));
|
||||
return Command::batch(commands);
|
||||
}
|
||||
}
|
||||
Message::DBusInit(dbus) => {
|
||||
self.dbus = dbus;
|
||||
return Command::perform(
|
||||
get_current_graphics(self.dbus.as_ref().unwrap().1.clone()),
|
||||
|cur_graphics| {
|
||||
Message::CurrentGraphics(match cur_graphics {
|
||||
Ok(g) => Some(g),
|
||||
Err(err) => {
|
||||
dbg!(err);
|
||||
None
|
||||
}
|
||||
})
|
||||
},
|
||||
);
|
||||
}
|
||||
Message::CurrentGraphics(g) => {
|
||||
if let Some(g) = g {
|
||||
self.graphics_mode = Some(match self.graphics_mode.take() {
|
||||
Some(GraphicsMode::CurrentGraphicsMode(_)) | None => {
|
||||
GraphicsMode::CurrentGraphicsMode(g)
|
||||
}
|
||||
Some(g) => g,
|
||||
});
|
||||
}
|
||||
}
|
||||
Message::PopupClosed(id) => {
|
||||
if self.popup.as_ref() == Some(&id) {
|
||||
self.popup = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
Command::none()
|
||||
}
|
||||
|
||||
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Window(_) => self.applet_helper.icon_button("input-gaming-symbolic")
|
||||
.on_press(Message::TogglePopup)
|
||||
.style(Button::Text)
|
||||
.into(),
|
||||
SurfaceIdWrapper::Popup(_) => {
|
||||
let content = match self.state {
|
||||
State::SelectGraphicsMode(pending_restart) => {
|
||||
let mut content_list = vec![
|
||||
radio(
|
||||
"Integrated Graphics",
|
||||
Graphics::Integrated,
|
||||
self.graphics_mode.map(|g| g.inner()),
|
||||
|g| Message::SelectGraphicsMode(g),
|
||||
)
|
||||
.into(),
|
||||
radio(
|
||||
"Nvidia Graphics",
|
||||
Graphics::Nvidia,
|
||||
self.graphics_mode.map(|g| g.inner()),
|
||||
|g| Message::SelectGraphicsMode(g),
|
||||
)
|
||||
.into(),
|
||||
radio(
|
||||
"Hybrid Graphics",
|
||||
Graphics::Hybrid,
|
||||
self.graphics_mode.map(|g| g.inner()),
|
||||
|g| Message::SelectGraphicsMode(g),
|
||||
)
|
||||
.into(),
|
||||
radio(
|
||||
"Compute Graphics",
|
||||
Graphics::Compute,
|
||||
self.graphics_mode.map(|g| g.inner()),
|
||||
|g| Message::SelectGraphicsMode(g),
|
||||
)
|
||||
.into(),
|
||||
];
|
||||
if pending_restart {
|
||||
content_list.insert(
|
||||
0,
|
||||
text("Restart to apply changes")
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(Horizontal::Center)
|
||||
.size(16)
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
column(content_list).padding([8, 0]).spacing(8).into()
|
||||
}
|
||||
State::SettingGraphicsMode(graphics) => {
|
||||
let graphics_str = match graphics {
|
||||
Graphics::Integrated => "integrated",
|
||||
Graphics::Hybrid => "hybrid",
|
||||
Graphics::Nvidia => "nvidia",
|
||||
Graphics::Compute => "compute",
|
||||
};
|
||||
column(vec![text(format!(
|
||||
"Setting graphics mode to {graphics_str}..."
|
||||
))
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(Horizontal::Center)
|
||||
.into()])
|
||||
.into()
|
||||
}
|
||||
};
|
||||
self.applet_helper.popup_container(
|
||||
column(vec![
|
||||
text("Graphics Mode")
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(Horizontal::Center)
|
||||
.size(24)
|
||||
.into(),
|
||||
horizontal_rule(1).into(),
|
||||
content,
|
||||
])
|
||||
.padding(4)
|
||||
.spacing(4),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn close_requested(&self, id: SurfaceIdWrapper) -> Self::Message {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) | SurfaceIdWrapper::Window(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Popup(id) => Message::PopupClosed(id),
|
||||
}
|
||||
}
|
||||
|
||||
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
|
||||
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||
text_color: theme.cosmic().on_bg_color().into(),
|
||||
})
|
||||
}
|
||||
|
||||
fn should_exit(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
}
|
||||
}
|
||||
3986
applets/cosmic-applet-network/Cargo.lock
generated
|
|
@ -1,32 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-applet-network"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[dependencies]
|
||||
once_cell = "1.16.0"
|
||||
cosmic-dbus-networkmanager = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
||||
futures-util = "0.3.21"
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
||||
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", default-features = false }
|
||||
iced_sctk = { git = "https://github.com/pop-os/iced-sctk" }
|
||||
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", version = "0.16" }
|
||||
futures = "0.3"
|
||||
zbus = { version = "3.5", no-default-features = true }
|
||||
log = "0.4"
|
||||
pretty_env_logger = "0.4"
|
||||
# Application i18n
|
||||
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
|
||||
i18n-embed-fl = "0.6.4"
|
||||
rust-embed = "6.3.0"
|
||||
itertools = "0.10.3"
|
||||
slotmap = "1.0.6"
|
||||
tokio = { version = "1.15.0", features = ["full"] }
|
||||
|
||||
[dependencies.iced]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
# path = "../iced"
|
||||
default-features = false
|
||||
features = ["image", "svg", "tokio"]
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Applet Network
|
||||
Comment=Write a GTK + Rust application
|
||||
Type=Application
|
||||
Exec=cosmic-applet-network
|
||||
Terminal=false
|
||||
Categories=GNOME;GTK;
|
||||
Keywords=Gnome;GTK;
|
||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||
Icon=com.system76.CosmicAppletNetwork.svg
|
||||
StartupNotify=true
|
||||
NoDisplay=true
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10632" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10635" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10638" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10641" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10578">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/com/System76/CosmicDockAppList/">
|
||||
<!-- see https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Application.html#automatic-resources -->
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
fallback_language = "en"
|
||||
|
||||
[fluent]
|
||||
assets_dir = "i18n"
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
network = Network
|
||||
airplane-mode = Airplane mode
|
||||
wifi = Wi-Fi
|
||||
ipv4 = IPv4 Address
|
||||
ipv6 = IPv6 Address
|
||||
mac = MAC
|
||||
megabits-per-second = Mbps
|
||||
|
|
@ -1,344 +0,0 @@
|
|||
use cosmic::{
|
||||
applet::CosmicAppletHelper,
|
||||
iced::{
|
||||
executor,
|
||||
widget::{column, container, row, scrollable, text},
|
||||
Alignment, Application, Color, Command, Length, Subscription,
|
||||
},
|
||||
iced_native::window,
|
||||
iced_style::{application, svg},
|
||||
theme::{Button, Svg},
|
||||
widget::{button, horizontal_rule, icon, list_column, toggler},
|
||||
Element, Theme,
|
||||
};
|
||||
use futures::channel::mpsc::UnboundedSender;
|
||||
use iced_sctk::{
|
||||
application::SurfaceIdWrapper,
|
||||
commands::popup::{destroy_popup, get_popup},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
config, fl,
|
||||
network_manager::{
|
||||
available_wifi::AccessPoint, current_networks::ActiveConnectionInfo,
|
||||
network_manager_subscription, NetworkManagerEvent, NetworkManagerRequest,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn run() -> cosmic::iced::Result {
|
||||
let helper = CosmicAppletHelper::default();
|
||||
CosmicNetworkApplet::run(helper.window_settings())
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct CosmicNetworkApplet {
|
||||
icon_name: String,
|
||||
theme: Theme,
|
||||
popup: Option<window::Id>,
|
||||
id_ctr: u32,
|
||||
applet_helper: CosmicAppletHelper,
|
||||
// STATE
|
||||
airplane_mode: bool,
|
||||
wifi: bool,
|
||||
wireless_access_points: Vec<AccessPoint>,
|
||||
active_conns: Vec<ActiveConnectionInfo>,
|
||||
nm_sender: Option<UnboundedSender<NetworkManagerRequest>>,
|
||||
}
|
||||
|
||||
impl CosmicNetworkApplet {
|
||||
fn update_icon_name(&mut self) {
|
||||
self.icon_name = self
|
||||
.active_conns
|
||||
.iter()
|
||||
.fold("network-offline-symbolic", |icon_name, conn| {
|
||||
match (icon_name, conn) {
|
||||
("network-offline-symbolic", ActiveConnectionInfo::WiFi { .. }) => {
|
||||
"network-wireless-symbolic"
|
||||
}
|
||||
(
|
||||
"network-offline-symbolic",
|
||||
ActiveConnectionInfo::Wired { .. },
|
||||
)
|
||||
| (
|
||||
"network-wireless-symbolic",
|
||||
ActiveConnectionInfo::Wired { .. },
|
||||
) => "network-wired-symbolic",
|
||||
(_, ActiveConnectionInfo::Vpn { .. }) => "network-vpn-symbolic",
|
||||
_ => icon_name,
|
||||
}
|
||||
})
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
TogglePopup,
|
||||
ToggleAirplaneMode(bool),
|
||||
ToggleWiFi(bool),
|
||||
Errored(String),
|
||||
Ignore,
|
||||
NetworkManagerEvent(NetworkManagerEvent),
|
||||
SelectWirelessAccessPoint(String),
|
||||
}
|
||||
|
||||
impl Application for CosmicNetworkApplet {
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Executor = executor::Default;
|
||||
type Flags = ();
|
||||
|
||||
fn new(_flags: ()) -> (Self, Command<Message>) {
|
||||
(
|
||||
CosmicNetworkApplet {
|
||||
icon_name: "network-offline-symbolic".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
config::APP_ID.to_string()
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::TogglePopup => {
|
||||
if let Some(p) = self.popup.take() {
|
||||
return destroy_popup(p);
|
||||
} else {
|
||||
// TODO request update of state maybe
|
||||
self.id_ctr += 1;
|
||||
let new_id = window::Id::new(self.id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
|
||||
let popup_settings = self.applet_helper.get_popup_settings(
|
||||
window::Id::new(0),
|
||||
new_id,
|
||||
(420, 600),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
return get_popup(popup_settings);
|
||||
}
|
||||
}
|
||||
Message::Errored(_) => todo!(),
|
||||
Message::Ignore => {}
|
||||
Message::ToggleAirplaneMode(enabled) => {
|
||||
self.airplane_mode = enabled;
|
||||
// TODO apply changes
|
||||
}
|
||||
Message::ToggleWiFi(enabled) => {
|
||||
self.wifi = enabled;
|
||||
if let Some(tx) = self.nm_sender.as_mut() {
|
||||
let _ = tx.unbounded_send(NetworkManagerRequest::SetWiFi(enabled));
|
||||
}
|
||||
}
|
||||
Message::NetworkManagerEvent(event) => match event {
|
||||
NetworkManagerEvent::Init {
|
||||
sender,
|
||||
wireless_access_points,
|
||||
active_conns,
|
||||
wifi_enabled,
|
||||
airplane_mode,
|
||||
} => {
|
||||
self.nm_sender.replace(sender);
|
||||
self.wireless_access_points = wireless_access_points;
|
||||
self.active_conns = active_conns;
|
||||
self.wifi = wifi_enabled;
|
||||
self.airplane_mode = airplane_mode;
|
||||
self.update_icon_name();
|
||||
}
|
||||
NetworkManagerEvent::WiFiEnabled(enabled) => {
|
||||
self.wifi = enabled;
|
||||
}
|
||||
NetworkManagerEvent::WirelessAccessPoints(access_points) => {
|
||||
self.wireless_access_points = access_points;
|
||||
}
|
||||
NetworkManagerEvent::ActiveConns(conns) => {
|
||||
self.active_conns = conns;
|
||||
self.update_icon_name();
|
||||
}
|
||||
NetworkManagerEvent::RequestResponse { wireless_access_points, active_conns, wifi_enabled, success, ..} => {
|
||||
if success {
|
||||
self.wireless_access_points = wireless_access_points;
|
||||
self.active_conns = active_conns;
|
||||
self.wifi = wifi_enabled;
|
||||
self.update_icon_name();
|
||||
}
|
||||
},
|
||||
},
|
||||
Message::SelectWirelessAccessPoint(ssid) => {
|
||||
if let Some(tx) = self.nm_sender.as_ref() {
|
||||
let _ = tx.unbounded_send(NetworkManagerRequest::SelectAccessPoint(ssid));
|
||||
}
|
||||
}
|
||||
}
|
||||
Command::none()
|
||||
}
|
||||
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Window(_) => self
|
||||
.applet_helper
|
||||
.icon_button(&self.icon_name)
|
||||
.on_press(Message::TogglePopup)
|
||||
.into(),
|
||||
SurfaceIdWrapper::Popup(_) => {
|
||||
let name = text(fl!("network")).size(18);
|
||||
let icon = icon(&self.icon_name, 24)
|
||||
.style(Svg::Custom(|theme| svg::Appearance {
|
||||
fill: Some(theme.palette().text),
|
||||
}))
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24));
|
||||
let mut list_col = list_column();
|
||||
|
||||
for conn in &self.active_conns {
|
||||
let el = match conn {
|
||||
ActiveConnectionInfo::Vpn { name, ip_addresses } => {
|
||||
let mut ipv4 = column![];
|
||||
let mut ipv6 = column![];
|
||||
for addr in ip_addresses {
|
||||
match addr {
|
||||
std::net::IpAddr::V4(a) => {
|
||||
ipv4 = ipv4.push(text(format!(
|
||||
"{}: {}",
|
||||
fl!("ipv4"),
|
||||
a.to_string()
|
||||
)));
|
||||
}
|
||||
std::net::IpAddr::V6(a) => {
|
||||
ipv6 = ipv6.push(text(format!(
|
||||
"{}: {}",
|
||||
fl!("ipv6"),
|
||||
a.to_string()
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
column![text(name), ipv4, ipv6].spacing(4)
|
||||
}
|
||||
ActiveConnectionInfo::Wired {
|
||||
name,
|
||||
hw_address,
|
||||
speed,
|
||||
ip_addresses,
|
||||
} => {
|
||||
let mut ipv4 = column![];
|
||||
let mut ipv6 = column![];
|
||||
for addr in ip_addresses {
|
||||
match addr {
|
||||
std::net::IpAddr::V4(a) => {
|
||||
ipv4 = ipv4.push(text(format!(
|
||||
"{}: {}",
|
||||
fl!("ipv4"),
|
||||
a.to_string()
|
||||
)));
|
||||
}
|
||||
std::net::IpAddr::V6(a) => {
|
||||
ipv6 = ipv6.push(text(format!(
|
||||
"{}: {}",
|
||||
fl!("ipv6"),
|
||||
a.to_string()
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
column![
|
||||
row![
|
||||
text(name),
|
||||
text(format!("{speed} {}", fl!("megabits-per-second")))
|
||||
]
|
||||
.spacing(16),
|
||||
ipv4,
|
||||
ipv6,
|
||||
text(format!("{}: {hw_address}", fl!("mac"))),
|
||||
]
|
||||
.spacing(4)
|
||||
}
|
||||
ActiveConnectionInfo::WiFi {
|
||||
name, hw_address, ..
|
||||
} => column![row![
|
||||
text(name),
|
||||
text(format!("{}: {hw_address}", fl!("mac")))
|
||||
]
|
||||
.spacing(12)]
|
||||
.spacing(4),
|
||||
};
|
||||
list_col = list_col.add(el);
|
||||
}
|
||||
|
||||
let mut content = column![
|
||||
row![icon, name].spacing(8).width(Length::Fill),
|
||||
list_col,
|
||||
horizontal_rule(1),
|
||||
container(
|
||||
toggler(fl!("airplane-mode"), self.airplane_mode, |m| {
|
||||
Message::ToggleAirplaneMode(m)
|
||||
})
|
||||
.width(Length::Fill)
|
||||
)
|
||||
.padding([0, 12]),
|
||||
horizontal_rule(1),
|
||||
container(
|
||||
toggler(fl!("wifi"), self.wifi, |m| { Message::ToggleWiFi(m) })
|
||||
.width(Length::Fill)
|
||||
)
|
||||
.padding([0, 12]),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(8)
|
||||
.padding(8);
|
||||
if self.wifi {
|
||||
let mut list_col = list_column();
|
||||
for ap in &self.wireless_access_points {
|
||||
let button = self
|
||||
.active_conns
|
||||
.iter()
|
||||
.find_map(|conn| match conn {
|
||||
ActiveConnectionInfo::WiFi { name, .. } if name == &ap.ssid => {
|
||||
Some(
|
||||
button(Button::Primary)
|
||||
.text(&ap.ssid)
|
||||
.on_press(Message::Ignore)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
button(Button::Text)
|
||||
.text(&ap.ssid)
|
||||
.on_press(Message::SelectWirelessAccessPoint(ap.ssid.clone()))
|
||||
.width(Length::Fill)
|
||||
});
|
||||
list_col = list_col.add(button);
|
||||
}
|
||||
content = content.push(scrollable(list_col).height(Length::Fill));
|
||||
}
|
||||
self.applet_helper.popup_container(content).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
network_manager_subscription(0).map(|(_, event)| Message::NetworkManagerEvent(event))
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
}
|
||||
|
||||
fn close_requested(&self, _id: iced_sctk::application::SurfaceIdWrapper) -> Self::Message {
|
||||
Message::Ignore
|
||||
}
|
||||
|
||||
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| application::Appearance {
|
||||
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||
text_color: theme.cosmic().on_bg_color().into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
pub const APP_ID: &str = "com.system76.CosmicAppletNetwork";
|
||||
pub const PROFILE: &str = "";
|
||||
pub const VERSION: &str = "0.1.0";
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
// SPDX-License-Identifier: MPL-2.0-only
|
||||
|
||||
use i18n_embed::{
|
||||
fluent::{fluent_language_loader, FluentLanguageLoader},
|
||||
DefaultLocalizer, LanguageLoader, Localizer,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "i18n/"]
|
||||
struct Localizations;
|
||||
|
||||
pub static LANGUAGE_LOADER: Lazy<FluentLanguageLoader> = Lazy::new(|| {
|
||||
let loader: FluentLanguageLoader = fluent_language_loader!();
|
||||
|
||||
loader
|
||||
.load_fallback_language(&Localizations)
|
||||
.expect("Error while loading fallback language");
|
||||
|
||||
loader
|
||||
});
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! fl {
|
||||
($message_id:literal) => {{
|
||||
i18n_embed_fl::fl!($crate::localize::LANGUAGE_LOADER, $message_id)
|
||||
}};
|
||||
|
||||
($message_id:literal, $($args:expr),*) => {{
|
||||
i18n_embed_fl::fl!($crate::localize::LANGUAGE_LOADER, $message_id, $($args), *)
|
||||
}};
|
||||
}
|
||||
|
||||
// Get the `Localizer` to be used for localizing this library.
|
||||
pub fn localizer() -> Box<dyn Localizer> {
|
||||
Box::from(DefaultLocalizer::new(&*LANGUAGE_LOADER, &Localizations))
|
||||
}
|
||||
|
||||
pub fn localize() {
|
||||
let localizer = localizer();
|
||||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
mod app;
|
||||
mod config;
|
||||
mod localize;
|
||||
mod network_manager;
|
||||
|
||||
use log::info;
|
||||
|
||||
use crate::config::{APP_ID, PROFILE, VERSION};
|
||||
use crate::localize::localize;
|
||||
|
||||
fn main() -> cosmic::iced::Result {
|
||||
// Initialize logger
|
||||
pretty_env_logger::init();
|
||||
info!("Iced Workspaces Applet ({})", APP_ID);
|
||||
info!("Version: {} ({})", VERSION, PROFILE);
|
||||
|
||||
// Prepare i18n
|
||||
localize();
|
||||
|
||||
app::run()
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use cosmic_dbus_networkmanager::device::wireless::WirelessDevice;
|
||||
|
||||
use futures_util::StreamExt;
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub async fn handle_wireless_device(device: WirelessDevice<'_>) -> zbus::Result<Vec<AccessPoint>> {
|
||||
device.request_scan(HashMap::new()).await?;
|
||||
let mut scan_changed = device.receive_last_scan_changed().await;
|
||||
if let Some(t) = scan_changed.next().await {
|
||||
if let Ok(-1) = t.get().await {
|
||||
eprintln!("scan errored");
|
||||
return Ok(Default::default());
|
||||
}
|
||||
}
|
||||
let access_points = device.get_access_points().await?;
|
||||
// Sort by strength and remove duplicates
|
||||
let mut aps = HashMap::<String, AccessPoint>::new();
|
||||
for ap in access_points {
|
||||
let ssid = String::from_utf8_lossy(&ap.ssid().await?.clone()).into_owned();
|
||||
let strength = ap.strength().await?;
|
||||
if let Some(access_point) = aps.get(&ssid) {
|
||||
if access_point.strength > strength {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
aps.insert(ssid.clone(), AccessPoint { ssid, strength });
|
||||
}
|
||||
let aps = aps
|
||||
.into_iter()
|
||||
.map(|(_, x)| x)
|
||||
.sorted_by(|a, b| b.strength.cmp(&a.strength))
|
||||
.collect();
|
||||
Ok(aps)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AccessPoint {
|
||||
pub ssid: String,
|
||||
pub strength: u8,
|
||||
}
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use cosmic_dbus_networkmanager::{
|
||||
active_connection::ActiveConnection,
|
||||
device::SpecificDevice,
|
||||
interface::enums::{ApFlags, ApSecurityFlags},
|
||||
};
|
||||
use std::net::IpAddr;
|
||||
|
||||
pub async fn active_connections(
|
||||
active_connections: Vec<ActiveConnection<'_>>,
|
||||
) -> zbus::Result<Vec<ActiveConnectionInfo>> {
|
||||
let mut info = Vec::<ActiveConnectionInfo>::with_capacity(active_connections.len());
|
||||
for connection in active_connections {
|
||||
if connection.vpn().await.unwrap_or_default() {
|
||||
let mut ip_addresses = Vec::new();
|
||||
for address_data in connection.ip4_config().await?.address_data().await.unwrap_or_default() {
|
||||
ip_addresses.push(IpAddr::V4(address_data.address));
|
||||
}
|
||||
for address_data in connection.ip6_config().await?.address_data().await.unwrap_or_default() {
|
||||
ip_addresses.push(IpAddr::V6(address_data.address));
|
||||
}
|
||||
info.push(ActiveConnectionInfo::Vpn {
|
||||
name: connection.id().await?,
|
||||
ip_addresses,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
for device in connection.devices().await.unwrap_or_default() {
|
||||
match device.downcast_to_device().await.ok().and_then(|inner| inner) {
|
||||
Some(SpecificDevice::Wired(wired_device)) => {
|
||||
let mut ip_addresses = Vec::new();
|
||||
for address_data in device.ip4_config().await?.address_data().await.unwrap_or_default() {
|
||||
ip_addresses.push(IpAddr::V4(address_data.address));
|
||||
}
|
||||
for address_data in device.ip6_config().await?.address_data().await.unwrap_or_default() {
|
||||
ip_addresses.push(IpAddr::V6(address_data.address));
|
||||
}
|
||||
info.push(ActiveConnectionInfo::Wired {
|
||||
name: connection.id().await?,
|
||||
hw_address: wired_device.hw_address().await?,
|
||||
speed: wired_device.speed().await?,
|
||||
ip_addresses,
|
||||
});
|
||||
}
|
||||
Some(SpecificDevice::Wireless(wireless_device)) => {
|
||||
if let Ok(access_point) = wireless_device.active_access_point().await {
|
||||
info.push(ActiveConnectionInfo::WiFi {
|
||||
name: String::from_utf8_lossy(&access_point.ssid().await?).into_owned(),
|
||||
hw_address: wireless_device.hw_address().await?,
|
||||
flags: access_point.flags().await?,
|
||||
rsn_flags: access_point.rsn_flags().await?,
|
||||
wpa_flags: access_point.wpa_flags().await?,
|
||||
});
|
||||
}
|
||||
}
|
||||
Some(SpecificDevice::WireGuard(_)) => {
|
||||
let mut ip_addresses = Vec::new();
|
||||
for address_data in connection.ip4_config().await?.address_data().await.unwrap_or_default() {
|
||||
ip_addresses.push(IpAddr::V4(address_data.address));
|
||||
}
|
||||
for address_data in connection.ip6_config().await?.address_data().await.unwrap_or_default() {
|
||||
ip_addresses.push(IpAddr::V6(address_data.address));
|
||||
}
|
||||
info.push(ActiveConnectionInfo::Vpn {
|
||||
name: connection.id().await?,
|
||||
ip_addresses,
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info.sort_by(|a, b| {
|
||||
let helper = |conn: &ActiveConnectionInfo| {
|
||||
match conn {
|
||||
ActiveConnectionInfo::Vpn { name, .. } => format!("0{name}"),
|
||||
ActiveConnectionInfo::Wired { name, .. } => format!("1{name}"),
|
||||
ActiveConnectionInfo::WiFi { name, .. } => format!("2{name}"),
|
||||
}
|
||||
};
|
||||
helper(a).cmp(&helper(b))
|
||||
});
|
||||
|
||||
Ok(info)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ActiveConnectionInfo {
|
||||
Wired {
|
||||
name: String,
|
||||
hw_address: String,
|
||||
speed: u32,
|
||||
ip_addresses: Vec<IpAddr>,
|
||||
},
|
||||
WiFi {
|
||||
name: String,
|
||||
hw_address: String,
|
||||
flags: ApFlags,
|
||||
rsn_flags: ApSecurityFlags,
|
||||
wpa_flags: ApSecurityFlags,
|
||||
},
|
||||
Vpn {
|
||||
name: String,
|
||||
ip_addresses: Vec<IpAddr>,
|
||||
},
|
||||
}
|
||||
|
|
@ -1,242 +0,0 @@
|
|||
pub mod available_wifi;
|
||||
pub mod current_networks;
|
||||
|
||||
use std::{fmt::Debug, hash::Hash, time::Duration};
|
||||
|
||||
use cosmic::iced::{self, subscription};
|
||||
use cosmic_dbus_networkmanager::{
|
||||
device::SpecificDevice, interface::enums::DeviceType, nm::NetworkManager,
|
||||
};
|
||||
use futures::{
|
||||
channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender},
|
||||
FutureExt, StreamExt,
|
||||
};
|
||||
use zbus::Connection;
|
||||
|
||||
use self::{
|
||||
available_wifi::{handle_wireless_device, AccessPoint},
|
||||
current_networks::{active_connections, ActiveConnectionInfo},
|
||||
};
|
||||
|
||||
// TODO subscription for wifi list & selection of wifi
|
||||
// TODO subscription & channel for enabling / disabling wifi
|
||||
// TODO subscription for displaying active connections & devices
|
||||
|
||||
pub fn network_manager_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
||||
id: I,
|
||||
) -> iced::Subscription<(I, NetworkManagerEvent)> {
|
||||
subscription::unfold(id, State::Ready, move |state| start_listening(id, state))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum State {
|
||||
Ready,
|
||||
Waiting(Connection, UnboundedReceiver<NetworkManagerRequest>),
|
||||
Finished,
|
||||
}
|
||||
|
||||
async fn start_listening<I: Copy>(
|
||||
id: I,
|
||||
state: State,
|
||||
) -> (Option<(I, NetworkManagerEvent)>, State) {
|
||||
match state {
|
||||
State::Ready => {
|
||||
let conn = match Connection::system().await {
|
||||
Ok(c) => c,
|
||||
Err(_) => return (None, State::Finished),
|
||||
};
|
||||
let network_manager = match NetworkManager::new(&conn).await {
|
||||
Ok(n) => n,
|
||||
Err(_) => return (None, State::Finished),
|
||||
};
|
||||
let (tx, rx) = unbounded();
|
||||
let mut active_conns = active_connections(
|
||||
network_manager
|
||||
.active_connections()
|
||||
.await
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
active_conns.sort_by(|a, b| {
|
||||
let helper = |conn: &ActiveConnectionInfo| match conn {
|
||||
ActiveConnectionInfo::Vpn { name, .. } => format!("0{name}"),
|
||||
ActiveConnectionInfo::Wired { name, .. } => format!("1{name}"),
|
||||
ActiveConnectionInfo::WiFi { name, .. } => format!("2{name}"),
|
||||
};
|
||||
helper(a).cmp(&helper(b))
|
||||
});
|
||||
let wifi_enabled = network_manager.wireless_enabled().await.unwrap_or_default();
|
||||
let devices = network_manager.devices().await.ok().unwrap_or_default();
|
||||
let wireless_access_point_futures: Vec<_> = devices
|
||||
.into_iter()
|
||||
.map(|device| async move {
|
||||
if let Ok(Some(SpecificDevice::Wireless(wireless_device))) =
|
||||
device.downcast_to_device().await
|
||||
{
|
||||
handle_wireless_device(wireless_device)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let mut wireless_access_points =
|
||||
Vec::with_capacity(wireless_access_point_futures.len());
|
||||
for f in wireless_access_point_futures {
|
||||
wireless_access_points.append(&mut f.await);
|
||||
}
|
||||
wireless_access_points.sort_by(|a, b| b.strength.cmp(&a.strength));
|
||||
drop(network_manager);
|
||||
return (
|
||||
Some((
|
||||
id,
|
||||
NetworkManagerEvent::Init {
|
||||
sender: tx,
|
||||
wireless_access_points,
|
||||
wifi_enabled,
|
||||
airplane_mode: false,
|
||||
active_conns,
|
||||
},
|
||||
)),
|
||||
State::Waiting(conn, rx),
|
||||
);
|
||||
}
|
||||
State::Waiting(conn, mut rx) => {
|
||||
let network_manager = match NetworkManager::new(&conn).await {
|
||||
Ok(n) => n,
|
||||
Err(_) => return (None, State::Finished),
|
||||
};
|
||||
let mut active_conns_changed = tokio::time::sleep(Duration::from_secs(5))
|
||||
.then(|_| async { network_manager.receive_active_connections_changed().await })
|
||||
.await;
|
||||
let mut devices_changed = network_manager.receive_devices_changed().await;
|
||||
let mut wireless_enabled_changed =
|
||||
network_manager.receive_wireless_enabled_changed().await;
|
||||
let mut req = rx.next().boxed().fuse();
|
||||
|
||||
let (update, should_exit) = futures::select! {
|
||||
req = req => {
|
||||
match req {
|
||||
Some(NetworkManagerRequest::SetAirplaneMode(state)) => {
|
||||
// TODO set airplane mode
|
||||
let _ = network_manager.set_wireless_enabled(state).await;
|
||||
(None, false)
|
||||
}
|
||||
Some(NetworkManagerRequest::SetWiFi(enabled)) => {
|
||||
let success = network_manager.set_wireless_enabled(enabled).await.is_ok();
|
||||
let active_conns = active_connections(network_manager.active_connections().await.unwrap_or_default()).await.unwrap_or_default();
|
||||
let devices = network_manager.devices().await.ok().unwrap_or_default();
|
||||
let wireless_access_point_futures: Vec<_> = devices.into_iter().map(|device| async move {
|
||||
if let Ok(Some(SpecificDevice::Wireless(wireless_device))) =
|
||||
device.downcast_to_device().await
|
||||
{
|
||||
handle_wireless_device(wireless_device).await.unwrap_or_default()
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
}).collect();
|
||||
let mut wireless_access_points = Vec::with_capacity(wireless_access_point_futures.len());
|
||||
for f in wireless_access_point_futures {
|
||||
wireless_access_points.append(&mut f.await);
|
||||
}
|
||||
(Some((id, NetworkManagerEvent::RequestResponse {
|
||||
req: NetworkManagerRequest::SetWiFi(enabled),
|
||||
success,
|
||||
active_conns,
|
||||
wireless_access_points,
|
||||
wifi_enabled: enabled,
|
||||
airplane_mode: false,
|
||||
})), false)
|
||||
}
|
||||
Some(NetworkManagerRequest::SelectAccessPoint(ssid)) => {
|
||||
'device_loop: for device in network_manager.devices().await.ok().unwrap_or_default() {
|
||||
if matches!(device.device_type().await.unwrap_or(DeviceType::Other), DeviceType::Wifi) {
|
||||
for conn in device.available_connections().await.unwrap_or_default() {
|
||||
// dbg!(&conn.path());
|
||||
// TODO activate connection
|
||||
}
|
||||
}
|
||||
}
|
||||
(None, false)
|
||||
}
|
||||
None => {
|
||||
(None, true)
|
||||
}
|
||||
}}
|
||||
_ = active_conns_changed.next().boxed().fuse() => {
|
||||
let active_conns = active_connections(network_manager.active_connections().await.unwrap_or_default()).await.unwrap_or_default();
|
||||
|
||||
(Some((id, NetworkManagerEvent::ActiveConns(active_conns))), false)
|
||||
}
|
||||
_ = devices_changed.next().boxed().fuse() => {
|
||||
let devices = network_manager.devices().await.ok().unwrap_or_default();
|
||||
let wireless_access_point_futures: Vec<_> = devices.into_iter().map(|device| async move {
|
||||
if let Ok(Some(SpecificDevice::Wireless(wireless_device))) =
|
||||
device.downcast_to_device().await
|
||||
{
|
||||
handle_wireless_device(wireless_device).await.unwrap_or_default()
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
}).collect();
|
||||
let mut wireless_access_points = Vec::with_capacity(wireless_access_point_futures.len());
|
||||
for f in wireless_access_point_futures {
|
||||
wireless_access_points.append(&mut f.await);
|
||||
}
|
||||
(Some((id, NetworkManagerEvent::WirelessAccessPoints(wireless_access_points))), false)
|
||||
}
|
||||
enabled = wireless_enabled_changed.next().boxed().fuse() => {
|
||||
let update = if let Some(update) = enabled {
|
||||
update.get().await.ok().map(|update| (id, NetworkManagerEvent::WiFiEnabled(update)))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
(update, false)
|
||||
}
|
||||
};
|
||||
drop(active_conns_changed);
|
||||
drop(wireless_enabled_changed);
|
||||
drop(req);
|
||||
(
|
||||
update,
|
||||
if should_exit {
|
||||
State::Finished
|
||||
} else {
|
||||
State::Waiting(conn, rx)
|
||||
},
|
||||
)
|
||||
}
|
||||
State::Finished => iced::futures::future::pending().await,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum NetworkManagerRequest {
|
||||
SetAirplaneMode(bool),
|
||||
SetWiFi(bool),
|
||||
SelectAccessPoint(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum NetworkManagerEvent {
|
||||
Init {
|
||||
sender: UnboundedSender<NetworkManagerRequest>,
|
||||
wireless_access_points: Vec<AccessPoint>,
|
||||
active_conns: Vec<ActiveConnectionInfo>,
|
||||
wifi_enabled: bool,
|
||||
airplane_mode: bool,
|
||||
},
|
||||
RequestResponse {
|
||||
req: NetworkManagerRequest,
|
||||
wireless_access_points: Vec<AccessPoint>,
|
||||
active_conns: Vec<ActiveConnectionInfo>,
|
||||
wifi_enabled: bool,
|
||||
airplane_mode: bool,
|
||||
success: bool,
|
||||
},
|
||||
WiFiEnabled(bool),
|
||||
WirelessAccessPoints(Vec<AccessPoint>),
|
||||
ActiveConns(Vec<ActiveConnectionInfo>),
|
||||
}
|
||||
3241
applets/cosmic-applet-notifications/Cargo.lock
generated
|
|
@ -1,10 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-applet-notifications"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[dependencies]
|
||||
icon-loader = { version = "0.3.6", features = ["gtk"] }
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
||||
nix = "0.24.1"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Applet Notifications
|
||||
Type=Application
|
||||
Exec=cosmic-applet-notifications
|
||||
Terminal=false
|
||||
Categories=GNOME;GTK;
|
||||
Keywords=Gnome;GTK;
|
||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||
Icon=com.system76.CosmicAppletNotifications
|
||||
NoDisplay=true
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10632" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10635" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10638" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10641" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10578">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
|
@ -1,189 +0,0 @@
|
|||
use cosmic::applet::CosmicAppletHelper;
|
||||
use cosmic::iced::wayland::{
|
||||
popup::{destroy_popup, get_popup},
|
||||
SurfaceIdWrapper,
|
||||
};
|
||||
use cosmic::iced::{
|
||||
executor,
|
||||
widget::{button, column, horizontal_rule, row, text, Row, Space},
|
||||
window, Alignment, Application, Color, Command, Length, Subscription,
|
||||
};
|
||||
|
||||
use cosmic::iced_style::application::{self, Appearance};
|
||||
use cosmic::iced_style::svg;
|
||||
use cosmic::theme::{self, Svg};
|
||||
use cosmic::widget::icon;
|
||||
use cosmic::widget::toggler;
|
||||
use cosmic::Renderer;
|
||||
use cosmic::{Element, Theme};
|
||||
|
||||
use std::process;
|
||||
|
||||
pub fn main() -> cosmic::iced::Result {
|
||||
let helper = CosmicAppletHelper::default();
|
||||
Notifications::run(helper.window_settings())
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Notifications {
|
||||
applet_helper: CosmicAppletHelper,
|
||||
theme: Theme,
|
||||
icon_name: String,
|
||||
popup: Option<window::Id>,
|
||||
id_ctr: u32,
|
||||
do_not_disturb: bool,
|
||||
notifications: Vec<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
TogglePopup,
|
||||
DoNotDisturb(bool),
|
||||
Settings,
|
||||
Ignore,
|
||||
}
|
||||
|
||||
impl Application for Notifications {
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Executor = executor::Default;
|
||||
type Flags = ();
|
||||
|
||||
fn new(_flags: ()) -> (Notifications, Command<Message>) {
|
||||
(
|
||||
Notifications {
|
||||
icon_name: "notification-alert-symbolic".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Notifications")
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
}
|
||||
|
||||
fn close_requested(&self, _id: SurfaceIdWrapper) -> Self::Message {
|
||||
Message::Ignore
|
||||
}
|
||||
|
||||
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
|
||||
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||
text_color: theme.cosmic().on_bg_color().into(),
|
||||
})
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
Subscription::none()
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::TogglePopup => {
|
||||
if let Some(p) = self.popup.take() {
|
||||
destroy_popup(p)
|
||||
} else {
|
||||
self.id_ctr += 1;
|
||||
let new_id = window::Id::new(self.id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
|
||||
let popup_settings = self.applet_helper.get_popup_settings(
|
||||
window::Id::new(0),
|
||||
new_id,
|
||||
(400, 300),
|
||||
Some(60),
|
||||
None,
|
||||
);
|
||||
get_popup(popup_settings)
|
||||
}
|
||||
}
|
||||
Message::DoNotDisturb(b) => {
|
||||
self.do_not_disturb = b;
|
||||
Command::none()
|
||||
}
|
||||
Message::Settings => {
|
||||
let _ = process::Command::new("cosmic-settings notifications").spawn();
|
||||
Command::none()
|
||||
}
|
||||
Message::Ignore => Command::none(),
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Window(_) => self
|
||||
.applet_helper
|
||||
.icon_button(&self.icon_name)
|
||||
.on_press(Message::TogglePopup)
|
||||
.into(),
|
||||
SurfaceIdWrapper::Popup(_) => {
|
||||
let do_not_disturb =
|
||||
row![
|
||||
toggler(String::from("Do Not Disturb"), self.do_not_disturb, |b| {
|
||||
Message::DoNotDisturb(b)
|
||||
})
|
||||
.width(Length::Fill)
|
||||
]
|
||||
.padding([0, 24]);
|
||||
|
||||
let settings =
|
||||
row_button(vec!["Notification Settings...".into()]).on_press(Message::Settings);
|
||||
|
||||
let notifications = if self.notifications.len() == 0 {
|
||||
row![
|
||||
Space::with_width(Length::Fill),
|
||||
column![text_icon(&self.icon_name, 40), "No Notifications"]
|
||||
.align_items(Alignment::Center),
|
||||
Space::with_width(Length::Fill)
|
||||
]
|
||||
.spacing(12)
|
||||
} else {
|
||||
row![text("TODO: make app worky with notifications")]
|
||||
};
|
||||
|
||||
let main_content = column![horizontal_rule(1), notifications, horizontal_rule(1)]
|
||||
.padding([0, 24])
|
||||
.spacing(12);
|
||||
|
||||
let content = column![]
|
||||
.align_items(Alignment::Start)
|
||||
.spacing(12)
|
||||
.padding([12, 0])
|
||||
.push(do_not_disturb)
|
||||
.push(main_content)
|
||||
.push(settings);
|
||||
|
||||
self.applet_helper.popup_container(content).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// todo put into libcosmic doing so will fix the row_button's boarder radius
|
||||
fn row_button(
|
||||
mut content: Vec<Element<Message>>,
|
||||
) -> cosmic::iced_native::widget::Button<Message, Renderer> {
|
||||
content.insert(0, Space::with_width(Length::Units(24)).into());
|
||||
content.push(Space::with_width(Length::Units(24)).into());
|
||||
|
||||
button(
|
||||
Row::with_children(content)
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Units(35))
|
||||
.style(theme::Button::Text)
|
||||
}
|
||||
|
||||
fn text_icon(name: &str, size: u16) -> cosmic::widget::Icon {
|
||||
icon(name, size).style(Svg::Custom(|theme| svg::Appearance {
|
||||
color: Some(theme.palette().text),
|
||||
}))
|
||||
}
|
||||
3644
applets/cosmic-applet-power/Cargo.lock
generated
|
|
@ -1,43 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-applet-power"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[dependencies]
|
||||
icon-loader = { version = "0.3.6", features = ["gtk"] }
|
||||
libpulse-binding = "2.26.0"
|
||||
libpulse-glib-binding = "2.25.0"
|
||||
tokio = { version = "1.20.1", features=["full"] }
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
||||
iced_sctk = { git = "https://github.com/pop-os/iced-sctk" }
|
||||
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", version = "0.16" }
|
||||
nix = "0.24.1"
|
||||
|
||||
[workspace]
|
||||
resolved = "2"
|
||||
|
||||
[dependencies.iced]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
# path = "../iced"
|
||||
default-features = false
|
||||
features = ["image", "svg", "tokio", "wayland"]
|
||||
|
||||
[dependencies.iced_native]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
|
||||
[dependencies.iced_futures]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
|
||||
# Until the 3.6.3 release, need the implementation of clone on zbus::Error
|
||||
[dependencies.zbus]
|
||||
git = "https://gitlab.freedesktop.org/dbus/zbus"
|
||||
branch = "main"
|
||||
|
||||
# Until zbus 3.6.3 is released
|
||||
[dependencies.logind-zbus]
|
||||
git = "https://github.com/pop-os/logind-zbus"
|
||||
branch = "main"
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Applet Power
|
||||
Comment=Write a GTK + Rust application
|
||||
Type=Application
|
||||
Exec=cosmic-applet-power
|
||||
Terminal=false
|
||||
Categories=GNOME;GTK;
|
||||
Keywords=Gnome;GTK;
|
||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||
Icon=com.system76.CosmicAppletPower.svg
|
||||
StartupNotify=true
|
||||
NoDisplay=true
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10632" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10635" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10638" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10641" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10578">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/com/System76/CosmicDockAppList/">
|
||||
<!-- see https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Application.html#automatic-resources -->
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "com.system76.CosmicSession",
|
||||
default_service = "com.system76.CosmicSession",
|
||||
default_path = "/com/system76/CosmicSession"
|
||||
)]
|
||||
trait CosmicSession {
|
||||
fn exit(&self) -> zbus::Result<()>;
|
||||
}
|
||||
|
|
@ -1,295 +0,0 @@
|
|||
use std::process;
|
||||
|
||||
use iced::widget::Space;
|
||||
|
||||
use cosmic::applet::CosmicAppletHelper;
|
||||
use cosmic::widget::{horizontal_rule, icon};
|
||||
use cosmic::Renderer;
|
||||
|
||||
use cosmic::iced::{
|
||||
executor,
|
||||
widget::{button, column, row},
|
||||
window, Alignment, Application, Command, Length, Subscription,
|
||||
};
|
||||
use cosmic::iced_style::application::{self, Appearance};
|
||||
use cosmic::iced_style::svg;
|
||||
use cosmic::theme::{self, Svg};
|
||||
use cosmic::{Element, Theme};
|
||||
|
||||
use iced_sctk::application::SurfaceIdWrapper;
|
||||
use iced_sctk::commands::popup::{destroy_popup, get_popup};
|
||||
use iced_sctk::widget::Row;
|
||||
use iced_sctk::Color;
|
||||
|
||||
use logind_zbus::manager::ManagerProxy;
|
||||
use logind_zbus::session::{SessionProxy, SessionType};
|
||||
use logind_zbus::user::UserProxy;
|
||||
use nix::unistd::getuid;
|
||||
use zbus::Connection;
|
||||
|
||||
pub mod cosmic_session;
|
||||
pub mod session_manager;
|
||||
|
||||
use crate::cosmic_session::CosmicSessionProxy;
|
||||
use crate::session_manager::SessionManagerProxy;
|
||||
|
||||
pub fn main() -> cosmic::iced::Result {
|
||||
let helper = CosmicAppletHelper::default();
|
||||
Power::run(helper.window_settings())
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Power {
|
||||
applet_helper: CosmicAppletHelper,
|
||||
icon_name: String,
|
||||
theme: Theme,
|
||||
popup: Option<window::Id>,
|
||||
id_ctr: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
Lock,
|
||||
LogOut,
|
||||
Suspend,
|
||||
Restart,
|
||||
Shutdown,
|
||||
TogglePopup,
|
||||
Settings,
|
||||
Ignore,
|
||||
Zbus(Result<(), zbus::Error>),
|
||||
}
|
||||
|
||||
impl Application for Power {
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Executor = executor::Default;
|
||||
type Flags = ();
|
||||
|
||||
fn new(_flags: ()) -> (Power, Command<Message>) {
|
||||
(
|
||||
Power {
|
||||
icon_name: "system-shutdown-symbolic".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Power")
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
}
|
||||
|
||||
fn close_requested(&self, _id: iced_sctk::application::SurfaceIdWrapper) -> Self::Message {
|
||||
Message::Ignore
|
||||
}
|
||||
|
||||
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
|
||||
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||
text_color: theme.cosmic().on_bg_color().into(),
|
||||
})
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
Subscription::none()
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::TogglePopup => {
|
||||
if let Some(p) = self.popup.take() {
|
||||
destroy_popup(p)
|
||||
} else {
|
||||
self.id_ctr += 1;
|
||||
let new_id = window::Id::new(self.id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
|
||||
let popup_settings = self.applet_helper.get_popup_settings(
|
||||
window::Id::new(0),
|
||||
new_id,
|
||||
(400, 300),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
get_popup(popup_settings)
|
||||
}
|
||||
}
|
||||
Message::Settings => {
|
||||
let _ = process::Command::new("cosmic-settings").spawn();
|
||||
Command::none()
|
||||
}
|
||||
Message::Lock => Command::perform(lock(), Message::Zbus),
|
||||
Message::LogOut => Command::perform(log_out(), Message::Zbus),
|
||||
Message::Suspend => Command::perform(suspend(), Message::Zbus),
|
||||
Message::Restart => Command::perform(restart(), Message::Zbus),
|
||||
Message::Shutdown => Command::perform(shutdown(), Message::Zbus),
|
||||
Message::Zbus(result) => {
|
||||
if let Err(e) = result {
|
||||
eprintln!("cosmic-applet-power ERROR: '{}'", e);
|
||||
}
|
||||
Command::none()
|
||||
}
|
||||
Message::Ignore => Command::none(),
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Window(_) => self
|
||||
.applet_helper
|
||||
.icon_button(&self.icon_name)
|
||||
.on_press(Message::TogglePopup)
|
||||
.into(),
|
||||
SurfaceIdWrapper::Popup(_) => {
|
||||
let settings = row_button(vec!["Settings...".into()])
|
||||
.on_press(Message::Settings);
|
||||
|
||||
let session = column![
|
||||
row_button(vec![
|
||||
text_icon("system-lock-screen-symbolic", 24).into(),
|
||||
"Lock Screen".into(),
|
||||
Space::with_width(Length::Fill).into(),
|
||||
"Super + Escape".into(),
|
||||
])
|
||||
.on_press(Message::Lock),
|
||||
row_button(vec![
|
||||
text_icon("system-log-out-symbolic", 24).into(),
|
||||
"Log Out".into(),
|
||||
Space::with_width(Length::Fill).into(),
|
||||
"Ctrl + Alt + Delete".into(),
|
||||
])
|
||||
.on_press(Message::LogOut),
|
||||
];
|
||||
|
||||
let power = row![
|
||||
power_buttons("system-lock-screen-symbolic", "Suspend")
|
||||
.on_press(Message::Suspend),
|
||||
power_buttons("system-restart-symbolic", "Restart").on_press(Message::Restart),
|
||||
power_buttons("system-shutdown-symbolic", "Shutdown")
|
||||
.on_press(Message::Shutdown),
|
||||
]
|
||||
.spacing(24)
|
||||
.padding([0, 24]);
|
||||
|
||||
let content = column![]
|
||||
.align_items(Alignment::Start)
|
||||
.spacing(12)
|
||||
.padding([24, 0])
|
||||
.push(settings)
|
||||
.push(horizontal_rule(1))
|
||||
.push(session)
|
||||
.push(horizontal_rule(1))
|
||||
.push(power);
|
||||
|
||||
self.applet_helper.popup_container(content).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ### UI Helplers
|
||||
|
||||
// todo put into libcosmic doing so will fix the row_button's boarder radius
|
||||
fn row_button(mut content: Vec<Element<Message>>) -> iced_sctk::widget::Button<Message, Renderer> {
|
||||
content.insert(0, Space::with_width(Length::Units(24)).into());
|
||||
content.push(Space::with_width(Length::Units(24)).into());
|
||||
|
||||
button(
|
||||
Row::with_children(content)
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Units(35))
|
||||
.style(theme::Button::Text)
|
||||
}
|
||||
|
||||
fn power_buttons<'a>(
|
||||
name: &'a str,
|
||||
text: &'a str,
|
||||
) -> iced_sctk::widget::Button<'a, Message, Renderer> {
|
||||
button(
|
||||
column![text_icon(name, 40), text]
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Units(75))
|
||||
.style(theme::Button::Text)
|
||||
}
|
||||
|
||||
fn text_icon(name: &str, size: u16) -> cosmic::widget::Icon {
|
||||
icon(name, size).style(Svg::Custom(|theme| svg::Appearance {
|
||||
fill: Some(theme.palette().text),
|
||||
}))
|
||||
}
|
||||
|
||||
// ### System helpers
|
||||
|
||||
async fn restart() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||
manager_proxy.reboot(true).await
|
||||
}
|
||||
|
||||
async fn shutdown() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||
manager_proxy.power_off(true).await
|
||||
}
|
||||
|
||||
async fn suspend() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||
manager_proxy.suspend(true).await
|
||||
}
|
||||
|
||||
async fn lock() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||
// Get the session this current process is running in
|
||||
let our_uid = getuid().as_raw() as u32;
|
||||
let user_path = manager_proxy.get_user(our_uid).await?;
|
||||
let user = UserProxy::builder(&connection)
|
||||
.path(user_path)?
|
||||
.build()
|
||||
.await?;
|
||||
// Lock all non-TTY sessions of this user
|
||||
let sessions = user.sessions().await?;
|
||||
for (_, session_path) in sessions {
|
||||
let session = SessionProxy::builder(&connection)
|
||||
.path(session_path)?
|
||||
.build()
|
||||
.await?;
|
||||
if session.type_().await? != SessionType::TTY {
|
||||
session.lock().await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn log_out() -> zbus::Result<()> {
|
||||
let session_type = std::env::var("XDG_CURRENT_DESKTOP").ok();
|
||||
let connection = Connection::session().await?;
|
||||
match session_type.as_ref().map(|s| s.trim()) {
|
||||
Some("pop:COSMIC") => {
|
||||
let cosmic_session = CosmicSessionProxy::new(&connection).await?;
|
||||
cosmic_session.exit().await?;
|
||||
}
|
||||
Some("pop:GNOME") => {
|
||||
let manager_proxy = SessionManagerProxy::new(&connection).await?;
|
||||
manager_proxy.logout(0).await?;
|
||||
}
|
||||
Some(desktop) => {
|
||||
eprintln!("unknown XDG_CURRENT_DESKTOP: {desktop}")
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//! # DBus interface proxy for: `org.gnome.SessionManager`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/gnome/SessionManager' from service 'org.gnome.SessionManager' on session bus`.
|
||||
//!
|
||||
//! You may prefer to adapt it, instead of using it verbatim.
|
||||
//!
|
||||
//! More information can be found in the
|
||||
//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html)
|
||||
//! section of the zbus documentation.
|
||||
//!
|
||||
//! This DBus object implements
|
||||
//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html),
|
||||
//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used:
|
||||
//!
|
||||
//! * [`zbus::fdo::PropertiesProxy`]
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(interface = "org.gnome.SessionManager", assume_defaults = true)]
|
||||
trait SessionManager {
|
||||
/// CanRebootToFirmwareSetup method
|
||||
fn can_reboot_to_firmware_setup(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// CanShutdown method
|
||||
fn can_shutdown(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// GetClients method
|
||||
fn get_clients(&self) -> zbus::Result<Vec<zbus::zvariant::OwnedObjectPath>>;
|
||||
|
||||
/// GetInhibitors method
|
||||
fn get_inhibitors(&self) -> zbus::Result<Vec<zbus::zvariant::OwnedObjectPath>>;
|
||||
|
||||
/// GetLocale method
|
||||
fn get_locale(&self, category: i32) -> zbus::Result<String>;
|
||||
|
||||
/// Inhibit method
|
||||
fn inhibit(
|
||||
&self,
|
||||
app_id: &str,
|
||||
toplevel_xid: u32,
|
||||
reason: &str,
|
||||
flags: u32,
|
||||
) -> zbus::Result<u32>;
|
||||
|
||||
/// InitializationError method
|
||||
fn initialization_error(&self, message: &str, fatal: bool) -> zbus::Result<()>;
|
||||
|
||||
/// Initialized method
|
||||
fn initialized(&self) -> zbus::Result<()>;
|
||||
|
||||
/// IsAutostartConditionHandled method
|
||||
fn is_autostart_condition_handled(&self, condition: &str) -> zbus::Result<bool>;
|
||||
|
||||
/// IsInhibited method
|
||||
fn is_inhibited(&self, flags: u32) -> zbus::Result<bool>;
|
||||
|
||||
/// IsSessionRunning method
|
||||
fn is_session_running(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Logout method
|
||||
fn logout(&self, mode: u32) -> zbus::Result<()>;
|
||||
|
||||
/// Reboot method
|
||||
fn reboot(&self) -> zbus::Result<()>;
|
||||
|
||||
/// RegisterClient method
|
||||
fn register_client(
|
||||
&self,
|
||||
app_id: &str,
|
||||
client_startup_id: &str,
|
||||
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||
|
||||
/// RequestReboot method
|
||||
fn request_reboot(&self) -> zbus::Result<()>;
|
||||
|
||||
/// RequestShutdown method
|
||||
fn request_shutdown(&self) -> zbus::Result<()>;
|
||||
|
||||
/// SetRebootToFirmwareSetup method
|
||||
fn set_reboot_to_firmware_setup(&self, enable: bool) -> zbus::Result<()>;
|
||||
|
||||
/// Setenv method
|
||||
fn setenv(&self, variable: &str, value: &str) -> zbus::Result<()>;
|
||||
|
||||
/// Shutdown method
|
||||
fn shutdown(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Uninhibit method
|
||||
fn uninhibit(&self, inhibit_cookie: u32) -> zbus::Result<()>;
|
||||
|
||||
/// UnregisterClient method
|
||||
fn unregister_client(&self, client_id: &zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// ClientAdded signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn client_added(&self, id: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// ClientRemoved signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn client_removed(&self, id: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// InhibitorAdded signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn inhibitor_added(&self, id: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// InhibitorRemoved signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn inhibitor_removed(&self, id: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// SessionOver signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn session_over(&self) -> zbus::Result<()>;
|
||||
|
||||
/// SessionRunning signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn session_running(&self) -> zbus::Result<()>;
|
||||
|
||||
/// InhibitedActions property
|
||||
#[dbus_proxy(property)]
|
||||
fn inhibited_actions(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// Renderer property
|
||||
#[dbus_proxy(property)]
|
||||
fn renderer(&self) -> zbus::Result<String>;
|
||||
|
||||
/// SessionIsActive property
|
||||
#[dbus_proxy(property)]
|
||||
fn session_is_active(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// SessionName property
|
||||
#[dbus_proxy(property)]
|
||||
fn session_name(&self) -> zbus::Result<String>;
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-applet-status-area"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[dependencies]
|
||||
cascade = "1"
|
||||
futures = "0.3"
|
||||
gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs" }
|
||||
adw = { git = "https://gitlab.gnome.org/World/Rust/libadwaita-rs", package = "libadwaita"}
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = false }
|
||||
libcosmic-applet = { path = "../../libcosmic-applet" }
|
||||
once_cell = "1.12"
|
||||
serde = "1"
|
||||
zbus = "3"
|
||||
zvariant = "3"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Applet Status Area
|
||||
Type=Application
|
||||
Exec=cosmic-applet-status-area
|
||||
Terminal=false
|
||||
Categories=GNOME;GTK;
|
||||
Keywords=Gnome;GTK;
|
||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||
Icon=com.system76.CosmicAppletStatusArea
|
||||
NoDisplay=true
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10632" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10635" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10638" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10641" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10578">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
|
@ -1,31 +0,0 @@
|
|||
use once_cell::unsync::OnceCell;
|
||||
|
||||
/// Wrapper around `OnceCell` implementing `Deref`, and thus also panicking
|
||||
/// when not set (or set twice).
|
||||
///
|
||||
/// To be used in place of `gtk::TemplateChild`, but without xml.
|
||||
pub struct DerefCell<T>(OnceCell<T>);
|
||||
|
||||
impl<T> DerefCell<T> {
|
||||
#[track_caller]
|
||||
pub fn set(&self, value: T) {
|
||||
if self.0.set(value).is_err() {
|
||||
panic!("Initialized twice");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for DerefCell<T> {
|
||||
fn default() -> Self {
|
||||
Self(OnceCell::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> std::ops::Deref for DerefCell<T> {
|
||||
type Target = T;
|
||||
|
||||
#[track_caller]
|
||||
fn deref(&self) -> &T {
|
||||
self.0.get().unwrap()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
use cascade::cascade;
|
||||
use gtk4::{glib, prelude::*};
|
||||
|
||||
mod deref_cell;
|
||||
mod status_area;
|
||||
mod status_menu;
|
||||
mod status_notifier_watcher;
|
||||
|
||||
use status_area::StatusArea;
|
||||
|
||||
fn main() {
|
||||
let _monitors = libcosmic::init();
|
||||
|
||||
// XXX Implement DBus service somewhere other than applet?
|
||||
glib::MainContext::default().spawn_local(status_notifier_watcher::start());
|
||||
|
||||
let status_area = StatusArea::new();
|
||||
cascade! {
|
||||
libcosmic_applet::AppletWindow::new();
|
||||
..set_child(Some(&status_area));
|
||||
..show();
|
||||
};
|
||||
|
||||
let main_loop = glib::MainLoop::new(None, false);
|
||||
main_loop.run();
|
||||
}
|
||||
|
|
@ -1,145 +0,0 @@
|
|||
use cascade::cascade;
|
||||
use futures::stream::StreamExt;
|
||||
use gtk4::{
|
||||
glib::{self, clone},
|
||||
prelude::*,
|
||||
subclass::prelude::*,
|
||||
};
|
||||
use once_cell::unsync::OnceCell;
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
use crate::deref_cell::DerefCell;
|
||||
use crate::status_menu::StatusMenu;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct StatusAreaInner {
|
||||
box_: DerefCell<gtk4::Box>,
|
||||
watcher: OnceCell<StatusNotifierWatcherProxy<'static>>,
|
||||
icons: RefCell<HashMap<String, StatusMenu>>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for StatusAreaInner {
|
||||
const NAME: &'static str = "S76StatusArea";
|
||||
type ParentType = gtk4::Widget;
|
||||
type Type = StatusArea;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.set_layout_manager_type::<gtk4::BinLayout>();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for StatusAreaInner {
|
||||
fn constructed(&self, obj: &StatusArea) {
|
||||
let box_ = cascade! {
|
||||
gtk4::Box::new(gtk4::Orientation::Horizontal, 0);
|
||||
..set_parent(obj);
|
||||
};
|
||||
|
||||
self.box_.set(box_);
|
||||
|
||||
glib::MainContext::default().spawn_local(clone!(@strong obj => async move {
|
||||
async {
|
||||
let connection = zbus::Connection::session().await?;
|
||||
let watcher = StatusNotifierWatcherProxy::new(&connection).await?;
|
||||
|
||||
let name = connection.unique_name().unwrap().as_str();
|
||||
if let Err(err) = watcher.register_status_notifier_host(name).await {
|
||||
eprintln!("Failed to register status notifier host: {}", err);
|
||||
}
|
||||
|
||||
let mut registered_stream = watcher.receive_status_notifier_item_registered().await?;
|
||||
let mut unregistered_stream = watcher.receive_status_notifier_item_unregistered().await?;
|
||||
|
||||
for name in watcher.registered_status_notifier_items().await? {
|
||||
glib::MainContext::default().spawn_local(clone!(@strong obj => async move {
|
||||
obj.item_registered(&name).await;
|
||||
}));
|
||||
}
|
||||
|
||||
glib::MainContext::default().spawn_local(clone!(@strong obj => async move {
|
||||
if let Some(evt) = registered_stream.next().await {
|
||||
if let Ok(args) = evt.args() {
|
||||
obj.item_registered(&args.name).await;
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
glib::MainContext::default().spawn_local(clone!(@strong obj => async move {
|
||||
if let Some(evt) = unregistered_stream.next().await {
|
||||
if let Ok(args) = evt.args() {
|
||||
obj.item_unregistered(&args.name);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
let _ = obj.inner().watcher.set(watcher);
|
||||
|
||||
Ok::<_, zbus::Error>(())
|
||||
}.await.unwrap_or_else(|err| {
|
||||
eprintln!("Failed to connect to 'org.kde.StatusNotifierWatcher': {}", err);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
fn dispose(&self, _obj: &StatusArea) {
|
||||
self.box_.unparent();
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for StatusAreaInner {}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct StatusArea(ObjectSubclass<StatusAreaInner>)
|
||||
@extends gtk4::Widget;
|
||||
}
|
||||
|
||||
impl StatusArea {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(&[]).unwrap()
|
||||
}
|
||||
|
||||
fn inner(&self) -> &StatusAreaInner {
|
||||
StatusAreaInner::from_instance(self)
|
||||
}
|
||||
|
||||
async fn item_registered(&self, name: &str) {
|
||||
match StatusMenu::new(&name).await {
|
||||
Ok(item) => {
|
||||
self.inner().box_.append(&item);
|
||||
|
||||
self.item_unregistered(name);
|
||||
self.inner()
|
||||
.icons
|
||||
.borrow_mut()
|
||||
.insert(name.to_owned(), item);
|
||||
}
|
||||
Err(err) => eprintln!("Failed to connect to '{}': {}", name, err),
|
||||
}
|
||||
}
|
||||
|
||||
fn item_unregistered(&self, name: &str) {
|
||||
if let Some(icon) = self.inner().icons.borrow_mut().remove(name) {
|
||||
self.inner().box_.remove(&icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.kde.StatusNotifierWatcher",
|
||||
default_service = "org.kde.StatusNotifierWatcher",
|
||||
default_path = "/StatusNotifierWatcher"
|
||||
)]
|
||||
trait StatusNotifierWatcher {
|
||||
fn register_status_notifier_host(&self, name: &str) -> zbus::Result<()>;
|
||||
|
||||
#[dbus_proxy(property)]
|
||||
fn registered_status_notifier_items(&self) -> zbus::Result<Vec<String>>;
|
||||
|
||||
#[dbus_proxy(signal)]
|
||||
fn status_notifier_item_registered(&self, name: &str) -> zbus::Result<()>;
|
||||
|
||||
#[dbus_proxy(signal)]
|
||||
fn status_notifier_item_unregistered(&self, name: &str) -> zbus::Result<()>;
|
||||
}
|
||||
|
|
@ -1,345 +0,0 @@
|
|||
use cascade::cascade;
|
||||
use futures::StreamExt;
|
||||
use gtk4::{
|
||||
gdk_pixbuf,
|
||||
glib::{self, clone},
|
||||
prelude::*,
|
||||
subclass::prelude::*,
|
||||
};
|
||||
use std::{cell::RefCell, collections::HashMap, io};
|
||||
use zbus::dbus_proxy;
|
||||
use zvariant::OwnedValue;
|
||||
|
||||
use crate::deref_cell::DerefCell;
|
||||
|
||||
struct Menu {
|
||||
box_: gtk4::Box,
|
||||
children: Vec<i32>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct StatusMenuInner {
|
||||
menu_button: DerefCell<libcosmic_applet::AppletButton>,
|
||||
vbox: DerefCell<gtk4::Box>,
|
||||
item: DerefCell<StatusNotifierItemProxy<'static>>,
|
||||
dbus_menu: DerefCell<DBusMenuProxy<'static>>,
|
||||
menus: RefCell<HashMap<i32, Menu>>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for StatusMenuInner {
|
||||
const NAME: &'static str = "S76StatusMenu";
|
||||
type ParentType = gtk4::Widget;
|
||||
type Type = StatusMenu;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.set_layout_manager_type::<gtk4::BinLayout>();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for StatusMenuInner {
|
||||
fn constructed(&self, obj: &StatusMenu) {
|
||||
let vbox = cascade! {
|
||||
gtk4::Box::new(gtk4::Orientation::Vertical, 0);
|
||||
};
|
||||
|
||||
let menu_button = cascade! {
|
||||
libcosmic_applet::AppletButton::new();
|
||||
..set_parent(obj);
|
||||
..set_popover_child(Some(&vbox));
|
||||
};
|
||||
|
||||
self.menu_button.set(menu_button);
|
||||
self.vbox.set(vbox);
|
||||
}
|
||||
|
||||
fn dispose(&self, _obj: &StatusMenu) {
|
||||
self.menu_button.unparent();
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for StatusMenuInner {}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct StatusMenu(ObjectSubclass<StatusMenuInner>)
|
||||
@extends gtk4::Widget;
|
||||
}
|
||||
|
||||
impl StatusMenu {
|
||||
pub async fn new(name: &str) -> zbus::Result<Self> {
|
||||
let (dest, path) = if let Some(idx) = name.find('/') {
|
||||
(&name[..idx], &name[idx..])
|
||||
} else {
|
||||
(name, "/StatusNotifierItem")
|
||||
};
|
||||
|
||||
let connection = zbus::Connection::session().await?;
|
||||
let item = StatusNotifierItemProxy::builder(&connection)
|
||||
.destination(dest.to_string())?
|
||||
.path(path.to_string())?
|
||||
.build()
|
||||
.await?;
|
||||
let obj = glib::Object::new::<Self>(&[]).unwrap();
|
||||
let icon_name = item.icon_name().await?;
|
||||
obj.inner().menu_button.set_button_icon_name(&icon_name);
|
||||
|
||||
let menu = item.menu().await?;
|
||||
let menu = DBusMenuProxy::builder(&connection)
|
||||
.destination(dest.to_string())?
|
||||
.path(menu)?
|
||||
.build()
|
||||
.await?;
|
||||
let layout = menu.get_layout(0, -1, &[]).await?.1;
|
||||
|
||||
let mut layout_updated_stream = menu.receive_layout_updated().await?;
|
||||
glib::MainContext::default().spawn_local(clone!(@strong obj => async move {
|
||||
while let Some(evt) = layout_updated_stream.next().await {
|
||||
let args = match evt.args() {
|
||||
Ok(args) => args,
|
||||
Err(_) => { continue; },
|
||||
};
|
||||
obj.layout_updated(args.revision, args.parent);
|
||||
}
|
||||
}));
|
||||
|
||||
obj.inner().item.set(item);
|
||||
obj.inner().dbus_menu.set(menu);
|
||||
|
||||
println!("{:#?}", layout);
|
||||
obj.populate_menu(&obj.inner().vbox, &layout);
|
||||
|
||||
Ok(obj)
|
||||
}
|
||||
|
||||
fn inner(&self) -> &StatusMenuInner {
|
||||
StatusMenuInner::from_instance(self)
|
||||
}
|
||||
|
||||
fn layout_updated(&self, _revision: u32, parent: i32) {
|
||||
let mut menus = self.inner().menus.borrow_mut();
|
||||
|
||||
if let Some(Menu { box_, children }) = menus.remove(&parent) {
|
||||
let mut next_child = box_.first_child();
|
||||
while let Some(child) = next_child {
|
||||
next_child = child.next_sibling();
|
||||
box_.remove(&child);
|
||||
}
|
||||
|
||||
fn remove_child_menus(menus: &mut HashMap<i32, Menu>, children: Vec<i32>) {
|
||||
for i in children {
|
||||
if let Some(menu) = menus.remove(&i) {
|
||||
remove_child_menus(menus, menu.children);
|
||||
}
|
||||
}
|
||||
}
|
||||
remove_child_menus(&mut menus, children);
|
||||
|
||||
glib::MainContext::default().spawn_local(clone!(@weak self as self_ => async move {
|
||||
match self_.inner().dbus_menu.get_layout(parent, -1, &[]).await {
|
||||
Ok((_, layout)) => self_.populate_menu(&box_, &layout),
|
||||
Err(err) => eprintln!("Failed to call 'GetLayout': {}", err),
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
fn populate_menu(&self, box_: >k4::Box, layout: &Layout) {
|
||||
let mut children = Vec::new();
|
||||
|
||||
for i in layout.children() {
|
||||
children.push(i.id());
|
||||
|
||||
if i.type_().as_deref() == Some("separator") {
|
||||
let separator = cascade! {
|
||||
gtk4::Separator::new(gtk4::Orientation::Horizontal);
|
||||
..set_visible(i.visible());
|
||||
};
|
||||
box_.append(&separator);
|
||||
} else if let Some(label) = i.label() {
|
||||
let mut label = label.to_string();
|
||||
if let Some(toggle_state) = i.toggle_state() {
|
||||
if toggle_state != 0 {
|
||||
label = format!("✓ {}", label);
|
||||
}
|
||||
}
|
||||
|
||||
let label_widget = cascade! {
|
||||
gtk4::Label::new(Some(&label));
|
||||
..set_halign(gtk4::Align::Start);
|
||||
..set_hexpand(true);
|
||||
..set_use_underline(true);
|
||||
};
|
||||
|
||||
let hbox = cascade! {
|
||||
gtk4::Box::new(gtk4::Orientation::Horizontal, 0);
|
||||
..append(&label_widget);
|
||||
};
|
||||
|
||||
if let Some(icon_data) = i.icon_data() {
|
||||
let icon_data = io::Cursor::new(icon_data.to_vec());
|
||||
let pixbuf = gdk_pixbuf::Pixbuf::from_read(icon_data).unwrap(); // XXX unwrap
|
||||
let image = cascade! {
|
||||
gtk4::Image::from_pixbuf(Some(&pixbuf));
|
||||
..set_halign(gtk4::Align::End);
|
||||
};
|
||||
hbox.append(&image);
|
||||
}
|
||||
|
||||
let id = i.id();
|
||||
let close_on_click = i.children_display().as_deref() != Some("submenu");
|
||||
let button = cascade! {
|
||||
gtk4::Button::new();
|
||||
..set_child(Some(&hbox));
|
||||
..style_context().add_class("flat");
|
||||
..set_visible(i.visible());
|
||||
..set_sensitive(i.enabled());
|
||||
..connect_clicked(clone!(@weak self as self_ => move |_| {
|
||||
// XXX data, timestamp
|
||||
if close_on_click {
|
||||
self_.inner().menu_button.popdown();
|
||||
}
|
||||
glib::MainContext::default().spawn_local(clone!(@strong self_ => async move {
|
||||
let _ = self_.inner().dbus_menu.event(id, "clicked", &0.into(), 0).await;
|
||||
}));
|
||||
}));
|
||||
};
|
||||
box_.append(&button);
|
||||
|
||||
if i.children_display().as_deref() == Some("submenu") {
|
||||
let vbox = cascade! {
|
||||
gtk4::Box::new(gtk4::Orientation::Vertical, 0);
|
||||
};
|
||||
|
||||
let revealer = cascade! {
|
||||
gtk4::Revealer::new();
|
||||
..set_child(Some(&vbox));
|
||||
};
|
||||
|
||||
self.populate_menu(&vbox, &i);
|
||||
|
||||
box_.append(&revealer);
|
||||
|
||||
button.connect_clicked(move |_| {
|
||||
revealer.set_reveal_child(!revealer.reveals_child());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.inner().menus.borrow_mut().insert(
|
||||
layout.id(),
|
||||
Menu {
|
||||
box_: box_.clone(),
|
||||
children,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[dbus_proxy(interface = "org.kde.StatusNotifierItem")]
|
||||
trait StatusNotifierItem {
|
||||
#[dbus_proxy(property)]
|
||||
fn icon_name(&self) -> zbus::Result<String>;
|
||||
|
||||
#[dbus_proxy(property)]
|
||||
fn menu(&self) -> zbus::Result<zvariant::OwnedObjectPath>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Layout(i32, LayoutProps, Vec<Layout>);
|
||||
|
||||
impl<'a> serde::Deserialize<'a> for Layout {
|
||||
fn deserialize<D: serde::Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
let (id, props, children) =
|
||||
<(i32, LayoutProps, Vec<(zvariant::Signature<'_>, Self)>)>::deserialize(deserializer)?;
|
||||
Ok(Self(id, props, children.into_iter().map(|x| x.1).collect()))
|
||||
}
|
||||
}
|
||||
|
||||
impl zvariant::Type for Layout {
|
||||
fn signature() -> zvariant::Signature<'static> {
|
||||
zvariant::Signature::try_from("(ia{sv}av)").unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, zvariant::DeserializeDict, zvariant::Type)]
|
||||
pub struct LayoutProps {
|
||||
#[zvariant(rename = "accessible-desc")]
|
||||
accessible_desc: Option<String>,
|
||||
#[zvariant(rename = "children-display")]
|
||||
children_display: Option<String>,
|
||||
label: Option<String>,
|
||||
enabled: Option<bool>,
|
||||
visible: Option<bool>,
|
||||
#[zvariant(rename = "type")]
|
||||
type_: Option<String>,
|
||||
#[zvariant(rename = "toggle-type")]
|
||||
toggle_type: Option<String>,
|
||||
#[zvariant(rename = "toggle-state")]
|
||||
toggle_state: Option<i32>,
|
||||
#[zvariant(rename = "icon-data")]
|
||||
icon_data: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Layout {
|
||||
fn id(&self) -> i32 {
|
||||
self.0
|
||||
}
|
||||
|
||||
fn children(&self) -> &[Self] {
|
||||
&self.2
|
||||
}
|
||||
|
||||
fn accessible_desc(&self) -> Option<&str> {
|
||||
self.1.accessible_desc.as_deref()
|
||||
}
|
||||
|
||||
fn children_display(&self) -> Option<&str> {
|
||||
self.1.children_display.as_deref()
|
||||
}
|
||||
|
||||
fn label(&self) -> Option<&str> {
|
||||
self.1.label.as_deref()
|
||||
}
|
||||
|
||||
fn enabled(&self) -> bool {
|
||||
self.1.enabled.unwrap_or(true)
|
||||
}
|
||||
|
||||
fn visible(&self) -> bool {
|
||||
self.1.visible.unwrap_or(true)
|
||||
}
|
||||
|
||||
fn type_(&self) -> Option<&str> {
|
||||
self.1.type_.as_deref()
|
||||
}
|
||||
|
||||
fn toggle_type(&self) -> Option<&str> {
|
||||
self.1.toggle_type.as_deref()
|
||||
}
|
||||
|
||||
fn toggle_state(&self) -> Option<i32> {
|
||||
self.1.toggle_state
|
||||
}
|
||||
|
||||
fn icon_data(&self) -> Option<&[u8]> {
|
||||
self.1.icon_data.as_deref()
|
||||
}
|
||||
}
|
||||
|
||||
#[dbus_proxy(interface = "com.canonical.dbusmenu")]
|
||||
trait DBusMenu {
|
||||
fn get_layout(
|
||||
&self,
|
||||
parent_id: i32,
|
||||
recursion_depth: i32,
|
||||
property_names: &[&str],
|
||||
) -> zbus::Result<(u32, Layout)>;
|
||||
|
||||
fn event(&self, id: i32, event_id: &str, data: &OwnedValue, timestamp: u32)
|
||||
-> zbus::Result<()>;
|
||||
|
||||
#[dbus_proxy(signal)]
|
||||
fn layout_updated(&self, revision: u32, parent: i32) -> zbus::Result<()>;
|
||||
}
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use futures::prelude::*;
|
||||
use gtk4::glib::{self, clone};
|
||||
use std::cell::Cell;
|
||||
use zbus::{
|
||||
dbus_interface,
|
||||
fdo::{DBusProxy, RequestNameFlags, RequestNameReply},
|
||||
names::{BusName, UniqueName, WellKnownName},
|
||||
MessageHeader, Result, SignalContext,
|
||||
};
|
||||
|
||||
const OBJECT_PATH: &str = "/StatusNotifierWatcher";
|
||||
|
||||
#[derive(Default)]
|
||||
struct StatusNotifierWatcher {
|
||||
items: Vec<(UniqueName<'static>, String)>,
|
||||
}
|
||||
|
||||
#[dbus_interface(name = "org.kde.StatusNotifierWatcher")]
|
||||
impl StatusNotifierWatcher {
|
||||
async fn register_status_notifier_item(
|
||||
&mut self,
|
||||
service: &str,
|
||||
#[zbus(header)] hdr: MessageHeader<'_>,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
) {
|
||||
let sender = hdr.sender().unwrap().unwrap();
|
||||
let service = if service.starts_with('/') {
|
||||
format!("{}{}", sender, service)
|
||||
} else {
|
||||
service.to_string()
|
||||
};
|
||||
Self::status_notifier_item_registered(&ctxt, &service)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
self.items.push((sender.to_owned(), service));
|
||||
}
|
||||
|
||||
fn register_status_notifier_host(&self, _service: &str) {
|
||||
// XXX emit registed/unregistered
|
||||
}
|
||||
|
||||
#[dbus_interface(property)]
|
||||
fn registered_status_notifier_items(&self) -> Vec<String> {
|
||||
self.items.iter().map(|(_, x)| x.clone()).collect()
|
||||
}
|
||||
|
||||
#[dbus_interface(property)]
|
||||
fn is_status_notifier_host_registered(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[dbus_interface(property)]
|
||||
fn protocol_version(&self) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn status_notifier_item_registered(ctxt: &SignalContext<'_>, service: &str)
|
||||
-> Result<()>;
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn status_notifier_item_unregistered(
|
||||
ctxt: &SignalContext<'_>,
|
||||
service: &str,
|
||||
) -> Result<()>;
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn status_notifier_host_registered(ctxt: &SignalContext<'_>) -> Result<()>;
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn status_notifier_host_unregistered(ctxt: &SignalContext<'_>) -> Result<()>;
|
||||
}
|
||||
|
||||
async fn create_service() -> zbus::Result<zbus::Connection> {
|
||||
let well_known_name = WellKnownName::try_from("org.kde.StatusNotifierWatcher")?;
|
||||
|
||||
let connection = zbus::ConnectionBuilder::session()?.build().await?;
|
||||
connection
|
||||
.object_server()
|
||||
.at(OBJECT_PATH, StatusNotifierWatcher::default())
|
||||
.await?;
|
||||
let interface = connection
|
||||
.object_server()
|
||||
.interface::<_, StatusNotifierWatcher>(OBJECT_PATH)
|
||||
.await
|
||||
.unwrap();
|
||||
let dbus_proxy = DBusProxy::new(&connection).await?;
|
||||
let mut name_owner_changed_stream = dbus_proxy.receive_name_owner_changed().await?;
|
||||
|
||||
let flags = RequestNameFlags::AllowReplacement.into();
|
||||
match dbus_proxy
|
||||
.request_name(well_known_name.as_ref(), flags)
|
||||
.await?
|
||||
{
|
||||
RequestNameReply::InQueue => {
|
||||
eprintln!("Bus name '{}' already owned", well_known_name);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
glib::MainContext::default().spawn_local(clone!(@strong connection => async move {
|
||||
let have_bus_name = Cell::new(false);
|
||||
let unique_name = connection.unique_name().map(|x| x.as_ref());
|
||||
while let Some(evt) = name_owner_changed_stream.next().await {
|
||||
let args = match evt.args() {
|
||||
Ok(args) => args,
|
||||
Err(_) => { continue; },
|
||||
};
|
||||
if args.name.as_ref() == well_known_name {
|
||||
if args.new_owner.as_ref() == unique_name.as_ref() {
|
||||
eprintln!("Acquired bus name: {}", well_known_name);
|
||||
have_bus_name.set(true);
|
||||
} else if have_bus_name.get() {
|
||||
eprintln!("Lost bus name: {}", well_known_name);
|
||||
have_bus_name.set(false);
|
||||
}
|
||||
} else if let BusName::Unique(name) = &args.name {
|
||||
let mut interface = interface.get_mut().await;
|
||||
if let Some(idx) = interface.items.iter().position(|(unique_name, _)| unique_name == name) {
|
||||
let ctxt = zbus::SignalContext::new(&connection, OBJECT_PATH).unwrap();
|
||||
let service = interface.items.remove(idx).1;
|
||||
StatusNotifierWatcher::status_notifier_item_unregistered(&ctxt, &service)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
Ok(connection)
|
||||
}
|
||||
|
||||
pub async fn start() {
|
||||
if let Err(err) = create_service().await {
|
||||
eprintln!("Failed to start `StatusNotifierWatcher` service: {}", err);
|
||||
}
|
||||
}
|
||||
3414
applets/cosmic-applet-time/Cargo.lock
generated
|
|
@ -1,12 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-applet-time"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[dependencies]
|
||||
icon-loader = { version = "0.3.6", features = ["gtk"] }
|
||||
tokio = { version = "1.20.1", features=["full"] }
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
||||
nix = "0.24.1"
|
||||
chrono = { version = "0.4.23", features = ["clock"] }
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Applet Time
|
||||
Type=Application
|
||||
Exec=cosmic-applet-time
|
||||
Terminal=false
|
||||
Categories=GNOME;GTK;
|
||||
Keywords=Gnome;GTK;
|
||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||
Icon=com.system76.CosmicAppletTime
|
||||
NoDisplay=true
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10632" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10635" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10638" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10641" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10578">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
|
@ -1,175 +0,0 @@
|
|||
use cosmic::applet::CosmicAppletHelper;
|
||||
use cosmic::iced::wayland::{
|
||||
popup::{destroy_popup, get_popup},
|
||||
SurfaceIdWrapper,
|
||||
};
|
||||
use cosmic::iced::{
|
||||
executor, time,
|
||||
widget::{button, column, text},
|
||||
window, Alignment, Application, Color, Command, Length, Subscription,
|
||||
};
|
||||
use cosmic::iced_style::application::{self, Appearance};
|
||||
use cosmic::theme;
|
||||
use cosmic::{Element, Theme};
|
||||
|
||||
use chrono::{DateTime, Local, Timelike};
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn main() -> cosmic::iced::Result {
|
||||
let mut helper = CosmicAppletHelper::default();
|
||||
helper.window_size(120, 16);
|
||||
Time::run(helper.window_settings())
|
||||
}
|
||||
|
||||
struct Time {
|
||||
applet_helper: CosmicAppletHelper,
|
||||
theme: Theme,
|
||||
popup: Option<window::Id>,
|
||||
id_ctr: u32,
|
||||
update_at: Every,
|
||||
now: DateTime<Local>,
|
||||
}
|
||||
|
||||
impl Default for Time {
|
||||
fn default() -> Self {
|
||||
Time {
|
||||
applet_helper: CosmicAppletHelper::default(),
|
||||
theme: Theme::default(),
|
||||
popup: None,
|
||||
id_ctr: 0,
|
||||
update_at: Every::Minute,
|
||||
now: Local::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[allow(dead_code)]
|
||||
enum Every {
|
||||
Minute,
|
||||
Second,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
TogglePopup,
|
||||
Tick,
|
||||
Ignore,
|
||||
}
|
||||
|
||||
impl Application for Time {
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Executor = executor::Default;
|
||||
type Flags = ();
|
||||
|
||||
fn new(_flags: ()) -> (Time, Command<Message>) {
|
||||
(Time::default(), Command::none())
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Time")
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
}
|
||||
|
||||
fn close_requested(&self, _id: SurfaceIdWrapper) -> Self::Message {
|
||||
Message::Ignore
|
||||
}
|
||||
|
||||
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
|
||||
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||
text_color: theme.cosmic().on_bg_color().into(),
|
||||
})
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
const FALLBACK_DELAY: u64 = 500;
|
||||
let update_delay = match self.update_at {
|
||||
Every::Minute => chrono::Duration::minutes(1),
|
||||
Every::Second => chrono::Duration::seconds(1),
|
||||
};
|
||||
|
||||
// Calculate the time until next second/minute so we can sleep the thread until then.
|
||||
let now = Local::now().time();
|
||||
let next = (now + update_delay)
|
||||
.with_second(0)
|
||||
.expect("Setting seconds to 0 should always be possible")
|
||||
.with_nanosecond(0)
|
||||
.expect("Setting nanoseconds to 0 should always be possible.");
|
||||
let wait = (next - now).num_milliseconds();
|
||||
time::every(Duration::from_millis(
|
||||
wait.try_into().unwrap_or(FALLBACK_DELAY),
|
||||
))
|
||||
.map(|_| Message::Tick)
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::TogglePopup => {
|
||||
if let Some(p) = self.popup.take() {
|
||||
destroy_popup(p)
|
||||
} else {
|
||||
self.id_ctr += 1;
|
||||
let new_id = window::Id::new(self.id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
|
||||
let popup_settings = self.applet_helper.get_popup_settings(
|
||||
window::Id::new(0),
|
||||
new_id,
|
||||
(400, 300),
|
||||
Some(60),
|
||||
None,
|
||||
);
|
||||
get_popup(popup_settings)
|
||||
}
|
||||
}
|
||||
Message::Tick => {
|
||||
self.now = Local::now();
|
||||
Command::none()
|
||||
}
|
||||
Message::Ignore => Command::none(),
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Window(_) => button(
|
||||
column![text(self.now.format("%b %-d %-I:%M %p").to_string())]
|
||||
.width(Length::Fill)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.on_press(Message::TogglePopup)
|
||||
.style(theme::Button::Text)
|
||||
.width(Length::Units(120))
|
||||
.into(),
|
||||
SurfaceIdWrapper::Popup(_) => {
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
let calendar = std::str::from_utf8(
|
||||
&std::process::Command::new("happiness")
|
||||
.output()
|
||||
.unwrap_or(std::process::Output {
|
||||
stdout: "`sudo apt install happiness`".as_bytes().to_vec(),
|
||||
stderr: Vec::new(),
|
||||
status: std::process::ExitStatus::from_raw(0),
|
||||
})
|
||||
.stdout,
|
||||
)
|
||||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let content = column![]
|
||||
.align_items(Alignment::Start)
|
||||
.spacing(12)
|
||||
.padding([24, 0])
|
||||
.push(text(calendar));
|
||||
|
||||
self.applet_helper.popup_container(content).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3370
applets/cosmic-applet-workspaces/Cargo.lock
generated
|
|
@ -1,33 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-applet-workspaces"
|
||||
version = "0.1.0"
|
||||
authors = ["Ashley Wulber <ashley@system76.com>"]
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
||||
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", default-features = false }
|
||||
iced_sctk = { git = "https://github.com/pop-os/iced-sctk" }
|
||||
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", version = "0.16" }
|
||||
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = ["client"] }
|
||||
wayland-backend = {version = "0.1.0-beta.13", features = ["client_system"]}
|
||||
wayland-client = {version = "0.30.0-beta.13"}
|
||||
calloop = "0.10.1"
|
||||
nix = "0.26.1"
|
||||
log = "0.4"
|
||||
pretty_env_logger = "0.4"
|
||||
once_cell = "1.9"
|
||||
futures = "0.3.21"
|
||||
xdg = "2.4.0"
|
||||
anyhow = "1.0"
|
||||
# Application i18n
|
||||
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
|
||||
i18n-embed-fl = "0.6.4"
|
||||
rust-embed = "6.3.0"
|
||||
|
||||
[patch.crates-io]
|
||||
wayland-protocols = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"}
|
||||
wayland-sys = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"}
|
||||
wayland-backend = { git = "https://github.com/smithay/wayland-rs", version = "0.1.0-beta.13"}
|
||||
wayland-scanner = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"}
|
||||
wayland-client = { git = "https://github.com/smithay/wayland-rs", version = "0.30.0-beta.13"}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Applet Workspaces
|
||||
Comment=Write a GTK + Rust application
|
||||
Type=Application
|
||||
Exec=cosmic-applet-workspaces
|
||||
Terminal=false
|
||||
Categories=GNOME;GTK;
|
||||
Keywords=Gnome;GTK;
|
||||
Icon=com.system76.CosmicAppletWorkspaces.svg
|
||||
StartupNotify=true
|
||||
NoDisplay=true
|
||||
X-HostWaylandDisplay=true
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
|
||||
<defs>
|
||||
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
|
||||
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
|
||||
</filter>
|
||||
<mask id="mask0">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip1">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10632" clip-path="url(#clip1)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask1">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip2">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10635" clip-path="url(#clip2)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask2">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip3">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10638" clip-path="url(#clip3)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
<mask id="mask3">
|
||||
<g filter="url(#alpha)">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
|
||||
</g>
|
||||
</mask>
|
||||
<clipPath id="clip4">
|
||||
<rect x="0" y="0" width="192" height="152"/>
|
||||
</clipPath>
|
||||
<g id="surface10641" clip-path="url(#clip4)">
|
||||
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
|
||||
</g>
|
||||
</defs>
|
||||
<g id="surface10578">
|
||||
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
|
||||
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
|
||||
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
|
||||
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
|
||||
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
|
||||
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/com/System76/CosmicAppletWorkspaces/">
|
||||
<file compressed="true">style.css</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
button.alert {
|
||||
border-radius: 0;
|
||||
padding: 0px;
|
||||
background-color: @destructive_color;
|
||||
background-image: none;
|
||||
color: @destructive_fg_color;
|
||||
border-color: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
||||
button.active {
|
||||
border-radius: 0;
|
||||
padding: 0px;
|
||||
background-color: @accent_color;
|
||||
background-image: none;
|
||||
color: @accent_fg_color;
|
||||
border-color: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
||||
button.inactive {
|
||||
border-radius: 0;
|
||||
padding: 0px;
|
||||
background-color: @view_bg_color;
|
||||
background-image: none;
|
||||
color: @view_fg_color;
|
||||
border-color: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
||||
button.alert:hover {
|
||||
border-radius: 0;
|
||||
padding: 0px;
|
||||
background-color: darker(@destructive_color);
|
||||
background-image: none;
|
||||
color: @destructive_fg_color;
|
||||
border-color: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
||||
button.active:hover {
|
||||
border-radius: 0;
|
||||
padding: 0px;
|
||||
background-color: darker(@accent_color);
|
||||
background-image: none;
|
||||
color: @accent_fg_color;
|
||||
border-color: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
||||
button.inactive:hover {
|
||||
border-radius: 0;
|
||||
padding: 0px;
|
||||
background-color: darker(@view_bg_color);
|
||||
background-image: none;
|
||||
color: @view_fg_color;
|
||||
border-color: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
||||
window {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
listview {
|
||||
border-color: transparent;
|
||||
background: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
||||
listview row {
|
||||
padding-left: 0px;
|
||||
padding-right: 0px;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
background: transparent;
|
||||
border-color: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
||||
listview row:hover {
|
||||
padding-left: 0px;
|
||||
padding-right: 0px;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
background: transparent;
|
||||
border-color: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
||||
label {
|
||||
padding: 0px;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
box {
|
||||
padding: 0px;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
fallback_language = "en"
|
||||
|
||||
[fluent]
|
||||
assets_dir = "i18n"
|
||||
|
|
@ -1 +0,0 @@
|
|||
cosmic-applet-workspaces = Cosmic Workspaces
|
||||
|
|
@ -1 +0,0 @@
|
|||
cosmic-applet-workspaces = Espaces de travail Cosmic
|
||||