mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:07:34 +00:00
LibGUI+WindowServer: Introduce new mouse tracking mechanism
This commit is contained in:
parent
bde3c7301e
commit
45126655cd
10 changed files with 94 additions and 3 deletions
|
@ -66,6 +66,7 @@ set(SOURCES
|
|||
Model.cpp
|
||||
ModelIndex.cpp
|
||||
ModelSelection.cpp
|
||||
MouseTracker.cpp
|
||||
MultiView.cpp
|
||||
Notification.cpp
|
||||
OpacitySlider.cpp
|
||||
|
|
36
Userland/Libraries/LibGUI/MouseTracker.cpp
Normal file
36
Userland/Libraries/LibGUI/MouseTracker.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibGUI/MouseTracker.h>
|
||||
#include <LibGUI/WindowServerConnection.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
MouseTracker::List MouseTracker::s_trackers;
|
||||
|
||||
MouseTracker::MouseTracker()
|
||||
{
|
||||
if (s_trackers.is_empty()) {
|
||||
WindowServerConnection::the().async_set_global_mouse_tracking(true);
|
||||
}
|
||||
s_trackers.append(*this);
|
||||
}
|
||||
MouseTracker::~MouseTracker()
|
||||
{
|
||||
m_list_node.remove();
|
||||
if (s_trackers.is_empty()) {
|
||||
WindowServerConnection::the().async_set_global_mouse_tracking(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MouseTracker::track_mouse_move(Badge<WindowServerConnection>, Gfx::IntPoint const& point)
|
||||
{
|
||||
for (auto& tracker : s_trackers) {
|
||||
tracker.track_mouse_move(point);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
33
Userland/Libraries/LibGUI/MouseTracker.h
Normal file
33
Userland/Libraries/LibGUI/MouseTracker.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/IntrusiveList.h>
|
||||
#include <LibGUI/Forward.h>
|
||||
#include <LibGfx/Point.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class MouseTracker {
|
||||
public:
|
||||
MouseTracker();
|
||||
virtual ~MouseTracker();
|
||||
|
||||
static void track_mouse_move(Badge<WindowServerConnection>, Gfx::IntPoint const&);
|
||||
|
||||
protected:
|
||||
virtual void track_mouse_move(Gfx::IntPoint const&) = 0;
|
||||
|
||||
private:
|
||||
IntrusiveListNode<MouseTracker> m_list_node;
|
||||
using List = IntrusiveList<MouseTracker, RawPtr<MouseTracker>, &MouseTracker::m_list_node>;
|
||||
static List s_trackers;
|
||||
};
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@
|
|||
#include <LibGUI/EmojiInputDialog.h>
|
||||
#include <LibGUI/Event.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/MouseTracker.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGUI/WindowServerConnection.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
|
@ -370,6 +371,11 @@ void WindowServerConnection::display_link_notification()
|
|||
});
|
||||
}
|
||||
|
||||
void WindowServerConnection::track_mouse_move(Gfx::IntPoint const& mouse_position)
|
||||
{
|
||||
MouseTracker::track_mouse_move({}, mouse_position);
|
||||
}
|
||||
|
||||
void WindowServerConnection::ping()
|
||||
{
|
||||
async_pong();
|
||||
|
|
|
@ -55,6 +55,7 @@ private:
|
|||
virtual void update_system_fonts(String const&, String const&) override;
|
||||
virtual void window_state_changed(i32, bool, bool) override;
|
||||
virtual void display_link_notification() override;
|
||||
virtual void track_mouse_move(Gfx::IntPoint const&) override;
|
||||
virtual void ping() override;
|
||||
|
||||
bool m_display_link_notification_pending { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue