gnome-shell alt+tab 扩展
详情见《小hack一下gnome-shell的alt+tab》and《GNOME Shell的“Alt+Tab”革新》
听从TualatriX建议写成了个扩展
这可是我第一个gnome-shell扩展哦
刚开始看js 也刚耍上gnome-shell
用的也是最笨的方法………………
使用方法:
在~/.local/share/gnome-shell/extensions/
建立alt_tab_key_press@imdiot.wordpress.com
文件夹
在alt_tab_key_press@imdiot.wordpress.com
文件夹中建立两文件
extension.js:
1 const St = imports.gi.St;
2 const Mainloop = imports.mainloop;
3 const Shell = imports.gi.Shell;
4 const Clutter = imports.gi.Clutter;
5 const Meta = imports.gi.Meta;
6 const Lang = imports.lang;
7
8 const Main = imports.ui.main;
9 const AltTab = imports.ui.altTab;
10
11 function startAppSwitcher (shellwm, binding, window, backwards) {
12 if (shellwm._workspaceSwitcherPopup != null)
13 shellwm._workspaceSwitcherPopup.actor.hide();
14
15 let tabPopup = new AltTab.AltTabPopup();
16 tabPopup._keyPressEvent = function(actor, event) {
17 let keysym = event.get_key_symbol();
18 let event_state = Shell.get_event_state(event);
19 let backwards = event_state & Clutter.ModifierType.SHIFT_MASK;
20 let action = global.screen.get_display().get_keybinding_action(event.get_key_code(), event_state);
21
22 this._disableHover();
23
24 if (action == Meta.KeyBindingAction.SWITCH_GROUP)
25 this._select(this._currentApp, backwards ? this._previousWindow() : this._nextWindow());
26 else if (keysym == Clutter.Escape)
27 this.destroy();
28 else if (this._thumbnailsFocused) {
29 if (action == Meta.KeyBindingAction.SWITCH_WINDOWS)
30 if (backwards) {
31 if (this._currentWindow == 0 || this._currentWindow == -1)
32 this._select(this._previousApp());
33 else
34 this._select(this._currentApp, this._previousWindow());
35 } else {
36 if (this._currentWindow == this._appIcons[this._currentApp].cachedWindows.length - 1)
37 this._select(this._nextApp());
38 else
39 this._select(this._currentApp, this._nextWindow());
40 }
41 else if (keysym == Clutter.Left || keysym == Clutter.a)
42 this._select(this._currentApp, this._previousWindow());
43 else if (keysym == Clutter.Right || keysym == Clutter.d || keysym == 96)
44 this._select(this._currentApp, this._nextWindow());
45 else if (keysym == Clutter.Up || keysym == Clutter.w)
46 this._select(this._currentApp, null, true);
47 } else {
48 if (action == Meta.KeyBindingAction.SWITCH_WINDOWS)
49 this._select(backwards ? this._previousApp() : this._nextApp());
50 else if (keysym == Clutter.Left || keysym == Clutter.a)
51 this._select(this._previousApp());
52 else if (keysym == Clutter.Right || keysym == Clutter.d)
53 this._select(this._nextApp());
54 else if (keysym == Clutter.Down || keysym == Clutter.s || keysym == 96)
55 this._select(this._currentApp, 0);
56 }
57
58 return true;
59 }
60
61 if (!tabPopup.show(backwards, binding == 'switch_group'))
62 tabPopup.destroy();
63 }
64
65 function main() {
66 Main.wm.setKeybindingHandler('switch_windows', Lang.bind(Main.wm, startAppSwitcher));
67 }
metadata.json:
1 {
2 "shell-version": ["3.0.0.2"],
3 "uuid": "alt_tab_key_press@imdiot.wordpress.com",
4 "name": "alt_tab_key_press",
5 "description": "change alt+tab key press -> begin alt+tab you can alt+w,s,a,d,` control",
6 "url": "imdiot.wordpress.com"
7 }