Repository navigation
Expand file tree
/
Copy pathextension.js
More file actions
82 lines (66 loc) · 2.31 KB
/
Copy pathextension.js
File metadata and controls
82 lines (66 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import GLib from 'gi://GLib'
import Clutter from 'gi://Clutter'
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js'
export default class HideCursor extends Extension {
TICK_TIMEOUT = 1
enable() {
this._settings = this.getSettings()
this.HIDE_TIMEOUT = this._settings.get_int('timeout') * 1000
this._settingsConnectionID = this._settings.connect('changed::timeout', () =>
this.HIDE_TIMEOUT = this._settings.get_int('timeout') * 1000)
this._seat = global.stage.context.get_backend().get_default_seat()
this._timer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, this.TICK_TIMEOUT, this.tick)
this._tracker = global.backend.get_cursor_tracker()
this._positionChangedId = this._tracker.connect('position-invalidated', this.move)
this._lastMove = Date.now()
}
disable() {
if (this._positionChangedId) {
this._tracker.disconnect(this._positionChangedId)
this._positionChangedId = null
}
if (this._settingsConnectionID) {
this._settings.disconnect(this._settingsConnectionID)
this._settingsConnectionID = null
}
if (this._tracker) {
if (this._hasVisibilityInhibited && !this._tracker.get_pointer_visible())
this._tracker.uninhibit_cursor_visibility()
this._tracker = null
this._hasVisibilityInhibited = null
}
if (this._timer) {
GLib.Source.remove(this._timer)
this._timer = null
}
if (this._hasFocusInhibited) {
this._seat.uninhibit_unfocus()
this._hasFocusInhibited = null
}
this._seat = null
this._lastMove = null
this._settings = null
this.HIDE_TIMEOUT = null
}
tick = () => {
if (Date.now() - this._lastMove > this.HIDE_TIMEOUT && this._tracker.get_pointer_visible()) {
if (!this._hasFocusInhibited) {
this._seat.inhibit_unfocus()
this._hasFocusInhibited = true
}
this._tracker.inhibit_cursor_visibility()
this._hasVisibilityInhibited = true
}
return GLib.SOURCE_CONTINUE
}
move = () => {
this._lastMove = Date.now()
if (!this._tracker.get_pointer_visible())
this._tracker.uninhibit_cursor_visibility()
if (this._hasFocusInhibited) {
this._seat.uninhibit_unfocus()
this._hasFocusInhibited = false
}
this._hasVisibilityInhibited = false
}
}