Skip to content

Commit c2f8f47

Browse files
committed
Adding keyboard support items
1 parent 9a70f51 commit c2f8f47

File tree

8 files changed

+724
-792
lines changed

8 files changed

+724
-792
lines changed

CMakeLists.txt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,32 @@ endif()
139139
if(UNIX AND NOT APPLE)
140140
find_package(PkgConfig REQUIRED)
141141

142+
pkg_check_modules(EVDEV REQUIRED libevdev)
143+
target_include_directories(uiohook PRIVATE "${EVDEV_INCLUDE_DIRS}")
144+
target_link_libraries(uiohook "${EVDEV_LDFLAGS}")
145+
146+
#pkg_check_modules(XCB REQUIRED xcb)
147+
#target_include_directories(uiohook PRIVATE "${XCB_INCLUDE_DIRS}")
148+
#target_link_libraries(uiohook "${XCB_LDFLAGS}")
149+
150+
pkg_check_modules(XCB_X11 REQUIRED x11-xcb)
151+
target_include_directories(uiohook PRIVATE "${XCB_X11_INCLUDE_DIRS}")
152+
target_link_libraries(uiohook "${XCB_X11_LDFLAGS}")
153+
154+
pkg_check_modules(XKB REQUIRED xkbcommon)
155+
target_include_directories(uiohook PRIVATE "${XKB_INCLUDE_DIRS}")
156+
target_link_libraries(uiohook "${XKB_LDFLAGS}")
157+
158+
pkg_check_modules(XKB_X11 REQUIRED xkbcommon-x11)
159+
target_include_directories(uiohook PRIVATE "${XKB_X11_INCLUDE_DIRS}")
160+
target_link_libraries(uiohook "${XKB_X11_LDFLAGS}")
161+
162+
# FIXME Check for header X11/extensions/XKB.h
163+
include(CheckIncludeFile)
164+
check_include_file(X11/extensions/XKB.h HAVE_XKB_H)
165+
166+
167+
142168
pkg_check_modules(X11 REQUIRED x11)
143169
target_include_directories(uiohook PRIVATE "${X11_INCLUDE_DIRS}")
144170
target_link_libraries(uiohook "${X11_LDFLAGS}")
@@ -151,18 +177,14 @@ if(UNIX AND NOT APPLE)
151177
target_include_directories(uiohook PRIVATE "${XINPUT_INCLUDE_DIRS}")
152178
target_link_libraries(uiohook "${XINPUT_LDFLAGS}")
153179

154-
pkg_check_modules(EVDEV REQUIRED libevdev)
155-
target_include_directories(uiohook PRIVATE "${EVDEV_INCLUDE_DIRS}")
156-
target_link_libraries(uiohook "${EVDEV_LDFLAGS}")
180+
157181

158182
include(CMakePrintHelpers)
159183
cmake_print_variables(EVDEV_INCLUDE_DIRS)
160184

161185
include(CheckLibraryExists)
162186
check_library_exists(Xtst XRecordQueryVersion "" HAVE_XRECORD)
163187

164-
include(CheckIncludeFile)
165-
check_include_file(X11/extensions/record.h HAVE_RECORD_H "-include X11/Xlib.h")
166188

167189
option(USE_XT "X Toolkit Extension (default: ON)" ON)
168190
if(USE_XT)

src/evdev/dispatch_event.c

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -96,41 +96,20 @@ void dispatch_hook_disabled(XAnyEvent * const x_event) {
9696
unload_input_helper();
9797
}
9898

99-
void dispatch_key_press(XKeyPressedEvent * const x_event) {
99+
void dispatch_key_press(uint64_t time, xkb_keycode_t keycode) {
100100
KeySym keysym = 0x00;
101101

102-
wchar_t surrogate[2] = {};
103-
size_t count = x_key_event_lookup(x_event, surrogate, sizeof(surrogate) - 1, &keysym);
104-
105-
106-
uint16_t uiocode = keysym_to_vcode(keysym);
107-
108-
// FIXME This can happen inside of keysym_to_vcode()
109-
// TODO VC_ALT_GRAPH MASK?
110-
if (uiocode == VC_SHIFT_L) { set_modifier_mask(MASK_SHIFT_L); }
111-
else if (uiocode == VC_SHIFT_R) { set_modifier_mask(MASK_SHIFT_R); }
112-
else if (uiocode == VC_CONTROL_L) { set_modifier_mask(MASK_CTRL_L); }
113-
else if (uiocode == VC_CONTROL_R) { set_modifier_mask(MASK_CTRL_R); }
114-
else if (uiocode == VC_ALT_L) { set_modifier_mask(MASK_ALT_L); }
115-
else if (uiocode == VC_ALT_R) { set_modifier_mask(MASK_ALT_R); }
116-
else if (uiocode == VC_META_L) { set_modifier_mask(MASK_META_L); }
117-
else if (uiocode == VC_META_R) { set_modifier_mask(MASK_META_R); }
118-
119-
// FIXME We shouldn't be doing this on each key press, do something similar to above.
120-
//initialize_locks();
121-
122-
123-
102+
uint16_t uiocode = keycode_to_uiocode(keycode);
124103

125104
// Populate key pressed event.
126-
uio_event.time = x_event->serial;
105+
uio_event.time = time;
127106
uio_event.reserved = 0x00;
128107

129108
uio_event.type = EVENT_KEY_PRESSED;
130109
uio_event.mask = get_modifiers();
131110

132111
uio_event.data.keyboard.keycode = uiocode;
133-
uio_event.data.keyboard.rawcode = keysym;
112+
uio_event.data.keyboard.rawcode = keycode;
134113
uio_event.data.keyboard.keychar = CHAR_UNDEFINED;
135114

136115
logger(LOG_LEVEL_DEBUG, "%s [%u]: Key %#X pressed. (%#X)\n",
@@ -142,9 +121,11 @@ void dispatch_key_press(XKeyPressedEvent * const x_event) {
142121

143122
// If the pressed event was not consumed and we got a char in the buffer.
144123
if (uio_event.reserved ^ 0x01) {
124+
wchar_t surrogate[4] = {};
125+
size_t count = keycode_to_utf8(keycode, surrogate, sizeof(surrogate));
145126
for (unsigned int i = 0; i < count; i++) {
146127
// Populate key typed event.
147-
uio_event.time = x_event->serial;
128+
uio_event.time = time;
148129
uio_event.reserved = 0x00;
149130

150131
uio_event.type = EVENT_KEY_TYPED;
@@ -165,37 +146,22 @@ void dispatch_key_press(XKeyPressedEvent * const x_event) {
165146
}
166147
}
167148

168-
void dispatch_key_release(XKeyReleasedEvent * const x_event) {
149+
void dispatch_key_release(uint64_t time, xkb_keycode_t keycode) {
169150
// The X11 KeyCode associated with this event.
170151
KeySym keysym = 0x00;
171152

172-
x_key_event_lookup(x_event, NULL, 0, &keysym);
173-
174-
uint16_t uiocode = keysym_to_vcode(keysym);
175-
176-
// FIXME This can happen inside of keycode_to_scancode()
177-
if (uiocode == VC_SHIFT_L) { unset_modifier_mask(MASK_SHIFT_L); }
178-
else if (uiocode == VC_SHIFT_R) { unset_modifier_mask(MASK_SHIFT_R); }
179-
else if (uiocode == VC_CONTROL_L) { unset_modifier_mask(MASK_CTRL_L); }
180-
else if (uiocode == VC_CONTROL_R) { unset_modifier_mask(MASK_CTRL_R); }
181-
else if (uiocode == VC_ALT_L) { unset_modifier_mask(MASK_ALT_L); }
182-
else if (uiocode == VC_ALT_R) { unset_modifier_mask(MASK_ALT_R); }
183-
else if (uiocode == VC_META_L) { unset_modifier_mask(MASK_META_L); }
184-
else if (uiocode == VC_META_R) { unset_modifier_mask(MASK_META_R); }
185-
186-
// FIXME We shouldn't be doing this on each key release.
187-
//initialize_locks();
153+
uint16_t uiocode = keycode_to_uiocode(keycode);
188154

189155

190156
// Populate key released event.
191-
uio_event.time = x_event->serial;
157+
uio_event.time = time;
192158
uio_event.reserved = 0x00;
193159

194160
uio_event.type = EVENT_KEY_RELEASED;
195161
uio_event.mask = get_modifiers();
196162

197163
uio_event.data.keyboard.keycode = uiocode;
198-
uio_event.data.keyboard.rawcode = keysym;
164+
uio_event.data.keyboard.rawcode = keycode;
199165
uio_event.data.keyboard.keychar = CHAR_UNDEFINED;
200166

201167
logger(LOG_LEVEL_DEBUG, "%s [%u]: Key %#X released. (%#X)\n",
@@ -242,6 +208,8 @@ static void dispatch_mouse_wheel_rotated(XButtonEvent * const x_event) {
242208
/* Some scroll wheel properties are available via the new XInput2 (XI2) extension. Unfortunately the extension is
243209
* not available on my development platform at this time. For the time being we will just use the Windows default
244210
* value of 3. */
211+
212+
/*
245213
uio_event.data.wheel.delta = 100;
246214
if (x_event->button == WheelDown || x_event->button == WheelLeft) {
247215
// Wheel Rotated Up and Away.
@@ -258,7 +226,7 @@ static void dispatch_mouse_wheel_rotated(XButtonEvent * const x_event) {
258226
// Wheel Rotated Left or Right.
259227
uio_event.data.wheel.direction = WHEEL_HORIZONTAL_DIRECTION;
260228
}
261-
229+
*/
262230
logger(LOG_LEVEL_DEBUG, "%s [%u]: Mouse wheel %i / %u of type %u in the %u direction at %u, %u.\n",
263231
__FUNCTION__, __LINE__,
264232
uio_event.data.wheel.rotation, uio_event.data.wheel.delta,
@@ -270,6 +238,7 @@ static void dispatch_mouse_wheel_rotated(XButtonEvent * const x_event) {
270238
}
271239

272240
static void dispatch_mouse_button_pressed(XButtonPressedEvent * const x_event) {
241+
/*
273242
switch (x_event->button) {
274243
case Button1:
275244
x_event->button = MOUSE_BUTTON1;
@@ -305,7 +274,7 @@ static void dispatch_mouse_button_pressed(XButtonPressedEvent * const x_event) {
305274
x_event->button = MOUSE_NOBUTTON;
306275
}
307276
}
308-
277+
*/
309278
// Track the number of clicks, the button must match the previous button.
310279
if (x_event->button == click.button && x_event->serial - click.time <= hook_get_multi_click_time()) {
311280
if (click.count < UINT16_MAX) {
@@ -361,8 +330,8 @@ static void dispatch_mouse_button_pressed(XButtonPressedEvent * const x_event) {
361330
}
362331

363332
void dispatch_mouse_press(XButtonEvent * const x_event) {
364-
x_event->button = button_map_lookup(x_event->button);
365-
333+
x_event->button = 0; // FIXME button_map_lookup(x_event->button);
334+
/*
366335
switch (x_event->button) {
367336
case WheelUp:
368337
case WheelDown:
@@ -375,10 +344,12 @@ void dispatch_mouse_press(XButtonEvent * const x_event) {
375344
dispatch_mouse_button_pressed((XButtonPressedEvent *) x_event);
376345
break;
377346
}
347+
*/
378348
}
379349

380350
static void dispatch_mouse_button_released(XButtonReleasedEvent * const x_event) {
381-
switch (button_map_lookup(x_event->button)) {
351+
switch (0 /* FIXME button_map_lookup(x_event->button) */) {
352+
/*
382353
case Button1:
383354
x_event->button = MOUSE_BUTTON1;
384355
unset_modifier_mask(MASK_BUTTON1);
@@ -412,6 +383,7 @@ static void dispatch_mouse_button_released(XButtonReleasedEvent * const x_event)
412383
// Something screwed up, default to MOUSE_NOBUTTON
413384
x_event->button = MOUSE_NOBUTTON;
414385
}
386+
*/
415387
}
416388

417389
// Populate mouse released event.
@@ -484,16 +456,17 @@ static void dispatch_mouse_button_clicked(XButtonEvent * const x_event) {
484456
}
485457

486458
void dispatch_mouse_release(XButtonEvent * const x_event) {
487-
x_event->button = button_map_lookup(x_event->button);
459+
x_event->button = 0; // FIXME button_map_lookup(x_event->button);
488460

461+
/*
489462
switch (x_event->button) {
490463
case WheelUp:
491464
case WheelDown:
492465
case WheelLeft:
493466
case WheelRight:
494467
return;
495468
}
496-
469+
*/
497470
dispatch_mouse_button_released((XButtonReleasedEvent *) x_event);
498471

499472
// If the pressed event was not consumed...

src/evdev/dispatch_event.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
#include <xkbcommon/xkbcommon.h>
1920
#include <X11/Xlib.h>
2021

2122
// FIXME Shouldn't be extern, remove
2223
#include <uiohook.h>
24+
2325
extern void dispatch_event(uiohook_event *const uio_event);
2426

2527
extern void dispatch_hook_enabled();
2628

2729
extern void dispatch_hook_disabled();
2830

29-
extern void dispatch_key_press(XKeyPressedEvent * const x_event);
31+
extern void dispatch_key_press(uint64_t time, xkb_keycode_t keycode);
3032

31-
extern void dispatch_key_release(XKeyReleasedEvent * const x_event);
33+
extern void dispatch_key_release(uint64_t time, xkb_keycode_t keycode);
3234

3335
extern void dispatch_mouse_press(XButtonEvent * const x_event);
3436

0 commit comments

Comments
 (0)