summaryrefslogtreecommitdiff
path: root/toggle-workspace@jodersky.github.com/extension.js
blob: 5309f491c972523fd10fa64afc89730b1681e1cb (plain) (blame)
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
const Main = imports.ui.main;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
const Utils = imports.misc.extensionUtils.getCurrentExtension().imports.util; 

let primary, saved;
 
function _toggleWorkspace() {
  let current = global.screen.get_active_workspace().index();
  if (current == primary) {
    global.screen.get_workspace_by_index(saved).activate(global.get_current_time());
  } else {
    global.screen.get_workspace_by_index(primary).activate(global.get_current_time());
    saved = current;
  }
}

function init() {
  primary = 0;
  saved = 1;
}

function enable() {
  Main.wm.addKeybinding(
    'toggle-primary-workspace',
    Utils.getSettings(),
    Meta.KeyBindingFlags.NONE,
    Shell.KeyBindingMode.NORMAL | Shell.KeyBindingMode.MESSAGE_TRAY,
    function() {
      _toggleWorkspace();
    }
  );
}

function disable() {
  Main.wm.removeKeybinding('toggle-primary-workspace');
}