chromium/chrome/browser/ui/webui/ash/settings/pages/device/input_device_settings/input_device_settings_provider.mojom

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

module ash.settings.mojom;

import "ash/public/mojom/input_device_settings.mojom";
import "ash/public/mojom/accelerator_actions.mojom";
import "ui/events/ash/mojom/meta_key.mojom";

// Represents the options for user in the dropdown of button customization.
struct ActionChoice {
  ActionType action_type;
  string name;
};

// Represents the different types of actions that are remappable to buttons
// within settings.
union ActionType {
  ash.mojom.AcceleratorAction accelerator_action;
  ash.mojom.StaticShortcutAction static_shortcut_action;
};

// Interface for observing keyboard settings changes in OSSettings SWA.
interface KeyboardSettingsObserver {
  // Notifies KeyboardSettingsObserver when the list of connected keyboards
  // and their settings are updated.
  OnKeyboardListUpdated(array<ash.mojom.Keyboard> keyboards);
  // Notifies KeyboardSettingsObserver whenever the set of policies which
  // control keyboard settings change.
  OnKeyboardPoliciesUpdated(ash.mojom.KeyboardPolicies policies);
};

// Interface for observing touchpad settings changes in OSSettings SWA.
interface TouchpadSettingsObserver {
  // Notifies TouchpadSettingsObserver when the list of connected touchpads
  // and their settings are updated.
  OnTouchpadListUpdated(array<ash.mojom.Touchpad> touchpads);
};

// Interface for observing point stick settings changes in OSSettings SWA.
interface PointingStickSettingsObserver {
  // Notifies PointingStickSettingsObserver when the list of connected
  // pointing sticks and their settings are updated.
  OnPointingStickListUpdated(array<ash.mojom.PointingStick> pointSticks);
};

// Interface for observing mouse settings changes in OSSettings SWA.
interface MouseSettingsObserver {
  // Notifies MouseSettingsObserver when the list of connected mice
  // and their settings are updated.
  OnMouseListUpdated(array<ash.mojom.Mouse> mice);
  // Notifies MouseSettingsObserver whenever the set of policies which
  // control mouse settings change.
  OnMousePoliciesUpdated(ash.mojom.MousePolicies policies);
};

// Interface for observing button presses from mice and graphics tablets while
// on the customize button page.
interface ButtonPressObserver {
  // Notifies ButtonPressObserver when a `button` is pressed on a device
  // currently being observed.
  OnButtonPressed(ash.mojom.Button button);
};

// Interface for observing graphics tablet settings changes in OSSettings SWA.
interface GraphicsTabletSettingsObserver {
  // Notifies GraphicsTabletSettingsObserver when the list of connected
  // graphics tablets and their settings are updated.
  OnGraphicsTabletListUpdated(array<ash.mojom.GraphicsTablet> graphics_tablets);
};

// Interface for observing keyboard brightness settings changes in OSSettings
// SWA.
interface KeyboardBrightnessObserver {
  // Notifies KeyboardBrightnessObserver when the keyboard brightness changed.
  OnKeyboardBrightnessChanged(double brightness_percent);
};

// Interface for observing keyboard ambient light sensor settings changes in
// OSSettings SWA.
interface KeyboardAmbientLightSensorObserver {
  // OnKeyboardAmbientLightSensorEnabledChanged calls are triggered when the
  // keyboard ambient light sensor is enabled or disabled.
  OnKeyboardAmbientLightSensorEnabledChanged(
    bool keyboard_ambient_light_sensor_enabled);
};

// Implemented by clients that wish to be notified when the lid state changes.
interface LidStateObserver {
  // OnLidStateChanged calls are triggered when the lid of the device opens or
  // closes.
  OnLidStateChanged(bool is_lid_open);
};

// Interface for fetching and configuring input device settings in OSSettings.
interface InputDeviceSettingsProvider {
  // Registers an observer which will be notified every time
  // a keyboard connects/disconnects or when settings change.
  // The observer which is registered is immediately informed
  // of the current state via its OnKeyboardListUpdated function.
  ObserveKeyboardSettings(pending_remote<KeyboardSettingsObserver> observer);
  // Registers an observer which will be notified every time
  // a touchpad connects/disconnects or when settings change.
  // The observer which is registered is immediately informed
  // of the current state via its ObserveTouchpadSettings function.
  ObserveTouchpadSettings(pending_remote<TouchpadSettingsObserver> observer);
  // Registers an observer which will be notified every time
  // a pointing stick connects/disconnects or when settings change.
  // The observer which is registered is immediately informed
  // of the current state via its ObservePointingStickSettings function.
  ObservePointingStickSettings(
      pending_remote<PointingStickSettingsObserver> observer);
  // Registers an observer which will be notified every time
  // a mouse connects/disconnects or when settings change.
  // The observer which is registered is immediately informed
  // of the current state via its ObserveMouseSettings function.
  ObserveMouseSettings(pending_remote<MouseSettingsObserver> observer);
  // Registers an observer which will be notified every time
  // a graphics tablet connects/disconnects or when settings change.
  // The observer which is registered is immediately informed
  // of the current state via its ObserveGraphicsTabletSettings function.
  ObserveGraphicsTabletSettings(
      pending_remote<GraphicsTabletSettingsObserver> observer);

  // Registers an observer which is notified every time a button is pressed on a
  // device that is currently being observed via the `StartObserving` method.
  ObserveButtonPresses(
      pending_remote<ButtonPressObserver> observer);

  // Registers an observer which is notified every time the keyboard brightness
  // changed. The observer which is registered is immediately informed of the
  // current state via its OnKeyboardBrightnessChanged function.
  ObserveKeyboardBrightness(
      pending_remote<KeyboardBrightnessObserver> observer);

  // Registers an observer for keyboard ambient light sensor changes and
  // returns whether the keyboard ambient light sensor is currently enabled.
  ObserveKeyboardAmbientLightSensor(
    pending_remote<KeyboardAmbientLightSensorObserver> observer);

  // Registers an observer for lid state changes and returns lid initial state.
  ObserveLidState(pending_remote<LidStateObserver> observer) =>
    (bool is_lid_open);

  // Restore the keyboard remappings to default based on its id.
  RestoreDefaultKeyboardRemappings(uint32 device_id);
  // Sets the keyboard settings based on its id.
  SetKeyboardSettings(uint32 device_id, ash.mojom.KeyboardSettings settings);
  // Sets the point stick settings based on its id.
  SetPointingStickSettings(
      uint32 device_id, ash.mojom.PointingStickSettings settings);
  // Sets the mouse settings based on its id.
  SetMouseSettings(uint32 device_id, ash.mojom.MouseSettings settings);
  // Sets the touchpad settings based on its id.
  SetTouchpadSettings(uint32 device_id, ash.mojom.TouchpadSettings settings);
  // Sets the graphics tablet settings based on its id.
  SetGraphicsTabletSettings(
      uint32 device_id, ash.mojom.GraphicsTabletSettings settings);

  // Sets the keyboard brightness to a specified level.
  SetKeyboardBrightness(double percent);
  // Sets whether to use ambient light sensor to automatically set the keyboard
  // brightness.
  SetKeyboardAmbientLightSensorEnabled(bool enabled);

  // Starts observing customizable button presses for the device with the given
  // `device_id`.
  StartObserving(uint32 device_id);
  // Stops observing customizable button presses for all devices.
  StopObserving();

  // Returns the set of actions that are valid for mouse button customization.
  GetActionsForMouseButtonCustomization() => (array<ActionChoice> options);

  // Returns the set of actions that are valid for graphics tablet button
  // customization.
  GetActionsForGraphicsTabletButtonCustomization() =>
      (array<ActionChoice> options);

  // Returns the meta key to display in the UI to represent the overall current
  // keyboard situation. This will only return either Launcher, Search, or
  // LauncherRefresh.
  GetMetaKeyToDisplay() => (ui.mojom.MetaKey meta_key);

  // Returns whether the internal keyboard has a backlight.
  HasKeyboardBacklight() => (bool has_keyboard_backlight);

  // Returns whether the internal keyboard has ambient light sensor.
  HasAmbientLightSensor() => (bool has_ambient_light_sensor);

  // Returns whether the internal keyboard support RGB lighting.
  IsRgbKeyboardSupported() => (bool is_rgb_keyboard_supported);

  // Tracks clicks on the "Keyboard Color" link in Keyboard Settings, that
  // navigates to the RGB Control in the Personalization Hub.
  RecordKeyboardColorLinkClicked();

  // Records metric each time user changes the keyboard brightness through
  // the slider.
  RecordKeyboardBrightnessChangeFromSlider(double percent);

  // Returns the device image as a Data URL. Returns null if the device doesn't
  // have a corresponding image.
  GetDeviceIconImage(string device_key) => (string? data_url);

  // Opens companion app for a connected peripheral.
  LaunchCompanionApp(string package_id);
};