backup
This commit is contained in:
parent
55c7c928e9
commit
0b4eacb4ba
15 changed files with 2371 additions and 4 deletions
634
configs/waybar/air_control.py
Executable file
634
configs/waybar/air_control.py
Executable file
|
|
@ -0,0 +1,634 @@
|
|||
#!/run/current-system/sw/bin/python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
import subprocess
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
import fcntl
|
||||
|
||||
HA_URL = "http://localhost:8123"
|
||||
ENTITY = "climate.ar"
|
||||
TOKEN_FILE = os.path.expanduser("~/.config/secrets/ha_token")
|
||||
|
||||
STEP = 1
|
||||
MIN_TEMP = 18
|
||||
MAX_TEMP = 30
|
||||
SEND_DELAY = 3
|
||||
PENDING_TTL = 15
|
||||
CONFIRM_TTL = 20
|
||||
|
||||
CACHE_DIR = os.path.expanduser("~/.cache")
|
||||
STATE_FILE = os.path.join(CACHE_DIR, "waybar_air_state.json")
|
||||
STATE_LOCK = os.path.join(CACHE_DIR, "waybar_air_state.lock")
|
||||
|
||||
|
||||
def get_token():
|
||||
with open(TOKEN_FILE) as f:
|
||||
return f.read().strip()
|
||||
|
||||
|
||||
HEADERS = {"Authorization": f"Bearer {get_token()}", "Content-Type": "application/json"}
|
||||
|
||||
|
||||
def get_state():
|
||||
return request_json("GET", f"/api/states/{ENTITY}")
|
||||
|
||||
|
||||
def set_temperature(temp):
|
||||
request_json(
|
||||
"POST",
|
||||
"/api/services/climate/set_temperature",
|
||||
{"entity_id": ENTITY, "temperature": temp},
|
||||
)
|
||||
|
||||
|
||||
def set_mode(mode):
|
||||
request_json(
|
||||
"POST",
|
||||
"/api/services/climate/set_hvac_mode",
|
||||
{"entity_id": ENTITY, "hvac_mode": mode},
|
||||
)
|
||||
|
||||
|
||||
def set_fan_mode(mode):
|
||||
request_json(
|
||||
"POST",
|
||||
"/api/services/climate/set_fan_mode",
|
||||
{"entity_id": ENTITY, "fan_mode": mode},
|
||||
)
|
||||
|
||||
|
||||
PENDING = {
|
||||
"temp": {
|
||||
"key": "temp",
|
||||
"cast": float,
|
||||
"setter": set_temperature,
|
||||
"after": None,
|
||||
},
|
||||
"mode": {
|
||||
"key": "mode",
|
||||
"cast": str,
|
||||
"setter": set_mode,
|
||||
"after": lambda: schedule("flush"),
|
||||
},
|
||||
"fan": {
|
||||
"key": "fan",
|
||||
"cast": str,
|
||||
"setter": set_fan_mode,
|
||||
"after": None,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def request_json(method, path, payload=None):
|
||||
url = f"{HA_URL}{path}"
|
||||
data = None
|
||||
headers = dict(HEADERS)
|
||||
if payload is not None:
|
||||
data = json.dumps(payload).encode("utf-8")
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||
body = resp.read()
|
||||
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError, ValueError):
|
||||
return None
|
||||
if not body:
|
||||
return None
|
||||
try:
|
||||
return json.loads(body)
|
||||
except json.JSONDecodeError:
|
||||
return None
|
||||
|
||||
|
||||
def load_json(path):
|
||||
try:
|
||||
with open(path) as f:
|
||||
return json.load(f)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
except (OSError, ValueError, json.JSONDecodeError):
|
||||
return None
|
||||
|
||||
|
||||
def save_json(path, payload):
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, "w") as f:
|
||||
json.dump(payload, f)
|
||||
|
||||
def save_json_atomic(path, payload):
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
tmp_path = f"{path}.{os.getpid()}.tmp"
|
||||
with open(tmp_path, "w") as f:
|
||||
json.dump(payload, f)
|
||||
os.replace(tmp_path, path)
|
||||
|
||||
|
||||
def load_state():
|
||||
data = load_json(STATE_FILE)
|
||||
if not isinstance(data, dict):
|
||||
return {}
|
||||
return data
|
||||
|
||||
|
||||
def save_state(state):
|
||||
save_json_atomic(STATE_FILE, state)
|
||||
|
||||
|
||||
def update_state(update_fn):
|
||||
os.makedirs(CACHE_DIR, exist_ok=True)
|
||||
with open(STATE_LOCK, "w") as lockf:
|
||||
fcntl.flock(lockf, fcntl.LOCK_EX)
|
||||
state = load_state()
|
||||
if not isinstance(state, dict):
|
||||
state = {}
|
||||
new_state = update_fn(state)
|
||||
if new_state is not None:
|
||||
state = new_state
|
||||
save_state(state)
|
||||
|
||||
|
||||
def get_state_section(state, key):
|
||||
section = state.get(key)
|
||||
if isinstance(section, dict):
|
||||
return section
|
||||
return {}
|
||||
|
||||
|
||||
def read_pending(key):
|
||||
state = load_state()
|
||||
pending_map = get_state_section(state, "pending")
|
||||
data = pending_map.get(key)
|
||||
if not isinstance(data, dict):
|
||||
return None
|
||||
value = data.get("value")
|
||||
ts = data.get("ts")
|
||||
sent = data.get("sent", False)
|
||||
sent_ts = data.get("sent_ts")
|
||||
if not isinstance(value, (int, float, str)) or not isinstance(ts, (int, float)):
|
||||
return None
|
||||
sent_ts_val = None
|
||||
if isinstance(sent_ts, (int, float)):
|
||||
sent_ts_val = float(sent_ts)
|
||||
return {
|
||||
"value": value,
|
||||
"ts": float(ts),
|
||||
"sent": bool(sent),
|
||||
"sent_ts": sent_ts_val,
|
||||
}
|
||||
|
||||
|
||||
def write_pending(key, value, sent=False, sent_ts=None, ts=None):
|
||||
if ts is None:
|
||||
ts = time.time()
|
||||
payload = {"value": value, "ts": float(ts), "sent": bool(sent)}
|
||||
if sent_ts is not None:
|
||||
payload["sent_ts"] = float(sent_ts)
|
||||
def apply(state):
|
||||
pending_map = get_state_section(state, "pending")
|
||||
pending_map[key] = payload
|
||||
state["pending"] = pending_map
|
||||
return state
|
||||
|
||||
update_state(apply)
|
||||
|
||||
|
||||
def clear_pending(key):
|
||||
def apply(state):
|
||||
pending_map = get_state_section(state, "pending")
|
||||
if key in pending_map:
|
||||
pending_map.pop(key, None)
|
||||
state["pending"] = pending_map
|
||||
return state
|
||||
|
||||
update_state(apply)
|
||||
|
||||
|
||||
def read_last_mode():
|
||||
state = load_state()
|
||||
last_map = get_state_section(state, "last")
|
||||
mode = last_map.get("mode")
|
||||
if isinstance(mode, str):
|
||||
return mode
|
||||
return None
|
||||
|
||||
|
||||
def write_last_mode(mode):
|
||||
def apply(state):
|
||||
last_map = get_state_section(state, "last")
|
||||
last_map["mode"] = mode
|
||||
state["last"] = last_map
|
||||
return state
|
||||
|
||||
update_state(apply)
|
||||
|
||||
|
||||
def read_last_target():
|
||||
state = load_state()
|
||||
last_map = get_state_section(state, "last")
|
||||
value = last_map.get("target")
|
||||
if isinstance(value, (int, float)):
|
||||
return float(value)
|
||||
return None
|
||||
|
||||
|
||||
def write_last_target(value):
|
||||
def apply(state):
|
||||
last_map = get_state_section(state, "last")
|
||||
last_map["target"] = float(value)
|
||||
state["last"] = last_map
|
||||
return state
|
||||
|
||||
update_state(apply)
|
||||
|
||||
|
||||
def pending_active(pending):
|
||||
now = time.time()
|
||||
show = now - pending["ts"] <= PENDING_TTL
|
||||
if pending["sent"] and pending.get("sent_ts") is not None:
|
||||
show = show or (now - pending["sent_ts"] <= CONFIRM_TTL)
|
||||
return show
|
||||
|
||||
|
||||
def mode_change_pending(state=None):
|
||||
pending = read_pending(PENDING["mode"]["key"])
|
||||
if not pending:
|
||||
return False
|
||||
if state and state.get("state") == pending.get("value"):
|
||||
return False
|
||||
return bool(pending_active(pending))
|
||||
|
||||
|
||||
_MISSING = object()
|
||||
|
||||
|
||||
def pending_value(key, cast=None, current_value=_MISSING, preserve_if_mode_pending=False):
|
||||
pending = read_pending(key)
|
||||
if pending is None:
|
||||
return (current_value, None) if current_value is not _MISSING else None
|
||||
value = cast(pending["value"]) if cast else pending["value"]
|
||||
if current_value is not _MISSING:
|
||||
if current_value == value:
|
||||
if preserve_if_mode_pending and mode_change_pending():
|
||||
return value, pending
|
||||
clear_pending(key)
|
||||
return current_value, None
|
||||
if pending_active(pending):
|
||||
return value, pending
|
||||
clear_pending(key)
|
||||
return current_value, None
|
||||
if pending_active(pending):
|
||||
return value
|
||||
clear_pending(key)
|
||||
return None
|
||||
|
||||
|
||||
def pending_value_with_current(key, cast, current_value, preserve_if_mode_pending=False):
|
||||
result = pending_value(
|
||||
key,
|
||||
cast,
|
||||
current_value=current_value,
|
||||
preserve_if_mode_pending=preserve_if_mode_pending,
|
||||
)
|
||||
if result is None:
|
||||
return current_value, None
|
||||
return result
|
||||
|
||||
|
||||
def get_effective_mode(state):
|
||||
if state:
|
||||
mode = state.get("state")
|
||||
else:
|
||||
mode = None
|
||||
pending = pending_value(PENDING["mode"]["key"], PENDING["mode"]["cast"])
|
||||
return pending if pending is not None else mode
|
||||
|
||||
|
||||
def clamp(value, low, high):
|
||||
return max(low, min(high, value))
|
||||
|
||||
|
||||
def get_state_attrs():
|
||||
state = get_state()
|
||||
if not state:
|
||||
return None, {}
|
||||
return state, state.get("attributes", {})
|
||||
|
||||
|
||||
def resolve_current_target(state):
|
||||
current_target = None
|
||||
if state:
|
||||
attrs = state["attributes"]
|
||||
current_target = attrs.get("temperature")
|
||||
if current_target is None:
|
||||
current_target = attrs.get("current_temperature")
|
||||
pending_target = pending_value(PENDING["temp"]["key"], PENDING["temp"]["cast"])
|
||||
if pending_target is not None:
|
||||
current_target = pending_target
|
||||
if current_target is None:
|
||||
current_target = read_last_target()
|
||||
if current_target is None and state:
|
||||
current_target = state["attributes"].get("current_temperature")
|
||||
return current_target
|
||||
|
||||
|
||||
def preserve_settings_on_mode_change(state):
|
||||
target = resolve_current_target(state)
|
||||
if isinstance(target, (int, float)) and read_pending(PENDING["temp"]["key"]) is None:
|
||||
write_pending(PENDING["temp"]["key"], float(target), sent=False)
|
||||
schedule("flush")
|
||||
if state:
|
||||
fan_mode = state["attributes"].get("fan_mode")
|
||||
if isinstance(fan_mode, str) and read_pending(PENDING["fan"]["key"]) is None:
|
||||
write_pending(PENDING["fan"]["key"], str(fan_mode), sent=False)
|
||||
schedule("flush-fan")
|
||||
|
||||
|
||||
def flush_pending_generic(
|
||||
key, cast, setter, after=None, defer_cmd=None, state=None, force=False
|
||||
):
|
||||
if not force and key != PENDING["mode"]["key"] and mode_change_pending(state):
|
||||
if defer_cmd is not None:
|
||||
time.sleep(SEND_DELAY)
|
||||
schedule(defer_cmd)
|
||||
return False
|
||||
pending = read_pending(key)
|
||||
if pending is None:
|
||||
return False
|
||||
ts = pending["ts"]
|
||||
remaining = SEND_DELAY - (time.time() - ts)
|
||||
if remaining > 0:
|
||||
time.sleep(remaining)
|
||||
pending = read_pending(key)
|
||||
if pending is None:
|
||||
return False
|
||||
if pending["ts"] != ts:
|
||||
return False
|
||||
value = cast(pending["value"])
|
||||
setter(value)
|
||||
write_pending(key, value, sent=True, sent_ts=time.time(), ts=ts)
|
||||
if after is not None:
|
||||
after()
|
||||
return True
|
||||
|
||||
|
||||
def schedule(cmd):
|
||||
subprocess.Popen(
|
||||
[sys.executable, os.path.abspath(__file__), cmd],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
|
||||
def display():
|
||||
state, attrs = get_state_attrs()
|
||||
if not state:
|
||||
print(json.dumps({"text": "-- - ", "class": "off"}))
|
||||
return
|
||||
mode = state["state"]
|
||||
|
||||
current = attrs.get("current_temperature")
|
||||
target = attrs.get("temperature")
|
||||
target, _ = pending_value_with_current(
|
||||
PENDING["temp"]["key"],
|
||||
PENDING["temp"]["cast"],
|
||||
target,
|
||||
preserve_if_mode_pending=True,
|
||||
)
|
||||
if target is not None:
|
||||
write_last_target(target)
|
||||
|
||||
mode, _ = pending_value_with_current(
|
||||
PENDING["mode"]["key"], PENDING["mode"]["cast"], mode
|
||||
)
|
||||
|
||||
fan_mode = attrs.get("fan_mode")
|
||||
fan_mode, _ = pending_value_with_current(
|
||||
PENDING["fan"]["key"],
|
||||
PENDING["fan"]["cast"],
|
||||
fan_mode,
|
||||
preserve_if_mode_pending=True,
|
||||
)
|
||||
|
||||
if current is None:
|
||||
current = 0
|
||||
|
||||
if mode == "off":
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"text": f"<span font_family='FiraCode Nerd Font Mono' rise='-1500' size='140%'></span> {current:.0f} - ",
|
||||
"class": "off",
|
||||
}
|
||||
)
|
||||
)
|
||||
return
|
||||
write_last_mode(mode)
|
||||
|
||||
mode_map = {
|
||||
"cool": ("", "cool"),
|
||||
"heat": ("", "heat"),
|
||||
"dry": ("", "dry"),
|
||||
"fan_only": ("", "fan"),
|
||||
}
|
||||
mode_key = mode if isinstance(mode, str) else "unknown"
|
||||
icon, css_class = mode_map.get(mode_key, ("", "other"))
|
||||
|
||||
if mode in ("fan_only", "dry"):
|
||||
target_text = f"{current:.0f}"
|
||||
elif target is None:
|
||||
target_text = f"{current:.0f}"
|
||||
else:
|
||||
target_text = f"{target:.0f}"
|
||||
fan_text = ""
|
||||
if fan_mode is not None:
|
||||
fan_text = f"<span size='60%' rise='-1500'>{fan_mode}</span>"
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"text": f"<span font_family='FiraCode Nerd Font Mono' rise='-1500' size='140%'>{icon}</span>{fan_text} {target_text} - ",
|
||||
"class": css_class,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def change(delta):
|
||||
state, _ = get_state_attrs()
|
||||
effective_mode = get_effective_mode(state)
|
||||
if effective_mode in ("fan_only", "dry"):
|
||||
change_fan(delta)
|
||||
return
|
||||
current_target = resolve_current_target(state)
|
||||
if current_target is None:
|
||||
return
|
||||
|
||||
new_temp = clamp(current_target + delta, MIN_TEMP, MAX_TEMP)
|
||||
write_pending(PENDING["temp"]["key"], float(new_temp), sent=False)
|
||||
schedule("flush")
|
||||
|
||||
|
||||
def change_fan(delta):
|
||||
state, attrs = get_state_attrs()
|
||||
if not state:
|
||||
return
|
||||
modes = attrs.get("fan_modes")
|
||||
current = attrs.get("fan_mode")
|
||||
if not modes or current is None:
|
||||
return
|
||||
pending_fan = pending_value(PENDING["fan"]["key"], PENDING["fan"]["cast"])
|
||||
if pending_fan is not None:
|
||||
current = pending_fan
|
||||
try:
|
||||
idx = modes.index(current)
|
||||
except ValueError:
|
||||
idx = 0
|
||||
new_idx = (idx + delta) % len(modes)
|
||||
if new_idx != idx:
|
||||
write_pending(PENDING["fan"]["key"], modes[new_idx], sent=False)
|
||||
schedule("flush-fan")
|
||||
|
||||
|
||||
def cycle_mode():
|
||||
state, attrs = get_state_attrs()
|
||||
if not state:
|
||||
return
|
||||
modes = attrs.get("hvac_modes") or []
|
||||
modes = [m for m in modes if m != "off"]
|
||||
if not modes:
|
||||
return
|
||||
current = get_effective_mode(state)
|
||||
try:
|
||||
idx = modes.index(current)
|
||||
except ValueError:
|
||||
idx = -1
|
||||
new_idx = (idx + 1) % len(modes)
|
||||
new_mode = modes[new_idx]
|
||||
write_pending(PENDING["mode"]["key"], new_mode, sent=False)
|
||||
preserve_settings_on_mode_change(state)
|
||||
schedule("flush-mode")
|
||||
|
||||
|
||||
def toggle_mode():
|
||||
state, attrs = get_state_attrs()
|
||||
if not state:
|
||||
return
|
||||
modes = attrs.get("hvac_modes") or []
|
||||
current = get_effective_mode(state)
|
||||
if current == "off":
|
||||
last = read_last_mode()
|
||||
if last in modes and last != "off":
|
||||
write_pending(PENDING["mode"]["key"], last, sent=False)
|
||||
preserve_settings_on_mode_change(state)
|
||||
schedule("flush-mode")
|
||||
return
|
||||
for m in modes:
|
||||
if m != "off":
|
||||
write_pending(PENDING["mode"]["key"], m, sent=False)
|
||||
preserve_settings_on_mode_change(state)
|
||||
schedule("flush-mode")
|
||||
return
|
||||
else:
|
||||
clear_pending(PENDING["temp"]["key"])
|
||||
clear_pending(PENDING["fan"]["key"])
|
||||
set_mode("off")
|
||||
write_pending(
|
||||
PENDING["mode"]["key"], "off", sent=True, sent_ts=time.time(), ts=time.time()
|
||||
)
|
||||
|
||||
|
||||
def cycle_fan():
|
||||
change_fan(1)
|
||||
|
||||
|
||||
def flush_pending():
|
||||
meta = PENDING["temp"]
|
||||
state, _ = get_state_attrs()
|
||||
flush_pending_generic(
|
||||
meta["key"],
|
||||
meta["cast"],
|
||||
meta["setter"],
|
||||
meta["after"],
|
||||
defer_cmd="flush",
|
||||
state=state,
|
||||
)
|
||||
|
||||
|
||||
def flush_mode():
|
||||
meta = PENDING["mode"]
|
||||
sent = flush_pending_generic(
|
||||
meta["key"], meta["cast"], meta["setter"], meta["after"]
|
||||
)
|
||||
if not sent:
|
||||
return
|
||||
temp_meta = PENDING["temp"]
|
||||
flush_pending_generic(
|
||||
temp_meta["key"],
|
||||
temp_meta["cast"],
|
||||
temp_meta["setter"],
|
||||
temp_meta["after"],
|
||||
force=True,
|
||||
)
|
||||
fan_meta = PENDING["fan"]
|
||||
flush_pending_generic(
|
||||
fan_meta["key"],
|
||||
fan_meta["cast"],
|
||||
fan_meta["setter"],
|
||||
fan_meta["after"],
|
||||
force=True,
|
||||
)
|
||||
|
||||
|
||||
def flush_fan():
|
||||
meta = PENDING["fan"]
|
||||
state, _ = get_state_attrs()
|
||||
flush_pending_generic(
|
||||
meta["key"],
|
||||
meta["cast"],
|
||||
meta["setter"],
|
||||
meta["after"],
|
||||
defer_cmd="flush-fan",
|
||||
state=state,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) == 1:
|
||||
display()
|
||||
return
|
||||
|
||||
cmd = sys.argv[1]
|
||||
|
||||
if cmd == "heat":
|
||||
set_mode("heat")
|
||||
elif cmd == "cool":
|
||||
set_mode("cool")
|
||||
elif cmd == "off":
|
||||
set_mode("off")
|
||||
elif cmd == "up":
|
||||
change(STEP)
|
||||
elif cmd == "down":
|
||||
change(-STEP)
|
||||
elif cmd == "fan-up":
|
||||
change_fan(STEP)
|
||||
elif cmd == "fan-down":
|
||||
change_fan(-STEP)
|
||||
elif cmd == "cycle-mode":
|
||||
cycle_mode()
|
||||
elif cmd == "toggle":
|
||||
toggle_mode()
|
||||
elif cmd == "cycle-fan":
|
||||
cycle_fan()
|
||||
elif cmd == "flush":
|
||||
flush_pending()
|
||||
elif cmd == "flush-mode":
|
||||
flush_mode()
|
||||
elif cmd == "flush-fan":
|
||||
flush_fan()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
201
configs/waybar/config
Normal file
201
configs/waybar/config
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
{
|
||||
"layer": "top",
|
||||
"position": "top",
|
||||
"fixed-center": true,
|
||||
"height": 48,
|
||||
"margin-top": 20,
|
||||
"margin-bottom": 0,
|
||||
"output": ["DP-5", "DP-3"],
|
||||
"modules-left": ["hyprland/workspaces", "cava"],
|
||||
"modules-center": ["custom/ac", "clock"],
|
||||
"modules-right": [
|
||||
"mpris",
|
||||
"network",
|
||||
"bluetooth",
|
||||
"pulseaudio",
|
||||
"backlight",
|
||||
"battery",
|
||||
"custom/poweroff"
|
||||
],
|
||||
"group/power": {
|
||||
"orientation": "inherit",
|
||||
"drawer": {
|
||||
"transition-duration": 500,
|
||||
"transition-left-to-right": false
|
||||
},
|
||||
"modules": [
|
||||
"custom/poweroff",
|
||||
"custom/restart",
|
||||
"custom/exit",
|
||||
"custom/sleep",
|
||||
"custom/lock"
|
||||
]
|
||||
},
|
||||
"custom/poweroff": {
|
||||
"format": "",
|
||||
"on-click": "poweroff"
|
||||
},
|
||||
"custom/restart": {
|
||||
"format": "",
|
||||
"on-click": "reboot"
|
||||
},
|
||||
"custom/exit": {
|
||||
"format": "",
|
||||
"on-click": "hyprctl dispatch exit"
|
||||
},
|
||||
"custom/sleep": {
|
||||
"format": "",
|
||||
"on-click": "systemctl suspend"
|
||||
},
|
||||
"custom/lock": {
|
||||
"format": "",
|
||||
"on-click": "hyprlock"
|
||||
},
|
||||
"custom/kde": {
|
||||
"format": "",
|
||||
"on-click": "hyprlock"
|
||||
},
|
||||
"hyprland/workspaces": {
|
||||
"all-outputs": false,
|
||||
"active-only": false,
|
||||
"persistent-workspaces": {
|
||||
"DP-3": [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
"DP-5": [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
"HDMI-A-1": [10]
|
||||
},
|
||||
"format": "{icon}",
|
||||
"format-icons": {
|
||||
"1": "",
|
||||
"2": "",
|
||||
"3": "",
|
||||
"4": "",
|
||||
"5": "",
|
||||
"6": "",
|
||||
"7": "",
|
||||
"8": "",
|
||||
"9": "",
|
||||
"10": ""
|
||||
},
|
||||
"on-scroll-up": "hyprctl dispatch workspace e+1",
|
||||
"on-scroll-down": "hyprctl dispatch workspace e-1"
|
||||
},
|
||||
"clock": {
|
||||
"format": "{:%d/%m/%Y - %H:%M}",
|
||||
"tooltip": false,
|
||||
"locale": "pt_BR.utf8"
|
||||
},
|
||||
"cpu": {
|
||||
"interval": 5,
|
||||
"format": "︁ {}%",
|
||||
"max-length": 10
|
||||
},
|
||||
"cava": {
|
||||
"framerate": 60,
|
||||
"hide_on_silence": true,
|
||||
"bars": 10,
|
||||
"source": "auto",
|
||||
"method": "pipewire",
|
||||
"stereo": true,
|
||||
"bar_delimiter": 0,
|
||||
"monstercat": false,
|
||||
"waves": true,
|
||||
"noise_reduction": 0.2,
|
||||
"sleep_timer": 1,
|
||||
"input_delay": 0,
|
||||
"format-icons": ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"],
|
||||
"actions": {
|
||||
"on-click-right": "mode"
|
||||
}
|
||||
},
|
||||
"memory": {
|
||||
"interval": 15,
|
||||
"format": "︁ {used:0.1f}G/{total:0.1f}G",
|
||||
"tooltip": false
|
||||
},
|
||||
"pulseaudio": {
|
||||
"format": "{icon}",
|
||||
"format-bluetooth": "{icon}",
|
||||
"format-muted": "",
|
||||
"format-icons": {
|
||||
// "headphone": "",
|
||||
// "hands-free": "",
|
||||
// "headset": "",
|
||||
// "phone": "",
|
||||
// "portable": "",
|
||||
// "car": "",
|
||||
"default": ["", "", "", "", "", ""]
|
||||
},
|
||||
"scroll-step": 10,
|
||||
"on-click": "pavucontrol",
|
||||
"on-click-right": "$HOME/nixos-config/configs/waybar/switch_sink.sh",
|
||||
"ignored-sinks": ["Easy Effects Sink"],
|
||||
"tooltip-format": "{icon} {volume}"
|
||||
},
|
||||
"bluetooth": {
|
||||
"format": "",
|
||||
"format-connected": "",
|
||||
"format-connected-battery": "",
|
||||
"tooltip-format": "{controller_alias}\t{controller_address}\n\n{num_connections} connected",
|
||||
"tooltip-format-connected": "{device_enumerate}",
|
||||
"tooltip-format-enumerate-connected": "{device_alias}\t{device_address}",
|
||||
"tooltip-format-enumerate-connected-battery": "{device_alias}\t{device_address}\t{device_battery_percentage}%",
|
||||
"on-click": "bluetoothctl disconnect",
|
||||
"on-click-right": "bluetoothctl connect B6:97:1A:3D:6A:B2"
|
||||
},
|
||||
"backlight": {
|
||||
"device": "intel_backlight",
|
||||
"format": "{icon}",
|
||||
"scroll-step": 5,
|
||||
"format-icons": ["", "", "", "", "", ""]
|
||||
},
|
||||
"mpris": {
|
||||
"format": "{player_icon} {dynamic}",
|
||||
"format-paused": "{status_icon} {dynamic}",
|
||||
"tooltip-format": "{status_icon} {dynamic}",
|
||||
"player-icons": {
|
||||
"default": "",
|
||||
"mpv": "🎵"
|
||||
},
|
||||
"status-icons": {
|
||||
"paused": ""
|
||||
},
|
||||
"dynamic-len": 40,
|
||||
"dynamic-order": ["title", "artist", "album"],
|
||||
"player": "spotify",
|
||||
"ignored-players": ["firefox*"],
|
||||
"on-scroll-up": "playerctl -i firefox volume 0.1+",
|
||||
"on-scroll-down": "playerctl -i firefox volume 0.1-"
|
||||
},
|
||||
"battery": {
|
||||
"format": "{icon} ",
|
||||
"format-icons": ["", "", "", "", ""],
|
||||
"format-charging": "{icon}",
|
||||
"format-full": "{icon}",
|
||||
"interval": 15,
|
||||
"states": {
|
||||
"warning": 25,
|
||||
"critical": 10
|
||||
},
|
||||
"tooltip": false
|
||||
},
|
||||
"network": {
|
||||
"format": "{icon}",
|
||||
"format-alt": " {ipaddr}",
|
||||
"format-alt-click": "click-left",
|
||||
"format-wifi": " ",
|
||||
"format-ethernet": "",
|
||||
"format-disconnected": "⚠",
|
||||
"tooltip": false
|
||||
},
|
||||
"custom/ac": {
|
||||
"exec": "$HOME/nixos-config/configs/waybar/air_control.py",
|
||||
"interval": 3,
|
||||
"return-type": "json",
|
||||
"markup": "true",
|
||||
"on-click": "$HOME/nixos-config/configs/waybar/air_control.py toggle",
|
||||
"on-click-right": "$HOME/nixos-config/configs/waybar/air_control.py cycle-mode",
|
||||
"on-click-middle": "$HOME/nixos-config/configs/waybar/air_control.py cycle-fan",
|
||||
"on-scroll-up": "$HOME/nixos-config/configs/waybar/air_control.py up",
|
||||
"on-scroll-down": "$HOME/nixos-config/configs/waybar/air_control.py down"
|
||||
}
|
||||
}
|
||||
31
configs/waybar/dracula.css
Normal file
31
configs/waybar/dracula.css
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
@define-color base #24273a;
|
||||
@define-color mantle #1e2030;
|
||||
@define-color crust #181926;
|
||||
|
||||
@define-color text #f2f3f7;
|
||||
@define-color subtext0 #a5adcb;
|
||||
@define-color subtext1 #b8c0e0;
|
||||
|
||||
@define-color surface0 #282A36;
|
||||
@define-color surface1 #494d64;
|
||||
@define-color surface2 #6272A4;
|
||||
|
||||
@define-color overlay0 #6e738d;
|
||||
@define-color overlay1 #8087a2;
|
||||
@define-color overlay2 #939ab7;
|
||||
|
||||
@define-color blue #8aadf4;
|
||||
@define-color lavender #b7bdf8;
|
||||
@define-color sapphire #7dc4e4;
|
||||
@define-color sky #91d7e3;
|
||||
@define-color teal #8BE9FD;
|
||||
@define-color green #50fa7E;
|
||||
@define-color yellow #f1fa8c;
|
||||
@define-color peach #f5a97f;
|
||||
@define-color maroon #ee99a0;
|
||||
@define-color red #ff5555;
|
||||
@define-color mauve #c6a0f6;
|
||||
@define-color purple #d6acff;
|
||||
@define-color pink #f5bde6;
|
||||
@define-color flamingo #f0c6c6;
|
||||
@define-color rosewater #f4dbd6;
|
||||
10
configs/waybar/launch.sh
Executable file
10
configs/waybar/launch.sh
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# Terminate already running bar instances
|
||||
killall -q waybar
|
||||
|
||||
# Wait until the processes have been shut down
|
||||
while pgrep -x waybar >/dev/null; do sleep 1; done
|
||||
|
||||
# Launch main
|
||||
waybar
|
||||
135
configs/waybar/style.css
Normal file
135
configs/waybar/style.css
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
@import "./dracula.css";
|
||||
|
||||
* {
|
||||
font-family: FreeMono;
|
||||
font-size: 17px;
|
||||
font-weight: 600;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#waybar {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
#workspaces {
|
||||
color: @teal;
|
||||
}
|
||||
|
||||
#workspaces button {
|
||||
color: @teal;
|
||||
margin: 0 0.8rem 0 0.4rem;
|
||||
padding: 0;
|
||||
/* border-bottom-width: 1px; */
|
||||
}
|
||||
#workspaces button:hover {
|
||||
box-shadow: none;
|
||||
text-shadow: none;
|
||||
background: none;
|
||||
transition: none;
|
||||
}
|
||||
|
||||
#workspaces button.empty {
|
||||
color: @surface2;
|
||||
}
|
||||
|
||||
#workspaces button.visible {
|
||||
color: @red;
|
||||
}
|
||||
|
||||
#custom-lock,
|
||||
#custom-kde,
|
||||
#custom-restart,
|
||||
#custom-exit,
|
||||
#custom-sleep,
|
||||
#custom-poweroff,
|
||||
#mpris,
|
||||
#battery,
|
||||
#pulseaudio,
|
||||
#bluetooth,
|
||||
#backlight,
|
||||
#network {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
#mpris {
|
||||
font-family: "GohuFont 11 Nerd Font Mono";
|
||||
font-weight: 700;
|
||||
letter-spacing: 1.5px;
|
||||
}
|
||||
|
||||
#cava {
|
||||
font-family: "GohuFont 11 Nerd Font Mono";
|
||||
font-weight: 700;
|
||||
letter-spacing: 1.5px;
|
||||
color: @teal;
|
||||
margin: 0 5px 0 10px;
|
||||
}
|
||||
|
||||
#custom-sleep,
|
||||
#battery,
|
||||
#network {
|
||||
color: @green;
|
||||
}
|
||||
|
||||
#custom-exit,
|
||||
#mpris,
|
||||
#pulseaudio,
|
||||
#backlight {
|
||||
color: @yellow;
|
||||
}
|
||||
|
||||
#custom-kde,
|
||||
#custom-lock,
|
||||
#bluetooth {
|
||||
color: @teal;
|
||||
}
|
||||
|
||||
#custom-restart,
|
||||
#custom-poweroff {
|
||||
color: @red;
|
||||
}
|
||||
|
||||
#clock,
|
||||
#custom-ac {
|
||||
color: @text;
|
||||
color: @yellow;
|
||||
font-family: "GohuFont 11 Nerd Font Mono";
|
||||
font-weight: 700;
|
||||
letter-spacing: 1.5px;
|
||||
}
|
||||
|
||||
#battery.warning:not(.charging) {
|
||||
color: @red;
|
||||
}
|
||||
|
||||
/* .modules-left, */
|
||||
/* .modules-center, */
|
||||
/* .modules-right { */
|
||||
/* border: double 3px transparent; */
|
||||
/* border-radius: 10px; */
|
||||
/* background-image: */
|
||||
/* linear-gradient(rgba(12, 10, 32, 1), rgba(12, 10, 32, 1)), */
|
||||
/* linear-gradient( */
|
||||
/* to bottom right, */
|
||||
/* rgba(254, 4, 117, 0.93), */
|
||||
/* rgba(32, 241, 253, 0.93) */
|
||||
/* ); */
|
||||
/* background-origin: border-box; */
|
||||
/* background-clip: padding-box, border-box; */
|
||||
/* padding: 0 1rem; */
|
||||
/* margin: 0 20px; */
|
||||
/* } */
|
||||
|
||||
.modules-left,
|
||||
.modules-center,
|
||||
.modules-right {
|
||||
border: solid 3px;
|
||||
border-color: @lavender;
|
||||
border-radius: 10px;
|
||||
padding: 0 1rem;
|
||||
background: @surface0;
|
||||
}
|
||||
|
||||
.modules-right,
|
||||
.modules-left {
|
||||
margin: 0 20px;
|
||||
}
|
||||
36
configs/waybar/switch_sink.sh
Executable file
36
configs/waybar/switch_sink.sh
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# Cycle default sink and move existing inputs.
|
||||
if ! command -v pactl >/dev/null 2>&1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
current="$(pactl get-default-sink 2>/dev/null)"
|
||||
[ -z "$current" ] && exit 1
|
||||
|
||||
sinks="$(pactl list short sinks | awk '{print $2}')"
|
||||
[ -z "$sinks" ] && exit 1
|
||||
|
||||
next=""
|
||||
found=0
|
||||
for s in $sinks; do
|
||||
if [ "$found" -eq 1 ]; then
|
||||
next="$s"
|
||||
break
|
||||
fi
|
||||
if [ "$s" = "$current" ]; then
|
||||
found=1
|
||||
fi
|
||||
done
|
||||
|
||||
# If current is last or not found, wrap to first.
|
||||
if [ -z "$next" ]; then
|
||||
next="$(printf '%s\n' "$sinks" | head -n 1)"
|
||||
fi
|
||||
|
||||
pactl set-default-sink "$next" || exit 1
|
||||
|
||||
# Move existing audio streams to the new sink.
|
||||
for input in $(pactl list short sink-inputs | awk '{print $1}'); do
|
||||
pactl move-sink-input "$input" "$next" >/dev/null 2>&1 || true
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue