Skip to content

Commit

Permalink
remove top level decorator and other wlrootisms.
Browse files Browse the repository at this point in the history
  • Loading branch information
james-lawrence committed Jan 16, 2022
1 parent cb3da65 commit 4902c26
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 51 deletions.
26 changes: 12 additions & 14 deletions druid-shell/src/backend/wayland/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use wayland_client::{
},
};
use wayland_cursor::CursorTheme;
use wayland_protocols::unstable::xdg_decoration::v1::client::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1;
use wayland_protocols::wlr::unstable::layer_shell::v1::client::zwlr_layer_shell_v1::ZwlrLayerShellV1;
use wayland_protocols::xdg_shell::client::xdg_positioner::XdgPositioner;
use wayland_protocols::xdg_shell::client::xdg_surface;
Expand Down Expand Up @@ -93,8 +92,7 @@ pub struct Application {
#[allow(dead_code)]
pub(crate) struct Data {
pub(super) wayland: std::rc::Rc<display::Environment>,
pub(super) zxdg_decoration_manager_v1: wl::Main<ZxdgDecorationManagerV1>,
pub(super) zwlr_layershell_v1: wl::Main<ZwlrLayerShellV1>,
pub(super) zwlr_layershell_v1: Option<wl::Main<ZwlrLayerShellV1>>,
pub(super) wl_compositor: wl::Main<WlCompositor>,
pub(super) wl_shm: wl::Main<WlShm>,
/// A map of wayland object IDs to outputs.
Expand Down Expand Up @@ -201,14 +199,17 @@ impl Application {
let env = display::new(dispatcher)?;
display::print(&env.registry);

let zxdg_decoration_manager_v1 = env
.registry
.instantiate_exact::<ZxdgDecorationManagerV1>(1)
.map_err(|e| Error::global("zxdg_decoration_manager_v1", 1, e))?;
let zwlr_layershell_v1 = env
.registry
.instantiate_exact::<ZwlrLayerShellV1>(1)
.map_err(|e| Error::global("zwlr_layershell_v1", 1, e))?;
.map_or_else(
|e| {
tracing::info!("unable to instantiate layershell {:?}", e);
None
},
|x| Some(x),
);

let wl_compositor = env
.registry
.instantiate_exact::<WlCompositor>(4)
Expand All @@ -230,7 +231,6 @@ impl Application {

// We need to have keyboard events set up for our seats before the next roundtrip.
let appdata = std::sync::Arc::new(Data {
zxdg_decoration_manager_v1,
zwlr_layershell_v1,
wl_compositor,
wl_shm: wl_shm.clone(),
Expand Down Expand Up @@ -334,6 +334,7 @@ impl Application {
calloop::channel::Event::Closed => {}
calloop::channel::Event::Msg(output) => match output {
outputs::Event::Located(output) => {
tracing::debug!("output added {:?} {:?}", output.gid, output.id());
appdata
.outputs
.borrow_mut()
Expand All @@ -343,6 +344,7 @@ impl Application {
}
}
outputs::Event::Removed(output) => {
tracing::debug!("output removed {:?} {:?}", output.gid, output.id());
appdata.outputs.borrow_mut().remove(&output.id());
for (_, win) in appdata.handles_iter() {
surfaces::Outputs::removed(&win, &output);
Expand Down Expand Up @@ -419,11 +421,7 @@ impl surfaces::Compositor for Data {
self.wayland.xdg_base.get_xdg_surface(s)
}

fn zxdg_decoration_manager_v1(&self) -> wl::Main<ZxdgDecorationManagerV1> {
self.zxdg_decoration_manager_v1.clone()
}

fn zwlr_layershell_v1(&self) -> wl::Main<ZwlrLayerShellV1> {
fn zwlr_layershell_v1(&self) -> Option<wl::Main<ZwlrLayerShellV1>> {
self.zwlr_layershell_v1.clone()
}
}
Expand Down
22 changes: 15 additions & 7 deletions druid-shell/src/backend/wayland/surfaces/layershell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl Surface {
) -> Self {
let compositor = CompositorHandle::new(c);
let wl_surface = surface::Surface::new(compositor.clone(), handler, kurbo::Size::ZERO);
let ls_surface = compositor.zwlr_layershell_v1().get_layer_surface(
let ls_surface = compositor.zwlr_layershell_v1().unwrap().get_layer_surface(
&wl_surface.inner.wl_surface.borrow(),
None,
config.layer,
Expand Down Expand Up @@ -273,7 +273,12 @@ impl Surface {
.borrow_mut()
.preferred
.get_or_insert(o.name.clone());
handle.inner.output.borrow_mut().current.get_or_insert(o);
handle
.inner
.output
.borrow_mut()
.current
.get_or_insert(o.clone());
}
handle.inner.ls_surface.borrow().destroy();
handle.inner.available.replace(false);
Expand Down Expand Up @@ -320,15 +325,18 @@ impl Outputs for Surface {
.wl_surface
.replace(surface::Surface::replace(&sdata));
let sdata = self.inner.wl_surface.borrow().inner.clone();
let replacedlayershell =
self.inner
.ls_surface
.replace(sdata.compositor.zwlr_layershell_v1().get_layer_surface(
let replacedlayershell = self.inner.ls_surface.replace(
sdata
.compositor
.zwlr_layershell_v1()
.unwrap()
.get_layer_surface(
&self.inner.wl_surface.borrow().inner.wl_surface.borrow(),
None,
self.inner.config.layer,
self.inner.config.namespace.to_string(),
));
),
);

Surface::initialize(self);
replacedlayershell.destroy();
Expand Down
20 changes: 6 additions & 14 deletions druid-shell/src/backend/wayland/surfaces/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use wayland_client::protocol::wl_shm::WlShm;
use wayland_client::{self as wlc, protocol::wl_surface::WlSurface};
use wayland_protocols::unstable::xdg_decoration::v1::client::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1;
use wayland_protocols::wlr::unstable::layer_shell::v1::client::zwlr_layer_shell_v1::ZwlrLayerShellV1;
use wayland_protocols::xdg_shell::client::xdg_popup;
use wayland_protocols::xdg_shell::client::xdg_positioner;
Expand Down Expand Up @@ -29,8 +28,7 @@ pub trait Compositor {
fn get_xdg_surface(&self, surface: &wlc::Main<WlSurface>)
-> wlc::Main<xdg_surface::XdgSurface>;
fn get_xdg_positioner(&self) -> wlc::Main<xdg_positioner::XdgPositioner>;
fn zxdg_decoration_manager_v1(&self) -> wlc::Main<ZxdgDecorationManagerV1>;
fn zwlr_layershell_v1(&self) -> wlc::Main<ZwlrLayerShellV1>;
fn zwlr_layershell_v1(&self) -> Option<wlc::Main<ZwlrLayerShellV1>>;
}

pub trait Decor {
Expand Down Expand Up @@ -157,19 +155,13 @@ impl Compositor for CompositorHandle {
}
}

fn zxdg_decoration_manager_v1(&self) -> wlc::Main<ZxdgDecorationManagerV1> {
fn zwlr_layershell_v1(&self) -> Option<wlc::Main<ZwlrLayerShellV1>> {
match self.inner.upgrade() {
None => {
panic!("unable to acquire underyling compositor to acquire the decoration manager")
}
Some(c) => c.zxdg_decoration_manager_v1(),
}
}

fn zwlr_layershell_v1(&self) -> wlc::Main<ZwlrLayerShellV1> {
match self.inner.upgrade() {
None => {
panic!("unable to acquire underyling compositor to acquire the layershell manager")
tracing::warn!(
"unable to acquire underyling compositor to acquire the layershell manager"
);
None
}
Some(c) => c.zwlr_layershell_v1(),
}
Expand Down
17 changes: 1 addition & 16 deletions druid-shell/src/backend/wayland/surfaces/toplevel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use wayland_client as wlc;
use wayland_protocols::unstable::xdg_decoration::v1::client::zxdg_toplevel_decoration_v1 as toplevel_decorations;
use wayland_protocols::xdg_shell::client::xdg_surface;
use wayland_protocols::xdg_shell::client::xdg_toplevel;

Expand All @@ -17,12 +16,8 @@ use super::Popup;

struct Inner {
wl_surface: surface::Surface,
#[allow(unused)]
pub(super) xdg_surface: wlc::Main<xdg_surface::XdgSurface>,
pub(super) xdg_toplevel: wlc::Main<xdg_toplevel::XdgToplevel>,
#[allow(unused)]
pub(super) zxdg_toplevel_decoration_v1:
wlc::Main<toplevel_decorations::ZxdgToplevelDecorationV1>,
}

impl From<Inner> for std::sync::Arc<surface::Data> {
Expand All @@ -47,9 +42,6 @@ impl Surface {
let wl_surface = surface::Surface::new(compositor.clone(), handler, kurbo::Size::ZERO);
let xdg_surface = compositor.get_xdg_surface(&wl_surface.inner.wl_surface.borrow());
let xdg_toplevel = xdg_surface.get_toplevel();
let zxdg_toplevel_decoration_v1 = compositor
.zxdg_decoration_manager_v1()
.get_toplevel_decoration(&xdg_toplevel);

// register to receive xdg_surface events.
xdg_surface.quick_assign({
Expand All @@ -66,6 +58,7 @@ impl Surface {
}
}
});

xdg_toplevel.quick_assign({
let wl_surface = wl_surface.clone();
let mut dim = initial_size;
Expand Down Expand Up @@ -97,20 +90,12 @@ impl Surface {
}
});

zxdg_toplevel_decoration_v1.quick_assign(move |_zxdg_toplevel_decoration_v1, event, _| {
tracing::info!("toplevel decoration unimplemented {:?}", event);
});

let inner = Inner {
wl_surface,
xdg_toplevel,
xdg_surface,
zxdg_toplevel_decoration_v1,
};

inner
.zxdg_toplevel_decoration_v1
.set_mode(toplevel_decorations::Mode::ServerSide);
if let Some(size) = min_size {
inner
.xdg_toplevel
Expand Down

0 comments on commit 4902c26

Please sign in to comment.