Skip to content

Commit

Permalink
Window: Prefer iterating from front to find window by class/ID
Browse files Browse the repository at this point in the history
  • Loading branch information
JGRennison committed Nov 10, 2024
1 parent 64dceb0 commit 4b939ae
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ Window *FindWindowById(WindowClass cls, WindowNumber number)
{
if (cls < WC_END && !_present_window_types[cls]) return nullptr;

for (Window *w : Window::IterateFromBack()) {
for (Window *w : Window::IterateFromFront()) {
if (w->window_class == cls && w->window_number == number) return w;
}

Expand All @@ -1140,7 +1140,7 @@ Window *FindWindowByClass(WindowClass cls)
{
if (cls < WC_END && !_present_window_types[cls]) return nullptr;

for (Window *w : Window::IterateFromBack()) {
for (Window *w : Window::IterateFromFront()) {
if (w->window_class == cls) return w;
}

Expand All @@ -1154,7 +1154,7 @@ Window *FindWindowByClass(WindowClass cls)
*/
Window *FindWindowByToken(WindowToken token)
{
for (Window *w : Window::IterateFromBack()) {
for (Window *w : Window::IterateFromFront()) {
if (w->GetWindowToken() == token) return w;
}

Expand All @@ -1168,9 +1168,10 @@ Window *FindWindowByToken(WindowToken token)
*/
Window *GetMainWindow()
{
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
assert(w != nullptr);
return w;
for (Window *w : Window::IterateFromBack()) {
if (w->window_class == WC_MAIN_WINDOW && w->window_number == 0) return w;
}
NOT_REACHED();
}

/**
Expand Down

0 comments on commit 4b939ae

Please sign in to comment.