From 15d918f1fb7bf56a9138a322b7f6a8d3a3487aa2 Mon Sep 17 00:00:00 2001 From: deepend Date: Tue, 17 Feb 2026 22:19:50 -0700 Subject: [PATCH] =?UTF-8?q?Added=20Windows-side=20icon=20theme=20fallback?= =?UTF-8?q?=20logic=20in=20win32=5Fconfigure=5Ficon=5Ftheme=20that=20now?= =?UTF-8?q?=20checks=20(in=20addition=20to=20the=20existing=20/share?= =?UTF-8?q?/icons)=20these=20paths:=20=20=20=20=20ZOITECHAT=5FICON=5FPATH?= =?UTF-8?q?=20(user=20override=20env=20var),=20=20=20=20=20current=20worki?= =?UTF-8?q?ng=20directory=20+=20share/icons,=20=20=20=20=20argv[0]=20direc?= =?UTF-8?q?tory=20+=20share/icons.=20=20=20=20=20Valid=20directories=20are?= =?UTF-8?q?=20appended=20to=20GTK=E2=80=99s=20icon=20search=20path.=20Adde?= =?UTF-8?q?d=20diagnostic=20logging=20so=20startup=20clearly=20reports=20e?= =?UTF-8?q?ither=20the=20selected=20icon=20path=20source/path=20or=20that?= =?UTF-8?q?=20none=20of=20the=20expected=20locations=20were=20usable,=20to?= =?UTF-8?q?=20speed=20up=20Windows=20missing-icon=20triage.=20Reused/store?= =?UTF-8?q?d=20the=20computed=20argv[0]=20directory=20in=20fe=5Fargs=20(vi?= =?UTF-8?q?a=20win32=5Fargv0=5Fdir)=20so=20it=20can=20be=20used=20both=20f?= =?UTF-8?q?or=20chdir=20and=20for=20icon=20fallback=20resolution.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fe-gtk/fe-gtk.c | 70 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c index 07bab186..b7376750 100644 --- a/src/fe-gtk/fe-gtk.c +++ b/src/fe-gtk/fe-gtk.c @@ -117,6 +117,8 @@ create_msg_dialog (gchar *title, gchar *message) gtk_widget_destroy (dialog); } +static char *win32_argv0_dir; + static void win32_set_gsettings_schema_dir (void) { @@ -225,24 +227,66 @@ static void win32_configure_icon_theme (void) { GtkIconTheme *theme; + const char *env_icons_path; char *base_path; char *icons_path; + char *cwd_dir; + char *cwd_path; + char *argv0_icons_path; + const char *selected_source = NULL; + char *selected_path = NULL; + + #define WIN32_SET_ICON_PATH(source_name, path_value) \ + G_STMT_START { \ + if ((path_value) != NULL && g_file_test ((path_value), G_FILE_TEST_IS_DIR)) \ + { \ + gtk_icon_theme_append_search_path (theme, (path_value)); \ + if (selected_path == NULL) \ + { \ + selected_source = (source_name); \ + selected_path = g_strdup (path_value); \ + } \ + } \ + } G_STMT_END theme = gtk_icon_theme_get_default (); if (!theme) return; + env_icons_path = g_getenv ("ZOITECHAT_ICON_PATH"); + if (env_icons_path && *env_icons_path) + WIN32_SET_ICON_PATH ("ZOITECHAT_ICON_PATH", env_icons_path); + base_path = g_win32_get_package_installation_directory_of_module (NULL); - if (!base_path) - return; + if (base_path) + { + icons_path = g_build_filename (base_path, "share", "icons", NULL); + WIN32_SET_ICON_PATH ("module base", icons_path); + g_free (icons_path); + } - icons_path = g_build_filename (base_path, "share", "icons", NULL); + cwd_dir = g_get_current_dir (); + cwd_path = g_build_filename (cwd_dir, "share", "icons", NULL); + WIN32_SET_ICON_PATH ("current working directory", cwd_path); + g_free (cwd_path); + g_free (cwd_dir); - if (g_file_test (icons_path, G_FILE_TEST_IS_DIR)) - gtk_icon_theme_append_search_path (theme, icons_path); + if (win32_argv0_dir) + { + argv0_icons_path = g_build_filename (win32_argv0_dir, "share", "icons", NULL); + WIN32_SET_ICON_PATH ("argv[0] directory", argv0_icons_path); + g_free (argv0_icons_path); + } - g_free (icons_path); + if (selected_path) + g_message ("win32_configure_icon_theme: selected icon path (%s): %s", selected_source, selected_path); + else + g_message ("win32_configure_icon_theme: no usable icon path found (checked ZOITECHAT_ICON_PATH, module base/share/icons, cwd/share/icons, argv[0]/share/icons)"); + + g_free (selected_path); g_free (base_path); + + #undef WIN32_SET_ICON_PATH } #endif @@ -361,16 +405,10 @@ fe_args (int argc, char *argv[]) /* cuts can. So we have to set the current dir manually, to the path */ /* of the exe. */ { - char *tmp = g_strdup (argv[0]); - char *sl; - - sl = strrchr (tmp, G_DIR_SEPARATOR); - if (sl) - { - *sl = 0; - chdir (tmp); - } - g_free (tmp); + g_free (win32_argv0_dir); + win32_argv0_dir = g_path_get_dirname (argv[0]); + if (win32_argv0_dir) + chdir (win32_argv0_dir); } #endif