Skip to content

Commit

Permalink
fix instable window switching after minimize/restore (mintty#1242, mi…
Browse files Browse the repository at this point in the history
  • Loading branch information
mintty committed Jan 4, 2024
1 parent f454ab8 commit f1712ae
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/winmain.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,28 @@ manage_tab_hiding(void)
return sync_level() > 1;
}

/*
Fix instable tab set behaviour (#1242). There are 3 changes below;
a weird set of 4 combinations of them fixes the issue while the others don't.
Def. fix1242 chooses among the set of working fixes,
0 (none, default), 1 (a and b), 2 (b), 3 (c)
As they might interfere with future changes related to tabs, these options
are kept in the source for documentation.
*/
#ifndef fix1242
#define fix1242 0
#endif
#if fix1242 == 1
#define fix1242a
#define fix1242b
#endif
#if fix1242 == 2
#define fix1242b
#endif
#if fix1242 == 3
#define fix1242c
#endif

/*
Notify tab focus. Manage hidden tab status.
*/
Expand All @@ -797,9 +819,11 @@ win_set_tab_focus(char tag)
// guard by is_init to avoid hiding background tabs by early WM_ACTIVATE
if (is_init && manage_tab_hiding()) {
// hide background tabs; rather here than below?
#ifdef fix1242a
if (cfg.window) // not hidden explicitly
// attempt to suppresses initial Ctrl+TAB
win_hide_other_tabs(wnd);
#endif

//printf("[%p] set_tab_focus %c focus %d\n", wnd, tag, GetFocus() == wnd);
// don't need to unhide as we don't hide above
Expand All @@ -812,6 +836,12 @@ win_set_tab_focus(char tag)
LONG style = GetWindowLong(wnd, GWL_EXSTYLE);
style &= ~WS_EX_TOOLWINDOW;
SetWindowLong(wnd, GWL_EXSTYLE, style);

#ifndef fix1242a
// hide background tabs
if (cfg.window) // not hidden explicitly
win_hide_other_tabs(wnd);
#endif
}
}

Expand Down Expand Up @@ -3325,12 +3355,16 @@ win_update_transparency(int trans, bool opaque)
LONG style = GetWindowLong(wnd, GWL_EXSTYLE);

// check whether this is actually a background tab that should be hidden
#ifdef fix1242b
if (style & WS_EX_TOOLWINDOW) {
//printf("[%p] SetLayeredWindowAttributes\n", wnd);
// for virtual hiding, set max transparency
SetWindowLong(wnd, GWL_EXSTYLE, style | WS_EX_LAYERED);
SetLayeredWindowAttributes(wnd, 0, 0, LWA_ALPHA);
}
else {
else
#endif
{
// otherwise, set actual transparency
style = trans ? style | WS_EX_LAYERED : style & ~WS_EX_LAYERED;
SetWindowLong(wnd, GWL_EXSTYLE, style);
Expand Down Expand Up @@ -4020,7 +4054,7 @@ static struct {
wm_user = false;

when WM_COMMAND or WM_SYSCOMMAND: {
# ifdef debug_messages
# if defined(debug_messages) || defined(debug_tabs)
static struct {
uint idm_;
char * idm_name;
Expand Down Expand Up @@ -7525,8 +7559,10 @@ static int dynfonts = 0;

//printf("check all_hidden %d vanished %d\n", all_hidden, vanished);
if (manage_tab_hiding() && all_hidden) {
#ifdef fix1242c
// unhide myself, hide other tabs:
win_set_tab_focus('U');
#endif
// maybe not necessary to repeat this:
win_update_transparency(cfg.transparency, cfg.opaque_when_focused);
}
Expand Down
3 changes: 3 additions & 0 deletions wiki/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ Misc
* Fix handling of options to be saved (#1246, #1247).
* Tune and fix click-opening URL (mintty/wsltty#346).

Window handling
* Fix instable window switching after minimize/restore (#1242, #1249).

Configuration
* New user-definable key Alt for option KeyFunctions (#1245).
* New user-definable function intr (~#1245).
Expand Down

0 comments on commit f1712ae

Please sign in to comment.