Skip to content

Commit 7f62add

Browse files
authored
Use libhandy for rounded corners (#180)
* Use libhandy for rounded corners Closes: #178
1 parent 84e5d48 commit 7f62add

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

linux/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ add_subdirectory(${FLUTTER_MANAGED_DIR})
4242
# System-level dependencies.
4343
find_package(PkgConfig REQUIRED)
4444
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
45+
pkg_check_modules(HANDY REQUIRED IMPORTED_TARGET libhandy-1)
4546

4647
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
4748

@@ -54,6 +55,7 @@ add_executable(${BINARY_NAME}
5455
apply_standard_settings(${BINARY_NAME})
5556
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
5657
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
58+
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::HANDY)
5759
add_dependencies(${BINARY_NAME} flutter_assemble)
5860
# Only the install-generated bundle's copy of the executable will launch
5961
# correctly, since the resources must in the right relative locations. To avoid

linux/my_application.cc

+17-31
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifdef GDK_WINDOWING_X11
55
#include <gdk/gdkx.h>
66
#endif
7+
#include <handy.h>
78

89
#include "flutter/generated_plugin_registrant.h"
910

@@ -17,35 +18,18 @@ G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
1718
// Implements GApplication::activate.
1819
static void my_application_activate(GApplication* application) {
1920
MyApplication* self = MY_APPLICATION(application);
20-
GtkWindow* window =
21-
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
22-
23-
// Use a header bar when running in GNOME as this is the common style used
24-
// by applications and is the setup most users will be using (e.g. Ubuntu
25-
// desktop).
26-
// If running on X and not using GNOME then just use a traditional title bar
27-
// in case the window manager does more exotic layout, e.g. tiling.
28-
// If running on Wayland assume the header bar will work (may need changing
29-
// if future cases occur).
30-
gboolean use_header_bar = TRUE;
31-
#ifdef GDK_WINDOWING_X11
32-
GdkScreen* screen = gtk_window_get_screen(window);
33-
if (GDK_IS_X11_SCREEN(screen)) {
34-
const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
35-
if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
36-
use_header_bar = FALSE;
37-
}
38-
}
39-
#endif
40-
if (use_header_bar) {
41-
GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
42-
gtk_widget_show(GTK_WIDGET(header_bar));
43-
gtk_header_bar_set_title(header_bar, "Ubuntu Settings");
44-
gtk_header_bar_set_show_close_button(header_bar, TRUE);
45-
gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
46-
} else {
47-
gtk_window_set_title(window, "Ubuntu Settings");
48-
}
21+
GtkWindow* window = GTK_WINDOW(hdy_application_window_new());
22+
gtk_window_set_application(window, GTK_APPLICATION(application));
23+
24+
GtkBox* box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
25+
gtk_widget_show(GTK_WIDGET(box));
26+
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(box));
27+
28+
HdyHeaderBar* header_bar = HDY_HEADER_BAR(hdy_header_bar_new());
29+
gtk_widget_show(GTK_WIDGET(header_bar));
30+
hdy_header_bar_set_title(header_bar, "Ubuntu Settings");
31+
hdy_header_bar_set_show_close_button(header_bar, TRUE);
32+
gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(header_bar), false, true, 0);
4933

5034
GdkGeometry geometry;
5135
geometry.min_width = 600;
@@ -60,7 +44,7 @@ static void my_application_activate(GApplication* application) {
6044

6145
FlView* view = fl_view_new(project);
6246
gtk_widget_show(GTK_WIDGET(view));
63-
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
47+
gtk_box_pack_end(GTK_BOX(box), GTK_WIDGET(view), true, true, 0);
6448

6549
fl_register_plugins(FL_PLUGIN_REGISTRY(view));
6650

@@ -80,6 +64,8 @@ static gboolean my_application_local_command_line(GApplication* application, gch
8064
return TRUE;
8165
}
8266

67+
hdy_init();
68+
8369
g_application_activate(application);
8470
*exit_status = 0;
8571

@@ -99,7 +85,7 @@ static void my_application_class_init(MyApplicationClass* klass) {
9985
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
10086
}
10187

102-
static void my_application_init(MyApplication* self) {}
88+
static void my_application_init(MyApplication* self) { }
10389

10490
MyApplication* my_application_new() {
10591
return MY_APPLICATION(g_object_new(my_application_get_type(),

0 commit comments

Comments
 (0)