我正在尝试获取XEvents,然后决定它是否应该像正常一样继续或被阻止。
基本上gdk_window_add_filter
正在做什么:https://developer.gnome.org/gdk3/stable/gdk3-Windows.html#gdk-window-add-filter
我尝试使用下面的代码,但遇到了这些问题:
这是我在ctypes中的完整代码:
var win = ostypes.TYPE.Window();
var revert_to = ostypes.TYPE.int();
var rez_XGetFocus = ostypes.API('XGetInputFocus')(ostypes.HELPER.cachedXOpenDisplay(), win.address(), revert_to.address());
console.log('rez_XGetFocus:', rez_XGetFocus);
var rez_XSelectInput = ostypes.API('XSelectInput')(ostypes.HELPER.cachedXOpenDisplay(), win, ostypes.CONST.ButtonPressMask | ostypes.CONST.ButtonReleaseMask);
console.log('rez_XSelectInput:', rez_XSelectInput);
var rez_XGrab = ostypes.API('XGrabPointer')(ostypes.HELPER.cachedXOpenDisplay(), win, true, ostypes.CONST.ButtonPressMask | ostypes.CONST.ButtonReleaseMask, ostypes.CONST.GrabModeSync, ostypes.CONST.GrabModeAsync, ostypes.CONST.None, ostypes.CONST.None, ostypes.CONST.CurrentTime);
console.log('rez_XGrab:', rez_XGrab);
var rez_XGrab = 0;
if (!cutils.jscEqual(rez_XGrab, ostypes.CONST.GrabSuccess)) {
if (cutils.jscEqual(rez_XGrab, ostypes.CONST.AlreadyGrabbed)) {
console.log('already grabbed so will ungrab then regrab');
var rez_XUngrab = ostypes.API('XUngrabPointer')(ostypes.HELPER.cachedXOpenDisplay(), ostypes.CONST.CurrentTime);
console.log('rez_XUngrab:', rez_XUngrab);
var rez_XFlush = ostypes.API('XFlush')(ostypes.HELPER.cachedXOpenDisplay());
console.log('rez_XFlush:', rez_XFlush);
var rez_XGrab2 = ostypes.API('XGrabPointer')(ostypes.HELPER.cachedXOpenDisplay(), win, false, ostypes.CONST.ButtonPressMask | ostypes.CONST.ButtonReleaseMask, ostypes.CONST.GrabModeSync, ostypes.CONST.GrabModeAsync, ostypes.CONST.None, ostypes.CONST.None, ostypes.CONST.CurrentTime);
console.log('rez_XGrab2:', rez_XGrab2);
if (!cutils.jscEqual(rez_XGrab2, ostypes.CONST.GrabSuccess)) {
console.error('failed to XGrabPointer a SECOND time with value:', rez_XGrab);
throw new Error('failed to XGrabPointer a SECOND time with value: ' + rez_XGrab);
}
} else {
console.error('failed to XGrabPointer with value:', rez_XGrab);
throw new Error('failed to XGrabPointer with value: ' + rez_XGrab);
}
}
//
// // var rez_XChangeGrab = ostypes.API('XChangeActivePointerGrab')(ostypes.HELPER.cachedXOpenDisplay(), ostypes.HELPER.cachedDefaultRootWindow(), ostypes.CONST.ButtonPressMask | ostypes.CONST.ButtonReleaseMask, ostypes.CONST.CurrentTime);
// // console.log('rez_XChangeGrab:', rez_XChangeGrab);
//
// // throw new Error('ok?');
// // var rez_XSelectInput = ostypes.API('XSelectInput')(ostypes.HELPER.cachedXOpenDisplay(), ostypes.HELPER.cachedDefaultRootWindow(), ostypes.CONST.ButtonPressMask | ostypes.CONST.ButtonReleaseMask);
// // console.log('rez_XSelectInput:', rez_XSelectInput);
//
var ev = ostypes.TYPE.XEvent();
var st = new Date().getTime();
var runFor = 10000; // ms
while (true) {
var rez_XAllow = ostypes.API('XAllowEvents')(ostypes.HELPER.cachedXOpenDisplay(), ostypes.CONST.SyncPointer, ostypes.CONST.CurrentTime);
console.log('rez_XAllow:', rez_XAllow);
var rez_XNextEvent = ostypes.API('XNextEvent')(ostypes.HELPER.cachedXOpenDisplay(), ev.address());
console.log('rez_XNextEvent:', rez_XNextEvent);
console.info('ev:', ev.xbutton);
// :debug:
if (new Date().getTime() - st > runFor) {
console.log('time up');
break;
}
}
var rez_XUngrab2 = ostypes.API('XUngrabPointer')(ostypes.HELPER.cachedXOpenDisplay(), ostypes.CONST.CurrentTime);
console.log('rez_XUngrab2:', rez_XUngrab2);