Skip to content

Fix Windows GTK3 build - #1363

Open
LAfricain wants to merge 5 commits into
crosswire:masterfrom
LAfricain:test-nogtk2
Open

Fix Windows GTK3 build#1363
LAfricain wants to merge 5 commits into
crosswire:masterfrom
LAfricain:test-nogtk2

Conversation

@LAfricain

Copy link
Copy Markdown
Contributor

Windows GTK3 build (test/windows-build-gtk3)

Starting point

After moving to GTK3/GtkBuilder/WebKit1, two blocking issues showed up at runtime on Windows (tested via Wine): icons weren't rendering, and opening the Preferences dialog silently crashed the app. Several other issues surfaced and were fixed along the way.


1. Missing icons & Preferences crash

Diagnosis: The cause: win32/CMakeLists.txt installed the GTK3 DLLs but not three runtime resources GTK3 needs:

  1. The system icon theme (hicolor/Adwaita)
  2. gdk-pixbuf loaders
  3. Compiled GSettings schemas (used internally by GtkFileChooserButton in Preferences)

Missing 3 caused a fatal GLib-GIO-ERROR: No GSettings schemas are installed, killing the process on Preferences open.

Fix (win32/CMakeLists.txt): added install() rules for the icon theme, pixbuf loaders, and compiled schemas.

Follow-up bug: even with resources bundled, GTK/GLib didn't discover them automatically at runtime — needed GSETTINGS_SCHEMA_DIR and XDG_DATA_DIRS set explicitly. Added this in src/main/main.c, computed dynamically via xiphos_win32_get_subdir("share").

Regression 1: setting XDG_DATA_DIRS before the existing g_get_system_data_dirs() call (used for SWORD_PATH) redirected installed modules into the Xiphos install dir instead of the system location.

Regression 2 (root cause, fixed properly): g_get_system_data_dirs() caches its result for the life of the process on first call (documented GLib behavior). Calling it for SWORD_PATH — before or after setting XDG_DATA_DIRS — poisons that cache, and GTK's internal icon theme lookup (which uses the same cached call) never sees our override. Fixed by computing SWORD_PATH from PROGRAMDATA/ALLUSERSPROFILE directly instead of calling g_get_system_data_dirs() at all, so XDG_DATA_DIRS/GSETTINGS_SCHEMA_DIR can be set freely before gtk_init() without anything having poisoned the cache first.

Result: icons render correctly, Preferences opens without crashing, modules stay in the correct location. ✅


2. Editor ("studypad") crash — fatal strdup

Symptom: xiphos va s'arrêter sur une erreur strdup in gtktextview_editor.c:469, building "<html><body>%s</body></html>".

Diagnosis: On glibc (Linux), printf("%s", NULL) prints "(null)" and continues; on MSVCRT/UCRT (Windows/MinGW), passing NULL to %s aborts the process immediately. Two call sites to _load_text_into_buffer() could pass NULL text:

  • _load_file() — when reading a studypad file fails
  • editor_load_note() — when a note/bookmark has no content yet (e.g. brand-new note)

A third call site already guarded with text ? text : ""; applied the same pattern to the two unguarded ones.

Result: editor/studypad no longer crashes. ✅


3. Daily devotional: enable GTK3 calendar on Windows

Context: a #ifdef _WIN32 fallback showed a manual MM.DD text entry instead of the GtkCalendar popover, with the comment "Windows: GtkCalendar is broken." This was presumably true under the old GTK2/WebKit1 build.

Fix: removed the Windows-specific fallback in src/gtk/dictlex.c (widget creation #ifdef _WIN32/#else/#endif, and the #ifndef _WIN32 guard around the calendar/button signal connects), so Windows now uses the same calendar+popover UI as Linux. The entry_devotional widget is kept unshown as internal date storage, matching prior Linux behavior.

Result: calendar popover opens and date selection works. ✅

Known remaining cosmetic issue: the devotional date button shows as a blank/gray box — no visible label text (not even the initial "--") — though it's fully functional (clicking still opens the popover correctly, and the box size is fixed regardless of window resizing, ruling out a layout/reflow issue). This looks like a GTK3 "wimp" theme-engine text rendering quirk under Wine specifically, rather than an app bug — pending confirmation on native Windows (not yet tested outside Wine).

greg-hellings and others added 5 commits August 2, 2026 23:07
* Move to long-deprecated WEBKIT1 backend, but at least it gives us a
  shot at GTK3
* Use GTKTVEDITOR in the builds

TODO: Something is still pulling in gtk-2 in the images. That should be
sorted out before everything is fully merged
Setting XDG_DATA_DIRS before g_get_system_data_dirs() (used for
SWORD_PATH) changed where SWORD_PATH pointed, moving installed
modules into the Xiphos install dir instead of the usual system
location. Now GSETTINGS_SCHEMA_DIR/XDG_DATA_DIRS are set after
SWORD_PATH is computed, and XDG_DATA_DIRS appends to any existing
value instead of replacing it.
_load_text_into_buffer() builds "<html><body>%s</body></html>" via
g_strdup_printf() with the given text. Two call sites could pass NULL
(a studypad file that failed to read, or a note/bookmark with no
content yet). On glibc this silently printed "(null)"; on MSVCRT/UCRT
(Windows/MinGW) passing NULL to %s aborts the process immediately —
this was the reported "strdup" crash when opening the editor.

A third call site already guarded against this with text ? text : "";
apply the same pattern here.
Removes the Windows-specific fallback (manual MM.DD text entry) that
was added because GtkCalendar was presumably broken on Windows under
the previous GTK2/WebKit1 build. Windows now uses the same
calendar+popover UI as Linux; entry_devotional is kept unshown as
internal date storage, as it already was on Linux.
g_get_system_data_dirs() caches its result on first call, for the
lifetime of the process (documented GLib behavior). Calling it to
compute SWORD_PATH — regardless of whether that happens before or
after we set XDG_DATA_DIRS — permanently poisons the cache with
whichever value was current at that moment, and GTK's internal icon
theme lookup (which also goes through g_get_system_data_dirs())
inherits that cached value for the rest of the run.

The fix is to stop calling g_get_system_data_dirs() for SWORD_PATH
entirely, using ALLUSERSPROFILE/PROGRAMDATA directly instead (which
is what the original commented-out code already hinted at). This way
XDG_DATA_DIRS can be set freely before gtk_init() without anything
having poisoned the cache beforehand.
@greg-hellings

Copy link
Copy Markdown
Contributor

@karlkleinpaste If you have no objections, I'll merge this. If we don't get major bugs related to it, we can consider beginning the removal of GTK2 specific code at that point as nothing remaining would use GTK2 pathways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants