mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
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.
This commit is contained in:
@@ -10,7 +10,7 @@ use niri::render_helpers::{RenderTarget, SplitElements};
|
||||
use niri::window::ResolvedWindowRules;
|
||||
use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
|
||||
use smithay::backend::renderer::element::{Id, Kind};
|
||||
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};
|
||||
|
||||
@@ -199,7 +199,7 @@ impl LayoutElement for TestWindow {
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
+6
-6
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+29
-12
@@ -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,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+16
-1
@@ -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")?;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user