1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:24:58 +00:00

WindowServer: Prefer structured bindings when iterating over HashMaps

This commit is contained in:
Hendiadyoin1 2024-03-01 14:05:52 +01:00 committed by Andrew Kaster
parent 773a280bdf
commit d6c631ebe0
5 changed files with 29 additions and 32 deletions

View file

@ -67,10 +67,10 @@ ConnectionFromClient::~ConnectionFromClient()
MenuManager::the().close_all_menus_from_client({}, *this); MenuManager::the().close_all_menus_from_client({}, *this);
auto windows = move(m_windows); auto windows = move(m_windows);
for (auto& window : windows) { for (auto& [_, window] : windows) {
window.value->detach_client({}); window->detach_client({});
if (window.value->type() == WindowType::Applet) if (window->type() == WindowType::Applet)
AppletManager::the().remove_applet(window.value); AppletManager::the().remove_applet(window);
} }
if (m_show_screen_number) if (m_show_screen_number)
@ -105,11 +105,10 @@ void ConnectionFromClient::set_menu_name(i32 menu_id, String const& name)
} }
auto& menu = *it->value; auto& menu = *it->value;
menu.set_name(name); menu.set_name(name);
for (auto& it : m_windows) { for (auto& [_, window] : m_windows) {
auto& window = *it.value; window->menubar().for_each_menu([&](Menu& other_menu) {
window.menubar().for_each_menu([&](Menu& other_menu) {
if (&menu == &other_menu) { if (&menu == &other_menu) {
window.invalidate_menubar(); window->invalidate_menubar();
return IterationDecision::Break; return IterationDecision::Break;
} }
return IterationDecision::Continue; return IterationDecision::Continue;
@ -126,11 +125,10 @@ void ConnectionFromClient::set_menu_minimum_width(i32 menu_id, i32 minimum_width
} }
auto& menu = *it->value; auto& menu = *it->value;
menu.set_minimum_width(minimum_width); menu.set_minimum_width(minimum_width);
for (auto& it : m_windows) { for (auto& [_, window] : m_windows) {
auto& window = *it.value; window->menubar().for_each_menu([&](Menu& other_menu) {
window.menubar().for_each_menu([&](Menu& other_menu) {
if (&menu == &other_menu) { if (&menu == &other_menu) {
window.invalidate_menubar(); window->invalidate_menubar();
return IterationDecision::Break; return IterationDecision::Break;
} }
return IterationDecision::Continue; return IterationDecision::Continue;

View file

@ -64,16 +64,16 @@ public:
template<typename Callback> template<typename Callback>
void for_each_window(Callback callback) void for_each_window(Callback callback)
{ {
for (auto& it : m_windows) { for (auto& [_, window] : m_windows) {
if (callback(*it.value) == IterationDecision::Break) if (callback(*window) == IterationDecision::Break)
break; break;
} }
} }
template<typename Callback> template<typename Callback>
void for_each_menu(Callback callback) void for_each_menu(Callback callback)
{ {
for (auto& it : m_menus) { for (auto& [_, menu] : m_menus) {
if (callback(*it.value) == IterationDecision::Break) if (callback(*menu) == IterationDecision::Break)
break; break;
} }
} }

View file

@ -8,7 +8,6 @@
#include "Screen.h" #include "Screen.h"
#include "Compositor.h" #include "Compositor.h"
#include "Event.h" #include "Event.h"
#include "EventLoop.h"
#include "ScreenBackend.h" #include "ScreenBackend.h"
#include "VirtualScreenBackend.h" #include "VirtualScreenBackend.h"
#include "WindowManager.h" #include "WindowManager.h"
@ -85,22 +84,21 @@ bool Screen::apply_layout(ScreenLayout&& screen_layout, ByteString& error_msg)
} }
HashMap<Screen*, size_t> screens_with_resolution_change; HashMap<Screen*, size_t> screens_with_resolution_change;
HashMap<Screen*, size_t> screens_with_scale_change; HashMap<Screen*, size_t> screens_with_scale_change;
for (auto& it : current_to_new_indices_map) { for (auto [current_index, new_index] : current_to_new_indices_map) {
auto& screen = s_layout.screens[it.key]; auto& screen = s_layout.screens[current_index];
auto& new_screen = screen_layout.screens[it.value]; auto& new_screen = screen_layout.screens[new_index];
if (screen.resolution != new_screen.resolution) if (screen.resolution != new_screen.resolution)
screens_with_resolution_change.set(s_screens[it.key], it.value); screens_with_resolution_change.set(s_screens[current_index], new_index);
if (screen.scale_factor != new_screen.scale_factor) if (screen.scale_factor != new_screen.scale_factor)
screens_with_scale_change.set(s_screens[it.key], it.value); screens_with_scale_change.set(s_screens[current_index], new_index);
} }
auto screens_backup = move(s_screens); auto screens_backup = move(s_screens);
auto layout_backup = move(s_layout); auto layout_backup = move(s_layout);
for (auto& it : screens_with_resolution_change) { for (auto& [existing_screen, _] : screens_with_resolution_change) {
auto& existing_screen = *it.key; dbgln("Closing device {} in preparation for resolution change", layout_backup.screens[existing_screen->index()].device.value_or("<virtual screen>"));
dbgln("Closing device {} in preparation for resolution change", layout_backup.screens[existing_screen.index()].device.value_or("<virtual screen>")); existing_screen->close_device();
existing_screen.close_device();
} }
AK::ArmedScopeGuard rollback([&] { AK::ArmedScopeGuard rollback([&] {

View file

@ -7,6 +7,8 @@
#pragma once #pragma once
#include <AK/Forward.h> #include <AK/Forward.h>
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <LibCore/Forward.h> #include <LibCore/Forward.h>
#include <LibGfx/Forward.h> #include <LibGfx/Forward.h>
@ -101,10 +103,9 @@ public:
void set_dirty(bool re_render_shadow = false) void set_dirty(bool re_render_shadow = false)
{ {
for (auto& it : m_rendered_cache) { for (auto& [_, cached] : m_rendered_cache) {
auto& cached = *it.value; cached->m_dirty = true;
cached.m_dirty = true; cached->m_shadow_dirty |= re_render_shadow;
cached.m_shadow_dirty |= re_render_shadow;
} }
} }

View file

@ -583,8 +583,8 @@ void WindowManager::for_each_window_manager(Callback callback)
auto& connections = WMConnectionFromClient::s_connections; auto& connections = WMConnectionFromClient::s_connections;
// FIXME: this isn't really ordered... does it need to be? // FIXME: this isn't really ordered... does it need to be?
for (auto it = connections.begin(); it != connections.end(); ++it) { for (auto [_, connection] : connections) {
if (callback(*it->value) == IterationDecision::Break) if (callback(connection) == IterationDecision::Break)
return; return;
} }
} }