Beispiel #1
0
void XxWindow::HandleEvent (const XEvent &WinEvent)
{
    switch (WinEvent.type) {
    case ClientMessage:
        if (WinEvent.xclient.format == 32) {
            const long *l = WinEvent.xclient.data.l;
            if (*l == (long)GetWmDeleteWindow ()) OnDelete ();
        };
        break;
    case Expose:
        OnExpose
            ( WinEvent.xexpose.x
            , WinEvent.xexpose.y
            , WinEvent.xexpose.width
            , WinEvent.xexpose.height
            );
        break;
    case ButtonPress:
        OnButtonPress
            ( WinEvent.xbutton.button
            , WinEvent.xbutton.x
            , WinEvent.xbutton.y
            );
        break;
    case ButtonRelease:
        OnButtonRelease
            ( WinEvent.xbutton.button
            , WinEvent.xbutton.x
            , WinEvent.xbutton.y
            );
        break;
    case EnterNotify:
        OnEnterWindow
            ( WinEvent.xcrossing.x
            , WinEvent.xcrossing.y
            );
        break;
    case LeaveNotify:
        OnLeaveWindow
            ( WinEvent.xcrossing.x
            , WinEvent.xcrossing.y
            );
        break;
    case ResizeRequest:
        OnResize
            ( WinEvent.xresizerequest.width
            , WinEvent.xresizerequest.height
            );
        break;
    default:
        break;
    };
};
Beispiel #2
0
static void MsgLoop(Display* dpy, Window win, GC gc, XFontStruct* font)
{
    int running = 1;
    XEvent evt;
    Atom wm_quit = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
    XSelectInput(dpy, win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask | PointerMotionMask);
    XSetWMProtocols(dpy, win, &wm_quit, 1);
    while(running)
    {
        XNextEvent(dpy, &evt);
        switch(evt.type)
        {
            case Expose:
                if(evt.xexpose.count)
                    break;
                OnExpose(&evt.xexpose, gc, font);
                break;
                //    case ConfigureNotify:
                //      Resize(wnd, evt.xconfigure.width, evt.xconfigure.height);
                //      break;
            case KeyPress:
                OnKeyPress(&evt.xkey);
                break;
            case ButtonPress:
                OnButtonPress(&evt.xbutton);
                break;
            case MotionNotify:
                OnMotionNotify(&evt.xmotion);
                break;
            case ClientMessage:
                if(evt.xclient.data.l[0] != wm_quit)
                    continue;
                running = 0;
                break;
        }
    }
    //Stop receiving events
    XSelectInput(dpy, win, NoEventMask);
}
void CHardwareLayer::timerEvent(QTimerEvent *ev)
{
    if(ev->timerId()==timerKeyJoy)
    {
        struct input_event ev;
        //-F- Button check
        pollfd pollStruct = {fdKey,POLLIN,0};

        while(poll(&pollStruct,1,0))
        {
            if(read (fdKey, &ev, sizeof(ev))==sizeof(ev))
            {
                if(ev.value)
                {
                    OnButtonPress();
                    isButtonDown=true;
                }
                else
                {
                    OnButtonRelease();
                    isButtonDown=false;
                }
            }
        }

        //-F- Joystick check
        pollStruct.fd=fdJoy;

        while(poll(&pollStruct,1,0))
        {
            struct input_event ev;
            if(read (fdJoy, &ev, sizeof(ev))==sizeof(ev))
            {
                emit OnRotaryMoved(ev.value,isButtonDown);
            }
        }
    }
}