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_RETURN))
- over = menu_control_keyboard_nav(over, OB_KEY_RETURN);
- else if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE))
- over = menu_control_keyboard_nav(over, OB_KEY_ESCAPE);
+ 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) {
- if (over->parent->mouseover)
- over->parent->mouseover(over, FALSE);
- else
- menu_control_mouseover(over, FALSE);
- menu_entry_render(over);
+ over->parent->mouseover(over, FALSE);
over = NULL;
}
-/*
- if (top->hide)
- top->hide(top);
- else
-*/
+
menu_hide(top);
}
break;
ob_debug("BUTTON PRESS\n");
break;
case ButtonRelease:
- if (e->xbutton.button > 3) break;
-
ob_debug("BUTTON RELEASED\n");
for (it = menu_visible; it; it = g_list_next(it)) {
e->xbutton.y_root -
m->location.y))) {
if (over) {
- if (over->parent->mouseover)
- over->parent->mouseover(over, FALSE);
- else
- menu_control_mouseover(over, FALSE);
- menu_entry_render(over);
- over = NULL;
+ over->parent->mouseover(over, FALSE);
/* this hides the menu */
- menu_entry_fire(entry);
+
+ over->parent->selected(entry, e->xbutton.button,
+ e->xbutton.x_root,
+ e->xbutton.y_root);
+ over = NULL;
}
}
break;
}
if (!it) {
if (over) {
- if (over->parent->mouseover)
- over->parent->mouseover(over, FALSE);
- else
- menu_control_mouseover(over, FALSE);
- menu_entry_render(over);
+ over->parent->mouseover(over, FALSE);
over = NULL;
}
/*
e->xmotion.y_root -
m->location.y))) {
if (over && entry != over) {
- if (over->parent->mouseover)
- over->parent->mouseover(over, FALSE);
- else
- menu_control_mouseover(over, FALSE);
- menu_entry_render(over);
+ over->parent->mouseover(over, FALSE);
}
over = entry;
- if (over->parent->mouseover)
- over->parent->mouseover(over, TRUE);
- else
- menu_control_mouseover(over, TRUE);
- menu_entry_render(over);
+ over->parent->mouseover(over, TRUE);
break;
}
}
if (!it && over) {
- if (over->parent->mouseover)
- over->parent->mouseover(over, FALSE);
- else
- menu_control_mouseover(over, FALSE);
- menu_entry_render(over);
+ over->parent->mouseover(over, FALSE);
over = NULL;
}
break;
void menu_startup()
{
-/*
- ObMenu *m;
- ObMenu *s;
- ObMenu *t;
- Action *a;
-*/
-
menu_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
(GDestroyNotify)menu_destroy_hash_key,
(GDestroyNotify)menu_destroy_hash_value);
parse_register("menu", parse_menu, NULL);
-/*
- m = menu_new("sex menu", "root", NULL);
-
- a = action_from_string("execute");
- a->data.execute.path = g_strdup("xterm");
- menu_add_entry(m, menu_entry_new("xterm", a));
- a = action_from_string("restart");
- menu_add_entry(m, menu_entry_new("restart", a));
- menu_add_entry(m, menu_entry_new_separator("--"));
- a = action_from_string("exit");
- menu_add_entry(m, menu_entry_new("exit", a));
-*/
-
- /*
- s = menu_new("subsex menu", "submenu", m);
- a = action_from_string("execute");
- a->data.execute.path = g_strdup("xclock");
- menu_add_entry(s, menu_entry_new("xclock", a));
-
- menu_add_entry(m, menu_entry_new_submenu("subz", s));
-
- s = menu_new("empty", "chub", m);
- menu_add_entry(m, menu_entry_new_submenu("empty", s));
-
- s = menu_new("", "s-club", m);
- menu_add_entry(m, menu_entry_new_submenu("empty", s));
-
- s = menu_new(NULL, "h-club", m);
- menu_add_entry(m, menu_entry_new_submenu("empty", s));
-
- s = menu_new(NULL, "g-club", m);
-
- a = action_from_string("execute");
- a->data.execute.path = g_strdup("xterm");
- menu_add_entry(s, menu_entry_new("xterm", a));
- a = action_from_string("restart");
- menu_add_entry(s, menu_entry_new("restart", a));
- menu_add_entry(s, menu_entry_new_separator("--"));
- a = action_from_string("exit");
- menu_add_entry(s, menu_entry_new("exit", a));
-
- menu_add_entry(m, menu_entry_new_submenu("long", s));
- */
}
void menu_shutdown()
}
ObMenu *menu_new_full(char *label, char *name, ObMenu *parent,
- menu_controller_show show, menu_controller_update update)
+ menu_controller_show show, menu_controller_update update,
+ menu_controller_selected selected,
+ menu_controller_hide hide,
+ menu_controller_mouseover mouseover)
{
XSetWindowAttributes attrib;
ObMenu *self;
self->invalid = TRUE;
/* default controllers */
- self->show = show;
- self->hide = NULL;
- self->update = update;
- self->mouseover = NULL;
- self->selected = NULL;
+ self->show = (show != NULL ? show : menu_show_full);
+ self->hide = (hide != NULL ? hide : menu_hide);
+ self->update = (update != NULL ? update : menu_render);
+ self->mouseover = (mouseover != NULL ? mouseover :
+ menu_control_mouseover);
+ self->selected = (selected != NULL ? selected : menu_entry_fire);
self->plugin = NULL;
self->plugin_data = NULL;
menu_visible = g_list_append(menu_visible, self);
}
- if (self->show) {
- self->show(self, x, y, client);
- } else {
- menu_control_show(self, x, y, client);
- }
+ menu_control_show(self, x, y, client);
}
void menu_hide(ObMenu *self) {
self->parent->open_submenu = NULL;
e = menu_find_entry_by_submenu(self->parent, self);
- if (self->parent->mouseover)
- self->parent->mouseover(e, FALSE);
- else
- menu_control_mouseover(e, FALSE);
- menu_entry_render(e);
+ self->parent->mouseover(e, FALSE);
}
if (!(self->parent && self->parent->shown)) {
return g_list_nth_data(menu->entries, y / menu->item_h);
}
-void menu_entry_fire(ObMenuEntry *self)
+void menu_entry_fire(ObMenuEntry *self, unsigned int button, unsigned int x,
+ unsigned int y)
{
ObMenu *m;
+ if (button > 3) return;
+
if (self->action) {
self->action->data.any.c = self->parent->client;
self->action->func(&self->action->data);
menu_find_entry_by_submenu(self->parent,
self->parent->open_submenu) != self)
self->hilite = enter;
+
+ menu_entry_render(self);
}
ObMenuEntry *menu_control_keyboard_nav(ObMenuEntry *over, ObKey key)
switch (key) {
case OB_KEY_DOWN: {
if (over != NULL) {
- if (over->parent->mouseover)
- over->parent->mouseover(over, FALSE);
- else
- menu_control_mouseover(over, FALSE);
- menu_entry_render(over);
+ over->parent->mouseover(over, FALSE);
it = over->parent->entries;
while (it != NULL && it->data != over)
over->parent->entries->data : NULL);
}
- if (over) {
- if (over->parent->mouseover)
- over->parent->mouseover(over, TRUE);
- else
- menu_control_mouseover(over, TRUE);
- menu_entry_render(over);
- }
+ if (over)
+ over->parent->mouseover(over, TRUE);
break;
}
case OB_KEY_UP: {
if (over != NULL) {
- if (over->parent->mouseover)
- over->parent->mouseover(over, FALSE);
- else
- menu_control_mouseover(over, FALSE);
- menu_entry_render(over);
+ over->parent->mouseover(over, FALSE);
it = g_list_last(over->parent->entries);
while (it != NULL && it->data != over)
g_list_last(over->parent->entries)->data :
NULL);
- if (over->parent->mouseover)
- over->parent->mouseover(over, TRUE);
- else
- menu_control_mouseover(over, TRUE);
- menu_entry_render(over);
+ over->parent->mouseover(over, TRUE);
break;
}
- case OB_KEY_RETURN: {
+ case OB_KEY_RIGHT: {
if (over == NULL)
return over;
if (over->submenu) {
- if (over->parent->mouseover)
- over->parent->mouseover(over, FALSE);
- else
- menu_control_mouseover(over, FALSE);
- menu_entry_render(over);
+ over->parent->mouseover(over, FALSE);
if (over->submenu->entries)
over = over->submenu->entries->data;
- if (over->parent->mouseover)
- over->parent->mouseover(over, TRUE);
- else
- menu_control_mouseover(over, TRUE);
- menu_entry_render(over);
+ over->parent->mouseover(over, TRUE);
}
else {
- if (over->parent->mouseover)
- over->parent->mouseover(over, FALSE);
- else
- menu_control_mouseover(over, FALSE);
- menu_entry_render(over);
+ over->parent->mouseover(over, FALSE);
- menu_entry_fire(over);
+ /* zero is enter */
+ menu_entry_fire(over, 0, 0, 0);
}
break;
}
- case OB_KEY_ESCAPE: {
+ case OB_KEY_LEFT: {
if (over != NULL) {
- if (over->parent->mouseover)
- over->parent->mouseover(over, FALSE);
- else
- menu_control_mouseover(over, FALSE);
- menu_entry_render(over);
-
+ over->parent->mouseover(over, FALSE);
menu_hide(over->parent);
} else {
it = g_list_last(menu_visible);
return over;
}
+
+void menu_noop()
+{
+ /* This noop brought to you by OLS 2003 Email Garden. */
+}
struct _ObClient *);
typedef void(*menu_controller_update)(ObMenu *self);
typedef void(*menu_controller_mouseover)(ObMenuEntry *self, gboolean enter);
+typedef void(*menu_controller_selected)(ObMenuEntry *self, unsigned int button,
+ unsigned int x, unsigned int y);
+typedef void(*menu_controller_hide)(ObMenu *self);
+
extern GHashTable *menu_hash;
extern GList *menu_visible;
/* place a menu on screen */
menu_controller_show show;
- void (*hide)( /* some bummu */);
+ menu_controller_hide hide;
/* render a menu */
menu_controller_update update;
menu_controller_mouseover mouseover;
- void (*selected)( /* some bummu */);
+ menu_controller_selected selected;
/* render stuff */
void menu_startup();
void menu_shutdown();
+void menu_noop();
+
#define menu_new(l, n, p) \
- menu_new_full(l, n, p, NULL, NULL)
+ menu_new_full(l, n, p, menu_show_full, menu_render, menu_entry_fire, \
+ menu_hide, menu_control_mouseover)
ObMenu *menu_new_full(char *label, char *name, ObMenu *parent,
- menu_controller_show show, menu_controller_update update);
+ menu_controller_show show, menu_controller_update update,
+ menu_controller_selected selected,
+ menu_controller_hide hide,
+ menu_controller_mouseover mouseover);
+
void menu_free(char *name);
void menu_show(char *name, int x, int y, struct _ObClient *client);
void menu_entry_render(ObMenuEntry *self);
-void menu_entry_fire(ObMenuEntry *self);
+void menu_entry_fire(ObMenuEntry *self, unsigned int button, unsigned int x,
+ unsigned int y);
void menu_render(ObMenu *self);
void menu_render_full(ObMenu *self);