Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write mouse bidings and Xmonad Prompt bindings with EZ Keys ? #507

Open
thealio opened this issue May 20, 2024 · 3 comments
Open

Write mouse bidings and Xmonad Prompt bindings with EZ Keys ? #507

thealio opened this issue May 20, 2024 · 3 comments

Comments

@thealio
Copy link

thealio commented May 20, 2024

Hi
I have these keybindis, that work OK with standard keybinds


myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
    -- mod-button1, Set the window to floating mode and move by dragging
    [ ((modMask, 1), (\w -> focus w >> mouseMoveWindow w >> windows W.shiftMaster))
    -- mod-button2, Raise the window to the top of the stack
    , ((modMask, 2), (\w -> focus w >> windows W.shiftMaster))
    -- mod-button3, Set the window to floating mode and resize by dragging
    , ((modMask, 3), (\w -> focus w >> mouseResizeWindow w >> windows W.shiftMaster)) ]
myXPKeymap :: M.Map (KeyMask,KeySym) (XP ())
myXPKeymap = M.fromList $
     map (first $ (,) controlMask)      -- control + <key>
     [ (xK_z, killBefore)               -- kill line backwards
     , (xK_k, killAfter)                -- kill line forwards
     , (xK_a, startOfLine)              -- move to the beginning of the line
     , (xK_e, endOfLine)                -- move to the end of the line
     , (xK_m, deleteString Next)        -- delete a character foward
     , (xK_b, moveCursor Prev)          -- move cursor forward
     , (xK_f, moveCursor Next)          -- move cursor backward
     , (xK_BackSpace, killWord Prev)    -- kill the previous word
     , (xK_v, pasteString)              -- paste a string
     , (xK_q, quit)                     -- quit out of prompt
     , (xK_bracketleft, quit) ]
     ++

Now I'd like to write them using the XMonad.Util.EZConfig module keys and also wit addName , I tried many times , but unsuccesfully .

I wanna ask if this is technically possible, and how to do that. If it's not, I wanna made a feature request.

I have these lines for normal keys

xmonad $ ewmh $ docks $ addDescrKeys' ((mod4Mask, xK_F1), showKeybindings) myKeys $ ewmhFullscreen $ pagerHints $ myDefaults

myKeys :: XConfig Layout -> [((KeyMask, KeySym), NamedAction)]
myKeys conf =
  --(subtitle "Custom Keys":) $ mkNamedKeymap c $                 -- subtitle
  let subKeys str ks = subtitle' str : mkNamedKeymap conf ks in   -- subtitle'
------------------------------------------
  subKeys "Base xmonad"
  [ ("M-M1-r",      addName "Recompile & Restart xmonad" $ xmonadRecompile)  -- custom function
  , ("M-<Return>",  addName "Launch terminal"            $ spawn (myTerminal))
  , ("M1-r",        addName "Restart xmonad"             $ spawn "xmonad --restart")]

I'm using distrotube config as a code source : https://gitlab.com/dwt1/dotfiles/-/blob/master/.config/xmonad/xmonad.hs

@slotThe
Copy link
Member

slotThe commented May 22, 2024

What are you having trouble with?

@geekosaur
Copy link
Contributor

I'd like to note that this belongs in xmonad-contrib, not core.

The lower level mechanisms in EZKeys could be used to make a function that would let you use additionalKeysP-style bindings with Prompt. The higher level ones (additionalKeys and friends) won't work because they require and produce an XConfig, plus they expect the actions to be X (), not XP ().

addName isn't even meaningful here. Why do you want it?

Similarly, mouse bindings are not key bindings and so it's not useful to define mouse bindings in additionalKeysP style.

@thealio
Copy link
Author

thealio commented May 22, 2024

Hi, and thank you for your answer

I'd like to note that this belongs in xmonad-contrib, not core.

The lower level mechanisms in EZKeys could be used to make a function that would let you use additionalKeysP-style bindings with Prompt. The higher level ones (additionalKeys and friends) won't work because they require and produce an XConfig, plus they expect the actions to be X (), not XP ().

addName isn't even meaningful here. Why do you want it?

Similarly, mouse bindings are not key bindings and so it's not useful to define mouse bindings in additionalKeysP style.

The addName is used in a custom function that pipes the keybindings into rofi for have a list of keybindings

-- Show Keybindings                                
showKeybindings :: [((KeyMask, KeySym), NamedAction)] -> NamedAction
showKeybindings x = addName "Show Keybindings" $ io $ do
  h <- spawnPipe $ myMenu 
--  hPutStr h (unlines $ showKm x)         -- showKM adds ">>" before subtitles
  hPutStr h (unlines $ showKmSimple x)     -- showKmSimple doesn't add ">>" to subtitles
  hClose h
  return ()
  where
     myMenu = "rofi -dmenu -i -matching fuzzy -p 'Xmonad keys'"
-- Keybind for showing the keybinds list
myMenuKey = addDescrKeys' ((mod4Mask, xK_F1), showKeybindings)

myWorkspaces = myNamedWS
 -- Main section
main :: IO ()
main = do
    dbus <- D.connectSession      -- dbus is required for polybar
 -- Request access to the DBus name
    D.requestName dbus (D.busName_ "org.xmonad.Log")
        [D.nameAllowReplacement, D.nameReplaceExisting, D.nameDoNotQueue]

    xmonad $ ewmh $ docks $ addDescrKeys' ((mod4Mask, xK_F1), showKeybindings) myKeys $ ewmhFullscreen $ pagerHints $ myDefaults
 -- $ pagerHints is required for print the current layout in xmonad ( xprop -root _XMONAD_CURRENT_LAYOUT | awk '{print $NF}' | tr -d "\"" )

 -- Start polybar
myBarHook = do
    spawn "polybar --config=~/.config/polybar/config.ini mainbar-xmonad"  -- Start polybar

I wanna also pipe mouse bindings and prompt bindings in the keybind list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants