Tk Source Code

View Ticket
Login
Ticket UUID: 1600dc73a9ffc6901144aaf7a971f785cd570dc6
Title: Application window opens between ttk::combobox and its pop-down list
Type: Bug Version: 8.6.10
Submitter: florian Created on: 2020-10-09 08:26:40
Subsystem: 88. Themed Tk Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2020-10-13 15:33:17
Resolution: None Closed By: nobody
    Closed on:
Description:

If an external application's window opens while a ttk::combobox is "open", the new window opens just below the combobox's pop-down list, but above the ttk::combobox itself. This happens both on Windows 10 and Linux (Ubuntu 20.04).

Example (run this script in wish, then click the "Open other app" button, and within 3 seconds open the combobox's drop-down list):

ttk::button .button -text "1.) Open other app in 3 seconds." -command "after 3000 open_other"

ttk::combobox .combobox -values {value1 value2 value3}
.combobox set "2.) Open me before the other app opens"
grid .button   -row 0 -column 0 -padx 10 -pady 10 -sticky we
grid .combobox -row 1 -column 0 -padx 10 -pady 10 -sticky we
grid columnconfigure . 0 -weight 1

wm geometry . 400x300

proc open_other {} {
    set x [expr {[winfo rootx .] - 100}]
    set y [expr {[winfo rooty .] - 100}]
    exec [info nameofexecutable] -geometry 400x300+${x}+${y} -name "Other App" &
}

User Comments: bll added on 2020-10-13 15:33:17:
Tested on MacOS.  No issues.

bll added on 2020-10-13 01:24:14:
This seems to work to get the usable height/width:

{
    HWND hwnd;
    HMONITOR hmonitor;
    MONITORINFOEX minfo;
    LRESULT rc;
    hwnd = wmPtr->wrapper;
    if (hwnd == NULL) {
        hwnd = Tk_GetHWND(Tk_WindowId((Tk_Window) winPtr));
    }
    hmonitor = MonitorFromWindow (hwnd, MONITOR_DEFAULTTONEAREST);
    memset (&minfo, 0, sizeof (minfo));
    minfo.cbSize = (DWORD) sizeof (minfo);
    rc = GetMonitorInfo (hmonitor, (LPMONITORINFO) &minfo);
    fprintf (stdout, "width: %ld\n", minfo.rcWork.right - minfo.rcWork.left);
    fprintf (stdout, "height: %ld\n", minfo.rcWork.bottom - minfo.rcWork.top);
}

bll added on 2020-10-12 23:36:40:
Windows APIs of interest:

GetMonitorInfoW()

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmonitorinfow

SHAppBarMessage()

https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shappbarmessage?redirectedfrom=MSDN

fvogel added on 2020-10-12 19:34:24:

Removing the two occurrences of '-topmost 1' in combobox.tcl indeed would fix the present issue.

The problem with this suggested fix is that it would also resurrect bug [1991930]: this '-topmost 1' was added to fix it. And using '-topmost 1' followed by '-topmost 0' after a while does not help here, of course (the popdown gets hidden behind the taskbar).

I believe we should:

- Remove the two '-topmost 1' settings, I think this is the wrong fix for [1991930].
- And adjust ttk::combobox::PlacePopdown to take the taskbar into account. This is however not exactly trivial. proc taskbar on the wiki does not constitute an acceptable way to know this IMO, due to the screen flashing it makes (let alone the fact that the taskbar is not always at the bottom of the screen).


bll added on 2020-10-11 20:44:22:
Yes, on Windows, I commented out both:
   wm attributes ... -topmost 1
and it works better.  The popdown doesn't close, but it also is
not on top of the other windows.

There is a potential that this could cause other issues depending on the
stacking order of the Tk windows.  I wonder if '-topmost 1' could be used
initially, and after the window is drawn the attribute could be reset to
'-topmost 0'.

The Visibility check can be wrapped so it is X11 only.  Windows receives
an initial VisibilityUnobscured event, and no more visibility events.

bll added on 2020-10-11 20:32:24:
Ugh. Yes, the bugfix branch does not work on windows.
Obviously the Visibility events are not implemented in the same manner.

Note that the windows ttk::combobox code turns on -topmost for the 
popdown/listbox window (these are not needed for unix).
There may be other possibilities that work for windows.

fvogel added on 2020-10-11 20:19:54:
Trying the proposed workaround it appears that it does not seem to work for me on Windows.

Instead of trying to manually close the dropdown listbox when obscured, it would be better to let the wm handle this. The issue is we really need the overrideredirect in ttk::combobox::PopdownToplevel, otherwise the dropdown window gets decorations from the wm.

bll added on 2020-10-11 15:52:13:
Bugfix branch added:  bug-1600dc73

bll added on 2020-10-11 15:29:24:
I have attached a patch to library/ttk/combobox.tcl to solve this issue.
If the visibility state of the combobox changes, then the popdown is unposted.

Note that the visibility of the popdown does not change -- it receives no events 
since it is always on top.

bll added on 2020-10-11 14:55:44:
It appears that the overrideredirect setting in X11 causes the window to
also appear as the topmost.

It seems like the easiest way to fix this is to have the creation of a new
toplevel force an unpost of the combobox popdown in the current window.

Add to the 'open_other' procedure as a work-around:
   event generate . <ButtonPress> -x 1 -y 1

Attachments: