From: Dana Jansens Date: Mon, 8 Aug 2011 14:51:45 +0000 (-0400) Subject: Turn the Foo/ToggleFoo/UnFoo actions into a single Foo action with option "set" which... X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=b24e311c92b440f5165464e8063224a9e29919a8;p=dana%2Fopenbox.git Turn the Foo/ToggleFoo/UnFoo actions into a single Foo action with option "set" which is "on", "off", or "toggle" --- diff --git a/openbox/actions/cyclewindows.c b/openbox/actions/cyclewindows.c index c2d39c92..a56022c3 100644 --- a/openbox/actions/cyclewindows.c +++ b/openbox/actions/cyclewindows.c @@ -109,9 +109,9 @@ static gpointer setup_func(GHashTable *config, else { ObActionParser *p = action_parser_new(); o->actions = action_parser_read_string(p, - "focus\n" - "raise\n" - "unshade\n"); + "focus\n" + "raise\n" + "shade set:off\n"); action_parser_unref(p); } diff --git a/openbox/actions/decorations.c b/openbox/actions/decorations.c index 037b9d57..ec833368 100644 --- a/openbox/actions/decorations.c +++ b/openbox/actions/decorations.c @@ -1,74 +1,68 @@ #include "openbox/action.h" #include "openbox/action_list_run.h" +#include "openbox/config_value.h" #include "openbox/client.h" #include "openbox/client_set.h" -static gboolean run_func_on(const ObClientSet *set, - const ObActionListRun *data, gpointer options); -static gboolean run_func_off(const ObClientSet *set, - const ObActionListRun *data, gpointer options); -static gboolean run_func_toggle(const ObClientSet *set, - const ObActionListRun *data, gpointer options); +typedef struct { + gboolean toggle; + gboolean set; +} Options; + +static gpointer setup_func(GHashTable *config); +static void free_func(gpointer o); +static gboolean run_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options); void action_decorations_startup(void) { action_register("Decorate", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_on); - action_register("Undecorate", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_off); - action_register("ToggleDecorations", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_toggle); + setup_func, free_func, run_func); } -static gboolean each_on(ObClient *c, const ObActionListRun *data, gpointer o) +static gpointer setup_func(GHashTable *config) { - client_set_undecorated(data->target, FALSE); - return TRUE; -} + ObConfigValue *v; + Options *o; -/* Always return FALSE because its not interactive */ -static gboolean run_func_on(const ObClientSet *set, - const ObActionListRun *data, gpointer options) -{ - if (!client_set_is_empty(set)) { - action_client_move(data, TRUE); - client_set_run(set, data, each_on, options); - action_client_move(data, FALSE); + o = g_slice_new0(Options); + o->toggle = TRUE; + o->set = FALSE; + + v = g_hash_table_lookup(config, "set"); + if (v && config_value_is_string(v)) { + const gchar *s = config_value_string(v); + if (!g_ascii_strcasecmp(s, "on")) + o->toggle = FALSE; + else if (!g_ascii_strcasecmp(s, "off")) { + o->toggle = FALSE; + o->set = TRUE; + } } - return FALSE; -} -static gboolean each_off(ObClient *c, const ObActionListRun *data, gpointer o) -{ - client_set_undecorated(data->target, TRUE); - return TRUE; + return o; } -/* Always return FALSE because its not interactive */ -static gboolean run_func_off(const ObClientSet *set, - const ObActionListRun *data, gpointer options) +static void free_func(gpointer o) { - if (!client_set_is_empty(set)) { - action_client_move(data, TRUE); - client_set_run(set, data, each_off, options); - action_client_move(data, FALSE); - } - return FALSE; + g_slice_free(Options, o); } -static gboolean each_flip(ObClient *c, const ObActionListRun *data, gpointer o) +static gboolean each_run(ObClient *c, const ObActionListRun *data, + gpointer options) { - client_set_undecorated(data->target, !c->undecorated); + Options *o = options; + client_set_undecorated(data->target, o->toggle ? !c->undecorated : o->set); return TRUE; } /* Always return FALSE because its not interactive */ -static gboolean run_func_toggle(const ObClientSet *set, - const ObActionListRun *data, gpointer options) +static gboolean run_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options) { if (!client_set_is_empty(set)) { action_client_move(data, TRUE); - client_set_run(set, data, each_flip, options); + client_set_run(set, data, each_run, options); action_client_move(data, FALSE); } return FALSE; diff --git a/openbox/actions/directionalwindows.c b/openbox/actions/directionalwindows.c index fcd3d109..bdbe004d 100644 --- a/openbox/actions/directionalwindows.c +++ b/openbox/actions/directionalwindows.c @@ -112,7 +112,7 @@ static gpointer setup_func(GHashTable *config) o->actions = action_parser_read_string(p, "focus\n" "raise\n" - "unshade\n"); + "shade set:off\n"); action_parser_unref(p); } diff --git a/openbox/actions/fullscreen.c b/openbox/actions/fullscreen.c index 1abc3cbb..14280ec2 100644 --- a/openbox/actions/fullscreen.c +++ b/openbox/actions/fullscreen.c @@ -1,74 +1,66 @@ #include "openbox/action.h" #include "openbox/action_list_run.h" +#include "openbox/config_value.h" #include "openbox/client.h" #include "openbox/client_set.h" -static gboolean run_func_on(const ObClientSet *set, - const ObActionListRun *data, gpointer options); -static gboolean run_func_off(const ObClientSet *set, - const ObActionListRun *data, gpointer options); -static gboolean run_func_toggle(const ObClientSet *set, - const ObActionListRun *data, gpointer options); +typedef struct { + gboolean toggle; + gboolean set; +} Options; + +static gpointer setup_func(GHashTable *config); +static void free_func(gpointer o); +static gboolean run_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options); void action_fullscreen_startup(void) { action_register("Fullscreen", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_on); - action_register("Unfullscreen", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_off); - action_register("ToggleFullscreen", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_toggle); + setup_func, free_func, run_func); } -static gboolean each_on(ObClient *c, const ObActionListRun *data, - gpointer options) +static gpointer setup_func(GHashTable *config) { - client_fullscreen(c, TRUE); - return TRUE; -} + ObConfigValue *v; + Options *o; -/* Always return FALSE because its not interactive */ -static gboolean run_func_on(const ObClientSet *set, - const ObActionListRun *data, gpointer options) -{ - action_client_move(data, TRUE); - client_set_run(set, data, each_on, options); - action_client_move(data, FALSE); - return FALSE; -} + o = g_slice_new0(Options); + o->toggle = TRUE; + o->set = TRUE; -static gboolean each_off(ObClient *c, const ObActionListRun *data, - gpointer options) -{ - client_fullscreen(c, FALSE); - return TRUE; + v = g_hash_table_lookup(config, "set"); + if (v && config_value_is_string(v)) { + const gchar *s = config_value_string(v); + if (!g_ascii_strcasecmp(s, "on")) + o->toggle = FALSE; + else if (!g_ascii_strcasecmp(s, "off")) { + o->toggle = FALSE; + o->set = FALSE; + } + } + return o; } -/* Always return FALSE because its not interactive */ -static gboolean run_func_off(const ObClientSet *set, - const ObActionListRun *data, gpointer options) +static void free_func(gpointer o) { - action_client_move(data, TRUE); - client_set_run(set, data, each_off, options); - action_client_move(data, FALSE); - return FALSE; + g_slice_free(Options, o); } -static gboolean each_toggle(ObClient *c, const ObActionListRun *data, +static gboolean each_run(ObClient *c, const ObActionListRun *data, gpointer options) { - client_fullscreen(c, !c->fullscreen); + Options *o = options; + client_fullscreen(c, o->toggle ? !c->fullscreen : o->set); return TRUE; } /* Always return FALSE because its not interactive */ -static gboolean run_func_toggle(const ObClientSet *set, - const ObActionListRun *data, gpointer options) +static gboolean run_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options) { - if (!client_set_is_empty(set)) { - action_client_move(data, TRUE); - client_set_run(set, data, each_toggle, options); - action_client_move(data, FALSE); - } + action_client_move(data, TRUE); + client_set_run(set, data, each_run, options); + action_client_move(data, FALSE); return FALSE; } diff --git a/openbox/actions/maximize.c b/openbox/actions/maximize.c index 6d594ee1..f720e3a6 100644 --- a/openbox/actions/maximize.c +++ b/openbox/actions/maximize.c @@ -13,25 +13,19 @@ typedef enum { typedef struct { MaxDirection dir; + gboolean toggle; + gboolean set; } Options; static gpointer setup_func(GHashTable *config); static void free_func(gpointer o); -static gboolean run_func_on(const ObClientSet *set, - const ObActionListRun *data, gpointer options); -static gboolean run_func_off(const ObClientSet *set, - const ObActionListRun *data, gpointer options); -static gboolean run_func_toggle(const ObClientSet *set, - const ObActionListRun *data, gpointer options); +static gboolean run_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options); void action_maximize_startup(void) { action_register("Maximize", OB_ACTION_DEFAULT_FILTER_SINGLE, - setup_func, free_func, run_func_on); - action_register("Unmaximize", OB_ACTION_DEFAULT_FILTER_SINGLE, - setup_func, free_func, run_func_off); - action_register("ToggleMaximize", OB_ACTION_DEFAULT_FILTER_SINGLE, - setup_func, free_func, run_func_toggle); + setup_func, free_func, run_func); } static gpointer setup_func(GHashTable *config) @@ -41,6 +35,8 @@ static gpointer setup_func(GHashTable *config) o = g_slice_new0(Options); o->dir = BOTH; + o->toggle = TRUE; + o->set = TRUE; v = g_hash_table_lookup(config, "dir"); if (v && config_value_is_string(v)) { @@ -52,6 +48,16 @@ static gpointer setup_func(GHashTable *config) !g_ascii_strcasecmp(s, "horz")) o->dir = HORZ; } + v = g_hash_table_lookup(config, "set"); + if (v && config_value_is_string(v)) { + const gchar *s = config_value_string(v); + if (!g_ascii_strcasecmp(s, "on")) + o->toggle = FALSE; + else if (!g_ascii_strcasecmp(s, "off")) { + o->toggle = FALSE; + o->set = FALSE; + } + } return o; } @@ -61,74 +67,25 @@ static void free_func(gpointer o) g_slice_free(Options, o); } -static gboolean each_on(ObClient *c, const ObActionListRun *data, +static gboolean each_run(ObClient *c, const ObActionListRun *data, gpointer options) -{ - Options *o = options; - if (data->target) { - action_client_move(data, TRUE); - client_maximize(data->target, TRUE, o->dir); - action_client_move(data, FALSE); - } - return TRUE; -} - -/* Always return FALSE because its not interactive */ -static gboolean run_func_on(const ObClientSet *set, - const ObActionListRun *data, gpointer options) -{ - if (!client_set_is_empty(set)) { - action_client_move(data, TRUE); - client_set_run(set, data, each_on, options); - action_client_move(data, FALSE); - } - return FALSE; -} - -static gboolean each_off(ObClient *c, const ObActionListRun *data, - gpointer options) -{ - Options *o = options; - if (data->target) { - action_client_move(data, TRUE); - client_maximize(data->target, FALSE, o->dir); - action_client_move(data, FALSE); - } - return TRUE; -} - -/* Always return FALSE because its not interactive */ -static gboolean run_func_off(const ObClientSet *set, - const ObActionListRun *data, gpointer options) -{ - if (!client_set_is_empty(set)) { - action_client_move(data, TRUE); - client_set_run(set, data, each_off, options); - action_client_move(data, FALSE); - } - return FALSE; -} - -static gboolean each_toggle(ObClient *c, const ObActionListRun *data, - gpointer options) { Options *o = options; gboolean toggle; - toggle = ((o->dir == HORZ && !data->target->max_horz) || - (o->dir == VERT && !data->target->max_vert) || - (o->dir == BOTH && - !(data->target->max_horz && data->target->max_vert))); - client_maximize(data->target, toggle, o->dir); + toggle = ((o->dir == HORZ && !c->max_horz) || + (o->dir == VERT && !c->max_vert) || + (o->dir == BOTH && !(c->max_horz && c->max_vert))); + client_maximize(data->target, (o->toggle ? toggle : o->set), o->dir); return TRUE; } /* Always return FALSE because its not interactive */ -static gboolean run_func_toggle(const ObClientSet *set, - const ObActionListRun *data, gpointer options) +static gboolean run_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options) { if (!client_set_is_empty(set)) { action_client_move(data, TRUE); - client_set_run(set, data, each_toggle, options); + client_set_run(set, data, each_run, options); action_client_move(data, FALSE); } return FALSE; diff --git a/openbox/actions/omnipresent.c b/openbox/actions/omnipresent.c index 1bc304f6..84d11a79 100644 --- a/openbox/actions/omnipresent.c +++ b/openbox/actions/omnipresent.c @@ -1,79 +1,73 @@ #include "openbox/action.h" #include "openbox/action_list_run.h" +#include "openbox/config_value.h" #include "openbox/client.h" #include "openbox/client_set.h" #include "openbox/screen.h" -static gboolean run_func_on(const ObClientSet *set, - const ObActionListRun *data, gpointer options); -static gboolean run_func_off(const ObClientSet *set, - const ObActionListRun *data, gpointer options); -static gboolean run_func_toggle(const ObClientSet *set, - const ObActionListRun *data, gpointer options); +typedef struct { + gboolean toggle; + gboolean set; +} Options; + +static gpointer setup_func(GHashTable *config); +static void free_func(gpointer o); +static gboolean run_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options); void action_omnipresent_startup(void) { action_register("Omnipresent", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_on); - action_register("Unomnipresent", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_off); - action_register("ToggleOmnipresent", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_toggle); + setup_func, free_func, run_func); } -static gboolean each_off(ObClient *c, const ObActionListRun *data, - gpointer options) +static gpointer setup_func(GHashTable *config) { - client_set_desktop(c, FALSE, FALSE, TRUE); - return TRUE; -} + ObConfigValue *v; + Options *o; -/* Always return FALSE because its not interactive */ -static gboolean run_func_off(const ObClientSet *set, - const ObActionListRun *data, gpointer options) -{ - if (!client_set_is_empty(set)) { - action_client_move(data, TRUE); - client_set_run(set, data, each_off, options); - action_client_move(data, FALSE); + o = g_slice_new0(Options); + o->toggle = TRUE; + o->set = TRUE; + + v = g_hash_table_lookup(config, "set"); + if (v && config_value_is_string(v)) { + const gchar *s = config_value_string(v); + if (!g_ascii_strcasecmp(s, "on")) + o->toggle = FALSE; + else if (!g_ascii_strcasecmp(s, "off")) { + o->toggle = FALSE; + o->set = FALSE; + } } - return FALSE; -} -static gboolean each_on(ObClient *c, const ObActionListRun *data, - gpointer options) -{ - client_set_desktop(c, TRUE, FALSE, TRUE); - return TRUE; + return o; } -/* Always return FALSE because its not interactive */ -static gboolean run_func_on(const ObClientSet *set, - const ObActionListRun *data, gpointer options) +static void free_func(gpointer o) { - if (!client_set_is_empty(set)) { - action_client_move(data, TRUE); - client_set_run(set, data, each_on, options); - action_client_move(data, FALSE); - } - return FALSE; + g_slice_free(Options, o); } -static gboolean each_toggle(ObClient *c, const ObActionListRun *data, +static gboolean each_run(ObClient *c, const ObActionListRun *data, gpointer options) { - gboolean omni = c->desktop == DESKTOP_ALL ? screen_desktop : DESKTOP_ALL; - client_set_desktop(c, omni, FALSE, TRUE); + Options *o = options; + guint toggle; + toggle = c->desktop == DESKTOP_ALL ? screen_desktop : DESKTOP_ALL; + client_set_desktop(c, (o->toggle ? toggle : + (o->set ? DESKTOP_ALL : screen_desktop)), + FALSE, TRUE); return TRUE; } /* Always return FALSE because its not interactive */ -static gboolean run_func_toggle(const ObClientSet *set, - const ObActionListRun *data, gpointer options) +static gboolean run_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options) { if (!client_set_is_empty(set)) { action_client_move(data, TRUE); - client_set_run(set, data, each_toggle, options); + client_set_run(set, data, each_run, options); action_client_move(data, FALSE); } return FALSE; diff --git a/openbox/actions/shade.c b/openbox/actions/shade.c index 489891a5..3e65df2c 100644 --- a/openbox/actions/shade.c +++ b/openbox/actions/shade.c @@ -1,77 +1,68 @@ #include "openbox/action.h" #include "openbox/action_list_run.h" +#include "openbox/config_value.h" #include "openbox/client.h" #include "openbox/client_set.h" -static gboolean run_func_on(const ObClientSet *set, - const ObActionListRun *data, gpointer options); -static gboolean run_func_off(const ObClientSet *set, - const ObActionListRun *data, gpointer options); -static gboolean run_func_toggle(const ObClientSet *set, - const ObActionListRun *data, gpointer options); +typedef struct { + gboolean toggle; + gboolean set; +} Options; + +static gpointer setup_func(GHashTable *config); +static void free_func(gpointer o); +static gboolean run_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options); void action_shade_startup(void) { action_register("Shade", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_on); - action_register("Unshade", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_off); - action_register("ToggleShade", OB_ACTION_DEFAULT_FILTER_SINGLE, - NULL, NULL, run_func_toggle); + setup_func, free_func, run_func); } -static gboolean each_on(ObClient *c, const ObActionListRun *data, - gpointer options) +static gpointer setup_func(GHashTable *config) { - client_shade(c, TRUE); - return TRUE; -} + ObConfigValue *v; + Options *o; -/* Always return FALSE because its not interactive */ -static gboolean run_func_on(const ObClientSet *set, - const ObActionListRun *data, gpointer options) -{ - if (data->target) { - action_client_move(data, TRUE); - client_set_run(set, data, each_on, options); - action_client_move(data, FALSE); + o = g_slice_new0(Options); + o->toggle = TRUE; + o->set = TRUE; + + v = g_hash_table_lookup(config, "set"); + if (v && config_value_is_string(v)) { + const gchar *s = config_value_string(v); + if (!g_ascii_strcasecmp(s, "on")) + o->toggle = FALSE; + else if (!g_ascii_strcasecmp(s, "off")) { + o->toggle = FALSE; + o->set = FALSE; + } } - return FALSE; -} -static gboolean each_off(ObClient *c, const ObActionListRun *data, - gpointer options) -{ - client_shade(c, FALSE); - return TRUE; + return o; } -/* Always return FALSE because its not interactive */ -static gboolean run_func_off(const ObClientSet *set, - const ObActionListRun *data, gpointer options) +static void free_func(gpointer o) { - if (data->target) { - action_client_move(data, TRUE); - client_set_run(set, data, each_off, options); - action_client_move(data, FALSE); - } - return FALSE; + g_slice_free(Options, o); } -static gboolean each_toggle(ObClient *c, const ObActionListRun *data, - gpointer options) +static gboolean each_run(ObClient *c, const ObActionListRun *data, + gpointer options) { - client_shade(c, !c->shaded); + Options *o = options; + client_shade(c, o->toggle ? !c->shaded : o->set); return TRUE; } /* Always return FALSE because its not interactive */ -static gboolean run_func_toggle(const ObClientSet *set, - const ObActionListRun *data, gpointer options) +static gboolean run_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options) { if (data->target) { action_client_move(data, TRUE); - client_set_run(set, data, each_toggle, options); + client_set_run(set, data, each_run, options); action_client_move(data, FALSE); } return FALSE; diff --git a/openbox/config.c b/openbox/config.c index d2635d6f..5e30f9e1 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -992,10 +992,10 @@ static void bind_default_mouse(void) { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Raise" }, { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Raise" }, { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Close" }, - { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "ToggleMaximize" }, + { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "Maximize" }, { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Iconify" }, - { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "ToggleOmnipresent" }, - { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "ToggleShade" }, + { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Omnipresent" }, + { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Shade" }, { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION, "Resize" }, { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION, "Resize" }, { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },