diff options
| author | lassulus <lassulus@lassul.us> | 2021-02-11 11:09:03 +0100 | 
|---|---|---|
| committer | lassulus <lassulus@lassul.us> | 2021-02-11 11:09:03 +0100 | 
| commit | 424bed37941a2d0db083e76ef5183fbf2cb950c2 (patch) | |
| tree | 120cf684ea4f9a302e719b54179dbdf6da321381 | |
| parent | e266373de4dd8e987cdceb04f8dab6347420de79 (diff) | |
| parent | 4ec04fe23a6e6c8fc151a8ab77a8ab27c78c1b4f (diff) | |
Merge remote-tracking branch 'ni/master'
| -rw-r--r-- | tv/5pkgs/haskell/xmonad-tv/src/Paths.hs | 3 | ||||
| -rw-r--r-- | tv/5pkgs/haskell/xmonad-tv/src/main.hs | 3 | ||||
| -rw-r--r-- | tv/5pkgs/simple/xdpytools/default.nix | 31 | ||||
| -rwxr-xr-x | tv/5pkgs/simple/xdpytools/src/xdpychvt | 11 | ||||
| -rwxr-xr-x | tv/5pkgs/simple/xdpytools/src/xdpysel | 49 | 
5 files changed, 97 insertions, 0 deletions
| diff --git a/tv/5pkgs/haskell/xmonad-tv/src/Paths.hs b/tv/5pkgs/haskell/xmonad-tv/src/Paths.hs index 6b72355..b2ad01a 100644 --- a/tv/5pkgs/haskell/xmonad-tv/src/Paths.hs +++ b/tv/5pkgs/haskell/xmonad-tv/src/Paths.hs @@ -29,3 +29,6 @@ urxvtc = findExecutable "urxvtc"  xcalib :: FilePath  xcalib = findExecutable "xcalib" + +xdpychvt :: FilePath +xdpychvt = findExecutable "xdpychvt" diff --git a/tv/5pkgs/haskell/xmonad-tv/src/main.hs b/tv/5pkgs/haskell/xmonad-tv/src/main.hs index 50b03d8..e5a4473 100644 --- a/tv/5pkgs/haskell/xmonad-tv/src/main.hs +++ b/tv/5pkgs/haskell/xmonad-tv/src/main.hs @@ -190,6 +190,9 @@ myKeys conf = Map.fromList $      , ((_4, xK_Prior), forkFile Paths.xcalib ["-invert", "-alter"] Nothing)      , ((0, xK_Print), forkFile Paths.flameshot [] Nothing) + +    , ((_C, xF86XK_Forward), forkFile Paths.xdpychvt ["next"] Nothing) +    , ((_C, xF86XK_Back), forkFile Paths.xdpychvt ["prev"] Nothing)      ]      where      _4 = mod4Mask diff --git a/tv/5pkgs/simple/xdpytools/default.nix b/tv/5pkgs/simple/xdpytools/default.nix new file mode 100644 index 0000000..7d1ee07 --- /dev/null +++ b/tv/5pkgs/simple/xdpytools/default.nix @@ -0,0 +1,31 @@ +{ lib, pkgs }: + +let +  install = name: { path }: /* sh */ '' +    ( +      mkdir -p $out/bin +      touch $out/bin/${name} +      chmod +x $out/bin/${name} +      exec >$out/bin/${name} + +      echo '#! ${pkgs.dash}/bin/dash' +      echo export PATH=${lib.makeBinPath path} +      sed 1d ${./src + "/${name}"} +    ) +  ''; +in + +pkgs.runCommand "xdpytools" {} +  (toString +    (lib.mapAttrsToList install { +      xdpychvt.path = [ +        "$out" +        "/run/wrappers/'$LOGNAME'" +        "/run/wrappers" +      ]; +      xdpysel.path = [ +        "$out" +        pkgs.findutils +        pkgs.jq +      ]; +    })) diff --git a/tv/5pkgs/simple/xdpytools/src/xdpychvt b/tv/5pkgs/simple/xdpytools/src/xdpychvt new file mode 100755 index 0000000..84c1907 --- /dev/null +++ b/tv/5pkgs/simple/xdpytools/src/xdpychvt @@ -0,0 +1,11 @@ +#! /bin/sh +# usage: xdpychvt {prev,next} +# Changes to the VT based on the selected X display. +# +# This allows switching between X servers when display names and VT numbers +# correlate.  A more sophisticated tool would try to determine the correct VT +# by e.g. looking at /proc, but this might not possible when e.g.  using +# security.hideProcessInformation. +# + +chvt "$(xdpysel "$1")" diff --git a/tv/5pkgs/simple/xdpytools/src/xdpysel b/tv/5pkgs/simple/xdpytools/src/xdpysel new file mode 100755 index 0000000..e080155 --- /dev/null +++ b/tv/5pkgs/simple/xdpytools/src/xdpysel @@ -0,0 +1,49 @@ +#! /bin/sh +# usage: xdpysel {prev,next} +# Print the number of the selected X display. + +find /tmp/.X11-unix -mindepth 1 -maxdepth 1 | +jq -Rrs --arg command "$1" ' +  ( +    split("\n") | +    map( +      select(.!="") | +      match("^.*/X([0-9]+)$").captures[0].string | +      tonumber +    ) +  ) +    as $all_displays | + +  ( +    env.DISPLAY | +    match("^:([0-9]+)(?:[.][0-9]+)?$").captures[0].string | +    tonumber +  ) +    as $current_display | + +  ($all_displays | length) as $all_displays_count | + +  ($all_displays|index($current_display)) +    as $current_index | + +  (($current_index + 1) % $all_displays_count) +    as $next_index | + +  (($all_displays_count + $current_index - 1) % $all_displays_count) +    as $prev_index | + +  $all_displays[$prev_index] as $prev_display | +  $all_displays[$next_index] as $next_display | + +  { +    prev: $prev_display, +    next: $next_display, +  }[$command] +    as $result | + +  if $result | type == "number" then +    $result +  else +    "xdpysel: bad argument: \($command)\n" | halt_error(-1) +  end +' | 
