1
0
Fork 0
forked from wry/wry

tree: update to latest version of wp_fractional_scale

This commit is contained in:
Julian Orth 2022-11-12 15:05:58 +01:00
parent e61d6ab074
commit 5b2eb5855a
22 changed files with 104 additions and 54 deletions

View file

@ -14,7 +14,6 @@ use {
clientmem::{self, ClientMemError},
config::ConfigProxy,
dbus::Dbus,
fixed::Fixed,
forker,
globals::Globals,
ifs::{wl_output::WlOutputGlobal, wl_surface::NoneSurfaceExt},
@ -22,6 +21,7 @@ use {
leaks,
logger::Logger,
render::{self, RenderError},
scale::Scale,
sighand::{self, SighandError},
state::{ConnectorData, IdleState, ScreenlockState, State, XWaylandState},
tasks::{self, idle},
@ -123,7 +123,7 @@ fn start_compositor2(
let (_run_toplevel_future, run_toplevel) = RunToplevel::install(&engine);
let node_ids = NodeIds::default();
let scales = RefCounted::default();
scales.add(Fixed::from_int(1));
scales.add(Scale::from_int(1));
let state = Rc::new(State {
xkb_ctx,
backend: CloneCell::new(Rc::new(DummyBackend)),
@ -389,7 +389,7 @@ fn create_dummy_output(state: &Rc<State>) {
scroll: Default::default(),
pointer_positions: Default::default(),
lock_surface: Default::default(),
preferred_scale: Cell::new(Fixed::from_int(1)),
preferred_scale: Cell::new(Scale::from_int(1)),
hardware_cursor: Default::default(),
update_render_data_scheduled: Cell::new(false),
screencasts: Default::default(),

View file

@ -7,8 +7,8 @@ use {
},
compositor::MAX_EXTENTS,
config::ConfigProxy,
fixed::Fixed,
ifs::wl_seat::{SeatId, WlSeatGlobal},
scale::Scale,
state::{ConnectorData, DeviceHandlerData, DrmDevData, OutputData, State},
theme::{Color, ThemeSized, DEFAULT_FONT},
tree::{ContainerNode, ContainerSplit, FloatNode, Node, NodeVisitorBase, OutputNode},
@ -654,7 +654,7 @@ impl ConfigProxyHandler {
if scale > 1000.0 {
return Err(CphError::ScaleTooLarge(scale));
}
let scale = Fixed::from_f64(scale);
let scale = Scale::from_f64(scale);
let connector = self.get_output(connector)?;
connector.node.set_preferred_scale(scale);
self.state.damage();

View file

@ -4,6 +4,7 @@ use {
format::ARGB8888,
rect::Rect,
render::{RenderContext, RenderError, Renderer, Texture},
scale::Scale,
state::State,
time::Time,
tree::OutputNode,
@ -41,7 +42,7 @@ const HEADER_SIZE: u32 = 16;
pub trait Cursor {
fn render(&self, renderer: &mut Renderer, x: Fixed, y: Fixed);
fn render_hardware_cursor(&self, renderer: &mut Renderer);
fn extents_at_scale(&self, scale: Fixed) -> Rect;
fn extents_at_scale(&self, scale: Scale) -> Rect;
fn set_output(&self, output: &Rc<OutputNode>) {
let _ = output;
}
@ -113,7 +114,7 @@ impl ServerCursors {
pub struct ServerCursorTemplate {
var: ServerCursorTemplateVariant,
pub xcursor: Vec<AHashMap<(Fixed, u32), Rc<XCursorImage>>>,
pub xcursor: Vec<AHashMap<(Scale, u32), Rc<XCursorImage>>>,
}
enum ServerCursorTemplateVariant {
@ -125,7 +126,7 @@ impl ServerCursorTemplate {
fn load(
name: &str,
theme: Option<&BStr>,
scales: &[Fixed],
scales: &[Scale],
sizes: &[u32],
paths: &[BString],
ctx: &Rc<RenderContext>,
@ -213,12 +214,12 @@ struct CursorImageScaled {
struct CursorImage {
delay_ns: u64,
sizes: SmallMapMut<(Fixed, u32), Rc<CursorImageScaled>, 2>,
sizes: SmallMapMut<(Scale, u32), Rc<CursorImageScaled>, 2>,
}
struct InstantiatedCursorImage {
delay_ns: u64,
scales: SmallMapMut<Fixed, Rc<CursorImageScaled>, 2>,
scales: SmallMapMut<Scale, Rc<CursorImageScaled>, 2>,
}
impl CursorImageScaled {
@ -240,7 +241,7 @@ impl CursorImageScaled {
impl CursorImage {
fn from_sizes(
delay_ms: u64,
sizes: SmallMapMut<(Fixed, u32), Rc<CursorImageScaled>, 2>,
sizes: SmallMapMut<(Scale, u32), Rc<CursorImageScaled>, 2>,
) -> Result<Self, CursorError> {
Ok(Self {
delay_ns: delay_ms.max(1) * 1_000_000,
@ -306,7 +307,7 @@ impl Cursor for StaticCursor {
}
}
fn extents_at_scale(&self, scale: Fixed) -> Rect {
fn extents_at_scale(&self, scale: Scale) -> Rect {
match self.image.scales.get(&scale) {
None => Rect::new_empty(0, 0),
Some(i) => i.extents,
@ -336,7 +337,7 @@ impl Cursor for AnimatedCursor {
}
}
fn extents_at_scale(&self, scale: Fixed) -> Rect {
fn extents_at_scale(&self, scale: Scale) -> Rect {
let img = &self.images[self.idx.get()];
match img.scales.get(&scale) {
None => Rect::new_empty(0, 0),
@ -368,13 +369,13 @@ impl Cursor for AnimatedCursor {
}
struct OpenCursorResult {
images: Vec<AHashMap<(Fixed, u32), Rc<XCursorImage>>>,
images: Vec<AHashMap<(Scale, u32), Rc<XCursorImage>>>,
}
fn open_cursor(
name: &str,
theme: Option<&BStr>,
scales: &[Fixed],
scales: &[Scale],
sizes: &[u32],
paths: &[BString],
) -> Result<OpenCursorResult, CursorError> {
@ -538,7 +539,7 @@ impl Debug for XCursorImage {
fn parser_cursor_file<R: BufRead + Seek>(
r: &mut R,
scales: &[Fixed],
scales: &[Scale],
sizes: &[u32],
) -> Result<OpenCursorResult, CursorError> {
let [magic, header] = read_u32_n(r)?;
@ -554,7 +555,7 @@ fn parser_cursor_file<R: BufRead + Seek>(
positions: Vec<u32>,
effective_size: u32,
size: u32,
scale: Fixed,
scale: Scale,
best_fit: i64,
}
let mut targets = Vec::new();

View file

@ -39,10 +39,6 @@ impl Fixed {
self.0 >> 8
}
pub fn round_up(self) -> i32 {
(self.0 + 255) >> 8
}
pub fn apply_fract(self, i: i32) -> Self {
Self((i << 8) | (self.0 & 255))
}

View file

@ -72,7 +72,7 @@ pub struct WlOutputGlobal {
pub unused_captures: LinkedList<Rc<ZwlrScreencopyFrameV1>>,
pub pending_captures: LinkedList<Rc<ZwlrScreencopyFrameV1>>,
pub destroyed: Cell<bool>,
pub legacy_scale: Cell<i32>,
pub legacy_scale: Cell<u32>,
}
#[derive(Eq, PartialEq)]
@ -316,7 +316,7 @@ impl WlOutput {
fn send_scale(self: &Rc<Self>) {
let event = Scale {
self_id: self.id,
factor: self.global.legacy_scale.get(),
factor: self.global.legacy_scale.get() as _,
};
self.client.event(event);
}

View file

@ -217,7 +217,7 @@ impl SurfaceRole {
}
}
pub struct SurfaceSendPreferredScaleVisitor(pub Fixed);
pub struct SurfaceSendPreferredScaleVisitor;
impl NodeVisitorBase for SurfaceSendPreferredScaleVisitor {
fn visit_surface(&mut self, node: &Rc<WlSurface>) {
node.send_preferred_scale();

View file

@ -6,6 +6,7 @@ use {
leaks::Tracker,
rect::Rect,
render::Renderer,
scale::Scale,
tree::{Node, NodeVisitorBase, OutputNode},
},
std::{cell::Cell, ops::Deref, rc::Rc},
@ -103,7 +104,7 @@ impl Cursor for CursorSurface {
FrameRequests.visit_surface(&self.surface);
}
fn extents_at_scale(&self, scale: Fixed) -> Rect {
fn extents_at_scale(&self, scale: Scale) -> Rect {
let rect = self.extents.get();
if scale == 1 {
return rect;

View file

@ -39,7 +39,7 @@ impl WpFractionalScaleV1 {
pub fn send_preferred_scale(&self) {
self.client.event(PreferredScale {
self_id: self.id,
scale: self.surface.output.get().preferred_scale.get(),
scale: self.surface.output.get().preferred_scale.get().0,
});
}

View file

@ -72,6 +72,7 @@ mod pipewire;
mod portal;
mod rect;
mod render;
mod scale;
mod screenshoter;
mod sighand;
mod state;

View file

@ -7,6 +7,7 @@ use {
ifs::zwlr_layer_shell_v1::OVERLAY,
portal::ptl_display::{PortalDisplay, PortalOutput, PortalSeat},
render::{Framebuffer, RenderContext, RendererBase, Texture},
scale::Scale,
text::{self, TextMeasurement},
theme::Color,
utils::{
@ -467,7 +468,7 @@ pub struct WindowData {
pub frame_missed: Cell<bool>,
pub first_scale: Cell<bool>,
pub have_frame: Cell<bool>,
pub scale: Cell<Fixed>,
pub scale: Cell<Scale>,
pub render_trigger: AsyncEvent,
pub render_task: Cell<Option<SpawnedFuture<()>>>,
pub dpy: Rc<PortalDisplay>,
@ -560,7 +561,7 @@ impl WindowData {
content: Default::default(),
surface,
viewport,
scale: Cell::new(Fixed::from_int(1)),
scale: Cell::new(Scale::from_int(1)),
fractional_scale,
seats: Default::default(),
});
@ -833,7 +834,8 @@ impl UsrWlBufferOwner for GuiBuffer {
impl UsrWpFractionalScaleOwner for WindowData {
fn preferred_scale(self: Rc<Self>, ev: &PreferredScale) {
let mut layout = self.first_scale.replace(false);
layout |= self.scale.replace(ev.scale) != ev.scale;
let scale = Scale(ev.scale);
layout |= self.scale.replace(scale) != scale;
if layout {
self.layout();
self.allocate_buffers();

View file

@ -16,6 +16,7 @@ use {
sys::{glBlendFunc, glFlush, glReadnPixels, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
RenderResult, Texture,
},
scale::Scale,
state::State,
tree::Node,
},
@ -61,7 +62,7 @@ impl Framebuffer {
glViewport(0, 0, self.gl.width, self.gl.height);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
let scale = Fixed::from_int(1);
let scale = Scale::from_int(1);
let mut renderer = Renderer {
base: RendererBase {
ctx: &self.ctx,
@ -114,7 +115,7 @@ impl Framebuffer {
});
}
pub fn render_custom(&self, scale: Fixed, f: impl FnOnce(&mut RendererBase)) {
pub fn render_custom(&self, scale: Scale, f: impl FnOnce(&mut RendererBase)) {
let _ = self.ctx.ctx.with_current(|| {
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, self.gl.fbo);
@ -143,7 +144,7 @@ impl Framebuffer {
cursor_rect: Option<Rect>,
on_output: bool,
result: &mut RenderResult,
scale: Fixed,
scale: Scale,
render_hardware_cursor: bool,
) {
let _ = self.ctx.ctx.with_current(|| {
@ -201,7 +202,7 @@ impl Framebuffer {
});
}
pub fn render_hardware_cursor(&self, cursor: &dyn Cursor, state: &State, scale: Fixed) {
pub fn render_hardware_cursor(&self, cursor: &dyn Cursor, state: &State, scale: Scale) {
let _ = self.ctx.ctx.with_current(|| {
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, self.gl.fbo);

View file

@ -1,6 +1,5 @@
use {
crate::{
fixed::Fixed,
format::ARGB8888,
ifs::{
wl_buffer::WlBuffer,
@ -12,6 +11,7 @@ use {
},
rect::Rect,
render::{gl::frame_buffer::with_scissor, renderer::renderer_base::RendererBase},
scale::Scale,
state::State,
theme::Color,
tree::{
@ -48,7 +48,7 @@ pub struct Renderer<'a> {
}
impl Renderer<'_> {
pub fn scale(&self) -> Fixed {
pub fn scale(&self) -> Scale {
self.base.scale
}

View file

@ -1,6 +1,5 @@
use {
crate::{
fixed::Fixed,
format::Format,
rect::Rect,
render::{
@ -18,6 +17,7 @@ use {
sys::{glClear, glClearColor, glDisable, glEnable, GL_BLEND, GL_COLOR_BUFFER_BIT},
Texture,
},
scale::Scale,
theme::Color,
utils::rc_eq::rc_eq,
},
@ -28,12 +28,12 @@ pub struct RendererBase<'a> {
pub(super) ctx: &'a Rc<RenderContext>,
pub(super) fb: &'a GlFrameBuffer,
pub(super) scaled: bool,
pub(super) scale: Fixed,
pub(super) scale: Scale,
pub(super) scalef: f64,
}
impl RendererBase<'_> {
pub fn scale(&self) -> Fixed {
pub fn scale(&self) -> Scale {
self.scale
}
@ -188,7 +188,7 @@ impl RendererBase<'_> {
format: &Format,
tpoints: Option<&[f32; 8]>,
tsize: Option<(i32, i32)>,
tscale: Fixed,
tscale: Scale,
) {
assert!(rc_eq(&self.ctx.ctx, &texture.ctx.ctx));
unsafe {

44
src/scale.rs Normal file
View file

@ -0,0 +1,44 @@
use std::fmt::{Debug, Display, Formatter};
const BASE: u32 = 120;
const BASEF: f64 = BASE as f64;
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(transparent)]
pub struct Scale(pub u32);
impl Scale {
pub fn from_int(f: u32) -> Self {
Self(f.saturating_mul(BASE))
}
pub fn from_f64(f: f64) -> Self {
Self((f * BASEF).round() as u32)
}
pub fn to_f64(self) -> f64 {
self.0 as f64 / BASEF
}
pub fn round_up(self) -> u32 {
self.0.saturating_add(BASE - 1) / BASE
}
}
impl PartialEq<u32> for Scale {
fn eq(&self, other: &u32) -> bool {
self.0 == other * BASE
}
}
impl Debug for Scale {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(&self.to_f64(), f)
}
}
impl Display for Scale {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.to_f64(), f)
}
}

View file

@ -1,8 +1,8 @@
use {
crate::{
fixed::Fixed,
format::XRGB8888,
render::RenderError,
scale::Scale,
state::State,
video::{
drm::DrmError,
@ -60,7 +60,7 @@ pub fn take_screenshot(state: &State) -> Result<Screenshot, ScreenshooterError>
Some(state.root.extents.get()),
false,
&mut Default::default(),
Fixed::from_int(1),
Scale::from_int(1),
true,
);
let drm = ctx.gbm.drm.dup_render()?.fd().clone();

View file

@ -12,7 +12,6 @@ use {
config::ConfigProxy,
cursor::{Cursor, ServerCursors},
dbus::Dbus,
fixed::Fixed,
forker::ForkerProxy,
globals::{Globals, GlobalsError, WaylandGlobal},
ifs::{
@ -33,6 +32,7 @@ use {
logger::Logger,
rect::Rect,
render::RenderContext,
scale::Scale,
theme::Theme,
tree::{
ContainerNode, ContainerSplit, Direction, DisplayNode, FloatNode, Node, NodeIds,
@ -116,7 +116,7 @@ pub struct State {
pub data_offer_ids: NumCell<u64>,
pub ring: Rc<IoUring>,
pub lock: ScreenlockState,
pub scales: RefCounted<Fixed>,
pub scales: RefCounted<Scale>,
pub cursor_sizes: RefCounted<u32>,
pub hardware_tick_cursor: AsyncQueue<Option<Rc<dyn Cursor>>>,
pub testers: RefCell<AHashMap<(ClientId, JaySeatEventsId), Rc<JaySeatEvents>>>,
@ -235,13 +235,13 @@ impl NodeVisitorBase for UpdateTextTexturesVisitor {
}
impl State {
pub fn add_output_scale(&self, scale: Fixed) {
pub fn add_output_scale(&self, scale: Scale) {
if self.scales.add(scale) {
self.output_scales_changed();
}
}
pub fn remove_output_scale(&self, scale: Fixed) {
pub fn remove_output_scale(&self, scale: Scale) {
if self.scales.remove(&scale) {
self.output_scales_changed();
}

View file

@ -1,8 +1,8 @@
use {
crate::{
backend::{Connector, ConnectorEvent, ConnectorId, MonitorInfo},
fixed::Fixed,
ifs::wl_output::WlOutputGlobal,
scale::Scale,
state::{ConnectorData, OutputData, State},
tree::{OutputNode, OutputRenderData},
utils::{asyncevent::AsyncEvent, clonecell::CloneCell},
@ -122,7 +122,7 @@ impl ConnectorHandler {
scroll: Default::default(),
pointer_positions: Default::default(),
lock_surface: Default::default(),
preferred_scale: Cell::new(Fixed::from_int(1)),
preferred_scale: Cell::new(Scale::from_int(1)),
hardware_cursor: Default::default(),
jay_outputs: Default::default(),
screencasts: Default::default(),

View file

@ -9,6 +9,7 @@ use {
},
rect::Rect,
render::{Renderer, Texture},
scale::Scale,
state::State,
text,
tree::{
@ -85,7 +86,7 @@ pub struct ContainerRenderData {
pub last_active_rect: Option<Rect>,
pub border_rects: Vec<Rect>,
pub underline_rects: Vec<Rect>,
pub titles: SmallMapMut<Fixed, Vec<ContainerTitle>, 2>,
pub titles: SmallMapMut<Scale, Vec<ContainerTitle>, 2>,
}
pub struct ContainerNode {

View file

@ -6,6 +6,7 @@ use {
ifs::wl_seat::{NodeSeatState, SeatId, WlSeatGlobal, BTN_LEFT},
rect::Rect,
render::{Renderer, Texture},
scale::Scale,
state::State,
text,
tree::{
@ -42,7 +43,7 @@ pub struct FloatNode {
pub layout_scheduled: Cell<bool>,
pub render_titles_scheduled: Cell<bool>,
pub title: RefCell<String>,
pub title_textures: CopyHashMap<Fixed, Rc<Texture>>,
pub title_textures: CopyHashMap<Scale, Rc<Texture>>,
seats: RefCell<AHashMap<SeatId, SeatState>>,
}

View file

@ -20,6 +20,7 @@ use {
},
rect::Rect,
render::{Framebuffer, Renderer, Texture},
scale::Scale,
state::State,
text,
tree::{
@ -57,7 +58,7 @@ pub struct OutputNode {
pub scroll: Scroller,
pub pointer_positions: CopyHashMap<SeatId, (i32, i32)>,
pub lock_surface: CloneCell<Option<Rc<ExtSessionLockSurfaceV1>>>,
pub preferred_scale: Cell<Fixed>,
pub preferred_scale: Cell<Scale>,
pub hardware_cursor: CloneCell<Option<Rc<dyn HardwareCursor>>>,
pub update_render_data_scheduled: Cell<bool>,
pub screencasts: CopyHashMap<(ClientId, JayScreencastId), Rc<JayScreencast>>,
@ -102,7 +103,7 @@ impl OutputNode {
}
}
pub fn set_preferred_scale(self: &Rc<Self>, scale: Fixed) {
pub fn set_preferred_scale(self: &Rc<Self>, scale: Scale) {
let old_scale = self.preferred_scale.replace(scale);
if scale == old_scale {
return;
@ -115,7 +116,7 @@ impl OutputNode {
self.state.add_output_scale(scale);
let rect = self.calculate_extents();
self.change_extents_(&rect);
let mut visitor = SurfaceSendPreferredScaleVisitor(scale);
let mut visitor = SurfaceSendPreferredScaleVisitor;
self.node_visit_children(&mut visitor);
for ws in self.workspaces.iter() {
for stacked in ws.stacked.iter() {

View file

@ -6,6 +6,7 @@ use {
ifs::wl_seat::{NodeSeatState, WlSeatGlobal},
rect::Rect,
render::{Renderer, Texture},
scale::Scale,
state::State,
text,
tree::{
@ -23,7 +24,7 @@ pub struct PlaceholderNode {
id: PlaceholderNodeId,
toplevel: ToplevelData,
destroyed: Cell<bool>,
pub textures: SmallMap<Fixed, Rc<Texture>, 2>,
pub textures: SmallMap<Scale, Rc<Texture>, 2>,
}
impl PlaceholderNode {

View file

@ -7,5 +7,5 @@ msg destroy = 0 {
# events
msg preferred_scale = 0 {
scale: fixed,
scale: u32,
}