More menu changes to facilitate plugins.

This commit is contained in:
Scott Moynes 2003-04-22 03:48:34 +00:00
parent 6a237b91bc
commit 574dd66b32
3 changed files with 52 additions and 19 deletions

View file

@ -12,6 +12,8 @@ GHashTable *menu_map = NULL;
#define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \ #define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
ButtonPressMask | ButtonReleaseMask) ButtonPressMask | ButtonReleaseMask)
void menu_control_show(Menu *self, int x, int y, Client *client);
void menu_destroy_hash_key(gpointer data) void menu_destroy_hash_key(gpointer data)
{ {
g_free(data); g_free(data);
@ -91,7 +93,8 @@ static Window createWindow(Window parent, unsigned long mask,
} }
Menu *menu_new(char *label, char *name, Menu *parent) Menu *menu_new_full(char *label, char *name, Menu *parent,
menu_controller_show show, menu_controller_update update)
{ {
XSetWindowAttributes attrib; XSetWindowAttributes attrib;
Menu *self; Menu *self;
@ -106,6 +109,12 @@ Menu *menu_new(char *label, char *name, Menu *parent)
self->invalid = FALSE; self->invalid = FALSE;
/* default controllers? */ /* default controllers? */
self->show = show;
self->hide = NULL;
self->update = update;
self->mouseover = NULL;
self->selected = NULL;
attrib.override_redirect = TRUE; attrib.override_redirect = TRUE;
attrib.event_mask = FRAME_EVENTMASK; attrib.event_mask = FRAME_EVENTMASK;
self->frame = createWindow(ob_root, CWOverrideRedirect|CWEventMask, &attrib); self->frame = createWindow(ob_root, CWOverrideRedirect|CWEventMask, &attrib);
@ -197,18 +206,19 @@ void menu_show(char *name, int x, int y, Client *client)
} }
if (self->invalid) { if (self->invalid) {
if (self->update) {
self->update(self);
} else {
menu_render(self); menu_render(self);
} }
}
XMoveWindow(ob_display, self->frame, x, y);
self->client = client; self->client = client;
if (!self->shown) { if (self->show) {
stacking_raise_internal(self->frame); self->show(self, x, y, client);
XMapWindow(ob_display, self->frame); } else {
/* grab_pointer_window(TRUE, None, self->frame);*/ menu_control_show(self, x, y, client);
self->shown = TRUE;
} }
} }
@ -268,3 +278,17 @@ void menu_entry_fire(MenuEntry *self)
menu_hide(m); menu_hide(m);
} }
} }
/*
Default menu controller action for showing.
*/
void menu_control_show(Menu *self, int x, int y, Client *client) {
XMoveWindow(ob_display, self->frame, x, y);
if (!self->shown) {
stacking_raise_internal(self->frame);
XMapWindow(ob_display, self->frame);
self->shown = TRUE;
}
}

View file

@ -8,23 +8,28 @@
extern GHashTable *menu_map; extern GHashTable *menu_map;
struct Menu;
typedef void(*menu_controller_show)(struct Menu *self, int x, int y, Client *);
typedef void(*menu_controller_update)(struct Menu *self);
typedef struct Menu { typedef struct Menu {
char *label; char *label;
char *name; char *name;
GList *entries; GList *entries;
/* GList *tail; */
/* ? */
gboolean shown; gboolean shown;
gboolean invalid; gboolean invalid;
struct Menu *parent; struct Menu *parent;
/* waste o' pointers */ /* place a menu on screen */
void (*show)( /* some bummu */); menu_controller_show show;
void (*hide)( /* some bummu */); void (*hide)( /* some bummu */);
void (*update)( /* some bummu */);
/* render a menu */
menu_controller_update update;
void (*mouseover)( /* some bummu */); void (*mouseover)( /* some bummu */);
void (*selected)( /* some bummu */); void (*selected)( /* some bummu */);
@ -76,7 +81,11 @@ typedef struct {
void menu_startup(); void menu_startup();
void menu_shutdown(); void menu_shutdown();
Menu *menu_new(char *label, char *name, Menu *parent); #define menu_new(l, n, p) \
menu_new_full(l, n, p, NULL, NULL)
Menu *menu_new_full(char *label, char *name, Menu *parent,
menu_controller_show show, menu_controller_update update);
void menu_free(char *name); void menu_free(char *name);
void menu_show(char *name, int x, int y, Client *client); void menu_show(char *name, int x, int y, Client *client);

View file

@ -1,4 +1,4 @@
// Functions for default rendering of menus. Might become pluginnable /* Functions for default rendering of menus. Might become pluginnable */
#include "menu.h" #include "menu.h"
#include "openbox.h" #include "openbox.h"