forked from quickshell/quickshell
hyprland/ipc: implement toplevel address association
This commit is contained in:
parent
ee570ec623
commit
dcd9e3aed8
6 changed files with 384 additions and 0 deletions
53
src/wayland/hyprland/ipc/hyprland_toplevel.cpp
Normal file
53
src/wayland/hyprland/ipc/hyprland_toplevel.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#include "hyprland_toplevel.hpp"
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qobject.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "toplevel_mapping.hpp"
|
||||
#include "../../toplevel_management/handle.hpp"
|
||||
#include "../../toplevel_management/qml.hpp"
|
||||
|
||||
using namespace qs::wayland::toplevel_management;
|
||||
using namespace qs::wayland::toplevel_management::impl;
|
||||
|
||||
namespace qs::hyprland::ipc {
|
||||
|
||||
HyprlandToplevel::HyprlandToplevel(Toplevel* toplevel)
|
||||
: QObject(toplevel)
|
||||
, handle(toplevel->implHandle()) {
|
||||
auto* instance = HyprlandToplevelMappingManager::instance();
|
||||
auto addr = instance->getToplevelAddress(handle);
|
||||
|
||||
if (addr != 0) this->setAddress(addr);
|
||||
else {
|
||||
QObject::connect(
|
||||
instance,
|
||||
&HyprlandToplevelMappingManager::toplevelAddressed,
|
||||
this,
|
||||
&HyprlandToplevel::onToplevelAddressed
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void HyprlandToplevel::onToplevelAddressed(ToplevelHandle* handle, quint64 address) {
|
||||
if (handle == this->handle) {
|
||||
this->setAddress(address);
|
||||
QObject::disconnect(HyprlandToplevelMappingManager::instance(), nullptr, this, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void HyprlandToplevel::setAddress(quint64 address) {
|
||||
this->mAddress = QString::number(address, 16);
|
||||
emit this->addressChanged();
|
||||
}
|
||||
|
||||
HyprlandToplevel* HyprlandToplevel::qmlAttachedProperties(QObject* object) {
|
||||
if (auto* toplevel = qobject_cast<Toplevel*>(object)) {
|
||||
return new HyprlandToplevel(toplevel);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
} // namespace qs::hyprland::ipc
|
||||
Loading…
Add table
Add a link
Reference in a new issue