Skip to content

Commit

Permalink
Add support for wl_compositor@v6
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov committed Oct 25, 2023
1 parent 64ac316 commit f3b7bb8
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 34 deletions.
30 changes: 14 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ xcursor = "0.3.4"
zbus = { version = "3.14.1", optional = true }

[dependencies.smithay]
git = "https://github.com/Smithay/smithay.git"
git = "https://github.com/kchibisov/smithay.git"
branch = "compositor-version"
# path = "../smithay"
default-features = false
features = [
Expand All @@ -53,7 +54,8 @@ features = [
]

[dependencies.smithay-drm-extras]
git = "https://github.com/Smithay/smithay.git"
git = "https://github.com/kchibisov/smithay.git"
branch = "compositor-version"
# path = "../smithay/smithay-drm-extras"

[dev-dependencies]
Expand Down
5 changes: 2 additions & 3 deletions src/backend/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,6 @@ impl Tty {
.map(|info| (info.manufacturer, info.model))
.unwrap_or_else(|| ("Unknown".into(), "Unknown".into()));

let scale = config.scale.clamp(0.1, 10.);
let scale = scale.max(1.).round() as i32;

let output = Output::new(
output_name.clone(),
PhysicalProperties {
Expand All @@ -539,7 +536,9 @@ impl Tty {
make,
},
);

let wl_mode = Mode::from(*mode);
let scale = config.scale.clamp(1., 10.).ceil() as i32;
output.change_current_state(Some(wl_mode), None, Some(Scale::Integer(scale)), None);
output.set_preferred(wl_mode);

Expand Down
13 changes: 6 additions & 7 deletions src/backend/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ impl Winit {
.find(|o| o.name == "winit")
.cloned()
.unwrap_or_default();
let scale = output_config.scale.clamp(0.1, 10.);
let scale = scale.max(1.).round() as i32;

let mode = Mode {
size: backend.window_size(),
refresh: 60_000,
};

let output = Output::new(
"winit".to_string(),
Expand All @@ -62,6 +55,12 @@ impl Winit {
model: "Winit".into(),
},
);

let mode = Mode {
size: backend.window_size(),
refresh: 60_000,
};
let scale = output_config.scale.clamp(1., 10.).ceil() as i32;
output.change_current_state(
Some(mode),
Some(Transform::Flipped180),
Expand Down
6 changes: 6 additions & 0 deletions src/handlers/layer_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use smithay::desktop::{layer_map_for_output, LayerSurface, WindowSurfaceType};
use smithay::output::Output;
use smithay::reexports::wayland_server::protocol::wl_output::WlOutput;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::reexports::wayland_server::Resource;
use smithay::wayland::compositor::with_states;
use smithay::wayland::shell::wlr_layer::{
Layer, LayerSurface as WlrLayerSurface, LayerSurfaceData, WlrLayerShellHandler,
Expand Down Expand Up @@ -92,6 +93,11 @@ impl State {
.layer_for_surface(surface, WindowSurfaceType::TOPLEVEL)
.unwrap();

if surface.version() >= 6 {
surface.preferred_buffer_scale(output.current_scale().integer_scale());
surface.preferred_buffer_transform(output.current_transform().into());
}

layer.layer_surface().send_configure();
}
drop(map);
Expand Down
16 changes: 14 additions & 2 deletions src/handlers/xdg_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{se
use smithay::reexports::wayland_server::protocol::wl_output;
use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::reexports::wayland_server::Resource;
use smithay::utils::Serial;
use smithay::wayland::compositor::with_states;
use smithay::wayland::shell::kde::decoration::{KdeDecorationHandler, KdeDecorationState};
Expand Down Expand Up @@ -264,8 +265,19 @@ impl State {
.initial_configure_sent
});
if !initial_configure_sent {
// NOTE: This should never fail as the initial configure is always
// allowed.
if surface.version() >= 6 {
if let Some(output) = popup.get_parent_surface().and_then(|parent| {
self.niri
.layout
.find_window_and_output(&parent)
.map(|(_, output)| output)
}) {
surface
.preferred_buffer_scale(output.current_scale().integer_scale());
surface
.preferred_buffer_transform(output.current_transform().into());
}
}
popup.send_configure().expect("initial configure failed");
}
}
Expand Down
25 changes: 24 additions & 1 deletion src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ use smithay::output::Output;
use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::reexports::wayland_server::Resource;
use smithay::render_elements;
use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
use smithay::wayland::compositor::with_states;
use smithay::wayland::compositor::{with_states, SurfaceData};
use smithay::wayland::shell::xdg::SurfaceCachedState;

use crate::animation::Animation;
Expand All @@ -77,6 +78,7 @@ pub trait LayoutElement: SpaceElement + PartialEq + Clone {
fn max_size(&self) -> Size<i32, Logical>;
fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool;
fn has_ssd(&self) -> bool;
fn with_surfaces<F: FnMut(&WlSurface, &SurfaceData) + Copy>(&self, processor: F);
}

#[derive(Debug)]
Expand Down Expand Up @@ -333,6 +335,10 @@ impl LayoutElement for Window {
self.toplevel().wl_surface() == wl_surface
}

fn with_surfaces<F: FnMut(&WlSurface, &SurfaceData) + Copy>(&self, processor: F) {
self.with_surfaces(processor);
}

fn has_ssd(&self) -> bool {
self.toplevel().current_state().decoration_mode
== Some(zxdg_toplevel_decoration_v1::Mode::ServerSide)
Expand Down Expand Up @@ -1902,6 +1908,12 @@ impl<W: LayoutElement> Workspace<W> {

fn enter_output_for_window(&self, window: &W) {
if let Some(output) = &self.output {
window.with_surfaces(|surface, _| {
if surface.version() >= 6 {
surface.preferred_buffer_scale(output.current_scale().integer_scale());
surface.preferred_buffer_transform(output.current_transform().into());
}
});
// FIXME: proper overlap.
window.output_enter(
output,
Expand Down Expand Up @@ -1937,6 +1949,15 @@ impl<W: LayoutElement> Workspace<W> {

let bounds = self.toplevel_bounds();

if let Some(output) = self.output.as_ref() {
window.with_surfaces(|surface, _| {
if surface.version() >= 6 {
surface.preferred_buffer_scale(output.current_scale().integer_scale());
surface.preferred_buffer_transform(output.current_transform().into());
}
});
}

window.toplevel().with_pending_state(|state| {
state.size = Some(size);
state.bounds = Some(bounds);
Expand Down Expand Up @@ -2890,6 +2911,8 @@ mod tests {
false
}

fn with_surfaces<F: FnMut(&WlSurface, &SurfaceData) + Copy>(&self, _processor: F) {}

fn has_ssd(&self) -> bool {
false
}
Expand Down
21 changes: 18 additions & 3 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use smithay::reexports::wayland_server::backend::{
ClientData, ClientId, DisconnectReason, GlobalId,
};
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::reexports::wayland_server::{Display, DisplayHandle};
use smithay::reexports::wayland_server::{Display, DisplayHandle, Resource};
use smithay::utils::{
ClockSource, IsAlive, Logical, Monotonic, Physical, Point, Rectangle, Scale, Size, Transform,
SERIAL_COUNTER,
Expand Down Expand Up @@ -507,7 +507,7 @@ impl Niri {

let layout = Layout::new(&config_);

let compositor_state = CompositorState::new::<State>(&display_handle);
let compositor_state = CompositorState::new::<State, 6>(&display_handle);
let xdg_shell_state = XdgShellState::new_with_capabilities::<State>(
&display_handle,
[WmCapabilities::Fullscreen],
Expand Down Expand Up @@ -538,7 +538,7 @@ impl Niri {
|_| true,
);
let presentation_state =
PresentationState::new::<State>(&display_handle, Monotonic::id() as u32);
PresentationState::new::<State>(&display_handle, Monotonic::ID as u32);

let text_input_state = TextInputManagerState::new::<State>(&display_handle);
let input_method_state =
Expand Down Expand Up @@ -1194,12 +1194,17 @@ impl Niri {
.as_ref()
.map(|surface| (surface, bbox_from_surface_tree(surface, surface_pos)));

// FIXME we basically need to pick the largest scale factor across the overlapping
// outputs, this is how it's usually done in clients as well.
let mut cursor_scale = 1;
let mut dnd_scale = 1;
for output in self.global_space.outputs() {
let geo = self.global_space.output_geometry(output).unwrap();

// Compute pointer surface overlap.
if let Some(mut overlap) = geo.intersection(bbox) {
overlap.loc -= surface_pos;
cursor_scale = cursor_scale.max(output.current_scale().integer_scale());
output_update(output, Some(overlap), surface);
} else {
output_update(output, None, surface);
Expand All @@ -1209,12 +1214,22 @@ impl Niri {
if let Some((surface, bbox)) = dnd {
if let Some(mut overlap) = geo.intersection(bbox) {
overlap.loc -= surface_pos;
dnd_scale = cursor_scale.max(output.current_scale().integer_scale());
output_update(output, Some(overlap), surface);
} else {
output_update(output, None, surface);
}
}
}

if surface.version() >= 6 {
surface.preferred_buffer_scale(cursor_scale);
}
if let Some((surface, _)) = dnd {
if surface.version() >= 6 {
surface.preferred_buffer_scale(dnd_scale);
}
}
}
}
}
Expand Down

0 comments on commit f3b7bb8

Please sign in to comment.