swallow windows

This commit is contained in:
zoe 2022-09-30 10:00:28 +02:00
parent d2394cf1b1
commit 0d068908d7
3 changed files with 34 additions and 39 deletions

View File

@ -1,7 +1,9 @@
from libqtile.config import Click, Drag, Group, Key, ScratchPad
from libqtile.config import Click, Drag, Group, Key
from libqtile.lazy import lazy
from libqtile import hook
import psutil
import autostart
import my_layouts
import my_widgets
@ -86,3 +88,27 @@ wmname = "LG3D"
@hook.subscribe.startup_once
def start_once():
autostart.start_all()
@hook.subscribe.client_new
def swallow(window):
pid = window.window.get_net_wm_pid()
ppid = psutil.Process(pid).ppid()
cpids = {
c.window.get_net_wm_pid(): wid for wid, c in window.qtile.windows_map.items()
}
for _ in range(5):
if not ppid:
return
if ppid in cpids:
parent = window.qtile.windows_map.get(cpids[ppid])
parent.minimized = True
window.parent = parent
return
ppid = psutil.Process(ppid).ppid()
@hook.subscribe.client_killed
def unswallow(window):
if hasattr(window, "parent"):
window.parent.minimized = False

View File

@ -1,4 +1,3 @@
import subprocess
from libqtile.lazy import lazy
@ -7,21 +6,3 @@ def set_all_float_windows_to_non_floating_mode(qtile):
for window in qtile.current_group.windows:
if window.floating:
window.cmd_disable_floating()
def get_currently_playing():
output: str = (
subprocess.run(
[
"playerctl",
"metadata",
"--format",
r"{{artist}} - {{title}}",
"--player=cmus,%any",
],
stdout=subprocess.PIPE,
)
.stdout.decode("utf-8")
.strip()
)
return output

View File

@ -2,7 +2,6 @@ from libqtile.config import Screen
from libqtile import bar, widget
from enum import Enum
import my_globals
import my_functions
import os
from screeninfo import get_monitors
@ -55,6 +54,7 @@ def _get_powerline_arrow(direction: _PowerLineDirection, accent: _Accent, end=Fa
bg = _Accent.A.value
return widget.TextBox(
update_interval=60,
font="CaskaydiaCove Nerd Font Mono",
text=text,
foreground=accent.value,
@ -66,13 +66,9 @@ def _get_powerline_arrow(direction: _PowerLineDirection, accent: _Accent, end=Fa
)
_keylayout = widget.KeyboardLayout(
**get_defaults(),
fmt="{}",
)
_net = widget.Net(
**get_defaults(),
update_interval=60,
background=my_globals.colors["accent-dark"],
foreground=my_globals.colors["on-accent-dark"],
format="{down}↓↑{up}",
@ -82,7 +78,7 @@ _net = widget.Net(
_cpu = widget.CPU(
**get_defaults(),
update_interval=5,
update_interval=60,
background=my_globals.colors["accent-dark"],
foreground=my_globals.colors["on-accent-dark"],
format="{load_percent}%",
@ -91,6 +87,7 @@ _cpu = widget.CPU(
_weather = widget.OpenWeather(
**get_defaults(),
update_interval=3600,
background=_Accent.A.value,
location="Eidelstedt",
foreground=my_globals.colors["on-accent-dark"],
@ -108,7 +105,7 @@ _ram = widget.Memory(
background=_Accent.A.value,
foreground=my_globals.colors["on-accent-dark"],
measure_mem="G",
update_interval=5,
update_interval=60,
format="{MemUsed:.2f}{mm}",
)
@ -141,7 +138,8 @@ _window_name = widget.WindowName(
_clock = widget.Clock(
**get_defaults(),
format="%d.%m.%y %H:%M:%S",
format="%d.%m %H:%M",
update_interval=20,
background=my_globals.colors["accent-dark"],
foreground=my_globals.colors["on-accent-dark"],
)
@ -161,14 +159,6 @@ _volume = widget.Volume(
fmt="{}",
)
_music = widget.GenPollText(
**get_defaults(),
update_interval=5,
max_chars=30,
background=_Accent.B.value,
func=my_functions.get_currently_playing,
)
_chords = widget.Chord(
**get_defaults(),
background=my_globals.colors["bg-light"],
@ -194,7 +184,6 @@ def _get_bar_contents(primary=False):
),
_window_name,
widget.Spacer(**get_defaults(), length=bar.STRETCH),
_keylayout,
_updates,
_get_powerline_arrow(
_PowerLineDirection.RIGHT,
@ -202,7 +191,6 @@ def _get_bar_contents(primary=False):
end=True,
),
_volume,
_music,
_get_powerline_arrow(_PowerLineDirection.RIGHT, _Accent.A),
_clock,
_weather,