summaryrefslogtreecommitdiff
path: root/Userland/Applications/MouseSettings
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2022-06-06 10:16:43 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-06 11:03:05 +0100
commitd116fc01e89c15a992e30bb6b26ad13f6b87996a (patch)
treeb3c9794d9d448c6f69c7507de172a9280984728b /Userland/Applications/MouseSettings
parenta0bea0b86f7ce45f7c0a77cf91336ca227959dd6 (diff)
downloadserenity-d116fc01e89c15a992e30bb6b26ad13f6b87996a.zip
MouseSettings: Get highlight preview cursor via cursor theme Config.ini
Fixes #14200
Diffstat (limited to 'Userland/Applications/MouseSettings')
-rw-r--r--Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp23
-rw-r--r--Userland/Applications/MouseSettings/HighlightPreviewWidget.h2
2 files changed, 23 insertions, 2 deletions
diff --git a/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp b/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp
index e7372e7a00..2ee4f852a4 100644
--- a/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp
+++ b/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp
@@ -6,6 +6,7 @@
#include "HighlightPreviewWidget.h"
#include <AK/String.h>
+#include <LibCore/ConfigFile.h>
#include <LibGUI/ConnectionToWindowServer.h>
#include <LibGUI/Painter.h>
#include <LibGfx/AntiAliasingPainter.h>
@@ -15,8 +16,25 @@ namespace MouseSettings {
HighlightPreviewWidget::HighlightPreviewWidget(Gfx::Palette const& palette)
: GUI::AbstractThemePreview(palette)
{
+ (void)reload_cursor();
+}
+
+ErrorOr<void> HighlightPreviewWidget::reload_cursor()
+{
auto cursor_theme = GUI::ConnectionToWindowServer::the().get_cursor_theme();
- m_cursor_bitmap = Gfx::Bitmap::try_load_from_file(String::formatted("/res/cursor-themes/{}/arrow.x2y2.png", cursor_theme)).release_value_but_fixme_should_propagate_errors();
+ auto theme_path = String::formatted("/res/cursor-themes/{}/{}", cursor_theme, "Config.ini");
+ auto cursor_theme_config = TRY(Core::ConfigFile::open(theme_path));
+ auto load_bitmap = [](StringView path, StringView default_path) {
+ auto maybe_bitmap = Gfx::Bitmap::try_load_from_file(path);
+ if (!maybe_bitmap.is_error())
+ return maybe_bitmap;
+ return Gfx::Bitmap::try_load_from_file(default_path);
+ };
+ constexpr auto default_cursor_path = "/res/cursor-themes/Default/arrow.x2y2.png";
+ auto cursor_path = String::formatted("/res/cursor-themes/{}/{}",
+ cursor_theme, cursor_theme_config->read_entry("Cursor", "Arrow"));
+ m_cursor_bitmap = TRY(load_bitmap(cursor_path, default_cursor_path));
+ return {};
}
void HighlightPreviewWidget::paint_preview(GUI::PaintEvent&)
@@ -28,7 +46,8 @@ void HighlightPreviewWidget::paint_preview(GUI::PaintEvent&)
highlight_rect.center_within(frame_inner_rect());
aa_painter.fill_ellipse(highlight_rect, m_color);
}
- painter.blit(m_cursor_bitmap->rect().centered_within(frame_inner_rect()).location(), *m_cursor_bitmap, m_cursor_bitmap->rect());
+ if (m_cursor_bitmap)
+ painter.blit(m_cursor_bitmap->rect().centered_within(frame_inner_rect()).location(), *m_cursor_bitmap, m_cursor_bitmap->rect());
}
}
diff --git a/Userland/Applications/MouseSettings/HighlightPreviewWidget.h b/Userland/Applications/MouseSettings/HighlightPreviewWidget.h
index 72d638db94..01d4b3d5ba 100644
--- a/Userland/Applications/MouseSettings/HighlightPreviewWidget.h
+++ b/Userland/Applications/MouseSettings/HighlightPreviewWidget.h
@@ -33,6 +33,8 @@ public:
private:
explicit HighlightPreviewWidget(Gfx::Palette const& palette);
+ ErrorOr<void> reload_cursor();
+
RefPtr<Gfx::Bitmap> m_cursor_bitmap;
int m_radius { 0 };