dotfiles

*nix config files
git clone git://git.pyratebeard.net/dotfiles.git
Log | Files | Refs | README

herbstluftwm-min_max (2335B)


      1 #!/usr/bin/env bash
      2 
      3 # A script allowing to minimize and un-minimize clients in a LIFO way
      4 # (last minimized client will be un-minimized first).
      5 # 
      6 # `chmod +x unminimize.sh` then call it or add it to `autostart`.
      7 
      8 
      9 Mod=${Mod:-Mod4}
     10 Minimizekey=Shift-m
     11 Unminimizekey=Ctrl-m
     12 # get the absolute path of this script, to call it when minimizing
     13 SCRIPT_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/$(basename "${BASH_SOURCE[0]}")
     14 
     15 hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;}
     16 
     17 
     18 # 
     19 # initialize minimize and unminimize shortcuts
     20 #
     21 init() {
     22 
     23    # initialize a global minimization counter
     24    hc silent new_attr uint my_minimized_counter 1
     25 
     26    # minimize current window
     27    hc keybind $Mod-$Minimizekey spawn "$SCRIPT_PATH" minimize
     28 
     29    # unminimize last window of a tag
     30    # if the `my_minimized_age` attribute does not exist (i.e. the window has not been
     31    #  minimized with this script), use arbitrary order to unminimize
     32    hc keybind $Mod-$Unminimizekey mktemp string LASTCLIENTATT mktemp uint LASTAGEATT chain \
     33      . set_attr LASTAGEATT 0 \
     34      . foreach CLIENT clients. and \
     35        , sprintf MINATT "%c.minimized" CLIENT \
     36            compare MINATT "=" "true" \
     37        , sprintf TAGATT "%c.tag" CLIENT substitute FOCUS "tags.focus.name" \
     38            compare TAGATT "=" FOCUS \
     39        , sprintf AGEATT "%c.my_minimized_age" CLIENT or \
     40          case: and \
     41             : ! get_attr AGEATT \
     42             : compare LASTAGEATT "=" 0 \
     43          case: and \
     44             : substitute LASTAGE LASTAGEATT \
     45                 compare AGEATT 'gt' LASTAGE \
     46             : substitute AGE AGEATT \
     47                 set_attr LASTAGEATT AGE \
     48        , set_attr LASTCLIENTATT CLIENT \
     49      . and \
     50        , compare LASTCLIENTATT "!=" "" \
     51        , substitute CLIENT LASTCLIENTATT chain \
     52          : sprintf MINATT "%c.minimized" CLIENT \
     53              set_attr MINATT false \
     54          : sprintf AGEATT "%c.my_minimized_age" CLIENT \
     55              try remove_attr AGEATT \
     56 
     57 }
     58 
     59 
     60 # 
     61 # minimize focused client
     62 #
     63 minimize() {
     64 
     65    hc and \
     66      . substitute C my_minimized_counter new_attr uint clients.focus.my_minimized_age C \
     67      . set_attr my_minimized_counter $(($(hc get_attr my_minimized_counter)+1)) \
     68      . set_attr clients.focus.minimized true \
     69 
     70 }
     71 
     72 
     73 if [ "$1" = "minimize" ] ; then minimize ; else init ; fi