-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
## Unreleased | ||
|
||
- Add wl shell protocol implementation | ||
|
||
## 0.19.1 - 2024-06-04 | ||
|
||
#### Additions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use wayland_client::{ | ||
globals::{BindError, GlobalList}, | ||
protocol::{wl_shell, wl_shell_surface, wl_surface::WlSurface}, | ||
Connection, Dispatch, QueueHandle | ||
}; | ||
|
||
use crate::{ | ||
error::GlobalError, globals::{GlobalData, ProvidesBoundGlobal} | ||
}; | ||
|
||
pub mod window; | ||
|
||
use window::Window; | ||
|
||
|
||
#[derive(Debug)] | ||
pub struct WlShell { | ||
wl_shell: wl_shell::WlShell, | ||
} | ||
|
||
impl WlShell { | ||
pub fn bind<State>(globals: &GlobalList, qh: &QueueHandle<State>) -> Result<WlShell, BindError> | ||
where | ||
State: Dispatch<wl_shell::WlShell, GlobalData, State> + 'static, | ||
{ | ||
let wl_shell = globals.bind(qh, 1..=1, GlobalData)?; | ||
|
||
Ok(WlShell { wl_shell}) | ||
} | ||
|
||
pub fn create_window<State>(&self, surface: WlSurface, qh: &QueueHandle<State>) -> Window | ||
where | ||
State: Dispatch<wl_shell_surface::WlShellSurface, GlobalData, State> + 'static | ||
{ | ||
let wl_shell_surface = self.wl_shell.get_shell_surface(&surface, qh, GlobalData); | ||
|
||
Window::new(surface, wl_shell_surface) | ||
} | ||
|
||
pub fn wl_shell(&self) -> &wl_shell::WlShell { | ||
&self.wl_shell | ||
} | ||
} | ||
|
||
|
||
impl ProvidesBoundGlobal<wl_shell::WlShell, 1> for WlShell { | ||
fn bound_global(&self) -> Result<wl_shell::WlShell, GlobalError> { | ||
Ok(self.wl_shell.clone()) | ||
} | ||
} | ||
|
||
impl<D> Dispatch<wl_shell_surface::WlShellSurface, GlobalData, D> for WlShell | ||
where | ||
D: Dispatch<wl_shell_surface::WlShellSurface, GlobalData>{ | ||
fn event( | ||
_state: &mut D, | ||
proxy: &wl_shell_surface::WlShellSurface, | ||
event: wl_shell_surface::Event, | ||
_data: &GlobalData, | ||
_conn: &Connection, | ||
_qhandle: &QueueHandle<D>, | ||
) { | ||
match event { | ||
wl_shell_surface::Event::Ping { serial } => { | ||
proxy.pong(serial); | ||
}, | ||
_ => unreachable!(), | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use std::sync::{Arc, Weak}; | ||
|
||
use crate::{compositor::Surface, shell::WaylandSurface}; | ||
use wayland_client::{protocol::{ | ||
wl_output::WlOutput, | ||
wl_seat::WlSeat, | ||
wl_shell_surface::{Resize, WlShellSurface}, | ||
wl_surface::WlSurface | ||
}, Connection, QueueHandle}; | ||
|
||
pub trait WindowHandler: Sized { | ||
fn configure(&mut self, | ||
conn: &Connection, | ||
qh: &QueueHandle<Self>, | ||
wl_surface: &WlSurface, | ||
configure: (Resize, u32, u32) | ||
); | ||
|
||
fn request_close(&mut self, _: &Connection, _: &QueueHandle<Self>, wl_surface: &WlSurface); | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct WlShellWindowInner { | ||
pub surface: Surface, | ||
pub wl_shell_surface: WlShellSurface | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Window (Arc<WlShellWindowInner>); | ||
|
||
impl Window { | ||
pub fn new(surface: impl Into<Surface>, wl_shell_surface: WlShellSurface) -> Self { | ||
Self(Arc::new_cyclic(|_weak| { | ||
WlShellWindowInner{ | ||
surface: surface.into(), | ||
wl_shell_surface | ||
} | ||
})) | ||
} | ||
|
||
pub fn wl_shell_surface(&self) -> &WlShellSurface { | ||
&self.0.wl_shell_surface | ||
} | ||
|
||
pub fn set_maximized(&self) { | ||
self.0.wl_shell_surface.set_maximized(None) | ||
} | ||
pub fn set_top_level(&self) { | ||
self.0.wl_shell_surface.set_toplevel() | ||
} | ||
|
||
pub fn set_fullscreen(&self, output: Option<&WlOutput>) { | ||
self.0.wl_shell_surface.set_fullscreen(wayland_client::protocol::wl_shell_surface::FullscreenMethod::Fill, 60000, output); | ||
} | ||
|
||
pub fn resize(&self, seat: &WlSeat, serial: u32, edges: Resize) { | ||
self.0.wl_shell_surface.resize(seat, serial, edges) | ||
} | ||
|
||
pub fn move_(&self, seat: &WlSeat, serial: u32) { | ||
self.0.wl_shell_surface._move(seat, serial) | ||
} | ||
|
||
pub fn set_title(&self, title: impl Into<String>) { | ||
self.0.wl_shell_surface.set_title(title.into()) | ||
} | ||
|
||
pub fn set_app_id(&self, app_id: impl Into<String>) { | ||
self.0.wl_shell_surface.set_class(app_id.into()) | ||
} | ||
} | ||
|
||
impl WaylandSurface for Window { | ||
fn wl_surface(&self) -> &WlSurface { | ||
&self.0.surface.wl_surface() | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct WindowData(pub(crate) Weak<WlShellWindowInner>); | ||
Check warning on line 80 in src/shell/wl_shell/window.rs GitHub Actions / test (stable)
Check warning on line 80 in src/shell/wl_shell/window.rs GitHub Actions / test (stable)
Check warning on line 80 in src/shell/wl_shell/window.rs GitHub Actions / test (stable)
Check warning on line 80 in src/shell/wl_shell/window.rs GitHub Actions / ci (stable)
Check warning on line 80 in src/shell/wl_shell/window.rs GitHub Actions / ci (stable)
Check warning on line 80 in src/shell/wl_shell/window.rs GitHub Actions / test (beta)
Check warning on line 80 in src/shell/wl_shell/window.rs GitHub Actions / test (beta)
Check warning on line 80 in src/shell/wl_shell/window.rs GitHub Actions / test (beta)
Check warning on line 80 in src/shell/wl_shell/window.rs GitHub Actions / ci (beta)
|