From fdcef2c099c11fa0856a3c9b9cb4905856e5ed8c Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Fri, 22 Nov 2024 19:11:44 +0100 Subject: [PATCH] Don't copy style. Try to load them locally, then globally, then run style-less --- src/x50ng/module.c | 53 ++++++++++++++++++++++++--------------------- src/x50ng/options.h | 6 +++++ src/x50ng/ui.c | 22 ++++++++++++++----- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/x50ng/module.c b/src/x50ng/module.c index a17947d..7a6d033 100644 --- a/src/x50ng/module.c +++ b/src/x50ng/module.c @@ -13,34 +13,37 @@ #include "x49gp.h" #include "options.h" -#ifdef X49GP_DATADIR -# define GLOBAL_DATADIR X49GP_DATADIR -#else -# define GLOBAL_DATADIR x49gp->progpath -#endif #define STATE_FILE_NAME "state" -static int copy_file_from_global_datadir_to_user_datadir( const char* filename ) -{ - GError* gerror = NULL; - if ( !g_file_test( g_build_filename( opt.datadir, filename, NULL ), G_FILE_TEST_EXISTS ) ) { - if ( opt.verbose ) - fprintf( stderr, "Copying %s to %s\n", g_build_filename( GLOBAL_DATADIR, filename, NULL ), - g_build_filename( opt.datadir, filename, NULL ) ); +/* #ifdef X49GP_DATADIR */ +/* # define GLOBAL_DATADIR X49GP_DATADIR */ +/* #else */ +/* # define GLOBAL_DATADIR x49gp->progpath */ +/* #endif */ - if ( !g_file_test( g_build_filename( GLOBAL_DATADIR, filename, NULL ), G_FILE_TEST_EXISTS ) ) - return EXIT_FAILURE; +/* static int copy_file_from_global_datadir_to_user_datadir( const char* filename ) */ +/* { */ +/* GError* gerror = NULL; */ +/* if ( !g_file_test( g_build_filename( opt.datadir, filename, NULL ), G_FILE_TEST_EXISTS ) ) { */ +/* if ( opt.verbose ) */ +/* fprintf( stderr, "Copying %s to %s\n", g_build_filename( GLOBAL_DATADIR, filename, NULL ), */ +/* g_build_filename( opt.datadir, filename, NULL ) ); */ - if ( !g_file_copy( g_file_new_build_filename( GLOBAL_DATADIR, filename, NULL ), - g_file_new_build_filename( opt.datadir, filename, NULL ), G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &gerror ) ) { - fprintf( stderr, "Unable to copy style: %s\n", gerror->message ); - g_error_free( gerror ); - return -errno; - } - } +/* if ( !g_file_test( g_build_filename( GLOBAL_DATADIR, filename, NULL ), G_FILE_TEST_EXISTS ) ) */ +/* return EXIT_FAILURE; */ - return EXIT_SUCCESS; -} +/* if ( !g_file_copy( g_file_new_build_filename( GLOBAL_DATADIR, filename, NULL ), */ +/* g_file_new_build_filename( opt.datadir, filename, NULL ), G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &gerror ) ) + */ +/* { */ +/* fprintf( stderr, "Unable to copy style: %s\n", gerror->message ); */ +/* g_error_free( gerror ); */ +/* return -errno; */ +/* } */ +/* } */ + +/* return EXIT_SUCCESS; */ +/* } */ int x49gp_modules_init( x49gp_t* x49gp ) { @@ -134,8 +137,8 @@ int x49gp_modules_load( x49gp_t* x49gp ) return error; } - copy_file_from_global_datadir_to_user_datadir( "style-50g.css" ); - copy_file_from_global_datadir_to_user_datadir( "style-49gp.css" ); + /* copy_file_from_global_datadir_to_user_datadir( "style-50g.css" ); */ + /* copy_file_from_global_datadir_to_user_datadir( "style-49gp.css" ); */ x49gp->state = g_key_file_new(); if ( NULL == x49gp->state ) { diff --git a/src/x50ng/options.h b/src/x50ng/options.h index 75c832a..ac7016a 100644 --- a/src/x50ng/options.h +++ b/src/x50ng/options.h @@ -15,6 +15,12 @@ # define PATCHLEVEL 0 #endif +#ifdef X49GP_DATADIR +# define GLOBAL_DATADIR X49GP_DATADIR +#else +# define GLOBAL_DATADIR x49gp->progpath +#endif + typedef enum { MODEL_49GP = 0, MODEL_50G } x50ng_model_t; struct options { diff --git a/src/x50ng/ui.c b/src/x50ng/ui.c index c4f02e3..8d70593 100644 --- a/src/x50ng/ui.c +++ b/src/x50ng/ui.c @@ -1689,14 +1689,26 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile ) #endif // Apply CSS - GtkCssProvider* style_provider = gtk_css_provider_new(); + char* style_full_path = g_build_filename( opt.datadir, opt.style_filename, NULL ); + if ( !g_file_test( style_full_path, G_FILE_TEST_EXISTS ) ) + style_full_path = g_build_filename( GLOBAL_DATADIR, opt.style_filename, NULL ); - gtk_css_provider_load_from_path( style_provider, g_build_filename( opt.datadir, opt.style_filename, NULL ), NULL ); + if ( !g_file_test( style_full_path, G_FILE_TEST_EXISTS ) ) + fprintf( stderr, "Can't load style %s neither from %s/%s nor form %s/%s\n", opt.style_filename, opt.datadir, opt.style_filename, + GLOBAL_DATADIR, opt.style_filename ); + else { + GtkCssProvider* style_provider = gtk_css_provider_new(); + gtk_css_provider_load_from_path( style_provider, g_build_filename( GLOBAL_DATADIR, opt.style_filename, NULL ), NULL ); - gtk_style_context_add_provider_for_screen( gdk_screen_get_default(), GTK_STYLE_PROVIDER( style_provider ), - GTK_STYLE_PROVIDER_PRIORITY_USER + 1 ); + gtk_style_context_add_provider_for_screen( gdk_screen_get_default(), GTK_STYLE_PROVIDER( style_provider ), + GTK_STYLE_PROVIDER_PRIORITY_USER + 1 ); - g_object_unref( style_provider ); + g_object_unref( style_provider ); + + if ( opt.verbose ) + fprintf( stderr, "Loaded style from %s\n", style_full_path ); + } + free( style_full_path ); // finally show the window gtk_widget_realize( ui->window );