aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2022-10-08 11:29:51 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2022-10-08 11:29:51 +0200
commitb9f0781a6f43eed6e8ead2aa7250ecc312c90acc (patch)
tree7b3c6e43d5ae933c893908b59cd94082d9394d9a
parentc391eceb5af2e5f6ec2558ec130f854c8926367a (diff)
downloadlite-xl-master-2.0.tar.gz
lite-xl-master-2.0.zip
Fix AppImage working directory problemmaster-2.0
-rw-r--r--src/main.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index e0fcb107..f7fc34bb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -85,6 +85,21 @@ void set_macos_bundle_resources(lua_State *L);
#endif
#endif
+#if __linux__
+/* Because AppImages change the working directory before running the executable,
+** we need to change it back to the original one.
+** https://github.com/AppImage/AppImageKit/issues/172
+** https://github.com/AppImage/AppImageKit/pull/191 */
+static void fix_appimage_working_dir() {
+ char *appimage = getenv("APPIMAGE");
+ char *owd = (appimage ? getenv("OWD") : NULL);
+ if (owd) {
+ /* Ignoring any error since there is not much we can do. */
+ chdir(owd);
+ }
+}
+#endif
+
int main(int argc, char **argv) {
#ifdef _WIN32
HINSTANCE lib = LoadLibrary("user32.dll");
@@ -94,6 +109,10 @@ int main(int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
#endif
+#if __linux__
+ fix_appimage_working_dir();
+#endif
+
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_EnableScreenSaver();
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);