blob: 795e2ad7ba5f8ebe81ddb3723fe9847ba9727591 [file] [log] [blame]
scroggob7e9aee2011-03-15 15:15:15 +00001#include "X11/Xlib.h"
2#include "X11/keysym.h"
3
4#include "SkApplication.h"
Scroggo9df214e2011-04-15 14:48:08 +00005#include "SkEvent.h"
scroggob7e9aee2011-03-15 15:15:15 +00006#include "SkWindow.h"
scroggob7e9aee2011-03-15 15:15:15 +00007#include "SkTypes.h"
Scroggo9df214e2011-04-15 14:48:08 +00008
Scroggo5a234242011-06-13 19:17:58 +00009#include <signal.h>
10#include <sys/time.h>
scroggob7e9aee2011-03-15 15:15:15 +000011
Scroggo9df214e2011-04-15 14:48:08 +000012SkOSWindow* gWindow;
scroggob7e9aee2011-03-15 15:15:15 +000013
scroggob7e9aee2011-03-15 15:15:15 +000014static void catch_alarm(int sig)
15{
scroggob7e9aee2011-03-15 15:15:15 +000016 SkEvent::ServiceQueueTimer();
17}
scroggob7e9aee2011-03-15 15:15:15 +000018
senorblanco@chromium.org78b82532011-06-28 19:44:03 +000019int main(int argc, char** argv){
Scroggo5a234242011-06-13 19:17:58 +000020 signal(SIGALRM, catch_alarm);
scroggob7e9aee2011-03-15 15:15:15 +000021
senorblanco@chromium.org78b82532011-06-28 19:44:03 +000022 gWindow = create_sk_window(NULL, argc, argv);
bsalomon@google.com098e96d2011-07-14 14:30:46 +000023
24 // drain any events that occurred before gWindow was assigned.
25 while (SkEvent::ProcessEvent());
26
scroggob7e9aee2011-03-15 15:15:15 +000027 // Start normal Skia sequence
28 application_init();
29
Scroggo9df214e2011-04-15 14:48:08 +000030 gWindow->loop();
scroggob7e9aee2011-03-15 15:15:15 +000031
Scroggo62b65b02011-06-21 16:01:26 +000032 delete gWindow;
scroggob7e9aee2011-03-15 15:15:15 +000033 application_term();
34 return 0;
35}
36
37// SkEvent handlers
38
39void SkEvent::SignalNonEmptyQueue()
40{
bsalomon@google.com098e96d2011-07-14 14:30:46 +000041 if (gWindow) {
Scroggo9df214e2011-04-15 14:48:08 +000042 gWindow->post_linuxevent();
bsalomon@google.com098e96d2011-07-14 14:30:46 +000043 }
scroggob7e9aee2011-03-15 15:15:15 +000044}
45
46void SkEvent::SignalQueueTimer(SkMSec delay)
47{
scroggob7e9aee2011-03-15 15:15:15 +000048 itimerval newTimer;
49 newTimer.it_interval.tv_sec = 0;
50 newTimer.it_interval.tv_usec = 0;
51 newTimer.it_value.tv_sec = 0;
52 newTimer.it_value.tv_usec = delay * 1000;
Scroggo5a234242011-06-13 19:17:58 +000053
54 setitimer(ITIMER_REAL, &newTimer, NULL);
scroggob7e9aee2011-03-15 15:15:15 +000055}