Initial implementation of the Tiling applet
This commit is contained in:
parent
fcd1cfff5e
commit
3353dc95ac
11 changed files with 509 additions and 49 deletions
15
cosmic-applet-tiling/Cargo.toml
Normal file
15
cosmic-applet-tiling/Cargo.toml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "cosmic-applet-tiling"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
libcosmic.workspace = true
|
||||
once_cell = "1"
|
||||
i18n-embed = { version = "0.14.0", features = ["fluent-system", "desktop-requester"] }
|
||||
i18n-embed-fl = "0.7.0"
|
||||
rust-embed = "8.0.0"
|
||||
tracing = "0.1"
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
[Desktop Entry]
|
||||
Name=Cosmic Applet Tiling
|
||||
Comment=Applet for Cosmic Panel
|
||||
Type=Application
|
||||
Exec=cosmic-applet-tiling
|
||||
Terminal=false
|
||||
Categories=Cosmic;Iced;
|
||||
Keywords=Cosmic;Iced;
|
||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||
Icon=com.system76.CosmicAppletTiling
|
||||
StartupNotify=true
|
||||
NoDisplay=true
|
||||
X-CosmicApplet=true
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="applet-graphics-mode">
|
||||
<rect id="Rectangle 47" x="4" y="4" width="8" height="8" fill="#232323"/>
|
||||
<g id="Rectangle 48">
|
||||
<path d="M4 0.75C4 0.75 4 0 5 0C6 0 6 0.75 6 0.75V3H4V0.75Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 54">
|
||||
<path d="M0.75 6C0.75 6 0 6 0 5C0 4 0.75 4 0.75 4H3V6H0.75Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 57">
|
||||
<path d="M15.25 6C15.25 6 16 6 16 5C16 4 15.25 4 15.25 4H13V6H15.25Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 51">
|
||||
<path d="M4 15.25C4 15.25 4 16 5 16C6 16 6 15.25 6 15.25V13H4V15.25Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 49">
|
||||
<path d="M7 0.75C7 0.75 7 0 8 0C9 0 9 0.75 9 0.75V3H7V0.75Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 55">
|
||||
<path d="M0.75 9C0.75 9 0 9 0 8C0 7 0.75 7 0.75 7H3V9H0.75Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 58">
|
||||
<path d="M15.25 9C15.25 9 16 9 16 8C16 7 15.25 7 15.25 7H13V9H15.25Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 52">
|
||||
<path d="M7 15.25C7 15.25 7 16 8 16C9 16 9 15.25 9 15.25V13H7V15.25Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 50">
|
||||
<path d="M10 0.75C10 0.75 10 0 11 0C12 0 12 0.75 12 0.75V3H10V0.75Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 56">
|
||||
<path d="M0.75 12C0.75 12 0 12 0 11C0 10 0.75 10 0.75 10H3V12H0.75Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 59">
|
||||
<path d="M15.25 12C15.25 12 16 12 16 11C16 10 15.25 10 15.25 10H13V12H15.25Z" fill="#232323"/>
|
||||
</g>
|
||||
<g id="Rectangle 53">
|
||||
<path d="M10 15.25C10 15.25 10 16 11 16C12 16 12 15.25 12 15.25V13H10V15.25Z" fill="#232323"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
4
cosmic-applet-tiling/i18n.toml
Normal file
4
cosmic-applet-tiling/i18n.toml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fallback_language = "en"
|
||||
|
||||
[fluent]
|
||||
assets_dir = "i18n"
|
||||
16
cosmic-applet-tiling/i18n/en/cosmic_applet_tiling.ftl
Normal file
16
cosmic-applet-tiling/i18n/en/cosmic_applet_tiling.ftl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
tile-windows = Tile Windows
|
||||
floating-window-exceptions = Floating Window Exceptions
|
||||
shortcuts = Shortcuts
|
||||
launcher = Launcher
|
||||
navigate-windows = Navigate Windows
|
||||
toggle-tiling = Toggle Tiling
|
||||
view-all = View All
|
||||
show-window-titles = Show Window Titles
|
||||
show-active-hint = Show Active Hint
|
||||
active-border-radius = Active Border Radius
|
||||
active-hint-color = Active Hint Color
|
||||
gaps = Gaps
|
||||
|
||||
// Commands
|
||||
super = Super
|
||||
arrow-keys = Arrow keys
|
||||
47
cosmic-applet-tiling/src/localize.rs
Normal file
47
cosmic-applet-tiling/src/localize.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// 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);
|
||||
}
|
||||
}
|
||||
10
cosmic-applet-tiling/src/main.rs
Normal file
10
cosmic-applet-tiling/src/main.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use crate::window::Window;
|
||||
|
||||
mod localize;
|
||||
mod window;
|
||||
|
||||
fn main() -> cosmic::iced::Result {
|
||||
localize::localize();
|
||||
|
||||
cosmic::app::applet::run::<Window>(true, ())
|
||||
}
|
||||
189
cosmic-applet-tiling/src/window.rs
Normal file
189
cosmic-applet-tiling/src/window.rs
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
use crate::fl;
|
||||
use cosmic::app::Core;
|
||||
use cosmic::cosmic_theme::palette::rgb::Rgb;
|
||||
use cosmic::iced::wayland::popup::{destroy_popup, get_popup};
|
||||
use cosmic::iced::window::Id;
|
||||
use cosmic::iced::{Command, Limits};
|
||||
use cosmic::iced_runtime::core::window;
|
||||
use cosmic::iced_style::application;
|
||||
use cosmic::theme::{Button, Svg};
|
||||
use cosmic::widget::{button, list_column, settings, spin_button, text, toggler};
|
||||
use cosmic::{Element, Theme};
|
||||
|
||||
const ID: &str = "com.system76.CosmicAppletTiling";
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Window {
|
||||
core: Core,
|
||||
popup: Option<Id>,
|
||||
id_ctr: u128,
|
||||
tile_windows: bool,
|
||||
show_window_titles: bool,
|
||||
show_active_hint: bool,
|
||||
active_border_radius: spin_button::Model<i32>,
|
||||
active_hint_color: Rgb,
|
||||
gaps: spin_button::Model<i32>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Message {
|
||||
TogglePopup,
|
||||
PopupClosed(Id),
|
||||
ToggleTileWindows(bool),
|
||||
ToggleShowWindowTitles(bool),
|
||||
ToggleShowActiveHint(bool),
|
||||
HandleActiveBorderRadius(spin_button::Message),
|
||||
SetActiveHintColor(Rgb),
|
||||
HandleGaps(spin_button::Message),
|
||||
}
|
||||
|
||||
impl cosmic::Application for Window {
|
||||
type Executor = cosmic::SingleThreadExecutor;
|
||||
type Flags = ();
|
||||
type Message = Message;
|
||||
const APP_ID: &'static str = ID;
|
||||
|
||||
fn core(&self) -> &Core {
|
||||
&self.core
|
||||
}
|
||||
|
||||
fn core_mut(&mut self) -> &mut Core {
|
||||
&mut self.core
|
||||
}
|
||||
|
||||
fn init(
|
||||
core: Core,
|
||||
_flags: Self::Flags,
|
||||
) -> (Self, Command<cosmic::app::Message<Self::Message>>) {
|
||||
let window = Window {
|
||||
core,
|
||||
active_border_radius: spin_button::Model::default().max(99).min(0).step(1),
|
||||
gaps: spin_button::Model::default().max(99).min(0).step(1),
|
||||
..Default::default()
|
||||
};
|
||||
(window, Command::none())
|
||||
}
|
||||
|
||||
fn on_close_requested(&self, id: window::Id) -> Option<Message> {
|
||||
Some(Message::PopupClosed(id))
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Self::Message) -> Command<cosmic::app::Message<Self::Message>> {
|
||||
match message {
|
||||
Message::TogglePopup => {
|
||||
return if let Some(p) = self.popup.take() {
|
||||
destroy_popup(p)
|
||||
} else {
|
||||
self.id_ctr += 1;
|
||||
let new_id = Id(self.id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
let mut popup_settings =
|
||||
self.core
|
||||
.applet_helper
|
||||
.get_popup_settings(Id(0), new_id, None, None, None);
|
||||
popup_settings.positioner.size_limits = Limits::NONE
|
||||
.max_width(372.0)
|
||||
.min_width(300.0)
|
||||
.min_height(200.0)
|
||||
.max_height(1080.0);
|
||||
get_popup(popup_settings)
|
||||
}
|
||||
}
|
||||
Message::PopupClosed(id) => {
|
||||
if self.popup.as_ref() == Some(&id) {
|
||||
self.popup = None;
|
||||
}
|
||||
}
|
||||
Message::ToggleTileWindows(toggled) => self.tile_windows = toggled,
|
||||
Message::ToggleShowWindowTitles(toggled) => self.show_window_titles = toggled,
|
||||
Message::ToggleShowActiveHint(toggled) => self.show_active_hint = toggled,
|
||||
Message::HandleActiveBorderRadius(msg) => match msg {
|
||||
spin_button::Message::Increment => self
|
||||
.active_border_radius
|
||||
.update(spin_button::Message::Increment),
|
||||
spin_button::Message::Decrement => self
|
||||
.active_border_radius
|
||||
.update(spin_button::Message::Decrement),
|
||||
},
|
||||
Message::SetActiveHintColor(_) => {}
|
||||
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)
|
||||
}
|
||||
},
|
||||
}
|
||||
Command::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Self::Message> {
|
||||
self.core
|
||||
.applet_helper
|
||||
.icon_button(ID)
|
||||
.on_press(Message::TogglePopup)
|
||||
.style(Button::Text)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: Id) -> Element<Self::Message> {
|
||||
let content_list = list_column()
|
||||
.add(settings::item(
|
||||
fl!("tile-windows"),
|
||||
toggler(None, self.tile_windows, |value| {
|
||||
Message::ToggleTileWindows(value)
|
||||
}),
|
||||
))
|
||||
.add(settings::item(
|
||||
fl!("floating-window-exceptions"),
|
||||
button(Button::Card).icon(Svg::Symbolic, "arrow-right", 16),
|
||||
))
|
||||
.add(
|
||||
settings::view_section(fl!("shortcuts"))
|
||||
.add(settings::item(
|
||||
fl!("launcher"),
|
||||
text(format!("{} + /", fl!("super"))),
|
||||
))
|
||||
.add(settings::item(
|
||||
fl!("navigate-windows"),
|
||||
text(format!("{} + {}", fl!("super"), fl!("arrow-keys"))),
|
||||
))
|
||||
.add(settings::item(
|
||||
fl!("toggle-tiling"),
|
||||
text(format!("{} + Y", fl!("super"))),
|
||||
))
|
||||
.add(settings::item(fl!("view-all"), text(""))),
|
||||
)
|
||||
.add(settings::item(
|
||||
fl!("show-window-titles"),
|
||||
toggler(None, self.show_window_titles, |value| {
|
||||
Message::ToggleShowWindowTitles(value)
|
||||
}),
|
||||
))
|
||||
.add(settings::item(
|
||||
fl!("show-active-hint"),
|
||||
toggler(None, self.show_active_hint, |value| {
|
||||
Message::ToggleShowActiveHint(value)
|
||||
}),
|
||||
))
|
||||
.add(settings::item(
|
||||
fl!("active-border-radius"),
|
||||
spin_button(
|
||||
self.active_border_radius.value.to_string(),
|
||||
Message::HandleActiveBorderRadius,
|
||||
),
|
||||
))
|
||||
.add(settings::item(fl!("active-hint-color"), text("TODO")))
|
||||
.add(settings::item(
|
||||
fl!("gaps"),
|
||||
spin_button(self.gaps.value.to_string(), Message::HandleGaps),
|
||||
));
|
||||
|
||||
self.core.applet_helper.popup_container(content_list).into()
|
||||
}
|
||||
|
||||
fn style(&self) -> Option<<Theme as application::StyleSheet>::Style> {
|
||||
Some(cosmic::app::applet::style())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue