Skip to content

Commit f984c12

Browse files
committed
feat: add screen type detection and adjust floating window logic
1 parent 6be1742 commit f984c12

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

src/Utils.hs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ toggleFloat w =
4141
(^=?) :: (Eq a) => Query [a] -> [a] -> Query Bool
4242
q ^=? x = L.isPrefixOf x <$> q
4343

44-
45-
4644
-- receive one sperate and three funs to format count, focused window and unfocused window
4745
myLogTitles ::
4846
String ->
@@ -100,15 +98,38 @@ logWinCount :: X Int
10098
logWinCount = length . W.index . windowset <$> get
10199

102100
logIsVerticalScreen :: X Bool
103-
logIsVerticalScreen = curScreenId <&> isScreenVertical
104-
105-
trimPrefixWithList :: [String] -> String -> String
101+
logIsVerticalScreen = do
102+
rect <- logFocusedScreenRect
103+
return $ rect_height rect > rect_width rect
104+
105+
data ScreenType = Screen1080p | Screen2K | ScreenUltraWide
106+
deriving (Show, Eq)
107+
108+
-- | Determine screen type based on physical dimensions and aspect ratio
109+
logScreenType :: X ScreenType
110+
logScreenType = do
111+
rect <- logFocusedScreenRect
112+
isVertical <- logIsVerticalScreen
113+
let (w, h) =
114+
if isVertical
115+
then (rect_height rect, rect_width rect)
116+
else (rect_width rect, rect_height rect)
117+
aspectRatio = (fromIntegral w :: Double) / fromIntegral h
118+
return $
119+
if aspectRatio > 2.0
120+
then ScreenUltraWide
121+
else
122+
if w > 2560 -- 2K width threshold
123+
then Screen2K
124+
else Screen1080p
125+
126+
trimPrefixWithList :: [String] -> String -> String
106127
-- trimPrefixWithList _ Nothing = Nothing
107128
trimPrefixWithList xs s = case mapMaybe (`L.stripPrefix` s) xs of
108-
[] -> s
129+
[] -> s
109130
n : _ -> trimPrefixWithList xs n
110131

111-
trimLayoutModifiers :: String -> String
132+
trimLayoutModifiers :: String -> String
112133
trimLayoutModifiers = trimPrefixWithList ["Spacing", " "]
113134

114135
isMaster :: W.StackSet i l a s sd -> Bool

src/WeissScratchpad.hs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,16 @@ niceFloating = do
7272
isM <- liftX logMaster
7373
layout <- liftX logLayout <&> fmap trimLayoutModifiers
7474
c <- liftX logWinCount <&> (\c -> c - 1) -- exclude the NSP window
75-
doRectFloat $ case (isV, isM, layout) of
76-
(False, False, Just l)
75+
screenType <- liftX logScreenType
76+
doRectFloat $ case (isV, isM, layout, screenType) of
77+
(False, False, Just l, _)
7778
| c == 3 && "ThreeCol" `isInfixOf` l -> r (33 / 100) (6 / 50) (32 / 100) (25 / 50)
78-
(False, False, Just l)
79+
(False, False, Just l, _)
7980
| c == 2 && "ThreeCol" `isInfixOf` l ->
8081
r (1 / 100) (6 / 50) (30 / 100) (25 / 50)
81-
(False, _, _) -> r (66 / 100) (6 / 50) (33 / 100) (25 / 50)
82-
-- (_, Just "StackTile") -> r (1 / 50) (26 / 50) (45 / 50) (20 / 50)
83-
-- (True, Just "Mirror Tall") -> r (1 / 50) (26 / 50) (45 / 50) (20 / 50)
84-
-- (False, Just "Mirror Tall") -> r (1 / 50) (5 / 50) (45 / 50) (20 / 50)
85-
(True, True, _) -> r (1 / 50) (26 / 50) (46 / 50) (20 / 50)
86-
(True, False, _) -> r (1 / 50) (3 / 50) (46 / 50) (20 / 50)
82+
(False, _, _, _) -> r (66 / 100) (6 / 50) (33 / 100) (25 / 50)
83+
(True, True, _, _) -> r (1 / 50) (26 / 50) (46 / 50) (20 / 50)
84+
(True, False, _, _) -> r (1 / 50) (3 / 50) (46 / 50) (20 / 50)
8785

8886
newtype CurrentScratchpadName = CurrentScratchpadName String
8987
instance ExtensionClass CurrentScratchpadName where

0 commit comments

Comments
 (0)