hackerb9 / lsix

Like "ls", but for images. Shows thumbnails in terminal using sixel graphics.
GNU General Public License v3.0
4.03k stars 127 forks source link

(solution) Detect dimensions of `foot` running under Sway #47

Open savchenko opened 3 years ago

savchenko commented 3 years ago

When used with foot, window dimensions in lsix can be set as following:

window_width=$(swaymsg -t get_tree | jq -r '.. | (.nodes? // empty)[] | select(.'focused' and .pid) | "\(.rect.width)"')
window_height=$(swaymsg -t get_tree | jq -r '.. | (.nodes? // empty)[] | select(.'focused' and .pid) | "\(.rect.height)"')
width=$window_width
hackerb9 commented 3 years ago

Thank you for the bug report and proposed solution, but it doesn't make sense for lsix to inquire the dimensions directly from different window managers / windowing systems.

Lsix asks the terminal what its resolution is using an escape sequence that works with many terminal emulators, including, I had thought, @dnkl's foot. If it is not working, this sounds like an issue for foot or Sway.

Would you please test for me if lsix gets the correct dimensions from foot when you are not running Sway? Thanks!

hackerb9 commented 3 years ago

Thank you for the bug report and proposed solution, but it doesn't make sense for lsix to inquire the dimensions directly from different window managers / windowing systems.

Lsix asks the terminal what its resolution is using an escape sequence that works with many terminal emulators, including, I had thought, @dnkl's foot. If it is not working, this sounds like an issue for foot or Sway.

Would you please test for me if lsix gets the correct dimensions from foot when you are not running Sway? Thanks!

hackerb9 commented 3 years ago

Thank you for the bug report and proposed solution, but it doesn't make sense for lsix to inquire the dimensions directly from different window managers / windowing systems.

Lsix asks the terminal what its resolution is using an escape sequence that works with many terminal emulators, including, I had thought, @dnkl's foot. If it is not working, this sounds like an issue for foot or Sway.

Would you please test for me if lsix gets the correct dimensions from foot when you are not running Sway? Thanks!

hackerb9 commented 3 years ago

Thank you for the bug report and proposed solution, but it doesn't make sense for lsix to inquire the dimensions directly from different window managers / windowing systems.

Lsix asks the terminal what its resolution is using an escape sequence that works with many terminal emulators, including, I had thought, @dnkl's foot. If it is not working, this sounds like an issue for foot or Sway.

Would you please test for me if lsix gets the correct dimensions from foot when you are not running Sway? Thanks!

hackerb9 commented 3 years ago

Thank you for the bug report and proposed solution, but it doesn't make sense for lsix to inquire the dimensions directly from different window managers / windowing systems.

Lsix asks the terminal what its resolution is using an escape sequence that works with many terminal emulators, including, I had thought, @dnkl's foot. If it is not working, this sounds like an issue for foot or Sway.

Would you please test for me if lsix gets the correct dimensions from foot when you are not running Sway? Thanks!

savchenko commented 3 years ago

Would you please test for me if lsix gets the correct dimensions from foot when you are not running Sway? Thanks!

I don't have other WMs installed (yet...), but sure, let's do it. Do you have any preference?

dnkl commented 3 years ago

@hackerb9 the escapes used by lsix (the first one, \e[?2;1;0S) works for me (in Sway).

Using swaymsg will only work under Sway. Also, note that swaymsg will return the full window size, including the unusable margin area.

hackerb9 commented 3 years ago

@savchenko I suspect there is something else going wrong for you since the developer of foot reports that it already works correctly under Sway.

Perhaps there is something confusing in the lsix documentation that I could improve?

Please try again with the latest version of foot, if you haven't already. If that works, let me know what version of foot you had been using and how you had gotten it so other people won't have the same issue.

If it doesn't help, you could try another window manager or terminal emulator, but I doubt it would make a difference. If we get to that point, send screenshots and the output from env.

savchenko commented 3 years ago

@savchenko I suspect there is something else going wrong for you since the developer of foot reports that it already works correctly under Sway.

"It depends". In somewhat more involved scenario: two windows in the tabbed mode, 2nd one is the web-browser and split horizontally with the foot running at the bottom.

lsix

image

...and with the active dimensions querying:

image

Please try again with the latest version of foot, if you haven't already

Sway

I wrote that when trying the script on -master which at that time was v1.6, currently running v1.5 which comes pre-packaged in Debian.

foot

Tested on a wide variety of versions ranging from approximately 1.5 to 1.8.2 which is currently the latest.

you could try another window manager or terminal emulator

Opportunistically tried kitty and alacritty, turns out both (!) don't support sixel.

send screenshots and the output from env.

Screenshots above and here is the output:

AWT_TOOLKIT=MToolkit
BAT_THEME=Midnight.hybrid
CCACHE_DIR=/home/sv/.cache/ccache
CLICOLOR=1
CLUTTER_BACKEND=wayland
COLORTERM=truecolor
CPU %P%
CURL_HOME=/home/sv/.config/curl
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
DISPLAY=:0
ECORE_EVAS_ENGINE=wayland_egl
EDITOR=nvim
ELM_ACCEL=gl
ELM_DISPLAY=wl
FILEMANAGER=vifm
FZF_DEFAULT_COMMAND=fd -uu --one-file-system -t f -t d -t l
FZF_DEFAULT_OPTS=--height=99% --reverse --color=dark,fg:#707880,bg:#000000,hl:#b5bd68,fg+:#c5c8c6,bg+:#000000,hl+:#d7ffaf,info:#707880,gutter:#000000,border:#373b41,prompt:#707880,pointer:#de935f,marker:#de935f,spinner:#8abeb7,header:#707880
FZF_PREVIEW_COMMAND=bat --style=plain --color always {} || tree -C {}
GDK_DPI_SCALE=1
GDK_SCALE=1
GIT_EDITOR=nvim -u /home/sv/.config/nvim/init.vim
GNC_CONFIG_HOME=/home/sv/.config/gnucash
GNC_DATA_HOME=/home/sv/.local/share/gnucash
GPG_TTY=/dev/pts/1
GREP_COLOR=32
HISTCONTROL=ignoreboth:erasedups
HISTFILESIZE=10000
HISTIGNORE=&:ls:[bf]g:exit:pwd:clear:c
HISTSIZE=10000
HOME=/home/sv
HSTR_CONFIG=hicolor
HSTR_PROMPT=> 
HUSHLOGIN=TRUE
I3SOCK=/home/sv/.local/runtime/sway-ipc.1000.1856.sock
INVOCATION_ID=c756c3f05a7d4c1bb6747f5ab1ed96b5
JOURNAL_STREAM=8:17326
LANG=en_AU.UTF-8
LANGUAGE=en_AU:en
LESSCHARSET=utf-8
LESSCOLOR=yes
LESSOPEN=|lesspipe.sh %s
LESSQUIET=1
LESS_ADVANCED_PREPROCESSOR=1
LIBVIRT_DEFAULT_URI=qemu:///system
LOGNAME=sv
MAIL=/var/mail/sv
MANPAGER=nvim -u /home/sv/.config/nvim/init.vim -c 'set ft=man' -
MANPATH=/home/sv/.local/man:/home/sv/.local/man:
MOZ_ENABLE_WAYLAND=1
MPD_HOST=/home/sv/.mpd/socket
NO_AT_BRIDGE=1
NVIM_GTK_NO_HEADERBAR=1
NVIM_GTK_NO_WINDOW_DECORATION=1
NVIM_GTK_PREFER_DARK_THEME=1
NVIM_QT_RUNTIME_PATH=/usr/share/nvim-qt/runtime
PATH=/usr/local/bin:/home/sv/.local/bin:/home/sv/code/portable/bin:/home/sv/.cargo/bin:/usr/local/bin:/home/sv/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
PROMPT_COMMAND=history -a; history -n; osc7_cwd; _zlua_precmd;history -a; history -n; osc7_cwd; 
PS1=\[\e[38;5;242m\]\[\e[38;5;249m\] \[\e[38;5;245m\]\w\[\e[38;5;249m\]$(__git_ps1)\n\[\e[38;5;242m\] \[(B\]\[\e[0m\]
PS2= \[(B\]\[\e[0m\] 
PWD=/home/sv/Desktop/screenshots
QT_AUTO_SCREEN_SCALE_FACTOR=1
QT_QPA_PLATFORM=wayland
QT_QPA_PLATFORMTHEME=qt5ct
QT_WAYLAND_DISABLE_WINDOWDECORATION=1
RIPGREP_CONFIG_PATH=/home/sv/.config/.ripgreprc
SDL_VIDEODRIVER=wayland
SHELL=/bin/bash
SHLVL=0
SSH_AUTH_SOCK=/run/user/1000/gnupg/S.gpg-agent.ssh
STNOUPGRADE=1
SWAYSOCK=/home/sv/.local/runtime/sway-ipc.1000.1856.sock
TEMP=/tmp/user/1000
TEMPDIR=/tmp/user/1000
TERM=foot
TIMEFORMAT=real %3lR
TMP=/tmp/user/1000
TMPDIR=/home/sv/.cache/TMPDIR
USER=sv
WAYLAND_DISPLAY=wayland-0
WGETRC=/home/sv/.config/wgetrc
XCURSOR_SIZE=24
XCURSOR_THEME=Adwaita
XDG_CACHE_HOME=/home/sv/.cache
XDG_CONFIG_HOME=/home/sv/.config
XDG_CURRENT_DESKTOP=sway
XDG_DATA_HOME=/home/sv/.local/share
XDG_RUNTIME_DIR=/home/sv/.local/runtime
XDG_SEAT=seat0
XDG_SESSION_CLASS=user
XDG_SESSION_ID=1
XDG_SESSION_TYPE=wayland
XDG_VTNR=1
XKB_DEFAULT_OPTIONS=caps:escape
_=/usr/bin/env
_JAVA_AWT_WM_NONREPARENTING=1
_ZL_ADD_ONCE=1
_ZL_DATA=/home/sv/.cache/zlua
_ZL_HYPHEN=1
_ZL_MATCH_MODE=1
sys %3lS
user    %3lU
hackerb9 commented 3 years ago

"It depends". In somewhat more involved scenario: two windows in the tabbed mode, 2nd one is the web-browser and split horizontally with the foot running at the bottom.

Thank you for trying out all those tests.

Environment variables seem fine, but it's a bit hard to see what is going on in those screenshots. Does the problem only occur when in tabbed mode, split horizontally? Can you make a simpler scenario with just foot?

Do you have only four images in that directory? Is the one that is showing two images the one that is incorrect? Do you have any idea why the prompt ended up on top of the images? Does it always do that?

When you run this command, does it give you the same dimensions you get from swaymsg?

 read -p $'\e[?2;1;0S' -d 'S'; echo

Thanks!

dnkl commented 3 years ago

When you run this command, does it give you the same dimensions you get from swaymsg?

@savchenko @hackerb9 note: I'd expect the escape to return (possibly) slightly smaller values, since it doesn't include the margins. But the reported sizes should be roughly the same.

In addition to that, can you (with a non-working window size), run this:

read -p $'\e[?2;4;0S' -d 'S'; echo

It will report the maximum sixel size, and should be 10000x10000 in foot 1.8. Worth noting: the above command didn't work in zsh, but did work in bash. If it doesn't work, just run echo -e '\e[?2;4;0S',

Do you have any idea why the prompt ended up on top of the images? Does it always do that?

@hackerb9 for foot 1.8.2, you need https://github.com/hackerb9/lsix/pull/46, as we reversed the meaning of DECSDM (i.e. private mode 80) in 1.8.2.

hackerb9 commented 3 years ago

Do you have any idea why the prompt ended up on top of the images? Does it always do that?

@hackerb9 for foot 1.8.2, you need #46, as we reversed the meaning of DECSDM (i.e. private mode 80) in 1.8.2.

Hoist upon my own petard! I'll fix that ASAP.

hackerb9 commented 3 years ago

@savchenko If you would be willing to take the screen shots again with a simpler scenario, please use release 1.8 of lsix as that has the DECSDM fix. Thanks!