summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/MouseTracker.cpp
blob: 4e4129dc27de24403ad09874077933f0cb3f4cd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * Copyright (c) 2021, Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibGUI/ConnectionToWindowServer.h>
#include <LibGUI/MouseTracker.h>

namespace GUI {

MouseTracker::List MouseTracker::s_trackers;

MouseTracker::MouseTracker()
{
    if (s_trackers.is_empty()) {
        ConnectionToWindowServer::the().async_set_global_mouse_tracking(true);
    }
    s_trackers.append(*this);
}
MouseTracker::~MouseTracker()
{
    m_list_node.remove();
    if (s_trackers.is_empty()) {
        ConnectionToWindowServer::the().async_set_global_mouse_tracking(false);
    }
}

void MouseTracker::track_mouse_move(Badge<ConnectionToWindowServer>, Gfx::IntPoint point)
{
    for (auto& tracker : s_trackers) {
        tracker.track_mouse_move(point);
    }
}

}