diff --git a/po/de.po b/po/de.po index f95242a..784942e 100644 --- a/po/de.po +++ b/po/de.po @@ -72,6 +72,11 @@ msgctxt "shortcut window" msgid "New Window" msgstr "Neues Fenster" +#: src/help-overlay.ui:22 +msgctxt "shortcut window" +msgid "Fullscreen" +msgstr "Vollbild" + #: src/help-overlay.ui:23 msgctxt "shortcut window" msgid "Terminal" @@ -427,6 +432,10 @@ msgstr "" msgid "_New Window" msgstr "_Neues Fenster" +#: src/kgx-window.ui:21 +msgid "_Fullscreen" +msgstr "_Vollbild" + #: src/kgx-window.ui:23 msgid "_Show All Tabs" msgstr "Alle Reiter _anzeigen" diff --git a/po/en_GB.po b/po/en_GB.po index f3d5bbb..b481f49 100644 --- a/po/en_GB.po +++ b/po/en_GB.po @@ -63,6 +63,11 @@ msgctxt "shortcut window" msgid "New Window" msgstr "New Window" +#: src/help-overlay.ui:22 +msgctxt "shortcut window" +msgid "Fullscreen" +msgstr "Fullscreen" + #: src/help-overlay.ui:23 msgctxt "shortcut window" msgid "Terminal" @@ -410,6 +415,10 @@ msgstr "" msgid "_New Window" msgstr "_New Window" +#: src/kgx-window.ui:11 +msgid "_Fullscreen" +msgstr "_Fullscreen" + #: src/kgx-window.ui:23 msgid "_Show All Tabs" msgstr "_Show All Tabs" diff --git a/src/help-overlay.ui b/src/help-overlay.ui index b53ee42..ea46fb4 100644 --- a/src/help-overlay.ui +++ b/src/help-overlay.ui @@ -16,6 +16,12 @@ New Window + + + win.fullscreen + Fullscreen + + diff --git a/src/kgx-application.c b/src/kgx-application.c index 2d2bfa4..cd0e4b0 100644 --- a/src/kgx-application.c +++ b/src/kgx-application.c @@ -151,6 +151,7 @@ static void kgx_application_startup (GApplication *app) { const char *const new_window_accels[] = { "n", NULL }; + const char *const fullscreen_accels[] = { "F11", NULL }; const char *const new_tab_accels[] = { "t", NULL }; const char *const close_tab_accels[] = { "w", NULL }; const char *const copy_accels[] = { "c", NULL }; @@ -180,6 +181,8 @@ kgx_application_startup (GApplication *app) gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.new-window", new_window_accels); + gtk_application_set_accels_for_action (GTK_APPLICATION (app), + "win.fullscreen", fullscreen_accels); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.new-tab", new_tab_accels); gtk_application_set_accels_for_action (GTK_APPLICATION (app), @@ -564,6 +567,14 @@ new_tab_activated (GSimpleAction *action, } } +static void +fullscreen_activated (GSimpleAction *action, + GVariant *parameter, + gpointer data) +{ + KgxWindow *self = KGX_WINDOW (data); + tgl_fullscreen(self); +} static void focus_activated (GSimpleAction *action, @@ -620,6 +631,7 @@ zoom_in_activated (GSimpleAction *action, static GActionEntry app_entries[] = { { "new-window", new_window_activated, NULL, NULL, NULL }, { "new-tab", new_tab_activated, NULL, NULL, NULL }, + { "fullscreen", fullscreen_activated, NULL, NULL, NULL }, { "focus-page", focus_activated, "u", NULL, NULL }, { "zoom-out", zoom_out_activated, NULL, NULL, NULL }, { "zoom-normal", zoom_normal_activated, NULL, NULL, NULL }, diff --git a/src/kgx-window.c b/src/kgx-window.c index 49569f5..b30983f 100644 --- a/src/kgx-window.c +++ b/src/kgx-window.c @@ -495,6 +495,14 @@ new_activated (GtkWidget *widget, NULL); } +static void +fullscreen_activated (GtkWidget *widget, + const char *action_name, + GVariant *parameter) +{ + KgxWindow *self = KGX_WINDOW (widget); + tgl_fullscreen(self); +} static void new_tab_activated (GtkWidget *widget, @@ -627,6 +635,7 @@ kgx_window_class_init (KgxWindowClass *klass) gtk_widget_class_bind_template_child_private (widget_class, KgxWindow, settings_binds); gtk_widget_class_bind_template_child_private (widget_class, KgxWindow, surface_binds); + gtk_widget_class_bind_template_callback (widget_class, and); gtk_widget_class_bind_template_callback (widget_class, zoom); gtk_widget_class_bind_template_callback (widget_class, create_tearoff_host); @@ -648,6 +657,10 @@ kgx_window_class_init (KgxWindowClass *klass) "win.new-window", NULL, new_activated); + gtk_widget_class_install_action (widget_class, + "win.fullscreen", + NULL, + fullscreen_activated); gtk_widget_class_install_action (widget_class, "win.new-tab", NULL, @@ -780,3 +793,57 @@ kgx_window_add_tab (KgxWindow *self, kgx_pages_add_page (KGX_PAGES (priv->pages), tab); kgx_pages_focus_page (KGX_PAGES (priv->pages), tab); } + +/** + * find_header_bar: + * @widget: the widget so search in + * + * Searches for a GtkHeaderBar inside a GtkWidget (and its childs) + * + * Returns: (NULL || HeaderBar) + */ +static GtkWidget* find_header_bar(GtkWidget *widget) { + GtkWidget *result = NULL, *child = NULL; + + if (GTK_IS_HEADER_BAR(widget)) + return widget; + + child = gtk_widget_get_first_child(widget); + while (child != NULL && result == NULL) { + result = find_header_bar(child); + child = gtk_widget_get_next_sibling(child); + } + + return result; +} + +/** + * tgl_fullscreen: + * @self: the #KgxWindow + * + * Toggles fullscreen + */ +void tgl_fullscreen (KgxWindow *self) +{ + GtkWindow *window; + GtkWidget *container, *header_bar; + + g_return_if_fail (KGX_IS_WINDOW (self)); + + window = GTK_WINDOW(self); + g_return_if_fail (GTK_IS_WINDOW (window)); + + container = gtk_window_get_child(window); + g_return_if_fail (GTK_IS_WIDGET (container)); + + header_bar = find_header_bar(container); + g_return_if_fail (GTK_IS_HEADER_BAR (header_bar)); + + if (!gtk_window_is_fullscreen(window)) { + gtk_widget_set_visible(header_bar, FALSE); + gtk_window_fullscreen (window); + } else { + gtk_window_unfullscreen(window); + gtk_widget_set_visible(header_bar, TRUE); + } +} diff --git a/src/kgx-window.h b/src/kgx-window.h index 73614c1..eb952a2 100644 --- a/src/kgx-window.h +++ b/src/kgx-window.h @@ -40,5 +40,6 @@ G_DECLARE_DERIVABLE_TYPE (KgxWindow, kgx_window, KGX, WINDOW, AdwApplicationWind GFile *kgx_window_get_working_dir (KgxWindow *self); void kgx_window_add_tab (KgxWindow *self, KgxTab *tab); +void tgl_fullscreen (KgxWindow *self); G_END_DECLS diff --git a/src/kgx-window.ui b/src/kgx-window.ui index 29d755b..504f558 100644 --- a/src/kgx-window.ui +++ b/src/kgx-window.ui @@ -17,6 +17,10 @@ _New Window win.new-window + + _Fullscreen + win.fullscreen +