From f717008bdefecc877155a8dd1c9230c9673b5e47 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Tue, 7 Sep 2021 21:56:27 +0200 Subject: [PATCH] CatDog: Switch to new mouse-tracking method --- Userland/Demos/CatDog/CatDog.cpp | 18 ++++-------------- Userland/Demos/CatDog/CatDog.h | 7 ++++--- Userland/Demos/CatDog/main.cpp | 1 - 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/Userland/Demos/CatDog/CatDog.cpp b/Userland/Demos/CatDog/CatDog.cpp index bccfaab3a25..9ee9a0fadf5 100644 --- a/Userland/Demos/CatDog/CatDog.cpp +++ b/Userland/Demos/CatDog/CatDog.cpp @@ -7,7 +7,6 @@ #include "CatDog.h" #include #include -#include void CatDog::timer_event(Core::TimerEvent&) { @@ -105,13 +104,14 @@ void CatDog::paint_event(GUI::PaintEvent& event) painter.blit(Gfx::IntPoint(0, 0), *m_curr_bmp, m_curr_bmp->rect()); } -void CatDog::mousemove_event(GUI::MouseEvent& event) +void CatDog::track_mouse_move(Gfx::IntPoint const& point) { if (!m_roaming) return; - if (m_temp_pos == event.position()) + Gfx::IntPoint relative_point = point - window()->position(); + if (m_temp_pos == relative_point) return; - m_temp_pos = event.position(); + m_temp_pos = relative_point; m_timer.start(); if (m_sleeping) { m_curr_bmp = m_alert; @@ -128,16 +128,6 @@ void CatDog::mousedown_event(GUI::MouseEvent& event) on_click(); } -void CatDog::track_cursor_globally() -{ - VERIFY(window()); - auto window_id = window()->window_id(); - VERIFY(window_id >= 0); - - set_global_cursor_tracking(true); - GUI::WindowServerConnection::the().async_set_global_cursor_tracking(window_id, true); -} - void CatDog::context_menu_event(GUI::ContextMenuEvent& event) { if (on_context_menu_request) diff --git a/Userland/Demos/CatDog/CatDog.h b/Userland/Demos/CatDog/CatDog.h index bde31f3d6df..49f702b1726 100644 --- a/Userland/Demos/CatDog/CatDog.h +++ b/Userland/Demos/CatDog/CatDog.h @@ -6,22 +6,23 @@ #include #include +#include #include #include #pragma once -class CatDog final : public GUI::Widget { +class CatDog final : public GUI::Widget + , GUI::MouseTracker { C_OBJECT(CatDog); public: virtual void timer_event(Core::TimerEvent&) override; virtual void paint_event(GUI::PaintEvent& event) override; - virtual void mousemove_event(GUI::MouseEvent& event) override; + virtual void track_mouse_move(Gfx::IntPoint const& point) override; virtual void mousedown_event(GUI::MouseEvent& event) override; virtual void context_menu_event(GUI::ContextMenuEvent& event) override; - void track_cursor_globally(); void start_the_timer() { m_timer.start(); } Function on_click; diff --git a/Userland/Demos/CatDog/main.cpp b/Userland/Demos/CatDog/main.cpp index ac6c2aae36f..380b68f7f41 100644 --- a/Userland/Demos/CatDog/main.cpp +++ b/Userland/Demos/CatDog/main.cpp @@ -59,7 +59,6 @@ int main(int argc, char** argv) context_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); window->show(); - catdog_widget.track_cursor_globally(); catdog_widget.start_timer(250, Core::TimerShouldFireWhenNotVisible::Yes); catdog_widget.start_the_timer(); // timer for "mouse sleep detection"