mixu / nwm

Tiling window manager for X11 written in Node.js
http://mixu.net/nwm/
MIT License
788 stars 72 forks source link

Short-cut Problems #29

Closed trans closed 12 years ago

trans commented 12 years ago

Hi, I am trying to redefine some of the short-cuts, and I can't get some of them to work.

First, I am trying to get dmenu to run. I added:

    {
      key: 'Menu',  // launches dmenu
      callback: function(event) {
        child_process.spawn('dmenu_run', ['-bi'], { env: process.env });
      }
    },

I tried a number of alternatives to Menu, including slash, backslash and Insert, but none worked.

Another is trying to use Alt_L in place of shift for moving windows to other workspaces.

  {
    key: [1, 2, 3, 4, 5, 6, 7, 8, 9], // with left alt, move windows between workspaces
    modifier: [ 'alt_l' ],
    callback: function(event) {
      var monitor = currentMonitor();
      monitor.windowTo(monitor.focused_window, String.fromCharCode(event.keysym));
    }
  },

I tried alt_l and Alt_L. I'm thinking that maybe the event.keysym is changed by using alt? Or is it something more fundamental?

mixu commented 12 years ago

Have a look here, this is where the friendly syntax gets turned into key bindings (which are registered on in X11 almost directly):

https://github.com/mixu/nwm/blob/master/nwm-user-sample.js#L168

which goes through a few calls and becomes a X11 call here : https://github.com/mixu/nwm/blob/master/src/nwm/nwm.c#L211

Basically you can more directly register a shortcut via:

nwm.addKey({ key: (X11 keysym int), modifier: (X11 modifier bitmask) }, callback);

Key names to ints lookup is from the XK array, which is defined here: https://github.com/mixu/nwm/blob/master/lib/keysymdef.js

You can find the X11 keysym corresponding to a key using xev.

Only "shift" and "ctrl" are supported as modifiers by name, however, you could use the other modifiers (mod keys) listed in https://github.com/mixu/nwm/blob/master/lib/x.js

The bitmask is something like:

var mask = Xh.Mod4Mask|Xh.ShiftMask|Xh.ControlMask;

X11 doesn't have a fixed "alt" key modifier, it refers to modifier keys other than shift and ctrl as Mod1 ... Mod5 and those must be bound by the user. You can run xmodmap to find out what your mod keys are (and google for configuration):

xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

Closing this as "not a bug".

trans commented 12 years ago

Thanks. It wasn't easy but I was able to work it out. To help I added:

    (shortcut.modifier.indexOf('alt') > -1) && (modifier = modifier|Xh.Mod1Mask);

It doesn't limit it too just left alt, but it's good enough, at least for now.

Also, I added a wiki pages called "Launchers" with a section for "dmenu".