Skip to content

Commit

Permalink
input-capture: send modifiers (highly experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
3l0w committed Dec 17, 2024
1 parent 12a1622 commit be33110
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core/PortalManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SOutput::SOutput(SP<CCWlOutput> output_) : output(output_) {
refreshRate = refresh;
width = width_;
height = height_;
Debug::log(LOG, "??? {} {}", flags, refresh);
});
output->setGeometry(
[this](CCWlOutput* r, int32_t x_, int32_t y_, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform_) {
Expand Down
16 changes: 16 additions & 0 deletions src/portals/InputCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ CInputCapturePortal::CInputCapturePortal(SP<CCHyprlandInputCaptureManagerV1> mgr
onKeymap(format == HYPRLAND_INPUT_CAPTURE_MANAGER_V1_KEYMAP_FORMAT_XKB_V1 ? fd : 0, size);
});

mgr->setModifiers([this](CCHyprlandInputCaptureManagerV1* r, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) {
onModifiers(mods_depressed, mods_latched, mods_locked, group);
});

mgr->setKey([this](CCHyprlandInputCaptureManagerV1* r, uint32_t key, hyprlandInputCaptureManagerV1KeyState state) { onKey(key, state); });

mgr->setButton([this](CCHyprlandInputCaptureManagerV1* r, uint32_t button, hyprlandInputCaptureManagerV1ButtonState state) { onButton(button, state); });
Expand Down Expand Up @@ -321,6 +325,11 @@ void CInputCapturePortal::onKey(uint32_t id, bool pressed) {
value->key(id, pressed);
}

void CInputCapturePortal::onModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group) {
for (const auto& [key, value] : sessions)
value->modifiers(modsDepressed, modsLatched, modsLocked, group);
}

void CInputCapturePortal::onKeymap(int32_t fd, uint32_t size) {
keymap.fd = fd;
keymap.size = size;
Expand Down Expand Up @@ -475,6 +484,13 @@ void CInputCapturePortal::SSession::key(uint32_t key, bool pressed) {
eis->sendKey(key, pressed);
}

void CInputCapturePortal::SSession::modifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group) {
if (status != ACTIVATED)
return;

eis->sendModifiers(modsDepressed, modsLatched, modsLocked, group);
}

void CInputCapturePortal::SSession::button(uint32_t button, bool pressed) {
if (status != ACTIVATED)
return;
Expand Down
2 changes: 2 additions & 0 deletions src/portals/InputCapture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CInputCapturePortal {
void onMotion(double x, double y, double dx, double dy);
void onKeymap(int32_t fd, uint32_t size);
void onKey(uint32_t key, bool pressed);
void onModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group);
void onButton(uint32_t button, bool pressed);
void onAxis(bool axis, double value);
void onAxisValue120(bool axis, int32_t value120);
Expand Down Expand Up @@ -66,6 +67,7 @@ class CInputCapturePortal {

void motion(double dx, double dy);
void key(uint32_t key, bool pressed);
void modifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group);
void keymap(Keymap keymap);
void button(uint32_t button, bool pressed);
void axis(bool axis, double value);
Expand Down
8 changes: 8 additions & 0 deletions src/shared/Eis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ void EmulatedInputServer::sendKey(uint32_t key, bool pressed) {
eis_device_frame(client.keyboard, now);
}

void EmulatedInputServer::sendModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group) {
if (!client.keyboard)
return;
uint64_t now = eis_now(eisCtx);
eis_device_keyboard_send_xkb_modifiers(client.keyboard, modsDepressed, modsLatched, modsLocked, group);
eis_device_frame(client.keyboard, now);
}

void EmulatedInputServer::sendButton(uint32_t button, bool pressed) {
if (!client.pointer)
return;
Expand Down
1 change: 1 addition & 0 deletions src/shared/Eis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class EmulatedInputServer {

void sendMotion(double x, double y);
void sendKey(uint32_t key, bool pressed);
void sendModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group);
void sendButton(uint32_t button, bool pressed);
void sendScrollDelta(double x, double y);
void sendScrollDiscrete(int32_t x, int32_t y);
Expand Down
2 changes: 1 addition & 1 deletion subprojects/hyprland-protocols

0 comments on commit be33110

Please sign in to comment.