ENH call rofi directly
This commit is contained in:
parent
d06d5d5a0b
commit
3e9b08db08
37
README.md
37
README.md
|
@ -21,6 +21,23 @@ stack install
|
||||||
|
|
||||||
See individual sections for other dependencies to install.
|
See individual sections for other dependencies to install.
|
||||||
|
|
||||||
|
## Putting Rofi on the correct screen (rofi)
|
||||||
|
|
||||||
|
This is a total hack...actually it isn't because it's written in Haskell and not
|
||||||
|
bash.
|
||||||
|
|
||||||
|
The problem is that when used with xmonad, rofi doesn't place itself on the
|
||||||
|
"current" workspace since the concept of a "workspace" is weird and specific to
|
||||||
|
xmonad. The solution is to use this program to query `_NET_DESKTOP_VIEWPORT`
|
||||||
|
(which my xmonad config sets) and use this determine the name of the active
|
||||||
|
workspace which can then be fed to rofi using the `-m` flag.
|
||||||
|
|
||||||
|
See comments of this binary for details.
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
- X11
|
||||||
|
|
||||||
## Bitwarden (rofi-bw)
|
## Bitwarden (rofi-bw)
|
||||||
|
|
||||||
[Bitwarden](https://bitwarden.com/) is an open-source password management server
|
[Bitwarden](https://bitwarden.com/) is an open-source password management server
|
||||||
|
@ -174,23 +191,3 @@ bitwarden-name: <name of GPG bitwarden entry>
|
||||||
### Dependencies
|
### Dependencies
|
||||||
|
|
||||||
- rofi-bw (see above): bitwarden integration
|
- rofi-bw (see above): bitwarden integration
|
||||||
|
|
||||||
## Putting Rofi on the correct screen (current-output)
|
|
||||||
|
|
||||||
This is a total hack...actually it isn't because it's written in Haskell and not
|
|
||||||
bash.
|
|
||||||
|
|
||||||
The problem is that when used with xmonad, rofi doesn't place itself on the
|
|
||||||
"current" workspace since the concept of a "workspace" is weird and specific to
|
|
||||||
xmonad. The solution is to use this program to query `_NET_DESKTOP_VIEWPORT`
|
|
||||||
(which my xmonad config sets) and use this determine the name of the active
|
|
||||||
workspace which can then be fed to rofi using the `-m` flag.
|
|
||||||
|
|
||||||
See comments of this binary for details.
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
|
|
||||||
- X11
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ module Main (main) where
|
||||||
|
|
||||||
import Bitwarden.Internal
|
import Bitwarden.Internal
|
||||||
|
|
||||||
-- import Control.Exception
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.Reader
|
import Control.Monad.Reader
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- | Return current xrandr output name
|
-- | Run rofi (and display on the correct screen)
|
||||||
--
|
--
|
||||||
-- Since this seems random, the reason for this is that I want rofi to appear
|
-- Since this seems random, the reason for this is that I want rofi to appear
|
||||||
-- over the current xmonad workspace, and rofi has no concept of what an
|
-- over the current xmonad workspace, and rofi has no concept of what an
|
||||||
-- xmonad workspace is (not that it is supposed to, xmonad is weird...). Rofi
|
-- xmonad workspace is (not that it is supposed to, xmonad is weird...). Rofi
|
||||||
-- accepts the name of an xrandr output onto which it should appear, so this
|
-- accepts the name of an xrandr output onto which it should appear, so this
|
||||||
-- script provides a way to determine which xmonad workspace is in focus and
|
-- binary determines which xmonad workspace is in focus and calls rofi with the
|
||||||
-- provide the name of the output displaying said workspace.
|
-- name of that workspace.
|
||||||
--
|
--
|
||||||
-- Assumptions: xmonad sets the _NET_DESKTOP_VIEWPORT atom with the positions of
|
-- Assumptions: xmonad sets the _NET_DESKTOP_VIEWPORT atom with the positions of
|
||||||
-- the active workspace (actually an array of the positions of all workspaces
|
-- the active workspace (actually an array of the positions of all workspaces
|
||||||
|
@ -21,6 +21,7 @@ module Main (main) where
|
||||||
-- 2) Use index from (1) and to get the position of the active workspace from
|
-- 2) Use index from (1) and to get the position of the active workspace from
|
||||||
-- _NET_DESKTOP_VIEWPORT
|
-- _NET_DESKTOP_VIEWPORT
|
||||||
-- 3) Find the name of the xrandr output whose position matches that from (2)
|
-- 3) Find the name of the xrandr output whose position matches that from (2)
|
||||||
|
-- 4) Call rofi with the '-m' flag to override the default monitor placement
|
||||||
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
|
||||||
|
@ -29,13 +30,17 @@ import Graphics.X11.Xlib
|
||||||
import Graphics.X11.Xlib.Extras
|
import Graphics.X11.Xlib.Extras
|
||||||
import Graphics.X11.Xrandr
|
import Graphics.X11.Xrandr
|
||||||
|
|
||||||
import System.Exit
|
import System.Environment
|
||||||
|
import System.Process
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = getMonitorName >>= maybe exitFailure (\n -> putStrLn n >> exitSuccess)
|
main = do
|
||||||
|
r <- getMonitorName
|
||||||
|
let pre = maybe [] (\n -> ["-m", n]) r
|
||||||
|
args <- getArgs
|
||||||
|
callProcess "/usr/bin/rofi" $ pre ++ args
|
||||||
|
|
||||||
data Coord = Coord Int Int
|
data Coord = Coord Int Int deriving (Eq, Show)
|
||||||
deriving (Eq, Show)
|
|
||||||
|
|
||||||
getMonitorName :: IO (Maybe String)
|
getMonitorName :: IO (Maybe String)
|
||||||
getMonitorName = do
|
getMonitorName = do
|
||||||
|
@ -55,9 +60,8 @@ getDesktopViewports dpy root =
|
||||||
pairs <$> getAtom32 dpy root "_NET_DESKTOP_VIEWPORT"
|
pairs <$> getAtom32 dpy root "_NET_DESKTOP_VIEWPORT"
|
||||||
where
|
where
|
||||||
pairs = reverse . pairs' []
|
pairs = reverse . pairs' []
|
||||||
pairs' acc [] = acc
|
|
||||||
pairs' acc [_] = acc
|
|
||||||
pairs' acc (x1:x2:xs) = pairs' (Coord x1 x2 : acc) xs
|
pairs' acc (x1:x2:xs) = pairs' (Coord x1 x2 : acc) xs
|
||||||
|
pairs' acc _ = acc
|
||||||
|
|
||||||
getOutputs :: Display -> Window -> IO [(Coord, String)]
|
getOutputs :: Display -> Window -> IO [(Coord, String)]
|
||||||
getOutputs dpy root = xrrGetScreenResourcesCurrent dpy root >>=
|
getOutputs dpy root = xrrGetScreenResourcesCurrent dpy root >>=
|
||||||
|
@ -70,8 +74,7 @@ getOutputs dpy root = xrrGetScreenResourcesCurrent dpy root >>=
|
||||||
, xrr_oi_name = n
|
, xrr_oi_name = n
|
||||||
, xrr_oi_crtc = c
|
, xrr_oi_crtc = c
|
||||||
}) = do
|
}) = do
|
||||||
cinfo <- xrrGetCrtcInfo dpy r c
|
fmap (\i -> (toCoord i, n)) <$> xrrGetCrtcInfo dpy r c
|
||||||
return $ fmap (\i -> (toCoord i, n)) cinfo
|
|
||||||
infoToCell _ _ = return Nothing
|
infoToCell _ _ = return Nothing
|
||||||
toCoord c = Coord (fromIntegral $ xrr_ci_x c) (fromIntegral $ xrr_ci_y c)
|
toCoord c = Coord (fromIntegral $ xrr_ci_x c) (fromIntegral $ xrr_ci_y c)
|
||||||
|
|
||||||
|
@ -79,12 +82,7 @@ infix 9 !!?
|
||||||
(!!?) :: [a] -> Int -> Maybe a
|
(!!?) :: [a] -> Int -> Maybe a
|
||||||
(!!?) xs i
|
(!!?) xs i
|
||||||
| i < 0 = Nothing
|
| i < 0 = Nothing
|
||||||
| otherwise = go i xs
|
| otherwise = listToMaybe $ drop i xs
|
||||||
where
|
|
||||||
go :: Int -> [a] -> Maybe a
|
|
||||||
go 0 (x:_) = Just x
|
|
||||||
go j (_:ys) = go (j - 1) ys
|
|
||||||
go _ [] = Nothing
|
|
||||||
|
|
||||||
getAtom32 :: Display -> Window -> String -> IO [Int]
|
getAtom32 :: Display -> Window -> String -> IO [Int]
|
||||||
getAtom32 dpy root str = do
|
getAtom32 dpy root str = do
|
|
@ -121,8 +121,8 @@ executables:
|
||||||
dependencies:
|
dependencies:
|
||||||
- rofi-extras
|
- rofi-extras
|
||||||
|
|
||||||
current-output:
|
rofi:
|
||||||
main: current-output.hs
|
main: rofi.hs
|
||||||
source-dirs: app
|
source-dirs: app
|
||||||
ghc-options:
|
ghc-options:
|
||||||
- -Wall
|
- -Wall
|
||||||
|
|
Loading…
Reference in New Issue