-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
150 lines (117 loc) · 4.34 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const WorkspaceSwitcherPopup = imports.ui.workspaceSwitcherPopup;
const Lang = imports.lang;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
const Main = imports.ui.main;
const WorkspaceManager = global.workspace_manager;
const St = imports.gi.St;
const Mainloop = imports.mainloop;
// gsettings set org.gnome.shell.app-switcher current-workspace-only true
// gsettings set org.gnome.shell.keybindings toggle-overview "['<Super>s']"
let dateTimeActor = Main.panel.statusArea.dateMenu.actor;
const KeyManager = new Lang.Class({
Name: 'MyKeyManager',
_init: function() {
this.grabbers = new Map()
global.display.connect(
'accelerator-activated',
Lang.bind(this, function(display, action, deviceId, timestamp){
// log('Accelerator Activated: [display={}, action={}, deviceId={}, timestamp={}]', display, action, deviceId, timestamp)
this._onAccelerator(action);
}))
},
listenFor: function(accelerator, callback) {
let action = global.display.grab_accelerator(accelerator, 0)
if(action != Meta.KeyBindingAction.NONE) {
// log('Grabbed accelerator [action={}]', action)
let name = Meta.external_binding_name_for_action(action);
// log('Received binding name for action [name={}, action={}]',name, action)
// log('Requesting WM to allow binding [name={}]', name)
Main.wm.allowKeybinding(name, Shell.ActionMode.ALL);
this.grabbers.set(action, {
name: name,
accelerator: accelerator,
callback: callback,
action: action
});
}
},
_onAccelerator: function(action) {
let grabber = this.grabbers.get(action);
if(grabber) {
this.grabbers.get(action).callback();
}
}
});
const label = new St.Label({ style_class: 'workspace-flag', text: "1" });
var sources_id;
function disableWorskpacePopupWindow() {
WorkspaceSwitcherPopup.ANIMATION_TIME = 0;
WorkspaceSwitcherPopup.DISPLAY_TIMEOUT = 0;
WorkspaceSwitcherPopup.WorkspaceSwitcherPopup.prototype._show = function() { return false };
let width = Math.floor(global.screen_width / 2 - label.get_width() / 2);
// let height = Math.floor(label.height * 1.877);
// due to hide top bar extension
// height = 0;
label.set_position(width, -1);
hideLabel();
global.stage.add_actor(label);
}
function hideLabel() {
label.hide();
sources_id = undefined;
dateTimeActor.show();
}
function showLabel(currentWrkIndex) {
dateTimeActor.hide();
label.set_text(''+(currentWrkIndex+1));
label.show();
sources_id = Mainloop.timeout_add(700, hideLabel);
}
function clearTimedHide() {
if(sources_id) {
Mainloop.source_remove(sources_id);
}
}
function switchNextWorkspace() {
clearTimedHide();
let activeIdx = WorkspaceManager.get_active_workspace().index();
// just flip between 0 & 1
activeIdx ^= 1;
WorkspaceManager.get_workspace_by_index(activeIdx).activate(global.get_current_time())
showLabel(activeIdx);
}
function moveActiveWindowNextWorkspace() {
clearTimedHide();
let activeIdx = WorkspaceManager.get_active_workspace().index();
// just flip between 0 & 1
activeIdx ^= 1;
let focusedWin = global.display.get_focus_window();
focusedWin.change_workspace_by_index(activeIdx, false);
focusedWin.activate(global.get_current_time());
// WorkspaceManager.get_workspace_by_index(activeIdx).activate(global.get_current_time());
showLabel(activeIdx);
}
function closeAppsCurrentWorkspace() {
WorkspaceManager.get_active_workspace();
// let pid = current_window.get_pid();
// try {
// let argv = ['kill', '' + pid];
// GLib.spawn_sync(null, argv, null, GLib.SpawnFlags.SEARCH_PATH, null);
// } catch (e) {
// logError(e, 'Failed to kill ' + current_window.title);
// }
switchNextWorkspace();
}
function init() {
disableWorskpacePopupWindow();
let keyMngr = new KeyManager();
keyMngr.listenFor("Control_R", switchNextWorkspace);
keyMngr.listenFor("<ctrl>Control_R", moveActiveWindowNextWorkspace);
// TODO:
//keyMngr.listenFor("<ctrl><alt><shift>Control_R", closeAppsCurrentWorkspace);
}
function enable() {
}
function disable() {
}