summaryrefslogtreecommitdiff
path: root/openbox
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-04-05 20:27:03 +0000
committerDana Jansens <danakj@orodu.net>2003-04-05 20:27:03 +0000
commitcbbf90a718ecc6836ef7a77b9040aebb9da348b8 (patch)
treea53bcdc993f850bc0500daaebd5b1bd0b7b50ee1 /openbox
parent88f8ebada97c4c82252badeb57b7e71a2940600b (diff)
change how rc parsing will work. a=b will be parsed in any [section] and given to a separate parsing callback. no more general config infrastructure needed/
Diffstat (limited to 'openbox')
-rw-r--r--openbox/action.c35
-rw-r--r--openbox/action.h12
-rw-r--r--openbox/client.c28
-rw-r--r--openbox/client.h2
-rw-r--r--openbox/config.c237
-rw-r--r--openbox/config.h57
-rw-r--r--openbox/engine.c31
-rw-r--r--openbox/engine.h16
-rw-r--r--openbox/event.c10
-rw-r--r--openbox/focus.c10
-rw-r--r--openbox/focus.h5
-rw-r--r--openbox/openbox.c8
-rw-r--r--openbox/parse.c110
-rw-r--r--openbox/parse.h4
-rw-r--r--openbox/parse.l2
-rw-r--r--openbox/parse.y35
-rw-r--r--openbox/screen.c6
17 files changed, 156 insertions, 452 deletions
diff --git a/openbox/action.c b/openbox/action.c
index 7e0321bc..0e41e2eb 100644
--- a/openbox/action.c
+++ b/openbox/action.c
@@ -157,9 +157,16 @@ Action *action_from_string(char *name)
a = action_new(action_restart);
} else if (!g_ascii_strcasecmp(name, "exit")) {
a = action_new(action_exit);
- }
- else if (!g_ascii_strcasecmp(name, "showmenu")) {
+ } else if (!g_ascii_strcasecmp(name, "showmenu")) {
a = action_new(action_showmenu);
+ } else if (!g_ascii_strcasecmp(name, "nextwindowlinear")) {
+ a = action_new(action_cycle_windows);
+ a->data.cycle.linear = TRUE;
+ a->data.cycle.forward = TRUE;
+ } else if (!g_ascii_strcasecmp(name, "previouswindowlinear")) {
+ a = action_new(action_cycle_windows);
+ a->data.cycle.linear = TRUE;
+ a->data.cycle.forward = FALSE;
}
return a;
@@ -655,3 +662,27 @@ void action_showmenu(union ActionData *data)
{
g_message(__FUNCTION__);
}
+
+void action_cycle_windows(union ActionData *data)
+{
+ if (data->cycle.linear) {
+ if (!data->cycle.final) {
+ GList *it, *start;
+
+ start = it = g_list_find(client_list, data->cycle.c);
+ do {
+ if (data->cycle.forward) {
+ it = it->next;
+ if (it == NULL) it = client_list;
+ } else {
+ it = it->prev;
+ if (it == NULL) it = g_list_last(client_list);
+ }
+ if (client_focus(it->data))
+ break;
+ } while (it != start);
+ }
+ } else {
+ }
+}
+
diff --git a/openbox/action.h b/openbox/action.h
index 9c204e35..0fe42f64 100644
--- a/openbox/action.h
+++ b/openbox/action.h
@@ -65,7 +65,14 @@ struct Resize {
struct ShowMenu {
Client *c;
- char * menuName;
+ char *menuName;
+};
+
+struct CycleWindows {
+ Client *c;
+ gboolean linear;
+ gboolean forward;
+ gboolean final;
};
union ActionData {
@@ -80,6 +87,7 @@ union ActionData {
struct Move move;
struct Resize resize;
struct ShowMenu showMenu;
+ struct CycleWindows cycle;
};
typedef struct {
@@ -194,4 +202,6 @@ void action_restart(union ActionData *data);
void action_exit(union ActionData *data);
/* ShowMenu */
void action_showmenu(union ActionData *data);
+/* CycleWindows */
+void action_cycle_windows(union ActionData *data);
#endif
diff --git a/openbox/client.c b/openbox/client.c
index 1df411e2..36ca352c 100644
--- a/openbox/client.c
+++ b/openbox/client.c
@@ -2,7 +2,6 @@
#include "screen.h"
#include "prop.h"
#include "extensions.h"
-#include "config.h"
#include "frame.h"
#include "engine.h"
#include "event.h"
@@ -21,7 +20,7 @@
#define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
ButtonMotionMask)
-GSList *client_list = NULL;
+GList *client_list = NULL;
GHashTable *client_map = NULL;
static Window *client_startup_stack_order = NULL;
@@ -65,8 +64,8 @@ void client_shutdown()
void client_set_list()
{
Window *windows, *win_it;
- GSList *it;
- guint size = g_slist_length(client_list);
+ GList *it;
+ guint size = g_list_length(client_list);
/* create an array of the window ids */
if (size > 0) {
@@ -87,7 +86,6 @@ void client_set_list()
void client_manage_all()
{
- ConfigValue focus_new;
unsigned int i, j, nchild;
Window w, *children;
XWMHints *wmhints;
@@ -138,9 +136,7 @@ void client_manage_all()
client_startup_stack_order = NULL;
client_startup_stack_size = 0;
- if (!config_get("focusNew", Config_Bool, &focus_new))
- g_assert_not_reached();
- if (focus_new.bool)
+ if (focus_new)
focus_fallback(FALSE);
}
@@ -152,7 +148,6 @@ void client_manage(Window window)
XSetWindowAttributes attrib_set;
/* XWMHints *wmhint; */
guint i;
- ConfigValue focus_new;
grab_server(TRUE);
@@ -215,7 +210,7 @@ void client_manage(Window window)
grab_server(FALSE);
- client_list = g_slist_append(client_list, client);
+ client_list = g_list_append(client_list, client);
stacking_list = g_list_append(stacking_list, client);
g_assert(!g_hash_table_lookup(client_map, &client->window));
g_hash_table_insert(client_map, &client->window, client);
@@ -239,9 +234,7 @@ void client_manage(Window window)
dispatch_client(Event_Client_Mapped, client, 0, 0);
- if (!config_get("focusNew", Config_Bool, &focus_new))
- g_assert_not_reached();
- if (ob_state != State_Starting && focus_new.bool)
+ if (ob_state != State_Starting && focus_new)
client_focus(client);
/* update the list hints */
@@ -275,7 +268,7 @@ void client_unmanage(Client *client)
engine_frame_hide(client->frame);
- client_list = g_slist_remove(client_list, client);
+ client_list = g_list_remove(client_list, client);
stacking_list = g_list_remove(stacking_list, client);
g_hash_table_remove(client_map, &client->window);
@@ -1708,7 +1701,6 @@ void client_kill(Client *self)
void client_set_desktop(Client *self, guint target, gboolean donthide)
{
guint old, i;
- ConfigValue focus_new;
if (target == self->desktop) return;
@@ -1730,8 +1722,6 @@ void client_set_desktop(Client *self, guint target, gboolean donthide)
screen_update_struts();
/* update the focus lists */
- if (!config_get("focusNew", Config_Bool, &focus_new))
- g_assert_not_reached();
if (old == DESKTOP_ALL) {
for (i = 0; i < screen_num_desktops; ++i)
focus_order[i] = g_list_remove(focus_order[i], self);
@@ -1739,13 +1729,13 @@ void client_set_desktop(Client *self, guint target, gboolean donthide)
focus_order[old] = g_list_remove(focus_order[old], self);
if (target == DESKTOP_ALL) {
for (i = 0; i < screen_num_desktops; ++i) {
- if (focus_new.bool)
+ if (focus_new)
focus_order[i] = g_list_prepend(focus_order[i], self);
else
focus_order[i] = g_list_append(focus_order[i], self);
}
} else {
- if (focus_new.bool)
+ if (focus_new)
focus_order[target] = g_list_prepend(focus_order[target], self);
else
focus_order[target] = g_list_append(focus_order[target], self);
diff --git a/openbox/client.h b/openbox/client.h
index 28385351..94bcf38c 100644
--- a/openbox/client.h
+++ b/openbox/client.h
@@ -285,7 +285,7 @@ typedef struct Client {
Pixmap pixmap_icon_mask;
} Client;
-extern GSList *client_list;
+extern GList *client_list;
extern GHashTable *client_map;
void client_startup();
diff --git a/openbox/config.c b/openbox/config.c
deleted file mode 100644
index a6056ee1..00000000
--- a/openbox/config.c
+++ /dev/null
@@ -1,237 +0,0 @@
-#include "config.h"
-
-#ifdef HAVE_STDIO_H
-# include <stdio.h>
-#endif
-
-static void config_free_entry(ConfigEntry *entry);
-static void config_set_entry(char *name, ConfigValueType type,
- ConfigValue value);
-static void config_def_free(ConfigDefEntry *entry);
-
-static GData *config = NULL;
-static GData *config_def = NULL;
-
-/* provided by cparse.l */
-void cparse_go(char *filename, FILE *);
-
-
-void config_startup()
-{
- ConfigValue val;
-
- /* set up options exported by the kernel */
- config_def_set(config_def_new("engine", Config_String,
- "Engine",
- "The name of the theming engine to be used "
- "to decorate windows."));
-
- config_def_set(config_def_new("theme", Config_String,
- "Theme",
- "The name of the theme to load with the "
- "chosen engine."));
-
- config_def_set(config_def_new("font", Config_String,
- "Titlebar Font",
- "The fontstring specifying the font to "
- "be used in window titlebars."));
- val.string = "Sans-7";
- config_set("font", Config_String, val);
-
- config_def_set(config_def_new("font.shadow", Config_Bool,
- "Titlebar Font Shadow",
- "Whether or not the text in the window "
- "titlebars gets a drop shadow."));
- val.bool = FALSE;
- config_set("font.shadow", Config_Bool, val);
-
- config_def_set(config_def_new("font.shadow.offset", Config_Integer,
- "Titlebar Font Shadow Offset",
- "The offset of the drop shadow for text "
- "in the window titlebars."));
- val.integer = 1;
- config_set("font.shadow.offset", Config_Integer, val);
-
- config_def_set(config_def_new("font.shadow.tint", Config_Integer,
- "Titlebar Font Shadow Tint",
- "The percentage of tint/opacity to give the "
- "the shadow(from -100(white) to "
- "100(black))."));
- val.integer = 25;
- config_set("font.shadow.tint", Config_Integer, val);
-
- config_def_set(config_def_new("titlebar.layout", Config_String,
- "Titlebar Layout",
- "The ordering of the elements in the "
- "window titlebars."));
- val.string = "NDSLIMC";
- config_set("titlebar.layout", Config_String, val);
-
- config_def_set(config_def_new("focusNew", Config_Bool,
- "Focus New Windows",
- "Focus windows when they first appear."));
- val.bool = TRUE;
- config_set("focusNew", Config_Bool, val);
-
- config_def_set(config_def_new("focusFollowsMouse", Config_Bool,
- "Focus Follows Mouse",
- "Focus windows when the mouse pointer "
- "enters them."));
- val.bool = TRUE;
- config_set("focusFollowsMouse", Config_Bool, val);
-}
-
-void config_shutdown()
-{
- g_datalist_clear(&config);
- g_datalist_clear(&config_def);
-}
-
-gboolean config_set(char *name, ConfigValueType type, ConfigValue value)
-{
- ConfigDefEntry *def;
- gboolean ret = FALSE;
-
- name = g_ascii_strdown(name, -1);
-
- def = g_datalist_get_data(&config_def, name);
-
- if (def == NULL) {
- g_warning("Invalid config option '%s'", name);
- } else {
- if (def->hasList) {
- gboolean found = FALSE;
- GSList *it;
-
- it = def->values;
- g_assert(it != NULL);
- do {
- if (g_ascii_strcasecmp(it->data, value.string) == 0) {
- found = TRUE;
- break;
- }
- } while ((it = it->next));
-
- if (!found)
- g_warning("Invalid value '%s' for config option '%s'",
- value.string, name);
- else
- ret = TRUE;
- } else if (type != def->type) {
- g_warning("Incorrect type of value for config option '%s'", name);
- } else
- ret = TRUE;
-
- }
-
- if (ret)
- config_set_entry(name, type, value);
- else
- g_free(name);
-
- return ret;
-}
-
-gboolean config_get(char *name, ConfigValueType type, ConfigValue *value)
-{
- ConfigEntry *entry;
- gboolean ret = FALSE;
-
- name = g_ascii_strdown(name, -1);
- entry = g_datalist_get_data(&config, name);
- if (entry != NULL && entry->type == type) {
- *value = entry->value;
- ret = TRUE;
- }
- g_free(name);
- return ret;
-}
-
-static void config_set_entry(char *name, ConfigValueType type,
- ConfigValue value)
-{
- ConfigEntry *entry = NULL;
-
- entry = g_new(ConfigEntry, 1);
- entry->name = name;
- entry->type = type;
- if (type == Config_String)
- entry->value.string = g_strdup(value.string);
- else
- entry->value = value;
-
- g_datalist_set_data_full(&config, name, entry,
- (GDestroyNotify)config_free_entry);
-}
-
-static void config_free_entry(ConfigEntry *entry)
-{
- g_free(entry->name);
- entry->name = NULL;
- if(entry->type == Config_String) {
- g_free(entry->value.string);
- entry->value.string = NULL;
- }
- g_free(entry);
-}
-
-ConfigDefEntry *config_def_new(char *name, ConfigValueType type,
- char *descriptive_name, char *long_description)
-{
- ConfigDefEntry *entry;
-
- entry = g_new(ConfigDefEntry, 1);
- entry->name = g_ascii_strdown(name, -1);
- entry->descriptive_name = g_strdup(descriptive_name);
- entry->long_description = g_strdup(long_description);
- entry->hasList = FALSE;
- entry->type = type;
- entry->values = NULL;
- return entry;
-}
-
-static void config_def_free(ConfigDefEntry *entry)
-{
- GSList *it;
-
- g_free(entry->name);
- g_free(entry->descriptive_name);
- g_free(entry->long_description);
- if (entry->hasList) {
- for (it = entry->values; it != NULL; it = it->next)
- g_free(it->data);
- g_slist_free(entry->values);
- }
- g_free(entry);
-}
-
-gboolean config_def_add_value(ConfigDefEntry *entry, char *value)
-{
- if (entry->type != Config_String) {
- g_warning("Tried adding value to non-string config definition");
- return FALSE;
- }
-
- entry->hasList = TRUE;
- entry->values = g_slist_append(entry->values, g_ascii_strdown(value, -1));
- return TRUE;
-}
-
-gboolean config_def_set(ConfigDefEntry *entry)
-{
- gboolean ret = FALSE;
- ConfigDefEntry *def;
-
- if ((def = g_datalist_get_data(&config_def, entry->name))) {
- g_assert(def != entry); /* adding it twice!? */
- g_warning("Definition already set for config option '%s'. ",
- entry->name);
- config_def_free(entry);
- } else {
- g_datalist_set_data_full(&config_def, entry->name, entry,
- (GDestroyNotify)config_def_free);
- ret = TRUE;
- }
-
- return ret;
-}
diff --git a/openbox/config.h b/openbox/config.h
deleted file mode 100644
index 3d82090b..00000000
--- a/openbox/config.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef __config_h
-#define __config_h
-
-#include <glib.h>
-
-typedef enum {
- Config_String,
- Config_Integer,
- Config_Bool
-} ConfigValueType;
-
-typedef union {
- char *string;
- int integer;
- gboolean bool;
-} ConfigValue;
-
-typedef struct {
- char *name;
- ConfigValueType type;
- ConfigValue value;
-} ConfigEntry;
-
-typedef struct {
- char *name;
- char *descriptive_name; /* user friendly name */
- char *long_description; /* text description of option */
- ConfigValueType type;
- /* if it is a string type optionally provide a list of valid strings */
- gboolean hasList;
- GSList *values;
-} ConfigDefEntry;
-
-void config_startup();
-void config_shutdown();
-
-/* Set a config variable's value. The variable must have already been defined
- with a call to config_def_set */
-gboolean config_set(char *name, ConfigValueType type, ConfigValue value);
-
-/* Get a config variable's value. Returns FALSE if the value has not been
- set. */
-gboolean config_get(char *name, ConfigValueType type, ConfigValue *value);
-
-/* Create a new config definition to add to the config system */
-ConfigDefEntry *config_def_new(char *name, ConfigValueType type,
- char *descriptive_name, char *long_description);
-
-/* Add a value to a String type config definition */
-gboolean config_def_add_value(ConfigDefEntry *entry, char *value);
-
-/* Sets up the definition in the config system, Don't free or touch the entry
- after setting it with this. It is invalidated even if the function returns
- FALSE. */
-gboolean config_def_set(ConfigDefEntry *entry);
-
-#endif
diff --git a/openbox/engine.c b/openbox/engine.c
index c654d263..0ede97ff 100644
--- a/openbox/engine.c
+++ b/openbox/engine.c
@@ -1,5 +1,4 @@
#include "engine.h"
-#include "config.h"
#include <glib.h>
#include <gmodule.h>
@@ -7,9 +6,17 @@
# include <stdlib.h>
#endif
-static GModule *module;
-static EngineStartup *estartup;
-static EngineShutdown *eshutdown;
+char *engine_name = NULL;
+char *engine_theme = NULL;
+char *engine_layout = "NDSLIMC";
+char *engine_font = "Sans-7";
+gboolean engine_shadow = FALSE;
+int engine_shadow_offset = 1;
+int engine_shadow_tint = 25;
+
+static GModule *module = NULL;
+static EngineStartup *estartup = NULL;
+static EngineShutdown *eshutdown = NULL;
#define LOADSYM(name, var) \
if (!g_module_symbol(module, #name, (gpointer*)&var)) { \
@@ -61,16 +68,15 @@ static gboolean load(char *name)
void engine_startup()
{
- ConfigValue engine;
-
module = NULL;
+}
- if (config_get("engine", Config_String, &engine)) {
- if (load(engine.string))
- return;
- g_warning("Failed to load the engine '%s'", engine.string);
- g_message("Falling back to the default: '%s'", DEFAULT_ENGINE);
- }
+void engine_load()
+{
+ if (load(engine_name))
+ return;
+ g_warning("Failed to load the engine '%s'", engine_name);
+ g_message("Falling back to the default: '%s'", DEFAULT_ENGINE);
if (!load(DEFAULT_ENGINE)) {
g_critical("Failed to load the engine '%s'. Aborting", DEFAULT_ENGINE);
exit(1);
@@ -79,6 +85,7 @@ void engine_startup()
void engine_shutdown()
{
+ g_free(engine_name);
if (module != NULL) {
eshutdown();
g_module_close(module);
diff --git a/openbox/engine.h b/openbox/engine.h
index 0ab578ce..76bb1495 100644
--- a/openbox/engine.h
+++ b/openbox/engine.h
@@ -3,7 +3,23 @@
#include "../engines/engineinterface.h"
+/* The engine to load */
+extern char *engine_name;
+/* The theme to load */
+extern char *engine_theme;
+/* The titlebar layout */
+extern char *engine_layout;
+/* The titlebar font */
+extern char *engine_font;
+/* The titlebar font's shadow */
+extern gboolean engine_shadow;
+/* The titlebar font's shadow offset */
+extern int engine_shadow_offset;
+/* The titlebar font's shadow transparency */
+extern int engine_shadow_tint;
+
void engine_startup();
+void engine_load();
void engine_shutdown();
EngineFrameNew *engine_frame_new;
diff --git a/openbox/event.c b/openbox/event.c
index 2d144519..79befa66 100644
--- a/openbox/event.c
+++ b/openbox/event.c
@@ -1,6 +1,5 @@
#include "openbox.h"
#include "client.h"
-#include "config.h"
#include "xerror.h"
#include "prop.h"
#include "screen.h"
@@ -356,7 +355,6 @@ static void event_handle_client(Client *client, XEvent *e)
XEvent ce;
Atom msgtype;
int i=0;
- ConfigValue focus_follow;
switch (e->type) {
case FocusIn:
@@ -378,12 +376,8 @@ static void event_handle_client(Client *client, XEvent *e)
client);
focus_order[desktop] = g_list_prepend(focus_order[desktop],
client);
- } else {
- if (!config_get("focusFollowsMouse",Config_Bool,&focus_follow))
- g_assert_not_reached();
- if (focus_follow.bool)
- client_focus(client);
- }
+ } else if (focus_follow)
+ client_focus(client);
}
break;
case ConfigureRequest:
diff --git a/openbox/focus.c b/openbox/focus.c
index 1c5d2c7f..b676c127 100644
--- a/openbox/focus.c
+++ b/openbox/focus.c
@@ -1,5 +1,4 @@
#include "event.h"
-#include "config.h"
#include "openbox.h"
#include "client.h"
#include "frame.h"
@@ -16,6 +15,8 @@ GList **focus_order = NULL; /* these lists are created when screen_startup
sets the number of desktops */
Window focus_backup = None;
+gboolean focus_new = TRUE;
+gboolean focus_follow = TRUE;
void focus_startup()
{
@@ -25,6 +26,8 @@ void focus_startup()
XSetWindowAttributes attrib;
focus_client = NULL;
+ focus_new = TRUE;
+ focus_follow = TRUE;
attrib.override_redirect = TRUE;
focus_backup = XCreateWindow(ob_display, ob_root,
@@ -113,7 +116,6 @@ static gboolean focus_under_pointer()
void focus_fallback(gboolean switching_desks)
{
- ConfigValue focus_follow;
GList *it;
gboolean under = FALSE;
Client *old = NULL;
@@ -130,9 +132,7 @@ void focus_fallback(gboolean switching_desks)
/* don't skip any windows when switching desktops */
old = NULL;
} else {
- if (!config_get("focusFollowsMouse", Config_Bool, &focus_follow))
- g_assert_not_reached();
- if (focus_follow.bool)
+ if (focus_follow)
under = focus_under_pointer();
}
diff --git a/openbox/focus.h b/openbox/focus.h
index af95015c..8a511cf3 100644
--- a/openbox/focus.h
+++ b/openbox/focus.h
@@ -15,6 +15,11 @@ extern struct Client *focus_client;
/*! The recent focus order on each desktop */
extern GList **focus_order;
+/*! Should new windows be focused */
+extern gboolean focus_new;
+/*! Should focus follow the mouse pointer */
+extern gboolean focus_follow;
+
void focus_startup();
void focus_shutdown();
diff --git a/openbox/openbox.c b/openbox/openbox.c
index e2a4de3f..90756097 100644
--- a/openbox/openbox.c
+++ b/openbox/openbox.c
@@ -7,7 +7,6 @@
#include "screen.h"
#include "focus.h"
#include "extensions.h"
-#include "config.h"
#include "parse.h"
#include "grab.h"
#include "engine.h"
@@ -149,11 +148,11 @@ int main(int argc, char **argv)
if (screen_annex()) { /* it will be ours! */
timer_startup();
- config_startup();
render_startup();
font_startup();
event_startup();
grab_startup();
+ engine_startup();
plugin_startup();
/* startup the parsing so plugins can register sections of the rc */
@@ -167,7 +166,9 @@ int main(int argc, char **argv)
/* we're done with parsing now, kill it */
parse_shutdown();
- engine_startup();
+ /* load the engine specified in the rc */
+ engine_load();
+
screen_startup();
focus_startup();
client_startup();
@@ -193,7 +194,6 @@ int main(int argc, char **argv)
grab_shutdown();
event_shutdown();
render_shutdown();
- config_shutdown();
timer_shutdown();
}
diff --git a/openbox/parse.c b/openbox/parse.c
index 80a918cb..a72cfd84 100644
--- a/openbox/parse.c
+++ b/openbox/parse.c
@@ -1,20 +1,18 @@
#include "parse.h"
-#include "config.h"
-static GHashTable *reg = NULL;
-static ParseFunc func = NULL;
+static GHashTable *reg = NULL;
-/* parse tokens from the [openbox] section of the rc file */
-static void parse_rc_token(ParseToken *token);
+struct Functions {
+ ParseFunc func;
+ AssignParseFunc afunc;
+} *funcs;
-void destkey(gpointer key) { g_free(key); }
+void destshit(gpointer key) { g_free(key); }
void parse_startup()
{
- reg = g_hash_table_new_full(g_str_hash, g_str_equal, destkey, NULL);
- func = NULL;
-
- parse_reg_section("openbox", parse_rc_token);
+ reg = g_hash_table_new_full(g_str_hash, g_str_equal, destshit, destshit);
+ funcs = NULL;
}
void parse_shutdown()
@@ -22,13 +20,17 @@ void parse_shutdown()
g_hash_table_destroy(reg);
}
-void parse_reg_section(char *section, ParseFunc func)
+void parse_reg_section(char *section, ParseFunc func, AssignParseFunc afunc)
{
if (g_hash_table_lookup(reg, section) != NULL)
g_warning("duplicate request for section '%s' in the rc file",
section);
- else
- g_hash_table_insert(reg, g_ascii_strdown(section, -1), (void*)func);
+ else {
+ struct Functions *f = g_new(struct Functions, 1);
+ f->func = func;
+ f->afunc = afunc;
+ g_hash_table_insert(reg, g_ascii_strdown(section, -1), f);
+ }
}
void parse_free_token(ParseToken *token)
@@ -54,7 +56,6 @@ void parse_free_token(ParseToken *token)
case TOKEN_BOOL:
case TOKEN_LBRACE:
case TOKEN_RBRACE:
- case TOKEN_EQUALS:
case TOKEN_COMMA:
case TOKEN_NEWLINE:
break;
@@ -63,82 +64,25 @@ void parse_free_token(ParseToken *token)
void parse_set_section(char *section)
{
- func = (ParseFunc)g_hash_table_lookup(reg, section);
+ funcs = g_hash_table_lookup(reg, section);
}
void parse_token(ParseToken *token)
{
- if (func != NULL)
- func(token);
+ if (funcs) {
+ if (funcs->func != NULL)
+ funcs->func(token);
+ else if (token->type != TOKEN_NEWLINE)
+ yyerror("syntax error");
+ }
}
-static void parse_rc_token(ParseToken *token)
+void parse_assign(char *name, ParseToken *value)
{
- static int got_eq = FALSE;
- static ParseTokenType got_val = 0;
- static char *id = NULL, *s = NULL;
- static int i;
- static gboolean b;
-
- if (id == NULL) {
- if (token->type == TOKEN_IDENTIFIER) {
- id = token->data.identifier;
- return;
- } else {
- yyerror("syntax error");
- }
- } else if (!got_eq) {
- if (token->type == TOKEN_EQUALS) {
- got_eq = TRUE;
- return;
- } else {
- yyerror("syntax error");
- }
- } else if (!got_val) {
- if (token->type == TOKEN_STRING) {
- s = token->data.string;
- got_val = token->type;
- return;
- } else if (token->type == TOKEN_BOOL) {
- b = token->data.bool;
- got_val = token->type;
- return;
- } else if (token->type == TOKEN_INTEGER) {
- i = token->data.integer;
- got_val = token->type;
- return;
- } else
+ if (funcs) {
+ if (funcs->afunc != NULL)
+ funcs->afunc(name, value);
+ else
yyerror("syntax error");
- } else if (token->type != TOKEN_NEWLINE) {
- yyerror("syntax error");
- } else {
- ConfigValue v;
-
- switch (got_val) {
- case TOKEN_STRING:
- v.string = s;
- if (!config_set(id, Config_String, v))
- yyerror("invalid value type");
- break;
- case TOKEN_BOOL:
- v.bool = b;
- if (!config_set(id, Config_Bool, v))
- yyerror("invalid value type");
- break;
- case TOKEN_INTEGER:
- v.integer = i;
- if (!config_set(id, Config_Integer, v))
- yyerror("invalid value type");
- break;
- default:
- g_assert_not_reached(); /* unhandled type got parsed */
- }
}
-
- g_free(id);
- g_free(s);
- id = s = NULL;
- got_eq = FALSE;
- got_val = 0;
- parse_free_token(token);
}
diff --git a/openbox/parse.h b/openbox/parse.h
index bd6c03f8..d77b6924 100644
--- a/openbox/parse.h
+++ b/openbox/parse.h
@@ -13,7 +13,6 @@ typedef enum {
TOKEN_LIST,
TOKEN_LBRACE = '{',
TOKEN_RBRACE = '}',
- TOKEN_EQUALS = '=',
TOKEN_COMMA = ',',
TOKEN_NEWLINE = '\n'
} ParseTokenType;
@@ -24,6 +23,7 @@ typedef struct {
} ParseToken;
typedef void (*ParseFunc)(ParseToken *token);
+typedef void (*AssignParseFunc)(char *name, ParseToken *value);
void parse_startup();
void parse_shutdown();
@@ -33,7 +33,7 @@ void parse_shutdown();
*/
void parse_rc();
-void parse_reg_section(char *section, ParseFunc func);
+void parse_reg_section(char *section, ParseFunc func, AssignParseFunc afunc);
/* Free a parsed token's allocated memory */
diff --git a/openbox/parse.l b/openbox/parse.l
index 427a55cd..4dcdc2ca 100644
--- a/openbox/parse.l
+++ b/openbox/parse.l
@@ -35,7 +35,7 @@ bool ([tT][rR][uU][eE]|[fF][aA][lL][sS][eE]|[yY][eE][sS]|[nN][oO]|[oO][nN]|[oO][
}
{identifier} { yylval.identifier = g_strdup(yytext); return IDENTIFIER; }
[{}()\[\]=,] { yylval.character = *yytext; return *yytext; }
-\n { yylval.character = *yytext; ++yylineno; return *yytext; }
+\n { yylval.character = *yytext; return *yytext; }
. { return INVALID; }
%%
diff --git a/openbox/parse.y b/openbox/parse.y
index f8b0a044..125f1803 100644
--- a/openbox/parse.y
+++ b/openbox/parse.y
@@ -31,6 +31,7 @@ static ParseToken t;
/* in parse.c */
void parse_token(ParseToken *token);
+void parse_assign(char *name, ParseToken *token);
void parse_set_section(char *section);
%}
@@ -54,31 +55,32 @@ void parse_set_section(char *section);
%%
sections:
- | sections '[' IDENTIFIER ']' { parse_set_section($3); } '\n' lines
+ | sections '[' IDENTIFIER ']' { parse_set_section($3); } '\n'
+ { ++yylineno; } lines
;
lines:
- | lines tokens '\n' { t.type = $3; t.data.character = $3; parse_token(&t); }
+ | lines tokens { t.type='\n'; t.data.character='\n'; parse_token(&t); } '\n'
+ { ++yylineno; }
+ | lines IDENTIFIER '=' listtoken { parse_assign($2, &t); } '\n'
+ { ++yylineno; }
;
tokens:
- tokens token
- | token
+ tokens token { parse_token(&t); }
+ | token { parse_token(&t); }
;
token:
- REAL { t.type = TOKEN_REAL; t.data.real = $1; parse_token(&t); }
- | INTEGER { t.type = TOKEN_INTEGER; t.data.integer = $1;
- parse_token(&t); }
- | STRING { t.type = TOKEN_STRING; t.data.string = $1; parse_token(&t); }
- | IDENTIFIER { t.type = TOKEN_IDENTIFIER; t.data.identifier = $1;
- parse_token(&t);}
- | BOOL { t.type = TOKEN_BOOL; t.data.bool = $1; parse_token(&t); }
- | list { t.type = TOKEN_LIST; t.data.list = $1; parse_token(&t); }
- | '{' { t.type = $1; t.data.character = $1; parse_token(&t); }
- | '}' { t.type = $1; t.data.character = $1; parse_token(&t); }
- | '=' { t.type = $1; t.data.character = $1; parse_token(&t); }
- | ',' { t.type = $1; t.data.character = $1; parse_token(&t); }
+ REAL { t.type = TOKEN_REAL; t.data.real = $1; }
+ | INTEGER { t.type = TOKEN_INTEGER; t.data.integer = $1; }
+ | STRING { t.type = TOKEN_STRING; t.data.string = $1; }
+ | IDENTIFIER { t.type = TOKEN_IDENTIFIER; t.data.identifier = $1; }
+ | BOOL { t.type = TOKEN_BOOL; t.data.bool = $1; }
+ | list { t.type = TOKEN_LIST; t.data.list = $1; }
+ | '{' { t.type = $1; t.data.character = $1; }
+ | '}' { t.type = $1; t.data.character = $1; }
+ | ',' { t.type = $1; t.data.character = $1; }
;
list:
@@ -107,7 +109,6 @@ listtoken:
| list { t.type = TOKEN_LIST; t.data.list = $1; }
| '{' { t.type = $1; t.data.character = $1; }
| '}' { t.type = $1; t.data.character = $1; }
- | '=' { t.type = $1; t.data.character = $1; }
| ',' { t.type = $1; t.data.character = $1; }
;
diff --git a/openbox/screen.c b/openbox/screen.c
index 5cf2bc55..3145a63c 100644
--- a/openbox/screen.c
+++ b/openbox/screen.c
@@ -208,7 +208,7 @@ void screen_set_num_desktops(guint num)
{
guint i, old;
gulong *viewport;
- GSList *it;
+ GList *it;
g_assert(num > 0);
@@ -424,7 +424,7 @@ void screen_install_colormap(Client *client, gboolean install)
void screen_update_struts()
{
- GSList *it;
+ GList *it;
guint i;
g_free(strut);
@@ -496,7 +496,7 @@ static void screen_update_area()
*/
if (!RECT_EQUAL(old_area, area[i])) {
/* the area has changed, adjust all the maximized windows */
- GSList *it;
+ GList *it;
for (it = client_list; it; it = it->next) {
Client *c = it->data;
if (i < screen_num_desktops) {