Skip to content

Commit ed030d1

Browse files
authored
mouse-click-effects@anaximeno: Version 0.4.1 (#745)
* Don't display click effect when the focused window is fullscreen instead of disabling on fullscreen. This is better for a multi-monitor setup. * Minor refactoring
1 parent a96ce58 commit ed030d1

File tree

4 files changed

+47
-65
lines changed

4 files changed

+47
-65
lines changed

mouse-click-effects@anaximeno/files/mouse-click-effects@anaximeno/5.4/clickAnimations.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const Main = imports.ui.main;
2121
const Clutter = imports.gi.Clutter;
2222
const St = imports.gi.St;
2323

24-
class ClickAnimationMode {
24+
var ClickAnimationMode = class ClickAnimationMode {
2525
constructor(mode) {
2626
this.mode = mode;
2727
}
@@ -36,7 +36,7 @@ class ClickAnimationMode {
3636
}
3737
}
3838

39-
class ExpansionClickAnimationMode extends ClickAnimationMode {
39+
var ExpansionClickAnimationMode = class ExpansionClickAnimationMode extends ClickAnimationMode {
4040
animateClick(icon, options) {
4141
const actor_scale = options.icon_size > 20 ? 1.15 : 3;
4242
const [mouse_x, mouse_y, mask] = global.get_pointer();
@@ -73,7 +73,7 @@ class ExpansionClickAnimationMode extends ClickAnimationMode {
7373
}
7474
}
7575

76-
class RetractionClickAnimationMode extends ClickAnimationMode {
76+
var RetractionClickAnimationMode = class RetractionClickAnimationMode extends ClickAnimationMode {
7777
animateClick(icon, options) {
7878
const [mouse_x, mouse_y, mask] = global.get_pointer();
7979

@@ -107,7 +107,7 @@ class RetractionClickAnimationMode extends ClickAnimationMode {
107107
}
108108
}
109109

110-
class BounceBackClickAnimationMode extends ClickAnimationMode {
110+
var BounceBackClickAnimationMode = class BounceBackClickAnimationMode extends ClickAnimationMode {
111111
animateClick(icon, options) {
112112
const [mouse_x, mouse_y, mask] = global.get_pointer();
113113

@@ -154,7 +154,7 @@ class BounceBackClickAnimationMode extends ClickAnimationMode {
154154
}
155155
}
156156

157-
class BlinkClickAnimationMode extends ClickAnimationMode {
157+
var BlinkClickAnimationMode = class BlinkClickAnimationMode extends ClickAnimationMode {
158158
animateClick(icon, options = {}) {
159159
const [mouse_x, mouse_y, mask] = global.get_pointer();
160160

@@ -184,7 +184,7 @@ class BlinkClickAnimationMode extends ClickAnimationMode {
184184
}
185185
}
186186

187-
class ClickAnimationFactory {
187+
var ClickAnimationFactory = class ClickAnimationFactory {
188188
/**
189189
* Returns an click animation mode depending on the given name
190190
* @param {String} mode Click Animation mode name to create

mouse-click-effects@anaximeno/files/mouse-click-effects@anaximeno/5.4/extension.js

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
const Main = imports.ui.main;
2121
const Settings = imports.ui.settings;
2222
const Gettext = imports.gettext;
23-
const SignalManager = imports.misc.signalManager;
2423
const ByteArray = imports.byteArray;
2524
const { Atspi, GLib, Gio } = imports.gi;
2625
const { ClickAnimationFactory } = require("./clickAnimations.js");
@@ -56,13 +55,10 @@ class MouseClickEffects {
5655

5756
Atspi.init();
5857

59-
this.listener = Atspi.EventListener.new(this._click_event.bind(this));
60-
this.signals = new SignalManager.SignalManager(null);
61-
this.signals.connect(global.screen, 'in-fullscreen-changed', this.on_fullscreen_changed, this);
58+
this.listener = Atspi.EventListener.new(this.on_mouse_click.bind(this));
59+
this.click_animator = ClickAnimationFactory.createForMode(this.animation_mode);
60+
this.display_click = (new Debouncer()).debounce(this.animate_click.bind(this), 2);
6261

63-
this._click_animation = ClickAnimationFactory.createForMode(this.animation_mode);
64-
65-
this.display_click = (new Debouncer()).debounce(this._animate_click.bind(this), 2);
6662
this.colored_icon_store = {};
6763
this.enabled = false;
6864
}
@@ -150,7 +146,7 @@ class MouseClickEffects {
150146
{
151147
key: "deactivate-in-fullscreen",
152148
value: "deactivate_in_fullscreen",
153-
cb: this.on_fullscreen_changed,
149+
cb: null,
154150
},
155151
]
156152

@@ -169,10 +165,6 @@ class MouseClickEffects {
169165
this.set_active(true);
170166
}
171167

172-
disable() {
173-
this.destroy();
174-
}
175-
176168
unset_keybindings() {
177169
Main.keybindingManager.removeHotKey(PAUSE_EFFECTS_KEY);
178170
}
@@ -182,40 +174,29 @@ class MouseClickEffects {
182174
Main.keybindingManager.addHotKey(
183175
PAUSE_EFFECTS_KEY,
184176
this.pause_effects_binding,
185-
this._on_pause_toggled.bind(this),
177+
this.on_pause_toggled.bind(this),
186178
);
187179
}
188180

189-
_on_pause_toggled() {
181+
on_pause_toggled() {
190182
this.set_active(!this.enabled);
191183

192184
if (this.pause_animation_effects_enabled) {
193-
this.display_click(ClickType.PAUSE, this.enabled ? PAUSE_OFF_COLOR : PAUSE_ON_COLOR);
194-
}
195-
}
196-
197-
on_fullscreen_changed() {
198-
if (this.deactivate_in_fullscreen) {
199-
const monitor = global.screen.get_current_monitor();
200-
const monitorIsInFullscreen = global.screen.get_monitor_in_fullscreen(monitor);
201-
this.set_active(!monitorIsInFullscreen);
202-
} else {
203-
this.set_active(this.enabled);
185+
let color = this.enabled ? PAUSE_OFF_COLOR : PAUSE_ON_COLOR;
186+
this.display_click(ClickType.PAUSE, color);
204187
}
205188
}
206189

207190
update_animation_mode() {
208-
if (!this._click_animation || this._click_animation.mode != this.animation_mode) {
209-
this._click_animation = ClickAnimationFactory.createForMode(this.animation_mode);
210-
}
191+
if (!this.click_animator || this.click_animator.mode != this.animation_mode)
192+
this.click_animator = ClickAnimationFactory.createForMode(this.animation_mode);
211193
}
212194

213195
get_colored_icon(mode, click_type, color) {
214196
const name = `${mode}_${click_type}_${color}`;
215197

216-
if (this.colored_icon_store[name]) {
198+
if (this.colored_icon_store[name])
217199
return this.colored_icon_store[name];
218-
}
219200

220201
const path = `${this.data_dir}/icons/${name}.svg`;
221202

@@ -227,39 +208,37 @@ class MouseClickEffects {
227208
return null;
228209
}
229210

211+
disable() {
212+
this.destroy();
213+
}
214+
230215
destroy() {
231216
this.set_active(false);
232217
this.unset_keybindings();
233-
this.signals.disconnectAllSignals();
234218
this.settings.finalize();
235219
this.colored_icon_store = null;
236220
this.display_click = null;
237-
this._click_animation = null;
221+
this.click_animator = null;
238222
}
239223

240224
update_colored_icons() {
241-
this._create_colored_icon_data(ClickType.PAUSE, PAUSE_ON_COLOR);
242-
this._create_colored_icon_data(ClickType.PAUSE, PAUSE_OFF_COLOR);
243-
this._create_colored_icon_data(ClickType.LEFT, this.left_click_color);
244-
this._create_colored_icon_data(ClickType.MIDDLE, this.middle_click_color);
245-
this._create_colored_icon_data(ClickType.RIGHT, this.right_click_color);
225+
this.create_icon_data(ClickType.PAUSE, PAUSE_ON_COLOR);
226+
this.create_icon_data(ClickType.PAUSE, PAUSE_OFF_COLOR);
227+
this.create_icon_data(ClickType.LEFT, this.left_click_color);
228+
this.create_icon_data(ClickType.MIDDLE, this.middle_click_color);
229+
this.create_icon_data(ClickType.RIGHT, this.right_click_color);
246230
}
247231

248232
set_active(enabled) {
249233
this.enabled = enabled;
250234

251235
this.listener.deregister('mouse');
236+
if (enabled) this.listener.register('mouse');
252237

253-
if (enabled) {
254-
this.listener.register('mouse');
255-
}
256-
257-
global.log(UUID,
258-
`Click effects ${enabled ? "activated" : "deactivated"}!`,
259-
);
238+
global.log(UUID, `Click effects ${enabled ? "activated" : "deactivated"}!`);
260239
}
261240

262-
_create_colored_icon_data(click_type, color) {
241+
create_icon_data(click_type, color) {
263242
if (this.get_colored_icon(this.icon_mode, click_type, color))
264243
return true;
265244

@@ -274,27 +253,30 @@ class MouseClickEffects {
274253
const name = `${this.icon_mode}_${click_type}_${color}`;
275254
let dest = Gio.File.new_for_path(`${this.data_dir}/icons/${name}.svg`);
276255

277-
if (!dest.query_exists(null)) {
278-
dest.create(Gio.FileCreateFlags.NONE, null);
279-
}
256+
if (!dest.query_exists(null)) dest.create(Gio.FileCreateFlags.NONE, null);
280257

281258
let [r_success, tag] = dest.replace_contents(contents, null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, null);
282259
return r_success;
283260
}
284261

285-
_animate_click(click_type, color) {
286-
let icon;
262+
animate_click(click_type, color) {
263+
if (global.display.focus_window.is_fullscreen() && this.deactivate_in_fullscreen) {
264+
// global.log(UUID, "Click effects not displayed due to being disabled for fullscreen focused windows");
265+
return;
266+
}
267+
287268
this.update_animation_mode();
288-
if (icon = this.get_colored_icon(this.icon_mode, click_type, color)) {
289-
this._click_animation.animateClick(icon, {
290-
opacity: this.general_opacity,
291-
icon_size: this.size,
292-
timeout: this.animation_time,
293-
});
269+
let icon = this.get_colored_icon(this.icon_mode, click_type, color);
270+
271+
if (icon) {
272+
let options = { opacity: this.general_opacity, icon_size: this.size, timeout: this.animation_time };
273+
this.click_animator.animateClick(icon, options);
274+
} else {
275+
global.logError(`${UUID}: Couldn't get Click Icon (mode = ${this.icon_mode}, type = ${click_type}, color = ${color})`)
294276
}
295277
}
296278

297-
_click_event(event) {
279+
on_mouse_click(event) {
298280
switch (event.type) {
299281
case 'mouse:button:1p':
300282
if (this.left_click_effect_enabled)

mouse-click-effects@anaximeno/files/mouse-click-effects@anaximeno/5.4/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
const Util = imports.misc.util;
2121

22-
class Debouncer {
22+
var Debouncer = class Debouncer {
2323
_sourceId;
2424

2525
constructor() {

mouse-click-effects@anaximeno/files/mouse-click-effects@anaximeno/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"uuid": "mouse-click-effects@anaximeno",
33
"name": "Mouse Click Effects",
4-
"version": "0.4.0",
4+
"version": "0.4.1",
55
"description": "Display mouse click effects on Cinnamon.",
66
"url": "https://github.com/anaximeno/mouse-click-effects",
77
"website": "https://github.com/anaximeno/mouse-click-effects",

0 commit comments

Comments
 (0)