Add Wayland layer-shell wrapper, behind layer-shell feature

Requires patched GTK4 from
https://github.com/pop-os/gtk4/tree/layer-shell_impish.
This commit is contained in:
Ian Douglas Scott 2022-01-05 13:28:49 -08:00
parent cfd1edcde3
commit 6195ab2db9
5 changed files with 753 additions and 1 deletions

33
src/deref_cell.rs Normal file
View file

@ -0,0 +1,33 @@
#![allow(dead_code)]
use once_cell::unsync::OnceCell;
/// Wrapper around `OnceCell` implementing `Deref`, and thus also panicking
/// when not set (or set twice).
///
/// To be used in place of `gtk::TemplateChild`, but without xml.
pub struct DerefCell<T>(OnceCell<T>);
impl<T> DerefCell<T> {
#[track_caller]
pub fn set(&self, value: T) {
if self.0.set(value).is_err() {
panic!("Initialized twice");
}
}
}
impl<T> Default for DerefCell<T> {
fn default() -> Self {
Self(OnceCell::default())
}
}
impl<T> std::ops::Deref for DerefCell<T> {
type Target = T;
#[track_caller]
fn deref(&self) -> &T {
self.0.get().unwrap()
}
}