ltk/platform/wayland/
window.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: LGPL-2.1-only
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>

use smithay_client_toolkit::reexports::protocols::xdg::shell::client::xdg_toplevel;
use smithay_client_toolkit::shell::xdg::window::Window;

use crate::app::App;
use crate::event_loop::SurfaceFocus;
use crate::event_loop::cursor_shape::ResizeEdge;

use super::{ SurfaceKind, WaylandPlatform, WaylandSurfaceState };

pub( super ) fn window( surface: &WaylandSurfaceState ) -> Option<&Window>
{
	match surface.surface
	{
		SurfaceKind::Window( ref window ) => Some( window ),
		_                                 => None,
	}
}

pub( super ) fn begin_move<A: App>( platform: &WaylandPlatform<A>, main: &WaylandSurfaceState )
{
	let Some( window ) = window( main ) else { return };
	let Some( seat ) = platform.seat_state.seats().next() else { return };
	window.move_( &seat, platform.last_pointer_serial );
}

pub( super ) fn begin_resize<A: App>( platform: &WaylandPlatform<A>, main: &WaylandSurfaceState, edge: ResizeEdge )
{
	let Some( window ) = window( main ) else { return };
	let Some( seat ) = platform.seat_state.seats().next() else { return };
	window.resize( &seat, platform.last_pointer_serial, xdg_edge( edge ) );
}

pub( super ) fn set_fullscreen( main: &WaylandSurfaceState, fullscreen: bool ) -> bool
{
	let Some( window ) = window( main ) else { return false };
	if fullscreen
	{
		window.set_fullscreen( None );
	} else {
		window.unset_fullscreen();
	}
	true
}

pub( super ) fn request_frame<A: App>( platform: &WaylandPlatform<A>, surface: &WaylandSurfaceState, focus: SurfaceFocus ) -> bool
{
	let Some( wl ) = surface.surface.try_wl_surface() else { return false };
	let _ = wl.frame( &platform.qh, focus );
	wl.commit();
	true
}

fn xdg_edge( edge: ResizeEdge ) -> xdg_toplevel::ResizeEdge
{
	match edge
	{
		ResizeEdge::Top         => xdg_toplevel::ResizeEdge::Top,
		ResizeEdge::Bottom      => xdg_toplevel::ResizeEdge::Bottom,
		ResizeEdge::Left        => xdg_toplevel::ResizeEdge::Left,
		ResizeEdge::Right       => xdg_toplevel::ResizeEdge::Right,
		ResizeEdge::TopLeft     => xdg_toplevel::ResizeEdge::TopLeft,
		ResizeEdge::TopRight    => xdg_toplevel::ResizeEdge::TopRight,
		ResizeEdge::BottomLeft  => xdg_toplevel::ResizeEdge::BottomLeft,
		ResizeEdge::BottomRight => xdg_toplevel::ResizeEdge::BottomRight,
	}
}