Commit a17069e5 authored by Min Chen's avatar Min Chen Committed by Commit Bot

Add InputDeviceManager::GetUncategorizedDevices.

Add the function in InputDeviceManager to get all the uncategorized
input devices. The categorized input devices currently includes mouse,
keyboard, touchscreen and touchpad. After add this function, we can
also get the InputDevice like side volume button.

This is an initial change for side volume button control based on
screen orientation for convertibles.

Bug: 937907
Change-Id: I750e9919d47c11f8e881dc3f3db42bc0b0f1108c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1559247Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Commit-Queue: Min Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649706}
parent 198fb2cf
...@@ -57,6 +57,8 @@ void InputDeviceServer::OnInputDeviceConfigurationChanged( ...@@ -57,6 +57,8 @@ void InputDeviceServer::OnInputDeviceConfigurationChanged(
OnTouchpadDeviceConfigurationChanged(); OnTouchpadDeviceConfigurationChanged();
if (input_device_types & ui::InputDeviceEventObserver::kTouchscreen) if (input_device_types & ui::InputDeviceEventObserver::kTouchscreen)
OnTouchscreenDeviceConfigurationChanged(); OnTouchscreenDeviceConfigurationChanged();
if (input_device_types & ui::InputDeviceEventObserver::kUncategorized)
OnUncategorizedDeviceConfigurationChanged();
} }
void InputDeviceServer::OnKeyboardDeviceConfigurationChanged() { void InputDeviceServer::OnKeyboardDeviceConfigurationChanged() {
...@@ -112,6 +114,7 @@ void InputDeviceServer::SendDeviceListsComplete( ...@@ -112,6 +114,7 @@ void InputDeviceServer::SendDeviceListsComplete(
observer->OnDeviceListsComplete( observer->OnDeviceListsComplete(
manager_->GetKeyboardDevices(), manager_->GetTouchscreenDevices(), manager_->GetKeyboardDevices(), manager_->GetTouchscreenDevices(),
manager_->GetMouseDevices(), manager_->GetTouchpadDevices(), manager_->GetMouseDevices(), manager_->GetTouchpadDevices(),
manager_->GetUncategorizedDevices(),
manager_->AreTouchscreenTargetDisplaysValid()); manager_->AreTouchscreenTargetDisplaysValid());
} }
...@@ -129,4 +132,14 @@ void InputDeviceServer::OnTouchscreenDeviceConfigurationChanged() { ...@@ -129,4 +132,14 @@ void InputDeviceServer::OnTouchscreenDeviceConfigurationChanged() {
}); });
} }
void InputDeviceServer::OnUncategorizedDeviceConfigurationChanged() {
if (!manager_->AreDeviceListsComplete())
return;
auto& devices = manager_->GetUncategorizedDevices();
observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
observer->OnUncategorizedDeviceConfigurationChanged(devices);
});
}
} // namespace ws } // namespace ws
...@@ -51,6 +51,7 @@ class InputDeviceServer : public mojom::InputDeviceServer, ...@@ -51,6 +51,7 @@ class InputDeviceServer : public mojom::InputDeviceServer,
void OnTouchscreenDeviceConfigurationChanged(); void OnTouchscreenDeviceConfigurationChanged();
void OnMouseDeviceConfigurationChanged(); void OnMouseDeviceConfigurationChanged();
void OnTouchpadDeviceConfigurationChanged(); void OnTouchpadDeviceConfigurationChanged();
void OnUncategorizedDeviceConfigurationChanged();
mojo::BindingSet<mojom::InputDeviceServer> bindings_; mojo::BindingSet<mojom::InputDeviceServer> bindings_;
mojo::InterfacePtrSet<mojom::InputDeviceObserverMojo> observers_; mojo::InterfacePtrSet<mojom::InputDeviceObserverMojo> observers_;
......
...@@ -39,6 +39,11 @@ const std::vector<ui::InputDevice>& InputDeviceClient::GetTouchpadDevices() ...@@ -39,6 +39,11 @@ const std::vector<ui::InputDevice>& InputDeviceClient::GetTouchpadDevices()
return touchpad_devices_; return touchpad_devices_;
} }
const std::vector<ui::InputDevice>& InputDeviceClient::GetUncategorizedDevices()
const {
return uncategorized_devices_;
}
bool InputDeviceClient::AreDeviceListsComplete() const { bool InputDeviceClient::AreDeviceListsComplete() const {
return device_lists_complete_; return device_lists_complete_;
} }
...@@ -79,6 +84,12 @@ void InputDeviceClient::OnKeyboardDeviceConfigurationChanged( ...@@ -79,6 +84,12 @@ void InputDeviceClient::OnKeyboardDeviceConfigurationChanged(
NotifyObserversKeyboardDeviceConfigurationChanged(); NotifyObserversKeyboardDeviceConfigurationChanged();
} }
void InputDeviceClient::OnUncategorizedDeviceConfigurationChanged(
const std::vector<ui::InputDevice>& devices) {
uncategorized_devices_ = devices;
NotifyObserversUncategorizedDeviceConfigurationChanged();
}
void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged( void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged(
const std::vector<ui::TouchscreenDevice>& devices, const std::vector<ui::TouchscreenDevice>& devices,
bool touchscreen_target_display_ids_changed) { bool touchscreen_target_display_ids_changed) {
...@@ -116,6 +127,7 @@ void InputDeviceClient::OnDeviceListsComplete( ...@@ -116,6 +127,7 @@ void InputDeviceClient::OnDeviceListsComplete(
const std::vector<ui::TouchscreenDevice>& touchscreen_devices, const std::vector<ui::TouchscreenDevice>& touchscreen_devices,
const std::vector<ui::InputDevice>& mouse_devices, const std::vector<ui::InputDevice>& mouse_devices,
const std::vector<ui::InputDevice>& touchpad_devices, const std::vector<ui::InputDevice>& touchpad_devices,
const std::vector<ui::InputDevice>& uncategorized_devices,
bool are_touchscreen_target_displays_valid) { bool are_touchscreen_target_displays_valid) {
are_touchscreen_target_displays_valid_ = are_touchscreen_target_displays_valid_ =
are_touchscreen_target_displays_valid; are_touchscreen_target_displays_valid;
...@@ -133,6 +145,9 @@ void InputDeviceClient::OnDeviceListsComplete( ...@@ -133,6 +145,9 @@ void InputDeviceClient::OnDeviceListsComplete(
if (!touchpad_devices.empty()) if (!touchpad_devices.empty())
OnTouchpadDeviceConfigurationChanged(touchpad_devices); OnTouchpadDeviceConfigurationChanged(touchpad_devices);
if (!uncategorized_devices.empty())
OnUncategorizedDeviceConfigurationChanged(uncategorized_devices);
if (!device_lists_complete_) { if (!device_lists_complete_) {
device_lists_complete_ = true; device_lists_complete_ = true;
NotifyObserversDeviceListsComplete(); NotifyObserversDeviceListsComplete();
...@@ -170,4 +185,12 @@ void InputDeviceClient::NotifyObserversTouchpadDeviceConfigurationChanged() { ...@@ -170,4 +185,12 @@ void InputDeviceClient::NotifyObserversTouchpadDeviceConfigurationChanged() {
} }
} }
void InputDeviceClient::
NotifyObserversUncategorizedDeviceConfigurationChanged() {
for (auto& observer : observers_) {
observer.OnInputDeviceConfigurationChanged(
ui::InputDeviceEventObserver::kUncategorized);
}
}
} // namespace ws } // namespace ws
...@@ -39,6 +39,7 @@ class InputDeviceClient : public mojom::InputDeviceObserverMojo, ...@@ -39,6 +39,7 @@ class InputDeviceClient : public mojom::InputDeviceObserverMojo,
const override; const override;
const std::vector<ui::InputDevice>& GetMouseDevices() const override; const std::vector<ui::InputDevice>& GetMouseDevices() const override;
const std::vector<ui::InputDevice>& GetTouchpadDevices() const override; const std::vector<ui::InputDevice>& GetTouchpadDevices() const override;
const std::vector<ui::InputDevice>& GetUncategorizedDevices() const override;
bool AreDeviceListsComplete() const override; bool AreDeviceListsComplete() const override;
bool AreTouchscreensEnabled() const override; bool AreTouchscreensEnabled() const override;
bool AreTouchscreenTargetDisplaysValid() const override; bool AreTouchscreenTargetDisplaysValid() const override;
...@@ -61,11 +62,14 @@ class InputDeviceClient : public mojom::InputDeviceObserverMojo, ...@@ -61,11 +62,14 @@ class InputDeviceClient : public mojom::InputDeviceObserverMojo,
const std::vector<ui::InputDevice>& devices) override; const std::vector<ui::InputDevice>& devices) override;
void OnTouchpadDeviceConfigurationChanged( void OnTouchpadDeviceConfigurationChanged(
const std::vector<ui::InputDevice>& devices) override; const std::vector<ui::InputDevice>& devices) override;
void OnUncategorizedDeviceConfigurationChanged(
const std::vector<ui::InputDevice>& devices) override;
void OnDeviceListsComplete( void OnDeviceListsComplete(
const std::vector<ui::InputDevice>& keyboard_devices, const std::vector<ui::InputDevice>& keyboard_devices,
const std::vector<ui::TouchscreenDevice>& touchscreen_devices, const std::vector<ui::TouchscreenDevice>& touchscreen_devices,
const std::vector<ui::InputDevice>& mouse_devices, const std::vector<ui::InputDevice>& mouse_devices,
const std::vector<ui::InputDevice>& touchpad_devices, const std::vector<ui::InputDevice>& touchpad_devices,
const std::vector<ui::InputDevice>& uncategorized_devices,
bool are_touchscreen_target_displays_valid) override; bool are_touchscreen_target_displays_valid) override;
void OnStylusStateChanged(ui::StylusState state) override; void OnStylusStateChanged(ui::StylusState state) override;
...@@ -76,6 +80,7 @@ class InputDeviceClient : public mojom::InputDeviceObserverMojo, ...@@ -76,6 +80,7 @@ class InputDeviceClient : public mojom::InputDeviceObserverMojo,
void NotifyObserversKeyboardDeviceConfigurationChanged(); void NotifyObserversKeyboardDeviceConfigurationChanged();
void NotifyObserversTouchscreenDeviceConfigurationChanged(); void NotifyObserversTouchscreenDeviceConfigurationChanged();
void NotifyObserversTouchpadDeviceConfigurationChanged(); void NotifyObserversTouchpadDeviceConfigurationChanged();
void NotifyObserversUncategorizedDeviceConfigurationChanged();
mojo::Binding<mojom::InputDeviceObserverMojo> binding_; mojo::Binding<mojom::InputDeviceObserverMojo> binding_;
...@@ -87,6 +92,7 @@ class InputDeviceClient : public mojom::InputDeviceObserverMojo, ...@@ -87,6 +92,7 @@ class InputDeviceClient : public mojom::InputDeviceObserverMojo,
std::vector<ui::TouchscreenDevice> touchscreen_devices_; std::vector<ui::TouchscreenDevice> touchscreen_devices_;
std::vector<ui::InputDevice> mouse_devices_; std::vector<ui::InputDevice> mouse_devices_;
std::vector<ui::InputDevice> touchpad_devices_; std::vector<ui::InputDevice> touchpad_devices_;
std::vector<ui::InputDevice> uncategorized_devices_;
bool device_lists_complete_ = false; bool device_lists_complete_ = false;
bool are_touchscreen_target_displays_valid_ = false; bool are_touchscreen_target_displays_valid_ = false;
......
...@@ -66,7 +66,7 @@ void InputDeviceClientTestApi::OnDeviceListsComplete() { ...@@ -66,7 +66,7 @@ void InputDeviceClientTestApi::OnDeviceListsComplete() {
if (ui::DeviceDataManager::instance_) if (ui::DeviceDataManager::instance_)
ui::DeviceDataManager::instance_->OnDeviceListsComplete(); ui::DeviceDataManager::instance_->OnDeviceListsComplete();
else else
GetInputDeviceClient()->OnDeviceListsComplete({}, {}, {}, {}, false); GetInputDeviceClient()->OnDeviceListsComplete({}, {}, {}, {}, {}, false);
} }
void InputDeviceClientTestApi::SetKeyboardDevices( void InputDeviceClientTestApi::SetKeyboardDevices(
......
...@@ -25,6 +25,11 @@ interface InputDeviceObserverMojo { ...@@ -25,6 +25,11 @@ interface InputDeviceObserverMojo {
// Is called when the list of touchpads changes. // Is called when the list of touchpads changes.
OnTouchpadDeviceConfigurationChanged(array<ui.mojom.InputDevice> devices); OnTouchpadDeviceConfigurationChanged(array<ui.mojom.InputDevice> devices);
// Is called when the list of uncategorized input devices (besides keyboards,
// touchscreens, mice and touchpads) changes.
OnUncategorizedDeviceConfigurationChanged(
array<ui.mojom.InputDevice> devices);
// Is called once all of the input-device lists are available. This will // Is called once all of the input-device lists are available. This will
// always be the first call that an observer receives. // always be the first call that an observer receives.
OnDeviceListsComplete( OnDeviceListsComplete(
...@@ -32,6 +37,7 @@ interface InputDeviceObserverMojo { ...@@ -32,6 +37,7 @@ interface InputDeviceObserverMojo {
array<ui.mojom.TouchscreenDevice> touchscreen_devices, array<ui.mojom.TouchscreenDevice> touchscreen_devices,
array<ui.mojom.InputDevice> mouse_devices, array<ui.mojom.InputDevice> mouse_devices,
array<ui.mojom.InputDevice> touchpad_devices, array<ui.mojom.InputDevice> touchpad_devices,
array<ui.mojom.InputDevice> uncategorized_devices,
bool are_touchscreen_target_displays_valid); bool are_touchscreen_target_displays_valid);
// Is called when a stylus is removed or inserted into the device. // Is called when a stylus is removed or inserted into the device.
......
...@@ -149,6 +149,11 @@ const std::vector<InputDevice>& DeviceDataManager::GetTouchpadDevices() const { ...@@ -149,6 +149,11 @@ const std::vector<InputDevice>& DeviceDataManager::GetTouchpadDevices() const {
return touchpad_devices_; return touchpad_devices_;
} }
const std::vector<InputDevice>& DeviceDataManager::GetUncategorizedDevices()
const {
return uncategorized_devices_;
}
bool DeviceDataManager::AreDeviceListsComplete() const { bool DeviceDataManager::AreDeviceListsComplete() const {
return device_lists_complete_; return device_lists_complete_;
} }
...@@ -217,6 +222,17 @@ void DeviceDataManager::OnTouchpadDevicesUpdated( ...@@ -217,6 +222,17 @@ void DeviceDataManager::OnTouchpadDevicesUpdated(
NotifyObserversTouchpadDeviceConfigurationChanged(); NotifyObserversTouchpadDeviceConfigurationChanged();
} }
void DeviceDataManager::OnUncategorizedDevicesUpdated(
const std::vector<InputDevice>& devices) {
if (devices.size() == uncategorized_devices_.size() &&
std::equal(devices.begin(), devices.end(), uncategorized_devices_.begin(),
InputDeviceEquals)) {
return;
}
uncategorized_devices_ = devices;
NotifyObserversUncategorizedDeviceConfigurationChanged();
}
void DeviceDataManager::OnDeviceListsComplete() { void DeviceDataManager::OnDeviceListsComplete() {
if (!device_lists_complete_) { if (!device_lists_complete_) {
device_lists_complete_ = true; device_lists_complete_ = true;
...@@ -240,6 +256,10 @@ NOTIFY_OBSERVERS( ...@@ -240,6 +256,10 @@ NOTIFY_OBSERVERS(
NotifyObserversTouchpadDeviceConfigurationChanged(), NotifyObserversTouchpadDeviceConfigurationChanged(),
OnInputDeviceConfigurationChanged(InputDeviceEventObserver::kTouchpad)) OnInputDeviceConfigurationChanged(InputDeviceEventObserver::kTouchpad))
NOTIFY_OBSERVERS(
NotifyObserversUncategorizedDeviceConfigurationChanged(),
OnInputDeviceConfigurationChanged(InputDeviceEventObserver::kUncategorized))
NOTIFY_OBSERVERS( NOTIFY_OBSERVERS(
NotifyObserversTouchscreenDeviceConfigurationChanged(), NotifyObserversTouchscreenDeviceConfigurationChanged(),
OnInputDeviceConfigurationChanged(InputDeviceEventObserver::kTouchscreen)) OnInputDeviceConfigurationChanged(InputDeviceEventObserver::kTouchscreen))
......
...@@ -60,6 +60,7 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager ...@@ -60,6 +60,7 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager
const std::vector<InputDevice>& GetKeyboardDevices() const override; const std::vector<InputDevice>& GetKeyboardDevices() const override;
const std::vector<InputDevice>& GetMouseDevices() const override; const std::vector<InputDevice>& GetMouseDevices() const override;
const std::vector<InputDevice>& GetTouchpadDevices() const override; const std::vector<InputDevice>& GetTouchpadDevices() const override;
const std::vector<InputDevice>& GetUncategorizedDevices() const override;
bool AreDeviceListsComplete() const override; bool AreDeviceListsComplete() const override;
bool AreTouchscreensEnabled() const override; bool AreTouchscreensEnabled() const override;
bool AreTouchscreenTargetDisplaysValid() const override; bool AreTouchscreenTargetDisplaysValid() const override;
...@@ -80,6 +81,8 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager ...@@ -80,6 +81,8 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager
const std::vector<InputDevice>& devices) override; const std::vector<InputDevice>& devices) override;
void OnTouchpadDevicesUpdated( void OnTouchpadDevicesUpdated(
const std::vector<InputDevice>& devices) override; const std::vector<InputDevice>& devices) override;
void OnUncategorizedDevicesUpdated(
const std::vector<InputDevice>& devices) override;
void OnDeviceListsComplete() override; void OnDeviceListsComplete() override;
void OnStylusStateChanged(StylusState state) override; void OnStylusStateChanged(StylusState state) override;
...@@ -96,6 +99,7 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager ...@@ -96,6 +99,7 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager
void NotifyObserversKeyboardDeviceConfigurationChanged(); void NotifyObserversKeyboardDeviceConfigurationChanged();
void NotifyObserversMouseDeviceConfigurationChanged(); void NotifyObserversMouseDeviceConfigurationChanged();
void NotifyObserversTouchpadDeviceConfigurationChanged(); void NotifyObserversTouchpadDeviceConfigurationChanged();
void NotifyObserversUncategorizedDeviceConfigurationChanged();
void NotifyObserversDeviceListsComplete(); void NotifyObserversDeviceListsComplete();
void NotifyObserversStylusStateChanged(StylusState stylus_state); void NotifyObserversStylusStateChanged(StylusState stylus_state);
...@@ -105,6 +109,7 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager ...@@ -105,6 +109,7 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager
std::vector<InputDevice> keyboard_devices_; std::vector<InputDevice> keyboard_devices_;
std::vector<InputDevice> mouse_devices_; std::vector<InputDevice> mouse_devices_;
std::vector<InputDevice> touchpad_devices_; std::vector<InputDevice> touchpad_devices_;
std::vector<InputDevice> uncategorized_devices_;
bool device_lists_complete_ = false; bool device_lists_complete_ = false;
base::ObserverList<InputDeviceEventObserver>::Unchecked observers_; base::ObserverList<InputDeviceEventObserver>::Unchecked observers_;
......
...@@ -40,6 +40,12 @@ class EVENTS_DEVICES_EXPORT DeviceHotplugEventObserver { ...@@ -40,6 +40,12 @@ class EVENTS_DEVICES_EXPORT DeviceHotplugEventObserver {
virtual void OnTouchpadDevicesUpdated( virtual void OnTouchpadDevicesUpdated(
const std::vector<InputDevice>& devices) = 0; const std::vector<InputDevice>& devices) = 0;
// On a hotplug event this is called with the list of the available
// uncategorized input devices, which means not touchscreens, keyboards, mice
// and touchpads.
virtual void OnUncategorizedDevicesUpdated(
const std::vector<InputDevice>& devices) = 0;
// On completion of the initial startup scan. This means all of the above // On completion of the initial startup scan. This means all of the above
// OnDevicesUpdated() methods have been called with a complete list. // OnDevicesUpdated() methods have been called with a complete list.
virtual void OnDeviceListsComplete() = 0; virtual void OnDeviceListsComplete() = 0;
......
...@@ -22,6 +22,7 @@ class EVENTS_DEVICES_EXPORT InputDeviceEventObserver { ...@@ -22,6 +22,7 @@ class EVENTS_DEVICES_EXPORT InputDeviceEventObserver {
static constexpr uint8_t kMouse = 1 << 1; static constexpr uint8_t kMouse = 1 << 1;
static constexpr uint8_t kTouchpad = 1 << 2; static constexpr uint8_t kTouchpad = 1 << 2;
static constexpr uint8_t kTouchscreen = 1 << 3; static constexpr uint8_t kTouchscreen = 1 << 3;
static constexpr uint8_t kUncategorized = 1 << 4;
virtual ~InputDeviceEventObserver() {} virtual ~InputDeviceEventObserver() {}
......
...@@ -32,6 +32,10 @@ class EVENTS_DEVICES_EXPORT InputDeviceManager { ...@@ -32,6 +32,10 @@ class EVENTS_DEVICES_EXPORT InputDeviceManager {
virtual const std::vector<InputDevice>& GetMouseDevices() const = 0; virtual const std::vector<InputDevice>& GetMouseDevices() const = 0;
virtual const std::vector<InputDevice>& GetTouchpadDevices() const = 0; virtual const std::vector<InputDevice>& GetTouchpadDevices() const = 0;
// Returns all the uncategorized input devices, which means input devices
// besides keyboards, touchscreens, mice and touchpads.
virtual const std::vector<InputDevice>& GetUncategorizedDevices() const = 0;
virtual bool AreDeviceListsComplete() const = 0; virtual bool AreDeviceListsComplete() const = 0;
virtual bool AreTouchscreensEnabled() const = 0; virtual bool AreTouchscreensEnabled() const = 0;
......
...@@ -183,6 +183,8 @@ class EVENTS_OZONE_EVDEV_EXPORT DeviceEventDispatcherEvdev { ...@@ -183,6 +183,8 @@ class EVENTS_OZONE_EVDEV_EXPORT DeviceEventDispatcherEvdev {
virtual void DispatchStylusStateChanged(StylusState stylus_state) = 0; virtual void DispatchStylusStateChanged(StylusState stylus_state) = 0;
virtual void DispatchGamepadDevicesUpdated( virtual void DispatchGamepadDevicesUpdated(
const std::vector<InputDevice>& devices) = 0; const std::vector<InputDevice>& devices) = 0;
virtual void DispatchUncategorizedDevicesUpdated(
const std::vector<InputDevice>& devices) = 0;
}; };
} // namespace ui } // namespace ui
......
...@@ -78,6 +78,10 @@ class TestDeviceEventDispatcherEvdev : public DeviceEventDispatcherEvdev { ...@@ -78,6 +78,10 @@ class TestDeviceEventDispatcherEvdev : public DeviceEventDispatcherEvdev {
const std::vector<InputDevice>& devices) override { const std::vector<InputDevice>& devices) override {
event_factory_evdev_->DispatchTouchpadDevicesUpdated(devices); event_factory_evdev_->DispatchTouchpadDevicesUpdated(devices);
} }
void DispatchUncategorizedDevicesUpdated(
const std::vector<InputDevice>& devices) override {
event_factory_evdev_->DispatchUncategorizedDevicesUpdated(devices);
}
void DispatchDeviceListsComplete() override { void DispatchDeviceListsComplete() override {
event_factory_evdev_->DispatchDeviceListsComplete(); event_factory_evdev_->DispatchDeviceListsComplete();
} }
......
...@@ -43,6 +43,18 @@ TEST(EventDeviceInfoTest, BasicCrosKeyboard) { ...@@ -43,6 +43,18 @@ TEST(EventDeviceInfoTest, BasicCrosKeyboard) {
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_INTERNAL, devinfo.device_type()); EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_INTERNAL, devinfo.device_type());
} }
TEST(EventDeviceInfoTest, SideVolumeButton) {
EventDeviceInfo devinfo;
EXPECT_TRUE(CapabilitiesToDeviceInfo(kSideVolumeButton, &devinfo));
EXPECT_FALSE(devinfo.HasKeyboard());
EXPECT_FALSE(devinfo.HasMouse());
EXPECT_FALSE(devinfo.HasTouchpad());
EXPECT_FALSE(devinfo.HasTouchscreen());
EXPECT_FALSE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
}
TEST(EventDeviceInfoTest, BasicCrosTouchscreen) { TEST(EventDeviceInfoTest, BasicCrosTouchscreen) {
EventDeviceInfo devinfo; EventDeviceInfo devinfo;
EXPECT_TRUE(CapabilitiesToDeviceInfo(kLinkTouchscreen, &devinfo)); EXPECT_TRUE(CapabilitiesToDeviceInfo(kLinkTouchscreen, &devinfo));
......
...@@ -760,6 +760,28 @@ const DeviceCapabilities kIlitekTP = { ...@@ -760,6 +760,28 @@ const DeviceCapabilities kIlitekTP = {
base::size(kIlitekTPAbsAxes), base::size(kIlitekTPAbsAxes),
}; };
const DeviceCapabilities kSideVolumeButton = {
/* path */
"/sys/devices/pci0000:00/0000:00:1f.0/PNP0C09:00/GOOG0004:00/GOOG0007:00/"
"input/input5/event4",
/* name */ "cros_ec_buttons",
/* phys */ "GOOG0004:00/input1",
/* uniq */ "",
/* bustype */ "0006",
/* vendor */ "0000",
/* product */ "0000",
/* version */ "0001",
/* prop */ "0",
/* ev */ "100023",
/* key */ "1c000000000000 0",
/* rel */ "0",
/* abs */ "0",
/* msc */ "0",
/* sw */ "1",
/* led */ "0",
/* ff */ "0",
};
// NB: Please use the capture_device_capabilities.py script to add more // NB: Please use the capture_device_capabilities.py script to add more
// test data here. This will help ensure the data matches what the kernel // test data here. This will help ensure the data matches what the kernel
// reports for a real device and is entered correctly. // reports for a real device and is entered correctly.
......
...@@ -81,6 +81,7 @@ extern const DeviceCapabilities kHammerKeyboard; ...@@ -81,6 +81,7 @@ extern const DeviceCapabilities kHammerKeyboard;
extern const DeviceCapabilities kHammerTouchpad; extern const DeviceCapabilities kHammerTouchpad;
extern const DeviceCapabilities kIlitekTP_Mouse; extern const DeviceCapabilities kIlitekTP_Mouse;
extern const DeviceCapabilities kIlitekTP; extern const DeviceCapabilities kIlitekTP;
extern const DeviceCapabilities kSideVolumeButton;
} // namspace ui } // namspace ui
......
...@@ -140,6 +140,14 @@ class ProxyDeviceEventDispatcher : public DeviceEventDispatcherEvdev { ...@@ -140,6 +140,14 @@ class ProxyDeviceEventDispatcher : public DeviceEventDispatcherEvdev {
event_factory_evdev_, devices)); event_factory_evdev_, devices));
} }
void DispatchUncategorizedDevicesUpdated(
const std::vector<InputDevice>& devices) override {
ui_thread_runner_->PostTask(
FROM_HERE,
base::BindOnce(&EventFactoryEvdev::DispatchUncategorizedDevicesUpdated,
event_factory_evdev_, devices));
}
private: private:
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner_; scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner_;
base::WeakPtr<EventFactoryEvdev> event_factory_evdev_; base::WeakPtr<EventFactoryEvdev> event_factory_evdev_;
...@@ -409,6 +417,14 @@ void EventFactoryEvdev::DispatchStylusStateChanged(StylusState stylus_state) { ...@@ -409,6 +417,14 @@ void EventFactoryEvdev::DispatchStylusStateChanged(StylusState stylus_state) {
observer->OnStylusStateChanged(stylus_state); observer->OnStylusStateChanged(stylus_state);
} }
void EventFactoryEvdev::DispatchUncategorizedDevicesUpdated(
const std::vector<InputDevice>& devices) {
TRACE_EVENT0("evdev",
"EventFactoryEvdev::DispatchUncategorizedDevicesUpdated");
DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
observer->OnUncategorizedDevicesUpdated(devices);
}
void EventFactoryEvdev::DispatchGamepadDevicesUpdated( void EventFactoryEvdev::DispatchGamepadDevicesUpdated(
const std::vector<InputDevice>& devices) { const std::vector<InputDevice>& devices) {
TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchGamepadDevicesUpdated"); TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchGamepadDevicesUpdated");
......
...@@ -81,6 +81,8 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver, ...@@ -81,6 +81,8 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver,
const std::vector<TouchscreenDevice>& devices); const std::vector<TouchscreenDevice>& devices);
void DispatchMouseDevicesUpdated(const std::vector<InputDevice>& devices); void DispatchMouseDevicesUpdated(const std::vector<InputDevice>& devices);
void DispatchTouchpadDevicesUpdated(const std::vector<InputDevice>& devices); void DispatchTouchpadDevicesUpdated(const std::vector<InputDevice>& devices);
void DispatchUncategorizedDevicesUpdated(
const std::vector<InputDevice>& devices);
void DispatchDeviceListsComplete(); void DispatchDeviceListsComplete();
void DispatchStylusStateChanged(StylusState stylus_state); void DispatchStylusStateChanged(StylusState stylus_state);
......
...@@ -156,6 +156,12 @@ std::unique_ptr<EventConverterEvdev> OpenInputDevice( ...@@ -156,6 +156,12 @@ std::unique_ptr<EventConverterEvdev> OpenInputDevice(
return CreateConverter(params, std::move(fd), devinfo); return CreateConverter(params, std::move(fd), devinfo);
} }
bool IsUncategorizedDevice(const EventConverterEvdev& converter) {
return !converter.HasTouchscreen() && !converter.HasKeyboard() &&
!converter.HasMouse() && !converter.HasTouchpad() &&
!converter.HasGamepad();
}
} // namespace } // namespace
InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( InputDeviceFactoryEvdev::InputDeviceFactoryEvdev(
...@@ -391,6 +397,9 @@ void InputDeviceFactoryEvdev::UpdateDirtyFlags( ...@@ -391,6 +397,9 @@ void InputDeviceFactoryEvdev::UpdateDirtyFlags(
if (converter->HasGamepad()) if (converter->HasGamepad())
gamepad_list_dirty_ = true; gamepad_list_dirty_ = true;
if (IsUncategorizedDevice(*converter))
uncategorized_list_dirty_ = true;
} }
void InputDeviceFactoryEvdev::NotifyDevicesUpdated() { void InputDeviceFactoryEvdev::NotifyDevicesUpdated() {
...@@ -406,6 +415,8 @@ void InputDeviceFactoryEvdev::NotifyDevicesUpdated() { ...@@ -406,6 +415,8 @@ void InputDeviceFactoryEvdev::NotifyDevicesUpdated() {
NotifyTouchpadDevicesUpdated(); NotifyTouchpadDevicesUpdated();
if (gamepad_list_dirty_) if (gamepad_list_dirty_)
NotifyGamepadDevicesUpdated(); NotifyGamepadDevicesUpdated();
if (uncategorized_list_dirty_)
NotifyUncategorizedDevicesUpdated();
if (!startup_devices_opened_) { if (!startup_devices_opened_) {
dispatcher_->DispatchDeviceListsComplete(); dispatcher_->DispatchDeviceListsComplete();
startup_devices_opened_ = true; startup_devices_opened_ = true;
...@@ -415,6 +426,7 @@ void InputDeviceFactoryEvdev::NotifyDevicesUpdated() { ...@@ -415,6 +426,7 @@ void InputDeviceFactoryEvdev::NotifyDevicesUpdated() {
mouse_list_dirty_ = false; mouse_list_dirty_ = false;
touchpad_list_dirty_ = false; touchpad_list_dirty_ = false;
gamepad_list_dirty_ = false; gamepad_list_dirty_ = false;
uncategorized_list_dirty_ = false;
} }
void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() {
...@@ -474,6 +486,16 @@ void InputDeviceFactoryEvdev::NotifyGamepadDevicesUpdated() { ...@@ -474,6 +486,16 @@ void InputDeviceFactoryEvdev::NotifyGamepadDevicesUpdated() {
dispatcher_->DispatchGamepadDevicesUpdated(gamepads); dispatcher_->DispatchGamepadDevicesUpdated(gamepads);
} }
void InputDeviceFactoryEvdev::NotifyUncategorizedDevicesUpdated() {
std::vector<InputDevice> uncategorized_devices;
for (auto it = converters_.begin(); it != converters_.end(); ++it) {
if (IsUncategorizedDevice(*(it->second)))
uncategorized_devices.push_back(it->second->input_device());
}
dispatcher_->DispatchUncategorizedDevicesUpdated(uncategorized_devices);
}
void InputDeviceFactoryEvdev::SetIntPropertyForOneType( void InputDeviceFactoryEvdev::SetIntPropertyForOneType(
const EventDeviceType type, const EventDeviceType type,
const std::string& name, const std::string& name,
......
...@@ -86,6 +86,7 @@ class EVENTS_OZONE_EVDEV_EXPORT InputDeviceFactoryEvdev { ...@@ -86,6 +86,7 @@ class EVENTS_OZONE_EVDEV_EXPORT InputDeviceFactoryEvdev {
void NotifyMouseDevicesUpdated(); void NotifyMouseDevicesUpdated();
void NotifyTouchpadDevicesUpdated(); void NotifyTouchpadDevicesUpdated();
void NotifyGamepadDevicesUpdated(); void NotifyGamepadDevicesUpdated();
void NotifyUncategorizedDevicesUpdated();
void SetIntPropertyForOneType(const EventDeviceType type, void SetIntPropertyForOneType(const EventDeviceType type,
const std::string& name, const std::string& name,
...@@ -117,6 +118,7 @@ class EVENTS_OZONE_EVDEV_EXPORT InputDeviceFactoryEvdev { ...@@ -117,6 +118,7 @@ class EVENTS_OZONE_EVDEV_EXPORT InputDeviceFactoryEvdev {
bool mouse_list_dirty_ = true; bool mouse_list_dirty_ = true;
bool touchpad_list_dirty_ = true; bool touchpad_list_dirty_ = true;
bool gamepad_list_dirty_ = true; bool gamepad_list_dirty_ = true;
bool uncategorized_list_dirty_ = true;
// Whether we have a list of devices that were present at startup. // Whether we have a list of devices that were present at startup.
bool startup_devices_enumerated_ = false; bool startup_devices_enumerated_ = false;
......
...@@ -159,6 +159,8 @@ class MockDeviceEventDispatcherEvdev : public DeviceEventDispatcherEvdev { ...@@ -159,6 +159,8 @@ class MockDeviceEventDispatcherEvdev : public DeviceEventDispatcherEvdev {
const std::vector<InputDevice>& devices) override {} const std::vector<InputDevice>& devices) override {}
void DispatchTouchpadDevicesUpdated( void DispatchTouchpadDevicesUpdated(
const std::vector<InputDevice>& devices) override {} const std::vector<InputDevice>& devices) override {}
void DispatchUncategorizedDevicesUpdated(
const std::vector<InputDevice>& devices) override {}
void DispatchDeviceListsComplete() override {} void DispatchDeviceListsComplete() override {}
void DispatchStylusStateChanged(StylusState stylus_state) override {} void DispatchStylusStateChanged(StylusState stylus_state) override {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment