✨ feat(ui): display active window title in menu bar and set default app name to Finder
This commit is contained in:
5 files changed
+77
-7
No files matched your search
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"wallpapers_dir": "~/Pictures/Wallpapers/",
|
||||
"wallpapers_dir": "/home/sankalp/Pictures/Wallpapers/",
|
||||
"dock_position": "Bottom",
|
||||
"terminal_command": "kitty -e",
|
||||
"dock_enabled": true,
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ CURRENT_WIDTH = screen.get_width()
|
||||
CURRENT_HEIGHT = screen.get_height()
|
||||
|
||||
|
||||
WALLPAPERS_DIR_DEFAULT = os.path.expanduser(f"~/Pictures/Wallpapers/")
|
||||
WALLPAPERS_DIR_DEFAULT = os.path.expanduser(f"~/Pictures/Wallpapers")
|
||||
CONFIG_FILE = get_relative_path("../config/assets/config.json")
|
||||
MATUGEN_STATE_FILE = os.path.join(CONFIG_DIR, "matugen")
|
||||
|
||||
|
||||
@@ -252,6 +252,9 @@ class MenuBarDropdowns:
|
||||
),
|
||||
)
|
||||
|
||||
# Connect to active app name changes to update the title button
|
||||
modus_service.connect("current-active-app-name-changed", self._on_active_app_changed)
|
||||
|
||||
self.global_menu_button_title = Button(
|
||||
child=ActiveWindow(
|
||||
formatter=FormattedString(
|
||||
@@ -335,6 +338,11 @@ class MenuBarDropdowns:
|
||||
# If we can't get window info, don't show dropdown
|
||||
pass
|
||||
|
||||
def _on_active_app_changed(self, _, value):
|
||||
"""Handle active app name changes"""
|
||||
# Update the "About" menu item label
|
||||
self.global_title_menu_about.set_property("label", f"About {value}")
|
||||
|
||||
def hide_dropdowns(self, *_):
|
||||
self.menu_button.remove_style_class("active")
|
||||
self.global_menu_button_edit.remove_style_class("active")
|
||||
|
||||
+55
-2
@@ -230,7 +230,7 @@ class ModusService(Service):
|
||||
self._bluetooth = ""
|
||||
self._dock_apps = ""
|
||||
self._dont_disturb = False
|
||||
self._current_active_app_name = "Hyprland"
|
||||
self._current_active_app_name = "Finder" # Changed from "Hyprland" to "Finder"
|
||||
self._current_workspace = "1"
|
||||
self._music = ""
|
||||
self._current_dropdown = None
|
||||
@@ -241,8 +241,9 @@ class ModusService(Service):
|
||||
self._dock_width = 0
|
||||
self._dock_height = 0
|
||||
|
||||
# Initialize Hyprland connection for workspace monitoring
|
||||
# Initialize Hyprland connection for workspace and window monitoring
|
||||
self._setup_workspace_monitoring()
|
||||
self._setup_active_window_monitoring()
|
||||
|
||||
def _setup_workspace_monitoring(self):
|
||||
"""Setup Hyprland connection and workspace monitoring"""
|
||||
@@ -265,6 +266,58 @@ class ModusService(Service):
|
||||
logger.error(f"[ModusService] Failed to setup workspace monitoring: {e}")
|
||||
self._current_workspace = "1"
|
||||
|
||||
def _setup_active_window_monitoring(self):
|
||||
"""Setup active window monitoring"""
|
||||
try:
|
||||
if not hasattr(self, '_hyprland_connection') or not self._hyprland_connection:
|
||||
return
|
||||
|
||||
# Get initial active window
|
||||
self._update_active_window()
|
||||
|
||||
# Note: The HyprlandActiveWindow widget from Fabric library
|
||||
# should handle active window updates automatically.
|
||||
# We just need to ensure the initial state is correct.
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[ModusService] Failed to setup active window monitoring: {e}")
|
||||
|
||||
def _update_active_window(self):
|
||||
"""Update the current active app name based on active window"""
|
||||
try:
|
||||
if not hasattr(self, '_hyprland_connection') or not self._hyprland_connection:
|
||||
return
|
||||
|
||||
window_data = self._hyprland_connection.send_command("j/activewindow").reply
|
||||
if not window_data:
|
||||
self.current_active_app_name = "Finder"
|
||||
return
|
||||
|
||||
window_info = json.loads(window_data.decode("utf-8"))
|
||||
wmclass = window_info.get("class", "")
|
||||
title = window_info.get("title", "")
|
||||
|
||||
# Handle the case when there's no active window
|
||||
if not title and not wmclass:
|
||||
self.current_active_app_name = "Finder"
|
||||
return
|
||||
|
||||
# Simple app name formatting without circular import
|
||||
name = wmclass if wmclass else title
|
||||
if name:
|
||||
# Basic formatting: capitalize first letter and remove file extensions
|
||||
name = str(name).title()
|
||||
if "." in name:
|
||||
name = name.split(".")[-1]
|
||||
else:
|
||||
name = "Finder"
|
||||
|
||||
self.current_active_app_name = name
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[ModusService] Error updating active window: {e}")
|
||||
self.current_active_app_name = "Finder"
|
||||
|
||||
def _on_workspace_changed(self, obj, signal):
|
||||
"""Handle workspace change events from Hyprland"""
|
||||
try:
|
||||
|
||||
@@ -53,7 +53,7 @@ class AppName:
|
||||
def format_app_name(self, title, wmclass, update=False):
|
||||
# Handle case when both title and wmclass are empty (no active window)
|
||||
if not title and not wmclass:
|
||||
name = "Hyprland"
|
||||
name = "Finder"
|
||||
else:
|
||||
name = wmclass
|
||||
if name == "":
|
||||
@@ -78,7 +78,16 @@ app_name_resolver = AppName()
|
||||
|
||||
|
||||
def format_window(title, wmclass):
|
||||
if not title and not wmclass:
|
||||
# Handle the case when HyprlandActiveWindow passes "unknown" instead of empty strings
|
||||
if (not title or title == "unknown") and (not wmclass or wmclass == "unknown"):
|
||||
return "Finder"
|
||||
|
||||
# Clean up "unknown" values
|
||||
if title == "unknown":
|
||||
title = ""
|
||||
if wmclass == "unknown":
|
||||
wmclass = ""
|
||||
|
||||
name = app_name_resolver.format_app_name(title, wmclass, True)
|
||||
return name
|
||||
return name
|
||||
|
||||
Reference in new issue
Block a user