protocols: Move globalshortcuts impl (#7102)

* move global shortcuts to hyprwayland-scanner

* remove wayland-scanner from deps

* fix the thing
This commit is contained in:
Ikalco 2024-07-30 16:33:56 -05:00 committed by GitHub
parent 8ec3dc4c09
commit 3b9b5346b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 84 additions and 212 deletions

View file

@ -49,8 +49,6 @@ endif()
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_get_variable(WaylandScanner wayland-scanner wayland_scanner)
message(STATUS "Found WaylandScanner at ${WaylandScanner}")
pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir) pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}") message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}")
pkg_get_variable(WAYLAND_SERVER_DIR wayland-server pkgdatadir) pkg_get_variable(WAYLAND_SERVER_DIR wayland-server pkgdatadir)
@ -232,30 +230,6 @@ target_link_libraries(Hyprland rt PkgConfig::deps)
# used by `make installheaders`, to ensure the headers are generated # used by `make installheaders`, to ensure the headers are generated
add_custom_target(generate-protocol-headers) add_custom_target(generate-protocol-headers)
function(protocol protoPath protoName external)
if(external)
set(path ${CMAKE_SOURCE_DIR}/${protoPath})
else()
set(path ${WAYLAND_PROTOCOLS_DIR}/${protoPath})
endif()
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/protocols/${protoName}-protocol.h
COMMAND ${WaylandScanner} server-header ${path}
protocols/${protoName}-protocol.h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/protocols/${protoName}-protocol.c
COMMAND ${WaylandScanner} private-code ${path}
protocols/${protoName}-protocol.c
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
target_sources(
Hyprland PRIVATE ${CMAKE_SOURCE_DIR}/protocols/${protoName}-protocol.h
${CMAKE_SOURCE_DIR}/protocols/${protoName}-protocol.c)
target_sources(generate-protocol-headers
PRIVATE ${CMAKE_SOURCE_DIR}/protocols/${protoName}-protocol.h)
endfunction()
function(protocolnew protoPath protoName external) function(protocolnew protoPath protoName external)
if(external) if(external)
set(path ${CMAKE_SOURCE_DIR}/${protoPath}) set(path ${CMAKE_SOURCE_DIR}/${protoPath})
@ -288,10 +262,7 @@ endfunction()
target_link_libraries(Hyprland OpenGL::EGL OpenGL::GL Threads::Threads target_link_libraries(Hyprland OpenGL::EGL OpenGL::GL Threads::Threads
libudis86 uuid) libudis86 uuid)
protocol( protocolnew("subprojects/hyprland-protocols/protocols" "hyprland-global-shortcuts-v1" true)
"subprojects/hyprland-protocols/protocols/hyprland-global-shortcuts-v1.xml"
"hyprland-global-shortcuts-v1" true)
protocolnew("unstable/text-input" "text-input-unstable-v1" false) protocolnew("unstable/text-input" "text-input-unstable-v1" false)
protocolnew("subprojects/hyprland-protocols/protocols" "hyprland-toplevel-export-v1" true) protocolnew("subprojects/hyprland-protocols/protocols" "hyprland-toplevel-export-v1" true)
protocolnew("protocols" "wlr-screencopy-unstable-v1" true) protocolnew("protocols" "wlr-screencopy-unstable-v1" true)

View file

@ -12,21 +12,12 @@ hyprland_protos = dependency('hyprland-protocols',
wl_protocol_dir = wayland_protos.get_variable('pkgdatadir') wl_protocol_dir = wayland_protos.get_variable('pkgdatadir')
hl_protocol_dir = hyprland_protos.get_variable('pkgdatadir') hl_protocol_dir = hyprland_protos.get_variable('pkgdatadir')
wayland_scanner_dep = dependency('wayland-scanner', native: true)
wayland_scanner = find_program(
wayland_scanner_dep.get_variable('wayland_scanner'),
native: true,
)
hyprwayland_scanner_dep = dependency('hyprwayland-scanner', version: '>=0.3.8', native: true) hyprwayland_scanner_dep = dependency('hyprwayland-scanner', version: '>=0.3.8', native: true)
hyprwayland_scanner = find_program( hyprwayland_scanner = find_program(
hyprwayland_scanner_dep.get_variable('hyprwayland_scanner'), hyprwayland_scanner_dep.get_variable('hyprwayland_scanner'),
native: true, native: true,
) )
protocols = [
[hl_protocol_dir, 'protocols/hyprland-global-shortcuts-v1.xml']
]
new_protocols = [ new_protocols = [
['wlr-gamma-control-unstable-v1.xml'], ['wlr-gamma-control-unstable-v1.xml'],
['wlr-foreign-toplevel-management-unstable-v1.xml'], ['wlr-foreign-toplevel-management-unstable-v1.xml'],
@ -40,6 +31,7 @@ new_protocols = [
['wayland-drm.xml'], ['wayland-drm.xml'],
['wlr-data-control-unstable-v1.xml'], ['wlr-data-control-unstable-v1.xml'],
['wlr-screencopy-unstable-v1.xml'], ['wlr-screencopy-unstable-v1.xml'],
[hl_protocol_dir, 'protocols/hyprland-global-shortcuts-v1.xml'],
[hl_protocol_dir, 'protocols/hyprland-toplevel-export-v1.xml'], [hl_protocol_dir, 'protocols/hyprland-toplevel-export-v1.xml'],
[hl_protocol_dir, 'protocols/hyprland-focus-grab-v1.xml'], [hl_protocol_dir, 'protocols/hyprland-focus-grab-v1.xml'],
[wl_protocol_dir, 'staging/tearing-control/tearing-control-v1.xml'], [wl_protocol_dir, 'staging/tearing-control/tearing-control-v1.xml'],
@ -73,24 +65,6 @@ new_protocols = [
wl_protos_src = [] wl_protos_src = []
wl_protos_headers = [] wl_protos_headers = []
foreach p : protocols
xml = join_paths(p)
wl_protos_src += custom_target(
xml.underscorify() + '_server_c',
input: xml,
output: '@BASENAME@-protocol.c',
command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'],
)
wl_protos_headers += custom_target(
xml.underscorify() + '_server_h',
input: xml,
install: true,
install_dir: join_paths(get_option('includedir'), 'hyprland/protocols'),
output: '@BASENAME@-protocol.h',
command: [wayland_scanner, 'server-header', '@INPUT@', '@OUTPUT@'],
)
endforeach
new_wl_protos = [] new_wl_protos = []
foreach p : new_protocols foreach p : new_protocols
xml = join_paths(p) xml = join_paths(p)

View file

@ -32,6 +32,7 @@ using namespace Hyprutils::String;
#include "../devices/IKeyboard.hpp" #include "../devices/IKeyboard.hpp"
#include "../devices/ITouch.hpp" #include "../devices/ITouch.hpp"
#include "../devices/Tablet.hpp" #include "../devices/Tablet.hpp"
#include "../protocols/GlobalShortcuts.hpp"
#include "debug/RollingLogFollow.hpp" #include "debug/RollingLogFollow.hpp"
#include "config/ConfigManager.hpp" #include "config/ConfigManager.hpp"
#include "helpers/MiscFunctions.hpp" #include "helpers/MiscFunctions.hpp"
@ -776,7 +777,7 @@ std::string rollinglogRequest(eHyprCtlOutputFormat format, std::string request)
std::string globalShortcutsRequest(eHyprCtlOutputFormat format, std::string request) { std::string globalShortcutsRequest(eHyprCtlOutputFormat format, std::string request) {
std::string ret = ""; std::string ret = "";
const auto SHORTCUTS = g_pProtocolManager->m_pGlobalShortcutsProtocolManager->getAllShortcuts(); const auto SHORTCUTS = PROTO::globalShortcuts->getAllShortcuts();
if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) { if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) {
for (auto& sh : SHORTCUTS) for (auto& sh : SHORTCUTS)
ret += std::format("{}:{} -> {}\n", sh.appid, sh.id, sh.description); ret += std::format("{}:{} -> {}\n", sh.appid, sh.id, sh.description);

View file

@ -3,6 +3,7 @@
#include "../managers/SeatManager.hpp" #include "../managers/SeatManager.hpp"
#include "../protocols/LayerShell.hpp" #include "../protocols/LayerShell.hpp"
#include "../protocols/ShortcutsInhibit.hpp" #include "../protocols/ShortcutsInhibit.hpp"
#include "../protocols/GlobalShortcuts.hpp"
#include "../render/decorations/CHyprGroupBarDecoration.hpp" #include "../render/decorations/CHyprGroupBarDecoration.hpp"
#include "../devices/IKeyboard.hpp" #include "../devices/IKeyboard.hpp"
#include "KeybindManager.hpp" #include "KeybindManager.hpp"
@ -2664,10 +2665,10 @@ void CKeybindManager::global(std::string args) {
if (NAME.empty()) if (NAME.empty())
return; return;
if (!g_pProtocolManager->m_pGlobalShortcutsProtocolManager->globalShortcutExists(APPID, NAME)) if (!PROTO::globalShortcuts->isTaken(APPID, NAME))
return; return;
g_pProtocolManager->m_pGlobalShortcutsProtocolManager->sendGlobalShortcutEvent(APPID, NAME, g_pKeybindManager->m_iPassPressed); PROTO::globalShortcuts->sendGlobalShortcutEvent(APPID, NAME, g_pKeybindManager->m_iPassPressed);
} }
void CKeybindManager::moveGroupWindow(std::string args) { void CKeybindManager::moveGroupWindow(std::string args) {

View file

@ -42,6 +42,7 @@
#include "../protocols/Screencopy.hpp" #include "../protocols/Screencopy.hpp"
#include "../protocols/ToplevelExport.hpp" #include "../protocols/ToplevelExport.hpp"
#include "../protocols/TextInputV1.hpp" #include "../protocols/TextInputV1.hpp"
#include "../protocols/GlobalShortcuts.hpp"
#include "../protocols/core/Seat.hpp" #include "../protocols/core/Seat.hpp"
#include "../protocols/core/DataDevice.hpp" #include "../protocols/core/DataDevice.hpp"
@ -148,6 +149,7 @@ CProtocolManager::CProtocolManager() {
PROTO::xwaylandShell = std::make_unique<CXWaylandShellProtocol>(&xwayland_shell_v1_interface, 1, "XWaylandShell"); PROTO::xwaylandShell = std::make_unique<CXWaylandShellProtocol>(&xwayland_shell_v1_interface, 1, "XWaylandShell");
PROTO::screencopy = std::make_unique<CScreencopyProtocol>(&zwlr_screencopy_manager_v1_interface, 3, "Screencopy"); PROTO::screencopy = std::make_unique<CScreencopyProtocol>(&zwlr_screencopy_manager_v1_interface, 3, "Screencopy");
PROTO::toplevelExport = std::make_unique<CToplevelExportProtocol>(&hyprland_toplevel_export_manager_v1_interface, 2, "ToplevelExport"); PROTO::toplevelExport = std::make_unique<CToplevelExportProtocol>(&hyprland_toplevel_export_manager_v1_interface, 2, "ToplevelExport");
PROTO::globalShortcuts = std::make_unique<CGlobalShortcutsProtocol>(&hyprland_global_shortcuts_manager_v1_interface, 1, "GlobalShortcuts");
for (auto& b : g_pCompositor->m_pAqBackend->getImplementations()) { for (auto& b : g_pCompositor->m_pAqBackend->getImplementations()) {
if (b->type() != Aquamarine::AQ_BACKEND_DRM) if (b->type() != Aquamarine::AQ_BACKEND_DRM)
@ -164,10 +166,6 @@ CProtocolManager::CProtocolManager() {
PROTO::linuxDma = std::make_unique<CLinuxDMABufV1Protocol>(&zwp_linux_dmabuf_v1_interface, 5, "LinuxDMABUF"); PROTO::linuxDma = std::make_unique<CLinuxDMABufV1Protocol>(&zwp_linux_dmabuf_v1_interface, 5, "LinuxDMABUF");
} else } else
Debug::log(WARN, "ProtocolManager: Not binding linux-dmabuf and MesaDRM: DMABUF not available"); Debug::log(WARN, "ProtocolManager: Not binding linux-dmabuf and MesaDRM: DMABUF not available");
// Old protocol implementations.
// TODO: rewrite them to use hyprwayland-scanner.
m_pGlobalShortcutsProtocolManager = std::make_unique<CGlobalShortcutsProtocolManager>();
} }
CProtocolManager::~CProtocolManager() { CProtocolManager::~CProtocolManager() {
@ -220,6 +218,7 @@ CProtocolManager::~CProtocolManager() {
PROTO::xwaylandShell.reset(); PROTO::xwaylandShell.reset();
PROTO::screencopy.reset(); PROTO::screencopy.reset();
PROTO::toplevelExport.reset(); PROTO::toplevelExport.reset();
PROTO::globalShortcuts.reset();
PROTO::lease.reset(); PROTO::lease.reset();
PROTO::sync.reset(); PROTO::sync.reset();

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "../defines.hpp" #include "../defines.hpp"
#include "../protocols/GlobalShortcuts.hpp"
#include "../helpers/Monitor.hpp" #include "../helpers/Monitor.hpp"
#include "../helpers/memory/Memory.hpp" #include "../helpers/memory/Memory.hpp"
#include "../helpers/signal/Signal.hpp" #include "../helpers/signal/Signal.hpp"
@ -12,9 +11,6 @@ class CProtocolManager {
CProtocolManager(); CProtocolManager();
~CProtocolManager(); ~CProtocolManager();
// TODO: rewrite to use the new protocol framework
std::unique_ptr<CGlobalShortcutsProtocolManager> m_pGlobalShortcutsProtocolManager;
private: private:
std::unordered_map<std::string, CHyprSignalListener> m_mModeChangeListeners; std::unordered_map<std::string, CHyprSignalListener> m_mModeChangeListeners;

View file

@ -1,120 +1,61 @@
#include "GlobalShortcuts.hpp" #include "GlobalShortcuts.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"
#define GLOBAL_SHORTCUTS_VERSION 1 #define LOGM PROTO::globalShortcuts->protoLog
static void bindManagerInt(wl_client* client, void* data, uint32_t version, uint32_t id) { CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_) : resource(resource_) {
g_pProtocolManager->m_pGlobalShortcutsProtocolManager->bindManager(client, data, version, id); if (!good())
}
static void handleDisplayDestroy(struct wl_listener* listener, void* data) {
CGlobalShortcutsProtocolManagerDestroyWrapper* wrap = wl_container_of(listener, wrap, listener);
CGlobalShortcutsProtocolManager* proto = wrap->parent;
proto->displayDestroy();
}
void CGlobalShortcutsProtocolManager::displayDestroy() {
wl_list_remove(&m_liDisplayDestroy.listener.link);
wl_list_init(&m_liDisplayDestroy.listener.link);
wl_global_destroy(m_pGlobal);
}
CGlobalShortcutsProtocolManager::~CGlobalShortcutsProtocolManager() {
displayDestroy();
}
CGlobalShortcutsProtocolManager::CGlobalShortcutsProtocolManager() {
m_pGlobal = wl_global_create(g_pCompositor->m_sWLDisplay, &hyprland_global_shortcuts_manager_v1_interface, GLOBAL_SHORTCUTS_VERSION, this, bindManagerInt);
if (!m_pGlobal) {
Debug::log(ERR, "GlobalShortcutsManager could not start!");
return; return;
}
wl_list_init(&m_liDisplayDestroy.listener.link); resource->setOnDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
m_liDisplayDestroy.listener.notify = handleDisplayDestroy; resource->setDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
m_liDisplayDestroy.parent = this;
wl_display_add_destroy_listener(g_pCompositor->m_sWLDisplay, &m_liDisplayDestroy.listener);
Debug::log(LOG, "GlobalShortcutsManager started successfully!"); resource->setRegisterShortcut([this](CHyprlandGlobalShortcutsManagerV1* pMgr, uint32_t shortcut, const char* id, const char* app_id, const char* description,
} const char* trigger_description) {
if (PROTO::globalShortcuts->isTaken(id, app_id)) {
static void handleRegisterShortcut(wl_client* client, wl_resource* resource, uint32_t shortcut, const char* id, const char* app_id, const char* description, resource->error(HYPRLAND_GLOBAL_SHORTCUTS_MANAGER_V1_ERROR_ALREADY_TAKEN, "Combination is taken");
const char* trigger_description) { return;
g_pProtocolManager->m_pGlobalShortcutsProtocolManager->registerShortcut(client, resource, shortcut, id, app_id, description, trigger_description);
}
static void handleDestroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
static const struct hyprland_global_shortcuts_manager_v1_interface globalShortcutsManagerImpl = {
.register_shortcut = handleRegisterShortcut,
.destroy = handleDestroy,
};
static const struct hyprland_global_shortcut_v1_interface shortcutImpl = {
.destroy = handleDestroy,
};
void CGlobalShortcutsProtocolManager::bindManager(wl_client* client, void* data, uint32_t version, uint32_t id) {
const auto RESOURCE = wl_resource_create(client, &hyprland_global_shortcuts_manager_v1_interface, version, id);
wl_resource_set_implementation(RESOURCE, &globalShortcutsManagerImpl, this, nullptr);
Debug::log(LOG, "GlobalShortcutsManager bound successfully!");
m_vClients.emplace_back(std::make_unique<SShortcutClient>(client));
}
SShortcutClient* CGlobalShortcutsProtocolManager::clientFromWlClient(wl_client* client) {
for (auto& c : m_vClients) {
if (c->client == client) {
return c.get();
} }
}
return nullptr; const auto PSHORTCUT = shortcuts.emplace_back(makeShared<SShortcut>(makeShared<CHyprlandGlobalShortcutV1>(resource->client(), resource->version(), shortcut)));
} PSHORTCUT->id = id;
PSHORTCUT->description = description;
PSHORTCUT->appid = app_id;
PSHORTCUT->shortcut = shortcut;
static void onShortcutDestroy(wl_resource* pResource) { if (!PSHORTCUT->resource->resource()) {
g_pProtocolManager->m_pGlobalShortcutsProtocolManager->destroyShortcut(pResource); PSHORTCUT->resource->noMemory();
} shortcuts.pop_back();
return;
void CGlobalShortcutsProtocolManager::registerShortcut(wl_client* client, wl_resource* resource, uint32_t shortcut, const char* id, const char* app_id, const char* description,
const char* trigger_description) {
const auto PCLIENT = clientFromWlClient(client);
if (!PCLIENT) {
Debug::log(ERR, "Error at global shortcuts: no client in register?");
return;
}
for (auto& c : m_vClients) {
for (auto& sh : c->shortcuts) {
if (sh->appid == app_id && sh->id == id) {
wl_resource_post_error(resource, HYPRLAND_GLOBAL_SHORTCUTS_MANAGER_V1_ERROR_ALREADY_TAKEN, "Combination is taken");
return;
}
} }
}
const auto PSHORTCUT = PCLIENT->shortcuts.emplace_back(std::make_unique<SShortcut>()).get(); PSHORTCUT->resource->setDestroy([this](CHyprlandGlobalShortcutV1* pMgr) { std::erase_if(shortcuts, [&](const auto& other) { return other->resource.get() == pMgr; }); });
PSHORTCUT->id = id; });
PSHORTCUT->description = description; }
PSHORTCUT->appid = app_id;
PSHORTCUT->shortcut = shortcut;
PSHORTCUT->resource = wl_resource_create(client, &hyprland_global_shortcut_v1_interface, 1, shortcut); bool CShortcutClient::good() {
if (!PSHORTCUT->resource) { return resource->resource();
}
CGlobalShortcutsProtocol::CGlobalShortcutsProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
;
}
void CGlobalShortcutsProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESROUCE = m_vClients.emplace_back(makeShared<CShortcutClient>(makeShared<CHyprlandGlobalShortcutsManagerV1>(client, ver, id)));
if (!RESROUCE->good()) {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
std::erase_if(PCLIENT->shortcuts, [&](const auto& other) { return other.get() == PSHORTCUT; }); m_vClients.pop_back();
return; return;
} }
wl_resource_set_implementation(PSHORTCUT->resource, &shortcutImpl, this, &onShortcutDestroy);
} }
bool CGlobalShortcutsProtocolManager::globalShortcutExists(std::string appid, std::string trigger) { void CGlobalShortcutsProtocol::destroyResource(CShortcutClient* client) {
std::erase_if(m_vClients, [&](const auto& other) { return other.get() == client; });
}
bool CGlobalShortcutsProtocol::isTaken(std::string appid, std::string trigger) {
for (auto& c : m_vClients) { for (auto& c : m_vClients) {
for (auto& sh : c->shortcuts) { for (auto& sh : c->shortcuts) {
if (sh->appid == appid && sh->id == trigger) { if (sh->appid == appid && sh->id == trigger) {
@ -126,7 +67,7 @@ bool CGlobalShortcutsProtocolManager::globalShortcutExists(std::string appid, st
return false; return false;
} }
void CGlobalShortcutsProtocolManager::sendGlobalShortcutEvent(std::string appid, std::string trigger, bool pressed) { void CGlobalShortcutsProtocol::sendGlobalShortcutEvent(std::string appid, std::string trigger, bool pressed) {
for (auto& c : m_vClients) { for (auto& c : m_vClients) {
for (auto& sh : c->shortcuts) { for (auto& sh : c->shortcuts) {
if (sh->appid == appid && sh->id == trigger) { if (sh->appid == appid && sh->id == trigger) {
@ -135,15 +76,15 @@ void CGlobalShortcutsProtocolManager::sendGlobalShortcutEvent(std::string appid,
uint32_t tvSecHi = (sizeof(now.tv_sec) > 4) ? now.tv_sec >> 32 : 0; uint32_t tvSecHi = (sizeof(now.tv_sec) > 4) ? now.tv_sec >> 32 : 0;
uint32_t tvSecLo = now.tv_sec & 0xFFFFFFFF; uint32_t tvSecLo = now.tv_sec & 0xFFFFFFFF;
if (pressed) if (pressed)
hyprland_global_shortcut_v1_send_pressed(sh->resource, tvSecHi, tvSecLo, now.tv_nsec); sh->resource->sendPressed(tvSecHi, tvSecLo, now.tv_nsec);
else else
hyprland_global_shortcut_v1_send_released(sh->resource, tvSecHi, tvSecLo, now.tv_nsec); sh->resource->sendReleased(tvSecHi, tvSecLo, now.tv_nsec);
} }
} }
} }
} }
std::vector<SShortcut> CGlobalShortcutsProtocolManager::getAllShortcuts() { std::vector<SShortcut> CGlobalShortcutsProtocol::getAllShortcuts() {
std::vector<SShortcut> copy; std::vector<SShortcut> copy;
for (auto& c : m_vClients) { for (auto& c : m_vClients) {
for (auto& sh : c->shortcuts) { for (auto& sh : c->shortcuts) {
@ -153,9 +94,3 @@ std::vector<SShortcut> CGlobalShortcutsProtocolManager::getAllShortcuts() {
return copy; return copy;
} }
void CGlobalShortcutsProtocolManager::destroyShortcut(wl_resource* resource) {
for (auto& c : m_vClients) {
std::erase_if(c->shortcuts, [&](const auto& other) { return other->resource == resource; });
}
}

View file

@ -1,48 +1,43 @@
#pragma once #pragma once
#include "../defines.hpp" #include "../defines.hpp"
#include "hyprland-global-shortcuts-v1-protocol.h" #include "hyprland-global-shortcuts-v1.hpp"
#include "../protocols/WaylandProtocol.hpp"
#include <vector> #include <vector>
struct SShortcut { struct SShortcut {
wl_resource* resource; SP<CHyprlandGlobalShortcutV1> resource;
std::string id, description, appid; std::string id, description, appid;
uint32_t shortcut = 0; uint32_t shortcut = 0;
}; };
struct SShortcutClient { class CShortcutClient {
wl_client* client = nullptr;
std::vector<std::unique_ptr<SShortcut>> shortcuts;
};
class CGlobalShortcutsProtocolManager;
struct CGlobalShortcutsProtocolManagerDestroyWrapper {
wl_listener listener;
CGlobalShortcutsProtocolManager* parent = nullptr;
};
class CGlobalShortcutsProtocolManager {
public: public:
CGlobalShortcutsProtocolManager(); CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource);
~CGlobalShortcutsProtocolManager();
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id); bool good();
void displayDestroy();
void registerShortcut(wl_client* client, wl_resource* resource, uint32_t shortcut, const char* id, const char* app_id, const char* description,
const char* trigger_description);
void destroyShortcut(wl_resource* resource);
bool globalShortcutExists(std::string appid, std::string trigger);
void sendGlobalShortcutEvent(std::string appid, std::string trigger, bool pressed);
std::vector<SShortcut> getAllShortcuts();
CGlobalShortcutsProtocolManagerDestroyWrapper m_liDisplayDestroy;
private: private:
std::vector<std::unique_ptr<SShortcutClient>> m_vClients; SP<CHyprlandGlobalShortcutsManagerV1> resource;
std::vector<SP<SShortcut>> shortcuts;
SShortcutClient* clientFromWlClient(wl_client* client); friend class CGlobalShortcutsProtocol;
};
wl_global* m_pGlobal = nullptr;
class CGlobalShortcutsProtocol : IWaylandProtocol {
public:
CGlobalShortcutsProtocol(const wl_interface* iface, const int& ver, const std::string& name);
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
void destroyResource(CShortcutClient* client);
void sendGlobalShortcutEvent(std::string appid, std::string trigger, bool pressed);
bool isTaken(std::string id, std::string app_id);
std::vector<SShortcut> getAllShortcuts();
private:
std::vector<SP<CShortcutClient>> m_vClients;
};
namespace PROTO {
inline UP<CGlobalShortcutsProtocol> globalShortcuts;
}; };