Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f38d79e29 |
@@ -8,19 +8,21 @@ use crate::{
|
|||||||
wayland::{Message, core::surface::Surface},
|
wayland::{Message, core::surface::Surface},
|
||||||
};
|
};
|
||||||
use mint::Vector2;
|
use mint::Vector2;
|
||||||
use std::sync::Arc;
|
use parking_lot::Mutex;
|
||||||
use std::sync::Weak;
|
use std::{collections::HashMap, sync::{Arc, Weak}};
|
||||||
use tracing;
|
use tracing;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct XdgBackend {
|
pub struct XdgBackend {
|
||||||
toplevel: Weak<Toplevel>,
|
toplevel: Weak<Toplevel>,
|
||||||
|
children: Mutex<HashMap<u64, Weak<Surface>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XdgBackend {
|
impl XdgBackend {
|
||||||
pub fn new(toplevel: Arc<Toplevel>) -> Self {
|
pub fn new(toplevel: Arc<Toplevel>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
toplevel: Arc::downgrade(&toplevel),
|
toplevel: Arc::downgrade(&toplevel),
|
||||||
|
children: Mutex::new(HashMap::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,9 +37,17 @@ impl XdgBackend {
|
|||||||
fn surface_from_id(&self, id: SurfaceId) -> Option<Arc<Surface>> {
|
fn surface_from_id(&self, id: SurfaceId) -> Option<Arc<Surface>> {
|
||||||
match id {
|
match id {
|
||||||
SurfaceId::Toplevel(_) => Some(self.toplevel().surface()),
|
SurfaceId::Toplevel(_) => Some(self.toplevel().surface()),
|
||||||
SurfaceId::Child(_) => None,
|
SurfaceId::Child(uid) => self.children.lock().get(&uid).and_then(Weak::upgrade),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn register_child(&self, id: u64, surface: &Arc<Surface>) {
|
||||||
|
self.children.lock().insert(id, Arc::downgrade(surface));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unregister_child(&self, id: u64) {
|
||||||
|
self.children.lock().remove(&id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend for XdgBackend {
|
impl Backend for XdgBackend {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use super::{
|
|||||||
surface::Surface,
|
surface::Surface,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
nodes::items::panel::{Geometry, PanelItem, SurfaceId},
|
nodes::items::panel::{ChildInfo, Geometry, PanelItem, SurfaceId},
|
||||||
wayland::util::DoubleBuffer,
|
wayland::util::DoubleBuffer,
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@@ -27,7 +27,7 @@ pub struct Popup {
|
|||||||
surface: Weak<Surface>,
|
surface: Weak<Surface>,
|
||||||
pub panel_item: Weak<PanelItem<XdgBackend>>,
|
pub panel_item: Weak<PanelItem<XdgBackend>>,
|
||||||
positioner_data: Mutex<PositionerData>,
|
positioner_data: Mutex<PositionerData>,
|
||||||
geometry: DoubleBuffer<Geometry>,
|
geometry: Mutex<DoubleBuffer<Geometry>>,
|
||||||
mapped: AtomicBool,
|
mapped: AtomicBool,
|
||||||
}
|
}
|
||||||
impl Popup {
|
impl Popup {
|
||||||
@@ -48,11 +48,82 @@ impl Popup {
|
|||||||
surface: Arc::downgrade(xdg_surface),
|
surface: Arc::downgrade(xdg_surface),
|
||||||
panel_item: Arc::downgrade(panel_item),
|
panel_item: Arc::downgrade(panel_item),
|
||||||
positioner_data: Mutex::new(positioner_data),
|
positioner_data: Mutex::new(positioner_data),
|
||||||
geometry: DoubleBuffer::new(positioner_data.infinite_geometry()),
|
geometry: Mutex::new(DoubleBuffer::new(positioner_data.infinite_geometry())),
|
||||||
mapped: AtomicBool::new(false),
|
mapped: AtomicBool::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Popup {
|
||||||
|
fn id(&self) -> u64 {
|
||||||
|
match self.surface_id {
|
||||||
|
SurfaceId::Child(id) => id,
|
||||||
|
SurfaceId::Toplevel(_) => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn surface_id(&self) -> SurfaceId { self.surface_id.clone() }
|
||||||
|
|
||||||
|
pub fn current_geometry(&self) -> Geometry {
|
||||||
|
*self.geometry.lock().current()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_mapped(&self) -> bool {
|
||||||
|
self.mapped.load(std::sync::atomic::Ordering::SeqCst)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn map(&self) {
|
||||||
|
if self.is_mapped() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some(panel_item) = self.panel_item.upgrade() else { return; };
|
||||||
|
let xdg_surface = match self.surface.upgrade() { Some(s) => s, None => return };
|
||||||
|
let core_surface = xdg_surface.wl_surface();
|
||||||
|
|
||||||
|
// Determine parent surface id
|
||||||
|
let parent_wl_surface = self.parent.wl_surface();
|
||||||
|
let parent_role = parent_wl_surface.role.lock();
|
||||||
|
let parent_id = match parent_role.as_ref().unwrap() {
|
||||||
|
crate::wayland::core::surface::SurfaceRole::XdgToplevel(_) => {
|
||||||
|
SurfaceId::Toplevel(())
|
||||||
|
}
|
||||||
|
crate::wayland::core::surface::SurfaceRole::XDGPopup(p) => p.surface_id(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let geometry = *self.geometry.lock().current();
|
||||||
|
let info = ChildInfo {
|
||||||
|
id: self.id(),
|
||||||
|
parent: parent_id,
|
||||||
|
geometry,
|
||||||
|
z_order: 0,
|
||||||
|
receives_input: true,
|
||||||
|
};
|
||||||
|
panel_item.create_child(self.id(), &info);
|
||||||
|
panel_item.backend.register_child(self.id(), &core_surface);
|
||||||
|
self.mapped.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unmap(&self) {
|
||||||
|
if !self.mapped.swap(false, std::sync::atomic::Ordering::SeqCst) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(panel_item) = self.panel_item.upgrade() {
|
||||||
|
panel_item.destroy_child(self.id());
|
||||||
|
panel_item.backend.unregister_child(self.id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reposition_child(&self) {
|
||||||
|
if self.is_mapped() {
|
||||||
|
if let Some(panel_item) = self.panel_item.upgrade() {
|
||||||
|
let geometry = *self.geometry.lock().current();
|
||||||
|
panel_item.reposition_child(self.id(), &geometry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
impl XdgPopup for Popup {
|
impl XdgPopup for Popup {
|
||||||
/// https://wayland.app/protocols/xdg-shell#xdg_popup:request:grab
|
/// https://wayland.app/protocols/xdg-shell#xdg_popup:request:grab
|
||||||
async fn grab(
|
async fn grab(
|
||||||
@@ -80,6 +151,11 @@ impl XdgPopup for Popup {
|
|||||||
self.repositioned(client, sender_id, token).await?;
|
self.repositioned(client, sender_id, token).await?;
|
||||||
}
|
}
|
||||||
let geometry = positioner_data.infinite_geometry();
|
let geometry = positioner_data.infinite_geometry();
|
||||||
|
{
|
||||||
|
let mut geo = self.geometry.lock();
|
||||||
|
geo.pending = geometry;
|
||||||
|
geo.apply();
|
||||||
|
}
|
||||||
self.configure(
|
self.configure(
|
||||||
client,
|
client,
|
||||||
sender_id,
|
sender_id,
|
||||||
@@ -90,11 +166,13 @@ impl XdgPopup for Popup {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
self.surface.upgrade().unwrap().reconfigure(client).await?;
|
self.surface.upgrade().unwrap().reconfigure(client).await?;
|
||||||
|
self.reposition_child();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://wayland.app/protocols/xdg-shell#xdg_popup:request:destroy
|
/// https://wayland.app/protocols/xdg-shell#xdg_popup:request:destroy
|
||||||
async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
|
async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
|
||||||
|
self.unmap();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use super::{popup::Popup, positioner::Positioner, toplevel::Mapped};
|
use super::{popup::Popup, positioner::Positioner, toplevel::Mapped};
|
||||||
use crate::wayland::{core::surface::SurfaceRole, display::Display, xdg::toplevel::Toplevel};
|
use crate::wayland::{core::surface::SurfaceRole, display::Display, xdg::toplevel::Toplevel};
|
||||||
|
use waynest::server::protocol::stable::xdg_shell::xdg_popup::XdgPopup;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Weak;
|
use std::sync::Weak;
|
||||||
pub use waynest::server::protocol::stable::xdg_shell::xdg_surface::*;
|
pub use waynest::server::protocol::stable::xdg_shell::xdg_surface::*;
|
||||||
@@ -130,6 +131,7 @@ impl XdgSurface for Surface {
|
|||||||
let positioner = client.get::<Positioner>(positioner).unwrap();
|
let positioner = client.get::<Positioner>(positioner).unwrap();
|
||||||
|
|
||||||
let surface = client.get::<Surface>(self.id).unwrap();
|
let surface = client.get::<Surface>(self.id).unwrap();
|
||||||
|
let wl_surface = surface.wl_surface();
|
||||||
|
|
||||||
let popup = client.insert(
|
let popup = client.insert(
|
||||||
popup_id,
|
popup_id,
|
||||||
@@ -143,6 +145,19 @@ impl XdgSurface for Surface {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Initial popup configure
|
||||||
|
let geometry = popup.current_geometry();
|
||||||
|
popup
|
||||||
|
.configure(
|
||||||
|
client,
|
||||||
|
popup_id,
|
||||||
|
geometry.origin.x,
|
||||||
|
geometry.origin.y,
|
||||||
|
geometry.size.x as i32,
|
||||||
|
geometry.size.y as i32,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
{
|
{
|
||||||
let wl_surface = self.wl_surface();
|
let wl_surface = self.wl_surface();
|
||||||
let mut surface_role = wl_surface.role.lock();
|
let mut surface_role = wl_surface.role.lock();
|
||||||
@@ -158,6 +173,25 @@ impl XdgSurface for Surface {
|
|||||||
let serial = client.next_event_serial();
|
let serial = client.next_event_serial();
|
||||||
self.configure(client, sender_id, serial).await?;
|
self.configure(client, sender_id, serial).await?;
|
||||||
|
|
||||||
|
let configured = self.configured.clone();
|
||||||
|
wl_surface.add_commit_handler(move |surface, state| {
|
||||||
|
let Some(SurfaceRole::XDGPopup(popup)) = &*surface.role.lock() else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
let has_valid_buffer = state
|
||||||
|
.buffer
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|b| b.buffer.size().x > 0 && b.buffer.size().y > 0);
|
||||||
|
if !popup.is_mapped()
|
||||||
|
&& configured.load(std::sync::atomic::Ordering::SeqCst)
|
||||||
|
&& has_valid_buffer
|
||||||
|
{
|
||||||
|
popup.map();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
true
|
||||||
|
});
|
||||||
|
|
||||||
// let pid = client.get::<Display>(ObjectId::DISPLAY).unwrap().pid;
|
// let pid = client.get::<Display>(ObjectId::DISPLAY).unwrap().pid;
|
||||||
// let configured = self.configured.clone();
|
// let configured = self.configured.clone();
|
||||||
// surface.add_commit_handler(move |surface, state| {
|
// surface.add_commit_handler(move |surface, state| {
|
||||||
|
|||||||
Reference in New Issue
Block a user