Skip to content

Commit

Permalink
Run/RunWait: fix overwriting env LC_ALL
Browse files Browse the repository at this point in the history
launched programs were falsely forced to en_US instead of the user's configured environment
  • Loading branch information
phil294 committed Mar 21, 2023
1 parent ca10161 commit b4f7c36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/ahk_x11.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ fun main(argc : Int32, argv : UInt8**) : Int32
# Enforce 3 threads because less than that break the program. For now, this is the
# only way to enforce it. (1 = main, 2 = gui, 3 = ? probably timer)
LibC.setenv("CRYSTAL_WORKERS", "3", 1)

# https://github.com/crystal-lang/crystal/issues/11952#issuecomment-1216955886
LibC.setenv("ahk_x11_LC_ALL_backup", ENV["LC_ALL"], 1)
LibC.setenv("LC_ALL", "en_US.UTF-8", 1)

Crystal.main(argc, argv)
end

Expand Down
13 changes: 9 additions & 4 deletions src/cmd/misc/run.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ class Cmd::Misc::Run < Cmd::Base
params = args
end

# AppImage/linuxdeploy-plugin-gtk sets several env vars *for the main binary itself*
# but we need to prevent those overrides from being inherited by spawned sub processes
# because it changes appearance and can even prevent proper functionality in some cases
env = { "GTK_DATA_PREFIX" => nil, "GDK_BACKEND" => nil, "XDG_DATA_DIRS" => nil, "GSETTINGS_SCHEMA_DIR" => nil, "GI_TYPELIB_PATH" => nil, "GTK_EXE_PREFIX" => nil, "GTK_PATH" => nil, "GTK_IM_MODULE_FILE" => nil, "GDK_PIXBUF_MODULE_FILE" => nil }
env = {
# AppImage/linuxdeploy-plugin-gtk sets several env vars *for the main binary itself*
# but we need to prevent those overrides from being inherited by spawned sub processes
# because it changes appearance and can even prevent proper functionality in some cases
"GTK_DATA_PREFIX" => nil, "GDK_BACKEND" => nil, "XDG_DATA_DIRS" => nil, "GSETTINGS_SCHEMA_DIR" => nil, "GI_TYPELIB_PATH" => nil, "GTK_EXE_PREFIX" => nil, "GTK_PATH" => nil, "GTK_IM_MODULE_FILE" => nil, "GDK_PIXBUF_MODULE_FILE" => nil,
# Was force set to EN in ahk_str.cr, revert
"LC_ALL" => ENV["ahk_x11_LC_ALL_backup"],
"ahk_x11_LC_ALL_backup" => nil
}
begin
p = Process.new(cmd, params, chdir: chdir, output: stdout_m, error: stderr_m, env: env)
rescue e : IO::Error
Expand Down

0 comments on commit b4f7c36

Please sign in to comment.