Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
main_unix.cpp File Reference
#include "include/core/SkTypes.h"
#include "src/core/SkTHash.h"
#include "tools/sk_app/Application.h"
#include "tools/sk_app/unix/Window_unix.h"
#include "tools/timer/Timer.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 17 of file main_unix.cpp.

17 {
18 XInitThreads();
19 Display* display = XOpenDisplay(nullptr);
20
21 sk_app::Application* app = sk_app::Application::Create(argc, argv, (void*)display);
22
23 // Get the file descriptor for the X display
24 const int x11_fd = ConnectionNumber(display);
25
26 bool done = false;
27 while (!done) {
28 if (0 == XPending(display)) {
29 // Only call select() when we have no events.
30
31 // Create a file description set containing x11_fd
32 fd_set in_fds;
33 FD_ZERO(&in_fds);
34 FD_SET(x11_fd, &in_fds);
35
36 // Set a sleep timer
37 struct timeval tv;
38 tv.tv_usec = 10;
39 tv.tv_sec = 0;
40
41 // Wait for an event on the file descriptor or for timer expiration
42 (void)select(1, &in_fds, nullptr, nullptr, &tv);
43 }
44
45 // Handle all pending XEvents (if any) and flush the input
46 // Only handle a finite number of events before finishing resize and paint..
47 if (int count = XPending(display)) {
48 // collapse any Expose and Resize events.
49 THashSet<sk_app::Window_unix*> pendingWindows;
50 while (count-- && !done) {
51 XEvent event;
52 XNextEvent(display, &event);
53
55 if (!win) {
56 continue;
57 }
58
59 // paint and resize events get collapsed
60 switch (event.type) {
61 case Expose:
62 win->markPendingPaint();
63 pendingWindows.add(win);
64 break;
65 case ConfigureNotify:
66 win->markPendingResize(event.xconfigurerequest.width,
67 event.xconfigurerequest.height);
68 pendingWindows.add(win);
69 break;
70 default:
71 if (win->handleEvent(event)) {
72 done = true;
73 }
74 break;
75 }
76 }
77 pendingWindows.foreach([](sk_app::Window_unix* win) {
78 win->finishResize();
79 win->finishPaint();
80 });
81 } else {
82 // We are only really "idle" when the timer went off with zero events.
83 app->onIdle();
84 }
85
86 XFlush(display);
87 }
88
89 delete app;
90
91 XCloseDisplay(display);
92
93 return 0;
94}
static void done(const char *config, const char *src, const char *srcOptions, const char *name)
Definition DM.cpp:263
int count
static Application * Create(int argc, char **argv, void *platformData)
bool handleEvent(const XEvent &event)
static SkTDynamicHash< Window_unix, XWindow > gWindowMap
Definition Window_unix.h:58
void markPendingResize(int width, int height)
Definition Window_unix.h:68
void add(T item)
Definition SkTHash.h:573
void foreach(Fn &&fn) const
Definition SkTHash.h:590
FlKeyEvent * event