lvgl / lv_drivers

TFT and touch pad drivers for LVGL embedded GUI library
https://docs.lvgl.io/master/porting/index.html
MIT License
306 stars 314 forks source link

feat(wayland): Wayland useability improvements #204

Closed ghost closed 2 years ago

ghost commented 2 years ago

Adds/stubs out a few functions allowing for a proper event-driven LVGL usage (when using the Wayland backend).

ghost commented 2 years ago

Example usage:

#include <stdint.h>
#include <errno.h>
#include <time.h>
#include <limits.h>
#include <poll.h>
#include "lvgl.h"
#include "lv_drivers/wayland/wayland.h"

int main(void)
{
   struct pollfd pfd;
   uint32_t time_till_next;
   int sleep;
   lv_disp_t *disp;
   lv_obj_t * label;

   lv_init();
   lv_wayland_init();

   pfd.fd = lv_wayland_get_fd();
   pfd.events = POLLIN;

   disp = lv_wayland_create_window(320, 240, "My Window", NULL);
   label = lv_label_create(lv_scr_act());
   lv_obj_align(label, LV_ALIGN_BOTTOM_MID, 0, 0);

   while (1) {
      time_till_next = lv_wayland_timer_handler();

      /* Check that there's still a window to wait on */
      if (!lv_wayland_window_is_open(NULL)) {
         break;
      }

      /* Wait for something interesting to happen */
      if (time_till_next == LV_NO_TIMER_READY) {
         sleep = -1;
      } else if (time_till_next > INT_MAX) {
         sleep = INT_MAX;
      } else {
         sleep = time_till_next;
      }

      while ((poll(&pfd, 1, sleep) < 0) && (errno == EINTR));
   }

   lv_wayland_deinit();
   return 0x00;
}

LVGL still needs to be configured appropriately (i.e. lv_conf.h/lv_drv_conf.h) ** Recommended to use a high (>10 seconds) read polling rate (LV_INDEV_DEF_READ_PERIOD) as lv_wayland_timer_handler() will ready all input timers when Wayland input is received

kisvegabor commented 2 years ago

I'm afraid people won't know about this feature if it's not documented in the README of the Wayland driver. So could a you add a few lines about it?

ghost commented 2 years ago

Updated.

kisvegabor commented 2 years ago

Thank you!