Check-in [e54a8ad2b7]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:in tk protect against weird screen dpi values
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e54a8ad2b7fa9da16a8a38e94c839d93770223a5
User & Date: chw 2019-06-12 12:53:54
Context
2019-06-12
13:05
improve twv demos check-in: d0fc7d3af8 user: chw tags: trunk
12:53
in tk protect against weird screen dpi values check-in: e54a8ad2b7 user: chw tags: trunk
11:33
fix typos in some build scripts check-in: 9d6b7570a1 user: chw tags: trunk
Changes

Changes to jni/sdl2tk/library/tk.tcl.

494
495
496
497
498
499
500





501

502
503
504
505
506
507
508
# ----------------------------------------------------------------------
# Setup flags/vars for SDL, screen dpi, and Android.
# ----------------------------------------------------------------------

namespace eval ::tk {
    variable sdltk [expr {[info command "sdltk"] eq "sdltk"}]
    variable dpi





    set dpi [expr int((25.4 * [winfo screenwidth .]) / [winfo screenmmwidth .])]

    variable android 0
    if {$sdltk} {
	set android [sdltk android]
    }
}
 
# ----------------------------------------------------------------------







>
>
>
>
>
|
>







494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# ----------------------------------------------------------------------
# Setup flags/vars for SDL, screen dpi, and Android.
# ----------------------------------------------------------------------

namespace eval ::tk {
    variable sdltk [expr {[info command "sdltk"] eq "sdltk"}]
    variable dpi
    set dpi [winfo screenmmwidth .]
    if {$dpi <= 0} {
	# Observed in X on Wayland in a VM, provide fallback
	set dpi 75
    } else {
	set dpi [expr {int((25.4 * [winfo screenwidth .]) / $dpi)}]
    }
    variable android 0
    if {$sdltk} {
	set android [sdltk android]
    }
}
 
# ----------------------------------------------------------------------

Changes to jni/sdl2tk/unix/tkUnixEvent.c.

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
...
183
184
185
186
187
188
189


















190
191
192
193
194
195
196
    */
    display = XkbOpenDisplay((char *)displayNameStr, &event, &error, &major,
	    &minor, &reason);

    if (display == NULL) {
	/*fprintf(stderr,"event=%d error=%d major=%d minor=%d reason=%d\nDisabling xkb\n",
	event, error, major, minor, reason);*/
	display  = XOpenDisplay(displayNameStr);
    } else {
	use_xkb = TK_DISPLAY_USE_XKB;
	/*fprintf(stderr, "Using xkb %d.%d\n", major, minor);*/
    }

    if (display == NULL) {
	return NULL;
................................................................................
#ifdef TK_USE_INPUT_METHODS
    OpenIM(dispPtr);
    XRegisterIMInstantiateCallback(dispPtr->display, NULL, NULL, NULL,
	    InstantiateIMCallback, (XPointer) dispPtr);
#endif
    Tcl_CreateFileHandler(ConnectionNumber(display), TCL_READABLE,
	    DisplayFileProc, dispPtr);



















    /*
     * Key map info must be available immediately, because of "send event".
     */
    TkpInitKeymapInfo(dispPtr);

    return dispPtr;







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
    */
    display = XkbOpenDisplay((char *)displayNameStr, &event, &error, &major,
	    &minor, &reason);

    if (display == NULL) {
	/*fprintf(stderr,"event=%d error=%d major=%d minor=%d reason=%d\nDisabling xkb\n",
	event, error, major, minor, reason);*/
	display = XOpenDisplay(displayNameStr);
    } else {
	use_xkb = TK_DISPLAY_USE_XKB;
	/*fprintf(stderr, "Using xkb %d.%d\n", major, minor);*/
    }

    if (display == NULL) {
	return NULL;
................................................................................
#ifdef TK_USE_INPUT_METHODS
    OpenIM(dispPtr);
    XRegisterIMInstantiateCallback(dispPtr->display, NULL, NULL, NULL,
	    InstantiateIMCallback, (XPointer) dispPtr);
#endif
    Tcl_CreateFileHandler(ConnectionNumber(display), TCL_READABLE,
	    DisplayFileProc, dispPtr);

    /*
     * Observed weird WidthMMOfScreen() in X on Wayland on a
     * Fedora 30/i386 running in a VM. Fallback to 75 dpi,
     * otherwise many other strange things may happen later.
     */
    if (WidthMMOfScreen(DefaultScreenOfDisplay(display)) <= 0) {
	int mm;

	mm = (WidthOfScreen(DefaultScreenOfDisplay(display)) * 25.4) / 75.0;
	WidthMMOfScreen(DefaultScreenOfDisplay(display)) = mm;
    }
    if (HeightMMOfScreen(DefaultScreenOfDisplay(display)) <= 0) {
	int mm;

	mm = (HeightOfScreen(DefaultScreenOfDisplay(display)) * 25.4) / 75.0;
	HeightMMOfScreen(DefaultScreenOfDisplay(display)) = mm;
    }

    /*
     * Key map info must be available immediately, because of "send event".
     */
    TkpInitKeymapInfo(dispPtr);

    return dispPtr;