Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mouse-click-effects@anaximeno: Version 1.0.2 #754

Merged
merged 2 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
'use strict';

const DEBUG = false;

const UUID = "mouse-click-effects@anaximeno";

const PAUSE_EFFECTS_KEY = `${UUID}-bind-pause-effects`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Gettext = imports.gettext;
const ByteArray = imports.byteArray;
const { Atspi, GLib, Gio } = imports.gi;
const { ClickAnimationFactory, ClickAnimationModes } = require("./clickAnimations.js");
const { Debouncer } = require("./helpers.js");
const { Debouncer, logInfo, logError } = require("./helpers.js");
const { UUID, PAUSE_EFFECTS_KEY, CLICK_DEBOUNCE_MS, POINTER_WATCH_MS, IDLE_TIME } = require("./constants.js");
const { IdleMonitor } = require("./idleMonitor.js");
const { MouseMovementTracker } = require("./mouseMovementTracker.js");
Expand Down Expand Up @@ -76,7 +76,7 @@ class MouseClickEffects {
let data_dir = `${GLib.get_user_cache_dir()}/${uuid}`;

if (GLib.mkdir_with_parents(`${data_dir}/icons`, 0o777) < 0) {
global.logError(`Failed to create cache dir at ${data_dir}`);
logError(`Failed to create cache dir at ${data_dir}`);
throw new Error(`Failed to create cache dir at ${data_dir}`);
}

Expand Down Expand Up @@ -255,14 +255,14 @@ class MouseClickEffects {
this._enable_on_drag_end = true;
this.set_active(false);
}
}).bind(this)
}).bind(this);

dragDrop = ((event) => {
if (this._enable_on_drag_end) {
this._enable_on_drag_end = false;
this.set_active(true);
}
}).bind(this)
}).bind(this);

enable() {
this.update_colored_icons();
Expand Down Expand Up @@ -372,9 +372,9 @@ class MouseClickEffects {
// this.idleMonitor.start();
// }

global.log(UUID, "activated");
logInfo("activated");
} else {
global.log(UUID, "deactivated");
logInfo("deactivated");
}
}

Expand All @@ -397,17 +397,18 @@ class MouseClickEffects {

let [r_success, tag] = dest.replace_contents(contents, null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, null);

if (r_success) global.log(UUID, `created colored icon cache for ${name}`);
if (r_success) logInfo(`created colored icon cache for ${name}`);

return r_success;
}

display_click = (new Debouncer()).debounce((...args) => {
if (this.deactivate_in_fullscreen && global.display.focus_window && global.display.focus_window.is_fullscreen()) {
// global.log(UUID, "Click effects not displayed due to being disabled for fullscreen focused windows");
logInfo("Click effects not displayed due to being disabled for fullscreen focused windows");
return;
}
this.animate_click(...args);
}, CLICK_DEBOUNCE_MS)
}, CLICK_DEBOUNCE_MS);

animate_click(click_type, color) {
this.update_animation_mode();
Expand All @@ -432,7 +433,7 @@ class MouseClickEffects {
timeout: this.animation_time,
});
} else {
global.logError(`${UUID}: Couldn't get Click Icon (mode = ${this.icon_mode}, type = ${click_type}, color = ${color})`)
logError(`Couldn't get Click Icon (mode = ${this.icon_mode}, type = ${click_type}, color = ${color})`)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

const Util = imports.misc.util;

const { UUID, DEBUG } = require('./constants.js');


var Debouncer = class Debouncer {
_sourceId;

Expand All @@ -43,3 +46,12 @@ var Debouncer = class Debouncer {
}).bind(this);
}
}


function logInfo(...args) {
if (DEBUG) global.log(`${UUID}: ${args.join(' ')}`);
}

function logError(...args) {
global.logError(`${UUID}: ${args.join(' ')}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ const Main = imports.ui.main;

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


var MouseMovementTracker = class MouseMovementTracker {
constructor(icon, size, opacity, persist_on_stopped) {
this.size = size;
this.opacity = opacity;
this.icon = icon;
this.persist_on_stopped = persist_on_stopped;
this.icon_actor = null;
this.listener = null;
this.persist_on_stopped = persist_on_stopped;
this.handle_parade = (new Debouncer()).debounce(
this.on_parade.bind(this),
MOUSE_PARADE_DELAY_MS,
);
}

start() {
Expand All @@ -34,7 +30,7 @@ var MouseMovementTracker = class MouseMovementTracker {
this.move_to(x, y);
Main.uiGroup.add_child(this.icon_actor);
this.listener = PointerWatcher.addWatch(POINTER_WATCH_MS, this.move_to.bind(this));
global.log(UUID, "mouse movement tracker started");
logInfo("mouse movement tracker started");
}

update(params) {
Expand All @@ -59,19 +55,21 @@ var MouseMovementTracker = class MouseMovementTracker {
Main.uiGroup.remove_child(this.icon_actor);
this.listener.remove();
this.icon_actor.destroy();
global.log(UUID, "mouse movement tracker finalized");
logInfo("mouse movement tracker finalized");
}

move_to(x, y) {
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.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();
}
}

on_parade() {
this.icon_actor.hide();
}
handle_parade = (new Debouncer()).debounce(() => {
if (this.icon_actor) this.icon_actor.hide();
}, MOUSE_PARADE_DELAY_MS);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"style-section": {
"type": "section",
"title": "Colors",
"title": "Style",
anaximeno marked this conversation as resolved.
Show resolved Hide resolved
"keys": [
"icon-mode",
"size",
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.1",
"version": "1.0.2",
"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