Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix - [Linux] Fix keyboard grab when running on Wayland #158

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/unix/linux/x11/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <string.h>
#include <math.h>
#include <limits.h>
#include <dlfcn.h>

#include <unistd.h>

Expand Down Expand Up @@ -624,13 +625,80 @@ static Cursor app_create_empty_cursor(Display *display)
return cursor;
}

static void app_configure_xwayland()
{
typedef void *GSettings;
typedef void *GVariant;

typedef GSettings *(*g_settings_new_func)(const char *);
typedef bool (*g_settings_set_boolean_func)(GSettings *, const char *, bool);
typedef bool (*g_settings_set_value_func)(GSettings *, const char *, GVariant *);
typedef GVariant *(*g_variant_new_strv_func)(const char **, size_t);
typedef void (*g_object_unref_func)(void *);

GSettings *settings = NULL;
GVariant *value = NULL;

void *handle = dlopen("libgio-2.0.so", RTLD_LAZY);
if (!handle) {
MTY_Log("Failed to load libgio-2.0.so: %s", dlerror());
goto end;
}

#define G_LOAD(name) \
name##_func name = dlsym(handle, #name); \
if (name == NULL) { MTY_Log("Failed to resolve symbol: " #name); goto end; }

G_LOAD(g_settings_new);
G_LOAD(g_settings_set_boolean);
G_LOAD(g_settings_set_value);
G_LOAD(g_variant_new_strv);
G_LOAD(g_object_unref);

#undef G_LOAD

settings = g_settings_new("org.gnome.mutter.wayland");
if (!settings) {
MTY_Log("Failed to create GSettings object: org.gnome.mutter.wayland");
goto end;
}

if (!g_settings_set_boolean(settings, "xwayland-allow-grabs", true)) {
MTY_Log("Failed to set 'xwayland-allow-grabs' to true");
goto end;
}

const char *rules[] = {"parsecd", NULL};
value = g_variant_new_strv(rules, -1);
if (!value) {
MTY_Log("Failed to create GVariant for 'xwayland-grab-access-rules'");
goto end;
}

if (!g_settings_set_value(settings, "xwayland-grab-access-rules", value)) {
MTY_Log("Failed to set 'xwayland-grab-access-rules'");
goto end;
}

end:

if (value != NULL)
g_object_unref(value);
if (settings != NULL)
g_object_unref(settings);
if (handle != NULL)
dlclose(handle);
}

MTY_App *MTY_AppCreate(MTY_AppFlag flags, MTY_AppFunc appFunc, MTY_EventFunc eventFunc, void *opaque)
{
if (!libX11_global_init())
return NULL;

XInitThreads();

app_configure_xwayland();

bool r = true;
MTY_App *ctx = MTY_Alloc(1, sizeof(MTY_App));
ctx->hotkey = MTY_HashCreate(0);
Expand Down