Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 58 lines (47 sloc) 1.186 kB
e2ac788 @keithw Initial import of Ahab 0.1
authored
1 #include <pthread.h>
2 #include <signal.h>
3 #include <stdio.h>
2631b35 @keithw xevents now handles repaints directly, can advance frames in display win
authored
4 #include <X11/Xlib.h>
e2ac788 @keithw Initial import of Ahab 0.1
authored
5
6 #include "exceptions.hpp"
7 #include "xeventloop.hpp"
8
9 static void *thread_helper( void *xeventloop )
10 {
11 XEventLoop *me = static_cast<XEventLoop *>( xeventloop );
12 ahabassert( me );
13 me->loop();
14 return NULL;
15 }
16
17 XEventLoop::XEventLoop( OpenGLDisplay *s_display )
2631b35 @keithw xevents now handles repaints directly, can advance frames in display win
authored
18 : keys( 0 ),
19 repaints( 0 ),
e2ac788 @keithw Initial import of Ahab 0.1
authored
20 display( s_display ),
21 live( true )
22 {
23 unixassert( pthread_mutex_init( &mutex, NULL ) );
24 pthread_create( &thread_handle, NULL, thread_helper, this );
25 }
26
27 void XEventLoop::loop( void )
28 {
2631b35 @keithw xevents now handles repaints directly, can advance frames in display win
authored
29 XEvent ev;
30 XExposeEvent *expose = (XExposeEvent *)&ev;
31 XKeyEvent *key = (XKeyEvent *)&ev;
32
e2ac788 @keithw Initial import of Ahab 0.1
authored
33 while ( 1 ) {
2631b35 @keithw xevents now handles repaints directly, can advance frames in display win
authored
34 display->getevent( true, &ev );
e2ac788 @keithw Initial import of Ahab 0.1
authored
35
2631b35 @keithw xevents now handles repaints directly, can advance frames in display win
authored
36 { MutexLock x( &mutex ); if ( !live ) return; }
e2ac788 @keithw Initial import of Ahab 0.1
authored
37
2631b35 @keithw xevents now handles repaints directly, can advance frames in display win
authored
38 if ( ev.type == Expose && expose->count == 0 ) {
39 repaints.enqueue( new Repaint() );
40 } else if ( ev.type == KeyPress ) {
41 KeySym keysym = XLookupKeysym( key, 0 );
42 keys.enqueue( new XKey( keysym ) );
e2ac788 @keithw Initial import of Ahab 0.1
authored
43 }
44 }
45 }
46
47 XEventLoop::~XEventLoop()
48 {
49 {
50 MutexLock x( &mutex );
51 live = false;
52 }
53
54 display->makeevent();
55
56 pthread_join( thread_handle, NULL );
57 }
Something went wrong with that request. Please try again.