Skip to content

Commit

Permalink
Use libhandy for rounded corners (#180)
Browse files Browse the repository at this point in the history
* Use libhandy for rounded corners

Closes: #178
  • Loading branch information
jpnurmi authored Dec 7, 2021
1 parent 84e5d48 commit 7f62add
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
2 changes: 2 additions & 0 deletions linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ add_subdirectory(${FLUTTER_MANAGED_DIR})
# System-level dependencies.
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
pkg_check_modules(HANDY REQUIRED IMPORTED_TARGET libhandy-1)

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

Expand All @@ -54,6 +55,7 @@ add_executable(${BINARY_NAME}
apply_standard_settings(${BINARY_NAME})
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::HANDY)
add_dependencies(${BINARY_NAME} flutter_assemble)
# Only the install-generated bundle's copy of the executable will launch
# correctly, since the resources must in the right relative locations. To avoid
Expand Down
48 changes: 17 additions & 31 deletions linux/my_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#include <handy.h>

#include "flutter/generated_plugin_registrant.h"

Expand All @@ -17,35 +18,18 @@ G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
// Implements GApplication::activate.
static void my_application_activate(GApplication* application) {
MyApplication* self = MY_APPLICATION(application);
GtkWindow* window =
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));

// Use a header bar when running in GNOME as this is the common style used
// by applications and is the setup most users will be using (e.g. Ubuntu
// desktop).
// If running on X and not using GNOME then just use a traditional title bar
// in case the window manager does more exotic layout, e.g. tiling.
// If running on Wayland assume the header bar will work (may need changing
// if future cases occur).
gboolean use_header_bar = TRUE;
#ifdef GDK_WINDOWING_X11
GdkScreen* screen = gtk_window_get_screen(window);
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, "Ubuntu Settings");
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, "Ubuntu Settings");
}
GtkWindow* window = GTK_WINDOW(hdy_application_window_new());
gtk_window_set_application(window, GTK_APPLICATION(application));

GtkBox* box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
gtk_widget_show(GTK_WIDGET(box));
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(box));

HdyHeaderBar* header_bar = HDY_HEADER_BAR(hdy_header_bar_new());
gtk_widget_show(GTK_WIDGET(header_bar));
hdy_header_bar_set_title(header_bar, "Ubuntu Settings");
hdy_header_bar_set_show_close_button(header_bar, TRUE);
gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(header_bar), false, true, 0);

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

FlView* view = fl_view_new(project);
gtk_widget_show(GTK_WIDGET(view));
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
gtk_box_pack_end(GTK_BOX(box), GTK_WIDGET(view), true, true, 0);

fl_register_plugins(FL_PLUGIN_REGISTRY(view));

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

hdy_init();

g_application_activate(application);
*exit_status = 0;

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

static void my_application_init(MyApplication* self) {}
static void my_application_init(MyApplication* self) { }

MyApplication* my_application_new() {
return MY_APPLICATION(g_object_new(my_application_get_type(),
Expand Down

0 comments on commit 7f62add

Please sign in to comment.