mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 21:40:33 +00:00
WindowServer: Prefer structured bindings when iterating over HashMaps
This commit is contained in:
parent
773a280bdf
commit
d6c631ebe0
Notes:
sideshowbarker
2024-07-16 23:52:22 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/d6c631ebe0 Pull-request: https://github.com/SerenityOS/serenity/pull/23403 Reviewed-by: https://github.com/ADKaster ✅
5 changed files with 29 additions and 32 deletions
|
@ -67,10 +67,10 @@ ConnectionFromClient::~ConnectionFromClient()
|
|||
|
||||
MenuManager::the().close_all_menus_from_client({}, *this);
|
||||
auto windows = move(m_windows);
|
||||
for (auto& window : windows) {
|
||||
window.value->detach_client({});
|
||||
if (window.value->type() == WindowType::Applet)
|
||||
AppletManager::the().remove_applet(window.value);
|
||||
for (auto& [_, window] : windows) {
|
||||
window->detach_client({});
|
||||
if (window->type() == WindowType::Applet)
|
||||
AppletManager::the().remove_applet(window);
|
||||
}
|
||||
|
||||
if (m_show_screen_number)
|
||||
|
@ -105,11 +105,10 @@ void ConnectionFromClient::set_menu_name(i32 menu_id, String const& name)
|
|||
}
|
||||
auto& menu = *it->value;
|
||||
menu.set_name(name);
|
||||
for (auto& it : m_windows) {
|
||||
auto& window = *it.value;
|
||||
window.menubar().for_each_menu([&](Menu& other_menu) {
|
||||
for (auto& [_, window] : m_windows) {
|
||||
window->menubar().for_each_menu([&](Menu& other_menu) {
|
||||
if (&menu == &other_menu) {
|
||||
window.invalidate_menubar();
|
||||
window->invalidate_menubar();
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
|
@ -126,11 +125,10 @@ void ConnectionFromClient::set_menu_minimum_width(i32 menu_id, i32 minimum_width
|
|||
}
|
||||
auto& menu = *it->value;
|
||||
menu.set_minimum_width(minimum_width);
|
||||
for (auto& it : m_windows) {
|
||||
auto& window = *it.value;
|
||||
window.menubar().for_each_menu([&](Menu& other_menu) {
|
||||
for (auto& [_, window] : m_windows) {
|
||||
window->menubar().for_each_menu([&](Menu& other_menu) {
|
||||
if (&menu == &other_menu) {
|
||||
window.invalidate_menubar();
|
||||
window->invalidate_menubar();
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
|
|
|
@ -64,16 +64,16 @@ public:
|
|||
template<typename Callback>
|
||||
void for_each_window(Callback callback)
|
||||
{
|
||||
for (auto& it : m_windows) {
|
||||
if (callback(*it.value) == IterationDecision::Break)
|
||||
for (auto& [_, window] : m_windows) {
|
||||
if (callback(*window) == IterationDecision::Break)
|
||||
break;
|
||||
}
|
||||
}
|
||||
template<typename Callback>
|
||||
void for_each_menu(Callback callback)
|
||||
{
|
||||
for (auto& it : m_menus) {
|
||||
if (callback(*it.value) == IterationDecision::Break)
|
||||
for (auto& [_, menu] : m_menus) {
|
||||
if (callback(*menu) == IterationDecision::Break)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "Screen.h"
|
||||
#include "Compositor.h"
|
||||
#include "Event.h"
|
||||
#include "EventLoop.h"
|
||||
#include "ScreenBackend.h"
|
||||
#include "VirtualScreenBackend.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_scale_change;
|
||||
for (auto& it : current_to_new_indices_map) {
|
||||
auto& screen = s_layout.screens[it.key];
|
||||
auto& new_screen = screen_layout.screens[it.value];
|
||||
for (auto [current_index, new_index] : current_to_new_indices_map) {
|
||||
auto& screen = s_layout.screens[current_index];
|
||||
auto& new_screen = screen_layout.screens[new_index];
|
||||
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)
|
||||
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 layout_backup = move(s_layout);
|
||||
|
||||
for (auto& it : 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>"));
|
||||
existing_screen.close_device();
|
||||
for (auto& [existing_screen, _] : screens_with_resolution_change) {
|
||||
dbgln("Closing device {} in preparation for resolution change", layout_backup.screens[existing_screen->index()].device.value_or("<virtual screen>"));
|
||||
existing_screen->close_device();
|
||||
}
|
||||
|
||||
AK::ArmedScopeGuard rollback([&] {
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <LibCore/Forward.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
|
@ -101,10 +103,9 @@ public:
|
|||
|
||||
void set_dirty(bool re_render_shadow = false)
|
||||
{
|
||||
for (auto& it : m_rendered_cache) {
|
||||
auto& cached = *it.value;
|
||||
cached.m_dirty = true;
|
||||
cached.m_shadow_dirty |= re_render_shadow;
|
||||
for (auto& [_, cached] : m_rendered_cache) {
|
||||
cached->m_dirty = true;
|
||||
cached->m_shadow_dirty |= re_render_shadow;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -583,8 +583,8 @@ void WindowManager::for_each_window_manager(Callback callback)
|
|||
auto& connections = WMConnectionFromClient::s_connections;
|
||||
|
||||
// FIXME: this isn't really ordered... does it need to be?
|
||||
for (auto it = connections.begin(); it != connections.end(); ++it) {
|
||||
if (callback(*it->value) == IterationDecision::Break)
|
||||
for (auto [_, connection] : connections) {
|
||||
if (callback(connection) == IterationDecision::Break)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue