make menu event handling work more like how other events are handled, less special-casey
This commit is contained in:
parent
770032fdb5
commit
46cf95d36b
2 changed files with 161 additions and 160 deletions
|
@ -200,18 +200,17 @@ KeyCode obt_keyboard_keysym_to_keycode(KeySym sym)
|
|||
gchar *obt_keyboard_keycode_to_string(guint keycode)
|
||||
{
|
||||
KeySym sym;
|
||||
const gchar *ret = NULL;
|
||||
|
||||
if ((sym = XKeycodeToKeysym(obt_display, keycode, 0)) != NoSymbol)
|
||||
ret = XKeysymToString(sym);
|
||||
return g_locale_to_utf8(ret, -1, NULL, NULL, NULL);
|
||||
return g_locale_to_utf8(XKeysymToString(sym), -1, NULL, NULL, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gunichar obt_keyboard_keycode_to_unichar(guint keycode)
|
||||
{
|
||||
gunichar unikey = 0;
|
||||
|
||||
char *key;
|
||||
|
||||
if ((key = obt_keyboard_keycode_to_string(keycode)) != NULL &&
|
||||
/* don't accept keys that aren't a single letter, like "space" */
|
||||
key[1] == '\0')
|
||||
|
|
|
@ -83,8 +83,8 @@ typedef struct
|
|||
|
||||
static void event_process(const XEvent *e, gpointer data);
|
||||
static void event_handle_root(XEvent *e);
|
||||
static gboolean event_handle_menu_keyboard(XEvent *e);
|
||||
static gboolean event_handle_menu(XEvent *e);
|
||||
static gboolean event_handle_menu_input(XEvent *e);
|
||||
static void event_handle_menu(ObMenuFrame *frame, XEvent *e);
|
||||
static void event_handle_dock(ObDock *s, XEvent *e);
|
||||
static void event_handle_dockapp(ObDockApp *app, XEvent *e);
|
||||
static void event_handle_client(ObClient *c, XEvent *e);
|
||||
|
@ -450,13 +450,15 @@ static gboolean event_ignore(XEvent *e, ObClient *client)
|
|||
|
||||
static void event_process(const XEvent *ec, gpointer data)
|
||||
{
|
||||
XEvent ee, *e;
|
||||
ObEventData *ed = data;
|
||||
|
||||
Window window;
|
||||
ObClient *client = NULL;
|
||||
ObDock *dock = NULL;
|
||||
ObDockApp *dockapp = NULL;
|
||||
ObWindow *obwin = NULL;
|
||||
XEvent ee, *e;
|
||||
ObEventData *ed = data;
|
||||
ObMenuFrame *menu = NULL;
|
||||
|
||||
/* make a copy we can mangle */
|
||||
ee = *ec;
|
||||
|
@ -472,7 +474,7 @@ static void event_process(const XEvent *ec, gpointer data)
|
|||
client = WINDOW_AS_CLIENT(obwin);
|
||||
break;
|
||||
case OB_WINDOW_CLASS_MENUFRAME:
|
||||
/* XXX use this to handle events more uniformly */
|
||||
menu = WINDOW_AS_MENUFRAME(obwin);
|
||||
break;
|
||||
case OB_WINDOW_CLASS_INTERNALWINDOW:
|
||||
/* we don't do anything with events directly on these windows */
|
||||
|
@ -494,12 +496,7 @@ static void event_process(const XEvent *ec, gpointer data)
|
|||
|
||||
/* deal with it in the kernel */
|
||||
|
||||
if (menu_frame_visible &&
|
||||
(e->type == EnterNotify || e->type == LeaveNotify))
|
||||
{
|
||||
/* crossing events for menu */
|
||||
event_handle_menu(e);
|
||||
} else if (e->type == FocusIn) {
|
||||
if (e->type == FocusIn) {
|
||||
if (client &&
|
||||
e->xfocus.detail == NotifyInferior)
|
||||
{
|
||||
|
@ -634,6 +631,8 @@ static void event_process(const XEvent *ec, gpointer data)
|
|||
event_handle_dockapp(dockapp, e);
|
||||
else if (dock)
|
||||
event_handle_dock(dock, e);
|
||||
else if (menu)
|
||||
event_handle_menu(menu, e);
|
||||
else if (window == RootWindow(obt_display, ob_screen))
|
||||
event_handle_root(e);
|
||||
else if (e->type == MapRequest)
|
||||
|
@ -1661,12 +1660,43 @@ static ObMenuFrame* find_active_or_last_menu(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static gboolean event_handle_menu_keyboard(XEvent *ev)
|
||||
static gboolean event_handle_menu_input(XEvent *ev)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
|
||||
if (ev->type == ButtonRelease) {
|
||||
ObMenuEntryFrame *e;
|
||||
|
||||
if (menu_hide_delay_reached() &&
|
||||
(ev->xbutton.button < 4 || ev->xbutton.button > 5))
|
||||
{
|
||||
if ((e = menu_entry_frame_under(ev->xbutton.x_root,
|
||||
ev->xbutton.y_root)))
|
||||
{
|
||||
menu_frame_select(e->frame, e, TRUE);
|
||||
menu_entry_frame_execute(e, ev->xbutton.state);
|
||||
}
|
||||
else
|
||||
menu_frame_hide_all();
|
||||
}
|
||||
ret = TRUE;
|
||||
}
|
||||
else if (ev->type == MotionNotify) {
|
||||
ObMenuFrame *f;
|
||||
ObMenuEntryFrame *e;
|
||||
|
||||
if ((e = menu_entry_frame_under(ev->xmotion.x_root,
|
||||
ev->xmotion.y_root)))
|
||||
if (!(f = find_active_menu()) ||
|
||||
f == e->frame ||
|
||||
f->parent == e->frame ||
|
||||
f->child == e->frame)
|
||||
menu_frame_select(e->frame, e, FALSE);
|
||||
}
|
||||
else if (ev->type == KeyPress || ev->type == KeyRelease) {
|
||||
guint keycode, state;
|
||||
gunichar unikey;
|
||||
ObMenuFrame *frame;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
keycode = ev->xkey.keycode;
|
||||
state = ev->xkey.state;
|
||||
|
@ -1708,8 +1738,8 @@ static gboolean event_handle_menu_keyboard(XEvent *ev)
|
|||
}
|
||||
}
|
||||
|
||||
/* Use KeyRelease events for running things so that the key release doesn't
|
||||
get sent to the focused application.
|
||||
/* 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 && (state & ~ControlMask) == 0 &&
|
||||
|
@ -1769,8 +1799,8 @@ static gboolean event_handle_menu_keyboard(XEvent *ev)
|
|||
num_found == 1)
|
||||
{
|
||||
menu_frame_select(frame, found, TRUE);
|
||||
usleep(50000); /* highlight the item for a short bit so the
|
||||
user can see what happened */
|
||||
usleep(50000); /* highlight the item for a short bit so
|
||||
the user can see what happened */
|
||||
menu_entry_frame_execute(found, state);
|
||||
} else {
|
||||
menu_frame_select(frame, found, TRUE);
|
||||
|
@ -1782,31 +1812,17 @@ static gboolean event_handle_menu_keyboard(XEvent *ev)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean event_handle_menu(XEvent *ev)
|
||||
static void event_handle_menu(ObMenuFrame *frame, XEvent *ev)
|
||||
{
|
||||
ObMenuFrame *f;
|
||||
ObMenuEntryFrame *e;
|
||||
gboolean ret = TRUE;
|
||||
|
||||
switch (ev->type) {
|
||||
case ButtonRelease:
|
||||
if (menu_hide_delay_reached() &&
|
||||
(ev->xbutton.button < 4 || ev->xbutton.button > 5))
|
||||
{
|
||||
if ((e = menu_entry_frame_under(ev->xbutton.x_root,
|
||||
ev->xbutton.y_root)))
|
||||
{
|
||||
menu_frame_select(e->frame, e, TRUE);
|
||||
menu_entry_frame_execute(e, ev->xbutton.state);
|
||||
}
|
||||
else
|
||||
menu_frame_hide_all();
|
||||
}
|
||||
break;
|
||||
case EnterNotify:
|
||||
if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window))) {
|
||||
if (e->ignore_enters)
|
||||
|
@ -1830,21 +1846,7 @@ static gboolean event_handle_menu(XEvent *ev)
|
|||
menu_frame_select(e->frame, NULL, FALSE);
|
||||
}
|
||||
break;
|
||||
case MotionNotify:
|
||||
if ((e = menu_entry_frame_under(ev->xmotion.x_root,
|
||||
ev->xmotion.y_root)))
|
||||
if (!(f = find_active_menu()) ||
|
||||
f == e->frame ||
|
||||
f->parent == e->frame ||
|
||||
f->child == e->frame)
|
||||
menu_frame_select(e->frame, e, FALSE);
|
||||
break;
|
||||
case KeyPress:
|
||||
case KeyRelease:
|
||||
ret = event_handle_menu_keyboard(ev);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void event_handle_user_input(ObClient *client, XEvent *e)
|
||||
|
@ -1854,7 +1856,7 @@ static void event_handle_user_input(ObClient *client, XEvent *e)
|
|||
e->type == KeyRelease);
|
||||
|
||||
if (menu_frame_visible) {
|
||||
if (event_handle_menu(e))
|
||||
if (event_handle_menu_input(e))
|
||||
/* don't use the event if the menu used it, but if the menu
|
||||
didn't use it and it's a keypress that is bound, it will
|
||||
close the menu and be used */
|
||||
|
|
Loading…
Reference in a new issue