Fix is_focus_priority_greater function

This commit is contained in:
Simon Ser 2021-03-02 09:23:53 +01:00
parent 2d992653a0
commit 0f96db3dc2

View file

@ -1306,6 +1306,12 @@ check_wlr_surface_deleted ( win *w )
} }
} }
static bool
win_has_game_id( win *w )
{
return w->gameID != 0;
}
static bool static bool
win_is_override_redirect( win *w ) win_is_override_redirect( win *w )
{ {
@ -1318,31 +1324,43 @@ win_skip_taskbar_and_pager( win *w )
return w->skipTaskbar && w->skipPager; return w->skipTaskbar && w->skipPager;
} }
// Returns true if a's focus priority > b's. /* Returns true if a's focus priority > b's.
*
* This function establishes a list of criteria to decide which window should
* have focus. The first criteria has higher priority. If the first criteria
* is a tie, fallback to the second one, then the third, and so on.
*
* The general workflow is:
*
* if ( windows don't have the same criteria value )
* return true if a should be focused;
* // This is a tie, fallback to the next criteria
*/
static bool static bool
is_focus_priority_greater( win *a, win *b ) is_focus_priority_greater( win *a, win *b )
{ {
if ( !a->gameID && b->gameID ) if ( win_has_game_id( a ) != win_has_game_id ( b ) )
return false; return win_has_game_id( a );
// We allow using an override redirect window in some cases, but if we have // We allow using an override redirect window in some cases, but if we have
// a choice between two windows we always prefer the non-override redirect // a choice between two windows we always prefer the non-override redirect
// one. // one.
if ( win_is_override_redirect( a ) && !win_is_override_redirect( b ) ) if ( win_is_override_redirect( a ) != win_is_override_redirect( b ) )
return false; return !win_is_override_redirect( a );
if ( a->wantsUnfocus && !b->wantsUnfocus ) if ( a->wantsUnfocus != b->wantsUnfocus )
return false; return !a->wantsUnfocus;
// Wine sets SKIP_TASKBAR and SKIP_PAGER hints for WS_EX_NOACTIVATE windows. // Wine sets SKIP_TASKBAR and SKIP_PAGER hints for WS_EX_NOACTIVATE windows.
// See https://github.com/Plagman/gamescope/issues/87 // See https://github.com/Plagman/gamescope/issues/87
if ( win_skip_taskbar_and_pager( a ) && !win_skip_taskbar_and_pager ( b ) ) if ( win_skip_taskbar_and_pager( a ) != win_skip_taskbar_and_pager ( b ) )
return false; return !win_skip_taskbar_and_pager( a );
if ( a->damage_sequence < b->damage_sequence ) // The damage sequences are only relevant for game windows.
return false; if ( win_has_game_id( a ) && a->damage_sequence != b->damage_sequence )
return a->damage_sequence > b->damage_sequence;
return true; return false;
} }
static void static void