✨ feat(hypr/config): add window rules tagging system and positioning improvements

This commit is contained in:
sankalp committed 2025-06-07 14:53:34 +05:45
1 parent 528e3d7bdf
commit 35bc711ddc
5 files changed
+88 -372

No files matched your search

-6
View File
@@ -1,6 +0,0 @@
{
"browser": "firefox",
"editor": "nvim",
"filemanager": "thunar",
"terminal": "kitty"
}
-8
View File
@@ -1,8 +0,0 @@
{
"custom-color": "none",
"swww-anim": "wipe",
"color-scheme": "dark",
"generation-scheme": "tonalSpot",
"wallpaper-engine": "swww",
"hyprpaper-tpl": "preload = WALLPAPER\n wallpaper = ,WALLPAPER\n splash = false"
}
+88 -75
View File
@@ -9,64 +9,101 @@ windowrulev2 = maxsize 1 1,class:^(xwaylandvideobridge)$
windowrulev2 = noblur,class:^(xwaylandvideobridge)$
# MPV/VLC
windowrule = workspace 5, ^(.*vlc.*)$|(.*mpv.*)$
windowrulev2 = float, class:^(.*mpv.*)$|(.*vlc.*)$
windowrulev2 = size 70% 70%, class:^(.*mpv.*)$|(.*vlc.*)$
# Pavucontrol
windowrulev2 = float, class:^(pavucontrol|org.pulseaudio.pavucontrol|com.saivert.pavucontrol)$
# windowrule - tags - add apps under appropriate tag to use the same settings
# browser tags
windowrule = tag +browser, class:^([Ff]irefox|org.mozilla.firefox|[Ff]irefox-esr|[Ff]irefox-bin)$
windowrule = tag +browser, class:^([Gg]oogle-chrome(-beta|-dev|-unstable)?)$
windowrule = tag +browser, class:^(chrome-.+-Default)$ # Chrome PWAs
windowrule = tag +browser, class:^([Cc]hromium)$
windowrule = tag +browser, class:^([Mm]icrosoft-edge(-stable|-beta|-dev|-unstable))$
windowrule = tag +browser, class:^(Brave-browser(-beta|-dev|-unstable)?)$
windowrule = tag +browser, class:^([Tt]horium-browser|[Cc]achy-browser)$
windowrule = tag +browser, class:^(zen-alpha|zen|zen-browser)$
#Zathura
$zathura = class:^(.*zathura.*)$
windowrulev2 = float, $zathura
windowrulev2 = size 35% 90%, $zathura
windowrulev2 = center 1, $zathura
# Fireox class settings
windowrulev2 = workspace 3, class:^(firefox)$
windowrulev2 = pin,title:^(Picture-in-Picture)$
windowrulev2 = float, title:^(Picture-in-Picture)$
windowrulev2 = size 25% 25%,title:^(Picture-in-Picture)$
windowrulev2 = move 72% 7%,title:^(Picture-in-Picture)$
windowrulev2 = idleinhibit fullscreen, class:^(.*firefox.*)$
# terminal tags
windowrule = tag +terminal, class:^(Alacritty|kitty|Kitty)$
# Thunar
windowrulev2 = float, class:([Tt]hunar), title:(File Operation Progress)
windowrulev2 = float, class:([Tt]hunar), title:(Confirm to replace files)
windowrulev2 = workspace 4, class:(thunar)
# File / Folder pickers
$center-float = class:^(center-float)$|^(.*file-roller.*)$|^(.*FileRoller.*)$
$center-float-title = title:^(.*Open Folder.*)$|^(.*Open File.*)$|^(.*Save File.*)$|^(.*Save Folder.*)$|^(.*Save Image.*)$|^(.*Save As.*)$|^(.*Open As.*)$
windowrulev2 = float, $center-float
windowrulev2 = float, $center-float-title
windowrulev2 = size 50% 50%, $center-float
windowrulev2 = size 50% 50%, $center-float-title
windowrulev2 = center 1, $center-float
windowrulev2 = center 1, $center-float-title
# project tags
windowrule = tag +projects, class:^(codium|codium-url-handler|VSCodium)$
windowrule = tag +projects, class:^(VSCode|code-url-handler)$
# File Roller
windowrulev2 = workspace 4, class:(file-roller), title:(Archive Manager)
windowrulev2 = float, class:(file-roller), title:(Archive Manager)
windowrulev2 = size 45% 50%, class:(file-roller), title:(Archive Manager)
windowrulev2 = center, class:(file-roller), title:(Archive Manager)
windowrulev2 = float, class:(file-roller), title:(Extract archive)
windowrulev2 = size 30% 15%, class:(file-roller), title:(Extract archive)
windowrulev2 = center, class:(file-roller), title:(Extract archive)
# IM tags
windowrule = tag +im, class:^([Dd]iscord|[Ww]ebCord|[Vv]esktop)$
windowrule = tag +im, class:^([Ff]erdium)$
windowrule = tag +im, class:^([Ww]hatsapp-for-linux)$
windowrule = tag +im, class:^(org.telegram.desktop|io.github.tdesktop_x64.TDesktop|materialgram)$
windowrule = tag +im, class:^(teams-for-linux)$
# VS Code
# windowrulev2 = workspace 2, class:(codium|codium-url-handler|VSCodium|code-oss|code)
windowrulev2 = float, class:(codium|codium-url-handler|VSCodium|code-oss|code), title:(Add Folder to Workspace)
# Telegram
windowrulev2 = fullscreen, class:^(.*materialgram.*)$|(.*telegram-desktop.*), title:(Media viewer)
windowrulev2 = workspace 6, class:^(.*materialgram.*)$|(.*telegram-desktop.*)$
windowrulev2 = size 833 455, class:^(.*materialgram.*)$|(.*telegram-desktop.*)$, title:(Choose Files)
windowrulev2 = center, class:^(.*materialgram.*)$|(.*telegram-desktop.*), title:(Choose Files)
# file-manager tags
windowrule = tag +file-manager, class:^([Tt]hunar|org.gnome.Nautilus|[Pp]cmanfm-qt)$
windowrule = tag +file-manager, class:^(app.drey.Warp)$
# multimedia-video tags
windowrule = tag +multimedia_video, class:^([Mm]pv|vlc)$
# settings tags
windowrule = tag +settings, class:^(gnome-disks|wihotspot(-gui)?)$
windowrule = tag +settings, class:^(file-roller|org.gnome.FileRoller)$ # archive manager
windowrule = tag +settings, class:^(nm-applet|nm-connection-editor|blueman-manager)$
windowrule = tag +settings, class:^(pavucontrol|org.pulseaudio.pavucontrol|com.saivert.pwvucontrol)$
windowrule = tag +settings, class:^(qt5ct|qt6ct|[Yy]ad)$
windowrule = tag +settings, class:(xdg-desktop-portal-gtk)
windowrule = tag +settings, class:^(org.kde.polkit-kde-authentication-agent-1)$
# viewer tags
windowrule = tag +viewer, class:^(gnome-system-monitor|org.gnome.SystemMonitor|io.missioncenter.MissionCenter)$ # system monitor
windowrule = tag +viewer, class:^(evince|zathura)$ # document viewer
windowrule = tag +viewer, class:^(eog|org.gnome.Loupe|imv|imv-dir)$ # image viewer
# POSITION
# windowrule = center,floating:1 # warning, it cause even the menu to float and center.
windowrule = center, class:([Tt]hunar), title:negative:(.*[Tt]hunar.*)
windowrule = center, class:^(pavucontrol|org.pulseaudio.pavucontrol|com.saivert.pwvucontrol)$
windowrule = center, class:^([Ww]hatsapp-for-linux)$
windowrule = center, class:^([Ff]erdium)$
windowrule = move 72% 7%,title:^(Picture-in-Picture)$
#windowrule = move 72% 7%,title:^(Firefox)$
# windowrule move to workspace
windowrule = workspace 3, tag:browser*
windowrule = workspace 4, class:^([Tt]hunar)$
windowrule = workspace 6, tag:im*
# FLOAT
windowrule = float, tag:settings*
windowrule = float, tag:viewer*
windowrule = float, class:([Zz]oom|onedriver|onedriver-launcher)$
windowrule = float, class:(org.gnome.Calculator), title:(Calculator)
windowrule = float, class:^(mpv|com.github.rafostar.Clapper)$
windowrule = float, class:^([Qq]alculate-gtk)$
#windowrule = float, class:^([Ww]hatsapp-for-linux|ZapZap|com.rtosta.zapzap)$
windowrule = float, class:^([Ff]erdium)$
windowrule = float, title:^(Picture-in-Picture)$
#windowrule = float, title:^(Firefox)$
# windowrule - ######### float popups and dialogue #######
windowrule = float, title:^(Authentication Required)$
windowrule = center, title:^(Authentication Required)$
#windowrule = float, class:(codium|codium-url-handler|VSCodium), title:negative:(.*codium.*|.*VSCodium.*)
windowrule = float, class:([Tt]hunar), title:negative:(.*[Tt]hunar.*)
windowrule = float, title:^(Add Folder to Workspace)$
windowrule = size 70% 60%, title:^(Add Folder to Workspace)$
windowrule = center, title:^(Add Folder to Workspace)$
windowrule = float, title:^(Save As)$
windowrule = size 70% 60%, title:^(Save As)$
windowrule = center, title:^(Save As)$
windowrule = float, initialTitle:(Open Files)
windowrule = size 70% 60%, initialTitle:(Open Files)
# discord
windowrulev2 = workspace 7, class:^(.*discord.*)$|(.*vesktop.*)$|(.*WebCord.*)$
# Kitty
windowrulev2 = float,class:^(kitty)$,title:^(Kitty)$
@@ -75,34 +112,9 @@ windowrulev2 = move center, class^(kitty)$, title:^(Kitty)$
windowrulev2 = animation slide, class:^(kitty)$, title:^(Kitty)$
windowrulev2 = float, class:^(kitty)$, title:^(Kitty)$
# Bluetooth applet
windowrulev2 = float, class:(blueman)
windowrulev2 = size 680 665, class:(blueman)
windowrulev2 = center, class:(blueman)
# IMV image viewer
$center-float-large = class:^(center-float-large)$|^(.*imv.*)$|^(.*imv-dir.*)$
windowrulev2 = float, $center-float-large
windowrulev2 = size 70% 70%, $center-float-large
windowrulev2 = center 1, $center-float-large
# qt5ct / qt6ct
windowrulev2 = float, class:^(nwg-look|qt5ct|qt6ct)$
windowrulev2 = size 60% 70%, class:^(qt6ct)$
# Other
windowrule = float, nm-connection-editor|yad|Lxappearance
windowrulev2 = size 543 239, class:^(polkit-gnome-authentication-agent-1)$
windowrulev2 = float, class:^(polkit-gnome-authentication-agent-1)$
windowrulev2 = center, class:(polkit-gnome-authentication-agent-1)
windowrulev2 = float, class:(electron), title:(Add Folder to Workspace)
windowrulev2 = float, class:^(org.kde.polkit-kde-authentication-agent-1)$
windowrulev2 = float, class:(xdg-desktop-portal-gtk)
windowrulev2 = size 70% 70%, class:^(xdg-desktop-portal-gtk)$
windowrulev2 = stayfocused, class:(polkit-gnome-authentication-agent-1)
#Layer Rules
# layerrule = noanim, popup.*
layerrule = noanim, hyprpicker
layerrule = noanim, selection
@@ -110,6 +122,7 @@ layerrule = noanim, noanim
layerrule = ignorezero, gtk-layer-shell
layerrule = noanim,selection
# layerrule = noanim, fabric
layerrule = noanim, fabric
# layerrule = animation slide, launcher
-5
View File
@@ -1,5 +0,0 @@
{
"color-scheme": "dark",
"custom-color": "none",
"generation-scheme": "tonalSpot"
}
-278
View File
@@ -1,278 +0,0 @@
import os
import sys
import importlib.util
import argparse
import fcntl
import subprocess
import asyncio
import random as _random
import colorsys
import json
import inspect
def get_relative_path(path: str, level: int = 1) -> str:
prev_globals = inspect.stack()[level][0].f_globals
file_var = (
os.path.dirname(os.path.abspath(prev_globals["__file__"]))
if "__file__" in prev_globals
else os.getcwd()
)
return os.path.join(file_var, path)
lock_file_path = "/tmp/wallpaper.lock"
# settings_file_path = os.path.expanduser("~/dotfiles/.settings/settings.json")
settings_file_path = get_relative_path("./settings.json")
def acquire_lock():
global lock_file
lock_file = open(lock_file_path, "w")
try:
fcntl.flock(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
lock_file.write(str(os.getpid()))
lock_file.flush()
except IOError:
print("Another instance of the script is already running.")
sys.exit(1)
def release_lock():
fcntl.flock(lock_file, fcntl.LOCK_UN)
lock_file.close()
os.remove(lock_file_path)
def hue_to_numeric_hex(hue):
hue = hue / 360.0
rgb = colorsys.hls_to_rgb(hue, 0.5, 1.0)
hex_color_str = "#{:02x}{:02x}{:02x}".format(
int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255)
)
numeric_hex_color = int(hex_color_str.lstrip("#"), 16)
return numeric_hex_color
def load_settings():
default_settings = {
"color-scheme": "dark",
"custom-color": "none",
"generation-scheme": "tonalSpot",
}
if not os.path.exists(settings_file_path):
os.makedirs(os.path.dirname(settings_file_path), exist_ok=True)
with open(settings_file_path, "w") as file:
json.dump(default_settings, file, indent=4)
with open(settings_file_path, "r") as file:
return json.load(file)
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-I", "--image", type=str, help="Image")
group.add_argument(
"-P",
"--prev",
help="Use last used wallpaper for color generation",
action="store_true",
)
group.add_argument(
"-R", "--random", help="Random image from folder", action="store_true"
)
parser.add_argument("-n", "--notify", help="Send notifications", action="store_true")
parser.add_argument(
"--status", type=str, help="Status file", default="/tmp/wallpaper.status"
)
args = parser.parse_args()
random = args.random
prev = args.prev
image = args.image
notify = args.notify
status = args.status
HOME = os.path.expanduser("~")
module_path = f"{HOME}/dotfiles/material-colors"
sys.path.append(module_path)
module_name = "generate"
file_path = f"{module_path}/{module_name}.py"
spec = importlib.util.spec_from_file_location(module_name, file_path)
GENERATOR = importlib.util.module_from_spec(spec) # type: ignore
spec.loader.exec_module(GENERATOR) # type: ignore
cache_file = f"{HOME}/.cache/current_wallpaper"
square = f"{HOME}/.cache/square_wallpaper.png"
png = f"{HOME}/.cache/current_wallpaper.png"
def current_state(state_str: str):
with open(status, "w") as f:
f.write(state_str)
def send_notify(label: str, desc: str):
if not notify:
return
subprocess.run(["notify-send", label, desc])
def state(name: str | None, label: str | None, desc: str | None):
if name is not None:
current_state(name)
if label is not None:
send_notify(label, desc or "")
def join(*args):
return os.path.join(*args)
async def main():
# global \
# color_scheme, \
# custom_color, \
# generation_scheme, \
# swww_animation, \
# wallpaper_engine
state("init", None, None)
settings = load_settings()
color_scheme = settings["color-scheme"]
custom_color = settings["custom-color"]
generation_scheme = settings["generation-scheme"]
swww_animation = "wipe"
wallpaper_engine = "swww"
new_wallpaper = f"{HOME}/Pictures/wallpapers/1.png"
if random:
files = [
f
for f in os.listdir(f"{HOME}/Pictures/wallpapers/")
if f.endswith((".png", ".jpg", ".jpeg"))
]
if files:
new_wallpaper = join(f"{HOME}/Pictures/wallpapers", _random.choice(files))
elif prev:
try:
with open(cache_file) as f:
new_wallpaper = f.read().strip()
except FileNotFoundError:
pass
elif image is not None:
new_wallpaper = os.path.abspath(image)
print(f":: Wallpaper {new_wallpaper}")
with open(cache_file, "w") as f:
f.write(new_wallpaper)
with_image = f"with image {new_wallpaper}"
# -----------------------------------------------------
# Set the new wallpaper
# -----------------------------------------------------
transition_type = swww_animation
state("changing", "Changing wallpaper...", with_image)
print(":: Changing wallpaper...")
if wallpaper_engine == "swww":
print(":: Using swww")
cursor_pos = subprocess.getoutput("hyprctl cursorpos").replace(", ", ",")
subprocess.run(
[
"swww",
"img",
new_wallpaper,
"--transition-bezier",
".43,1.19,1,.4",
"--transition-fps",
"60",
"--transition-type",
transition_type,
"--transition-duration",
"0.7",
"--transition-pos",
cursor_pos,
]
)
else:
print(":: Wallpaper Engine disabled")
# -----------------------------------------------------
# Generate colors
# -----------------------------------------------------
state("colors", "Generating colors...", with_image)
print(":: Generate colors")
_starts_with = lambda x: str(x).startswith("-")
GENERATOR.main(
color_scheme,
new_wallpaper,
(
hue_to_numeric_hex(int(custom_color.lstrip("-")))
if _starts_with(custom_color)
else (int(custom_color.lstrip("#"), 16) if custom_color != "none" else None)
),
scheme_name=generation_scheme,
)
# Generate square and png versions
await asyncio.gather(square_image(new_wallpaper), png_image(new_wallpaper))
state("finish", "Wallpaper procedure complete!", with_image)
async def png_image(wallpaper: str):
if wallpaper.lower().endswith((".jpg", ".jpeg")):
state(None, "Converting jpg to png...", f"with image {wallpaper}")
print(":: Converting jpg to png...")
cmd = f"magick {wallpaper}[0] {png}"
else:
cmd = f"cp -f {wallpaper} {png}"
process = await asyncio.create_subprocess_shell(
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
if process.returncode != 0:
print(f":: Error while processing image: {stderr.decode()}")
else:
print(":: JPG successfully converted to PNG!")
async def square_image(wallpaper):
state(None, "Creating square version...", f"with image {wallpaper}")
print(":: Creating square version")
cmd = f"magick {wallpaper}[0] -gravity Center -extent 1:1 {square}"
process = await asyncio.create_subprocess_shell(
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
if process.returncode != 0:
print(f":: Error while processing image: {stderr.decode()}")
else:
print(":: Square image created!")
if __name__ == "__main__":
acquire_lock()
try:
asyncio.run(main())
finally:
release_lock()