2016-05-23 20:13:36 +00:00
|
|
|
/*
|
2017-02-24 23:04:47 +00:00
|
|
|
|
2016-05-23 20:13:36 +00:00
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/private/SkTHash.h"
|
|
|
|
#include "tools/sk_app/Application.h"
|
|
|
|
#include "tools/sk_app/unix/Window_unix.h"
|
|
|
|
#include "tools/timer/Timer.h"
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
int main(int argc, char**argv) {
|
2018-09-27 16:25:41 +00:00
|
|
|
XInitThreads();
|
2016-05-23 20:13:36 +00:00
|
|
|
Display* display = XOpenDisplay(nullptr);
|
|
|
|
|
2019-08-01 15:12:01 +00:00
|
|
|
sk_app::Application* app = sk_app::Application::Create(argc, argv, (void*)display);
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
// Get the file descriptor for the X display
|
2019-08-01 15:12:01 +00:00
|
|
|
const int x11_fd = ConnectionNumber(display);
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
bool done = false;
|
|
|
|
while (!done) {
|
2019-08-01 15:12:01 +00:00
|
|
|
if (0 == XPending(display)) {
|
|
|
|
// Only call select() when we have no events.
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2019-08-01 15:12:01 +00:00
|
|
|
// Create a file description set containing x11_fd
|
|
|
|
fd_set in_fds;
|
|
|
|
FD_ZERO(&in_fds);
|
|
|
|
FD_SET(x11_fd, &in_fds);
|
|
|
|
|
|
|
|
// Set a sleep timer
|
|
|
|
struct timeval tv;
|
|
|
|
tv.tv_usec = 10;
|
|
|
|
tv.tv_sec = 0;
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2016-08-11 14:03:04 +00:00
|
|
|
// Wait for an event on the file descriptor or for timer expiration
|
2019-08-01 15:12:01 +00:00
|
|
|
(void)select(1, &in_fds, nullptr, nullptr, &tv);
|
2016-08-11 14:03:04 +00:00
|
|
|
}
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2019-08-01 15:12:01 +00:00
|
|
|
// Handle all pending XEvents (if any) and flush the input
|
|
|
|
// Only handle a finite number of events before finishing resize and paint..
|
|
|
|
if (int count = XPending(display)) {
|
|
|
|
// collapse any Expose and Resize events.
|
|
|
|
SkTHashSet<sk_app::Window_unix*> pendingWindows;
|
|
|
|
while (count-- && !done) {
|
|
|
|
XEvent event;
|
|
|
|
XNextEvent(display, &event);
|
|
|
|
|
|
|
|
sk_app::Window_unix* win = sk_app::Window_unix::gWindowMap.find(event.xany.window);
|
|
|
|
if (!win) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-05 18:50:49 +00:00
|
|
|
|
2019-08-01 15:12:01 +00:00
|
|
|
// paint and resize events get collapsed
|
|
|
|
switch (event.type) {
|
|
|
|
case Expose:
|
|
|
|
win->markPendingPaint();
|
|
|
|
pendingWindows.add(win);
|
|
|
|
break;
|
|
|
|
case ConfigureNotify:
|
|
|
|
win->markPendingResize(event.xconfigurerequest.width,
|
|
|
|
event.xconfigurerequest.height);
|
|
|
|
pendingWindows.add(win);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (win->handleEvent(event)) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
break;
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
2017-10-09 19:45:33 +00:00
|
|
|
}
|
2019-08-01 15:12:01 +00:00
|
|
|
pendingWindows.foreach([](sk_app::Window_unix* win) {
|
|
|
|
win->finishResize();
|
|
|
|
win->finishPaint();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// We are only really "idle" when the timer went off with zero events.
|
2016-07-06 21:11:32 +00:00
|
|
|
app->onIdle();
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
2016-08-11 14:03:04 +00:00
|
|
|
|
|
|
|
XFlush(display);
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete app;
|
|
|
|
|
|
|
|
XCloseDisplay(display);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|