mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2026-01-01 17:35:55 +00:00
fix: popup configuration resizing only once
This commit is contained in:
parent
b0fae9867c
commit
0f5bd88742
3 changed files with 56 additions and 37 deletions
|
|
@ -2,6 +2,7 @@ use super::renderable_window::{RenderState, RenderableWindow};
|
||||||
use crate::errors::{RenderingError, Result};
|
use crate::errors::{RenderingError, Result};
|
||||||
use crate::wayland::surfaces::popup_manager::OnCloseCallback;
|
use crate::wayland::surfaces::popup_manager::OnCloseCallback;
|
||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
|
use layer_shika_domain::dimensions::LogicalSize;
|
||||||
use layer_shika_domain::value_objects::handle::PopupHandle;
|
use layer_shika_domain::value_objects::handle::PopupHandle;
|
||||||
use log::info;
|
use log::info;
|
||||||
use slint::{
|
use slint::{
|
||||||
|
|
@ -37,6 +38,7 @@ pub struct PopupWindow {
|
||||||
on_close: OnceCell<OnCloseCallback>,
|
on_close: OnceCell<OnCloseCallback>,
|
||||||
popup_render_state: Cell<PopupRenderState>,
|
popup_render_state: Cell<PopupRenderState>,
|
||||||
component_instance: RefCell<Option<ComponentInstance>>,
|
component_instance: RefCell<Option<ComponentInstance>>,
|
||||||
|
logical_size: Cell<LogicalSize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PopupWindow {
|
impl PopupWindow {
|
||||||
|
|
@ -54,6 +56,7 @@ impl PopupWindow {
|
||||||
on_close: OnceCell::new(),
|
on_close: OnceCell::new(),
|
||||||
popup_render_state: Cell::new(PopupRenderState::Unconfigured),
|
popup_render_state: Cell::new(PopupRenderState::Unconfigured),
|
||||||
component_instance: RefCell::new(None),
|
component_instance: RefCell::new(None),
|
||||||
|
logical_size: Cell::new(LogicalSize::default()),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -141,10 +144,21 @@ impl PopupWindow {
|
||||||
.dispatch_event(WindowEvent::WindowActiveChanged(true));
|
.dispatch_event(WindowEvent::WindowActiveChanged(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_resize(&self, width: f32, height: f32) {
|
pub fn request_resize(&self, width: f32, height: f32) -> bool {
|
||||||
info!("Requesting popup resize to {}x{}", width, height);
|
let new_size = LogicalSize::from_raw(width, height);
|
||||||
|
let current_size = self.logical_size.get();
|
||||||
|
|
||||||
|
if current_size == new_size {
|
||||||
|
info!("Popup resize skipped - size unchanged: {}x{}", width, height);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("Requesting popup resize from {}x{} to {}x{}",
|
||||||
|
current_size.width(), current_size.height(), width, height);
|
||||||
|
self.logical_size.set(new_size);
|
||||||
self.set_size(WindowSize::Logical(slint::LogicalSize::new(width, height)));
|
self.set_size(WindowSize::Logical(slint::LogicalSize::new(width, height)));
|
||||||
RenderableWindow::request_redraw(self);
|
RenderableWindow::request_redraw(self);
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn begin_repositioning(&self) {
|
pub fn begin_repositioning(&self) {
|
||||||
|
|
|
||||||
|
|
@ -903,24 +903,26 @@ impl EventDispatchContext<'_> {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let Some(popup_surface) = popup_manager.get_popup_window(handle.key()) {
|
if let Some(popup_surface) = popup_manager.get_popup_window(handle.key()) {
|
||||||
popup_surface.request_resize(width, height);
|
let size_changed = popup_surface.request_resize(width, height);
|
||||||
|
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
if size_changed {
|
||||||
#[allow(clippy::cast_possible_wrap)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
let logical_width = width as i32;
|
#[allow(clippy::cast_possible_wrap)]
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
let logical_width = width as i32;
|
||||||
#[allow(clippy::cast_possible_wrap)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
let logical_height = height as i32;
|
#[allow(clippy::cast_possible_wrap)]
|
||||||
|
let logical_height = height as i32;
|
||||||
|
|
||||||
popup_manager.update_popup_viewport(handle.key(), logical_width, logical_height);
|
popup_manager.update_popup_viewport(handle.key(), logical_width, logical_height);
|
||||||
popup_manager.commit_popup_surface(handle.key());
|
popup_manager.commit_popup_surface(handle.key());
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"Updated popup viewport to logical size: {}x{} (from resize to {}x{})",
|
"Updated popup viewport to logical size: {}x{} (from resize to {}x{})",
|
||||||
logical_width,
|
logical_width,
|
||||||
logical_height,
|
logical_height,
|
||||||
width,
|
width,
|
||||||
height
|
height
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -1022,27 +1024,29 @@ impl EventDispatchContext<'_> {
|
||||||
|
|
||||||
if let Some(popup_manager) = popup_manager_weak.upgrade() {
|
if let Some(popup_manager) = popup_manager_weak.upgrade() {
|
||||||
if let Some(popup_surface) = popup_manager.get_popup_window(popup_key) {
|
if let Some(popup_surface) = popup_manager.get_popup_window(popup_key) {
|
||||||
popup_surface.request_resize(dimensions.width, dimensions.height);
|
let size_changed = popup_surface.request_resize(dimensions.width, dimensions.height);
|
||||||
|
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
if size_changed {
|
||||||
#[allow(clippy::cast_possible_wrap)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
let logical_width = dimensions.width as i32;
|
#[allow(clippy::cast_possible_wrap)]
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
let logical_width = dimensions.width as i32;
|
||||||
#[allow(clippy::cast_possible_wrap)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
let logical_height = dimensions.height as i32;
|
#[allow(clippy::cast_possible_wrap)]
|
||||||
|
let logical_height = dimensions.height as i32;
|
||||||
|
|
||||||
popup_manager.update_popup_viewport(
|
popup_manager.update_popup_viewport(
|
||||||
popup_key,
|
popup_key,
|
||||||
logical_width,
|
logical_width,
|
||||||
logical_height,
|
logical_height,
|
||||||
);
|
);
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"Updated popup viewport to logical size: {}x{} (from direct resize to {}x{})",
|
"Updated popup viewport to logical size: {}x{} (from direct resize to {}x{})",
|
||||||
logical_width,
|
logical_width,
|
||||||
logical_height,
|
logical_height,
|
||||||
dimensions.width,
|
dimensions.width,
|
||||||
dimensions.height
|
dimensions.height
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::Void
|
Value::Void
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ export component ExamplePopup inherits Window {
|
||||||
interval: 1ms;
|
interval: 1ms;
|
||||||
running: true;
|
running: true;
|
||||||
triggered => {
|
triggered => {
|
||||||
|
resize_timer.running = false;
|
||||||
root.resize_popup(root.preferred-width, root.preferred-height);
|
root.resize_popup(root.preferred-width, root.preferred-height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue