-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimitpointer.cpp
More file actions
47 lines (37 loc) · 1.02 KB
/
Copy pathlimitpointer.cpp
File metadata and controls
47 lines (37 loc) · 1.02 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
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <iostream>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
bool active = true;
void playpause ( int sig )
{
active = active ? false : true;
}
int main(int argc, char* argv[])
{
signal(28, playpause); //killall -s 28 limitpointer will execute this function
Display *dsp = XOpenDisplay( NULL );
if( !dsp ){ return 1; }
int screen_width;
if (argc == 2)
screen_width = atoi(argv[1]);
else
screen_width = DisplayWidth(dsp, DefaultScreen(dsp)) / 2;
Window focusWin = RootWindow(dsp, DefaultScreen(dsp));
XEvent event;
while (true)
{
while (active)
{
XQueryPointer(dsp, focusWin, &event.xbutton.root, &event.xbutton.window, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
if (event.xbutton.x >= screen_width)
XTestFakeMotionEvent(dsp, DefaultScreen(dsp), screen_width - 1, event.xbutton.y, 0);
usleep(500); //0.5 ms
}
sleep (1); // 1 s
}
XCloseDisplay( dsp );
return 0;
}