Some menu updates.

Don't talk to me about menus.
This commit is contained in:
Scott Moynes 2003-07-26 06:02:58 +00:00
parent 11cde9683d
commit 3c92311b3c
3 changed files with 115 additions and 150 deletions

View file

@ -972,7 +972,6 @@ static void event_handle_client(ObClient *client, XEvent *e)
static void event_handle_menu(ObClient *client, XEvent *e) static void event_handle_menu(ObClient *client, XEvent *e)
{ {
static ObMenuEntry *over = NULL;
ObMenuEntry *entry; ObMenuEntry *entry;
ObMenu *top; ObMenu *top;
GList *it = NULL; GList *it = NULL;
@ -982,27 +981,11 @@ static void event_handle_menu(ObClient *client, XEvent *e)
ob_debug("EVENT %d\n", e->type); ob_debug("EVENT %d\n", e->type);
switch (e->type) { switch (e->type) {
case KeyPress: case KeyPress:
if (e->xkey.keycode == ob_keycode(OB_KEY_DOWN)) menu_control_keyboard_nav(e->xkey.keycode);
over = menu_control_keyboard_nav(over, OB_KEY_DOWN);
else if (e->xkey.keycode == ob_keycode(OB_KEY_UP))
over = menu_control_keyboard_nav(over, OB_KEY_UP);
else if (e->xkey.keycode == ob_keycode(OB_KEY_RIGHT)) /* fuck */
over = menu_control_keyboard_nav(over, OB_KEY_RIGHT);
else if (e->xkey.keycode == ob_keycode(OB_KEY_LEFT)) /* users */
over = menu_control_keyboard_nav(over, OB_KEY_LEFT);
else {
if (over) {
over->parent->mouseover(over, FALSE);
over = NULL;
}
menu_hide(top);
}
break; break;
case ButtonPress: case ButtonPress:
if (e->xbutton.button > 3) break;
ob_debug("BUTTON PRESS\n"); ob_debug("BUTTON PRESS\n");
break; break;
case ButtonRelease: case ButtonRelease:
ob_debug("BUTTON RELEASED\n"); ob_debug("BUTTON RELEASED\n");
@ -1020,31 +1003,13 @@ static void event_handle_menu(ObClient *client, XEvent *e)
m->location.x, m->location.x,
e->xbutton.y_root - e->xbutton.y_root -
m->location.y))) { m->location.y))) {
if (over) { m->selected(entry, e->xbutton.button,
over->parent->mouseover(over, FALSE); e->xbutton.x_root,
/* this hides the menu */ e->xbutton.y_root);
break;
over->parent->selected(entry, e->xbutton.button,
e->xbutton.x_root,
e->xbutton.y_root);
over = NULL;
}
} }
break;
} }
} }
if (!it) {
if (over) {
over->parent->mouseover(over, FALSE);
over = NULL;
}
/*
if (top->hide)
top->hide(top);
else
*/
menu_hide(top);
}
break; break;
case MotionNotify: case MotionNotify:
@ -1056,19 +1021,14 @@ static void event_handle_menu(ObClient *client, XEvent *e)
m->location.x, m->location.x,
e->xmotion.y_root - e->xmotion.y_root -
m->location.y))) { m->location.y))) {
if (over && entry != over) { if (m->over && m->over->data != entry)
over->parent->mouseover(over, FALSE); m->mouseover(m->over->data, FALSE);
}
over = entry; m->mouseover(entry, TRUE);
over->parent->mouseover(over, TRUE);
break; break;
} }
} }
if (!it && over) {
over->parent->mouseover(over, FALSE);
over = NULL;
}
break; break;
} }
} }

View file

@ -183,6 +183,7 @@ ObMenu *menu_new_full(char *label, char *name, ObMenu *parent,
self->name = g_strdup(name); self->name = g_strdup(name);
self->parent = parent; self->parent = parent;
self->open_submenu = NULL; self->open_submenu = NULL;
self->over = NULL;
self->entries = NULL; self->entries = NULL;
self->shown = FALSE; self->shown = FALSE;
@ -318,12 +319,8 @@ void menu_hide(ObMenu *self) {
if (self->open_submenu) if (self->open_submenu)
menu_hide(self->open_submenu); menu_hide(self->open_submenu);
if (self->parent && self->parent->open_submenu == self) { if (self->parent && self->parent->open_submenu == self) {
ObMenuEntry *e; self->over = NULL;
self->parent->open_submenu = NULL; self->parent->open_submenu = NULL;
e = menu_find_entry_by_submenu(self->parent, self);
self->parent->mouseover(e, FALSE);
} }
if (!(self->parent && self->parent->shown)) { if (!(self->parent && self->parent->shown)) {
@ -440,12 +437,14 @@ void menu_control_mouseover(ObMenuEntry *self, gboolean enter)
Rect *a; Rect *a;
ObMenuEntry *e; ObMenuEntry *e;
g_assert(self != NULL);
if (enter) { if (enter) {
/* TODO: we prolly don't need open_submenu */
if (self->parent->open_submenu && self->submenu if (self->parent->open_submenu && self->submenu
!= self->parent->open_submenu) != self->parent->open_submenu)
{ {
e = menu_find_entry_by_submenu(self->parent, e = (ObMenuEntry *) self->parent->over->data;
self->parent->open_submenu);
e->hilite = FALSE; e->hilite = FALSE;
menu_entry_render(e); menu_entry_render(e);
menu_hide(self->parent->open_submenu); menu_hide(self->parent->open_submenu);
@ -473,113 +472,100 @@ void menu_control_mouseover(ObMenuEntry *self, gboolean enter)
menu_show_full(self->submenu, x, menu_show_full(self->submenu, x,
self->parent->location.y + self->y, self->parent->location.y + self->y,
self->parent->client); self->parent->client);
} }
} self->hilite = TRUE;
self->parent->over = g_list_find(self->parent->entries, self);
if (enter || !self->submenu ||
menu_find_entry_by_submenu(self->parent, } else
self->parent->open_submenu) != self) self->hilite = FALSE;
self->hilite = enter;
menu_entry_render(self); menu_entry_render(self);
} }
ObMenuEntry *menu_control_keyboard_nav(ObMenuEntry *over, ObKey key) void menu_control_keyboard_nav(unsigned int key)
{ {
GList *it = NULL; static ObMenu *current_menu = NULL;
switch (key) {
case OB_KEY_DOWN: {
if (over != NULL) {
over->parent->mouseover(over, FALSE);
it = over->parent->entries;
while (it != NULL && it->data != over)
it = it->next;
}
if (it && it->next)
over = (ObMenuEntry *)it->next->data;
else if (over == NULL) {
if (menu_visible && ((ObMenu *)menu_visible->data)->entries)
over = (ObMenuEntry *)
(((ObMenu *)menu_visible->data)->entries)->data;
else
over = NULL;
} else {
over = (over->parent->entries != NULL ?
over->parent->entries->data : NULL);
}
if (over) ObKey obkey = OB_NUM_KEYS;
over->parent->mouseover(over, TRUE);
/* hrmm. could be fixed */
if (key == ob_keycode(OB_KEY_DOWN))
obkey = OB_KEY_DOWN;
else if (key == ob_keycode(OB_KEY_UP))
obkey = OB_KEY_UP;
else if (key == ob_keycode(OB_KEY_RIGHT)) /* fuck */
obkey = OB_KEY_RIGHT;
else if (key == ob_keycode(OB_KEY_LEFT)) /* users */
obkey = OB_KEY_LEFT;
if (current_menu == NULL)
current_menu = menu_visible->data;
switch (obkey) {
case OB_KEY_DOWN: {
if (current_menu->over) {
current_menu->mouseover(current_menu->over->data, FALSE);
current_menu->over = (current_menu->over->next != NULL ?
current_menu->over->next :
current_menu->entries);
}
else
current_menu->over = current_menu->entries;
if (current_menu->over)
current_menu->mouseover(current_menu->over->data, TRUE);
break; break;
} }
case OB_KEY_UP: { case OB_KEY_UP: {
if (over != NULL) { if (current_menu->over) {
over->parent->mouseover(over, FALSE); current_menu->mouseover(current_menu->over->data, FALSE);
current_menu->over = (current_menu->over->prev != NULL ?
it = g_list_last(over->parent->entries); current_menu->over->prev :
while (it != NULL && it->data != over) g_list_last(current_menu->entries));
it = it->prev;
}
if (it && it->prev)
over = (ObMenuEntry *)it->prev->data;
else if (over == NULL) {
it = g_list_last(menu_visible);
if (it != NULL) {
it = g_list_last(((ObMenu *)it->data)->entries);
over = (ObMenuEntry *)(it != NULL ? it->data : NULL);
}
} else } else
over = (over->parent->entries != NULL ? current_menu->over = g_list_last(current_menu->entries);
g_list_last(over->parent->entries)->data :
NULL);
over->parent->mouseover(over, TRUE); if (current_menu->over)
current_menu->mouseover(current_menu->over->data, TRUE);
break; break;
} }
case OB_KEY_RIGHT: { case OB_KEY_RIGHT: {
if (over == NULL) ObMenuEntry *e;
return over; if (current_menu->over == NULL)
return;
if (over->submenu) {
over->parent->mouseover(over, FALSE);
if (over->submenu->entries)
over = over->submenu->entries->data;
over->parent->mouseover(over, TRUE);
}
else {
over->parent->mouseover(over, FALSE);
e = (ObMenuEntry *)current_menu->over->data;
if (e->submenu) {
current_menu = e->submenu;
current_menu->over = current_menu->entries;
if (current_menu->over)
current_menu->mouseover(current_menu->over->data, TRUE);
} else {
current_menu->mouseover(e, FALSE);
current_menu->over = NULL;
/* zero is enter */ /* zero is enter */
menu_entry_fire(over, 0, 0, 0); menu_entry_fire(e, 0, 0, 0);
} }
break; break;
} }
case OB_KEY_LEFT: { case OB_KEY_LEFT: {
if (over != NULL) { if (current_menu->over == NULL)
over->parent->mouseover(over, FALSE); return;
menu_hide(over->parent); current_menu->mouseover(current_menu->over->data, FALSE);
} else { current_menu->over = NULL;
it = g_list_last(menu_visible);
if (it) { menu_hide(current_menu);
menu_hide((ObMenu *)it->data);
} if (current_menu->parent)
} current_menu = current_menu->parent;
over = NULL;
break; break;
} }
default:
g_error("Unknown key");
} }
return;
return over;
} }
void menu_noop() void menu_noop()

View file

@ -10,14 +10,15 @@
struct _ObClient; struct _ObClient;
typedef struct _ObMenu ObMenu; typedef struct _ObMenu ObMenu;
typedef struct _ObMenuEntry ObMenuEntry; typedef struct _ObMenuEntry ObMenuEntry;
typedef void(*menu_controller_show)(ObMenu *self, int x, int y, typedef void(*menu_controller_show)(ObMenu *self, int x, int y,
struct _ObClient *); struct _ObClient *);
typedef void(*menu_controller_update)(ObMenu *self); typedef void(*menu_controller_update)(ObMenu *self);
typedef void(*menu_controller_mouseover)(ObMenuEntry *self, gboolean enter); typedef void(*menu_controller_mouseover)(ObMenuEntry *self, gboolean enter);
typedef void(*menu_controller_selected)(ObMenuEntry *self, unsigned int button, typedef void(*menu_controller_selected)(ObMenuEntry *entry,
unsigned int button,
unsigned int x, unsigned int y); unsigned int x, unsigned int y);
typedef void(*menu_controller_hide)(ObMenu *self); typedef void(*menu_controller_hide)(ObMenu *self);
@ -29,25 +30,42 @@ struct _ObMenu
{ {
ObWindow obwin; ObWindow obwin;
/* The title displayed above the menu.
NULL for no titlebar */
gchar *label; gchar *label;
/* Name of the menu.
Used in the action showmenu */
gchar *name; gchar *name;
/* ObMenuEntry list */
GList *entries; GList *entries;
/* If the menu is currently displayed */
gboolean shown; gboolean shown;
/* If the rendering of the menu has changed and needs to be rerendered. */
gboolean invalid; gboolean invalid;
/* Kind of lame.Each menu can only be a submenu, and each menu can only
have one submenu open */
ObMenu *parent; ObMenu *parent;
ObMenu *open_submenu; ObMenu *open_submenu;
GList *over;
/* behaviour callbacks
TODO: Document and split code that HAS to be in the overridden callback */
/* place a menu on screen */ /* place a menu on screen */
menu_controller_show show; menu_controller_show show;
/* Hide the menu */
menu_controller_hide hide; menu_controller_hide hide;
/* render a menu */ /* render a menu */
menu_controller_update update; menu_controller_update update;
/* Event for a mouse enter/exit on an entry
TODO: May have to split from simple render updating?
*/
menu_controller_mouseover mouseover; menu_controller_mouseover mouseover;
/* Entry is clicked/hit enter on */
menu_controller_selected selected; menu_controller_selected selected;
@ -65,8 +83,9 @@ struct _ObMenu
Size size; Size size;
guint xin_area; /* index of the xinerama head/area */ guint xin_area; /* index of the xinerama head/area */
/* plugin stuff */ /* Name of plugin for menu */
char *plugin; char *plugin;
/* plugin's data */
void *plugin_data; void *plugin_data;
}; };
@ -161,8 +180,8 @@ ObMenuEntry *menu_find_entry_by_pos(ObMenu *menu, int x, int y);
void menu_entry_render(ObMenuEntry *self); void menu_entry_render(ObMenuEntry *self);
void menu_entry_fire(ObMenuEntry *self, unsigned int button, unsigned int x, void menu_entry_fire(ObMenuEntry *entry,
unsigned int y); unsigned int button, unsigned int x, unsigned int y);
void menu_render(ObMenu *self); void menu_render(ObMenu *self);
void menu_render_full(ObMenu *self); void menu_render_full(ObMenu *self);
@ -170,5 +189,5 @@ void menu_render_full(ObMenu *self);
/*so plugins can call it? */ /*so plugins can call it? */
void parse_menu_full(xmlDocPtr doc, xmlNodePtr node, void *data, gboolean new); void parse_menu_full(xmlDocPtr doc, xmlNodePtr node, void *data, gboolean new);
void menu_control_mouseover(ObMenuEntry *entry, gboolean enter); void menu_control_mouseover(ObMenuEntry *entry, gboolean enter);
ObMenuEntry *menu_control_keyboard_nav(ObMenuEntry *over, ObKey key); void menu_control_keyboard_nav(unsigned int key);
#endif #endif