通过键盘输入动态设置Qtile页边距



我希望设置键绑定来增加/减少Qtile中的间隙和边距,类似于i3间隙中的以下操作:

bindsym $mod+equal gaps inner current plus 5
bindsym $mod+minus gaps inner current minus 5
bindsym $mod+Shift+equal gaps outer current plus 5
bindsym $mod+Shift+minus gaps outer current minus 5

我可以在某种程度上获得相当于外部间隙的代码来使用以下代码:

def increase_gap(qtile):
qtile.screens[0].top.size = screens[0].top.size+5
qtile.screens[0].right.size = screens[0].top.size+5
qtile.screens[0].left.size = screens[0].top.size+5
#margs = screens[0].bottom.margin
screens[0].bottom.margin[0] = screens[0].bottom.margin[0]+5
screens[0].bottom.size=20
qtile.screens[0].cmd_resize()

def decrease_gap(qtile):
qtile.screens[0].top.size = max(screens[0].top.size-5, 0)
qtile.screens[0].right.size = max(screens[0].top.size-5, 0)
qtile.screens[0].left.size = max(screens[0].top.size-5, 0)
#margs = screens[0].bottom.margin
screens[0].bottom.margin[0] = max(screens[0].bottom.margin[0]-5, 0)
screens[0].bottom.size=20
qtile.screens[0].cmd_resize()
Key([mod, "shift"], "equal", lazy.function(increase_gap), desc="Increase gap"),
Key([mod, "shift"], "minus", lazy.function(decrease_gap), desc="Decrease gap"),

不过,我不确定这是否是正确的做事方式。我不确定这是否应该被这样操纵。我真的不确定cmd_resize((函数是否是我应该使用的,但经过反复试验,我发现它是有效的。我不知道为什么需要screen[0].bottom.size=20(20是我的底部条的大小。我知道我不应该硬编码,但我正在尝试在清理代码之前生成一个概念验证(,但如果没有,条就会开始浮动。最后,增加和减少间隙变得很近,但与原始配置不太一样。这些间隙看起来与原来的略有不同。所以,我不确定这是实现这一目标的正确方法,我可以利用这些建议。

其次,尽管这接近于在外部差距上实现我想要的目标,但我在让内部差距发挥作用方面没有取得任何进展。我最初尝试更改布局的边距参数,当这不起作用时,我尝试简单地初始化一个新布局并替换下面发布的旧布局,但这两种方法都不起作用。

def column_increase_margin(qtile):
current_margin = current_margin + 5
layouts[0] = layout.Columns(border_focus_stack='#d75f5f', margin=current_margin, border_width=0)
screens[0].bottom.size=20
qtile.screens[0].cmd_resize()

我试过在这里浏览代码,但这是一个大项目,我很难从中得出结论。

如有任何建议,我们将不胜感激。

如果我理解你想要什么,你可以在libqtile/Layout/base.py中的Layout类中添加以下内容:

def cmd_increase_margin(self):
self.margin += 10
self.group.layout_all()
def cmd_decrease_margin(self):
new_margin = self.margin - 10
if new_margin < 0:
new_margin = 0
self.margin = new_margin
self.group.layout_all()

然后,您可以在config.py中添加一些键来增加和减少边距。例如

KeyChord([mod], "m", [
Key([], "Up", lazy.layout.increase_margin()),
Key([], "Down", lazy.layout.decrease_margin())
],
mode="Margins"
),

我是qtile的新手,所以上面的方法可能有问题,但它似乎有效。

最新更新