26#include "libui/types.h"
28int main(
int argc,
char** argv) {
29 const std::optional<demo::Options>
options = demo::parseOptions(argc, argv);
33 libui::client::Client client = libui::client::Client::connect(
options->socketPath);
34 if (!client.valid()) {
35 std::fprintf(stderr,
"uitest could not connect to compositor\n");
39 demo::Options redOptions = *
options;
40 redOptions.title =
"UI Test A";
41 redOptions.background = libui::packColor({255, 0, 0, 255});
42 std::optional<libui::client::Window> redResult = demo::createWindow(client, redOptions);
44 std::fprintf(stderr,
"uitest could not create red window\n");
48 demo::Options greenOptions = *
options;
49 greenOptions.title =
"UI Test B";
52 greenOptions.background = libui::packColor({0, 255, 0, 255});
53 std::optional<libui::client::Window> greenResult = demo::createWindow(client, greenOptions);
55 std::fprintf(stderr,
"uitest could not create green window\n");
59 libui::client::Window& redWindow = redResult.value();
60 libui::client::Window& greenWindow = greenResult.value();
61 bool redClosed =
false;
62 bool greenClosed =
false;
64 redWindow.setWindowProc([&redClosed](libui::client::Window&,
const libui::client::Event& event) {
65 if (event.type() == libui::client::Event::Type::Close) {
71 greenWindow.setWindowProc(
72 [&greenClosed](libui::client::Window&,
const libui::client::Event& event) {
73 if (event.type() == libui::client::Event::Type::Close) {
80 auto dispatchPending = [&] {
82 bool progressed =
false;
83 if (client.dispatch(redWindow,
false,
false))
85 if (client.dispatch(greenWindow,
false,
false))
87 if (!progressed || !client.hasPendingMessages())
92 if (!client.setNonBlocking(
true) || !client.paint(redWindow) || !client.paint(greenWindow))
95 while ((!redClosed || !greenClosed) && client.valid()) {
96 if ((!redClosed && !client.paintDirty(redWindow)) ||
97 (!greenClosed && !client.paintDirty(greenWindow)))
100 if (client.hasPendingMessages()) {
105 pollfd descriptor{client.descriptor(), POLLIN, 0};
106 const int result = ::poll(&descriptor, 1, 50);
114 if (descriptor.revents & (POLLHUP | POLLERR | POLLNVAL))
116 if (descriptor.revents & POLLIN)
120 return (redClosed && greenClosed) ? 0 : 1;