Skip to content

Commit

Permalink
Do registration where it makes sense
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanGriffiths committed Jul 11, 2024
1 parent bf6c851 commit 8fdbce6
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 31 deletions.
File renamed without changes.
29 changes: 10 additions & 19 deletions src/platforms/evdev/libinput_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,19 @@ auto get_axis_source(libinput_event_pointer* pointer) -> MirPointerAxisSource
default: return mir_pointer_axis_source_none;
}
}
}

class LibInputDeviceLedObserver : public mir::input::LedObserver
void mie::LibInputDevice::leds_set(KeyboardLeds leds)
{
public:
explicit LibInputDeviceLedObserver(mie::LibInputDevice const* device) : device{device} {}

void leds_set(mir::input::KeyboardLeds leds) override
{
int led = 0;
if (contains(leds, mir::input::KeyboardLed::caps_lock))
led |= LIBINPUT_LED_CAPS_LOCK;
if (contains(leds, mir::input::KeyboardLed::num_lock))
led |= LIBINPUT_LED_NUM_LOCK;
if (contains(leds, mir::input::KeyboardLed::scroll_lock))
led |= LIBINPUT_LED_SCROLL_LOCK;

libinput_device_led_update(device->device(), static_cast<libinput_led>(led));
}
int led = 0;
if (contains(leds, mir::input::KeyboardLed::caps_lock))
led |= LIBINPUT_LED_CAPS_LOCK;
if (contains(leds, mir::input::KeyboardLed::num_lock))
led |= LIBINPUT_LED_NUM_LOCK;
if (contains(leds, mir::input::KeyboardLed::scroll_lock))
led |= LIBINPUT_LED_SCROLL_LOCK;

private:
mie::LibInputDevice const* device;
};
libinput_device_led_update(device(), static_cast<libinput_led>(led));
}

mie::LibInputDevice::LibInputDevice(std::shared_ptr<mi::InputReport> const& report, LibInputDevicePtr dev)
Expand Down
6 changes: 3 additions & 3 deletions src/platforms/evdev/libinput_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OutputInfo;
class InputReport;
namespace evdev
{
class LibInputDevice : public input::InputDevice
class LibInputDevice : public input::InputDevice, public mir::input::LedObserver
{
public:
LibInputDevice(std::shared_ptr<InputReport> const& report, LibInputDevicePtr dev);
Expand All @@ -59,7 +59,8 @@ class LibInputDevice : public input::InputDevice
void apply_settings(TouchpadSettings const&) override;
optional_value<TouchscreenSettings> get_touchscreen_settings() const override;
void apply_settings(TouchscreenSettings const&) override;
void associate_to_id(MirInputDeviceId id);

void leds_set(KeyboardLeds leds) override;

void process_event(libinput_event* event);
::libinput_device* device() const;
Expand Down Expand Up @@ -104,7 +105,6 @@ class LibInputDevice : public input::InputDevice
std::map<MirTouchId,ContactData> last_seen_properties;

void update_contact_data(ContactData &data, MirTouchAction action, libinput_event_touch* touch);
void try_stop_observing_leds();
};
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/platforms/evdev/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include "mir/input/input_device_registry.h"
#include "mir/input/input_report.h"
#include "mir/input/device.h"
#include "mir/fd.h"
#include "mir/raii.h"

Expand Down Expand Up @@ -432,9 +431,6 @@ void mie::Platform::device_added(libinput_device* dev)

input_device_registry->add_device(devices.back());

if (auto device = weak_device.lock())
new_device->associate_to_id(device->id());

log_info("Opened device: %s", describe(dev).c_str());
}
catch(...)
Expand Down
3 changes: 2 additions & 1 deletion src/server/input/default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ std::shared_ptr<mi::DefaultInputDeviceHub> mir::DefaultServerConfiguration::the_
the_input_reading_multiplexer(),
the_clock(),
the_key_mapper(),
the_server_status_listener());
the_server_status_listener(),
the_led_observer_registrar());

// lp:1675357: KeyRepeatDispatcher must be informed about removed input devices, otherwise
// pressed keys get repeated indefinitely
Expand Down
11 changes: 10 additions & 1 deletion src/server/input/default_input_device_hub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "mir/log.h"

#include "boost/throw_exception.hpp"
#include "mir/input/led_observer_registrar.h"
#include "mir/input/key_mapper.h"

#include <algorithm>
#include <atomic>
Expand Down Expand Up @@ -199,13 +201,15 @@ mi::DefaultInputDeviceHub::DefaultInputDeviceHub(
std::shared_ptr<dispatch::MultiplexingDispatchable> const& input_multiplexer,
std::shared_ptr<time::Clock> const& clock,
std::shared_ptr<mi::KeyMapper> const& key_mapper,
std::shared_ptr<mir::ServerStatusListener> const& server_status_listener)
std::shared_ptr<mir::ServerStatusListener> const& server_status_listener,
std::shared_ptr<LedObserverRegistrar> led_observer_registrar)
: seat{seat},
input_dispatchable{input_multiplexer},
device_queue(std::make_shared<dispatch::ActionQueue>()),
clock(clock),
key_mapper(key_mapper),
server_status_listener(server_status_listener),
led_observer_registrar{std::move(led_observer_registrar)},
device_id_generator{0}
{
input_dispatchable->add_watch(device_queue);
Expand Down Expand Up @@ -492,6 +496,11 @@ auto mi::DefaultInputDeviceHub::add_device(std::shared_ptr<InputDevice> const& d
seat->add_device(*handle);
dev->start(seat, input_dispatchable);

if (auto const observer = std::dynamic_pointer_cast<LedObserver>(device))
{
led_observer_registrar->register_interest(observer, handle->id());
}

return handle;
}
else
Expand Down
5 changes: 4 additions & 1 deletion src/server/input/default_input_device_hub.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace input
{
class InputSink;
class InputDeviceObserver;
class LedObserverRegistrar;
class DefaultDevice;
class Seat;
class KeyMapper;
Expand Down Expand Up @@ -86,7 +87,8 @@ class DefaultInputDeviceHub :
std::shared_ptr<dispatch::MultiplexingDispatchable> const& input_multiplexer,
std::shared_ptr<time::Clock> const& clock,
std::shared_ptr<KeyMapper> const& key_mapper,
std::shared_ptr<ServerStatusListener> const& server_status_listener);
std::shared_ptr<ServerStatusListener> const& server_status_listener,
std::shared_ptr<LedObserverRegistrar> led_observer_registrar);

// InputDeviceRegistry - calls from mi::Platform
auto add_device(std::shared_ptr<InputDevice> const& device) -> std::weak_ptr<Device> override;
Expand Down Expand Up @@ -118,6 +120,7 @@ class DefaultInputDeviceHub :
std::shared_ptr<time::Clock> const clock;
std::shared_ptr<KeyMapper> const key_mapper;
std::shared_ptr<ServerStatusListener> const server_status_listener;
std::shared_ptr<LedObserverRegistrar> const led_observer_registrar;
ThreadSafeList<std::shared_ptr<InputDeviceObserver>> observers;

/// Does not guarantee it's own threadsafety, non-const methods should not be called from multiple threads at once
Expand Down
5 changes: 4 additions & 1 deletion tests/integration-tests/input/test_single_seat_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "mir/test/doubles/mock_touch_visualizer.h"
#include "mir/test/doubles/mock_cursor_listener.h"
#include "mir/test/doubles/mock_input_manager.h"
#include "mir/test/doubles/mock_led_observer_registrar.h"
#include "mir/test/doubles/mock_seat_report.h"
#include "mir/test/doubles/mock_server_status_listener.h"
#include "mir/test/doubles/mock_scene_session.h"
Expand Down Expand Up @@ -97,6 +98,7 @@ struct SingleSeatInputDeviceHubSetup : ::testing::Test
ms::SessionContainer session_container;
ms::BroadcastingSessionEventSink session_event_sink;
mtd::FakeDisplayConfigurationObserverRegistrar display_config;
NiceMock<mtd::MockLedObserverRegistrar> led_observer_registrar;
mi::BasicSeat seat{mt::fake_shared(mock_dispatcher), mt::fake_shared(mock_visualizer),
mt::fake_shared(mock_cursor_listener), mt::fake_shared(display_config),
mt::fake_shared(key_mapper), mt::fake_shared(clock),
Expand All @@ -106,7 +108,8 @@ struct SingleSeatInputDeviceHubSetup : ::testing::Test
mt::fake_shared(multiplexer),
mt::fake_shared(clock),
mt::fake_shared(key_mapper),
mt::fake_shared(mock_status_listener)};
mt::fake_shared(mock_status_listener),
mt::fake_shared(led_observer_registrar)};
NiceMock<mtd::MockInputDeviceObserver> mock_observer;
mi::ConfigChanger changer{
mt::fake_shared(mock_input_manager),
Expand Down
5 changes: 4 additions & 1 deletion tests/unit-tests/input/test_default_input_device_hub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "mir/test/doubles/mock_input_seat.h"
#include "mir/test/doubles/mock_event_sink.h"
#include "mir/test/doubles/mock_key_mapper.h"
#include "mir/test/doubles/mock_led_observer_registrar.h"
#include "mir/test/doubles/mock_server_status_listener.h"
#include "mir/test/doubles/advanceable_clock.h"
#include "mir/test/fake_shared.h"
Expand Down Expand Up @@ -67,6 +68,7 @@ MATCHER_P(WithName, name,
struct InputDeviceHubTest : ::testing::Test
{
mir::dispatch::MultiplexingDispatchable multiplexer;
NiceMock<mtd::MockLedObserverRegistrar> led_observer_registrar;
NiceMock<mtd::MockInputSeat> mock_seat;
NiceMock<mtd::MockKeyMapper> mock_key_mapper;
NiceMock<mtd::MockServerStatusListener> mock_server_status_listener;
Expand All @@ -76,7 +78,8 @@ struct InputDeviceHubTest : ::testing::Test
mt::fake_shared(multiplexer),
mt::fake_shared(clock),
mt::fake_shared(mock_key_mapper),
mt::fake_shared(mock_server_status_listener)};
mt::fake_shared(mock_server_status_listener),
mt::fake_shared(led_observer_registrar)};
NiceMock<mtd::MockInputDeviceObserver> mock_observer;
NiceMock<mtd::MockInputDevice> device{"device","dev-1", mi::DeviceCapability::unknown};
NiceMock<mtd::MockInputDevice> another_device{"another_device","dev-2", mi::DeviceCapability::keyboard};
Expand Down

0 comments on commit 8fdbce6

Please sign in to comment.