main.c 17 KB

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