uvtd: vt: implement VT_GETMODE/SETMODE ioctl state-tracking
[platform/upstream/kmscon.git] / src / wlt_toolkit.c
index 41f6d0c..18a0233 100644 (file)
 #include <wayland-cursor.h>
 #include <xkbcommon/xkbcommon.h>
 #include "eloop.h"
-#include "log.h"
 #include "shl_array.h"
 #include "shl_dlist.h"
 #include "shl_hook.h"
+#include "shl_log.h"
 #include "shl_misc.h"
 #include "tsm_vte.h"
 #include "wlt_main.h"
@@ -126,7 +126,6 @@ struct wlt_window {
        bool buffer_attached;
        bool skip_damage;
        bool need_resize;
-       bool need_redraw;
        bool need_frame;
        bool idle_pending;
        unsigned int new_width;
@@ -682,8 +681,7 @@ static void keyboard_key(void *data, struct wl_keyboard *keyboard,
                }
        }
 
-       if (state == WL_KEYBOARD_KEY_STATE_RELEASED &&
-           sym == disp->repeat_sym) {
+       if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
                ev_timer_update(disp->repeat_timer, NULL);
        } else if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
                disp->repeat_sym = sym;
@@ -1231,7 +1229,7 @@ int wlt_display_register_cb(struct wlt_display *disp,
        if (!disp)
                return -EINVAL;
 
-       return shl_hook_add_cast(disp->listeners, cb, data);
+       return shl_hook_add_cast(disp->listeners, cb, data, false);
 }
 
 void wlt_display_unregister_cb(struct wlt_display *disp,
@@ -1305,7 +1303,7 @@ static void wlt_window_do_redraw(struct wlt_window *wnd,
 }
 
 static int resize_window(struct wlt_window *wnd, unsigned int width,
-                        unsigned int height, bool force_redraw)
+                        unsigned int height)
 {
        struct shl_dlist *iter;
        struct wlt_widget *widget;
@@ -1351,8 +1349,7 @@ static int resize_window(struct wlt_window *wnd, unsigned int width,
 
        if (width == wnd->buffer.width &&
            height == wnd->buffer.height) {
-               if (force_redraw)
-                       wlt_window_do_redraw(wnd, width, height);
+               wlt_window_do_redraw(wnd, width, height);
                return 0;
        }
 
@@ -1420,26 +1417,18 @@ static const struct wl_callback_listener frame_callback_listener = {
 
 static void do_frame(struct wlt_window *wnd)
 {
-       bool force;
-
-       wnd->idle_pending = false;
        ev_eloop_unregister_idle_cb(wnd->disp->eloop, idle_frame, wnd,
                                    EV_NORMAL);
 
        if (wnd->need_resize) {
-               force = wnd->need_redraw;
                wnd->need_frame = true;
                wnd->need_resize = false;
-               wnd->need_redraw = false;
                wnd->w_frame = wl_surface_frame(wnd->w_surface);
                wl_callback_add_listener(wnd->w_frame,
                                         &frame_callback_listener, wnd);
-               resize_window(wnd, wnd->new_width, wnd->new_height, force);
-       }
-
-       if (wnd->need_redraw) {
+               resize_window(wnd, wnd->new_width, wnd->new_height);
+       } else {
                wnd->need_frame = true;
-               wnd->need_redraw = false;
                wnd->w_frame = wl_surface_frame(wnd->w_surface);
                wl_callback_add_listener(wnd->w_frame,
                                         &frame_callback_listener, wnd);
@@ -1448,6 +1437,8 @@ static void do_frame(struct wlt_window *wnd)
        }
 }
 
+static void schedule_frame(struct wlt_window *wnd);
+
 static void frame_callback(void *data, struct wl_callback *w_callback,
                           uint32_t time)
 {
@@ -1455,9 +1446,10 @@ static void frame_callback(void *data, struct wl_callback *w_callback,
 
        wl_callback_destroy(w_callback);
        wnd->w_frame = NULL;
-       wnd->need_frame = false;
 
-       do_frame(wnd);
+       wnd->idle_pending = false;
+       if (wnd->need_frame)
+               schedule_frame(wnd);
 }
 
 static void idle_frame(struct ev_eloop *eloop, void *unused, void *data)
@@ -1496,10 +1488,12 @@ static void schedule_frame(struct wlt_window *wnd)
 {
        int ret;
 
-       if (!wnd || wnd->w_frame)
+       if (!wnd)
                return;
 
-       if (wnd->need_frame || wnd->idle_pending)
+       wnd->need_frame = true;
+
+       if (wnd->idle_pending)
                return;
 
        ret = ev_eloop_register_idle_cb(wnd->disp->eloop, idle_frame, wnd,
@@ -1592,7 +1586,7 @@ int wlt_display_create_window(struct wlt_display *disp,
                                      &shell_surface_listener, wnd);
        wl_shell_surface_set_toplevel(wnd->w_shell_surface);
 
-       ret = resize_window(wnd, width, height, true);
+       ret = resize_window(wnd, width, height);
        if (ret)
                goto err_shell_surface;
 
@@ -1677,7 +1671,6 @@ void wlt_window_schedule_redraw(struct wlt_window *wnd)
        if (!wnd)
                return;
 
-       wnd->need_redraw = true;
        schedule_frame(wnd);
 }
 
@@ -1820,6 +1813,11 @@ void wlt_window_toggle_maximize(struct wlt_window *wnd)
        wnd->maximized = !wnd->maximized;
 }
 
+bool wlt_window_is_maximized(struct wlt_window *wnd)
+{
+       return wnd && wnd->maximized;
+}
+
 void wlt_window_toggle_fullscreen(struct wlt_window *wnd)
 {
        if (!wnd)
@@ -1847,6 +1845,11 @@ void wlt_window_toggle_fullscreen(struct wlt_window *wnd)
        wnd->fullscreen = !wnd->fullscreen;
 }
 
+bool wlt_window_is_fullscreen(struct wlt_window *wnd)
+{
+       return wnd && wnd->fullscreen;
+}
+
 struct ev_eloop *wlt_window_get_eloop(struct wlt_window *wnd)
 {
        if (!wnd)