Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Xwayland support for anvil #254

Merged
merged 6 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ udev = { version = "0.5", optional = true }
wayland-commons = { version = "0.28", optional = true }
wayland-egl = { version = "0.28", optional = true }
wayland-protocols = { version = "0.28", features = ["unstable_protocols", "server"], optional = true }
wayland-server = { version = "0.28", optional = true }
wayland-server = { version = "0.28.3", optional = true }
wayland-sys = { version = "0.28", optional = true }
winit = { version = "0.23.0", optional = true }
xkbcommon = "0.4.0"
Expand Down
9 changes: 8 additions & 1 deletion anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ path = ".."
default-features = false
features = [ "renderer_glium", "backend_egl", "wayland_frontend" ]

[dependencies.x11rb]
optional = true
version = "0.7"
default-features = false
features = [ "composite" ]

[build-dependencies]
gl_generator = "0.14"

[features]
default = [ "winit", "egl", "udev", "logind" ]
default = [ "winit", "egl", "udev", "logind", "xwayland" ]
egl = [ "smithay/use_system_lib" ]
winit = [ "smithay/backend_winit" ]
udev = [ "smithay/backend_libinput", "smithay/backend_udev", "smithay/backend_drm_atomic", "smithay/backend_drm_legacy", "smithay/backend_drm_gbm", "smithay/backend_drm_eglstream", "smithay/backend_drm_egl", "smithay/backend_session", "input" ]
logind = [ "smithay/backend_session_logind" ]
elogind = ["logind", "smithay/backend_session_elogind" ]
xwayland = [ "smithay/xwayland", "x11rb" ]
test_all_features = ["default"]
2 changes: 2 additions & 0 deletions anvil/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ mod udev;
mod window_map;
#[cfg(feature = "winit")]
mod winit;
#[cfg(feature = "xwayland")]
mod xwayland;

use state::AnvilState;

Expand Down
20 changes: 20 additions & 0 deletions anvil/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,25 @@ use crate::{
window_map::{Kind as SurfaceKind, WindowMap},
};

#[cfg(feature = "xwayland")]
use crate::xwayland::X11SurfaceRole;

// The xwayland feature only adds a X11Surface role, but the macro does not support #[cfg]
#[cfg(not(feature = "xwayland"))]
define_roles!(Roles =>
[ XdgSurface, XdgSurfaceRole ]
[ ShellSurface, ShellSurfaceRole]
[ DnDIcon, DnDIconRole ]
[ CursorImage, CursorImageRole ]
);
#[cfg(feature = "xwayland")]
define_roles!(Roles =>
[ XdgSurface, XdgSurfaceRole ]
[ ShellSurface, ShellSurfaceRole]
[ X11Surface, X11SurfaceRole ]
[ DnDIcon, DnDIconRole ]
[ CursorImage, CursorImageRole ]
);

pub type MyWindowMap = WindowMap<Roles>;

Expand Down Expand Up @@ -219,6 +232,10 @@ impl PointerGrab for ResizeSurfaceGrab {
(self.last_window_size.0 as u32, self.last_window_size.1 as u32),
self.edges.into(),
),
#[cfg(feature = "xwayland")]
SurfaceKind::X11(_) => {
// TODO: What to do here? Send the update via X11?
}
}
}

Expand Down Expand Up @@ -768,6 +785,9 @@ fn surface_commit(
buffer_utils: &BufferUtils,
window_map: &RefCell<MyWindowMap>,
) {
#[cfg(feature = "xwayland")]
super::xwayland::commit_hook(surface);

let mut geometry = None;
let mut min_size = (0, 0);
let mut max_size = (0, 0);
Expand Down
19 changes: 19 additions & 0 deletions anvil/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ use smithay::{

#[cfg(feature = "udev")]
use smithay::backend::session::{auto::AutoSession, Session};
#[cfg(feature = "xwayland")]
use smithay::xwayland::XWayland;

#[cfg(feature = "udev")]
use crate::udev::MyOutput;
#[cfg(feature = "xwayland")]
use crate::xwayland::XWm;
use crate::{buffer_utils::BufferUtils, shell::init_shell};

pub struct AnvilState {
Expand All @@ -51,6 +55,8 @@ pub struct AnvilState {
pub session: Option<AutoSession>,
// things we must keep alive
_wayland_event_source: Source<Generic<Fd>>,
#[cfg(feature = "xwayland")]
_xwayland: XWayland<XWm>,
}

impl AnvilState {
Expand Down Expand Up @@ -153,6 +159,17 @@ impl AnvilState {
})
.expect("Failed to initialize the keyboard");

#[cfg(feature = "xwayland")]
let _xwayland = {
let xwm = XWm::new(
handle.clone(),
shell_handles.token,
shell_handles.window_map.clone(),
log.clone(),
);
XWayland::init(xwm, handle.clone(), display.clone(), &mut (), log.clone()).unwrap()
};

AnvilState {
running: Arc::new(AtomicBool::new(true)),
display,
Expand All @@ -172,6 +189,8 @@ impl AnvilState {
#[cfg(feature = "udev")]
session,
_wayland_event_source,
#[cfg(feature = "xwayland")]
_xwayland,
}
}
}
12 changes: 12 additions & 0 deletions anvil/src/window_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ use smithay::{
};

use crate::shell::SurfaceData;
#[cfg(feature = "xwayland")]
use crate::xwayland::X11Surface;

pub enum Kind<R> {
Xdg(ToplevelSurface<R>),
Wl(ShellSurface<R>),
#[cfg(feature = "xwayland")]
X11(X11Surface),
}

// We implement Clone manually because #[derive(..)] would require R: Clone.
Expand All @@ -25,6 +29,8 @@ impl<R> Clone for Kind<R> {
match self {
Kind::Xdg(xdg) => Kind::Xdg(xdg.clone()),
Kind::Wl(wl) => Kind::Wl(wl.clone()),
#[cfg(feature = "xwayland")]
Kind::X11(x11) => Kind::X11(x11.clone()),
}
}
}
Expand All @@ -37,12 +43,16 @@ where
match *self {
Kind::Xdg(ref t) => t.alive(),
Kind::Wl(ref t) => t.alive(),
#[cfg(feature = "xwayland")]
Kind::X11(ref t) => t.alive(),
}
}
pub fn get_surface(&self) -> Option<&wl_surface::WlSurface> {
match *self {
Kind::Xdg(ref t) => t.get_surface(),
Kind::Wl(ref t) => t.get_surface(),
#[cfg(feature = "xwayland")]
Kind::X11(ref t) => t.get_surface(),
}
}

Expand All @@ -51,6 +61,8 @@ where
match (self, other) {
(Kind::Xdg(a), Kind::Xdg(b)) => a.equals(b),
(Kind::Wl(a), Kind::Wl(b)) => a.equals(b),
#[cfg(feature = "xwayland")]
(Kind::X11(a), Kind::X11(b)) => a.equals(b),
_ => false,
}
}
Expand Down
Loading