• You are not logged in.

    Creating a Virtual Modal Interface (X/ Linux)

    • Started by angelic_sedition
    • 15 Replies:
    • Reputation: 0
    • Registered: 11-Oct-2013
    • Posts: 79

    Artificial Modal Bindings for Any Program

    Since I'm pretty used to using modal programs, it's always annoying when I have to use something that doesn't have customizable keyboard shortcuts or a modal interface. For example, most of my text input is done in vim or with pentadactyl's modal interface for text entry boxes, but sometimes I have to use Libre Office/ Open Office. Having a navigation layer can help with selection and movement, but it's really not nearly as easy as just using single keypresses like in vim.

    Today I decided to try to simulate a modal interface. The result is actually totally usable and works pretty well. It obsoletes a lot of functionality of a navigation layer in certain instances. For example, it makes it so that it doesn't really matter that it's not easy to map control inside a normal layer. Selecting text and copying or cutting text can now be as simple as entering a virtual visual mode and jumping by words or lines with w and n and e instead of all the keys that would need to be pressed to do this normally.

    As a test, I decided to set up modes for Libre Writer. They'll work for anything that takes the same generic shortcuts though. What I think might be really interesting is to do something like this for photoshop or the GIMP. This idea could potentially be used for any gui program with no modal mappings but a bunch of control alt shift nonsense (i.e. file manager, music player .. it could even be used to bolster vimium so that d would work on something like a new tab).

    Video Demonstration
    https://www.youtube.com/watch?v=iB1fCASlpY8

    Successfully Tested Features:
    •hnei and basic navigation
    •gg and G
    •things taking a count (i.e 10dw is possible; 10j is possible; setup is long though)
    •copy, cut, and paste (y(..), d(w,d,etc.), p)
    •saving, undoing, searching, etc.
    •visual mode
    •visual block mode
    •pretty much anything that can be done with default keyboard shortcuts (in this case: https://help.libreoffice.org/Writer/Sho … or_Writer)

    The basic principle is to use a hotkey program to fake keyboard input in order to map single letters to longer keyboard shortcuts involving things like shift and control.

    Tools:
    •sxhkd or xchainkeys (for binding and modes)*
    •something like xdo, xdotool, xvkbd, xte, etc. (for faking keyboard input)

    I've found the best way is to use xchainkeys and xsendkey (and a bit of xdotool and xte as workarounds for staying in the modes).
    * However xpybind might be even a better way to do it (have not tried)

    Sxhkd v xchainkeys:
    Both programs can be used to enter modes using a hotkey where all keyboard input is captured and interpreted based on your bindings. The main downside of sxhkd that makes it not really usable is that once you reach a certain depth, letters can't be reused (i.e. you can't move by word with w and delete word with dw; binding something to dw at this depth will result in just using the previous depth w/moving forward by a word). The other problem is that escaping isn't customizable (meaning that Escape will always exit the mode entirely). Xchainkeys, on the other hand, allows for pretty much unlimited depth and the ability to set up a specific key to abort the chain. This means that a specific key like q (or i.. for insert) can be chosen to exit normal mode and Escape can be used to return to normal mode from visual mode for example. It should be noted, however, that if abort is set to automatic, then any keys that are not bound for that depth will exit the chain.

    The only downside of xchainkeys is that fact that if abort is set to manual, that the popup showing the keys pressed will always stay visible. This does NOT effect the bindings (they still work), but it makes the cursor invisible in Libre (and you might find it annoying, but it's pretty small). What I've done to make the cursor somewhat visible when moving in "normal mode" is to turn abort to automatic and set it up to reenter the mode after every hotkey (which is why you'll see a bunch of these: " && xdotool key super+o"). This is the only thing that sxhkd has over xchainkeys (cursor remains visible).

    My decision to use super+o (W-o) was totally random. I'd recommend a dedicated key. You can use symbols on layers to enter modes, but they cause hitting that key unmodified to glitch up.

    I think I'm using xdotool to send the re-entering keypresses because xchainkeys will interpret keys sent by it but not by xsendkey, but I'm tired and don't really remember.

    For more information about xchainkeys (basic syntax): https://code.google.com/p/xchainkeys/

    Sxhkd and xchainkeys have a lot of other cool possibilities for use including setting up virtual layers (because anything below 100 is not enough) and virtual modifiers (any symbol can act as a prefix key or load a layer/mode and lock it; i.e. hotkey to either load an xmodmap configuration file or a virtual layer for gaming with wasd/esdf) and layer and keyboard locks.

    Here's what a basic implementation of this concept for Libre Office looks like (my ~/.config/xchainkeys/xcainkeys.conf):
    It's pretty much self explanatory for the most part and commented. Let me know what you think.

    ## License
    ## This software is licensed under the CC0 1.0 Public Domain Declaration, as
    ## released by Creative Commons <https://creativecommons.org/publicdomain/zero/1.0/>.
    
    ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
    ## WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
    ## THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    ## NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
    ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    ## (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    ## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    ## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
    W-o :enter timeout=0 abort=automatic
    W-o r :reload
    
    # to do without gui popup, have to re-enter the mode at the end of every command like so:
    # W-o h :exec xsendkey Left && xdotool key super+o
    # benefit is that cursor doesn't totally dissapear
    
    # Normal Mode {{{
    # let escape act as normal and don't exit
    W-o q :abort
    W-o Escape :exec xsendkey Escape && xdotool key super+o
    W-o Mode_switch :exec xdotool key Escape && xdotool key super+o
    
    # basic movement
    W-o h :exec xsendkey Left && xdotool key super+o
    W-o n :exec xsendkey Down && xdotool key super+o
    W-o e :exec xsendkey Up && xdotool key super+o
    W-o i :exec xsendkey Right && xdotool key super+o
    
    # take a count; could add for everything
    W-o 5 e :exec xsendkey Up && xsendkey Up && xsendkey Up && xsendkey Up && xsendkey Up && xdotool key super+o
    
    # by word
    W-o w :exec xsendkey Control+Right && xdotool key super+o
    W-o b :exec xsendkey Control+Left && xdotool key super+o
    
    # gg and G
    W-o g g :exec xsendkey Control+Home && xdotool key super+o
    # o will be shifted unless do this and won't re-enter mode
    # sleeping prevents the o from being shifted
    W-o S-g :exec xsendkey Control+End && sleep 0.2 && xdotool key super+o
    # keyup on shift with xte stopped working so sleep now; maybe can lower to 0.1
    
    # undo and redo
    W-o u :exec xsendkey Control+z && xdotool key super+o
    W-o S-u :exec xsendkey Control+y && sleep 0.2 && xdotool key super+o
    
    # save (this pulls you out)
    W-o s :exec xsendkey Control+s
    
    # search (this also requires you to exit the mode... unless you want to set up virtual keyboard input for every letter)
    W-o slash :exec xsendkey Control+f
    
    # next word suggestion
    W-o Tab :exec xsendkey Control+Tab && xdotool key super+o
    
    # cut, copy, and paste
    # won't delete blank lines, use x
    W-o d d :exec xsendkey End && xsendkey Shift+Home && xsendkey Delete && xdotool key super+o
    W-o x :exec xsendkey Delete && xdotool key super+o
    # this won't work in the middle of the word (alternatively and do a control left before, but them if you're at the start of the word it will delete the previous word)
    W-o d w :exec xsendkey Control+Shift+Right && xsendkey Control+x && xdotool key super+o
    W-o S-d :exec xsendkey Shift+End && xsendkey Control+x && sleep 0.2 && xdotool key super+o
    # maybe more vim like D:
    # xsendkey Shift+End && xsendkey BackSpace && xsendkey Right && xsendkey Return && xsendkey Up && xsendkey End
    
    
    W-o y w :exec xsendkey Control+Shift+Right && xsendkey Control+c && xdotool key super+o
    W-o S-y :exec xsendkey Shift+End && xsendkey Control+c && sleep 0.2 && xdotool key super+o
    
    W-o p :exec xsendkey Control+v && xdotool key super+o
    #}}}
    # Visual mode# {{{
    W-o v :enter timout=0 abort=manual
    
    # exit visual mode; return to normal mode
    W-o v v :abort
    W-o v Escape :exec xsendkey Escape && xdotool key v && xdotool key super+o
    W-o v Mode_switch :exec xsendkey Escape && xdotool key v && xdotool key super+o
    
    # basic movemennts
    W-o v h :exec xsendkey Shift+Left
    W-o v n :exec xsendkey Shift+Down
    W-o v e :exec xsendkey Shift+Up
    W-o v i :exec xsendkey Shift+Right
    
    # by word
    W-o v w :exec xsendkey Control+Shift+Right
    W-o v b :exec xsendkey Control+Shift+Left
    
    # gg and G
    W-o v g g :exec xsendkey Control+Shift+Home && xdotool key super+o && xdotool key v
    W-o v S-g :exec xsendkey Control+Shift+End
    
    # yank and return to normal
    W-o v y :exec xsendkey Control+c && xsendkey Escape && xdotool key v && xdotool key super+o
    
    # cut and return to normal
    W-o v d :exec xsendkey Control+x && xsendkey Escape && xdotool key v && xdotool key super+o
    # }}}
    # Visual block mode# {{{
    W-o S-v :enter timout=0 abort=manual
    
    W-o S-v v :abort
    W-o S-v Escape :exec xsendkey Escape && xdotool key v && xdotool key super+o
    W-o S-v Mode_switch :exec xsendkey Escape && xdotool key v && xdotool key super+o
    
    # make this better
    W-o S-v n :exec xsendkey Shift+End && xsendkey Control+Shift+Down
    W-o S-v e :exec xsendkey Shift+Home && xsendkey Control+Shift+Up
    
    # could also do counts here of course.. too lazy to do right now
    
    W-o S-v S-g :exec xsendkey Control+Shift+End
    
    # yank
    W-o S-v y :exec xsendkey Control+c && xsendkey Escape && xdotool key v && xdotool key super+o
    
    # cut
    W-o S-v d :exec xsendkey Control+x && xsendkey Escape && xdotool key v && xdotool key super+o
    # }}}
    # command mode example
    W-o semicolon w :exec xsendkey Control+s

    EDIT: I added a video and fixed some of the settings (using shifted mappings has the glitch of shifting what you send at the end, exiting the mode; i was using xte to keyup the shift, but this stopped working so I added sleep).

    EDIT: I added the suggested license.

    Last edited by angelic_sedition (19-Feb-2014 18:38:38)
    Offline
    • 0
    • Reputation: 210
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,343

    Nice! But some of this can be done more universally with the Extend mappings, can't it?

    In Vim, I don't remap anything so I'll find the same Vim everywhere; instead of 10j I'll use 10(Caps+N) if I have my Extend mappings. Would've been nice to have that everywhere I use Extend but I haven't found a practical way to do that yet. One ghetto alternative is an accelerated mapping layer with 5×<LEFT>, 3×<PGUP> etc.

    *** Learn Colemak in 2–5 steps with Tarmak! ***
    *** Check out my Big Bag of Keyboard Tricks for Win/Linux/TMK... ***

    Offline
    • 0
    • Reputation: 0
    • Registered: 11-Oct-2013
    • Posts: 79

    I wouldn't necessarily say more universally. Both work globally. Some of it (basic movement like Home, End, PageUp, PageDown, left, right, up, down) in some cases can be down more efficiently with the extend mappings. If you just want to hit Home, there's no reason to enter a mode to do it.

    The real difference is that since with normal layers, control doesn't work in an extend layer and you can't bind multiple keys to a single key with extend mappings, xchainkeys allows for "better" keyboard selection in this case. Since you can bind multiple sequences of keypresses to a single key, there are a lot of possibilities for doing multiple actions at once and mapping long modifiers to a single key. I think applications would be more interesting for software with a lot of keyboard shortcuts (maybe mmos) that aren't totally customizable and modal.

    I've made a demo video also and added it to the original post for a better/more clear picture of what this actually does/ looks like.

    That's what I used to do (10 caps n and e), but since I never use e and I use down more then next search match, I remapped those two keys and left i for insert. This is like turning Libre Office into vim, so you do have to pick all the mappings yourself in the first place. This does support taking counts as well, so you can setup 5h to work for example.

    Last edited by angelic_sedition (08-Feb-2014 19:21:34)
    Offline
    • 0
    • Reputation: 210
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,343

    Not sure what you mean by "control doesn't work in an extend layer and you can't bind multiple keys to a single key"? In case you haven't gotten the latest news, Control/Shift/Alt all work perfectly with my Extend layer in XKB now. But yeah, unless you count modifiers as a part of the "multiple keys" paradigm then I guess you can't bind multiple keys to a single key in XKB without performing some nasty virtual mods gymnastics that I generally wouldn't want to do. You can do a lot with the modifier states and have quite a few of them, but I suppose that's more Emacs-like than Vim-like. ;)

    *** Learn Colemak in 2–5 steps with Tarmak! ***
    *** Check out my Big Bag of Keyboard Tricks for Win/Linux/TMK... ***

    Offline
    • 0
    • Reputation: 0
    • Registered: 11-Oct-2013
    • Posts: 79

    Ah, I didn't know you got it working; I'll be sure to check it out. The only use I would really have for control in the extend layer would be control+backspace, but maybe I'll start doing it like that instead of what I'm doing right now by using xdotool to send control backspace. Modifiers in layers being held down simultaneously is definitely more Emacs like.. but it's also definitely better than having to adjust the hand position to reach all the modifiers like you do in emacs.

    I don't understand that virtual mod stuff though, so I'd rather just stick with a simple hotkey program.

    Last edited by angelic_sedition (08-Feb-2014 22:35:06)
    Offline
    • 0
    • Reputation: 210
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,343

    Oh, you missed my

    "WOO HOO – I'M SO STOKED NOW!!!'

    post. ;) Fair enough. But yeah, it really got together after two years of frustration over that issue to my great satisfaction.

    I do see how key chaining can be wonderful, as in Vim powerful. At some point I'll probably get around to it. And just forget about the "virtual mod stuff"; it isn't flexible enough to actually use.

    Last edited by DreymaR (08-Feb-2014 23:45:20)

    *** Learn Colemak in 2–5 steps with Tarmak! ***
    *** Check out my Big Bag of Keyboard Tricks for Win/Linux/TMK... ***

    Offline
    • 0
    • Reputation: 0
    • Registered: 04-Apr-2013
    • Posts: 538

    Just tried it.  I ended up grabbing xsendkey from here and compiling with

    gcc xsendkey.c -g -Wall -L /usr/X11R6/lib -lX11 -o xsendkey

     
    A more thorough installation guide could help quite a bit. 

    First impressions: Very promising!  I can maybe see this as finally obviating those pesky C- shortcuts, and making everything single-finger.  It's not perfect, of course; I notice that holding keys down doesn't really work.

    I'll definitely be playing with the setup. 

    One thing to wonder is whether we can set per-program bindings (preferably without having to use a different prefix for each).

    Offline
    • 0
    • Reputation: 0
    • Registered: 11-Oct-2013
    • Posts: 79
    DreymaR said:

    Oh, you missed my

    "WOO HOO – I'M SO STOKED NOW!!!'

    post. ;) Fair enough. But yeah, it really got together after two years of frustration over that issue to my great satisfaction.

    I do see how key chaining can be wonderful, as in Vim powerful. At some point I'll probably get around to it. And just forget about the "virtual mod stuff"; it isn't flexible enough to actually use.

    Haha well I'm pretty excited about it too. When I boot into linux after using Windows, I'll always accidentally try to use control on my extend layer out of habit.

    Yeah, I'm getting tired of software remapping. Results in a lot of failed testing and necessary reboots for me lately..

    lalop said:

    Just tried it.  I ended up grabbing xsendkey from here and compiling with

    gcc xsendkey.c -g -Wall -L /usr/X11R6/lib -lX11 -o xsendkey

     
    A more thorough installation guide could help quite a bit. 

    First impressions: Very promising!  I can maybe see this as finally obviating those pesky C- shortcuts, and making everything single-finger.  It's not perfect, of course; I notice that holding keys down doesn't really work.

    I'll definitely be playing with the setup. 

    One thing to wonder is whether we can set per-program bindings (preferably without having to use a different prefix for each).

    Well I can't help with the installation really, since I just installed it from the aur. I've only ever compiled something once on arch. Xdotool alone may work, but I just found xsendkey easier to use when trying it with sxhdk, so I stuck with it.

    What do you want to do with holding keys down? I know sxhdk, for example, allows for doing things on keydown vs key release and with xte you can specify key down and up. I have to test xchainkeys a bit more, but potentially you could send a keydown on keydown and send a keyup on keyup.

    As for different bindings for different programs with the same prefix key, xdotool and others (I don't remember about xsendkey) allow sending the input to a specific window. The other probably better option would just be to use shell scripting to fake different keyboard input based on current window type. I'd have to test it, but I think it would be pretty easy to implement, though maybe pretty inelegant.

    Ultimately, I'm looking at getting a teensy to use with the tmk firmware (https://github.com/tmk/tmk_keyboard) which I think would potentially work for chaining with no faking input. I'd much rather have all my remapping done in one place and be OS independent, so this looks pretty promising with regards to hardware remapping.

    It allows for 32 layers currently. I haven't looked at how robust the macro system is, but potentially this would allow one to even create an insert layer.. It allows switching to and locking layers, as well as a lot of cool "keyboard tricks." For example, press the mode enter key to enter "normal mode." Then in normal mode, pressing "i" or key of choice would enter an "insert mode" layer that's exactly the same as your layer 0 with duplicated shifted layers and such EXCEPT, pressing escape (i.e. release of caps lock), goes back to "normal mode" to prevent having to re-enter with some hotkey. This would make it so you could work in normal mode as the base layer the whole time you were using a particular program without any accidental escaping.

    The other really great thing about the tmk firmware is that I'm told the dual role feature (key is modifier when held, normal if tapped) works extremely well for normal keys (i.e. letters and spacebar). I've had to stop using At Home Modifier to map the spacebar to super, because it wasn't working perfectly. The tmk firmware supports a lot of different ways to use layers. Layer toggle key. Hold for layer, and tap to toggle. Hold for layer and tap for normal key output. Etc. (https://github.com/tmk/tmk_keyboard/blo … yer-action)

    Offline
    • 0
    • Reputation: 0
    • Registered: 04-Apr-2013
    • Posts: 538

    Heh, sadly I'm probably not hardcore enough for arch. 

    I'm using C-Return instead of W-o.  (I didn't even realize it did anything until I tried it out just now.)  This is due to my config of putting C- on CapsLock.  I'd love other suggestions for the "normal mode key".

    Long-term, I face in some sense the opposite problem: I mainly use only one OS and one computer, but since that computer is a laptop I'm stuck with the default keyboard.  So my config is all OS-dependent software.

    A medium-term goal is a "config generator" that, given a choice of normal mode key and a base bindings file, populates the config with those bindings as well as counts.  I don't think this should be too hard.  Maybe have four sections, one for each combo of {goes back to normal mode, doesn't go back to normal mode} x {adds count, doesn't add counts}


    angelic_sedition said:

    What do you want to do with holding keys down? I know sxhdk, for example, allows for doing things on keydown vs key release and with xte you can specify key down and up. I have to test xchainkeys a bit more, but potentially you could send a keydown on keydown and send a keyup on keyup.

    I just meant spammy stuff like holding down n/e.  But having completely different commands sounds cool as well!



    Also, admin crap: could you please add a license or similar to the config?  Technically we aren't allowed to copy it or share our modifications if there isn't one.  My personal favorite for this sort of thing is:

    ## License
    ## This software is licensed under the CC0 1.0 Public Domain Declaration, as
    ## released by Creative Commons <https://creativecommons.org/publicdomain/zero/1.0/>.
    
    ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
    ## WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
    ## THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    ## NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
    ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    ## (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    ## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    ## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    (So that it's clear, I'm not a lawyer.)

    Offline
    • 0
    • Reputation: 0
    • Registered: 11-Oct-2013
    • Posts: 79

    Arch isn't really that bad besides for the first install (which is time consuming).

    Yeah W-o was just something random I picked. I'm using a cheap Japanese keyboard with a bunch of thumb keys, so I'll probably end up using one of those to enter the mode. 

    Even though I mainly only use one OS and a laptop, I still use keyboards (because I really can't stand default laptop keyboards), so better, easier hardware remapping is a goal for me.

    A config generator wouldn't be too hard to make, but unless I start adding a ton of bindings in this, I'd probably just opt for vim, macros and incrementing to duplicate stuff for different counts. One cool thing I'm thinking of doing is adding bindings for the mouse to use with tabsoutliner, which is a tab saving and organizing extension I'm using..

    Spammy stuff would be hard to do.. If I could find a way to determine how long the key was held down for, it would be possible and easy, but so far everything I've tried has failed. I'll try again later.

    I added the license you suggested, but is that really necessary just for a config file? I guess it counts as software kind of. I'm kind of a fan of the do whatever the f you want license myself.

    Last edited by angelic_sedition (15-Feb-2014 09:08:47)
    Offline
    • 0
    • Reputation: 2
    • Registered: 25-Oct-2013
    • Posts: 136

    Arch isn't really that bad besides for the first install (which is time consuming).

    True. I say this as a fellow arch user. It is hard core though in the sense that it offers a lot of choice - just like other "from scratch" distros. Too much choice can be paralyzing and time consuming. Always on the hunt for a better window manager, an even lighter pdf-reader and so on. Sometimes sane defaults (think Ubuntu, Fedora or even OSX or, why not, Windows 7) are nice....

    Offline
    • 0
    • Reputation: 0
    • Registered: 11-Oct-2013
    • Posts: 79
    pieter said:

    Arch isn't really that bad besides for the first install (which is time consuming).

    True. I say this as a fellow arch user. It is hard core though in the sense that it offers a lot of choice - just like other "from scratch" distros. Too much choice can be paralyzing and time consuming. Always on the hunt for a better window manager, an even lighter pdf-reader and so on. Sometimes sane defaults (think Ubuntu, Fedora or even OSX or, why not, Windows 7) are nice....

    Well if you already know what you want, it's pretty easy to just script your config setup and everything you want to install on Arch (which is what I do). Arch is also good for people who know exactly what they want (especially for those who don't use a DE or display manager) and find that no distro caters well to that.

    Last edited by angelic_sedition (08-Jul-2014 18:54:22)
    Offline
    • 0
    • Reputation: 0
    • Registered: 11-Oct-2013
    • Posts: 79
    lalop said:

    One thing to wonder is whether we can set per-program bindings (preferably without having to use a different prefix for each).

    I'm not really using this anymore (since I've been mostly using markdown and LaTeX instead of libre office and don't really use any other non-configurable software), but I did have an extremely hackish idea on how do this (well the idea in the first place is pretty hackish). I don't know how viable a solution it really is (especially since it may depend on the window manager), but I guess I'll give a hypothetical way in which it could be done because it's interesting at least (and would not require a prefix key).

    I've been setting up single key bindings for empty desktops (home row keys change desktops; other letters open programs and such) by restarting my hotkey program with an alternate config file when switching to an empty desktop and then reverting to the normal config file when switching to an occupied desktop. Surprisingly, there is no delay, and nothing breaks if I go back and forth as fast as I can. The same thing could be done for setting up bindings for a specific window class using window manager hooks.

    For example, hlwm has a hook for window change (which would be much better for this). Bspwm (which is what I'm using) has bspwm control --subscribe, which will continuously print information. This can be piped into awk and then used to execute shell commands for certain changes. I'm not sure about other window managers. It could be possible to use wmctrl (it has flags like -l and -d for printing information), but I'm not sure if it has some option to print continuously on changes (and the output is multiline).

    So for example, you could set things up so that on desktop change, a bash script is run to check the active window class (e.g. using xprop) and if it's something you have bindings setup for, it will restart the hotkey program with the "normal mode" keys. In the config, you map "i" or whatever you want to return to normal (being able to type) by restarting with a config file that only maps escape or another key to restart using the previous config file. With bspwm, you'd have to map window focus switching bindings to also run this bash script since --subscribe won't print on focus change. This gets pretty complicated. Maybe you could just run a daemon that keeps checking the current window repeatedly instead (then you would have to make sure that it only setup the bindings the first time the right window is found to be active). The "mode" would not be saved if you switched windows though... unless you were to complicate it even further and have it be saved to a file and checked or something.

    I might end up trying this with gimp (though more likely with faking mousing movement and clicking) for fun.

    Offline
    • 0
    • Reputation: 2
    • Registered: 25-Oct-2013
    • Posts: 136

    This is great to read, I will experiment with your ideas. It happens that I use Archlinux plus the wonderful herbstluftwm (hlwm) windowmanager as well :-) If it's not too offtopic, what makes bspwm better than hlwm?

    I'm in the fist phase of building my own keyboard. With its own programmable firmware :-) which means that the keyboard will send the right keycodes to the computer. Independent of OS, windowmanager or application... yeah!

    Offline
    • 0
    • Reputation: 11
    • Registered: 06-Jun-2013
    • Posts: 551

    is the fist phase where you punch it until it starts working?

    Offline
    • 0
    • Reputation: 2
    • Registered: 25-Oct-2013
    • Posts: 136

    @bph: LOL, typo

    Offline
    • 0