forked from quickshell/quickshell
service/mpris: add uniqueId property to detect track changes
Also emits all property changes after trackChanged
This commit is contained in:
parent
d9f66e63a3
commit
abc0201f6e
4 changed files with 104 additions and 34 deletions
|
@ -21,3 +21,22 @@ Qt::Edges Edges::toQt(Edges::Flags edges) { return Qt::Edges(edges.toInt()); }
|
|||
bool Edges::isOpposing(Edges::Flags edges) {
|
||||
return edges.testFlags(Edges::Top | Edges::Bottom) || edges.testFlags(Edges::Left | Edges::Right);
|
||||
}
|
||||
|
||||
DropEmitter::DropEmitter(DropEmitter&& other) noexcept: object(other.object), signal(other.signal) {
|
||||
other.object = nullptr;
|
||||
}
|
||||
|
||||
DropEmitter& DropEmitter::operator=(DropEmitter&& other) noexcept {
|
||||
this->object = other.object;
|
||||
this->signal = other.signal;
|
||||
other.object = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
DropEmitter::~DropEmitter() { this->call(); }
|
||||
|
||||
void DropEmitter::call() {
|
||||
if (!this->object) return;
|
||||
this->signal(this->object);
|
||||
this->object = nullptr;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <qdebug.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qpoint.h>
|
||||
#include <qrect.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
|
@ -68,3 +69,28 @@ bool isOpposing(Flags edges);
|
|||
}; // namespace Edges
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Edges::Flags);
|
||||
|
||||
// NOLINTBEGIN
|
||||
#define DROP_EMIT(object, func) \
|
||||
DropEmitter(object, static_cast<void (*)(typeof(object))>([](typeof(object) o) { o->func(); }))
|
||||
// NOLINTEND
|
||||
|
||||
class DropEmitter {
|
||||
public:
|
||||
template <class O>
|
||||
DropEmitter(O* object, void (*signal)(O*))
|
||||
: object(object)
|
||||
, signal(*reinterpret_cast<void (*)(void*)>(signal)) {} // NOLINT
|
||||
|
||||
DropEmitter() = default;
|
||||
DropEmitter(DropEmitter&& other) noexcept;
|
||||
DropEmitter& operator=(DropEmitter&& other) noexcept;
|
||||
~DropEmitter();
|
||||
Q_DISABLE_COPY(DropEmitter);
|
||||
|
||||
void call();
|
||||
|
||||
private:
|
||||
void* object = nullptr;
|
||||
void (*signal)(void*) = nullptr;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue