new
This commit is contained in:
105 files changed
+6137
-27999
No files matched your search
@@ -0,0 +1,69 @@
|
||||
from config.data import (APP_NAME, APP_NAME_CAP, NOTIF_POS_DEFAULT, NOTIF_POS_KEY,WALLPAPERS_DIR_DEFAULT)
|
||||
|
||||
SOURCE_STRING = f"""
|
||||
# {APP_NAME_CAP}
|
||||
source = ~/{APP_NAME_CAP}/config/hypr/{APP_NAME}.conf
|
||||
"""
|
||||
|
||||
DEFAULTS = {
|
||||
"prefix_restart": "SUPER ALT",
|
||||
"suffix_restart": "B",
|
||||
"prefix_axmsg": "SUPER",
|
||||
"suffix_axmsg": "A",
|
||||
"prefix_dash": "SUPER",
|
||||
"suffix_dash": "D",
|
||||
"prefix_bluetooth": "SUPER SHIFT",
|
||||
"suffix_bluetooth": "B",
|
||||
"prefix_pins": "SUPER",
|
||||
"suffix_pins": "Q",
|
||||
"prefix_kanban": "SUPER",
|
||||
"suffix_kanban": "N",
|
||||
"prefix_launcher": "SUPER",
|
||||
"suffix_launcher": "R",
|
||||
"prefix_tmux": "SUPER",
|
||||
"suffix_tmux": "T",
|
||||
"prefix_cliphist": "SUPER",
|
||||
"suffix_cliphist": "V",
|
||||
"prefix_toolbox": "SUPER",
|
||||
"suffix_toolbox": "S",
|
||||
"prefix_overview": "SUPER",
|
||||
"suffix_overview": "TAB",
|
||||
"prefix_wallpapers": "SUPER",
|
||||
"suffix_wallpapers": "COMMA",
|
||||
"prefix_randwall": "SUPER SHIFT",
|
||||
"suffix_randwall": "COMMA",
|
||||
"prefix_emoji": "SUPER",
|
||||
"suffix_emoji": "PERIOD",
|
||||
"prefix_power": "SUPER",
|
||||
"suffix_power": "ESCAPE",
|
||||
"prefix_caffeine": "SUPER SHIFT",
|
||||
"suffix_caffeine": "M",
|
||||
"prefix_css": "SUPER SHIFT",
|
||||
"suffix_css": "B",
|
||||
"prefix_restart_inspector": "SUPER CTRL ALT",
|
||||
"suffix_restart_inspector": "B",
|
||||
"wallpapers_dir": "/home/sankalp/Pictures/wallpapers",
|
||||
"vertical": True,
|
||||
"dock_enabled": True,
|
||||
"dock_always_occluded": False,
|
||||
"dock_auto_hide": True,
|
||||
"terminal_command": "kitty -e",
|
||||
"corners_visible": False,
|
||||
"dock_theme": "Pills",
|
||||
"notif_pos": "Top",
|
||||
"dock_position": "Bottom",
|
||||
"dock_workspaces_visible": True,
|
||||
"dock_metrics_visible": True,
|
||||
"dock_battery_visible": True,
|
||||
"dock_date_time_visible": True,
|
||||
"dock_controls_visible": True,
|
||||
"dock_indicators_visible": True,
|
||||
"metrics_visible": {
|
||||
"cpu": True,
|
||||
"ram": True,
|
||||
"disk": True,
|
||||
"swap": True,
|
||||
"gpu": False
|
||||
},
|
||||
"bar_metrics_disks": []
|
||||
}
|
||||
@@ -0,0 +1,773 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from fabric.widgets.box import Box
|
||||
from fabric.widgets.button import Button
|
||||
from fabric.widgets.entry import Entry
|
||||
from fabric.widgets.image import Image as FabricImage
|
||||
from fabric.widgets.label import Label
|
||||
from fabric.widgets.scale import Scale
|
||||
from fabric.widgets.scrolledwindow import ScrolledWindow
|
||||
from fabric.widgets.stack import Stack
|
||||
from fabric.widgets.window import Window
|
||||
from gi.repository import GdkPixbuf, GLib, Gtk
|
||||
from PIL import Image
|
||||
|
||||
from config.data import (APP_NAME, APP_NAME_CAP, NOTIF_POS_DEFAULT, NOTIF_POS_KEY)
|
||||
from config.settings.utils import backup_and_replace, bind_vars, start_config
|
||||
|
||||
|
||||
class HyprConfGUI(Window):
|
||||
def __init__(self, show_lock_checkbox: bool, show_idle_checkbox: bool, **kwargs):
|
||||
super().__init__(
|
||||
title="Ax-Shell Settings",
|
||||
name="axshell-settings-window",
|
||||
size=(640, 640),
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
self.set_resizable(False)
|
||||
self.themes = ["Pills", "Dense", "Edge"]
|
||||
self.selected_face_icon = None
|
||||
self.show_lock_checkbox = show_lock_checkbox
|
||||
self.show_idle_checkbox = show_idle_checkbox
|
||||
|
||||
root_box = Box(orientation="v", spacing=10, style="margin: 10px;")
|
||||
self.add(root_box)
|
||||
|
||||
main_content_box = Box(orientation="h", spacing=6, v_expand=True, h_expand=True)
|
||||
root_box.add(main_content_box)
|
||||
|
||||
self.tab_stack = Stack(
|
||||
transition_type="slide-up-down",
|
||||
transition_duration=250,
|
||||
v_expand=True, h_expand=True
|
||||
)
|
||||
|
||||
self.key_bindings_tab_content = self.create_key_bindings_tab()
|
||||
self.appearance_tab_content = self.create_appearance_tab()
|
||||
self.system_tab_content = self.create_system_tab()
|
||||
self.about_tab_content = self.create_about_tab()
|
||||
|
||||
self.tab_stack.add_titled(self.key_bindings_tab_content, "key_bindings", "Key Bindings")
|
||||
self.tab_stack.add_titled(self.appearance_tab_content, "appearance", "Appearance")
|
||||
self.tab_stack.add_titled(self.system_tab_content, "system", "System")
|
||||
self.tab_stack.add_titled(self.about_tab_content, "about", "About")
|
||||
|
||||
tab_switcher = Gtk.StackSwitcher()
|
||||
tab_switcher.set_stack(self.tab_stack)
|
||||
tab_switcher.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
main_content_box.add(tab_switcher)
|
||||
main_content_box.add(self.tab_stack)
|
||||
|
||||
button_box = Box(orientation="h", spacing=10, h_align="end")
|
||||
reset_btn = Button(label="Reset to Defaults", on_clicked=self.on_reset)
|
||||
button_box.add(reset_btn)
|
||||
close_btn = Button(label="Close", on_clicked=self.on_close)
|
||||
button_box.add(close_btn)
|
||||
accept_btn = Button(label="Apply & Reload", on_clicked=self.on_accept)
|
||||
button_box.add(accept_btn)
|
||||
root_box.add(button_box)
|
||||
|
||||
def create_key_bindings_tab(self):
|
||||
scrolled_window = ScrolledWindow(
|
||||
h_scrollbar_policy="never",
|
||||
v_scrollbar_policy="automatic",
|
||||
h_expand=True,
|
||||
v_expand=True,
|
||||
propagate_width=False,
|
||||
propagate_height=False
|
||||
)
|
||||
|
||||
main_vbox = Box(orientation="v", spacing=10, style="margin: 15px;")
|
||||
scrolled_window.add(main_vbox)
|
||||
|
||||
keybind_grid = Gtk.Grid()
|
||||
keybind_grid.set_column_spacing(10)
|
||||
keybind_grid.set_row_spacing(8)
|
||||
keybind_grid.set_margin_start(5)
|
||||
keybind_grid.set_margin_end(5)
|
||||
keybind_grid.set_margin_top(5)
|
||||
keybind_grid.set_margin_bottom(5)
|
||||
|
||||
action_label = Label(markup="<b>Action</b>", h_align="start", style="margin-bottom: 5px;")
|
||||
modifier_label = Label(markup="<b>Modifier</b>", h_align="start", style="margin-bottom: 5px;")
|
||||
separator_label = Label(label="+", h_align="center", style="margin-bottom: 5px;")
|
||||
key_label = Label(markup="<b>Key</b>", h_align="start", style="margin-bottom: 5px;")
|
||||
|
||||
keybind_grid.attach(action_label, 0, 0, 1, 1)
|
||||
keybind_grid.attach(modifier_label, 1, 0, 1, 1)
|
||||
keybind_grid.attach(separator_label, 2, 0, 1, 1)
|
||||
keybind_grid.attach(key_label, 3, 0, 1, 1)
|
||||
|
||||
self.entries = []
|
||||
bindings = [
|
||||
(f"Reload {APP_NAME_CAP}", 'prefix_restart', 'suffix_restart'),
|
||||
("Message", 'prefix_axmsg', 'suffix_axmsg'),
|
||||
("Dashboard", 'prefix_dash', 'suffix_dash'),
|
||||
("Bluetooth", 'prefix_bluetooth', 'suffix_bluetooth'),
|
||||
("Pins", 'prefix_pins', 'suffix_pins'),
|
||||
("Kanban", 'prefix_kanban', 'suffix_kanban'),
|
||||
("App Launcher", 'prefix_launcher', 'suffix_launcher'),
|
||||
("Tmux", 'prefix_tmux', 'suffix_tmux'),
|
||||
("Clipboard History", 'prefix_cliphist', 'suffix_cliphist'),
|
||||
("Toolbox", 'prefix_toolbox', 'suffix_toolbox'),
|
||||
("Overview", 'prefix_overview', 'suffix_overview'),
|
||||
("Wallpapers", 'prefix_wallpapers', 'suffix_wallpapers'),
|
||||
("Random Wallpaper", 'prefix_randwall', 'suffix_randwall'),
|
||||
("Emoji Picker", 'prefix_emoji', 'suffix_emoji'),
|
||||
("Power Menu", 'prefix_power', 'suffix_power'),
|
||||
("Toggle Caffeine", 'prefix_caffeine', 'suffix_caffeine'),
|
||||
("Reload CSS", 'prefix_css', 'suffix_css'),
|
||||
("Restart with inspector", 'prefix_restart_inspector', 'suffix_restart_inspector'),
|
||||
]
|
||||
|
||||
for i, (label_text, prefix_key, suffix_key) in enumerate(bindings):
|
||||
row = i + 1
|
||||
binding_label = Label(label=label_text, h_align="start")
|
||||
keybind_grid.attach(binding_label, 0, row, 1, 1)
|
||||
prefix_entry = Entry(text=bind_vars.get(prefix_key, ''))
|
||||
keybind_grid.attach(prefix_entry, 1, row, 1, 1)
|
||||
plus_label = Label(label="+", h_align="center")
|
||||
keybind_grid.attach(plus_label, 2, row, 1, 1)
|
||||
suffix_entry = Entry(text=bind_vars.get(suffix_key, ''))
|
||||
keybind_grid.attach(suffix_entry, 3, row, 1, 1)
|
||||
self.entries.append((prefix_key, suffix_key, prefix_entry, suffix_entry))
|
||||
|
||||
main_vbox.add(keybind_grid)
|
||||
return scrolled_window
|
||||
|
||||
def create_appearance_tab(self):
|
||||
scrolled_window = ScrolledWindow(
|
||||
h_scrollbar_policy="never",
|
||||
v_scrollbar_policy="automatic",
|
||||
h_expand=True,
|
||||
v_expand=True,
|
||||
propagate_width=False,
|
||||
propagate_height=False
|
||||
)
|
||||
|
||||
vbox = Box(orientation="v", spacing=15, style="margin: 15px;")
|
||||
scrolled_window.add(vbox)
|
||||
|
||||
top_grid = Gtk.Grid()
|
||||
top_grid.set_column_spacing(20)
|
||||
top_grid.set_row_spacing(5)
|
||||
top_grid.set_margin_bottom(10)
|
||||
vbox.add(top_grid)
|
||||
|
||||
wall_header = Label(markup="<b>Wallpapers</b>", h_align="start")
|
||||
top_grid.attach(wall_header, 0, 0, 1, 1)
|
||||
wall_label = Label(label="Directory:", h_align="start", v_align="center")
|
||||
top_grid.attach(wall_label, 0, 1, 1, 1)
|
||||
|
||||
chooser_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
chooser_container.set_halign(Gtk.Align.START)
|
||||
chooser_container.set_valign(Gtk.Align.CENTER)
|
||||
self.wall_dir_chooser = Gtk.FileChooserButton(
|
||||
title="Select a folder", action=Gtk.FileChooserAction.SELECT_FOLDER
|
||||
)
|
||||
self.wall_dir_chooser.set_tooltip_text("Select the directory containing your wallpaper images")
|
||||
self.wall_dir_chooser.set_filename(bind_vars.get('wallpapers_dir',''))
|
||||
self.wall_dir_chooser.set_size_request(180, -1)
|
||||
chooser_container.add(self.wall_dir_chooser)
|
||||
top_grid.attach(chooser_container, 1, 1, 1, 1)
|
||||
|
||||
face_header = Label(markup="<b>Profile Icon</b>", h_align="start")
|
||||
top_grid.attach(face_header, 2, 0, 2, 1)
|
||||
current_face = os.path.expanduser("~/.face.icon")
|
||||
face_image_container = Box(style_classes=["image-frame"], h_align="center", v_align="center")
|
||||
self.face_image = FabricImage(size=64)
|
||||
try:
|
||||
if os.path.exists(current_face):
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(current_face, 64, 64)
|
||||
self.face_image.set_from_pixbuf(pixbuf)
|
||||
else:
|
||||
self.face_image.set_from_icon_name("user-info", Gtk.IconSize.DIALOG)
|
||||
except Exception as e:
|
||||
print(f"Error loading face icon: {e}")
|
||||
self.face_image.set_from_icon_name("image-missing", Gtk.IconSize.DIALOG)
|
||||
face_image_container.add(self.face_image)
|
||||
top_grid.attach(face_image_container, 2, 1, 1, 1)
|
||||
|
||||
browse_btn_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
browse_btn_container.set_halign(Gtk.Align.START)
|
||||
browse_btn_container.set_valign(Gtk.Align.CENTER)
|
||||
face_btn = Button(label="Browse...",
|
||||
tooltip_text="Select a square image for your profile icon",
|
||||
on_clicked=self.on_select_face_icon)
|
||||
browse_btn_container.add(face_btn)
|
||||
top_grid.attach(browse_btn_container, 3, 1, 1, 1)
|
||||
self.face_status_label = Label(label="", h_align="start")
|
||||
top_grid.attach(self.face_status_label, 2, 2, 2, 1)
|
||||
|
||||
separator1 = Box(style="min-height: 1px; background-color: alpha(@fg_color, 0.2); margin: 5px 0px;", h_expand=True)
|
||||
vbox.add(separator1)
|
||||
|
||||
layout_header = Label(markup="<b>Layout Options</b>", h_align="start")
|
||||
vbox.add(layout_header)
|
||||
layout_grid = Gtk.Grid()
|
||||
layout_grid.set_column_spacing(20)
|
||||
layout_grid.set_row_spacing(10)
|
||||
layout_grid.set_margin_start(10)
|
||||
layout_grid.set_margin_top(5)
|
||||
vbox.add(layout_grid)
|
||||
|
||||
position_label = Label(label="Dock Position", h_align="start", v_align="center")
|
||||
layout_grid.attach(position_label, 0, 0, 1, 1)
|
||||
position_combo_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
self.position_combo = Gtk.ComboBoxText()
|
||||
self.position_combo.set_tooltip_text("Select the position of the dock")
|
||||
positions = ["Bottom", "Left", "Right"]
|
||||
for pos in positions:
|
||||
self.position_combo.append_text(pos)
|
||||
current_position = bind_vars.get('dock_position', "Bottom")
|
||||
try:
|
||||
self.position_combo.set_active(positions.index(current_position))
|
||||
except ValueError:
|
||||
self.position_combo.set_active(0)
|
||||
self.position_combo.connect("changed", self.on_position_changed)
|
||||
position_combo_container.add(self.position_combo)
|
||||
layout_grid.attach(position_combo_container, 1, 0, 1, 1)
|
||||
|
||||
dock_theme_label = Label(label="Dock Theme", h_align="start", v_align="center")
|
||||
layout_grid.attach(dock_theme_label, 2, 0, 1, 1)
|
||||
dock_theme_combo_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
self.dock_theme_combo = Gtk.ComboBoxText()
|
||||
self.dock_theme_combo.set_tooltip_text("Select the visual theme for the dock")
|
||||
for theme in self.themes:
|
||||
self.dock_theme_combo.append_text(theme)
|
||||
current_dock_theme = bind_vars.get('dock_theme', "Pills")
|
||||
try:
|
||||
self.dock_theme_combo.set_active(self.themes.index(current_dock_theme))
|
||||
except ValueError:
|
||||
self.dock_theme_combo.set_active(0)
|
||||
dock_theme_combo_container.add(self.dock_theme_combo)
|
||||
layout_grid.attach(dock_theme_combo_container, 3, 0, 1, 1)
|
||||
|
||||
dock_label = Label(label="Show Dock", h_align="start", v_align="center")
|
||||
layout_grid.attach(dock_label, 0, 1, 1, 1)
|
||||
dock_switch_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
self.dock_switch = Gtk.Switch(active=bind_vars.get('dock_enabled', True))
|
||||
self.dock_switch.connect("notify::active", self.on_dock_enabled_changed)
|
||||
dock_switch_container.add(self.dock_switch)
|
||||
layout_grid.attach(dock_switch_container, 1, 1, 1, 1)
|
||||
|
||||
dock_auto_hide_label = Label(label="Auto-hide Dock", h_align="start", v_align="center")
|
||||
layout_grid.attach(dock_auto_hide_label, 0, 2, 1, 1)
|
||||
dock_auto_hide_switch_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
self.dock_auto_hide_switch = Gtk.Switch(active=bind_vars.get('dock_auto_hide', False), sensitive=self.dock_switch.get_active())
|
||||
dock_auto_hide_switch_container.add(self.dock_auto_hide_switch)
|
||||
layout_grid.attach(dock_auto_hide_switch_container, 1, 2, 1, 1)
|
||||
|
||||
dock_hover_label = Label(label="Show Dock Only on Hover", h_align="start", v_align="center")
|
||||
layout_grid.attach(dock_hover_label, 2, 1, 1, 1)
|
||||
dock_hover_switch_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
self.dock_hover_switch = Gtk.Switch(active=bind_vars.get('dock_always_occluded', False), sensitive=self.dock_switch.get_active())
|
||||
dock_hover_switch_container.add(self.dock_hover_switch)
|
||||
layout_grid.attach(dock_hover_switch_container, 3, 1, 1, 1)
|
||||
|
||||
notification_pos_label = Label(label="Notification Position", h_align="start", v_align="center")
|
||||
layout_grid.attach(notification_pos_label, 0, 7, 1, 1)
|
||||
|
||||
notification_pos_combo_container = Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
|
||||
self.notification_pos_combo = Gtk.ComboBoxText()
|
||||
self.notification_pos_combo.set_tooltip_text("Select where notifications appear on the screen.")
|
||||
|
||||
notification_positions_list = ["Top", "Bottom"]
|
||||
for pos in notification_positions_list:
|
||||
self.notification_pos_combo.append_text(pos)
|
||||
|
||||
current_notif_pos = bind_vars.get(NOTIF_POS_KEY, NOTIF_POS_DEFAULT)
|
||||
try:
|
||||
self.notification_pos_combo.set_active(notification_positions_list.index(current_notif_pos))
|
||||
except ValueError:
|
||||
self.notification_pos_combo.set_active(0)
|
||||
|
||||
self.notification_pos_combo.connect("changed", self.on_notification_position_changed)
|
||||
|
||||
notification_pos_combo_container.add(self.notification_pos_combo)
|
||||
layout_grid.attach(notification_pos_combo_container, 1, 7, 3, 1)
|
||||
|
||||
separator2 = Box(style="min-height: 1px; background-color: alpha(@fg_color, 0.2); margin: 5px 0px;", h_expand=True)
|
||||
vbox.add(separator2)
|
||||
|
||||
components_header = Label(markup="<b>Modules</b>", h_align="start")
|
||||
vbox.add(components_header)
|
||||
components_grid = Gtk.Grid()
|
||||
components_grid.set_column_spacing(15)
|
||||
components_grid.set_row_spacing(8)
|
||||
components_grid.set_margin_start(10)
|
||||
components_grid.set_margin_top(5)
|
||||
vbox.add(components_grid)
|
||||
|
||||
self.component_switches = {}
|
||||
component_display_names = {
|
||||
'workspace':"Workspaces",
|
||||
'metrics':"System Metrics",
|
||||
'date_time':"Date & Time",
|
||||
'battery':"Battery Indicator",
|
||||
'controls':"Control Panel",
|
||||
'indicators':"Indicators",
|
||||
'systray':"System Tray",
|
||||
}
|
||||
|
||||
self.corners_switch = Gtk.Switch(active=bind_vars.get('corners_visible', True))
|
||||
num_components = len(component_display_names) + 1
|
||||
rows_per_column = (num_components + 1) // 2
|
||||
|
||||
corners_label = Label(label="Rounded Corners", h_align="start", v_align="center")
|
||||
components_grid.attach(corners_label, 0, 0, 1, 1)
|
||||
switch_container_corners = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
switch_container_corners.add(self.corners_switch)
|
||||
components_grid.attach(switch_container_corners, 1, 0, 1, 1)
|
||||
|
||||
current_row = 0
|
||||
current_col = 0
|
||||
item_idx = 0
|
||||
for i, (name, display) in enumerate(component_display_names.items()):
|
||||
if item_idx < (rows_per_column -1) :
|
||||
row = item_idx + 1
|
||||
col = 0
|
||||
else:
|
||||
row = (item_idx - (rows_per_column -1))
|
||||
col = 2
|
||||
|
||||
component_label = Label(label=display, h_align="start", v_align="center")
|
||||
components_grid.attach(component_label, col, row, 1, 1)
|
||||
|
||||
switch_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
component_switch = Gtk.Switch(active=bind_vars.get(f'bar_{name}_visible', True))
|
||||
switch_container.add(component_switch)
|
||||
components_grid.attach(switch_container, col + 1, row, 1, 1)
|
||||
self.component_switches[name] = component_switch
|
||||
item_idx +=1
|
||||
|
||||
|
||||
return scrolled_window
|
||||
|
||||
|
||||
|
||||
def on_notification_position_changed(self, combo: Gtk.ComboBoxText):
|
||||
selected_text = combo.get_active_text()
|
||||
if selected_text:
|
||||
bind_vars[NOTIF_POS_KEY] = selected_text
|
||||
print(f"Notification position updated in bind_vars: {bind_vars[NOTIF_POS_KEY]}")
|
||||
|
||||
def create_system_tab(self):
|
||||
scrolled_window = ScrolledWindow(
|
||||
h_scrollbar_policy="never",
|
||||
v_scrollbar_policy="automatic",
|
||||
h_expand=True,
|
||||
v_expand=True,
|
||||
propagate_width=False,
|
||||
propagate_height=False
|
||||
)
|
||||
|
||||
vbox = Box(orientation="v", spacing=15, style="margin: 15px;")
|
||||
scrolled_window.add(vbox)
|
||||
|
||||
system_grid = Gtk.Grid()
|
||||
system_grid.set_column_spacing(20)
|
||||
system_grid.set_row_spacing(10)
|
||||
system_grid.set_margin_bottom(15)
|
||||
vbox.add(system_grid)
|
||||
|
||||
terminal_header = Label(markup="<b>Terminal Settings</b>", h_align="start")
|
||||
system_grid.attach(terminal_header, 0, 0, 2, 1)
|
||||
terminal_label = Label(label="Command:", h_align="start", v_align="center")
|
||||
system_grid.attach(terminal_label, 0, 1, 1, 1)
|
||||
self.terminal_entry = Entry(
|
||||
text=bind_vars.get('terminal_command', "kitty -e"),
|
||||
tooltip_text="Command used to launch terminal apps (e.g., 'kitty -e')",
|
||||
h_expand=True
|
||||
)
|
||||
system_grid.attach(self.terminal_entry, 1, 1, 1, 1)
|
||||
hint_label = Label(markup="<small>Examples: 'kitty -e', 'alacritty -e', 'foot -e'</small>", h_align="start")
|
||||
system_grid.attach(hint_label, 0, 2, 2, 1)
|
||||
|
||||
hypr_header = Label(markup="<b>Hyprland Integration</b>", h_align="start")
|
||||
system_grid.attach(hypr_header, 2, 0, 2, 1)
|
||||
row = 1
|
||||
self.lock_switch = None
|
||||
if self.show_lock_checkbox:
|
||||
lock_label = Label(label="Replace Hyprlock config", h_align="start", v_align="center")
|
||||
system_grid.attach(lock_label, 2, row, 1, 1)
|
||||
lock_switch_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
self.lock_switch = Gtk.Switch(tooltip_text="Replace Hyprlock configuration with Ax-Shell's custom config")
|
||||
lock_switch_container.add(self.lock_switch)
|
||||
system_grid.attach(lock_switch_container, 3, row, 1, 1)
|
||||
row += 1
|
||||
self.idle_switch = None
|
||||
if self.show_idle_checkbox:
|
||||
idle_label = Label(label="Replace Hypridle config", h_align="start", v_align="center")
|
||||
system_grid.attach(idle_label, 2, row, 1, 1)
|
||||
idle_switch_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
self.idle_switch = Gtk.Switch(tooltip_text="Replace Hypridle configuration with Ax-Shell's custom config")
|
||||
idle_switch_container.add(self.idle_switch)
|
||||
system_grid.attach(idle_switch_container, 3, row, 1, 1)
|
||||
row += 1
|
||||
if self.show_lock_checkbox or self.show_idle_checkbox:
|
||||
note_label = Label(markup="<small>Existing configs will be backed up</small>", h_align="start")
|
||||
system_grid.attach(note_label, 2, row, 2, 1)
|
||||
|
||||
metrics_header = Label(markup="<b>System Metrics Options</b>", h_align="start")
|
||||
vbox.add(metrics_header)
|
||||
metrics_grid = Gtk.Grid(column_spacing=15, row_spacing=8, margin_start=10, margin_top=5)
|
||||
vbox.add(metrics_grid)
|
||||
|
||||
self.metrics_switches = {}
|
||||
metric_names = {'cpu': "CPU", 'ram': "RAM", 'disk': "Disk", 'swap': "Swap", 'gpu': "GPU"}
|
||||
|
||||
metrics_grid.attach(Label(label="Show in Metrics", h_align="start"), 0, 0, 1, 1)
|
||||
for i, (key, label_text) in enumerate(metric_names.items()):
|
||||
switch = Gtk.Switch(active=bind_vars.get('metrics_visible', {}).get(key, True))
|
||||
self.metrics_switches[key] = switch
|
||||
metrics_grid.attach(Label(label=label_text, h_align="start"), 0, i + 1, 1, 1)
|
||||
metrics_grid.attach(switch, 1, i + 1, 1, 1)
|
||||
|
||||
|
||||
def enforce_minimum_metrics(switch_dict):
|
||||
enabled_switches = [s for s in switch_dict.values() if s.get_active()]
|
||||
can_disable = len(enabled_switches) > 1
|
||||
for s in switch_dict.values():
|
||||
s.set_sensitive(True if can_disable or not s.get_active() else False)
|
||||
|
||||
def on_metric_toggle(switch, gparam, switch_dict): enforce_minimum_metrics(switch_dict)
|
||||
for k_s, s_s in self.metrics_switches.items(): s_s.connect("notify::active", on_metric_toggle, self.metrics_switches)
|
||||
enforce_minimum_metrics(self.metrics_switches)
|
||||
|
||||
disks_label = Label(label="Disk directories for Metrics", h_align="start", v_align="center")
|
||||
vbox.add(disks_label)
|
||||
self.disk_entries = Box(orientation="v", spacing=8, h_align="start")
|
||||
|
||||
self._create_disk_edit_entry_func = lambda path: self._add_disk_entry_widget(path)
|
||||
|
||||
for p in bind_vars.get('bar_metrics_disks', ["/"]): self._create_disk_edit_entry_func(p)
|
||||
vbox.add(self.disk_entries)
|
||||
|
||||
add_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.START, valign=Gtk.Align.CENTER)
|
||||
add_btn = Button(label="Add new disk", on_clicked=lambda _: self._create_disk_edit_entry_func("/"))
|
||||
add_container.add(add_btn)
|
||||
vbox.add(add_container)
|
||||
|
||||
return scrolled_window
|
||||
|
||||
def _add_disk_entry_widget(self, path):
|
||||
"""Helper para añadir una fila de entrada de disco al Box disk_entries."""
|
||||
bar = Box(orientation="h", spacing=10, h_align="start")
|
||||
entry = Entry(text=path, h_expand=True)
|
||||
bar.add(entry)
|
||||
x_btn = Button(label="X")
|
||||
x_btn.connect("clicked", lambda _, current_bar_to_remove=bar: self.disk_entries.remove(current_bar_to_remove))
|
||||
bar.add(x_btn)
|
||||
self.disk_entries.add(bar)
|
||||
self.disk_entries.show_all()
|
||||
|
||||
|
||||
def create_about_tab(self):
|
||||
vbox = Box(orientation="v", spacing=18, style="margin: 30px;")
|
||||
vbox.add(Label(markup=f"<b>{APP_NAME_CAP}</b>", h_align="start", style="font-size: 1.5em; margin-bottom: 8px;"))
|
||||
vbox.add(Label(label="A hackable shell for Hyprland, powered by Fabric.", h_align="start", style="margin-bottom: 12px;"))
|
||||
repo_box = Box(orientation="h", spacing=6, h_align="start")
|
||||
repo_label = Label(label="GitHub:", h_align="start")
|
||||
repo_link = Label(markup='<a href="https://github.com/S4NKALP/Modus">https://github.com/S4NKALP/Modus</a>')
|
||||
repo_box.add(repo_label); repo_box.add(repo_link)
|
||||
vbox.add(repo_box)
|
||||
def on_kofi_clicked(_): import webbrowser; webbrowser.open("https://ko-fi.com/S4NKALP")
|
||||
kofi_btn = Button(label="Support on Ko-Fi ❤️", on_clicked=on_kofi_clicked, tooltip_text="Support S4NKALP on Ko-Fi", style="margin-top: 18px; min-width: 160px;")
|
||||
vbox.add(kofi_btn)
|
||||
vbox.add(Box(v_expand=True))
|
||||
return vbox
|
||||
|
||||
def on_ws_num_changed(self, switch, gparam):
|
||||
is_active = switch.get_active()
|
||||
self.ws_chinese_switch.set_sensitive(is_active)
|
||||
if not is_active: self.ws_chinese_switch.set_active(False)
|
||||
|
||||
def on_position_changed(self, combo):
|
||||
position = combo.get_active_text()
|
||||
is_vertical = position in ["Left", "Right"]
|
||||
self.centered_switch.set_sensitive(is_vertical)
|
||||
if not is_vertical:
|
||||
self.centered_switch.set_active(False)
|
||||
|
||||
def on_dock_enabled_changed(self, switch, gparam):
|
||||
is_active = switch.get_active()
|
||||
self.dock_hover_switch.set_sensitive(is_active)
|
||||
self.dock_auto_hide_switch.set_sensitive(is_active)
|
||||
if not is_active:
|
||||
self.dock_hover_switch.set_active(False)
|
||||
self.dock_auto_hide_switch.set_active(False)
|
||||
|
||||
def on_select_face_icon(self, widget):
|
||||
dialog = Gtk.FileChooserDialog(
|
||||
title="Select Face Icon", transient_for=self.get_toplevel(), action=Gtk.FileChooserAction.OPEN
|
||||
)
|
||||
dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
|
||||
image_filter = Gtk.FileFilter()
|
||||
image_filter.set_name("Image files")
|
||||
for mime in ["image/png", "image/jpeg"]: image_filter.add_mime_type(mime)
|
||||
for pattern in ["*.png", "*.jpg", "*.jpeg"]: image_filter.add_pattern(pattern)
|
||||
dialog.add_filter(image_filter)
|
||||
if dialog.run() == Gtk.ResponseType.OK:
|
||||
self.selected_face_icon = dialog.get_filename()
|
||||
self.face_status_label.label = f"Selected: {os.path.basename(self.selected_face_icon)}"
|
||||
try:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(self.selected_face_icon, 64, 64)
|
||||
self.face_image.set_from_pixbuf(pixbuf)
|
||||
except Exception as e:
|
||||
print(f"Error loading selected face icon preview: {e}")
|
||||
self.face_image.set_from_icon_name("image-missing", Gtk.IconSize.DIALOG)
|
||||
dialog.destroy()
|
||||
|
||||
def on_accept(self, widget):
|
||||
|
||||
current_bind_vars_snapshot = {}
|
||||
for prefix_key, suffix_key, prefix_entry, suffix_entry in self.entries:
|
||||
current_bind_vars_snapshot[prefix_key] = prefix_entry.get_text()
|
||||
current_bind_vars_snapshot[suffix_key] = suffix_entry.get_text()
|
||||
|
||||
current_bind_vars_snapshot['wallpapers_dir'] = self.wall_dir_chooser.get_filename()
|
||||
|
||||
current_bind_vars_snapshot['dock_position'] = self.position_combo.get_active_text()
|
||||
current_bind_vars_snapshot['vertical'] = current_bind_vars_snapshot['dock_position'] in ["Left", "Right"]
|
||||
|
||||
current_bind_vars_snapshot['dock_enabled'] = self.dock_switch.get_active()
|
||||
current_bind_vars_snapshot['dock_auto_hide'] = self.dock_auto_hide_switch.get_active()
|
||||
current_bind_vars_snapshot['dock_always_occluded'] = self.dock_hover_switch.get_active()
|
||||
current_bind_vars_snapshot['terminal_command'] = self.terminal_entry.get_text()
|
||||
current_bind_vars_snapshot['corners_visible'] = self.corners_switch.get_active()
|
||||
current_bind_vars_snapshot['dock_theme'] = self.dock_theme_combo.get_active_text()
|
||||
|
||||
selected_notif_pos_text = self.notification_pos_combo.get_active_text()
|
||||
if selected_notif_pos_text:
|
||||
current_bind_vars_snapshot[NOTIF_POS_KEY] = selected_notif_pos_text
|
||||
else:
|
||||
current_bind_vars_snapshot[NOTIF_POS_KEY] = NOTIF_POS_DEFAULT
|
||||
|
||||
for component_name, switch in self.component_switches.items():
|
||||
current_bind_vars_snapshot[f'bar_{component_name}_visible'] = switch.get_active()
|
||||
|
||||
current_bind_vars_snapshot['metrics_visible'] = {k: s.get_active() for k, s in self.metrics_switches.items()}
|
||||
current_bind_vars_snapshot['metrics_disks'] = [
|
||||
child.get_children()[0].get_text() for child in self.disk_entries.get_children() if isinstance(child, Gtk.Box) and child.get_children() and isinstance(child.get_children()[0], Entry)
|
||||
]
|
||||
|
||||
|
||||
selected_icon_path = self.selected_face_icon
|
||||
replace_lock = self.lock_switch and self.lock_switch.get_active()
|
||||
replace_idle = self.idle_switch and self.idle_switch.get_active()
|
||||
|
||||
if self.selected_face_icon:
|
||||
self.selected_face_icon = None
|
||||
self.face_status_label.label = ""
|
||||
|
||||
def _apply_and_reload_task_thread():
|
||||
nonlocal current_bind_vars_snapshot
|
||||
|
||||
from . import utils
|
||||
utils.bind_vars.clear()
|
||||
utils.bind_vars.update(current_bind_vars_snapshot)
|
||||
|
||||
|
||||
start_time = time.time()
|
||||
print(f"{start_time:.4f}: Background task started.")
|
||||
|
||||
config_json = os.path.expanduser(f'~/{APP_NAME_CAP}/config/config.json')
|
||||
os.makedirs(os.path.dirname(config_json), exist_ok=True)
|
||||
try:
|
||||
with open(config_json, 'w') as f:
|
||||
json.dump(utils.bind_vars, f, indent=4)
|
||||
print(f"{time.time():.4f}: Saved config.json.")
|
||||
except Exception as e: print(f"Error saving config.json: {e}")
|
||||
|
||||
if selected_icon_path:
|
||||
print(f"{time.time():.4f}: Processing face icon...")
|
||||
try:
|
||||
img = Image.open(selected_icon_path)
|
||||
side = min(img.size); left = (img.width - side)//2; top = (img.height - side)//2
|
||||
cropped_img = img.crop((left, top, left + side, top + side))
|
||||
face_icon_dest = os.path.expanduser("~/.face.icon")
|
||||
cropped_img.save(face_icon_dest, format='PNG')
|
||||
print(f"{time.time():.4f}: Face icon saved to {face_icon_dest}")
|
||||
GLib.idle_add(self._update_face_image_widget, face_icon_dest)
|
||||
except Exception as e: print(f"Error processing face icon: {e}")
|
||||
print(f"{time.time():.4f}: Finished processing face icon.")
|
||||
|
||||
if replace_lock:
|
||||
print(f"{time.time():.4f}: Replacing hyprlock config...")
|
||||
src = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/hyprlock.conf")
|
||||
dest = os.path.expanduser("~/.config/hypr/hyprlock.conf")
|
||||
if os.path.exists(src): backup_and_replace(src, dest, "Hyprlock")
|
||||
else: print(f"Warning: Source hyprlock config not found at {src}")
|
||||
print(f"{time.time():.4f}: Finished replacing hyprlock config.")
|
||||
|
||||
if replace_idle:
|
||||
print(f"{time.time():.4f}: Replacing hypridle config...")
|
||||
src = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/hypridle.conf")
|
||||
dest = os.path.expanduser("~/.config/hypr/hypridle.conf")
|
||||
if os.path.exists(src): backup_and_replace(src, dest, "Hypridle")
|
||||
else: print(f"Warning: Source hypridle config not found at {src}")
|
||||
print(f"{time.time():.4f}: Finished replacing hypridle config.")
|
||||
|
||||
print(f"{time.time():.4f}: Checking/Appending hyprland.conf source string...")
|
||||
hypr_path = os.path.expanduser("~/.config/hypr/hyprland.conf")
|
||||
try:
|
||||
from .constants import SOURCE_STRING
|
||||
needs_append = True
|
||||
if os.path.exists(hypr_path):
|
||||
with open(hypr_path, "r") as f:
|
||||
if SOURCE_STRING.strip() in f.read(): needs_append = False
|
||||
else: os.makedirs(os.path.dirname(hypr_path), exist_ok=True)
|
||||
|
||||
if needs_append:
|
||||
with open(hypr_path, "a") as f: f.write("\n" + SOURCE_STRING)
|
||||
print(f"Appended source string to {hypr_path}")
|
||||
except Exception as e: print(f"Error updating {hypr_path}: {e}")
|
||||
print(f"{time.time():.4f}: Finished checking/appending hyprland.conf source string.")
|
||||
|
||||
print(f"{time.time():.4f}: Running start_config()...")
|
||||
start_config()
|
||||
print(f"{time.time():.4f}: Finished start_config().")
|
||||
|
||||
print(f"{time.time():.4f}: Initiating Ax-Shell restart using Popen...")
|
||||
main_py = os.path.expanduser(f"~/{APP_NAME_CAP}/main.py")
|
||||
kill_cmd = f"killall {APP_NAME}"
|
||||
start_cmd = ["uwsm", "app", "--", "python", main_py]
|
||||
try:
|
||||
kill_proc = subprocess.Popen(kill_cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
kill_proc.wait(timeout=2)
|
||||
print(f"{time.time():.4f}: killall process finished (o timed out).")
|
||||
except subprocess.TimeoutExpired: print("Warning: killall command timed out.")
|
||||
except Exception as e: print(f"Error running killall: {e}")
|
||||
|
||||
try:
|
||||
subprocess.Popen(start_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
|
||||
print(f"{APP_NAME_CAP} restart initiated via Popen.")
|
||||
except FileNotFoundError as e: print(f"Error restarting {APP_NAME_CAP}: Command not found ({e})")
|
||||
except Exception as e: print(f"Error restarting {APP_NAME_CAP} via Popen: {e}")
|
||||
|
||||
print(f"{time.time():.4f}: Ax-Shell restart commands issued via Popen.")
|
||||
end_time = time.time()
|
||||
print(f"{end_time:.4f}: Background task finished (Total: {end_time - start_time:.4f}s).")
|
||||
|
||||
thread = threading.Thread(target=_apply_and_reload_task_thread)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
print("Configuration apply/reload task started in background.")
|
||||
|
||||
def _update_face_image_widget(self, icon_path):
|
||||
try:
|
||||
if self.face_image and self.face_image.get_window():
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_path, 64, 64)
|
||||
self.face_image.set_from_pixbuf(pixbuf)
|
||||
except Exception as e:
|
||||
print(f"Error reloading face icon preview: {e}")
|
||||
if self.face_image and self.face_image.get_window():
|
||||
self.face_image.set_from_icon_name("image-missing", Gtk.IconSize.DIALOG)
|
||||
return GLib.SOURCE_REMOVE
|
||||
|
||||
def on_reset(self, widget):
|
||||
dialog = Gtk.MessageDialog(
|
||||
transient_for=self.get_toplevel(), flags=0, message_type=Gtk.MessageType.QUESTION,
|
||||
buttons=Gtk.ButtonsType.YES_NO, text="Reset all settings to defaults?"
|
||||
)
|
||||
dialog.format_secondary_text("This will reset all keybindings and appearance settings to their default values.")
|
||||
response = dialog.run()
|
||||
dialog.hide() # Hide the dialog first
|
||||
dialog.destroy() # Then destroy it
|
||||
|
||||
# Process any pending events
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
|
||||
if response == Gtk.ResponseType.YES:
|
||||
from . import utils
|
||||
from .constants import DEFAULTS
|
||||
|
||||
utils.bind_vars.clear()
|
||||
utils.bind_vars.update(DEFAULTS.copy())
|
||||
|
||||
for prefix_key, suffix_key, prefix_entry, suffix_entry in self.entries:
|
||||
prefix_entry.set_text(utils.bind_vars[prefix_key])
|
||||
suffix_entry.set_text(utils.bind_vars[suffix_key])
|
||||
|
||||
self.wall_dir_chooser.set_filename(utils.bind_vars['wallpapers_dir'])
|
||||
|
||||
positions = ["Bottom", "Left", "Right"]
|
||||
default_position = DEFAULTS.get('dock_position', "Top")
|
||||
try:
|
||||
self.position_combo.set_active(positions.index(default_position))
|
||||
except ValueError:
|
||||
self.position_combo.set_active(0)
|
||||
|
||||
|
||||
self.dock_switch.set_active(utils.bind_vars.get('dock_enabled', True))
|
||||
self.dock_auto_hide_switch.set_active(utils.bind_vars.get('dock_auto_hide', False))
|
||||
self.dock_hover_switch.set_active(utils.bind_vars.get('dock_always_occluded', False))
|
||||
self.dock_hover_switch.set_sensitive(self.dock_switch.get_active())
|
||||
self.dock_auto_hide_switch.set_sensitive(self.dock_switch.get_active())
|
||||
self.terminal_entry.set_text(utils.bind_vars['terminal_command'])
|
||||
|
||||
default_dock_theme_val = DEFAULTS.get('dock_theme', "Pills")
|
||||
try:
|
||||
self.dock_theme_combo.set_active(self.themes.index(default_dock_theme_val))
|
||||
except ValueError:
|
||||
self.dock_theme_combo.set_active(0)
|
||||
|
||||
default_notif_pos_val = DEFAULTS.get(NOTIF_POS_KEY, NOTIF_POS_DEFAULT)
|
||||
notification_positions_list = ["Top", "Bottom"]
|
||||
try:
|
||||
self.notification_pos_combo.set_active(notification_positions_list.index(default_notif_pos_val))
|
||||
except ValueError:
|
||||
self.notification_pos_combo.set_active(0)
|
||||
|
||||
for name, switch in self.component_switches.items():
|
||||
switch.set_active(utils.bind_vars.get(f'bar_{name}_visible', True))
|
||||
self.corners_switch.set_active(utils.bind_vars.get('corners_visible', True))
|
||||
|
||||
metrics_vis_defaults = DEFAULTS.get('metrics_visible', {})
|
||||
for k, s_widget in self.metrics_switches.items(): s_widget.set_active(metrics_vis_defaults.get(k, True))
|
||||
|
||||
|
||||
def enforce_minimum_metrics(switch_dict):
|
||||
enabled_switches = [s for s in switch_dict.values() if s.get_active()]
|
||||
can_disable = len(enabled_switches) > 1
|
||||
for s in switch_dict.values():
|
||||
s.set_sensitive(True if can_disable or not s.get_active() else False)
|
||||
enforce_minimum_metrics(self.metrics_switches)
|
||||
|
||||
|
||||
for child in list(self.disk_entries.get_children()): self.disk_entries.remove(child)
|
||||
|
||||
for p in DEFAULTS.get('metrics_disks', ["/"]):
|
||||
self._add_disk_edit_entry_func(p)
|
||||
|
||||
self._update_panel_position_sensitivity()
|
||||
|
||||
self.selected_face_icon = None
|
||||
self.face_status_label.label = ""
|
||||
current_face = os.path.expanduser("~/.face.icon")
|
||||
try:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(current_face, 64, 64) if os.path.exists(current_face) else None
|
||||
if pixbuf: self.face_image.set_from_pixbuf(pixbuf)
|
||||
else: self.face_image.set_from_icon_name("user-info", Gtk.IconSize.DIALOG)
|
||||
except Exception: self.face_image.set_from_icon_name("image-missing", Gtk.IconSize.DIALOG)
|
||||
|
||||
if self.lock_switch: self.lock_switch.set_active(False)
|
||||
if self.idle_switch: self.idle_switch.set_active(False)
|
||||
print("Settings reset to defaults.")
|
||||
|
||||
def on_close(self, widget):
|
||||
if self.application: self.application.quit()
|
||||
else: self.destroy()
|
||||
@@ -0,0 +1,349 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
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
|
||||
|
||||
# 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á
|
||||
|
||||
def deep_update(target: dict, update: dict) -> dict:
|
||||
"""
|
||||
Recursively update a nested dictionary with values from another dictionary.
|
||||
Modifies target in-place.
|
||||
"""
|
||||
for key, value in update.items():
|
||||
if isinstance(value, dict) and key in target and isinstance(target[key], dict):
|
||||
# Si el valor es un diccionario y la clave ya existe en target como diccionario,
|
||||
# entonces actualiza recursivamente.
|
||||
deep_update(target[key], value)
|
||||
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
|
||||
|
||||
def ensure_matugen_config():
|
||||
"""
|
||||
Ensure that the matugen configuration file exists and is updated
|
||||
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'
|
||||
],
|
||||
'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}
|
||||
}
|
||||
},
|
||||
'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()' &"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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:
|
||||
existing_config = toml.load(f)
|
||||
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
|
||||
except Exception as e:
|
||||
print(f"Error reading or backing up {config_path}: {e}")
|
||||
# existing_config podría estar parcialmente cargado o vacío.
|
||||
# Continuar para intentar fusionar con defaults.
|
||||
|
||||
# Usamos una copia de existing_config para deep_update si no queremos modificarlo directamente
|
||||
# o asegurarse que deep_update no lo haga si no es deseado.
|
||||
# La implementación actual de deep_update modifica 'target'.
|
||||
# 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
|
||||
|
||||
try:
|
||||
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):
|
||||
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")
|
||||
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
|
||||
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):
|
||||
print(f"Generating color theme from wallpaper: {image_path}")
|
||||
try:
|
||||
matugen_cmd = f"matugen image '{image_path}'"
|
||||
exec_shell_command_async(matugen_cmd)
|
||||
print("Matugen color theme generation initiated.")
|
||||
except FileNotFoundError:
|
||||
print("Error: matugen command not found. Please install matugen.")
|
||||
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.")
|
||||
|
||||
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
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:
|
||||
saved_vars = json.load(f)
|
||||
# 3. Usar deep_update para fusionar saved_vars en el bind_vars existente.
|
||||
deep_update(bind_vars, saved_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']:
|
||||
# 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]
|
||||
# Si la clave no está en bind_vars o no es un diccionario después de deep_update,
|
||||
# restaurarla desde una copia de DEFAULTS para esa clave.
|
||||
if not isinstance(bind_vars.get(vis_key), dict):
|
||||
bind_vars[vis_key] = default_sub_dict.copy()
|
||||
else:
|
||||
# Si es un diccionario, asegurar que todas las sub-claves de DEFAULTS estén presentes.
|
||||
current_sub_dict = bind_vars[vis_key]
|
||||
for m_key, m_val in default_sub_dict.items():
|
||||
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).")
|
||||
# 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).")
|
||||
# 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).")
|
||||
|
||||
|
||||
def generate_hyprconf() -> str:
|
||||
"""
|
||||
Generate the Hypr configuration string using the current bind_vars.
|
||||
"""
|
||||
home = os.path.expanduser('~')
|
||||
# Determine animation type based on bar position
|
||||
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
|
||||
exec-once = wl-paste --type text --watch cliphist store
|
||||
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
|
||||
|
||||
# Wallpapers directory: {bind_vars.get('wallpapers_dir', '~/Modus/assets/wallpapers_example')}
|
||||
|
||||
source = {home}/{APP_NAME_CAP}/config/hypr/colors.conf
|
||||
|
||||
layerrule = noanim, fabric
|
||||
|
||||
exec = cp $wallpaper ~/.current.wall
|
||||
|
||||
general {{
|
||||
col.active_border = rgb($primary)
|
||||
col.inactive_border = rgb($surface)
|
||||
gaps_in = 2
|
||||
gaps_out = 4
|
||||
border_size = 2
|
||||
layout = dwindle
|
||||
}}
|
||||
|
||||
cursor {{
|
||||
no_warps=true
|
||||
}}
|
||||
|
||||
decoration {{
|
||||
blur {{
|
||||
enabled = yes
|
||||
size = 5
|
||||
passes = 3
|
||||
new_optimizations = yes
|
||||
contrast = 1
|
||||
brightness = 1
|
||||
}}
|
||||
rounding = 14
|
||||
shadow {{
|
||||
enabled = true
|
||||
range = 10
|
||||
render_power = 2
|
||||
color = rgba(0, 0, 0, 0.25)
|
||||
}}
|
||||
}}
|
||||
|
||||
animations {{
|
||||
enabled = yes
|
||||
bezier = myBezier, 0.4, 0.0, 0.2, 1.0
|
||||
animation = windows, 1, 2.5, myBezier, popin 80%
|
||||
animation = border, 1, 2.5, myBezier
|
||||
animation = fade, 1, 2.5, myBezier
|
||||
animation = workspaces, 1, 2.5, myBezier, {animation_type} 20%
|
||||
}}
|
||||
"""
|
||||
|
||||
def ensure_face_icon():
|
||||
"""
|
||||
Ensure the face icon exists. If not, copy the default icon.
|
||||
"""
|
||||
face_icon_path = os.path.expanduser("~/.face.icon")
|
||||
default_icon_path = os.path.expanduser(f"~/{APP_NAME_CAP}/assets/default.png")
|
||||
if not os.path.exists(face_icon_path) and os.path.exists(default_icon_path):
|
||||
try:
|
||||
shutil.copy(default_icon_path, face_icon_path)
|
||||
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.
|
||||
"""
|
||||
try:
|
||||
if os.path.exists(dest):
|
||||
backup_path = dest + ".bak"
|
||||
# Asegurarse que el directorio de backup existe si es diferente
|
||||
# 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
|
||||
shutil.copy(src, dest)
|
||||
print(f"{config_name} config replaced from {src}")
|
||||
except Exception as e:
|
||||
print(f"Error backing up/replacing {config_name} config: {e}")
|
||||
|
||||
|
||||
def start_config():
|
||||
"""
|
||||
Run final configuration steps: ensure necessary configs, write the hyprconf, and reload.
|
||||
"""
|
||||
print(f"{time.time():.4f}: start_config: Ensuring matugen config...")
|
||||
ensure_matugen_config()
|
||||
print(f"{time.time():.4f}: start_config: Ensuring face icon...")
|
||||
ensure_face_icon()
|
||||
print(f"{time.time():.4f}: start_config: Generating hypr conf...")
|
||||
|
||||
hypr_config_dir = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/")
|
||||
os.makedirs(hypr_config_dir, exist_ok=True)
|
||||
# Usar APP_NAME para el nombre del archivo .conf para que coincida con SOURCE_STRING corregido
|
||||
hypr_conf_path = os.path.join(hypr_config_dir, f"{APP_NAME}.conf")
|
||||
try:
|
||||
with open(hypr_conf_path, "w") as f:
|
||||
f.write(generate_hyprconf())
|
||||
print(f"Generated Hyprland config at {hypr_conf_path}")
|
||||
except Exception as e:
|
||||
print(f"Error writing Hyprland config: {e}")
|
||||
print(f"{time.time():.4f}: start_config: Finished generating hypr conf.")
|
||||
|
||||
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.")
|
||||
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}")
|
||||
except Exception as e:
|
||||
print(f"An error occurred initiating hyprctl reload: {e}")
|
||||
print(f"{time.time():.4f}: start_config: Finished initiating hyprctl reload.")
|
||||
Reference in new issue
Block a user