Skip to content

Commit

Permalink
merge changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
lmaxyz committed Jun 6, 2024
2 parents ac2c420 + fa6f2ec commit ecd9fae
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Add wl shell protocol implementation

## 0.19.1 - 2024-06-04

#### Additions
Expand Down
10 changes: 10 additions & 0 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
//!

Check failure on line 32 in src/shell/mod.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/client-toolkit/client-toolkit/src/shell/mod.rs
//! The layer shell may be used to implement many desktop shell components, such as backgrounds, docks and
//! launchers.
//!
//! ## Wl shell
//!
//! The Wl shell is a deprecated protocol which is like xdg shell but less functional.
//!
//! ### Why use the Wl shell
//!
//! The Wl shell uses like xdg shell for application windows creation.
//! It's deprecated, so it uses only in some legacy projects like Sailfish OS.
//!
//! [^window]: The XDG shell protocol actually refers to a window as a toplevel surface, but we use the more
//! familiar term "window" for the sake of clarity.
Expand All @@ -47,6 +56,7 @@ use wayland_client::{
Proxy,
};

pub mod wl_shell;
pub mod wlr_layer;
pub mod xdg;

Expand Down
70 changes: 70 additions & 0 deletions src/shell/wl_shell/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use wayland_client::{

Check failure on line 1 in src/shell/wl_shell/mod.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/client-toolkit/client-toolkit/src/shell/wl_shell/mod.rs
globals::{BindError, GlobalList},
protocol::{wl_shell, wl_shell_surface, wl_surface::WlSurface},
Connection, Dispatch, QueueHandle
};

use crate::{
error::GlobalError, globals::{GlobalData, ProvidesBoundGlobal}

Check failure on line 8 in src/shell/wl_shell/mod.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/client-toolkit/client-toolkit/src/shell/wl_shell/mod.rs
};

pub mod window;

Check failure on line 12 in src/shell/wl_shell/mod.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/client-toolkit/client-toolkit/src/shell/wl_shell/mod.rs
use window::Window;


#[derive(Debug)]
pub struct WlShell {
wl_shell: wl_shell::WlShell,
}

impl WlShell {

Check failure on line 21 in src/shell/wl_shell/mod.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/client-toolkit/client-toolkit/src/shell/wl_shell/mod.rs
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
}

Check failure on line 42 in src/shell/wl_shell/mod.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/client-toolkit/client-toolkit/src/shell/wl_shell/mod.rs
}


impl ProvidesBoundGlobal<wl_shell::WlShell, 1> for WlShell {
fn bound_global(&self) -> Result<wl_shell::WlShell, GlobalError> {
Ok(self.wl_shell.clone())
}
}

Check failure on line 51 in src/shell/wl_shell/mod.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/client-toolkit/client-toolkit/src/shell/wl_shell/mod.rs
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 {

Check failure on line 63 in src/shell/wl_shell/mod.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/client-toolkit/client-toolkit/src/shell/wl_shell/mod.rs
wl_shell_surface::Event::Ping { serial } => {
proxy.pong(serial);
},
_ => unreachable!(),
}
}
}
80 changes: 80 additions & 0 deletions src/shell/wl_shell/window.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use std::sync::{Arc, Weak};

Check failure on line 1 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/client-toolkit/client-toolkit/src/shell/wl_shell/window.rs

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)

Check failure on line 16 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/client-toolkit/client-toolkit/src/shell/wl_shell/window.rs
);

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

View workflow job for this annotation

GitHub Actions / test (stable)

field `0` is never read

Check warning on line 80 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / test (stable)

field `0` is never read

Check warning on line 80 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / test (stable)

field `0` is never read

Check warning on line 80 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / ci (stable)

field `0` is never read

Check warning on line 80 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / ci (stable)

field `0` is never read

Check warning on line 80 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / test (beta)

field `0` is never read

Check warning on line 80 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / test (beta)

field `0` is never read

Check warning on line 80 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / test (beta)

field `0` is never read

Check warning on line 80 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / ci (beta)

field `0` is never read

Check warning on line 80 in src/shell/wl_shell/window.rs

View workflow job for this annotation

GitHub Actions / ci (beta)

field `0` is never read

0 comments on commit ecd9fae

Please sign in to comment.