-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvcursor.cpp
More file actions
127 lines (107 loc) · 3.17 KB
/
vcursor.cpp
File metadata and controls
127 lines (107 loc) · 3.17 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "vcursor.h"
#include "xcbutil.h"
#include <stdio.h>
#include <vector>
using namespace std;
static vector<Vcursor *> cursors; // Vector of all cursors
static bool firstTime = true; // First time connecting
const int NUMCURSORS = 8; // Number of cursors to spawn
// Different random colors to choose from
static int colors [8] = { 16777215, 858083, 0, 33023, 2263842, 14772544, 14381203, 65535 };
// Return the mouseId of the cursor
int Vcursor::getMouseId ( ) {
return mouseId;
}
// Return the windowId of the cursor
xcb_window_t Vcursor::getWindowId ( ) {
return windowId;
}
/* Return whether the cursor is hidden (inactive)
or visible (active) */
bool Vcursor::isHidden ( ) {
return hidden;
}
/* Create a new virtual cursor with the given
mouseId and color. */
Vcursor::Vcursor ( int mouseId, int color ) {
// Cursors start hidden and become visible when activated
hidden = true;
isMouseDown = false;
xpos = 0;
ypos = 0;
this->mouseId = mouseId;
// Create the window corresponding to the vcursor
this->windowId = xcbCreateWindow ( color );
}
/* Returns an inactive cursor if one is available
or null if all cursors are already in use */
Vcursor * Vcursor::getCursor( ) {
Vcursor * temp;
int i;
// If this is the first call, create the cursors
if (firstTime) {
// Create NUMCURSORS virtual cursors and place them in the vector
for (i = 0; i < NUMCURSORS; i++) {
temp = new Vcursor ( i , colors[i % sizeof(colors)] ) ;
cursors.push_back ( temp );
}
firstTime = false;
}
// If not first time, return an inactive cursor or null
for (i = 0; i < NUMCURSORS; i++)
if (cursors[i]->isHidden ( )) {
// Unhide the cursor since it is now in use
cursors[i]->show ( );
return cursors[i];
}
// All cursor are occupied
return NULL;
}
// Make the cursor window visible and set hidden appropriately
void Vcursor::show( ) {
xcbShowWindow ( this->windowId );
hidden = false;
// Update the display
}
// Make the cursor window invisible and set hidden appropriately
void Vcursor::hide( ) {
xcbHideWindow ( this->windowId );
hidden = true;
move ( 0,0 );
// Update the display
}
// Return the current position of the cursor
pair<int,int> Vcursor::getPosition( ) {
return pair<int,int> ( xpos, ypos );
}
// Move the cursor to the specified location
void Vcursor::move ( int x, int y ) {
xpos = x;
ypos = y;
moveWindow( windowId, x, y );
}
// Mouse button is released
void Vcursor::up ( int buttonId ) {
xcbMouseUp ( buttonId );
int i;
// When a click is released bring all cursors to the front (in terms of z-order)
for ( i = 0; i < cursors.size(); i++ ) {
if ( !cursors[i]->isHidden( ) )
xcbPullToTop ( cursors[i]->windowId );
}
}
// Mouse button is pushed
void Vcursor::down ( int buttonId ) {
/* Move system cursor to vcursor's current position -1 so
the vcursor window doesn't eat the event, then click */
xcbMove( xpos-1, ypos-1 );
xcbMouseDown ( buttonId );
}
// Set isMouseDown to state when a mouse click is started (true) or released (false)
void Vcursor::setMDown ( bool state ) {
isMouseDown = state;
}
// Get the current state of the virtual cursor
bool Vcursor::getMDown ( ) {
return isMouseDown;
}