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

Font size super tiny and unchangeable when connecting a display with the setting "optimize for <external display>" on macOS #1056

Closed
terlar opened this issue Oct 9, 2018 · 15 comments

Comments

@terlar
Copy link

terlar commented Oct 9, 2018

When connecting a new display to a computer running macOS 10.13.6 and selecting in the display menu that the screen should be optimized for the external display and not the built-in one.

E.g.
optimize-for-remote-screen

The font renders super tiny and is unchangeable. The keybindings for decreasing/increasing/resetting size does nothing as well as manually running something like:

kitty @ set-font-size 20.0

Assuming this could be some GL releated rendering issue I started kitty with debug-gl flag, but that doesn't output any extra information. However I see errors mentioning Cocoa: Failed to find a screen for monitor which potentially could be related. I don't see that when I select the other option and optimize for the Built-in Retina Display.

$ kitty --debug-gl                                                                                                                                                                                                                                                                                                                       (14.53s) 
[282 17:21:50.250056] Failed to set locale with LANG: en_SE.UTF-8
GL version string: '4.1 INTEL-10.36.19' Detected version: 4.1
[282 17:22:13.334988] [glfw error 65544]: Cocoa: Failed to find a screen for monitor
[282 17:22:18.640242] [glfw error 65544]: Cocoa: Failed to find a screen for monitor

Anything else that could be done to debug this further to get to the bottom of this? Restarting kitty makes the terminal be in a workable state again, until you disconnect and reconnect the external display again, then the same behavior is experienced.

@kovidgoyal
Copy link
Owner

Do the font size bindings you are using work normally? And before using kitty @ did you enable remote control?

@terlar
Copy link
Author

terlar commented Oct 9, 2018

Yes, the bindings normally work, and as soon as I disconnect the screen or change to optimize for built-in screen they start working again. And yes, I enabled the remote control. Sorry for missing out on this information in my first description.

@kovidgoyal
Copy link
Owner

try using an outrageously large number for the font size, like 200 or 2000 (I suspect what is happening is the DPI used when the external monitor is connected is some invalid value)

@terlar
Copy link
Author

terlar commented Oct 9, 2018

Good theory, I haven't thought about that. However seems that is not the case. I tried with 0.0, 1.0, 200, 2000 and 20000. None of them affect the font-size in any way. However as soon as I disconnect the display or change to optimize for the Built-in Retina Display I get that font-change that I set.

@kovidgoyal
Copy link
Owner

well in that case you will need to debug, font size calculations are basically a function of the specified size in pts and the DPI. look in update_os_window_viewport() in glfw.c and check what DPI value is being set.

Then the cell size calculation is in calc_cell_metrics() in fonts.c

@kovidgoyal
Copy link
Owner

no followup

@terlar
Copy link
Author

terlar commented Oct 20, 2018

Sorry, I wasn't sure about how to run a debugger or similar with the c code. I will look into it when I have some free time and get back to you at that time. Thanks for the help and instructions

@kovidgoyal
Copy link
Owner

you dont need to run a debugger, just insert some printf() statements to print out the values. You can see the output of the printf() statements by running kitty from within another terminal. And you can build kityt from source by following the instructions on the kitty website.

@terlar
Copy link
Author

terlar commented Oct 20, 2018

Thank you for the instructions, this was easier than I thought.

I did the following operations:

  1. Open kitty
  2. Zoom in
  3. Zoom out
  4. Connect remote screen
  5. Zoom in
  6. Zoom out
  7. Disconnect remote screen

This was the following output:

cell height: 42, cell width: 14, baseline: 30
X DPI: 144.000000, Y DPI: 144.000000
cell height: 48, cell width: 16, baseline: 35
cell height: 42, cell width: 14, baseline: 30
[293 12:11:10.538417] [glfw error 65544]: Cocoa: Failed to find a screen for monitor
X DPI: 144.000000, Y DPI: 144.000000
cell height: 18, cell width: 6, baseline: 12
cell height: 18, cell width: 6, baseline: 12
cell height: 18, cell width: 6, baseline: 12
X DPI: 0.000000, Y DPI: 0.000000
cell height: 42, cell width: 14, baseline: 30

Seems that when the screen is connected the cell height and cell width stays the same. Another curious thing is also that the DPI X/Y says 0 when the screen is disconnected. Not sure if this tells you anything, I will continue explore a bit. If you have some pointers to more information that could be useful I could also present that.

@kovidgoyal
Copy link
Owner

can you post the diff to show me exactly what you are printing.

@terlar
Copy link
Author

terlar commented Oct 20, 2018

diff --git a/kitty/fonts.c b/kitty/fonts.c
index 80323759..f9065132 100644
--- a/kitty/fonts.c
+++ b/kitty/fonts.c
@@ -407,6 +407,7 @@ calc_cell_metrics(FontGroup *fg) {
         underline_position += MIN(cell_height - 1, (unsigned)line_height_adjustment / 2);
     }
     sprite_tracker_set_layout(&fg->sprite_tracker, cell_width, cell_height);
+    printf("cell height: %d, cell width: %d, baseline: %d\n", cell_height, cell_width, baseline);
     fg->cell_width = cell_width; fg->cell_height = cell_height;
     fg->baseline = baseline; fg->underline_position = underline_position; fg->underline_thickness 
= underline_thickness;
     free(fg->canvas);
diff --git a/kitty/glfw.c b/kitty/glfw.c
index 74063c3e..eaa3b305 100644
--- a/kitty/glfw.c
+++ b/kitty/glfw.c
@@ -36,6 +36,7 @@ update_os_window_viewport(OSWindow *window, bool notify_boss) {
     window->viewport_y_ratio = (double)window->viewport_height / (double)h;
     double xdpi = window->logical_dpi_x, ydpi = window->logical_dpi_y;
     set_os_window_dpi(window);
+    printf("X DPI: %f, Y DPI: %f\n", xdpi, ydpi);
     bool dpi_changed = (xr != 0.0 && xr != window->viewport_x_ratio) || (yr != 0.0 && yr != window
->viewport_y_ratio) || (xdpi != window->logical_dpi_x) || (ydpi != window->logical_dpi_y);
 
     window->viewport_size_dirty = true;

@kovidgoyal
Copy link
Owner

If the cell height calculation is resulting in the same cell height values with different font sizes, then something very strange is going on. Look in font_group_for() in fonts.c to see exactly what pt sz and dpi values are being used to create the font group that is then used in calc_cell_metrics()

@kovidgoyal kovidgoyal reopened this Oct 23, 2018
@terlar
Copy link
Author

terlar commented Oct 23, 2018

diff --git a/kitty/fonts.c b/kitty/fonts.c
index 80323759..ea8b802a 100644
--- a/kitty/fonts.c
+++ b/kitty/fonts.c
@@ -162,6 +162,7 @@ font_group_for(double font_sz_in_pts, double logical_dpi_x, double logical_dpi_y
     add_font_group();
     FontGroup *fg = font_groups + num_font_groups - 1;
     memset(fg, 0, sizeof(FontGroup));
+    printf("font_size: %f, dpi_x: %f, dpi_y: %f\n", font_sz_in_pts, logical_dpi_x, logical_dpi_y);
     fg->font_sz_in_pts = font_sz_in_pts;
     fg->logical_dpi_x = logical_dpi_x;
     fg->logical_dpi_y = logical_dpi_y;
@@ -407,6 +408,7 @@ calc_cell_metrics(FontGroup *fg) {
         underline_position += MIN(cell_height - 1, (unsigned)line_height_adjustment / 2);
     }
     sprite_tracker_set_layout(&fg->sprite_tracker, cell_width, cell_height);
+    printf("cell height: %d, cell width: %d, baseline: %d\n", cell_height, cell_width, baseline);
     fg->cell_width = cell_width; fg->cell_height = cell_height;
     fg->baseline = baseline; fg->underline_position = underline_position; fg->underline_thickness = underline_thickness;
     free(fg->canvas);

We are closing in on the issue, so with this new log line I can see that the font-size is changing but as kind of suspected before the DPI is ending up as 0.

X DPI: 144.000000, Y DPI: 144.000000
viewport width: 1680, viewport height: 2100
font_size: 16.000000, dpi_x: 144.000000, dpi_y: 144.000000
cell height: 48, cell width: 16, baseline: 35
font_size: 14.000000, dpi_x: 144.000000, dpi_y: 144.000000
cell height: 42, cell width: 14, baseline: 30

*** Screen connected ***

[296 21:54:04.506086] [glfw error 65544]: Cocoa: Failed to find a screen for monitor
X DPI: 144.000000, Y DPI: 144.000000
viewport width: 1280, viewport height: 1440
font_size: 14.000000, dpi_x: 0.000000, dpi_y: 0.000000
cell height: 18, cell width: 6, baseline: 12
font_size: 12.000000, dpi_x: 0.000000, dpi_y: 0.000000
cell height: 18, cell width: 6, baseline: 12
font_size: 14.000000, dpi_x: 0.000000, dpi_y: 0.000000
cell height: 18, cell width: 6, baseline: 12
font_size: 12.000000, dpi_x: 0.000000, dpi_y: 0.000000
cell height: 18, cell width: 6, baseline: 12
font_size: 10.000000, dpi_x: 0.000000, dpi_y: 0.000000
cell height: 18, cell width: 6, baseline: 12
font_size: 12.000000, dpi_x: 0.000000, dpi_y: 0.000000
cell height: 18, cell width: 6, baseline: 12
font_size: 14.000000, dpi_x: 0.000000, dpi_y: 0.000000
cell height: 18, cell width: 6, baseline: 12
font_size: 16.000000, dpi_x: 0.000000, dpi_y: 0.000000
cell height: 18, cell width: 6, baseline: 12
font_size: 18.000000, dpi_x: 0.000000, dpi_y: 0.000000
cell height: 18, cell width: 6, baseline: 12
font_size: 20.000000, dpi_x: 0.000000, dpi_y: 0.000000
cell height: 18, cell width: 6, baseline: 12

@terlar
Copy link
Author

terlar commented Oct 23, 2018

I also notice that update_os_window_viewport returns DPI of 0 everytime the window is resized and the screen is connected.

[296 22:22:43.995260] [glfw error 65544]: Cocoa: Failed to find a screen for monitor
X DPI: 0.000000, Y DPI: 0.000000
viewport width: 2560, viewport height: 720
[296 22:22:45.667500] [glfw error 65544]: Cocoa: Failed to find a screen for monitor
X DPI: 0.000000, Y DPI: 0.000000
viewport width: 1280, viewport height: 1440

Where does the DPI values originate?

I traced it from the create_os_window into the load_fonts_data function, however, that one is only called once at the beginning.

@terlar
Copy link
Author

terlar commented Oct 24, 2018

I can verify that this works now, thank you for the fix. It was a tricky one to track down.

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

2 participants