This commit is contained in:
wheaney 2024-05-01 22:07:16 -07:00
parent 1942a2d5af
commit db727f60c1
6 changed files with 49 additions and 50 deletions

View File

@ -24,6 +24,8 @@ export default class BreezyDesktopExtension extends Extension {
constructor(metadata, uuid) { constructor(metadata, uuid) {
super(metadata, uuid); super(metadata, uuid);
this.settings = this.getSettings();
// Set/destroyed by enable/disable // Set/destroyed by enable/disable
this._cursor_manager = null; this._cursor_manager = null;
this._monitor_manager = null; this._monitor_manager = null;
@ -129,43 +131,39 @@ export default class BreezyDesktopExtension extends Extension {
this._xr_effect = new XREffect({ this._xr_effect = new XREffect({
target_monitor: this._target_monitor, target_monitor: this._target_monitor,
target_framerate: this._refresh_rate ?? 60 target_framerate: this._refresh_rate ?? 60,
display_distance: this.settings.get_double('display-distance')
}); });
this.settings.bind('display-distance', this._xr_effect, 'display-distance', Gio.SettingsBindFlags.GET)
this._overlay.add_effect_with_name('xr-desktop', this._xr_effect); this._overlay.add_effect_with_name('xr-desktop', this._xr_effect);
Meta.disable_unredirect_for_display(global.display); Meta.disable_unredirect_for_display(global.display);
Main.wm.addKeybinding( Main.wm.addKeybinding(
'shortcut-recenter', 'recenter-display-shortcut',
this.getSettings(), this.settings,
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP, Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP,
this._recenter_display.bind(this) this._recenter_display.bind(this)
); );
const initialKeybinding = settings.get_strv('shortcut-change-distance')[0];
// Add the initial keybinding (if it's not empty) Main.wm.addKeybinding(
if (initialKeybinding) { 'toggle-display-distance-shortcut',
Main.wm.addKeybinding( this.settings,
initialKeybinding, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
this.getSettings(), Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP,
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, this._xr_effect._change_distance.bind(this._xr_effect)
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP, );
this._xr_effect._change_distance.bind(this._xr_effect)
);
}
// Connect to the 'changed' signal for the keybinding property // Connect to the 'changed' signal for the keybinding property
settings.connect('changed::shortcut-change-distance', () => { this.settings.connect('changed::toggle-display-distance-shortcut', () => {
// Remove the old keybinding // Remove the old keybinding
Main.wm.removeKeybinding('shortcut-change-distance'); Main.wm.removeKeybinding('toggle-display-distance-shortcut');
// Get the updated keybinding value from settings
const newKeybinding = settings.get_strv('shortcut-change-distance')[0];
// Add the updated keybinding // Add the updated keybinding
Main.wm.addKeybinding( Main.wm.addKeybinding(
newKeybinding, 'toggle-display-distance-shortcut',
this.getSettings(), this.settings,
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP, Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP,
this._xr_effect._change_distance.bind(this._xr_effect) this._xr_effect._change_distance.bind(this._xr_effect)
@ -190,8 +188,8 @@ export default class BreezyDesktopExtension extends Extension {
if (this._running_poller_id) GLib.source_remove(this._running_poller_id); if (this._running_poller_id) GLib.source_remove(this._running_poller_id);
Main.wm.removeKeybinding('shortcut-recenter'); Main.wm.removeKeybinding('recenter-display-shortcut');
Main.wm.removeKeybinding('shortcut-change-distance'); Main.wm.removeKeybinding('toggle-display-distance-shortcut');
Meta.enable_unredirect_for_display(global.display); Meta.enable_unredirect_for_display(global.display);
if (this._overlay) { if (this._overlay) {

View File

@ -182,7 +182,16 @@ export const XREffect = GObject.registerClass({
'Target Framerate', 'Target Framerate',
'Target framerate for this effect', 'Target framerate for this effect',
GObject.ParamFlags.READWRITE, 60, 240, 60 GObject.ParamFlags.READWRITE, 60, 240, 60
) ),
'display-distance': GObject.ParamSpec.double(
'display-distance',
'Display Distance',
'How far away the display appears',
GObject.ParamFlags.READWRITE,
0.2,
2.5,
1.05
),
} }
}, class XREffect extends Shell.GLSLEffect { }, class XREffect extends Shell.GLSLEffect {
constructor(params = {}) { constructor(params = {}) {
@ -190,25 +199,23 @@ export const XREffect = GObject.registerClass({
this._frametime = Math.floor(1000 / this.target_framerate); this._frametime = Math.floor(1000 / this.target_framerate);
// slightly zoomed out by default
this._display_distance = display_distance_furthest;
this._display_distance_near = false; this._display_distance_near = false;
this._distance_ease_timeline = null; this._distance_ease_timeline = null;
} }
_change_distance() { _change_distance() {
if (this._distance_ease_timeline?.is_playing()) this._distance_ease_timeline.stop(); if (this._distance_ease_timeline?.is_playing()) this._distance_ease_timeline.stop();
this._distance_ease_start = this._display_distance; this._distance_ease_start = this.display_distance;
this._distance_ease_timeline = Clutter.Timeline.new_for_actor(this.get_actor(), 250); this._distance_ease_timeline = Clutter.Timeline.new_for_actor(this.get_actor(), 250);
if (this._display_distance_near) { if (this._display_distance_near) {
this._distance_ease_timeline.connect('new-frame', () => { this._distance_ease_timeline.connect('new-frame', () => {
this._display_distance = this._distance_ease_start + this._distance_ease_timeline.get_progress() * (display_distance_furthest - this._distance_ease_start); this.display_distance = this._distance_ease_start + this._distance_ease_timeline.get_progress() * (display_distance_furthest - this._distance_ease_start);
}); });
this._display_distance_near = false; this._display_distance_near = false;
} else { } else {
this._distance_ease_timeline.connect('new-frame', () => { this._distance_ease_timeline.connect('new-frame', () => {
this._display_distance = this._distance_ease_start - this._distance_ease_timeline.get_progress() * (this._distance_ease_start - display_distance_nearest); this.display_distance = this._distance_ease_start - this._distance_ease_timeline.get_progress() * (this._distance_ease_start - display_distance_nearest);
}); });
this._display_distance_near = true; this._display_distance_near = true;
} }
@ -252,7 +259,7 @@ export const XREffect = GObject.registerClass({
} }
if (this._dataView.byteLength === DATA_VIEW_LENGTH) { if (this._dataView.byteLength === DATA_VIEW_LENGTH) {
setSingleFloat(this, 'display_north_offset', this._display_distance); setSingleFloat(this, 'display_north_offset', this.display_distance);
setSingleFloat(this, 'look_ahead_ms', lookAheadMS(this._dataView)); setSingleFloat(this, 'look_ahead_ms', lookAheadMS(this._dataView));
setUniformMatrix(this, 'imu_quat_data', 4, this._dataView, IMU_QUAT_DATA); setUniformMatrix(this, 'imu_quat_data', 4, this._dataView, IMU_QUAT_DATA);
} else if (this._dataView.byteLength !== 0) { } else if (this._dataView.byteLength !== 0) {

View File

@ -21,7 +21,6 @@ class MainWindow(Gtk.ApplicationWindow):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.set_title("Breezy GNOME") self.set_title("Breezy GNOME")
# grab ui from breezy-desktop.ui file and render it
builder = Gtk.Builder() builder = Gtk.Builder()
builder.add_from_file("./breezy-desktop.ui") builder.add_from_file("./breezy-desktop.ui")
self.set_child(builder.get_object("main")) self.set_child(builder.get_object("main"))
@ -34,14 +33,8 @@ class MainWindow(Gtk.ApplicationWindow):
builder.get_object('reassign-toggle-display-distance-shortcut-button'), builder.get_object('reassign-toggle-display-distance-shortcut-button'),
]) ])
def on_button_clicked(self, widget): display_distance_slider = builder.get_object('display-distance-slider')
print("Hello World") self.settings.bind('display-distance', display_distance_slider, 'value', Gio.SettingsBindFlags.DEFAULT)
self.settings.set_strv('shortcut-change-distance', ['<Control><Super>Return'])
print(self.settings.get_strv('shortcut-change-distance'))
config = self.ipc.retrieve_config()
print(config)
class MyApp(Adw.Application): class MyApp(Adw.Application):
def __init__(self, **kwargs): def __init__(self, **kwargs):

View File

@ -13,8 +13,6 @@ class ShortcutDialog:
eventController = self._builder.get_object('event-controller') eventController = self._builder.get_object('event-controller')
eventController.connect('key-pressed', self._on_key_pressed) eventController.connect('key-pressed', self._on_key_pressed)
return self.widget
def _on_key_pressed(self, widget, keyval, keycode, state): def _on_key_pressed(self, widget, keyval, keycode, state):
mask = state & Gtk.accelerator_get_default_mod_mask() mask = state & Gtk.accelerator_get_default_mod_mask()
mask &= ~Gdk.ModifierType.LOCK_MASK mask &= ~Gdk.ModifierType.LOCK_MASK
@ -26,12 +24,12 @@ class ShortcutDialog:
if keyval == Gdk.KEY_BackSpace: if keyval == Gdk.KEY_BackSpace:
self.settings.set_strv(self.shortcut, []) self.settings.set_strv(self.shortcut, [])
self.widget.close() self.widget.close()
elif is_binding_valid(mask, keycode, keyval) and is_accel_valid(mask, keyval): elif is_binding_valid(mask, keycode, keyval) and is_accel_valid(state, keyval):
binding = Gtk.accelerator_name_with_keycode( binding = Gtk.accelerator_name_with_keycode(
None, None,
keyval, keyval,
keycode, keycode,
mask state
) )
self.settings.set_strv(self.shortcut, [binding]) self.settings.set_strv(self.shortcut, [binding])
self.widget.close() self.widget.close()
@ -39,7 +37,7 @@ class ShortcutDialog:
return Gdk.EVENT_STOP return Gdk.EVENT_STOP
def is_binding_valid(mask, keycode, keyval): def is_binding_valid(mask, keycode, keyval):
if mask == 0 or mask == Gdk.SHIFT_MASK and keycode != 0: if mask == 0 or mask == Gdk.ModifierType.SHIFT_MASK and keycode != 0:
if keyval >= Gdk.KEY_a and keyval <= Gdk.KEY_z or \ if keyval >= Gdk.KEY_a and keyval <= Gdk.KEY_z or \
keyval >= Gdk.KEY_A and keyval <= Gdk.KEY_Z or \ keyval >= Gdk.KEY_A and keyval <= Gdk.KEY_Z or \
keyval >= Gdk.KEY_0 and keyval <= Gdk.KEY_9 or \ keyval >= Gdk.KEY_0 and keyval <= Gdk.KEY_9 or \
@ -77,18 +75,19 @@ def is_accel_valid(mask, keyval):
def bind_shortcut_settings(window, settings, widgets): def bind_shortcut_settings(window, settings, widgets):
for widget in widgets: for widget in widgets:
settings.connect('changed::' + widget.get_name(), lambda: reload_shortcut_widget(settings, widget)) settings.connect('changed::' + widget.get_name(), lambda *args: reload_shortcut_widget(settings, widget))
widget.connect('clicked', lambda: on_assign_shortcut(window, settings, widget)) widget.connect('clicked', lambda *args: on_assign_shortcut(window, settings, widget))
reload_shortcut_widgets(settings, widgets) reload_shortcut_widgets(settings, widgets)
def on_assign_shortcut(window, settings, widget): def on_assign_shortcut(window, settings, widget):
dialog = ShortcutDialog(settings, widget.get_name()) dialog = ShortcutDialog(settings, widget.get_name())
dialog.set_transient_for(window) dialog.widget.set_transient_for(window)
dialog.present() dialog.widget.present()
def reload_shortcut_widget(settings, widget): def reload_shortcut_widget(settings, widget):
shortcut = settings.get_strv(widget.get_name()) shortcut = settings.get_strv(widget.get_name())
widget.label = shortcut[0] if len(shortcut) > 0 else 'Disabled' widget.set_label(shortcut[0] if len(shortcut) > 0 else 'Disabled')
def reload_shortcut_widgets(settings, widgets): def reload_shortcut_widgets(settings, widgets):
for widget in widgets: for widget in widgets:

View File

@ -36,7 +36,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"> <object class="GtkAdjustment" id="display-distance-slider">
<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>
@ -67,6 +67,7 @@
<style> <style>
<class name="row-button"/> <class name="row-button"/>
</style> </style>
<property name="name">recenter-display-shortcut</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="label">Test</property> <property name="label">Test</property>
</object> </object>
@ -82,6 +83,7 @@
<style> <style>
<class name="row-button"/> <class name="row-button"/>
</style> </style>
<property name="name">toggle-display-distance-shortcut</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="label">Test</property> <property name="label">Test</property>
</object> </object>