From c3bb58f47a9e63e32a64a0b45bd96033e6f51d83 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 16 Sep 2007 23:12:53 +0200 Subject: [PATCH] stop making awesomelibconf global and store screen number in awesome_configs we strdup elems and p_delete them in cleanup --- awesome.c | 14 +++++++++++++- config.c | 24 +++++++++++++----------- config.h | 14 ++++++++------ tag.c | 2 +- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/awesome.c b/awesome.c index 4f5f1c53..1259563c 100644 --- a/awesome.c +++ b/awesome.c @@ -56,7 +56,7 @@ static Bool readin = True, running = True; static void cleanup(Display *disp, DC *drawcontext, awesome_config *awesomeconf) { - int screen; + int screen, i; close(STDIN_FILENO); @@ -81,6 +81,18 @@ cleanup(Display *disp, DC *drawcontext, awesome_config *awesomeconf) XFreeCursor(disp, drawcontext[screen].cursor[CurNormal]); XFreeCursor(disp, drawcontext[screen].cursor[CurResize]); XFreeCursor(disp, drawcontext[screen].cursor[CurMove]); + + for(i = 0; i < awesomeconf[screen].ntags; i++) + p_delete(&awesomeconf[screen].tags[i]); + for(i = 0; i < awesomeconf[screen].nkeys; i++) + p_delete(&awesomeconf[screen].keys[i].arg); + for(i = 0; i < awesomeconf[screen].nlayouts; i++) + p_delete(&awesomeconf[screen].layouts[i].symbol); + for(i = 0; i < awesomeconf[screen].nrules; i++) + { + p_delete(&awesomeconf[screen].rules[i].prop); + p_delete(&awesomeconf[screen].rules[i].tags); + } p_delete(&awesomeconf[screen].tags); p_delete(&awesomeconf[screen].selected_tags); p_delete(&awesomeconf[screen].prev_selected_tags); diff --git a/config.c b/config.c index a724920a..c36545cb 100644 --- a/config.c +++ b/config.c @@ -37,14 +37,10 @@ #include "layouts/spiral.h" #include "layouts/floating.h" -/* static */ static void initfont(const char *, Display *, DC *); -static unsigned long initcolor(const char *colstr, Display *, int); +static unsigned long initcolor(const char *, Display *, int); static unsigned int get_numlockmask(Display *); -/** Main configuration object for parsing*/ -config_t awesomelibconf; - /** Link a name to a function */ typedef struct { @@ -176,6 +172,8 @@ set_default_config(awesome_config *awesomeconf) void parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomeconf) { + /* Main configuration object for parsing*/ + config_t awesomelibconf; config_setting_t *conftags; config_setting_t *conflayouts, *confsublayouts; config_setting_t *confrules, *confsubrules; @@ -196,6 +194,9 @@ parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomec config_init(&awesomelibconf); + /* set screen */ + awesomeconf->screen = scr; + if(config_read_file(&awesomelibconf, confpath) == CONFIG_FALSE) eprint("awesome: error parsing configuration file at line %d: %s\n", config_error_line(&awesomelibconf), config_error_text(&awesomelibconf)); @@ -223,7 +224,7 @@ parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomec awesomeconf->layouts[i].symbol = NULL; continue; } - awesomeconf->layouts[i].symbol = config_setting_get_string_elem(confsublayouts, 0); + awesomeconf->layouts[i].symbol = a_strdup(config_setting_get_string_elem(confsublayouts, 0)); j = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->layouts[i].symbol, drawcontext->font.height); if(j > awesomeconf->statusbar.width) @@ -245,14 +246,14 @@ parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomec if(!conftags) eprint("awesome: fatal: no tags found in configuration file\n"); awesomeconf->ntags = config_setting_length(conftags); - awesomeconf->tags = p_new(const char *, awesomeconf->ntags); + awesomeconf->tags = p_new(char *, awesomeconf->ntags); awesomeconf->selected_tags = p_new(Bool, awesomeconf->ntags); awesomeconf->prev_selected_tags = p_new(Bool, awesomeconf->ntags); awesomeconf->tag_layouts = p_new(Layout *, awesomeconf->ntags); for(i = 0; (tmp = config_setting_get_string_elem(conftags, i)); i++) { - awesomeconf->tags[i] = tmp; + awesomeconf->tags[i] = a_strdup(tmp); awesomeconf->selected_tags[i] = False; awesomeconf->prev_selected_tags[i] = False; /** \todo add support for default tag/layout in configuration file */ @@ -274,8 +275,8 @@ parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomec awesomeconf->rules = p_new(Rule, awesomeconf->nrules); for(i = 0; (confsubrules = config_setting_get_elem(confrules, i)); i++) { - awesomeconf->rules[i].prop = config_setting_get_string(config_setting_get_member(confsubrules, "name")); - awesomeconf->rules[i].tags = config_setting_get_string(config_setting_get_member(confsubrules, "tags")); + awesomeconf->rules[i].prop = a_strdup(config_setting_get_string(config_setting_get_member(confsubrules, "name"))); + awesomeconf->rules[i].tags = a_strdup(config_setting_get_string(config_setting_get_member(confsubrules, "tags"))); if(awesomeconf->rules[i].tags && !strlen(awesomeconf->rules[i].tags)) awesomeconf->rules[i].tags = NULL; awesomeconf->rules[i].isfloating = @@ -308,7 +309,7 @@ parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomec awesomeconf->keys[i].keysym = XStringToKeysym(config_setting_get_string_elem(confsubkeys, 1)); awesomeconf->keys[i].func = name_func_lookup(config_setting_get_string_elem(confsubkeys, 2), KeyfuncList); - awesomeconf->keys[i].arg = config_setting_get_string_elem(confsubkeys, 3); + awesomeconf->keys[i].arg = a_strdup(config_setting_get_string_elem(confsubkeys, 3)); } } @@ -370,6 +371,7 @@ parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomec tmp = config_lookup_string(&awesomelibconf, "awesome.focus_fg_color"); drawcontext->sel[ColFG] = initcolor(tmp ? tmp : "#ffffff", disp, scr); + config_destroy(&awesomelibconf); p_delete(&confpath); } diff --git a/config.h b/config.h index 58988c92..ce2c1571 100644 --- a/config.h +++ b/config.h @@ -55,8 +55,8 @@ typedef struct typedef struct { - const char *prop; - const char *tags; + char *prop; + char *tags; Bool isfloating; } Rule; @@ -64,7 +64,7 @@ typedef struct awesome_config awesome_config; typedef struct { - const char *symbol; + char *symbol; void (*arrange) (Display *, int, awesome_config *); } Layout; @@ -72,8 +72,8 @@ typedef struct { unsigned long mod; KeySym keysym; - void (*func) (Display *, int, DC *, awesome_config *, const char *); - const char *arg; + void (*func) (Display *, int, DC *, awesome_config *, char *); + char *arg; } Key; /** Status bar */ @@ -96,8 +96,10 @@ typedef struct /** Main configuration structure */ struct awesome_config { + /** Config screen number */ + int screen; /** Tag list */ - const char **tags; + char **tags; /** Selected tags */ Bool *selected_tags; /* Previously selected tags */ diff --git a/tag.c b/tag.c index 81452bfb..0fe70bba 100644 --- a/tag.c +++ b/tag.c @@ -36,7 +36,7 @@ static Regs *regs = NULL; * \return index of tag */ static int -idxoftag(const char *tag_to_find, const char **tags, int ntags) +idxoftag(const char *tag_to_find, char **tags, int ntags) { int i;