-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for wlr_layer_shell windows #2832
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ use sctk::output::{OutputHandler, OutputState}; | |
use sctk::registry::{ProvidesRegistryState, RegistryState}; | ||
use sctk::seat::pointer::ThemedPointer; | ||
use sctk::seat::SeatState; | ||
use sctk::shell::wlr_layer::{LayerShell, LayerShellHandler, LayerSurface, LayerSurfaceConfigure}; | ||
use sctk::shell::xdg::window::{Window, WindowConfigure, WindowHandler}; | ||
use sctk::shell::xdg::XdgShell; | ||
use sctk::shell::WaylandSurface; | ||
|
@@ -59,6 +60,9 @@ pub struct WinitState { | |
/// The XDG shell that is used for widnows. | ||
pub xdg_shell: XdgShell, | ||
|
||
/// The layer shell for layer surfaces | ||
pub layer_shell: LayerShell, | ||
|
||
/// The currently present windows. | ||
pub windows: RefCell<FnvHashMap<WindowId, Arc<Mutex<WindowState>>>>, | ||
|
||
|
@@ -148,6 +152,8 @@ impl WinitState { | |
xdg_shell: XdgShell::bind(globals, queue_handle)?, | ||
xdg_activation: XdgActivationState::bind(globals, queue_handle).ok(), | ||
|
||
layer_shell: LayerShell::bind(globals, queue_handle)?, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this make winit fail on compositors without layer-shell support? Like Gnome. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way it's written -> yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So definitely something that would need to be fixed here. An application using this will want some way to recognize when X is being used instead of Wayland, and when Wayland is in use but the layer-shell protocol isn't available. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, but I mean, the entire approach present here I don't like, because it complicates internal code without a reason for that. I'd also like to have a way to bind stuff lazily. |
||
|
||
windows: Default::default(), | ||
window_requests: Default::default(), | ||
window_compositor_updates: Vec::new(), | ||
|
@@ -273,7 +279,51 @@ impl WindowHandler for WinitState { | |
.expect("got configure for dead window.") | ||
.lock() | ||
.unwrap() | ||
.configure(configure, &self.shm, &self.subcompositor_state); | ||
.configure_xdg(configure, &self.shm, &self.subcompositor_state); | ||
|
||
self.window_compositor_updates[pos].size = Some(new_size); | ||
} | ||
} | ||
|
||
impl LayerShellHandler for WinitState { | ||
fn closed(&mut self, _: &Connection, _: &QueueHandle<Self>, layer: &LayerSurface) { | ||
let window_id = super::make_wid(layer.wl_surface()); | ||
Self::queue_close(&mut self.window_compositor_updates, window_id); | ||
} | ||
|
||
fn configure( | ||
&mut self, | ||
_: &Connection, | ||
_: &QueueHandle<Self>, | ||
layer: &LayerSurface, | ||
configure: LayerSurfaceConfigure, | ||
_serial: u32, | ||
) { | ||
let window_id = super::make_wid(layer.wl_surface()); | ||
|
||
let pos = if let Some(pos) = self | ||
.window_compositor_updates | ||
.iter() | ||
.position(|update| update.window_id == window_id) | ||
{ | ||
pos | ||
} else { | ||
self.window_compositor_updates | ||
.push(WindowCompositorUpdate::new(window_id)); | ||
self.window_compositor_updates.len() - 1 | ||
}; | ||
|
||
// Populate the configure to the window. | ||
// | ||
// XXX the size on the window will be updated right before dispatching the size to the user. | ||
let new_size = self | ||
.windows | ||
.get_mut() | ||
.get_mut(&window_id) | ||
.expect("got configure for dead window.") | ||
.lock() | ||
.unwrap() | ||
.configure_layer(configure); | ||
|
||
self.window_compositor_updates[pos].size = Some(new_size); | ||
} | ||
|
@@ -366,3 +416,4 @@ sctk::delegate_registry!(WinitState); | |
sctk::delegate_shm!(WinitState); | ||
sctk::delegate_xdg_shell!(WinitState); | ||
sctk::delegate_xdg_window!(WinitState); | ||
sctk::delegate_layer!(WinitState); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the types from sctk are used in the API (without or without a re-export) that makes updating sctk a breaking change to winit. But that might not be a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. Currently, the only public dependency in winit (except for cursor_icon, which is under the rust-windowing org) is on the
android-activity
crate, and it's a simple re-export of the entire crate for the android platform.In this case, a re-export seems to have negligible benefit, and is very easily avoidable; so I'll redefine the types.