fix(linux): use native window decorations instead of GTK header bar
This commit is contained in:
1 parent
4795062ccc
commit
d8543cc0f3
1 file changed
+10
-29
@@ -1,9 +1,6 @@
|
|||||||
#include "my_application.h"
|
#include "my_application.h"
|
||||||
|
|
||||||
#include <flutter_linux/flutter_linux.h>
|
#include <flutter_linux/flutter_linux.h>
|
||||||
#ifdef GDK_WINDOWING_X11
|
|
||||||
#include <gdk/gdkx.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "flutter/generated_plugin_registrant.h"
|
#include "flutter/generated_plugin_registrant.h"
|
||||||
|
|
||||||
@@ -25,32 +22,16 @@ static void my_application_activate(GApplication* application) {
|
|||||||
GtkWindow* window =
|
GtkWindow* window =
|
||||||
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
|
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
|
||||||
|
|
||||||
// Use a header bar when running in GNOME as this is the common style used
|
// Let the window manager draw the window decorations (server-side
|
||||||
// by applications and is the setup most users will be using (e.g. Ubuntu
|
// decorations) instead of installing a GTK header bar.
|
||||||
// desktop).
|
//
|
||||||
// If running on X and not using GNOME then just use a traditional title bar
|
// The stock Flutter template forces a GtkHeaderBar whenever it runs on
|
||||||
// in case the window manager does more exotic layout, e.g. tiling.
|
// Wayland. That header bar is a client-side decoration painted by GTK with
|
||||||
// If running on Wayland assume the header bar will work (may need changing
|
// Adwaita metrics, so on KDE Plasma (or any non-GNOME compositor) it looks
|
||||||
// if future cases occur).
|
// out of place and noticeably thicker than the native title bar. Relying on
|
||||||
gboolean use_header_bar = TRUE;
|
// the compositor gives the native Breeze/KWin decoration on Plasma, and the
|
||||||
#ifdef GDK_WINDOWING_X11
|
// desktop's own title bar everywhere else.
|
||||||
GdkScreen* screen = gtk_window_get_screen(window);
|
gtk_window_set_title(window, "KiriMemo");
|
||||||
if (GDK_IS_X11_SCREEN(screen)) {
|
|
||||||
const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
|
|
||||||
if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
|
|
||||||
use_header_bar = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (use_header_bar) {
|
|
||||||
GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
|
|
||||||
gtk_widget_show(GTK_WIDGET(header_bar));
|
|
||||||
gtk_header_bar_set_title(header_bar, "mobile");
|
|
||||||
gtk_header_bar_set_show_close_button(header_bar, TRUE);
|
|
||||||
gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
|
|
||||||
} else {
|
|
||||||
gtk_window_set_title(window, "mobile");
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_window_set_default_size(window, 1280, 720);
|
gtk_window_set_default_size(window, 1280, 720);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user