mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-25 09:59:21 +01:00
Add output location helper methods
This commit is contained in:
parent
f99c8b886d
commit
0190b66958
4 changed files with 174 additions and 16 deletions
|
@ -219,3 +219,35 @@ function output:focused() end
|
|||
---dp2:set_loc({ x = 2560, y = 1440 - 1080 })
|
||||
---@tparam table loc A table of the form `{ x: integer?, y: integer? }`
|
||||
function output:set_loc(loc) end
|
||||
|
||||
---Set this output's location to the right of `op`.
|
||||
---
|
||||
---This will fail if `op` is an invalid output.
|
||||
---@tparam Output op
|
||||
---@tparam[opt="top"] string alignment One of `top`, `center`, or `bottom`. This is how you want to align the `self` output.
|
||||
---@see Output.set_loc
|
||||
function output:set_loc_right_of(op, alignment) end
|
||||
|
||||
---Set this output's location to the left of `op`.
|
||||
---
|
||||
---This will fail if `op` is an invalid output.
|
||||
---@tparam Output op
|
||||
---@tparam[opt="top"] string alignment One of `top`, `center`, or `bottom`. This is how you want to align the `self` output.
|
||||
---@see Output.set_loc
|
||||
function output:set_loc_left_of(op, alignment) end
|
||||
|
||||
---Set this output's location to the top of `op`.
|
||||
---
|
||||
---This will fail if `op` is an invalid output.
|
||||
---@tparam Output op
|
||||
---@tparam[opt="left"] string alignment One of `left`, `center`, or `right`. This is how you want to align the `self` output.
|
||||
---@see Output.set_loc
|
||||
function output:set_loc_top_of(op, alignment) end
|
||||
|
||||
---Set this output's location to the bottom of `op`.
|
||||
---
|
||||
---This will fail if `op` is an invalid output.
|
||||
---@tparam Output op
|
||||
---@tparam[opt="left"] string alignment One of `left`, `center`, or `right`. This is how you want to align the `self` output.
|
||||
---@see Output.set_loc
|
||||
function output:set_loc_bottom_of(op, alignment) end
|
||||
|
|
|
@ -4,15 +4,6 @@
|
|||
---@module TagModule
|
||||
local tag_module = {}
|
||||
|
||||
---@alias Layout
|
||||
---| "MasterStack" # One master window on the left with all other windows stacked to the right.
|
||||
---| "Dwindle" # Windows split in half towards the bottom right corner.
|
||||
---| "Spiral" # Windows split in half in a spiral.
|
||||
---| "CornerTopLeft" # One main corner window in the top left with a column of windows on the right and a row on the bottom.
|
||||
---| "CornerTopRight" # One main corner window in the top right with a column of windows on the left and a row on the bottom.
|
||||
---| "CornerBottomLeft" # One main corner window in the bottom left with a column of windows on the right and a row on the top.
|
||||
---| "CornerBottomRight" # One main corner window in the bottom right with a column of windows on the left and a row on the top.
|
||||
|
||||
---Add tags to the specified output.
|
||||
---
|
||||
---@usage
|
||||
|
|
|
@ -115,9 +115,149 @@ end
|
|||
---```
|
||||
---@param loc { x: integer?, y: integer? }
|
||||
function output:set_loc(loc)
|
||||
return output_module.set_loc(self, loc)
|
||||
output_module.set_loc(self, loc)
|
||||
end
|
||||
|
||||
-- TODO: move this into own file or something ---------------------------------------------
|
||||
|
||||
---@alias AlignmentVertical
|
||||
---| "top" Align the tops of the outputs
|
||||
---| "center" Center the outputs vertically
|
||||
---| "bottom" Align the bottoms of the outputs
|
||||
|
||||
---@alias AlignmentHorizontal
|
||||
---| "left" Align the left edges of the outputs
|
||||
---| "center" Center the outputs vertically
|
||||
---| "right" Align the right edges of the outputs
|
||||
|
||||
---@param op1 Output
|
||||
---@param op2 Output
|
||||
---@param left_or_right "left" | "right"
|
||||
---@param alignment AlignmentVertical? How you want to align the `self` output. Defaults to `top`.
|
||||
local function set_loc_horizontal(op1, op2, left_or_right, alignment)
|
||||
local alignment = alignment or "top"
|
||||
local self_loc = op1:loc()
|
||||
local self_res = op1:res()
|
||||
local other_loc = op2:loc()
|
||||
local other_res = op2:res()
|
||||
|
||||
if
|
||||
self_loc == nil
|
||||
or self_res == nil
|
||||
or other_loc == nil
|
||||
or other_res == nil
|
||||
then
|
||||
return
|
||||
end
|
||||
|
||||
---@type integer
|
||||
local x
|
||||
if left_or_right == "left" then
|
||||
x = other_loc.x - self_res.w
|
||||
else
|
||||
x = other_loc.x + other_res.w
|
||||
end
|
||||
|
||||
if alignment == "top" then
|
||||
output_module.set_loc(op1, { x = x, y = other_loc.y })
|
||||
elseif alignment == "center" then
|
||||
output_module.set_loc(
|
||||
op1,
|
||||
{ x = x, y = other_loc.y + (other_res.h - self_res.h) // 2 }
|
||||
)
|
||||
elseif alignment == "bottom" then
|
||||
output_module.set_loc(
|
||||
op1,
|
||||
{ x = x, y = other_loc.y + (other_res.h - self_res.h) }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
---Set this output's location to the right of the specified output.
|
||||
---
|
||||
---This will fail if `op` is an invalid output.
|
||||
---@param op Output
|
||||
---@param alignment AlignmentVertical? How you want to align the `self` output. Defaults to `top`.
|
||||
---@see Output.set_loc if you need more granular control
|
||||
function output:set_loc_right_of(op, alignment)
|
||||
set_loc_horizontal(self, op, "right", alignment)
|
||||
end
|
||||
|
||||
---Set this output's location to the left of the specified output.
|
||||
---
|
||||
---This will fail if `op` is an invalid output.
|
||||
---@param op Output
|
||||
---@param alignment AlignmentVertical? How you want to align the `self` output. Defaults to `top`.
|
||||
---@see Output.set_loc if you need more granular control
|
||||
function output:set_loc_left_of(op, alignment)
|
||||
set_loc_horizontal(self, op, "left", alignment)
|
||||
end
|
||||
|
||||
---@param op1 Output
|
||||
---@param op2 Output
|
||||
---@param top_or_bottom "top" | "bottom"
|
||||
---@param alignment AlignmentHorizontal? How you want to align the `self` output. Defaults to `top`.
|
||||
local function set_loc_vertical(op1, op2, top_or_bottom, alignment)
|
||||
local alignment = alignment or "left"
|
||||
local self_loc = op1:loc()
|
||||
local self_res = op1:res()
|
||||
local other_loc = op2:loc()
|
||||
local other_res = op2:res()
|
||||
|
||||
if
|
||||
self_loc == nil
|
||||
or self_res == nil
|
||||
or other_loc == nil
|
||||
or other_res == nil
|
||||
then
|
||||
return
|
||||
end
|
||||
|
||||
---@type integer
|
||||
local y
|
||||
if top_or_bottom == "top" then
|
||||
y = other_loc.y - self_res.h
|
||||
else
|
||||
y = other_loc.y + other_res.h
|
||||
end
|
||||
|
||||
if alignment == "left" then
|
||||
output_module.set_loc(op1, { x = other_loc.x, y = y })
|
||||
elseif alignment == "center" then
|
||||
output_module.set_loc(
|
||||
op1,
|
||||
{ x = other_loc.x + (other_res.w - self_res.w) // 2, y = y }
|
||||
)
|
||||
elseif alignment == "right" then
|
||||
output_module.set_loc(
|
||||
op1,
|
||||
{ x = other_loc.x + (other_res.w - self_res.w), y = y }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
---Set this output's location to the top of the specified output.
|
||||
---
|
||||
---This will fail if `op` is an invalid output.
|
||||
---@param op Output
|
||||
---@param alignment AlignmentHorizontal? How you want to align the `self` output. Defaults to `left`.
|
||||
---@see Output.set_loc if you need more granular control
|
||||
function output:set_loc_top_of(op, alignment)
|
||||
set_loc_vertical(self, op, "top", alignment)
|
||||
end
|
||||
|
||||
---Set this output's location to the bottom of the specified output.
|
||||
---
|
||||
---This will fail if `op` is an invalid output.
|
||||
---@param op Output
|
||||
---@param alignment AlignmentHorizontal? How you want to align the `self` output. Defaults to `left`.
|
||||
---@see Output.set_loc if you need more granular control
|
||||
function output:set_loc_bottom_of(op, alignment)
|
||||
set_loc_vertical(self, op, "bottom", alignment)
|
||||
end
|
||||
|
||||
-- TODO: ----------------------------------------------------------------------------------
|
||||
|
||||
------------------------------------------------------
|
||||
|
||||
---Get an output by its name.
|
||||
|
|
|
@ -68,13 +68,8 @@ require("pinnacle").setup(function(pinnacle)
|
|||
input.keybind({ mod_key }, keys.h, function()
|
||||
local dp2 = output.get_by_name("DP-2")
|
||||
local dp3 = output.get_by_name("DP-3")
|
||||
output.set_loc(dp2, { x = 1920, y = 0 })
|
||||
output.set_loc(dp3, { x = 0, y = 1440 - 1080 })
|
||||
local dp2loc = dp2:loc()
|
||||
local dp3loc = dp3:loc()
|
||||
|
||||
print("dp2: " .. dp2loc.x .. ", " .. dp2loc.y)
|
||||
print("dp3: " .. dp3loc.x .. ", " .. dp3loc.y)
|
||||
dp2:set_loc_bottom_of(dp3, "right")
|
||||
|
||||
-- local win = window.get_focused()
|
||||
-- if win ~= nil then
|
||||
|
|
Loading…
Reference in a new issue