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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
#include "SkTHash.h"
|
|
|
|
#include "Timer.h"
|
|
|
|
#include "Window_unix.h"
|
|
|
|
#include "../Application.h"
|
|
|
|
|
|
|
|
using sk_app::Application;
|
|
|
|
|
|
|
|
void finishWindow(sk_app::Window_unix* win) {
|
|
|
|
win->finishResize();
|
|
|
|
win->finishPaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char**argv) {
|
|
|
|
|
|
|
|
Display* display = XOpenDisplay(nullptr);
|
|
|
|
|
|
|
|
Application* app = Application::Create(argc, argv, (void*)display);
|
|
|
|
|
|
|
|
// Get the file descriptor for the X display
|
|
|
|
int x11_fd = ConnectionNumber(display);
|
2016-08-11 14:03:04 +00:00
|
|
|
int count = x11_fd + 1;
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
SkTHashSet<sk_app::Window_unix*> pendingWindows;
|
|
|
|
bool done = false;
|
|
|
|
while (!done) {
|
|
|
|
// Create a file description set containing x11_fd
|
2016-08-11 14:03:04 +00:00
|
|
|
fd_set in_fds;
|
2016-05-23 20:13:36 +00:00
|
|
|
FD_ZERO(&in_fds);
|
|
|
|
FD_SET(x11_fd, &in_fds);
|
|
|
|
|
|
|
|
// Set a sleep timer
|
|
|
|
struct timeval tv;
|
|
|
|
tv.tv_usec = 100;
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
|
2016-08-11 14:03:04 +00:00
|
|
|
while (!XPending(display)) {
|
|
|
|
// Wait for an event on the file descriptor or for timer expiration
|
|
|
|
(void) select(count, &in_fds, NULL, NULL, &tv);
|
|
|
|
}
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2017-01-05 18:50:49 +00:00
|
|
|
// Handle XEvents (if any) and flush the input
|
2016-08-11 14:03:04 +00:00
|
|
|
int count = XPending(display);
|
|
|
|
while (count-- && !done) {
|
|
|
|
XEvent event;
|
2016-05-23 20:13:36 +00:00
|
|
|
XNextEvent(display, &event);
|
|
|
|
|
|
|
|
sk_app::Window_unix* win = sk_app::Window_unix::gWindowMap.find(event.xany.window);
|
2017-02-24 23:04:47 +00:00
|
|
|
if (!win) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-05 18:50:49 +00:00
|
|
|
|
2016-05-23 20:13:36 +00:00
|
|
|
// paint and resize events get collapsed
|
|
|
|
switch (event.type) {
|
2017-01-05 18:50:49 +00:00
|
|
|
case Expose:
|
2016-05-23 20:13:36 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pendingWindows.foreach(finishWindow);
|
|
|
|
if (pendingWindows.count() > 0) {
|
2016-07-06 21:11:32 +00:00
|
|
|
app->onIdle();
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
pendingWindows.reset();
|
2016-08-11 14:03:04 +00:00
|
|
|
|
|
|
|
XFlush(display);
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete app;
|
|
|
|
|
|
|
|
XCloseDisplay(display);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|