Skip to content

Commit

Permalink
Add support for deactivate in fullscrenn to the pointer movement tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
anaximeno committed Sep 24, 2024
1 parent 23a4cdd commit 15f42e8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@ class MouseClickEffects {
if (this.mouse_movement_tracker_enabled) {
const icon = this.get_click_icon(this.icon_mode, ClickType.MOUSE_MOV, this.mouse_movement_color);
this.mouse_movement_tracker = new MouseMovementTracker(
icon, this.size, this.general_opacity,
this.mouse_movement_tracker_persist_on_stopped_enabled);
this, icon, this.size, this.general_opacity,
this.mouse_movement_tracker_persist_on_stopped_enabled,
);
this.mouse_movement_tracker.start();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
const { St } = imports.gi;
const Main = imports.ui.main;
const SignalManager = imports.misc.signalManager;

const PointerWatcher = require("./pointerWatcher.js").getPointerWatcher();
const { POINTER_WATCH_MS, UUID, MOUSE_PARADE_DELAY_MS } = require("./constants.js");
const { POINTER_WATCH_MS, MOUSE_PARADE_DELAY_MS } = require("./constants.js");
const { Debouncer, logInfo } = require("./helpers.js");


var MouseMovementTracker = class MouseMovementTracker {
constructor(icon, size, opacity, persist_on_stopped) {
constructor(extension, icon, size, opacity, persist_on_stopped) {
this.extension = extension;
this.size = size;
this.opacity = opacity;
this.icon = icon;
this.persist_on_stopped = persist_on_stopped;
this.icon_actor = null;
this.listener = null;
this.signals = new SignalManager.SignalManager(null);
}

start() {
get is_fullscreen_block() {
return this.extension.deactivate_in_fullscreen &&
global.display.focus_window &&
global.display.focus_window.is_fullscreen();
}

on_fullscreen_changed() {
const [x, y, _] = global.get_pointer();
this.move_to(x, y);
}

start() {
this.icon_actor = new St.Icon({
reactive: false,
can_focus: false,
Expand All @@ -27,31 +40,34 @@ var MouseMovementTracker = class MouseMovementTracker {
gicon: this.icon,
});
this.icon_actor.set_style("pointer-events: none;");
this.move_to(x, y);

Main.uiGroup.add_child(this.icon_actor);

this.listener = PointerWatcher.addWatch(POINTER_WATCH_MS, this.move_to.bind(this));
this.signals.connect(global.screen, 'in-fullscreen-changed', this.on_fullscreen_changed, this);

const [x, y, _] = global.get_pointer();
this.move_to(x, y);

logInfo("mouse movement tracker started");
}

update(params) {
if (params.size) {
if (params.size)
this.size = params.size;
}
if (params.opacity) {
if (params.opacity)
this.opacity = params.opacity;
}
if (params.icon) {
if (params.icon)
this.icon = params.icon;
}
if (params.persist_on_stopped === true || params.persist_on_stopped === false) {
if (params.persist_on_stopped === true || params.persist_on_stopped === false)
this.persist_on_stopped = params.persist_on_stopped;
}

this.finalize();
this.start();
}

finalize() {
this.signals.disconnectAllSignals();
Main.uiGroup.remove_child(this.icon_actor);
this.listener.remove();
this.icon_actor.destroy();
Expand All @@ -60,12 +76,17 @@ var MouseMovementTracker = class MouseMovementTracker {

move_to(x, y) {
if (this.icon_actor) {
this.icon_actor.show();
this.icon_actor.set_position(
x - (this.size * global.ui_scale / 2),
y - (this.size * global.ui_scale / 2));
if (!this.persist_on_stopped)
this.handle_parade();
if (this.is_fullscreen_block) {
this.icon_actor.hide();
logInfo("movement tracker hidden due to deactivation in fullscreen");
} else {
this.icon_actor.set_position(
x - (this.size * global.ui_scale / 2),
y - (this.size * global.ui_scale / 2));
this.icon_actor.show();
if (!this.persist_on_stopped)
this.handle_parade();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"uuid": "mouse-click-effects@anaximeno",
"name": "Mouse Click Effects",
"version": "1.0.2",
"version": "1.0.3",
"description": "Display mouse click effects on Cinnamon.",
"url": "https://github.com/anaximeno/mouse-click-effects",
"website": "https://github.com/anaximeno/mouse-click-effects",
Expand Down

0 comments on commit 15f42e8

Please sign in to comment.