blob: 108e9ac20688e05ccdfe278990b0ba4d50d2f0b5 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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 */
scroggob7e9aee2011-03-15 15:15:15 +00008#include "X11/Xlib.h"
9#include "X11/keysym.h"
10
11#include "SkApplication.h"
Scroggo9df214e2011-04-15 14:48:08 +000012#include "SkEvent.h"
scroggob7e9aee2011-03-15 15:15:15 +000013#include "SkWindow.h"
scroggob7e9aee2011-03-15 15:15:15 +000014#include "SkTypes.h"
Scroggo9df214e2011-04-15 14:48:08 +000015
Scroggo5a234242011-06-13 19:17:58 +000016#include <signal.h>
17#include <sys/time.h>
scroggob7e9aee2011-03-15 15:15:15 +000018
Scroggo9df214e2011-04-15 14:48:08 +000019SkOSWindow* gWindow;
scroggob7e9aee2011-03-15 15:15:15 +000020
scroggob7e9aee2011-03-15 15:15:15 +000021static void catch_alarm(int sig)
22{
scroggob7e9aee2011-03-15 15:15:15 +000023 SkEvent::ServiceQueueTimer();
24}
scroggob7e9aee2011-03-15 15:15:15 +000025
senorblanco@chromium.org78b82532011-06-28 19:44:03 +000026int main(int argc, char** argv){
Scroggo5a234242011-06-13 19:17:58 +000027 signal(SIGALRM, catch_alarm);
scroggob7e9aee2011-03-15 15:15:15 +000028
senorblanco@chromium.org78b82532011-06-28 19:44:03 +000029 gWindow = create_sk_window(NULL, argc, argv);
bsalomon@google.com098e96d2011-07-14 14:30:46 +000030
31 // drain any events that occurred before gWindow was assigned.
32 while (SkEvent::ProcessEvent());
33
scroggob7e9aee2011-03-15 15:15:15 +000034 // Start normal Skia sequence
35 application_init();
36
Scroggo9df214e2011-04-15 14:48:08 +000037 gWindow->loop();
scroggob7e9aee2011-03-15 15:15:15 +000038
Scroggo62b65b02011-06-21 16:01:26 +000039 delete gWindow;
scroggob7e9aee2011-03-15 15:15:15 +000040 application_term();
41 return 0;
42}
43
44// SkEvent handlers
45
46void SkEvent::SignalNonEmptyQueue()
47{
bsalomon@google.com098e96d2011-07-14 14:30:46 +000048 if (gWindow) {
Scroggo9df214e2011-04-15 14:48:08 +000049 gWindow->post_linuxevent();
bsalomon@google.com098e96d2011-07-14 14:30:46 +000050 }
scroggob7e9aee2011-03-15 15:15:15 +000051}
52
53void SkEvent::SignalQueueTimer(SkMSec delay)
54{
scroggob7e9aee2011-03-15 15:15:15 +000055 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;
Scroggo5a234242011-06-13 19:17:58 +000060
61 setitimer(ITIMER_REAL, &newTimer, NULL);
scroggob7e9aee2011-03-15 15:15:15 +000062}