1:我想有一个闪屏但我只有一个窗口?那么,如何处理sth like parm
2:我已经用了一段时间(!完成)来绘制窗口,所以如何用函数或其他东西打破
这是我的代码,非常感谢你
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);
}