1 //! Unified shell surface handling
2 //!
3 //! This module provides an abstraction unifying the various iterations of
4 //! the shell surface protocols (`wl_shell`, `zxdg_shell_v6` and `xdg_shell`,
5 //! the current standard).
6 //!
7 //! This abstraction only manages the protocol part of shell surfaces. If you're
8 //! looking for a more battery-included abstraction for creating windows,
9 //! consider the `Window` type.
10 use wayland_client::protocol::{wl_output, wl_seat, wl_surface};
11 use wayland_client::Proxy;
12
13 use wayland_protocols::xdg_shell::client::xdg_toplevel;
14 pub use wayland_protocols::xdg_shell::client::xdg_toplevel::State;
15
16 use Shell;
17
18 mod wl;
19 mod xdg;
20 mod zxdg;
21
22 /// Possible events generated by a shell surface that you need to handle
23 #[derive(Clone, Debug)]
24 pub enum Event {
25 /// The state of your window has been changed
26 Configure {
27 /// Optional new size for your shell surface
28 ///
29 /// This is the new size of the contents of your shell surface
30 /// as suggested by the server. You can ignore it and choose
31 /// a new size if you want better control on the possible
32 /// sizes of your shell surface.
33 ///
34 /// In all cases, these events can be generated in large batches
35 /// during an interactive resize, and you should buffer them before
36 /// processing them. You only need to handle the last one of a batch.
37 new_size: Option<(u32, u32)>,
38 /// New combination of states of your window
39 ///
40 /// Typically tells you if your surface is active/inactive, maximized,
41 /// etc...
42 states: Vec<State>,
43 },
44 /// A close request has been received
45 ///
46 /// Most likely the user has clicked on the close button of the decorations
47 /// or something equivalent
48 Close,
49 }
50
create_shell_surface<Impl>( shell: &Shell, surface: &Proxy<wl_surface::WlSurface>, implem: Impl, ) -> Box<ShellSurface> where Impl: FnMut(Event) + Send + 'static,51 pub(crate) fn create_shell_surface<Impl>(
52 shell: &Shell,
53 surface: &Proxy<wl_surface::WlSurface>,
54 implem: Impl,
55 ) -> Box<ShellSurface>
56 where
57 Impl: FnMut(Event) + Send + 'static,
58 {
59 match *shell {
60 Shell::Wl(ref shell) => Box::new(wl::Wl::create(surface, shell, implem)) as Box<_>,
61 Shell::Xdg(ref shell) => Box::new(xdg::Xdg::create(surface, shell, implem)) as Box<_>,
62 Shell::Zxdg(ref shell) => Box::new(zxdg::Zxdg::create(surface, shell, implem)) as Box<_>,
63 }
64 }
65
66 /// Trait abstracting over shell surface protocols
67 ///
68 /// This trait's API is designed to reflect the behavior of the current standard
69 /// shell surface protocol: `xdg_shell`. Compatibility implementations are
70 /// provided for older protocols.
71 pub trait ShellSurface: Send + Sync {
72 /// Resizes the shell surface
resize(&self, seat: &Proxy<wl_seat::WlSeat>, serial: u32, edges: xdg_toplevel::ResizeEdge)73 fn resize(&self, seat: &Proxy<wl_seat::WlSeat>, serial: u32, edges: xdg_toplevel::ResizeEdge);
74 /// Moves the shell surface
move_(&self, seat: &Proxy<wl_seat::WlSeat>, serial: u32)75 fn move_(&self, seat: &Proxy<wl_seat::WlSeat>, serial: u32);
76 /// Set the title of the shell surface
set_title(&self, title: String)77 fn set_title(&self, title: String);
78 /// Set the app id of the shell surface
set_app_id(&self, app_id: String)79 fn set_app_id(&self, app_id: String);
80 /// Make fullscreen
set_fullscreen(&self, output: Option<&Proxy<wl_output::WlOutput>>)81 fn set_fullscreen(&self, output: Option<&Proxy<wl_output::WlOutput>>);
82 /// Unset fullscreen
unset_fullscreen(&self)83 fn unset_fullscreen(&self);
84 /// Maximize surface
set_maximized(&self)85 fn set_maximized(&self);
86 /// Unmaximize surface
unset_maximized(&self)87 fn unset_maximized(&self);
88 /// Minimize surface
set_minimized(&self)89 fn set_minimized(&self);
90 /// Set geometry
set_geometry(&self, x: i32, y: i32, width: i32, height: i32)91 fn set_geometry(&self, x: i32, y: i32, width: i32, height: i32);
92 /// Set minimum surface size
set_min_size(&self, size: Option<(i32, i32)>)93 fn set_min_size(&self, size: Option<(i32, i32)>);
94 /// Set maximum surface size
set_max_size(&self, size: Option<(i32, i32)>)95 fn set_max_size(&self, size: Option<(i32, i32)>);
96 /// Retrive the `XdgToplevel` proxy if the underlying shell surface
97 /// uses the `xdg_shell` protocol.
98 ///
99 /// This allows interactions with other protocol extensions, like
100 /// `xdg_decoratins` for example.
get_xdg(&self) -> Option<&Proxy<xdg_toplevel::XdgToplevel>>101 fn get_xdg(&self) -> Option<&Proxy<xdg_toplevel::XdgToplevel>>;
102 }
103