From 34c02ac7fa4efba6dc3d0f93006bcd17bb77b937 Mon Sep 17 00:00:00 2001 From: Greg V Date: Fri, 5 Jun 2020 20:52:11 +0300 Subject: [PATCH] Refactor dock sizing, other cleanup --- shell/src/dock.rs | 73 ++++++++++++++++++++++++++--------------- shell/src/util/apps.rs | 6 ++-- shell/src/util/icons.rs | 10 +++--- wstk/src/toplevels.rs | 4 +-- 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/shell/src/dock.rs b/shell/src/dock.rs index 0585a34..2aba900 100644 --- a/shell/src/dock.rs +++ b/shell/src/dock.rs @@ -6,6 +6,13 @@ lazy_static::lazy_static! { icons::IconHandle::from_path(apps::unknown_icon()); } +pub const APP_PADDING: u16 = 4; +pub const DOCK_PADDING: u16 = 4; +pub const DOCK_GAP: u16 = 6; +pub const BAR_HEIGHT: u16 = 10; +pub const DOCK_AND_GAP_HEIGHT: u16 = + icons::ICON_SIZE + APP_PADDING * 2 + DOCK_PADDING * 2 + DOCK_GAP; + #[derive(Debug, Clone)] pub enum Msg { ActivateApp(usize), @@ -22,7 +29,7 @@ struct DockApp { } impl DockApp { - pub fn new(app: apps::App) -> DockApp { + fn new(app: apps::App) -> DockApp { let icon = app .icon() .map(icons::IconHandle::from_path) @@ -34,26 +41,32 @@ impl DockApp { } } - pub fn from_id(id: &str) -> Option { + fn from_id(id: &str) -> Option { apps::App::lookup(id).map(DockApp::new) } - pub fn id(&self) -> &str { + fn id(&self) -> &str { &self.app.id } - pub fn widget(&mut self, position: usize) -> Element { + fn widget(&mut self, position: usize) -> Element { use iced_native::*; - Container::new( - Button::new(&mut self.button, self.icon.clone().widget()) - .style(style::Dock) - .on_press(Msg::ActivateApp(position)), - ) - .style(style::Dock) - .center_x() - .center_y() - .into() + let big_button = Button::new(&mut self.button, self.icon.clone().widget()) + .style(style::Dock) + .padding(APP_PADDING) + .on_press(Msg::ActivateApp(position)); + + Container::new(big_button) + .style(style::Dock) + .center_x() + .center_y() + .into() + } + + fn width(&self) -> u16 { + // TODO: will be dynamic based on extras + icons::ICON_SIZE + APP_PADDING * 2 } } @@ -112,8 +125,8 @@ impl DesktopWidget for Dock { | layer_surface::Anchor::Right | layer_surface::Anchor::Bottom, ); - layer_surface.set_size(0, 85); - layer_surface.set_exclusive_zone(10); + layer_surface.set_size(0, (BAR_HEIGHT + DOCK_AND_GAP_HEIGHT) as _); + layer_surface.set_exclusive_zone(BAR_HEIGHT as _); } } @@ -129,7 +142,7 @@ impl IcedWidget for Dock { if self.shown { let row = self.apps.iter_mut().enumerate().fold( - Row::new().align_items(Align::Center).spacing(4), + Row::new().align_items(Align::Center).spacing(DOCK_PADDING), |row, (i, app)| row.push(app.widget(i)), ); // TODO: show toplevels for unrecognized apps @@ -138,19 +151,23 @@ impl IcedWidget for Dock { Container::new(row) .style(style::Dock) .width(Length::Shrink) - .height(Length::Units(69)) + .height(Length::Shrink) .center_x() .center_y() - .padding(4), + .padding(DOCK_PADDING), ) .width(Length::Fill) - .height(Length::Units(75)) + .height(Length::Shrink) .center_x(); - col = col.push(dock); + col = col.push(dock).push( + Container::new(Text::new("".to_string()).size(0)).height(Length::Units(DOCK_GAP)), + ); } else { - col = col - .push(Container::new(Text::new("".to_string()).size(0)).height(Length::Units(75))); + col = col.push( + Container::new(Text::new("".to_string()).size(0)) + .height(Length::Units(DOCK_AND_GAP_HEIGHT)), + ); } let bar = Container::new( @@ -161,7 +178,7 @@ impl IcedWidget for Dock { ) .style(style::DarkBar) .width(Length::Fill) - .height(Length::Units(10)) + .height(Length::Units(BAR_HEIGHT)) .center_x() .center_y(); @@ -171,18 +188,20 @@ impl IcedWidget for Dock { fn input_region(&self, width: i32, _height: i32) -> Option>> { let bar = Rectangle { x: 0, - y: 75, + y: DOCK_AND_GAP_HEIGHT as _, width, - height: 10, + height: BAR_HEIGHT as _, }; if self.shown { - let dock_width = 420; // TODO actually calculate based on icons + let dock_width = (self.apps.iter().fold(0, |w, app| w + app.width()) + + DOCK_PADDING * (std::cmp::max(self.apps.len() as u16, 1) - 1) + + DOCK_PADDING * 2) as _; Some(vec![ Rectangle { x: (width - dock_width) / 2, y: 0, width: dock_width, - height: 85, + height: (BAR_HEIGHT + DOCK_AND_GAP_HEIGHT) as _, }, bar, ]) diff --git a/shell/src/util/apps.rs b/shell/src/util/apps.rs index 3dca459..da73e16 100644 --- a/shell/src/util/apps.rs +++ b/shell/src/util/apps.rs @@ -1,3 +1,4 @@ +use crate::util::icons; use std::path::Path; lazy_static::lazy_static! { @@ -51,7 +52,8 @@ impl App { .unwrap() .get_names(); let name = names.iter().next()?; - linicon::lookup_icon_with_extra_paths("Adwaita", name, 64, 1, &PATHS[..]) + // TODO: support scales properly + linicon::lookup_icon_with_extra_paths("Adwaita", name, icons::ICON_SIZE * 2, 1, &PATHS[..]) .unwrap() .flat_map(|x| x) .next() @@ -76,7 +78,7 @@ fn check_icon(p: String, icon_type: linicon::IconType) -> Option linicon::IconPath { - linicon::lookup_icon_with_extra_paths("Adwaita", "application-x-executable", 64, 1, &PATHS[..]) + linicon::lookup_icon_with_extra_paths("Adwaita", "application-x-executable", 128, 1, &PATHS[..]) .unwrap() .flat_map(|x| x) .next() diff --git a/shell/src/util/icons.rs b/shell/src/util/icons.rs index 2293e36..c8f70cb 100644 --- a/shell/src/util/icons.rs +++ b/shell/src/util/icons.rs @@ -1,5 +1,7 @@ use wstk::*; +pub const ICON_SIZE: u16 = 64; + #[derive(Clone)] pub enum IconHandle { Vector(iced_native::svg::Handle), @@ -20,12 +22,12 @@ impl IconHandle { use iced_native::{Image, Length, Svg}; match self { IconHandle::Raster(h) => Image::new(h) - .width(Length::Units(64)) - .height(Length::Units(64)) + .width(Length::Units(ICON_SIZE)) + .height(Length::Units(ICON_SIZE)) .into(), IconHandle::Vector(h) => Svg::new(h) - .width(Length::Units(64)) - .height(Length::Units(64)) + .width(Length::Units(ICON_SIZE)) + .height(Length::Units(ICON_SIZE)) .into(), } } diff --git a/wstk/src/toplevels.rs b/wstk/src/toplevels.rs index abbded3..8e714b4 100644 --- a/wstk/src/toplevels.rs +++ b/wstk/src/toplevels.rs @@ -1,10 +1,9 @@ -use crate::event_loop::wayland_event_chan; use futures::{channel::mpsc, prelude::*}; use smithay_client_toolkit::{ environment::GlobalHandler, reexports::client::{ protocol::{wl_output, wl_registry}, - Attached, DispatchData, Interface, MessageGroup, Proxy, ProxyMap, + Attached, DispatchData, Proxy, }, }; @@ -18,7 +17,6 @@ use std::{ collections::HashMap, hash::{Hash, Hasher}, rc::Rc, - sync::Arc, }; #[derive(PartialEq, Eq)]