summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-04-16 18:09:11 +0000
committerDana Jansens <danakj@orodu.net>2003-04-16 18:09:11 +0000
commit185d1337e553283530e23b1edff3bb709f04e9bb (patch)
tree20acdcbc0795a4ab333d2ec04aefaa7ecfbd636d
parent04cfdd261dd6b8030cd7618aee5df588f25ef4d2 (diff)
menus works on some level. add a built-in root menu
-rw-r--r--openbox/event.c41
-rw-r--r--openbox/grab.c42
-rw-r--r--openbox/grab.h1
-rw-r--r--openbox/menu.c56
-rw-r--r--openbox/menu.h4
5 files changed, 115 insertions, 29 deletions
diff --git a/openbox/event.c b/openbox/event.c
index 4398c977..7d61c9eb 100644
--- a/openbox/event.c
+++ b/openbox/event.c
@@ -79,6 +79,7 @@ void event_loop()
XEvent e;
int x_fd;
struct timeval *wait;
+ gboolean had_event = FALSE;
while (TRUE) {
/*
@@ -105,13 +106,16 @@ void event_loop()
XNextEvent(ob_display, &e);
event_process(&e);
+ had_event = TRUE;
+ }
+
+ if (!had_event) {
+ timer_dispatch((GTimeVal**)&wait);
+ x_fd = ConnectionNumber(ob_display);
+ FD_ZERO(&selset);
+ FD_SET(x_fd, &selset);
+ select(x_fd + 1, &selset, NULL, NULL, wait);
}
-
- timer_dispatch((GTimeVal**)&wait);
- x_fd = ConnectionNumber(ob_display);
- FD_ZERO(&selset);
- FD_SET(x_fd, &selset);
- select(x_fd + 1, &selset, NULL, NULL, wait);
}
static Window event_get_window(XEvent *e)
@@ -711,7 +715,32 @@ static void event_handle_menu(Menu *menu, XEvent *e)
{
MenuEntry *entry;
+ g_message("EVENT %d", e->type);
switch (e->type) {
+ case ButtonPress:
+ if (e->xbutton.button == 3)
+ menu_hide(menu);
+ break;
+ case ButtonRelease:
+ if (!menu->shown) break;
+
+/* grab_pointer_window(FALSE, None, menu->frame);*/
+
+ 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)) {
+ menu_entry_fire(entry);
+ }
+ }
+ break;
case EnterNotify:
case LeaveNotify:
g_message("enter/leave");
diff --git a/openbox/grab.c b/openbox/grab.c
index 97a1a3db..b2426b9d 100644
--- a/openbox/grab.c
+++ b/openbox/grab.c
@@ -5,15 +5,16 @@
#include <glib.h>
#include <X11/Xlib.h>
-static guint kgrabs, pgrabs, sgrabs;
+#define GRAB_PTR_MASK (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
#define MASK_LIST_SIZE 8
/*! A list of all possible combinations of keyboard lock masks */
static unsigned int mask_list[MASK_LIST_SIZE];
-void grab_keyboard(gboolean grab)
+int grab_keyboard(gboolean grab)
{
+ static guint kgrabs = 0;
if (grab) {
if (kgrabs++ == 0)
XGrabKeyboard(ob_display, ob_root, 0, GrabModeAsync, GrabModeSync,
@@ -22,22 +23,41 @@ void grab_keyboard(gboolean grab)
if (--kgrabs == 0)
XUngrabKeyboard(ob_display, event_lasttime);
}
+ return kgrabs;
}
-void grab_pointer(gboolean grab, Cursor cur)
+int grab_pointer(gboolean grab, Cursor cur)
{
+ static guint pgrabs = 0;
if (grab) {
if (pgrabs++ == 0)
- XGrabPointer(ob_display, ob_root, False, 0, GrabModeAsync,
- GrabModeAsync, FALSE, cur, event_lasttime);
+ XGrabPointer(ob_display, ob_root, False, GRAB_PTR_MASK,
+ GrabModeAsync, GrabModeAsync, FALSE, cur,
+ event_lasttime);
} else if (pgrabs > 0) {
if (--pgrabs == 0)
XUngrabPointer(ob_display, event_lasttime);
}
+ return pgrabs;
}
-void grab_server(gboolean grab)
+int grab_pointer_window(gboolean grab, Cursor cur, Window win)
{
+ static guint pgrabs = 0;
+ if (grab) {
+ if (pgrabs++ == 0)
+ XGrabPointer(ob_display, win, False, GRAB_PTR_MASK, GrabModeAsync,
+ GrabModeAsync, TRUE, cur, event_lasttime);
+ } else if (pgrabs > 0) {
+ if (--pgrabs == 0)
+ XUngrabPointer(ob_display, event_lasttime);
+ }
+ return pgrabs;
+}
+
+int grab_server(gboolean grab)
+{
+ static guint sgrabs = 0;
if (grab) {
if (sgrabs++ == 0) {
XGrabServer(ob_display);
@@ -49,14 +69,13 @@ void grab_server(gboolean grab)
XFlush(ob_display);
}
}
+ return sgrabs;
}
void grab_startup()
{
guint i = 0;
- kgrabs = pgrabs = sgrabs = 0;
-
mask_list[i++] = 0;
mask_list[i++] = LockMask;
mask_list[i++] = NumLockMask;
@@ -70,9 +89,10 @@ void grab_startup()
void grab_shutdown()
{
- while (kgrabs) grab_keyboard(FALSE);
- while (pgrabs) grab_pointer(FALSE, None);
- while (sgrabs) grab_server(FALSE);
+ while (grab_keyboard(FALSE));
+ while (grab_pointer(FALSE, None));
+ while (grab_pointer_window(FALSE, None, None));
+ while (grab_server(FALSE));
}
void grab_button(guint button, guint state, Window win, guint mask,
diff --git a/openbox/grab.h b/openbox/grab.h
index cf3a7fd5..2ba4ed51 100644
--- a/openbox/grab.h
+++ b/openbox/grab.h
@@ -9,6 +9,7 @@ void grab_shutdown();
void grab_keyboard(gboolean grab);
void grab_pointer(gboolean grab, Cursor cur);
+void grab_pointer_window(gboolean grab, Cursor cur, Window win);
void grab_server(gboolean grab);
void grab_button(guint button, guint state, Window win, guint mask,
diff --git a/openbox/menu.c b/openbox/menu.c
index 4a37d2c6..52903dcd 100644
--- a/openbox/menu.c
+++ b/openbox/menu.c
@@ -1,11 +1,13 @@
#include "menu.h"
#include "openbox.h"
#include "stacking.h"
+#include "grab.h"
#include "render/theme.h"
static GHashTable *menu_hash = NULL;
GHashTable *menu_map = NULL;
+#define FRAME_EVENTMASK (ButtonMotionMask | EnterWindowMask | LeaveWindowMask)
#define TITLE_EVENTMASK (ButtonPressMask | ButtonMotionMask)
#define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
ButtonPressMask | ButtonReleaseMask)
@@ -56,6 +58,7 @@ void menu_entry_free(MenuEntry *self)
void menu_startup()
{
Menu *m;
+ Action *a;
menu_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
menu_destroy_hash_key,
@@ -63,14 +66,14 @@ void menu_startup()
menu_map = g_hash_table_new(g_int_hash, g_int_equal);
m = menu_new("sex menu", "root", NULL);
- menu_add_entry(m, menu_entry_new("foo shit etc bleh",
- action_from_string("restart")));
- menu_add_entry(m, menu_entry_new("more shit",
- action_from_string("restart")));
- menu_add_entry(m, menu_entry_new("",
- action_from_string("restart")));
- menu_add_entry(m, menu_entry_new("and yet more",
- action_from_string("restart")));
+ 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("--", NULL));
+ a = action_from_string("exit");
+ menu_add_entry(m, menu_entry_new("exit", a));
}
void menu_shutdown()
@@ -104,7 +107,8 @@ Menu *menu_new(char *label, char *name, Menu *parent)
/* default controllers? */
attrib.override_redirect = TRUE;
- self->frame = createWindow(ob_root, CWOverrideRedirect, &attrib);
+ attrib.event_mask = FRAME_EVENTMASK;
+ self->frame = createWindow(ob_root, CWOverrideRedirect|CWEventMask, &attrib);
attrib.event_mask = TITLE_EVENTMASK;
self->title = createWindow(self->frame, CWEventMask, &attrib);
self->items = createWindow(self->frame, 0, &attrib);
@@ -196,6 +200,8 @@ void menu_show(char *name, int x, int y, Client *client)
return;
}
+ self->client = client;
+
self->width = 1;
self->item_h = 0;
@@ -254,8 +260,19 @@ void menu_show(char *name, int x, int y, Client *client)
item_y += self->item_h;
}
- stacking_raise_internal(self->frame);
- XMapWindow(ob_display, self->frame);
+ if (!self->shown) {
+ stacking_raise_internal(self->frame);
+ XMapWindow(ob_display, self->frame);
+/* grab_pointer_window(TRUE, None, self->frame);*/
+ self->shown = TRUE;
+ }
+}
+
+void menu_hide(Menu *self) {
+ if (self->shown) {
+ XUnmapWindow(ob_display, self->frame);
+ self->shown = FALSE;
+ }
}
MenuEntry *menu_find_entry(Menu *menu, Window win)
@@ -276,7 +293,7 @@ void menu_entry_render(MenuEntry *self)
Appearance *a;
a = !self->enabled ? self->a_disabled :
- (self->hilite ? self->a_hilite : self->a_item);
+ (self->hilite && self->action ? self->a_hilite : self->a_item);
RECT_SET(a->area, 0, 0, menu->width,
menu->item_h);
@@ -292,3 +309,18 @@ void menu_entry_render(MenuEntry *self)
paint(self->item, a);
}
+
+void menu_entry_fire(MenuEntry *self)
+{
+ Menu *m;
+
+ if (self->action) {
+ self->action->data.any.c = self->parent->client;
+ self->action->func(&self->action->data);
+
+ /* hide the whole thing */
+ m = self->parent;
+ while (m->parent) m = m->parent;
+ menu_hide(m);
+ }
+}
diff --git a/openbox/menu.h b/openbox/menu.h
index 2371dee0..32944b79 100644
--- a/openbox/menu.h
+++ b/openbox/menu.h
@@ -30,6 +30,7 @@ typedef struct Menu {
/* render stuff */
+ Client *client;
Window frame;
Window title;
Appearance *a_title;
@@ -79,6 +80,7 @@ Menu *menu_new(char *label, char *name, Menu *parent);
void menu_free(char *name);
void menu_show(char *name, int x, int y, Client *client);
+void menu_hide(Menu *self);
MenuEntry *menu_entry_new_full(char *label, Action *action,
MenuEntryRenderType render_type,
@@ -97,4 +99,6 @@ MenuEntry *menu_find_entry(Menu *menu, Window win);
void menu_entry_render(MenuEntry *self);
+void menu_entry_fire(MenuEntry *self);
+
#endif