From dc8d1c63c72cbacc30864eb86b138b0d35871d39 Mon Sep 17 00:00:00 2001 From: mail Date: Sun, 7 Oct 2007 01:30:10 +0200 Subject: NextWorkspace: Go forward or backward Hi, inspired by RotView, I implemented an Extension that allows the user to go forward or backward in the list of workspaces, or to move the current window to the next or previous workspace. Haddock included. Works here, but hardly tested (and while tired). Cu torrow @ HacII, if you are there. Greetings, Joachim darcs-hash:20071006233010-c9905-35ef3364ee10c770aef2a35a295d11b519b0ca7c.gz --- MetaModule.hs | 1 + NextWorkspace.hs | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 NextWorkspace.hs diff --git a/MetaModule.hs b/MetaModule.hs index bacc475..4d43044 100644 --- a/MetaModule.hs +++ b/MetaModule.hs @@ -55,6 +55,7 @@ import XMonadContrib.Maximize () import XMonadContrib.MosaicAlt () import XMonadContrib.MouseGestures () import XMonadContrib.NamedWindows () +import XMonadContrib.NextWorkspace () import XMonadContrib.NoBorders () import XMonadContrib.ResizableTile () import XMonadContrib.Roledex () diff --git a/NextWorkspace.hs b/NextWorkspace.hs new file mode 100644 index 0000000..8243a62 --- /dev/null +++ b/NextWorkspace.hs @@ -0,0 +1,91 @@ +----------------------------------------------------------------------------- +-- | +-- Module : XMonadContrib.NextWorkspace +-- Copyright : (c) Joachim Breitner +-- License : BSD3-style (see LICENSE) +-- +-- Maintainer : Joachim Breitner +-- Stability : unstable +-- Portability : unportable +-- +-- Provides bindings to cycle forward or backward through the list +-- of workspaces, and to move windows there. +-- +----------------------------------------------------------------------------- + +module XMonadContrib.NextWorkspace ( + -- * Usage + -- $usage + nextWorkspace, + prevWorkspace, + shiftToNext, + shiftToPrev, + ) where + +import Control.Monad.State ( gets ) +import Data.List ( sortBy, findIndex ) +import Data.Maybe ( fromMaybe ) +import Data.Ord ( comparing ) + +import XMonad +import StackSet hiding (filter, findIndex) +import Operations +import {-# SOURCE #-} qualified Config (workspaces) + +-- $usage +-- You can use this module with the following in your Config.hs file: +-- +-- > import XMonadContrib.NextWorkspace +-- +-- > , ((modMask, xK_Right), nextWorkspace) +-- > , ((modMask, xK_Left), prevWorkspace) +-- > , ((modMask .|. shiftMask, xK_Right), shiftToNext) +-- > , ((modMask .|. shiftMask, xK_Left), shiftToPrev) + +-- %import XMonadContrib.RotView +-- %keybind , ((modMask .|. shiftMask, xK_Right), rotView True) +-- %keybind , ((modMask .|. shiftMask, xK_Left), rotView False) + + +-- --------------------- +-- | +-- Switch to next workspace +nextWorkspace :: X() +nextWorkspace = switchWorkspace (1) + +-- --------------------- +-- | +-- Switch to previous workspace +prevWorkspace :: X() +prevWorkspace = switchWorkspace (-1) + +-- | +-- Move focused window to next workspace +shiftToNext :: X() +shiftToNext = shiftBy (1) + +-- | +-- Move focused window to previous workspace +shiftToPrev :: X () +shiftToPrev = shiftBy (-1) + +switchWorkspace :: Int -> X () +switchWorkspace d = wsBy d >>= windows . greedyView + +shiftBy :: Int -> X () +shiftBy d = wsBy d >>= windows . shift + +wsBy :: Int -> X (WorkspaceId) +wsBy d = do + ws <- gets windowset + let orderedWs = sortBy (comparing wsIndex) (workspaces ws) + let now = fromMaybe 0 $ findWsIndex (workspace (current ws)) orderedWs + let next = orderedWs !! ((now + d) `mod` length orderedWs) + return $ tag next + + +wsIndex :: WindowSpace -> Maybe Int +wsIndex ws = findIndex (==(tag ws)) Config.workspaces + +findWsIndex :: WindowSpace -> [WindowSpace] -> Maybe Int +findWsIndex ws wss = findIndex ((== tag ws) . tag) wss -- cgit v1.2.3