kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.12k stars 971 forks source link

Background image with the same resolution as the monitor is tiled #6230

Closed oyarsa closed 1 year ago

oyarsa commented 1 year ago

Describe the bug In kitty 0.28.1, the background image is tiled even if it has the same resolution as the monitor. I have a dual monitor setup with the built-in Macbook monitor and a 4K monitor. It looks correct in the built-in monitor.

In kitty 0.25, this was behaving as expected. I upgraded to 0.28, and this started happening.

I don't want to use scaled because it would look weird when the terminal doesn't occupy the full screen.

To Reproduce Steps to reproduce the behaviour:

  1. Have a dual-monitor setup with different resolutions
  2. Use a 4K image
  3. The image is tiled on the 4K monitor, but it shouldn't be

Screenshots

image

Environment details

``` kitty 0.28.1 (07bcc5ba61) created by Kovid Goyal Darwin 192.168.1.100 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64 ProductName: macOS ProductVersion: 13.3.1 BuildVersion: 22E261 Frozen: True Paths: kitty: /Applications/kitty.app/Contents/MacOS/kitty base dir: /Applications/kitty.app/Contents/Resources/kitty extensions dir: /Applications/kitty.app/Contents/Resources/Python/lib/kitty-extensions system shell: /opt/homebrew/bin/fish Loaded config files: /Users/italo/.config/kitty/kitty.conf Config options different from defaults: active_tab_title_template {fmt.fg.red}{bell_symbol}{activity_symbol}{fmt.fg.tab}{fmt.noitalic}{index}{layout_name[:2].capitalize()} {title} allow_remote_control yes background_image /Users/italo/Pictures/saber-4k.png background_tint 0.95 bold_font Iosevka Term Bold bold_italic_font Iosevka Term Bold Oblique cursor_text_color None disable_ligatures 1 enabled_layouts ['splits', 'horizontal', 'fat', 'grid', 'tall', 'vertical', 'stack'] font_family Iosevka Term Medium font_size 16.0 hide_window_decorations 2 inactive_text_alpha 0.7 italic_font Iosevka Term Oblique listen_on unix:/tmp/mykitty macos_option_as_alt 3 macos_quit_when_last_window_closed True sync_to_monitor False tab_bar_min_tabs 1 tab_bar_style powerline tab_title_template {fmt.fg.red}{bell_symbol}{activity_symbol}{fmt.fg.tab}{fmt.noitalic}{index} {title} Added shortcuts: cmd+; → nth_window -1 cmd+a > h → launch --location=hsplit --cwd=current cmd+a > r → layout_action rotate cmd+a > v → launch --location=vsplit --cwd=current cmd+j → kitten pass_keys.py neighboring_window bottom alt+shift+j cmd+l → kitten pass_keys.py neighboring_window right alt+shift+l ctrl+cmd+tab → next_window ctrl+shift+cmd+tab → previous_window shift+cmd+; → kitten kitty_grab/grab.py shift+cmd+down → neighboring_window down shift+cmd+h → move_window left shift+cmd+j → move_window down shift+cmd+k → move_window up shift+cmd+l → move_window right shift+cmd+left → neighboring_window left shift+cmd+right → neighboring_window right shift+cmd+up → neighboring_window up Changed shortcuts: cmd+enter → launch --location=split --cwd=current cmd+h → kitten pass_keys.py neighboring_window left alt+shift+h cmd+k → kitten pass_keys.py neighboring_window top alt+shift+k cmd+t → launch --cwd=current --type=tab --location=neighbor shift+cmd+/ → launch --allow-remote-control kitty +kitten kitty_search/search.py @active-kitty-window-id Colors: active_tab_background #f8f8f2 active_tab_foreground #282a36 background #282a36 color0 #21222c color1 #ff5555 color10 #69ff94 color11 #ffffa5 color12 #d6acff color13 #ff92df color14 #a4ffff color2 #50fa7b color3 #f1fa8c color4 #bd93f9 color5 #ff79c6 color6 #8be9fd color7 #f8f8f2 color8 #6272a4 color9 #ff6e6e cursor #f8f8f2 foreground #f8f8f2 inactive_tab_background #6272a4 inactive_tab_foreground #282a36 mark1_background #ff5555 mark1_foreground #282a36 selection_background #44475a selection_foreground #ffffff url_color #8be9fd Important environment variables seen by the kitty process: PATH /opt/homebrew/bin:/Users/italo/.pyenv/shims:/opt/homebrew/opt/coreutils/libexec/gnubin:/Users/italo/.config/fish/conf.d/bin:/opt/homebrew/opt/tcl-tk/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/bin:/Users/italo/go/bin:/Users/italo/.local/bin:/Users/italo/.cargo/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/italo/.local/miniconda3/condabin:/Applications/kitty.app/Contents/MacOS LANG en_GB.UTF-8 SHELL /opt/homebrew/bin/fish USER italo ```

Additional context Minimal kitty.conf:

background_image ~/Pictures/saber-4k.png
background_image_layout tiled

saber-4k.png: saber-4k.png

kovidgoyal commented 1 year ago

The only way the image would be tiled is if its resolution is smaller than the pixel resolution (not logical but actual pixels) of the monitor. So pick an large enough image.

oyarsa commented 1 year ago

Both the image (linked in the post) and the monitor are 4K (3840 × 2160).

This seems like some issue with a two-monitor setup with different resolutions because the image is not tiled in the built-in monitor, even when its resolution differs from that monitor.

oyarsa commented 1 year ago

I tried with other image sizes, and the smallest size that fills the monitor height almost totally is 5000 × 2813, which is bigger than it should be for a 4K monitor.

That being the case, I don't see how it's an image problem. A 4K image should fill a 4K monitor.

kovidgoyal commented 1 year ago

On Sun, Apr 30, 2023 at 06:19:33PM -0700, Italo Silva wrote:

Both the image (linked in the post) and the monitor are 4K (3840 × 2160).

This seems like some issue with a two-monitor setup with different resolutions because the image is not tiled in the built-in monitor, even when its resolution differs from that monitor.

The resolution differing is not sufficient, it has to be less than the resolution of th emonitor, only then will it be tiled, and the tiling happens automatically on the GPU, not under kitty's control.

oyarsa commented 1 year ago

it has to be less than the resolution of th monitor

I don't understand. I already verified that the image's resolution matches the monitor (both are 4K).

not under kitty's control

Then why did the behaviour change between 0.25 and 0.28?

oyarsa commented 1 year ago

Kitty 0.25.2:

image

Kitty 0.28.1:

image

The 0.25 behaviour also looks weird because the image is cropped.

kovidgoyal commented 1 year ago

No clue, I cannot replicate. Feel free to debug yourself, relevant code is the draw_bg() function in shaders.c and and bgimage_vertex.glsl shader both of which are small and simple.

oyarsa commented 1 year ago

This is the commit that changed the behaviour: https://github.com/kovidgoyal/kitty/commit/4d80427908b3d54ed6f48a57a250f404b1951984. I found it through bisect.

I don't know enough about graphics to understand it, but this should help.

kovidgoyal commented 1 year ago

Fix committed. I am travelling and dont have access to a mac ot test right now so please see it it works.

oyarsa commented 1 year ago

I've tested on macOS, and it's back to the behaviour before that patch.

Are you sure that's correct, though? Because now it has the opposite behaviour: it's cropped. See here:

image

Refer to the original image:

image
kovidgoyal commented 1 year ago

There are only two available dimensions, the viewport size and the window size. SO it has to be one of them. What is your monitors scale factor? i.e. how many physical pixels make a logical pixel? THe only way I can see for bth number to be incorrect is for the scale factor glfw reports to kitty to not match the actual scale factor of your monitor.

oyarsa commented 1 year ago

The 4K monitor is on 1.5 scaling (2560x1440). How can I check the scale factor from glfw?

kovidgoyal commented 1 year ago

It will be the ratio of the viewport size to window size. And the code where glfw gets the scale factor is in glfw/cocoa_window.m IIRC search for scale.

oyarsa commented 1 year ago

I added some logging to that file (commit), and the scale factor seems to be correct:

viewDidChangeBackingProperties 2.000000 2.000000
viewDidChangeBackingProperties 2.000000 2.000000
_glfwPlatformGetWindowContentScale 0.000000 0.000000
viewDidChangeBackingProperties 2.000000 2.000000
_glfwPlatformGetWindowContentScale 0.000000 0.000000
_glfwPlatformGetWindowContentScale 0.000000 0.000000

I'm afraid I don't understand what the code is doing. Could it be that glfw is also scaling the background image when it shouldn't be?

kovidgoyal commented 1 year ago

glfw doesnt see the image at all, it is directly transmitted to the GPU and didnt you say the scale should be 1.5 not 2?

oyarsa commented 1 year ago

didnt you say the scale should be 1.5 not 2

You're right; the correct scale should be 1.5. I got confused for a moment.

kovidgoyal commented 1 year ago

That will be the reason for the mismatch then.

kovidgoyal commented 1 year ago

I am guessing cocoa rounds these scale numbers up and then rescales post rendering to work around applications that dont support fractional scaling. Dont see much kitty can do here.

vagnermaltauro commented 9 months ago

hey @oyarsa how did you make the image darker, and highlight the terminal text? plase!

oyarsa commented 9 months ago

To darken the background, you can use background_tint. I'm not sure what you mean by "highlight the terminal text".