* Make key symbols table, NumLock, ShiftLock and CapsLock global variables.
* Get CapsLock and ShiftLock masks properly and fix XLookupString() XCB equivalent.
This commit is contained in:
parent
bcdc000e2c
commit
1eab0e44e7
|
@ -103,10 +103,6 @@ typedef struct
|
||||||
xcb_connection_t *connection;
|
xcb_connection_t *connection;
|
||||||
/** Default screen number */
|
/** Default screen number */
|
||||||
int default_screen;
|
int default_screen;
|
||||||
/** Is the caps lock enabled? */
|
|
||||||
bool caps_lock;
|
|
||||||
/** Is the shift lock enabled? */
|
|
||||||
bool shift_lock;
|
|
||||||
/** The window */
|
/** The window */
|
||||||
SimpleWindow *sw;
|
SimpleWindow *sw;
|
||||||
/** The draw contet */
|
/** The draw contet */
|
||||||
|
@ -117,8 +113,14 @@ typedef struct
|
||||||
style_t normal;
|
style_t normal;
|
||||||
style_t focus;
|
style_t focus;
|
||||||
} styles;
|
} styles;
|
||||||
|
/** Key symbols */
|
||||||
|
xcb_key_symbols_t *keysyms;
|
||||||
/** Numlock mask */
|
/** Numlock mask */
|
||||||
unsigned int numlockmask;
|
unsigned int numlockmask;
|
||||||
|
/** Shiftlock mask */
|
||||||
|
unsigned int shiftlockmask;
|
||||||
|
/** Capslock mask */
|
||||||
|
unsigned int capslockmask;
|
||||||
/** The text */
|
/** The text */
|
||||||
char *text;
|
char *text;
|
||||||
/** The text when we asked to complete */
|
/** The text when we asked to complete */
|
||||||
|
@ -510,29 +512,17 @@ redraw(void)
|
||||||
* \todo use XKB!
|
* \todo use XKB!
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
x_lookup_string(xcb_key_press_event_t *e, char **buf, size_t *buf_len, xcb_keysym_t *ksym)
|
key_press_lookup_string(xcb_key_press_event_t *e,
|
||||||
|
char **buf, size_t *buf_len,
|
||||||
|
xcb_keysym_t *ksym)
|
||||||
{
|
{
|
||||||
xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(globalconf.connection);
|
|
||||||
xcb_keysym_t k0, k1;
|
xcb_keysym_t k0, k1;
|
||||||
|
|
||||||
/* 'col' (third parameter) is used to get the proper KeySym
|
/* 'col' (third parameter) is used to get the proper KeySym
|
||||||
* according to modifier (XCB doesn't provide an equivalent to
|
* according to modifier (XCB doesn't provide an equivalent to
|
||||||
* XLookupString()) */
|
* XLookupString()) */
|
||||||
k0 = xcb_key_press_lookup_keysym(keysyms, e, 0);
|
k0 = xcb_key_press_lookup_keysym(globalconf.keysyms, e, 0);
|
||||||
k1 = xcb_key_press_lookup_keysym(keysyms, e, 1);
|
k1 = xcb_key_press_lookup_keysym(globalconf.keysyms, e, 1);
|
||||||
|
|
||||||
xcb_key_symbols_free(keysyms);
|
|
||||||
|
|
||||||
if(xcb_is_modifier_key(k0) && !k1)
|
|
||||||
{
|
|
||||||
/* The Caps_Lock is now enabled */
|
|
||||||
if(k0 == XK_Caps_Lock)
|
|
||||||
globalconf.caps_lock = true;
|
|
||||||
|
|
||||||
/* The Shift lock is now enabled */
|
|
||||||
if(k0 == XK_Shift_Lock)
|
|
||||||
globalconf.shift_lock = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The numlock modifier is on and the second KeySym is a keypad
|
/* The numlock modifier is on and the second KeySym is a keypad
|
||||||
* KeySym */
|
* KeySym */
|
||||||
|
@ -541,7 +531,7 @@ x_lookup_string(xcb_key_press_event_t *e, char **buf, size_t *buf_len, xcb_keysy
|
||||||
/* The Shift modifier is on, or if the Lock modifier is on and
|
/* The Shift modifier is on, or if the Lock modifier is on and
|
||||||
* is interpreted as ShiftLock, use the first KeySym */
|
* is interpreted as ShiftLock, use the first KeySym */
|
||||||
if((e->state & XCB_MOD_MASK_SHIFT) ||
|
if((e->state & XCB_MOD_MASK_SHIFT) ||
|
||||||
(e->state & XCB_MOD_MASK_LOCK && globalconf.shift_lock))
|
(e->state & XCB_MOD_MASK_LOCK && (e->state & globalconf.shiftlockmask)))
|
||||||
*ksym = k0;
|
*ksym = k0;
|
||||||
else
|
else
|
||||||
*ksym = k1;
|
*ksym = k1;
|
||||||
|
@ -555,25 +545,25 @@ x_lookup_string(xcb_key_press_event_t *e, char **buf, size_t *buf_len, xcb_keysy
|
||||||
/* The Shift modifier is off and the Lock modifier is on and is
|
/* The Shift modifier is off and the Lock modifier is on and is
|
||||||
* interpreted as CapsLock */
|
* interpreted as CapsLock */
|
||||||
else if(!(e->state & XCB_MOD_MASK_SHIFT) &&
|
else if(!(e->state & XCB_MOD_MASK_SHIFT) &&
|
||||||
(e->state & XCB_MOD_MASK_LOCK && globalconf.caps_lock))
|
(e->state & XCB_MOD_MASK_LOCK && (e->state & globalconf.capslockmask)))
|
||||||
/* TODO: The first Keysym is used but if that KeySym is
|
/* The first Keysym is used but if that KeySym is lowercase
|
||||||
* lowercase alphabetic, then the corresponding uppercase
|
* alphabetic, then the corresponding uppercase KeySym is used
|
||||||
* KeySym is used instead */
|
* instead */
|
||||||
*ksym = k0;
|
*ksym = k1;
|
||||||
|
|
||||||
/* The Shift modifier is on, and the Lock modifier is on and is
|
/* The Shift modifier is on, and the Lock modifier is on and is
|
||||||
* interpreted as CapsLock */
|
* interpreted as CapsLock */
|
||||||
else if((e->state & XCB_MOD_MASK_SHIFT) &&
|
else if((e->state & XCB_MOD_MASK_SHIFT) &&
|
||||||
(e->state & XCB_MOD_MASK_LOCK && globalconf.caps_lock))
|
(e->state & XCB_MOD_MASK_LOCK && (e->state & globalconf.capslockmask)))
|
||||||
/* TODO: The second Keysym is used but if that KeySym is
|
/* The second Keysym is used but if that KeySym is lowercase
|
||||||
* lowercase alphabetic, then the corresponding uppercase
|
* alphabetic, then the corresponding uppercase KeySym is used
|
||||||
* KeySym is used instead */
|
* instead */
|
||||||
*ksym = k1;
|
*ksym = k1;
|
||||||
|
|
||||||
/* The Shift modifer is on, or the Lock modifier is on and is
|
/* The Shift modifer is on, or the Lock modifier is on and is
|
||||||
* interpreted as ShiftLock, or both */
|
* interpreted as ShiftLock, or both */
|
||||||
else if((e->state & XCB_MOD_MASK_SHIFT) ||
|
else if((e->state & XCB_MOD_MASK_SHIFT) ||
|
||||||
(e->state & XCB_MOD_MASK_LOCK && globalconf.shift_lock))
|
(e->state & XCB_MOD_MASK_LOCK && (e->state & globalconf.shiftlockmask)))
|
||||||
*ksym = k1;
|
*ksym = k1;
|
||||||
|
|
||||||
if(xcb_is_modifier_key(*ksym) || xcb_is_function_key(*ksym) ||
|
if(xcb_is_modifier_key(*ksym) || xcb_is_function_key(*ksym) ||
|
||||||
|
@ -607,7 +597,7 @@ handle_kpress(xcb_key_press_event_t *e)
|
||||||
|
|
||||||
len = a_strlen(globalconf.text);
|
len = a_strlen(globalconf.text);
|
||||||
|
|
||||||
x_lookup_string(e, &buf, &num, &ksym);
|
key_press_lookup_string(e, &buf, &num, &ksym);
|
||||||
/* Got a special key, see x_lookup_string() */
|
/* Got a special key, see x_lookup_string() */
|
||||||
if(!num)
|
if(!num)
|
||||||
return;
|
return;
|
||||||
|
@ -931,10 +921,11 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
|
|
||||||
/* TODO: do we need to check at startup that the Caps_Lock and
|
globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection);
|
||||||
* Shift_Lock keys are pressed? */
|
|
||||||
globalconf.caps_lock = false;
|
/* Get the numlock, capslock and shiftlock mask */
|
||||||
globalconf.shift_lock = false;
|
xutil_get_lock_mask(conn, globalconf.keysyms, &globalconf.numlockmask,
|
||||||
|
&globalconf.shiftlockmask, &globalconf.capslockmask);
|
||||||
|
|
||||||
xutil_map_raised(globalconf.connection, globalconf.sw->window);
|
xutil_map_raised(globalconf.connection, globalconf.sw->window);
|
||||||
|
|
||||||
|
@ -982,6 +973,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xcb_key_symbols_free(globalconf.keysyms);
|
||||||
p_delete(&globalconf.text);
|
p_delete(&globalconf.text);
|
||||||
draw_context_delete(&globalconf.ctx);
|
draw_context_delete(&globalconf.ctx);
|
||||||
simplewindow_delete(&globalconf.sw);
|
simplewindow_delete(&globalconf.sw);
|
||||||
|
|
|
@ -411,7 +411,14 @@ main(int argc, char *argv[])
|
||||||
XSynchronize(dpy, true);
|
XSynchronize(dpy, true);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* store display */
|
/* Allocate the key symbols */
|
||||||
|
globalconf.keysyms = xcb_key_symbols_alloc(conn);
|
||||||
|
|
||||||
|
/* Get the NumLock, ShiftLock and CapsLock masks */
|
||||||
|
xutil_get_lock_mask(conn, globalconf.keysyms, &globalconf.numlockmask,
|
||||||
|
&globalconf.shiftlockmask, &globalconf.capslockmask);
|
||||||
|
|
||||||
|
/* store connection */
|
||||||
globalconf.connection = conn;
|
globalconf.connection = conn;
|
||||||
|
|
||||||
/* init EWMH atoms */
|
/* init EWMH atoms */
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include <xcb/xcb_aux.h>
|
#include <xcb/xcb_aux.h>
|
||||||
#include <xcb/xcb_atom.h>
|
#include <xcb/xcb_atom.h>
|
||||||
#include <xcb/xinerama.h>
|
#include <xcb/xinerama.h>
|
||||||
#include <xcb/xcb_keysyms.h>
|
|
||||||
|
|
||||||
#include "common/util.h"
|
#include "common/util.h"
|
||||||
#include "common/xutil.h"
|
#include "common/xutil.h"
|
||||||
|
@ -67,13 +66,14 @@ xgettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
void
|
||||||
xgetnumlockmask(xcb_connection_t *conn)
|
xutil_get_lock_mask(xcb_connection_t *conn, xcb_key_symbols_t *keysyms,
|
||||||
|
unsigned int *numlockmask, unsigned int *shiftlockmask,
|
||||||
|
unsigned int *capslockmask)
|
||||||
{
|
{
|
||||||
xcb_get_modifier_mapping_reply_t *modmap_r;
|
xcb_get_modifier_mapping_reply_t *modmap_r;
|
||||||
xcb_keycode_t *modmap;
|
xcb_keycode_t *modmap, kc;
|
||||||
xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(conn);
|
unsigned int mask;
|
||||||
unsigned int mask = 0;
|
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
modmap_r = xcb_get_modifier_mapping_reply(conn,
|
modmap_r = xcb_get_modifier_mapping_reply(conn,
|
||||||
|
@ -84,14 +84,22 @@ xgetnumlockmask(xcb_connection_t *conn)
|
||||||
|
|
||||||
for(i = 0; i < 8; i++)
|
for(i = 0; i < 8; i++)
|
||||||
for(j = 0; j < modmap_r->keycodes_per_modifier; j++)
|
for(j = 0; j < modmap_r->keycodes_per_modifier; j++)
|
||||||
if(modmap[i * modmap_r->keycodes_per_modifier + j]
|
{
|
||||||
== xcb_key_symbols_get_keycode(keysyms, XK_Num_Lock))
|
kc = modmap[i * modmap_r->keycodes_per_modifier + j];
|
||||||
mask = (1 << i);
|
mask = (1 << i);
|
||||||
|
|
||||||
|
if(numlockmask != NULL &&
|
||||||
|
kc == xcb_key_symbols_get_keycode(keysyms, XK_Num_Lock))
|
||||||
|
*numlockmask = mask;
|
||||||
|
else if(shiftlockmask != NULL &&
|
||||||
|
kc == xcb_key_symbols_get_keycode(keysyms, XK_Shift_Lock))
|
||||||
|
*shiftlockmask = mask;
|
||||||
|
else if(capslockmask != NULL &&
|
||||||
|
kc == xcb_key_symbols_get_keycode(keysyms, XK_Caps_Lock))
|
||||||
|
*capslockmask = mask;
|
||||||
|
}
|
||||||
|
|
||||||
p_delete(&modmap_r);
|
p_delete(&modmap_r);
|
||||||
xcb_key_symbols_free(keysyms);
|
|
||||||
|
|
||||||
return mask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Equivalent to 'XGetTransientForHint' which is actually a
|
/** Equivalent to 'XGetTransientForHint' which is actually a
|
||||||
|
|
|
@ -25,12 +25,14 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
#include <xcb/xcb_keysyms.h>
|
||||||
|
|
||||||
/* XCB doesn't provide keysyms definition */
|
/* XCB doesn't provide keysyms definition */
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
|
|
||||||
bool xgettextprop(xcb_connection_t *, xcb_window_t, xcb_atom_t, char *, ssize_t);
|
bool xgettextprop(xcb_connection_t *, xcb_window_t, xcb_atom_t, char *, ssize_t);
|
||||||
unsigned int xgetnumlockmask(xcb_connection_t *);
|
void xutil_get_lock_mask(xcb_connection_t *, xcb_key_symbols_t *,
|
||||||
|
unsigned int *, unsigned int *, unsigned int *);
|
||||||
|
|
||||||
/* See http://tronche.com/gui/x/xlib/appendix/b/ for values */
|
/* See http://tronche.com/gui/x/xlib/appendix/b/ for values */
|
||||||
#define CURSOR_FLEUR 52
|
#define CURSOR_FLEUR 52
|
||||||
|
|
4
config.c
4
config.c
|
@ -22,7 +22,6 @@
|
||||||
/* XStringToKeysym() */
|
/* XStringToKeysym() */
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
#include <xcb/xcb_keysyms.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -561,9 +560,6 @@ config_parse(const char *confpatharg)
|
||||||
/* Mouse: titlebar windows click bindings */
|
/* Mouse: titlebar windows click bindings */
|
||||||
globalconf.buttons.titlebar = parse_mouse_bindings(cfg_mouse, "titlebar", true);
|
globalconf.buttons.titlebar = parse_mouse_bindings(cfg_mouse, "titlebar", true);
|
||||||
|
|
||||||
/* Keys */
|
|
||||||
globalconf.numlockmask = xgetnumlockmask(globalconf.connection);
|
|
||||||
|
|
||||||
globalconf.keys = section_keys(cfg_keys);
|
globalconf.keys = section_keys(cfg_keys);
|
||||||
|
|
||||||
if(defconfig)
|
if(defconfig)
|
||||||
|
|
11
event.c
11
event.c
|
@ -388,7 +388,6 @@ event_handle_keypress(void *data __attribute__ ((unused)),
|
||||||
{
|
{
|
||||||
int screen;
|
int screen;
|
||||||
xcb_query_pointer_reply_t *qpr = NULL;
|
xcb_query_pointer_reply_t *qpr = NULL;
|
||||||
xcb_key_symbols_t *keysyms;
|
|
||||||
xcb_keysym_t keysym;
|
xcb_keysym_t keysym;
|
||||||
Key *k;
|
Key *k;
|
||||||
|
|
||||||
|
@ -407,16 +406,13 @@ event_handle_keypress(void *data __attribute__ ((unused)),
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
keysyms = xcb_key_symbols_alloc(globalconf.connection);
|
keysym = xcb_key_symbols_get_keysym(globalconf.keysyms, ev->detail, 0);
|
||||||
keysym = xcb_key_symbols_get_keysym(keysyms, ev->detail, 0);
|
|
||||||
|
|
||||||
for(k = globalconf.keys; k; k = k->next)
|
for(k = globalconf.keys; k; k = k->next)
|
||||||
if(((k->keycode && ev->detail == k->keycode) || (k->keysym && keysym == k->keysym))
|
if(((k->keycode && ev->detail == k->keycode) || (k->keysym && keysym == k->keysym))
|
||||||
&& k->func && CLEANMASK(k->mod) == CLEANMASK(ev->state))
|
&& k->func && CLEANMASK(k->mod) == CLEANMASK(ev->state))
|
||||||
k->func(screen, k->arg);
|
k->func(screen, k->arg);
|
||||||
|
|
||||||
xcb_key_symbols_free(keysyms);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,11 +425,8 @@ event_handle_mappingnotify(void *data __attribute__ ((unused)),
|
||||||
xcb_connection_t *connection, xcb_mapping_notify_event_t *ev)
|
xcb_connection_t *connection, xcb_mapping_notify_event_t *ev)
|
||||||
{
|
{
|
||||||
int screen;
|
int screen;
|
||||||
xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(connection);
|
|
||||||
|
|
||||||
xcb_refresh_keyboard_mapping(keysyms, ev);
|
|
||||||
xcb_key_symbols_free(keysyms);
|
|
||||||
|
|
||||||
|
xcb_refresh_keyboard_mapping(globalconf.keysyms, ev);
|
||||||
if(ev->request == XCB_MAPPING_KEYBOARD)
|
if(ev->request == XCB_MAPPING_KEYBOARD)
|
||||||
for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup(connection)); screen++)
|
for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup(connection)); screen++)
|
||||||
window_root_grabkeys(screen);
|
window_root_grabkeys(screen);
|
||||||
|
|
|
@ -348,6 +348,8 @@ struct AwesomeConf
|
||||||
xcb_event_handlers_t *evenths;
|
xcb_event_handlers_t *evenths;
|
||||||
/** Default screen number */
|
/** Default screen number */
|
||||||
int default_screen;
|
int default_screen;
|
||||||
|
/** Keys symbol table */
|
||||||
|
xcb_key_symbols_t *keysyms;
|
||||||
/** Logical screens */
|
/** Logical screens */
|
||||||
VirtScreen *screens;
|
VirtScreen *screens;
|
||||||
/** Screens info */
|
/** Screens info */
|
||||||
|
@ -365,6 +367,10 @@ struct AwesomeConf
|
||||||
} buttons;
|
} buttons;
|
||||||
/** Numlock mask */
|
/** Numlock mask */
|
||||||
unsigned int numlockmask;
|
unsigned int numlockmask;
|
||||||
|
/** Numlock mask */
|
||||||
|
unsigned int shiftlockmask;
|
||||||
|
/** Numlock mask */
|
||||||
|
unsigned int capslockmask;
|
||||||
/** Check for XShape extension */
|
/** Check for XShape extension */
|
||||||
bool have_shape;
|
bool have_shape;
|
||||||
/** Check for XRandR extension */
|
/** Check for XRandR extension */
|
||||||
|
|
7
window.c
7
window.c
|
@ -180,15 +180,12 @@ window_root_grabkeys(int phys_screen)
|
||||||
{
|
{
|
||||||
Key *k;
|
Key *k;
|
||||||
xcb_keycode_t kc;
|
xcb_keycode_t kc;
|
||||||
xcb_key_symbols_t *keysyms;
|
|
||||||
|
|
||||||
xcb_ungrab_key(globalconf.connection, ANY_KEY,
|
xcb_ungrab_key(globalconf.connection, ANY_KEY,
|
||||||
root_window(globalconf.connection, phys_screen), ANY_MODIFIER);
|
root_window(globalconf.connection, phys_screen), ANY_MODIFIER);
|
||||||
|
|
||||||
keysyms = xcb_key_symbols_alloc(globalconf.connection);
|
|
||||||
|
|
||||||
for(k = globalconf.keys; k; k = k->next)
|
for(k = globalconf.keys; k; k = k->next)
|
||||||
if((kc = k->keycode) || (k->keysym && (kc = xcb_key_symbols_get_keycode(keysyms, k->keysym))))
|
if((kc = k->keycode) || (k->keysym && (kc = xcb_key_symbols_get_keycode(globalconf.keysyms, k->keysym))))
|
||||||
{
|
{
|
||||||
xcb_grab_key(globalconf.connection, true, root_window(globalconf.connection, phys_screen),
|
xcb_grab_key(globalconf.connection, true, root_window(globalconf.connection, phys_screen),
|
||||||
k->mod, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
k->mod, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
||||||
|
@ -200,8 +197,6 @@ window_root_grabkeys(int phys_screen)
|
||||||
k->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC,
|
k->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC,
|
||||||
XCB_GRAB_MODE_ASYNC);
|
XCB_GRAB_MODE_ASYNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
xcb_key_symbols_free(keysyms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue