[gtk/matthiasc/for-master: 9/9] gtk-demo: Make F11 toggle fullscreen
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master: 9/9] gtk-demo: Make F11 toggle fullscreen
- Date: Sun, 13 Sep 2020 06:33:42 +0000 (UTC)
commit 7518fd0d70c584a8f2a5209b144b6ce90648ecc6
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Sep 13 02:31:41 2020 -0400
gtk-demo: Make F11 toggle fullscreen
In the video player demo, we have a button to make
the window fullscreen, but no easy way back. Add
the usual F11 keybinding, to make things at least
somewhat recoverable.
demos/gtk-demo/video_player.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
---
diff --git a/demos/gtk-demo/video_player.c b/demos/gtk-demo/video_player.c
index 221a5b1617..f417870549 100644
--- a/demos/gtk-demo/video_player.c
+++ b/demos/gtk-demo/video_player.c
@@ -82,6 +82,25 @@ fullscreen_clicked_cb (GtkWidget *button,
gtk_window_fullscreen (GTK_WINDOW (widget_window));
}
+static gboolean
+toggle_fullscreen (GtkWidget *widget,
+ GVariant *args,
+ gpointer data)
+{
+ GdkSurface *surface;
+ GdkToplevelState state;
+
+ surface = gtk_native_get_surface (GTK_NATIVE (widget));
+ state = gdk_toplevel_get_state (GDK_TOPLEVEL (surface));
+
+ if (state & GDK_TOPLEVEL_STATE_FULLSCREEN)
+ gtk_window_unfullscreen (GTK_WINDOW (widget));
+ else
+ gtk_window_fullscreen (GTK_WINDOW (widget));
+
+ return TRUE;
+}
+
GtkWidget *
do_video_player (GtkWidget *do_widget)
{
@@ -90,6 +109,7 @@ do_video_player (GtkWidget *do_widget)
GtkWidget *button;
GtkWidget *image;
GtkWidget *fullscreen_button;
+ GtkEventController *controller;
if (!window)
{
@@ -128,6 +148,14 @@ do_video_player (GtkWidget *do_widget)
fullscreen_button = gtk_button_new_from_icon_name ("view-fullscreen-symbolic");
g_signal_connect (fullscreen_button, "clicked", G_CALLBACK (fullscreen_clicked_cb), NULL);
gtk_header_bar_pack_end (GTK_HEADER_BAR (title), fullscreen_button);
+
+ controller = gtk_shortcut_controller_new ();
+ gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (controller),
+ GTK_SHORTCUT_SCOPE_GLOBAL);
+ gtk_widget_add_controller (window, controller);
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_F11, 0),
+ gtk_callback_action_new (toggle_fullscreen, NULL, NULL)));
}
if (!gtk_widget_get_visible (window))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]