static void event_handle_dock(Dock *s, XEvent *e);
static void event_handle_dockapp(DockApp *app, XEvent *e);
static void event_handle_client(Client *c, XEvent *e);
-static void event_handle_menu(Menu *menu, Client *c, XEvent *e);
+static void event_handle_menu(Client *c, XEvent *e);
static void fd_event_handle();
#ifdef USE_SM
static void ice_watch(IceConn conn, IcePointer data, Bool opening,
return;
/* deal with it in the kernel */
- if (menu) {
- event_handle_menu(menu, client, e);
- return;
- } else if (client)
+ if (client)
event_handle_client(client, e);
else if (dockapp)
event_handle_dockapp(dockapp, e);
xerror_set_ignore(FALSE);
}
+ if (menu_visible)
+ if (e->type == MotionNotify || e->type == ButtonRelease ||
+ e->type == ButtonPress ||
+ e->type == KeyPress || e->type == KeyRelease) {
+ event_handle_menu(client, e);
+
+ return; /* no dispatch! */
+ }
+
if (moveresize_in_progress)
if (e->type == MotionNotify || e->type == ButtonRelease ||
e->type == ButtonPress ||
}
}
-static void event_handle_menu(Menu *menu, Client *client, XEvent *e)
+static void event_handle_menu(Client *client, XEvent *e)
{
+ static MenuEntry *over = NULL;
MenuEntry *entry;
+ Menu *top;
+ GSList *it;
+
+ top = g_slist_nth_data(menu_visible, 0);
g_message("EVENT %d", e->type);
switch (e->type) {
+ case KeyPress:
+ if (over) {
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, FALSE);
+ else
+ menu_control_mouseover(over, FALSE);
+ menu_entry_render(over);
+ }
+/*
+ if (top->hide)
+ top->hide(top);
+ else
+*/
+ menu_hide(top);
+ break;
case ButtonPress:
+ if (e->xbutton.button > 3) break;
+
g_message("BUTTON PRESS");
- if (e->xbutton.button == 3)
- menu_hide(menu);
- else if (e->xbutton.button == 1) {
- entry = menu_find_entry(menu, e->xbutton.window);
- if (!entry)
- stacking_raise(MENU_AS_WINDOW(menu));
- }
break;
case ButtonRelease:
+ if (e->xbutton.button > 3) break;
+
g_message("BUTTON RELEASED");
- if (!menu->shown) break;
-
-/* grab_pointer_window(FALSE, None, menu->frame);*/
-
- if (e->xbutton.button == 1) {
- entry = menu_find_entry(menu, e->xbutton.window);
- if (entry) {
- int junk;
- Window wjunk;
- guint ujunk, b, w, h;
- XGetGeometry(ob_display, e->xbutton.window,
- &wjunk, &junk, &junk, &w, &h, &b, &ujunk);
- if (e->xbutton.x >= (signed)-b &&
- e->xbutton.y >= (signed)-b &&
- e->xbutton.x < (signed)(w+b) &&
- e->xbutton.y < (signed)(h+b)) {
+
+ for (it = menu_visible; it; it = g_slist_next(it)) {
+ Menu *m = it->data;
+ if (e->xbutton.x_root >= m->location.x - ob_rr_theme->bwidth &&
+ e->xbutton.y_root >= m->location.y - ob_rr_theme->bwidth &&
+ e->xbutton.x_root < m->location.x + m->size.width +
+ ob_rr_theme->bwidth &&
+ e->xbutton.y_root < m->location.y + m->size.height +
+ ob_rr_theme->bwidth) {
+ if ((entry = menu_find_entry_by_pos(it->data,
+ e->xbutton.x_root -
+ m->location.x,
+ e->xbutton.y_root -
+ m->location.y))) {
menu_entry_fire(entry);
}
+ break;
}
}
+ if (!it) {
+ if (over) {
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, FALSE);
+ else
+ menu_control_mouseover(over, FALSE);
+ }
+ menu_entry_render(over);
+/*
+ if (top->hide)
+ top->hide(top);
+ else
+*/
+ menu_hide(top);
+ }
break;
- case EnterNotify:
- case LeaveNotify:
- g_message("enter/leave");
- entry = menu_find_entry(menu, e->xcrossing.window);
- if (entry) {
- if (menu->mouseover)
- menu->mouseover(entry, e->type == EnterNotify);
+ case MotionNotify:
+ g_message("motion");
+ for (it = menu_visible; it; it = g_slist_next(it)) {
+ Menu *m = it->data;
+ if ((entry = menu_find_entry_by_pos(it->data,
+ e->xmotion.x_root -
+ m->location.x,
+ 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 = entry;
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, TRUE);
+ else
+ menu_control_mouseover(over, TRUE);
+ menu_entry_render(over);
+ break;
+ }
+ }
+ if (!it && over) {
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, FALSE);
else
- menu_control_mouseover(entry, e->type == EnterNotify);
-
- menu_entry_render(entry);
+ menu_control_mouseover(over, FALSE);
+ menu_entry_render(over);
+ over = NULL;
}
break;
}
#include "openbox.h"
#include "stacking.h"
#include "grab.h"
-#include "render/theme.h"
#include "screen.h"
#include "geom.h"
#include "plugin.h"
GHashTable *menu_hash = NULL;
+GSList *menu_visible = NULL;
#define FRAME_EVENTMASK (ButtonPressMask |ButtonMotionMask | EnterWindowMask | \
LeaveWindowMask)
self->client = client;
+ if (!self->shown) {
+ GSList *it;
+
+ if (!self->parent) {
+ grab_pointer(TRUE, None);
+ grab_keyboard(TRUE);
+ }
+ menu_visible = g_slist_append(menu_visible, self);
+ }
+
if (self->show) {
self->show(self, x, y, client);
} else {
if (self->parent && self->parent->open_submenu == self)
self->parent->open_submenu = NULL;
+ if (!self->parent) {
+ grab_keyboard(FALSE);
+ grab_pointer(FALSE, None);
+ }
+ menu_visible = g_slist_remove(menu_visible, self);
}
}
return NULL;
}
+MenuEntry *menu_find_entry_by_pos(Menu *menu, int x, int y)
+{
+ if (x < 0 || x >= menu->size.width || y < 0 || y >= menu->size.height)
+ return NULL;
+
+ y -= menu->title_h + ob_rr_theme->bwidth;
+ if (y < 0) return NULL;
+
+ g_message ("%d %p", y/menu->item_h, g_list_nth_data(menu->entries, y / menu->item_h));
+ return g_list_nth_data(menu->entries, y / menu->item_h);
+}
+
void menu_entry_fire(MenuEntry *self)
{
Menu *m;
void menu_control_show(Menu *self, int x, int y, Client *client) {
g_assert(!self->invalid);
- XMoveWindow(ob_display, self->frame,
- MIN(x, screen_physical_size.width - self->size.width),
- MIN(y, screen_physical_size.height - self->size.height));
POINT_SET(self->location,
MIN(x, screen_physical_size.width - self->size.width),
MIN(y, screen_physical_size.height - self->size.height));
+ XMoveWindow(ob_display, self->frame, self->location.x, self->location.y);
if (!self->shown) {
XMapWindow(ob_display, self->frame);
/* need to get the width. is this bad?*/
menu_render(self->submenu);
- if (self->submenu->size.width + x > screen_physical_size.width)
+ if (self->submenu->size.width + x >= screen_physical_size.width)
x = self->parent->location.x - self->submenu->size.width -
- ob_rr_theme->bevel;
+ ob_rr_theme->bwidth;
menu_show_full(self->submenu, x,
self->parent->location.y + self->y,
self->item_h += ob_rr_theme->bevel * 2;
items_h = self->item_h * MAX(nitems, 1);
- XResizeWindow(ob_display, self->frame, self->size.width,
- MAX(self->title_h + items_h + ob_rr_theme->bwidth, 1));
+ self->size.height = MAX(self->title_h + items_h + ob_rr_theme->bwidth, 1);
+ XResizeWindow(ob_display, self->frame, self->size.width,self->size.height);
if (self->label)
XMoveResizeWindow(ob_display, self->title, -ob_rr_theme->bwidth,
-ob_rr_theme->bwidth,
item_y += self->item_h;
}
- self->size.height = item_y;
self->invalid = FALSE;
}
self->a_hilite : self->a_item);
break;
}
+ g_message ("%s %d", self->label, self->hilite);
XMoveResizeWindow(ob_display, self->item, 0, self->y,
menu->size.width, menu->item_h);