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