在被Xlib​​闪屏如何绘制字符串 [英] How a draw a string in a splash screen by Xlib

查看:197
本文介绍了在被Xlib​​闪屏如何绘制字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code,我不能跳出一段时间(!完成)功能

使用XFlush(D)可以在显示屏上显示的形式缓冲区XCloseDisplay之前不会消失(D)

和我要让拉绳像

G ++ -o youname youcppname -lX11

 的#include< X11 / Xlib.h>
#包括LT&; X11 / Xatom.h>
#包括LT&;&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#包括LT&;&string.h中GT;
#包括LT&;&unistd.h中GT;INT主要(无效)
{
    显示* D;
    窗W;
    XEventê;
    为const char *味精=你好,世界!
    int类型;
    布尔做= FALSE;    / *与服务器打开的连接* /
    D = XOpenDisplay(NULL);
    如果(D == NULL)
    {
        fprintf中(标准错误,无法打开显示屏\\ n);
        出口(1);
    }
    S = DefaultScreen(四);    / *创建窗口* /
    W = XCreateSimpleWindow(D,RootWindow(D,S),10,10,480,320,0,BlackPixel(D,S),WhitePixel(D,S));
    原子类型= XInternAtom(四,_ NET_WM_WINDOW_TYPE,FALSE);
    原子值= XInternAtom(四,_ NET_WM_WINDOW_TYPE_SPLASH,FALSE);
    XChangeProperty(D,W,类型,XA_ATOM,32,PropModeReplace,reinter pret_cast<无符号字符*>(安培;值),1);
    / *在删除窗口消息注册兴趣* /
    原子wmDeleteMessage = XInternAtom(DWM_DELETE_WINDOW,FALSE);
    XSetWMProtocols(D,W,&放大器; wmDeleteMessage,1);    / *选择类型的事件,我们感兴趣的是* /
    XSelectInput(D,W,ExposureMask |重点pressMask | StructureNotifyMask);    / *映射(显示)窗口* /
    XMapWindow(D,w)的;
    / *事件循环* /
    而(!完成)
    {
        XNextEvent例行(D,急症室);
        / *绘制或重绘窗口* /
        如果(e.type ==暴露)
        {
            XDrawString(D,W,DefaultGC(D,S),50,50,味精,strlen的(MSG));
        }        / *关键preSS退出* /
        开关(e.type)
        {
        案例重点preSS:
            XDestroyWindow(D,w)的;        打破;        案例DestroyNotify:
            做= TRUE;
        打破;        案例ClientMessage:
            如果(e.xclient.data.l [0] == wmDeleteMessage)
            {
                做= TRUE;
            }
        打破;
        }
    }
    / *服务器关闭连接* /
    XCloseDisplay(四);    返回0;
}


解决方案

我真的不知道为什么XFlush没有工作,但是这是事件循环和冲洗的混合体。它等待揭露事件,绘制字符串,并退出循环。

5秒后它取消映射窗口便退出5秒更高版本。

 的#include< X11 / Xlib.h>
#包括LT&; X11 / Xatom.h>
#包括LT&;&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#包括LT&;&string.h中GT;
#包括LT&;&unistd.h中GT;INT主要(无效)
{
    显示* D;
    窗W;
    XEventê;
    为const char *味精=你好,世界!
    int类型;
    布尔做= FALSE;    / *与服务器打开的连接* /
    D = XOpenDisplay(NULL);
    如果(D == NULL)
    {
        fprintf中(标准错误,无法打开显示屏\\ n);
        出口(1);
    }
    S = DefaultScreen(四);    / *创建窗口* /
    W = XCreateSimpleWindow(D,RootWindow(D,S),10,10,480,320,0,BlackPixel(D,S),WhitePixel(D,S));
    原子类型= XInternAtom(四,_ NET_WM_WINDOW_TYPE,FALSE);
    原子值= XInternAtom(四,_ NET_WM_WINDOW_TYPE_SPLASH,FALSE);
    XChangeProperty(D,W,类型,XA_ATOM,32,PropModeReplace,reinter pret_cast<无符号字符*>(安培;值),1);
    / *在删除窗口消息注册兴趣* /
    原子wmDeleteMessage = XInternAtom(DWM_DELETE_WINDOW,FALSE);
    XSetWMProtocols(D,W,&放大器; wmDeleteMessage,1);    / *选择类型的事件,我们感兴趣的是* /
    XSelectInput(D,W,ExposureMask);    / *映射(显示)窗口* /
    XMapWindow(D,w)的;    / *事件循环* /
    而(!完成)
    {
        XNextEvent例行(D,急症室);
        / *绘制或重绘窗口* /
        如果(e.type ==暴露)
        {
            XDrawString(D,W,DefaultGC(D,S),50,50,味精,strlen的(MSG));
            做= TRUE;
        }
    }
    XFlush(四);
    睡眠(5);
    XUnmapWindow(D,w)的;
    XFlush(四);
    的printf(取消映射\\ n);
    睡眠(5);
    / *服务器关闭连接* /
    XCloseDisplay(四);    返回0;
}

here is my code and I can not jump out of the while(!done) function

use XFlush(d) can show the display form buffer and do not disappear before XCloseDisplay(d)

and I want to make draw string like that

g++ -o youname youcppname -lX11

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
    Display *d;
    Window w;
    XEvent e;
    const char *msg = "Hello, World!";
    int s;
    bool done = false;

    /* open connection with the server */
    d = XOpenDisplay(NULL);
    if (d == NULL)
    {
        fprintf(stderr, "Cannot open display\n");
        exit(1);
    }
    s = DefaultScreen(d);

    /* create window */
    w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 480, 320, 0,BlackPixel(d, s), WhitePixel(d, s));
    Atom type = XInternAtom(d,"_NET_WM_WINDOW_TYPE", False);
    Atom value = XInternAtom(d,"_NET_WM_WINDOW_TYPE_SPLASH", False);
    XChangeProperty(d, w, type, XA_ATOM, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&value), 1);
    /* register interest in the delete window message */
    Atom wmDeleteMessage = XInternAtom(d, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(d, w, &wmDeleteMessage, 1);

    /* select kind of events we are interested in */
    XSelectInput(d, w, ExposureMask | KeyPressMask | StructureNotifyMask);

    /* map (show) the window */
    XMapWindow(d, w);
    /* event loop */
    while (!done)
    {
        XNextEvent(d, &e);
        /* draw or redraw the window */
        if (e.type == Expose)
        {
            XDrawString(d, w, DefaultGC(d, s), 50, 50, msg, strlen(msg));
        }

        /* exit on key press */
        switch(e.type)
        {
        case KeyPress:
            XDestroyWindow(d, w);

        break;

        case DestroyNotify:
            done = true;
        break;

        case ClientMessage:
            if (e.xclient.data.l[0] == wmDeleteMessage)
            {
                done = true;
            }
        break;
        }
    }
    /* close connection to server */
    XCloseDisplay(d);

    return 0;
}

解决方案

I'm not really sure why XFlush didn't work, but this is a hybrid of the event loop and flush. It waits for the expose event, draws the string and exits the loop.

After 5 seconds it unmaps the window then exits 5 seconds later.

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
    Display *d;
    Window w;
    XEvent e;
    const char *msg = "Hello, World!";
    int s;
    bool done = false;

    /* open connection with the server */
    d = XOpenDisplay(NULL);
    if (d == NULL)
    {
        fprintf(stderr, "Cannot open display\n");
        exit(1);
    }
    s = DefaultScreen(d);

    /* create window */
    w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 480, 320, 0,BlackPixel(d, s), WhitePixel(d, s));
    Atom type = XInternAtom(d,"_NET_WM_WINDOW_TYPE", False);
    Atom value = XInternAtom(d,"_NET_WM_WINDOW_TYPE_SPLASH", False);
    XChangeProperty(d, w, type, XA_ATOM, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&value), 1);
    /* register interest in the delete window message */
    Atom wmDeleteMessage = XInternAtom(d, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(d, w, &wmDeleteMessage, 1);

    /* select kind of events we are interested in */
    XSelectInput(d, w, ExposureMask);

    /* map (show) the window */
    XMapWindow(d, w);

    /* event loop */
    while (!done)
    {
        XNextEvent(d, &e);
        /* draw or redraw the window */
        if (e.type == Expose)
        {
            XDrawString(d, w, DefaultGC(d, s), 50, 50, msg, strlen(msg));
            done = true;
        }
    }
    XFlush(d);
    sleep(5);
    XUnmapWindow(d,w);
    XFlush(d);
    printf("unmapped\n");
    sleep(5);
    /* close connection to server */
    XCloseDisplay(d);

    return 0;
}

这篇关于在被Xlib​​闪屏如何绘制字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆