add the showmenu action

This commit is contained in:
Dana Jansens 2007-06-22 03:53:22 +00:00
parent 9dacac5e5e
commit 38268dc917
9 changed files with 82 additions and 58 deletions

View file

@ -158,6 +158,7 @@ openbox_openbox_SOURCES = \
openbox/actions/all.h \ openbox/actions/all.h \
openbox/actions/debug.c \ openbox/actions/debug.c \
openbox/actions/execute.c \ openbox/actions/execute.c \
openbox/actions/showmenu.c \
openbox/actions.c \ openbox/actions.c \
openbox/actions.h \ openbox/actions.h \
openbox/client.c \ openbox/client.c \

View file

@ -458,18 +458,6 @@ void setup_action_resize(ObAction **a, ObUserAction uact)
(*a)->data.moveresize.corner = 0; (*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) void setup_action_addremove_desktop_current(ObAction **a, ObUserAction uact)
{ {
(*a)->data.addremovedesktop.current = TRUE; (*a)->data.addremovedesktop.current = TRUE;
@ -492,16 +480,6 @@ void setup_client_action(ObAction **a, ObUserAction uact)
ActionString actionstrings[] = ActionString actionstrings[] =
{ {
{
"debug",
action_debug,
NULL
},
{
"execute",
action_execute,
NULL
},
{ {
"directionalfocusnorth", "directionalfocusnorth",
action_directional_focus, action_directional_focus,
@ -832,11 +810,6 @@ ActionString actionstrings[] =
action_exit, action_exit,
NULL NULL
}, },
{
"showmenu",
action_showmenu,
setup_action_showmenu
},
{ {
"sendtotoplayer", "sendtotoplayer",
action_send_to_layer, action_send_to_layer,
@ -1005,9 +978,6 @@ ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
if (parse_attr_string("name", node, &actname)) { if (parse_attr_string("name", node, &actname)) {
if ((act = action_from_string(actname, uact))) { 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 || } else if (act->func == action_move_relative_horz ||
act->func == action_move_relative_vert || act->func == action_move_relative_vert ||
act->func == action_resize_relative_horz || 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); 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) void action_activate(union ActionData *data)
{ {
if (data->client.any.c) { if (data->client.any.c) {
@ -1776,14 +1736,6 @@ void action_exit(union ActionData *data)
ob_exit(0); 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) void action_cycle_windows(union ActionData *data)
{ {
/* if using focus_delay, stop the timer now so that focus doesn't go moving /* if using focus_delay, stop the timer now so that focus doesn't go moving

View file

@ -4,4 +4,5 @@ void action_all_startup()
{ {
action_execute_startup(); action_execute_startup();
action_debug_startup(); action_debug_startup();
action_showmenu_startup();
} }

View file

@ -5,5 +5,6 @@ void action_all_startup();
void action_execute_startup(); void action_execute_startup();
void action_debug_startup(); void action_debug_startup();
void action_showmenu_startup();
#endif #endif

View file

@ -0,0 +1,69 @@
#include "openbox/actions.h"
#include <glib.h>
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;
}

View file

@ -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, static void client_menu_place(ObMenuFrame *frame, gint *x, gint *y,
gint button, gpointer data) gboolean mouse, gpointer data)
{ {
gint dx, dy; gint dx, dy;
if (button == 0 && frame->client) { if (!mouse && frame->client) {
*x = frame->client->frame->area.x; *x = frame->client->frame->area.x;
/* try below the titlebar */ /* try below the titlebar */

View file

@ -407,7 +407,7 @@ static gboolean menu_hide_delay_func(gpointer data)
return FALSE; /* no repeat */ 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; ObMenu *self;
ObMenuFrame *frame; ObMenuFrame *frame;
@ -429,10 +429,10 @@ void menu_show(gchar *name, gint x, gint y, gint button, ObClient *client)
menu_clear_pipe_caches(); menu_clear_pipe_caches();
frame = menu_frame_new(self, 0, client); 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); menu_frame_free(frame);
else { else {
if (!button) { if (!mouse) {
/* select the first entry if it's not a submenu and we opened /* select the first entry if it's not a submenu and we opened
* the menu with the keyboard, and skip all headers */ * the menu with the keyboard, and skip all headers */
GList *it = frame->entries; 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 */ /* reset the hide timer */
if (!button) if (!mouse)
menu_can_hide = TRUE; menu_can_hide = TRUE;
else { else {
menu_can_hide = FALSE; menu_can_hide = FALSE;

View file

@ -52,7 +52,7 @@ typedef void (*ObMenuDestroyFunc)(struct _ObMenu *menu, gpointer data);
for the menu for the menu
*/ */
typedef void (*ObMenuPlaceFunc)(struct _ObMenuFrame *frame, gint *x, gint *y, typedef void (*ObMenuPlaceFunc)(struct _ObMenuFrame *frame, gint *x, gint *y,
gint button, gpointer data); gboolean mouse, gpointer data);
struct _ObMenu struct _ObMenu
{ {
@ -174,7 +174,7 @@ void menu_clear_pipe_caches();
void menu_show_all_shortcuts(ObMenu *self, gboolean show); 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); struct _ObClient *client);
gboolean menu_hide_delay_reached(); gboolean menu_hide_delay_reached();

View file

@ -941,7 +941,7 @@ static gboolean menu_frame_show(ObMenuFrame *self)
} }
gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y, gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y,
gint button) gboolean mouse)
{ {
gint px, py; gint px, py;
guint i; guint i;
@ -963,7 +963,7 @@ gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y,
} }
if (self->menu->place_func) 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 else
menu_frame_place_topmenu(self, &x, &y); menu_frame_place_topmenu(self, &x, &y);