wip: update libcosmic (#93)
* wip: update libcosmic * fix: damge issue resolved by updating iced * fix: high cpu usage by time applet and app-list * refactor subscriptions to produce fewer events * refactor network applet to use less cpu * fix: text size * refactor: i18n for audio applet * refactor: power applet i18n setup * fix (battery): always send profile update * fix (battery): set toggler width to layout correctly * fix (app-list): backoff for restarts of toplevel subscription * fix (network): alignment * feat: ask for comfirmation before applying power applet actions * wip: integrate cosmic-config * update zbus * feat: update to use latest libcosmic * update iced * udpate deps * update deps * refactor: move applet helpers to this repo, outside of libcosmic. this should help alleviate some dependency hell * chore update deps * update deps * cleanup
This commit is contained in:
parent
8b46cc209f
commit
9ebd9b511a
48 changed files with 2841 additions and 1681 deletions
|
|
@ -5,15 +5,16 @@ authors = ["Ashley Wulber <ashley@system76.com>"]
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["tokio", "wayland", "applet"] }
|
||||
cosmic-client-toolkit = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false }
|
||||
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = ["client"] }
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", rev = "31f7e97", default-features = false, features = ["tokio", "wayland"] }
|
||||
cosmic-applet = { path = "../applet" }
|
||||
cosmic-client-toolkit = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, rev = "f0cfe09" }
|
||||
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = ["client"], rev = "f0cfe09" }
|
||||
wayland-backend = {version = "0.1.0", features = ["client_system"]}
|
||||
wayland-client = {version = "0.30.0"}
|
||||
calloop = "0.10.1"
|
||||
nix = "0.26.1"
|
||||
log = "0.4"
|
||||
pretty_env_logger = "0.4"
|
||||
pretty_env_logger = "0.5"
|
||||
once_cell = "1.9"
|
||||
futures = "0.3.21"
|
||||
xdg = "2.4.0"
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
use calloop::channel::SyncSender;
|
||||
use cosmic::applet::cosmic_panel_config::PanelAnchor;
|
||||
use cosmic::applet::CosmicAppletHelper;
|
||||
use cosmic::iced::alignment::{Horizontal, Vertical};
|
||||
use cosmic::iced::mouse::{self, ScrollDelta};
|
||||
use cosmic::iced::wayland::actions::window::SctkWindowSettings;
|
||||
use cosmic::iced::wayland::{window::resize_window, InitialSurface};
|
||||
use cosmic::iced::widget::{column, container, row, text};
|
||||
use cosmic::iced::Color;
|
||||
use cosmic::iced::{
|
||||
subscription, widget::button, window, Application, Command, Event::Mouse, Length, Settings,
|
||||
Subscription,
|
||||
};
|
||||
use cosmic::iced_style::application::{self, Appearance};
|
||||
use cosmic::iced_style::Color;
|
||||
use cosmic::theme::Button;
|
||||
use cosmic::{Element, Theme};
|
||||
use cosmic_applet::cosmic_panel_config::PanelAnchor;
|
||||
use cosmic_applet::CosmicAppletHelper;
|
||||
use cosmic_protocols::workspace::v1::client::zcosmic_workspace_handle_v1;
|
||||
use std::cmp::Ordering;
|
||||
use wayland_backend::client::ObjectId;
|
||||
|
|
@ -25,10 +25,7 @@ use crate::wayland_subscription::{workspaces, WorkspacesUpdate};
|
|||
pub fn run() -> cosmic::iced::Result {
|
||||
let settings = Settings {
|
||||
initial_surface: InitialSurface::XdgWindow(SctkWindowSettings {
|
||||
iced_settings: cosmic::iced_native::window::Settings {
|
||||
size: (32, 32),
|
||||
..Default::default()
|
||||
},
|
||||
size: (32, 32),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
|
|
@ -103,7 +100,7 @@ impl Application for IcedWorkspacesApplet {
|
|||
Layout::Row => (unit * self.workspaces.len().max(1) as u32, unit),
|
||||
Layout::Column => (unit, unit * self.workspaces.len().max(1) as u32),
|
||||
};
|
||||
return resize_window(window::Id::new(0), w, h);
|
||||
return resize_window(window::Id(0), w, h);
|
||||
}
|
||||
WorkspacesUpdate::Started(tx) => {
|
||||
self.workspace_tx.replace(tx);
|
||||
|
|
@ -141,6 +138,7 @@ impl Application for IcedWorkspacesApplet {
|
|||
.filter_map(|w| {
|
||||
let btn = button(
|
||||
text(w.0.clone())
|
||||
.size(14)
|
||||
.horizontal_alignment(Horizontal::Center)
|
||||
.vertical_alignment(Vertical::Center)
|
||||
.width(Length::Fill)
|
||||
|
|
@ -184,7 +182,7 @@ impl Application for IcedWorkspacesApplet {
|
|||
fn subscription(&self) -> Subscription<Message> {
|
||||
Subscription::batch(
|
||||
vec![
|
||||
workspaces(0).map(|(_, msg)| Message::WorkspaceUpdate(msg)),
|
||||
workspaces(0).map(|e| Message::WorkspaceUpdate(e.1)),
|
||||
subscription::events_with(|e, _| match e {
|
||||
Mouse(mouse::Event::WheelScrolled { delta }) => {
|
||||
Some(Message::WheelScrolled(delta))
|
||||
|
|
@ -197,7 +195,7 @@ impl Application for IcedWorkspacesApplet {
|
|||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
self.theme.clone()
|
||||
}
|
||||
|
||||
fn close_requested(&self, _id: window::Id) -> Self::Message {
|
||||
|
|
@ -205,9 +203,9 @@ impl Application for IcedWorkspacesApplet {
|
|||
}
|
||||
|
||||
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(Box::new(|theme| Appearance {
|
||||
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||
text_color: theme.cosmic().on_bg_color().into(),
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
global_conf = configuration_data()
|
||||
global_conf.set_quoted('APP_ID', application_id)
|
||||
global_conf.set_quoted('PROFILE', profile)
|
||||
global_conf.set_quoted('VERSION', version + version_suffix)
|
||||
config = configure_file(
|
||||
input: 'config.rs.in',
|
||||
output: 'config.rs',
|
||||
configuration: global_conf
|
||||
)
|
||||
# Copy the config.rs output to the source directory.
|
||||
run_command(
|
||||
'cp',
|
||||
meson.project_build_root() / 'src' / 'config.rs',
|
||||
meson.project_source_root() / 'src' / 'config.rs',
|
||||
check: true
|
||||
)
|
||||
|
||||
cargo_options = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ]
|
||||
cargo_options += [ '--target-dir', meson.project_build_root() / 'src' ]
|
||||
|
||||
if get_option('profile') == 'default'
|
||||
cargo_options += [ '--release' ]
|
||||
rust_target = 'release'
|
||||
message('Building in release mode')
|
||||
else
|
||||
rust_target = 'debug'
|
||||
message('Building in debug mode')
|
||||
endif
|
||||
|
||||
if get_option('vendor') == true
|
||||
cargo_options += [ '--locked' ]
|
||||
message('Building with vendoring')
|
||||
endif
|
||||
|
||||
cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
|
||||
|
||||
cargo_build = custom_target(
|
||||
'cargo-build',
|
||||
build_by_default: true,
|
||||
build_always_stale: true,
|
||||
output: meson.project_name(),
|
||||
console: true,
|
||||
install: true,
|
||||
install_dir: bindir,
|
||||
command: [
|
||||
'env',
|
||||
cargo_env,
|
||||
cargo, 'build',
|
||||
cargo_options,
|
||||
'&&',
|
||||
'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@',
|
||||
]
|
||||
)
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
use calloop::channel::*;
|
||||
use cosmic::applet::cosmic_panel_config::CosmicPanelOuput;
|
||||
use cosmic_client_toolkit::{
|
||||
sctk::{
|
||||
self,
|
||||
|
|
@ -11,7 +10,7 @@ use cosmic_client_toolkit::{
|
|||
};
|
||||
use cosmic_protocols::workspace::v1::client::zcosmic_workspace_handle_v1;
|
||||
use futures::{channel::mpsc, executor::block_on, SinkExt};
|
||||
use std::{env, os::unix::net::UnixStream, path::PathBuf, str::FromStr, time::Duration};
|
||||
use std::{env, os::unix::net::UnixStream, path::PathBuf, time::Duration};
|
||||
use wayland_backend::client::ObjectId;
|
||||
use wayland_client::{
|
||||
globals::registry_queue_init,
|
||||
|
|
@ -45,10 +44,6 @@ pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<Workspace
|
|||
std::thread::spawn(move || {
|
||||
let configured_output = std::env::var("COSMIC_PANEL_OUTPUT")
|
||||
.ok()
|
||||
.map(|output_str| match CosmicPanelOuput::from_str(&output_str) {
|
||||
Ok(CosmicPanelOuput::Name(name)) => name,
|
||||
_ => "".to_string(),
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let mut event_loop = calloop::EventLoop::<State>::try_new().unwrap();
|
||||
let loop_handle = event_loop.handle();
|
||||
|
|
@ -97,7 +92,11 @@ pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<Workspace
|
|||
.workspace_groups()
|
||||
.iter()
|
||||
.find_map(|g| {
|
||||
if !g.outputs.iter().any(|o| Some(o) == state.expected_output.as_ref()) {
|
||||
if !g
|
||||
.outputs
|
||||
.iter()
|
||||
.any(|o| Some(o) == state.expected_output.as_ref())
|
||||
{
|
||||
return None;
|
||||
}
|
||||
g.workspaces
|
||||
|
|
@ -179,7 +178,10 @@ impl State {
|
|||
.workspace_groups()
|
||||
.iter()
|
||||
.filter_map(|g| {
|
||||
if g.outputs.iter().any(|o| Some(o) == self.expected_output.as_ref()) {
|
||||
if g.outputs
|
||||
.iter()
|
||||
.any(|o| Some(o) == self.expected_output.as_ref())
|
||||
{
|
||||
Some(g.workspaces.iter().map(|w| {
|
||||
(
|
||||
w.name.clone(),
|
||||
|
|
|
|||
|
|
@ -18,29 +18,36 @@ pub fn workspaces<I: 'static + Hash + Copy + Send + Sync>(
|
|||
subscription::unfold(id, State::Ready, move |state| _workspaces(id, state))
|
||||
}
|
||||
|
||||
async fn _workspaces<I: Copy>(id: I, state: State) -> (Option<(I, WorkspacesUpdate)>, State) {
|
||||
match state {
|
||||
State::Ready => {
|
||||
if let Ok(watcher) = WorkspacesWatcher::new() {
|
||||
(
|
||||
Some((id, WorkspacesUpdate::Started(watcher.get_sender()))),
|
||||
State::Waiting(watcher),
|
||||
)
|
||||
} else {
|
||||
(Some((id, WorkspacesUpdate::Errored)), State::Error)
|
||||
async fn _workspaces<I: Copy>(id: I, mut state: State) -> ((I, WorkspacesUpdate), State) {
|
||||
loop {
|
||||
let (update, new_state) = match state {
|
||||
State::Ready => {
|
||||
if let Ok(watcher) = WorkspacesWatcher::new() {
|
||||
(
|
||||
Some((id, WorkspacesUpdate::Started(watcher.get_sender()))),
|
||||
State::Waiting(watcher),
|
||||
)
|
||||
} else {
|
||||
(Some((id, WorkspacesUpdate::Errored)), State::Error)
|
||||
}
|
||||
}
|
||||
}
|
||||
State::Waiting(mut t) => {
|
||||
if let Some(w) = t.workspaces().await {
|
||||
(
|
||||
Some((id, WorkspacesUpdate::Workspaces(w))),
|
||||
State::Waiting(t),
|
||||
)
|
||||
} else {
|
||||
(Some((id, WorkspacesUpdate::Errored)), State::Error)
|
||||
State::Waiting(mut t) => {
|
||||
if let Some(w) = t.workspaces().await {
|
||||
(
|
||||
Some((id, WorkspacesUpdate::Workspaces(w))),
|
||||
State::Waiting(t),
|
||||
)
|
||||
} else {
|
||||
(Some((id, WorkspacesUpdate::Errored)), State::Error)
|
||||
}
|
||||
}
|
||||
State::Error => cosmic::iced::futures::future::pending().await,
|
||||
};
|
||||
state = new_state;
|
||||
|
||||
if let Some(update) = update {
|
||||
return (update, state);
|
||||
}
|
||||
State::Error => cosmic::iced::futures::future::pending().await,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue