X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Factions%2Fmaximize.c;h=db7c36bb8aaebb9fd9d47a7eea41768bb40d5662;hb=c590a83207ed5825b513e2278789ed13f55574b2;hp=ebfb1e5c309c586ad3f54a690720f6ec26425efb;hpb=06ed8ab6c03337710acba8d6a70781456e979384;p=chaz%2Fopenbox diff --git a/openbox/actions/maximize.c b/openbox/actions/maximize.c index ebfb1e5c..db7c36bb 100644 --- a/openbox/actions/maximize.c +++ b/openbox/actions/maximize.c @@ -1,66 +1,140 @@ #include "openbox/actions.h" #include "openbox/client.h" +/* These match the values for client_maximize */ +typedef enum { + BOTH = 0, + HORZ = 1, + VERT = 2 +} MaxDirection; + typedef struct { - gboolean vertical; - gboolean horizontal; + MaxDirection dir; } 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 gpointer setup_func(xmlNodePtr node); +static void free_func(gpointer o); +static gboolean run_func_on(ObActionsData *data, gpointer options); +static gboolean run_func_off(ObActionsData *data, gpointer options); +static gboolean run_func_toggle(ObActionsData *data, gpointer options); +/* 3.4-compatibility */ +static gpointer setup_both_func(xmlNodePtr node); +static gpointer setup_horz_func(xmlNodePtr node); +static gpointer setup_vert_func(xmlNodePtr node); -void action_maximize_startup() +void action_maximize_startup(void) { - actions_register("Maximize", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("Maximize", setup_func, free_func, run_func_on); + actions_register("Unmaximize", setup_func, free_func, run_func_off); + actions_register("ToggleMaximize", setup_func, free_func, run_func_toggle); + /* 3.4-compatibility */ + actions_register("MaximizeFull", setup_both_func, free_func, + run_func_on); + actions_register("UnmaximizeFull", setup_both_func, free_func, + run_func_off); + actions_register("ToggleMaximizeFull", setup_both_func, free_func, + run_func_toggle); + actions_register("MaximizeHorz", setup_horz_func, free_func, + run_func_on); + actions_register("UnmaximizeHorz", setup_horz_func, free_func, + run_func_off); + actions_register("ToggleMaximizeHorz", setup_horz_func, free_func, + run_func_toggle); + actions_register("MaximizeVert", setup_vert_func, free_func, + run_func_on); + actions_register("UnmaximizeVert", setup_vert_func, free_func, + run_func_off); + actions_register("ToggleMaximizeVert", setup_vert_func, free_func, + run_func_toggle); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; - o = g_new0(Options, 1); - o->vertical = TRUE; - o->horizontal = TRUE; + o = g_slice_new0(Options); + o->dir = BOTH; + + if ((n = obt_xml_find_node(node, "direction"))) { + gchar *s = obt_xml_node_string(n); + if (!g_ascii_strcasecmp(s, "vertical") || + !g_ascii_strcasecmp(s, "vert")) + o->dir = VERT; + else if (!g_ascii_strcasecmp(s, "horizontal") || + !g_ascii_strcasecmp(s, "horz")) + o->dir = HORZ; + g_free(s); + } - if ((n = parse_find_node("vertical", node))) - o->vertical = parse_bool(doc, n); - if ((n = parse_find_node("horizontal", node))) - o->horizontal = parse_bool(doc, n); return o; } -static void free_func(gpointer options) +static void free_func(gpointer o) { - Options *o = options; - - g_free(o); + g_slice_free(Options, o); } /* Always return FALSE because its not interactive */ -static gboolean run_func(ObActionsData *data, gpointer options) +static gboolean run_func_on(ObActionsData *data, gpointer options) { Options *o = options; - if (data->client) { actions_client_move(data, TRUE); + client_maximize(data->client, TRUE, o->dir); + actions_client_move(data, FALSE); + } + return FALSE; +} - if (o->horizontal && !o->vertical) - client_maximize(data->client, !data->client->max_horz, 1); - else if (!o->horizontal && o->vertical) - client_maximize(data->client, !data->client->max_vert, 2); - else if (o->horizontal && o->vertical) - client_maximize(data->client, - !data->client->max_horz || !data->client->max_vert, - 0); - +/* Always return FALSE because its not interactive */ +static gboolean run_func_off(ObActionsData *data, gpointer options) +{ + Options *o = options; + if (data->client) { + actions_client_move(data, TRUE); + client_maximize(data->client, FALSE, o->dir); actions_client_move(data, FALSE); } + return FALSE; +} +/* Always return FALSE because its not interactive */ +static gboolean run_func_toggle(ObActionsData *data, gpointer options) +{ + Options *o = options; + if (data->client) { + gboolean toggle; + actions_client_move(data, TRUE); + toggle = ((o->dir == HORZ && !data->client->max_horz) || + (o->dir == VERT && !data->client->max_vert) || + (o->dir == BOTH && + !(data->client->max_horz && data->client->max_vert))); + client_maximize(data->client, toggle, o->dir); + actions_client_move(data, FALSE); + } return FALSE; } + +/* 3.4-compatibility */ +static gpointer setup_both_func(xmlNodePtr node) +{ + Options *o = g_slice_new0(Options); + o->dir = BOTH; + return o; +} + +static gpointer setup_horz_func(xmlNodePtr node) +{ + Options *o = g_slice_new0(Options); + o->dir = HORZ; + return o; +} + +static gpointer setup_vert_func(xmlNodePtr node) +{ + Options *o = g_slice_new0(Options); + o->dir = VERT; + return o; +} +