refactor(src/window): migrate control center windows to AppletWindow and simplify UI

Replace Window base with AppletWindow for consistency, switch to FlatScale, and streamline mouse capture handling.
This commit is contained in:
sankalp committed 2026-06-17 01:45:43 +05:45
1 parent b8d3e74afd
commit f78534dce0
11 files changed
+168 -199

No files matched your search

+7 -9
View File
@@ -1,7 +1,7 @@
import subprocess
from fabric.bluetooth import BluetoothClient, BluetoothDevice
from fabric.utils import Gdk, GLib, Gtk, exec_shell_command, logger
from fabric.utils import Gdk, GLib, exec_shell_command, logger
from fabric.widgets.box import Box
from fabric.widgets.button import Button
from fabric.widgets.centerbox import CenterBox
@@ -12,6 +12,7 @@ from fabric.widgets.scrolledwindow import ScrolledWindow
from fabric.widgets.separator import Separator
from utils.utils import svg_file
from shared.widgets.smooth_switch import SmoothSwitch
def get_battery_icon_file(
@@ -246,14 +247,11 @@ class BluetoothConnections(Box):
children=title_children,
)
self.toggle_button = Gtk.Switch(visible=True, name="toggle-button")
# Safely set initial state
self.toggle_button.set_active(self.client.enabled)
self.toggle_button.connect(
"notify::active",
lambda *_: set_bluetooth_enabled_with_fallback(
self.client, self.toggle_button.get_active()
self.toggle_button = SmoothSwitch(
name="toggle-button",
active=self.client.enabled,
on_user_toggle=lambda active: set_bluetooth_enabled_with_fallback(
self.client, active
),
)
@@ -1437,9 +1437,6 @@ class ExpandedPlayer(Window):
super().destroy()
def _init_mousecapture(self, mousecapture):
self._mousecapture_parent = mousecapture
def hide_controlcenter(self, *_):
# self._mousecapture_parent.toggle_mousecapture()
self.set_visible(False)
+17 -19
View File
@@ -5,8 +5,7 @@ from fabric.widgets.box import Box
from fabric.widgets.button import Button
from fabric.widgets.centerbox import CenterBox
from fabric.widgets.label import Label
from fabric.widgets.scale import Scale
from fabric.widgets.wayland import WaylandWindow as Window
from shared.widgets.flat_scale import FlatScale
from services.brightness import Brightness
from services.network import NetworkClient
@@ -22,18 +21,21 @@ from window.controlcenter.per_app_volume import PerAppVolumeControl
from window.controlcenter.player import PlayerBoxStack, get_shared_mpris_manager
from window.controlcenter.wifi import WifiConnections
brightness_service = Brightness.get_initial()
from shared.window.applet_window import AppletWindow
brightness_service = Brightness()
class ModusControlCenter(Window):
def __init__(self, **kwargs):
class ModusControlCenter(AppletWindow):
def __init__(self, parent=None, pointing_to=None, **kwargs):
super().__init__(
parent=parent,
pointing_to=pointing_to,
layer="top",
title="modus",
anchor="top right",
margin="2px 10px 0px 0px",
exclusivity="auto",
keyboard_mode="on-demand",
name="control-center-menu",
visible=False,
**kwargs,
@@ -98,11 +100,11 @@ class ModusControlCenter(Window):
ellipsization="end",
h_align="start",
)
self.volume_scale = Scale(
self.volume_scale = FlatScale(
value=volume,
min_value=0,
max_value=100,
increments=(5, 5),
step=5,
name="volume-widget-slider",
size=30,
h_expand=True,
@@ -115,11 +117,11 @@ class ModusControlCenter(Window):
else 50
)
self.brightness_scale = Scale(
self.brightness_scale = FlatScale(
value=brightness_percentage,
min_value=0,
max_value=100,
increments=(5, 5),
step=5,
name="brightness-widget-slider",
size=30,
h_expand=True,
@@ -555,7 +557,7 @@ class ModusControlCenter(Window):
# Connect brightness controls if brightness service is available
if brightness_service.max_screen > 0:
self.brightness_scale.connect("change-value", self.set_brightness)
self.brightness_scale.connect("value-changed", self.set_brightness)
self.brightness_scale.connect("scroll-event", self.on_brightness_scroll)
self._signal_connections.append(
(
@@ -565,7 +567,7 @@ class ModusControlCenter(Window):
)
# Connect volume scale signals
self.volume_scale.connect("change-value", self.set_volume)
self.volume_scale.connect("value-changed", self.set_volume)
self.volume_scale.connect("scroll-event", self.on_volume_scroll)
# Mark signals as connected
@@ -762,14 +764,14 @@ class ModusControlCenter(Window):
except Exception as e:
logger.warning(f"Failed to toggle caffeine: {e}")
def set_volume(self, _, __, volume):
def set_volume(self, _, volume):
if not self._signals_connected:
return
self._updating_volume = True
audio_service.speaker.volume = round(volume)
self._updating_volume = False
def set_brightness(self, _, __, brightness):
def set_brightness(self, _, brightness):
if not self._signals_connected:
return
self._updating_brightness = True
@@ -1023,9 +1025,6 @@ class ModusControlCenter(Window):
)
self.focus_status_label.set_label("On" if self.focus_mode else "Off")
def _init_mousecapture(self, mousecapture):
self._mousecapture_parent = mousecapture
def _disconnect_all_signals(self):
"""Disconnect all signal connections to prevent memory leaks"""
try:
@@ -1206,8 +1205,7 @@ class ModusControlCenter(Window):
self._disconnect_signals_when_hidden()
# Hide the control center
if hasattr(self, "_mousecapture_parent"):
self._mousecapture_parent.toggle_mousecapture()
self.set_visible(False)
self.set_visible(False)
except Exception as e:
+5 -5
View File
@@ -3,7 +3,7 @@ from fabric.widgets.box import Box
from fabric.widgets.button import Button
from fabric.widgets.image import Image
from fabric.widgets.label import Label
from fabric.widgets.scale import Scale
from shared.widgets.flat_scale import FlatScale
from fabric.widgets.scrolledwindow import ScrolledWindow
from fabric.widgets.separator import Separator
@@ -249,11 +249,11 @@ class PerAppVolumeControl(Box):
)
# Volume scale (smaller and horizontal)
volume_scale = Scale(
volume_scale = FlatScale(
value=volume_percent,
min_value=0,
max_value=max_vol,
increments=(1, 5),
step=5,
name="compact-volume-slider",
size=20,
h_expand=True,
@@ -261,8 +261,8 @@ class PerAppVolumeControl(Box):
# Connect volume change handler
volume_scale.connect(
"change-value",
lambda scale, scroll_type, value, app=app: self._set_app_volume(app, value),
"value-changed",
lambda scale, value, app=app: self._set_app_volume(app, value),
)
# Create horizontal compact layout
+8 -3
View File
@@ -1,6 +1,6 @@
import subprocess
from fabric.utils import Gdk, GLib, Gtk
from fabric.utils import Gdk, GLib
from fabric.widgets.box import Box
from fabric.widgets.button import Button
from fabric.widgets.centerbox import CenterBox
@@ -13,6 +13,7 @@ from fabric.widgets.separator import Separator
from services.network import NetworkClient
from utils.functions import get_wifi_connecting_icon, get_wifi_icon_for_strength
from utils.utils import svg_file
from shared.widgets.smooth_switch import SmoothSwitch
from shared.dialogs.wifi_password_dialog import WiFiPasswordDialog
from gi.repository import NM
@@ -299,7 +300,12 @@ class WifiConnections(Box):
children=title_children,
)
self.toggle_button = Gtk.Switch(visible=True, name="toggle-button")
self.toggle_button = SmoothSwitch(
name="toggle-button",
on_user_toggle=lambda active: self.on_toggle_changed(
self.toggle_button, active
),
)
# Create Known Network section
self.known_networks_label = Label(
@@ -393,7 +399,6 @@ class WifiConnections(Box):
if self.wifi_service:
# Set up WiFi toggle
self.toggle_button.set_active(self.wifi_service.wireless_enabled)
self.toggle_button.connect("notify::active", self.on_toggle_changed)
# Connect to WiFi service signals — track IDs for cleanup
self._signal_ids.append(