mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 06:43:32 +00:00
Bug 1828067 [Wayland] Migrate nsGtkKeyUtils wl_registry to nsWaylandDisplay r=emilio
To speed up start Firefox on Wayland don't use extra wl_registry connection in nsGtkKeyUtils but use the one from nsWaylandDisplay. In this patch we do: - Remove wl_registry handlers from KeymapWrapper but use the one in nsWaylandDisplay - Make wl_seat/wl_keyboard static and store obtained values here. We don't need to create KeymapWrapper object for it. - Support wl_seat/wl_keyboard removal by Wayland compositor. Differential Revision: https://phabricator.services.mozilla.com/D175464
This commit is contained in:
parent
79eedc0614
commit
068285e189
@ -63,6 +63,12 @@ Time KeymapWrapper::sLastRepeatableKeyTime = 0;
|
||||
KeymapWrapper::RepeatState KeymapWrapper::sRepeatState =
|
||||
KeymapWrapper::NOT_PRESSED;
|
||||
|
||||
#ifdef MOZ_WAYLAND
|
||||
wl_seat* KeymapWrapper::sSeat = nullptr;
|
||||
int KeymapWrapper::sSeatID = -1;
|
||||
wl_keyboard* KeymapWrapper::sKeyboard = nullptr;
|
||||
#endif
|
||||
|
||||
static const char* GetBoolName(bool aBool) { return aBool ? "TRUE" : "FALSE"; }
|
||||
|
||||
static const char* GetStatusName(nsEventStatus aStatus) {
|
||||
@ -326,17 +332,19 @@ KeymapWrapper::ModifierKey* KeymapWrapper::GetModifierKey(
|
||||
|
||||
/* static */
|
||||
KeymapWrapper* KeymapWrapper::GetInstance() {
|
||||
if (sInstance) {
|
||||
if (!sInstance) {
|
||||
sInstance = new KeymapWrapper();
|
||||
sInstance->Init();
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
sInstance = new KeymapWrapper();
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
#ifdef MOZ_WAYLAND
|
||||
void KeymapWrapper::EnsureInstance() { (void)GetInstance(); }
|
||||
|
||||
void KeymapWrapper::InitBySystemSettingsWayland() {
|
||||
MOZ_UNUSED(WaylandDisplayGet());
|
||||
}
|
||||
#endif
|
||||
|
||||
/* static */
|
||||
@ -363,8 +371,6 @@ KeymapWrapper::KeymapWrapper()
|
||||
InitXKBExtension();
|
||||
}
|
||||
#endif
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
void KeymapWrapper::Init() {
|
||||
@ -760,14 +766,13 @@ static const struct wl_keyboard_listener keyboard_listener = {
|
||||
|
||||
static void seat_handle_capabilities(void* data, struct wl_seat* seat,
|
||||
unsigned int caps) {
|
||||
static wl_keyboard* keyboard = nullptr;
|
||||
|
||||
wl_keyboard* keyboard = KeymapWrapper::GetKeyboard();
|
||||
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !keyboard) {
|
||||
keyboard = wl_seat_get_keyboard(seat);
|
||||
wl_keyboard_add_listener(keyboard, &keyboard_listener, nullptr);
|
||||
KeymapWrapper::SetKeyboard(keyboard);
|
||||
} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && keyboard) {
|
||||
wl_keyboard_destroy(keyboard);
|
||||
keyboard = nullptr;
|
||||
KeymapWrapper::ClearKeyboard();
|
||||
}
|
||||
}
|
||||
|
||||
@ -775,29 +780,6 @@ static const struct wl_seat_listener seat_listener = {
|
||||
seat_handle_capabilities,
|
||||
};
|
||||
|
||||
static void gdk_registry_handle_global(void* data, struct wl_registry* registry,
|
||||
uint32_t id, const char* interface,
|
||||
uint32_t version) {
|
||||
if (strcmp(interface, "wl_seat") == 0) {
|
||||
auto* seat =
|
||||
WaylandRegistryBind<wl_seat>(registry, id, &wl_seat_interface, 1);
|
||||
KeymapWrapper::SetSeat(seat);
|
||||
wl_seat_add_listener(seat, &seat_listener, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void gdk_registry_handle_global_remove(void* data,
|
||||
struct wl_registry* registry,
|
||||
uint32_t id) {}
|
||||
|
||||
static const struct wl_registry_listener keyboard_registry_listener = {
|
||||
gdk_registry_handle_global, gdk_registry_handle_global_remove};
|
||||
|
||||
void KeymapWrapper::InitBySystemSettingsWayland() {
|
||||
wl_display* display = WaylandDisplayGetWLDisplay();
|
||||
wl_registry_add_listener(wl_display_get_registry(display),
|
||||
&keyboard_registry_listener, this);
|
||||
}
|
||||
#endif
|
||||
|
||||
KeymapWrapper::~KeymapWrapper() {
|
||||
@ -2473,14 +2455,33 @@ void KeymapWrapper::GetFocusInfo(wl_surface** aFocusSurface,
|
||||
*aFocusSerial = keymapWrapper->mFocusSerial;
|
||||
}
|
||||
|
||||
void KeymapWrapper::SetSeat(wl_seat* aSeat) {
|
||||
KeymapWrapper* keymapWrapper = KeymapWrapper::GetInstance();
|
||||
keymapWrapper->mSeat = aSeat;
|
||||
void KeymapWrapper::SetSeat(wl_seat* aSeat, int aId) {
|
||||
sSeat = aSeat;
|
||||
sSeatID = aId;
|
||||
wl_seat_add_listener(aSeat, &seat_listener, nullptr);
|
||||
}
|
||||
|
||||
wl_seat* KeymapWrapper::GetSeat() {
|
||||
KeymapWrapper* keymapWrapper = KeymapWrapper::GetInstance();
|
||||
return keymapWrapper->mSeat;
|
||||
void KeymapWrapper::ClearSeat(int aId) {
|
||||
if (sSeatID == aId) {
|
||||
ClearKeyboard();
|
||||
sSeat = nullptr;
|
||||
sSeatID = -1;
|
||||
}
|
||||
}
|
||||
|
||||
wl_seat* KeymapWrapper::GetSeat() { return sSeat; }
|
||||
|
||||
void KeymapWrapper::SetKeyboard(wl_keyboard* aKeyboard) {
|
||||
sKeyboard = aKeyboard;
|
||||
}
|
||||
|
||||
wl_keyboard* KeymapWrapper::GetKeyboard() { return sKeyboard; }
|
||||
|
||||
void KeymapWrapper::ClearKeyboard() {
|
||||
if (sKeyboard) {
|
||||
wl_keyboard_destroy(sKeyboard);
|
||||
sKeyboard = nullptr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -213,9 +213,14 @@ class KeymapWrapper {
|
||||
static void SetFocusOut(wl_surface* aFocusSurface);
|
||||
static void GetFocusInfo(wl_surface** aFocusSurface, uint32_t* aFocusSerial);
|
||||
|
||||
static void SetSeat(wl_seat* aSeat);
|
||||
static void SetSeat(wl_seat* aSeat, int aId);
|
||||
static void ClearSeat(int aId);
|
||||
static wl_seat* GetSeat();
|
||||
|
||||
static void SetKeyboard(wl_keyboard* aKeyboard);
|
||||
static wl_keyboard* GetKeyboard();
|
||||
static void ClearKeyboard();
|
||||
|
||||
/**
|
||||
* EnsureInstance() is provided on Wayland to register Wayland callbacks
|
||||
* early.
|
||||
@ -234,7 +239,7 @@ class KeymapWrapper {
|
||||
*/
|
||||
static void Shutdown();
|
||||
|
||||
protected:
|
||||
private:
|
||||
/**
|
||||
* GetInstance() returns a KeymapWrapper instance.
|
||||
*
|
||||
@ -496,7 +501,9 @@ class KeymapWrapper {
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WAYLAND
|
||||
wl_seat* mSeat = nullptr;
|
||||
static wl_seat* sSeat;
|
||||
static int sSeatID;
|
||||
static wl_keyboard* sKeyboard;
|
||||
wl_surface* mFocusSurface = nullptr;
|
||||
uint32_t mFocusSerial = 0;
|
||||
#endif
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "mozilla/StaticPrefs_widget.h"
|
||||
#include "mozilla/Sprintf.h"
|
||||
#include "WidgetUtilsGtk.h"
|
||||
#include "nsGtkKeyUtils.h"
|
||||
|
||||
namespace mozilla::widget {
|
||||
|
||||
@ -196,11 +197,18 @@ static void global_registry_handler(void* data, wl_registry* registry,
|
||||
auto* activation = WaylandRegistryBind<xdg_activation_v1>(
|
||||
registry, id, &xdg_activation_v1_interface, 1);
|
||||
display->SetXdgActivation(activation);
|
||||
// Install keyboard handlers for main thread only
|
||||
} else if (NS_IsMainThread() && strcmp(interface, "wl_seat") == 0) {
|
||||
auto* seat =
|
||||
WaylandRegistryBind<wl_seat>(registry, id, &wl_seat_interface, 1);
|
||||
KeymapWrapper::SetSeat(seat, id);
|
||||
}
|
||||
}
|
||||
|
||||
static void global_registry_remover(void* data, wl_registry* registry,
|
||||
uint32_t id) {}
|
||||
uint32_t id) {
|
||||
KeymapWrapper::ClearSeat(id);
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
global_registry_handler, global_registry_remover};
|
||||
|
Loading…
Reference in New Issue
Block a user