Repository navigation
Conversation
On a HiDPI desktop the X server (or XWayland with native scaling) reports an ordinary 96 dpi screen and announces the scale only through the Xft.dpi resource, e.g. 192 for 200 %. Tk's text follows Xft.dpi, but nothing else did: widget sizes, borders, sliders and scrollbars, fixed window sizes, images, the preview's lines, DRO text and icons, and PyVCP's drawn widgets all came out at their 96 dpi size. Tk: - tcl/hidpi.tcl reads Xft.dpi (LINUXCNC_UI_SCALE overrides it, 1 disables), sets tk scaling and scales the pixel defaults of the Tk and BWidget widgets through the option database, below ~/.Xresources and a program's own settings. It also offers scale and scale_image for programs' own pixel sizes and images. - linuxcnc.tcl turns it on when Tk is loaded, so the Tcl tools get it; halshow, emccalib and halconfig, which load Tk after it, call it themselves. nf.init_hidpi() does the same for Python Tk programs. - pickconfig, halshow (window, sidebar, tree rows, watch canvas) and the splash screen scale their own pixel sizes and images; AXIS scales its toolbar and other icons. - linuxcnctop's name column and the vismach window scale. Preview: - glcanon_gl.set_line_scale() widens every line the preview draws, and build_atlas() takes a scale for the DRO font; the DRO's home/limit icons and offsets follow the font's scale. - AXIS sets both from the Tk factor. gremlin follows the GTK window's scale factor, checked every frame. PyVCP: - Panels scale their XML pixel sizes, line widths and images, embedded in AXIS or run standalone. Point-size fonts are left alone, as Tk already scales them. At 96 dpi, or without Xft.dpi as under Xvfb, the factor is 1 and nothing changes.
grandixximo
left a comment
There was a problem hiding this comment.
Related: HD screens came up in the gmoccapy roadmap #3498, where hansu pointed to the window manager's zoom, and #2398 (pickconfig on a 200 % desktop) was fixed by hansu in #4010 by sizing the tree rows from the font's line height. Sizing from font metrics follows Xft.dpi without changing tk scaling, which is what shrinks the pixel fonts below. Did you consider that over a global factor, or does it not reach far enough (images, GL lines)?
|
|
||
| # Sizes given in screen units (points, mm, inches) - many Tk defaults, | ||
| # e.g. button padding - follow tk scaling. | ||
| tk scaling [expr {$factor * 96.0 / 72.0}] |
There was a problem hiding this comment.
With tk scaling at factor*96/72, Tk turns a pixel font into points with that scaling and Xft.dpi doubles it back, so pixel fonts stay at their nominal size. On master they followed Xft.dpi. Doesn't ngcgui's default {Helvetica -10 bold} then drop to half its current size on a 200 % desktop (22 px => 11 px line height here)? tkbackplot's -10 buttons too.
There was a problem hiding this comment.
Confirmed: at 192 dpi {Helvetica -10 bold} went from 20 px on master to 11 px. Tk turns -10 into points with tk scaling and Xft then applies Xft.dpi, so the mismatch on master (96/72 vs 192) is what doubles pixel fonts there. 45836d6 no longer touches tk scaling, so it's 20 px again. The Button padX/padY defaults, which are in screen units and relied on it, are now scaled through the option database like the other pixel defaults.
|
|
||
| # Desktop scale relative to 96 dpi, rounded to a quarter step. | ||
| proc linuxcnc::hidpi::detect {} { | ||
| if {[info exists ::env(LINUXCNC_UI_SCALE)] |
There was a problem hiding this comment.
With Xft.dpi 96 and LINUXCNC_UI_SCALE=2, the widgets double, point text stays at 19 px and pixel fonts halve to 20 px. Should the override also set the Xft dpi, or is it meant only for desktops that don't announce Xft.dpi?
There was a problem hiding this comment.
It can't set the Xft dpi: Tk reads Xft.dpi when it opens the display, and there's no way to change it from Tcl. So the override scales widget sizes, images and lines only, and text keeps following Xft.dpi. With tk scaling left alone it no longer shrinks pixel fonts. I've documented it that way in hidpi.tcl, mainly for correcting a detected factor. Happy to drop it if you think it's more confusing than useful.
|
|
||
| # Sizes given in screen units (points, mm, inches) - many Tk defaults, | ||
| # e.g. button padding - follow tk scaling. | ||
| tk scaling [expr {$factor * 96.0 / 72.0}] |
There was a problem hiding this comment.
This runs before the factor == 1.0 return, so at factor 1 the X server's own DPI is replaced by 96 (Xvfb: 1.389 => 1.332, 12 pt 20 => 19 px without Xft.dpi). Move the return above it, so nothing changes at factor 1?
There was a problem hiding this comment.
Gone with 45836d6, which doesn't set tk scaling at all. At factor 1 nothing is touched.
| ttk::style configure . -arrowsize [scale 12] \ | ||
| -sliderthickness [scale 15] -sliderlength [scale 30] \ | ||
| -indicatordiameter [scale 12] -indicatorsize [scale 12] \ | ||
| -gripcount [scale 5] |
There was a problem hiding this comment.
-gripcount [scale 5]: isn't gripcount a number of lines, not pixels?
There was a problem hiding this comment.
Right, it's a count of grip lines. It stays at 5 now.
| """Scale Tk to the desktop's HiDPI factor (Xft.dpi) - tk scaling and the | ||
| pixel defaults of the Tk widgets, see tcl/hidpi.tcl - and return the | ||
| factor (1.0 when unscaled). Call before creating widgets. Safe to call | ||
| again: later calls only return the factor.""" |
There was a problem hiding this comment.
"later calls only return the factor": rs274.options.install() re-sources linuxcnc.tcl after init_hidpi(), and the namespace eval resets initialised to 0, so init runs again. Harmless, every step is absolute; if {![info exists initialised]} would make the docstring true.
There was a problem hiding this comment.
Good catch. The namespace variables are guarded with info exists now, so re-sourcing linuxcnc.tcl keeps the earlier init and the docstring is true.
Tk's Xft code turns a pixel font into points with tk scaling and Xft
then applies Xft.dpi, so setting tk scaling to factor*96/72 halved every
pixel font (ngcgui's {Helvetica -10 bold}, tkbackplot, lh_chart) compared
to master. Text is now left entirely to Xft.dpi, as on master; the
Button padX/padY defaults, which are in screen units and relied on tk
scaling, go into the option database with the other pixel defaults.
This also means nothing is changed at factor 1 any more.
- ttk -gripcount is a number of lines, not pixels: don't scale it.
- Guard the namespace variables so that re-sourcing linuxcnc.tcl (as
rs274.options.install does) keeps the state of an earlier init.
- Document that LINUXCNC_UI_SCALE scales sizes, images and lines but not
text, which follows Xft.dpi.
|
Font metrics cover text-sized things like the pickconfig rows from #4010, but a lot of what this PR scales has nothing to do with a font: images and icons, the preview's GL line widths, the DRO atlas, PyVCP's drawn widgets, slider and scrollbar sizes. Those need a factor. Where something does follow a font I'd rather keep using the metrics, as #4010 does. You're right that |
|
the GTK UIs work fine on hidpi, this PR only changes the line width in the backplot. |
Their text uses a pixel font sized from the dial, which is now in screen pixels. With tk scaling left alone Tk's Xft code scales pixel fonts by Xft.dpi already, so the text came out at twice its size on a 200 % desktop. Size it from the 96 dpi size, as the meter does for its point fonts.
On a HiDPI desktop the X server (or XWayland with native scaling) reports an ordinary 96 dpi screen and announces the scale only through the Xft.dpi resource, e.g. 192 for 200 %. Tk's text follows Xft.dpi, but nothing else did: widget sizes, borders, sliders and scrollbars, fixed window sizes, images, the preview's lines, DRO text and icons, and PyVCP's drawn widgets all came out at their 96 dpi size.
Tk:
Preview:
PyVCP:
At 96 dpi, or without Xft.dpi as under Xvfb, the factor is 1 and nothing changes.