X.H.EwmhDesktops: Added customization for external desktop switching.

Added a configuration option to change the action for handling the
_NET_CURRENT_DESKTOP requests.
This commit is contained in:
m1mir 2025-01-23 16:01:42 +01:00 committed by Tony Zorman
parent c0a5bc5f0f
commit 2b11459496
2 changed files with 40 additions and 2 deletions

View File

@ -39,6 +39,12 @@
`DestroyWindowEvent` messages instead, which are broadcast to layouts `DestroyWindowEvent` messages instead, which are broadcast to layouts
since xmonad v0.17.0. since xmonad v0.17.0.
* `XMonad.Hooks.EwmhDesktops`
- Added a customization option for the action that gets executed when
a client sends a **_NET_CURRENT_DESKTOP** request. It is now possible
to change it using the `setEwmhSwitchDesktopHook`.
## 0.18.1 (August 20, 2024) ## 0.18.1 (August 20, 2024)
### Breaking Changes ### Breaking Changes

View File

@ -42,6 +42,10 @@ module XMonad.Hooks.EwmhDesktops (
-- $customActivate -- $customActivate
setEwmhActivateHook, setEwmhActivateHook,
-- ** Workspace switching
-- $customWorkspaceSwitch
setEwmhSwitchDesktopHook,
-- ** Fullscreen -- ** Fullscreen
-- $customFullscreen -- $customFullscreen
setEwmhFullscreenHooks, setEwmhFullscreenHooks,
@ -114,6 +118,8 @@ data EwmhDesktopsConfig =
-- ^ configurable handling of window activation requests -- ^ configurable handling of window activation requests
, fullscreenHooks :: (ManageHook, ManageHook) , fullscreenHooks :: (ManageHook, ManageHook)
-- ^ configurable handling of fullscreen state requests -- ^ configurable handling of fullscreen state requests
, switchDesktopHook :: WorkspaceId -> WindowSet -> WindowSet
-- ^ configurable action for handling _NET_CURRENT_DESKTOP
, manageDesktopViewport :: Bool , manageDesktopViewport :: Bool
-- ^ manage @_NET_DESKTOP_VIEWPORT@? -- ^ manage @_NET_DESKTOP_VIEWPORT@?
} }
@ -124,6 +130,7 @@ instance Default EwmhDesktopsConfig where
, workspaceRename = pure pure , workspaceRename = pure pure
, activateHook = doFocus , activateHook = doFocus
, fullscreenHooks = (doFullFloat, doSink) , fullscreenHooks = (doFullFloat, doSink)
, switchDesktopHook = W.view
, manageDesktopViewport = True , manageDesktopViewport = True
} }
@ -245,6 +252,31 @@ setEwmhActivateHook :: ManageHook -> XConfig l -> XConfig l
setEwmhActivateHook h = XC.modifyDef $ \c -> c{ activateHook = h } setEwmhActivateHook h = XC.modifyDef $ \c -> c{ activateHook = h }
-- $customWorkspaceSwitch
-- When a client sends a @_NET_CURRENT_DESKTOP@ request to switch to a workspace,
-- the default action used to do that is the 'W.view' function.
-- This may not be the desired behaviour in all configurations.
--
-- For example if using the "XMonad.Layout.IndependentScreens" the default action
-- might move a workspace to a screen that it isn't supposed to be on.
-- This behaviour can be fixed using the following:
--
-- > import XMonad.Actions.OnScreen
-- > import XMonad.Layout.IndependentScreens
-- >
-- > main = xmonad $ ... . setEwmhSwitchDesktopHook focusWorkspace . ewmh . ... $
-- > def{
-- > ...
-- > workspaces = withScreens 2 (workspaces def)
-- > ...
-- > }
-- | Set (replace) the action which is invoked when a client sends a
-- @_NET_CURRENT_DESKTOP@ request to switch workspace.
setEwmhSwitchDesktopHook :: (WorkspaceId -> WindowSet -> WindowSet) -> XConfig l -> XConfig l
setEwmhSwitchDesktopHook action = XC.modifyDef $ \c -> c{ switchDesktopHook = action }
-- $customFullscreen -- $customFullscreen
-- When a client sends a @_NET_WM_STATE@ request to add\/remove\/toggle the -- When a client sends a @_NET_WM_STATE@ request to add\/remove\/toggle the
-- @_NET_WM_STATE_FULLSCREEN@ state, 'ewmhFullscreen' uses a pair of hooks to -- @_NET_WM_STATE_FULLSCREEN@ state, 'ewmhFullscreen' uses a pair of hooks to
@ -449,7 +481,7 @@ mkViewPorts winset = setDesktopViewport . concat . mapMaybe (viewPorts M.!?)
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}
EwmhDesktopsConfig{workspaceSort, activateHook} = EwmhDesktopsConfig{workspaceSort, activateHook, switchDesktopHook} =
withWindowSet $ \s -> do withWindowSet $ \s -> do
sort' <- workspaceSort sort' <- workspaceSort
let ws = sort' $ W.workspaces s let ws = sort' $ W.workspaces s
@ -462,7 +494,7 @@ ewmhDesktopsEventHook'
if | mt == a_cw -> if | mt == a_cw ->
killWindow w killWindow w
| mt == a_cd, n : _ <- d, Just ww <- ws !? fi n -> | mt == a_cd, n : _ <- d, Just ww <- ws !? fi n ->
if W.currentTag s == W.tag ww then mempty else windows $ W.view (W.tag ww) if W.currentTag s == W.tag ww then mempty else windows $ switchDesktopHook (W.tag ww)
| mt == a_cd -> | mt == a_cd ->
trace $ "Bad _NET_CURRENT_DESKTOP with data=" ++ show d trace $ "Bad _NET_CURRENT_DESKTOP with data=" ++ show d
| not (w `W.member` s) -> | not (w `W.member` s) ->