This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
forked from pop-os/cosmic
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextension.js
130 lines (110 loc) · 3.5 KB
/
extension.js
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
128
129
130
const { Gio, GObject} = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const extension = ExtensionUtils.getCurrentExtension();
const Main = imports.ui.main;
let signal_overlay_key = null;
let original_signal_overlay_key = null;
let settings = null;
// Variable to declare the value for the pop-launcher
var OVERVIEW_LAUNCHER = 2;
// Check if Pop shell is installed
function with_pop_shell(callback) {
let pop_shell = Main.extensionManager.lookup("pop-shell@system76.com");
if (pop_shell && pop_shell.stateObj) {
let ext = pop_shell.stateObj.ext;
if (ext) {
return callback(ext);
}
}
}
// Overview functions
function overview_visible(kind) {
if (kind == OVERVIEW_LAUNCHER) {
if (with_pop_shell((ext) => {
return ext.window_search.dialog.visible;
}) === true) {
return true;
}
} else {
if (Main.overview.visibleTarget) {
return true;
}
}
return false;
}
function overview_show(kind) {
if (kind == OVERVIEW_LAUNCHER) {
Main.overview.hide();
with_pop_shell((ext) => {
ext.tiler.exit(ext);
ext.window_search.load_desktop_files();
ext.window_search.open(ext);
});
} else {
Main.overview.show();
}
}
function overview_hide(kind) {
if (kind == OVERVIEW_LAUNCHER) {
with_pop_shell((ext) => {
ext.exit_modes();
});
} else {
Main.overview.hide();
}
}
function overview_toggle(kind) {
if (Main.overview.animationInProgress) {
// prevent accidental re-show
} else if (overview_visible(kind)) {
overview_hide(kind);
} else {
overview_show(kind);
}
}
// Overlay-key
var overlay_key_action = OVERVIEW_LAUNCHER;
function overlay_key() {
overview_toggle(overlay_key_action);
}
function overlay_key_changed(settings) {
if (overview_visible(overlay_key_action)) {
overview_hide(overlay_key_action);
}
overlay_key_action = settings.get_enum("overlay-key-action");
}
function init(metadata) {}
function enable() {
settings = ExtensionUtils.getSettings((extension.metadata["settings-schema"]));
// Load overlay key action and keep it up to date with settings
overlay_key_changed(settings);
settings.connect("changed::overlay-key-action", () => {
overlay_key_changed(settings);
});
// Block original overlay key handler
original_signal_overlay_key = GObject.signal_handler_find(global.display, { signalId: "overlay-key" });
if (original_signal_overlay_key !== null) {
global.display.block_signal_handler(original_signal_overlay_key);
}
// Connect modified overlay key handler
const A11Y_SCHEMA = 'org.gnome.desktop.a11y.keyboard';
const STICKY_KEYS_ENABLE = 'stickykeys-enable';
let _a11ySettings = new Gio.Settings({ schema_id: A11Y_SCHEMA });
signal_overlay_key = global.display.connect("overlay-key", () => {
if (!_a11ySettings.get_boolean(STICKY_KEYS_ENABLE))
overlay_key();
});
}
function disable() {
// Disconnect modified overlay key handler
if (signal_overlay_key !== null) {
global.display.disconnect(signal_overlay_key);
signal_overlay_key = null;
}
// Unblock original overlay key handler
if (original_signal_overlay_key !== null) {
global.display.unblock_signal_handler(original_signal_overlay_key);
original_signal_overlay_key = null;
}
settings = null;
}