Skip to content

Commit f054541

Browse files
committed
feat(wayland): xdg decoration
1 parent e8f98f1 commit f054541

File tree

4 files changed

+105
-6
lines changed

4 files changed

+105
-6
lines changed

src/wayland/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ pub enum WaylandError {
8585
}
8686
impl<T: Clone> From<StoreError<T>> for WaylandError {
8787
fn from(_value: StoreError<T>) -> Self {
88-
panic!("a");
8988
Self::FailedToInsertObject
9089
}
9190
}

src/wayland/registry.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use crate::wayland::relative_pointer::RelativePointerManager;
2-
use crate::wayland::{Client, WaylandResult};
31
use crate::wayland::{
4-
WaylandError,
2+
Client, WaylandError, WaylandResult,
53
core::{
64
compositor::{Compositor, WlCompositor},
75
data_device::DataDeviceManager,
@@ -13,9 +11,13 @@ use crate::wayland::{
1311
dmabuf::Dmabuf,
1412
mesa_drm::MesaDrm,
1513
presentation::Presentation,
14+
relative_pointer::RelativePointerManager,
1615
util::ClientExt,
1716
viewporter::Viewporter,
18-
xdg::wm_base::{WmBase, XdgWmBase},
17+
xdg::{
18+
decoration::XdgDecorationManager,
19+
wm_base::{WmBase, XdgWmBase},
20+
},
1921
};
2022
use waynest::{NewId, ObjectId};
2123
use waynest_protocols::server::{
@@ -29,7 +31,10 @@ use waynest_protocols::server::{
2931
presentation_time::wp_presentation::WpPresentation,
3032
viewporter::wp_viewporter::WpViewporter,
3133
},
32-
unstable::relative_pointer_unstable_v1::zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1,
34+
unstable::{
35+
relative_pointer_unstable_v1::zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1,
36+
xdg_decoration_unstable_v1::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1,
37+
},
3338
};
3439
use waynest_server::Client as _;
3540

@@ -47,6 +52,7 @@ impl RegistryGlobals {
4752
pub const VIEWPORTER: u32 = 9;
4853
pub const RELATIVE_POINTER: u32 = 10;
4954
pub const SUBCOMPOSITOR: u32 = 11;
55+
pub const XDG_DECORATION: u32 = 12;
5056
}
5157

5258
#[derive(Debug, waynest_server::RequestDispatcher, Default)]
@@ -167,6 +173,15 @@ impl Registry {
167173
)
168174
.await?;
169175

176+
self.global(
177+
client,
178+
sender_id,
179+
RegistryGlobals::XDG_DECORATION,
180+
XdgDecorationManager::INTERFACE.to_string(),
181+
XdgDecorationManager::VERSION,
182+
)
183+
.await?;
184+
170185
Ok(())
171186
}
172187
}
@@ -261,6 +276,17 @@ impl WlRegistry for Registry {
261276

262277
client.insert(new_id.object_id, Subcompositor)?;
263278
}
279+
RegistryGlobals::XDG_DECORATION => {
280+
tracing::info!("Binding xdg_decoration_manager");
281+
282+
client.insert(
283+
new_id.object_id,
284+
XdgDecorationManager {
285+
_version: new_id.version,
286+
id: new_id.object_id,
287+
},
288+
)?;
289+
}
264290
id => {
265291
tracing::error!(id, "Wayland: failed to bind to registry global");
266292
return Err(WaylandError::UnknownGlobal(name));

src/wayland/xdg/decoration.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use crate::wayland::{Client, WaylandResult};
2+
use waynest::ObjectId;
3+
use waynest_protocols::server::unstable::xdg_decoration_unstable_v1::{
4+
zxdg_decoration_manager_v1::*, zxdg_toplevel_decoration_v1::*,
5+
};
6+
use waynest_server::Client as _;
7+
8+
#[derive(Debug, waynest_server::RequestDispatcher)]
9+
#[waynest(error = crate::wayland::WaylandError, connection = crate::wayland::Client)]
10+
pub struct XdgDecorationManager {
11+
pub _version: u32,
12+
pub id: ObjectId,
13+
}
14+
impl ZxdgDecorationManagerV1 for XdgDecorationManager {
15+
type Connection = Client;
16+
17+
async fn destroy(
18+
&self,
19+
client: &mut Self::Connection,
20+
_sender_id: ObjectId,
21+
) -> WaylandResult<()> {
22+
client.remove(self.id);
23+
Ok(())
24+
}
25+
26+
async fn get_toplevel_decoration(
27+
&self,
28+
client: &mut Self::Connection,
29+
_sender_id: ObjectId,
30+
id: ObjectId,
31+
_toplevel: ObjectId,
32+
) -> WaylandResult<()> {
33+
client.insert(id, XdgDecoration { id })?;
34+
Ok(())
35+
}
36+
}
37+
38+
#[derive(Debug, waynest_server::RequestDispatcher)]
39+
#[waynest(error = crate::wayland::WaylandError, connection = crate::wayland::Client)]
40+
pub struct XdgDecoration {
41+
id: ObjectId,
42+
}
43+
impl ZxdgToplevelDecorationV1 for XdgDecoration {
44+
type Connection = Client;
45+
46+
async fn destroy(
47+
&self,
48+
client: &mut Self::Connection,
49+
sender_id: ObjectId,
50+
) -> WaylandResult<()> {
51+
client.remove(sender_id);
52+
Ok(())
53+
}
54+
55+
async fn set_mode(
56+
&self,
57+
client: &mut Self::Connection,
58+
_sender_id: ObjectId,
59+
_mode: Mode,
60+
) -> WaylandResult<()> {
61+
// TODO: proper robust implementation where configure must be sent before first buffer attach
62+
self.configure(client, self.id, Mode::ServerSide).await
63+
}
64+
65+
async fn unset_mode(
66+
&self,
67+
client: &mut Self::Connection,
68+
_sender_id: ObjectId,
69+
) -> WaylandResult<()> {
70+
// TODO: proper robust implementation where configure must be sent before first buffer attach
71+
self.configure(client, self.id, Mode::ServerSide).await
72+
}
73+
}

src/wayland/xdg/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod backend;
2+
pub mod decoration;
23
pub mod popup;
34
pub mod positioner;
45
pub mod surface;

0 commit comments

Comments
 (0)