From ff04e2c9a98325e4ae13958ef63b455df303abc9 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Fri, 9 Jun 2006 14:14:17 +0000 Subject: [PATCH] add the rest of the possible states to per app settings, and fix some mem leaks in the code that _set_ the per app list --- openbox/client.c | 48 +++++++++++++++++++++++++------- openbox/client.h | 18 ++++++++---- openbox/config.c | 72 ++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 110 insertions(+), 28 deletions(-) diff --git a/openbox/client.c b/openbox/client.c index cfcc7da2..a8db51d3 100644 --- a/openbox/client.c +++ b/openbox/client.c @@ -215,7 +215,10 @@ static ObAppSettings *get_settings(ObClient *client) if (!strcmp(app->name, client->name)) { ob_debug("Window matching: %s\n", app->name); - if (!app->role || !strcmp(app->role, client->role)) + /* Match if no role was specified in the per app setting, or if the string + * matches the beginning of the role, since apps like to set the role to + * things like browser-window-23c4b2f */ + if (!app->role || !strncmp(app->role, client->role, strlen(app->role))) return app; } @@ -317,16 +320,41 @@ void client_manage(Window window) settings = get_settings(self); if (settings) { - if (settings->shade && !settings->decor) - settings->decor = TRUE; - - client_shade(self, settings->shade); - client_set_undecorated(self, !settings->decor); - - if (settings->desktop != -1) + /* Don't worry, we won't actually both shade and undecorate the + * window when push comes to shove. */ + if (settings->shade != -1) + client_shade(self, settings->shade); + if (settings->decor != -1) + client_set_undecorated(self, !settings->decor); + if (settings->iconic != -1) + client_iconify(self, settings->iconic); + if (settings->skip_pager != -1) + client->skip_pager = !!settings->skip_pager; + if (settings->skip_taskbar != -1) + client->skip_taskbar = !!settings->skip_taskbar; + + /* 1 && -1 shouldn't be possible by the code in config.c */ + if (settings->max_vert == 1 && self->max_horz == 1) + client_maximize(self, TRUE, 0, TRUE); + else if (settings->max_vert == 0 && self->max_horz == 0) + client_maximize(self, FALSE, 0, TRUE); + else if (settings->max_vert == 1 && self->max_horz == 0) { + client_maximize(self, TRUE, 2, TRUE); + client_maximize(self, FALSE, 1, TRUE); + } else if (settings->max_vert == 0 && self->max_horz == 1) { + client_maximize(self, TRUE, 1, TRUE); + client_maximize(self, FALSE, 2, TRUE); + } + + if (settings->fullscreen != -1) + client_fullscreen(self, !!settings->fullscreen, TRUE); + + if (settings->desktop < screen_num_desktops) client_set_desktop(self, settings->desktop, FALSE); - client_set_layer(self, settings->layer); + if (settings->layer > -2 && settings->layer < 2) + client_set_layer(self, settings->layer); + } stacking_add(CLIENT_AS_WINDOW(self)); @@ -335,7 +363,7 @@ void client_manage(Window window) /* focus the new window? */ if (ob_state() != OB_STATE_STARTING && (config_focus_new || client_search_focus_parent(self)) || - (settings && settings->focus) && + (settings && settings->focus == TRUE) && /* note the check against Type_Normal/Dialog, not client_normal(self), which would also include other types. in this case we want more strict rules for focus */ diff --git a/openbox/client.h b/openbox/client.h index ab1c830c..a75c6d2b 100644 --- a/openbox/client.h +++ b/openbox/client.h @@ -274,9 +274,6 @@ struct _ObAppSettings { gchar *name; gchar *role; - gboolean decor; - gboolean shade; - gboolean focus; Point position; gboolean center_x; @@ -284,9 +281,18 @@ struct _ObAppSettings gboolean pos_given; guint desktop; - guint head; - - guint layer; + gint shade; + gint decor; + gint focus; + gint head; + gint iconic; + gint skip_pager; + gint skip_taskbar; + gint max_horz; + gint max_vert; + gint fullscreen; + + gint layer; }; extern GList *client_list; diff --git a/openbox/config.c b/openbox/config.c index 5b669685..aa903a2a 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -103,8 +103,6 @@ GSList *config_per_app_settings; Some notes: head is the screen number in a multi monitor (Xinerama) setup (starting from 0) or mouse, meaning the head the pointer is on. Default: mouse. - If decor is false and shade is true, the decor will be - set to true (otherwise we will have an invisible window). Layer can be three values, above (Always on top), below (Always on bottom) and everything else (normal behaviour). Positions can be an integer value or center, which will @@ -127,10 +125,11 @@ static void parse_per_app_settings(ObParseInst *i, xmlDocPtr doc, if (!parse_attr_string("role", app, &settings->role)) settings->role = NULL; - settings->decor = TRUE; + settings->decor = -1; if ((n = parse_find_node("decor", app->children))) settings->decor = parse_bool(doc, n); + settings->shade = -1; if ((n = parse_find_node("shade", app->children))) settings->shade = parse_bool(doc, n); @@ -138,48 +137,97 @@ static void parse_per_app_settings(ObParseInst *i, xmlDocPtr doc, settings->pos_given = FALSE; if ((n = parse_find_node("position", app->children))) { if ((c = parse_find_node("x", n->children))) { - if (!strcmp(parse_string(doc, c), "center")) { + str *s = parse_string(doc, c); + if (!strcmp(s, "center")) { settings->center_x = TRUE; x_pos_given = TRUE; } else { settings->position.x = parse_int(doc, c); x_pos_given = TRUE; } + g_free(s); } if (x_pos_given && (c = parse_find_node("y", n->children))) { - if (!strcmp(parse_string(doc, c), "center")) { + str *s = parse_string(doc, c); + if (!strcmp(s, "center")) { settings->center_y = TRUE; settings->pos_given = TRUE; } else { settings->position.y = parse_int(doc, c); settings->pos_given = TRUE; } + g_free(s); } } + settings->focus = -1; if ((n = parse_find_node("focus", app->children))) settings->focus = parse_bool(doc, n); - if ((n = parse_find_node("desktop", app->children))) - settings->desktop = parse_int(doc, n); - else - settings->desktop = -1; + if ((n = parse_find_node("desktop", app->children))) { + str *s = parse_string(doc, n); + if (!strcmp(s, "all")) + settings->desktop = DESKTOP_ALL; + else + settings->desktop = parse_int(doc, n); + g_free(s); + } else + settings->desktop = DESKTOP_ALL - 1; /* lets hope the user + * doesn't have 2^32 + * desktops */ if ((n = parse_find_node("head", app->children))) { - if (!strcmp(parse_string(doc, n), "mouse")) + str *s = parse_string(doc, n); + if (!strcmp(s, "mouse")) settings->head = -1; else settings->head = parse_int(doc, n); + g_free(s); } + settings->layer = -2; if ((n = parse_find_node("layer", app->children))) { - if (!strcmp(parse_string(doc, n), "above")) + str *s = parse_string(doc, n); + if (!strcmp(s, "above")) settings->layer = 1; - else if (!strcmp(parse_string(doc, n), "below")) + else if (!strcmp(s, "below")) settings->layer = -1; else settings->layer = 0; + g_free(s); + } + + settings->iconic = -1; + if ((n = parse_find_node("iconic", app->children))) + settings->iconic = parse_bool(doc, n); + + settings->skip_pager = -1; + if ((n = parse_find_node("skip_pager", app->children))) + settings->skip_pager = parse_bool(doc, n); + + settings->skip_taskbar = -1; + if ((n = parse_find_node("skip_taskbar", app->children))) + settings->skip_taskbar = parse_bool(doc, n); + + settings->fullscreen = -1; + if ((n = parse_find_node("fullscreen", app->children))) + settings->fullscreen = parse_bool(doc, n); + + settings->max_horz = -1; + settings->max_vert = -1; + if ((n = parse_find_node("maximized", app->children))) { + str *s = parse_string(doc, n); + if (!strcmp(s, "horizontal")) { + settings->max_horz = TRUE; + settings->max_vert = FALSE; + } else if (!strcmp(s, "vertical")) { + settings->max_horz = FALSE; + settings->max_vert = TRUE; + } else + settings->max_horz = settings->max_vert = + parse_bool(doc, n); + g_free(s); } config_per_app_settings = g_slist_append(config_per_app_settings, -- 2.45.2