disp_x11.cpp 2.34 KB
using namespace std;

#include <cstdlib>
#include <iostream>

#include "disp_x11.h"

void disp_x11::go(void) {
    XEvent event;
    char ch;
    KeySym keysym;
    bool e_chk;

    canvas_x11* screen=(canvas_x11*)e_src;
    xwindow* win=screen->win;

    if(!halt_f)
        e_chk=XCheckWindowEvent(win->getxscr()->getxdisp()->getdisplay(), 
                                win->getwindow(), KeyPressMask|ExposureMask,
                                &event);
    else {
        e_chk=true;
        XWindowEvent(win->getxscr()->getxdisp()->getdisplay(), 
                     win->getwindow(), KeyPressMask|ExposureMask,
                     &event);
    }
    if(e_chk) {
        switch(event.type) {
            case KeyPress:
                XLookupString(&event.xkey, &ch, 1, &keysym, NULL);
                if(!cb[Key].is_null())
                    cb[Key](e_src, (void*)&ch);
                break;

            case Expose:
                if(event.xexpose.count==0) {
                    if(!cb[Draw].is_null()) {
                        //semop(working, &work, 1);
                        cb[Draw](e_src, (void*)&ch);
                        //semop(working, &no_work, 1);
                    }
                }
                break;
        }
    }
    else {
        if(!halt_f) {
            if(!cb[Idle].is_null()) {
                //semop(working, &work, 1);
                cb[Idle](e_src, NULL);
                //semop(working, &no_work, 1);
            }
        }
    }

    if(!halt_f)
        XSync(win->getxscr()->getxdisp()->getdisplay(), false);
}

void disp_x11::trigger_event(event ev) {
    canvas_x11* screen=(canvas_x11*)e_src;
    xwindow* win=screen->win;

    switch(ev) {
        case Draw:
            XEvent e;
            e.type = Expose;
            e.xexpose.send_event = true;
            e.xexpose.display = win->getxscr()->getxdisp()->getdisplay();
            e.xexpose.window = win->getwindow();
            e.xexpose.x = e.xexpose.y = 0;
            e.xexpose.width = e.xexpose.height = 0;
            e.xexpose.count = 0;

            XSendEvent(win->getxscr()->getxdisp()->getdisplay(),
                       win->getwindow(),
                       true,
                       ExposureMask,
                       &e);
            break;

        case Stop:
            if(!cb[Stop].is_null())
                cb[Stop](e_src, NULL);
    }
}