Skip to content

Commit 474a8f0

Browse files
authored
Merge pull request #1 from InputActions/code-quality
make stuff movable
2 parents 012bd22 + 8eecccf commit 474a8f0

File tree

8 files changed

+49
-18
lines changed

8 files changed

+49
-18
lines changed

src/libinput-cpp/LibinputDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ QSizeF LibinputDevice::size() const
5959
return {width, height};
6060
}
6161

62-
std::unique_ptr<UdevDevice> LibinputDevice::udevDevice() const
62+
UdevDevice LibinputDevice::udevDevice() const
6363
{
64-
return std::make_unique<UdevDevice>(libinput_device_get_udev_device(m_device));
64+
return {libinput_device_get_udev_device(m_device)};
6565
}
6666

6767
}

src/libinput-cpp/LibinputDevice.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class LibinputDevice
3535
LibinputDevice(libinput_device *device);
3636
~LibinputDevice();
3737

38-
Q_DISABLE_COPY_MOVE(LibinputDevice);
39-
4038
libinput_device *raw() { return m_device; }
4139

4240
/**
@@ -56,7 +54,7 @@ class LibinputDevice
5654
/**
5755
* @see libinput_device_get_udev_device
5856
*/
59-
std::unique_ptr<UdevDevice> udevDevice() const;
57+
UdevDevice udevDevice() const;
6058

6159
/**
6260
* @param value true - LIBINPUT_CONFIG_TAP_ENABLED, false - LIBINPUT_CONFIG_TAP_DISABLED
@@ -65,6 +63,8 @@ class LibinputDevice
6563
void configTapSetEnabled(bool value);
6664

6765
private:
66+
Q_DISABLE_COPY_MOVE(LibinputDevice);
67+
6868
libinput_device *m_device;
6969
};
7070

src/libinput-cpp/LibinputEvent.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ LibinputEvent::LibinputEvent(libinput_event *event)
3030
{
3131
}
3232

33+
LibinputEvent::LibinputEvent(LibinputEvent &&other)
34+
{
35+
*this = std::move(other);
36+
}
37+
3338
LibinputEvent::~LibinputEvent()
3439
{
40+
if (!m_event) {
41+
return;
42+
}
43+
3544
libinput_event_destroy(m_event);
3645
}
3746

@@ -80,4 +89,10 @@ std::optional<LibinputTouchEvent> LibinputEvent::touchEvent() const
8089
return LibinputTouchEvent(event);
8190
}
8291

92+
LibinputEvent &LibinputEvent::operator=(LibinputEvent &&other)
93+
{
94+
std::swap(m_event, other.m_event);
95+
return *this;
96+
}
97+
8398
}

src/libinput-cpp/LibinputEvent.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ class LibinputEvent
3434
{
3535
public:
3636
LibinputEvent(libinput_event *event);
37+
LibinputEvent(LibinputEvent &&);
3738
~LibinputEvent();
3839

39-
Q_DISABLE_COPY_MOVE(LibinputEvent);
40-
4140
libinput_event_type type() const;
4241

4342
/**
@@ -61,8 +60,12 @@ class LibinputEvent
6160
*/
6261
std::optional<LibinputTouchEvent> touchEvent() const;
6362

63+
LibinputEvent &operator=(LibinputEvent &&);
64+
6465
private:
65-
libinput_event *m_event;
66+
Q_DISABLE_COPY(LibinputEvent);
67+
68+
libinput_event *m_event{};
6669
};
6770

6871
}

src/libinput-cpp/LibinputPathContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ void LibinputPathContext::dispatch()
8080
libinput_dispatch(m_libinput);
8181
}
8282

83-
std::unique_ptr<LibinputEvent> LibinputPathContext::getEvent()
83+
std::optional<LibinputEvent> LibinputPathContext::getEvent()
8484
{
8585
auto *event = libinput_get_event(m_libinput);
8686
if (!event) {
8787
return {};
8888
}
8989

90-
return std::make_unique<LibinputEvent>(event);
90+
return {event};
9191
}
9292

9393
int LibinputPathContext::openRestricted(const char *path, int flags, void *data)

src/libinput-cpp/LibinputPathContext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ class LibinputPathContext : public QObject
4242
* @see libinput_path_create_context
4343
*/
4444
LibinputPathContext();
45-
~LibinputPathContext();
46-
47-
Q_DISABLE_COPY_MOVE(LibinputPathContext);
45+
~LibinputPathContext() override;
4846

4947
/**
5048
* @see libinput_get_fd
@@ -64,7 +62,7 @@ class LibinputPathContext : public QObject
6462
/**
6563
* @see libinput_get_event
6664
*/
67-
std::unique_ptr<LibinputEvent> getEvent();
65+
std::optional<LibinputEvent> getEvent();
6866

6967
signals:
7068
void eventsAvailable();
@@ -73,6 +71,8 @@ class LibinputPathContext : public QObject
7371
static int openRestricted(const char *path, int flags, void *data);
7472
static void closeRestricted(int fd, void *data);
7573

74+
Q_DISABLE_COPY_MOVE(LibinputPathContext);
75+
7676
libinput *m_libinput;
7777
std::unique_ptr<QSocketNotifier> m_notifier;
7878
bool m_grab{};

src/libinput-cpp/UdevDevice.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,22 @@ UdevDevice::UdevDevice(udev_device *device)
2929

3030
UdevDevice::~UdevDevice()
3131
{
32+
if (!m_device) {
33+
return;
34+
}
35+
3236
udev_device_unref(m_device);
3337
}
3438

35-
const char *UdevDevice::propertyValue(const char *key)
39+
const char *UdevDevice::propertyValue(const char *key) const
3640
{
3741
return udev_device_get_property_value(m_device, key);
3842
}
3943

44+
UdevDevice &UdevDevice::operator=(UdevDevice &&other)
45+
{
46+
std::swap(m_device, other.m_device);
47+
return *this;
48+
}
49+
4050
}

src/libinput-cpp/UdevDevice.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ class UdevDevice
2929
{
3030
public:
3131
UdevDevice(udev_device *device);
32+
UdevDevice(UdevDevice &&);
3233
~UdevDevice();
3334

34-
Q_DISABLE_COPY_MOVE(UdevDevice);
35+
const char *propertyValue(const char *key) const;
3536

36-
const char *propertyValue(const char *key);
37+
UdevDevice &operator=(UdevDevice &&);
3738

3839
private:
39-
udev_device *m_device;
40+
Q_DISABLE_COPY(UdevDevice);
41+
42+
udev_device *m_device{};
4043
};
4144

4245
}

0 commit comments

Comments
 (0)