Skip to content

Commit a9498d1

Browse files
committed
Merged several fixes from the mac_capslock branch. Should at least fix capslock release on darwin.
1 parent 37965a8 commit a9498d1

File tree

8 files changed

+227
-107
lines changed

8 files changed

+227
-107
lines changed

src/darwin/input_hook.c

Lines changed: 188 additions & 58 deletions
Large diffs are not rendered by default.

src/demo_post.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
// Virtual event pointers
3232
static uiohook_event *event = NULL;
3333

34+
// TODO Implement CLI options.
3435
//int main(int argc, char *argv[]) {
3536
int main() {
3637
// Allocate memory for the virtual events only once.

src/demo_properties.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
#include <stdlib.h>
2626
#include <uiohook.h>
2727

28+
bool logger_proc(unsigned int level, const char *format, ...) {
29+
return false;
30+
}
31+
2832
int main() {
2933
// Disable the logger.
30-
// FIXME This doesn't appear to do what it should...
31-
hook_set_logger_proc(NULL);
34+
hook_set_logger_proc(&logger_proc);
3235

3336
// Retrieves an array of screen data for each available monitor.
3437
uint8_t count = 0;

src/logger.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static bool default_logger(unsigned int level, const char *format, ...) {
5656
}
5757

5858
// Current logger function pointer, this should never be null.
59+
// FIXME This should be static and wrapped with a public facing function.
5960
logger_t logger = &default_logger;
6061

6162

src/windows/input_hook.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,8 @@ static inline void process_mouse_moved(uint64_t timestamp, MSLLHOOKSTRUCT *mshoo
403403

404404
event.mask = get_modifiers();
405405

406-
// Check the upper half of the current modifiers for non zero
407-
// value. This indicates the presence of a button down mask.
408-
bool mouse_dragged = (event.mask >> 8 > 0);
406+
// Check the modifier mask range for MASK_BUTTON1 - 5.
407+
bool mouse_dragged = event.mask & (MASK_BUTTON1 | MASK_BUTTON2 | MASK_BUTTON3 | MASK_BUTTON4 | MASK_BUTTON5);
409408
if (mouse_dragged) {
410409
// Create Mouse Dragged event.
411410
event.type = EVENT_MOUSE_DRAGGED;
@@ -450,10 +449,10 @@ static inline void process_mouse_wheel(uint64_t timestamp, MSLLHOOKSTRUCT *mshoo
450449
event.data.wheel.amount = get_scroll_wheel_amount();
451450

452451
/* Delta HIWORD(mshook->mouseData)
453-
* A positive value indicates that the wheel was rotated
454-
* forward, away from the user; a negative value indicates that
455-
* the wheel was rotated backward, toward the user. One wheel
456-
* click is defined as WHEEL_DELTA, which is 120. */
452+
* A positive value indicates that the wheel was rotated
453+
* forward, away from the user; a negative value indicates that
454+
* the wheel was rotated backward, toward the user. One wheel
455+
* click is defined as WHEEL_DELTA, which is 120. */
457456
event.data.wheel.rotation = ((int16_t) HIWORD(mshook->mouseData) / WHEEL_DELTA) * -1;
458457

459458
logger(LOG_LEVEL_INFO, "%s [%u]: Mouse wheel type %u, rotated %i units at %u, %u.\n",
@@ -499,8 +498,12 @@ LRESULT CALLBACK mouse_hook_event_proc(int nCode, WPARAM wParam, LPARAM lParam)
499498
// Extra mouse buttons.
500499
uint16_t button = HIWORD(mshook->mouseData);
501500

502-
if (button + 7 < 16) {
503-
set_modifier_mask(1 << (button + 7));
501+
// Add support for mouse 4 & 5.
502+
if (button == 4) {
503+
set_modifier_mask(MOUSE_BUTTON4);
504+
}
505+
else if (button == 5) {
506+
set_modifier_mask(MOUSE_BUTTON5);
504507
}
505508

506509
process_button_pressed(timestamp, mshook, button);
@@ -537,8 +540,12 @@ LRESULT CALLBACK mouse_hook_event_proc(int nCode, WPARAM wParam, LPARAM lParam)
537540
// Extra mouse buttons.
538541
uint16_t button = HIWORD(mshook->mouseData);
539542

540-
if (button + 7 < 16) {
541-
unset_modifier_mask(1 << (button + 7));
543+
// Add support for mouse 4 & 5.
544+
if (button == 4) {
545+
unset_modifier_mask(MOUSE_BUTTON4);
546+
}
547+
else if (button == 5) {
548+
unset_modifier_mask(MOUSE_BUTTON5);
542549
}
543550

544551
process_button_released(timestamp, mshook, MOUSE_BUTTON5);
@@ -688,8 +695,7 @@ UIOHOOK_API int hook_run() {
688695

689696
// Block until the thread receives an WM_QUIT request.
690697
MSG message;
691-
//while (GetMessage(&message, (HWND) -1, 0, 0) > 0) {
692-
while (GetMessage(&message, (HWND) 0, 0, 0) > 0) {
698+
while (GetMessage(&message, (HWND) NULL, 0, 0) > 0) {
693699
TranslateMessage(&message);
694700
DispatchMessage(&message);
695701
}

src/x11/input_helper.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,22 +1812,18 @@ void load_input_helper(Display *disp) {
18121812
const char *prefix_evdev = "evdev_";
18131813
if (strncmp(layout_name, prefix_evdev, strlen(prefix_evdev)) == 0) {
18141814
is_evdev = true;
1815-
}
1816-
else {
1815+
} else
18171816
#endif
1818-
if (strncmp(layout_name, prefix_xfree86, strlen(prefix_xfree86)) != 0) {
1819-
logger(LOG_LEVEL_ERROR,
1820-
"%s [%u]: Unknown keycode name '%s', please file a bug report!\n",
1821-
__FUNCTION__, __LINE__, layout_name);
1822-
}
1823-
else if (layout_name == NULL) {
1824-
logger(LOG_LEVEL_ERROR,
1825-
"%s [%u]: X atom name failure for desc->names->keycodes!\n",
1826-
__FUNCTION__, __LINE__);
1827-
}
1828-
#if defined(USE_EVDEV) && defined(USE_XKB)
1817+
if (strncmp(layout_name, prefix_xfree86, strlen(prefix_xfree86)) != 0) {
1818+
logger(LOG_LEVEL_ERROR,
1819+
"%s [%u]: Unknown keycode name '%s', please file a bug report!\n",
1820+
__FUNCTION__, __LINE__, layout_name);
1821+
}
1822+
else if (layout_name == NULL) {
1823+
logger(LOG_LEVEL_ERROR,
1824+
"%s [%u]: X atom name failure for desc->names->keycodes!\n",
1825+
__FUNCTION__, __LINE__);
18291826
}
1830-
#endif
18311827

18321828
XkbFreeClientMap(desc, XkbGBN_AllComponentsMask, True);
18331829
}

src/x11/input_hook.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {
267267
else if (scancode == VC_META_L) { unset_modifier_mask(MASK_META_L); }
268268
else if (scancode == VC_META_R) { unset_modifier_mask(MASK_META_R); }
269269

270-
271270
// Populate key released event.
272271
event.time = timestamp;
273272
event.reserved = 0x00;
@@ -333,8 +332,6 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {
333332
*/
334333
event.data.wheel.amount = 3;
335334

336-
// MS assumption is more natural (follows the cartesian coordinate system)
337-
// FIXME I don't understand the above adjustment and comment...
338335
if (data->event.u.u.detail == WheelUp) {
339336
// Wheel Rotated Up and Away.
340337
event.data.wheel.rotation = -1;
@@ -385,14 +382,7 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {
385382
break;
386383

387384
default:
388-
// Extra buttons are at # - 4 starting after WheelUp and WheelDown.
389-
if (data->event.u.u.detail - 4 <= UINT16_MAX) {
390-
button = data->event.u.u.detail - 4;
391-
392-
if (button + 7 < 16) {
393-
set_modifier_mask(1 << (button + 7));
394-
}
395-
}
385+
// Do not set modifier masks past button MASK_BUTTON5.
396386
break;
397387
}
398388

@@ -483,14 +473,7 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {
483473
break;
484474

485475
default:
486-
// Extra buttons are at # - 4 starting after WheelUp and WheelDown.
487-
if (data->event.u.u.detail - 4 <= UINT16_MAX) {
488-
button = data->event.u.u.detail - 4;
489-
490-
if (button + 7 < 16) {
491-
unset_modifier_mask(1 << (button + 7));
492-
}
493-
}
476+
// Do not set modifier masks past button MASK_BUTTON5.
494477
break;
495478
}
496479

src/x11/post_event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static unsigned int btnmask_lookup[5] = {
6161
static unsigned int convert_to_native_mask(unsigned int mask) {
6262
unsigned int native_mask = 0x00;
6363

64-
if (mask & (MASK_SHIFT)) { native_mask |= ShiftMask; }
64+
if (mask & (MASK_SHIFT)) { native_mask |= ShiftMask; }
6565
if (mask & (MASK_CTRL)) { native_mask |= ControlMask; }
6666
if (mask & (MASK_META)) { native_mask |= Mod4Mask; }
6767
if (mask & (MASK_ALT)) { native_mask |= Mod1Mask; }

0 commit comments

Comments
 (0)