forked from quickshell/quickshell
core/util: move DropEmitter to utils and add generic accessor macros
This commit is contained in:
parent
abc0201f6e
commit
3a8e67e8ab
3 changed files with 81 additions and 44 deletions
|
|
@ -69,28 +69,3 @@ 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