Merge pull request #78 from pop-os/cosmic-panel-button_jammy
Add back cosmic-panel-button
This commit is contained in:
commit
2c74a551c7
15 changed files with 148 additions and 147 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
|
@ -681,6 +681,14 @@ dependencies = [
|
||||||
"zvariant",
|
"zvariant",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cosmic-panel-button"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"freedesktop-desktop-entry",
|
||||||
|
"libcosmic",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-panel-config"
|
name = "cosmic-panel-config"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ members = [
|
||||||
"cosmic-applet-power",
|
"cosmic-applet-power",
|
||||||
"cosmic-applet-time",
|
"cosmic-applet-time",
|
||||||
"cosmic-applet-workspaces",
|
"cosmic-applet-workspaces",
|
||||||
|
"cosmic-panel-button",
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
||||||
|
|
@ -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,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,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,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,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;
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
Name=Cosmic Panel App Library Button
|
Name=Cosmic Panel App Library Button
|
||||||
Comment=Write a GTK + Rust application
|
Comment=Write a GTK + Rust application
|
||||||
Type=Application
|
Type=Application
|
||||||
Exec=cosmic-panel-button --id com.system76.CosmicAppLibrary
|
Exec=cosmic-panel-button com.system76.CosmicAppLibrary
|
||||||
Terminal=false
|
Terminal=false
|
||||||
Categories=GNOME;GTK;
|
Categories=GNOME;GTK;
|
||||||
Keywords=Gnome;GTK;
|
Keywords=Gnome;GTK;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<gresources>
|
|
||||||
<gresource prefix="/com/system76/CosmicPanelAppButton/">
|
|
||||||
<!-- see https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Application.html#automatic-resources -->
|
|
||||||
</gresource>
|
|
||||||
</gresources>
|
|
||||||
9
cosmic-panel-button/Cargo.toml
Normal file
9
cosmic-panel-button/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "cosmic-panel-button"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
license = "GPL-3.0-or-later"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
freedesktop-desktop-entry = "0.5.0"
|
||||||
|
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["tokio", "wayland", "applet"] }
|
||||||
122
cosmic-panel-button/src/main.rs
Normal file
122
cosmic-panel-button/src/main.rs
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
use cosmic::{
|
||||||
|
applet::CosmicAppletHelper,
|
||||||
|
iced::{
|
||||||
|
self,
|
||||||
|
wayland::{InitialSurface, SurfaceIdWrapper},
|
||||||
|
Application,
|
||||||
|
},
|
||||||
|
iced_sctk::layout::Limits,
|
||||||
|
iced_style::application,
|
||||||
|
};
|
||||||
|
use freedesktop_desktop_entry::DesktopEntry;
|
||||||
|
use std::{env, fs, process::Command};
|
||||||
|
|
||||||
|
#[derive(Clone, Default)]
|
||||||
|
struct Desktop {
|
||||||
|
name: String,
|
||||||
|
icon: Option<String>,
|
||||||
|
exec: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Button {
|
||||||
|
desktop: Desktop,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
enum Msg {
|
||||||
|
Press,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl iced::Application for Button {
|
||||||
|
type Message = Msg;
|
||||||
|
type Theme = cosmic::Theme;
|
||||||
|
type Executor = cosmic::SingleThreadExecutor;
|
||||||
|
type Flags = Desktop;
|
||||||
|
|
||||||
|
fn new(desktop: Desktop) -> (Self, iced::Command<Msg>) {
|
||||||
|
(Button { desktop }, iced::Command::none())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title(&self) -> String {
|
||||||
|
String::from("Button")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn close_requested(&self, _id: SurfaceIdWrapper) -> Msg {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||||
|
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| application::Appearance {
|
||||||
|
background_color: iced::Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||||
|
text_color: theme.cosmic().on_bg_color().into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn subscription(&self) -> iced::Subscription<Msg> {
|
||||||
|
iced::Subscription::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, message: Msg) -> iced::Command<Msg> {
|
||||||
|
match message {
|
||||||
|
Msg::Press => {
|
||||||
|
let _ = Command::new("sh").arg("-c").arg(&self.desktop.exec).spawn();
|
||||||
|
iced::Command::none()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self, _id: SurfaceIdWrapper) -> cosmic::Element<Msg> {
|
||||||
|
// TODO icon?
|
||||||
|
cosmic::widget::button(cosmic::theme::Button::Text)
|
||||||
|
.text(&self.desktop.name)
|
||||||
|
.on_press(Msg::Press)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() -> iced::Result {
|
||||||
|
let id = env::args()
|
||||||
|
.skip(1)
|
||||||
|
.next()
|
||||||
|
.expect("Requires desktop file id as argument.");
|
||||||
|
|
||||||
|
let filename = format!("{id}.desktop");
|
||||||
|
let mut desktop = None;
|
||||||
|
for mut path in freedesktop_desktop_entry::default_paths() {
|
||||||
|
path.push(&filename);
|
||||||
|
if let Ok(bytes) = fs::read_to_string(&path) {
|
||||||
|
if let Ok(entry) = DesktopEntry::decode(&path, &bytes) {
|
||||||
|
desktop = Some(Desktop {
|
||||||
|
name: entry
|
||||||
|
.name(None)
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.expect(&format!("Desktop file '{filename}' doesn't have `Name`")),
|
||||||
|
icon: entry.icon().map(|x| x.to_string()),
|
||||||
|
exec: entry
|
||||||
|
.exec()
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.expect(&format!("Desktop file '{filename}' doesn't have `Exec`")),
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let desktop = desktop.expect(&format!(
|
||||||
|
"Failed to find valid desktop file '{filename}' in search paths"
|
||||||
|
));
|
||||||
|
let helper = CosmicAppletHelper::default();
|
||||||
|
let mut settings = iced::Settings {
|
||||||
|
flags: desktop,
|
||||||
|
..helper.window_settings()
|
||||||
|
};
|
||||||
|
match &mut settings.initial_surface {
|
||||||
|
InitialSurface::XdgWindow(s) => {
|
||||||
|
s.iced_settings.min_size = Some((1, 1));
|
||||||
|
s.iced_settings.max_size = None;
|
||||||
|
s.autosize = true;
|
||||||
|
s.size_limits = Limits::NONE.min_height(1).min_width(1);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
Button::run(settings)
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
Name=Cosmic Panel Workspaces Button
|
Name=Cosmic Panel Workspaces Button
|
||||||
Comment=Write a GTK + Rust application
|
Comment=Write a GTK + Rust application
|
||||||
Type=Application
|
Type=Application
|
||||||
Exec=cosmic-panel-button -id com.system76.CosmicWorkspaces
|
Exec=cosmic-panel-button com.system76.CosmicWorkspaces
|
||||||
Terminal=false
|
Terminal=false
|
||||||
Categories=GNOME;GTK;
|
Categories=GNOME;GTK;
|
||||||
Keywords=Gnome;GTK;
|
Keywords=Gnome;GTK;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<gresources>
|
|
||||||
<gresource prefix="/com/system76/CosmicPanelAppButton/">
|
|
||||||
<!-- see https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Application.html#automatic-resources -->
|
|
||||||
</gresource>
|
|
||||||
</gresources>
|
|
||||||
10
justfile
10
justfile
|
|
@ -39,12 +39,14 @@ _install_power: (_install 'com.system76.CosmicAppletPower' 'cosmic-applet-power'
|
||||||
_install_workspace: (_install 'com.system76.CosmicAppletWorkspaces' 'cosmic-applet-workspaces')
|
_install_workspace: (_install 'com.system76.CosmicAppletWorkspaces' 'cosmic-applet-workspaces')
|
||||||
_install_time: (_install 'com.system76.CosmicAppletTime' 'cosmic-applet-time')
|
_install_time: (_install 'com.system76.CosmicAppletTime' 'cosmic-applet-time')
|
||||||
|
|
||||||
# TODO: `cosmic-panel-button` no longer exists and hasn't been ported to Iced
|
# TODO: Turn this into one configurable applet?
|
||||||
# _install_app_button: (_install 'com.system76.CosmicPanelAppButton' 'cosmic-panel-app-button')
|
_install_panel_button: (_install_bin 'cosmic-panel-button')
|
||||||
# _install_workspaces_button: (_install 'com.system76.CosmicPanelWorkspacesButton' 'cosmic-panel-workspaces-button')
|
_install_button id name: (_install_icon name + '/data/icons/' + id + '.svg') (_install_desktop name + '/data/' + id + '.desktop')
|
||||||
|
_install_app_button: (_install_button 'com.system76.CosmicPanelAppButton' 'cosmic-panel-app-button')
|
||||||
|
_install_workspaces_button: (_install_button 'com.system76.CosmicPanelWorkspacesButton' 'cosmic-panel-workspaces-button')
|
||||||
|
|
||||||
# Installs files into the system
|
# Installs files into the system
|
||||||
install: _install_app_list _install_audio _install_battery _install_bluetooth _install_graphics _install_network _install_notifications _install_power _install_workspace _install_time
|
install: _install_app_list _install_audio _install_battery _install_bluetooth _install_graphics _install_network _install_notifications _install_power _install_workspace _install_time _install_panel_button _install_app_button _install_workspaces_button
|
||||||
|
|
||||||
# Extracts vendored dependencies if vendor=1
|
# Extracts vendored dependencies if vendor=1
|
||||||
_extract_vendor:
|
_extract_vendor:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue