--- a/ui/gtk/toolkit.c Mon Jun 17 21:20:58 2024 +0200 +++ b/ui/gtk/toolkit.c Sun Sep 29 13:32:51 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; @@ -67,22 +67,24 @@ static int scale_factor = 1; UIEXPORT void ui_init(const char *appname, int argc, char **argv) { + application_name = appname; uic_init_global_context(); +#if GTK_MAJOR_VERSION >= 4 + gtk_init(); +#else gtk_init(&argc, &argv); - application_name = appname; +#endif ui_css_init(); - uic_docmgr_init(); - uic_toolbar_init(); - ui_image_init(); - uic_load_app_properties(); -#ifdef UI_SUPPORTS_SCALE +#if GTK_MAJOR_VERSION >= 4 + scale_factor = 1; // TODO +#elif defined(UI_SUPPORTS_SCALE) scale_factor = gdk_monitor_get_scale_factor( gdk_display_get_primary_monitor(gdk_display_get_default())); #endif @@ -121,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); @@ -153,17 +152,22 @@ } GtkApplication* ui_get_application() { - return app; + return GTK_APPLICATION(app); } #endif void ui_show(UiObject *obj) { uic_check_group_widgets(obj->ctx); +#if GTK_MAJOR_VERSION >= 4 + gtk_window_present(GTK_WINDOW(obj->widget)); +#elif GTK_MAJOR_VERSION <= 3 gtk_widget_show_all(obj->widget); +#endif } void ui_close(UiObject *obj) { - gtk_widget_destroy(obj->widget); + // TODO + //gtk_widget_destroy(obj->widget); } @@ -226,24 +230,38 @@ } void ui_set_show_all(UIWIDGET widget, int value) { + // TODO: gtk4 +#if GTK_MAJOR_VERSION <= 3 gtk_widget_set_no_show_all(widget, !value); +#endif } void ui_set_visible(UIWIDGET widget, int visible) { + // TODO: gtk4 +#if GTK_MAJOR_VERSION <= 3 if(visible) { gtk_widget_set_no_show_all(widget, FALSE); gtk_widget_show_all(widget); } else { gtk_widget_hide(widget); } +#endif } void ui_clipboard_set(char *str) { +#if GTK_MAJOR_VERSION >= 4 + // TODO: gtk4: needs widget +#else GtkClipboard *cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); gtk_clipboard_set_text(cb, str, strlen(str)); +#endif } char* ui_clipboard_get() { +#if GTK_MAJOR_VERSION >= 4 + // TODO: gtk4: needs widget + return NULL; +#else GtkClipboard *cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); char *str = gtk_clipboard_wait_for_text(cb); if(str) { @@ -253,6 +271,7 @@ } else { return NULL; } +#endif } int ui_get_scalefactor() { @@ -295,12 +314,44 @@ static GtkCssProvider* ui_gtk_css_provider; +#if GTK_MAJOR_VERSION == 4 +static const char *ui_gtk_css = +"#path-textfield-box {\n" +" background-color: alpha(currentColor, 0.1);" +" border-radius: 6px;" +" padding: 0px;" +"}\n" +".pathbar-extra-button {\n" +" border-top-right-radius: 6px;" +" border-bottom-right-radius: 6px;" +" border-top-left-radius: 0px;" +" border-bottom-left-radius: 0px;" +"}\n" +"#pathbar button {\n" +" margin: 3px;" +" border-radius: 4px;" +" padding-top: 0px;" +" padding-bottom: 0px;" +" padding-left: 8px;" +" padding-right: 8px;" +"}\n" +"#path-textfield-box entry {\n" +" background-color: #00000000;" +" border-top-left-radius: 6px;" +" border-bottom-left-radius: 6px;" +" border-top-right-radius: 0px;" +" border-bottom-right-radius: 0px;" +"}" +; + +#elif GTK_MAJOR_VERSION == 3 static const char *ui_gtk_css = "#path-textfield-box {" " background-color: @theme_base_color;" " border-radius: 5px;" " padding: 0px;" "}"; +#endif void ui_css_init(void) { ui_gtk_css_provider = gtk_css_provider_new(); @@ -325,7 +376,7 @@ #endif /* GTK_MINOR_VERSION < 12 */ GdkDisplay *display = gdk_display_get_default(); - gtk_style_context_add_provider_for_display(display, GTK_STYLE_PROVIDER(ui_gtk_css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER); + gtk_style_context_add_provider_for_display(display, GTK_STYLE_PROVIDER(ui_gtk_css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); #endif /* UI_GTK4 */ }