Better disable support, still not perfect

This commit is contained in:
wheaney 2024-04-03 01:07:37 -04:00
parent f5e08e4ba6
commit 0779ffe7d2
2 changed files with 51 additions and 33 deletions

View File

@ -114,12 +114,12 @@ export class CursorManager {
} }
_cursorTrackerSetPointerVisibleReplacement(visible) { _cursorTrackerSetPointerVisibleReplacement(visible) {
this._cursorWantedVisible = visible;
if (visible) { if (visible) {
this._startCloningMouse(); this._startCloningMouse();
} else { } else {
this._stopCloningMouse(); this._stopCloningMouse();
} }
this._cursorWantedVisible = visible;
} }
_startCloningMouse() { _startCloningMouse() {
@ -143,9 +143,6 @@ export class CursorManager {
} }
_stopCloningShowMouse() { _stopCloningShowMouse() {
if (!this._isMouseClonable()) {
return;
}
this._stopCloningMouse(); this._stopCloningMouse();
this._cursorTrackerSetPointerVisibleBound(this._cursorWantedVisible); this._cursorTrackerSetPointerVisibleBound(this._cursorWantedVisible);
@ -159,9 +156,6 @@ export class CursorManager {
} }
_stopCloningMouse() { _stopCloningMouse() {
if (!this._isMouseClonable()) {
return;
}
if (this._cursorWatch != null) { if (this._cursorWatch != null) {
this._cursorWatch.remove(); this._cursorWatch.remove();
this._cursorWatch = null; this._cursorWatch = null;

View File

@ -208,36 +208,53 @@ export default class BreezyDesktopExtension extends Extension {
// Set/destroyed by enable/disable // Set/destroyed by enable/disable
this._cursorManager = null; this._cursorManager = null;
this._shared_mem_file = null;
this._xr_effect = null;
} }
enable() { enable() {
this._cursorManager = new CursorManager(global.stage); if (!this._check_driver_running()) {
this._running_poller_id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, (() => {
if (this._check_driver_running()) {
this._effect_enable();
return GLib.SOURCE_REMOVE;
} else {
return GLib.SOURCE_CONTINUE;
}
}).bind(this));
}
this._effect_enable();
}
_check_driver_running() {
if (!this._shared_mem_file) this._shared_mem_file = Gio.file_new_for_path("/dev/shm/imu_data");
return this._shared_mem_file.query_exists(null);
}
_effect_enable() {
this._running_poller_id = undefined;
if (!this._cursorManager) this._cursorManager = new CursorManager(global.stage);
this._cursorManager.enable(); this._cursorManager.enable();
const extensionPath = this._extensionPath; if (!this._xr_effect) {
var XREffect = GObject.registerClass({}, class XREffect extends Shell.GLSLEffect { const extensionPath = this._extensionPath;
vfunc_build_pipeline() { const shared_mem_file = this._shared_mem_file;
const code = getShaderSource(`${extensionPath}/IMUAdjust.frag`); var XREffect = GObject.registerClass({}, class XREffect extends Shell.GLSLEffect {
const main = 'PS_IMU_Transform(vec4(0, 0, 0, 0), cogl_tex_coord_in[0].xy, cogl_color_out);'; vfunc_build_pipeline() {
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, code, main, false); const code = getShaderSource(`${extensionPath}/IMUAdjust.frag`);
const main = 'PS_IMU_Transform(vec4(0, 0, 0, 0), cogl_tex_coord_in[0].xy, cogl_color_out);';
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, code, main, false);
this._frametime = 10; // 100 FPS this._frametime = 10; // 100 FPS
}
vfunc_paint_target(node, paintContext) {
if (!this._initialized) {
this._shared_mem_file = Gio.file_new_for_path("/dev/shm/imu_data");
} }
if (this._shared_mem_file.query_exists(null)) { vfunc_paint_target(node, paintContext) {
const data = this._shared_mem_file.load_contents(null); const data = shared_mem_file.load_contents(null);
if (data[0]) { if (data[0]) {
const buffer = new Uint8Array(data[1]).buffer; const buffer = new Uint8Array(data[1]).buffer;
this._dataView = new DataView(buffer); this._dataView = new DataView(buffer);
if (!this._initialized) { if (!this._initialized) {
this.set_uniform_float(this.get_uniform_location('uDesktopTexture'), 1, [8]); this.set_uniform_float(this.get_uniform_location('uDesktopTexture'), 1, [0]);
// iterate over shaderUniformLocations keys and set the uniform locations
for (let key in shaderUniformLocations) { for (let key in shaderUniformLocations) {
shaderUniformLocations[key] = this.get_uniform_location(key); shaderUniformLocations[key] = this.get_uniform_location(key);
} }
@ -265,22 +282,29 @@ export default class BreezyDesktopExtension extends Extension {
} }
if (this._repaint_needed) { if (this._repaint_needed) {
super.vfunc_paint_target(node, paintContext); super.vfunc_paint_target(node, paintContext);
this._repaint_needed = false; this._repaint_needed = false;
} }
} }
} }
} });
});
this._xr_effect = new XREffect();
}
global.stage.add_effect_with_name('xr-desktop', this._xr_effect);
Meta.disable_unredirect_for_display(global.display); Meta.disable_unredirect_for_display(global.display);
global.stage.add_effect_with_name('xr-desktop', new XREffect());
} }
disable() { disable() {
global.stage.remove_effect_by_name('xr-desktop'); if (this._running_poller_id) {
this._cursorManager.disable(); GLib.source_remove(this._running_poller_id);
this._cursorManager = null; } else {
Meta.enable_unredirect_for_display(global.display);
global.stage.remove_effect_by_name('xr-desktop');
this._cursorManager.disable();
this._cursorManager = null;
}
} }
} }