mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 14:14:45 +03:00
CatDog: Switch to new mouse-tracking method
This commit is contained in:
parent
2f38cad987
commit
f717008bde
Notes:
sideshowbarker
2024-07-18 04:27:42 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/f717008bdef Pull-request: https://github.com/SerenityOS/serenity/pull/9881
@ -7,7 +7,6 @@
|
||||
#include "CatDog.h"
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGUI/WindowServerConnection.h>
|
||||
|
||||
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)
|
||||
|
@ -6,22 +6,23 @@
|
||||
|
||||
#include <LibCore/ElapsedTimer.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/MouseTracker.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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<void()> on_click;
|
||||
|
@ -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"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user