Use user provided xdg runtime directory

This commit is contained in:
Wisest_wizard 2021-08-16 08:51:31 +05:30 committed by Wisest_wizard
parent 7446d74d28
commit c131fec2da
2 changed files with 34 additions and 5 deletions

View File

@ -29,7 +29,7 @@ public:
void on_egl_init(); void on_egl_init();
void on_egl_uninit(); void on_egl_uninit();
LorieEGLHelper helper; LorieEGLHelper helper;
struct xkb_context *xkb_context = nullptr; struct xkb_context *xkb_context = nullptr;
@ -67,11 +67,11 @@ void LorieBackendAndroid::backend_init() {
return; return;
} }
} }
xkb_names.rules = strdup("evdev"); xkb_names.rules = strdup("evdev");
xkb_names.model = strdup("pc105"); xkb_names.model = strdup("pc105");
xkb_names.layout = strdup("us"); xkb_names.layout = strdup("us");
xkb_keymap = xkb_keymap_new_from_names(xkb_context, &xkb_names, (enum xkb_keymap_compile_flags) 0); xkb_keymap = xkb_keymap_new_from_names(xkb_context, &xkb_names, (enum xkb_keymap_compile_flags) 0);
if (xkb_keymap == nullptr) { if (xkb_keymap == nullptr) {
LOGE("failed to compile global XKB keymap\n"); LOGE("failed to compile global XKB keymap\n");
@ -179,9 +179,31 @@ static LorieBackendAndroid* fromLong(jlong v) {
return u.b; return u.b;
} }
jstring spname(JNIEnv *env) {
return env->NewStringUTF("sharedstore");
}
extern "C" JNIEXPORT jlong JNICALL extern "C" JNIEXPORT jlong JNICALL
JNI_DECLARE(LorieService, createLorieThread)(JNIEnv __unused *env, jobject __unused instance) { JNI_DECLARE(LorieService, createLorieThread)(JNIEnv *env, jobject __unused instance) {
setenv("XDG_RUNTIME_DIR", "/data/data/com.termux/files/usr/tmp", 1);
jclass spcls = env->FindClass("android/content/SharedPreferences");
jclass contextcls = env->FindClass("android/content/Context");
mainClass = env->NewGlobalRef(activity);
jmethodID mid = env->GetMethodID(contextcls, "getSharedPreferences",
"(Ljava/lang/String;I)Landroid/content/SharedPreferences;");
jmethodID midstring = env->GetMethodID(spcls, "getSring",
"(Ljava/lang/String;Z)Z");
jobject jobjectshared = env->CallObjectMethod(mainClass, mid, spname(env), 0);
jstring xdgcustpath = env->CallStringMethod(jobjectshared, mistring, objectname(env), "/data/data/com.termux/files/usr/tmp");
const char *pathxdg = env->GetStringUTFChars(xdgcustpath, 0);
env->ReleaseStringUTFChars(xdgcustpath, pathxdg);
setenv("XDG_RUNTIME_DIR", pathxdg, 1);
return (jlong) new LorieBackendAndroid; return (jlong) new LorieBackendAndroid;
} }

View File

@ -36,4 +36,11 @@
android:key="PIP" android:key="PIP"
android:summary="Show app in picture-in-picture mode when home button or recents button is pressed" /> android:summary="Show app in picture-in-picture mode when home button or recents button is pressed" />
<EditTextPreference
android:title="Custom XDG_RUNTIME_DIR"
android:defaultValue="/data/data/com.termux/files/usr/tmp"
android:key="CustXDG"
android:summary="Set the XDG runtime directory for wayland sockets"
android:dialogMessage="Please be careful here as setting the wrong directory may make the app not run as expected" />
</PreferenceScreen> </PreferenceScreen>