epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 1 | |
2 | /* | ||||
3 | * Copyright 2011 Google Inc. | ||||
4 | * | ||||
5 | * Use of this source code is governed by a BSD-style license that can be | ||||
6 | * found in the LICENSE file. | ||||
7 | */ | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 8 | #include "X11/Xlib.h" |
9 | #include "X11/keysym.h" | ||||
10 | |||||
11 | #include "SkApplication.h" | ||||
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 12 | #include "SkEvent.h" |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 13 | #include "SkWindow.h" |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 14 | #include "SkTypes.h" |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 15 | |
Scroggo | 5a23424 | 2011-06-13 19:17:58 +0000 | [diff] [blame] | 16 | #include <signal.h> |
17 | #include <sys/time.h> | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 18 | |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 19 | SkOSWindow* gWindow; |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 20 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 21 | static void catch_alarm(int sig) |
22 | { | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 23 | SkEvent::ServiceQueueTimer(); |
24 | } | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 25 | |
senorblanco@chromium.org | 78b8253 | 2011-06-28 19:44:03 +0000 | [diff] [blame] | 26 | int main(int argc, char** argv){ |
Scroggo | 5a23424 | 2011-06-13 19:17:58 +0000 | [diff] [blame] | 27 | signal(SIGALRM, catch_alarm); |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 28 | |
senorblanco@chromium.org | 78b8253 | 2011-06-28 19:44:03 +0000 | [diff] [blame] | 29 | gWindow = create_sk_window(NULL, argc, argv); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 30 | |
31 | // drain any events that occurred before gWindow was assigned. | ||||
32 | while (SkEvent::ProcessEvent()); | ||||
33 | |||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 34 | // Start normal Skia sequence |
35 | application_init(); | ||||
36 | |||||
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 37 | gWindow->loop(); |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 38 | |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 39 | delete gWindow; |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 40 | application_term(); |
41 | return 0; | ||||
42 | } | ||||
43 | |||||
44 | // SkEvent handlers | ||||
45 | |||||
46 | void SkEvent::SignalNonEmptyQueue() | ||||
47 | { | ||||
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 48 | if (gWindow) { |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 49 | gWindow->post_linuxevent(); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 50 | } |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 51 | } |
52 | |||||
53 | void SkEvent::SignalQueueTimer(SkMSec delay) | ||||
54 | { | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 55 | itimerval newTimer; |
56 | newTimer.it_interval.tv_sec = 0; | ||||
57 | newTimer.it_interval.tv_usec = 0; | ||||
58 | newTimer.it_value.tv_sec = 0; | ||||
59 | newTimer.it_value.tv_usec = delay * 1000; | ||||
Scroggo | 5a23424 | 2011-06-13 19:17:58 +0000 | [diff] [blame] | 60 | |
61 | setitimer(ITIMER_REAL, &newTimer, NULL); | ||||
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 62 | } |