summaryrefslogtreecommitdiff
path: root/openbox
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-04-08 07:31:26 +0000
committerDana Jansens <danakj@orodu.net>2003-04-08 07:31:26 +0000
commit71badb0790c8595a0ab6dedfbf8027c698369210 (patch)
tree2985012f6a12b5b0157541885d663c141b5bb0c7 /openbox
parent672f1de2812adc49170414d7abbb2df7db69f34c (diff)
move config option loading for the kernel into config.c/h
add options for the number of desktops and the names of the desktops
Diffstat (limited to 'openbox')
-rw-r--r--openbox/client.c9
-rw-r--r--openbox/config.c177
-rw-r--r--openbox/config.h39
-rw-r--r--openbox/engine.c79
-rw-r--r--openbox/engine.h15
-rw-r--r--openbox/event.c3
-rw-r--r--openbox/focus.c47
-rw-r--r--openbox/focus.h5
-rw-r--r--openbox/openbox.c6
-rw-r--r--openbox/prop.c14
-rw-r--r--openbox/screen.c13
11 files changed, 261 insertions, 146 deletions
diff --git a/openbox/client.c b/openbox/client.c
index 7fca4796..af24d921 100644
--- a/openbox/client.c
+++ b/openbox/client.c
@@ -10,6 +10,7 @@
#include "stacking.h"
#include "dispatch.h"
#include "group.h"
+#include "config.h"
#include <glib.h>
#include <X11/Xutil.h>
@@ -138,7 +139,7 @@ void client_manage_all()
client_startup_stack_order = NULL;
client_startup_stack_size = 0;
- if (focus_new)
+ if (config_focus_new)
focus_fallback(Fallback_NoFocus);
}
@@ -237,7 +238,7 @@ void client_manage(Window window)
dispatch_client(Event_Client_Mapped, self, 0, 0);
- if (ob_state != State_Starting && focus_new)
+ if (ob_state != State_Starting && config_focus_new)
client_focus(self);
/* update the list hints */
@@ -1811,13 +1812,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)
+ if (config_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)
+ if (config_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/config.c b/openbox/config.c
new file mode 100644
index 00000000..12255906
--- /dev/null
+++ b/openbox/config.c
@@ -0,0 +1,177 @@
+#include "config.h"
+#include "parse.h"
+
+gboolean config_focus_new;
+gboolean config_focus_follow;
+gboolean config_focus_last;
+gboolean config_focus_last_on_desktop;
+
+char *config_engine_name;
+char *config_engine_theme;
+char *config_engine_layout;
+char *config_engine_font;
+gboolean config_engine_shadow;
+int config_engine_shadow_offset;
+int config_engine_shadow_tint;
+
+int config_desktops_num;
+GSList *config_desktops_names;
+
+static void parse_focus(char *name, ParseToken *value)
+{
+ if (!g_ascii_strcasecmp(name, "focusnew")) {
+ if (value->type != TOKEN_BOOL)
+ yyerror("invalid value");
+ else {
+ config_focus_new = value->data.bool;
+ }
+ } else if (!g_ascii_strcasecmp(name, "followmouse")) {
+ if (value->type != TOKEN_BOOL)
+ yyerror("invalid value");
+ else {
+ config_focus_follow = value->data.bool;
+ }
+ } else if (!g_ascii_strcasecmp(name, "focuslast")) {
+ if (value->type != TOKEN_BOOL)
+ yyerror("invalid value");
+ else {
+ config_focus_last = value->data.bool;
+ }
+ } else if (!g_ascii_strcasecmp(name, "focuslastondesktop")) {
+ if (value->type != TOKEN_BOOL)
+ yyerror("invalid value");
+ else {
+ config_focus_last_on_desktop = value->data.bool;
+ }
+ } else
+ yyerror("invalid option");
+ parse_free_token(value);
+}
+
+static void parse_engine(char *name, ParseToken *value)
+{
+ if (!g_ascii_strcasecmp(name, "engine")) {
+ if (value->type != TOKEN_STRING)
+ yyerror("invalid value");
+ else {
+ g_free(config_engine_name);
+ config_engine_name = g_strdup(value->data.string);
+ }
+ } else if (!g_ascii_strcasecmp(name, "theme")) {
+ if (value->type != TOKEN_STRING)
+ yyerror("invalid value");
+ else {
+ g_free(config_engine_theme);
+ config_engine_theme = g_strdup(value->data.string);
+ }
+ } else if (!g_ascii_strcasecmp(name, "titlebarlayout")) {
+ if (value->type != TOKEN_STRING)
+ yyerror("invalid value");
+ else {
+ g_free(config_engine_layout);
+ config_engine_layout = g_strdup(value->data.string);
+ }
+ } else if (!g_ascii_strcasecmp(name, "font.title")) {
+ if (value->type != TOKEN_STRING)
+ yyerror("invalid value");
+ else {
+ g_free(config_engine_font);
+ config_engine_font = g_strdup(value->data.string);
+ }
+ } else if (!g_ascii_strcasecmp(name, "font.title.shadow")) {
+ if (value->type != TOKEN_BOOL)
+ yyerror("invalid value");
+ else {
+ config_engine_shadow = value->data.bool;
+ }
+ } else if (!g_ascii_strcasecmp(name, "font.title.shadow.offset")) {
+ if (value->type != TOKEN_INTEGER)
+ yyerror("invalid value");
+ else {
+ config_engine_shadow_offset = value->data.integer;
+ }
+ } else if (!g_ascii_strcasecmp(name, "font.title.shadow.tint")) {
+ if (value->type != TOKEN_INTEGER)
+ yyerror("invalid value");
+ else {
+ config_engine_shadow_tint = value->data.integer;
+ if (config_engine_shadow_tint < -100)
+ config_engine_shadow_tint = -100;
+ else if (config_engine_shadow_tint > 100)
+ config_engine_shadow_tint = 100;
+ }
+ } else
+ yyerror("invalid option");
+ parse_free_token(value);
+}
+
+static void parse_desktops(char *name, ParseToken *value)
+{
+ GList *it;
+
+ if (!g_ascii_strcasecmp(name, "number")) {
+ if (value->type != TOKEN_INTEGER)
+ yyerror("invalid value");
+ else {
+ config_desktops_num = value->data.integer;
+ }
+ } else if (!g_ascii_strcasecmp(name, "names")) {
+ if (value->type == TOKEN_LIST) {
+ for (it = value->data.list; it; it = it->next)
+ if (((ParseToken*)it->data)->type != TOKEN_STRING) break;
+ if (it == NULL) {
+ /* build a string list */
+ g_free(config_desktops_names);
+ for (it = value->data.list; it; it = it->next)
+ config_desktops_names =
+ g_slist_append(config_desktops_names,
+ g_strdup
+ (((ParseToken*)it->data)->data.string));
+ } else {
+ yyerror("invalid string in names list");
+ }
+ } else {
+ yyerror("syntax error (expected list of strings)");
+ }
+ } else
+ yyerror("invalid option");
+ parse_free_token(value);
+}
+
+void config_startup()
+{
+ config_focus_new = TRUE;
+ config_focus_follow = FALSE;
+ config_focus_last = TRUE;
+ config_focus_last_on_desktop = TRUE;
+
+ parse_reg_section("focus", NULL, parse_focus);
+
+ config_engine_name = g_strdup(DEFAULT_ENGINE);
+ config_engine_theme = NULL;
+ config_engine_layout = g_strdup("NLIMC");
+ config_engine_font = g_strdup("Sans-7");
+ config_engine_shadow = FALSE;
+ config_engine_shadow_offset = 1;
+ config_engine_shadow_tint = 25;
+
+ parse_reg_section("engine", NULL, parse_engine);
+
+ config_desktops_num = 4;
+ config_desktops_names = NULL;
+
+ parse_reg_section("desktops", NULL, parse_desktops);
+}
+
+void config_shutdown()
+{
+ GSList *it;
+
+ g_free(config_engine_name);
+ g_free(config_engine_layout);
+ g_free(config_engine_font);
+
+ for (it = config_desktops_names; it; it = it->next)
+ g_free(it->data);
+ g_slist_free(config_desktops_names);
+}
diff --git a/openbox/config.h b/openbox/config.h
new file mode 100644
index 00000000..0dceb920
--- /dev/null
+++ b/openbox/config.h
@@ -0,0 +1,39 @@
+#ifndef __config_h
+#define __config_h
+
+#include <glib.h>
+
+/*! Should new windows be focused */
+extern gboolean config_focus_new;
+/*! Focus windows when the mouse enters them */
+extern gboolean config_focus_follow;
+/*! Focus the last focused window as a fallback */
+extern gboolean config_focus_last;
+/*! Focus the last focused window as a fallback when switching desktops */
+extern gboolean config_focus_last_on_desktop;
+
+/*! The engine to load */
+extern char *config_engine_name;
+/*! The theme to load */
+extern char *config_engine_theme;
+/*! The titlebar layout */
+extern char *config_engine_layout;
+/*! The titlebar font */
+extern char *config_engine_font;
+/*! The titlebar font's shadow */
+extern gboolean config_engine_shadow;
+/*! The titlebar font's shadow offset */
+extern int config_engine_shadow_offset;
+/*! The titlebar font's shadow transparency */
+extern int config_engine_shadow_tint;
+
+/*! The number of desktops */
+extern int config_desktops_num;
+/*! Names for the desktops */
+extern GSList *config_desktops_names;
+
+
+void config_startup();
+void config_shutdown();
+
+#endif
diff --git a/openbox/engine.c b/openbox/engine.c
index 66d30580..53e10deb 100644
--- a/openbox/engine.c
+++ b/openbox/engine.c
@@ -1,5 +1,5 @@
#include "engine.h"
-#include "parse.h"
+#include "config.h"
#include <glib.h>
#include <gmodule.h>
@@ -7,14 +7,6 @@
# include <stdlib.h>
#endif
-char *engine_name;
-char *engine_theme;
-char *engine_layout;
-char *engine_font;
-gboolean engine_shadow;
-int engine_shadow_offset;
-int engine_shadow_tint;
-
EngineFrameNew *engine_frame_new;
EngineFrameGrabClient *engine_frame_grab_client;
EngineFrameReleaseClient *engine_frame_release_client;
@@ -86,80 +78,16 @@ static gboolean load(char *name)
return TRUE;
}
-static void parse_assign(char *name, ParseToken *value)
-{
- if (!g_ascii_strcasecmp(name, "engine")) {
- if (value->type != TOKEN_STRING)
- yyerror("invalid value");
- else {
- g_free(engine_name);
- engine_name = g_strdup(value->data.string);
- }
- } else if (!g_ascii_strcasecmp(name, "theme")) {
- if (value->type != TOKEN_STRING)
- yyerror("invalid value");
- else {
- g_free(engine_theme);
- engine_theme = g_strdup(value->data.string);
- }
- } else if (!g_ascii_strcasecmp(name, "titlebarlayout")) {
- if (value->type != TOKEN_STRING)
- yyerror("invalid value");
- else {
- g_free(engine_layout);
- engine_layout = g_strdup(value->data.string);
- }
- } else if (!g_ascii_strcasecmp(name, "font.title")) {
- if (value->type != TOKEN_STRING)
- yyerror("invalid value");
- else {
- g_free(engine_font);
- engine_font = g_strdup(value->data.string);
- }
- } else if (!g_ascii_strcasecmp(name, "font.title.shadow")) {
- if (value->type != TOKEN_BOOL)
- yyerror("invalid value");
- else {
- engine_shadow = value->data.bool;
- }
- } else if (!g_ascii_strcasecmp(name, "font.title.shadow.offset")) {
- if (value->type != TOKEN_INTEGER)
- yyerror("invalid value");
- else {
- engine_shadow_offset = value->data.integer;
- }
- } else if (!g_ascii_strcasecmp(name, "font.title.shadow.tint")) {
- if (value->type != TOKEN_INTEGER)
- yyerror("invalid value");
- else {
- engine_shadow_tint = value->data.integer;
- if (engine_shadow_tint < -100) engine_shadow_tint = -100;
- else if (engine_shadow_tint > 100) engine_shadow_tint = 100;
- }
- } else
- yyerror("invalid option");
- parse_free_token(value);
-}
-
void engine_startup()
{
module = NULL;
- engine_name = g_strdup(DEFAULT_ENGINE);
- engine_theme = NULL;
- engine_layout = g_strdup("NLIMC");
- engine_font = g_strdup("Sans-7");
- engine_shadow = FALSE;
- engine_shadow_offset = 1;
- engine_shadow_tint = 25;
-
- parse_reg_section("engine", NULL, parse_assign);
}
void engine_load()
{
- if (load(engine_name))
+ if (load(config_engine_name))
return;
- g_warning("Failed to load the engine '%s'", engine_name);
+ g_warning("Failed to load the engine '%s'", config_engine_name);
g_message("Falling back to the default: '%s'", DEFAULT_ENGINE);
if (module != NULL) {
g_module_close(module);
@@ -173,7 +101,6 @@ void engine_load()
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 0180e3e5..e2c314a6 100644
--- a/openbox/engine.h
+++ b/openbox/engine.h
@@ -3,21 +3,6 @@
#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();
diff --git a/openbox/event.c b/openbox/event.c
index 04174af0..edd6f4ce 100644
--- a/openbox/event.c
+++ b/openbox/event.c
@@ -2,6 +2,7 @@
#include "client.h"
#include "xerror.h"
#include "prop.h"
+#include "config.h"
#include "screen.h"
#include "frame.h"
#include "engine.h"
@@ -388,7 +389,7 @@ static void event_handle_client(Client *client, XEvent *e)
client);
focus_order[desktop] = g_list_prepend(focus_order[desktop],
client);
- } else if (focus_follow) {
+ } else if (config_focus_follow) {
#ifdef DEBUG_FOCUS
g_message("EnterNotify on %lx, focusing window",
client->window);
diff --git a/openbox/focus.c b/openbox/focus.c
index 8afbdcb6..7542fae6 100644
--- a/openbox/focus.c
+++ b/openbox/focus.c
@@ -1,6 +1,7 @@
#include "event.h"
#include "openbox.h"
#include "client.h"
+#include "config.h"
#include "frame.h"
#include "screen.h"
#include "group.h"
@@ -18,44 +19,9 @@ 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 = FALSE;
-static gboolean focus_last = TRUE;
-static gboolean focus_last_on_desktop = TRUE;
static gboolean noreorder = 0;
-static void parse_assign(char *name, ParseToken *value)
-{
- if (!g_ascii_strcasecmp(name, "focusnew")) {
- if (value->type != TOKEN_BOOL)
- yyerror("invalid value");
- else {
- focus_new = value->data.bool;
- }
- } else if (!g_ascii_strcasecmp(name, "followmouse")) {
- if (value->type != TOKEN_BOOL)
- yyerror("invalid value");
- else {
- focus_follow = value->data.bool;
- }
- } else if (!g_ascii_strcasecmp(name, "focuslast")) {
- if (value->type != TOKEN_BOOL)
- yyerror("invalid value");
- else {
- focus_last = value->data.bool;
- }
- } else if (!g_ascii_strcasecmp(name, "focuslastondesktop")) {
- if (value->type != TOKEN_BOOL)
- yyerror("invalid value");
- else {
- focus_last_on_desktop = value->data.bool;
- }
- } else
- yyerror("invalid option");
- parse_free_token(value);
-}
-
void focus_startup()
{
/* create the window which gets focus when no clients get it. Have to
@@ -64,10 +30,6 @@ void focus_startup()
XSetWindowAttributes attrib;
focus_client = NULL;
- focus_new = TRUE;
- focus_follow = FALSE;
- focus_last = TRUE;
- focus_last_on_desktop = TRUE;
attrib.override_redirect = TRUE;
focus_backup = XCreateWindow(ob_display, ob_root,
@@ -78,8 +40,6 @@ void focus_startup()
/* start with nothing focused */
focus_set_client(NULL);
-
- parse_reg_section("focus", NULL, parse_assign);
}
void focus_shutdown()
@@ -176,8 +136,9 @@ void focus_fallback(FallbackType type)
*/
focus_set_client(NULL);
- if (!(type == Fallback_Desktop ? focus_last_on_desktop : focus_last)) {
- if (focus_follow) focus_under_pointer();
+ if (!(type == Fallback_Desktop ?
+ config_focus_last_on_desktop : config_focus_last)) {
+ if (config_focus_follow) focus_under_pointer();
return;
}
diff --git a/openbox/focus.h b/openbox/focus.h
index 3ad60682..d7f0183e 100644
--- a/openbox/focus.h
+++ b/openbox/focus.h
@@ -15,11 +15,6 @@ 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;
-/*! Focus windows when the mouse enters them */
-extern gboolean focus_follow;
-
void focus_startup();
void focus_shutdown();
diff --git a/openbox/openbox.c b/openbox/openbox.c
index 74f8164c..c4784aff 100644
--- a/openbox/openbox.c
+++ b/openbox/openbox.c
@@ -13,6 +13,7 @@
#include "plugin.h"
#include "timer.h"
#include "group.h"
+#include "config.h"
#include "gettext.h"
#include "../render/render.h"
#include "../render/font.h"
@@ -159,11 +160,12 @@ int main(int argc, char **argv)
event_startup();
grab_startup();
engine_startup();
- focus_startup();
plugin_startup();
/* load the plugins specified in the pluginrc */
plugin_loadall();
+ /* set up the kernel config shit */
+ config_startup();
/* parse/load user options */
parse_rc();
/* we're done with parsing now, kill it */
@@ -172,6 +174,7 @@ int main(int argc, char **argv)
/* load the engine specified in the rc */
engine_load();
+ focus_startup();
screen_startup();
group_startup();
client_startup();
@@ -199,6 +202,7 @@ int main(int argc, char **argv)
event_shutdown();
render_shutdown();
timer_shutdown();
+ config_shutdown();
}
dispatch_shutdown();
diff --git a/openbox/prop.c b/openbox/prop.c
index 9a448500..97f5fb94 100644
--- a/openbox/prop.c
+++ b/openbox/prop.c
@@ -265,6 +265,20 @@ gboolean prop_get_strings(Window win, Atom prop, Atom type,
return FALSE;
}
+void prop_set_strings(Window win, Atom prop, Atom type, GPtrArray *data)
+{
+ GString *str;
+ guint i;
+
+ str = g_string_sized_new(0);
+ for (i = 0; i < data->len; ++i) {
+ str = g_string_append(str, data->pdata[i]);
+ str = g_string_append_c(str, '\0');
+ }
+ XChangeProperty(ob_display, win, prop, type, 8,
+ PropModeReplace, (guchar*)str->str, str->len);
+}
+
void prop_erase(Window win, Atom prop)
{
XDeleteProperty(ob_display, win, prop);
diff --git a/openbox/screen.c b/openbox/screen.c
index 4b551b7e..49d3d22d 100644
--- a/openbox/screen.c
+++ b/openbox/screen.c
@@ -1,5 +1,6 @@
#include "openbox.h"
#include "prop.h"
+#include "config.h"
#include "screen.h"
#include "client.h"
#include "frame.h"
@@ -148,13 +149,23 @@ gboolean screen_annex()
void screen_startup()
{
+ GSList *it;
+
screen_desktop_names = g_ptr_array_new();
/* get the initial size */
screen_resize();
+ /* set the names */
+ for (it = config_desktops_names; it; it = it->next)
+ g_ptr_array_add(screen_desktop_names, it->data); /* dont strdup */
+ PROP_SETSA(ob_root, net_desktop_names, utf8, screen_desktop_names);
+ g_ptr_array_set_size(screen_desktop_names, 0); /* rm the ptrs so they dont
+ get frees when we
+ update the desktop
+ names */
screen_num_desktops = 0;
- screen_set_num_desktops(4);
+ screen_set_num_desktops(config_desktops_num);
screen_desktop = 0;
screen_set_desktop(0);