add the showmenu action
This commit is contained in:
parent
9dacac5e5e
commit
38268dc917
9 changed files with 82 additions and 58 deletions
|
@ -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 \
|
||||
|
|
|
@ -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;
|
||||
|
@ -492,16 +480,6 @@ void setup_client_action(ObAction **a, ObUserAction uact)
|
|||
|
||||
ActionString actionstrings[] =
|
||||
{
|
||||
{
|
||||
"debug",
|
||||
action_debug,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
"execute",
|
||||
action_execute,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
"directionalfocusnorth",
|
||||
action_directional_focus,
|
||||
|
@ -832,11 +810,6 @@ ActionString actionstrings[] =
|
|||
action_exit,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
"showmenu",
|
||||
action_showmenu,
|
||||
setup_action_showmenu
|
||||
},
|
||||
{
|
||||
"sendtotoplayer",
|
||||
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 ((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
|
||||
|
|
|
@ -4,4 +4,5 @@ void action_all_startup()
|
|||
{
|
||||
action_execute_startup();
|
||||
action_debug_startup();
|
||||
action_showmenu_startup();
|
||||
}
|
||||
|
|
|
@ -5,5 +5,6 @@ void action_all_startup();
|
|||
|
||||
void action_execute_startup();
|
||||
void action_debug_startup();
|
||||
void action_showmenu_startup();
|
||||
|
||||
#endif
|
||||
|
|
69
openbox/actions/showmenu.c
Normal file
69
openbox/actions/showmenu.c
Normal 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;
|
||||
}
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue