-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathCursorOSX.cpp
58 lines (45 loc) · 1.44 KB
/
CursorOSX.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "Cursor.h"
#include <QApplication>
#include <QDesktopWidget>
#include <cassert>
#include <set>
#include <stdint.h>
#include "CaptureConfig.h"
#include "MurmurHash3.h"
#include "ObjectiveCBridge.h"
namespace screencast {
std::set<uint32_t> Cursor::m_cachedImages;
Cursor::Cursor() : m_imageID(0)
{
}
Cursor::Cursor(const CaptureConfig &config)
{
id cursor = cursor_currentSystemCursor();
BridgePoint hotSpot = cursor_hotSpot(cursor);
BridgePoint mouseLocation = event_mouseLocation();
id cursorImage = cursor_image(cursor);
id tiffData = cursorImage != nil ?
image_TIFFRepresentation(cursorImage) : nil;
if (tiffData == nil) {
m_imageID = Cursor::blankCursor();
m_position.rx() = 0;
m_position.ry() = 0;
return;
}
MurmurHash3_x86_32(
data_bytes(tiffData),
data_length(tiffData),
0,
&m_imageID);
if (m_cachedImages.find(m_imageID) == m_cachedImages.end()) {
m_cachedImages.insert(m_imageID);
bridgeWriteCursorFile(tiffData, m_imageID);
}
// The NSCursor Y coordinate's origin is at the bottom of the screen.
// Invert it.
mouseLocation.y =
QApplication::desktop()->screenGeometry().height() - mouseLocation.y;
m_position.rx() = mouseLocation.x - hotSpot.x - config.captureX;
m_position.ry() = mouseLocation.y - hotSpot.y - config.captureY;
}
} // namespace screencast