diff --git a/extension.js b/extension.js index c9152d5..33a897c 100644 --- a/extension.js +++ b/extension.js @@ -62,62 +62,10 @@ window.paperActions = { function init() { - initCount++; SESSIONID += "#" debug('init', SESSIONID); -} -var settings; -let nWorkspacesSignal; -let workspaceRemovedSignal; -let windowCreatedSignal; -function enable() { - // Only enable after disable have been run - if (enabled) - return; - - debug('enable', SESSIONID); - // HACK: couldn't find an other way within a reasonable time budget - // This state is different from being enabled after startup. Existing - // windows are not accessible yet for instance. - isDuringGnomeShellStartup = Main.actionMode === Shell.ActionMode.NONE; - - nWorkspacesSignal = - global.screen.connect('notify::n-workspaces', - Lang.bind(Tiling.spaces, utils.dynamic_function_ref('workspacesChanged', Tiling.spaces))); - - workspaceRemovedSignal = - global.screen.connect('workspace-removed', - utils.dynamic_function_ref('workspaceRemoved', Tiling.spaces)); - - windowCreatedSignal = - global.display.connect('window-created', - utils.dynamic_function_ref('window_created', Tiling.spaces)); - - function initWorkspaces() { - // Hook up existing workspaces - for (let i=0; i < global.screen.n_workspaces; i++) { - let workspace = global.screen.get_workspace_by_index(i) - Tiling.spaces.addSpace(workspace); - debug("workspace", workspace) - Tiling.add_all_from_workspace(workspace); - } - } - - if (isDuringGnomeShellStartup) { - // Defer workspace initialization until existing windows are accessible. - // Otherwise we're unable to restore the tiling-order. (when restarting - // gnome-shell) - Main.layoutManager.connect('startup-complete', function() { - isDuringGnomeShellStartup = false; - initWorkspaces(); - }); - } else { - initWorkspaces(); - } - - enabled = true; - if(initCount > 1) { + if(initCount > 0) { debug("#startup", "Reinitialized against our will! Skip adding bindings again to not cause trouble. ('disable()' isn't fully implemented yet)") return; @@ -127,15 +75,6 @@ function enable() { let dynamic_function_ref = utils.dynamic_function_ref; let as_key_handler = utils.as_key_handler; - settings = new Gio.Settings({ schema_id: "org.gnome.desktop.wm.keybindings"}); - - settings.set_strv("close", ['c']) - settings.set_strv("maximize-horizontally", ['f']) - settings.set_strv("toggle-fullscreen", ['f']); - - let shell_settings = new Gio.Settings({ schema_id: "org.gnome.shell.keybindings"}); - shell_settings.set_strv("toggle-overview", ["space"]) - // Or use "toggle-maximize"? Meta.keybindings_set_custom_handler("maximize-horizontally", as_key_handler("toggle_maximize_horizontally", @@ -188,6 +127,67 @@ function enable() { loadRcFile(); } +var settings; +let nWorkspacesSignal; +let workspaceRemovedSignal; +let windowCreatedSignal; +function enable() { + // Only enable after disable have been run + if (enabled) + return; + + debug('enable', SESSIONID); + // HACK: couldn't find an other way within a reasonable time budget + // This state is different from being enabled after startup. Existing + // windows are not accessible yet for instance. + isDuringGnomeShellStartup = Main.actionMode === Shell.ActionMode.NONE; + + nWorkspacesSignal = + global.screen.connect('notify::n-workspaces', + Lang.bind(Tiling.spaces, utils.dynamic_function_ref('workspacesChanged', Tiling.spaces))); + + workspaceRemovedSignal = + global.screen.connect('workspace-removed', + utils.dynamic_function_ref('workspaceRemoved', Tiling.spaces)); + + windowCreatedSignal = + global.display.connect('window-created', + utils.dynamic_function_ref('window_created', Tiling.spaces)); + + function initWorkspaces() { + // Hook up existing workspaces + for (let i=0; i < global.screen.n_workspaces; i++) { + let workspace = global.screen.get_workspace_by_index(i) + Tiling.spaces.addSpace(workspace); + debug("workspace", workspace) + Tiling.add_all_from_workspace(workspace); + } + } + + if (isDuringGnomeShellStartup) { + // Defer workspace initialization until existing windows are accessible. + // Otherwise we're unable to restore the tiling-order. (when restarting + // gnome-shell) + Main.layoutManager.connect('startup-complete', function() { + isDuringGnomeShellStartup = false; + initWorkspaces(); + }); + } else { + initWorkspaces(); + } + + let settings = new Gio.Settings({ schema_id: "org.gnome.desktop.wm.keybindings"}); + + settings.set_strv("close", ['c']) + settings.set_strv("maximize-horizontally", ['f']) + settings.set_strv("toggle-fullscreen", ['f']); + + let shell_settings = new Gio.Settings({ schema_id: "org.gnome.shell.keybindings"}); + shell_settings.set_strv("toggle-overview", ["space"]) + + enabled = true; +} + function disable() { if (!enabled) return;