我对 Xmonad WM 很陌生,并且 haskell 对我来说完全陌生,所以请耐心等待。
运行几乎原生的 ArcoLinux Xmonad。
我正在尝试将 Xmonad WM 设置为能够随时在我想要的所有应用程序中全屏显示,并将其绑定到(modMask, xK_f)
- 基本上使用该绑定作为切换以在我需要的一些应用程序中全屏显示,尤其是浏览器。同时polybar
完全隐藏。
这是我的~/.xmonad/xmonad.sh
import System.IO
import System.Exit
import XMonad
import XMonad.Hooks.SetWMName
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.ManageHelpers(doFullFloat, doCenterFloat, isFullscreen, isDialog)
import XMonad.Config.Desktop
import XMonad.Config.Azerty
import XMonad.Util.Run(spawnPipe)
import XMonad.Actions.SpawnOn
import XMonad.Util.EZConfig (additionalKeys, additionalMouseBindings)
import XMonad.Actions.CycleWS
import XMonad.Hooks.UrgencyHook
import qualified Codec.Binary.UTF8.String as UTF8
import XMonad.Layout.Spacing
import XMonad.Layout.Gaps
import XMonad.Layout.ResizableTile
---import XMonad.Layout.NoBorders
import XMonad.Layout.Fullscreen (fullscreenFull)
import XMonad.Layout.Cross(simpleCross)
import XMonad.Layout.Spiral(spiral)
import XMonad.Layout.ThreeColumns
import XMonad.Layout.MultiToggle
import XMonad.Layout.MultiToggle.Instances
import XMonad.Layout.IndependentScreens
import XMonad.Layout.CenteredMaster(centerMaster)
import Graphics.X11.ExtraTypes.XF86
import qualified XMonad.StackSet as W
import qualified Data.Map as M
import qualified Data.ByteString as B
import Control.Monad (liftM2)
import qualified DBus as D
import qualified DBus.Client as D
myStartupHook = do
spawn "$HOME/.xmonad/scripts/autostart.sh"
setWMName "LG3D"
-- colours
normBord = "#4c566a"
focdBord = "#5e81ac"
fore = "#DEE3E0"
back = "#282c34"
winType = "#c678dd"
--mod4Mask= super key
--mod1Mask= alt key
--controlMask= ctrl key
--shiftMask= shift key
myModMask = mod4Mask
encodeCChar = map fromIntegral . B.unpack
myFocusFollowsMouse = True
myBorderWidth = 2
myWorkspaces = ["\61612","\61899","\61947","\61635","\61502","\61501","\61705","\61564","\62150","\61872"]
--myWorkspaces = ["1","2","3","4","5","6","7","8","9","10"]
--myWorkspaces = ["I","II","III","IV","V","VI","VII","VIII","IX","X"]
myBaseConfig = desktopConfig
-- window manipulations
myManageHook = composeAll . concat $
[ [isDialog --> doCenterFloat]
, [className =? c --> doCenterFloat | c <- myCFloats]
, [title =? t --> doFloat | t <- myTFloats]
, [resource =? r --> doFloat | r <- myRFloats]
, [resource =? i --> doIgnore | i <- myIgnores]
-- , [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "\61612" | x <- my1Shifts]
-- , [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "\61899" | x <- my2Shifts]
-- , [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "\61947" | x <- my3Shifts]
-- , [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "\61635" | x <- my4Shifts]
-- , [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "\61502" | x <- my5Shifts]
-- , [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "\61501" | x <- my6Shifts]
-- , [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "\61705" | x <- my7Shifts]
-- , [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "\61564" | x <- my8Shifts]
-- , [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "\62150" | x <- my9Shifts]
-- , [(className =? x <||> title =? x <||> resource =? x) --> doShiftAndGo "\61872" | x <- my10Shifts]
]
where
-- doShiftAndGo = doF . liftM2 (.) W.greedyView W.shift
myCFloats = ["Arandr", "Arcolinux-calamares-tool.py", "Arcolinux-tweak-tool.py", "Arcolinux-welcome-app.py", "Galculator", "feh", "mpv", "Xfce4-terminal"]
myTFloats = ["Downloads", "Save As..."]
myRFloats = []
myIgnores = ["desktop_window"]
-- my1Shifts = ["Chromium", "Vivaldi-stable", "Firefox"]
-- my2Shifts = []
-- my3Shifts = ["Inkscape"]
-- my4Shifts = []
-- my5Shifts = ["Gimp", "feh"]
-- my6Shifts = ["vlc", "mpv"]
-- my7Shifts = ["Virtualbox"]
-- my8Shifts = ["Thunar"]
-- my9Shifts = []
-- my10Shifts = ["discord"]
myLayout = spacingRaw True (Border 0 5 5 5) True (Border 5 5 5 5) True $ avoidStruts $ mkToggle (NBFULL ?? NOBORDERS ?? EOT) $ tiled ||| Mirror tiled ||| spiral (6/7) ||| ThreeColMid 1 (3/100) (1/2) ||| Full
where
tiled = Tall nmaster delta tiled_ratio
nmaster = 1
delta = 3/100
tiled_ratio = 1/2
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))
]
-- keys config
myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
----------------------------------------------------------------------
-- SUPER + FUNCTION KEYS
[ ((modMask, xK_d ), spawn $ "dmenu_run -i -nb '#191919' -nf '#fea63c' -sb '#fea63c' -sf '#191919' -fn 'NotoMonoRegular:bold:pixelsize=15'")
, ((modMask, xK_f), sendMessage $ Toggle NBFULL)
, ((modMask, xK_Return), spawn $ "alacritty" )
, ((modMask, xK_q), kill )
, ((modMask, xK_t), spawn $ "termite" )
, ((modMask, xK_r), spawn $ "rofi -show drun" )
, ((modMask, xK_v), spawn $ "pavucontrol" )
, ((modMask, xK_x), spawn $ "arcolinux-logout" )
, ((modMask, xK_l), spawn $ "betterlockscreen -l" )
, ((modMask, xK_Escape), spawn $ "xkill" )
, ((modMask, xK_e), spawn $ "thunar" )
, ((modMask, xK_s ), spawn $ "xfce4-settings-manager")
--, ((modMask, xK_c), spawn $ "conky-toggle" )
--, ((modMask, xK_y), spawn $ "polybar-msg cmd toggle" )
-- FUNCTION KEYS
, ((0, xK_F12), spawn $ "xfce4-terminal --drop-down" )
-- SUPER + SHIFT KEYS
, ((modMask .|. shiftMask , xK_r ), spawn $ "xmonad --recompile && xmonad --restart")
, ((modMask .|. shiftMask , xK_q ), kill)
-- , ((modMask .|. shiftMask , xK_x ), io (exitWith ExitSuccess))
-- CONTROL + KEYS
-- CONTROL + ALT KEYS
, ((controlMask .|. mod1Mask , xK_v ), spawn $ "virt-manager")
, ((controlMask .|. mod1Mask , xK_Prior ), spawn $ "conky-rotate -p")
, ((controlMask .|. mod1Mask , xK_a ), spawn $ "xfce4-appfinder")
, ((controlMask .|. mod1Mask , xK_b ), spawn $ "thunar")
, ((controlMask .|. mod1Mask , xK_c ), spawn $ "catfish")
, ((controlMask .|. mod1Mask , xK_e ), spawn $ "arcolinux-tweak-tool")
, ((controlMask .|. mod1Mask , xK_f ), spawn $ "firefox")
, ((controlMask .|. mod1Mask , xK_i ), spawn $ "nitrogen")
, ((controlMask .|. mod1Mask , xK_o ), spawn $ "$HOME/.xmonad/scripts/picom-toggle.sh")
, ((controlMask .|. mod1Mask , xK_t ), spawn $ "urxvt")
, ((controlMask .|. mod1Mask , xK_u ), spawn $ "pavucontrol")
--, ((controlMask .|. mod1Mask , xK_r ), spawn $ "rofi-theme-selector")
--, ((controlMask .|. mod1Mask , xK_k ), spawn $ "arcolinux-logout")
--, ((controlMask .|. mod1Mask , xK_l ), spawn $ "arcolinux-logout")
--, ((controlMask .|. mod1Mask , xK_Next ), spawn $ "conky-rotate -n")
-- ALT + ... KEYS
, ((mod1Mask, xK_n), spawn $ "variety -n" )
, ((mod1Mask, xK_F3), spawn $ "xfce4-appfinder" )
, ((mod1Mask, xK_p), spawn $ "variety -p" )
, ((mod1Mask, xK_r), spawn $ "xmonad --restart" )
--, ((mod1Mask, xK_f), spawn $ "variety -f" )
--, ((mod1Mask, xK_t), spawn $ "variety -t" )
--, ((mod1Mask, xK_Up), spawn $ "variety --pause" )
--, ((mod1Mask, xK_Down), spawn $ "variety --resume" )
--, ((mod1Mask, xK_Left), spawn $ "variety -p" )
--, ((mod1Mask, xK_Right), spawn $ "variety -n" )
--, ((mod1Mask, xK_F2), spawn $ "xfce4-appfinder --collapsed" )
--VARIETY KEYS WITH PYWAL
--, ((mod1Mask .|. shiftMask , xK_f ), spawn $ "variety -f && wal -i $(cat $HOME/.config/variety/wallpaper/wallpaper.jpg.txt)&")
--, ((mod1Mask .|. shiftMask , xK_n ), spawn $ "variety -n && wal -i $(cat $HOME/.config/variety/wallpaper/wallpaper.jpg.txt)&")
--, ((mod1Mask .|. shiftMask , xK_p ), spawn $ "variety -p && wal -i $(cat $HOME/.config/variety/wallpaper/wallpaper.jpg.txt)&")
--, ((mod1Mask .|. shiftMask , xK_t ), spawn $ "variety -t && wal -i $(cat $HOME/.config/variety/wallpaper/wallpaper.jpg.txt)&")
--, ((mod1Mask .|. shiftMask , xK_u ), spawn $ "wal -i $(cat $HOME/.config/variety/wallpaper/wallpaper.jpg.txt)&")
--CONTROL + SHIFT KEYS
--SCREENSHOTS
, ((0, xK_Print), spawn $ "flameshot gui")
--, ((0, xK_Print), spawn $ "scrot 'ArcoLinux-%Y-%m-%d-%s_screenshot_$wx$h.jpg' -e 'mv $f $$(xdg-user-dir PICTURES)'")
, ((controlMask, xK_Print), spawn $ "xfce4-screenshooter" )
, ((controlMask .|. shiftMask , xK_Print ), spawn $ "gnome-screenshot -a -c")
--MULTIMEDIA KEYS
-- Mute volume
, ((0, xF86XK_AudioMute), spawn $ "amixer -q set Master toggle")
-- Decrease volume
, ((0, xF86XK_AudioLowerVolume), spawn $ "amixer -q set Master 5%-")
-- Increase volume
, ((0, xF86XK_AudioRaiseVolume), spawn $ "amixer -q set Master 5%+")
-- Increase brightness
, ((0, xF86XK_MonBrightnessUp), spawn $ "light -A 5")
-- Decrease brightness
, ((0, xF86XK_MonBrightnessDown), spawn $ "light -U 5")
-- , ((0, xF86XK_AudioPlay), spawn $ "mpc toggle")
-- , ((0, xF86XK_AudioNext), spawn $ "mpc next")
-- , ((0, xF86XK_AudioPrev), spawn $ "mpc prev")
-- , ((0, xF86XK_AudioStop), spawn $ "mpc stop")
, ((0, xF86XK_AudioPlay), spawn $ "playerctl play-pause")
, ((0, xF86XK_AudioNext), spawn $ "playerctl next")
, ((0, xF86XK_AudioPrev), spawn $ "playerctl previous")
, ((0, xF86XK_AudioStop), spawn $ "playerctl stop")
--------------------------------------------------------------------
-- XMONAD LAYOUT KEYS
-- Cycle through the available layout algorithms.
, ((modMask, xK_space), sendMessage NextLayout)
--Focus selected desktop
, ((mod1Mask, xK_Tab), nextWS)
--Focus selected desktop
, ((modMask, xK_Tab), nextWS)
--Focus selected desktop
, ((controlMask .|. mod1Mask , xK_Left ), prevWS)
--Focus selected desktop
, ((controlMask .|. mod1Mask , xK_Right ), nextWS)
-- Reset the layouts on the current workspace to default.
, ((modMask .|. shiftMask, xK_space), setLayout $ XMonad.layoutHook conf)
-- Move focus to the next window.
, ((modMask, xK_j), windows W.focusDown)
-- Move focus to the previous window.
, ((modMask, xK_k), windows W.focusUp )
-- Move focus to the master window.
, ((modMask .|. shiftMask, xK_m), windows W.focusMaster )
-- Swap the focused window with the next window.
, ((modMask .|. shiftMask, xK_j), windows W.swapDown )
-- Swap the focused window with the next window.
, ((controlMask .|. modMask, xK_Down), windows W.swapDown )
-- Swap the focused window with the previous window.
, ((modMask .|. shiftMask, xK_k), windows W.swapUp )
-- Swap the focused window with the previous window.
, ((controlMask .|. modMask, xK_Up), windows W.swapUp )
-- Shrink the master area.
, ((controlMask .|. shiftMask , xK_h), sendMessage Shrink)
-- Expand the master area.
, ((controlMask .|. shiftMask , xK_l), sendMessage Expand)
-- Push window back into tiling.
, ((controlMask .|. shiftMask , xK_t), withFocused $ windows . W.sink)
-- Increment the number of windows in the master area.
, ((controlMask .|. modMask, xK_Left), sendMessage (IncMasterN 1))
-- Decrement the number of windows in the master area.
, ((controlMask .|. modMask, xK_Right), sendMessage (IncMasterN (-1)))
]
++
-- mod-[1..9], Switch to workspace N
-- mod-shift-[1..9], Move client to workspace N
[((m .|. modMask, k), windows $ f i)
--Keyboard layouts
--qwerty users use this line
| (i, k) <- zip (XMonad.workspaces conf) [xK_1,xK_2,xK_3,xK_4,xK_5,xK_6,xK_7,xK_8,xK_9,xK_0]
--French Azerty users use this line
-- | (i, k) <- zip (XMonad.workspaces conf) [xK_ampersand, xK_eacute, xK_quotedbl, xK_apostrophe, xK_parenleft, xK_minus, xK_egrave, xK_underscore, xK_ccedilla , xK_agrave]
--Belgian Azerty users use this line
-- | (i, k) <- zip (XMonad.workspaces conf) [xK_ampersand, xK_eacute, xK_quotedbl, xK_apostrophe, xK_parenleft, xK_section, xK_egrave, xK_exclam, xK_ccedilla, xK_agrave]
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)
, (\i -> W.greedyView i . W.shift i, shiftMask)]]
++
-- ctrl-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
-- ctrl-shift-{w,e,r}, Move client to screen 1, 2, or 3
[((m .|. controlMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
| (key, sc) <- zip [xK_w, xK_e] [0..]
, (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
main :: IO ()
main = do
dbus <- D.connectSession
-- Request access to the DBus name
D.requestName dbus (D.busName_ "org.xmonad.Log")
[D.nameAllowReplacement, D.nameReplaceExisting, D.nameDoNotQueue]
xmonad . ewmh $
--Keyboard layouts
--qwerty users use this line
myBaseConfig
--French Azerty users use this line
--myBaseConfig { keys = azertyKeys <+> keys azertyConfig }
--Belgian Azerty users use this line
--myBaseConfig { keys = belgianKeys <+> keys belgianConfig }
{startupHook = myStartupHook
, layoutHook = gaps [(U,35), (D,5), (R,5), (L,5)] $ myLayout ||| layoutHook myBaseConfig
, manageHook = manageSpawn <+> myManageHook <+> manageHook myBaseConfig
, modMask = myModMask
, borderWidth = myBorderWidth
, handleEventHook = handleEventHook myBaseConfig <+> fullscreenEventHook
, focusFollowsMouse = myFocusFollowsMouse
, workspaces = myWorkspaces
, focusedBorderColor = focdBord
, normalBorderColor = normBord
, keys = myKeys
, mouseBindings = myMouseBindings
}
答案1
我不知道有什么方法可以在一个键绑定中完成所有这些操作,但可以通过两个键绑定来完成。
从 myLayout 中删除避免Struts,使其看起来如下所示:
myLayout = spacingRaw True (Border 0 5 5 5) True (Border 5 5 5 5) True $ mkToggle (NBFULL ?? NOBORDERS ?? EOT) $ tiled ||| Mirror tiled ||| spiral (6/7) ||| ThreeColMid 1 (3/100) (1/2) ||| Full
where
tiled = Tall nmaster delta tiled_ratio
nmaster = 1
delta = 3/100
tiled_ratio = 1/2
将以下内容添加到“超级+功能键”:
, ((modMask, xK_b), sendMessage ToggleGaps >> spawn "polybar-msg cmd toggle")
完成这些更改后,您可以执行 SUPER + F,然后执行 SUPER + B 以使应用程序全屏显示。
答案2
这也适用于全屏启动应用程序:
, ((modMask, xK_x), sendMessage (JumpToLayout "Full") >> spawn "archlinux-logout")
要跳转到全屏模式,请执行以下操作:
, ((modMask .|. shiftMask, xK_l), sendMessage $ JumpToLayout "Full" )