Sun, 22 Sep 2024 16:39:10 +0200
add libadwaita toolkit option
configure | file | annotate | diff | comparison | revisions | |
make/project.xml | file | annotate | diff | comparison | revisions | |
ui/gtk/toolkit.c | file | annotate | diff | comparison | revisions | |
ui/gtk/toolkit.h | file | annotate | diff | comparison | revisions | |
ui/gtk/window.c | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/configure Wed Sep 18 22:54:50 2024 +0200 +++ b/configure Sun Sep 22 16:39:10 2024 +0200 @@ -72,7 +72,7 @@ Options: --debug add extra compile flags for debug builds --release add extra compile flags for release builds - --toolkit=(gtk4|gtk3|gtk2|gtk2legacy|qt5|qt4|motif) + --toolkit=(libadwaita|gtk4|gtk3|gtk2|gtk2legacy|qt5|qt4|motif) __EOF__ } @@ -382,6 +382,32 @@ dep_checked_gtk4=1 return 0 } +dependency_error_libadwaita() +{ + print_check_msg "$dep_checked_libadwaita" "checking for libadwaita... " + # dependency libadwaita + while true + do + if [ -z "$PKG_CONFIG" ]; then + break + fi + if test_pkg_config "libadwaita-1" "" "" "" ; then + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libadwaita-1`" + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libadwaita-1`" + else + break + fi + TEMP_CFLAGS="$TEMP_CFLAGS -DUI_GTK4 -DUI_LIBADWAITA" + TEMP_LDFLAGS="$TEMP_LDFLAGS -lpthread" + print_check_msg "$dep_checked_libadwaita" "yes\n" + dep_checked_libadwaita=1 + return 1 + done + + print_check_msg "$dep_checked_libadwaita" "no\n" + dep_checked_libadwaita=1 + return 0 +} dependency_error_motif() { print_check_msg "$dep_checked_motif" "checking for motif... " @@ -541,6 +567,21 @@ # # OPTION VALUES # +checkopt_toolkit_libadwaita() +{ + VERR=0 + if dependency_error_libadwaita ; then + VERR=1 + fi + if [ $VERR -ne 0 ]; then + return 1 + fi + cat >> "$TEMP_DIR/make.mk" << __EOF__ +TOOLKIT = gtk +GTKOBJ = draw_cairo.o +__EOF__ + return 0 +} checkopt_toolkit_gtk4() { VERR=0 @@ -719,6 +760,14 @@ echo "checking option toolkit = $OPT_TOOLKIT" if false; then false + elif [ "$OPT_TOOLKIT" = "libadwaita" ]; then + echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options + if checkopt_toolkit_libadwaita ; then + : + else + ERROR=1 + DEPENDENCIES_FAILED="option 'toolkit' $DEPENDENCIES_FAILED" + fi elif [ "$OPT_TOOLKIT" = "gtk4" ]; then echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options if checkopt_toolkit_gtk4 ; then
--- a/make/project.xml Wed Sep 18 22:54:50 2024 +0200 +++ b/make/project.xml Sun Sep 22 16:39:10 2024 +0200 @@ -3,7 +3,12 @@ <dependency> <lang>c</lang> </dependency> - + + <dependency name="libadwaita"> + <pkgconfig>libadwaita-1</pkgconfig> + <cflags>-DUI_GTK4 -DUI_LIBADWAITA</cflags> + <ldflags>-lpthread</ldflags> + </dependency> <dependency name="gtk4"> <pkgconfig>gtk4</pkgconfig> <cflags>-DUI_GTK4</cflags> @@ -75,6 +80,11 @@ <target name="tk"> <option arg="toolkit"> + <value str="libadwaita"> + <dependencies>libadwaita</dependencies> + <make>TOOLKIT = gtk</make> + <make>GTKOBJ = draw_cairo.o</make> + </value> <value str="gtk4"> <dependencies>gtk4</dependencies> <make>TOOLKIT = gtk</make>
--- a/ui/gtk/toolkit.c Wed Sep 18 22:54:50 2024 +0200 +++ b/ui/gtk/toolkit.c Sun Sep 22 16:39:10 2024 +0200 @@ -46,8 +46,8 @@ #include <pthread.h> -#ifndef UI_GTK2 -static GtkApplication *app; +#ifdef UI_APPLICATION +UI_APPLICATION app; #endif static const char *application_name; @@ -123,14 +123,11 @@ #endif void ui_main() { -#ifndef UI_GTK2 +#ifdef UI_APPLICATION cxmutstr appid = cx_asprintf( "ui.%s", application_name ? application_name : "application1"); - - app = gtk_application_new( - appid.ptr, - G_APPLICATION_FLAGS_NONE); + app = UI_APPLICATION_NEW(appid.ptr); g_signal_connect (app, "startup", G_CALLBACK (app_startup), NULL); g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL); g_application_run(G_APPLICATION (app), 0, NULL); @@ -155,7 +152,7 @@ } GtkApplication* ui_get_application() { - return app; + return GTK_APPLICATION(app); } #endif
--- a/ui/gtk/toolkit.h Wed Sep 18 22:54:50 2024 +0200 +++ b/ui/gtk/toolkit.h Sun Sep 22 16:39:10 2024 +0200 @@ -38,7 +38,21 @@ #endif #pragma clang diagnostic ignored "-Wdeprecated-declarations" + + +#if GLIB_MAJOR_VERSION * 1000 + GLIB_MINOR_VERSION > 74 +#define UI_G_APPLICATION_FLAGS G_APPLICATION_DEFAULT_FLAGS +#else +#define UI_G_APPLICATION_FLAGS G_APPLICATION_FLAGS_NONE +#endif +#ifdef UI_LIBADWAITA +#define UI_APPLICATION AdwApplication* +#define UI_APPLICATION_NEW(id) adw_application_new(id, UI_G_APPLICATION_FLAGS) +#elif GTK_MAJOR_VERSION >= 3 +#define UI_APPLICATION GtkApplication* +#define UI_APPLICATION_NEW(id) gtk_application_new(id, UI_G_APPLICATION_FLAGS) +#endif #if GTK_MAJOR_VERSION >= 4 #define WINDOW_SHOW(window) gtk_window_present(GTK_WINDOW(window)) @@ -87,7 +101,7 @@ typedef enum UiOrientation UiOrientation; enum UiOrientation { UI_HORIZONTAL = 0, UI_VERTICAL }; -#ifndef UI_GTK2 +#ifdef UI_APPLICATION void ui_app_quit(); GtkApplication* ui_get_application(); #endif
--- a/ui/gtk/window.c Wed Sep 18 22:54:50 2024 +0200 +++ b/ui/gtk/window.c Sun Sep 22 16:39:10 2024 +0200 @@ -72,8 +72,10 @@ static UiObject* create_window(const char *title, void *window_data, UiBool simple) { CxMempool *mp = cxBasicMempoolCreate(256); UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); - -#ifndef UI_GTK2 + +#ifdef UI_LIBADWAITA + obj->widget = adw_application_window_new(ui_get_application()); +#elif !defined(UI_GTK2) obj->widget = gtk_application_window_new(ui_get_application()); #else obj->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); @@ -108,7 +110,14 @@ obj); GtkWidget *vbox = ui_gtk_vbox_new(0); -#if GTK_MAJOR_VERSION >= 4 +#ifdef UI_LIBADWAITA + GtkWidget *toolbar_view = adw_toolbar_view_new(); + adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), toolbar_view); + adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(toolbar_view), vbox); + + GtkWidget *headerbar = adw_header_bar_new(); + adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(toolbar_view), headerbar); +#elif GTK_MAJOR_VERSION >= 4 WINDOW_SET_CONTENT(obj->widget, vbox); #else gtk_container_add(GTK_CONTAINER(obj->widget), vbox);