wlt: toolkit: add fullscreen helpers
authorDavid Herrmann <dh.herrmann@googlemail.com>
Mon, 1 Oct 2012 14:55:49 +0000 (16:55 +0200)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Mon, 1 Oct 2012 14:55:49 +0000 (16:55 +0200)
Add helper to make a window fullscreen. Also forward the flags to all
resize and redraw handlers so widgets can changed behavior while being
fullscreen.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/wlt_toolkit.c
src/wlt_toolkit.h

index bad5c0b..88dbde3 100644 (file)
@@ -119,6 +119,7 @@ struct wlt_window {
        unsigned int saved_height;
        unsigned int resize_edges;
        bool maximized;
+       bool fullscreen;
        struct wlt_shm_buffer buffer;
        struct wl_callback *w_frame;
 
@@ -969,6 +970,8 @@ static void wlt_window_do_redraw(struct wlt_window *wnd,
        flags = 0;
        if (wnd->maximized)
                flags |= WLT_WINDOW_MAXIMIZED;
+       if (wnd->fullscreen)
+               flags |= WLT_WINDOW_FULLSCREEN;
 
        alloc.x = 0;
        alloc.y = 0;
@@ -1026,6 +1029,8 @@ static int resize_window(struct wlt_window *wnd, unsigned int width,
        flags = 0;
        if (wnd->maximized)
                flags |= WLT_WINDOW_MAXIMIZED;
+       if (wnd->fullscreen)
+               flags |= WLT_WINDOW_FULLSCREEN;
 
        neww = 0;
        newh = 0;
@@ -1499,14 +1504,37 @@ void wlt_window_toggle_maximize(struct wlt_window *wnd)
                wl_shell_surface_set_toplevel(wnd->w_shell_surface);
                wlt_window_set_size(wnd, wnd->saved_width, wnd->saved_height);
        } else {
-               wnd->saved_width = wnd->buffer.width;
-               wnd->saved_height = wnd->buffer.height;
+               if (!wnd->fullscreen) {
+                       wnd->saved_width = wnd->buffer.width;
+                       wnd->saved_height = wnd->buffer.height;
+               }
                wl_shell_surface_set_maximized(wnd->w_shell_surface, NULL);
        }
 
        wnd->maximized = !wnd->maximized;
 }
 
+void wlt_window_toggle_fullscreen(struct wlt_window *wnd)
+{
+       if (!wnd)
+               return;
+
+       if (wnd->fullscreen) {
+               wl_shell_surface_set_toplevel(wnd->w_shell_surface);
+               wlt_window_set_size(wnd, wnd->saved_width, wnd->saved_height);
+       } else {
+               if (!wnd->maximized) {
+                       wnd->saved_width = wnd->buffer.width;
+                       wnd->saved_height = wnd->buffer.height;
+               }
+               wl_shell_surface_set_fullscreen(wnd->w_shell_surface,
+                               WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
+                               0, NULL);
+       }
+
+       wnd->fullscreen = !wnd->fullscreen;
+}
+
 struct ev_eloop *wlt_window_get_eloop(struct wlt_window *wnd)
 {
        if (!wnd)
index f4d9b98..f3d4140 100644 (file)
@@ -74,6 +74,7 @@ enum cursor_type {
 };
 
 #define WLT_WINDOW_MAXIMIZED           0x01
+#define WLT_WINDOW_FULLSCREEN          0x02
 
 typedef void (*wlt_display_cb) (struct wlt_display *disp,
                                unsigned int event,
@@ -153,6 +154,7 @@ void wlt_window_set_close_cb(struct wlt_window *wnd,
                             wlt_window_close_cb cb);
 void wlt_window_close(struct wlt_window *wnd);
 void wlt_window_toggle_maximize(struct wlt_window *wnd);
+void wlt_window_toggle_fullscreen(struct wlt_window *wnd);
 struct ev_eloop *wlt_window_get_eloop(struct wlt_window *wnd);
 
 void wlt_widget_destroy(struct wlt_widget *widget);