Skip to content

Commit

Permalink
X.H.EwmhDesktops: Added customization for external desktop switching.
Browse files Browse the repository at this point in the history
Added a configuration option to change the action for handling the
_NET_CURRENT_DESKTOP requests.
  • Loading branch information
m1mir committed Jan 23, 2025
1 parent c0a5bc5 commit e5377d0
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions XMonad/Hooks/EwmhDesktops.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ module XMonad.Hooks.EwmhDesktops (
-- $customActivate
setEwmhActivateHook,

-- ** External workspace switching
-- $customWorkspaceSwitch
setEwmhSwitchDesktopAction,

-- ** Fullscreen
-- $customFullscreen
setEwmhFullscreenHooks,
Expand Down Expand Up @@ -114,6 +118,8 @@ data EwmhDesktopsConfig =
-- ^ configurable handling of window activation requests
, fullscreenHooks :: (ManageHook, ManageHook)
-- ^ configurable handling of fullscreen state requests
, switchDesktopAction :: WorkspaceId -> WindowSet -> WindowSet
-- ^ configurable action for handling _NET_CURRENT_DESKTOP
, manageDesktopViewport :: Bool
-- ^ manage @_NET_DESKTOP_VIEWPORT@?
}
Expand All @@ -124,6 +130,7 @@ instance Default EwmhDesktopsConfig where
, workspaceRename = pure pure
, activateHook = doFocus
, fullscreenHooks = (doFullFloat, doSink)
, switchDesktopAction = W.view
, manageDesktopViewport = True
}

Expand Down Expand Up @@ -245,6 +252,22 @@ setEwmhActivateHook :: ManageHook -> XConfig l -> XConfig l
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.
--
-- > -- TODO add code example

-- | Set (replace) the action which is invoked when a client sends a
-- @_NET_CURRENT_DESKTOP@ request to switch workspace.
setEwmhSwitchDesktopAction :: (WorkspaceId -> WindowSet -> WindowSet) -> XConfig l -> XConfig l
setEwmhSwitchDesktopAction action = XC.modifyDef $ \c -> c{ switchDesktopAction = action }


-- $customFullscreen
-- 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
Expand Down Expand Up @@ -449,7 +472,7 @@ mkViewPorts winset = setDesktopViewport . concat . mapMaybe (viewPorts M.!?)
ewmhDesktopsEventHook' :: Event -> EwmhDesktopsConfig -> X All
ewmhDesktopsEventHook'
ClientMessageEvent{ev_window = w, ev_message_type = mt, ev_data = d}
EwmhDesktopsConfig{workspaceSort, activateHook} =
EwmhDesktopsConfig{workspaceSort, activateHook, switchDesktopAction} =
withWindowSet $ \s -> do
sort' <- workspaceSort
let ws = sort' $ W.workspaces s
Expand All @@ -462,7 +485,7 @@ ewmhDesktopsEventHook'
if | mt == a_cw ->
killWindow w
| 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 $ switchDesktopAction (W.tag ww)
| mt == a_cd ->
trace $ "Bad _NET_CURRENT_DESKTOP with data=" ++ show d
| not (w `W.member` s) ->
Expand Down

0 comments on commit e5377d0

Please sign in to comment.