2007/09/11
Xmonad でウィンドウを縦方向リサイズをするためのパッチ
使いはじめてまもないのですが早速改造してみました。現在の正式リリースでは対応していないウィンドウの縦方向リサイズをできるようにするためのパッチです。
vresize.patch:
diff -rN -u old-xmonad/Config.hs new-xmonad/Config.hs
--- old-xmonad/Config.hs 2007-09-11 15:26:17.000000000 +0900
+++ new-xmonad/Config.hs 2007-09-11 15:26:17.000000000 +0900
@@ -101,7 +101,7 @@
]
where
-- default tiling algorithm partitions the screen into two panes
- tiled = tall nmaster delta ratio
+ tiled = tall nmaster delta ratio (repeat 1)
-- The default number of windows in the master pane
nmaster = 1
@@ -152,6 +152,8 @@
-- resizing the master/slave ratio
, ((modMask, xK_h ), sendMessage Shrink) -- @@ Shrink the master area
, ((modMask, xK_l ), sendMessage Expand) -- @@ Expand the master area
+ , ((modMask, xK_z ), vshrink)
+ , ((modMask, xK_a ), vexpand)
, ((modMask, xK_t ), withFocused sink) -- @@ Push window back into tiling
diff -rN -u old-xmonad/Operations.hs new-xmonad/Operations.hs
--- old-xmonad/Operations.hs 2007-09-11 15:26:17.000000000 +0900
+++ new-xmonad/Operations.hs 2007-09-11 15:26:17.000000000 +0900
@@ -364,7 +364,7 @@
-- Expand
--
-data Resize = Shrink | Expand deriving Typeable
+data Resize = Shrink | Expand | VShrink (W.Stack Window) | VExpand (W.Stack Window) deriving Typeable
data IncMasterN = IncMasterN Int deriving Typeable
instance Message Resize
instance Message IncMasterN
@@ -378,16 +378,36 @@
--
-- The tiling mode of xmonad, and its operations.
--
-tall :: Int -> Rational -> Rational -> Layout a
-tall nmaster delta frac =
+tall :: Int -> Rational -> Rational -> [Rational] -> Layout a
+tall nmaster delta frac vfrac =
Layout { doLayout = \r -> return . (\x->(x,Nothing)) .
- ap zip (tile frac r nmaster . length) . W.integrate
+ ap zip (tile frac vfrac r nmaster . length) . W.integrate
, modifyLayout = \m -> return $ msum [fmap resize (fromMessage m)
,fmap incmastern (fromMessage m)] }
- where resize Shrink = tall nmaster delta (max 0 $ frac-delta)
- resize Expand = tall nmaster delta (min 1 $ frac+delta)
- incmastern (IncMasterN d) = tall (max 0 (nmaster+d)) delta frac
+ where resize Shrink = tall nmaster delta (max 0 $ frac-delta) vfrac
+ resize Expand = tall nmaster delta (min 1 $ frac+delta) vfrac
+ resize (VShrink s) = vresize s delta
+ resize (VExpand s) = vresize s (0-delta)
+ vresize s d = let n = length $ W.up s
+ total = n + (length $ W.down s) + 1
+ in tall nmaster delta frac (modifyvfrac vfrac d (if n == (nmaster-1) || n == (total-1) then n-1 else n))
+ modifyvfrac [] _ _ = []
+ modifyvfrac (f:fx) d n | n == 0 = f+d : fx
+ | otherwise = f : modifyvfrac fx d (n-1)
+ incmastern (IncMasterN d) = tall (max 0 (nmaster+d)) delta frac vfrac
+
+currentStack :: (W.Stack Window -> X()) -> X ()
+currentStack f = do ms <- (W.stack . W.workspace . W.current) `fmap` gets windowset
+ case ms of
+ Nothing -> return ()
+ Just s -> f s
+
+vshrink :: X ()
+vshrink = currentStack (\s -> sendMessage $ VShrink s)
+
+vexpand :: X ()
+vexpand = currentStack (\s -> sendMessage $ VExpand s)
-- | Mirror a rectangle
mirrorRect :: Rectangle -> Rectangle
@@ -413,22 +433,24 @@
-- 'frac' specifies what proportion of the screen to devote to the
-- master area.
--
-tile :: Rational -> Rectangle -> Int -> Int -> [Rectangle]
-tile f r nmaster n = if n <= nmaster || nmaster == 0
- then splitVertically n r
- else splitVertically nmaster r1 ++ splitVertically (n-nmaster) r2 -- two columns
+tile :: Rational -> [Rational] -> Rectangle -> Int -> Int -> [Rectangle]
+tile f vfrac r nmaster n = if n <= nmaster || nmaster == 0
+ then splitVertically vfrac n r
+ else splitVertically vfrac nmaster r1 ++ splitVertically (drop nmaster vfrac) (n-nmaster) r2 -- two columns
where (r1,r2) = splitHorizontallyBy f r
--
-- Divide the screen vertically into n subrectangles
--
-splitVertically, splitHorizontally :: Int -> Rectangle -> [Rectangle]
-splitVertically n r | n < 2 = [r]
-splitVertically n (Rectangle sx sy sw sh) = Rectangle sx sy sw smallh :
- splitVertically (n-1) (Rectangle sx (sy+fromIntegral smallh) sw (sh-smallh))
- where smallh = sh `div` fromIntegral n --hmm, this is a fold or map.
+splitVertically :: RealFrac r => [r] -> Int -> Rectangle -> [Rectangle]
+splitVertically [] _ r = [r]
+splitVertically _ n r | n < 2 = [r]
+splitVertically (f:fx) n (Rectangle sx sy sw sh) = Rectangle sx sy sw smallh :
+ splitVertically fx (n-1) (Rectangle sx (sy+fromIntegral smallh) sw (sh-smallh))
+ where smallh = floor $ fromIntegral (sh `div` fromIntegral n) * f --hmm, this is a fold or map.
-splitHorizontally n = map mirrorRect . splitVertically n . mirrorRect
+--splitHorizontally :: Int -> Rectangle -> [Rectangle]
+--splitHorizontally n = map mirrorRect . splitVertically n . mirrorRect
-- Divide the screen into two rectangles, using a rational to specify the ratio
splitHorizontallyBy, splitVerticallyBy :: RealFrac r => r -> Rectangle -> (Rectangle, Rectangle)
パッチを保存して
% patch -p1 < vresize.patch
で適用できます。また Gentoo Overlay にも開放しています。 /etc/layman/layman.cfg に次の文字列を追加して layman -a panicode しておいてください。後は emerge xmonad でパッチ適用バージョンをインストールできます。ただし savedconfig 有効でインストールしている場合は /etc/portage/savedconfig/x11-wm/xmonad-0.3 を削除するなりしてからじゃないと正しくコンパイルできないので注意してください。
overlays : ...
http://gentoo.panicode.com/layman.txt
暇なときに公式ともコンタクトとるようにしよう。
- Category(s)
- linux
- The URL to Trackback this entry is:
- http://dev.ariel-networks.com/Members/matsuyama/xmonad-vresize/tbping
Re:Xmonad でウィンドウを縦方向リサイズをするためのパッチ
Posted by
matsuyama
at
2007-09-12 20:51
XMonadContribのモジュールとしておくってみるか