all repos — openbox @ 096dad0c6c027100494ede811b33cb8558d32e25

openbox fork - make it a bit more like ryudo

make control keys work in menus/dialogs/etc with the new obt code, using XLookup stuff
Dana Jansens danakj@orodu.net
commit

096dad0c6c027100494ede811b33cb8558d32e25

parent

6c760c5a63a2e49bc2a5a4f39f8b4b9ed285bd7e

M obt/keyboard.cobt/keyboard.c

@@ -281,7 +281,7 @@ }

return ret; } -gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XKeyPressedEvent *ev) +gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XEvent *ev) { gunichar unikey = 0; KeySym sym;

@@ -289,6 +289,8 @@ Status status;

gchar *buf, fixbuf[4]; /* 4 is enough for a utf8 char */ gint len, bufsz; gboolean got_string = FALSE; + + g_return_val_if_fail(ev->type == KeyPress, 0); if (!ic) g_warning("Using obt_keyboard_keypress_to_unichar() without an "

@@ -299,9 +301,9 @@ buf = fixbuf;

bufsz = sizeof(fixbuf); #ifdef X_HAVE_UTF8_STRING - len = Xutf8LookupString(ic->xic, ev, buf, bufsz, &sym, &status); + len = Xutf8LookupString(ic->xic, &ev->xkey, buf, bufsz, &sym, &status); #else - len = XmbLookupString(ic->xic, ev, buf, bufsz, &sym, &status); + len = XmbLookupString(ic->xic, &ev->xkey, buf, bufsz, &sym, &status); #endif if (status == XBufferOverflow) {

@@ -309,9 +311,11 @@ buf = g_new(char, len);

bufsz = len; #ifdef X_HAVE_UTF8_STRING - len = Xutf8LookupString(ic->xic, ev, buf, bufsz, &sym, &status); + len = Xutf8LookupString(ic->xic, &ev->xkey, buf, bufsz, &sym, + &status); #else - len = XmbLookupString(ic->xic, ev, buf, bufsz, &sym, &status); + len = XmbLookupString(ic->xic, &ev->xkey, buf, bufsz, &sym, + &status); #endif }

@@ -338,7 +342,7 @@ }

else { buf = fixbuf; bufsz = sizeof(fixbuf); - len = XLookupString(ev, buf, bufsz, &sym, NULL); + len = XLookupString(&ev->xkey, buf, bufsz, &sym, NULL); if ((guchar)buf[0] >= 32) /* not an ascii control character */ got_string = TRUE; }

@@ -352,6 +356,18 @@

if (buf != fixbuf) g_free(buf); return unikey; +} + +KeySym obt_keyboard_keypress_to_keysym(XEvent *ev) +{ + KeySym sym; + gint r; + + g_return_val_if_fail(ev->type == KeyPress, None); + + sym = None; + r = XLookupString(&ev->xkey, NULL, 0, &sym, NULL); + return sym; } void obt_keyboard_context_renew(ObtIC *ic)
M obt/keyboard.hobt/keyboard.h

@@ -21,6 +21,7 @@ #define __obt_keyboard_h

#include <glib.h> #include <X11/Xlib.h> +#include <X11/keysym.h> G_BEGIN_DECLS

@@ -60,7 +61,11 @@ /*! Convert a KeySym to all the KeyCodes which generate it. */

KeyCode* obt_keyboard_keysym_to_keycode(KeySym sym); /*! Translate a KeyPress event to the unicode character it represents */ -gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XKeyPressedEvent *ev); +gunichar obt_keyboard_keypress_to_unichar(ObtIC *ic, XEvent *ev); + +/*! Translate a KeyPress event to the KeySym that it represents. Use this + for control keys, not for getting text input! */ +KeySym obt_keyboard_keypress_to_keysym(XEvent *ev); /*! Create an input context for a window. @client The top-level client window for the input context.
M openbox/actions/cyclewindows.copenbox/actions/cyclewindows.c

@@ -185,17 +185,17 @@ mods &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);

} if (e->type == KeyPress) { + KeySym sym = obt_keyboard_keypress_to_keysym(e); + /* Escape cancels no matter what */ - if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) { + if (sym == XK_Escape) { o->cancel = TRUE; o->state = e->xkey.state; return FALSE; } /* There were no modifiers and they pressed enter */ - else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RETURN) && - !initial_state) - { + else if (sym == XK_Return && !initial_state) { o->cancel = FALSE; o->state = e->xkey.state; return FALSE;
M openbox/actions/desktop.copenbox/actions/desktop.c

@@ -312,17 +312,15 @@ mods &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);

} if (e->type == KeyPress) { + KeySym sym = obt_keyboard_keypress_to_keysym(e); + /* Escape cancels no matter what */ - if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) { + if (sym == XK_Escape) return FALSE; - } /* There were no modifiers and they pressed enter */ - else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RETURN) && - !initial_state) - { + else if (sym == XK_Return && !initial_state) return FALSE; - } } /* They released the modifiers */ else if (e->type == KeyRelease && initial_state && !(mods & initial_state))
M openbox/actions/directionalwindows.copenbox/actions/directionalwindows.c

@@ -269,16 +269,16 @@ mods &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);

} if (e->type == KeyPress) { + KeySym sym = obt_keyboard_keypress_to_keysym(e); + /* Escape cancels no matter what */ - if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) { + if (sym == XK_Escape) { end_cycle(TRUE, e->xkey.state, options); return FALSE; } /* There were no modifiers and they pressed enter */ - else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RETURN) && - !initial_state) - { + else if (sym == XK_Return && !initial_state) { end_cycle(FALSE, e->xkey.state, options); return FALSE; }
M openbox/event.copenbox/event.c

@@ -1777,20 +1777,20 @@

/* Allow control while going thru the menu */ else if (ev->type == KeyPress && (mods & ~ControlMask) == 0) { gunichar unikey; + KeySym sym; frame->got_press = TRUE; frame->press_keycode = ev->xkey.keycode; frame->press_doexec = FALSE; - unikey = obt_keyboard_keypress_to_unichar(menu_frame_ic(frame), - &ev->xkey); + sym = obt_keyboard_keypress_to_keysym(ev); - if (ob_keycode_match(ev->xkey.keycode, OB_KEY_ESCAPE)) { + if (sym == XK_Escape) { menu_frame_hide_all(); ret = TRUE; } - else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_LEFT)) { + else if (sym == XK_Left) { /* Left goes to the parent menu */ if (frame->parent) { /* remove focus from the child */

@@ -1802,7 +1802,7 @@ }

ret = TRUE; } - else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_RIGHT)) { + else if (sym == XK_Right) { /* Right goes to the selected submenu */ if (frame->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {

@@ -1813,28 +1813,37 @@ }

ret = TRUE; } - else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_UP)) { + else if (sym == XK_Up) { menu_frame_select_previous(frame); ret = TRUE; } - else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_DOWN)) { + else if (sym == XK_Down) { menu_frame_select_next(frame); ret = TRUE; } - else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_HOME)) { + else if (sym == XK_Home) { menu_frame_select_first(frame); ret = TRUE; } - else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_END)) { + else if (sym == XK_End) { menu_frame_select_last(frame); ret = TRUE; } + else if (sym == XK_Return) { + frame->press_doexec = TRUE; + ret = TRUE; + } + /* keyboard accelerator shortcuts. (if it was a valid key) */ - else if (unikey) { + else if (frame->entries && + (unikey = + obt_keyboard_keypress_to_unichar(menu_frame_ic(frame), + ev))) + { GList *start; GList *it; ObMenuEntryFrame *found = NULL;

@@ -1885,27 +1894,15 @@ /* Use KeyRelease events for running things so that the key release

doesn't get sent to the focused application. Allow ControlMask only, and don't bother if the menu is empty */ - else if (ev->type == KeyRelease && (mods & ~ControlMask) == 0 && - frame->entries && frame->got_press) - { - if (ob_keycode_match(ev->xkey.keycode, OB_KEY_RETURN)) { - /* Enter runs the active item or goes into the submenu. - Control-Enter runs it without closing the menu. */ - if (frame->child) - menu_frame_select_next(frame->child); - else if (frame->selected) - menu_entry_frame_execute(frame->selected, ev->xkey.state); - - ret = TRUE; - } - + else if (ev->type == KeyRelease && (mods & ~ControlMask) == 0) { if (frame->press_keycode == ev->xkey.keycode && + frame->got_press && frame->press_doexec) { - if (frame->selected->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) + if (frame->child) + menu_frame_select_next(frame->child); + else if (frame->selected) menu_entry_frame_execute(frame->selected, ev->xkey.state); - else - menu_frame_select_next(frame->child); } } }
M openbox/misc.hopenbox/misc.h

@@ -45,21 +45,6 @@ } ObCursor;

typedef enum { - OB_KEY_RETURN, - OB_KEY_ESCAPE, - OB_KEY_LEFT, - OB_KEY_RIGHT, - OB_KEY_UP, - OB_KEY_DOWN, - OB_KEY_TAB, - OB_KEY_SPACE, - OB_KEY_HOME, - OB_KEY_END, - OB_NUM_KEYS -} ObKey; - -typedef enum -{ OB_STATE_STARTING, OB_STATE_RUNNING, OB_STATE_EXITING,
M openbox/moveresize.copenbox/moveresize.c

@@ -594,24 +594,25 @@ {

obt_main_loop_timeout_remove(ob_main_loop, edge_warp_delay_func); } -static void move_with_keys(gint keycode, gint state) +static void move_with_keys(KeySym sym, guint state) { gint dx = 0, dy = 0, ox = cur_x, oy = cur_y; gint opx, px, opy, py; gint dist = 0; /* shift means jump to edge */ - if (state & obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT)) { + if (state & obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT)) + { gint x, y; ObDirection dir; - if (ob_keycode_match(keycode, OB_KEY_RIGHT)) + if (sym == XK_Right) dir = OB_DIRECTION_EAST; - else if (ob_keycode_match(keycode, OB_KEY_LEFT)) + else if (sym == XK_Left) dir = OB_DIRECTION_WEST; - else if (ob_keycode_match(keycode, OB_KEY_DOWN)) + else if (sym == XK_Down) dir = OB_DIRECTION_SOUTH; - else /* if (ob_keycode_match(keycode, OB_KEY_UP)) */ + else /* sym == XK_Up */ dir = OB_DIRECTION_NORTH; client_find_move_directional(moveresize_client, dir, &x, &y);

@@ -627,13 +628,13 @@ }

else dist = KEY_DIST; - if (ob_keycode_match(keycode, OB_KEY_RIGHT)) + if (sym == XK_Right) dx = dist; - else if (ob_keycode_match(keycode, OB_KEY_LEFT)) + else if (sym == XK_Left) dx = -dist; - else if (ob_keycode_match(keycode, OB_KEY_DOWN)) + else if (sym == XK_Down) dy = dist; - else /* if (ob_keycode_match(keycode, OB_KEY_UP)) */ + else /* if (sym == XK_Up) */ dy = -dist; }

@@ -659,14 +660,14 @@ start_x += (px - opx) - (cur_x - ox);

start_y += (py - opy) - (cur_y - oy); } -static void resize_with_keys(gint keycode, gint state) +static void resize_with_keys(KeySym sym, guint state) { gint dw = 0, dh = 0, pdx = 0, pdy = 0, opx, opy, px, py; gint resist = 0; ObDirection dir; /* pick the edge if it needs to move */ - if (ob_keycode_match(keycode, OB_KEY_RIGHT)) { + if (sym == XK_Right) { dir = OB_DIRECTION_EAST; if (key_resize_edge != OB_DIRECTION_WEST && key_resize_edge != OB_DIRECTION_EAST)

@@ -674,7 +675,7 @@ {

key_resize_edge = OB_DIRECTION_EAST; return; } - } else if (ob_keycode_match(keycode, OB_KEY_LEFT)) { + } else if (sym == XK_Left) { dir = OB_DIRECTION_WEST; if (key_resize_edge != OB_DIRECTION_WEST && key_resize_edge != OB_DIRECTION_EAST)

@@ -682,7 +683,7 @@ {

key_resize_edge = OB_DIRECTION_WEST; return; } - } else if (ob_keycode_match(keycode, OB_KEY_UP)) { + } else if (sym == XK_Up) { dir = OB_DIRECTION_NORTH; if (key_resize_edge != OB_DIRECTION_NORTH && key_resize_edge != OB_DIRECTION_SOUTH)

@@ -690,7 +691,7 @@ {

key_resize_edge = OB_DIRECTION_NORTH; return; } - } else /* if (ob_keycode_match(keycode, OB_KEY_DOWN)) */ { + } else /* if (sym == XK_Down) */ { dir = OB_DIRECTION_SOUTH; if (key_resize_edge != OB_DIRECTION_NORTH && key_resize_edge != OB_DIRECTION_SOUTH)

@@ -701,16 +702,17 @@ }

} /* shift means jump to edge */ - if (state & obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT)) { + if (state & obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT)) + { gint x, y, w, h; - if (ob_keycode_match(keycode, OB_KEY_RIGHT)) + if (sym == XK_Right) dir = OB_DIRECTION_EAST; - else if (ob_keycode_match(keycode, OB_KEY_LEFT)) + else if (sym == XK_Left) dir = OB_DIRECTION_WEST; - else if (ob_keycode_match(keycode, OB_KEY_DOWN)) + else if (sym == XK_Down) dir = OB_DIRECTION_SOUTH; - else /* if (ob_keycode_match(keycode, OB_KEY_UP)) */ + else /* if (sym == XK_Up)) */ dir = OB_DIRECTION_NORTH; client_find_resize_directional(moveresize_client, key_resize_edge,

@@ -912,24 +914,24 @@ do_resize();

} used = TRUE; } else if (e->type == KeyPress) { - if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) { + KeySym sym = obt_keyboard_keypress_to_keysym(e); + + if (sym == XK_Escape) { moveresize_end(TRUE); used = TRUE; - } else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RETURN)) { + } else if (sym == XK_Return) { moveresize_end(FALSE); used = TRUE; - } else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RIGHT) || - ob_keycode_match(e->xkey.keycode, OB_KEY_LEFT) || - ob_keycode_match(e->xkey.keycode, OB_KEY_DOWN) || - ob_keycode_match(e->xkey.keycode, OB_KEY_UP)) + } else if (sym == XK_Right || sym == XK_Left || + sym == XK_Up || sym == XK_Down) { if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) { - resize_with_keys(e->xkey.keycode, e->xkey.state); + resize_with_keys(sym, e->xkey.state); used = TRUE; } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD)) { - move_with_keys(e->xkey.keycode, e->xkey.state); + move_with_keys(sym, e->xkey.state); used = TRUE; } }
M openbox/openbox.copenbox/openbox.c

@@ -80,9 +80,6 @@ #if USE_XCURSOR

#include <X11/Xcursor/Xcursor.h> #endif -#include <X11/Xlib.h> -#include <X11/keysym.h> - RrInstance *ob_rr_inst; RrImageCache *ob_rr_icons; RrTheme *ob_rr_theme;

@@ -101,7 +98,6 @@ static gboolean reconfigure = FALSE;

static gboolean restart = FALSE; static gchar *restart_path = NULL; static Cursor cursors[OB_NUM_CURSORS]; -static KeyCode *keys[OB_NUM_KEYS]; static gint exitcode = 0; static guint remote_control = 0; static gboolean being_replaced = FALSE;

@@ -216,18 +212,6 @@ do {

ObPrompt *xmlprompt = NULL; if (reconfigure) obt_keyboard_reload(); - - /* get the keycodes for keys we use */ - keys[OB_KEY_RETURN] = obt_keyboard_keysym_to_keycode(XK_Return); - keys[OB_KEY_ESCAPE] = obt_keyboard_keysym_to_keycode(XK_Escape); - keys[OB_KEY_LEFT] = obt_keyboard_keysym_to_keycode(XK_Left); - keys[OB_KEY_RIGHT] = obt_keyboard_keysym_to_keycode(XK_Right); - keys[OB_KEY_UP] = obt_keyboard_keysym_to_keycode(XK_Up); - keys[OB_KEY_DOWN] = obt_keyboard_keysym_to_keycode(XK_Down); - keys[OB_KEY_TAB] = obt_keyboard_keysym_to_keycode(XK_Tab); - keys[OB_KEY_SPACE] = obt_keyboard_keysym_to_keycode(XK_space); - keys[OB_KEY_HOME] = obt_keyboard_keysym_to_keycode(XK_Home); - keys[OB_KEY_END] = obt_keyboard_keysym_to_keycode(XK_End); { ObtXmlInst *i;

@@ -405,18 +389,6 @@ sn_shutdown(reconfigure);

event_shutdown(reconfigure); config_shutdown(); actions_shutdown(reconfigure); - - /* Free the key codes for built in keys */ - g_free(keys[OB_KEY_RETURN]); - g_free(keys[OB_KEY_ESCAPE]); - g_free(keys[OB_KEY_LEFT]); - g_free(keys[OB_KEY_RIGHT]); - g_free(keys[OB_KEY_UP]); - g_free(keys[OB_KEY_DOWN]); - g_free(keys[OB_KEY_TAB]); - g_free(keys[OB_KEY_SPACE]); - g_free(keys[OB_KEY_HOME]); - g_free(keys[OB_KEY_END]); } while (reconfigure); }

@@ -735,16 +707,6 @@ Cursor ob_cursor(ObCursor cursor)

{ g_assert(cursor < OB_NUM_CURSORS); return cursors[cursor]; -} - -gboolean ob_keycode_match(KeyCode code, ObKey key) -{ - KeyCode *k; - - g_assert(key < OB_NUM_KEYS); - for (k = keys[key]; *k; ++k) - if (*k == code) return TRUE; - return FALSE; } ObState ob_state(void)
M openbox/openbox.hopenbox/openbox.h

@@ -27,7 +27,6 @@ #include "obt/mainloop.h"

#include "obt/display.h" #include <glib.h> -#include <X11/Xlib.h> extern RrInstance *ob_rr_inst; extern RrImageCache *ob_rr_icons;

@@ -61,7 +60,5 @@

void ob_exit_with_error(const gchar *msg) G_GNUC_NORETURN; Cursor ob_cursor(ObCursor cursor); - -gboolean ob_keycode_match(KeyCode code, ObKey key); #endif
M openbox/prompt.copenbox/prompt.c

@@ -525,6 +525,7 @@ gboolean prompt_key_event(ObPrompt *self, XEvent *e)

{ gboolean shift; guint shift_mask, mods; + KeySym sym; if (e->type != KeyPress) return FALSE;

@@ -536,23 +537,18 @@ /* only accept shift */

if (mods != 0 && mods != shift_mask) return FALSE; - if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) + sym = obt_keyboard_keypress_to_keysym(e); + + if (sym == XK_Escape) prompt_cancel(self); - else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RETURN) || - ob_keycode_match(e->xkey.keycode, OB_KEY_SPACE)) - { + else if (sym == XK_Return || sym == XK_space) prompt_run_callback(self, self->focus->result); - } - else if (ob_keycode_match(e->xkey.keycode, OB_KEY_TAB) || - ob_keycode_match(e->xkey.keycode, OB_KEY_LEFT) || - ob_keycode_match(e->xkey.keycode, OB_KEY_RIGHT)) - { + else if (sym == XK_Tab || sym == XK_Left || sym == XK_Right) { gint i; gboolean left; ObPromptElement *oldfocus; - left = ob_keycode_match(e->xkey.keycode, OB_KEY_LEFT) || - (ob_keycode_match(e->xkey.keycode, OB_KEY_TAB) && shift); + left = (sym == XK_Left) || ((sym == XK_Tab) && shift); oldfocus = self->focus; for (i = 0; i < self->n_buttons; ++i)