Closed iveney closed 4 years ago
Might be an idea to post your whole config, so we can see what/how you're binding keys.
local application = require "mjolnir.application"
local window = require "mjolnir.window"
local fnutils = require "mjolnir.fnutils"
local alert = require "mjolnir.alert"
local hotkey = require "mjolnir.hotkey"
local grid = require "mjolnir.sd.grid"
local tiling = require "mjolnir.tiling"
local geometry = require "mjolnir.geometry"
local mash = {"ctrl", "alt", "cmd"}
local delta = 80
-- Tiling
hotkey.bind(mash, "c", function() tiling.cyclelayout() end)
hotkey.bind(mash, ".", function() tiling.cycle(1) end)
hotkey.bind(mash, ",", function() tiling.cycle(-1) end)
hotkey.bind(mash, "space", function() tiling.promote() end)
-- reload config
hotkey.bind(mash, "R", function()
mjolnir.reload()
end)
local move = function(dx, dy)
return function()
local win = window.focusedwindow()
local f = win:frame()
f.x = f.x + dx
f.y = f.y + dy
win:setframe(f)
end
end
local resize = function(dx, dy)
return function()
local win = window.focusedwindow()
-- alert.show(geometry.rect(1,2,3,4))
local frame = win:frame()
frame.x = frame.x - dx/2
frame.w = frame.w + dx
frame.y = frame.y - dy/2
frame.h = frame.h + dy
win:setframe(frame)
end
end
-- move the window
hotkey.bind(mash, "Left", move(-delta, 0))
hotkey.bind(mash, "Right", move(delta, 0))
hotkey.bind(mash, "Up", move(0, -delta))
hotkey.bind(mash, "Down", move(0, delta))
-- expand/shrink the window
hotkey.bind(mash, '=', resize(delta, delta))
hotkey.bind(mash, '-', resize(-delta, -delta))
hotkey.bind(mash, '[', resize(-delta, 0))
hotkey.bind(mash, ']', resize(delta, 0))
hotkey.bind(mash, ';', resize(0, -delta))
hotkey.bind(mash, '\'', resize(0, delta))
-- snap the window
grid.MARGINX = 0
grid.MARGINY = 0
grid.GRIDWIDTH = 2
grid.GRIDHEIGHT = 2
-- a helper function that returns another function that resizes the current window
-- to a certain grid size.
local gridset = function(x, y, w, h)
return function()
cur_window = window.focusedwindow()
grid.set(
cur_window,
{x=x, y=y, w=w, h=h},
cur_window:screen()
)
end
end
hotkey.bind(mash, 'n', grid.pushwindow_nextscreen)
hotkey.bind(mash, 'j', gridset(0, 0, 1, 2)) -- left half
hotkey.bind(mash, 'l', gridset(1, 0, 1, 2)) -- right half
hotkey.bind(mash, 'i', gridset(0, 0, 2, 1)) -- up half
hotkey.bind(mash, 'k', gridset(0, 1, 2, 1)) -- bottom half
hotkey.bind(mash, 'm', grid.maximize_window)-- maximize
Issue also was reproduced on my simpliest config. Only difference from config in README is that Luarocks are installed in the local user directory /Users/haff/.luarocks.
Each app start was followed by this issue. But then conifg reload works ok.
Was investigating this issue when decided to move Mjolnir.app from Desktop (from where I was running it) to Applications folder. After that issue dissapeared. What is interesting is that when I moved app back to Desktop (for tests sake) issue is still gone so I can't reproduce it again.
Config:
package.path = package.path .. ';' .. os.getenv("HOME") .. "/.luarocks/share/lua/5.2/?.lua"
package.cpath = package.cpath .. ';' .. os.getenv("HOME") .. "/.luarocks/lib/lua/5.2/?.so"
local application = require "mjolnir.application"
local hotkey = require "mjolnir.hotkey"
local window = require "mjolnir.window"
local fnutils = require "mjolnir.fnutils"
hotkey.bind({ "cmd", "alt", "ctrl" }, "D", function()
local win = window.focusedwindow()
local f = win:frame()
f.x = f.x + 10
win:setframe(f)
end)
I have always put my Mjolnir.app in application folder. The issue still appears (but unpredictably).
I think I figured out what this issue is about. In my case fails where appearing because mjolnir was executed while system layout was russian.
In init config I bind test action to "D" with code:
hotkey.bind({ "cmd", "alt", "ctrl" }, "D", function()
but keycodes.map contains codes table for layout with which it was executed (russian). And so "D" is missing, we get nil as keycode. The easiest and most flexible solution I see is to add ability to specify keys in form of keycodes (e.g. "#2" instead of "D"). I've implemented it and will create pull request.
Stale issue message
Sometimes when I start Mjolnir, I got the following errors:
However, reloading the config from the menu bar will work normally. Have no idea why this happens. Is it related to the order I put the 'require' statement? My order is like this: