Bug 1903418 - Properly use the wayland code path when running under wayland. r=timhuang

Differential Revision: https://phabricator.services.mozilla.com/D214209
This commit is contained in:
Mike Hommey 2024-06-24 23:06:29 +00:00
Родитель 5a798245ea
Коммит 0b5aa260ab
1 изменённых файлов: 50 добавлений и 45 удалений

Просмотреть файл

@ -62,6 +62,7 @@
# include "nsMacUtilsImpl.h"
# include <CoreFoundation/CoreFoundation.h>
#elif defined(XP_LINUX)
# include "mozilla/WidgetUtilsGtk.h"
# include <gtk/gtk.h>
# ifdef MOZ_X11
# include <X11/XKBlib.h>
@ -308,56 +309,60 @@ void PopulateKeyboardLayout() {
TISGetInputSourceProperty(source, kTISPropertyInputSourceID));
CFStringGetCString(layoutID, layout, sizeof(layout), kCFStringEncodingUTF8);
layoutName.Assign(layout);
#elif defined(XP_LINUX)
#elif defined(XP_LINUX) && !defined(ANDROID)
if (mozilla::widget::GdkIsX11Display()) {
# if defined(MOZ_X11)
Display* display = XOpenDisplay(nullptr);
if (!display) {
return;
}
XkbDescRec* kbdDesc = XkbAllocKeyboard();
if (!kbdDesc) {
Display* display = XOpenDisplay(nullptr);
if (!display) {
return;
}
XkbDescRec* kbdDesc = XkbAllocKeyboard();
if (!kbdDesc) {
XCloseDisplay(display);
return;
}
XkbStateRec state;
XkbGetState(display, XkbUseCoreKbd, &state);
uint32_t group = state.group;
XkbGetNames(display, XkbGroupNamesMask, kbdDesc);
if (!kbdDesc->names || !kbdDesc->names->groups[group]) {
return;
}
char* layout = XGetAtomName(display, kbdDesc->names->groups[group]);
XkbFreeKeyboard(kbdDesc, 0, True);
XCloseDisplay(display);
return;
}
XkbStateRec state;
XkbGetState(display, XkbUseCoreKbd, &state);
uint32_t group = state.group;
XkbGetNames(display, XkbGroupNamesMask, kbdDesc);
if (!kbdDesc->names || !kbdDesc->names->groups[group]) {
return;
}
char* layout = XGetAtomName(display, kbdDesc->names->groups[group]);
XkbFreeKeyboard(kbdDesc, 0, True);
XCloseDisplay(display);
layoutName.Assign(layout);
# elif defined(MOZ_WAYLAND)
struct xkb_context* context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) {
return;
}
struct xkb_keymap* keymap =
xkb_keymap_new_from_names(context, NULL, XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) {
xkb_context_unref(context);
return;
}
const char* layout = xkb_keymap_layout_get_name(keymap, 0);
if (layout) {
layoutName.Assign(layout);
}
xkb_keymap_unref(keymap);
xkb_context_unref(context);
# endif
} else {
# if defined(MOZ_WAYLAND)
struct xkb_context* context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) {
return;
}
struct xkb_keymap* keymap = xkb_keymap_new_from_names(
context, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) {
xkb_context_unref(context);
return;
}
const char* layout = xkb_keymap_layout_get_name(keymap, 0);
if (layout) {
layoutName.Assign(layout);
}
xkb_keymap_unref(keymap);
xkb_context_unref(context);
# endif
}
#endif
if (layoutName.IsEmpty()) {