3 * Copyright 2016 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #include "include/core/SkTypes.h"
10 #include "include/private/SkTHash.h"
11 #include "tools/sk_app/Application.h"
12 #include "tools/sk_app/unix/Window_unix.h"
13 #include "tools/timer/Timer.h"
15 int main(int argc, char**argv) {
17 Display* display = XOpenDisplay(nullptr);
19 sk_app::Application* app = sk_app::Application::Create(argc, argv, (void*)display);
21 // Get the file descriptor for the X display
22 const int x11_fd = ConnectionNumber(display);
26 if (0 == XPending(display)) {
27 // Only call select() when we have no events.
29 // Create a file description set containing x11_fd
32 FD_SET(x11_fd, &in_fds);
39 // Wait for an event on the file descriptor or for timer expiration
40 (void)select(1, &in_fds, nullptr, nullptr, &tv);
43 // Handle all pending XEvents (if any) and flush the input
44 // Only handle a finite number of events before finishing resize and paint..
45 if (int count = XPending(display)) {
46 // collapse any Expose and Resize events.
47 SkTHashSet<sk_app::Window_unix*> pendingWindows;
48 while (count-- && !done) {
50 XNextEvent(display, &event);
52 sk_app::Window_unix* win = sk_app::Window_unix::gWindowMap.find(event.xany.window);
57 // paint and resize events get collapsed
60 win->markPendingPaint();
61 pendingWindows.add(win);
64 win->markPendingResize(event.xconfigurerequest.width,
65 event.xconfigurerequest.height);
66 pendingWindows.add(win);
69 if (win->handleEvent(event)) {
75 pendingWindows.foreach([](sk_app::Window_unix* win) {
80 // We are only really "idle" when the timer went off with zero events.
89 XCloseDisplay(display);