Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapting to changed font size #220

Open
jdujava opened this issue Sep 1, 2024 · 9 comments
Open

Adapting to changed font size #220

jdujava opened this issue Sep 1, 2024 · 9 comments

Comments

@jdujava
Copy link

jdujava commented Sep 1, 2024

As described in gokcehan/lf#1793, I use ueberzugpp for image previews in lf. After changing the font size, lf outputs updated position and size of preview (measured in rows/columns), but the preview is displayed as if the font size was the original one, resulting in wrong position/sizing.

Is there a way to update ueberzugpp about the change in font size?

@jstkdng
Copy link
Owner

jstkdng commented Sep 2, 2024

hey, i don't think there's a way for ueberzugpp to react to that event, there could be one I'd have to dig through some documentation.

You could trigger a redraw on font size change maybe? Does lf support that?

@jdujava
Copy link
Author

jdujava commented Sep 3, 2024

I think lf triggers a redraw on font size change. Maybe I should specify earlier: all subsequent image previews are positioned/sized wrong.

@joelim-work
Copy link

I spent some time to investigate, lf does detect terminal resizes and in response sends an update to ueberzugpp with the adjusted cell dimensions. However it appears that ueberzugpp calculates the pixel dimensions only once and then applies it for all subsequent updates, even if the terminal has resized.

Below are the steps to reproduce without involving lf:

  1. Start ueberzugpp (should read JSON commands from stdin):
    ueberzug layer
  2. Type the following to display the image:
    {"action": "add", "identifier": "test", "path": "foobar.jpg", "width": 10, "height": 10, "x": 2, "y": 2}
  3. Resize the terminal. At this point, it is expected that the image does not change, because ueberzugpp hasn't received any updates.
  4. Repeat step 2. Nothing happens, but now that another add command has been sent to ueberzugpp, I would expect the image to be resized and repositioned according the the new cell size.

I also tested this on (a continuation of) the original ueberzug, and the image updated fine even after resizing the terminal.

@jstkdng
Copy link
Owner

jstkdng commented Sep 25, 2024

It does? I think it recalculates terminal sizes on every command (calling ioctl) whilst ueberzugpp just uses the first value it calculates. Right now there's no trivial way to do that I believe.

@joelim-work
Copy link

That's my assumption based on what I found when I was trying to debug the issue myself. So just to confirm, are you or @jdujava able to reproduce the behavior I described above for both ueberzugpp and ueberzug?

@jdujava
Copy link
Author

jdujava commented Sep 25, 2024

Yeah, I tried following your steps, and ueberzug properly updated both position and size of the image, while ueberzugpp didn't.

This is maybe more suited to mention in lf issue, but position/size of previews in lf didn't update with neither ueberzug or ueberzugpp. But this can be caused by my setup and way of launching lf with ueberzug, more than with their response to resizing.

@jdujava
Copy link
Author

jdujava commented Sep 26, 2024

Just to clear up my previous message:
As I described in gokcehan/lf#1793, with proper setup ueberzug properly adapts to terminal font resize.
On the other hand, as we already know, ueberzugpp is stuck with the initial font size.

@seebye
Copy link

seebye commented Jan 30, 2025

It does? I think it recalculates terminal sizes on every command (calling ioctl) whilst ueberzugpp just uses the first value it calculates. Right now there's no trivial way to do that I believe.

OG ueberzug does not recalculate it on every command.
It computes it once and recomputes it if SIGWINCH was received.

Actually compute the values:
https://github.com/seebye/ueberzug/blob/52855b2493c35129cea28ccb37b26280d4e64b6d/ueberzug/ui.py#L154-L156

Trigger recompute:

  1. https://github.com/seebye/ueberzug/blob/52855b2493c35129cea28ccb37b26280d4e64b6d/ueberzug/layer.py#L240-L243
  2. https://github.com/seebye/ueberzug/blob/52855b2493c35129cea28ccb37b26280d4e64b6d/ueberzug/layer.py#L83-L87
  3. https://github.com/seebye/ueberzug/blob/52855b2493c35129cea28ccb37b26280d4e64b6d/ueberzug/ui.py#L175-L177
  4. https://github.com/seebye/ueberzug/blob/52855b2493c35129cea28ccb37b26280d4e64b6d/ueberzug/terminal.py#L56-L61

So you just need to update the information after receiving SIGWINCH and your program should behave in the same way.

@jstkdng
Copy link
Owner

jstkdng commented Feb 6, 2025

eyyyy @seebye, nice seeing you, thanks for the tip

@jdujava this issue has been solved on this repo: https://github.com/jstkdng/ueberzugpp-new, I'll see if I can implement SIGWINCH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants