SettingsManager and StateManager working impls
This commit is contained in:
parent
029a17d969
commit
7f8793ce53
|
|
@ -2,7 +2,7 @@
|
||||||
"uuid": "breezydesktop@org.xronlinux",
|
"uuid": "breezydesktop@org.xronlinux",
|
||||||
"name": "Breezy GNOME XR Desktop",
|
"name": "Breezy GNOME XR Desktop",
|
||||||
"description": "XR virtual desktop for GNOME.",
|
"description": "XR virtual desktop for GNOME.",
|
||||||
"settings-schema": "org.gnome.shell.extensions.breezy-desktop",
|
"settings-schema": "com.xronlinux.BreezyDesktop",
|
||||||
"shell-version": [
|
"shell-version": [
|
||||||
"45", "46"
|
"45", "46"
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<schemalist gettext-domain="breezydesktop@org.xronlinux">
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<schema id="org.gnome.shell.extensions.breezy-desktop" path="/org/gnome/shell/extensions/breezy-desktop/">
|
<schemalist gettext-domain="breezydesktop">
|
||||||
|
<schema id="com.xronlinux.BreezyDesktop" path="/com/xronlinux/BreezyDesktop/">
|
||||||
<key name="effect-enable" type="b">
|
<key name="effect-enable" type="b">
|
||||||
<default>
|
<default>
|
||||||
true
|
true
|
||||||
|
|
@ -54,5 +55,5 @@
|
||||||
End distance when using the "toggle display distance" shortcut.
|
End distance when using the "toggle display distance" shortcut.
|
||||||
</description>
|
</description>
|
||||||
</key>
|
</key>
|
||||||
</schema>
|
</schema>
|
||||||
</schemalist>
|
</schemalist>
|
||||||
Binary file not shown.
|
|
@ -0,0 +1 @@
|
||||||
|
3.11.9
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
from gi.repository import Gio
|
||||||
|
|
||||||
|
class SettingsManager:
|
||||||
|
_instance = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_instance():
|
||||||
|
if not SettingsManager._instance:
|
||||||
|
SettingsManager._instance = SettingsManager()
|
||||||
|
|
||||||
|
return SettingsManager._instance
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.settings = Gio.Settings.new_with_path("com.xronlinux.BreezyDesktop", "/com/xronlinux/BreezyDesktop/")
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
import threading
|
||||||
|
from gi.repository import GObject
|
||||||
|
from .XRDriverIPC import XRDriverIPC
|
||||||
|
|
||||||
|
class Logger:
|
||||||
|
def info(self, message):
|
||||||
|
print(message)
|
||||||
|
|
||||||
|
def error(self, message):
|
||||||
|
print(message)
|
||||||
|
|
||||||
|
class StateManager(GObject.GObject):
|
||||||
|
__gsignals__ = {
|
||||||
|
'device_update': (GObject.SIGNAL_RUN_FIRST, None, (str,))
|
||||||
|
}
|
||||||
|
|
||||||
|
_instance = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_instance():
|
||||||
|
if not StateManager._instance:
|
||||||
|
StateManager._instance = StateManager()
|
||||||
|
|
||||||
|
return StateManager._instance
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def device_name(state):
|
||||||
|
if state.get('connected_device_brand') and state.get('connected_device_model'):
|
||||||
|
return f"{state['connected_device_brand']} {state['connected_device_model']}"
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
GObject.GObject.__init__(self)
|
||||||
|
self.ipc = XRDriverIPC(logger = Logger(), user="wayne", user_home="/home/wayne")
|
||||||
|
self.connected_device_name = None
|
||||||
|
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
self.running = True
|
||||||
|
self._refresh_state()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
def _refresh_state(self):
|
||||||
|
self.state = self.ipc.retrieve_driver_state()
|
||||||
|
new_device_name = StateManager.device_name(self.state)
|
||||||
|
if self.connected_device_name != new_device_name:
|
||||||
|
self.connected_device_name = new_device_name
|
||||||
|
self.emit('device_update', self.connected_device_name)
|
||||||
|
|
||||||
|
if self.running: threading.Timer(1.0, self._refresh_state).start()
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from gi.repository import Adw, Gtk
|
from gi.repository import Adw, Gio, Gtk
|
||||||
|
from .SettingsManager import SettingsManager
|
||||||
|
|
||||||
@Gtk.Template(resource_path='/com/xronlinux/BreezyDesktop/connecteddevice.ui')
|
@Gtk.Template(resource_path='/com/xronlinux/BreezyDesktop/connecteddevice.ui')
|
||||||
class ConnectedDevice(Gtk.Box):
|
class ConnectedDevice(Gtk.Box):
|
||||||
|
|
@ -16,9 +16,10 @@ class ConnectedDevice(Gtk.Box):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Gtk.Box, self).__init__()
|
super(Gtk.Box, self).__init__()
|
||||||
self.init_template()
|
self.init_template()
|
||||||
|
self.settings = SettingsManager.get_instance().settings
|
||||||
|
|
||||||
self.get_settings().bind('display-distance', display_distance_scale, 'value', Gio.SettingsBindFlags.DEFAULT)
|
self.settings.bind('display-distance', self.display_distance_scale, 'value', Gio.SettingsBindFlags.DEFAULT)
|
||||||
self.get_settings().bind('effect-enable', effect_enable_switch, 'active', Gio.SettingsBindFlags.DEFAULT)
|
self.settings.bind('effect-enable', self.effect_enable_switch, 'active', Gio.SettingsBindFlags.DEFAULT)
|
||||||
|
|
||||||
def set_device_name(self, name):
|
def set_device_name(self, name):
|
||||||
self.device_label.set_markup(f"<b>{name}</b>")
|
self.device_label.set_markup(f"<b>{name}</b>")
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@
|
||||||
<object class="AdwActionRow">
|
<object class="AdwActionRow">
|
||||||
<property name="title" translatable="true">Display distance</property>
|
<property name="title" translatable="true">Display distance</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScale" id="display_distance_scale">
|
<object class="GtkScale">
|
||||||
<property name="valign">3</property>
|
<property name="valign">3</property>
|
||||||
<property name="draw-value">true</property>
|
<property name="draw-value">true</property>
|
||||||
<property name="value-pos">0</property>
|
<property name="value-pos">0</property>
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
<property name="width-request">350</property>
|
<property name="width-request">350</property>
|
||||||
<property name="has-origin">false</property>
|
<property name="has-origin">false</property>
|
||||||
<property name="adjustment">
|
<property name="adjustment">
|
||||||
<object class="GtkAdjustment" id="display-distance-slider">
|
<object class="GtkAdjustment" id="display_distance_scale">
|
||||||
<property name="lower">0.2</property>
|
<property name="lower">0.2</property>
|
||||||
<property name="upper">2.5</property>
|
<property name="upper">2.5</property>
|
||||||
<property name="step-increment">0.01</property>
|
<property name="step-increment">0.01</property>
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import gi
|
import gi
|
||||||
import threading
|
|
||||||
|
|
||||||
gi.require_version('Gtk', '4.0')
|
gi.require_version('Gtk', '4.0')
|
||||||
gi.require_version('Adw', '1')
|
gi.require_version('Adw', '1')
|
||||||
|
|
@ -27,16 +26,6 @@ gi.require_version('Gio', '2.0')
|
||||||
|
|
||||||
from gi.repository import Adw, Gtk, Gio
|
from gi.repository import Adw, Gtk, Gio
|
||||||
from .window import BreezydesktopWindow
|
from .window import BreezydesktopWindow
|
||||||
from .nodevice import NoDevice
|
|
||||||
from .connecteddevice import ConnectedDevice
|
|
||||||
from .XRDriverIPC import XRDriverIPC
|
|
||||||
|
|
||||||
class Logger:
|
|
||||||
def info(self, message):
|
|
||||||
print(message)
|
|
||||||
|
|
||||||
def error(self, message):
|
|
||||||
print(message)
|
|
||||||
|
|
||||||
class BreezydesktopApplication(Adw.Application):
|
class BreezydesktopApplication(Adw.Application):
|
||||||
"""The main application singleton class."""
|
"""The main application singleton class."""
|
||||||
|
|
@ -46,8 +35,6 @@ class BreezydesktopApplication(Adw.Application):
|
||||||
flags=Gio.ApplicationFlags.DEFAULT_FLAGS)
|
flags=Gio.ApplicationFlags.DEFAULT_FLAGS)
|
||||||
self.create_action('quit', lambda *_: self.quit(), ['<primary>q'])
|
self.create_action('quit', lambda *_: self.quit(), ['<primary>q'])
|
||||||
self.create_action('about', self.on_about_action)
|
self.create_action('about', self.on_about_action)
|
||||||
self.ipc = XRDriverIPC(logger = Logger(), user="wayne", user_home="/home/wayne")
|
|
||||||
self.settings = Gio.Settings.new_with_path("com.xronlinux.BreezyDesktop", "/com/xronlinux/BreezyDesktop/")
|
|
||||||
|
|
||||||
def do_activate(self):
|
def do_activate(self):
|
||||||
"""Called when the application is activated.
|
"""Called when the application is activated.
|
||||||
|
|
@ -58,15 +45,8 @@ class BreezydesktopApplication(Adw.Application):
|
||||||
win = self.props.active_window
|
win = self.props.active_window
|
||||||
if not win:
|
if not win:
|
||||||
win = BreezydesktopWindow(application=self)
|
win = BreezydesktopWindow(application=self)
|
||||||
win.set_settings(self.settings)
|
|
||||||
win.present()
|
win.present()
|
||||||
|
|
||||||
self._refresh_driver_state()
|
|
||||||
|
|
||||||
def _refresh_driver_state(self):
|
|
||||||
self.props.active_window.set_state(self.ipc.retrieve_driver_state())
|
|
||||||
threading.Timer(1.0, self._refresh_driver_state).start()
|
|
||||||
|
|
||||||
def on_about_action(self, widget, _):
|
def on_about_action(self, widget, _):
|
||||||
"""Callback for the app.about action."""
|
"""Callback for the app.about action."""
|
||||||
about = Gtk.AboutDialog(transient_for=self.props.active_window,
|
about = Gtk.AboutDialog(transient_for=self.props.active_window,
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ breezydesktop_sources = [
|
||||||
'connecteddevice.py',
|
'connecteddevice.py',
|
||||||
'main.py',
|
'main.py',
|
||||||
'nodevice.py',
|
'nodevice.py',
|
||||||
|
'SettingsManager.py',
|
||||||
|
'StateManager.py',
|
||||||
'window.py',
|
'window.py',
|
||||||
'XRDriverIPC.py'
|
'XRDriverIPC.py'
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
from .StateManager import StateManager
|
||||||
|
from .connecteddevice import ConnectedDevice
|
||||||
|
from .nodevice import NoDevice
|
||||||
|
|
||||||
@Gtk.Template(resource_path='/com/xronlinux/BreezyDesktop/window.ui')
|
@Gtk.Template(resource_path='/com/xronlinux/BreezyDesktop/window.ui')
|
||||||
class BreezydesktopWindow(Gtk.ApplicationWindow):
|
class BreezydesktopWindow(Gtk.ApplicationWindow):
|
||||||
|
|
@ -30,14 +33,16 @@ class BreezydesktopWindow(Gtk.ApplicationWindow):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.init_template()
|
self.init_template()
|
||||||
|
|
||||||
def set_settings(self, settings):
|
state_manager = StateManager.get_instance()
|
||||||
self.settings = settings
|
state_manager.connect('device_update', self._handle_device_update)
|
||||||
|
|
||||||
def set_state(self, state):
|
self._handle_device_update(state_manager, StateManager.device_name(state_manager.state))
|
||||||
if state.get('connected_device_brand') and state.get('connected_device_model'):
|
|
||||||
|
def _handle_device_update(self, state_manager, connected_device_name):
|
||||||
|
if connected_device_name:
|
||||||
self.connected_device.set_visible(True)
|
self.connected_device.set_visible(True)
|
||||||
self.no_device.set_visible(False)
|
self.no_device.set_visible(False)
|
||||||
self.connected_device.set_device_name(f"{state['connected_device_brand']} {state['connected_device_model']}")
|
self.connected_device.set_device_name(connected_device_name)
|
||||||
else:
|
else:
|
||||||
self.connected_device.set_visible(False)
|
self.connected_device.set_visible(False)
|
||||||
self.no_device.set_visible(True)
|
self.no_device.set_visible(True)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue