add code for interactive actions

This commit is contained in:
Dana Jansens 2007-06-22 02:30:13 +00:00
parent 8becd1f93f
commit ae624a1487
4 changed files with 91 additions and 15 deletions

View file

@ -18,9 +18,15 @@
#include "actions.h" #include "actions.h"
#include "gettext.h" #include "gettext.h"
#include "grab.h"
static void actions_definition_ref(ObActionsDefinition *def); static void actions_definition_ref(ObActionsDefinition *def);
static void actions_definition_unref(ObActionsDefinition *def); static void actions_definition_unref(ObActionsDefinition *def);
static gboolean actions_interactive_begin_act(ObActionsAct *act, guint state);
static void actions_interactive_end_act();
static ObActionsAct *interactive_act = NULL;
static guint interactive_initial_state = 0;
struct _ObActionsDefinition { struct _ObActionsDefinition {
guint ref; guint ref;
@ -202,6 +208,7 @@ void actions_run_acts(GSList *acts,
for (it = acts; it; it = g_slist_next(it)) { for (it = acts; it; it = g_slist_next(it)) {
ObActionsData data; ObActionsData data;
ObActionsAct *act = it->data; ObActionsAct *act = it->data;
gboolean ok = TRUE;
data.type = act->def->type; data.type = act->def->type;
actions_setup_data(&data, uact, time, state, x, y); actions_setup_data(&data, uact, time, state, x, y);
@ -216,7 +223,73 @@ void actions_run_acts(GSList *acts,
g_assert_not_reached(); g_assert_not_reached();
} }
if (actions_act_is_interactive(act) &&
(!interactive_act || interactive_act->def != act->def))
{
ok = actions_interactive_begin_act(act, state);
}
/* fire the action's run function with this data */ /* fire the action's run function with this data */
act->def->run(&data, act->options); if (ok) {
if (!act->def->run(&data, act->options))
actions_interactive_end_act();
else
break; /* no actions are run after the interactive one */
}
} }
} }
gboolean actions_interactive_act_running()
{
return interactive_act != NULL;
}
void actions_interactive_cancel_act()
{
if (interactive_act) {
interactive_act->def->i_cancel(interactive_act->options);
actions_interactive_end_act();
}
}
static gboolean actions_interactive_begin_act(ObActionsAct *act, guint state)
{
/* cancel the old one */
if (interactive_act)
actions_interactive_cancel_act();
if (grab_keyboard()) {
interactive_act = act;
actions_act_ref(interactive_act);
interactive_initial_state = state;
return TRUE;
}
else
return FALSE;
}
static void actions_interactive_end_act()
{
if (interactive_act) {
ungrab_keyboard();
actions_act_unref(interactive_act);
interactive_act = NULL;
}
}
gboolean actions_interactive_input_event(XEvent *e)
{
gboolean used = FALSE;
if (interactive_act) {
if (!interactive_act->def->i_input(interactive_initial_state, e,
interactive_act->options, &used))
{
used = TRUE; /* if it cancelled the action then it has to of
been used */
actions_interactive_end_act();
}
}
return used;
}

View file

@ -37,7 +37,8 @@ typedef gboolean (*ObActionsRunFunc)(ObActionsData *data,
gpointer options); gpointer options);
typedef gboolean (*ObActionsInteractiveInputFunc)(guint initial_state, typedef gboolean (*ObActionsInteractiveInputFunc)(guint initial_state,
XEvent *e, XEvent *e,
gpointer options); gpointer options,
gboolean *used);
typedef void (*ObActionsInteractiveCancelFunc)(gpointer options); typedef void (*ObActionsInteractiveCancelFunc)(gpointer options);
typedef enum { typedef enum {
@ -112,3 +113,8 @@ void actions_run_acts(GSList *acts,
gint y, gint y,
ObFrameContext con, ObFrameContext con,
struct _ObClient *client); struct _ObClient *client);
gboolean actions_interactive_act_running();
void actions_interactive_cancel_act();
gboolean actions_interactive_input_event(XEvent *e);

View file

@ -808,8 +808,7 @@ static void event_handle_client(ObClient *client, XEvent *e)
want to deal with them want to deal with them
*/ */
if (!(e->xbutton.button == 4 || e->xbutton.button == 5) && if (!(e->xbutton.button == 4 || e->xbutton.button == 5) &&
!keyboard_interactively_grabbed() && !grab_on_keyboard())
!menu_frame_visible)
{ {
/* use where the press occured */ /* use where the press occured */
con = frame_context(client, e->xbutton.window, px, py); con = frame_context(client, e->xbutton.window, px, py);
@ -956,7 +955,7 @@ static void event_handle_client(ObClient *client, XEvent *e)
(e->type == EnterNotify ? "Enter" : "Leave"), (e->type == EnterNotify ? "Enter" : "Leave"),
e->xcrossing.mode, e->xcrossing.mode,
e->xcrossing.detail, (client?client->window:0)); e->xcrossing.detail, (client?client->window:0));
if (keyboard_interactively_grabbed()) if (grab_on_keyboard())
break; break;
if (config_focus_follow && config_focus_delay && if (config_focus_follow && config_focus_delay &&
/* leave inferior events can happen when the mouse goes onto /* leave inferior events can happen when the mouse goes onto
@ -999,7 +998,7 @@ static void event_handle_client(ObClient *client, XEvent *e)
frame_adjust_state(client->frame); frame_adjust_state(client->frame);
break; break;
case OB_FRAME_CONTEXT_FRAME: case OB_FRAME_CONTEXT_FRAME:
if (keyboard_interactively_grabbed()) if (grab_on_keyboard())
break; break;
if (e->xcrossing.mode == NotifyGrab || if (e->xcrossing.mode == NotifyGrab ||
e->xcrossing.mode == NotifyUngrab || e->xcrossing.mode == NotifyUngrab ||
@ -1792,9 +1791,7 @@ static void event_handle_user_input(ObClient *client, XEvent *e)
/* if the keyboard interactive action uses the event then dont /* if the keyboard interactive action uses the event then dont
use it for bindings. likewise is moveresize uses the event. */ use it for bindings. likewise is moveresize uses the event. */
if (!keyboard_process_interactive_grab(e, &client) && if (!actions_interactive_input_event(e) && !moveresize_event(e)) {
!(moveresize_in_progress && moveresize_event(e)))
{
if (moveresize_in_progress) if (moveresize_in_progress)
/* make further actions work on the client being /* make further actions work on the client being
moved/resized */ moved/resized */
@ -1899,9 +1896,9 @@ static gboolean is_enter_focus_event_ignored(XEvent *e)
void event_cancel_all_key_grabs() void event_cancel_all_key_grabs()
{ {
if (keyboard_interactively_grabbed()) { if (actions_interactive_act_running()) {
keyboard_interactive_cancel(); actions_interactive_cancel_act();
ob_debug("KILLED interactive event\n"); ob_debug("KILLED interactive action\n");
} }
else if (menu_frame_visible) { else if (menu_frame_visible) {
menu_frame_hide_all(); menu_frame_hide_all();

View file

@ -416,7 +416,7 @@ gboolean moveresize_event(XEvent *e)
{ {
gboolean used = FALSE; gboolean used = FALSE;
g_assert(moveresize_in_progress); if (!moveresize_in_progress) return FALSE;
if (e->type == ButtonPress) { if (e->type == ButtonPress) {
if (!button) { if (!button) {