commit 7e47f1cea16741008c626fb39a1d6298064608cf
parent 1ee2efb9667af35d5e5ccfea6824701c2fdbce44
Author: William Casarin <jb55@jb55.com>
Date: Mon, 9 Jul 2018 18:49:53 -0700
move example commands to cfg.def.h
Diffstat:
4 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/cfg.def.h b/cfg.def.h
@@ -39,3 +39,22 @@ static struct scheme schemes[SchemeLast] = {
},
};
+static struct command browser_commands[] = {
+ { .bind = "s", .name = "chrome", .nchildren = 0, .children = NULL },
+ { .bind = "c", .name = "chromium", .nchildren = 0, .children = NULL },
+ { .bind = "f", .name = "firefox", .nchildren = 0, .children = NULL },
+};
+
+static const struct command commands[] = {
+ { .bind = "b",
+ .name = "browsers",
+ .nchildren = LENGTH(browser_commands),
+ .children = browser_commands
+ },
+
+ { .bind = "e",
+ .name = "emacs-dev",
+ .children = NULL,
+ .nchildren = 0
+ },
+};
diff --git a/cmdtree.c b/cmdtree.c
@@ -320,7 +320,8 @@ int main(void) {
/* parentwin = root; */
parentwin = root;
- rootcmds = test_root_commands(NULL, &ncmds);
+ ncmds = LENGTH(commands);
+ rootcmds = test_root_commands(NULL, commands, ncmds);
if (!XGetWindowAttributes(display, parentwin, &wa))
die("could not get embedding window attributes: 0x%lx",
@@ -331,7 +332,7 @@ int main(void) {
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
- /* grabkeyboard(); */
+ grabkeyboard();
setup(drw);
run(drw);
diff --git a/command.c b/command.c
@@ -40,39 +40,18 @@ command_lookup(struct command *cmd, int ncmds, const char *binding) {
/* { .bind = "d", .name = "emacs-dev", .nchildren = 0, .children = NULL }, */
/* }; */
-static struct command browser_commands[] = {
- { .bind = "s", .name = "chrome", .nchildren = 0, .children = NULL },
- { .bind = "c", .name = "chromium", .nchildren = 0, .children = NULL },
- { .bind = "f", .name = "firefox", .nchildren = 0, .children = NULL },
-};
-
-static const struct command examples[] = {
- { .bind = "b",
- .name = "browsers",
- .nchildren = LENGTH(browser_commands),
- .children = browser_commands
- },
-
- { .bind = "e",
- .name = "emacs-dev",
- .children = NULL,
- .nchildren = 0
- },
-};
-
struct command *
-test_root_commands(tal_t *ctx, int *ncmds) {
- unsigned long i;
+test_root_commands(tal_t *ctx, const struct command *commands, int ncmds) {
+ int i;
struct command *cmds = NULL;
- cmds = tal_arr(ctx, struct command, LENGTH(examples));
- *ncmds = LENGTH(examples);
+ cmds = tal_arr(ctx, struct command, ncmds);
- for (i = 0; i < LENGTH(examples); ++i) {
- cmds[i].children = examples[i].children;
- cmds[i].name = examples[i].name;
- cmds[i].bind = examples[i].bind;
- cmds[i].nchildren = examples[i].nchildren;
+ for (i = 0; i < ncmds; ++i) {
+ cmds[i].children = commands[i].children;
+ cmds[i].name = commands[i].name;
+ cmds[i].bind = commands[i].bind;
+ cmds[i].nchildren = commands[i].nchildren;
}
return cmds;
diff --git a/command.h b/command.h
@@ -25,6 +25,6 @@ struct command *
command_lookup(struct command *cmd, int ncmds, const char *binding);
struct command *
-test_root_commands(tal_t *ctx, int *ncmds);
+test_root_commands(tal_t *ctx, const struct command *commands, int ncmds);
#endif /* CMDTREE_COMMAND_H */