Skip to content

chore: use wayland-csd-frame for CSD interop #382

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

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `SeatState:get_pointer_with_them*` now takes `Shm` and `WlSurface` for the themed cursor.
- `ThemedPointer` now automatically releases the associated `WlPointer`.
- `CursorIcon` from `cursor-icon` crate is now used for `set_cursor` and `Frame`.
- `wayland-csd-frame` is now used for CSD types like `WindowState`, `DecorationsFrame`, etc.

## 0.17.0 - 2023-03-28

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ wayland-cursor = "0.30.0"
wayland-protocols = { version = "0.30.0", features = ["client", "unstable"] }
wayland-protocols-wlr = { version = "0.1.0", features = ["client"] }
wayland-scanner = "0.30.0"
wayland-csd-frame = "0.1.0"

xkbcommon = { version = "0.5", optional = true, features = ["wayland"] }
calloop = { version = "0.10.5", optional = true }
Expand Down
38 changes: 28 additions & 10 deletions examples/themed_window.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
use std::sync::Arc;
use std::{convert::TryInto, num::NonZeroU32};

use smithay_client_toolkit::reexports::client::{
globals::registry_queue_init,
protocol::{wl_keyboard, wl_output, wl_pointer, wl_seat, wl_shm, wl_surface},
Connection, Proxy, QueueHandle,
};
use smithay_client_toolkit::reexports::csd_frame::{
DecorationsFrame, FrameAction, FrameClick, ResizeEdge,
};
use smithay_client_toolkit::reexports::protocols::xdg::shell::client::xdg_toplevel::ResizeEdge as XdgResizeEdge;
use smithay_client_toolkit::seat::keyboard::keysyms;
use smithay_client_toolkit::{
compositor::{CompositorHandler, CompositorState},
Expand All @@ -19,8 +28,7 @@ use smithay_client_toolkit::{
},
shell::{
xdg::{
frame::fallback_frame::FallbackFrame,
frame::{DecorationsFrame, FrameAction, FrameClick},
fallback_frame::FallbackFrame,
window::{DecorationMode, Window, WindowConfigure, WindowDecorations, WindowHandler},
XdgShell, XdgSurface,
},
Expand All @@ -32,11 +40,6 @@ use smithay_client_toolkit::{
},
subcompositor::SubcompositorState,
};
use wayland_client::{
globals::registry_queue_init,
protocol::{wl_keyboard, wl_output, wl_pointer, wl_seat, wl_shm, wl_surface},
Connection, Proxy, QueueHandle,
};

// Cursor shapes.
const CURSORS: &[CursorIcon] = &[
Expand Down Expand Up @@ -471,7 +474,7 @@ impl PointerHandler for SimpleWindow {
self.decorations_cursor = self
.window_frame
.as_mut()
.and_then(|frame| frame.click_point_moved(&event.surface, x, y));
.and_then(|frame| frame.click_point_moved(&event.surface.id(), x, y));
}
Leave { .. } => {
if &event.surface != self.window.wl_surface() {
Expand All @@ -484,7 +487,7 @@ impl PointerHandler for SimpleWindow {
if let Some(new_cursor) = self
.window_frame
.as_mut()
.and_then(|frame| frame.click_point_moved(&event.surface, x, y))
.and_then(|frame| frame.click_point_moved(&event.surface.id(), x, y))
{
self.set_cursor = true;
self.decorations_cursor = Some(new_cursor);
Expand Down Expand Up @@ -526,8 +529,23 @@ impl SimpleWindow {
FrameAction::Maximize => self.window.set_maximized(),
FrameAction::UnMaximize => self.window.unset_maximized(),
FrameAction::ShowMenu(x, y) => self.window.show_window_menu(seat, serial, (x, y)),
FrameAction::Resize(edge) => self.window.resize(seat, serial, edge),
FrameAction::Resize(edge) => {
let edge = match edge {
ResizeEdge::None => XdgResizeEdge::None,
ResizeEdge::Top => XdgResizeEdge::Top,
ResizeEdge::Bottom => XdgResizeEdge::Bottom,
ResizeEdge::Left => XdgResizeEdge::Left,
ResizeEdge::TopLeft => XdgResizeEdge::TopLeft,
ResizeEdge::BottomLeft => XdgResizeEdge::BottomLeft,
ResizeEdge::Right => XdgResizeEdge::Right,
ResizeEdge::TopRight => XdgResizeEdge::TopRight,
ResizeEdge::BottomRight => XdgResizeEdge::BottomRight,
_ => return,
};
self.window.resize(seat, serial, edge);
}
FrameAction::Move => self.window.move_(seat, serial),
_ => return,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod reexports {
#[cfg(feature = "calloop")]
pub use calloop;
pub use wayland_client as client;
pub use wayland_csd_frame as csd_frame;
pub use wayland_protocols as protocols;
pub use wayland_protocols_wlr as protocols_wlr;
}
Expand Down
4 changes: 4 additions & 0 deletions src/seat/keyboard/repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ impl SeatState {
/// ## Errors
///
/// This will return [`SeatError::UnsupportedCapability`] if the seat does not support a keyboard.
///
/// [`EventSource`]: calloop::EventSource
pub fn get_keyboard_with_repeat<D, T>(
&mut self,
qh: &QueueHandle<D>,
Expand Down Expand Up @@ -84,6 +86,8 @@ impl SeatState {
/// ## Errors
///
/// This will return [`SeatError::UnsupportedCapability`] if the seat does not support a keyboard.
///
/// [`EventSource`]: calloop::EventSource
pub fn get_keyboard_with_repeat_with_data<D, U>(
&mut self,
qh: &QueueHandle<D>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ use crate::reexports::client::{
protocol::{wl_shm, wl_subsurface::WlSubsurface, wl_surface::WlSurface},
Dispatch, Proxy, QueueHandle,
};
use crate::reexports::protocols::xdg::shell::client::xdg_toplevel::ResizeEdge;
use crate::reexports::csd_frame::{
DecorationsFrame, FrameAction, FrameClick, ResizeEdge, WindowManagerCapabilities, WindowState,
};

use crate::{
compositor::SurfaceData,
seat::pointer::CursorIcon,
shell::xdg::{WindowManagerCapabilities, WindowState},
shell::WaylandSurface,
shm::{slot::SlotPool, Shm},
subcompositor::{SubcompositorState, SubsurfaceData},
};

use super::{DecorationsFrame, FrameAction, FrameClick};
use wayland_backend::client::ObjectId;

/// The size of the header bar.
const HEADER_SIZE: u32 = 24;
Expand Down Expand Up @@ -170,8 +171,8 @@ where
}

#[inline]
fn part_index_for_surface(&mut self, surface: &WlSurface) -> Option<usize> {
self.render_data.as_ref()?.parts.iter().position(|part| &part.surface == surface)
fn part_index_for_surface(&mut self, surface_id: &ObjectId) -> Option<usize> {
self.render_data.as_ref()?.parts.iter().position(|part| &part.surface.id() == surface_id)
}

fn draw_buttons(
Expand Down Expand Up @@ -316,7 +317,7 @@ impl<State> DecorationsFrame for FallbackFrame<State>
where
State: Dispatch<WlSurface, SurfaceData> + Dispatch<WlSubsurface, SubsurfaceData> + 'static,
{
fn on_click(&mut self, click: FrameClick, pressed: bool) -> Option<super::FrameAction> {
fn on_click(&mut self, click: FrameClick, pressed: bool) -> Option<FrameAction> {
// Handle alternate click before everything else.
if click == FrameClick::Alternate {
return if Location::Head != self.mouse_location
Expand Down Expand Up @@ -358,8 +359,8 @@ where
}
}

fn click_point_moved(&mut self, surface: &WlSurface, x: f64, y: f64) -> Option<CursorIcon> {
let part_index = self.part_index_for_surface(surface)?;
fn click_point_moved(&mut self, surface_id: &ObjectId, x: f64, y: f64) -> Option<CursorIcon> {
let part_index = self.part_index_for_surface(surface_id)?;
let location = match part_index {
LEFT_BORDER => Location::Left,
RIGHT_BORDER => Location::Right,
Expand Down
146 changes: 0 additions & 146 deletions src/shell/xdg/frame/mod.rs

This file was deleted.

17 changes: 9 additions & 8 deletions src/shell/xdg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// TODO: Examples

use std::sync::{Arc, Mutex};
use wayland_client::globals::{BindError, GlobalList};
use wayland_client::Connection;
use wayland_client::{protocol::wl_surface, Dispatch, Proxy, QueueHandle};
use wayland_protocols::xdg::decoration::zv1::client::zxdg_toplevel_decoration_v1::Mode;
use wayland_protocols::xdg::decoration::zv1::client::{

use crate::reexports::client::globals::{BindError, GlobalList};
use crate::reexports::client::Connection;
use crate::reexports::client::{protocol::wl_surface, Dispatch, Proxy, QueueHandle};
use crate::reexports::csd_frame::{WindowManagerCapabilities, WindowState};
use crate::reexports::protocols::xdg::decoration::zv1::client::zxdg_toplevel_decoration_v1::Mode;
use crate::reexports::protocols::xdg::decoration::zv1::client::{
zxdg_decoration_manager_v1, zxdg_toplevel_decoration_v1,
};
use wayland_protocols::xdg::shell::client::{
use crate::reexports::protocols::xdg::shell::client::{
xdg_positioner, xdg_surface, xdg_toplevel, xdg_wm_base,
};

Expand All @@ -21,12 +23,11 @@ use crate::registry::GlobalProxy;
use self::window::inner::WindowInner;
use self::window::{
DecorationMode, Window, WindowConfigure, WindowData, WindowDecorations, WindowHandler,
WindowManagerCapabilities, WindowState,
};

use super::WaylandSurface;

pub mod frame;
pub mod fallback_frame;
pub mod popup;
pub mod window;

Expand Down
Loading