2023-07-06 00:03:26 +02:00
|
|
|
use std::sync::Mutex;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
2024-04-03 16:02:27 +02:00
|
|
|
config::Config,
|
2023-07-06 00:03:26 +02:00
|
|
|
fl,
|
2024-04-03 16:02:27 +02:00
|
|
|
shell::grabs::ResizeEdge,
|
2023-07-06 00:03:26 +02:00
|
|
|
utils::iced::{IcedElement, Program},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use calloop::LoopHandle;
|
|
|
|
|
use cosmic::{
|
|
|
|
|
iced::widget::{column, container, horizontal_space, row, vertical_space},
|
2024-02-09 16:48:03 -08:00
|
|
|
iced_core::{Background, Border, Color, Length},
|
2023-07-06 00:03:26 +02:00
|
|
|
theme,
|
2023-10-02 19:37:23 +02:00
|
|
|
widget::{icon::from_name, text},
|
|
|
|
|
Apply,
|
2023-07-06 00:03:26 +02:00
|
|
|
};
|
2024-04-03 16:02:27 +02:00
|
|
|
use cosmic_settings_config::shortcuts::action::{Action, ResizeDirection};
|
2023-07-06 00:03:26 +02:00
|
|
|
use smithay::utils::Size;
|
|
|
|
|
|
|
|
|
|
pub type ResizeIndicator = IcedElement<ResizeIndicatorInternal>;
|
|
|
|
|
|
|
|
|
|
pub fn resize_indicator(
|
|
|
|
|
direction: ResizeDirection,
|
|
|
|
|
config: &Config,
|
2023-09-29 21:33:16 +02:00
|
|
|
evlh: LoopHandle<'static, crate::state::State>,
|
2023-10-10 13:55:34 -04:00
|
|
|
theme: cosmic::Theme,
|
2023-07-06 00:03:26 +02:00
|
|
|
) -> ResizeIndicator {
|
|
|
|
|
ResizeIndicator::new(
|
|
|
|
|
ResizeIndicatorInternal {
|
|
|
|
|
edges: Mutex::new(ResizeEdge::all()),
|
|
|
|
|
direction,
|
|
|
|
|
shortcut1: config
|
2024-04-03 16:02:27 +02:00
|
|
|
.shortcuts
|
2023-07-06 00:03:26 +02:00
|
|
|
.iter()
|
|
|
|
|
.find_map(|(pattern, action)| {
|
|
|
|
|
(*action == Action::Resizing(ResizeDirection::Outwards)).then_some(pattern)
|
|
|
|
|
})
|
|
|
|
|
.map(|pattern| format!("{}: ", pattern.to_string()))
|
|
|
|
|
.unwrap_or_else(|| crate::fl!("unknown-keybinding")),
|
|
|
|
|
shortcut2: config
|
2024-04-03 16:02:27 +02:00
|
|
|
.shortcuts
|
2023-07-06 00:03:26 +02:00
|
|
|
.iter()
|
|
|
|
|
.find_map(|(pattern, action)| {
|
|
|
|
|
(*action == Action::Resizing(ResizeDirection::Inwards)).then_some(pattern)
|
|
|
|
|
})
|
|
|
|
|
.map(|pattern| format!("{}: ", pattern.to_string()))
|
|
|
|
|
.unwrap_or_else(|| crate::fl!("unknown-keybinding")),
|
|
|
|
|
},
|
|
|
|
|
Size::from((1, 1)),
|
|
|
|
|
evlh,
|
2023-10-10 13:55:34 -04:00
|
|
|
theme,
|
2023-07-06 00:03:26 +02:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct ResizeIndicatorInternal {
|
|
|
|
|
pub edges: Mutex<ResizeEdge>,
|
|
|
|
|
pub direction: ResizeDirection,
|
|
|
|
|
pub shortcut1: String,
|
|
|
|
|
pub shortcut2: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Program for ResizeIndicatorInternal {
|
|
|
|
|
type Message = ();
|
|
|
|
|
|
2024-02-09 16:48:03 -08:00
|
|
|
fn view(&self) -> cosmic::Element<'_, Self::Message> {
|
2023-07-06 00:03:26 +02:00
|
|
|
let edges = self.edges.lock().unwrap();
|
2023-10-02 19:37:23 +02:00
|
|
|
let icon_container_style = || {
|
|
|
|
|
theme::Container::custom(|theme| container::Appearance {
|
|
|
|
|
icon_color: Some(Color::from(theme.cosmic().accent.on)),
|
|
|
|
|
text_color: Some(Color::from(theme.cosmic().accent.on)),
|
|
|
|
|
background: Some(Background::Color(theme.cosmic().accent_color().into())),
|
2024-02-09 16:48:03 -08:00
|
|
|
border: Border {
|
|
|
|
|
radius: 18.0.into(),
|
|
|
|
|
width: 0.0,
|
|
|
|
|
color: Color::TRANSPARENT,
|
|
|
|
|
},
|
|
|
|
|
shadow: Default::default(),
|
2023-10-02 19:37:23 +02:00
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-06 00:03:26 +02:00
|
|
|
column(vec![
|
|
|
|
|
if edges.contains(ResizeEdge::TOP) {
|
2023-10-02 19:37:23 +02:00
|
|
|
from_name(if self.direction == ResizeDirection::Outwards {
|
|
|
|
|
"go-up-symbolic"
|
|
|
|
|
} else {
|
|
|
|
|
"go-down-symbolic"
|
|
|
|
|
})
|
2024-09-28 13:58:51 +02:00
|
|
|
.size(20)
|
2023-10-02 19:37:23 +02:00
|
|
|
.prefer_svg(true)
|
2023-07-06 00:03:26 +02:00
|
|
|
.apply(container)
|
2024-09-28 13:58:51 +02:00
|
|
|
.padding(8)
|
2023-10-02 19:37:23 +02:00
|
|
|
.style(icon_container_style())
|
2023-07-06 00:03:26 +02:00
|
|
|
.width(Length::Shrink)
|
|
|
|
|
.apply(container)
|
|
|
|
|
.center_x()
|
|
|
|
|
.width(Length::Fill)
|
|
|
|
|
.into()
|
|
|
|
|
} else {
|
|
|
|
|
vertical_space(36).into()
|
|
|
|
|
},
|
|
|
|
|
row(vec![
|
|
|
|
|
if edges.contains(ResizeEdge::LEFT) {
|
2023-10-02 19:37:23 +02:00
|
|
|
from_name(if self.direction == ResizeDirection::Outwards {
|
|
|
|
|
"go-previous-symbolic"
|
|
|
|
|
} else {
|
|
|
|
|
"go-next-symbolic"
|
|
|
|
|
})
|
2024-09-28 13:58:51 +02:00
|
|
|
.size(20)
|
2023-10-02 19:37:23 +02:00
|
|
|
.prefer_svg(true)
|
2023-07-06 00:03:26 +02:00
|
|
|
.apply(container)
|
2024-09-28 13:58:51 +02:00
|
|
|
.padding(8)
|
2023-10-02 19:37:23 +02:00
|
|
|
.style(icon_container_style())
|
2023-07-06 00:03:26 +02:00
|
|
|
.width(Length::Shrink)
|
|
|
|
|
.apply(container)
|
|
|
|
|
.center_y()
|
|
|
|
|
.height(Length::Fill)
|
|
|
|
|
.into()
|
|
|
|
|
} else {
|
|
|
|
|
horizontal_space(36).into()
|
|
|
|
|
},
|
|
|
|
|
row(vec![
|
2024-09-28 13:58:51 +02:00
|
|
|
text::heading(&self.shortcut1).into(),
|
|
|
|
|
text::body(fl!("grow-window")).into(),
|
2023-07-06 00:03:26 +02:00
|
|
|
horizontal_space(40).into(),
|
2024-09-28 13:58:51 +02:00
|
|
|
text::heading(&self.shortcut2).into(),
|
|
|
|
|
text::body(fl!("shrink-window")).into(),
|
2023-07-06 00:03:26 +02:00
|
|
|
])
|
|
|
|
|
.apply(container)
|
|
|
|
|
.center_x()
|
|
|
|
|
.center_y()
|
|
|
|
|
.padding(16)
|
|
|
|
|
.apply(container)
|
2023-10-02 19:37:23 +02:00
|
|
|
.style(icon_container_style())
|
2023-07-06 00:03:26 +02:00
|
|
|
.width(Length::Shrink)
|
|
|
|
|
.height(Length::Shrink)
|
|
|
|
|
.apply(container)
|
|
|
|
|
.height(Length::Fill)
|
|
|
|
|
.width(Length::Fill)
|
|
|
|
|
.center_x()
|
|
|
|
|
.center_y()
|
|
|
|
|
.into(),
|
|
|
|
|
if edges.contains(ResizeEdge::RIGHT) {
|
2023-10-02 19:37:23 +02:00
|
|
|
from_name(if self.direction == ResizeDirection::Outwards {
|
|
|
|
|
"go-next-symbolic"
|
|
|
|
|
} else {
|
|
|
|
|
"go-previous-symbolic"
|
|
|
|
|
})
|
2024-09-28 13:58:51 +02:00
|
|
|
.size(20)
|
2023-10-02 19:37:23 +02:00
|
|
|
.prefer_svg(true)
|
2023-07-06 00:03:26 +02:00
|
|
|
.apply(container)
|
2024-09-28 13:58:51 +02:00
|
|
|
.padding(8)
|
2023-10-02 19:37:23 +02:00
|
|
|
.style(icon_container_style())
|
2023-07-06 00:03:26 +02:00
|
|
|
.height(Length::Shrink)
|
|
|
|
|
.apply(container)
|
|
|
|
|
.center_y()
|
|
|
|
|
.height(Length::Fill)
|
|
|
|
|
.into()
|
|
|
|
|
} else {
|
|
|
|
|
horizontal_space(36).into()
|
|
|
|
|
},
|
|
|
|
|
])
|
|
|
|
|
.width(Length::Fill)
|
|
|
|
|
.height(Length::Fill)
|
|
|
|
|
.into(),
|
|
|
|
|
if edges.contains(ResizeEdge::BOTTOM) {
|
2023-10-02 19:37:23 +02:00
|
|
|
from_name(if self.direction == ResizeDirection::Outwards {
|
|
|
|
|
"go-down-symbolic"
|
|
|
|
|
} else {
|
|
|
|
|
"go-up-symbolic"
|
|
|
|
|
})
|
2024-09-28 13:58:51 +02:00
|
|
|
.size(20)
|
2023-10-02 19:37:23 +02:00
|
|
|
.prefer_svg(true)
|
2023-07-06 00:03:26 +02:00
|
|
|
.apply(container)
|
2024-09-28 13:58:51 +02:00
|
|
|
.padding(8)
|
2023-10-02 19:37:23 +02:00
|
|
|
.style(icon_container_style())
|
2023-07-06 00:03:26 +02:00
|
|
|
.width(Length::Shrink)
|
|
|
|
|
.apply(container)
|
|
|
|
|
.center_x()
|
|
|
|
|
.width(Length::Fill)
|
|
|
|
|
.into()
|
|
|
|
|
} else {
|
|
|
|
|
vertical_space(36).into()
|
|
|
|
|
},
|
|
|
|
|
])
|
|
|
|
|
.into()
|
|
|
|
|
}
|
|
|
|
|
}
|