JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
new keyboard_mapping option to load pre-defined key bindings for
authorLawrence Teo <lteo@devio.us>
Wed, 26 Oct 2011 02:40:12 +0000 (22:40 -0400)
committerLawrence Teo <lteo@devio.us>
Wed, 26 Oct 2011 02:42:57 +0000 (22:42 -0400)
different keyboard layouts

ok marco

scrotwm.1
scrotwm.c
scrotwm.conf

index cb691c5..d6a0099 100644 (file)
--- a/scrotwm.1
+++ b/scrotwm.1
@@ -120,6 +120,11 @@ script.
 Some applications have dialogue windows that are too small to be useful.
 This ratio is the screen size to what they will be resized.
 For example, 0.6 is 60% of the physical screen size.
 Some applications have dialogue windows that are too small to be useful.
 This ratio is the screen size to what they will be resized.
 For example, 0.6 is 60% of the physical screen size.
+.It Cm keyboard_mapping
+Clear all key bindings and load new key bindings from the specified file.
+This allows you to load pre-defined key bindings for your keyboard layout.
+At present, keyboard mapping files for the US and Spanish keyboards are
+provided in scrotwm_us.conf and scrotwm_es.conf respectively.
 .It Cm layout
 Select layout to use at start-of-day.
 Defined in the format
 .It Cm layout
 Select layout to use at start-of-day.
 Defined in the format
index 862077f..47e7319 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
@@ -162,6 +162,9 @@ u_int32_t           swm_debug = 0
 #define SWM_FOCUS_SYNERGY      (1)
 #define SWM_FOCUS_FOLLOW       (2)
 
 #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
 #ifndef SWM_LIB
 #define SWM_LIB                        "/usr/local/lib/libswmhack.so"
 #endif
@@ -236,6 +239,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 */
 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)
 
 #define SWM_MENU_FN    (2)
 #define SWM_MENU_NB    (4)
@@ -321,6 +325,8 @@ void        new_region(struct swm_screen *, int, int, int, int);
 void   unmanage_window(struct ws_win *);
 long   getstate(Window);
 
 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);
 struct layout {
        void            (*l_stack)(struct workspace *, struct swm_geometry *);
        void            (*l_config)(struct workspace *, int);
@@ -4383,6 +4389,37 @@ setup_keys(void)
 }
 
 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;
 updatenumlockmask(void)
 {
        unsigned int            i, j;
@@ -4906,6 +4943,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 },
        { "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 },
        { "bind",                       setconfbinding, 0 },
        { "stack_enabled",              setconfvalue,   SWM_S_STACK_ENABLED },
        { "clock_enabled",              setconfvalue,   SWM_S_CLOCK_ENABLED },
@@ -4937,7 +4975,7 @@ struct config_option configopt[] = {
 
 
 int
 
 
 int
-conf_load(char *filename)
+conf_load(char *filename, int keymapping)
 {
        FILE                    *config;
        char                    *line, *cp, *optsub, *optval;
 {
        FILE                    *config;
        char                    *line, *cp, *optsub, *optval;
@@ -4952,7 +4990,7 @@ conf_load(char *filename)
                return (1);
        }
        if ((config = fopen(filename, "r")) == NULL) {
                return (1);
        }
        if ((config = fopen(filename, "r")) == NULL) {
-               warn("conf_load: fopen");
+               warn("conf_load: fopen: %s", filename);
                return (1);
        }
 
                return (1);
        }
 
@@ -4992,6 +5030,11 @@ conf_load(char *filename)
                            filename, lineno, wordlen, cp);
                        return (1);
                }
                            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 */
                cp += wordlen;
                cp += strspn(cp, " \t\n"); /* eat whitespace */
                /* get [selector] if any */
@@ -6266,7 +6309,6 @@ workaround(void)
 int
 main(int argc, char *argv[])
 {
 int
 main(int argc, char *argv[])
 {
-       struct passwd           *pwd;
        struct swm_region       *r, *rr;
        struct ws_win           *winfocus = NULL;
        struct timeval          tv;
        struct swm_region       *r, *rr;
        struct ws_win           *winfocus = NULL;
        struct timeval          tv;
@@ -6337,7 +6379,7 @@ main(int argc, char *argv[])
                                cfile = conf;
        }
        if (cfile)
                                cfile = conf;
        }
        if (cfile)
-               conf_load(cfile);
+               conf_load(cfile, SWM_CONF_DEFAULT);
 
        setup_ewmh();
        /* set some values to work around bad programs */
 
        setup_ewmh();
        /* set some values to work around bad programs */
index 2bc0fcc..ae06e3b 100644 (file)
@@ -57,73 +57,9 @@ dialog_ratio         = 0.6
 # mod key, (windows key is Mod4) (apple key on OSX is Mod2)
 # modkey = Mod1
 
 # mod key, (windows key is Mod4) (apple key on OSX is Mod2)
 # modkey = Mod1
 
-# key bindings
-# unbind with: bind[] = <keys>
-#bind[cycle_layout]    = MOD+space
-#bind[stack_reset]     = MOD+Shift+space
-#bind[master_shrink]   = MOD+h
-#bind[master_grow]     = MOD+l
-#bind[master_add]      = MOD+comma
-#bind[master_del]      = MOD+period
-#bind[stack_inc]               = MOD+Shift+comma
-#bind[stack_dec]               = MOD+Shift+period
-#bind[swap_main]               = MOD+Return
-#bind[focus_next]      = MOD+j
-#bind[focus_prev]      = MOD+k
-#bind[swap_next]               = MOD+Shift+j
-#bind[swap_prev]               = MOD+Shift+k
-#bind[spawn_term]      = MOD+Shift+Return
-#bind[menu]            = MOD+p
-#bind[quit]            = MOD+Shift+q
-#bind[restart]         = MOD+q
-#bind[focus_main]      = MOD+m
-#bind[ws_1]            = MOD+1
-#bind[ws_2]            = MOD+2
-#bind[ws_3]            = MOD+3
-#bind[ws_4]            = MOD+4
-#bind[ws_5]            = MOD+5
-#bind[ws_6]            = MOD+6
-#bind[ws_7]            = MOD+7
-#bind[ws_8]            = MOD+8
-#bind[ws_9]            = MOD+9
-#bind[ws_10]           = MOD+0
-#bind[ws_next]         = MOD+Right
-#bind[ws_prev]         = MOD+Left
-#bind[screen_next]     = MOD+Shift+Right
-#bind[screen_prev]     = MOD+Shift+Left
-#bind[mvws_1]          = MOD+Shift+1
-#bind[mvws_2]          = MOD+Shift+2
-#bind[mvws_3]          = MOD+Shift+3
-#bind[mvws_4]          = MOD+Shift+4
-#bind[mvws_5]          = MOD+Shift+5
-#bind[mvws_6]          = MOD+Shift+6
-#bind[mvws_7]          = MOD+Shift+7
-#bind[mvws_8]          = MOD+Shift+8
-#bind[mvws_9]          = MOD+Shift+9
-#bind[mvws_10]         = MOD+Shift+0
-#bind[bar_toggle]      = MOD+b
-#bind[focus_next]      = MOD+Tab
-#bind[focus_prev]      = MOD+Shift+Tab
-#bind[wind_kill]               = MOD+Shift+x
-#bind[wind_del]                = MOD+x
-#bind[screenshot_all]  = MOD+s
-#bind[screenshot_wind] = MOD+Shift+s
-#bind[float_toggle]    = MOD+t
-#bind[version]         = MOD+Shift+v
-#bind[lock]            = MOD+Shift+Delete
-#bind[initscr]         = MOD+Shift+i
-#bind[iconify]         = MOD+w
-#bind[uniconify]       = MOD+Shift+w
-#bind[raise_toggle]    = MOD+Shift+r
-#bind[button2]         = MOD+v
-#bind[width_shrink]    = MOD+minus
-#bind[width_grow]      = MOD+equal
-#bind[height_shrink]   = MOD+Shift+minus
-#bind[height_grow]     = MOD+Shift+equal
-#bind[move_left]       = MOD+bracketleft
-#bind[move_right]      = MOD+bracketright
-#bind[move_up]         = MOD+Shift+bracketleft
-#bind[move_down]       = MOD+Shift+bracketright
+# Clear key bindings and load new key bindings from the specified file.
+# This allows you to load pre-defined key bindings for your keyboard layout.
+# keyboard_mapping = ~/.scrotwm_us.conf
 
 # quirks
 # remove with: quirk[class:name] = NONE
 
 # quirks
 # remove with: quirk[class:name] = NONE