Initial commit of the Quickshell desktop suite: bar, dock, launcher, settings, Control Center, dashboard, OSD, lock screen, desktop widgets, plugin host with the vendored Noctalia/Omarchy compatibility layer, helpers, packaging, tests and phase documentation. Includes the optimization work so far: usage widgets and dashboard gauges no longer animate continuously, desktop widgets pause while covered, system controls stop flickering on background polls, dock app matching uses an indexed catalog, and workspace ghosts are created only for occupied slots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
6.0 KiB
Python
117 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Synthetic SNI + DBusMenu server. Use only inside a private dbus-run-session."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
import dbus
|
|
import dbus.service
|
|
from dbus.mainloop.glib import DBusGMainLoop
|
|
from gi.repository import GLib
|
|
|
|
DBusGMainLoop(set_as_default=True)
|
|
bus = dbus.SessionBus()
|
|
events = Path(sys.argv[1])
|
|
icon_path = events.parent / 'fixture.svg'
|
|
icon_path.write_text('<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"><rect x="2" y="2" width="20" height="20" rx="5" fill="#52b8b0"/></svg>')
|
|
|
|
def record(kind, **values):
|
|
with events.open('a') as file:
|
|
file.write(json.dumps(dict(kind=kind, **values)) + '\n')
|
|
|
|
SNI = 'org.kde.StatusNotifierItem'
|
|
MENU = 'com.canonical.dbusmenu'
|
|
PROPS = 'org.freedesktop.DBus.Properties'
|
|
|
|
class TrayItem(dbus.service.Object):
|
|
def __init__(self, path, identifier, menu):
|
|
super().__init__(bus, path)
|
|
self.identifier = identifier
|
|
self.menu = menu
|
|
|
|
def properties(self):
|
|
props = {'Category':'ApplicationStatus', 'Id':self.identifier, 'Title':self.identifier,
|
|
'Status':'Active', 'IconName':str(icon_path), 'IconPixmap':dbus.Array([], signature='(iiay)'),
|
|
'AttentionIconName':str(icon_path), 'AttentionIconPixmap':dbus.Array([], signature='(iiay)'),
|
|
'OverlayIconName':'', 'OverlayIconPixmap':dbus.Array([], signature='(iiay)'),
|
|
'ItemIsMenu':False,
|
|
'ToolTip':dbus.Struct((str(icon_path), dbus.Array([], signature='(iiay)'), self.identifier, 'Test fixture'), signature='sa(iiay)ss')}
|
|
if self.menu: props['Menu'] = dbus.ObjectPath('/Menu')
|
|
return props
|
|
|
|
@dbus.service.method(PROPS, in_signature='s', out_signature='a{sv}')
|
|
def GetAll(self, interface): return self.properties() if interface == SNI else {}
|
|
@dbus.service.method(PROPS, in_signature='ss', out_signature='v')
|
|
def Get(self, interface, name): return self.properties()[name]
|
|
@dbus.service.method(SNI, in_signature='ii')
|
|
def Activate(self, x, y): record('activate', item=self.identifier)
|
|
@dbus.service.method(SNI, in_signature='ii')
|
|
def SecondaryActivate(self, x, y): record('secondary', item=self.identifier)
|
|
@dbus.service.method(SNI, in_signature='ii')
|
|
def ContextMenu(self, x, y): record('context', item=self.identifier)
|
|
@dbus.service.method(SNI, in_signature='is')
|
|
def Scroll(self, delta, orientation): record('scroll', delta=delta, orientation=orientation)
|
|
|
|
class Menu(dbus.service.Object):
|
|
def __init__(self):
|
|
super().__init__(bus, '/Menu')
|
|
self.props = {
|
|
0:{'children-display':'submenu'},
|
|
1:{'label':'&Open fixture', 'icon-name':str(icon_path)},
|
|
2:{'type':'separator'},
|
|
3:{'label':'Disabled action', 'enabled':False},
|
|
4:{'label':'Checked option', 'toggle-type':'checkmark', 'toggle-state':dbus.Int32(1)},
|
|
5:{'label':'Radio option', 'toggle-type':'radio', 'toggle-state':dbus.Int32(0)},
|
|
6:{'label':'Submenu', 'children-display':'submenu'},
|
|
7:{'label':'Nested action'},
|
|
8:{'label':'Deeper submenu', 'children-display':'submenu'},
|
|
9:{'label':'Deep action'},
|
|
10:{'label':'Hidden action', 'visible':False},
|
|
}
|
|
self.children = {0:[1,2,3,4,5,6,10],6:[7,8],8:[9]}
|
|
|
|
def layout(self, ident, depth):
|
|
children = [] if depth == 0 else [dbus.Struct(self.layout(i, depth-1 if depth > 0 else -1), signature='ia{sv}av', variant_level=1) for i in self.children.get(ident, [])]
|
|
return (dbus.Int32(ident), dbus.Dictionary(self.props[ident], signature='sv'), dbus.Array(children, signature='v'))
|
|
|
|
@dbus.service.method(PROPS, in_signature='s', out_signature='a{sv}')
|
|
def GetAll(self, interface): return {'Version':dbus.UInt32(3),'TextDirection':'ltr','Status':'normal','IconThemePath':dbus.Array([],signature='s')}
|
|
@dbus.service.method(PROPS, in_signature='ss', out_signature='v')
|
|
def Get(self, interface, name): return self.GetAll(interface)[name]
|
|
@dbus.service.method(MENU, in_signature='iias', out_signature='u(ia{sv}av)')
|
|
def GetLayout(self, parent, depth, names): return (dbus.UInt32(1), self.layout(parent, depth))
|
|
@dbus.service.method(MENU, in_signature='aias', out_signature='a(ia{sv})')
|
|
def GetGroupProperties(self, ids, names): return [(i, self.props[i]) for i in ids]
|
|
@dbus.service.method(MENU, in_signature='is', out_signature='v')
|
|
def GetProperty(self, ident, name): return self.props[ident][name]
|
|
@dbus.service.method(MENU, in_signature='isvu')
|
|
def Event(self, ident, event, data, timestamp):
|
|
record('menu', id=int(ident), event=str(event))
|
|
if event == 'clicked' and ident in (4,5):
|
|
self.props[ident]['toggle-state'] = dbus.Int32(1-int(self.props[ident]['toggle-state']))
|
|
self.ItemsPropertiesUpdated([(ident, {'toggle-state':self.props[ident]['toggle-state']})], [])
|
|
@dbus.service.method(MENU, in_signature='a(isvu)', out_signature='ai')
|
|
def EventGroup(self, events):
|
|
for args in events: self.Event(*args)
|
|
return []
|
|
@dbus.service.method(MENU, in_signature='i', out_signature='b')
|
|
def AboutToShow(self, ident): record('about', id=int(ident)); return False
|
|
@dbus.service.method(MENU, in_signature='ai', out_signature='aiai')
|
|
def AboutToShowGroup(self, ids): return ([], [])
|
|
@dbus.service.signal(MENU, signature='a(ia{sv})a(ias)')
|
|
def ItemsPropertiesUpdated(self, updated, removed): pass
|
|
|
|
menu = Menu()
|
|
items = [TrayItem('/StatusNotifierItem', 'glassmxrph-fixture', True), TrayItem('/NoMenu', 'glassmxrph-no-menu', False)]
|
|
|
|
def register():
|
|
try:
|
|
watcher = dbus.Interface(bus.get_object('org.kde.StatusNotifierWatcher', '/StatusNotifierWatcher'), 'org.kde.StatusNotifierWatcher')
|
|
for path in ['/StatusNotifierItem', '/NoMenu']: watcher.RegisterStatusNotifierItem(path)
|
|
record('registered')
|
|
return False
|
|
except dbus.DBusException: return True
|
|
|
|
GLib.timeout_add(100, register)
|
|
GLib.MainLoop().run()
|