wip keypress handling
This commit is contained in:
parent
56c30d5e3e
commit
fb813d3ba3
|
@ -147,13 +147,32 @@ static void grab_keycode_for_binding(xcb_connection_t *conn, Binding *bind, uint
|
|||
GRAB_KEY(mods | xcb_numlock_mask | XCB_MOD_MASK_LOCK);
|
||||
}
|
||||
|
||||
SCM guile_register_keyboard_key(SCM keycode, SCM modifier) {
|
||||
// keycode
|
||||
printf("Register key: %d, modifier: %d\n", scm_to_int(keycode), scm_to_int(modifier));
|
||||
xcb_grab_key(conn, 0, root,
|
||||
scm_to_int(modifier),
|
||||
scm_to_int(keycode),
|
||||
|
||||
// THIS IS JUST A PROOF OF CONCEPT. IT'S TERRIBLE AND SLOW
|
||||
void get_keycode(struct xkb_keymap *keymap, xkb_keycode_t key, char *data) {
|
||||
xkb_keysym_t sym = xkb_state_key_get_one_sym(xkb_state_new(xkb_keymap), key);
|
||||
if (data[0] == sym) {
|
||||
data[0] = key;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// THIS IS JUST A PROOF OF CONCEPT. IT'S TERRIBLE AND SLOW
|
||||
SCM guile_register_keyboard_key(SCM g_name, SCM modifier) {
|
||||
xkb_keysym_t sym = XStringToKeysym(scm_to_utf8_string(g_name));
|
||||
/* /\* load_keymap(); *\/ */
|
||||
/* char data[8]; */
|
||||
/* data[0] = sym; */
|
||||
/* xkb_keymap_key_for_each(xkb_keymap, get_keycode, &data); */
|
||||
/* xcb_keycode_t keycode = data[0]; */
|
||||
/* printf("Register key: %s, code: %d, sym: %d, modifier: %d\n", */
|
||||
/* scm_to_utf8_string(g_name), keycode, sym, scm_to_int(modifier)); */
|
||||
xcb_grab_key(conn, 0, root, scm_to_int(modifier),
|
||||
// FIXME: THIS IS WRONG,
|
||||
XCB_GRAB_ANY,
|
||||
/* keycode, */
|
||||
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
|
||||
|
||||
/* const int mods = (bind->event_state_mask & 0xFFFF); */
|
||||
/* DLOG("Binding %p Grabbing keycode %d with event state mask 0x%x (mods 0x%x)\n", */
|
||||
/* bind, keycode, bind->event_state_mask, mods); */
|
||||
|
|
|
@ -1276,7 +1276,7 @@ static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom)
|
|||
*
|
||||
*/
|
||||
void handle_event(int type, xcb_generic_event_t *event) {
|
||||
puts("handle_event");
|
||||
/* puts("handle_event"); */
|
||||
|
||||
if (type != XCB_MOTION_NOTIFY)
|
||||
DLOG("event type %d, xkb_base %d\n", type, xkb_base);
|
||||
|
@ -1288,7 +1288,7 @@ void handle_event(int type, xcb_generic_event_t *event) {
|
|||
}
|
||||
|
||||
if (xkb_base > -1 && type == xkb_base) {
|
||||
puts("xkb event, need to handle it.");
|
||||
/* puts("xkb event, need to handle it."); */
|
||||
|
||||
xcb_xkb_state_notify_event_t *state = (xcb_xkb_state_notify_event_t *)event;
|
||||
if (state->xkbType == XCB_XKB_NEW_KEYBOARD_NOTIFY) {
|
||||
|
@ -1314,7 +1314,7 @@ void handle_event(int type, xcb_generic_event_t *event) {
|
|||
(void)load_keymap();
|
||||
}
|
||||
} else if (state->xkbType == XCB_XKB_STATE_NOTIFY) {
|
||||
printf("xkb state group = %d, current = %d\n", state->group, xkb_current_group);
|
||||
/* printf("xkb state group = %d, current = %d\n", state->group, xkb_current_group); */
|
||||
if (xkb_current_group == state->group)
|
||||
return;
|
||||
xkb_current_group = state->group;
|
||||
|
@ -1346,37 +1346,30 @@ void handle_event(int type, xcb_generic_event_t *event) {
|
|||
return;
|
||||
}
|
||||
|
||||
puts("switch");
|
||||
switch (type) {
|
||||
case XCB_KEY_PRESS:
|
||||
case XCB_KEY_RELEASE:
|
||||
puts("handle_key_press");
|
||||
handle_key_press((xcb_key_press_event_t *)event);
|
||||
break;
|
||||
|
||||
case XCB_BUTTON_PRESS:
|
||||
case XCB_BUTTON_RELEASE:
|
||||
puts("handle_button_press");
|
||||
handle_button_press((xcb_button_press_event_t *)event);
|
||||
break;
|
||||
|
||||
case XCB_MAP_REQUEST:
|
||||
puts("handle_map_request");
|
||||
handle_map_request((xcb_map_request_event_t *)event);
|
||||
break;
|
||||
|
||||
case XCB_UNMAP_NOTIFY:
|
||||
puts("handle_unmap_notify_event");
|
||||
handle_unmap_notify_event((xcb_unmap_notify_event_t *)event);
|
||||
break;
|
||||
|
||||
case XCB_DESTROY_NOTIFY:
|
||||
puts("handle_destroy_notify_event");
|
||||
handle_destroy_notify_event((xcb_destroy_notify_event_t *)event);
|
||||
break;
|
||||
|
||||
case XCB_EXPOSE:
|
||||
puts("handle_expose_event");
|
||||
if (((xcb_expose_event_t *)event)->count == 0) {
|
||||
handle_expose_event((xcb_expose_event_t *)event);
|
||||
}
|
||||
|
@ -1384,13 +1377,11 @@ void handle_event(int type, xcb_generic_event_t *event) {
|
|||
break;
|
||||
|
||||
case XCB_MOTION_NOTIFY:
|
||||
puts("handle_motion_notify");
|
||||
handle_motion_notify((xcb_motion_notify_event_t *)event);
|
||||
break;
|
||||
|
||||
/* Enter window = user moved their mouse over the window */
|
||||
case XCB_ENTER_NOTIFY:
|
||||
puts("handle_enter_notify");
|
||||
handle_enter_notify((xcb_enter_notify_event_t *)event);
|
||||
break;
|
||||
|
||||
|
@ -1427,7 +1418,7 @@ void handle_event(int type, xcb_generic_event_t *event) {
|
|||
break;
|
||||
|
||||
default:
|
||||
printf("Unhandled event of type %d\n", type);
|
||||
/* printf("Unhandled event of type %d\n", type); */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
*/
|
||||
#include "all.h"
|
||||
#include "guile.h"
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
/*
|
||||
* There was a KeyPress or KeyRelease (both events have the same fields). We
|
||||
|
@ -21,13 +22,24 @@ void handle_key_press(xcb_key_press_event_t *event) {
|
|||
|
||||
last_timestamp = event->time;
|
||||
|
||||
printf("%s %d, state raw = 0x%x\n", (key_release ? "KeyRelease" : "KeyPress"), event->detail, event->state);
|
||||
/* printf("%s %d, state raw = 0x%x\n", (key_release ? "KeyRelease" : "KeyPress"), event->detail, event->state); */
|
||||
|
||||
int col = (event->state & XCB_MOD_MASK_SHIFT);
|
||||
xcb_keysym_t sym = xcb_key_press_lookup_keysym(keysyms, event, col);
|
||||
if (sym == XKB_KEY_NoSymbol) {
|
||||
ELOG("Could not translate string to key symbol: \"%s\"\n", sym);
|
||||
return;
|
||||
}
|
||||
|
||||
char buf[7];
|
||||
xkb_keysym_to_utf8(sym, buf, 7);
|
||||
|
||||
|
||||
// Let guile resolve the binding for us
|
||||
guile_hook("key-press-hook",
|
||||
scm_list_3(scm_from_int(event->response_type),
|
||||
scm_from_int(event->detail),
|
||||
scm_from_int(event->state)));
|
||||
scm_from_int(event->state),
|
||||
scm_from_utf8_string(buf)));
|
||||
|
||||
/* Binding *bind = get_binding_from_xcb_event((xcb_generic_event_t *)event); */
|
||||
|
||||
|
|
|
@ -678,6 +678,9 @@ int main(int argc, char *argv[]) {
|
|||
#include "atoms.xmacro"
|
||||
#undef xmacro
|
||||
|
||||
if (!load_keymap())
|
||||
die("Could not load keymap\n");
|
||||
|
||||
load_configuration(override_configpath, C_LOAD);
|
||||
|
||||
if (config.ipc_socket_path == NULL) {
|
||||
|
@ -808,8 +811,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
xcb_numlock_mask = aio_get_mod_mask_for(XCB_NUM_LOCK, keysyms);
|
||||
|
||||
if (!load_keymap())
|
||||
die("Could not load keymap\n");
|
||||
/* if (!load_keymap()) */
|
||||
/* die("Could not load keymap\n"); */
|
||||
|
||||
translate_keysyms();
|
||||
grab_all_keys(conn);
|
||||
|
|
Loading…
Reference in New Issue