我想使启动画面,现在我有两个问题? [英] I want to make splash screen and now I have two problems?

查看:213
本文介绍了我想使启动画面,现在我有两个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1:我想有一个闪屏,但我只有一个窗口,这样,该怎么办像PARM某事

2:我已经使用了一段时间(!完成)来绘制窗口因此如何摆脱与函数或者某事

这是我的code和THX很多对你

G ++ -o m_splash m_splash.cpp -lX11 -lImlib2

 的#include<&stdio.h中GT;
#包括LT&; X11 / Xlib.h>
#包括LT&;&Imlib2.h GT;
#包括LT&;&unistd.h中GT;诠释的main()
{
    Imlib_Image m_img;
    显示* m_dpy;
    像素图m_pix;
    窗口m_root;
    屏幕* SCN;
    INT m_width,m_height;
    为const char *文件名=/home/ang/so_zt/w.png;    m_img = imlib_load_image(文件名);
    如果(!m_img)
    {
        的printf(%S \\ n,初始化m_img faild);
    }
    imlib_context_set_image(m_img);
    m_width = imlib_image_get_width();
    m_height = imlib_image_get_height();    m_dpy = XOpenDisplay(NULL);
    如果(!m_dpy)
    {
        的printf(%S \\ n,开放式陈列失败);
    }
    SCN = DefaultScreenOfDisplay(m_dpy);
    INT S = DefaultScreen(m_dpy);
    m_root = XCreateSimpleWindow(m_dpy,RootWindow(m_dpy,S),10,10,m_width,m_height,0,
                                 BlackPixel(m_dpy,S),WhitePixel(m_dpy,S));
    m_pix = XCreatePixmap(m_dpy,m_root,m_width,m_height,DefaultDepthOfScreen(SCN));    imlib_context_set_display(m_dpy);
    imlib_context_set_visual(DefaultVisu​​alOfScreen(SCN));
    imlib_context_set_colormap(DefaultColormapOfScreen(SCN));
    imlib_context_set_drawable(m_pix);    imlib_render_image_on_drawable(0,0);
    XSetWindowBackgroundPixmap(m_dpy,m_root,m_pix);
    XClearWindow(m_dpy,m_root);
    原子wmDeleteMessage = XInternAtom(m_dpy,WM_DELETE_WINDOW,FALSE);
    XSetWMProtocols(m_dpy,m_root,&放大器; wmDeleteMessage,1);    XSelectInput(m_dpy,m_root,ExposureMask |重点pressMask | StructureNotifyMask);
    XMapWindow(m_dpy,m_root);
    布尔做= FALSE;
    而(!完成)
    {
        XEvent m_ev;
        XNextEvent例行(m_dpy,&安培; m_ev);
        / *绘制或重绘窗口* /
        如果(m_ev.type ==暴露)
        {
            XFillRectangle(m_dpy,m_root,DefaultGC(m_dpy,DefaultScreen(m_dpy)),20,20,10,10);
        }    / *关键preSS退出* /
        // usleep(1000000);
        //做= TRUE;
        开关(m_ev.type)
        {
        案例重点preSS:
            XDestroyWindow(m_dpy,m_root);
        打破;        案例DestroyNotify:
            做= TRUE;
        打破;
        案例ClientMessage:
            如果(m_ev.xclient.data.l [0] == wmDeleteMessage)
            {
                做= TRUE;
            }
        打破;
        }
    }    // XFreePixmap(m_dpy,m_pix);
    // imlib_free_image();
    // XCloseDisplay(m_dpy);
}


解决方案

要使它成为一个闪屏,使用扩展窗口管理器提示。

 的#include< X11 / Xatom.h>原子类型= XInternAtom(m_dpy,_NET_WM_WINDOW_TYPE,FALSE);
原子值= XInternAtom(m_dpy,_NET_WM_WINDOW_TYPE_SPLASH,FALSE);
XChangeProperty(m_dpy,m_root,类型,XA_ATOM,32,PropModeReplace,reinter pret_cast<无符号字符*>(安培;值),1);

窗口出现时将不会装饰品和保持,直到点击。

当点击你得到一个 UnmapNotify 事件,所以这个你应该用什么来设置完成。

要避免让事件中,添加

  XFlush(m_dpy);

映射窗口后显示它以及

  XUnmapWindow(m_dpy,m_root);

当你想摆脱它。

在这个例子中,程序只是休眠5秒,然后再继续

 的#include<&stdio.h中GT;
#包括LT&; X11 / Xlib.h>
#包括LT&; X11 / Xatom.h>
#包括LT&;&Imlib2.h GT;
#包括LT&;&unistd.h中GT;诠释的main()
{
    Imlib_Image m_img;
    显示* m_dpy;
    像素图m_pix;
    窗口m_root;
    屏幕* SCN;
    INT m_width,m_height;
    为const char *文件名=w.png;    m_img = imlib_load_image(文件名);
    如果(!m_img)
    {
        的printf(%S \\ n,初始化m_img faild);
    }
    imlib_context_set_image(m_img);
    m_width = imlib_image_get_width();
    m_height = imlib_image_get_height();    m_dpy = XOpenDisplay(NULL);
    如果(!m_dpy)
    {
        的printf(%S \\ n,开放式陈列失败);
    }
    SCN = DefaultScreenOfDisplay(m_dpy);
    INT S = DefaultScreen(m_dpy);
    m_root = XCreateSimpleWindow(m_dpy,RootWindow(m_dpy,S),10,10,m_width,m_height,0,
                                 BlackPixel(m_dpy,S),WhitePixel(m_dpy,S));
    m_pix = XCreatePixmap(m_dpy,m_root,m_width,m_height,DefaultDepthOfScreen(SCN));    原子类型= XInternAtom(m_dpy,_NET_WM_WINDOW_TYPE,FALSE);
    原子值= XInternAtom(m_dpy,_NET_WM_WINDOW_TYPE_SPLASH,FALSE);
    XChangeProperty(m_dpy,m_root,类型,XA_ATOM,32,PropModeReplace,reinter pret_cast<无符号字符*>(安培;值),1);    imlib_context_set_display(m_dpy);
    imlib_context_set_visual(DefaultVisu​​alOfScreen(SCN));
    imlib_context_set_colormap(DefaultColormapOfScreen(SCN));
    imlib_context_set_drawable(m_pix);    imlib_render_image_on_drawable(0,0);
    XSetWindowBackgroundPixmap(m_dpy,m_root,m_pix);
    XClearWindow(m_dpy,m_root);
    原子wmDeleteMessage = XInternAtom(m_dpy,WM_DELETE_WINDOW,FALSE);
    XSetWMProtocols(m_dpy,m_root,&放大器; wmDeleteMessage,1);    XMapWindow(m_dpy,m_root);
    XFlush(m_dpy);
    睡眠(5);
    XUnmapWindow(m_dpy,m_root);
}

1: I want to have a splash screen but I only have a window?so,how to do with sth like parm

2: I've used a while(!done) to draw the window so how to break out with a function or sth else

here is my code and much thx to you

g++ -o m_splash m_splash.cpp -lX11 -lImlib2

#include <stdio.h>
#include <X11/Xlib.h>
#include <Imlib2.h>
#include <unistd.h>

int main()
{
    Imlib_Image  m_img;
    Display     *m_dpy;
    Pixmap       m_pix;
    Window       m_root;
    Screen      *scn;
    int m_width, m_height;
    const char *filename = "/home/ang/so_zt/w.png";

    m_img = imlib_load_image(filename);
    if(!m_img)
    {
        printf("%s\n","init m_img faild");
    }
    imlib_context_set_image(m_img);
    m_width = imlib_image_get_width();
    m_height = imlib_image_get_height();

    m_dpy = XOpenDisplay(NULL);
    if(!m_dpy)
    {
        printf("%s\n","open display failed");
    }
    scn = DefaultScreenOfDisplay(m_dpy);
    int s = DefaultScreen(m_dpy);
    m_root = XCreateSimpleWindow(m_dpy, RootWindow(m_dpy,s),10,10,m_width,m_height,0,
                                 BlackPixel(m_dpy, s), WhitePixel(m_dpy, s));
    m_pix = XCreatePixmap(m_dpy, m_root, m_width, m_height, DefaultDepthOfScreen(scn));

    imlib_context_set_display(m_dpy);
    imlib_context_set_visual(DefaultVisualOfScreen(scn));
    imlib_context_set_colormap(DefaultColormapOfScreen(scn));
    imlib_context_set_drawable(m_pix);

    imlib_render_image_on_drawable(0,0);
    XSetWindowBackgroundPixmap(m_dpy, m_root, m_pix);
    XClearWindow(m_dpy, m_root);
    Atom wmDeleteMessage = XInternAtom(m_dpy, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(m_dpy, m_root, &wmDeleteMessage, 1);

    XSelectInput(m_dpy, m_root, ExposureMask | KeyPressMask | StructureNotifyMask);
    XMapWindow(m_dpy, m_root);
    bool done = false;
    while (!done)
    {
        XEvent m_ev;
        XNextEvent(m_dpy, &m_ev);
        /* draw or redraw the window */
        if (m_ev.type == Expose)
        {
            XFillRectangle(m_dpy, m_root, DefaultGC(m_dpy, DefaultScreen(m_dpy)), 20, 20, 10, 10);
        }

    /* exit on key press */
        //usleep(1000000);
        //done = true;
        switch(m_ev.type)
        {
        case KeyPress:
            XDestroyWindow(m_dpy, m_root);
        break;

        case DestroyNotify:
            done = true;
        break;
        case ClientMessage:
            if (m_ev.xclient.data.l[0] == wmDeleteMessage)
            {
                done = true;
            }
        break;
        }
    }

    //XFreePixmap(m_dpy, m_pix);
    //imlib_free_image();
    //XCloseDisplay(m_dpy);
}

解决方案

To make it a splash screen, use extended window manager hints.

#include <X11/Xatom.h>

Atom type = XInternAtom(m_dpy, "_NET_WM_WINDOW_TYPE", False);
Atom value = XInternAtom(m_dpy, "_NET_WM_WINDOW_TYPE_SPLASH", False);
XChangeProperty(m_dpy, m_root, type, XA_ATOM, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&value), 1);

The window then appears without decorations and stays until clicked.

When clicked you get an UnmapNotify event, so this what you should use to set done.

To avoid having to get events, add

XFlush(m_dpy);

after mapping the window to display it and

XUnmapWindow(m_dpy, m_root);

when you want to get rid of it.

In this example the program just sleeps for 5 seconds before continuing:

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

int main()
{
    Imlib_Image  m_img;
    Display     *m_dpy;
    Pixmap       m_pix;
    Window       m_root;
    Screen      *scn;
    int m_width, m_height;
    const char *filename = "w.png";

    m_img = imlib_load_image(filename);
    if(!m_img)
    {
        printf("%s\n","init m_img faild");
    }
    imlib_context_set_image(m_img);
    m_width = imlib_image_get_width();
    m_height = imlib_image_get_height();

    m_dpy = XOpenDisplay(NULL);
    if(!m_dpy)
    {
        printf("%s\n","open display failed");
    }
    scn = DefaultScreenOfDisplay(m_dpy);
    int s = DefaultScreen(m_dpy);
    m_root = XCreateSimpleWindow(m_dpy, RootWindow(m_dpy,s),10,10,m_width,m_height,0,
                                 BlackPixel(m_dpy, s), WhitePixel(m_dpy, s));
    m_pix = XCreatePixmap(m_dpy, m_root, m_width, m_height, DefaultDepthOfScreen(scn));

    Atom type = XInternAtom(m_dpy, "_NET_WM_WINDOW_TYPE", False);
    Atom value = XInternAtom(m_dpy, "_NET_WM_WINDOW_TYPE_SPLASH", False);
    XChangeProperty(m_dpy, m_root, type, XA_ATOM, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&value), 1);

    imlib_context_set_display(m_dpy);
    imlib_context_set_visual(DefaultVisualOfScreen(scn));
    imlib_context_set_colormap(DefaultColormapOfScreen(scn));
    imlib_context_set_drawable(m_pix);

    imlib_render_image_on_drawable(0,0);
    XSetWindowBackgroundPixmap(m_dpy, m_root, m_pix);
    XClearWindow(m_dpy, m_root);
    Atom wmDeleteMessage = XInternAtom(m_dpy, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(m_dpy, m_root, &wmDeleteMessage, 1);

    XMapWindow(m_dpy, m_root);
    XFlush(m_dpy);
    sleep(5);
    XUnmapWindow(m_dpy, m_root);
}

这篇关于我想使启动画面,现在我有两个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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