gtk_layer_shell/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![deny(warnings)]
3#![allow(rustdoc::redundant_explicit_links)]
4
5#[allow(unused_imports)]
6#[allow(clippy::single_component_path_imports)]
7use gtk; // Required for the documentation to build without warnings
8use gtk::prelude::IsA;
9
10use gtk_layer_shell_sys as ffi;
11
12macro_rules! assert_initialized_main_thread {
13    () => {
14        if !::gtk::is_initialized_main_thread() {
15            if ::gtk::is_initialized() {
16                panic!("GTK may only be used from the main thread.");
17            } else {
18                panic!("GTK has not been initialized. Call `gtk::init` first.");
19            }
20        }
21    };
22}
23
24/// No-op.
25macro_rules! skip_assert_initialized {
26    () => {};
27}
28
29mod auto;
30pub use auto::{Edge, KeyboardMode, Layer};
31
32#[cfg(feature = "v0_4")]
33#[cfg_attr(docsrs, doc(cfg(feature = "v0_4")))]
34pub use auto::{functions::major_version, functions::micro_version, functions::minor_version};
35
36#[cfg(feature = "v0_5")]
37#[cfg_attr(docsrs, doc(cfg(feature = "v0_5")))]
38pub use auto::functions::is_supported;
39
40#[cfg(feature = "v0_6")]
41#[cfg_attr(docsrs, doc(cfg(feature = "v0_6")))]
42pub use auto::functions::protocol_version;
43
44// mod manual;
45// pub use manual::*;
46
47pub trait LayerShell: IsA<gtk::Window> {
48    /// When auto exclusive zone is enabled, exclusive zone is automatically set to the
49    /// size of the `window` + relevant margin. To disable auto exclusive zone, just set the
50    /// exclusive zone to 0 or any other fixed value.
51    ///
52    /// NOTE: you can control the auto exclusive zone by changing the margin on the non-anchored
53    /// edge. This behavior is specific to gtk-layer-shell and not part of the underlying protocol
54    /// ## `window`
55    /// A layer surface.
56    #[doc(alias = "gtk_layer_auto_exclusive_zone_enable")]
57    fn auto_exclusive_zone_enable(&self) {
58        crate::auto::functions::auto_exclusive_zone_enable(self);
59    }
60
61    /// ## `window`
62    /// A layer surface.
63    ///
64    /// # Returns
65    ///
66    /// if the surface's exclusive zone is set to change based on the window's size
67    #[cfg(feature = "v0_5")]
68    #[cfg_attr(docsrs, doc(cfg(feature = "v0_5")))]
69    #[doc(alias = "gtk_layer_auto_exclusive_zone_is_enabled")]
70    fn auto_exclusive_zone_is_enabled(&self) -> bool {
71        crate::auto::functions::auto_exclusive_zone_is_enabled(self)
72    }
73
74    /// ## `window`
75    /// A layer surface.
76    /// ## `edge`
77    /// the edge to which the surface may or may not be anchored
78    ///
79    /// # Returns
80    ///
81    /// if this surface is anchored to the given edge.
82    #[cfg(feature = "v0_5")]
83    #[cfg_attr(docsrs, doc(cfg(feature = "v0_5")))]
84    #[doc(alias = "gtk_layer_get_anchor")]
85    #[doc(alias = "get_anchor")]
86    fn is_anchor(&self, edge: Edge) -> bool {
87        crate::auto::functions::is_anchor(self, edge)
88    }
89
90    /// ## `window`
91    /// A layer surface.
92    ///
93    /// # Returns
94    ///
95    /// the window's exclusive zone (which may have been set manually or automatically)
96    #[cfg(feature = "v0_5")]
97    #[cfg_attr(docsrs, doc(cfg(feature = "v0_5")))]
98    #[doc(alias = "gtk_layer_get_exclusive_zone")]
99    #[doc(alias = "get_exclusive_zone")]
100    fn exclusive_zone(&self) -> i32 {
101        crate::auto::functions::exclusive_zone(self)
102    }
103
104    /// ## `window`
105    /// A layer surface.
106    ///
107    /// # Returns
108    ///
109    /// current keyboard interactivity mode for `window`.
110    #[cfg(feature = "v0_6")]
111    #[cfg_attr(docsrs, doc(cfg(feature = "v0_6")))]
112    #[doc(alias = "gtk_layer_get_keyboard_mode")]
113    #[doc(alias = "get_keyboard_mode")]
114    fn keyboard_mode(&self) -> KeyboardMode {
115        crate::auto::functions::keyboard_mode(self)
116    }
117
118    /// ## `window`
119    /// A layer surface.
120    ///
121    /// # Returns
122    ///
123    /// the current layer.
124    #[cfg(feature = "v0_5")]
125    #[cfg_attr(docsrs, doc(cfg(feature = "v0_5")))]
126    #[doc(alias = "gtk_layer_get_layer")]
127    #[doc(alias = "get_layer")]
128    fn layer(&self) -> Layer {
129        crate::auto::functions::layer(self)
130    }
131
132    /// ## `window`
133    /// A layer surface.
134    /// ## `edge`
135    /// the margin edge to get
136    ///
137    /// # Returns
138    ///
139    /// the size of the margin for the given edge.
140    #[cfg(feature = "v0_5")]
141    #[cfg_attr(docsrs, doc(cfg(feature = "v0_5")))]
142    #[doc(alias = "gtk_layer_get_margin")]
143    #[doc(alias = "get_margin")]
144    fn layer_shell_margin(&self, edge: Edge) -> i32 {
145        crate::auto::functions::margin(self, edge)
146    }
147
148    ///
149    /// # Deprecated since 0.6
150    ///
151    /// Use gtk_layer_get_keyboard_mode () instead.
152    /// ## `window`
153    /// A layer surface.
154    ///
155    /// # Returns
156    ///
157    /// if keybaord interactivity is enabled
158    #[cfg_attr(feature = "v0_6", deprecated = "Since 0.6")]
159    #[cfg(feature = "v0_5")]
160    #[cfg_attr(docsrs, doc(cfg(feature = "v0_5")))]
161    #[allow(deprecated)]
162    #[doc(alias = "gtk_layer_get_keyboard_interactivity")]
163    #[doc(alias = "get_keyboard_interactivity")]
164    fn is_keyboard_interactivity(&self) -> bool {
165        crate::auto::functions::is_keyboard_interactivity(self)
166    }
167
168    /// NOTE: To get which monitor the surface is actually on, use
169    /// `gdk_display_get_monitor_at_window()`.
170    /// ## `window`
171    /// A layer surface.
172    ///
173    /// # Returns
174    ///
175    /// the monitor this surface will/has requested to be on, can be [`None`].
176    #[cfg(feature = "v0_5")]
177    #[cfg_attr(docsrs, doc(cfg(feature = "v0_5")))]
178    #[doc(alias = "gtk_layer_get_monitor")]
179    #[doc(alias = "get_monitor")]
180    fn monitor(&self) -> Option<gdk::Monitor> {
181        crate::auto::functions::monitor(self)
182    }
183
184    /// NOTE: this function does not return ownership of the string. Do not free the returned string.
185    /// Future calls into the library may invalidate the returned string.
186    /// ## `window`
187    /// A layer surface.
188    ///
189    /// # Returns
190    ///
191    /// a reference to the namespace property. If namespace is unset, returns the
192    /// default namespace ("gtk-layer-shell"). Never returns [`None`].
193    #[cfg(feature = "v0_5")]
194    #[cfg_attr(docsrs, doc(cfg(feature = "v0_5")))]
195    #[doc(alias = "gtk_layer_get_namespace")]
196    #[doc(alias = "get_namespace")]
197    fn namespace(&self) -> Option<glib::GString> {
198        crate::auto::functions::namespace(self)
199    }
200
201    /// Set the `window` up to be a layer surface once it is mapped. this must be called before
202    /// the `window` is realized.
203    /// ## `window`
204    /// A [`gtk::Window`][crate::gtk::Window] to be turned into a layer surface.
205    #[doc(alias = "init_for_window")]
206    #[doc(alias = "gtk_layer_init_for_window")]
207    fn init_layer_shell(&self) {
208        crate::auto::functions::init_for_window(self);
209    }
210
211    /// ## `window`
212    /// A [`gtk::Window`][crate::gtk::Window] that may or may not have a layer surface.
213    ///
214    /// # Returns
215    ///
216    /// if `window` has been initialized as a layer surface.
217    #[cfg(feature = "v0_5")]
218    #[cfg_attr(docsrs, doc(cfg(feature = "v0_5")))]
219    #[doc(alias = "gtk_layer_is_layer_window")]
220    fn is_layer_window(&self) -> bool {
221        crate::auto::functions::is_layer_window(self)
222    }
223
224    /// Set whether `window` should be anchored to `edge`.
225    /// - If two perpendicular edges are anchored, the surface with be anchored to that corner
226    /// - If two opposite edges are anchored, the window will be stretched across the screen in that direction
227    ///
228    /// Default is [`false`] for each [`Edge`][crate::Edge]
229    /// ## `window`
230    /// A layer surface.
231    /// ## `edge`
232    /// A [`Edge`][crate::Edge] this layer surface may be anchored to.
233    /// ## `anchor_to_edge`
234    /// Whether or not to anchor this layer surface to `edge`.
235    #[doc(alias = "gtk_layer_set_anchor")]
236    fn set_anchor(&self, edge: Edge, anchor_to_edge: bool) {
237        crate::auto::functions::set_anchor(self, edge, anchor_to_edge);
238    }
239
240    /// Has no effect unless the surface is anchored to an edge. Requests that the compositor
241    /// does not place other surfaces within the given exclusive zone of the anchored edge.
242    /// For example, a panel can request to not be covered by maximized windows. See
243    /// wlr-layer-shell-unstable-v1.xml for details.
244    ///
245    /// Default is 0
246    /// ## `window`
247    /// A layer surface.
248    /// ## `exclusive_zone`
249    /// The size of the exclusive zone.
250    #[doc(alias = "gtk_layer_set_exclusive_zone")]
251    fn set_exclusive_zone(&self, exclusive_zone: i32) {
252        crate::auto::functions::set_exclusive_zone(self, exclusive_zone);
253    }
254
255    /// Whether the `window` should receive keyboard events from the compositor.
256    ///
257    /// Default is [`false`]
258    ///
259    /// # Deprecated since 0.6
260    ///
261    /// Use gtk_layer_set_keyboard_mode () instead.
262    /// ## `window`
263    /// A layer surface.
264    /// ## `interactivity`
265    /// Whether the layer surface should receive keyboard events.
266    #[cfg_attr(feature = "v0_6", deprecated = "Since 0.6")]
267    #[allow(deprecated)]
268    #[doc(alias = "gtk_layer_set_keyboard_interactivity")]
269    fn set_keyboard_interactivity(&self, interactivity: bool) {
270        crate::auto::functions::set_keyboard_interactivity(self, interactivity);
271    }
272
273    /// Sets if/when `window` should receive keyboard events from the compositor, see
274    /// GtkLayerShellKeyboardMode for details.
275    ///
276    /// Default is [`KeyboardMode::None`][crate::KeyboardMode::None]
277    /// ## `window`
278    /// A layer surface.
279    /// ## `mode`
280    /// The type of keyboard interactivity requested.
281    #[cfg(feature = "v0_6")]
282    #[cfg_attr(docsrs, doc(cfg(feature = "v0_6")))]
283    #[doc(alias = "gtk_layer_set_keyboard_mode")]
284    fn set_keyboard_mode(&self, mode: KeyboardMode) {
285        crate::auto::functions::set_keyboard_mode(self, mode);
286    }
287
288    /// Set the "layer" on which the surface appears (controls if it is over top of or below other surfaces). The layer may
289    /// be changed on-the-fly in the current version of the layer shell protocol, but on compositors that only support an
290    /// older version the `window` is remapped so the change can take effect.
291    ///
292    /// Default is [`Layer::Top`][crate::Layer::Top]
293    /// ## `window`
294    /// A layer surface.
295    /// ## `layer`
296    /// The layer on which this surface appears.
297    #[doc(alias = "gtk_layer_set_layer")]
298    fn set_layer(&self, layer: Layer) {
299        crate::auto::functions::set_layer(self, layer);
300    }
301
302    /// Set the margin for a specific `edge` of a `window`. Effects both surface's distance from
303    /// the edge and its exclusive zone size (if auto exclusive zone enabled).
304    ///
305    /// Default is 0 for each [`Edge`][crate::Edge]
306    /// ## `window`
307    /// A layer surface.
308    /// ## `edge`
309    /// The [`Edge`][crate::Edge] for which to set the margin.
310    /// ## `margin_size`
311    /// The margin for `edge` to be set.
312    #[doc(alias = "gtk_layer_set_margin")]
313    #[doc(alias = "set_margin")]
314    fn set_layer_shell_margin(&self, edge: Edge, margin_size: i32) {
315        crate::auto::functions::set_margin(self, edge, margin_size);
316    }
317
318    /// Set the output for the window to be placed on, or [`None`] to let the compositor choose.
319    /// If the window is currently mapped, it will get remapped so the change can take effect.
320    ///
321    /// Default is [`None`]
322    /// ## `window`
323    /// A layer surface.
324    /// ## `monitor`
325    /// The output this layer surface will be placed on ([`None`] to let the compositor decide).
326    #[doc(alias = "gtk_layer_set_monitor")]
327    fn set_monitor(&self, monitor: &gdk::Monitor) {
328        crate::auto::functions::set_monitor(self, monitor);
329    }
330
331    /// Set the "namespace" of the surface.
332    ///
333    /// No one is quite sure what this is for, but it probably should be something generic
334    /// ("panel", "osk", etc). The `name_space` string is copied, and caller maintains
335    /// ownership of original. If the window is currently mapped, it will get remapped so
336    /// the change can take effect.
337    ///
338    /// Default is "gtk-layer-shell" (which will be used if set to [`None`])
339    /// ## `window`
340    /// A layer surface.
341    /// ## `name_space`
342    /// The namespace of this layer surface.
343    #[doc(alias = "gtk_layer_set_namespace")]
344    fn set_namespace(&self, name_space: &str) {
345        crate::auto::functions::set_namespace(self, name_space);
346    }
347
348    /* TODO: Fix this
349    /// ## `window`
350    /// A layer surface.
351    ///
352    /// # Returns
353    ///
354    /// The underlying layer surface Wayland object
355    ///
356    #[doc(alias = "gtk_layer_get_zwlr_layer_surface_v1")]
357    #[doc(alias = "get_zwlr_layer_surface_v1")]
358    fn zwlr_layer_surface_v1(
359        window: &impl glib::object::IsA<gtk::Window>,
360    ) -> *mut ZwlrLayerSurfaceV1 {
361        zwlr_layer_surface_v1(self)
362    }*/
363}
364
365// The default implementation is always fine
366impl<T: IsA<gtk::Window>> LayerShell for T {}