JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Mention French keyboard conf file
[spectrwm.git] / scrotwm.c
index 862077f..d15a6e6 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
  * DEALINGS IN THE SOFTWARE.
  */
 
-static const char      *cvstag =
-    "$scrotwm$";
-
-#define        SWM_VERSION     "0.9.34"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <err.h>
@@ -92,6 +87,14 @@ static const char    *cvstag =
 #include <osx.h>
 #endif
 
+#include "version.h"
+
+#ifdef SCROTWM_BUILDSTR
+static const char      *buildstr = SCROTWM_BUILDSTR;
+#else
+static const char      *buildstr = SCROTWM_VERSION;
+#endif
+
 #if RANDR_MAJOR < 1
 #  error XRandR versions less than 1.0 are not supported
 #endif
@@ -162,6 +165,9 @@ u_int32_t           swm_debug = 0
 #define SWM_FOCUS_SYNERGY      (1)
 #define SWM_FOCUS_FOLLOW       (2)
 
+#define SWM_CONF_DEFAULT       (0)
+#define SWM_CONF_KEYMAPPING    (1)
+
 #ifndef SWM_LIB
 #define SWM_LIB                        "/usr/local/lib/libswmhack.so"
 #endif
@@ -236,6 +242,7 @@ int                 bar_fidx = 0;
 XFontStruct            *bar_fs;
 char                   *bar_fonts[] = { NULL, NULL, NULL, NULL };/* XXX Make fully dynamic */
 char                   *spawn_term[] = { NULL, NULL };         /* XXX Make fully dynamic */
+struct passwd          *pwd;
 
 #define SWM_MENU_FN    (2)
 #define SWM_MENU_NB    (4)
@@ -321,6 +328,8 @@ void        new_region(struct swm_screen *, int, int, int, int);
 void   unmanage_window(struct ws_win *);
 long   getstate(Window);
 
+int    conf_load(char *, int);
+
 struct layout {
        void            (*l_stack)(struct workspace *, struct swm_geometry *);
        void            (*l_config)(struct workspace *, int);
@@ -1534,8 +1543,8 @@ version(struct swm_region *r, union arg *args)
 {
        bar_version = !bar_version;
        if (bar_version)
-               snprintf(bar_vertext, sizeof bar_vertext, "Version: %s CVS: %s",
-                   SWM_VERSION, cvstag);
+               snprintf(bar_vertext, sizeof bar_vertext, "Version: %s Build: %s",
+                   SCROTWM_VERSION, buildstr);
        else
                strlcpy(bar_vertext, "", sizeof bar_vertext);
        bar_update();
@@ -4383,6 +4392,37 @@ setup_keys(void)
 }
 
 void
+clear_keys(void)
+{
+       int                     i;
+
+       /* clear all key bindings, if any */
+       for (i = 0; i < keys_length; i++)
+               free(keys[i].spawn_name);
+       keys_length = 0;
+}
+
+int
+setkeymapping(char *selector, char *value, int flags)
+{
+       char                    keymapping_file[PATH_MAX];
+       DNPRINTF(SWM_D_KEY, "setkeymapping: enter\n");
+       if (value[0] == '~')
+               snprintf(keymapping_file, sizeof keymapping_file, "%s/%s",
+                   pwd->pw_dir, &value[1]);
+       else
+               strlcpy(keymapping_file, value, sizeof keymapping_file);
+       clear_keys();
+       /* load new key bindings; if it fails, revert to default bindings */
+       if (conf_load(keymapping_file, SWM_CONF_KEYMAPPING)) {
+               clear_keys();
+               setup_keys();
+       }
+       DNPRINTF(SWM_D_KEY, "setkeymapping: leave\n");
+       return (0);
+}
+
+void
 updatenumlockmask(void)
 {
        unsigned int            i, j;
@@ -4906,6 +4946,7 @@ struct config_option configopt[] = {
        { "bar_font",                   setconfvalue,   SWM_S_BAR_FONT },
        { "bar_action",                 setconfvalue,   SWM_S_BAR_ACTION },
        { "bar_delay",                  setconfvalue,   SWM_S_BAR_DELAY },
+       { "keyboard_mapping",           setkeymapping,  0 },
        { "bind",                       setconfbinding, 0 },
        { "stack_enabled",              setconfvalue,   SWM_S_STACK_ENABLED },
        { "clock_enabled",              setconfvalue,   SWM_S_CLOCK_ENABLED },
@@ -4937,7 +4978,7 @@ struct config_option configopt[] = {
 
 
 int
-conf_load(char *filename)
+conf_load(char *filename, int keymapping)
 {
        FILE                    *config;
        char                    *line, *cp, *optsub, *optval;
@@ -4952,7 +4993,7 @@ conf_load(char *filename)
                return (1);
        }
        if ((config = fopen(filename, "r")) == NULL) {
-               warn("conf_load: fopen");
+               warn("conf_load: fopen: %s", filename);
                return (1);
        }
 
@@ -4992,6 +5033,11 @@ conf_load(char *filename)
                            filename, lineno, wordlen, cp);
                        return (1);
                }
+               if (keymapping && strcmp(opt->optname, "bind")) {
+                       warnx("%s: line %zd: invalid option %.*s",
+                           filename, lineno, wordlen, cp);
+                       return (1);
+               }
                cp += wordlen;
                cp += strspn(cp, " \t\n"); /* eat whitespace */
                /* get [selector] if any */
@@ -6266,7 +6312,6 @@ workaround(void)
 int
 main(int argc, char *argv[])
 {
-       struct passwd           *pwd;
        struct swm_region       *r, *rr;
        struct ws_win           *winfocus = NULL;
        struct timeval          tv;
@@ -6279,8 +6324,8 @@ main(int argc, char *argv[])
        struct sigaction        sact;
 
        start_argv = argv;
-       fprintf(stderr, "Welcome to scrotwm V%s cvs tag: %s\n",
-           SWM_VERSION, cvstag);
+       fprintf(stderr, "Welcome to scrotwm V%s Build: %s\n",
+           SCROTWM_VERSION, buildstr);
        if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
                warnx("no locale support");
 
@@ -6337,7 +6382,7 @@ main(int argc, char *argv[])
                                cfile = conf;
        }
        if (cfile)
-               conf_load(cfile);
+               conf_load(cfile, SWM_CONF_DEFAULT);
 
        setup_ewmh();
        /* set some values to work around bad programs */