简体   繁体   English

如何从XMonad中的所有浮动窗口中删除边框

[英]How would I remove borders from all Floating windows in XMonad

There are several similar questions but none quite solve it for me, for example this question explains how to remove borders from fullscreen floating windows. 有几个类似的问题,但没有一个完全解决它,例如这个问题解释了如何从全屏浮动窗口中删除边框。

Using XMonad.Layout.NoBorders you can do lots of cool stuff like remove borders from certain windows or if it is the only window or only fullscreen floating windows. 使用XMonad.Layout.NoBorders你可以做很多很酷的事情,比如从某些窗口移除边框,或者它是唯一的窗口还是只有全屏浮动窗口。

I couldn't find anything for all floating windows, however if someone could just point me to some tool that I could use to check if a window is floating or not, I am sure I could try hack up a solution. 我找不到所有浮动窗口的任何东西,但是如果有人可以指出我可以用来检查窗口是否浮动的某些工具,我相信我可以尝试破解解决方案。

Any suggestions are welcome 欢迎任何建议

I'll be using the source code of XMonad.Layout.NoBorders as a reference, since I can't find anything more fitting that already exists. 我将使用XMonad.Layout.NoBorders的源代码作为参考,因为我找不到任何已经存在的更合适的东西。 We want to see how it implements "remove borders on fullscreen floating windows", to see if it can be easily relaxed to "remove borders on floating windows" (without the fullscreen constraint). 我们希望看到它如何实现“在全屏浮动窗口上移除边框”,看看是否可以轻松放宽“移除浮动窗口上的边框”(没有全屏约束)。

According to the answer on the question you linked: 根据您链接的问题的答案:

layoutHook = lessBorders OnlyFloat $ avoidStruts $ myLayout

OnlyFloat seems to be the specifier for "remove borders on fullscreen floating windows", so let's check the definition of that: OnlyFloat似乎是“删除全屏浮动窗口边框”的说明符,所以让我们检查一下它的定义:

data Ambiguity = Combine With Ambiguity Ambiguity
               | OnlyFloat
               | Never
               | EmptyScreen
               | OtherIndicated
               | Screen
    deriving (Read, Show)

Not too helpful on its own. 对自己没有太大的帮助。 We should look elsewhere to see how the code treats these values. 我们应该到别处去看看代码如何处理这些值。


It's a pretty safe bet that the first function to check is lessBorders : 可以肯定的是,要检查的第一个函数是lessBorders

lessBorders :: (SetsAmbiguous p, Read p, Show p, LayoutClass l a) =>
        p -> l a -> ModifiedLayout (ConfigurableBorder p) l a
lessBorders amb = ModifiedLayout (ConfigurableBorder amb [])

From the type signature of lessBorders , we can see that: lessBorders的类型签名,我们可以看到:

OnlyFloat :: (SetsAmbiguous p, Read p, Show p) => p

This is a good sign, as it means lessBorders doesn't explicitly expect an Ambiguity : we can extend the functionality here by implementing our own SetsAmbiguous and passing it to the existing lessBorders . 这是一个好兆头,因为它意味着lessBorders没有明确指出Ambiguity :我们可以通过实现我们自己的SetsAmbiguous并将其传递给现有的lessBorders来扩展这里的功能。 Let's now look at SetsAmbiguous , and Ambiguity 's implementation of it: 现在让我们看看SetsAmbiguousAmbiguity的实现:

class SetsAmbiguous p where
    hiddens :: p -> WindowSet -> Maybe (W.Stack Window) -> [(Window, Rectangle)] -> [Window]

instance SetsAmbiguous Ambiguity where
    hiddens amb wset mst wrs
      | Combine Union a b <- amb = on union next a b
      | Combine Difference a b <- amb = on (\\) next a b
      | Combine Intersection a b <- amb = on intersect next a b
      | otherwise = tiled ms ++ floating
      where next p = hiddens p wset mst wrs
            nonzerorect (Rectangle _ _ 0 0) = False
            nonzerorect _ = True
            screens =
              [ scr | scr <- W.screens wset,
                      case amb of
                            Never -> True
                            _ -> not $ null $ integrate scr,
                      nonzerorect . screenRect $ W.screenDetail scr]
            floating = [ w |
                        (w, W.RationalRect px py wx wy) <- M.toList . W.floating $ wset,
                        px <= 0, py <= 0,
                        wx + px >= 1, wy + py >= 1]
            ms = filter (`elem` W.integrate' mst) $ map fst wrs
            tiled [w]
              | Screen <- amb = [w]
              | OnlyFloat <- amb = []
              | OtherIndicated <- amb
              , let nonF = map integrate $ W.current wset : W.visible wset
              , length (concat nonF) > length wrs
              , singleton $ filter (1==) $ map length nonF = [w]
              | singleton screens = [w]
            tiled _ = []
            integrate y = W.integrate' . W.stack $ W.workspace y

hiddens is the only method here that we need to implement. hiddens是我们需要实现的唯一方法。 Its arguments are our SetsAmbiguous value, a WindowSet , and some other things, and it returns a list of windows that should not show borders. 它的参数是我们的SetsAmbiguous值,一个WindowSet和其他一些东西,它返回一个不应该显示边框的窗口列表。 There's a lot of logic for the combining operations and other Ambiguity values, but those don't matter to us right now. 组合操作和其他Ambiguity值有很多逻辑,但这些对我们来说并不重要。 What we care about is this snippet: 我们关心的是这个片段:

            floating = [ w |
                        (w, W.RationalRect px py wx wy) <- M.toList . W.floating $ wset,
                        px <= 0, py <= 0,
                        wx + px >= 1, wy + py >= 1]

This is very promising. 这是非常有希望的。 It defines a set of floating windows by extracting all windows from the floating section of the WindowSet , converting it to a list (initially it's a Data.Map ), and filtering out all the windows that don't cover the entire screen. 它通过从WindowSetfloating部分提取所有窗口,将其转换为列表(最初是一个Data.Map ),并过滤掉所有不覆盖整个屏幕的窗口来定义一组浮动窗口。 All we need to do is remove the filter. 我们需要做的就是删除过滤器。


After making that change, and removing all unnecessary code pertaining to tiled windows and set operations (which is most of the implementation), we end up with simply: 在进行了更改之后,删除了与平铺窗口和设置操作相关的所有不必要的代码(这是大部分实现),我们最终简单地说:

import XMonad.Layout.NoBorders
import qualified XMonad.StackSet as W
import qualified Data.Map as M

data AllFloats = AllFloats deriving (Read, Show)

instance SetsAmbiguous AllFloats where
    hiddens _ wset _ _ = M.keys $ W.floating wset

We can then say: 然后我们可以说:

layoutHook = lessBorders AllFloats $ myLayout...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM