Tom199818 2015-09-26 04:13 采纳率: 0%
浏览 2162

XLIB的XSendEvent无效问题

 #include <X11/Xlib.h>

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <signal.h>

#include <time.h>

#include <sys/time.h>

 int x=10,y=10;
 struct _XDisplay *d;
 int s;
 Window w;
 XEvent e;

void sigroutine(int signo){

    /* send event */
    XSendEvent(d, w, 1, ExposureMask, &e);
    printf("Catch a signal -- SIGALRM \n");
    signal(SIGALRM, sigroutine);
    return;
}

int main()
{
        struct itimerval value, ovalue;
        /* open connection with the server */
        d = XOpenDisplay(NULL);
        if(d == NULL)
        {
                printf("Cannot open display\n");
                exit(1);
        }
        s = DefaultScreen(d);

        /* create window */
        w = XCreateSimpleWindow(d,
                                RootWindow(d, s),
                                10,
                                10,
                                500,
                                500,
                                1,
                                BlackPixel(d, s),
                                WhitePixel(d, s));

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

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

        /* Set timer */
        signal(SIGALRM, sigroutine);

        value.it_value.tv_sec = 1;

        value.it_value.tv_usec = 0;

        value.it_interval.tv_sec = 1;

        value.it_interval.tv_usec = 0;

        setitimer(ITIMER_REAL, &value, &ovalue);

        /* event loop */
        while(1)
        {
                XNextEvent(d, &e);
                /* draw or redraw the window */
                if(e.type == Expose)
                {
                        printf("Expose \n");
                        XFillRectangle(d, w, DefaultGC(d, s), x, y, 10, 10);
                        x+=10;
                        y+=10;
                }
                /* exit on key press */
                if(e.type == KeyPress)

                       break;
        }

        /* close connection to server */
        XCloseDisplay(d);

        return 0;
}

代码如上,sigroutine函数可以正确执行,但是expose事件不能触发,求大神解决

  • 写回答

1条回答 默认 最新

  • devmiao 2015-09-26 15:52
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退