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

@ -23,6 +23,8 @@ const SUPPORTED_MONITOR_PRODUCTS = [
export default class BreezyDesktopExtension extends Extension {
constructor(metadata, uuid) {
super(metadata, uuid);
this.settings = this.getSettings();
// Set/destroyed by enable/disable
this._cursor_manager = null;
@ -129,43 +131,39 @@ export default class BreezyDesktopExtension extends Extension {
this._xr_effect = new XREffect({
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);
Meta.disable_unredirect_for_display(global.display);
Main.wm.addKeybinding(
'shortcut-recenter',
this.getSettings(),
'recenter-display-shortcut',
this.settings,
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP,
this._recenter_display.bind(this)
);
const initialKeybinding = settings.get_strv('shortcut-change-distance')[0];
// Add the initial keybinding (if it's not empty)
if (initialKeybinding) {
Main.wm.addKeybinding(
initialKeybinding,
this.getSettings(),
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP,
this._xr_effect._change_distance.bind(this._xr_effect)
);
}
Main.wm.addKeybinding(
'toggle-display-distance-shortcut',
this.settings,
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
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
settings.connect('changed::shortcut-change-distance', () => {
this.settings.connect('changed::toggle-display-distance-shortcut', () => {
// Remove the old keybinding
Main.wm.removeKeybinding('shortcut-change-distance');
// Get the updated keybinding value from settings
const newKeybinding = settings.get_strv('shortcut-change-distance')[0];
Main.wm.removeKeybinding('toggle-display-distance-shortcut');
// Add the updated keybinding
Main.wm.addKeybinding(
newKeybinding,
this.getSettings(),
'toggle-display-distance-shortcut',
this.settings,
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP,
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);
Main.wm.removeKeybinding('shortcut-recenter');
Main.wm.removeKeybinding('shortcut-change-distance');
Main.wm.removeKeybinding('recenter-display-shortcut');
Main.wm.removeKeybinding('toggle-display-distance-shortcut');
Meta.enable_unredirect_for_display(global.display);
if (this._overlay) {

View File

@ -182,7 +182,16 @@ export const XREffect = GObject.registerClass({
'Target Framerate',
'Target framerate for this effect',
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 {
constructor(params = {}) {
@ -190,25 +199,23 @@ export const XREffect = GObject.registerClass({
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._distance_ease_timeline = null;
}
_change_distance() {
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);
if (this._display_distance_near) {
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;
} else {
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;
}
@ -252,7 +259,7 @@ export const XREffect = GObject.registerClass({
}
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));
setUniformMatrix(this, 'imu_quat_data', 4, this._dataView, IMU_QUAT_DATA);
} else if (this._dataView.byteLength !== 0) {

View File

@ -21,7 +21,6 @@ class MainWindow(Gtk.ApplicationWindow):
super().__init__(*args, **kwargs)
self.set_title("Breezy GNOME")
# grab ui from breezy-desktop.ui file and render it
builder = Gtk.Builder()
builder.add_from_file("./breezy-desktop.ui")
self.set_child(builder.get_object("main"))
@ -33,15 +32,9 @@ class MainWindow(Gtk.ApplicationWindow):
builder.get_object('reassign-recenter-display-shortcut-button'),
builder.get_object('reassign-toggle-display-distance-shortcut-button'),
])
def on_button_clicked(self, widget):
print("Hello World")
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)
display_distance_slider = builder.get_object('display-distance-slider')
self.settings.bind('display-distance', display_distance_slider, 'value', Gio.SettingsBindFlags.DEFAULT)
class MyApp(Adw.Application):
def __init__(self, **kwargs):

View File

@ -13,8 +13,6 @@ class ShortcutDialog:
eventController = self._builder.get_object('event-controller')
eventController.connect('key-pressed', self._on_key_pressed)
return self.widget
def _on_key_pressed(self, widget, keyval, keycode, state):
mask = state & Gtk.accelerator_get_default_mod_mask()
mask &= ~Gdk.ModifierType.LOCK_MASK
@ -26,12 +24,12 @@ class ShortcutDialog:
if keyval == Gdk.KEY_BackSpace:
self.settings.set_strv(self.shortcut, [])
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(
None,
keyval,
keycode,
mask
state
)
self.settings.set_strv(self.shortcut, [binding])
self.widget.close()
@ -39,7 +37,7 @@ class ShortcutDialog:
return Gdk.EVENT_STOP
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 \
keyval >= Gdk.KEY_A and keyval <= Gdk.KEY_Z 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):
for widget in widgets:
settings.connect('changed::' + widget.get_name(), lambda: reload_shortcut_widget(settings, widget))
widget.connect('clicked', lambda: on_assign_shortcut(window, settings, widget))
settings.connect('changed::' + widget.get_name(), lambda *args: reload_shortcut_widget(settings, widget))
widget.connect('clicked', lambda *args: on_assign_shortcut(window, settings, widget))
reload_shortcut_widgets(settings, widgets)
def on_assign_shortcut(window, settings, widget):
dialog = ShortcutDialog(settings, widget.get_name())
dialog.set_transient_for(window)
dialog.present()
dialog.widget.set_transient_for(window)
dialog.widget.present()
def reload_shortcut_widget(settings, widget):
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):
for widget in widgets:

View File

@ -36,7 +36,7 @@
<property name="width-request">350</property>
<property name="has-origin">false</property>
<property name="adjustment">
<object class="GtkAdjustment">
<object class="GtkAdjustment" id="display-distance-slider">
<property name="lower">0.2</property>
<property name="upper">2.5</property>
<property name="step-increment">0.01</property>
@ -67,6 +67,7 @@
<style>
<class name="row-button"/>
</style>
<property name="name">recenter-display-shortcut</property>
<property name="valign">center</property>
<property name="label">Test</property>
</object>
@ -82,6 +83,7 @@
<style>
<class name="row-button"/>
</style>
<property name="name">toggle-display-distance-shortcut</property>
<property name="valign">center</property>
<property name="label">Test</property>
</object>