-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.js
More file actions
127 lines (103 loc) · 3.24 KB
/
extension.js
File metadata and controls
127 lines (103 loc) · 3.24 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const St = imports.gi.St
const Main = imports.ui.main
const Tweener = imports.ui.tweener
const Shell = imports.gi.Shell
const Meta = imports.gi.Meta
const Gio = imports.gi.Gio
const ExtensionUtils = imports.misc.extensionUtils
// Import the schema.js (Used for loading settings schemas)
const Self = imports.misc.extensionUtils.getCurrentExtension();
const Schema = Self.imports.schema;
function NotificationPanel(){
this.constructor()
}
NotificationPanel.prototype = {
Name : 'NotificationPanel',
constructor: function(){
this.panel = null
},
show: function(text="Triggered!"){
if (!this.panel) {
this.panel = new St.Label({ style_class: 'notification-label'})
Main.uiGroup.add_actor(this.panel)
}
this.panel.opacity = 255
this.panel.text = text
let monitor = Main.layoutManager.primaryMonitor
let x = monitor.x + Math.floor(monitor.width / 2 - this.panel.width / 2)
let y = monitor.y + Math.floor(monitor.height / 2 - this.panel.height / 2)
this.panel.set_position(x, y)
Tweener.addTween(this.panel, {
opacity: 0,
time: 0.5,
transition: 'easeOutQuad',
onComplete: this.hide.bind(this)
})
},
hide: function(){
Main.uiGroup.remove_actor(this.panel)
this.panel = null
},
}
function App(){
this.constructor()
}
App.prototype = {
Name : 'App',
constructor: function(){
this.notificationPanel = new NotificationPanel()
this.settings = Schema.buildGsettingsSchema()
this.settings.connect('changed::show-notification', ()=>{
this.disable()
this.enable()
})
},
_addKeybinding: function(name, handler) {
if (Main.wm.addKeybinding) {
var ModeType = Shell.hasOwnProperty('ActionMode') ? Shell.ActionMode : Shell.KeyBindingMode
Main.wm.addKeybinding(name, this.settings, Meta.KeyBindingFlags.NONE, ModeType.NORMAL | ModeType.OVERVIEW, handler)
} else {
global.display.add_keybinding(name, this.settings, Meta.KeyBindingFlags.NONE, handler)
}
},
_removeKeybinding: function(name) {
if (Main.wm.removeKeybinding) {
Main.wm.removeKeybinding(name)
}
else {
global.display.remove_keybinding(name)
}
},
enable: function() {
// Will be called by Gnome Shell. It`s a part of extension API
let isNotificationVisible = this.settings.get_boolean('show-notification')
this._addKeybinding('switch-to-first-layout', () => {
if (isNotificationVisible)
this.notificationPanel.show('First Layout')
Meta.get_backend().lock_layout_group(0)
})
this._addKeybinding('switch-to-second-layout', () => {
if (isNotificationVisible)
this.notificationPanel.show('Second Layout')
Meta.get_backend().lock_layout_group(1)
})
},
disable: function() {
// Will be called by Gnome Shell. It`s a part of extension API
this._removeKeybinding('switch-to-first-layout')
this._removeKeybinding('switch-to-second-layout')
},
}
let app = null
function init() {
// Will be called by Gnome Shell. It`s a part of extension API
app = new App()
}
function enable() {
// Will be called by Gnome Shell. It`s a part of extension API
app.enable()
}
function disable() {
// Will be called by Gnome Shell. It`s a part of extension API
app.disable()
}