aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/interface-gtk
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2021-06-08 02:30:42 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2021-06-08 19:10:03 +0200
commit66c45d0d17feeaa86156a23df462b4612933cfef (patch)
treee058262eefa249f5c82e763b16cb614007239fe0 /src/interface-gtk
parent58dee5546e38a17f597bbd2da76d527eaa729282 (diff)
downloadsciteco-66c45d0d17feeaa86156a23df462b4612933cfef.tar.gz
Gtk UI: fixed lookup of icons and fallback.css on Windows
* Since we don't have an absolute and known installation directory, we should look for these files in the same directory as sciteco.exe. * For the time being, we look for them in $SCITECOCONFIG which defaults to that directory. * Cannot be a final solution as you may tweak $SCITECOCONFIG to fit an Unix-like environment (eg. set SCITECOCONFIG=$HOME). In such configurations it may also not be suitable to always look in the directory of sciteco.exe since that may be some /bin dir. Considering that GTK+ forces us to preserve some kind of UNIX-like directory hierarchy even for portable builds, we should perhaps install the icons into the hicolor icon theme. This would also simplify Debian packaging.
Diffstat (limited to 'src/interface-gtk')
-rw-r--r--src/interface-gtk/interface.c72
1 files changed, 39 insertions, 33 deletions
diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c
index 1e4e32b..9c16a5d 100644
--- a/src/interface-gtk/interface.c
+++ b/src/interface-gtk/interface.c
@@ -919,23 +919,35 @@ teco_interface_handle_key_press(guint keyval, guint state, GError **error)
gboolean
teco_interface_event_loop(GError **error)
{
- static const gchar *icon_files[] = {
- SCITECODATADIR G_DIR_SEPARATOR_S "sciteco-48.png",
- SCITECODATADIR G_DIR_SEPARATOR_S "sciteco-32.png",
- SCITECODATADIR G_DIR_SEPARATOR_S "sciteco-16.png",
- NULL
- };
+ teco_qreg_t *scitecoconfig_reg = teco_qreg_table_find(&teco_qreg_table_globals, "$SCITECOCONFIG", 14);
+ g_assert(scitecoconfig_reg != NULL);
+ g_auto(teco_string_t) scitecoconfig = {NULL, 0};
+ if (!scitecoconfig_reg->vtable->get_string(scitecoconfig_reg,
+ &scitecoconfig.data, &scitecoconfig.len, error))
+ return FALSE;
+ if (teco_string_contains(&scitecoconfig, '\0')) {
+ g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED,
+ "Null-character not allowed in filenames");
+ return FALSE;
+ }
- /*
- * Assign an icon to the window.
- *
- * FIXME: On Windows, it may be better to load the icon compiled
- * as a resource into the binary.
- */
+ static const gchar *icon_files[] = {"sciteco-48.png", "sciteco-32.png", "sciteco-16.png"};
GList *icon_list = NULL;
- for (const gchar **file = icon_files; *file; file++) {
- GdkPixbuf *icon_pixbuf = gdk_pixbuf_new_from_file(*file, NULL);
+ for (gint i = 0; i < G_N_ELEMENTS(icon_files); i++) {
+ /*
+ * FIXME: Looking for icon files in $SCITECOCONFIG on Windows makes
+ * sure they are usually found in the installation directory.
+ * Theoretically, $SCITECOCONFIG could be changed, though.
+ * Perhaps it would be cleaner to have a global variable pointing
+ * to the absolute directory of the binary.
+ */
+#ifdef G_OS_WIN32
+ g_autofree gchar *icon_path = g_build_filename(scitecoconfig.data, icon_files[i], NULL);
+#else
+ g_autofree gchar *icon_path = g_build_filename(SCITECODATADIR, icon_files[i], NULL);
+#endif
+ GdkPixbuf *icon_pixbuf = gdk_pixbuf_new_from_file(icon_path, NULL);
/* fail silently if there's a problem with one of the icons */
if (icon_pixbuf)
@@ -961,18 +973,19 @@ teco_interface_event_loop(GError **error)
GTK_STYLE_PROVIDER(teco_interface.css_var_provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- /* get path of $SCITECOCONFIG/.teco_css */
- teco_qreg_t *config_path_reg = teco_qreg_table_find(&teco_qreg_table_globals, "$SCITECOCONFIG", 14);
- g_assert(config_path_reg != NULL);
- g_auto(teco_string_t) config_path = {NULL, 0};
- if (!config_path_reg->vtable->get_string(config_path_reg, &config_path.data, &config_path.len, error))
- return FALSE;
- if (teco_string_contains(&config_path, '\0')) {
- g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED,
- "Null-character not allowed in filenames");
- return FALSE;
+ g_autofree gchar *user_css_file = g_build_filename(scitecoconfig.data, USER_CSS_FILE, NULL);
+ if (!g_file_test(user_css_file, G_FILE_TEST_IS_REGULAR)) {
+ /* use fallback CSS */
+ g_free(user_css_file);
+ /*
+ * FIXME: See above for icons.
+ */
+#ifdef G_OS_WIN32
+ user_css_file = g_build_filename(scitecoconfig.data, "fallback.css", NULL);
+#else
+ user_css_file = g_build_filename(SCITECODATADIR, "fallback.css", NULL);
+#endif
}
- g_autofree gchar *user_css_file = g_build_filename(config_path.data, USER_CSS_FILE, NULL);
GtkCssProvider *user_css_provider = gtk_css_provider_new();
/*
@@ -981,14 +994,7 @@ teco_interface_event_loop(GError **error)
* For the time being we just silently ignore parsing errors.
* They will be printed to stderr by Gtk anyway.
*/
- if (g_file_test(user_css_file, G_FILE_TEST_IS_REGULAR))
- /* open user CSS */
- gtk_css_provider_load_from_path(user_css_provider, user_css_file, NULL);
- else
- /* use fallback CSS */
- gtk_css_provider_load_from_path(user_css_provider,
- SCITECODATADIR G_DIR_SEPARATOR_S "fallback.css",
- NULL);
+ gtk_css_provider_load_from_path(user_css_provider, user_css_file, NULL);
gtk_style_context_add_provider_for_screen(default_screen,
GTK_STYLE_PROVIDER(user_css_provider),
GTK_STYLE_PROVIDER_PRIORITY_USER);