openbox/action_list_run.h \
openbox/action_parser.c \
openbox/action_parser.h \
- openbox/action_value.c \
- openbox/action_value.h \
openbox/apps_menu.c \
openbox/apps_menu.h \
openbox/client.c \
openbox/client_set.h \
openbox/config.c \
openbox/config.h \
+ openbox/config_value.c \
+ openbox/config_value.h \
openbox/debug.c \
openbox/debug.h \
openbox/dock.c \
}
}
-ObActionFilter* action_filter_new(const gchar *key, struct _ObActionValue *v)
+ObActionFilter* action_filter_new(const gchar *key, struct _ObConfigValue *v)
{
ObActionFilterDefinition *def;
ObActionFilter *filter;
#include <glib.h>
struct _ObActionListRun;
-struct _ObActionValue;
+struct _ObConfigValue;
struct _ObClient;
struct _ObClientSet;
typedef enum _ObActionFilterDefault ObActionFilterDefault;
typedef gpointer (*ObActionFilterSetupFunc)(gboolean invert,
- struct _ObActionValue *v);
+ struct _ObConfigValue *v);
typedef void (*ObActionFilterDestroyFunc)(gpointer data);
typedef struct _ObClientSet* (*ObActionFilterFunc)(
gboolean invert, const struct _ObActionListRun *run, gpointer data);
ObActionFilterDestroyFunc destroy,
ObActionFilterFunc set);
-ObActionFilter* action_filter_new(const gchar *key, struct _ObActionValue *v);
+ObActionFilter* action_filter_new(const gchar *key, struct _ObConfigValue *v);
void action_filter_ref(ObActionFilter *f);
void action_filter_unref(ObActionFilter *f);
#include "action_list.h"
#include "action.h"
#include "action_filter.h"
-#include "action_value.h"
#include <glib.h>
#include "action.h"
#include "action_filter.h"
#include "action_list.h"
-#include "action_value.h"
+#include "config_value.h"
#include "gettext.h"
#ifdef HAVE_STRING_H
struct _ObActionList;
struct _ObActionListTest;
-struct _ObActionValue;
#define SKIP " \t"
#define IDENTIFIER_FIRST G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "-_"
struct _ObActionList* parse_action(ObActionParser *p, gboolean *e);
struct _ObActionList* parse_filter(ObActionParser *p, gboolean *e);
struct _ObActionListTest* parse_filter_test(ObActionParser *p, gboolean *e);
-struct _ObActionValue* parse_value(ObActionParser *p,
+struct _ObConfigValue* parse_value(ObActionParser *p,
gboolean allow_actions,
gboolean *e);
gchar* parse_string(ObActionParser *p, guchar end, gboolean *e);
/* read the action's name */
name = g_strdup(p->scan->value.v_string);
config = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
- (GDestroyNotify)action_value_unref);
+ (GDestroyNotify)config_value_unref);
/* read the action's options key:value pairs */
t = g_scanner_peek_next_token(p->scan);
}
else {
gchar *key;
- ObActionValue *value;
+ ObConfigValue *value;
g_scanner_get_next_token(p->scan); /* eat the key */
t = g_scanner_peek_next_token(p->scan); /* check for ':' */
{
GTokenType t;
gchar *key;
- ObActionValue *value;
+ ObConfigValue *value;
gboolean and;
ObActionFilter *filter;
ObActionListTest *next;
/* don't allow any errors (but value can be null if not present) */
if (*e) {
g_free(key);
- action_value_unref(value);
+ config_value_unref(value);
return NULL;
}
}
g_free(key);
- action_value_unref(value);
+ config_value_unref(value);
if (!filter)
return NULL;
}
}
-ObActionValue* parse_value(ObActionParser *p,
+ObConfigValue* parse_value(ObActionParser *p,
gboolean allow_actions,
gboolean *e)
{
GTokenType t;
- ObActionValue *v;
+ ObConfigValue *v;
v = NULL;
t = g_scanner_get_next_token(p->scan);
if (t == G_TOKEN_IDENTIFIER) {
- v = action_value_new_string(p->scan->value.v_string);
+ v = config_value_new_string(p->scan->value.v_string);
}
else if (t == '"')
- v = action_value_new_string(parse_string(p, '"', e));
+ v = config_value_new_string(parse_string(p, '"', e));
else if (t == '(')
- v = action_value_new_string(parse_string(p, ')', e));
+ v = config_value_new_string(parse_string(p, ')', e));
else if (t == '{' && allow_actions) {
ObActionList *l = parse_list(p, '}', e);
- if (l) v = action_value_new_action_list(l);
+ if (l) v = config_value_new_action_list(l);
}
else
parse_error(p, G_TOKEN_NONE, _("Expected an option value"), e);
+++ /dev/null
-/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
-
- action_value.c for the Openbox window manager
- Copyright (c) 2011 Dana Jansens
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- See the COPYING file for a copy of the GNU General Public License.
-*/
-
-#include "action_value.h"
-#include "action_list.h"
-#include "geom.h"
-
-#include "stdlib.h"
-
-struct _ObActionValue {
- gint ref;
- enum {
- OB_AV_STRING,
- OB_AV_ACTIONLIST
- } type;
- union {
- gchar *string;
- gboolean boolean;
- guint integer;
- ObActionList *actions;
- } v;
-};
-
-ObActionValue* action_value_new_string(const gchar *s)
-{
- return action_value_new_string_steal(g_strdup(s));
-}
-
-ObActionValue* action_value_new_string_steal(gchar *s)
-{
- ObActionValue *v = g_slice_new(ObActionValue);
- v->ref = 1;
- v->type = OB_AV_STRING;
- v->v.string = s;
- return v;
-}
-
-ObActionValue* action_value_new_action_list(ObActionList *al)
-{
- ObActionValue *v = g_slice_new(ObActionValue);
- v->ref = 1;
- v->type = OB_AV_ACTIONLIST;
- v->v.actions = al;
- action_list_ref(al);
- return v;
-}
-
-void action_value_ref(ObActionValue *v)
-{
- ++v->ref;
-}
-
-void action_value_unref(ObActionValue *v)
-{
- if (v && --v->ref < 1) {
- switch (v->type) {
- case OB_AV_STRING:
- g_free(v->v.string);
- break;
- case OB_AV_ACTIONLIST:
- action_list_unref(v->v.actions);
- break;
- }
- g_slice_free(ObActionValue, v);
- }
-}
-
-gboolean action_value_is_string(ObActionValue *v)
-{
- return v->type == OB_AV_STRING;
-}
-
-gboolean action_value_is_action_list(ObActionValue *v)
-{
- return v->type == OB_AV_ACTIONLIST;
-}
-
-const gchar* action_value_string(ObActionValue *v)
-{
- g_return_val_if_fail(v->type == OB_AV_STRING, NULL);
- return v->v.string;
-}
-
-gboolean action_value_bool(ObActionValue *v)
-{
- g_return_val_if_fail(v->type == OB_AV_STRING, FALSE);
- if (g_strcasecmp(v->v.string, "true") == 0 ||
- g_strcasecmp(v->v.string, "yes") == 0)
- return TRUE;
- else
- return FALSE;
-}
-
-gint action_value_int(ObActionValue *v)
-{
- gchar *s;
-
- g_return_val_if_fail(v->type == OB_AV_STRING, 0);
- s = v->v.string;
- return strtol(s, &s, 10);
-}
-
-void action_value_fraction(ObActionValue *v, gint *numer, gint *denom)
-{
- gchar *s;
-
- *numer = *denom = 0;
-
- g_return_if_fail(v->type == OB_AV_STRING);
- s = v->v.string;
-
- *numer = strtol(s, &s, 10);
- if (*s == '%')
- *denom = 100;
- else if (*s == '/')
- *denom = atoi(s+1);
-}
-
-void action_value_gravity_coord(ObActionValue *v, GravityCoord *c)
-{
- gchar *s;
-
- c->center = FALSE;
- c->pos = 0;
- c->denom = 0;
-
- g_return_if_fail(v->type == OB_AV_STRING);
- s = v->v.string;
-
- if (!g_ascii_strcasecmp(s, "center"))
- c->center = TRUE;
- else {
- if (s[0] == '-')
- c->opposite = TRUE;
- if (s[0] == '-' || s[0] == '+')
- ++s;
-
- c->pos = strtol(s, &s, 10);
-
- if (*s == '%')
- c->denom = 100;
- else if (*s == '/')
- c->denom = atoi(s+1);
- }
-}
-
-ObActionList* action_value_action_list(ObActionValue *v)
-{
- g_return_val_if_fail(v->type == OB_AV_ACTIONLIST, NULL);
- return v->v.actions;
-}
+++ /dev/null
-/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
-
- action_value.h for the Openbox window manager
- Copyright (c) 2011 Dana Jansens
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- See the COPYING file for a copy of the GNU General Public License.
-*/
-
-#include <glib.h>
-
-struct _GravityCoord;
-struct _ObActionList;
-
-typedef struct _ObActionValue ObActionValue;
-
-/*! Creates a new value by making a copy of the given string. */
-ObActionValue* action_value_new_string(const gchar *s);
-/*! Creates a new value from a string, and steals ownership of the string. It
- will be freed when then value is destroyed. */
-ObActionValue* action_value_new_string_steal(gchar *s);
-/*! Creates a new value with a given actions list. */
-ObActionValue* action_value_new_action_list(struct _ObActionList *al);
-
-void action_value_ref(ObActionValue *v);
-void action_value_unref(ObActionValue *v);
-
-gboolean action_value_is_string(ObActionValue *v);
-gboolean action_value_is_action_list(ObActionValue *v);
-
-const gchar* action_value_string(ObActionValue *v);
-gboolean action_value_bool(ObActionValue *v);
-gint action_value_int(ObActionValue *v);
-void action_value_fraction(ObActionValue *v, gint *numer, gint *denom);
-void action_value_gravity_coord(ObActionValue *v, struct _GravityCoord *c);
-struct _ObActionList* action_value_action_list(ObActionValue *v);
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client_set.h"
#include "openbox/screen.h"
#include <glib.h>
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
v = g_hash_table_lookup(config, "where");
- if (v && action_value_is_string(v)) {
- const gchar *s = action_value_string(v);
+ if (v && config_value_is_string(v)) {
+ const gchar *s = config_value_string(v);
if (!g_ascii_strcasecmp(s, "last"))
o->current = FALSE;
else if (!g_ascii_strcasecmp(s, "current"))
#include "openbox/action_list.h"
#include "openbox/action_list_run.h"
#include "openbox/action_parser.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client_set.h"
#include "openbox/stacking.h"
#include "openbox/window.h"
ObActionICancelFunc *cancel,
ObActionIPostFunc *post)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_LIST;
v = g_hash_table_lookup(config, "linear");
- if (v && action_value_is_string(v))
- o->linear = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->linear = config_value_bool(v);
v = g_hash_table_lookup(config, "dialog");
- if (v && action_value_is_string(v)) {
- const gchar *s = action_value_string(v);
+ if (v && config_value_is_string(v)) {
+ const gchar *s = config_value_string(v);
if (g_strcasecmp(s, "none") == 0)
o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_NONE;
else if (g_strcasecmp(s, "no") == 0)
o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_ICONS;
}
v = g_hash_table_lookup(config, "bar");
- if (v && action_value_is_string(v))
- o->bar = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->bar = config_value_bool(v);
v = g_hash_table_lookup(config, "raise");
- if (v && action_value_is_string(v))
- o->raise = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->raise = config_value_bool(v);
v = g_hash_table_lookup(config, "panels");
- if (v && action_value_is_string(v))
- o->dock_windows = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->dock_windows = config_value_bool(v);
v = g_hash_table_lookup(config, "desktop");
- if (v && action_value_is_string(v))
- o->desktop_windows = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->desktop_windows = config_value_bool(v);
v = g_hash_table_lookup(config, "finalactions");
- if (v && action_value_is_action_list(v)) {
- o->actions = action_value_action_list(v);
+ if (v && config_value_is_action_list(v)) {
+ o->actions = config_value_action_list(v);
action_list_ref(o->actions);
}
else {
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client_set.h"
#include <glib.h>
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
v = g_hash_table_lookup(config, "string");
- if (v && action_value_is_string(v))
- o->str = g_strdup(action_value_string(v));
+ if (v && config_value_is_string(v))
+ o->str = g_strdup(config_value_string(v));
return o;
}
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/screen.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
ObActionICancelFunc *cancel,
ObActionIPostFunc *post)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
o->u.rel.wrap = TRUE;
v = g_hash_table_lookup(config, "to");
- if (v && action_value_is_string(v)) {
- const gchar *s = action_value_string(v);
+ if (v && config_value_is_string(v)) {
+ const gchar *s = config_value_string(v);
if (!g_ascii_strcasecmp(s, "last"))
o->type = LAST;
else if (!g_ascii_strcasecmp(s, "current"))
}
v = g_hash_table_lookup(config, "wrap");
- if (v && action_value_is_string(v))
- o->u.rel.wrap = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->u.rel.wrap = config_value_bool(v);
return o;
}
ObActionICancelFunc *cancel,
ObActionIPostFunc *post)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = setup_func(config, pre, input, cancel, post);
o->follow = TRUE;
v = g_hash_table_lookup(config, "follow");
- if (v && action_value_is_string(v))
- o->follow = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->follow = config_value_bool(v);
if (o->type == RELATIVE && o->follow) {
o->interactive = TRUE;
#include "openbox/action_list.h"
#include "openbox/action_list_run.h"
#include "openbox/action_parser.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client_set.h"
#include "openbox/event.h"
#include "openbox/stacking.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
o->bar = TRUE;
v = g_hash_table_lookup(config, "dialog");
- if (v && action_value_is_string(v))
- o->dialog = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->dialog = config_value_bool(v);
v = g_hash_table_lookup(config, "bar");
- if (v && action_value_is_string(v))
- o->bar = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->bar = config_value_bool(v);
v = g_hash_table_lookup(config, "raise");
- if (v && action_value_is_string(v))
- o->raise = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->raise = config_value_bool(v);
v = g_hash_table_lookup(config, "panels");
- if (v && action_value_is_string(v))
- o->dock_windows = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->dock_windows = config_value_bool(v);
v = g_hash_table_lookup(config, "desktop");
- if (v && action_value_is_string(v))
- o->desktop_windows = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->desktop_windows = config_value_bool(v);
v = g_hash_table_lookup(config, "direction");
- if (v && action_value_is_string(v)) {
- const gchar *s = action_value_string(v);
+ if (v && config_value_is_string(v)) {
+ const gchar *s = config_value_string(v);
if (!g_ascii_strcasecmp(s, "north") ||
!g_ascii_strcasecmp(s, "up"))
o->direction = OB_DIRECTION_NORTH;
}
v = g_hash_table_lookup(config, "finalactions");
- if (v && action_value_is_action_list(v)) {
- o->actions = action_value_action_list(v);
+ if (v && config_value_is_action_list(v)) {
+ o->actions = config_value_action_list(v);
action_list_ref(o->actions);
}
else {
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
#include "openbox/event.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
v = g_hash_table_lookup(config, "command");
- if (v && action_value_is_string(v))
- o->cmd = obt_paths_expand_tilde(action_value_string(v));
+ if (v && config_value_is_string(v))
+ o->cmd = obt_paths_expand_tilde(config_value_string(v));
v = g_hash_table_lookup(config, "prompt");
- if (v && action_value_is_string(v))
- o->prompt = g_strdup(action_value_string(v));
+ if (v && config_value_is_string(v))
+ o->prompt = g_strdup(config_value_string(v));
v = g_hash_table_lookup(config, "startupnotify");
- if (v && action_value_is_string(v) && action_value_bool(v)) {
+ if (v && config_value_is_string(v) && config_value_bool(v)) {
o->sn = TRUE;
v = g_hash_table_lookup(config, "name");
- if (v && action_value_is_string(v))
- o->sn_name = g_strdup(action_value_string(v));
+ if (v && config_value_is_string(v))
+ o->sn_name = g_strdup(config_value_string(v));
v = g_hash_table_lookup(config, "icon");
- if (v && action_value_is_string(v))
- o->sn_icon = g_strdup(action_value_string(v));
+ if (v && config_value_is_string(v))
+ o->sn_icon = g_strdup(config_value_string(v));
v = g_hash_table_lookup(config, "wmclass");
- if (v && action_value_is_string(v))
- o->sn_wmclass = g_strdup(action_value_string(v));
+ if (v && config_value_is_string(v))
+ o->sn_wmclass = g_strdup(config_value_string(v));
}
return o;
}
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client_set.h"
#include "openbox/openbox.h"
#include "openbox/prompt.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
o->prompt = TRUE;
v = g_hash_table_lookup(config, "prompt");
- if (v && action_value_is_string(v))
- o->prompt = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->prompt = config_value_bool(v);
return o;
}
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/event.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
o->stop_int = TRUE;
v = g_hash_table_lookup(config, "here");
- if (v && action_value_is_string(v))
- o->here = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->here = config_value_bool(v);
v = g_hash_table_lookup(config, "stopInteractive");
- if (v && action_value_is_string(v))
- o->stop_int = action_value_bool(v);
+ if (v && config_value_is_string(v))
+ o->stop_int = config_value_bool(v);
return o;
}
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/misc.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
o->shrink = FALSE;
v = g_hash_table_lookup(config, "direction");
- if (v && action_value_is_string(v)) {
- const gchar *s = action_value_string(v);
+ if (v && config_value_is_string(v)) {
+ const gchar *s = config_value_string(v);
if (!g_ascii_strcasecmp(s, "north") ||
!g_ascii_strcasecmp(s, "up"))
o->dir = OB_DIRECTION_NORTH;
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
static gpointer setup_func_send(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
v = g_hash_table_lookup(config, "layer");
- if (v && action_value_is_string(v)) {
- const gchar *s = action_value_string(v);
+ if (v && config_value_is_string(v)) {
+ const gchar *s = config_value_string(v);
if (!g_ascii_strcasecmp(s, "above") ||
!g_ascii_strcasecmp(s, "top"))
o->layer = 1;
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
o->dir = BOTH;
v = g_hash_table_lookup(config, "dir");
- if (v && action_value_is_string(v)) {
- const gchar *s = action_value_string(v);
+ if (v && config_value_is_string(v)) {
+ const gchar *s = config_value_string(v);
if (!g_ascii_strcasecmp(s, "vertical") ||
!g_ascii_strcasecmp(s, "vert"))
o->dir = VERT;
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
#include "openbox/screen.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
v = g_hash_table_lookup(config, "x");
- if (v && action_value_is_string(v))
- action_value_fraction(v, &o->x, &o->x_denom);
+ if (v && config_value_is_string(v))
+ config_value_fraction(v, &o->x, &o->x_denom);
v = g_hash_table_lookup(config, "y");
- if (v && action_value_is_string(v))
- action_value_fraction(v, &o->y, &o->y_denom);
+ if (v && config_value_is_string(v))
+ config_value_fraction(v, &o->y, &o->y_denom);
return o;
}
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
#include "openbox/screen.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
o->monitor = CURRENT_MONITOR;
v = g_hash_table_lookup(config, "x");
- if (v && action_value_is_string(v))
- action_value_gravity_coord(v, &o->x);
+ if (v && config_value_is_string(v))
+ config_value_gravity_coord(v, &o->x);
v = g_hash_table_lookup(config, "y");
- if (v && action_value_is_string(v))
- action_value_gravity_coord(v, &o->y);
+ if (v && config_value_is_string(v))
+ config_value_gravity_coord(v, &o->y);
v = g_hash_table_lookup(config, "width");
- if (v && action_value_is_string(v))
- if (g_ascii_strcasecmp(action_value_string(v), "current") != 0)
- action_value_fraction(v, &o->w, &o->w_denom);
+ if (v && config_value_is_string(v))
+ if (g_ascii_strcasecmp(config_value_string(v), "current") != 0)
+ config_value_fraction(v, &o->w, &o->w_denom);
v = g_hash_table_lookup(config, "height");
- if (v && action_value_is_string(v))
- if (g_ascii_strcasecmp(action_value_string(v), "current") != 0)
- action_value_fraction(v, &o->h, &o->h_denom);
+ if (v && config_value_is_string(v))
+ if (g_ascii_strcasecmp(config_value_string(v), "current") != 0)
+ config_value_fraction(v, &o->h, &o->h_denom);
v = g_hash_table_lookup(config, "monitor");
- if (v && action_value_is_string(v)) {
- const gchar *s = action_value_string(v);
+ if (v && config_value_is_string(v)) {
+ const gchar *s = config_value_string(v);
if (g_ascii_strcasecmp(s, "current") != 0) {
if (!g_ascii_strcasecmp(s, "all"))
o->monitor = ALL_MONITORS;
else if(!g_ascii_strcasecmp(s, "prev"))
o->monitor = PREV_MONITOR;
else
- o->monitor = action_value_int(v) - 1;
+ o->monitor = config_value_int(v) - 1;
}
}
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/misc.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
o->dir = OB_DIRECTION_NORTH;
v = g_hash_table_lookup(config, "direction");
- if (v && action_value_is_string(v)) {
- const gchar *s = action_value_string(v);
+ if (v && config_value_is_string(v)) {
+ const gchar *s = config_value_string(v);
if (!g_ascii_strcasecmp(s, "north") ||
!g_ascii_strcasecmp(s, "up"))
o->dir = OB_DIRECTION_NORTH;
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/moveresize.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
v = g_hash_table_lookup(config, "edge");
- if (v && action_value_is_string(v)) {
- const gchar *s = action_value_string(v);
+ if (v && config_value_is_string(v)) {
+ const gchar *s = config_value_string(v);
o->corner_specified = TRUE;
if (!g_ascii_strcasecmp(s, "top"))
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client.h"
#include "openbox/client_set.h"
#include "openbox/screen.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
v = g_hash_table_lookup(config, "left");
- if (v && action_value_is_string(v))
- action_value_fraction(v, &o->left, &o->left_denom);
+ if (v && config_value_is_string(v))
+ config_value_fraction(v, &o->left, &o->left_denom);
v = g_hash_table_lookup(config, "right");
- if (v && action_value_is_string(v))
- action_value_fraction(v, &o->right, &o->right_denom);
+ if (v && config_value_is_string(v))
+ config_value_fraction(v, &o->right, &o->right_denom);
v = g_hash_table_lookup(config, "top");
- if (v && action_value_is_string(v))
- action_value_fraction(v, &o->top, &o->top_denom);
+ if (v && config_value_is_string(v))
+ config_value_fraction(v, &o->top, &o->top_denom);
v = g_hash_table_lookup(config, "bottom");
- if (v && action_value_is_string(v))
- action_value_fraction(v, &o->bottom, &o->bottom_denom);
+ if (v && config_value_is_string(v))
+ config_value_fraction(v, &o->bottom, &o->bottom_denom);
return o;
}
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client_set.h"
#include "openbox/openbox.h"
#include "obt/paths.h"
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
v = g_hash_table_lookup(config, "command");
- if (v && action_value_is_string(v))
- o->cmd = obt_paths_expand_tilde(action_value_string(v));
+ if (v && config_value_is_string(v))
+ o->cmd = obt_paths_expand_tilde(config_value_string(v));
return o;
}
#include "openbox/action.h"
#include "openbox/action_list_run.h"
-#include "openbox/action_value.h"
+#include "openbox/config_value.h"
#include "openbox/client_set.h"
#include "openbox/menu.h"
#include <glib.h>
static gpointer setup_func(GHashTable *config)
{
- ObActionValue *v;
+ ObConfigValue *v;
Options *o;
o = g_slice_new0(Options);
v = g_hash_table_lookup(config, "menu");
- if (v && action_value_is_string(v))
- o->name = g_strdup(action_value_string(v));
+ if (v && config_value_is_string(v))
+ o->name = g_strdup(config_value_string(v));
return o;
}
--- /dev/null
+/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
+
+ config_value.c for the Openbox window manager
+ Copyright (c) 2011 Dana Jansens
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ See the COPYING file for a copy of the GNU General Public License.
+*/
+
+#include "config_value.h"
+#include "action_list.h"
+#include "geom.h"
+
+#include "stdlib.h"
+
+struct _ObConfigValue {
+ gint ref;
+ enum {
+ OB_CV_STRING,
+ OB_CV_LIST,
+ OB_CV_ACTION_LIST
+ } type;
+ union {
+ gchar *string;
+ GList *list;
+ ObActionList *actions;
+ } v;
+};
+
+void config_value_ref(ObConfigValue *v)
+{
+ ++v->ref;
+}
+
+void config_value_unref(ObConfigValue *v)
+{
+ if (v && --v->ref < 1) {
+ switch (v->type) {
+ case OB_CV_STRING:
+ g_free(v->v.string);
+ break;
+ case OB_CV_LIST: {
+ GList *it;
+ for (it = v->v.list; it; it = g_list_next(it))
+ config_value_unref(it->data);
+ g_list_free(v->v.list);
+ break;
+ }
+ case OB_CV_ACTION_LIST:
+ action_list_unref(v->v.actions);
+ break;
+ }
+ g_slice_free(ObConfigValue, v);
+ }
+}
+
+/*************************** describer functions ***************************/
+
+gboolean config_value_is_string(const ObConfigValue *v)
+{
+ g_return_val_if_fail(v != NULL, FALSE);
+ return v->type == OB_CV_STRING;
+}
+
+gboolean config_value_is_list(const ObConfigValue *v)
+{
+ g_return_val_if_fail(v != NULL, FALSE);
+ return v->type == OB_CV_LIST;
+}
+
+gboolean config_value_is_action_list(const ObConfigValue *v)
+{
+ g_return_val_if_fail(v != NULL, FALSE);
+ return v->type == OB_CV_ACTION_LIST;
+}
+
+/**************************** pointer functions ****************************/
+
+void config_value_copy_ptr(ObConfigValue *v,
+ ObConfigValueDataType type,
+ ObConfigValueDataPtr *p,
+ const ObConfigValueEnum e[])
+{
+ switch (type) {
+ case OB_CONFIG_VALUE_STRING:
+ *p->string = config_value_string(v);
+ break;
+ case OB_CONFIG_VALUE_BOOLEAN:
+ *p->boolean = config_value_bool(v);
+ break;
+ case OB_CONFIG_VALUE_INTEGER:
+ *p->integer = config_value_int(v);
+ break;
+ case OB_CONFIG_VALUE_ENUM:
+ *p->enumeration = config_value_enum(v, e);
+ break;
+ case OB_CONFIG_VALUE_FRACTION: {
+ gint n, d;
+ config_value_fraction(v, &n, &d);
+ p->fraction->numer = n;
+ p->fraction->denom = d;
+ break;
+ }
+ case OB_CONFIG_VALUE_GRAVITY_COORD: {
+ GravityCoord c;
+ config_value_gravity_coord(v, &c);
+ *p->coord = c;
+ break;
+ }
+ case OB_CONFIG_VALUE_LIST:
+ *p->list = config_value_list(v);
+ break;
+ case OB_CONFIG_VALUE_ACTIONLIST:
+ *p->actions = config_value_action_list(v);
+ break;
+ case NUM_OB_CONFIG_VALUE_TYPES:
+ default:
+ g_assert_not_reached();
+ }
+}
+
+
+/***************************** getter functions ****************************/
+
+const gchar* config_value_string(ObConfigValue *v)
+{
+ g_return_val_if_fail(v != NULL, NULL);
+ g_return_val_if_fail(config_value_is_string(v), NULL);
+ return v->v.string;
+}
+gboolean config_value_bool(ObConfigValue *v)
+{
+ g_return_val_if_fail(v != NULL, FALSE);
+ g_return_val_if_fail(config_value_is_string(v), FALSE);
+ return (g_strcasecmp(v->v.string, "true") == 0 ||
+ g_strcasecmp(v->v.string, "yes") == 0);
+}
+guint config_value_int(ObConfigValue *v)
+{
+ gchar *s;
+ g_return_val_if_fail(v != NULL, FALSE);
+ g_return_val_if_fail(config_value_is_string(v), FALSE);
+ s = v->v.string;
+ return strtol(s, &s, 10);
+}
+guint config_value_enum(ObConfigValue *v, const ObConfigValueEnum choices[])
+{
+ const ObConfigValueEnum *e;
+
+ g_return_val_if_fail(v != NULL, (guint)-1);
+ g_return_val_if_fail(config_value_is_string(v), (guint)-1);
+ g_return_val_if_fail(choices != NULL, (guint)-1);
+
+ for (e = choices; e->name; ++e)
+ if (g_strcasecmp(v->v.string, e->name) == 0)
+ return e->value;
+ return (guint)-1;
+}
+void config_value_fraction(ObConfigValue *v, gint *numer, gint *denom)
+{
+ gchar *s;
+
+ *numer = *denom = 0;
+
+ g_return_if_fail(v != NULL);
+ g_return_if_fail(config_value_is_string(v));
+
+ s = v->v.string;
+ *numer = strtol(s, &s, 10);
+ if (*s == '%')
+ *denom = 100;
+ else if (*s == '/')
+ *denom = atoi(s+1);
+ else
+ *denom = 0;
+}
+void config_value_gravity_coord(ObConfigValue *v, GravityCoord *c)
+{
+ gchar *s;
+
+ c->center = FALSE;
+ c->pos = 0;
+ c->denom = 0;
+
+ g_return_if_fail(v != NULL);
+ g_return_if_fail(config_value_is_string(v));
+
+ s = v->v.string;
+ if (!g_ascii_strcasecmp(s, "center"))
+ c->center = TRUE;
+ else {
+ if (s[0] == '-')
+ c->opposite = TRUE;
+ if (s[0] == '-' || s[0] == '+')
+ ++s;
+
+ c->pos = strtol(s, &s, 10);
+
+ if (*s == '%')
+ c->denom = 100;
+ else if (*s == '/')
+ c->denom = atoi(s+1);
+ }
+}
+GList* config_value_list(ObConfigValue *v)
+{
+ g_return_val_if_fail(v != NULL, NULL);
+ g_return_val_if_fail(config_value_is_list(v), NULL);
+ return v->v.list;
+}
+ObActionList* config_value_action_list(ObConfigValue *v)
+{
+ g_return_val_if_fail(v != NULL, NULL);
+ g_return_val_if_fail(config_value_is_action_list(v), NULL);
+ return v->v.actions;
+}
+
+/****************************** constructors ******************************/
+
+ObConfigValue* config_value_new_string(const gchar *s)
+{
+ g_return_val_if_fail(s != NULL, NULL);
+ return config_value_new_string_steal(g_strdup(s));
+}
+
+ObConfigValue* config_value_new_string_steal(gchar *s)
+{
+ ObConfigValue *v;
+ g_return_val_if_fail(s != NULL, NULL);
+ v = g_slice_new(ObConfigValue);
+ v->ref = 1;
+ v->type = OB_CV_STRING;
+ v->v.string = s;
+ return v;
+}
+
+ObConfigValue* config_value_new_list(GList *list)
+{
+ GList *c = g_list_copy(list);
+ GList *it;
+
+ for (it = c; it; it = g_list_next(it))
+ config_value_ref(it->data);
+ return config_value_new_list_steal(c);
+}
+
+ObConfigValue* config_value_new_list_steal(GList *list)
+{
+ ObConfigValue *v = g_slice_new(ObConfigValue);
+ v->ref = 1;
+ v->type = OB_CV_LIST;
+ v->v.list = list;
+ return v;
+}
+
+ObConfigValue* config_value_new_action_list(ObActionList *al)
+{
+ ObConfigValue *v = g_slice_new(ObConfigValue);
+ v->ref = 1;
+ v->type = OB_CV_ACTION_LIST;
+ v->v.actions = al;
+ action_list_ref(al);
+ return v;
+}
--- /dev/null
+/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
+
+ config_value.h for the Openbox window manager
+ Copyright (c) 2011 Dana Jansens
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ See the COPYING file for a copy of the GNU General Public License.
+*/
+
+#include "geom.h"
+
+#include <glib.h>
+
+struct _GravityCoord;
+struct _ObActionList;
+
+typedef struct _ObConfigValue ObConfigValue;
+typedef struct _ObConfigValueEnum ObConfigValueEnum;
+
+struct _ObConfigValueEnum {
+ const gchar *name;
+ guint value;
+};
+
+typedef enum {
+ OB_CONFIG_VALUE_STRING,
+ OB_CONFIG_VALUE_BOOLEAN,
+ OB_CONFIG_VALUE_ENUM,
+ OB_CONFIG_VALUE_INTEGER,
+ OB_CONFIG_VALUE_FRACTION,
+ OB_CONFIG_VALUE_GRAVITY_COORD,
+ OB_CONFIG_VALUE_LIST,
+ OB_CONFIG_VALUE_ACTIONLIST,
+ NUM_OB_CONFIG_VALUE_TYPES
+} ObConfigValueDataType;
+
+/*! This holds a pointer to one of the possible types in ObConfigValueType. */
+typedef union {
+ const gpointer *pointer; /*!< Generic pointer */
+ const gchar **string;
+ gboolean *boolean;
+ guint *integer;
+ guint *enumeration;
+ struct {
+ guint numer;
+ guint denom;
+ } *fraction;
+ GravityCoord *coord;
+ const GList **list; /*!< A list of ObConfigValue objects */
+ struct _ObActionList **actions;
+} ObConfigValueDataPtr;
+
+void config_value_ref(ObConfigValue *v);
+void config_value_unref(ObConfigValue *v);
+
+/*! Creates a new value by making a copy of the given string. */
+ObConfigValue* config_value_new_string(const gchar *s);
+/*! Creates a new value from a string, and steals ownership of the string. It
+ will be freed when then value is destroyed. */
+ObConfigValue* config_value_new_string_steal(gchar *s);
+
+/*! Creates a config value which holds a list of other values
+ This function copies the list and adds a refcount to the values within. */
+ObConfigValue* config_value_new_list(GList *list);
+/*! Creates a config value which holds a list of other values.
+ This function steals ownership the list and the values within. */
+ObConfigValue* config_value_new_list_steal(GList *list);
+ObConfigValue* config_value_new_action_list(struct _ObActionList *al);
+
+gboolean config_value_is_string(const ObConfigValue *v);
+gboolean config_value_is_list(const ObConfigValue *v);
+gboolean config_value_is_action_list(const ObConfigValue *v);
+
+/*! Copies the data inside @v to the destination that the pointer @p is
+ pointing to. */
+void config_value_copy_ptr(ObConfigValue *v,
+ ObConfigValueDataType type,
+ ObConfigValueDataPtr *p,
+ const ObConfigValueEnum e[]);
+
+/* These ones are valid on a string value */
+
+const gchar* config_value_string(ObConfigValue *v);
+gboolean config_value_bool(ObConfigValue *v);
+guint config_value_int(ObConfigValue *v);
+/*! returns (guint)-1 if an error */
+guint config_value_enum(ObConfigValue *v, const ObConfigValueEnum e[]);
+void config_value_fraction(ObConfigValue *v, gint *numer, gint *denom);
+void config_value_gravity_coord(ObConfigValue *v, struct _GravityCoord *c);
+
+/* These ones are valid on a list value */
+
+GList* config_value_list(ObConfigValue *v);
+
+/* These ones are value on a action list value */
+
+struct _ObActionList* config_value_action_list(ObConfigValue *v);