Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions xkbcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ int main(int argc, char * argv[]) {
{ // Register to receive XInput events
Window root = DefaultRootWindow(disp);
XIEventMask m;
m.deviceid = XIAllMasterDevices;
m.deviceid = XIAllDevices;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XI_KeyPress won't be capturable with master devices only

m.mask_len = XIMaskLen(XI_LASTEVENT);
m.mask = calloc(m.mask_len, sizeof(char));
// Raw key presses correspond to physical key-presses, without
// processing steps such as auto-repeat.
XISetMask(m.mask, XI_RawKeyPress);
XISetMask(m.mask, XI_KeyPress);
if (printKeyUps) XISetMask(m.mask, XI_RawKeyRelease);
XISelectEvents(disp, root, &m, 1 /*number of masks*/);
XSync(disp, false);
Expand Down Expand Up @@ -117,7 +117,7 @@ int main(int argc, char * argv[]) {
if (cookie->type == GenericEvent
&& cookie->extension == xiOpcode) {
if (cookie->evtype == XI_RawKeyRelease
|| cookie->evtype == XI_RawKeyPress) {
|| cookie->evtype == XI_KeyPress) {
XIRawEvent *ev = cookie->data;

// Ask X what it calls that key; skip if unknown.
Expand All @@ -142,9 +142,17 @@ int main(int argc, char * argv[]) {
char *str = XKeysymToString(s);
if (NULL == str) continue;

if (cookie->evtype == XI_RawKeyRelease && ev->deviceid != ev->sourceid) continue;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate key event would be sent so filtering with deviceid and sourceid


// Output line
if (printKeyUps) printf("%s",
cookie->evtype == XI_RawKeyPress ? "+" : "-");
if (printKeyUps) {
if (cookie->evtype == XI_KeyPress) {
XIDeviceEvent* dev_ev = cookie->data;
printf("%s", (dev_ev->flags & XIKeyRepeat) ? "=" : "+");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to output of xinput --test-xi2 --root , XIDeviceEvent was the correct type to handle XI_KeyPress

} else {
printf("-");
}
}
printf("%s\n", str);
fflush(stdout);
}
Expand Down