Skip to content

Commit

Permalink
fixes #12 causes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
z3t0 committed Jan 27, 2017
1 parent 5d81c5a commit 42e3614
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
19 changes: 17 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Licensed under the MIT License
require("utilities")
require("window")
require("server")
require("spaces")

-- zwm
applications = get_applications()
Expand Down Expand Up @@ -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"]
Expand All @@ -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
Expand Down
45 changes: 45 additions & 0 deletions spaces.lua
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions utilities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 0 additions & 7 deletions window.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 42e3614

Please sign in to comment.