disp_x11.cpp
2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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);
}
}