20
20
const Main = imports . ui . main ;
21
21
const Settings = imports . ui . settings ;
22
22
const Gettext = imports . gettext ;
23
- const SignalManager = imports . misc . signalManager ;
24
23
const ByteArray = imports . byteArray ;
25
24
const { Atspi, GLib, Gio } = imports . gi ;
26
25
const { ClickAnimationFactory } = require ( "./clickAnimations.js" ) ;
@@ -56,13 +55,10 @@ class MouseClickEffects {
56
55
57
56
Atspi . init ( ) ;
58
57
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 ) ;
62
61
63
- this . _click_animation = ClickAnimationFactory . createForMode ( this . animation_mode ) ;
64
-
65
- this . display_click = ( new Debouncer ( ) ) . debounce ( this . _animate_click . bind ( this ) , 2 ) ;
66
62
this . colored_icon_store = { } ;
67
63
this . enabled = false ;
68
64
}
@@ -150,7 +146,7 @@ class MouseClickEffects {
150
146
{
151
147
key : "deactivate-in-fullscreen" ,
152
148
value : "deactivate_in_fullscreen" ,
153
- cb : this . on_fullscreen_changed ,
149
+ cb : null ,
154
150
} ,
155
151
]
156
152
@@ -169,10 +165,6 @@ class MouseClickEffects {
169
165
this . set_active ( true ) ;
170
166
}
171
167
172
- disable ( ) {
173
- this . destroy ( ) ;
174
- }
175
-
176
168
unset_keybindings ( ) {
177
169
Main . keybindingManager . removeHotKey ( PAUSE_EFFECTS_KEY ) ;
178
170
}
@@ -182,40 +174,29 @@ class MouseClickEffects {
182
174
Main . keybindingManager . addHotKey (
183
175
PAUSE_EFFECTS_KEY ,
184
176
this . pause_effects_binding ,
185
- this . _on_pause_toggled . bind ( this ) ,
177
+ this . on_pause_toggled . bind ( this ) ,
186
178
) ;
187
179
}
188
180
189
- _on_pause_toggled ( ) {
181
+ on_pause_toggled ( ) {
190
182
this . set_active ( ! this . enabled ) ;
191
183
192
184
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 ) ;
204
187
}
205
188
}
206
189
207
190
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 ) ;
211
193
}
212
194
213
195
get_colored_icon ( mode , click_type , color ) {
214
196
const name = `${ mode } _${ click_type } _${ color } ` ;
215
197
216
- if ( this . colored_icon_store [ name ] ) {
198
+ if ( this . colored_icon_store [ name ] )
217
199
return this . colored_icon_store [ name ] ;
218
- }
219
200
220
201
const path = `${ this . data_dir } /icons/${ name } .svg` ;
221
202
@@ -227,39 +208,37 @@ class MouseClickEffects {
227
208
return null ;
228
209
}
229
210
211
+ disable ( ) {
212
+ this . destroy ( ) ;
213
+ }
214
+
230
215
destroy ( ) {
231
216
this . set_active ( false ) ;
232
217
this . unset_keybindings ( ) ;
233
- this . signals . disconnectAllSignals ( ) ;
234
218
this . settings . finalize ( ) ;
235
219
this . colored_icon_store = null ;
236
220
this . display_click = null ;
237
- this . _click_animation = null ;
221
+ this . click_animator = null ;
238
222
}
239
223
240
224
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 ) ;
246
230
}
247
231
248
232
set_active ( enabled ) {
249
233
this . enabled = enabled ;
250
234
251
235
this . listener . deregister ( 'mouse' ) ;
236
+ if ( enabled ) this . listener . register ( 'mouse' ) ;
252
237
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" } !` ) ;
260
239
}
261
240
262
- _create_colored_icon_data ( click_type , color ) {
241
+ create_icon_data ( click_type , color ) {
263
242
if ( this . get_colored_icon ( this . icon_mode , click_type , color ) )
264
243
return true ;
265
244
@@ -274,27 +253,30 @@ class MouseClickEffects {
274
253
const name = `${ this . icon_mode } _${ click_type } _${ color } ` ;
275
254
let dest = Gio . File . new_for_path ( `${ this . data_dir } /icons/${ name } .svg` ) ;
276
255
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 ) ;
280
257
281
258
let [ r_success , tag ] = dest . replace_contents ( contents , null , false , Gio . FileCreateFlags . REPLACE_DESTINATION , null ) ;
282
259
return r_success ;
283
260
}
284
261
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
+
287
268
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 } )` )
294
276
}
295
277
}
296
278
297
- _click_event ( event ) {
279
+ on_mouse_click ( event ) {
298
280
switch ( event . type ) {
299
281
case 'mouse:button:1p' :
300
282
if ( this . left_click_effect_enabled )
0 commit comments