chromium/ui/ozone/platform/wayland/host/wayland_keyboard.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/ozone/platform/wayland/host/wayland_keyboard.h"

#include <keyboard-extension-unstable-v1-client-protocol.h>
#include <keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h>
#include <sys/mman.h>

#include <cstddef>
#include <cstring>
#include <utility>

#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted_memory.h"
#include "base/unguessable_token.h"
#include "ui/base/buildflags.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/dom_key.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_codes_posix.h"
#include "ui/events/ozone/keyboard/event_auto_repeat_handler.h"
#include "ui/events/ozone/layout/keyboard_layout_engine.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/types/event_type.h"
#include "ui/ozone/platform/wayland/common/wayland_util.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_seat.h"
#include "ui/ozone/platform/wayland/host/wayland_serial_tracker.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/ozone/public/platform_keyboard_hook.h"

#if BUILDFLAG(USE_XKBCOMMON)
#include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
#endif

namespace ui {

namespace {

bool IsModifierKey(int key) {}

class WaylandKeyboardHook final : public PlatformKeyboardHook {};

}  // namespace

class WaylandKeyboard::ZCRExtendedKeyboard {};

WaylandKeyboard::WaylandKeyboard(
    wl_keyboard* keyboard,
    zcr_keyboard_extension_v1* keyboard_extension_v1,
    WaylandConnection* connection,
    KeyboardLayoutEngine* layout_engine,
    Delegate* delegate)
    :{}

WaylandKeyboard::~WaylandKeyboard() {}

void WaylandKeyboard::OnUnhandledKeyEvent(const KeyEvent& key_event) {}

// Two different behaviors are currently implemented for KeyboardLock support
// on Wayland:
//
// 1. On Lacros, shortcuts are kept inhibited since the window initialization.
// Such approach relies on the Exo-specific zcr-keyboard-extension protocol
// extension, which allows Lacros (ozone/wayland based) to report back to the
// Wayland compositor that a given key was not processed by the client, giving
// it a chance of processing global shortcuts (even with a shortcuts inhibitor
// in place), which is not currently possible with standard Wayland protocol
// and extensions. That is also required to keep Lacros behaving just like Ash
// Chrome's classic browser.
//
// 2. Otherwise, keyboard shortcuts will be inhibited only when in fullscreen
// and when a WaylandKeyboardHook is in place for a given widget. See
// KeyboardLock spec for more details: https://wicg.github.io/keyboard-lock
//
// TODO(crbug.com/40229635): Revisit once this scenario changes.
std::unique_ptr<PlatformKeyboardHook> WaylandKeyboard::CreateKeyboardHook(
    WaylandWindow* window,
    std::optional<base::flat_set<DomCode>> dom_codes,
    PlatformKeyboardHook::KeyEventCallback callback) {}

wl::Object<zwp_keyboard_shortcuts_inhibitor_v1>
WaylandKeyboard::CreateShortcutsInhibitor(WaylandWindow* window) {}

// static
void WaylandKeyboard::OnKeymap(void* data,
                               wl_keyboard* keyboard,
                               uint32_t format,
                               int32_t fd,
                               uint32_t size) {}

// static
void WaylandKeyboard::OnEnter(void* data,
                              wl_keyboard* keyboard,
                              uint32_t serial,
                              wl_surface* surface,
                              wl_array* keys) {}

// static
void WaylandKeyboard::OnLeave(void* data,
                              wl_keyboard* keyboard,
                              uint32_t serial,
                              wl_surface* surface) {}

void WaylandKeyboard::OnKey(void* data,
                            wl_keyboard* keyboard,
                            uint32_t serial,
                            uint32_t time,
                            uint32_t key,
                            uint32_t state) {}

// static
void WaylandKeyboard::OnModifiers(void* data,
                                  wl_keyboard* keyboard,
                                  uint32_t serial,
                                  uint32_t depressed,
                                  uint32_t latched,
                                  uint32_t locked,
                                  uint32_t group) {}

// static
void WaylandKeyboard::OnRepeatInfo(void* data,
                                   wl_keyboard* keyboard,
                                   int32_t rate,
                                   int32_t delay) {}

// static
void WaylandKeyboard::OnSyncDone(void* data,
                                 struct wl_callback* callback,
                                 uint32_t time) {}

void WaylandKeyboard::FlushInput(base::OnceClosure closure) {}

void WaylandKeyboard::DispatchKey(unsigned int key,
                                  unsigned int scan_code,
                                  bool down,
                                  bool repeat,
                                  base::TimeTicks timestamp,
                                  int device_id,
                                  int flags) {}

void WaylandKeyboard::ProcessKey(uint32_t serial,
                                 uint32_t time,
                                 uint32_t key,
                                 uint32_t state,
                                 KeyEventKind kind) {}

void WaylandKeyboard::DispatchKey(unsigned int key,
                                  unsigned int scan_code,
                                  bool down,
                                  bool repeat,
                                  std::optional<uint32_t> serial,
                                  base::TimeTicks timestamp,
                                  int device_id,
                                  int flags,
                                  KeyEventKind kind) {}

}  // namespace ui