Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add move and grow methods to move and grow (or shrink) windows #5

Merged
merged 8 commits into from
Oct 26, 2018
9 changes: 9 additions & 0 deletions MiroWindowsManager.spoon/.luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
stds.hs = {
globals = {
hs = {
other_fields = true,
},
},
}
std = 'max+hs'
ignore = { '614' }
239 changes: 0 additions & 239 deletions MiroWindowsManager.spoon/docs.json
Original file line number Diff line number Diff line change
@@ -1,242 +1,3 @@
[
{
"Constant" : [

],
"submodules" : [

],
"Function" : [

],
"Variable" : [
{
"doc" : "The sizes that the window can have. \nThe sizes are expressed as dividend of the entire screen's size.\nFor example `{2, 3, 3\/2}` means that it can be 1\/2, 1\/3 and 2\/3 of the total screen's size",
"name" : "sizes",
"stripped_doc" : [
"The sizes that the window can have. ",
"The sizes are expressed as dividend of the entire screen's size.",
"For example `{2, 3, 3\/2}` means that it can be 1\/2, 1\/3 and 2\/3 of the total screen's size"
],
"parameters" : [

],
"notes" : [

],
"signature" : "MiroWindowsManager.sizes",
"type" : "Variable",
"returns" : [

],
"def" : "MiroWindowsManager.sizes",
"desc" : "The sizes that the window can have."
},
{
"doc" : "The sizes that the window can have in full-screen. \nThe sizes are expressed as dividend of the entire screen's size.\nFor example `{1, 4\/3, 2}` means that it can be 1\/1 (hence full screen), 3\/4 and 1\/2 of the total screen's size",
"name" : "fullScreenSizes",
"stripped_doc" : [
"The sizes that the window can have in full-screen. ",
"The sizes are expressed as dividend of the entire screen's size.",
"For example `{1, 4\/3, 2}` means that it can be 1\/1 (hence full screen), 3\/4 and 1\/2 of the total screen's size"
],
"parameters" : [

],
"notes" : [

],
"signature" : "MiroWindowsManager.fullScreenSizes",
"type" : "Variable",
"returns" : [

],
"def" : "MiroWindowsManager.fullScreenSizes",
"desc" : "The sizes that the window can have in full-screen."
},
{
"doc" : "The screen's size using `hs.grid.setGrid()`\nThis parameter is used at the spoon's `:init()`",
"name" : "GRID",
"stripped_doc" : [
"The screen's size using `hs.grid.setGrid()`",
"This parameter is used at the spoon's `:init()`"
],
"parameters" : [

],
"notes" : [

],
"signature" : "MiroWindowsManager.GRID",
"type" : "Variable",
"returns" : [

],
"def" : "MiroWindowsManager.GRID",
"desc" : "The screen's size using `hs.grid.setGrid()`"
}
],
"stripped_doc" : [

],
"desc" : "With this script you will be able to move the window in halves and in corners using your keyboard and mainly using arrows. You would also be able to resize them by thirds, quarters, or halves.",
"type" : "Module",
"Deprecated" : [

],
"Constructor" : [

],
"doc" : "With this script you will be able to move the window in halves and in corners using your keyboard and mainly using arrows. You would also be able to resize them by thirds, quarters, or halves.\n\nOfficial homepage for more info and documentation: [https:\/\/github.com\/miromannino\/miro-windows-manager](https:\/\/github.com\/miromannino\/miro-windows-manager)\n\nDownload: [https:\/\/github.com\/miromannino\/miro-windows-manager\/raw\/master\/MiroWindowsManager.spoon.zip](https:\/\/github.com\/miromannino\/miro-windows-manager\/raw\/master\/MiroWindowsManager.spoon.zip)",
"Method" : [
{
"doc" : "Binds hotkeys for Miro's Windows Manager\nParameters:\n * mapping - A table containing hotkey details for the following items:\n * up: for the up action (usually {hyper, \"up\"})\n * right: for the right action (usually {hyper, \"right\"})\n * down: for the down action (usually {hyper, \"down\"})\n * left: for the left action (usually {hyper, \"left\"})\n * fullscreen: for the full-screen action (e.g. {hyper, \"f\"})\n\nA configuration example can be:\n```\nlocal hyper = {\"ctrl\", \"alt\", \"cmd\"}\nspoon.MiroWindowsManager:bindHotkeys({\n up = {hyper, \"up\"},\n right = {hyper, \"right\"},\n down = {hyper, \"down\"},\n left = {hyper, \"left\"},\n fullscreen = {hyper, \"f\"}\n})\n```",
"name" : "bindHotkeys",
"stripped_doc" : [
"Binds hotkeys for Miro's Windows Manager"
],
"parameters" : [
" * mapping - A table containing hotkey details for the following items:",
" * up: for the up action (usually {hyper, \"up\"})",
" * right: for the right action (usually {hyper, \"right\"})",
" * down: for the down action (usually {hyper, \"down\"})",
" * left: for the left action (usually {hyper, \"left\"})",
" * fullscreen: for the full-screen action (e.g. {hyper, \"f\"})",
"",
"A configuration example can be:",
"```",
"local hyper = {\"ctrl\", \"alt\", \"cmd\"}",
"spoon.MiroWindowsManager:bindHotkeys({",
" up = {hyper, \"up\"},",
" right = {hyper, \"right\"},",
" down = {hyper, \"down\"},",
" left = {hyper, \"left\"},",
" fullscreen = {hyper, \"f\"}",
"})",
"```"
],
"notes" : [

],
"signature" : "MiroWindowsManager:bindHotkeys()",
"type" : "Method",
"returns" : [

],
"def" : "MiroWindowsManager:bindHotkeys()",
"desc" : "Binds hotkeys for Miro's Windows Manager"
}
],
"Command" : [

],
"items" : [
{
"doc" : "The screen's size using `hs.grid.setGrid()`\nThis parameter is used at the spoon's `:init()`",
"name" : "GRID",
"stripped_doc" : [
"The screen's size using `hs.grid.setGrid()`",
"This parameter is used at the spoon's `:init()`"
],
"parameters" : [

],
"notes" : [

],
"signature" : "MiroWindowsManager.GRID",
"type" : "Variable",
"returns" : [

],
"def" : "MiroWindowsManager.GRID",
"desc" : "The screen's size using `hs.grid.setGrid()`"
},
{
"doc" : "The sizes that the window can have in full-screen. \nThe sizes are expressed as dividend of the entire screen's size.\nFor example `{1, 4\/3, 2}` means that it can be 1\/1 (hence full screen), 3\/4 and 1\/2 of the total screen's size",
"name" : "fullScreenSizes",
"stripped_doc" : [
"The sizes that the window can have in full-screen. ",
"The sizes are expressed as dividend of the entire screen's size.",
"For example `{1, 4\/3, 2}` means that it can be 1\/1 (hence full screen), 3\/4 and 1\/2 of the total screen's size"
],
"parameters" : [

],
"notes" : [

],
"signature" : "MiroWindowsManager.fullScreenSizes",
"type" : "Variable",
"returns" : [

],
"def" : "MiroWindowsManager.fullScreenSizes",
"desc" : "The sizes that the window can have in full-screen."
},
{
"doc" : "The sizes that the window can have. \nThe sizes are expressed as dividend of the entire screen's size.\nFor example `{2, 3, 3\/2}` means that it can be 1\/2, 1\/3 and 2\/3 of the total screen's size",
"name" : "sizes",
"stripped_doc" : [
"The sizes that the window can have. ",
"The sizes are expressed as dividend of the entire screen's size.",
"For example `{2, 3, 3\/2}` means that it can be 1\/2, 1\/3 and 2\/3 of the total screen's size"
],
"parameters" : [

],
"notes" : [

],
"signature" : "MiroWindowsManager.sizes",
"type" : "Variable",
"returns" : [

],
"def" : "MiroWindowsManager.sizes",
"desc" : "The sizes that the window can have."
},
{
"doc" : "Binds hotkeys for Miro's Windows Manager\nParameters:\n * mapping - A table containing hotkey details for the following items:\n * up: for the up action (usually {hyper, \"up\"})\n * right: for the right action (usually {hyper, \"right\"})\n * down: for the down action (usually {hyper, \"down\"})\n * left: for the left action (usually {hyper, \"left\"})\n * fullscreen: for the full-screen action (e.g. {hyper, \"f\"})\n\nA configuration example can be:\n```\nlocal hyper = {\"ctrl\", \"alt\", \"cmd\"}\nspoon.MiroWindowsManager:bindHotkeys({\n up = {hyper, \"up\"},\n right = {hyper, \"right\"},\n down = {hyper, \"down\"},\n left = {hyper, \"left\"},\n fullscreen = {hyper, \"f\"}\n})\n```",
"name" : "bindHotkeys",
"stripped_doc" : [
"Binds hotkeys for Miro's Windows Manager"
],
"parameters" : [
" * mapping - A table containing hotkey details for the following items:",
" * up: for the up action (usually {hyper, \"up\"})",
" * right: for the right action (usually {hyper, \"right\"})",
" * down: for the down action (usually {hyper, \"down\"})",
" * left: for the left action (usually {hyper, \"left\"})",
" * fullscreen: for the full-screen action (e.g. {hyper, \"f\"})",
"",
"A configuration example can be:",
"```",
"local hyper = {\"ctrl\", \"alt\", \"cmd\"}",
"spoon.MiroWindowsManager:bindHotkeys({",
" up = {hyper, \"up\"},",
" right = {hyper, \"right\"},",
" down = {hyper, \"down\"},",
" left = {hyper, \"left\"},",
" fullscreen = {hyper, \"f\"}",
"})",
"```"
],
"notes" : [

],
"signature" : "MiroWindowsManager:bindHotkeys()",
"type" : "Method",
"returns" : [

],
"def" : "MiroWindowsManager:bindHotkeys()",
"desc" : "Binds hotkeys for Miro's Windows Manager"
}
],
"Field" : [

],
"name" : "MiroWindowsManager"
}
]
65 changes: 65 additions & 0 deletions MiroWindowsManager.spoon/extend_GRID.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
-- Comment: Lots of work here to save users a little work. Previous versions
-- required users to call MiroWindowsManager:start() every time they changed
-- GRID. The metatable work here watches for those changes and does the work
-- :start() would have done.
--
-- usage:
-- require('extend_GRID').extend(obj, logger)

local M = {}

function M.extend(obj, logger)
-- Ensure changes to GRID update hs.grid
-- Prevent obj.GRID from being replaced
local _grid_store = {} -- we'll store the real GRID here
setmetatable(obj, {
__index = function(t,k) -- if code reads obj, use this function (eg. `obj.sizes`)
-- if code accesses obj.GRID, return the real GRID we created above,
-- otherwise access obj as normal
if k == 'GRID' then return _grid_store else return rawget(t,k) end end,
__newindex =
function(t,k,v) -- if code writes to obj, use this function (eg. `obj.sizes = {2, 3}`)
if k == 'GRID' then
-- if code assigns to obj.GRID (`obj.GRID = ...`), don't overwrite our
-- real GRID, otherwise access obj as normal
assert(type(v)=='table', rawget(obj,'name')..".GRID must be a table.")
-- assign the assigned table's content to our real GRID table
for kk,vv in pairs(v) do obj.GRID[kk] = vv end
else
rawset(t,k,v)
end
end,
})
-- Update hs.grid after relevant changes to obj.GRID
local _grid_value_store = {} -- we store the real GRID *values* here
setmetatable(_grid_store, {
__newindex =
function(_,k,v) -- if code assigns to our real GRID…
rawset(_grid_value_store,k,v) -- do the assignment, then…
if hs.fnutils.contains({'w','h'}, k) then
-- update hs.grid with hs.grid.setGrid, so the user doesn't have to
hs.grid.setGrid(tostring(_grid_value_store.w or 0) .. 'x' ..
tostring(_grid_value_store.h or 0))
logger.i("Updated hs.grid to ".. hs.inspect(_grid_value_store))
elseif k == 'margins' then
-- update hs.grid with hs.grid.setMargins, so the user doesn't have to
hs.grid.setMargins(v)
logger.i("Updated hs.grid to ".. hs.inspect(_grid_value_store))
elseif hs.fnutils.contains({'MARGINX','MARGINY'}, k) then
-- LEGACY
if k == 'MARGINX' then
obj.GRID.margins = hs.geometry(tostring(v) ..'x'..
tostring(rawget(_grid_value_store, 'margins').h or 0))
elseif k == 'MARGINY' then
obj.GRID.margins =
hs.geometry(tostring(rawget(_grid_value_store, 'margins').w or 0) ..'x'..
tostring(v))
end
logger.i("Updated hs.grid to ".. hs.inspect(_grid_value_store))
end
end,
__index = function(_,k) return rawget(_grid_value_store, k) end,
})
end

return M
Loading