简体   繁体   English

Xlib - 窗口未呈现

[英]Xlib - window is not rendering

I am creating library for Xlib (like gtk/qt, but simplified).我正在为 Xlib 创建库(如 gtk/qt,但已简化)。 And i don't see window at my desktop.而且我在桌面上看不到窗口。 GDB says nothing. GDB 什么也没说。 What i must do to fix this bug?我必须做些什么来修复这个错误? Already tried to move display declaration to main function.已尝试将显示声明移至主函数。 Used -g flag as compiling (to check with GDB).使用 -g 标志作为编译(检查 GDB)。 And no window!而且没有窗户! Seriously, it's awesome glitch!说真的,这是一个很棒的故障!

FXL++ library: FXL++ 库:

#include <iostream>
#include <X11/Xlib.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h> 
using namespace std;

class fxlpp{
public:
    void init(){
        disp = XOpenDisplay(NULL);

        if(disp == NULL){ //error 1 if can't open display
            cerr << "Can't open display" << endl;
            exit(1);
        }

        screen = DefaultScreen(disp);
    }
    void mkWin(int winID, int x1, int y1, unsigned x2, unsigned y2){
        win[winID] = XCreateSimpleWindow(disp, RootWindow(disp, screen), x1, y1, x2, y2, 0, BlackPixel(disp, screen), WhitePixel(disp, screen));
        XSelectInput(disp, win[winID], ExposureMask | KeyPressMask);
        XMapWindow(disp, win[winID]);
    }
    void mkCWin(int cWinID, int pWinID, int x1, int y1, int x2, int y2){
        cWin[pWinID][cWinID] = XCreateSimpleWindow(disp, win[pWinID], x1, y1, x2, y2, 1, BlackPixel(disp, screen), WhitePixel(disp, screen));
        XSelectInput(disp, cWin[pWinID][cWinID], ExposureMask | KeyPressMask);
        XMapWindow(disp, cWin[pWinID][cWinID]);
    }

protected:
    Display *disp; //declare display pointer
    int screen; //declare display num integer
    Window win[129]; //declare window
    Window cWin[129][129]; //declare child win array
    XEvent event; //declare event handler
};

Code to test library:测试库的代码:

#include <iostream>
#include "fxlpp.hpp"
using namespace std;

int main(){
    class fxlpp fxlpp;
    fxlpp.init();
    fxlpp.mkWin(1, 100, 100, 500, 300);
    sleep(2);
    return 0;
}

As I wrote before , there's a lot more to X11 than just create a window, paint some lines on it and expect output.正如我之前所写的,X11 不仅仅是创建一个窗口,在其上绘制一些线条并期望输出。 You must setup the X event loop to receive events, handle at a minumum exposure events, but also keyboard, mouse, etc. in the proper way.您必须设置 X 事件循环来接收事件,以正确的方式处理最少的曝光事件,以及键盘、鼠标等。 So I'm afraid it's not a bug, it's a design flaw in your program.所以恐怕这不是错误,而是您程序中的设计缺陷。

For a short tutorial, see here .有关简短教程,请参见此处

尽管事件循环在大多数情况下都很重要,但在这种简单的情况下,您只需要在绘制后调用XFlush()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM