From 0cba1b8075471dcb47511f8f793160729fc9ce30 Mon Sep 17 00:00:00 2001 From: wheaney <42350981+wheaney@users.noreply.github.com> Date: Thu, 25 Apr 2024 22:37:14 -0700 Subject: [PATCH] Add basic zoom shortcut --- .../IMUAdjust.frag | 2 +- .../breezydesktop@org.xronlinux/extension.js | 14 ++++++-- .../schemas/gschemas.compiled | Bin 340 -> 428 bytes ...hell.extensions.breezy-desktop.gschema.xml | 11 +++++- gnome/breezydesktop@org.xronlinux/xrEffect.js | 32 +++++++++++++++++- 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/gnome/breezydesktop@org.xronlinux/IMUAdjust.frag b/gnome/breezydesktop@org.xronlinux/IMUAdjust.frag index 0f9925e..fd2bf5c 100644 --- a/gnome/breezydesktop@org.xronlinux/IMUAdjust.frag +++ b/gnome/breezydesktop@org.xronlinux/IMUAdjust.frag @@ -152,7 +152,7 @@ void PS_IMU_Transform(vec4 pos, vec2 texcoord, out vec4 color) { // divide all values by x to scale the magnitude so x is exactly 1, and multiply by the final display distance // so the vector is pointing at a coordinate on the screen - float display_distance = (sbs_enabled ? display_north_offset : 1.0) - rotated_lens_vector.x; + float display_distance = display_north_offset - rotated_lens_vector.x; res *= display_distance / res.x; res += rotated_lens_vector; diff --git a/gnome/breezydesktop@org.xronlinux/extension.js b/gnome/breezydesktop@org.xronlinux/extension.js index f47593e..33ca3fd 100644 --- a/gnome/breezydesktop@org.xronlinux/extension.js +++ b/gnome/breezydesktop@org.xronlinux/extension.js @@ -134,13 +134,21 @@ export default class BreezyDesktopExtension extends Extension { this._overlay.add_effect_with_name('xr-desktop', this._xr_effect); Meta.disable_unredirect_for_display(global.display); - const action = Main.wm.addKeybinding( + Main.wm.addKeybinding( 'shortcut-recenter', this.getSettings(), Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP, this._recenter_display.bind(this) - ) + ); + + Main.wm.addKeybinding( + 'shortcut-change-distance', + this.getSettings(), + Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, + Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP, + this._xr_effect._change_distance.bind(this._xr_effect) + ); } catch (e) { console.error('Error enabling XR effect', e); this._effect_disable(); @@ -160,6 +168,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'); Meta.enable_unredirect_for_display(global.display); if (this._overlay) { diff --git a/gnome/breezydesktop@org.xronlinux/schemas/gschemas.compiled b/gnome/breezydesktop@org.xronlinux/schemas/gschemas.compiled index 28d35ad7712a59787c83b080dd8eb810c3fcd216..dd50967b2ca36b12110a97af95dbae5a98440a1a 100644 GIT binary patch delta 221 zcmcb@w1#;?2onS2#4xjZ76u4l0#eLC4C43Psks5-GcYnRNHCN!NC0V5AU;rA$Ne7& zKx|f^xC4;R1F=OJ7(n76HUonXLjjPk0ODhJui1di0kH*v>L&o{H9%aPkzZ7jTw0== zoS~nXm!7Jdl384mn3tStppjUtsaKF#k}+9| Z(Ml5JPPiFGsmZB%C8 - + space']]]> @@ -9,5 +9,14 @@ Shortcut to re-center the virtual display. + + + Return']]]> + + Trigger change to display distance + + Shortcut to change the display distance. + + \ No newline at end of file diff --git a/gnome/breezydesktop@org.xronlinux/xrEffect.js b/gnome/breezydesktop@org.xronlinux/xrEffect.js index b23ae5f..f238c31 100644 --- a/gnome/breezydesktop@org.xronlinux/xrEffect.js +++ b/gnome/breezydesktop@org.xronlinux/xrEffect.js @@ -1,9 +1,11 @@ +import Clutter from 'gi://Clutter'; import Cogl from 'gi://Cogl'; import GLib from 'gi://GLib'; import GObject from 'gi://GObject'; import Shell from 'gi://Shell'; import Globals from './globals.js'; + import { dataViewEnd, dataViewUint8, @@ -23,6 +25,8 @@ import { getShaderSource } from "./shader.js"; import { toSec } from "./time.js"; export const IPC_FILE_PATH = "/dev/shm/breezy_desktop_imu"; +const display_distance_nearest = 0.85; +const display_distance_furthest = 1.05; // the driver should be using the same data layout version const DATA_LAYOUT_VERSION = 2; @@ -157,7 +161,6 @@ function setIntermittentUniformVariables() { // TOOD - drive from settings setSingleFloat(this, 'display_zoom', 1.0); - setSingleFloat(this, 'display_north_offset', 1.0); setSingleFloat(this, 'sbs_content', 0.0); } setSingleFloat(this, 'enabled', enabled ? 1.0 : 0.0); @@ -186,6 +189,31 @@ export const XREffect = GObject.registerClass({ super(params); 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_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_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_near = true; + } + + this._distance_ease_timeline.start(); } vfunc_build_pipeline() { @@ -219,10 +247,12 @@ export const XREffect = GObject.registerClass({ this.setIntermittentUniformVariables(); return GLib.SOURCE_CONTINUE; }).bind(this)); + this._initialized = true; } if (this._dataView.byteLength === DATA_VIEW_LENGTH) { + 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) {