Merge pull request #717 from Pachin0/desktop-viewport

X.H.EwmhDesktops: Add `_NET_DESKTOP_VIEWPORT` support
This commit is contained in:
Tony Zorman 2022-05-06 08:51:33 +02:00 committed by GitHub
commit 21e613e242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -181,6 +181,11 @@
- Added support for dynamic scratchpads in the form of - Added support for dynamic scratchpads in the form of
`dynamicNSPAction` and `toggleDynamicNSP`. `dynamicNSPAction` and `toggleDynamicNSP`.
* `XMonad.Hooks.EwmhDesktops`
- Added support for `_NET_DESKTOP_VIEWPORT`, which is required by
some status bars.
### Other changes ### Other changes
* Migrated the sample build scripts from the deprecated `xmonad-testing` repo to * Migrated the sample build scripts from the deprecated `xmonad-testing` repo to

View File

@ -293,6 +293,10 @@ instance ExtensionClass WindowDesktops where initialValue = WindowDesktops (M.si
newtype ActiveWindow = ActiveWindow Window deriving Eq newtype ActiveWindow = ActiveWindow Window deriving Eq
instance ExtensionClass ActiveWindow where initialValue = ActiveWindow (complement none) instance ExtensionClass ActiveWindow where initialValue = ActiveWindow (complement none)
-- | Cached @_NET_DESKTOP_VIEWPORT@
newtype MonitorTags = MonitorTags [WorkspaceId] deriving (Show,Eq)
instance ExtensionClass MonitorTags where initialValue = MonitorTags []
-- | Compare the given value against the value in the extensible state. Run the -- | Compare the given value against the value in the extensible state. Run the
-- action if it has changed. -- action if it has changed.
whenChanged :: (Eq a, ExtensionClass a) => a -> X () -> X () whenChanged :: (Eq a, ExtensionClass a) => a -> X () -> X ()
@ -337,6 +341,32 @@ ewmhDesktopsLogHook' EwmhDesktopsConfig{workspaceSort, workspaceRename} = withWi
let activeWindow' = fromMaybe none (W.peek s) let activeWindow' = fromMaybe none (W.peek s)
whenChanged (ActiveWindow activeWindow') $ setActiveWindow activeWindow' whenChanged (ActiveWindow activeWindow') $ setActiveWindow activeWindow'
-- Set desktop Viewport
let visibleScreens = W.current s : W.visible s
currentTags = map (W.tag . W.workspace) visibleScreens
whenChanged (MonitorTags currentTags) $ mkViewPorts s (map W.tag ws)
-- | Create the viewports from the current 'WindowSet' and a list of
-- already sorted workspace IDs.
mkViewPorts :: WindowSet -> [WorkspaceId] -> X ()
mkViewPorts winset = setDesktopViewport . concat . mapMaybe (viewPorts M.!?)
where
foc = W.current winset
-- Hidden workspaces are mapped to the current screen's viewport.
viewPorts :: M.Map WorkspaceId [Position]
viewPorts = M.fromList $ map mkVisibleViewPort (foc : W.visible winset)
++ map (mkViewPort foc) (W.hidden winset)
mkViewPort :: WindowScreen -> WindowSpace -> (WorkspaceId, [Position])
mkViewPort scr w = (W.tag w, mkPos scr)
mkVisibleViewPort :: WindowScreen -> (WorkspaceId, [Position])
mkVisibleViewPort x = mkViewPort x (W.workspace x)
mkPos :: WindowScreen -> [Position]
mkPos scr = [rect_x (rect scr), rect_y (rect scr)]
where rect = screenRect . W.screenDetail
ewmhDesktopsEventHook' :: Event -> EwmhDesktopsConfig -> X All ewmhDesktopsEventHook' :: Event -> EwmhDesktopsConfig -> X All
ewmhDesktopsEventHook' ewmhDesktopsEventHook'
ClientMessageEvent{ev_window = w, ev_message_type = mt, ev_data = d} ClientMessageEvent{ev_window = w, ev_message_type = mt, ev_data = d}
@ -461,6 +491,12 @@ setActiveWindow w = withDisplay $ \dpy -> do
a <- getAtom "_NET_ACTIVE_WINDOW" a <- getAtom "_NET_ACTIVE_WINDOW"
io $ changeProperty32 dpy r a wINDOW propModeReplace [fromIntegral w] io $ changeProperty32 dpy r a wINDOW propModeReplace [fromIntegral w]
setDesktopViewport :: [Position] -> X ()
setDesktopViewport positions = withDisplay $ \dpy -> do
r <- asks theRoot
a <- io $ internAtom dpy "_NET_DESKTOP_VIEWPORT" True
io $ changeProperty32 dpy r a cARDINAL propModeReplace (map fi positions)
setSupported :: X () setSupported :: X ()
setSupported = withDisplay $ \dpy -> do setSupported = withDisplay $ \dpy -> do
r <- asks theRoot r <- asks theRoot