OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 #include "SkTHash.h" | 9 #include "SkTHash.h" |
10 #include "SDL.h" | |
10 #include "Timer.h" | 11 #include "Timer.h" |
11 #include "Window_mac.h" | 12 #include "Window_mac.h" |
12 #include "../Application.h" | 13 #include "../Application.h" |
13 | 14 |
14 using sk_app::Application; | 15 using sk_app::Application; |
15 | 16 |
16 int main(int argc, char**argv) { | 17 int main(int argc, char* argv[]) { |
17 #if 0 | 18 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) { |
18 // TODO: use Mac main loop | 19 SkDebugf("Could not initialize SDL!\n"); |
20 return 1; | |
21 } | |
19 | 22 |
20 Display* display = XOpenDisplay(nullptr); | 23 Application* app = Application::Create(argc, argv, nullptr); |
21 | 24 |
22 Application* app = Application::Create(argc, argv, (void*)display); | 25 SDL_Event event; |
23 | |
24 // Get the file descriptor for the X display | |
25 int x11_fd = ConnectionNumber(display); | |
26 fd_set in_fds; | |
27 | |
28 SkTHashSet<sk_app::Window_mac*> pendingWindows; | |
29 bool done = false; | 26 bool done = false; |
30 while (!done) { | 27 while (!done) { |
31 // Create a file description set containing x11_fd | 28 while (SDL_PollEvent(&event)) { |
32 FD_ZERO(&in_fds); | 29 switch (event.type) { |
33 FD_SET(x11_fd, &in_fds); | 30 // events handled by the windows |
31 case SDL_WINDOWEVENT: | |
32 case SDL_MOUSEMOTION: | |
33 case SDL_MOUSEBUTTONDOWN: | |
34 case SDL_MOUSEBUTTONUP: | |
35 case SDL_KEYDOWN: | |
36 case SDL_KEYUP: { | |
robertphillips
2016/08/03 21:22:05
overlength ?
jvanverth1
2016/08/04 15:28:33
Done.
| |
37 sk_app::Window_mac* win = sk_app::Window_mac::gWindowMap.fin d(event.window.windowID); | |
38 if (win && win->handleEvent(event)) { | |
39 done = true; | |
40 } | |
41 } break; | |
42 | |
43 case SDL_QUIT: | |
44 done = true; | |
45 break; | |
46 | |
47 default: | |
48 break; | |
49 } | |
50 } | |
34 | 51 |
35 // Set a sleep timer | 52 app->onIdle(); |
36 struct timeval tv; | |
37 tv.tv_usec = 100; | |
38 tv.tv_sec = 0; | |
39 | |
40 // Wait for an event on the file descriptor or for timer expiration | |
41 (void) select(1, &in_fds, NULL, NULL, &tv); | |
42 | |
43 // Handle XEvents (if any) and flush the input | |
44 XEvent event; | |
45 while (XPending(display) && !done) { | |
46 XNextEvent(display, &event); | |
47 | |
48 sk_app::Window_mac* win = sk_app::Window_mac::gWindowMap.find(event. xany.window); | |
49 // paint and resize events get collapsed | |
50 switch (event.type) { | |
51 case Expose: | |
52 win->markPendingPaint(); | |
53 pendingWindows.add(win); | |
54 break; | |
55 case ConfigureNotify: | |
56 win->markPendingResize(event.xconfigurerequest.width, | |
57 event.xconfigurerequest.height); | |
58 pendingWindows.add(win); | |
59 break; | |
60 default: | |
61 if (win->handleEvent(event)) { | |
62 done = true; | |
63 } | |
64 break; | |
65 } | |
66 } | |
67 } | 53 } |
68 | |
69 delete app; | 54 delete app; |
70 | 55 |
71 XCloseDisplay(display); | 56 SDL_Quit(); |
72 #endif | 57 |
73 | |
74 return 0; | 58 return 0; |
75 } | 59 } |
OLD | NEW |