This commit is contained in:
sankalp committed 2025-06-11 14:42:26 +05:45
1 parent b6a5343a42
commit a3c423c8b8
18 files changed
+2023 -966

No files matched your search

+158 -95
View File
@@ -1,3 +1,10 @@
from config.data import ( # CONFIG_DIR, HOME_DIR no se usan aquí directamente
APP_NAME,
APP_NAME_CAP,
)
from config.settings import constants as settings_constants
from gi.repository import GLib
from fabric.utils.helpers import exec_shell_command_async
import json
import os
import shutil
@@ -8,17 +15,13 @@ from pathlib import Path
import gi
import toml
gi.require_version('Gtk', '3.0')
from fabric.utils.helpers import exec_shell_command_async
from gi.repository import GLib
gi.require_version("Gtk", "3.0")
# Importar settings_constants para DEFAULTS
from config.settings import constants as settings_constants
from config.data import ( # CONFIG_DIR, HOME_DIR no se usan aquí directamente
APP_NAME, APP_NAME_CAP)
# Global variable to store binding variables, managed by this module
bind_vars = {} # Se inicializa vacío, load_bind_vars lo poblará
bind_vars = {} # Se inicializa vacío, load_bind_vars lo poblará
def deep_update(target: dict, update: dict) -> dict:
"""
@@ -33,7 +36,8 @@ def deep_update(target: dict, update: dict) -> dict:
else:
# De lo contrario, simplemente establece/sobrescribe el valor.
target[key] = value
return target # Aunque modifica in-place, devolverlo es una convención común
return target # Aunque modifica in-place, devolverlo es una convención común
def ensure_matugen_config():
"""
@@ -41,54 +45,64 @@ def ensure_matugen_config():
with the expected settings.
"""
expected_config = {
'config': {
'reload_apps': True,
'wallpaper': {
'command': 'swww',
'arguments': [
'img', '-t', 'outer',
'--transition-duration', '1.5',
'--transition-step', '255',
'--transition-fps', '60',
'-f', 'Nearest'
"config": {
"reload_apps": True,
"wallpaper": {
"command": "swww",
"arguments": [
"img",
"-t",
"outer",
"--transition-duration",
"1.5",
"--transition-step",
"255",
"--transition-fps",
"60",
"-f",
"Nearest",
],
'set': True
"set": True,
},
"custom_colors": {
"red": {"color": "#FF0000", "blend": True},
"green": {"color": "#00FF00", "blend": True},
"yellow": {"color": "#FFFF00", "blend": True},
"blue": {"color": "#0000FF", "blend": True},
"magenta": {"color": "#FF00FF", "blend": True},
"cyan": {"color": "#00FFFF", "blend": True},
"white": {"color": "#FFFFFF", "blend": True},
},
'custom_colors': {
'red': {'color': "#FF0000", 'blend': True},
'green': {'color': "#00FF00", 'blend': True},
'yellow': {'color': "#FFFF00", 'blend': True},
'blue': {'color': "#0000FF", 'blend': True},
'magenta': {'color': "#FF00FF", 'blend': True},
'cyan': {'color': "#00FFFF", 'blend': True},
'white': {'color': "#FFFFFF", 'blend': True}
}
},
'templates': {
'hyprland': {
'input_path': f'~/{APP_NAME_CAP}/config/matugen/templates/hyprland-colors.conf',
'output_path': f'~/{APP_NAME_CAP}/config/hypr/colors.conf'
"templates": {
"hyprland": {
"input_path": f"~/{APP_NAME_CAP}/config/matugen/templates/hyprland-colors.conf",
"output_path": f"~/{APP_NAME_CAP}/config/hypr/colors.conf",
},
f'{APP_NAME}': {
'input_path': f'~/{APP_NAME_CAP}/config/matugen/templates/{APP_NAME}.css',
'output_path': f'~/{APP_NAME_CAP}/styles/colors.css',
'post_hook': f"fabric-cli exec {APP_NAME} 'app.set_css()' &"
}
}
f"{APP_NAME}": {
"input_path": f"~/{APP_NAME_CAP}/config/matugen/templates/{APP_NAME}.css",
"output_path": f"~/{APP_NAME_CAP}/styles/colors.css",
"post_hook": f"fabric-cli exec {APP_NAME} 'app.set_css()' &",
},
},
}
config_path = os.path.expanduser('~/.config/matugen/config.toml')
config_path = os.path.expanduser("~/.config/matugen/config.toml")
os.makedirs(os.path.dirname(config_path), exist_ok=True)
existing_config = {}
if os.path.exists(config_path):
try:
with open(config_path, 'r') as f:
with open(config_path, "r") as f:
existing_config = toml.load(f)
shutil.copyfile(config_path, config_path + '.bak')
shutil.copyfile(config_path, config_path + ".bak")
except toml.TomlDecodeError:
print(f"Warning: Could not decode TOML from {config_path}. A new default config will be created.")
existing_config = {} # Resetear si está corrupto
print(
f"Warning: Could not decode TOML from {
config_path
}. A new default config will be created."
)
existing_config = {} # Resetear si está corrupto
except Exception as e:
print(f"Error reading or backing up {config_path}: {e}")
# existing_config podría estar parcialmente cargado o vacío.
@@ -100,39 +114,50 @@ def ensure_matugen_config():
# Para ser más seguros, podemos pasar una copia si existing_config no debe cambiar.
# merged_config = deep_update(existing_config.copy(), expected_config)
# O si existing_config puede ser modificado:
merged_config = deep_update(existing_config, expected_config) # existing_config se modifica in-place
# existing_config se modifica in-place
merged_config = deep_update(existing_config, expected_config)
try:
with open(config_path, 'w') as f:
with open(config_path, "w") as f:
toml.dump(merged_config, f)
except Exception as e:
print(f"Error writing matugen config to {config_path}: {e}")
current_wall = os.path.expanduser("~/.current.wall")
hypr_colors = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/colors.conf")
css_colors = os.path.expanduser(f"~/{APP_NAME_CAP}/styles/colors.css")
if not os.path.exists(current_wall) or not os.path.exists(hypr_colors) or not os.path.exists(css_colors):
if (
not os.path.exists(current_wall)
or not os.path.exists(hypr_colors)
or not os.path.exists(css_colors)
):
os.makedirs(os.path.dirname(hypr_colors), exist_ok=True)
os.makedirs(os.path.dirname(css_colors), exist_ok=True)
image_path = ""
if not os.path.exists(current_wall):
example_wallpaper_path = os.path.expanduser(f"~/.config/{APP_NAME_CAP}/assets/wallpapers_example/example-1.jpg")
example_wallpaper_path = os.path.expanduser(
f"~/.config/{APP_NAME_CAP}/assets/wallpapers_example/example-1.jpg"
)
if os.path.exists(example_wallpaper_path):
try:
# Si ya existe (posiblemente un enlace roto o archivo regular), eliminar y re-enlazar
if os.path.lexists(current_wall): # lexists para no seguir el enlace si es uno
# lexists para no seguir el enlace si es uno
if os.path.lexists(current_wall):
os.remove(current_wall)
os.symlink(example_wallpaper_path, current_wall)
image_path = example_wallpaper_path
except Exception as e:
print(f"Error creating symlink for wallpaper: {e}")
else:
image_path = os.path.realpath(current_wall) if os.path.islink(current_wall) else current_wall
if image_path and os.path.exists(image_path):
image_path = (
os.path.realpath(current_wall)
if os.path.islink(current_wall)
else current_wall
)
if image_path and os.path.exists(image_path):
print(f"Generating color theme from wallpaper: {image_path}")
try:
matugen_cmd = f"matugen image '{image_path}'"
@@ -143,9 +168,15 @@ def ensure_matugen_config():
except Exception as e:
print(f"Error initiating matugen: {e}")
elif not image_path:
print("Warning: No wallpaper path determined to generate matugen theme from.")
else: # image_path existe pero el archivo no
print(f"Warning: Wallpaper at {image_path} not found. Cannot generate matugen theme.")
print(
"Warning: No wallpaper path determined to generate matugen theme from."
)
else: # image_path existe pero el archivo no
print(
f"Warning: Wallpaper at {
image_path
} not found. Cannot generate matugen theme."
)
def load_bind_vars():
@@ -153,17 +184,18 @@ def load_bind_vars():
Load saved key binding variables from JSON, if available.
Populates the global `bind_vars` in-place.
"""
global bind_vars # Necesario para modificar el objeto global bind_vars
global bind_vars # Necesario para modificar el objeto global bind_vars
# 1. Limpiar el diccionario bind_vars existente.
bind_vars.clear()
# 2. Actualizarlo con una copia de DEFAULTS.
bind_vars.update(settings_constants.DEFAULTS.copy()) # Usar .copy() para no modificar DEFAULTS accidentalmente
# Usar .copy() para no modificar DEFAULTS accidentalmente
bind_vars.update(settings_constants.DEFAULTS.copy())
config_json = os.path.expanduser(f'~/{APP_NAME_CAP}/config/config.json')
config_json = os.path.expanduser(f"~/{APP_NAME_CAP}/config/config.json")
if os.path.exists(config_json):
try:
with open(config_json, 'r') as f:
with open(config_json, "r") as f:
saved_vars = json.load(f)
# 3. Usar deep_update para fusionar saved_vars en el bind_vars existente.
deep_update(bind_vars, saved_vars)
@@ -171,7 +203,7 @@ def load_bind_vars():
# La lógica para asegurar la estructura de diccionarios anidados
# como 'metrics_visible' y 'metrics_small_visible'
# debe operar sobre el 'bind_vars' ya actualizado.
for vis_key in ['metrics_visible']:
for vis_key in ["metrics_visible"]:
# Asegurar que la clave exista en DEFAULTS como referencia de estructura
if vis_key in settings_constants.DEFAULTS:
default_sub_dict = settings_constants.DEFAULTS[vis_key]
@@ -186,26 +218,34 @@ def load_bind_vars():
if m_key not in current_sub_dict:
current_sub_dict[m_key] = m_val
except json.JSONDecodeError:
print(f"Warning: Could not decode JSON from {config_json}. Using defaults (already initialized).")
print(
f"Warning: Could not decode JSON from {
config_json
}. Using defaults (already initialized)."
)
# bind_vars ya está poblado con DEFAULTS, no se necesita acción adicional aquí.
except Exception as e:
print(f"Error loading config from {config_json}: {e}. Using defaults (already initialized).")
print(
f"Error loading config from {config_json}: {
e
}. Using defaults (already initialized)."
)
# bind_vars ya está poblado con DEFAULTS.
# else:
# Si config_json no existe, bind_vars ya está poblado con DEFAULTS.
# print(f"Config file {config_json} not found. Using defaults (already initialized).")
# Si config_json no existe, bind_vars ya está poblado con DEFAULTS.
# print(f"Config file {config_json} not found. Using defaults (already initialized).")
def generate_hyprconf() -> str:
"""
Generate the Hypr configuration string using the current bind_vars.
"""
home = os.path.expanduser('~')
home = os.path.expanduser("~")
# Determine animation type based on bar position
bar_position = bind_vars.get('bar_position', 'Top')
bar_position = bind_vars.get("bar_position", "Top")
is_vertical = bar_position in ["Left", "Right"]
animation_type = "slidefadevert" if is_vertical else "slidefade"
return f"""exec-once = uwsm-app $(python {home}/{APP_NAME_CAP}/main.py)
exec = pgrep -x "hypridle" > /dev/null || uwsm app -- hypridle
exec = uwsm app -- swww-daemon
@@ -215,26 +255,37 @@ exec-once = wl-paste --type image --watch cliphist store
$fabricSend = fabric-cli exec {APP_NAME}
$axMessage = notify-send "Axenide" "FIRE IN THE HOLE‼️🗣️🔥🕳️" -i "{home}/.config/{APP_NAME_CAP}/assets/ax.png" -A "🗣️" -A "🔥" -A "🕳️" -a "Source Code"
bind = {bind_vars.get('prefix_restart', 'SUPER ALT')}, {bind_vars.get('suffix_restart', 'B')}, exec, killall {APP_NAME}; uwsm-app $(python {home}/.config/{APP_NAME_CAP}/main.py) # Reload {APP_NAME_CAP}
bind = {bind_vars.get('prefix_axmsg', 'SUPER')}, {bind_vars.get('suffix_axmsg', 'A')}, exec, $axMessage # Message
bind = {bind_vars.get('prefix_dash', 'SUPER')}, {bind_vars.get('suffix_dash', 'D')}, exec, $fabricSend 'notch.open_notch("dashboard")' # Dashboard
bind = {bind_vars.get('prefix_bluetooth', 'SUPER')}, {bind_vars.get('suffix_bluetooth', 'B')}, exec, $fabricSend 'notch.open_notch("bluetooth")' # Bluetooth
bind = {bind_vars.get('prefix_pins', 'SUPER')}, {bind_vars.get('suffix_pins', 'Q')}, exec, $fabricSend 'notch.open_notch("pins")' # Pins
bind = {bind_vars.get('prefix_kanban', 'SUPER')}, {bind_vars.get('suffix_kanban', 'N')}, exec, $fabricSend 'notch.open_notch("kanban")' # Kanban
bind = {bind_vars.get('prefix_launcher', 'SUPER')}, {bind_vars.get('suffix_launcher', 'R')}, exec, $fabricSend 'notch.open_notch("launcher")' # App Launcher
bind = {bind_vars.get('prefix_tmux', 'SUPER')}, {bind_vars.get('suffix_tmux', 'T')}, exec, $fabricSend 'notch.open_notch("tmux")' # Tmux
bind = {bind_vars.get('prefix_cliphist', 'SUPER')}, {bind_vars.get('suffix_cliphist', 'V')}, exec, $fabricSend 'notch.open_notch("cliphist")' # Clipboard History
bind = {bind_vars.get('prefix_toolbox', 'SUPER')}, {bind_vars.get('suffix_toolbox', 'S')}, exec, $fabricSend 'notch.open_notch("tools")' # Toolbox
bind = {bind_vars.get('prefix_overview', 'SUPER')}, {bind_vars.get('suffix_overview', 'TAB')}, exec, $fabricSend 'notch.open_notch("overview")' # Overview
bind = {bind_vars.get('prefix_wallpapers', 'SUPER')}, {bind_vars.get('suffix_wallpapers', 'COMMA')}, exec, $fabricSend 'notch.open_notch("wallpapers")' # Wallpapers
bind = {bind_vars.get('prefix_randwall', 'SUPER')}, {bind_vars.get('suffix_randwall', 'COMMA')}, exec, $fabricSend 'notch.dashboard.wallpapers.set_random_wallpaper(None, external=True)' # Random Wallpaper
bind = {bind_vars.get('prefix_emoji', 'SUPER')}, {bind_vars.get('suffix_emoji', 'PERIOD')}, exec, $fabricSend 'notch.open_notch("emoji")' # Emoji Picker
bind = {bind_vars.get('prefix_power', 'SUPER')}, {bind_vars.get('suffix_power', 'ESCAPE')}, exec, $fabricSend 'notch.open_notch("power")' # Power Menu
bind = {bind_vars.get('prefix_caffeine', 'SUPER SHIFT')}, {bind_vars.get('suffix_caffeine', 'M')}, exec, $fabricSend 'notch.dashboard.widgets.buttons.caffeine_button.toggle_inhibit(external=True)' # Toggle Caffeine
bind = {bind_vars.get('prefix_css', 'SUPER SHIFT')}, {bind_vars.get('suffix_css', 'B')}, exec, $fabricSend 'app.set_css()' # Reload CSS
bind = {bind_vars.get('prefix_restart_inspector', 'SUPER CTRL ALT')}, {bind_vars.get('suffix_restart_inspector', 'B')}, exec, killall {APP_NAME}; uwsm-app $(GTK_DEBUG=interactive python {home}/.config/{APP_NAME_CAP}/main.py) # Restart with inspector
# Reload {APP_NAME_CAP}
bind = {bind_vars.get("prefix_restart", "SUPER ALT")}, {bind_vars.get("suffix_restart", "B")}, exec, killall {APP_NAME}; uwsm-app $(python {home}/.config/{APP_NAME_CAP}/main.py)
# Message
bind = {bind_vars.get("prefix_axmsg", "SUPER")}, {bind_vars.get("suffix_axmsg", "A")}, exec, $axMessage
# Dashboard
bind = {bind_vars.get("prefix_dash", "SUPER")}, {bind_vars.get("suffix_dash", "D")}, exec, $fabricSend 'notch.open_notch("dashboard")'
# Bluetooth
bind = {bind_vars.get("prefix_bluetooth", "SUPER")}, {bind_vars.get("suffix_bluetooth", "B")}, exec, $fabricSend 'notch.open_notch("bluetooth")'
bind = {bind_vars.get("prefix_pins", "SUPER")}, {bind_vars.get("suffix_pins", "Q")}, exec, $fabricSend 'notch.open_notch("pins")' # Pins
bind = {bind_vars.get("prefix_kanban", "SUPER")}, {bind_vars.get("suffix_kanban", "N")}, exec, $fabricSend 'notch.open_notch("kanban")' # Kanban
# App Launcher
bind = {bind_vars.get("prefix_launcher", "SUPER")}, {bind_vars.get("suffix_launcher", "R")}, exec, $fabricSend 'notch.open_notch("launcher")'
bind = {bind_vars.get("prefix_tmux", "SUPER")}, {bind_vars.get("suffix_tmux", "T")}, exec, $fabricSend 'notch.open_notch("tmux")' # Tmux
# Clipboard History
bind = {bind_vars.get("prefix_cliphist", "SUPER")}, {bind_vars.get("suffix_cliphist", "V")}, exec, $fabricSend 'notch.open_notch("cliphist")'
# Toolbox
bind = {bind_vars.get("prefix_toolbox", "SUPER")}, {bind_vars.get("suffix_toolbox", "S")}, exec, $fabricSend 'notch.open_notch("tools")'
bind = {bind_vars.get("prefix_overview", "SUPER")}, {bind_vars.get("suffix_overview", "TAB")}, exec, $fabricSend 'notch.open_notch("overview")' # Overview
# Wallpapers
bind = {bind_vars.get("prefix_wallpapers", "SUPER")}, {bind_vars.get("suffix_wallpapers", "COMMA")}, exec, $fabricSend 'notch.open_notch("wallpapers")'
bind = {bind_vars.get("prefix_randwall", "SUPER")}, {bind_vars.get("suffix_randwall", "COMMA")}, exec, $fabricSend 'notch.dashboard.wallpapers.set_random_wallpaper(None, external=True)' # Random Wallpaper
# Emoji Picker
bind = {bind_vars.get("prefix_emoji", "SUPER")}, {bind_vars.get("suffix_emoji", "PERIOD")}, exec, $fabricSend 'notch.open_notch("emoji")'
# Power Menu
bind = {bind_vars.get("prefix_power", "SUPER")}, {bind_vars.get("suffix_power", "ESCAPE")}, exec, $fabricSend 'notch.open_notch("power")'
bind = {bind_vars.get("prefix_caffeine", "SUPER SHIFT")}, {bind_vars.get("suffix_caffeine", "M")}, exec, $fabricSend 'notch.dashboard.widgets.buttons.caffeine_button.toggle_inhibit(external=True)' # Toggle Caffeine
# Reload CSS
bind = {bind_vars.get("prefix_css", "SUPER SHIFT")}, {bind_vars.get("suffix_css", "B")}, exec, $fabricSend 'app.set_css()'
bind = {bind_vars.get("prefix_restart_inspector", "SUPER CTRL ALT")}, {bind_vars.get("suffix_restart_inspector", "B")}, exec, killall {APP_NAME}; uwsm-app $(GTK_DEBUG=interactive python {home}/.config/{APP_NAME_CAP}/main.py) # Restart with inspector
# Wallpapers directory: {bind_vars.get('wallpapers_dir', '~/Modus/assets/wallpapers_example')}
# Wallpapers directory: {bind_vars.get("wallpapers_dir", "~/Modus/assets/wallpapers_example")}
source = {home}/{APP_NAME_CAP}/config/hypr/colors.conf
@@ -283,6 +334,7 @@ animations {{
}}
"""
def ensure_face_icon():
"""
Ensure the face icon exists. If not, copy the default icon.
@@ -295,6 +347,7 @@ def ensure_face_icon():
except Exception as e:
print(f"Error copying default face icon: {e}")
def backup_and_replace(src: str, dest: str, config_name: str):
"""
Backup the existing configuration file and replace it with a new one.
@@ -306,7 +359,8 @@ def backup_and_replace(src: str, dest: str, config_name: str):
# os.makedirs(os.path.dirname(backup_path), exist_ok=True)
shutil.copy(dest, backup_path)
print(f"{config_name} config backed up to {backup_path}")
os.makedirs(os.path.dirname(dest), exist_ok=True) # Ensure dest directory exists
# Ensure dest directory exists
os.makedirs(os.path.dirname(dest), exist_ok=True)
shutil.copy(src, dest)
print(f"{config_name} config replaced from {src}")
except Exception as e:
@@ -338,12 +392,21 @@ def start_config():
print(f"{time.time():.4f}: start_config: Initiating hyprctl reload...")
try:
# subprocess.run(["hyprctl", "reload"], check=True, capture_output=True, text=True)
exec_shell_command_async("hyprctl reload") # Mantener async para no bloquear
print(f"{time.time():.4f}: start_config: Hyprland configuration reload initiated.")
# Mantener async para no bloquear
exec_shell_command_async("hyprctl reload")
print(
f"{time.time():.4f}: start_config: Hyprland configuration reload initiated."
)
except FileNotFoundError:
print("Error: hyprctl command not found. Cannot reload Hyprland.")
except subprocess.CalledProcessError as e: # Si usáramos subprocess.run con check=True
print(f"Error reloading Hyprland with hyprctl: {e}\nOutput:\n{e.stdout}\n{e.stderr}")
print("Error: hyprctl command not found. Cannot reload Hyprland.")
except (
subprocess.CalledProcessError
) as e: # Si usáramos subprocess.run con check=True
print(
f"Error reloading Hyprland with hyprctl: {e}\nOutput:\n{e.stdout}\n{
e.stderr
}"
)
except Exception as e:
print(f"An error occurred initiating hyprctl reload: {e}")
print(f"An error occurred initiating hyprctl reload: {e}")
print(f"{time.time():.4f}: start_config: Finished initiating hyprctl reload.")