feat: popup reposition
This commit is contained in:
parent
da9d15b2e8
commit
633ed14411
3 changed files with 79 additions and 13 deletions
|
|
@ -124,26 +124,34 @@ pub enum Action {
|
||||||
/// height
|
/// height
|
||||||
height: u32,
|
height: u32,
|
||||||
},
|
},
|
||||||
|
/// set the size of the popup
|
||||||
|
Reposition {
|
||||||
|
/// id of the popup
|
||||||
|
id: Id,
|
||||||
|
/// positioner of the popup
|
||||||
|
positioner: SctkPositioner,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Action {
|
impl fmt::Debug for Action {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Action::Popup { popup, .. } => write!(
|
Action::Popup { popup, .. } => {
|
||||||
f,
|
write!(f, "Action::PopupAction::Popup {{ popup: {:?} }}", popup)
|
||||||
"Action::PopupAction::Popup {{ popup: {:?} }}",
|
}
|
||||||
popup
|
Action::Destroy { id } => {
|
||||||
),
|
write!(f, "Action::PopupAction::Destroy {{ id: {:?} }}", id)
|
||||||
Action::Destroy { id } => write!(
|
}
|
||||||
f,
|
|
||||||
"Action::PopupAction::Destroy {{ id: {:?} }}",
|
|
||||||
id
|
|
||||||
),
|
|
||||||
Action::Size { id, width, height } => write!(
|
Action::Size { id, width, height } => write!(
|
||||||
f,
|
f,
|
||||||
"Action::PopupAction::Size {{ id: {:?}, width: {:?}, height: {:?} }}",
|
"Action::PopupAction::Size {{ id: {:?}, width: {:?}, height: {:?} }}",
|
||||||
id, width, height
|
id, width, height
|
||||||
),
|
),
|
||||||
|
Action::Reposition { id, positioner } => write!(
|
||||||
|
f,
|
||||||
|
"Action::Reposition {{ id: {:?}, positioner: {:?} }}",
|
||||||
|
id, positioner
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
//! Interact with the popups of your application.
|
//! Interact with the popups of your application.
|
||||||
use crate::core::window::Id as SurfaceId;
|
use crate::core::window::Id as SurfaceId;
|
||||||
use iced_runtime::{
|
use iced_runtime::{
|
||||||
self,
|
self, Action, Task,
|
||||||
platform_specific::{
|
platform_specific::{
|
||||||
self,
|
self,
|
||||||
wayland::{self, popup::SctkPopupSettings},
|
wayland::{
|
||||||
|
self,
|
||||||
|
popup::{SctkPopupSettings, SctkPositioner},
|
||||||
},
|
},
|
||||||
task, Action, Task,
|
},
|
||||||
|
task,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <https://wayland.app/protocols/wlr-layer-shell-unstable-v1#zwlr_layer_surface_v1:request:get_popup>
|
/// <https://wayland.app/protocols/wlr-layer-shell-unstable-v1#zwlr_layer_surface_v1:request:get_popup>
|
||||||
|
|
@ -32,6 +35,18 @@ pub fn set_size<Message>(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <https://wayland.app/protocols/xdg-shell#xdg_popup:request:reposition>
|
||||||
|
pub fn reposition<Message>(
|
||||||
|
id: SurfaceId,
|
||||||
|
positioner: SctkPositioner,
|
||||||
|
) -> Task<Message> {
|
||||||
|
task::effect(Action::PlatformSpecific(
|
||||||
|
platform_specific::Action::Wayland(wayland::Action::Popup(
|
||||||
|
wayland::popup::Action::Reposition { id, positioner },
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
/// <https://wayland.app/protocols/xdg-shell#xdg_popup:request:destroy>
|
/// <https://wayland.app/protocols/xdg-shell#xdg_popup:request:destroy>
|
||||||
pub fn destroy_popup<Message>(id: SurfaceId) -> Task<Message> {
|
pub fn destroy_popup<Message>(id: SurfaceId) -> Task<Message> {
|
||||||
task::effect(Action::PlatformSpecific(
|
task::effect(Action::PlatformSpecific(
|
||||||
|
|
|
||||||
|
|
@ -1454,6 +1454,49 @@ impl SctkState {
|
||||||
SctkEvent::PopupEvent { variant: crate::sctk_event::PopupEventVariant::Size(width, height), toplevel_id: sctk_popup.data.parent.wl_surface().clone(), parent_id: sctk_popup.data.parent.wl_surface().clone(), id: surface });
|
SctkEvent::PopupEvent { variant: crate::sctk_event::PopupEventVariant::Size(width, height), toplevel_id: sctk_popup.data.parent.wl_surface().clone(), parent_id: sctk_popup.data.parent.wl_surface().clone(), id: surface });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
platform_specific::wayland::popup::Action::Reposition { id, positioner } => {
|
||||||
|
if let Some(sctk_popup) = self
|
||||||
|
.popups
|
||||||
|
.iter_mut()
|
||||||
|
.find(|s| s.data.id == id)
|
||||||
|
{
|
||||||
|
sctk_popup.data.positioner.set_anchor(positioner.anchor);
|
||||||
|
sctk_popup.data.positioner.set_anchor_rect(
|
||||||
|
positioner.anchor_rect.x,
|
||||||
|
positioner.anchor_rect.y,
|
||||||
|
positioner.anchor_rect.width,
|
||||||
|
positioner.anchor_rect.height,
|
||||||
|
);
|
||||||
|
if let Ok(constraint_adjustment) =
|
||||||
|
positioner.constraint_adjustment.try_into()
|
||||||
|
{
|
||||||
|
sctk_popup.data.positioner.set_constraint_adjustment(constraint_adjustment);
|
||||||
|
}
|
||||||
|
sctk_popup.data.positioner.set_gravity(positioner.gravity);
|
||||||
|
sctk_popup.data.positioner.set_offset(
|
||||||
|
positioner.offset.0,
|
||||||
|
positioner.offset.1,
|
||||||
|
);
|
||||||
|
if positioner.reactive {
|
||||||
|
sctk_popup.data.positioner.set_reactive();
|
||||||
|
}
|
||||||
|
let guard =sctk_popup.common.lock().unwrap();
|
||||||
|
let w = guard.size.width;
|
||||||
|
let h = guard.size.height;
|
||||||
|
drop(guard);
|
||||||
|
let size = positioner.size.unwrap_or((w, h));
|
||||||
|
sctk_popup.popup
|
||||||
|
.xdg_surface()
|
||||||
|
.set_window_geometry(0, 0, w as i32, h as i32);
|
||||||
|
sctk_popup.update_viewport(w, h);
|
||||||
|
// update positioner
|
||||||
|
sctk_popup.data.positioner.set_size(w as i32, h as i32);
|
||||||
|
sctk_popup.popup.reposition(&sctk_popup.data.positioner, TOKEN_CTR.fetch_add(1, std::sync::atomic::Ordering::Relaxed)); let surface = sctk_popup.popup.wl_surface().clone();
|
||||||
|
dbg!("repositioning...");
|
||||||
|
_ = send_event(&self.events_sender, &self.proxy,
|
||||||
|
SctkEvent::PopupEvent { variant: crate::sctk_event::PopupEventVariant::Size(size.0, size.1), toplevel_id: sctk_popup.data.parent.wl_surface().clone(), parent_id: sctk_popup.data.parent.wl_surface().clone(), id: surface });
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action::Activation(activation_event) => match activation_event {
|
Action::Activation(activation_event) => match activation_event {
|
||||||
platform_specific::wayland::activation::Action::RequestToken { app_id, window, channel } => {
|
platform_specific::wayland::activation::Action::RequestToken { app_id, window, channel } => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue