tiling applet improvements

This commit is contained in:
Ashley Wulber 2023-10-18 18:29:51 -04:00 committed by Ashley Wulber
parent 46e9329614
commit a58fedba44
4 changed files with 153 additions and 92 deletions

16
Cargo.lock generated
View file

@ -935,7 +935,6 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-config" name = "cosmic-config"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"atomicwrites", "atomicwrites",
"cosmic-config-derive", "cosmic-config-derive",
@ -949,7 +948,6 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-config-derive" name = "cosmic-config-derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"quote", "quote",
"syn 1.0.109", "syn 1.0.109",
@ -1048,7 +1046,6 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-theme" name = "cosmic-theme"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"almost", "almost",
"cosmic-config", "cosmic-config",
@ -2412,7 +2409,6 @@ dependencies = [
[[package]] [[package]]
name = "iced" name = "iced"
version = "0.10.0" version = "0.10.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"iced_accessibility", "iced_accessibility",
"iced_core", "iced_core",
@ -2427,7 +2423,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_accessibility" name = "iced_accessibility"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"accesskit", "accesskit",
"accesskit_unix", "accesskit_unix",
@ -2436,7 +2431,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_core" name = "iced_core"
version = "0.10.0" version = "0.10.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"iced_accessibility", "iced_accessibility",
@ -2451,7 +2445,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_futures" name = "iced_futures"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"futures", "futures",
"iced_core", "iced_core",
@ -2464,7 +2457,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_graphics" name = "iced_graphics"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"bytemuck", "bytemuck",
@ -2482,7 +2474,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_renderer" name = "iced_renderer"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"iced_graphics", "iced_graphics",
"iced_tiny_skia", "iced_tiny_skia",
@ -2495,7 +2486,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_runtime" name = "iced_runtime"
version = "0.1.1" version = "0.1.1"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"iced_accessibility", "iced_accessibility",
"iced_core", "iced_core",
@ -2507,7 +2497,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_sctk" name = "iced_sctk"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"enum-repr", "enum-repr",
"float-cmp", "float-cmp",
@ -2531,7 +2520,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_style" name = "iced_style"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"iced_core", "iced_core",
"once_cell", "once_cell",
@ -2541,7 +2529,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_tiny_skia" name = "iced_tiny_skia"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"cosmic-text", "cosmic-text",
@ -2559,7 +2546,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_wgpu" name = "iced_wgpu"
version = "0.11.1" version = "0.11.1"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"bytemuck", "bytemuck",
@ -2581,7 +2567,6 @@ dependencies = [
[[package]] [[package]]
name = "iced_widget" name = "iced_widget"
version = "0.1.3" version = "0.1.3"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"iced_renderer", "iced_renderer",
"iced_runtime", "iced_runtime",
@ -2853,7 +2838,6 @@ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
[[package]] [[package]]
name = "libcosmic" name = "libcosmic"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic//#7cc791a3f5c0e54e091cce800a638aa5567055ef"
dependencies = [ dependencies = [
"apply", "apply",
"ashpd", "ashpd",

View file

@ -40,7 +40,7 @@ lto = "thin"
# [patch."https://github.com/pop-os/cosmic-time"] # [patch."https://github.com/pop-os/cosmic-time"]
# cosmic-time = { path = "../cosmic-time" } # cosmic-time = { path = "../cosmic-time" }
[patch."https://github.com/pop-os/libcosmic"] [patch."https://github.com/pop-os/libcosmic"]
libcosmic = { git = "https://github.com/pop-os/libcosmic//" } libcosmic = { path = "../libcosmic" }
cosmic-config = { git = "https://github.com/pop-os/libcosmic//" } cosmic-config = { path = "../libcosmic/cosmic-config" }
[patch."https://github.com/Smithay/client-toolkit"] [patch."https://github.com/Smithay/client-toolkit"]
sctk = { git = "https://github.com/smithay/client-toolkit//", package = "smithay-client-toolkit", rev = "dc8c4a0" } sctk = { git = "https://github.com/smithay/client-toolkit//", package = "smithay-client-toolkit", rev = "dc8c4a0" }

View file

@ -4,12 +4,11 @@ navigate-windows = Navigate windows
move-window = Move window move-window = Move window
toggle-floating-window = Toggle floating window toggle-floating-window = Toggle floating window
view-all-shortcuts = View all shortcuts... view-all-shortcuts = View all shortcuts...
show-active-hint = Show active hint active-hint = Active hint
gaps = Gaps gaps = Gaps
floating-window-exceptions = Floating window exceptions... floating-window-exceptions = Floating window exceptions...
window-management-settings = Window management settings... window-management-settings = Window management settings...
// Commands
super = Super super = Super
shift = Shift shift = Shift
arrow-keys = arrows arrow-keys = arrows

View file

@ -1,17 +1,23 @@
use crate::fl; use crate::fl;
use cosmic::app::Core; use cosmic::app::Core;
use cosmic::applet::button_theme; use cosmic::applet::button_theme;
use cosmic::cosmic_config::{ConfigGet, ConfigSet, CosmicConfigEntry};
use cosmic::cosmic_theme::ThemeBuilder;
use cosmic::iced::wayland::popup::{destroy_popup, get_popup}; use cosmic::iced::wayland::popup::{destroy_popup, get_popup};
use cosmic::iced::window::Id; use cosmic::iced::window::Id;
use cosmic::iced::{Command, Length, Limits, Subscription}; use cosmic::iced::{Command, Length, Limits, Subscription};
use cosmic::iced_core::{Alignment, Color}; use cosmic::iced_core::Alignment;
use cosmic::iced_futures::backend::native::tokio;
use cosmic::iced_style::application; use cosmic::iced_style::application;
use cosmic::iced_widget::canvas::path::lyon_path::builder;
use cosmic::iced_widget::graphics::image::image_rs::error;
use cosmic::iced_widget::row; use cosmic::iced_widget::row;
use cosmic::widget::{button, container, spin_button, text}; use cosmic::widget::{button, container, spin_button, text};
use cosmic::{Element, Theme}; use cosmic::{Element, Theme};
use cosmic_time::{anim, chain, id, Timeline}; use cosmic_time::{anim, chain, id, Timeline};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::time::Instant; use std::time::Instant;
use tracing::error;
const ID: &str = "com.system76.CosmicAppletTiling"; const ID: &str = "com.system76.CosmicAppletTiling";
const ON: &str = "com.system76.CosmicAppletTiling.On"; const ON: &str = "com.system76.CosmicAppletTiling.On";
@ -27,7 +33,7 @@ pub struct Window {
timeline: Timeline, timeline: Timeline,
id_ctr: u128, id_ctr: u128,
tile_windows: bool, tile_windows: bool,
show_active_hint: bool, active_hint: spin_button::Model<i32>,
gaps: spin_button::Model<i32>, gaps: spin_button::Model<i32>,
} }
@ -37,11 +43,12 @@ pub enum Message {
PopupClosed(Id), PopupClosed(Id),
Frame(Instant), Frame(Instant),
ToggleTileWindows(chain::Toggler, bool), ToggleTileWindows(chain::Toggler, bool),
ToggleShowActiveHint(chain::Toggler, bool), HandleActiveHint(spin_button::Message),
HandleGaps(spin_button::Message), HandleGaps(spin_button::Message),
ViewAllShortcuts, ViewAllShortcuts,
OpenFloatingWindowExceptions, OpenFloatingWindowExceptions,
OpenWindowManagementSettings, OpenWindowManagementSettings,
Ignore,
} }
impl cosmic::Application for Window { impl cosmic::Application for Window {
@ -62,9 +69,14 @@ impl cosmic::Application for Window {
core: Core, core: Core,
_flags: Self::Flags, _flags: Self::Flags,
) -> (Self, Command<cosmic::app::Message<Self::Message>>) { ) -> (Self, Command<cosmic::app::Message<Self::Message>>) {
let mut gaps = spin_button::Model::default().max(99).min(0).step(1);
gaps.value = core.system_theme().cosmic().gaps.1 as i32;
let mut active_hint = spin_button::Model::default().max(99).min(0).step(1);
active_hint.value = core.system_theme().cosmic().active_hint as i32;
let window = Window { let window = Window {
core, core,
gaps: spin_button::Model::default().max(99).min(0).step(1), gaps,
active_hint,
..Default::default() ..Default::default()
}; };
(window, Command::none()) (window, Command::none())
@ -113,21 +125,108 @@ impl cosmic::Application for Window {
self.timeline.set_chain(chain).start(); self.timeline.set_chain(chain).start();
self.tile_windows = toggled self.tile_windows = toggled
} }
Message::ToggleShowActiveHint(chain, toggled) => { Message::HandleActiveHint(msg) => {
self.timeline.set_chain(chain).start(); match msg {
self.show_active_hint = toggled spin_button::Message::Increment => {
self.active_hint.update(spin_button::Message::Increment)
}
spin_button::Message::Decrement => {
self.active_hint.update(spin_button::Message::Decrement)
}
};
let is_dark = self.core.system_theme().cosmic().is_dark;
let active_hint = self.active_hint.value;
return Command::perform(
async move {
let config = if is_dark {
cosmic::cosmic_theme::ThemeBuilder::dark_config()
} else {
cosmic::cosmic_theme::ThemeBuilder::light_config()
};
let Ok(config) = config else {
return;
};
let Ok(mut c_active_hint) = ConfigGet::get::<(u32, u32)>(&config, "active_hint") else {
error!("Error getting active_hint");
return;
};
c_active_hint.1 = active_hint as u32;
if let Err(err) = ConfigSet::set(&config, "active_hint", c_active_hint) {
error!(?err, "Error setting active_hint");
}
let config = if is_dark {
cosmic::theme::CosmicTheme::dark_config()
} else {
cosmic::theme::CosmicTheme::light_config()
};
let Ok(config) = config else {
return;
};
if let Err(err) = ConfigSet::set(&config, "active_hint", c_active_hint) {
error!(?err, "Error setting active_hint");
}
},
|_| cosmic::app::Message::App(Message::Ignore),
);
}
Message::HandleGaps(msg) => {
match msg {
spin_button::Message::Increment => {
self.gaps.update(spin_button::Message::Increment)
}
spin_button::Message::Decrement => {
self.gaps.update(spin_button::Message::Decrement)
}
};
let is_dark = self.core.system_theme().cosmic().is_dark;
let gaps = self.gaps.value;
return Command::perform(
async move {
let config = if is_dark {
cosmic::cosmic_theme::ThemeBuilder::dark_config()
} else {
cosmic::cosmic_theme::ThemeBuilder::light_config()
};
let Ok(config) = config else {
return;
};
let Ok(mut c_gaps) = ConfigGet::get::<(u32, u32)>(&config, "gaps") else {
error!("Error getting gaps");
return;
};
c_gaps.1 = gaps as u32;
if let Err(err) = ConfigSet::set(&config, "gaps", c_gaps) {
error!(?err, "Error setting gaps");
}
let config = if is_dark {
cosmic::theme::CosmicTheme::dark_config()
} else {
cosmic::theme::CosmicTheme::light_config()
};
let Ok(config) = config else {
return;
};
if let Err(err) = ConfigSet::set(&config, "gaps", c_gaps) {
error!(?err, "Error setting gaps");
}
},
|_| cosmic::app::Message::App(Message::Ignore),
);
} }
Message::HandleGaps(msg) => match msg {
spin_button::Message::Increment => {
self.gaps.update(spin_button::Message::Increment)
}
spin_button::Message::Decrement => {
self.gaps.update(spin_button::Message::Decrement)
}
},
Message::ViewAllShortcuts => println!("View all shortcuts..."), Message::ViewAllShortcuts => println!("View all shortcuts..."),
Message::OpenFloatingWindowExceptions => println!("Floating window exceptions..."), Message::OpenFloatingWindowExceptions => println!("Floating window exceptions..."),
Message::OpenWindowManagementSettings => println!("Window management settings..."), Message::OpenWindowManagementSettings => println!("Window management settings..."),
Message::Ignore => {}
} }
Command::none() Command::none()
} }
@ -141,10 +240,13 @@ impl cosmic::Application for Window {
} }
fn view_window(&self, _id: Id) -> Element<Self::Message> { fn view_window(&self, _id: Id) -> Element<Self::Message> {
let content_list = cosmic::widget::list_column() let cosmic = self.core.system_theme().cosmic();
.padding(0) let active_hint = cosmic.active_hint;
.spacing(5) let gaps = cosmic.gaps.1;
.add( let content_list = cosmic::widget::column()
.padding([8, 0])
.spacing(4)
.push(
container( container(
anim!( anim!(
TILE_WINDOWS, TILE_WINDOWS,
@ -156,16 +258,16 @@ impl cosmic::Application for Window {
.text_size(14) .text_size(14)
.width(Length::Fill), .width(Length::Fill),
) )
.padding([0, 15, 5, 15]), .padding([0, 16, 4, 16]),
) )
.add( .push(
row!( row!(
text(fl!("navigate-windows")).size(14).width(Length::Fill), text(fl!("navigate-windows")).size(14).width(Length::Fill),
text(format!("{} + {}", fl!("super"), fl!("arrow-keys"))).size(14), text(format!("{} + {}", fl!("super"), fl!("arrow-keys"))).size(14),
) )
.padding([5, 15, 5, 15]), .padding([4, 16, 4, 16]),
) )
.add( .push(
row!( row!(
text(fl!("move-window")).size(14).width(Length::Fill), text(fl!("move-window")).size(14).width(Length::Fill),
text(format!( text(format!(
@ -176,95 +278,71 @@ impl cosmic::Application for Window {
)) ))
.size(14), .size(14),
) )
.padding([5, 15, 5, 15]), .padding([4, 16, 4, 16]),
) )
.add( .push(
row!( row!(
text(fl!("toggle-floating-window")) text(fl!("toggle-floating-window"))
.size(14) .size(14)
.width(Length::Fill), .width(Length::Fill),
text(format!("{} + G", fl!("super"))).size(14), text(format!("{} + G", fl!("super"))).size(14),
) )
.padding([5, 15, 5, 15]), .padding([4, 16, 4, 16]),
) )
.add( .push(
container( container(
button(text(fl!("view-all-shortcuts")).size(14)) button(text(fl!("view-all-shortcuts")).size(14))
.width(Length::Fill) .width(Length::Fill)
.style(button_theme()) .style(button_theme())
.padding(10) .padding(8)
.on_press(Message::ViewAllShortcuts), .on_press(Message::ViewAllShortcuts),
) )
.width(Length::Fill) .width(Length::Fill)
.padding([0, 5, 0, 5]), .padding(0),
) )
.add( .push(
container(
anim!(
SHOW_ACTIVE_HINTS,
&self.timeline,
fl!("show-active-hint"),
self.show_active_hint,
|chain, enable| { Message::ToggleShowActiveHint(chain, enable) },
)
.text_size(14)
.width(Length::Fill),
)
.padding([5, 15, 5, 15]),
)
.add(
row!( row!(
text(fl!("gaps")).size(14).width(Length::Fill), text(fl!("active-hint")).size(14).width(Length::Fill),
spin_button(self.gaps.value.to_string(), Message::HandleGaps), spin_button(active_hint.to_string(), Message::HandleActiveHint),
) )
.padding([0, 15, 0, 15]) .padding([0, 16, 0, 16])
.align_items(Alignment::Center), .align_items(Alignment::Center),
) )
.add( .push(
row!(
text(fl!("gaps")).size(14).width(Length::Fill),
spin_button(gaps.to_string(), Message::HandleGaps),
)
.padding([0, 16, 0, 16])
.align_items(Alignment::Center),
)
.push(
container( container(
button(text(fl!("floating-window-exceptions")).size(14)) button(text(fl!("floating-window-exceptions")).size(14))
.width(Length::Fill) .width(Length::Fill)
.padding(10) .padding(8)
.style(button_theme()) .style(button_theme())
.on_press(Message::OpenFloatingWindowExceptions), .on_press(Message::OpenFloatingWindowExceptions),
) )
.width(Length::Fill) .width(Length::Fill)
.padding([0, 5, 0, 5]), .padding(0),
) )
.add( .push(
container( container(
button(text(fl!("window-management-settings")).size(14)) button(text(fl!("window-management-settings")).size(14))
.width(Length::Fill) .width(Length::Fill)
.padding(10) .padding(8)
.style(button_theme()) .style(button_theme())
.on_press(Message::OpenWindowManagementSettings), .on_press(Message::OpenWindowManagementSettings),
) )
.width(Length::Fill) .width(Length::Fill)
.padding([0, 5, 0, 5]), .padding(0),
); );
self.core self.core.applet.popup_container(content_list).into()
.applet
.popup_container(content_list)
.padding(1)
.style(popup_style())
.into()
} }
fn style(&self) -> Option<<Theme as application::StyleSheet>::Style> { fn style(&self) -> Option<<Theme as application::StyleSheet>::Style> {
Some(cosmic::applet::style()) Some(cosmic::applet::style())
} }
} }
fn popup_style() -> cosmic::theme::Container {
cosmic::theme::Container::Custom(Box::new(|theme| {
cosmic::iced_style::container::Appearance {
icon_color: Some(theme.cosmic().background.on.into()),
text_color: Some(theme.cosmic().background.on.into()),
background: Some(Color::from(theme.cosmic().background.base).into()),
border_radius: 8.0.into(),
border_width: 2.0,
border_color: theme.cosmic().bg_divider().into(),
}
}))
}