main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. #define _GNU_SOURCE // for O_TMPFILE
  2. #define NK_INCLUDE_FIXED_TYPES
  3. #define NK_INCLUDE_STANDARD_IO
  4. #define NK_INCLUDE_STANDARD_VARARGS
  5. #define NK_INCLUDE_DEFAULT_ALLOCATOR
  6. #define NK_IMPLEMENTATION
  7. #define NK_INCLUDE_FONT_BAKING
  8. #define NK_INCLUDE_DEFAULT_FONT
  9. #define NK_INCLUDE_SOFTWARE_FONT
  10. #include <wayland-client.h>
  11. #include <stdlib.h>
  12. #include <fcntl.h>
  13. #include <sys/mman.h>
  14. #include <unistd.h>
  15. #include <string.h>
  16. #include <stdio.h>
  17. #include <math.h>
  18. #include <time.h>
  19. #include <sys/time.h>
  20. #include "../../nuklear.h"
  21. #include "xdg-shell.h"
  22. #include "nuklear_raw_wayland.h"
  23. #define DTIME 20
  24. /* ===============================================================
  25. *
  26. * EXAMPLE
  27. *
  28. * ===============================================================*/
  29. /* This are some code examples to provide a small overview of what can be
  30. * done with this library. To try out an example uncomment the defines */
  31. /*#define INCLUDE_ALL */
  32. /*#define INCLUDE_STYLE */
  33. /*#define INCLUDE_CALCULATOR */
  34. /*#define INCLUDE_CANVAS */
  35. /*#define INCLUDE_OVERVIEW */
  36. /*#define INCLUDE_NODE_EDITOR */
  37. #ifdef INCLUDE_ALL
  38. #define INCLUDE_STYLE
  39. #define INCLUDE_CALCULATOR
  40. #define INCLUDE_CANVAS
  41. #define INCLUDE_OVERVIEW
  42. #define INCLUDE_NODE_EDITOR
  43. #endif
  44. #ifdef INCLUDE_STYLE
  45. #include "../../demo/common/style.c"
  46. #endif
  47. #ifdef INCLUDE_CALCULATOR
  48. #include "../../demo/common/calculator.c"
  49. #endif
  50. #ifdef INCLUDE_CANVAS
  51. #include "../../demo/common/canvas.c"
  52. #endif
  53. #ifdef INCLUDE_OVERVIEW
  54. #include "../../demo/common/overview.c"
  55. #endif
  56. #ifdef INCLUDE_NODE_EDITOR
  57. #include "../../demo/common/node_editor.c"
  58. #endif
  59. //WAYLAND OUTPUT INTERFACE
  60. static void nk_wayland_output_cb_geometry(void *data, struct wl_output *wl_output, int x, int y, int w, int h, int subpixel, const char *make, const char *model, int transform)
  61. {
  62. NK_UNUSED(data);
  63. NK_UNUSED(wl_output);
  64. NK_UNUSED(subpixel);
  65. NK_UNUSED(make);
  66. NK_UNUSED(model);
  67. NK_UNUSED(transform);
  68. printf("wl_output geometry x=%d, y=%d, w=%d, h=%d make=%s, model=%s \n", x,y,w,h, make, model);
  69. }
  70. static void nk_wayland_output_cb_mode(void *data, struct wl_output *wl_output, unsigned int flags, int w, int h, int refresh)
  71. {
  72. NK_UNUSED(data);
  73. NK_UNUSED(wl_output);
  74. NK_UNUSED(flags);
  75. NK_UNUSED(w);
  76. NK_UNUSED(h);
  77. NK_UNUSED(refresh);
  78. }
  79. static void nk_wayland_output_cb_done(void *data, struct wl_output *output)
  80. {
  81. NK_UNUSED(data);
  82. NK_UNUSED(output);
  83. }
  84. static void nk_wayland_output_cb_scale(void *data, struct wl_output *output, int scale)
  85. {
  86. NK_UNUSED(data);
  87. NK_UNUSED(output);
  88. NK_UNUSED(scale);
  89. }
  90. static const struct wl_output_listener nk_wayland_output_listener =
  91. {
  92. &nk_wayland_output_cb_geometry,
  93. &nk_wayland_output_cb_mode,
  94. &nk_wayland_output_cb_done,
  95. &nk_wayland_output_cb_scale
  96. };
  97. //-------------------------------------------------------------------- endof WAYLAND OUTPUT INTERFACE
  98. //WAYLAND POINTER INTERFACE (mouse/touchpad)
  99. static void nk_wayland_pointer_enter (void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y)
  100. {
  101. NK_UNUSED(data);
  102. NK_UNUSED(pointer);
  103. NK_UNUSED(serial);
  104. NK_UNUSED(surface);
  105. NK_UNUSED(surface_x);
  106. NK_UNUSED(surface_y);
  107. }
  108. static void nk_wayland_pointer_leave (void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface)
  109. {
  110. NK_UNUSED(data);
  111. NK_UNUSED(pointer);
  112. NK_UNUSED(serial);
  113. NK_UNUSED(surface);
  114. }
  115. static void nk_wayland_pointer_motion (void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y)
  116. {
  117. struct nk_wayland* win = (struct nk_wayland*)data;
  118. NK_UNUSED(pointer);
  119. NK_UNUSED(time);
  120. win->mouse_pointer_x = wl_fixed_to_int(x);
  121. win->mouse_pointer_y = wl_fixed_to_int(y);
  122. nk_input_motion(&(win->ctx), win->mouse_pointer_x, win->mouse_pointer_y);
  123. }
  124. static void nk_wayland_pointer_button (void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
  125. {
  126. struct nk_wayland* win = (struct nk_wayland*)data;
  127. NK_UNUSED(pointer);
  128. NK_UNUSED(serial);
  129. NK_UNUSED(time);
  130. if (button == 272){ //left mouse button
  131. if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
  132. // printf("nk_input_button x=%d, y=%d press: 1 \n", win->mouse_pointer_x, win->mouse_pointer_y);
  133. nk_input_button(&(win->ctx), NK_BUTTON_LEFT, win->mouse_pointer_x, win->mouse_pointer_y, 1);
  134. } else if (state == WL_POINTER_BUTTON_STATE_RELEASED) {
  135. nk_input_button(&(win->ctx), NK_BUTTON_LEFT, win->mouse_pointer_x, win->mouse_pointer_y, 0);
  136. }
  137. }
  138. }
  139. static void nk_wayland_pointer_axis (void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
  140. {
  141. NK_UNUSED(data);
  142. NK_UNUSED(pointer);
  143. NK_UNUSED(time);
  144. NK_UNUSED(axis);
  145. NK_UNUSED(value);
  146. }
  147. static struct wl_pointer_listener nk_wayland_pointer_listener =
  148. {
  149. &nk_wayland_pointer_enter,
  150. &nk_wayland_pointer_leave,
  151. &nk_wayland_pointer_motion,
  152. &nk_wayland_pointer_button,
  153. &nk_wayland_pointer_axis,
  154. NULL,
  155. NULL,
  156. NULL,
  157. NULL
  158. };
  159. //-------------------------------------------------------------------- endof WAYLAND POINTER INTERFACE
  160. //WAYLAND KEYBOARD INTERFACE
  161. static void nk_wayland_keyboard_keymap (void *data, struct wl_keyboard *keyboard, uint32_t format, int32_t fd, uint32_t size)
  162. {
  163. NK_UNUSED(data);
  164. NK_UNUSED(keyboard);
  165. NK_UNUSED(format);
  166. NK_UNUSED(fd);
  167. NK_UNUSED(size);
  168. }
  169. static void nk_wayland_keyboard_enter (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys)
  170. {
  171. NK_UNUSED(data);
  172. NK_UNUSED(keyboard);
  173. NK_UNUSED(serial);
  174. NK_UNUSED(surface);
  175. NK_UNUSED(keys);
  176. }
  177. static void nk_wayland_keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface)
  178. {
  179. NK_UNUSED(data);
  180. NK_UNUSED(keyboard);
  181. NK_UNUSED(serial);
  182. NK_UNUSED(surface);
  183. }
  184. static void nk_wayland_keyboard_key (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
  185. {
  186. NK_UNUSED(data);
  187. NK_UNUSED(keyboard);
  188. NK_UNUSED(serial);
  189. NK_UNUSED(time);
  190. NK_UNUSED(state);
  191. printf("key: %d \n", key);
  192. }
  193. static void nk_wayland_keyboard_modifiers (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
  194. {
  195. NK_UNUSED(data);
  196. NK_UNUSED(keyboard);
  197. NK_UNUSED(serial);
  198. NK_UNUSED(mods_depressed);
  199. NK_UNUSED(mods_latched);
  200. NK_UNUSED(mods_locked);
  201. NK_UNUSED(group);
  202. }
  203. static struct wl_keyboard_listener nk_wayland_keyboard_listener =
  204. {
  205. &nk_wayland_keyboard_keymap,
  206. &nk_wayland_keyboard_enter,
  207. &nk_wayland_keyboard_leave,
  208. &nk_wayland_keyboard_key,
  209. &nk_wayland_keyboard_modifiers,
  210. NULL
  211. };
  212. //-------------------------------------------------------------------- endof WAYLAND KEYBOARD INTERFACE
  213. //WAYLAND SEAT INTERFACE
  214. static void seat_capabilities (void *data, struct wl_seat *seat, uint32_t capabilities)
  215. {
  216. struct nk_wayland* win = (struct nk_wayland*)data;
  217. if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
  218. struct wl_pointer *pointer = wl_seat_get_pointer (seat);
  219. wl_pointer_add_listener (pointer, &nk_wayland_pointer_listener, win);
  220. }
  221. if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
  222. struct wl_keyboard *keyboard = wl_seat_get_keyboard (seat);
  223. wl_keyboard_add_listener (keyboard, &nk_wayland_keyboard_listener, win);
  224. }
  225. }
  226. static struct wl_seat_listener seat_listener =
  227. {
  228. &seat_capabilities,
  229. NULL
  230. };
  231. //-------------------------------------------------------------------- endof WAYLAND SEAT INTERFACE
  232. // WAYLAND SHELL INTERFACE
  233. static void nk_wayland_xdg_wm_base_ping (void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial)
  234. {
  235. NK_UNUSED(data);
  236. xdg_wm_base_pong (xdg_wm_base, serial);
  237. }
  238. static struct xdg_wm_base_listener nk_wayland_xdg_wm_base_listener =
  239. {
  240. &nk_wayland_xdg_wm_base_ping
  241. };
  242. static void nk_wayland_xdg_surface_configure (void *data, struct xdg_surface *xdg_surface, uint32_t serial)
  243. {
  244. NK_UNUSED(data);
  245. xdg_surface_ack_configure(xdg_surface, serial);
  246. }
  247. static struct xdg_surface_listener nk_wayland_xdg_surface_listener =
  248. {
  249. &nk_wayland_xdg_surface_configure,
  250. };
  251. static void nk_wayland_xdg_toplevel_configure (void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states)
  252. {
  253. NK_UNUSED(data);
  254. NK_UNUSED(xdg_toplevel);
  255. NK_UNUSED(width);
  256. NK_UNUSED(height);
  257. NK_UNUSED(states);
  258. }
  259. static void nk_wayland_xdg_toplevel_close (void *data, struct xdg_toplevel *xdg_toplevel)
  260. {
  261. NK_UNUSED(data);
  262. NK_UNUSED(xdg_toplevel);
  263. }
  264. static struct xdg_toplevel_listener nk_wayland_xdg_toplevel_listener =
  265. {
  266. &nk_wayland_xdg_toplevel_configure,
  267. &nk_wayland_xdg_toplevel_close
  268. };
  269. //--------------------------------------------------------------------- endof WAYLAND SHELL INTERFACE
  270. // WAYLAND REGISTRY INTERFACE
  271. static void nk_wayland_registry_add_object (void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
  272. {
  273. struct nk_wayland* win = (struct nk_wayland*)data;
  274. NK_UNUSED(version);
  275. //printf("looking for %s interface \n", interface);
  276. if (!strcmp(interface,"wl_compositor")) {
  277. win->compositor = wl_registry_bind (registry, name, &wl_compositor_interface, 1);
  278. } else if (!strcmp(interface,"xdg_wm_base")) {
  279. win->xdg_wm_base = wl_registry_bind (registry, name, &xdg_wm_base_interface, 1);
  280. xdg_wm_base_add_listener (win->xdg_wm_base, &nk_wayland_xdg_wm_base_listener, win);
  281. } else if (!strcmp(interface,"wl_shm")) {
  282. win->wl_shm = wl_registry_bind (registry, name, &wl_shm_interface, 1);
  283. } else if (!strcmp(interface,"wl_seat")) {
  284. win->seat = wl_registry_bind (registry, name, &wl_seat_interface, 1);
  285. wl_seat_add_listener (win->seat, &seat_listener, win);
  286. } else if (!strcmp(interface, "wl_output")) {
  287. struct wl_output *wl_output = wl_registry_bind(registry, name, &wl_output_interface, 1);
  288. wl_output_add_listener(wl_output, &nk_wayland_output_listener, NULL);
  289. }
  290. }
  291. static void nk_wayland_registry_remove_object (void *data, struct wl_registry *registry, uint32_t name)
  292. {
  293. NK_UNUSED(data);
  294. NK_UNUSED(registry);
  295. NK_UNUSED(name);
  296. }
  297. static struct wl_registry_listener nk_wayland_registry_listener =
  298. {
  299. &nk_wayland_registry_add_object,
  300. &nk_wayland_registry_remove_object
  301. };
  302. //------------------------------------------------------------------------------------------------ endof WAYLAND REGISTRY INTERFACE
  303. static void nk_wayland_init(struct nk_wayland* win)
  304. {
  305. const void *tex;
  306. win->font_tex.pixels = win->tex_scratch;
  307. win->font_tex.format = NK_FONT_ATLAS_ALPHA8;
  308. win->font_tex.w = win->font_tex.h = 0;
  309. if (0 == nk_init_default(&(win->ctx), 0)) {
  310. return;
  311. }
  312. nk_font_atlas_init_default(&(win->atlas));
  313. nk_font_atlas_begin(&(win->atlas));
  314. tex = nk_font_atlas_bake(&(win->atlas), &(win->font_tex.w), &(win->font_tex.h), win->font_tex.format);
  315. if (!tex) {
  316. return;
  317. }
  318. switch(win->font_tex.format) {
  319. case NK_FONT_ATLAS_ALPHA8:
  320. win->font_tex.pitch = win->font_tex.w * 1;
  321. break;
  322. case NK_FONT_ATLAS_RGBA32:
  323. win->font_tex.pitch = win->font_tex.w * 4;
  324. break;
  325. };
  326. /* Store the font texture in tex scratch memory */
  327. memcpy(win->font_tex.pixels, tex, win->font_tex.pitch * win->font_tex.h);
  328. nk_font_atlas_end(&(win->atlas), nk_handle_ptr(NULL), NULL);
  329. if (win->atlas.default_font)
  330. nk_style_set_font(&(win->ctx), &(win->atlas.default_font->handle));
  331. nk_style_load_all_cursors(&(win->ctx), win->atlas.cursors);
  332. nk_wayland_scissor(win, 0, 0, win->width, win->height);
  333. }
  334. static void nk_wayland_deinit(struct nk_wayland *win)
  335. {
  336. xdg_toplevel_destroy (win->xdg_toplevel);
  337. xdg_surface_destroy (win->xdg_surface);
  338. xdg_wm_base_destroy (win->xdg_wm_base);
  339. wl_surface_destroy (win->surface);
  340. }
  341. static long timestamp(void)
  342. {
  343. struct timeval tv;
  344. if (gettimeofday(&tv, NULL) < 0) return 0;
  345. return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
  346. }
  347. static void sleep_for(long t)
  348. {
  349. struct timespec req;
  350. const time_t sec = (int)(t/1000);
  351. const long ms = t - (sec * 1000);
  352. req.tv_sec = sec;
  353. req.tv_nsec = ms * 1000000L;
  354. while(-1 == nanosleep(&req, &req));
  355. }
  356. static void nk_wayland_surf_clear(struct nk_wayland* win)
  357. {
  358. int x, y;
  359. int pix_idx;
  360. for (y = 0; y < win->height; y++){
  361. for (x = 0; x < win->width; x++){
  362. pix_idx = y * win->width + x;
  363. win->data[pix_idx] = 0xFF000000;
  364. }
  365. }
  366. }
  367. //This causes the screen to refresh
  368. static const struct wl_callback_listener frame_listener;
  369. static void redraw(void *data, struct wl_callback *callback, uint32_t time)
  370. {
  371. // printf("redrawing.. 1\n");
  372. struct nk_wayland* win = (struct nk_wayland*)data;
  373. NK_UNUSED(callback);
  374. NK_UNUSED(time);
  375. wl_callback_destroy(win->frame_callback);
  376. wl_surface_damage(win->surface, 0, 0, WIDTH, HEIGHT);
  377. win->frame_callback = wl_surface_frame(win->surface);
  378. wl_surface_attach(win->surface, win->front_buffer, 0, 0);
  379. wl_callback_add_listener(win->frame_callback, &frame_listener, win);
  380. wl_surface_commit(win->surface);
  381. }
  382. static const struct wl_callback_listener frame_listener = {
  383. redraw
  384. };
  385. int main ()
  386. {
  387. long dt;
  388. long started;
  389. struct nk_wayland nk_wayland_ctx;
  390. struct wl_registry *registry;
  391. int running = 1;
  392. //1. Initialize display
  393. nk_wayland_ctx.display = wl_display_connect (NULL);
  394. if (nk_wayland_ctx.display == NULL) {
  395. printf("no wayland display found. do you have wayland composer running? \n");
  396. return -1;
  397. }
  398. registry = wl_display_get_registry (nk_wayland_ctx.display);
  399. wl_registry_add_listener (registry, &nk_wayland_registry_listener, &nk_wayland_ctx);
  400. wl_display_roundtrip (nk_wayland_ctx.display);
  401. //2. Create Window
  402. nk_wayland_ctx.width = WIDTH;
  403. nk_wayland_ctx.height = HEIGHT;
  404. nk_wayland_ctx.surface = wl_compositor_create_surface (nk_wayland_ctx.compositor);
  405. nk_wayland_ctx.xdg_surface = xdg_wm_base_get_xdg_surface(nk_wayland_ctx.xdg_wm_base, nk_wayland_ctx.surface);
  406. xdg_surface_add_listener (nk_wayland_ctx.xdg_surface, &nk_wayland_xdg_surface_listener, &nk_wayland_ctx);
  407. nk_wayland_ctx.xdg_toplevel = xdg_surface_get_toplevel(nk_wayland_ctx.xdg_surface);
  408. xdg_toplevel_add_listener (nk_wayland_ctx.xdg_toplevel, &nk_wayland_xdg_toplevel_listener, &nk_wayland_ctx);
  409. nk_wayland_ctx.frame_callback = wl_surface_frame(nk_wayland_ctx.surface);
  410. wl_callback_add_listener(nk_wayland_ctx.frame_callback, &frame_listener, &nk_wayland_ctx);
  411. wl_surface_commit (nk_wayland_ctx.surface);
  412. size_t size = WIDTH * HEIGHT * 4;
  413. char *xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
  414. int fd = open (xdg_runtime_dir, O_TMPFILE|O_RDWR|O_EXCL, 0600);
  415. ftruncate (fd, size);
  416. nk_wayland_ctx.data = mmap (NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  417. struct wl_shm_pool *pool = wl_shm_create_pool (nk_wayland_ctx.wl_shm, fd, size);
  418. nk_wayland_ctx.front_buffer = wl_shm_pool_create_buffer (pool, 0, WIDTH, HEIGHT, WIDTH*4, WL_SHM_FORMAT_XRGB8888);
  419. wl_shm_pool_destroy (pool);
  420. close (fd);
  421. wl_display_roundtrip (nk_wayland_ctx.display);
  422. //3. Clear window and start rendering loop
  423. nk_wayland_surf_clear(&nk_wayland_ctx);
  424. wl_surface_attach (nk_wayland_ctx.surface, nk_wayland_ctx.front_buffer, 0, 0);
  425. wl_surface_commit (nk_wayland_ctx.surface);
  426. nk_wayland_init(&nk_wayland_ctx);
  427. //4. rendering UI
  428. while (running) {
  429. started = timestamp();
  430. // GUI
  431. if (nk_begin(&(nk_wayland_ctx.ctx), "Demo", nk_rect(50, 50, 200, 200),
  432. NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|
  433. NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) {
  434. enum {EASY, HARD};
  435. static int op = EASY;
  436. static int property = 20;
  437. nk_layout_row_static(&(nk_wayland_ctx.ctx), 30, 80, 1);
  438. if (nk_button_label(&(nk_wayland_ctx.ctx), "button")){
  439. printf("button pressed\n");
  440. }
  441. nk_layout_row_dynamic(&(nk_wayland_ctx.ctx), 30, 2);
  442. if (nk_option_label(&(nk_wayland_ctx.ctx), "easy", op == EASY)) op = EASY;
  443. if (nk_option_label(&(nk_wayland_ctx.ctx), "hard", op == HARD)) op = HARD;
  444. nk_layout_row_dynamic(&(nk_wayland_ctx.ctx), 25, 1);
  445. nk_property_int(&(nk_wayland_ctx.ctx), "Compression:", 0, &property, 100, 10, 1);
  446. }
  447. nk_end(&(nk_wayland_ctx.ctx));
  448. if (nk_window_is_closed(&(nk_wayland_ctx.ctx), "Demo")) break;
  449. /* -------------- EXAMPLES ---------------- */
  450. #ifdef INCLUDE_CALCULATOR
  451. calculator(&(nk_wayland_ctx.ctx));
  452. #endif
  453. #ifdef INCLUDE_CANVAS
  454. canvas(&(nk_wayland_ctx.ctx));
  455. #endif
  456. #ifdef INCLUDE_OVERVIEW
  457. overview(&(nk_wayland_ctx.ctx));
  458. #endif
  459. #ifdef INCLUDE_NODE_EDITOR
  460. node_editor(&(nk_wayland_ctx.ctx));
  461. #endif
  462. /* ----------------------------------------- */
  463. // Draw framebuffer
  464. nk_wayland_render(&nk_wayland_ctx, nk_rgb(30,30,30), 1);
  465. //handle wayland stuff (send display to FB & get inputs)
  466. nk_input_begin(&(nk_wayland_ctx.ctx));
  467. wl_display_dispatch(nk_wayland_ctx.display);
  468. nk_input_end(&(nk_wayland_ctx.ctx));
  469. // Timing
  470. dt = timestamp() - started;
  471. if (dt < DTIME)
  472. sleep_for(DTIME - dt);
  473. }
  474. nk_wayland_deinit (&nk_wayland_ctx);
  475. wl_display_disconnect (nk_wayland_ctx.display);
  476. return 0;
  477. }