summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2021-06-21 08:02:31 -0600
committerAndreas Kling <kling@serenityos.org>2021-06-21 16:52:29 +0200
commit08e2dc22be85aa55ae5380d50ccda826eed96e30 (patch)
tree26a38389e65102fc3e9112c0249f2bb153a7c53f
parente79ef6461a2983985a94e6447418e9453487e212 (diff)
downloadserenity-08e2dc22be85aa55ae5380d50ccda826eed96e30.zip
WindowServer: Fix animated cursor regression
-rw-r--r--Userland/Services/WindowServer/Cursor.cpp17
-rw-r--r--Userland/Services/WindowServer/Cursor.h1
2 files changed, 12 insertions, 6 deletions
diff --git a/Userland/Services/WindowServer/Cursor.cpp b/Userland/Services/WindowServer/Cursor.cpp
index cd8559321f..7c759e97f9 100644
--- a/Userland/Services/WindowServer/Cursor.cpp
+++ b/Userland/Services/WindowServer/Cursor.cpp
@@ -106,6 +106,11 @@ Cursor::Cursor(NonnullRefPtr<Gfx::Bitmap>&& bitmap, int scale_factor, const Curs
, m_rect(bitmap->rect())
{
m_bitmaps.set(scale_factor, move(bitmap));
+ update_rect_if_animated();
+}
+
+void Cursor::update_rect_if_animated()
+{
if (m_params.frames() > 1) {
VERIFY(m_rect.width() % m_params.frames() == 0);
m_rect.set_width(m_rect.width() / m_params.frames());
@@ -129,17 +134,11 @@ RefPtr<Cursor> Cursor::create(const StringView& filename, const StringView& defa
bool Cursor::load(const StringView& filename, const StringView& default_filename)
{
bool did_load_any = false;
- bool first = true;
auto load_bitmap = [&](const StringView& path, int scale_factor) {
auto bitmap = Gfx::Bitmap::load_from_file(path, scale_factor);
if (bitmap) {
did_load_any = true;
- if (first) {
- m_params = CursorParams::parse_from_filename(filename, bitmap->rect().center());
- m_rect = bitmap->rect();
- first = false;
- }
m_bitmaps.set(scale_factor, bitmap.release_nonnull());
}
};
@@ -154,6 +153,12 @@ bool Cursor::load(const StringView& filename, const StringView& default_filename
return IterationDecision::Continue;
});
}
+ if (did_load_any) {
+ auto& bitmap = this->bitmap(1);
+ m_rect = bitmap.rect();
+ m_params = CursorParams::parse_from_filename(filename, m_rect.center()).constrained(bitmap);
+ update_rect_if_animated();
+ }
return did_load_any;
}
diff --git a/Userland/Services/WindowServer/Cursor.h b/Userland/Services/WindowServer/Cursor.h
index 58110c2fb8..e36ebd2945 100644
--- a/Userland/Services/WindowServer/Cursor.h
+++ b/Userland/Services/WindowServer/Cursor.h
@@ -72,6 +72,7 @@ private:
Cursor(NonnullRefPtr<Gfx::Bitmap>&&, int, const CursorParams&);
bool load(const StringView&, const StringView&);
+ void update_rect_if_animated();
HashMap<int, NonnullRefPtr<Gfx::Bitmap>> m_bitmaps;
CursorParams m_params;