Allow to show video in fullscreen if requested.
authorDaniel Carl <danielcarl@gmx.de>
Thu, 17 Jan 2019 23:02:14 +0000 (00:02 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Thu, 17 Jan 2019 23:02:14 +0000 (00:02 +0100)
If JavaScript calls element.webkitRequestFullScreen webkit switches vimb
into full screen mode. But the statusbar and the input box where still
shown. So now vimb hides the statusbar and the input box to allow videos
to be show on the whole screen.

src/main.c
src/main.h
src/normal.c

index 057cf39..dd5370c 100644 (file)
@@ -87,6 +87,8 @@ static void on_webview_ready_to_show(WebKitWebView *webview, Client *c);
 static gboolean on_webview_web_process_crashed(WebKitWebView *webview, Client *c);
 static gboolean on_webview_authenticate(WebKitWebView *webview,
         WebKitAuthenticationRequest *request, Client *c);
+static gboolean on_webview_enter_fullscreen(WebKitWebView *webview, Client *c);
+static gboolean on_webview_leave_fullscreen(WebKitWebView *webview, Client *c);
 static gboolean on_window_delete_event(GtkWidget *window, GdkEvent *event, Client *c);
 static void on_window_destroy(GtkWidget *window, Client *c);
 static gboolean quit(Client *c);
@@ -1478,6 +1480,28 @@ static gboolean on_webview_authenticate(WebKitWebView *webview,
     return FALSE;
 }
 
+/**
+ * Callback in case JS calls element.webkitRequestFullScreen.
+ */
+static gboolean on_webview_enter_fullscreen(WebKitWebView *webview, Client *c)
+{
+    c->state.is_fullscreen = TRUE;
+    gtk_widget_hide(GTK_WIDGET(c->statusbar.box));
+    gtk_widget_set_visible(GTK_WIDGET(c->input), FALSE);
+    return FALSE;
+}
+
+/**
+ * Callback to restore the window state after entering fullscreen.
+ */
+static gboolean on_webview_leave_fullscreen(WebKitWebView *webview, Client *c)
+{
+    c->state.is_fullscreen = FALSE;
+    gtk_widget_show(GTK_WIDGET(c->statusbar.box));
+    gtk_widget_set_visible(GTK_WIDGET(c->input), TRUE);
+    return FALSE;
+}
+
 /**
  * Callback for window ::delete-event signal which is emitted if a user
  * requests that a toplevel window is closed. The default handler for this
@@ -1808,6 +1832,8 @@ static WebKitWebView *webview_new(Client *c, WebKitWebView *webview)
         "signal::ready-to-show", G_CALLBACK(on_webview_ready_to_show), c,
         "signal::web-process-crashed", G_CALLBACK(on_webview_web_process_crashed), c,
         "signal::authenticate", G_CALLBACK(on_webview_authenticate), c,
+        "signal::enter-fullscreen", G_CALLBACK(on_webview_enter_fullscreen), c,
+        "signal::leave-fullscreen", G_CALLBACK(on_webview_leave_fullscreen), c,
         NULL
     );
 
index 56ba9e0..ec745fb 100644 (file)
@@ -171,6 +171,7 @@ struct State {
     GList               *downloads;
     guint               progress;
     WebKitHitTestResult *hit_test_result;
+    gboolean            is_fullscreen;
 
     struct {
         gboolean    active;         /* indicate if there is a active search */
index 5a2a27d..62a51f8 100644 (file)
@@ -339,6 +339,16 @@ VbResult pass_keypress(Client *c, int key)
 
 static VbResult normal_clear_input(Client *c, const NormalCmdInfo *info)
 {
+    /* If an element requested the fullscreen - the <esc> shoudl cause to
+     * leave this fullscreen mode. */
+    if (c->state.is_fullscreen) {
+        /* Unset the processed_key to indicate that the <esc> was not handled
+         * by us and letting the event bubble up. So that webkit handles the
+         * key for us to leave the fullscreen mode. */
+        c->state.processed_key = FALSE;
+        return RESULT_COMPLETE;
+    }
+
     gtk_widget_grab_focus(GTK_WIDGET(c->webview));
 
     /* Clear the inputbox and change the style to normal to reset also the