~mil/sxmo-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH peanutbutter] Correctly handle scale

Details
Message ID
<20241201211536.1050714-2-proycon@anaproy.nl>
DKIM signature
pass
Download raw message
Patch: +37 -6
The display was a bit blurry because the scale wasn't correctly handled,
now it is, and peanutbutter is crispier than ever!

---
This is to be applied on top of three earlier patches I sent

 src/draw.rs             | 11 +++++++++--
 src/wayland_protocol.rs | 32 ++++++++++++++++++++++++++++----
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/src/draw.rs b/src/draw.rs
index b600968..46e14ca 100644
--- a/src/draw.rs
+++ b/src/draw.rs
@@ -15,7 +15,10 @@ impl State {
        if self.debug {
            eprintln!("draw");
        }
        let (init_w, init_h) = (self.width.unwrap(), self.height.unwrap());
        let (init_w, init_h) = (
            self.width.unwrap() * self.scale,
            self.height.unwrap() * self.scale,
        );

        let fd: Memfd = memfd::MemfdOptions::default()
            .create("peanutbutter")
@@ -54,7 +57,10 @@ impl State {
        layout.set_font_description(Some(&self.fontdesc_status));
        layout.set_markup(&status);
        let (layout_w, _) = layout.pixel_size();
        context.move_to((init_w as f64 / 2.0) - (layout_w as f64 / 2.0), 50.0);
        context.move_to(
            (init_w as f64 / 2.0) - (layout_w as f64 / 2.0),
            (50 * self.scale) as f64,
        );
        pangocairo::functions::show_layout(&context, &layout);

        // hash the statusline so we can check if it changes later
@@ -95,6 +101,7 @@ impl State {

        if self.configured {
            let surface = self.base_surface.as_ref().unwrap();
            surface.set_buffer_scale(self.scale);
            surface.frame(&self.queue_handle, surface.clone());
            surface.attach(Some(&buffer), 0, 0);
            surface.damage(0, 0, i32::MAX, i32::MAX);
diff --git a/src/wayland_protocol.rs b/src/wayland_protocol.rs
index 689b730..c0a0adb 100644
--- a/src/wayland_protocol.rs
+++ b/src/wayland_protocol.rs
@@ -54,6 +54,7 @@ pub struct State {
    pub last_down: Option<TouchDown>,
    pub width: Option<i32>,
    pub height: Option<i32>,
    pub scale: i32,
    pub fontdesc_time: pango::FontDescription,
    pub fontdesc_status: pango::FontDescription,
    seat: Option<WlSeat>,
@@ -153,7 +154,7 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
                    state.compositor = Some(compositor);
                }
                "wl_output" => {
                    let output = registry.bind::<WlOutput, _, _>(name, 1, qh, ());
                    let output = registry.bind::<WlOutput, _, _>(name, 3, qh, ());
                    // Put first output as pin entry output
                    // TODO: allow user to set env variable to choose display
                    // Moreover, this code will cause bugs when new displays are plugged in
@@ -301,11 +302,11 @@ pub fn init_wayland(

    let mut fontdesc_time = pango::FontDescription::new();
    fontdesc_time.set_family(fontname);
    fontdesc_time.set_size(80 * pango::SCALE);
    //size is configured in scale event

    let mut fontdesc_status = pango::FontDescription::new();
    fontdesc_status.set_family(fontname);
    fontdesc_status.set_size(16 * pango::SCALE);
    //size is configured in scale event

    let mut state = State {
        lock: None,
@@ -328,6 +329,7 @@ pub fn init_wayland(
        last_down: None,
        width: None,
        height: None,
        scale: 1, //will be set by wloutput scale callback
        debug,
        notouch,
        running: true,
@@ -462,10 +464,32 @@ impl Dispatch<wl_callback::WlCallback, wl_surface::WlSurface> for State {
    }
}

impl Dispatch<wl_output::WlOutput, ()> for State {
    fn event(
        state: &mut Self,
        _touch: &wl_output::WlOutput,
        event: wl_output::Event,
        _: &(),
        _: &Connection,
        _qh: &QueueHandle<Self>,
    ) {
        match event {
            wl_output::Event::Scale { factor } => {
                if state.debug {
                    eprintln!("wloutput scaling factor = {factor}");
                }
                state.scale = factor;
                state.fontdesc_time.set_size(80 * pango::SCALE * factor);
                state.fontdesc_status.set_size(16 * pango::SCALE * factor);
            }
            _ => {}
        }
    }
}

delegate_noop!(State: ignore wl_shm::WlShm);
delegate_noop!(State: ignore wl_shm_pool::WlShmPool);
delegate_noop!(State: ignore wl_buffer::WlBuffer);
delegate_noop!(State: ignore wl_output::WlOutput);
delegate_noop!(State: ignore ext_session_lock_manager_v1::ExtSessionLockManagerV1);
delegate_noop!(State: ignore wl_surface::WlSurface);
delegate_noop!(State: ignore wl_seat::WlSeat);
-- 
2.47.1
Details
Message ID
<D64F2SDJEGFG.K6B4ULGQ7RU4@momi.ca>
In-Reply-To
<20241201211536.1050714-2-proycon@anaproy.nl> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git@git.sr.ht:~anjan/peanutbutter
   3da46c3a..90bd4e17  master -> master
Reply to thread Export thread (mbox)