diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-05-29 13:32:11 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-06-10 18:08:00 +0300 |
| commit | e3406ac2556c7f68cd00f11b5856222dcce7f680 (patch) | |
| tree | 06926e2b098d98b780345569bdfbf56a92c3c392 /src | |
| parent | 22a948cc759498923c1e9806580962cdd2d7b3e2 (diff) | |
| download | niri-e3406ac2556c7f68cd00f11b5856222dcce7f680.tar.gz niri-e3406ac2556c7f68cd00f11b5856222dcce7f680.tar.bz2 niri-e3406ac2556c7f68cd00f11b5856222dcce7f680.zip | |
Signal fractional scale to clients
Doesn't do anything yet because we don't bind the fractional scale
manager and don't allow fractional scales.
Diffstat (limited to 'src')
| -rw-r--r-- | src/handlers/compositor.rs | 10 | ||||
| -rw-r--r-- | src/handlers/layer_shell.rs | 7 | ||||
| -rw-r--r-- | src/handlers/mod.rs | 12 | ||||
| -rw-r--r-- | src/handlers/xdg_shell.rs | 9 | ||||
| -rw-r--r-- | src/layout/mod.rs | 6 | ||||
| -rw-r--r-- | src/layout/workspace.rs | 9 | ||||
| -rw-r--r-- | src/niri.rs | 41 | ||||
| -rw-r--r-- | src/utils/mod.rs | 17 | ||||
| -rw-r--r-- | src/window/mapped.rs | 12 |
9 files changed, 76 insertions, 47 deletions
diff --git a/src/handlers/compositor.rs b/src/handlers/compositor.rs index 0d64faa3..845b720d 100644 --- a/src/handlers/compositor.rs +++ b/src/handlers/compositor.rs @@ -8,9 +8,8 @@ use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::reexports::wayland_server::{Client, Resource}; use smithay::wayland::buffer::BufferHandler; use smithay::wayland::compositor::{ - add_blocker, add_pre_commit_hook, get_parent, is_sync_subsurface, send_surface_state, - with_states, BufferAssignment, CompositorClientState, CompositorHandler, CompositorState, - SurfaceAttributes, + add_blocker, add_pre_commit_hook, get_parent, is_sync_subsurface, with_states, + BufferAssignment, CompositorClientState, CompositorHandler, CompositorState, SurfaceAttributes, }; use smithay::wayland::dmabuf::get_dmabuf; use smithay::wayland::shell::xdg::XdgToplevelSurfaceData; @@ -19,6 +18,7 @@ use smithay::{delegate_compositor, delegate_shm}; use super::xdg_shell::add_mapped_toplevel_pre_commit_hook; use crate::niri::{ClientState, State}; +use crate::utils::send_scale_transform; use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped}; impl CompositorHandler for State { @@ -37,10 +37,10 @@ impl CompositorHandler for State { } if let Some(output) = self.niri.output_for_root(&root) { - let scale = output.current_scale().integer_scale(); + let scale = output.current_scale(); let transform = output.current_transform(); with_states(surface, |data| { - send_surface_state(surface, data, scale, transform); + send_scale_transform(surface, data, scale, transform); }); } } diff --git a/src/handlers/layer_shell.rs b/src/handlers/layer_shell.rs index 7862a9fe..ae4ffe66 100644 --- a/src/handlers/layer_shell.rs +++ b/src/handlers/layer_shell.rs @@ -3,7 +3,7 @@ use smithay::desktop::{layer_map_for_output, LayerSurface, PopupKind, WindowSurf use smithay::output::Output; use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; -use smithay::wayland::compositor::{send_surface_state, with_states}; +use smithay::wayland::compositor::with_states; use smithay::wayland::shell::wlr_layer::{ Layer, LayerSurface as WlrLayerSurface, LayerSurfaceData, WlrLayerShellHandler, WlrLayerShellState, @@ -11,6 +11,7 @@ use smithay::wayland::shell::wlr_layer::{ use smithay::wayland::shell::xdg::PopupSurface; use crate::niri::State; +use crate::utils::send_scale_transform; impl WlrLayerShellHandler for State { fn shell_state(&mut self) -> &mut WlrLayerShellState { @@ -103,10 +104,10 @@ impl State { .layer_for_surface(surface, WindowSurfaceType::TOPLEVEL) .unwrap(); - let scale = output.current_scale().integer_scale(); + let scale = output.current_scale(); let transform = output.current_transform(); with_states(surface, |data| { - send_surface_state(surface, data, scale, transform); + send_scale_transform(surface, data, scale, transform); }); layer.layer_surface().send_configure(); diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 8ee34c70..0a4ce334 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -22,7 +22,7 @@ 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::utils::{Logical, Rectangle, Size}; -use smithay::wayland::compositor::{send_surface_state, with_states}; +use smithay::wayland::compositor::with_states; use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier}; use smithay::wayland::drm_lease::{ DrmLease, DrmLeaseBuilder, DrmLeaseHandler, DrmLeaseRequest, DrmLeaseState, LeaseRejected, @@ -67,7 +67,7 @@ use crate::protocols::foreign_toplevel::{ }; use crate::protocols::gamma_control::{GammaControlHandler, GammaControlManagerState}; use crate::protocols::screencopy::{Screencopy, ScreencopyHandler}; -use crate::utils::output_size; +use crate::utils::{output_size, send_scale_transform}; use crate::{delegate_foreign_toplevel, delegate_gamma_control, delegate_screencopy}; impl SeatHandler for State { @@ -140,11 +140,11 @@ impl InputMethodHandler for State { fn new_popup(&mut self, surface: PopupSurface) { let popup = PopupKind::InputMethod(surface); if let Some(output) = self.output_for_popup(&popup) { - let scale = output.current_scale().integer_scale(); + let scale = output.current_scale(); let transform = output.current_transform(); let wl_surface = popup.wl_surface(); with_states(wl_surface, |data| { - send_surface_state(wl_surface, data, scale, transform); + send_scale_transform(wl_surface, data, scale, transform); }); } @@ -307,11 +307,11 @@ pub fn configure_lock_surface(surface: &LockSurface, output: &Output) { let size = output_size(output); states.size = Some(Size::from((size.w as u32, size.h as u32))); }); - let scale = output.current_scale().integer_scale(); + let scale = output.current_scale(); let transform = output.current_transform(); let wl_surface = surface.wl_surface(); with_states(wl_surface, |data| { - send_surface_state(wl_surface, data, scale, transform); + send_scale_transform(wl_surface, data, scale, transform); }); surface.send_configure(); } diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index 879bd1b0..c1e29ea4 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -14,8 +14,7 @@ use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::reexports::wayland_server::Resource; use smithay::utils::{Logical, Rectangle, Serial}; use smithay::wayland::compositor::{ - add_pre_commit_hook, send_surface_state, with_states, BufferAssignment, HookId, - SurfaceAttributes, + add_pre_commit_hook, with_states, BufferAssignment, HookId, SurfaceAttributes, }; use smithay::wayland::input_method::InputMethodSeat; use smithay::wayland::shell::kde::decoration::{KdeDecorationHandler, KdeDecorationState}; @@ -34,7 +33,7 @@ use crate::input::resize_grab::ResizeGrab; use crate::input::DOUBLE_CLICK_TIME; use crate::layout::workspace::ColumnWidth; use crate::niri::{PopupGrabState, State}; -use crate::utils::{get_monotonic_time, ResizeEdge}; +use crate::utils::{get_monotonic_time, send_scale_transform, ResizeEdge}; use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef}; impl XdgShellHandler for State { @@ -734,10 +733,10 @@ impl State { if !initial_configure_sent { if let Some(output) = self.output_for_popup(&PopupKind::Xdg(popup.clone())) { - let scale = output.current_scale().integer_scale(); + let scale = output.current_scale(); let transform = output.current_transform(); with_states(surface, |data| { - send_surface_state(surface, data, scale, transform); + send_scale_transform(surface, data, scale, transform); }); } popup.send_configure().expect("initial configure failed"); diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 05c1550c..e8e00609 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -41,7 +41,7 @@ use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement; use smithay::backend::renderer::element::texture::TextureBuffer; use smithay::backend::renderer::element::Id; use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; -use smithay::output::Output; +use smithay::output::{self, Output}; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::utils::{Logical, Point, Scale, Serial, Size, Transform}; @@ -146,7 +146,7 @@ pub trait LayoutElement { fn max_size(&self) -> Size<i32, Logical>; fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool; fn has_ssd(&self) -> bool; - fn set_preferred_scale_transform(&self, scale: i32, transform: Transform); + fn set_preferred_scale_transform(&self, scale: output::Scale, transform: Transform); fn output_enter(&self, output: &Output); fn output_leave(&self, output: &Output); fn set_offscreen_element_id(&self, id: Option<Id>); @@ -2487,7 +2487,7 @@ mod tests { false } - fn set_preferred_scale_transform(&self, _scale: i32, _transform: Transform) {} + fn set_preferred_scale_transform(&self, _scale: output::Scale, _transform: Transform) {} fn has_ssd(&self) -> bool { false diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index d18f37e0..3b74f159 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -11,7 +11,6 @@ use smithay::output::Output; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size}; -use smithay::wayland::compositor::send_surface_state; use super::closing_window::{ClosingWindow, ClosingWindowRenderElement}; use super::tile::{Tile, TileRenderElement}; @@ -22,7 +21,7 @@ use crate::niri_render_elements; use crate::render_helpers::renderer::NiriRenderer; use crate::render_helpers::RenderTarget; use crate::utils::id::IdCounter; -use crate::utils::{output_size, ResizeEdge}; +use crate::utils::{output_size, send_scale_transform, ResizeEdge}; use crate::window::ResolvedWindowRules; /// Amount of touchpad movement to scroll the view for the width of one working area. @@ -587,10 +586,10 @@ impl<W: LayoutElement> Workspace<W> { rules: &ResolvedWindowRules, ) { if let Some(output) = self.output.as_ref() { - let scale = output.current_scale().integer_scale(); + let scale = output.current_scale(); let transform = output.current_transform(); window.with_surfaces(|surface, data| { - send_surface_state(surface, data, scale, transform); + send_scale_transform(surface, data, scale, transform); }); } @@ -3389,7 +3388,7 @@ fn compute_new_view_offset( fn set_preferred_scale_transform(window: &impl LayoutElement, output: &Output) { // FIXME: cache this on the workspace. - let scale = output.current_scale().integer_scale(); + let scale = output.current_scale(); let transform = output.current_transform(); window.set_preferred_scale_transform(scale, transform); } diff --git a/src/niri.rs b/src/niri.rs index c03edd19..8e9e11bd 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -62,8 +62,8 @@ use smithay::utils::{ SERIAL_COUNTER, }; use smithay::wayland::compositor::{ - send_surface_state, with_states, with_surface_tree_downward, CompositorClientState, - CompositorState, SurfaceData, TraversalAction, + with_states, with_surface_tree_downward, CompositorClientState, CompositorState, SurfaceData, + TraversalAction, }; use smithay::wayland::cursor_shape::CursorShapeManagerState; use smithay::wayland::dmabuf::DmabufState; @@ -127,7 +127,7 @@ use crate::utils::scale::guess_monitor_scale; use crate::utils::spawning::CHILD_ENV; use crate::utils::{ center, center_f64, get_monotonic_time, ipc_transform_to_smithay, logical_output, - make_screenshot_path, output_size, write_png_rgba8, + make_screenshot_path, output_size, send_scale_transform, write_png_rgba8, }; use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef}; use crate::{animation, niri_render_elements}; @@ -2359,9 +2359,9 @@ impl Niri { // 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 cursor_scale = 1.; let mut cursor_transform = Transform::Normal; - let mut dnd_scale = 1; + let mut dnd_scale = 1.; let mut dnd_transform = Transform::Normal; for output in self.global_space.outputs() { let geo = self.global_space.output_geometry(output).unwrap(); @@ -2369,7 +2369,8 @@ impl Niri { // 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()); + cursor_scale = + f64::max(cursor_scale, output.current_scale().fractional_scale()); // FIXME: using the largest overlapping or "primary" output transform would // make more sense here. cursor_transform = output.current_transform(); @@ -2382,7 +2383,8 @@ impl Niri { if let Some((surface, bbox)) = dnd { if let Some(mut overlap) = geo.intersection(bbox) { overlap.loc -= surface_pos; - dnd_scale = dnd_scale.max(output.current_scale().integer_scale()); + dnd_scale = + f64::max(dnd_scale, output.current_scale().fractional_scale()); // FIXME: using the largest overlapping or "primary" output transform // would make more sense here. dnd_transform = output.current_transform(); @@ -2394,11 +2396,21 @@ impl Niri { } with_states(surface, |data| { - send_surface_state(surface, data, cursor_scale, cursor_transform); + send_scale_transform( + surface, + data, + output::Scale::Fractional(cursor_scale), + cursor_transform, + ) }); if let Some((surface, _)) = dnd { with_states(surface, |data| { - send_surface_state(surface, data, dnd_scale, dnd_transform); + send_scale_transform( + surface, + data, + output::Scale::Fractional(dnd_scale), + dnd_transform, + ); }); } } @@ -2414,7 +2426,7 @@ impl Niri { Default::default() }; - let mut dnd_scale = 1; + let mut dnd_scale = 1.; let mut dnd_transform = Transform::Normal; for output in self.global_space.outputs() { let geo = self.global_space.output_geometry(output).unwrap(); @@ -2436,7 +2448,7 @@ impl Niri { if let Some(mut overlap) = geo.intersection(bbox) { overlap.loc -= surface_pos; - dnd_scale = dnd_scale.max(output.current_scale().integer_scale()); + dnd_scale = f64::max(dnd_scale, output.current_scale().fractional_scale()); // FIXME: using the largest overlapping or "primary" output transform would // make more sense here. dnd_transform = output.current_transform(); @@ -2447,7 +2459,12 @@ impl Niri { } with_states(surface, |data| { - send_surface_state(surface, data, dnd_scale, dnd_transform); + send_scale_transform( + surface, + data, + output::Scale::Fractional(dnd_scale), + dnd_transform, + ); }); } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index f523d960..7d41b923 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -12,10 +12,13 @@ use directories::UserDirs; use git_version::git_version; use niri_config::Config; use smithay::input::pointer::CursorIcon; -use smithay::output::Output; +use smithay::output::{self, Output}; use smithay::reexports::rustix::time::{clock_gettime, ClockId}; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; +use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::utils::{Logical, Point, Rectangle, Size, Transform}; +use smithay::wayland::compositor::{send_surface_state, SurfaceData}; +use smithay::wayland::fractional_scale::with_fractional_scale; pub mod id; pub mod scale; @@ -133,6 +136,18 @@ pub fn ipc_transform_to_smithay(transform: niri_ipc::Transform) -> Transform { } } +pub fn send_scale_transform( + surface: &WlSurface, + data: &SurfaceData, + scale: output::Scale, + transform: Transform, +) { + send_surface_state(surface, data, scale.integer_scale(), transform); + with_fractional_scale(data, |fractional| { + fractional.set_preferred_scale(scale.fractional_scale()); + }); +} + pub fn expand_home(path: &Path) -> anyhow::Result<Option<PathBuf>> { if let Ok(rest) = path.strip_prefix("~") { let dirs = UserDirs::new().context("error retrieving home directory")?; diff --git a/src/window/mapped.rs b/src/window/mapped.rs index 4864d62e..8e495e70 100644 --- a/src/window/mapped.rs +++ b/src/window/mapped.rs @@ -9,14 +9,12 @@ use smithay::backend::renderer::element::{Id, Kind}; use smithay::backend::renderer::gles::GlesRenderer; use smithay::desktop::space::SpaceElement as _; use smithay::desktop::{PopupManager, Window}; -use smithay::output::Output; +use smithay::output::{self, 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::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform}; -use smithay::wayland::compositor::{ - remove_pre_commit_hook, send_surface_state, with_states, HookId, -}; +use smithay::wayland::compositor::{remove_pre_commit_hook, with_states, HookId}; use smithay::wayland::shell::xdg::{SurfaceCachedState, ToplevelSurface}; use super::{ResolvedWindowRules, WindowRef}; @@ -28,7 +26,7 @@ use crate::render_helpers::renderer::NiriRenderer; use crate::render_helpers::snapshot::RenderSnapshot; use crate::render_helpers::surface::render_snapshot_from_surface_tree; use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; -use crate::utils::ResizeEdge; +use crate::utils::{send_scale_transform, ResizeEdge}; #[derive(Debug)] pub struct Mapped { @@ -427,9 +425,9 @@ impl LayoutElement for Mapped { self.toplevel().wl_surface() == wl_surface } - fn set_preferred_scale_transform(&self, scale: i32, transform: Transform) { + fn set_preferred_scale_transform(&self, scale: output::Scale, transform: Transform) { self.window.with_surfaces(|surface, data| { - send_surface_state(surface, data, scale, transform); + send_scale_transform(surface, data, scale, transform); }); } |
