pointer motion. why are numbers so high? why does it print info in blocks not a constant stream?

主宰稳场 提交于 2019-12-20 04:43:11

问题


Hi! I am trying to write a program where I need to report the position of every mouse motion. I have called the XSelectInput() function with a PointerMotionMask mask. Everything seems to work alright but the numbers after printing don't appear after every movement, they appear in blocks and also the numbers in event.xmotion.x and event.xmotion.y are very high, in the hundred thousands.
What is causing these large numbers?
Also is my program getting every number and reporting it immediately or is it being stored in a queue and sent in blocks to the terminal?
Thanks

Here's my event loop:

while(1)
    {
        XNextEvent(display, &event);
        switch (event.type)
        {
            case Expose: 
                glClearColor( 1.0, 1.0, 0.0, 1.0 );
                    glClear( GL_COLOR_BUFFER_BIT );
                    glFlush();
                    glXSwapBuffers( display, glxwin );              
                break;
            case MotionNotify:
                printf("%d, %d", event.xmotion.x, event.xmotion.y);
                break;
            case ButtonPress: exit(1);
            default: break;     
        }   
    }

回答1:


Besides printing a newline at the end, you could also do a '\r' at the end it it will move the cursor to the beginning of the existing line, so it will just print over itself each time. To make this work better, change the digit formatting to be a fixed size, like:

printf("%4d, %4d  \r", event.xmotion.x, event.xmotion.y);
fflush(stdout) ;


来源:https://stackoverflow.com/questions/21241311/pointer-motion-why-are-numbers-so-high-why-does-it-print-info-in-blocks-not-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!