From 0d4fd4e2a66bf7d8224c6490c92bf133130923ac Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Mon, 22 Aug 2022 12:52:21 -0400 Subject: [PATCH] LibGfx+LibGUI+WindowServer+Apps+Demos: Replace ToolWindows with the RenderAbove WindowMode. This mode will ensure child windows always draw above their parents, even when focus is lost. RenderAbove modals are automatically themed the same as the old ToolWindows. Fixes ToolWindows rendering above ALL normal windows, regardless of parent. We can't rely on WindowType to create these sort of effects because of WindowManager's strict display hierarchy. --- .../Applications/FontEditor/MainWidget.cpp | 2 +- Userland/Applications/Terminal/main.cpp | 8 +- Userland/Demos/LibGfxScaleDemo/main.cpp | 2 +- .../Libraries/LibGUI/AbstractThemePreview.cpp | 8 +- .../Libraries/LibGfx/ClassicWindowTheme.cpp | 114 +++++++----------- .../Libraries/LibGfx/ClassicWindowTheme.h | 19 ++- Userland/Libraries/LibGfx/WindowTheme.h | 25 ++-- .../WindowServer/ConnectionFromClient.cpp | 2 +- Userland/Services/WindowServer/Menubar.cpp | 2 +- Userland/Services/WindowServer/Window.h | 6 +- .../Services/WindowServer/WindowFrame.cpp | 42 +++---- Userland/Services/WindowServer/WindowFrame.h | 1 - .../Services/WindowServer/WindowManager.cpp | 13 +- .../Services/WindowServer/WindowManager.h | 5 - Userland/Services/WindowServer/WindowType.h | 1 - 15 files changed, 106 insertions(+), 144 deletions(-) diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index c7a41e44688..c5fd3a874dc 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -60,7 +60,7 @@ static constexpr Array pangrams = { ErrorOr> MainWidget::create_preview_window() { auto window = TRY(GUI::Window::try_create(this)); - window->set_window_type(GUI::WindowType::ToolWindow); + window->set_window_mode(GUI::WindowMode::RenderAbove); window->set_title("Preview"); window->resize(400, 150); window->center_within(*this->window()); diff --git a/Userland/Applications/Terminal/main.cpp b/Userland/Applications/Terminal/main.cpp index 18669736737..481fcc1ad87 100644 --- a/Userland/Applications/Terminal/main.cpp +++ b/Userland/Applications/Terminal/main.cpp @@ -170,8 +170,8 @@ static ErrorOr run_command(String command, bool keep_open) static ErrorOr> create_find_window(VT::TerminalWidget& terminal) { - auto window = TRY(GUI::Window::try_create()); - window->set_window_type(GUI::WindowType::ToolWindow); + auto window = TRY(GUI::Window::try_create(&terminal)); + window->set_window_mode(GUI::WindowMode::RenderAbove); window->set_title("Find in Terminal"); window->set_resizable(false); window->resize(300, 90); @@ -416,10 +416,6 @@ ErrorOr serenity_main(Main::Arguments arguments) }))); TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Terminal", app_icon, window))); - window->on_close = [&]() { - find_window->close(); - }; - window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision { if (check_terminal_quit() == GUI::MessageBox::ExecResult::OK) return GUI::Window::CloseRequestDecision::Close; diff --git a/Userland/Demos/LibGfxScaleDemo/main.cpp b/Userland/Demos/LibGfxScaleDemo/main.cpp index 32167beb152..5658739e523 100644 --- a/Userland/Demos/LibGfxScaleDemo/main.cpp +++ b/Userland/Demos/LibGfxScaleDemo/main.cpp @@ -76,7 +76,7 @@ void Canvas::draw(Gfx::Painter& painter) { auto active_window_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/window.png"sv).release_value_but_fixme_should_propagate_errors(); - Gfx::WindowTheme::current().paint_normal_frame(painter, Gfx::WindowTheme::WindowState::Active, { 4, 18, WIDTH - 8, HEIGHT - 29 }, "Well hello friends 🐞"sv, *active_window_icon, palette(), { WIDTH - 20, 6, 16, 16 }, 0, false); + Gfx::WindowTheme::current().paint_normal_frame(painter, Gfx::WindowTheme::WindowState::Active, Gfx::WindowTheme::WindowMode::Other, { 4, 18, WIDTH - 8, HEIGHT - 29 }, "Well hello friends 🐞"sv, *active_window_icon, palette(), { WIDTH - 20, 6, 16, 16 }, 0, false); painter.fill_rect({ 4, 25, WIDTH - 8, HEIGHT - 30 }, palette().color(Gfx::ColorRole::Background)); painter.draw_rect({ 20, 34, WIDTH - 40, HEIGHT - 45 }, palette().color(Gfx::ColorRole::Selection), true); diff --git a/Userland/Libraries/LibGUI/AbstractThemePreview.cpp b/Userland/Libraries/LibGUI/AbstractThemePreview.cpp index e1cea74089f..0507c03f6d4 100644 --- a/Userland/Libraries/LibGUI/AbstractThemePreview.cpp +++ b/Userland/Libraries/LibGUI/AbstractThemePreview.cpp @@ -108,7 +108,7 @@ void AbstractThemePreview::paint_window(StringView title, Gfx::IntRect const& re int window_button_width = m_preview_palette.window_title_button_width(); int window_button_height = m_preview_palette.window_title_button_height(); - auto titlebar_text_rect = Gfx::WindowTheme::current().titlebar_text_rect(Gfx::WindowTheme::WindowType::Normal, rect, m_preview_palette); + auto titlebar_text_rect = Gfx::WindowTheme::current().titlebar_text_rect(Gfx::WindowTheme::WindowType::Normal, Gfx::WindowTheme::WindowMode::Other, rect, m_preview_palette); int pos = titlebar_text_rect.right() + 1; Array possible_buttons { @@ -126,7 +126,7 @@ void AbstractThemePreview::paint_window(StringView title, Gfx::IntRect const& re button.rect = button_rect; } - auto frame_rect = Gfx::WindowTheme::current().frame_rect_for_window(Gfx::WindowTheme::WindowType::Normal, rect, m_preview_palette, 0); + auto frame_rect = Gfx::WindowTheme::current().frame_rect_for_window(Gfx::WindowTheme::WindowType::Normal, Gfx::WindowTheme::WindowMode::Other, rect, m_preview_palette, 0); auto paint_shadow = [](Gfx::Painter& painter, Gfx::IntRect& frame_rect, Gfx::Bitmap const& shadow_bitmap) { auto total_shadow_size = shadow_bitmap.height(); @@ -142,7 +142,7 @@ void AbstractThemePreview::paint_window(StringView title, Gfx::IntRect const& re Gfx::PainterStateSaver saver(painter); painter.translate(frame_rect.location()); - Gfx::WindowTheme::current().paint_normal_frame(painter, state, rect, title, icon, m_preview_palette, buttons.last().rect, 0, false); + Gfx::WindowTheme::current().paint_normal_frame(painter, state, Gfx::WindowTheme::WindowMode::Other, rect, title, icon, m_preview_palette, buttons.last().rect, 0, false); painter.fill_rect(rect.translated(-frame_rect.location()), m_preview_palette.color(Gfx::ColorRole::Background)); for (auto& button : buttons) { @@ -171,7 +171,7 @@ void AbstractThemePreview::center_window_group_within(Span windows, Gfx: auto to_frame_rect = [&](Gfx::IntRect const& rect) { return Gfx::WindowTheme::current().frame_rect_for_window( - Gfx::WindowTheme::WindowType::Normal, rect, m_preview_palette, 0); + Gfx::WindowTheme::WindowType::Normal, Gfx::WindowTheme::WindowMode::Other, rect, m_preview_palette, 0); }; auto leftmost_x_value = windows[0].rect.x(); diff --git a/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp b/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp index 62388448c13..9fda7800668 100644 --- a/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp +++ b/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp @@ -16,12 +16,12 @@ namespace Gfx { static constexpr int menubar_height = 20; -Gfx::IntRect ClassicWindowTheme::titlebar_icon_rect(WindowType window_type, IntRect const& window_rect, Palette const& palette) const +Gfx::IntRect ClassicWindowTheme::titlebar_icon_rect(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Palette const& palette) const { - if (window_type == WindowType::ToolWindow) + if (window_mode == WindowMode::RenderAbove) return {}; - auto titlebar_rect = this->titlebar_rect(window_type, window_rect, palette); + auto titlebar_rect = this->titlebar_rect(window_type, window_mode, window_rect, palette); Gfx::IntRect icon_rect { titlebar_rect.x() + 2, titlebar_rect.y(), @@ -33,10 +33,10 @@ Gfx::IntRect ClassicWindowTheme::titlebar_icon_rect(WindowType window_type, IntR return icon_rect; } -Gfx::IntRect ClassicWindowTheme::titlebar_text_rect(WindowType window_type, IntRect const& window_rect, Palette const& palette) const +Gfx::IntRect ClassicWindowTheme::titlebar_text_rect(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Palette const& palette) const { - auto titlebar_rect = this->titlebar_rect(window_type, window_rect, palette); - auto titlebar_icon_rect = this->titlebar_icon_rect(window_type, window_rect, palette); + auto titlebar_rect = this->titlebar_rect(window_type, window_mode, window_rect, palette); + auto titlebar_icon_rect = this->titlebar_icon_rect(window_type, window_mode, window_rect, palette); return { titlebar_rect.x() + 3 + (titlebar_icon_rect.is_empty() ? 0 : (titlebar_icon_rect.width() + 2)), titlebar_rect.y(), @@ -45,17 +45,17 @@ Gfx::IntRect ClassicWindowTheme::titlebar_text_rect(WindowType window_type, IntR }; } -void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window_state, IntRect const& window_rect, StringView window_title, Bitmap const& icon, Palette const& palette, IntRect const& leftmost_button_rect, int menu_row_count, [[maybe_unused]] bool window_modified) const +void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window_state, WindowMode window_mode, IntRect const& window_rect, StringView window_title, Bitmap const& icon, Palette const& palette, IntRect const& leftmost_button_rect, int menu_row_count, [[maybe_unused]] bool window_modified) const { - auto frame_rect = frame_rect_for_window(WindowType::Normal, window_rect, palette, menu_row_count); + auto frame_rect = frame_rect_for_window(WindowType::Normal, window_mode, window_rect, palette, menu_row_count); frame_rect.set_location({ 0, 0 }); Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette); auto& title_font = FontDatabase::window_title_font(); - auto titlebar_rect = this->titlebar_rect(WindowType::Normal, window_rect, palette); - auto titlebar_icon_rect = this->titlebar_icon_rect(WindowType::Normal, window_rect, palette); - auto titlebar_inner_rect = titlebar_text_rect(WindowType::Normal, window_rect, palette); + auto titlebar_rect = this->titlebar_rect(WindowType::Normal, window_mode, window_rect, palette); + auto titlebar_icon_rect = this->titlebar_icon_rect(WindowType::Normal, window_mode, window_rect, palette); + auto titlebar_inner_rect = titlebar_text_rect(WindowType::Normal, window_mode, window_rect, palette); auto titlebar_title_rect = titlebar_inner_rect; titlebar_title_rect.set_width(title_font.width(window_title)); @@ -69,6 +69,18 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window auto title_alignment = palette.title_alignment(); int stripe_right = leftmost_button_rect.left() - 3; + + auto clipped_title_rect = titlebar_title_rect; + clipped_title_rect.set_width(stripe_right - clipped_title_rect.x()); + if (!clipped_title_rect.is_empty()) { + painter.draw_text(clipped_title_rect.translated(1, 2), window_title, title_font, title_alignment, shadow_color, Gfx::TextElision::Right); + // FIXME: The translated(0, 1) wouldn't be necessary if we could center text based on its baseline. + painter.draw_text(clipped_title_rect.translated(0, 1), window_title, title_font, title_alignment, title_color, Gfx::TextElision::Right); + } + + if (window_mode == WindowMode::RenderAbove) + return; + if (stripes_color.alpha() > 0) { switch (title_alignment) { case Gfx::TextAlignment::CenterLeft: { @@ -101,59 +113,20 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window } } - auto clipped_title_rect = titlebar_title_rect; - clipped_title_rect.set_width(stripe_right - clipped_title_rect.x()); - if (!clipped_title_rect.is_empty()) { - painter.draw_text(clipped_title_rect.translated(1, 2), window_title, title_font, title_alignment, shadow_color, Gfx::TextElision::Right); - // FIXME: The translated(0, 1) wouldn't be necessary if we could center text based on its baseline. - painter.draw_text(clipped_title_rect.translated(0, 1), window_title, title_font, title_alignment, title_color, Gfx::TextElision::Right); - } - painter.draw_scaled_bitmap(titlebar_icon_rect, icon, icon.rect()); } -void ClassicWindowTheme::paint_tool_window_frame(Painter& painter, WindowState window_state, IntRect const& window_rect, StringView title_text, Palette const& palette, IntRect const& leftmost_button_rect) const -{ - auto frame_rect = frame_rect_for_window(WindowType::ToolWindow, window_rect, palette, 0); - frame_rect.set_location({ 0, 0 }); - Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette); - - auto& title_font = FontDatabase::window_title_font(); - - auto titlebar_rect = this->titlebar_rect(WindowType::ToolWindow, window_rect, palette); - auto titlebar_inner_rect = titlebar_text_rect(WindowType::ToolWindow, window_rect, palette); - auto titlebar_title_rect = titlebar_inner_rect; - titlebar_title_rect.set_width(title_font.width(title_text)); - - auto [title_color, border_color, border_color2, stripes_color, shadow_color] = compute_frame_colors(window_state, palette); - - painter.draw_line(titlebar_rect.bottom_left().translated(0, 1), titlebar_rect.bottom_right().translated(0, 1), palette.button()); - painter.draw_line(titlebar_rect.bottom_left().translated(0, 2), titlebar_rect.bottom_right().translated(0, 2), palette.button()); - - painter.fill_rect_with_gradient(titlebar_rect, border_color, border_color2); - - int stripe_right = leftmost_button_rect.left() - 3; - - auto clipped_title_rect = titlebar_title_rect; - clipped_title_rect.set_width(stripe_right - clipped_title_rect.x()); - if (!clipped_title_rect.is_empty()) { - painter.draw_text(clipped_title_rect.translated(1, 2), title_text, title_font, Gfx::TextAlignment::CenterLeft, shadow_color, Gfx::TextElision::Right); - // FIXME: The translated(0, 1) wouldn't be necessary if we could center text based on its baseline. - painter.draw_text(clipped_title_rect.translated(0, 1), title_text, title_font, Gfx::TextAlignment::CenterLeft, title_color, Gfx::TextElision::Right); - } -} - -IntRect ClassicWindowTheme::menubar_rect(WindowType window_type, IntRect const& window_rect, Palette const& palette, int menu_row_count) const +IntRect ClassicWindowTheme::menubar_rect(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Palette const& palette, int menu_row_count) const { if (window_type != WindowType::Normal) return {}; - return { palette.window_border_thickness(), palette.window_border_thickness() - 1 + titlebar_height(window_type, palette) + 2, window_rect.width(), menubar_height * menu_row_count }; + return { palette.window_border_thickness(), palette.window_border_thickness() - 1 + titlebar_height(window_type, window_mode, palette) + 2, window_rect.width(), menubar_height * menu_row_count }; } -IntRect ClassicWindowTheme::titlebar_rect(WindowType window_type, IntRect const& window_rect, Palette const& palette) const +IntRect ClassicWindowTheme::titlebar_rect(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Palette const& palette) const { auto& title_font = FontDatabase::window_title_font(); - auto window_titlebar_height = titlebar_height(window_type, palette); + auto window_titlebar_height = titlebar_height(window_type, window_mode, palette); // FIXME: The top of the titlebar doesn't get redrawn properly if this padding is different int total_vertical_padding = title_font.glyph_height() - 1; @@ -178,13 +151,13 @@ ClassicWindowTheme::FrameColors ClassicWindowTheme::compute_frame_colors(WindowS } } -void ClassicWindowTheme::paint_notification_frame(Painter& painter, IntRect const& window_rect, Palette const& palette, IntRect const& close_button_rect) const +void ClassicWindowTheme::paint_notification_frame(Painter& painter, WindowMode window_mode, IntRect const& window_rect, Palette const& palette, IntRect const& close_button_rect) const { - auto frame_rect = frame_rect_for_window(WindowType::Notification, window_rect, palette, 0); + auto frame_rect = frame_rect_for_window(WindowType::Notification, window_mode, window_rect, palette, 0); frame_rect.set_location({ 0, 0 }); Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette); - auto titlebar_rect = this->titlebar_rect(WindowType::Notification, window_rect, palette); + auto titlebar_rect = this->titlebar_rect(WindowType::Notification, window_mode, window_rect, palette); painter.fill_rect_with_gradient(Gfx::Orientation::Vertical, titlebar_rect, palette.active_window_border1(), palette.active_window_border2()); if (palette.active_window_title_stripes().alpha() > 0) { @@ -198,14 +171,13 @@ void ClassicWindowTheme::paint_notification_frame(Painter& painter, IntRect cons } } -IntRect ClassicWindowTheme::frame_rect_for_window(WindowType window_type, IntRect const& window_rect, Gfx::Palette const& palette, int menu_row_count) const +IntRect ClassicWindowTheme::frame_rect_for_window(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Gfx::Palette const& palette, int menu_row_count) const { - auto window_titlebar_height = titlebar_height(window_type, palette); + auto window_titlebar_height = titlebar_height(window_type, window_mode, palette); auto border_thickness = palette.window_border_thickness(); switch (window_type) { case WindowType::Normal: - case WindowType::ToolWindow: return { window_rect.x() - border_thickness, window_rect.y() - window_titlebar_height - border_thickness - 1 - menu_row_count * menubar_height, @@ -224,43 +196,45 @@ IntRect ClassicWindowTheme::frame_rect_for_window(WindowType window_type, IntRec } } -Vector ClassicWindowTheme::layout_buttons(WindowType window_type, IntRect const& window_rect, Palette const& palette, size_t buttons) const +Vector ClassicWindowTheme::layout_buttons(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Palette const& palette, size_t buttons) const { int window_button_width = palette.window_title_button_width(); int window_button_height = palette.window_title_button_height(); int pos; Vector button_rects; if (window_type == WindowType::Notification) - pos = titlebar_rect(window_type, window_rect, palette).top() + 2; + pos = titlebar_rect(window_type, window_mode, window_rect, palette).top() + 2; else - pos = titlebar_text_rect(window_type, window_rect, palette).right() + 1; + pos = titlebar_text_rect(window_type, window_mode, window_rect, palette).right() + 1; for (size_t i = 0; i < buttons; i++) { if (window_type == WindowType::Notification) { // The button height & width have to be equal or it leaks out of its area Gfx::IntRect rect { 0, pos, window_button_height, window_button_height }; - rect.center_horizontally_within(titlebar_rect(window_type, window_rect, palette)); + rect.center_horizontally_within(titlebar_rect(window_type, window_mode, window_rect, palette)); button_rects.append(rect); pos += window_button_height; } else { pos -= window_button_width; Gfx::IntRect rect { pos, 0, window_button_width, window_button_height }; - rect.center_vertically_within(titlebar_text_rect(window_type, window_rect, palette)); + rect.center_vertically_within(titlebar_text_rect(window_type, window_mode, window_rect, palette)); button_rects.append(rect); } } return button_rects; } -int ClassicWindowTheme::titlebar_height(WindowType window_type, Palette const& palette) const +int ClassicWindowTheme::titlebar_height(WindowType window_type, WindowMode window_mode, Palette const& palette) const { auto& title_font = FontDatabase::window_title_font(); switch (window_type) { case WindowType::Normal: - case WindowType::Notification: - return max(palette.window_title_height(), title_font.glyph_height() + 8); - case WindowType::ToolWindow: - return max(palette.window_title_height() - 4, title_font.glyph_height() + 4); + case WindowType::Notification: { + if (window_mode == WindowMode::RenderAbove) + return max(palette.window_title_height() - 4, title_font.glyph_height() + 4); + else + return max(palette.window_title_height(), title_font.glyph_height() + 8); + } default: return 0; } diff --git a/Userland/Libraries/LibGfx/ClassicWindowTheme.h b/Userland/Libraries/LibGfx/ClassicWindowTheme.h index 8e2aff0fb12..72cb777fe4b 100644 --- a/Userland/Libraries/LibGfx/ClassicWindowTheme.h +++ b/Userland/Libraries/LibGfx/ClassicWindowTheme.h @@ -16,20 +16,19 @@ public: ClassicWindowTheme() = default; virtual ~ClassicWindowTheme() override = default; - virtual void paint_normal_frame(Painter& painter, WindowState window_state, IntRect const& window_rect, StringView window_title, Bitmap const& icon, Palette const& palette, IntRect const& leftmost_button_rect, int menu_row_count, bool window_modified) const override; - virtual void paint_tool_window_frame(Painter&, WindowState, IntRect const& window_rect, StringView title, Palette const&, IntRect const& leftmost_button_rect) const override; - virtual void paint_notification_frame(Painter&, IntRect const& window_rect, Palette const&, IntRect const& close_button_rect) const override; + virtual void paint_normal_frame(Painter& painter, WindowState window_state, WindowMode window_mode, IntRect const& window_rect, StringView window_title, Bitmap const& icon, Palette const& palette, IntRect const& leftmost_button_rect, int menu_row_count, bool window_modified) const override; + virtual void paint_notification_frame(Painter&, WindowMode, IntRect const& window_rect, Palette const&, IntRect const& close_button_rect) const override; - virtual int titlebar_height(WindowType, Palette const&) const override; - virtual IntRect titlebar_rect(WindowType, IntRect const& window_rect, Palette const&) const override; - virtual IntRect titlebar_icon_rect(WindowType, IntRect const& window_rect, Palette const&) const override; - virtual IntRect titlebar_text_rect(WindowType, IntRect const& window_rect, Palette const&) const override; + virtual int titlebar_height(WindowType, WindowMode, Palette const&) const override; + virtual IntRect titlebar_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&) const override; + virtual IntRect titlebar_icon_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&) const override; + virtual IntRect titlebar_text_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&) const override; - virtual IntRect menubar_rect(WindowType, IntRect const& window_rect, Palette const&, int menu_row_count) const override; + virtual IntRect menubar_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&, int menu_row_count) const override; - virtual IntRect frame_rect_for_window(WindowType, IntRect const& window_rect, Palette const&, int menu_row_count) const override; + virtual IntRect frame_rect_for_window(WindowType, WindowMode, IntRect const& window_rect, Palette const&, int menu_row_count) const override; - virtual Vector layout_buttons(WindowType, IntRect const& window_rect, Palette const&, size_t buttons) const override; + virtual Vector layout_buttons(WindowType, WindowMode, IntRect const& window_rect, Palette const&, size_t buttons) const override; virtual bool is_simple_rect_frame() const override { return true; } virtual bool frame_uses_alpha(WindowState state, Palette const& palette) const override { diff --git a/Userland/Libraries/LibGfx/WindowTheme.h b/Userland/Libraries/LibGfx/WindowTheme.h index 4d7e07b2ae1..741ec17bb7d 100644 --- a/Userland/Libraries/LibGfx/WindowTheme.h +++ b/Userland/Libraries/LibGfx/WindowTheme.h @@ -13,9 +13,13 @@ namespace Gfx { class WindowTheme { public: + enum class WindowMode { + RenderAbove, + Other, + }; + enum class WindowType { Normal, - ToolWindow, Notification, Other, }; @@ -31,20 +35,19 @@ public: static WindowTheme& current(); - virtual void paint_normal_frame(Painter&, WindowState, IntRect const& window_rect, StringView title, Bitmap const& icon, Palette const&, IntRect const& leftmost_button_rect, int menu_row_count, bool window_modified) const = 0; - virtual void paint_tool_window_frame(Painter&, WindowState, IntRect const& window_rect, StringView title, Palette const&, IntRect const& leftmost_button_rect) const = 0; - virtual void paint_notification_frame(Painter&, IntRect const& window_rect, Palette const&, IntRect const& close_button_rect) const = 0; + virtual void paint_normal_frame(Painter&, WindowState, WindowMode, IntRect const& window_rect, StringView title, Bitmap const& icon, Palette const&, IntRect const& leftmost_button_rect, int menu_row_count, bool window_modified) const = 0; + virtual void paint_notification_frame(Painter&, WindowMode, IntRect const& window_rect, Palette const&, IntRect const& close_button_rect) const = 0; - virtual int titlebar_height(WindowType, Palette const&) const = 0; - virtual IntRect titlebar_rect(WindowType, IntRect const& window_rect, Palette const&) const = 0; - virtual IntRect titlebar_icon_rect(WindowType, IntRect const& window_rect, Palette const&) const = 0; - virtual IntRect titlebar_text_rect(WindowType, IntRect const& window_rect, Palette const&) const = 0; + virtual int titlebar_height(WindowType, WindowMode, Palette const&) const = 0; + virtual IntRect titlebar_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&) const = 0; + virtual IntRect titlebar_icon_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&) const = 0; + virtual IntRect titlebar_text_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&) const = 0; - virtual IntRect menubar_rect(WindowType, IntRect const& window_rect, Palette const&, int menu_row_count) const = 0; + virtual IntRect menubar_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&, int menu_row_count) const = 0; - virtual IntRect frame_rect_for_window(WindowType, IntRect const& window_rect, Palette const&, int menu_row_count) const = 0; + virtual IntRect frame_rect_for_window(WindowType, WindowMode, IntRect const& window_rect, Palette const&, int menu_row_count) const = 0; - virtual Vector layout_buttons(WindowType, IntRect const& window_rect, Palette const&, size_t buttons) const = 0; + virtual Vector layout_buttons(WindowType, WindowMode, IntRect const& window_rect, Palette const&, size_t buttons) const = 0; virtual bool is_simple_rect_frame() const = 0; virtual bool frame_uses_alpha(WindowState, Palette const&) const = 0; virtual float frame_alpha_hit_threshold(WindowState) const = 0; diff --git a/Userland/Services/WindowServer/ConnectionFromClient.cpp b/Userland/Services/WindowServer/ConnectionFromClient.cpp index 283dd6b3d97..ccb3900d8b5 100644 --- a/Userland/Services/WindowServer/ConnectionFromClient.cpp +++ b/Userland/Services/WindowServer/ConnectionFromClient.cpp @@ -474,7 +474,7 @@ static Gfx::IntSize calculate_minimum_size_for_window(Window const& window) // NOTE: Windows with a title bar have a minimum size enforced by the system, // because we want to always keep their title buttons accessible. - if (window.type() == WindowType::Normal || window.type() == WindowType::ToolWindow) { + if (window.type() == WindowType::Normal) { auto palette = WindowManager::the().palette(); int required_width = 0; diff --git a/Userland/Services/WindowServer/Menubar.cpp b/Userland/Services/WindowServer/Menubar.cpp index f0cd7c50e32..f5f65a75286 100644 --- a/Userland/Services/WindowServer/Menubar.cpp +++ b/Userland/Services/WindowServer/Menubar.cpp @@ -16,7 +16,7 @@ void Menubar::layout_menu(Menu& menu, Gfx::IntRect window_rect) static constexpr auto menubar_menu_margin = 14; auto& wm = WindowManager::the(); - auto menubar_rect = Gfx::WindowTheme::current().menubar_rect(Gfx::WindowTheme::WindowType::Normal, window_rect, wm.palette(), 1); + auto menubar_rect = Gfx::WindowTheme::current().menubar_rect(Gfx::WindowTheme::WindowType::Normal, Gfx::WindowTheme::WindowMode::Other, window_rect, wm.palette(), 1); int text_width = wm.font().width(Gfx::parse_ampersand_string(menu.name())); menu.set_rect_in_window_menubar({ m_next_menu_location.x(), 0, text_width + menubar_menu_margin, menubar_rect.height() }); diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h index 7a58d708fc4..4abb87ebee1 100644 --- a/Userland/Services/WindowServer/Window.h +++ b/Userland/Services/WindowServer/Window.h @@ -134,10 +134,7 @@ public: bool is_occluded() const { return m_occluded; } void set_occluded(bool); - bool is_movable() const - { - return m_type == WindowType::Normal || m_type == WindowType::ToolWindow; - } + bool is_movable() const { return m_type == WindowType::Normal; } WindowFrame& frame() { return m_frame; } WindowFrame const& frame() const { return m_frame; } @@ -183,6 +180,7 @@ public: bool is_modal() const { return m_mode != WindowMode::Modeless; } bool is_passive() { return m_mode == WindowMode::Passive; } + bool is_rendering_above() { return m_mode == WindowMode::RenderAbove; } bool is_blocking() const { return m_mode == WindowMode::Blocking; } Window* blocking_modal_window(); diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp index a3f904d5f4b..f3e7bc22d69 100644 --- a/Userland/Services/WindowServer/WindowFrame.cpp +++ b/Userland/Services/WindowServer/WindowFrame.cpp @@ -26,8 +26,6 @@ static Gfx::WindowTheme::WindowType to_theme_window_type(WindowType type) switch (type) { case WindowType::Normal: return Gfx::WindowTheme::WindowType::Normal; - case WindowType::ToolWindow: - return Gfx::WindowTheme::WindowType::ToolWindow; case WindowType::Notification: return Gfx::WindowTheme::WindowType::Notification; default: @@ -35,6 +33,16 @@ static Gfx::WindowTheme::WindowType to_theme_window_type(WindowType type) } } +static Gfx::WindowTheme::WindowMode to_theme_window_mode(WindowMode mode) +{ + switch (mode) { + case WindowMode::RenderAbove: + return Gfx::WindowTheme::WindowMode::RenderAbove; + default: + return Gfx::WindowTheme::WindowMode::Other; + } +} + static Button::Icon s_minimize_icon; static Button::Icon s_maximize_icon; static Button::Icon s_restore_icon; @@ -57,7 +65,7 @@ static Gfx::IntRect frame_rect_for_window(Window& window, Gfx::IntRect const& re if (window.is_frameless()) return rect; int menu_row_count = (window.menubar().has_menus() && window.should_show_menubar()) ? 1 : 0; - return Gfx::WindowTheme::current().frame_rect_for_window(to_theme_window_type(window.type()), rect, WindowManager::the().palette(), menu_row_count); + return Gfx::WindowTheme::current().frame_rect_for_window(to_theme_window_type(window.type()), to_theme_window_mode(window.mode()), rect, WindowManager::the().palette(), menu_row_count); } WindowFrame::WindowFrame(Window& window) @@ -241,22 +249,22 @@ Gfx::IntRect WindowFrame::menubar_rect() const { if (!m_window.menubar().has_menus() || !m_window.should_show_menubar()) return {}; - return Gfx::WindowTheme::current().menubar_rect(to_theme_window_type(m_window.type()), m_window.rect(), WindowManager::the().palette(), menu_row_count()); + return Gfx::WindowTheme::current().menubar_rect(to_theme_window_type(m_window.type()), to_theme_window_mode(m_window.mode()), m_window.rect(), WindowManager::the().palette(), menu_row_count()); } Gfx::IntRect WindowFrame::titlebar_rect() const { - return Gfx::WindowTheme::current().titlebar_rect(to_theme_window_type(m_window.type()), m_window.rect(), WindowManager::the().palette()); + return Gfx::WindowTheme::current().titlebar_rect(to_theme_window_type(m_window.type()), to_theme_window_mode(m_window.mode()), m_window.rect(), WindowManager::the().palette()); } Gfx::IntRect WindowFrame::titlebar_icon_rect() const { - return Gfx::WindowTheme::current().titlebar_icon_rect(to_theme_window_type(m_window.type()), m_window.rect(), WindowManager::the().palette()); + return Gfx::WindowTheme::current().titlebar_icon_rect(to_theme_window_type(m_window.type()), to_theme_window_mode(m_window.mode()), m_window.rect(), WindowManager::the().palette()); } Gfx::IntRect WindowFrame::titlebar_text_rect() const { - return Gfx::WindowTheme::current().titlebar_text_rect(to_theme_window_type(m_window.type()), m_window.rect(), WindowManager::the().palette()); + return Gfx::WindowTheme::current().titlebar_text_rect(to_theme_window_type(m_window.type()), to_theme_window_mode(m_window.mode()), m_window.rect(), WindowManager::the().palette()); } Gfx::WindowTheme::WindowState WindowFrame::window_state_for_theme() const @@ -278,13 +286,7 @@ Gfx::WindowTheme::WindowState WindowFrame::window_state_for_theme() const void WindowFrame::paint_notification_frame(Gfx::Painter& painter) { auto palette = WindowManager::the().palette(); - Gfx::WindowTheme::current().paint_notification_frame(painter, m_window.rect(), palette, m_buttons.last().relative_rect()); -} - -void WindowFrame::paint_tool_window_frame(Gfx::Painter& painter) -{ - auto palette = WindowManager::the().palette(); - Gfx::WindowTheme::current().paint_tool_window_frame(painter, window_state_for_theme(), m_window.rect(), m_window.computed_title(), palette, leftmost_titlebar_button_rect()); + Gfx::WindowTheme::current().paint_notification_frame(painter, to_theme_window_mode(m_window.mode()), m_window.rect(), palette, m_buttons.last().relative_rect()); } void WindowFrame::paint_menubar(Gfx::Painter& painter) @@ -326,7 +328,7 @@ void WindowFrame::paint_menubar(Gfx::Painter& painter) void WindowFrame::paint_normal_frame(Gfx::Painter& painter) { auto palette = WindowManager::the().palette(); - Gfx::WindowTheme::current().paint_normal_frame(painter, window_state_for_theme(), m_window.rect(), m_window.computed_title(), m_window.icon(), palette, leftmost_titlebar_button_rect(), menu_row_count(), m_window.is_modified()); + Gfx::WindowTheme::current().paint_normal_frame(painter, window_state_for_theme(), to_theme_window_mode(m_window.mode()), m_window.rect(), m_window.computed_title(), m_window.icon(), palette, leftmost_titlebar_button_rect(), menu_row_count(), m_window.is_modified()); if (m_window.menubar().has_menus() && m_window.should_show_menubar()) paint_menubar(painter); @@ -387,8 +389,6 @@ void WindowFrame::render(Screen& screen, Gfx::Painter& painter) paint_notification_frame(painter); else if (m_window.type() == WindowType::Normal) paint_normal_frame(painter); - else if (m_window.type() == WindowType::ToolWindow) - paint_tool_window_frame(painter); else return; @@ -667,7 +667,7 @@ void WindowFrame::window_rect_changed(Gfx::IntRect const& old_rect, Gfx::IntRect void WindowFrame::layout_buttons() { - auto button_rects = Gfx::WindowTheme::current().layout_buttons(to_theme_window_type(m_window.type()), m_window.rect(), WindowManager::the().palette(), m_buttons.size()); + auto button_rects = Gfx::WindowTheme::current().layout_buttons(to_theme_window_type(m_window.type()), to_theme_window_mode(m_window.mode()), m_window.rect(), WindowManager::the().palette(), m_buttons.size()); for (size_t i = 0; i < m_buttons.size(); i++) m_buttons[i].set_relative_rect(button_rects[i]); } @@ -792,7 +792,7 @@ void WindowFrame::handle_titlebar_mouse_event(MouseEvent const& event) } if (event.type() == Event::MouseDown) { - if ((m_window.type() == WindowType::Normal || m_window.type() == WindowType::ToolWindow) && event.button() == MouseButton::Secondary) { + if (m_window.type() == WindowType::Normal && event.button() == MouseButton::Secondary) { auto default_action = m_window.is_maximized() ? WindowMenuDefaultAction::Restore : WindowMenuDefaultAction::Maximize; m_window.popup_window_menu(event.position().translated(rect().location()), default_action); return; @@ -806,11 +806,11 @@ void WindowFrame::handle_mouse_event(MouseEvent const& event) { VERIFY(!m_window.is_fullscreen()); - if (m_window.type() != WindowType::Normal && m_window.type() != WindowType::ToolWindow && m_window.type() != WindowType::Notification) + if (m_window.type() != WindowType::Normal && m_window.type() != WindowType::Notification) return; auto& wm = WindowManager::the(); - if (m_window.type() == WindowType::Normal || m_window.type() == WindowType::ToolWindow) { + if (m_window.type() == WindowType::Normal) { if (event.type() == Event::MouseDown) wm.move_to_front_and_make_active(m_window); } diff --git a/Userland/Services/WindowServer/WindowFrame.h b/Userland/Services/WindowServer/WindowFrame.h index 30483af6cdc..e7611a2d384 100644 --- a/Userland/Services/WindowServer/WindowFrame.h +++ b/Userland/Services/WindowServer/WindowFrame.h @@ -122,7 +122,6 @@ public: private: void paint_notification_frame(Gfx::Painter&); void paint_normal_frame(Gfx::Painter&); - void paint_tool_window_frame(Gfx::Painter&); void paint_menubar(Gfx::Painter&); MultiScaleBitmaps const* shadow_bitmap() const; Gfx::IntRect inflated_for_shadow(Gfx::IntRect const&) const; diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index e17a291bfc0..c57bd975e50 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -577,7 +577,7 @@ void WindowManager::tell_wms_current_window_stack_changed() static bool window_type_has_title(WindowType type) { - return type == WindowType::Normal || type == WindowType::ToolWindow; + return type == WindowType::Normal; } void WindowManager::notify_modified_changed(Window& window) @@ -649,7 +649,7 @@ bool WindowManager::pick_new_active_window(Window* previous_active) Window* first_candidate = nullptr; for_each_visible_window_from_front_to_back([&](Window& candidate) { - if (candidate.type() != WindowType::Normal && candidate.type() != WindowType::ToolWindow) + if (candidate.type() != WindowType::Normal) return IterationDecision::Continue; if (candidate.is_destroyed()) return IterationDecision::Continue; @@ -1246,7 +1246,7 @@ void WindowManager::process_mouse_event_for_window(HitTestResult& result, MouseE } if (event.type() == Event::MouseDown) { - if (window.type() == WindowType::Normal || window.type() == WindowType::ToolWindow) + if (window.type() == WindowType::Normal) move_to_front_and_make_active(window); else if (window.type() == WindowType::Desktop) set_active_window(&window); @@ -1420,7 +1420,6 @@ Gfx::IntRect WindowManager::arena_rect_for_type(Screen& screen, WindowType type) case WindowType::Desktop: return Screen::bounding_rect(); case WindowType::Normal: - case WindowType::ToolWindow: return desktop_rect(screen); case WindowType::Menu: case WindowType::WindowSwitcher: @@ -1797,7 +1796,7 @@ bool WindowManager::is_active_window_or_accessory(Window& window) const static bool window_type_can_become_active(WindowType type) { - return type == WindowType::Normal || type == WindowType::ToolWindow || type == WindowType::Desktop; + return type == WindowType::Normal || type == WindowType::Desktop; } void WindowManager::restore_active_input_window(Window* window) @@ -2193,7 +2192,7 @@ void WindowManager::set_always_on_top(Window& window, bool always_on_top) Gfx::IntPoint WindowManager::get_recommended_window_position(Gfx::IntPoint const& desired) { // FIXME: Find a better source for the width and height to shift by. - Gfx::IntPoint shift(8, Gfx::WindowTheme::current().titlebar_height(Gfx::WindowTheme::WindowType::Normal, palette()) + 10); + Gfx::IntPoint shift(8, Gfx::WindowTheme::current().titlebar_height(Gfx::WindowTheme::WindowType::Normal, Gfx::WindowTheme::WindowMode::Other, palette()) + 10); Window const* overlap_window = nullptr; current_window_stack().for_each_visible_window_of_type_from_front_to_back(WindowType::Normal, [&](Window& window) { @@ -2209,7 +2208,7 @@ Gfx::IntPoint WindowManager::get_recommended_window_position(Gfx::IntPoint const point = overlap_window->position() + shift; point = { point.x() % screen.width(), (point.y() >= (screen.height() - (screen.is_main_screen() ? TaskbarWindow::taskbar_height() : 0))) - ? Gfx::WindowTheme::current().titlebar_height(Gfx::WindowTheme::WindowType::Normal, palette()) + ? Gfx::WindowTheme::current().titlebar_height(Gfx::WindowTheme::WindowType::Normal, Gfx::WindowTheme::WindowMode::Other, palette()) : point.y() }; } else { point = desired; diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h index 40bb2c11c37..100bdab666c 100644 --- a/Userland/Services/WindowServer/WindowManager.h +++ b/Userland/Services/WindowServer/WindowManager.h @@ -312,7 +312,6 @@ public: { switch (window_type) { case WindowType::Normal: - case WindowType::ToolWindow: case WindowType::Tooltip: return false; default: @@ -516,8 +515,6 @@ inline IterationDecision WindowManager::for_each_visible_window_from_back_to_fro return IterationDecision::Break; if (for_each_window.template operator()() == IterationDecision::Break) return IterationDecision::Break; - if (for_each_window.template operator()() == IterationDecision::Break) - return IterationDecision::Break; if (for_each_window.template operator()() == IterationDecision::Break) return IterationDecision::Break; if (for_each_window.template operator()() == IterationDecision::Break) @@ -561,8 +558,6 @@ inline IterationDecision WindowManager::for_each_visible_window_from_front_to_ba return IterationDecision::Break; if (for_each_window.template operator()() == IterationDecision::Break) return IterationDecision::Break; - if (for_each_window.template operator()() == IterationDecision::Break) - return IterationDecision::Break; if (for_each_window.template operator()() == IterationDecision::Break) return IterationDecision::Break; return for_each_window.template operator()(); diff --git a/Userland/Services/WindowServer/WindowType.h b/Userland/Services/WindowServer/WindowType.h index 49e89cabd65..48516597628 100644 --- a/Userland/Services/WindowServer/WindowType.h +++ b/Userland/Services/WindowServer/WindowType.h @@ -18,7 +18,6 @@ enum class WindowType { Applet, Notification, Desktop, - ToolWindow, AppletArea, _Count };