X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Factions%2Fdesktop.c;h=8dadf550af3b2ea2787015be50528e48ce8c7a2d;hb=be9637e40317eb36e5a5357d3f58e3af21c81df4;hp=5b0282cc69f1edb87460aaba3ee61a9e0511c977;hpb=567fd15eebdd44e50cef140419dbf7a336708109;p=chaz%2Fopenbox diff --git a/openbox/actions/desktop.c b/openbox/actions/desktop.c index 5b0282cc..8dadf550 100644 --- a/openbox/actions/desktop.c +++ b/openbox/actions/desktop.c @@ -2,10 +2,11 @@ #include "openbox/screen.h" #include "openbox/client.h" #include "openbox/openbox.h" -#include +#include "obt/keyboard.h" typedef enum { LAST, + CURRENT, RELATIVE, ABSOLUTE } SwitchType; @@ -38,11 +39,13 @@ static gpointer setup_send_func(xmlNodePtr node, ObActionsIInputFunc *input, ObActionsICancelFunc *cancel, ObActionsIPostFunc *post); +static void free_func(gpointer o); 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, + ObtIC *ic, gpointer options, gboolean *used); static void i_post_func(gpointer options); @@ -51,7 +54,6 @@ static void i_post_func(gpointer options); 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, ObActionsIPreFunc *pre, ObActionsIInputFunc *input, @@ -112,36 +114,36 @@ static gpointer setup_send_down_func(xmlNodePtr node, ObActionsIInputFunc *input, ObActionsICancelFunc *cancel, ObActionsIPostFunc *post); - + void action_desktop_startup(void) { - actions_register_i("GoToDesktop", setup_go_func, g_free, run_func); - actions_register_i("SendToDesktop", setup_send_func, g_free, run_func); + actions_register_i("GoToDesktop", setup_go_func, free_func, run_func); + actions_register_i("SendToDesktop", setup_send_func, free_func, run_func); /* 3.4-compatibility */ - actions_register("DesktopLast", setup_go_last_func, g_free, run_func); + actions_register("DesktopLast", setup_go_last_func, free_func, 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_i("DesktopNext", setup_go_next_func, g_free, run_func); + free_func, run_func); + actions_register("Desktop", setup_go_abs_func, free_func, run_func); + actions_register_i("DesktopNext", setup_go_next_func, free_func, run_func); actions_register_i("SendToDesktopNext", setup_send_next_func, - g_free, run_func); + free_func, run_func); actions_register_i("DesktopPrevious", setup_go_prev_func, - g_free, run_func); + free_func, 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); + free_func, run_func); + actions_register_i("DesktopLeft", setup_go_left_func, free_func, 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); + free_func, run_func); + actions_register_i("DesktopRight", setup_go_right_func, + free_func, 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); + free_func, run_func); + actions_register_i("DesktopUp", setup_go_up_func, free_func, 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); + free_func, run_func); + actions_register_i("DesktopDown", setup_go_down_func, free_func, run_func); actions_register_i("SendToDesktopDown", setup_send_down_func, - g_free, run_func); + free_func, run_func); } static gpointer setup_func(xmlNodePtr node, @@ -153,7 +155,7 @@ static gpointer setup_func(xmlNodePtr node, xmlNodePtr n; Options *o; - o = g_new0(Options, 1); + o = g_slice_new0(Options); /* don't go anywhere if there are no options given */ o->type = ABSOLUTE; o->u.abs.desktop = screen_desktop; @@ -164,6 +166,8 @@ static gpointer setup_func(xmlNodePtr node, gchar *s = obt_xml_node_string(n); if (!g_ascii_strcasecmp(s, "last")) o->type = LAST; + else if (!g_ascii_strcasecmp(s, "current")) + o->type = CURRENT; else if (!g_ascii_strcasecmp(s, "next")) { o->type = RELATIVE; o->u.rel.linear = TRUE; @@ -237,6 +241,11 @@ static gpointer setup_send_func(xmlNodePtr node, Options *o; o = setup_func(node, pre, input, cancel, post); + if ((n = obt_xml_find_node(node, "desktop"))) { + /* 3.4 compatibility */ + o->u.abs.desktop = obt_xml_node_int(n) - 1; + o->type = ABSOLUTE; + } o->send = TRUE; o->follow = TRUE; @@ -253,7 +262,11 @@ static gpointer setup_send_func(xmlNodePtr node, return o; } -/* Always return FALSE because its not interactive */ +static void free_func(gpointer o) +{ + g_slice_free(Options, o); +} + static gboolean run_func(ObActionsData *data, gpointer options) { Options *o = options; @@ -263,6 +276,9 @@ static gboolean run_func(ObActionsData *data, gpointer options) case LAST: d = screen_last_desktop; break; + case CURRENT: + d = screen_desktop; + break; case ABSOLUTE: d = o->u.abs.desktop; break; @@ -274,7 +290,9 @@ static gboolean run_func(ObActionsData *data, gpointer options) g_assert_not_reached(); } - if (d < screen_num_desktops && d != screen_desktop) { + if (d < screen_num_desktops && + (d != screen_desktop || + (data->client && data->client->desktop != screen_desktop))) { gboolean go = TRUE; actions_client_move(data, TRUE); @@ -297,25 +315,33 @@ static gboolean run_func(ObActionsData *data, gpointer options) static gboolean i_input_func(guint initial_state, XEvent *e, + ObtIC *ic, gpointer options, gboolean *used) { + guint mods, initial_mods; + + initial_mods = obt_keyboard_only_modmasks(initial_state); + mods = obt_keyboard_only_modmasks(e->xkey.state); + if (e->type == KeyRelease) { + /* remove from the state the mask of the modifier key being + released, if it is a modifier key being released that is */ + mods &= ~obt_keyboard_keyevent_to_modmask(e); + } + if (e->type == KeyPress) { + KeySym sym = obt_keyboard_keypress_to_keysym(e); + /* Escape cancels no matter what */ - if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) { + if (sym == XK_Escape) return FALSE; - } /* There were no modifiers and they pressed enter */ - else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RETURN) && - !initial_state) - { + else if ((sym == XK_Return || sym == XK_KP_Enter) && !initial_mods) return FALSE; - } } /* They released the modifiers */ - else if (e->type == KeyRelease && initial_state && - (e->xkey.state & initial_state) == 0) + else if (e->type == KeyRelease && initial_mods && !(mods & initial_mods)) { return FALSE; } @@ -325,7 +351,8 @@ static gboolean i_input_func(guint initial_state, static gboolean i_pre_func(guint initial_state, gpointer options) { - if (!initial_state) { + guint initial_mods = obt_keyboard_only_modmasks(initial_state); + if (!initial_mods) { Options *o = options; o->interactive = FALSE; return FALSE; @@ -345,7 +372,7 @@ static void i_post_func(gpointer options) static gpointer setup_follow(xmlNodePtr node) { xmlNodePtr n; - Options *o = g_new0(Options, 1); + Options *o = g_slice_new0(Options); o->send = TRUE; o->follow = TRUE; if ((n = obt_xml_find_node(node, "follow"))) @@ -355,7 +382,7 @@ static gpointer setup_follow(xmlNodePtr node) static gpointer setup_go_last_func(xmlNodePtr node) { - Options *o = g_new0(Options, 1); + Options *o = g_slice_new0(Options); o->type = LAST; return o; } @@ -370,19 +397,7 @@ static gpointer setup_send_last_func(xmlNodePtr node) static gpointer setup_go_abs_func(xmlNodePtr node) { xmlNodePtr n; - Options *o = g_new0(Options, 1); - o->type = ABSOLUTE; - 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 gpointer setup_send_abs_func(xmlNodePtr node) -{ - xmlNodePtr n; - Options *o = setup_follow(node); + Options *o = g_slice_new0(Options); o->type = ABSOLUTE; if ((n = obt_xml_find_node(node, "desktop"))) o->u.abs.desktop = obt_xml_node_int(n) - 1; @@ -421,7 +436,7 @@ static gpointer setup_go_next_func(xmlNodePtr node, ObActionsICancelFunc *cancel, ObActionsIPostFunc *post) { - Options *o = g_new0(Options, 1); + Options *o = g_slice_new0(Options); setup_rel(o, node, TRUE, OB_DIRECTION_EAST, pre, input, post); return o; } @@ -444,7 +459,7 @@ static gpointer setup_go_prev_func(xmlNodePtr node, ObActionsICancelFunc *cancel, ObActionsIPostFunc *post) { - Options *o = g_new0(Options, 1); + Options *o = g_slice_new0(Options); setup_rel(o, node, TRUE, OB_DIRECTION_WEST, pre, input, post); return o; } @@ -467,7 +482,7 @@ static gpointer setup_go_left_func(xmlNodePtr node, ObActionsICancelFunc *cancel, ObActionsIPostFunc *post) { - Options *o = g_new0(Options, 1); + Options *o = g_slice_new0(Options); setup_rel(o, node, FALSE, OB_DIRECTION_WEST, pre, input, post); return o; } @@ -490,7 +505,7 @@ static gpointer setup_go_right_func(xmlNodePtr node, ObActionsICancelFunc *cancel, ObActionsIPostFunc *post) { - Options *o = g_new0(Options, 1); + Options *o = g_slice_new0(Options); setup_rel(o, node, FALSE, OB_DIRECTION_EAST, pre, input, post); return o; } @@ -513,7 +528,7 @@ static gpointer setup_go_up_func(xmlNodePtr node, ObActionsICancelFunc *cancel, ObActionsIPostFunc *post) { - Options *o = g_new0(Options, 1); + Options *o = g_slice_new0(Options); setup_rel(o, node, FALSE, OB_DIRECTION_NORTH, pre, input, post); return o; } @@ -536,7 +551,7 @@ static gpointer setup_go_down_func(xmlNodePtr node, ObActionsICancelFunc *cancel, ObActionsIPostFunc *post) { - Options *o = g_new0(Options, 1); + Options *o = g_slice_new0(Options); setup_rel(o, node, FALSE, OB_DIRECTION_SOUTH, pre, input, post); return o; }