diff options
author | Andreas Kling <kling@serenityos.org> | 2023-03-06 14:17:01 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-06 23:46:35 +0100 |
commit | 8a48246ed1a93983668a25f5b9b0af0e745e3f04 (patch) | |
tree | dd98425d119f79e0160bf19951f96a4a30276cbb /Userland/Services/WindowServer | |
parent | 104be6c8ace8d56f66a89b570cdd615e74d22aa8 (diff) | |
download | serenity-8a48246ed1a93983668a25f5b9b0af0e745e3f04.zip |
Everywhere: Stop using NonnullRefPtrVector
This class had slightly confusing semantics and the added weirdness
doesn't seem worth it just so we can say "." instead of "->" when
iterating over a vector of NNRPs.
This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
Diffstat (limited to 'Userland/Services/WindowServer')
-rw-r--r-- | Userland/Services/WindowServer/Screen.cpp | 36 | ||||
-rw-r--r-- | Userland/Services/WindowServer/Screen.h | 14 |
2 files changed, 25 insertions, 25 deletions
diff --git a/Userland/Services/WindowServer/Screen.cpp b/Userland/Services/WindowServer/Screen.cpp index 6b7f0ed292..4b95c9fa3d 100644 --- a/Userland/Services/WindowServer/Screen.cpp +++ b/Userland/Services/WindowServer/Screen.cpp @@ -23,7 +23,7 @@ namespace WindowServer { -NonnullRefPtrVector<Screen, default_screen_count> Screen::s_screens; +Vector<NonnullRefPtr<Screen>, default_screen_count> Screen::s_screens; Screen* Screen::s_main_screen { nullptr }; Gfx::IntRect Screen::s_bounding_screens_rect {}; ScreenLayout Screen::s_layout; @@ -89,9 +89,9 @@ bool Screen::apply_layout(ScreenLayout&& screen_layout, DeprecatedString& error_ auto& screen = s_layout.screens[it.key]; auto& new_screen = screen_layout.screens[it.value]; if (screen.resolution != new_screen.resolution) - screens_with_resolution_change.set(&s_screens[it.key], it.value); + screens_with_resolution_change.set(s_screens[it.key], it.value); 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[it.key], it.value); } auto screens_backup = move(s_screens); @@ -105,18 +105,18 @@ bool Screen::apply_layout(ScreenLayout&& screen_layout, DeprecatedString& error_ AK::ArmedScopeGuard rollback([&] { for (auto& screen : s_screens) - screen.close_device(); + screen->close_device(); s_screens = move(screens_backup); s_layout = move(layout_backup); for (size_t i = 0; i < s_screens.size(); i++) { auto& old_screen = s_screens[i]; // Restore the original screen index in case it changed - old_screen.set_index(i); + old_screen->set_index(i); if (i == s_layout.main_screen_index) - old_screen.make_main_screen(); - bool changed_scale = screens_with_scale_change.contains(&old_screen); - if (screens_with_resolution_change.contains(&old_screen)) { - if (old_screen.open_device()) { + old_screen->make_main_screen(); + bool changed_scale = screens_with_scale_change.contains(old_screen); + if (screens_with_resolution_change.contains(old_screen)) { + if (old_screen->open_device()) { // The resolution was changed, so we also implicitly applied the new scale factor changed_scale = false; } else { @@ -125,9 +125,9 @@ bool Screen::apply_layout(ScreenLayout&& screen_layout, DeprecatedString& error_ } } - old_screen.update_virtual_and_physical_rects(); + old_screen->update_virtual_and_physical_rects(); if (changed_scale) - old_screen.scale_factor_changed(); + old_screen->scale_factor_changed(); } update_bounding_rect(); }); @@ -137,7 +137,7 @@ bool Screen::apply_layout(ScreenLayout&& screen_layout, DeprecatedString& error_ bool need_to_open_device; if (auto it = new_to_current_indices_map.find(index); it != new_to_current_indices_map.end()) { // Re-use the existing screen instance - screen = &screens_backup[it->value]; + screen = screens_backup[it->value]; s_screens.append(*screen); screen->set_index(index); @@ -179,7 +179,7 @@ bool Screen::apply_layout(ScreenLayout&& screen_layout, DeprecatedString& error_ float closest_distance = 0; Optional<Gfx::IntPoint> closest_point; for (auto& screen : s_screens) { - auto closest_point_on_screen_rect = screen.rect().closest_to(cursor_location); + auto closest_point_on_screen_rect = screen->rect().closest_to(cursor_location); auto distance = closest_point_on_screen_rect.distance_from(cursor_location); if (!closest_point.has_value() || distance < closest_distance) { closest_distance = distance; @@ -279,10 +279,10 @@ Screen& Screen::closest_to_rect(Gfx::IntRect const& rect) Screen* best_screen = nullptr; int best_area = 0; for (auto& screen : s_screens) { - auto r = screen.rect().intersected(rect); + auto r = screen->rect().intersected(rect); int area = r.width() * r.height(); if (!best_screen || area > best_area) { - best_screen = &screen; + best_screen = screen; best_area = area; } } @@ -296,7 +296,7 @@ Screen& Screen::closest_to_rect(Gfx::IntRect const& rect) Screen& Screen::closest_to_location(Gfx::IntPoint point) { for (auto& screen : s_screens) { - if (screen.rect().contains(point)) + if (screen->rect().contains(point)) return screen; } // TODO: guess based on how close the point is to the next screen rectangle @@ -306,9 +306,9 @@ Screen& Screen::closest_to_location(Gfx::IntPoint point) void Screen::update_bounding_rect() { if (!s_screens.is_empty()) { - s_bounding_screens_rect = s_screens[0].rect(); + s_bounding_screens_rect = s_screens[0]->rect(); for (size_t i = 1; i < s_screens.size(); i++) - s_bounding_screens_rect = s_bounding_screens_rect.united(s_screens[i].rect()); + s_bounding_screens_rect = s_bounding_screens_rect.united(s_screens[i]->rect()); } else { s_bounding_screens_rect = {}; } diff --git a/Userland/Services/WindowServer/Screen.h b/Userland/Services/WindowServer/Screen.h index 64cce345bf..3d8b7bc50d 100644 --- a/Userland/Services/WindowServer/Screen.h +++ b/Userland/Services/WindowServer/Screen.h @@ -98,22 +98,22 @@ public: { if (index >= s_screens.size()) return nullptr; - return &s_screens[index]; + return s_screens[index]; } static Vector<Gfx::IntRect, 4> rects() { Vector<Gfx::IntRect, 4> rects; for (auto& screen : s_screens) - rects.append(screen.rect()); + rects.append(screen->rect()); return rects; } static Screen* find_by_location(Gfx::IntPoint point) { for (auto& screen : s_screens) { - if (screen.rect().contains(point)) - return &screen; + if (screen->rect().contains(point)) + return screen; } return nullptr; } @@ -127,7 +127,7 @@ public: static IterationDecision for_each(F f) { for (auto& screen : s_screens) { - IterationDecision decision = f(screen); + IterationDecision decision = f(*screen); if (decision != IterationDecision::Continue) return decision; } @@ -187,7 +187,7 @@ private: static void update_indices() { for (size_t i = 0; i < s_screens.size(); i++) - s_screens[i].m_index = i; + s_screens[i]->m_index = i; } static void update_bounding_rect(); static void update_scale_factors_in_use(); @@ -199,7 +199,7 @@ private: ScreenLayout::Screen& screen_layout_info() { return s_layout.screens[m_index]; } ScreenLayout::Screen const& screen_layout_info() const { return s_layout.screens[m_index]; } - static NonnullRefPtrVector<Screen, default_screen_count> s_screens; + static Vector<NonnullRefPtr<Screen>, default_screen_count> s_screens; static Screen* s_main_screen; static Gfx::IntRect s_bounding_screens_rect; static ScreenLayout s_layout; |