X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Factions%2Fdesktop.c;h=5b0282cc69f1edb87460aaba3ee61a9e0511c977;hb=b06b684589a618a2481ccc2745d5e03abb6bd5e0;hp=27b717b173f2e771be30264254a9b3fac5ecc2cf;hpb=d18d9c9379e3387073fc9346e9857fdde077b985;p=chaz%2Fopenbox diff --git a/openbox/actions/desktop.c b/openbox/actions/desktop.c index 27b717b1..5b0282cc 100644 --- a/openbox/actions/desktop.c +++ b/openbox/actions/desktop.c @@ -1,6 +1,7 @@ #include "openbox/actions.h" #include "openbox/screen.h" #include "openbox/client.h" +#include "openbox/openbox.h" #include typedef enum { @@ -24,59 +25,130 @@ typedef struct { } u; gboolean send; gboolean follow; + gboolean interactive; } Options; -static gpointer setup_go_func(xmlNodePtr node); -static gpointer setup_send_func(xmlNodePtr node); +static gpointer setup_go_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_send_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); static gboolean run_func(ObActionsData *data, gpointer options); + +static gboolean i_pre_func(guint state, gpointer options); +static gboolean i_input_func(guint initial_state, + XEvent *e, + gpointer options, + gboolean *used); +static void i_post_func(gpointer options); + /* 3.4-compatibility */ static gpointer setup_go_last_func(xmlNodePtr node); static gpointer setup_send_last_func(xmlNodePtr node); static gpointer setup_go_abs_func(xmlNodePtr node); static gpointer setup_send_abs_func(xmlNodePtr node); -static gpointer setup_go_next_func(xmlNodePtr node); -static gpointer setup_send_next_func(xmlNodePtr node); -static gpointer setup_go_prev_func(xmlNodePtr node); -static gpointer setup_send_prev_func(xmlNodePtr node); -static gpointer setup_go_left_func(xmlNodePtr node); -static gpointer setup_send_left_func(xmlNodePtr node); -static gpointer setup_go_right_func(xmlNodePtr node); -static gpointer setup_send_right_func(xmlNodePtr node); -static gpointer setup_go_up_func(xmlNodePtr node); -static gpointer setup_send_up_func(xmlNodePtr node); -static gpointer setup_go_down_func(xmlNodePtr node); -static gpointer setup_send_down_func(xmlNodePtr node); - +static gpointer setup_go_next_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_send_next_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_go_prev_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_send_prev_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_go_left_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_send_left_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_go_right_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_send_right_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_go_up_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_send_up_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_go_down_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); +static gpointer setup_send_down_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post); + void action_desktop_startup(void) { - actions_register("GoToDesktop", setup_go_func, g_free, run_func); - actions_register("SendToDesktop", setup_send_func, g_free, run_func); + actions_register_i("GoToDesktop", setup_go_func, g_free, run_func); + actions_register_i("SendToDesktop", setup_send_func, g_free, run_func); /* 3.4-compatibility */ actions_register("DesktopLast", setup_go_last_func, g_free, run_func); actions_register("SendToDesktopLast", setup_send_last_func, g_free, run_func); actions_register("Desktop", setup_go_abs_func, g_free, run_func); actions_register("SendToDesktop", setup_send_abs_func, g_free, run_func); - actions_register("DesktopNext", setup_go_next_func, g_free, run_func); - actions_register("SendToDesktopNext", setup_send_next_func, - g_free, run_func); - actions_register("DesktopPrevious", setup_go_prev_func, g_free, run_func); - actions_register("SendToDesktopPrevious", setup_send_prev_func, - g_free, run_func); - actions_register("DesktopLeft", setup_go_left_func, g_free, run_func); - actions_register("SendToDesktopLeft", setup_send_left_func, - g_free, run_func); - actions_register("DesktopRight", setup_go_right_func, g_free, run_func); - actions_register("SendToDesktopRight", setup_send_right_func, - g_free, run_func); - actions_register("DesktopUp", setup_go_up_func, g_free, run_func); - actions_register("SendToDesktopUp", setup_send_up_func, g_free, run_func); - actions_register("DesktopDown", setup_go_down_func, g_free, run_func); - actions_register("SendToDesktopDown", setup_send_down_func, - g_free, run_func); + actions_register_i("DesktopNext", setup_go_next_func, g_free, run_func); + actions_register_i("SendToDesktopNext", setup_send_next_func, + g_free, run_func); + actions_register_i("DesktopPrevious", setup_go_prev_func, + g_free, run_func); + actions_register_i("SendToDesktopPrevious", setup_send_prev_func, + g_free, run_func); + actions_register_i("DesktopLeft", setup_go_left_func, g_free, run_func); + actions_register_i("SendToDesktopLeft", setup_send_left_func, + g_free, run_func); + actions_register_i("DesktopRight", setup_go_right_func, g_free, run_func); + actions_register_i("SendToDesktopRight", setup_send_right_func, + g_free, run_func); + actions_register_i("DesktopUp", setup_go_up_func, g_free, run_func); + actions_register_i("SendToDesktopUp", setup_send_up_func, + g_free, run_func); + actions_register_i("DesktopDown", setup_go_down_func, g_free, run_func); + actions_register_i("SendToDesktopDown", setup_send_down_func, + g_free, run_func); } -static gpointer setup_go_func(xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { xmlNodePtr n; Options *o; @@ -88,8 +160,8 @@ static gpointer setup_go_func(xmlNodePtr node) /* wrap by default - it's handy! */ o->u.rel.wrap = TRUE; - if ((n = obt_parse_find_node(node, "to"))) { - gchar *s = obt_parse_node_string(n); + if ((n = obt_xml_find_node(node, "to"))) { + gchar *s = obt_xml_node_string(n); if (!g_ascii_strcasecmp(s, "last")) o->type = LAST; else if (!g_ascii_strcasecmp(s, "next")) { @@ -129,23 +201,54 @@ static gpointer setup_go_func(xmlNodePtr node) g_free(s); } - if ((n = obt_parse_find_node(node, "wrap"))) - o->u.rel.wrap = obt_parse_node_bool(n); + if ((n = obt_xml_find_node(node, "wrap"))) + o->u.rel.wrap = obt_xml_node_bool(n); + + return o; +} + + +static gpointer setup_go_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) +{ + Options *o; + + o = setup_func(node, pre, input, cancel, post); + if (o->type == RELATIVE) { + o->interactive = TRUE; + *pre = i_pre_func; + *input = i_input_func; + *post = i_post_func; + } return o; } -static gpointer setup_send_func(xmlNodePtr node) +static gpointer setup_send_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { xmlNodePtr n; Options *o; - o = setup_go_func(node); + o = setup_func(node, pre, input, cancel, post); o->send = TRUE; o->follow = TRUE; - if ((n = obt_parse_find_node(node, "follow"))) - o->follow = obt_parse_node_bool(n); + if ((n = obt_xml_find_node(node, "follow"))) + o->follow = obt_xml_node_bool(n); + + if (o->type == RELATIVE && o->follow) { + o->interactive = TRUE; + *pre = i_pre_func; + *input = i_input_func; + *post = i_post_func; + } return o; } @@ -188,7 +291,54 @@ static gboolean run_func(ObActionsData *data, gpointer options) actions_client_move(data, FALSE); } - return FALSE; + + return o->interactive; +} + +static gboolean i_input_func(guint initial_state, + XEvent *e, + gpointer options, + gboolean *used) +{ + if (e->type == KeyPress) { + /* Escape cancels no matter what */ + if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) { + return FALSE; + } + + /* There were no modifiers and they pressed enter */ + else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RETURN) && + !initial_state) + { + return FALSE; + } + } + /* They released the modifiers */ + else if (e->type == KeyRelease && initial_state && + (e->xkey.state & initial_state) == 0) + { + return FALSE; + } + + return TRUE; +} + +static gboolean i_pre_func(guint initial_state, gpointer options) +{ + if (!initial_state) { + Options *o = options; + o->interactive = FALSE; + return FALSE; + } + else { + screen_show_desktop_popup(screen_desktop, TRUE); + return TRUE; + } +} + +static void i_post_func(gpointer options) +{ + screen_hide_desktop_popup(); } /* 3.4-compatilibity */ @@ -198,8 +348,8 @@ static gpointer setup_follow(xmlNodePtr node) Options *o = g_new0(Options, 1); o->send = TRUE; o->follow = TRUE; - if ((n = obt_parse_find_node(node, "follow"))) - o->follow = obt_parse_node_bool(n); + if ((n = obt_xml_find_node(node, "follow"))) + o->follow = obt_xml_node_bool(n); return o; } @@ -222,8 +372,8 @@ static gpointer setup_go_abs_func(xmlNodePtr node) xmlNodePtr n; Options *o = g_new0(Options, 1); o->type = ABSOLUTE; - if ((n = obt_parse_find_node(node, "desktop"))) - o->u.abs.desktop = obt_parse_node_int(n) - 1; + if ((n = obt_xml_find_node(node, "desktop"))) + o->u.abs.desktop = obt_xml_node_int(n) - 1; else o->u.abs.desktop = screen_desktop; return o; @@ -234,14 +384,18 @@ static gpointer setup_send_abs_func(xmlNodePtr node) xmlNodePtr n; Options *o = setup_follow(node); o->type = ABSOLUTE; - if ((n = obt_parse_find_node(node, "desktop"))) - o->u.abs.desktop = obt_parse_node_int(n) - 1; + if ((n = obt_xml_find_node(node, "desktop"))) + o->u.abs.desktop = obt_xml_node_int(n) - 1; else o->u.abs.desktop = screen_desktop; return o; } -static void setup_rel(Options *o, xmlNodePtr node, gboolean lin, ObDirection dir) +static void setup_rel(Options *o, xmlNodePtr node, gboolean lin, + ObDirection dir, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsIPostFunc *post) { xmlNodePtr n; @@ -250,90 +404,151 @@ static void setup_rel(Options *o, xmlNodePtr node, gboolean lin, ObDirection dir o->u.rel.dir = dir; o->u.rel.wrap = TRUE; - if ((n = obt_parse_find_node(node, "wrap"))) - o->u.rel.wrap = obt_parse_node_bool(n); + if ((n = obt_xml_find_node(node, "wrap"))) + o->u.rel.wrap = obt_xml_node_bool(n); + + if (input) { + o->interactive = TRUE; + *pre = i_pre_func; + *input = i_input_func; + *post = i_post_func; + } } -static gpointer setup_go_next_func(xmlNodePtr node) +static gpointer setup_go_next_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = g_new0(Options, 1); - setup_rel(o, node, TRUE, OB_DIRECTION_EAST); + setup_rel(o, node, TRUE, OB_DIRECTION_EAST, pre, input, post); return o; } -static gpointer setup_send_next_func(xmlNodePtr node) +static gpointer setup_send_next_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = setup_follow(node); - setup_rel(o, node, TRUE, OB_DIRECTION_EAST); + setup_rel(o, node, TRUE, OB_DIRECTION_EAST, + pre, (o->follow ? input : NULL), post); return o; } -static gpointer setup_go_prev_func(xmlNodePtr node) +static gpointer setup_go_prev_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = g_new0(Options, 1); - setup_rel(o, node, TRUE, OB_DIRECTION_WEST); + setup_rel(o, node, TRUE, OB_DIRECTION_WEST, pre, input, post); return o; } -static gpointer setup_send_prev_func(xmlNodePtr node) +static gpointer setup_send_prev_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = setup_follow(node); - setup_rel(o, node, TRUE, OB_DIRECTION_WEST); + setup_rel(o, node, TRUE, OB_DIRECTION_WEST, + pre, (o->follow ? input : NULL), post); return o; } -static gpointer setup_go_left_func(xmlNodePtr node) +static gpointer setup_go_left_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = g_new0(Options, 1); - setup_rel(o, node, FALSE, OB_DIRECTION_WEST); + setup_rel(o, node, FALSE, OB_DIRECTION_WEST, pre, input, post); return o; } -static gpointer setup_send_left_func(xmlNodePtr node) +static gpointer setup_send_left_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = setup_follow(node); - setup_rel(o, node, FALSE, OB_DIRECTION_WEST); + setup_rel(o, node, FALSE, OB_DIRECTION_WEST, + pre, (o->follow ? input : NULL), post); return o; } -static gpointer setup_go_right_func(xmlNodePtr node) +static gpointer setup_go_right_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = g_new0(Options, 1); - setup_rel(o, node, FALSE, OB_DIRECTION_EAST); + setup_rel(o, node, FALSE, OB_DIRECTION_EAST, pre, input, post); return o; } -static gpointer setup_send_right_func(xmlNodePtr node) +static gpointer setup_send_right_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = setup_follow(node); - setup_rel(o, node, FALSE, OB_DIRECTION_EAST); + setup_rel(o, node, FALSE, OB_DIRECTION_EAST, + pre, (o->follow ? input : NULL), post); return o; } -static gpointer setup_go_up_func(xmlNodePtr node) +static gpointer setup_go_up_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = g_new0(Options, 1); - setup_rel(o, node, FALSE, OB_DIRECTION_NORTH); + setup_rel(o, node, FALSE, OB_DIRECTION_NORTH, pre, input, post); return o; } -static gpointer setup_send_up_func(xmlNodePtr node) +static gpointer setup_send_up_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = setup_follow(node); - setup_rel(o, node, FALSE, OB_DIRECTION_NORTH); + setup_rel(o, node, FALSE, OB_DIRECTION_NORTH, + pre, (o->follow ? input : NULL), post); return o; } -static gpointer setup_go_down_func(xmlNodePtr node) +static gpointer setup_go_down_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = g_new0(Options, 1); - setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH); + setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH, pre, input, post); return o; } -static gpointer setup_send_down_func(xmlNodePtr node) +static gpointer setup_send_down_func(xmlNodePtr node, + ObActionsIPreFunc *pre, + ObActionsIInputFunc *input, + ObActionsICancelFunc *cancel, + ObActionsIPostFunc *post) { Options *o = setup_follow(node); - setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH); + setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH, + pre, (o->follow ? input : NULL), post); return o; }