Skip to content

Commit 86081fc

Browse files
committed
improve switch window logic
1 parent 354cfea commit 86081fc

File tree

2 files changed

+48
-18
lines changed

2 files changed

+48
-18
lines changed

src/WeissWindowOperations.hs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ module WeissWindowOperations (weissSwap, weissSwitchFocus, weissSwitchRecent, we
44

55
import Data.List qualified as L
66
import Data.List.Unique
7-
import Data.Map qualified
8-
import Data.Map qualified as M
97
import Data.Map qualified as Map
108
import Data.Maybe
119
import TreeActions (weissTreeActions)
@@ -71,14 +69,40 @@ weissSwap = onWindowsCount $ \c ->
7169
weissSwitchFocus :: X ()
7270
weissSwitchFocus = selectWindow rightHandMotionConf >>= (`whenJust` windows . W.focusWindow)
7371

72+
_notScratchWs :: Query Bool
73+
_notScratchWs = do
74+
w <- ask
75+
ws <- liftX $ gets windowset
76+
let tag = W.findTag w ws
77+
return $ isJust tag && tag /= Just scratchpadWorkspaceTag
78+
79+
-- | Get all unfocused floating windows on any visible workspace.
80+
getUnfocusedVisibleFloats :: X [Window]
81+
getUnfocusedVisibleFloats = do
82+
ws <- gets windowset
83+
let visibleWorkspaceTags = map (W.tag . W.workspace) (W.current ws : W.visible ws)
84+
allFloatingWindows = W.floating ws
85+
onVisible wsTag = wsTag `elem` visibleWorkspaceTags
86+
visibleFloatingWindows = Map.filterWithKey (\w _ -> maybe False onVisible (W.findTag w ws)) allFloatingWindows
87+
maybeFocused = W.peek ws
88+
unfocusedFloats = case maybeFocused of
89+
Just focused -> Map.delete focused visibleFloatingWindows
90+
Nothing -> visibleFloatingWindows
91+
return $ Map.keys unfocusedFloats
92+
93+
{- | A query that matches switchable windows.
94+
If there are unfocused floating windows on a visible workspace, it matches only those.
95+
Otherwise, it matches all unfocused tiled windows on visible workspaces.
96+
-}
97+
mySwitchableWindows :: Query Bool
98+
mySwitchableWindows = do
99+
unfocusedFloats <- liftX getUnfocusedVisibleFloats
100+
if null unfocusedFloats
101+
then isOnAnyVisibleWS
102+
else fmap (\w -> w `elem` unfocusedFloats) ask
103+
74104
weissSwitchRecent :: X ()
75-
weissSwitchRecent = nextMatch History isOnAnyVisibleWS
76-
where
77-
_notScratchWs = do
78-
w <- ask
79-
ws <- liftX $ gets windowset
80-
let tag = W.findTag w ws
81-
return $ isJust tag && tag /= Just scratchpadWorkspaceTag
105+
weissSwitchRecent = nextMatch History mySwitchableWindows
82106

83107
-- | Focus the master window of the current workspace
84108
weissFocusMaster :: X ()

src/WeissXMonad.hs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,20 @@ myLayout =
9999
mouseResize $
100100
windowArrange $
101101
ifWider
102-
1500
102+
3000
103103
(threeCol ||| Full)
104-
(Mirror threeCol ||| mouseResizableTile {isMirrored = True, masterFrac = 0.7} ||| Full)
104+
( ifWider
105+
1500
106+
(myTall ||| Full)
107+
(Mirror threeCol ||| verticalTall ||| Full)
108+
)
105109
where
106-
threeCol = ResizableThreeColMid 1 (1 / 100) (-1 / 3) []
110+
threeCol = ResizableThreeColMid 1 (1 / 100) (-(1 / 3)) []
107111
myMulCol = multiCol [1, 1] 0 0.01 (-0.5)
108112
twoPane = TwoPane delta ratio
109-
myTall = Tall nmaster delta ratio
113+
-- myTall = Tall nmaster delta ratio
114+
myTall = mouseResizableTile {isMirrored = False, masterFrac = 0.55}
115+
verticalTall = mouseResizableTile {isMirrored = True, masterFrac = 0.6}
110116
myStackTile = StackTile 1 (3 / 100) (4 / 9)
111117
nmaster = 1
112118
ratio = 1 / 2
@@ -147,15 +153,15 @@ myKeys =
147153
<> [ ("<XF86Launch7> " <> key, fun)
148154
| (key, fun) <-
149155
[ ("t", sendMessage NextLayout)
150-
, -- , ("e", pure ())
151-
("r", spawn "xmonad --restart")
152-
, ("v", spawn "sh $HOME/.screenlayout/vertical.sh")
153-
, ("b", spawn "sh $HOME/.screenlayout/horizontal.sh")
154156
, ("s", spawn "flameshot gui")
155157
, -- ("f", spawn "fcitx-remote -s fcitx-keyboard-de-nodeadkeys"),
156158
("w", spawn "$SCRIPTS_DIR/notify_window_title.sh")
157159
, ("p", mkPassPrompt "select pass" sendToClj myXPConfig)
158160
, ("M-2", nextScreen)
161+
-- , ("e", exp1 >>= \x -> flashText def 3 x)
162+
-- , ("r", spawn "xmonad --restart")
163+
-- , ("v", spawn "sh $HOME/.screenlayout/vertical.sh")
164+
-- , ("b", spawn "sh $HOME/.screenlayout/horizontal.sh")
159165
-- , ("h" , spawn "rofi-pass")
160166
-- ("<Left>", sendMessage $ Move L),
161167
-- ("<Right>", sendMessage $ Move R),
@@ -207,7 +213,7 @@ myConfig =
207213
, normalBorderColor = myNormColor
208214
, focusedBorderColor = myFocusColor
209215
, -- return () to avoid infinite mutual recursion
210-
startupHook = return () >> checkKeymap myConfig myKeys >> scratchpadsExclusives >> spawn "systemctl --user start autostart.target"
216+
startupHook = return () >> checkKeymap myConfig myKeys >> scratchpadsExclusives >> spawn "sleep 10s && systemctl --user start autostart.target"
211217
, handleEventHook = handleEventHook def <> handleTimerEvent
212218
, focusFollowsMouse = True
213219
}

0 commit comments

Comments
 (0)