Skip to content

Commit

Permalink
Merge pull request #436 from joewing/defaults
Browse files Browse the repository at this point in the history
Configuration defaults.
  • Loading branch information
joewing authored Mar 27, 2018
2 parents e4b4341 + f4a0279 commit ef68a68
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ VPATH=.:os

OBJECTS = action.o background.o binding.o border.o button.o client.o \
clientlist.o clock.o color.o command.o confirm.o cursor.o debug.o \
desktop.o dock.o event.o error.o font.o grab.o gradient.o group.o \
help.o hint.o icon.o image.o lex.o main.o match.o menu.o misc.o \
default.o desktop.o dock.o event.o error.o font.o grab.o gradient.o \
group.o help.o hint.o icon.o image.o lex.o main.o match.o menu.o misc.o \
move.o outline.o pager.o parse.o place.o popup.o render.o resize.o \
root.o screen.o settings.o spacer.o status.o swallow.o taskbar.o \
timing.o tray.o traybutton.o winmenu.o
Expand Down
4 changes: 2 additions & 2 deletions src/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ static const DefaultColorNode DEFAULT_COLORS[] = {
{ COLOR_TASKLIST_BG1, THEME_INACTIVE },
{ COLOR_TASKLIST_BG2, THEME_INACTIVE },
{ COLOR_TASKLIST_ACTIVE_FG, THEME_TEXT },
{ COLOR_TASKLIST_ACTIVE_BG1, THEME_INACTIVE },
{ COLOR_TASKLIST_ACTIVE_BG2, THEME_INACTIVE },
{ COLOR_TASKLIST_ACTIVE_BG1, THEME_ACTIVE },
{ COLOR_TASKLIST_ACTIVE_BG2, THEME_ACTIVE },

{ COLOR_TRAYBUTTON_FG, THEME_TEXT },
{ COLOR_TRAYBUTTON_BG1, THEME_INACTIVE },
Expand Down
55 changes: 55 additions & 0 deletions src/default.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @file default.c
* @author Joe Wingbermuehle
* @date 2017
*
* @brief Default configuration.
*
*/

#include "default.h"

const char * const BASE_CONFIG =
"<JWM>"
"<Key key=\"Up\">up</Key>"
"<Key key=\"Down\">down</Key>"
"<Key key=\"Right\">right</Key>"
"<Key key=\"Left\">left</Key>"
"<Key key=\"Return\">select</Key>"
"<Key key=\"Escape\">escape</Key>"
"<Key mask=\"A\" key=\"Tab\">nextstacked</Key>"
"<Key mask=\"A\" key=\"F4\">close</Key>"
"<Mouse context=\"title\" button=\"1\">move</Mouse>"
"<Mouse context=\"title\" button=\"2\">move</Mouse>"
"<Mouse context=\"title\" button=\"3\">window</Mouse>"
"<Mouse context=\"title\" button=\"11\">maximize</Mouse>"
"<Mouse context=\"icon\" button=\"1\">window</Mouse>"
"<Mouse context=\"icon\" button=\"2\">move</Mouse>"
"<Mouse context=\"icon\" button=\"3\">window</Mouse>"
"<Mouse context=\"border\" button=\"1\">resize</Mouse>"
"<Mouse context=\"border\" button=\"2\">move</Mouse>"
"<Mouse context=\"border\" button=\"3\">window</Mouse>"
"<Mouse context=\"close\" button=\"-1\">close</Mouse>"
"<Mouse context=\"close\" button=\"2\">move</Mouse>"
"<Mouse context=\"close\" button=\"-3\">close</Mouse>"
"<Mouse context=\"maximize\" button=\"-1\">maximize</Mouse>"
"<Mouse context=\"maximize\" button=\"-2\">maxv</Mouse>"
"<Mouse context=\"maximize\" button=\"-3\">maxh</Mouse>"
"<Mouse context=\"minimize\" button=\"-1\">minimize</Mouse>"
"<Mouse context=\"minimize\" button=\"2\">move</Mouse>"
"<Mouse context=\"minimize\" button=\"-3\">shade</Mouse>"
"</JWM>"
;

const char * const DEFAULT_CONFIG =
"<JWM>"
"<RootMenu onroot=\"1\">"
"<Program>xterm</Program>"
"<Restart/>"
"<Exit/>"
"</RootMenu>"
"<Tray x=\"0\" y=\"-1\">"
"<Pager/><TaskList/><Dock/><Clock/>"
"</Tray>"
"</JWM>"
;
19 changes: 19 additions & 0 deletions src/default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file default.h
* @author Joe Wingbermuehle
* @date 2017
*
* @brief Default configuration.
*
*/

#ifndef DEFAULT_H
#define DEFAULT_H

/** Base configuration that is always included first. */
extern const char * const BASE_CONFIG;

/** A default configuration that is included if no configuration is found. */
extern const char * const DEFAULT_CONFIG;

#endif /* DEFAULT_H */
30 changes: 20 additions & 10 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "spacer.h"
#include "desktop.h"
#include "border.h"
#include "default.h"

#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -167,6 +168,7 @@ static const char * const CONFIG_FILES[] = {
};
static const unsigned CONFIG_FILE_COUNT = ARRAY_LENGTH(CONFIG_FILES);

static void ParseInternal(const char *config);
static char ParseFile(const char *fileName, int depth);
static TokenNode *TokenizeFile(const char *fileName);
static TokenNode *TokenizePipe(const char *command, unsigned timeout_ms);
Expand Down Expand Up @@ -250,27 +252,35 @@ static StatusWindowType ParseStatusWindowType(const TokenNode *tp);
static void InvalidTag(const TokenNode *tp, TokenType parent);
static void ParseError(const TokenNode *tp, const char *str, ...);

/** Parse the default configuration. */
void ParseInternal(const char *config)
{
TokenNode *tokens = Tokenize(config, "");
Parse(tokens, 0);
ReleaseTokens(tokens);
}

/** Parse the JWM configuration. */
void ParseConfig(const char *fileName)
{
ParseInternal(BASE_CONFIG);
if(fileName) {
if(!ParseFile(fileName, 0)) {
ParseError(NULL, _("could not open %s"), fileName);
ParseInternal(DEFAULT_CONFIG);
}
} else {
unsigned i;
char found = 0;
for(i = 0; i < CONFIG_FILE_COUNT; i++) {
if(ParseFile(CONFIG_FILES[i], 0)) {
found = 1;
break;
}
}
if(!found) {
unsigned i;
for(i = 0; i < CONFIG_FILE_COUNT; i++) {
if(ParseFile(CONFIG_FILES[i], 0)) {
goto ConfigFileFound;
}
}
ParseError(NULL, _("could not open %s or %s"),
CONFIG_FILES[0], SYSTEM_CONFIG);
}
ParseInternal(DEFAULT_CONFIG);
}
ConfigFileFound:
ValidateTrayButtons();
ValidateKeys();
}
Expand Down

0 comments on commit ef68a68

Please sign in to comment.