I had a commit message but my commit got stepped on so fuck it.

No one cares what I think anyway.
If the menu navigation isn't EXACTLY FUCKING RIGHT I WILL REMOVE IT
AND SOME OTHER POOR FUCK CAN PUT UP WITH ALL THE FUCKING BULLSHIT.
This commit is contained in:
Scott Moynes 2003-07-24 06:10:55 +00:00
parent 5973fb03f5
commit d51702affa
5 changed files with 72 additions and 174 deletions

View file

@ -986,24 +986,16 @@ static void event_handle_menu(ObClient *client, XEvent *e)
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;
@ -1013,8 +1005,6 @@ static void event_handle_menu(ObClient *client, XEvent *e)
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)) {
@ -1031,14 +1021,13 @@ static void event_handle_menu(ObClient *client, XEvent *e)
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;
@ -1046,11 +1035,7 @@ static void event_handle_menu(ObClient *client, XEvent *e)
}
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;
}
/*
@ -1072,28 +1057,16 @@ static void event_handle_menu(ObClient *client, XEvent *e)
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;

View file

@ -146,62 +146,12 @@ void menu_entry_free(ObMenuEntry *self)
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()
@ -219,7 +169,10 @@ static Window createWindow(Window parent, unsigned long mask,
}
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;
@ -236,11 +189,12 @@ ObMenu *menu_new_full(char *label, char *name, ObMenu *parent,
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;
@ -354,11 +308,7 @@ void menu_show_full(ObMenu *self, int x, int y, ObClient *client)
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) {
@ -373,11 +323,7 @@ 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)) {
@ -437,10 +383,13 @@ ObMenuEntry *menu_find_entry_by_pos(ObMenu *menu, int x, int y)
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);
@ -531,6 +480,8 @@ void menu_control_mouseover(ObMenuEntry *self, gboolean enter)
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)
@ -540,11 +491,7 @@ 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)
@ -564,23 +511,14 @@ ObMenuEntry *menu_control_keyboard_nav(ObMenuEntry *over, ObKey key)
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)
@ -600,52 +538,32 @@ ObMenuEntry *menu_control_keyboard_nav(ObMenuEntry *over, ObKey key)
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);
@ -663,3 +581,8 @@ ObMenuEntry *menu_control_keyboard_nav(ObMenuEntry *over, ObKey key)
return over;
}
void menu_noop()
{
/* This noop brought to you by OLS 2003 Email Garden. */
}

View file

@ -17,6 +17,10 @@ typedef void(*menu_controller_show)(ObMenu *self, int x, int y,
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;
@ -39,12 +43,12 @@ struct _ObMenu
/* 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 */
@ -108,11 +112,18 @@ typedef struct PluginMenuCreateData{
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);
@ -150,7 +161,8 @@ ObMenuEntry *menu_find_entry_by_pos(ObMenu *menu, int x, int y);
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);

View file

@ -5,17 +5,7 @@
#include "openbox.h"
#include "render/theme.h"
void menu_render_full(ObMenu *self);
void menu_render(ObMenu *self) {
if (self->update) {
self->update(self);
} else if (self->invalid) {
menu_render_full(self);
}
}
void menu_render_full(ObMenu *self) {
GList *it;
int items_h = 0;
int nitems = 0; /* each item, only one is used */

View file

@ -52,7 +52,7 @@ void client_send_to_update(ObMenu *self)
menu_add_entry(self, e);
}
menu_render_full(self);
self->update(self);
}
}
@ -102,7 +102,7 @@ void plugin_destroy (ObMenu *m)
void *plugin_create() /* TODO: need config */
{
ObMenu *m = menu_new_full(NULL, "client-menu", NULL,
client_menu_show, NULL);
client_menu_show, NULL, NULL, NULL, NULL);
m->plugin = PLUGIN_NAME;
menu_add_entry(m, menu_entry_new_submenu("Send To Workspace",
send_to_menu));
@ -144,7 +144,7 @@ void plugin_startup()
ObMenu *t;
/* create a Send To Workspace ObMenu */
send_to_menu = menu_new_full(NULL, "send-to-workspace",
NULL, NULL, client_send_to_update);
NULL, NULL, client_send_to_update, NULL, NULL, NULL);
layer_menu = menu_new(NULL, "layer", NULL);
menu_add_entry(layer_menu, menu_entry_new("Top Layer",