Ticket UUID: | 2b1ce31780542b90b7180b7f4ad8c6b77c24bbb0 | |||
Title: | Generalise scaling variables for multi-display systems | |||
Type: | Bug | Version: | 8.7 | |
Submitter: | kjnash | Created on: | 2023-08-23 14:39:31 | |
Subsystem: | 46. Unix Fonts | Assigned To: | nobody | |
Priority: | 5 Medium | Severity: | Minor | |
Status: | Open | Last Modified: | 2023-09-18 19:59:33 | |
Resolution: | None | Closed By: | nobody | |
Closed on: | ||||
Description: |
The variables ::tk::scalingPct and ::tk::svgFmt describe the screen used by the root window "." Tk attempts to be compatible with multiple independent displays, usually by giving commands optional arguments "-displayof WINDOW", where WINDOW defaults to "." if these arguments are not provided. It would be possible to generalise ::tk::scalingPct and ::tk::svgFmt by making them arrays or dicts, but it is neater to replace them with commands that use these optional arguments. The suggested commands are: ::tk_scalingPct ?-displayof WINDOW? ::tk_svgFormat ?-displayof WINDOW? The branch scaling-fixes has an implementation. The draft man page doc/scalingPct.n documents the commands; the intention is that for the base screen they will provide the same facilities as the variables ::tk::scalingPct and ::tk::svgFmt, except that the return value is fresh if the script has modified [tk scaling]. In case the commands are unsatisfactory and need to be reverted, the variables ::tk::scalingPct and ::tk::svgFmt have not been removed, and are still used in the demos. A remaining problem is that on X11, screens other than "-displayof ." are not initialised at startup - on X11 the initialisation process should set [tk scaling] on each screen. The first call to [tk_scalingPct -displayof $w] or [tk_svgFormat -displayof $w] will do this initialisation for the screen of window $w. It is not possible to do the initialisation at startup unless the screens are known. The script in the attachment does "brute force" discovery of screens. | |||
User Comments: |
nemethi (claiming to be Csaba Nemethi) added on 2023-09-18 19:59:33:
1. The variables ::tk::scalingPct and ::tk::svgFmt are now automatically kept in sync with [tk scaling]. 2. AFAIK, only toplevel windows can be explicitly created on a screen that is different from that of the main window. I think that the vast majority of applications create their toplevels on the screen of the main window, hence the current implementation of scaling support probably covers the needs of the vast majority of applications. 3. This said, Keith is right that it would be better to provide full support for multi-display systems. His proposed changes in the Tk library scripts are IMHO quite OK. OTOH, instead of the "brute force" discovery of screens, I propose to do the scaling-related initialization of a screen other than "-displayof ." when the application creates a toplevel on it. As a proof of concept, I have replaced the last two lines of the body of the Tk_CreateWindowFromPath() function in tkWindow.c with the following code: tkwin = CreateTopLevelWindow(interp, parent, pathName+numChars+1, screenName, /* flags */ 0); if (strlen(screenName) != 0) { char script[80]; snprintf(script, sizeof script, "::tk_ScalingPct -displayof %s", pathName); Tcl_EvalEx(interp, script, TCL_INDEX_NONE, TCL_EVAL_GLOBAL); } return tkwin; That is, after creating the toplevel pathName on a different screen, the function invokes ::tk_ScalingPct -displayof pathName which, among others, will set tk scaling on that screen to a screen-specific value. This will take some time in case of the first toplevel on that screen; for subsequent toplevels it will return in "no time". fvogel added on 2023-09-17 16:07:43: I didn't follow the recent scaling changes that have lead to the introduction of the new ::tk::scalingPct and ::tk::svgFmt variables, sorry. Someone else, who worked on scaling issues such as Csaba, should have a more informed and valuable opinion than me. In any case, such a change (creation of new commands) would need a TIP. Addition of the new variables ::tk::scalingPct and ::tk::svgFmt would have needed a TIP as well IMHO. jan.nijtmans added on 2023-09-15 12:24:26: @fvogel, what do you think? kjnash added on 2023-09-01 17:40:40: Revised form of script tkScreenDiscovery.tcl attached.
The unconventional VNC display "::1:1.0" mentioned in bug report [2912473] is :display.screen = :1.0 on host ::1, the IPv6 address of localhost.
However, rather than attempt to discover all displays at startup, it would be simpler to initialise an X11 display "SCREEN" on first use, i.e. on the first evaluation of
toplevel .foo -screen SCREEN
At present only the -screen used by "." is initialised. Other screens on X11 will default to [tk scaling 1.333333], but will use the values tk::scalingPct and tk::svgFmt that are calculated for the main display.
kjnash added on 2023-08-25 12:55:07: Implementation moved from branch scaling-fixes to new branch scaling-multidisplay. Earlier changes in branch scaling-fixes now committed to trunk. |
Attachments:
- tkScreenDiscovery.tcl [download] added by kjnash on 2023-09-01 17:03:03. [details]