jstkdng / ueberzugpp

Drop in replacement for ueberzug written in C++
GNU General Public License v3.0
803 stars 29 forks source link

x and y position way off when using `nnn` `preview-tui` plugin inside `tmux` #85

Closed amalgame21 closed 1 year ago

amalgame21 commented 1 year ago

With ueberzug:

ueberzug

With ueberzugpp:

ueberzugpp

Only my desktop have this problem, my laptop is fine. Both running X11, terminal is alacritty, install ueberzugpp 2.8.8-2 with AUR.

jstkdng commented 1 year ago

does it work outside of tmux? is the setup on your laptop the same as on your desktop?

amalgame21 commented 1 year ago

Yes the setup are the same. I think one of the difference is that my desktop monitor is not 16:9, maybe it is the cause? Since nnn 'preview-tui' plugin spawn another terminal to display previews when using it without tmux, it may be fine. Are there any ways for me to test it?

amalgame21 commented 1 year ago

Tested in ranger, same result. the whole preview even shifted out of the monitor. Tested in sakura terminal, same result.

Maybe because of my 1440x900 pixels monitor?

jstkdng commented 1 year ago

not 16:9, maybe it is the cause?

nah, my monitor is 16:10 and it works fine.

does this only show up when using tmux? does ranger work fine outside tmux?

amalgame21 commented 1 year ago

not 16:9, maybe it is the cause?

nah, my monitor is 16:10 and it works fine.

does this only show up when using tmux? does ranger work fine outside tmux?

no, ranger also not working fine outside tmux, the image shift outside the monitor. I also tested my laptop with my monitor and it also work fine... so I think the monitor is not causing the issue. Then the main difference between my laptop and desktop I can think of is that, my laptop have AMD GPU and my desktop is using NVIDIA, and both of them are using hardened-linux kernel, so my laptop is using nvidia-dkms driver.

jstkdng commented 1 year ago

alright, some debugging is needed as I'm unable to reproduce on my side. before running ranger run this export SPDLOG_LEVEL=debug and try to display some images. Once you are done, post the contents of the log file located under /tmp/ueberzugpp-$USER.log

amalgame21 commented 1 year ago

Thanks for your help.

ranger without tmux:

 _    _      _                                           
| |  | |    | |                                _     _   
| |  | | ___| |__   ___ _ __ _____   _  __ _ _| |_ _| |_ 
| |  | |/ _ \ '_ \ / _ \ '__|_  / | | |/ _` |_   _|_   _|
| |__| |  __/ |_) |  __/ |   / /| |_| | (_| | |_|   |_|  
 \____/ \___|_.__/ \___|_|  /___|\__,_|\__, |            
                                        __/ |            
                                       |___/     v2.8.8
[2023-07-14 12:33:03.603] [terminal] [info] TERM="alacritty", TERM_PROGRAM=""
[2023-07-14 12:33:03.604] [terminal] [debug] PTY = /dev/pts/0
[2023-07-14 12:33:03.604] [terminal] [debug] ioctl sizes: COLS=80 ROWS=24 XPIXEL=1280 YPIXEL=768
[2023-07-14 12:33:03.604] [terminal] [debug] iterm2 is not supported
[2023-07-14 12:33:03.604] [terminal] [debug] X11 is supported
[2023-07-14 12:33:03.604] [terminal] [debug] X11 sizes: XPIXEL=1440 YPIXEL=876
[2023-07-14 12:33:03.604] [terminal] [debug] Wayland is not supported
[2023-07-14 12:33:03.604] [terminal] [debug] padding_horiz=80 padding_vert=54
[2023-07-14 12:33:03.604] [terminal] [debug] font_width=16 font_height=32
[2023-07-14 12:33:03.605] [X11] [info] Canvas created
[2023-07-14 12:33:03.605] [X11] [debug] Started event handler
[2023-07-14 12:33:03.605] [main] [info] Listening for commands on socket /tmp/ueberzugpp-33651.socket.
[2023-07-14 12:33:03.633] [main] [info] Command received: {"action":"add","identifier":"preview","max_height":37,"max_width":33,"path":"/home/user/ueberzugpp-test/img/test.jpg","x":97,"y":1}
[2023-07-14 12:33:03.655] [opencv] [info] Loading image /home/user/ueberzugpp-test/img/test.jpg
[2023-07-14 12:33:03.746] [opencv] [debug] OpenCL is available
[2023-07-14 12:33:03.747] [opencv] [debug] Resizing image
[2023-07-14 12:33:03.756] [opencv] [debug] Saved resized image
[2023-07-14 12:33:03.765] [X11] [debug] Initializing canvas
[2023-07-14 12:33:03.765] [X11] [debug] Created child window 90177536 at (1632,86) with parent 69206020
[2023-07-14 12:33:03.767] [X11] [debug] Received expose event for window 90177536
[2023-07-14 12:33:03.768] [X11] [debug] Received expose event for window 90177536
[2023-07-14 12:33:06.282] [main] [error] SIGTERM received, exiting.
[2023-07-14 12:33:06.308] [main] [info] Exiting ueberzugpp
[2023-07-14 12:33:06.371] [X11] [debug] Stopped event handler

nnn with tmux:

 _    _      _                                           
| |  | |    | |                                _     _   
| |  | | ___| |__   ___ _ __ _____   _  __ _ _| |_ _| |_ 
| |  | |/ _ \ '_ \ / _ \ '__|_  / | | |/ _` |_   _|_   _|
| |__| |  __/ |_) |  __/ |   / /| |_| | (_| | |_|   |_|  
 \____/ \___|_.__/ \___|_|  /___|\__,_|\__, |            
                                        __/ |            
                                       |___/     v2.8.8
[2023-07-14 12:33:09.351] [terminal] [info] TERM="tmux-256color", TERM_PROGRAM="tmux"
[2023-07-14 12:33:09.380] [X11] [info] Canvas created
[2023-07-14 12:33:09.436] [main] [info] Listening for commands on socket /tmp/ueberzugpp-33838.socket.
[2023-07-14 12:33:09.505] [main] [info] Command received: {"action":"add","height":"38","identifier":"nnn_ueberzug","path":"/home/user/ueberzugpp-test/img/test.jpg","scaler":"fit_contain","width":"58","x":0,"y":0}
[2023-07-14 12:33:09.554] [opencv] [info] Loading image /home/user/ueberzugpp-test/img/test.jpg
[2023-07-14 12:33:10.801] [main] [info] Command received: {"action":"remove","identifier":"nnn_ueberzug"}
[2023-07-14 12:33:10.801] [main] [info] Removing image.
[2023-07-14 12:33:10.836] [main] [info] Command received: {"action":"add","height":"38","identifier":"nnn_ueberzug","path":"/home/user/ueberzugpp-test/img/test.jpg","scaler":"fit_contain","width":"130","x":0,"y":0}
[2023-07-14 12:33:10.879] [opencv] [info] Loading image /home/user/ueberzugpp-test/img/test.jpg
[2023-07-14 12:33:10.905] [main] [info] Command received: {"action":"tmux","hook":"window-layout-changed"}
 _    _      _                                           
| |  | |    | |                                _     _   
| |  | | ___| |__   ___ _ __ _____   _  __ _ _| |_ _| |_ 
| |  | |/ _ \ '_ \ / _ \ '__|_  / | | |/ _` |_   _|_   _|
| |__| |  __/ |_) |  __/ |   / /| |_| | (_| | |_|   |_|  
 \____/ \___|_.__/ \___|_|  /___|\__,_|\__, |            
                                        __/ |            
                                       |___/     v2.8.8
[2023-07-14 12:33:10.951] [terminal] [info] TERM="tmux-256color", TERM_PROGRAM="tmux"
[2023-07-14 12:33:10.989] [X11] [info] Canvas created
[2023-07-14 12:33:10.996] [main] [error] SIGTERM received, exiting.
[2023-07-14 12:33:10.996] [main] [error] SIGTERM received, exiting.
[2023-07-14 12:33:11.025] [main] [info] Exiting ueberzugpp
[2023-07-14 12:33:11.055] [main] [info] Listening for commands on socket /tmp/ueberzugpp-33918.socket.
[2023-07-14 12:33:11.155] [main] [info] Exiting ueberzugpp
jstkdng commented 1 year ago

Alright, it seems the calculations are way off. It seems ueberzugpp is opening /dev/pts/0, run the tty command, is that tty correct? What DE/WM are you using?

amalgame21 commented 1 year ago

I am using dwm in both of my machine. Sorry I do not know what tty is, but I run tty in the terminal it displayed /dev/pts/1.

amalgame21 commented 1 year ago

Oh I think I figured it out. I launch dwm with .xinitrc Before launching dwm in the .xinitrc I launched a bunch of programs like parcellite, xcompmgr, xss-lock, etc. One of them is a detached tmux instance, I think it occupied /dev/pts/0 So after inside dwm, when I run tty in the alacritty terminal, it shows /dev/pts/1, but ueberzugpp is using /dev/pts/0 And if I close that tmux instance later, and run tty again, it shows /dev/pts/0, and ueberzugpp is working fine again.

I commented out this tmux instance in the .xinitrc file on my laptop, which explain the differences.

Tested in GNOME, tty display /dev/pts/0 in alacritty, and ueberzugpp also working fine.

jstkdng commented 1 year ago

well at least the cause is known now. Can you post the process tree with and without the tmux instance? You can get that from htop.

amalgame21 commented 1 year ago

Sorry I do not know how to export output of htop so I use pstree instead.

with tmux:

systemd-+-NetworkManager---3*[{NetworkManager}]
        |-accounts-daemon---3*[{accounts-daemon}]
        |-auditd---{auditd}
        |-avahi-daemon---avahi-daemon
        |-blueman-mechani---3*[{blueman-mechani}]
        |-colord---3*[{colord}]
        |-dbus-daemon
        |-gdm-+-gdm-session-wor-+-gdm-x-session-+-Xorg---{Xorg}
        |     |                 |               |-sh-+-blueman-applet---4*[{blueman-applet}]
        |     |                 |               |    |-dunst---3*[{dunst}]
        |     |                 |               |    |-dwm---alacritty-+-zsh---pstree
        |     |                 |               |    |                 `-6*[{alacritty}]
        |     |                 |               |    |-dwmblocks
        |     |                 |               |    |-firewall-applet---5*[{firewall-applet}]
        |     |                 |               |    |-nm-applet---4*[{nm-applet}]
        |     |                 |               |    |-pa-applet---3*[{pa-applet}]
        |     |                 |               |    |-polkit-gnome-au---3*[{polkit-gnome-au}]
        |     |                 |               |    |-unclutter
        |     |                 |               |    |-xautolock
        |     |                 |               |    |-xcompmgr
        |     |                 |               |    `-xss-lock---3*[{xss-lock}]
        |     |                 |               `-3*[{gdm-x-session}]
        |     |                 `-3*[{gdm-session-wor}]
        |     `-3*[{gdm}]
        |-geoclue---3*[{geoclue}]
        |-gpg-agent-+-scdaemon---2*[{scdaemon}]
        |           `-{gpg-agent}
        |-polkitd---3*[{polkitd}]
        |-power-profiles----3*[{power-profiles-}]
        |-rngd---4*[{rngd}]
        |-rtkit-daemon---2*[{rtkit-daemon}]
        |-systemd-+-(sd-pam)
        |         |-at-spi-bus-laun-+-dbus-daemon
        |         |                 `-4*[{at-spi-bus-laun}]
        |         |-at-spi2-registr---3*[{at-spi2-registr}]
        |         |-bash---clipnotify
        |         |-dbus-daemon
        |         |-dconf-service---3*[{dconf-service}]
        |         |-gvfsd---3*[{gvfsd}]
        |         |-gvfsd-fuse---6*[{gvfsd-fuse}]
        |         |-obexd
        |         |-pipewire---{pipewire}
        |         |-pipewire-pulse---{pipewire-pulse}
        |         |-playerctld---3*[{playerctld}]
        |         |-wireplumber---5*[{wireplumber}]
        |         |-xdg-desktop-por---6*[{xdg-desktop-por}]
        |         |-xdg-document-po-+-fusermount3
        |         |                 `-6*[{xdg-document-po}]
        |         `-xdg-permission----3*[{xdg-permission-}]
        |-systemd-journal
        |-systemd-logind
        |-systemd-timesyn---{systemd-timesyn}
        |-systemd-udevd
        |-tmux: server---profanity---3*[{profanity}]
        |-upowerd---3*[{upowerd}]
        |-wpa_supplicant
        `-zsh---gitstatusd-linu---24*[{gitstatusd-linu}]

without tmux:

systemd-+-NetworkManager---3*[{NetworkManager}]
        |-accounts-daemon---3*[{accounts-daemon}]
        |-auditd---{auditd}
        |-avahi-daemon---avahi-daemon
        |-colord---3*[{colord}]
        |-dbus-daemon
        |-gdm-+-gdm-session-wor-+-gdm-x-session-+-Xorg---{Xorg}
        |     |                 |               |-sh-+-blueman-applet---4*[{blueman-applet}]
        |     |                 |               |    |-dunst---3*[{dunst}]
        |     |                 |               |    |-dwm---alacritty-+-zsh---pstree
        |     |                 |               |    |                 `-6*[{alacritty}]
        |     |                 |               |    |-dwmblocks
        |     |                 |               |    |-firewall-applet---5*[{firewall-applet}]
        |     |                 |               |    |-nm-applet---4*[{nm-applet}]
        |     |                 |               |    |-pa-applet---3*[{pa-applet}]
        |     |                 |               |    |-polkit-gnome-au---3*[{polkit-gnome-au}]
        |     |                 |               |    |-unclutter
        |     |                 |               |    |-xautolock
        |     |                 |               |    |-xcompmgr
        |     |                 |               |    `-xss-lock---3*[{xss-lock}]
        |     |                 |               `-3*[{gdm-x-session}]
        |     |                 `-3*[{gdm-session-wor}]
        |     `-3*[{gdm}]
        |-gpg-agent-+-scdaemon---2*[{scdaemon}]
        |           `-{gpg-agent}
        |-polkitd---3*[{polkitd}]
        |-power-profiles----3*[{power-profiles-}]
        |-rngd---4*[{rngd}]
        |-rtkit-daemon---2*[{rtkit-daemon}]
        |-systemd-+-(sd-pam)
        |         |-at-spi-bus-laun-+-dbus-daemon
        |         |                 `-4*[{at-spi-bus-laun}]
        |         |-at-spi2-registr---3*[{at-spi2-registr}]
        |         |-bash---clipnotify
        |         |-dbus-daemon
        |         |-dconf-service---3*[{dconf-service}]
        |         |-gvfsd---3*[{gvfsd}]
        |         |-gvfsd-fuse---6*[{gvfsd-fuse}]
        |         |-obexd
        |         |-pipewire---{pipewire}
        |         |-pipewire-pulse---{pipewire-pulse}
        |         |-playerctld---3*[{playerctld}]
        |         |-wireplumber---5*[{wireplumber}]
        |         |-xdg-desktop-por---6*[{xdg-desktop-por}]
        |         |-xdg-desktop-por---2*[{xdg-desktop-por}]
        |         |-xdg-document-po-+-fusermount3
        |         |                 `-6*[{xdg-document-po}]
        |         `-xdg-permission----3*[{xdg-permission-}]
        |-systemd-journal
        |-systemd-logind
        |-systemd-timesyn---{systemd-timesyn}
        |-systemd-udevd
        |-upowerd---3*[{upowerd}]
        |-wpa_supplicant
        `-zsh---gitstatusd-linu---24*[{gitstatusd-linu}]
amalgame21 commented 1 year ago

Now I have the same issue, but unrelated to tmux launched in .xinitrc. It can also be reproduced on my laptop.

To reproduce: After login into dwm, in the workspace 1

  1. open alacritty by dwm shortcut, run tty, output /dev/pts/0
  2. in the same workspace, open another alacritty by dwm shortcut (dwm will resize them automatically), run tty, output /dev/pts/1
  3. Switch to workspace 2, open another alacritty by dwm shortcut, run tty, output /dev/pts/2
  4. In this alacritty, run export SPDLOG_LEVEL=debug, ranger, and the preview shifted with the log below (Wrong PTY):
 _    _      _                                           
| |  | |    | |                                _     _   
| |  | | ___| |__   ___ _ __ _____   _  __ _ _| |_ _| |_ 
| |  | |/ _ \ '_ \ / _ \ '__|_  / | | |/ _` |_   _|_   _|
| |__| |  __/ |_) |  __/ |   / /| |_| | (_| | |_|   |_|  
 \____/ \___|_.__/ \___|_|  /___|\__,_|\__, |            
                                        __/ |            
                                       |___/     v2.8.8
[2023-07-15 15:04:25.825] [terminal] [info] TERM="alacritty", TERM_PROGRAM=""
[2023-07-15 15:04:25.826] [terminal] [debug] PTY = /dev/pts/0
[2023-07-15 15:04:25.826] [terminal] [debug] ioctl sizes: COLS=50 ROWS=38 XPIXEL=550 YPIXEL=836
[2023-07-15 15:04:25.826] [terminal] [debug] iterm2 is not supported
[2023-07-15 15:04:25.826] [terminal] [debug] X11 is supported
[2023-07-15 15:04:25.826] [terminal] [debug] X11 sizes: XPIXEL=1440 YPIXEL=876
[2023-07-15 15:04:25.826] [terminal] [debug] Wayland is not supported
[2023-07-15 15:04:25.826] [terminal] [debug] padding_horiz=445 padding_vert=20
[2023-07-15 15:04:25.826] [terminal] [debug] font_width=11 font_height=22
[2023-07-15 15:04:25.827] [X11] [info] Canvas created
[2023-07-15 15:04:25.827] [X11] [debug] Started event handler
[2023-07-15 15:04:25.827] [main] [info] Listening for commands on socket /tmp/ueberzugpp-140420.socket.
[2023-07-15 15:04:25.855] [main] [info] Command received: {"action":"add","identifier":"preview","max_height":37,"max_width":33,"path":"/home/user/ueberzugpp-test/img/test.jpg","x":97,"y":1}
[2023-07-15 15:04:25.862] [opencv] [info] Loading image /home/user/.cache/ueberzugpp/ea97b148fc8ef813fa0f22e058e823f427ca7d1eedfe2dc1b4a883e9d3c3be44ced5cb8288c774b1810a6398aaeb074b203d1aece025a3724102bbe76f9f9023.jpg
[2023-07-15 15:04:25.866] [X11] [debug] Initializing canvas
[2023-07-15 15:04:25.866] [X11] [debug] Created child window 88080384 at (1512,42) with parent 75497476
[2023-07-15 15:04:25.867] [X11] [debug] Received expose event for window 88080384
[2023-07-15 15:04:25.867] [X11] [debug] Received expose event for window 88080384
[2023-07-15 15:04:45.916] [main] [error] SIGTERM received, exiting.
[2023-07-15 15:04:45.950] [main] [info] Exiting ueberzugpp
[2023-07-15 15:04:45.991] [X11] [debug] Stopped event handler

related pstree:

        |-gdm-+-gdm-session-wor-+-gdm-x-session-+-Xorg---{Xorg}
        |     |                 |               |-sh-+-blueman-applet---4*[{blueman-applet}]
        |     |                 |               |    |-dunst---3*[{dunst}]
        |     |                 |               |    |-dwm-+-2*[alacritty-+-zsh]
        |     |                 |               |    |     |              `-6*[{alacritty}]]
        |     |                 |               |    |     |-alacritty-+-zsh---ranger---ueberzug---13*[{ueberzug}]
        |     |                 |               |    |     |           `-6*[{alacritty}]
        |     |                 |               |    |     `-alacritty-+-zsh---pstree
        |     |                 |               |    |                 `-6*[{alacritty}]
        |     |                 |               |    |-dwmblocks
        |     |                 |               |    |-firewall-applet---5*[{firewall-applet}]
        |     |                 |               |    |-nm-applet---4*[{nm-applet}]
        |     |                 |               |    |-pa-applet---3*[{pa-applet}]
        |     |                 |               |    |-polkit-gnome-au---3*[{polkit-gnome-au}]
        |     |                 |               |    |-unclutter
        |     |                 |               |    |-xautolock
        |     |                 |               |    |-xcompmgr
        |     |                 |               |    `-xss-lock---3*[{xss-lock}]
        |     |                 |               `-3*[{gdm-x-session}]
        |     |                 `-3*[{gdm-session-wor}]
        |     `-3*[{gdm}]
amalgame21 commented 1 year ago

The above issue can also be reproduced in GNOME, which can also be reproduced on my laptop:

  1. login to GNOME, open alacritty, rezise it, run tty, output /dev/pts/0
  2. open konsole, resize it, run tty, output /dev/pts/1, run export SPDLOG_LEVEL=debug, ranger, and the preview shifted, log shows it use /dev/pts/0

By the way I am using gdm display manager. By the way when I use i3, the log shows the correct PTY, so it works fine on i3

jstkdng commented 1 year ago

yeah I think I understand the problem. Under gnome/gdm, the terminals aren't direct children from systemd. And under dwm, the terminals are dwm children it seems. I'll see what I can do to fix the terminal recognition issues.

jstkdng commented 1 year ago

I've modified the terminal checks, can you test? I don't have a gnome/dwm vm at hand.

amalgame21 commented 1 year ago

Would you guide me through the install process? I am not familiar with cmake. I installed the package via AUR ueberzugpp which is v2.8.8, and seems the Build instructions in the readme.md also v2.8.8(?)

jstkdng commented 1 year ago

yeah, you can follow the instructions from the readme

amalgame21 commented 1 year ago

It solved all the above cases! Thanks!

jstkdng commented 1 year ago

awesome, closing then.

ih8d8 commented 1 year ago

I have the same problem but on Hyprland (wayland). Iuse alacritty+tmux+nnn preview-tui+ueberzugpp. On my 4K monitor, I use a fractional scaling factor of 1.5 but even when I set it to 1, the issue doesn't go away. 2023-08-12_00:24:14

jstkdng commented 1 year ago

@ih8d8 can you open a new issue?

ih8d8 commented 1 year ago

Done