no more hidden (and mysterious) config reloads and allow binding a key

to a config reload; CMS-r by default.

ok oga@
This commit is contained in:
okan 2008-07-11 15:18:29 +00:00
parent 8be175b175
commit 6ea4b1bd3b
6 changed files with 13 additions and 27 deletions

View File

@ -425,7 +425,6 @@ void conf_unbind(struct conf *, struct keybinding *);
void conf_mousebind(struct conf *, char *, char *); void conf_mousebind(struct conf *, char *, char *);
void conf_mouseunbind(struct conf *, struct mousebinding *); void conf_mouseunbind(struct conf *, struct mousebinding *);
void conf_grab_mouse(struct client_ctx *); void conf_grab_mouse(struct client_ctx *);
int conf_changed(char *);
void conf_reload(struct conf *); void conf_reload(struct conf *);
void conf_font(struct conf *); void conf_font(struct conf *);
@ -444,6 +443,7 @@ void kbfunc_client_nogroup(struct client_ctx *, void *);
void kbfunc_client_grouptoggle(struct client_ctx *, void *); void kbfunc_client_grouptoggle(struct client_ctx *, void *);
void kbfunc_client_maximize(struct client_ctx *, void *); void kbfunc_client_maximize(struct client_ctx *, void *);
void kbfunc_client_vmaximize(struct client_ctx *, void *); void kbfunc_client_vmaximize(struct client_ctx *, void *);
void kbfunc_reload(struct client_ctx *, void *);
void kbfunc_quit_wm(struct client_ctx *, void *); void kbfunc_quit_wm(struct client_ctx *, void *);
void kbfunc_moveresize(struct client_ctx *, void *); void kbfunc_moveresize(struct client_ctx *, void *);
void kbfunc_menu_search(struct client_ctx *, void *); void kbfunc_menu_search(struct client_ctx *, void *);

22
conf.c
View File

@ -61,29 +61,9 @@ conf_font(struct conf *c)
c->FontHeight = font_ascent() + font_descent() + 1; c->FontHeight = font_ascent() + font_descent() + 1;
} }
int
conf_changed(char *path)
{
static struct timespec old_ts;
struct stat sb;
int changed;
/* If the file does not exist we pretend that nothing changed */
if (stat(path, &sb) == -1 || !(sb.st_mode & S_IFREG))
return (0);
changed = !timespeccmp(&sb.st_mtimespec, &old_ts, ==);
old_ts = sb.st_mtimespec;
return (changed);
}
void void
conf_reload(struct conf *c) conf_reload(struct conf *c)
{ {
if (!conf_changed(c->conf_path))
return;
if (parse_config(c->conf_path, c) == -1) { if (parse_config(c->conf_path, c) == -1) {
warnx("config file %s has errors, not reloading", c->conf_path); warnx("config file %s has errors, not reloading", c->conf_path);
return; return;
@ -132,6 +112,7 @@ conf_init(struct conf *c)
conf_bindname(c, "CM-g", "grouptoggle"); conf_bindname(c, "CM-g", "grouptoggle");
conf_bindname(c, "CM-f", "maximize"); conf_bindname(c, "CM-f", "maximize");
conf_bindname(c, "CM-equal", "vmaximize"); conf_bindname(c, "CM-equal", "vmaximize");
conf_bindname(c, "CMS-r", "reload");
conf_bindname(c, "CMS-q", "quit"); conf_bindname(c, "CMS-q", "quit");
conf_bindname(c, "M-h", "moveleft"); conf_bindname(c, "M-h", "moveleft");
@ -254,6 +235,7 @@ struct {
{ "grouptoggle", kbfunc_client_grouptoggle, KBFLAG_NEEDCLIENT, 0}, { "grouptoggle", kbfunc_client_grouptoggle, KBFLAG_NEEDCLIENT, 0},
{ "maximize", kbfunc_client_maximize, KBFLAG_NEEDCLIENT, 0 }, { "maximize", kbfunc_client_maximize, KBFLAG_NEEDCLIENT, 0 },
{ "vmaximize", kbfunc_client_vmaximize, KBFLAG_NEEDCLIENT, 0 }, { "vmaximize", kbfunc_client_vmaximize, KBFLAG_NEEDCLIENT, 0 },
{ "reload", kbfunc_reload, 0, 0 },
{ "quit", kbfunc_quit_wm, 0, 0 }, { "quit", kbfunc_quit_wm, 0, 0 },
{ "exec", kbfunc_exec, 0, (void *)CWM_EXEC_PROGRAM }, { "exec", kbfunc_exec, 0, (void *)CWM_EXEC_PROGRAM },
{ "exec_wm", kbfunc_exec, 0, (void *)CWM_EXEC_WM }, { "exec_wm", kbfunc_exec, 0, (void *)CWM_EXEC_WM },

2
cwm.1
View File

@ -112,6 +112,8 @@ Spawn
dialog; allows you to switch from dialog; allows you to switch from
.Nm .Nm
to another window manager without restarting the X server. to another window manager without restarting the X server.
.It Ic C-M-S-r
Reload configuration.
.It Ic C-M-S-q .It Ic C-M-S-q
Quit cwm. Quit cwm.
.El .El

View File

@ -206,6 +206,8 @@ mousebind M-3 window_resize
.Ed .Ed
.Sh BIND COMMAND LIST .Sh BIND COMMAND LIST
.Bl -tag -width 18n -compact .Bl -tag -width 18n -compact
.It reload
reload configuration
.It quit .It quit
quit quit
.Xr cwm 1 .Xr cwm 1

View File

@ -168,7 +168,6 @@ kbfunc_menu_search(struct client_ctx *scratch, void *arg)
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
conf_reload(&Conf);
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
XCALLOC(mi, struct menu); XCALLOC(mi, struct menu);
strlcpy(mi->text, cmd->label, sizeof(mi->text)); strlcpy(mi->text, cmd->label, sizeof(mi->text));
@ -215,14 +214,12 @@ kbfunc_cmdexec(struct client_ctx *cc, void *arg)
void void
kbfunc_term(struct client_ctx *cc, void *arg) kbfunc_term(struct client_ctx *cc, void *arg)
{ {
conf_reload(&Conf);
u_spawn(Conf.termpath); u_spawn(Conf.termpath);
} }
void void
kbfunc_lock(struct client_ctx *cc, void *arg) kbfunc_lock(struct client_ctx *cc, void *arg)
{ {
conf_reload(&Conf);
u_spawn(Conf.lockpath); u_spawn(Conf.lockpath);
} }
@ -393,7 +390,6 @@ kbfunc_ssh(struct client_ctx *scratch, void *arg)
if ((mi = menu_filter(&menuq, "ssh", NULL, 1, if ((mi = menu_filter(&menuq, "ssh", NULL, 1,
search_match_exec, NULL)) != NULL) { search_match_exec, NULL)) != NULL) {
conf_reload(&Conf);
l = snprintf(cmd, sizeof(cmd), "%s -e ssh %s", Conf.termpath, l = snprintf(cmd, sizeof(cmd), "%s -e ssh %s", Conf.termpath,
mi->text); mi->text);
if (l != -1 && l < sizeof(cmd)) if (l != -1 && l < sizeof(cmd))
@ -482,3 +478,9 @@ kbfunc_quit_wm(struct client_ctx *cc, void *arg)
{ {
_xev_quit = 1; _xev_quit = 1;
} }
void
kbfunc_reload(struct client_ctx *cc, void *arg)
{
conf_reload(&Conf);
}

View File

@ -113,8 +113,6 @@ mousefunc_menu_cmd(struct client_ctx *cc, void *arg)
struct menu_q menuq; struct menu_q menuq;
struct cmd *cmd; struct cmd *cmd;
conf_reload(&Conf);
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
XCALLOC(mi, struct menu); XCALLOC(mi, struct menu);