我们有一个电子应用程序,希望在本地C代码中访问由该应用程序创建的窗口。下面是获取窗口id的电子端代码
const handle = windowObject.getNativeWindowHandle();
const windowId = handle.readUInt32LE(0); // We are currently targetting x86 on linux现在,我们用C语言编写了以下代码来创建曲面:
Display *d = XOpenDisplay(NULL);
int screen = DefaultScreen(d);
Drawable da = windowIdPassedFromElectronApp;
// Drawable da = XCreateSimpleWindow(d, DefaultRootWindow(d), 0, 0, x, y, 0, 0, 0);
// The code in the comment above works - but that creates a new window,
// we wish to use the window created by electron application
XSelectInput(d, da, ButtonPressMask | KeyPressMask);
XMapWindow(d, da);
cairo_surface_t* sfc = cairo_xlib_surface_create(d, da, DefaultVisual(d, screen), x, y);上面的代码抛出以下错误:
X Error of failed request: BadAccess (attempt to access private resource denied)
Major opcode of failed request: 2 (X_ChangeWindowAttributes)
Serial number of failed request: 7
Current serial number in output stream: 9我们如何确保C代码可以被安全地授予在电子应用程序创建的窗口上绘制的权限?对于我们的用例,一些替代的架构可以工作吗?
发布于 2021-01-27 15:11:35
我们设法解决了这个问题,创建了一个子窗口,父窗口作为电子应用程序传递的窗口。示例代码:
Drawable da = XCreateSimpleWindow(d, windowIdPassedFromElectronApp, offsetX, offsetY, sizeX, sizeY, 0, 0, 0);https://stackoverflow.com/questions/65914135
复制相似问题