Skip to content

Commit 36a3906

Browse files
committed
feat: support to move wlr_layer_shell
1 parent 9910590 commit 36a3906

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

src/platform/wayland.rs

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//! * `wayland-csd-adwaita` (default).
1414
//! * `wayland-csd-adwaita-crossfont`.
1515
//! * `wayland-csd-adwaita-notitle`.
16+
#[cfg(wayland_platform)]
1617
use sctk::shell::wlr_layer::{Anchor, KeyboardInteractivity, Layer};
1718

1819
use crate::dpi::{LogicalPosition, LogicalSize};
@@ -91,14 +92,19 @@ pub trait WindowAttributesExtWayland {
9192
/// [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id)
9293
fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self;
9394

95+
#[cfg(wayland_platform)]
9496
fn with_anchor(self, anchor: Anchor) -> Self;
9597

98+
#[cfg(wayland_platform)]
9699
fn with_exclusive_zone(self, exclusive_zone: i32) -> Self;
97100

101+
#[cfg(wayland_platform)]
98102
fn with_margin(self, top: i32, right: i32, bottom: i32, left: i32) -> Self;
99103

104+
#[cfg(wayland_platform)]
100105
fn with_keyboard_interactivity(self, keyboard_interactivity: KeyboardInteractivity) -> Self;
101106

107+
#[cfg(wayland_platform)]
102108
fn with_layer(self, layer: Layer) -> Self;
103109

104110
#[cfg(wayland_platform)]
@@ -117,24 +123,28 @@ impl WindowAttributesExtWayland for WindowAttributes {
117123
}
118124

119125
#[inline]
126+
#[cfg(wayland_platform)]
120127
fn with_anchor(mut self, anchor: Anchor) -> Self {
121128
self.platform_specific.wayland.anchor = Some(anchor);
122129
self
123130
}
124131

125132
#[inline]
133+
#[cfg(wayland_platform)]
126134
fn with_exclusive_zone(mut self, exclusive_zone: i32) -> Self {
127135
self.platform_specific.wayland.exclusive_zone = Some(exclusive_zone);
128136
self
129137
}
130138

131139
#[inline]
140+
#[cfg(wayland_platform)]
132141
fn with_margin(mut self, top: i32, right: i32, bottom: i32, left: i32) -> Self {
133142
self.platform_specific.wayland.margin = Some((top, right, bottom, left));
134143
self
135144
}
136145

137146
#[inline]
147+
#[cfg(wayland_platform)]
138148
fn with_keyboard_interactivity(
139149
mut self,
140150
keyboard_interactivity: KeyboardInteractivity,
@@ -144,6 +154,7 @@ impl WindowAttributesExtWayland for WindowAttributes {
144154
}
145155

146156
#[inline]
157+
#[cfg(wayland_platform)]
147158
fn with_layer(mut self, layer: Layer) -> Self {
148159
self.platform_specific.wayland.layer = Some(layer);
149160
self

src/platform_impl/linux/wayland/window/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,13 @@ impl CoreWindow for Window {
401401
}
402402

403403
fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
404-
Err(NotSupportedError::new("window position information is not available on Wayland")
405-
.into())
404+
// XXX just for LayerShell
405+
self.window_state.lock().unwrap().outer_position()
406406
}
407407

408-
fn set_outer_position(&self, _position: Position) {
409-
// Not possible.
408+
fn set_outer_position(&self, position: Position) {
409+
// XXX just for LayerShell
410+
self.window_state.lock().unwrap().set_outer_position(position);
410411
}
411412

412413
fn surface_size(&self) -> PhysicalSize<u32> {

src/platform_impl/linux/wayland/window/state.rs

+26-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::{Arc, Mutex, Weak};
55
use std::time::Duration;
66

77
use ahash::HashSet;
8+
use dpi::{PhysicalPosition, Position};
89
use sctk::compositor::{CompositorState, Region, SurfaceData, SurfaceDataExt};
910
use sctk::reexports::client::backend::ObjectId;
1011
use sctk::reexports::client::protocol::wl_seat::WlSeat;
@@ -76,7 +77,7 @@ pub struct WindowState {
7677
/// Queue handle.
7778
pub queue_handle: QueueHandle<WinitState>,
7879

79-
/// State that differes based on being an XDG shell or a WLR layer shell
80+
/// State that differs based on being an XDG shell or a WLR layer shell
8081
shell_specific: ShellSpecificState,
8182

8283
/// Theme variant.
@@ -85,9 +86,6 @@ pub struct WindowState {
8586
/// The current window title.
8687
title: String,
8788

88-
/// Whether the frame is resizable.
89-
resizable: bool,
90-
9189
// NOTE: we can't use simple counter, since it's racy when seat getting destroyed and new
9290
// is created, since add/removed stuff could be delivered a bit out of order.
9391
/// Seats that has keyboard focus on that window.
@@ -226,7 +224,6 @@ impl WindowState {
226224
pointer_constraints,
227225
pointers: Default::default(),
228226
queue_handle: queue_handle.clone(),
229-
resizable: true,
230227
scale_factor: 1.,
231228
shm: winit_state.shm.wl_shm().clone(),
232229
custom_cursor_pool: winit_state.custom_cursor_pool.clone(),
@@ -269,11 +266,10 @@ impl WindowState {
269266
},
270267
size: initial_size.to_logical(1.0),
271268
selected_cursor: Default::default(),
272-
decorate: true,
269+
decorate: false,
273270
frame_callback_state: FrameCallbackState::None,
274271
seat_focus: Default::default(),
275272
has_pending_move: None,
276-
resizable: true,
277273
custom_cursor_pool: winit_state.custom_cursor_pool.clone(),
278274
initial_size: Some(initial_size),
279275
text_inputs: Vec::new(),
@@ -733,6 +729,27 @@ impl WindowState {
733729
}
734730
}
735731

732+
#[inline]
733+
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
734+
Err(NotSupportedError::new("window position information is not available on xdg Wayland")
735+
.into())
736+
}
737+
738+
pub fn set_outer_position(&self, position: Position) {
739+
let position = position.to_logical(self.scale_factor);
740+
741+
match &self.shell_specific {
742+
ShellSpecificState::Xdg { .. } => {
743+
warn!("Change window position is not available on xdg Wayland",)
744+
},
745+
// XXX just works for LayerShell
746+
// Probably we can save this change to get in the `outer_position` function
747+
ShellSpecificState::WlrLayer { surface, .. } => {
748+
surface.set_margin(position.y, 0, 0, position.x)
749+
},
750+
}
751+
}
752+
736753
/// Get the outer size of the window.
737754
#[inline]
738755
pub fn outer_size(&self) -> LogicalSize<u32> {
@@ -862,7 +879,8 @@ impl WindowState {
862879
outer_size.height as i32,
863880
);
864881

865-
// Update the target viewport, this is used if and only if fractional scaling is in use.
882+
// Update the target viewport, this is used if and only if fractional scaling is in
883+
// use.
866884
if let Some(viewport) = viewport.as_ref() {
867885
// Set inner size without the borders.
868886
viewport.set_destination(self.size.width as _, self.size.height as _);

0 commit comments

Comments
 (0)