GitLab will be down for maintenance this Sunday 13th June, from approx 7-11am UTC. This is for a PostgreSQL migration. See the tracker issue for more informations.

Commit bcb882cd authored by Povilas Kanapickas's avatar Povilas Kanapickas
Browse files

Add a XI2 mask builder

parent 2b01b225
Pipeline #267313 passed with stages
in 1 minute and 13 seconds
......@@ -299,12 +299,24 @@ int double_cmp(double a, double b, int precision)
void SelectXI2Events(::Display *dpy, int deviceid, Window win, const std::vector<int>& evtypes)
{
XIEventMask mask;
unsigned char m[XIMaskLen(XI_LASTEVENT)] = {0};
EventMaskBuilder mask{deviceid, evtypes};
XISelectEvents(dpy, win, mask.GetMask(), 1);
}
void GrabXI2Device(::Display *dpy, int deviceid, Window grab_win, int grab_mode,
int paired_device_mode, const std::vector<int>& evtypes)
{
EventMaskBuilder mask{deviceid, evtypes};
XIGrabDevice(dpy, deviceid, grab_win, CurrentTime, None, grab_mode, paired_device_mode, False,
mask.GetMask());
}
EventMaskBuilder::EventMaskBuilder(int deviceid, const std::vector<int>& evtypes)
{
mask.deviceid = deviceid;
mask.mask_len = XIMaskLen(XI_LASTEVENT);
mask.mask = m;
for (auto evtype : evtypes)
XISetMask(mask.mask, evtype);
XISelectEvents(dpy, win, &mask, 1);
storage.resize(mask.mask_len, 0);
mask.mask = storage.data();
for (auto event : evtypes)
XISetMask(mask.mask, event);
}
......@@ -28,6 +28,7 @@
#include <string>
#include <xorg/gtest/xorg-gtest.h>
#include "xorg-conf.h"
#include <X11/extensions/XInput2.h>
#include "xit-server.h"
......@@ -185,5 +186,26 @@ int double_cmp(double a, double b, int precision = 2);
*/
void SelectXI2Events(Display *dpy, int deviceid, Window win,
const std::vector<int>& evtypes);
/**
* Grab the specific device for event types given in evtypes
*/
void GrabXI2Device(::Display *dpy, int deviceid, Window grab_win, int grab_mode,
int paired_device_mode, const std::vector<int>& evtypes);
/**
* Builds a XI2 event mask
*/
class EventMaskBuilder {
public:
EventMaskBuilder(int deviceid, const std::vector<int>& evtypes);
XIEventMask* GetMask() { return &mask; }
private:
XIEventMask mask;
std::vector<unsigned char> storage;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment