scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 1 | #include "X11/Xlib.h" |
2 | #include "X11/keysym.h" | ||||
3 | |||||
4 | #include "SkApplication.h" | ||||
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 5 | #include "SkEvent.h" |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 6 | #include "SkWindow.h" |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 7 | #include "SkTypes.h" |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 8 | |
Scroggo | 5a23424 | 2011-06-13 19:17:58 +0000 | [diff] [blame] | 9 | #include <signal.h> |
10 | #include <sys/time.h> | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 11 | |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 12 | SkOSWindow* gWindow; |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 13 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 14 | static void catch_alarm(int sig) |
15 | { | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 16 | SkEvent::ServiceQueueTimer(); |
17 | } | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 18 | |
senorblanco@chromium.org | 78b8253 | 2011-06-28 19:44:03 +0000 | [diff] [blame] | 19 | int main(int argc, char** argv){ |
Scroggo | 5a23424 | 2011-06-13 19:17:58 +0000 | [diff] [blame] | 20 | signal(SIGALRM, catch_alarm); |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 21 | |
senorblanco@chromium.org | 78b8253 | 2011-06-28 19:44:03 +0000 | [diff] [blame] | 22 | gWindow = create_sk_window(NULL, argc, argv); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 23 | |
24 | // drain any events that occurred before gWindow was assigned. | ||||
25 | while (SkEvent::ProcessEvent()); | ||||
26 | |||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 27 | // Start normal Skia sequence |
28 | application_init(); | ||||
29 | |||||
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 30 | gWindow->loop(); |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 31 | |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 32 | delete gWindow; |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 33 | application_term(); |
34 | return 0; | ||||
35 | } | ||||
36 | |||||
37 | // SkEvent handlers | ||||
38 | |||||
39 | void SkEvent::SignalNonEmptyQueue() | ||||
40 | { | ||||
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 41 | if (gWindow) { |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 42 | gWindow->post_linuxevent(); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 43 | } |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 44 | } |
45 | |||||
46 | void SkEvent::SignalQueueTimer(SkMSec delay) | ||||
47 | { | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 48 | 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; | ||||
Scroggo | 5a23424 | 2011-06-13 19:17:58 +0000 | [diff] [blame] | 53 | |
54 | setitimer(ITIMER_REAL, &newTimer, NULL); | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 55 | } |