等同于"Invalidate Rect". /"WM_PAINT";在X11中 [英] Equivalent of "Invalidate Rect" / "WM_PAINT" in X11
问题描述
我正在将一些代码从Windows移植到XLib.在Windows代码中,我可以通过调用InvalidateRect
然后处理相应的WM_PAINT
消息来强制重绘.但是,我在找出如何在X11/XLib中执行此操作时遇到了麻烦.我看到有一条Expose
消息,但不确定是否相同.
I'm Porting some code from Windows to XLib. In the windows code, I can force a redraw by calling InvalidateRect
and then handling the corresponding WM_PAINT
message. However, I am having trouble finding out how to do this in X11/XLib. I see there is an Expose
message but not sure if that is the same thing.
如果有关系,我需要执行此操作以强制窗口以特定帧速率渲染基于OpenGL的程序.
If it matters, I need to do this to force the window to render at a certain frame rate for an OpenGL based program.
推荐答案
您需要处理Expose事件. 本教程举例说明了如何处理Expose事件:>
You need to handle Expose events. This tutorial explains with an example how to handle Expose events :
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
/*Linux users will need to add -ldl to the Makefile to compile
*this example.
*/
Display *dis;
Window win;
XEvent report;
GC green_gc;
XColor green_col;
Colormap colormap;
/*
Try changing the green[] = below to a different color.
The color can also be from /usr/X11R6/lib/X11/rgb.txt, such as RoyalBlue4.
A # (number sign) is only needed when using hexadecimal colors.
*/
char green[] = "#00FF00";
int main() {
dis = XOpenDisplay(NULL);
win = XCreateSimpleWindow(dis, RootWindow(dis, 0), 1, 1, 500, 500, 0, BlackPixel (dis, 0), BlackPixel(dis, 0));
XMapWindow(dis, win);
colormap = DefaultColormap(dis, 0);
green_gc = XCreateGC(dis, win, 0, 0);
XParseColor(dis, colormap, green, &green_col);
XAllocColor(dis, colormap, &green_col);
XSetForeground(dis, green_gc, green_col.pixel);
XSelectInput(dis, win, ExposureMask | KeyPressMask | ButtonPressMask);
XDrawRectangle(dis, win, green_gc, 1, 1, 497, 497);
XDrawRectangle(dis, win, green_gc, 50, 50, 398, 398);
XFlush(dis);
while (1) {
XNextEvent(dis, &report);
switch (report.type) {
case Expose:
fprintf(stdout, "I have been exposed.\n");
XDrawRectangle(dis, win, green_gc, 1, 1, 497, 497);
XDrawRectangle(dis, win, green_gc, 50, 50, 398, 398);
XFlush(dis);
break;
case KeyPress:
/*Close the program if q is pressed.*/
if (XLookupKeysym(&report.xkey, 0) == XK_q) {
exit(0);
}
break;
}
}
return 0;
}
我可能误解了这个问题.如果要在应用程序中创建Expose事件,则可以创建并设置 expose事件,然后使用 XSendEvent 发送.
I may have misunderstood the question. If you want to create Expose events in your application, you can create and set expose event, and send it using XSendEvent.
这篇关于等同于"Invalidate Rect". /"WM_PAINT";在X11中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!