From 025bdcf34cbc9992617a67416b8886234914d2f7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 20 Feb 2023 19:02:54 +0100 Subject: [PATCH] WindowServer: Fix various const-correctness issues --- Userland/Services/WindowServer/Compositor.cpp | 13 +++--- Userland/Services/WindowServer/Compositor.h | 10 ++--- Userland/Services/WindowServer/Cursor.cpp | 10 ++--- Userland/Services/WindowServer/Cursor.h | 12 ++--- Userland/Services/WindowServer/MenuItem.h | 4 +- Userland/Services/WindowServer/Overlays.h | 3 +- Userland/Services/WindowServer/Window.h | 14 +++--- .../Services/WindowServer/WindowManager.cpp | 6 +-- .../Services/WindowServer/WindowManager.h | 44 +++++++++---------- 9 files changed, 59 insertions(+), 57 deletions(-) diff --git a/Userland/Services/WindowServer/Compositor.cpp b/Userland/Services/WindowServer/Compositor.cpp index 40860fa334..c0f6f452fa 100644 --- a/Userland/Services/WindowServer/Compositor.cpp +++ b/Userland/Services/WindowServer/Compositor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -820,7 +820,7 @@ bool Compositor::set_wallpaper_mode(DeprecatedString const& mode) return succeeded; } -bool Compositor::set_wallpaper(RefPtr bitmap) +bool Compositor::set_wallpaper(RefPtr bitmap) { if (!bitmap) m_wallpaper = nullptr; @@ -869,11 +869,12 @@ void Compositor::update_wallpaper_bitmap() // If the screen size is equal to the wallpaper size, we don't actually need to scale it screen_data.m_wallpaper_bitmap = m_wallpaper; } else { - if (!screen_data.m_wallpaper_bitmap) - screen_data.m_wallpaper_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, screen.size(), screen.scale_factor()).release_value_but_fixme_should_propagate_errors(); + auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, screen.size(), screen.scale_factor()).release_value_but_fixme_should_propagate_errors(); - Gfx::Painter painter(*screen_data.m_wallpaper_bitmap); - painter.draw_scaled_bitmap(screen_data.m_wallpaper_bitmap->rect(), *m_wallpaper, m_wallpaper->rect()); + Gfx::Painter painter(*bitmap); + painter.draw_scaled_bitmap(bitmap->rect(), *m_wallpaper, m_wallpaper->rect()); + + screen_data.m_wallpaper_bitmap = move(bitmap); } return IterationDecision::Continue; }); diff --git a/Userland/Services/WindowServer/Compositor.h b/Userland/Services/WindowServer/Compositor.h index cbbc5a4485..1e705556b0 100644 --- a/Userland/Services/WindowServer/Compositor.h +++ b/Userland/Services/WindowServer/Compositor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -36,7 +36,7 @@ struct CompositorScreenData { RefPtr m_front_bitmap; RefPtr m_back_bitmap; RefPtr m_temp_bitmap; - RefPtr m_wallpaper_bitmap; + RefPtr m_wallpaper_bitmap; OwnPtr m_back_painter; OwnPtr m_front_painter; OwnPtr m_temp_painter; @@ -107,8 +107,8 @@ public: bool set_wallpaper_mode(DeprecatedString const& mode); - bool set_wallpaper(RefPtr); - RefPtr wallpaper_bitmap() const { return m_wallpaper; } + bool set_wallpaper(RefPtr); + RefPtr wallpaper_bitmap() const { return m_wallpaper; } void invalidate_cursor(bool = false); Gfx::IntRect current_cursor_rect() const; @@ -231,7 +231,7 @@ private: Gfx::DisjointIntRectSet m_transparent_wallpaper_rects; WallpaperMode m_wallpaper_mode { WallpaperMode::Unchecked }; - RefPtr m_wallpaper; + RefPtr m_wallpaper; Cursor const* m_current_cursor { nullptr }; Screen* m_current_cursor_screen { nullptr }; diff --git a/Userland/Services/WindowServer/Cursor.cpp b/Userland/Services/WindowServer/Cursor.cpp index daea92f460..0735873b01 100644 --- a/Userland/Services/WindowServer/Cursor.cpp +++ b/Userland/Services/WindowServer/Cursor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,7 +11,7 @@ namespace WindowServer { -Cursor::Cursor(NonnullRefPtr&& bitmap, int scale_factor, Gfx::CursorParams const& cursor_params) +Cursor::Cursor(NonnullRefPtr&& bitmap, int scale_factor, Gfx::CursorParams const& cursor_params) : m_params(cursor_params.constrained(*bitmap)) , m_rect(bitmap->rect()) { @@ -27,13 +27,13 @@ void Cursor::update_rect_if_animated() } } -NonnullRefPtr Cursor::create(NonnullRefPtr&& bitmap, int scale_factor) +NonnullRefPtr Cursor::create(NonnullRefPtr&& bitmap, int scale_factor) { auto hotspot = bitmap->rect().center(); return adopt_ref(*new Cursor(move(bitmap), scale_factor, Gfx::CursorParams(hotspot))); } -RefPtr Cursor::create(StringView filename, StringView default_filename) +RefPtr Cursor::create(StringView filename, StringView default_filename) { auto cursor = adopt_ref(*new Cursor()); if (cursor->load(filename, default_filename)) @@ -72,7 +72,7 @@ bool Cursor::load(StringView filename, StringView default_filename) return did_load_any; } -RefPtr Cursor::create(Gfx::StandardCursor standard_cursor) +RefPtr Cursor::create(Gfx::StandardCursor standard_cursor) { switch (standard_cursor) { case Gfx::StandardCursor::None: diff --git a/Userland/Services/WindowServer/Cursor.h b/Userland/Services/WindowServer/Cursor.h index 83e769a5ba..731264c989 100644 --- a/Userland/Services/WindowServer/Cursor.h +++ b/Userland/Services/WindowServer/Cursor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,9 +15,9 @@ namespace WindowServer { class Cursor : public RefCounted { public: - static RefPtr create(StringView, StringView); - static NonnullRefPtr create(NonnullRefPtr&&, int); - static RefPtr create(Gfx::StandardCursor); + static RefPtr create(StringView, StringView); + static NonnullRefPtr create(NonnullRefPtr&&, int); + static RefPtr create(Gfx::StandardCursor); ~Cursor() = default; Gfx::CursorParams const& params() const { return m_params; } @@ -47,12 +47,12 @@ public: private: Cursor() = default; - Cursor(NonnullRefPtr&&, int, Gfx::CursorParams const&); + Cursor(NonnullRefPtr&&, int, Gfx::CursorParams const&); bool load(StringView, StringView); void update_rect_if_animated(); - HashMap> m_bitmaps; + HashMap> m_bitmaps; Gfx::CursorParams m_params; Gfx::IntRect m_rect; }; diff --git a/Userland/Services/WindowServer/MenuItem.h b/Userland/Services/WindowServer/MenuItem.h index f173f6914d..adb0d0a479 100644 --- a/Userland/Services/WindowServer/MenuItem.h +++ b/Userland/Services/WindowServer/MenuItem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -80,7 +80,7 @@ private: DeprecatedString m_text; DeprecatedString m_shortcut_text; Gfx::IntRect m_rect; - RefPtr m_icon; + RefPtr m_icon; int m_submenu_id { -1 }; bool m_exclusive { false }; }; diff --git a/Userland/Services/WindowServer/Overlays.h b/Userland/Services/WindowServer/Overlays.h index 5ce547f7ad..9bbb8df6f2 100644 --- a/Userland/Services/WindowServer/Overlays.h +++ b/Userland/Services/WindowServer/Overlays.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, the SerenityOS developers. + * Copyright (c) 2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -165,7 +166,7 @@ private: Gfx::Font const& font(); void update_rect(); - RefPtr m_bitmap; + RefPtr m_bitmap; DeprecatedString m_text; Gfx::IntRect m_label_rect; }; diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h index 52628e503a..2885d2773c 100644 --- a/Userland/Services/WindowServer/Window.h +++ b/Userland/Services/WindowServer/Window.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -279,13 +279,13 @@ public: void set_base_size(Gfx::IntSize size) { m_base_size = size; } Gfx::Bitmap const& icon() const { return *m_icon; } - void set_icon(NonnullRefPtr&& icon) { m_icon = move(icon); } + void set_icon(NonnullRefPtr&& icon) { m_icon = move(icon); } void set_default_icon(); Cursor const* cursor() const { return (m_cursor_override ? m_cursor_override : m_cursor).ptr(); } - void set_cursor(RefPtr cursor) { m_cursor = move(cursor); } - void set_cursor_override(RefPtr cursor) { m_cursor_override = move(cursor); } + void set_cursor(RefPtr cursor) { m_cursor = move(cursor); } + void set_cursor_override(RefPtr cursor) { m_cursor_override = move(cursor); } void remove_cursor_override() { m_cursor_override = nullptr; } void request_update(Gfx::IntRect const&, bool ignore_occlusion = false); @@ -445,9 +445,9 @@ private: Gfx::IntSize m_size_increment; Gfx::IntSize m_base_size; Gfx::IntSize m_minimum_size { 0, 0 }; - NonnullRefPtr m_icon; - RefPtr m_cursor; - RefPtr m_cursor_override; + NonnullRefPtr m_icon; + RefPtr m_cursor; + RefPtr m_cursor_override; WindowFrame m_frame; Gfx::DisjointIntRectSet m_pending_paint_rects; Gfx::IntRect m_rect_in_applet_area; diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 7751655290..97ee24cb86 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -35,7 +35,7 @@ WindowManager& WindowManager::the() return *s_the; } -WindowManager::WindowManager(Gfx::PaletteImpl const& palette) +WindowManager::WindowManager(Gfx::PaletteImpl& palette) : m_switcher(WindowSwitcher::construct()) , m_keymap_switcher(KeymapSwitcher::construct()) , m_palette(palette) @@ -2242,7 +2242,7 @@ void WindowManager::apply_cursor_theme(DeprecatedString const& theme_name) auto cursor_theme_config = cursor_theme_config_or_error.release_value(); auto* current_cursor = Compositor::the().current_cursor(); - auto reload_cursor = [&](RefPtr& cursor, DeprecatedString const& name) { + auto reload_cursor = [&](RefPtr& cursor, DeprecatedString const& name) { bool is_current_cursor = current_cursor && current_cursor == cursor.ptr(); static auto const s_default_cursor_path = "/res/cursor-themes/Default/arrow.x2y2.png"sv; diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h index c35ebd3a56..243a98bcdb 100644 --- a/Userland/Services/WindowServer/WindowManager.h +++ b/Userland/Services/WindowServer/WindowManager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -339,7 +339,7 @@ public: u8 last_processed_buttons() { return m_last_processed_buttons; } private: - explicit WindowManager(Gfx::PaletteImpl const&); + explicit WindowManager(Gfx::PaletteImpl&); void notify_new_active_window(Window&); void notify_previous_active_window(Window&); @@ -371,25 +371,25 @@ private: [[nodiscard]] static WindowStack& get_rendering_window_stacks(WindowStack*&); - RefPtr m_hidden_cursor; - RefPtr m_arrow_cursor; - RefPtr m_hand_cursor; - RefPtr m_help_cursor; - RefPtr m_resize_horizontally_cursor; - RefPtr m_resize_vertically_cursor; - RefPtr m_resize_diagonally_tlbr_cursor; - RefPtr m_resize_diagonally_bltr_cursor; - RefPtr m_resize_column_cursor; - RefPtr m_resize_row_cursor; - RefPtr m_i_beam_cursor; - RefPtr m_disallowed_cursor; - RefPtr m_move_cursor; - RefPtr m_drag_cursor; - RefPtr m_drag_copy_cursor; - RefPtr m_wait_cursor; - RefPtr m_crosshair_cursor; - RefPtr m_eyedropper_cursor; - RefPtr m_zoom_cursor; + RefPtr m_hidden_cursor; + RefPtr m_arrow_cursor; + RefPtr m_hand_cursor; + RefPtr m_help_cursor; + RefPtr m_resize_horizontally_cursor; + RefPtr m_resize_vertically_cursor; + RefPtr m_resize_diagonally_tlbr_cursor; + RefPtr m_resize_diagonally_bltr_cursor; + RefPtr m_resize_column_cursor; + RefPtr m_resize_row_cursor; + RefPtr m_i_beam_cursor; + RefPtr m_disallowed_cursor; + RefPtr m_move_cursor; + RefPtr m_drag_cursor; + RefPtr m_drag_copy_cursor; + RefPtr m_wait_cursor; + RefPtr m_crosshair_cursor; + RefPtr m_eyedropper_cursor; + RefPtr m_zoom_cursor; int m_cursor_highlight_radius { 0 }; Gfx::Color m_cursor_highlight_color; bool m_cursor_highlight_enabled { false }; @@ -477,7 +477,7 @@ private: DeprecatedString m_dnd_text; bool m_dnd_accepts_drag { false }; - RefPtr m_dnd_mime_data; + RefPtr m_dnd_mime_data; WindowStack* m_switching_to_window_stack { nullptr }; Vector, 4> m_carry_window_to_new_stack;