From 42e36144fd7b22d2435ff6d6bc203f470f8f0337 Mon Sep 17 00:00:00 2001 From: Rafi Khan Date: Thu, 26 Jan 2017 21:09:20 -0600 Subject: [PATCH] fixes #12 causes #16 --- init.lua | 19 +++++++++++++++++-- spaces.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ utilities.lua | 9 +++++++++ window.lua | 7 ------- 4 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 spaces.lua diff --git a/init.lua b/init.lua index 6654355..0db36c5 100644 --- a/init.lua +++ b/init.lua @@ -9,6 +9,7 @@ Licensed under the MIT License require("utilities") require("window") require("server") +require("spaces") -- zwm applications = get_applications() @@ -57,8 +58,10 @@ function config_load() -- key bindings if config["key_bindings"] then + + -- dynamic bindings for b, info in pairs(config["key_bindings"]) do - + local type = info["type"] local key = info["key"] local action = info["action"] @@ -85,7 +88,19 @@ function config_load() end elseif type == "space" then - + if action == "space_change" then + local bind = nil + -- number keys + for i=1, 9 do + bind_test = func_change_to_space(i) + if bind_test ~= nil then + hs.hotkey.bind(binding.key, tostring(i), nil, bind_test) + else + print("nil at " .. i) + end + end + end + -- Controlling the window manager elseif type == "window_management" then if (key ~= "" and action ~= "") then diff --git a/spaces.lua b/spaces.lua new file mode 100644 index 0000000..d7d6056 --- /dev/null +++ b/spaces.lua @@ -0,0 +1,45 @@ +-- spaces + +spaces = require("hs._asm.undocumented.spaces") +require("utilities") + +-- returns spaces in order, but its best to not move spaces around +-- FIXME: This only addresses the primary screen (https://github.com/z3t0/zwm/issues/15) +function get_spaces() + local all_spaces = spaces.layout() + local inner = nil + + for k, v in pairs(all_spaces) do + if v ~= nil and type(v) == "table" then + inner = v + break + end + end + + if inner ~= nil then + return inner + end +end + +function change_to_space(space) + -- already on space + if space == spaces.activeSpace() then + return + end + + local new_space = get_spaces()[space] + print("changed") + if new_space ~= nil then + spaces.changeToSpace(new_space, false) + else + error("space does not exist: " .. tostring(space)) + end +end + +function func_change_to_space(index) + + print("index" .. index) + return function() + return change_to_space(index) + end +end diff --git a/utilities.lua b/utilities.lua index e34cfde..19fb8af 100644 --- a/utilities.lua +++ b/utilities.lua @@ -70,3 +70,12 @@ function string_match(str, table) end return false end + + +function a(i) + return i + 1 +end + +function b(i) + return a(i) +end \ No newline at end of file diff --git a/window.lua b/window.lua index bf477e6..702d7c0 100644 --- a/window.lua +++ b/window.lua @@ -1,11 +1,4 @@ require ("utilities") -spaces = require("hs._asm.undocumented.spaces") - -function get_spaces() - local spaces = hs.screen.mainScreen():spaces() - - return spaces -end function get_applications() local applications = hs.application.runningApplications()