blob: 21de4d2fbc8ecbef7388fda0d3254f53baeb7c45 [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);
scroggob7e9aee2011-03-15 15:15:15 +000023 // Start normal Skia sequence
24 application_init();
25
Scroggo9df214e2011-04-15 14:48:08 +000026 gWindow->loop();
scroggob7e9aee2011-03-15 15:15:15 +000027
Scroggo62b65b02011-06-21 16:01:26 +000028 delete gWindow;
scroggob7e9aee2011-03-15 15:15:15 +000029 application_term();
30 return 0;
31}
32
33// SkEvent handlers
34
35void SkEvent::SignalNonEmptyQueue()
36{
Scroggo9df214e2011-04-15 14:48:08 +000037 if (gWindow)
38 gWindow->post_linuxevent();
39 else
40 while (SkEvent::ProcessEvent());
scroggob7e9aee2011-03-15 15:15:15 +000041}
42
43void SkEvent::SignalQueueTimer(SkMSec delay)
44{
scroggob7e9aee2011-03-15 15:15:15 +000045 itimerval newTimer;
46 newTimer.it_interval.tv_sec = 0;
47 newTimer.it_interval.tv_usec = 0;
48 newTimer.it_value.tv_sec = 0;
49 newTimer.it_value.tv_usec = delay * 1000;
Scroggo5a234242011-06-13 19:17:58 +000050
51 setitimer(ITIMER_REAL, &newTimer, NULL);
scroggob7e9aee2011-03-15 15:15:15 +000052}