Tag: xlib

与xlib链接需要做什么?

我正在使用GCC,我需要添加哪些开关才能与Xlib链接? 搜索之后,我找到的只是-lX11 ,但这给了我ld: library not found for -lX11 我正在使用mac(10.6),但我不喜欢Mac特有的任何东西。

指针运动。 为什么数字如此之高? 为什么它在块中打印信息而不是常量流?

嗨! 我正在尝试编写一个程序,我需要报告每个鼠标运动的位置。 我用PointerMotionMask掩码调用了XSelectInput()函数。 一切似乎都运行正常,但打印后的数字不会在每次移动后出现,它们以块的forms出现,而且event.xmotion.x和event.xmotion.y中的数字非常高,数十万。 造成这些大数字的原因是什么? 我的程序也是获取每个号码并立即报告它还是存储在队列中并以块的forms发送到终端? 谢谢 这是我的事件循环: while(1) { XNextEvent(display, &event); switch (event.type) { case Expose: glClearColor( 1.0, 1.0, 0.0, 1.0 ); glClear( GL_COLOR_BUFFER_BIT ); glFlush(); glXSwapBuffers( display, glxwin ); break; case MotionNotify: printf(“%d, %d”, event.xmotion.x, event.xmotion.y); break; case ButtonPress: exit(1); default: break; } }

如何在XLib中创建半透明白色窗口

我想在XLib中创建一个半透明的白色窗口,但窗口不是半透明的,它仍然是完全不透明的。 我使用compton合成器,系统中有透明窗口,所以问题在于代码: #include #include #include int main(int argc, char* argv[]) { Display* display = XOpenDisplay(NULL); XVisualInfo vinfo; XMatchVisualInfo(display, DefaultScreen(display), 32, TrueColor, &vinfo); XSetWindowAttributes attr; attr.colormap = XCreateColormap(display, DefaultRootWindow(display), vinfo.visual, AllocNone); attr.border_pixel = 0; attr.background_pixel = 0x80ffffff; Window win = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 300, 200, 0, vinfo.depth, InputOutput, vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel, &attr); […]

使用Xlib获取鼠标点击坐标

我想知道如何在屏幕上的任何位置使用Xlib获取鼠标点击的x和y坐标。 我发现这个post获取当前指针的位置 如何在X中获取当前鼠标(指针)位置坐标 , 但我不知道如何修改它,以便在单击鼠标时获取xy坐标。 我试过写这段代码,但它什么也没做。 #include #include #include #include int main (){ int x=-1,y=-1; XEvent event; int button; Display *display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr, “Cannot connect to X server!\n”); exit (EXIT_FAILURE); } Window root= XDefaultRootWindow(display); XSelectInput(display, root, ButtonReleaseMask) ; while(1){ XNextEvent(display,&event); switch(event.type){ case ButtonRelease: switch(event.xbutton.button){ case Button1: x=event.xbutton.x; y=event.xbutton.y; button=Button1; […]

如何将32位图像上传到服务器端像素图

我正在尝试从客户端缓冲区创建服务器端RGBA像素图。 CreatePixmap和CreateImage适用于32位和24位,但XPutImage会导致服务器返回匹配错误 X Error of failed request: BadMatch (invalid parameter attributes) Major opcode of failed request: 72 (X_PutImage) Serial number of failed request: 8 Current serial number in output stream: 8 服务器支持32位pixmaps(xdpyinfo输出: https ://gist.github.com/2582961)。 在ubuntu 12.04(X.Org版本:1.11.3)和OSX与X.app(X.Org版本:1.10.3)上的行为相同 为什么以下代码失败? #include #include int main(int argc, char **argv) { int width = 100; int height = 100; int depth […]

如何使用xlib正确截取屏幕截图?

我正在尝试捕获屏幕图像以用于截屏。 因此我需要一个快速的解决方案,并且不能依赖shell程序,如import或xwd。 这是我到目前为止编写的代码,但是它失败并且给了我一个垃圾图像,它似乎只是显示了几个奇怪颜色的图像片段被拼凑在一起。 http://sofzh.miximages.com/c%2B%2B/blah.png 关于我做错的任何想法? #include #include #include #include using namespace cimg_library; int main() { Display *display = XOpenDisplay(NULL); Window root = DefaultRootWindow(display); XWindowAttributes gwa; XGetWindowAttributes(display, root, &gwa); int width = gwa.width; int height = gwa.height; XImage *image = XGetImage(display,root, 0,0 , width,height,AllPlanes, ZPixmap); unsigned char *array = new unsigned char[width * height * 3]; […]

如何退出阻止xlib的XNextEvent

在windows下,GUI线程通常调用GetMessage来等待消息,当另一个线程使用PoseMessage将消息放入队列时,GUI线程将返回GetMessage(退出阻塞)。 有没有人能告诉我,当我在XWindows下使用XNextEvent等待事件时,如何在另一个线程中“唤醒”GUI线程。 我可以使用像PoseMessage这样的API吗?