forked from poehlerj/no-title-bar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
160 lines (129 loc) · 4.29 KB
/
utils.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
const Mainloop = imports.mainloop;
const Gio = imports.gi.Gio;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Prefs = Me.imports.prefs;
const appSys = Shell.AppSystem.get_default();
const MAXIMIZED = Meta.MaximizeFlags.BOTH;
const VERTICAL = Meta.MaximizeFlags.VERTICAL;
// global.screen removed in GNOME 3.30
var ws_manager = global.screen ? global.screen : global.workspace_manager;
var display = global.screen ? global.screen : global.display;
let settings = null;
let debug_mode = undefined;
let _debug_mode_listener_id;
function enable() {
settings = Convenience.getSettings();
_debug_mode_listener_id = settings.connect(
'changed::debug-mode',
function() {
debug_mode = settings.get_boolean('debug-mode');
log("Debug mode set to " + debug_mode);
}
);
return settings;
}
function disable() {
settings.disconnect(_debug_mode_listener_id);
_debug_mode_listener_id = null;
settings.run_dispose();
settings = null;
}
function log_debug(message) {
if (debug_mode === undefined) {
debug_mode = settings.get_boolean('debug-mode');
}
if (debug_mode) {
log(message);
}
}
function log(message) {
global.log("[no-title-bar] " + message);
}
// Get the window to display the title bar for (buttons etc) or to drag from the top panel
function getWindow(forceSnapped) {
if (typeof forceSnapped === 'undefined') {
forceSnapped = false;
}
let primaryMonitor = display.get_primary_monitor()
let onlyPrimaryMonitor = settings.get_boolean('only-main-monitor');
let includeSnapped = settings.get_boolean('buttons-for-snapped') || forceSnapped;
let allWindows = settings.get_boolean('buttons-for-all-win');
// get all window in stacking order.
let windows = global.display.sort_windows_by_stacking(
ws_manager.get_active_workspace().list_windows().filter(function (w) {
return w.get_window_type() !== Meta.WindowType.DESKTOP &&
(!onlyPrimaryMonitor || w.get_monitor() === primaryMonitor);
})
);
let i = windows.length;
while (i--) {
let window = windows[i];
if (window.minimized || window.is_hidden()) {
continue;
}
let max_state = window.get_maximized();
if (max_state === MAXIMIZED) {
return window;
}
if (max_state === VERTICAL && includeSnapped) {
return window;
}
if (allWindows) {
return window;
}
}
return null;
}
function onSizeChange(callback) {
let callbackIDs = [];
let wm = global.window_manager;
// Obvious size change callback.
callbackIDs.push(wm.connect('size-change', callback));
// Needed for window drag to top panel (this doesn't trigger maximize).
callbackIDs.push(wm.connect('hide-tile-preview', callback));
// NB: 'destroy' needs a delay for .list_windows() report correctly
callbackIDs.push(wm.connect('destroy', function () {
Mainloop.idle_add(callback);
}));
return callbackIDs;
}
function getAppList() {
let apps = Gio.AppInfo.get_all().filter(function(appInfo) {
try {
let id = appInfo.get_name(); // catch invalid file encodings
} catch(e) {
return false;
}
return appInfo.should_show();
});
return apps;
}
const IgnoreList = {
DISABLED: 0,
WHITELIST: 1,
BLACKLIST: 2,
}
function getAppInfoOf(window) {
return getAppList()
.find(function (appInfo) {
const app = appSys.lookup_app(appInfo.get_id());
return app.get_windows().includes(window);
});
}
function isWindowIgnored(settings, win) {
const listType = settings.get_enum('ignore-list-type');
if (listType === IgnoreList.DISABLED) return false;
let ignoreList = settings.get_string('ignore-list');
ignoreList = Prefs.splitEntries(ignoreList);
const appInfo = getAppInfoOf(win);
if (!appInfo) return false;
const isAppInList = ignoreList.includes(appInfo.get_name());
if (listType === IgnoreList.BLACKLIST) {
return isAppInList;
} else /* IgnoreList.WHITELIST */ {
return !isAppInList;
}
}