fix(power): remove mouse area from modal
This commit is contained in:
parent
ad656296e7
commit
d01ac41d12
1 changed files with 28 additions and 12 deletions
|
|
@ -14,6 +14,7 @@ use cosmic::{
|
||||||
wayland::{self, LayerEvent},
|
wayland::{self, LayerEvent},
|
||||||
PlatformSpecific,
|
PlatformSpecific,
|
||||||
},
|
},
|
||||||
|
keyboard::{key::Named, Key},
|
||||||
platform_specific::{
|
platform_specific::{
|
||||||
runtime::wayland::layer_surface::SctkLayerSurfaceSettings,
|
runtime::wayland::layer_surface::SctkLayerSurfaceSettings,
|
||||||
shell::commands::{
|
shell::commands::{
|
||||||
|
|
@ -30,7 +31,10 @@ use cosmic::{
|
||||||
iced_runtime::core::layout::Limits,
|
iced_runtime::core::layout::Limits,
|
||||||
iced_widget::mouse_area,
|
iced_widget::mouse_area,
|
||||||
theme,
|
theme,
|
||||||
widget::{button, divider, horizontal_space, icon, text, vertical_space, Column, Space},
|
widget::{
|
||||||
|
autosize::autosize, button, divider, horizontal_space, icon, text, vertical_space, Column,
|
||||||
|
Space,
|
||||||
|
},
|
||||||
Element, Task,
|
Element, Task,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -57,6 +61,7 @@ pub fn run() -> cosmic::iced::Result {
|
||||||
|
|
||||||
const COUNTDOWN_LENGTH: u8 = 60;
|
const COUNTDOWN_LENGTH: u8 = 60;
|
||||||
static CONFIRM_ID: Lazy<iced::id::Id> = Lazy::new(|| iced::id::Id::new("confirm-id"));
|
static CONFIRM_ID: Lazy<iced::id::Id> = Lazy::new(|| iced::id::Id::new("confirm-id"));
|
||||||
|
static AUTOSIZE_DIALOG_ID: Lazy<iced::id::Id> = Lazy::new(|| iced::id::Id::new("autosize-id"));
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Power {
|
struct Power {
|
||||||
|
|
@ -133,12 +138,21 @@ impl cosmic::Application for Power {
|
||||||
fn subscription(&self) -> Subscription<Message> {
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
let mut subscriptions = Vec::with_capacity(2);
|
let mut subscriptions = Vec::with_capacity(2);
|
||||||
subscriptions.push(listen_with(|e, _status, _| match e {
|
subscriptions.push(listen_with(|e, _status, _| match e {
|
||||||
cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland(
|
|
||||||
wayland::Event::Layer(LayerEvent::Unfocused, ..),
|
|
||||||
)) => Some(Message::Cancel),
|
|
||||||
cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland(
|
cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland(
|
||||||
wayland::Event::Layer(LayerEvent::Focused, ..),
|
wayland::Event::Layer(LayerEvent::Focused, ..),
|
||||||
)) => Some(Message::LayerFocus),
|
)) => Some(Message::LayerFocus),
|
||||||
|
cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland(
|
||||||
|
wayland::Event::Layer(LayerEvent::Unfocused, ..),
|
||||||
|
)) => Some(Message::Cancel),
|
||||||
|
cosmic::iced::Event::Keyboard(iced::keyboard::Event::KeyPressed {
|
||||||
|
key,
|
||||||
|
text: _,
|
||||||
|
modifiers,
|
||||||
|
..
|
||||||
|
}) => match key {
|
||||||
|
Key::Named(Named::Escape) => Some(Message::Cancel),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
}));
|
}));
|
||||||
if self.action_to_confirm.is_some() {
|
if self.action_to_confirm.is_some() {
|
||||||
|
|
@ -188,10 +202,10 @@ impl cosmic::Application for Power {
|
||||||
self.action_to_confirm = Some((id, action, COUNTDOWN_LENGTH));
|
self.action_to_confirm = Some((id, action, COUNTDOWN_LENGTH));
|
||||||
get_layer_surface(SctkLayerSurfaceSettings {
|
get_layer_surface(SctkLayerSurfaceSettings {
|
||||||
id,
|
id,
|
||||||
keyboard_interactivity: KeyboardInteractivity::None,
|
keyboard_interactivity: KeyboardInteractivity::Exclusive,
|
||||||
anchor: Anchor::all(),
|
anchor: Anchor::empty(),
|
||||||
namespace: "dialog".into(),
|
namespace: "dialog".into(),
|
||||||
size: Some((None, None)),
|
size: None,
|
||||||
size_limits: Limits::NONE.min_width(1.0).min_height(1.0),
|
size_limits: Limits::NONE.min_width(1.0).min_height(1.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
|
@ -370,12 +384,14 @@ impl cosmic::Application for Power {
|
||||||
button::text(fl!("restart")).on_press(Message::Action(PowerAction::Restart)),
|
button::text(fl!("restart")).on_press(Message::Action(PowerAction::Restart)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Element::from(
|
Element::from(
|
||||||
mouse_area(container(dialog).center(Length::Fill))
|
autosize(Element::from(container(dialog)), AUTOSIZE_DIALOG_ID.clone()).limits(
|
||||||
.on_press(Message::Cancel)
|
Limits::NONE
|
||||||
.on_right_press(Message::Cancel)
|
.min_width(1.)
|
||||||
.on_middle_press(Message::Cancel),
|
.min_height(1.)
|
||||||
|
.max_width(900.)
|
||||||
|
.max_height(900.),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
//panic!("no view for window {}", id.0)
|
//panic!("no view for window {}", id.0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue