From 38268dc917ac9e59d9e8ef87825c9489ced77e95 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 22 Jun 2007 03:53:22 +0000 Subject: [PATCH] add the showmenu action --- Makefile.am | 1 + openbox/action.c | 48 -------------------------------- openbox/actions/all.c | 1 + openbox/actions/all.h | 1 + openbox/actions/showmenu.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++ openbox/client_menu.c | 4 +-- openbox/menu.c | 8 +++--- openbox/menu.h | 4 +-- openbox/menuframe.c | 4 +-- 9 files changed, 82 insertions(+), 58 deletions(-) create mode 100644 openbox/actions/showmenu.c diff --git a/Makefile.am b/Makefile.am index c733558..e66d9d4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -158,6 +158,7 @@ openbox_openbox_SOURCES = \ openbox/actions/all.h \ openbox/actions/debug.c \ openbox/actions/execute.c \ + openbox/actions/showmenu.c \ openbox/actions.c \ openbox/actions.h \ openbox/client.c \ diff --git a/openbox/action.c b/openbox/action.c index d706e37..9b8653d 100644 --- a/openbox/action.c +++ b/openbox/action.c @@ -458,18 +458,6 @@ void setup_action_resize(ObAction **a, ObUserAction uact) (*a)->data.moveresize.corner = 0; } -void setup_action_showmenu(ObAction **a, ObUserAction uact) -{ - (*a)->data.showmenu.any.client_action = OB_CLIENT_ACTION_OPTIONAL; - /* you cannot call ShowMenu from inside a menu, cuz the menu code makes - assumptions that there is only one menu (and submenus) open at - a time! */ - if (uact == OB_USER_ACTION_MENU_SELECTION) { - action_unref(*a); - *a = NULL; - } -} - void setup_action_addremove_desktop_current(ObAction **a, ObUserAction uact) { (*a)->data.addremovedesktop.current = TRUE; @@ -493,16 +481,6 @@ void setup_client_action(ObAction **a, ObUserAction uact) ActionString actionstrings[] = { { - "debug", - action_debug, - NULL - }, - { - "execute", - action_execute, - NULL - }, - { "directionalfocusnorth", action_directional_focus, setup_action_directional_focus_north @@ -833,11 +811,6 @@ ActionString actionstrings[] = NULL }, { - "showmenu", - action_showmenu, - setup_action_showmenu - }, - { "sendtotoplayer", action_send_to_layer, setup_action_top_layer @@ -1005,9 +978,6 @@ ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, if (parse_attr_string("name", node, &actname)) { if ((act = action_from_string(actname, uact))) { - } else if (act->func == action_showmenu) { - if ((n = parse_find_node("menu", node->xmlChildrenNode))) - act->data.showmenu.name = parse_string(doc, n); } else if (act->func == action_move_relative_horz || act->func == action_move_relative_vert || act->func == action_resize_relative_horz || @@ -1222,16 +1192,6 @@ void action_run_string(const gchar *name, struct _ObClient *c, Time time) action_run(l, c, 0, time); } -void action_debug(union ActionData *data) -{ - if (data->debug.string) - g_print("%s\n", data->debug.string); -} - -void action_execute(union ActionData *data) -{ -} - void action_activate(union ActionData *data) { if (data->client.any.c) { @@ -1776,14 +1736,6 @@ void action_exit(union ActionData *data) ob_exit(0); } -void action_showmenu(union ActionData *data) -{ - if (data->showmenu.name) { - menu_show(data->showmenu.name, data->any.x, data->any.y, - data->any.button, data->showmenu.any.c); - } -} - void action_cycle_windows(union ActionData *data) { /* if using focus_delay, stop the timer now so that focus doesn't go moving diff --git a/openbox/actions/all.c b/openbox/actions/all.c index 09eae59..e0485eb 100644 --- a/openbox/actions/all.c +++ b/openbox/actions/all.c @@ -4,4 +4,5 @@ void action_all_startup() { action_execute_startup(); action_debug_startup(); + action_showmenu_startup(); } diff --git a/openbox/actions/all.h b/openbox/actions/all.h index b93f140..13fbbd4 100644 --- a/openbox/actions/all.h +++ b/openbox/actions/all.h @@ -5,5 +5,6 @@ void action_all_startup(); void action_execute_startup(); void action_debug_startup(); +void action_showmenu_startup(); #endif diff --git a/openbox/actions/showmenu.c b/openbox/actions/showmenu.c new file mode 100644 index 0000000..6b6cbbe --- /dev/null +++ b/openbox/actions/showmenu.c @@ -0,0 +1,69 @@ +#include "openbox/actions.h" +#include + +typedef struct { + gchar *name; +} Options; + +static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static void free_func(gpointer options); +static gboolean run_func(ObActionsData *data, gpointer options); +/* +static gboolean i_input_func(guint initial_state, + XEvent *e, + gpointer options, + gboolean *used); +static void i_cancel_func(gpointer options); +*/ + +void action_showmenu_startup() +{ + actions_register("ShowMenu", + setup_func, + free_func, + run_func, + NULL, NULL); +} + +static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +{ + xmlNodePtr n; + Options *o; + + o = g_new0(Options, 1); + + if ((n = parse_find_node("menu", node))) + o->name = parse_string(doc, n); + return o; +} + +static void free_func(gpointer options) +{ + Options *o = options; + + if (o) { + g_free(o->name); + g_free(o); + } +} + +/* Always return FALSE because its not interactive */ +static gboolean run_func(ObActionsData *data, gpointer options) +{ + Options *o = options; + + /* you cannot call ShowMenu from inside a menu */ + if (data->uact == OB_USER_ACTION_MENU_SELECTION) return FALSE; + + if (o->name) { + gboolean mouse = (data->uact == OB_USER_ACTION_MOUSE_PRESS || + data->uact == OB_USER_ACTION_MOUSE_RELEASE || + data->uact == OB_USER_ACTION_MOUSE_CLICK || + data->uact == OB_USER_ACTION_MOUSE_DOUBLE_CLICK || + data->uact == OB_USER_ACTION_MOUSE_MOTION); + + menu_show(o->name, data->x, data->y, mouse, data->client); + } + + return FALSE; +} diff --git a/openbox/client_menu.c b/openbox/client_menu.c index cc67a46..8e29bd7 100644 --- a/openbox/client_menu.c +++ b/openbox/client_menu.c @@ -293,11 +293,11 @@ static void send_to_menu_execute(ObMenuEntry *e, ObMenuFrame *f, } static void client_menu_place(ObMenuFrame *frame, gint *x, gint *y, - gint button, gpointer data) + gboolean mouse, gpointer data) { gint dx, dy; - if (button == 0 && frame->client) { + if (!mouse && frame->client) { *x = frame->client->frame->area.x; /* try below the titlebar */ diff --git a/openbox/menu.c b/openbox/menu.c index c411101..855828c 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -407,7 +407,7 @@ static gboolean menu_hide_delay_func(gpointer data) return FALSE; /* no repeat */ } -void menu_show(gchar *name, gint x, gint y, gint button, ObClient *client) +void menu_show(gchar *name, gint x, gint y, gboolean mouse, ObClient *client) { ObMenu *self; ObMenuFrame *frame; @@ -429,10 +429,10 @@ void menu_show(gchar *name, gint x, gint y, gint button, ObClient *client) menu_clear_pipe_caches(); frame = menu_frame_new(self, 0, client); - if (!menu_frame_show_topmenu(frame, x, y, button)) + if (!menu_frame_show_topmenu(frame, x, y, mouse)) menu_frame_free(frame); else { - if (!button) { + if (!mouse) { /* select the first entry if it's not a submenu and we opened * the menu with the keyboard, and skip all headers */ GList *it = frame->entries; @@ -449,7 +449,7 @@ void menu_show(gchar *name, gint x, gint y, gint button, ObClient *client) } /* reset the hide timer */ - if (!button) + if (!mouse) menu_can_hide = TRUE; else { menu_can_hide = FALSE; diff --git a/openbox/menu.h b/openbox/menu.h index 47b65fb..f0fc42b 100644 --- a/openbox/menu.h +++ b/openbox/menu.h @@ -52,7 +52,7 @@ typedef void (*ObMenuDestroyFunc)(struct _ObMenu *menu, gpointer data); for the menu */ typedef void (*ObMenuPlaceFunc)(struct _ObMenuFrame *frame, gint *x, gint *y, - gint button, gpointer data); + gboolean mouse, gpointer data); struct _ObMenu { @@ -174,7 +174,7 @@ void menu_clear_pipe_caches(); void menu_show_all_shortcuts(ObMenu *self, gboolean show); -void menu_show(gchar *name, gint x, gint y, gint button, +void menu_show(gchar *name, gint x, gint y, gboolean mouse, struct _ObClient *client); gboolean menu_hide_delay_reached(); diff --git a/openbox/menuframe.c b/openbox/menuframe.c index 7bacf02..4cdf6a3 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -941,7 +941,7 @@ static gboolean menu_frame_show(ObMenuFrame *self) } gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y, - gint button) + gboolean mouse) { gint px, py; guint i; @@ -963,7 +963,7 @@ gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y, } if (self->menu->place_func) - self->menu->place_func(self, &x, &y, button, self->menu->data); + self->menu->place_func(self, &x, &y, mouse, self->menu->data); else menu_frame_place_topmenu(self, &x, &y); -- 1.9.1