gpt4 book ai didi

c - 即使缓冲区已在 Xlib 中刷新,该行也未显示

转载 作者:行者123 更新时间:2023-11-30 15:32:51 25 4
gpt4 key购买 nike

/* Draw_Red_Line.c */

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>

Window Win;
Display *Dsp;
GC Gc;
XGCValues Gc_Values;
XEvent Event;
Colormap Color_Map;
XColor Screen_RGB, Exact_RGB;

unsigned int Win_Size;

int main (void)
{
/* Set window size */
Win_Size = 625;

/* Open a connection to the X server that controls a display */
Dsp = XOpenDisplay(NULL);

/* Create an unmapped subwindow of root window */
Win = XCreateWindow(Dsp, XDefaultRootWindow(Dsp), 0, 0, Win_Size, Win_Size, 0,
XDefaultDepth(Dsp, 0), InputOutput, CopyFromParent, 0, 0);

/* Map the window on the screen */
XMapWindow(Dsp, Win);

/* Wait until the window appears */
do
XNextEvent(Dsp, &Event);
while
(Event.type != MapNotify);

/* Draw a red line */
Color_Map = DefaultColormap(Dsp, DefaultScreen(Dsp));
XAllocNamedColor(Dsp, Color_Map, "Red", &Screen_RGB, &Exact_RGB);
Gc_Values.foreground = Screen_RGB.pixel;
Gc_Values.line_width = 1;
Gc = XCreateGC(Dsp, Win, GCForeground | GCLineWidth, &Gc_Values);
XDrawLine (Dsp, Win, Gc, 0, 0, 624, 624);
XFlush(Dsp);

/* Exit */
fprintf(stdout, "Exit the process");
return EXIT_SUCCESS;
}

我尝试在(Gnome-)终端中编译并运行它:

EXECUTABLENAME="Draw_Red_Line"
gcc "$EXECUTABLENAME.c" -o "$EXECUTABLENAME" -std=c99 -Wall -lX11
./"$EXECUTABLENAME"

GCC 未报告任何警告和错误。无论背景如何,红线都没有显示,甚至消息字符串“退出进程”也没有打印到标准输出(运行脚本的终端)。为什么?

最佳答案

您需要在 Expose 事件处理程序中包含绘图代码。调用 XDrawLine 后,可能的内容会以某种方式失效,因此不可见。如果您用以下代码替换 XFlush,一切都会按预期工作:

  //XFlush(Dsp);
XSelectInput(Dsp, Win, ExposureMask);
while(1) {
XDrawLine (Dsp, Win, Gc, 0, 0, 624, 624);
XNextEvent(Dsp, &Event);
}

关于c - 即使缓冲区已在 Xlib 中刷新,该行也未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23968756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com