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

[Feature Request] Can this somehow work with Amethyst? #95

Open
dlvhdr opened this issue Jan 23, 2022 · 1 comment
Open

[Feature Request] Can this somehow work with Amethyst? #95

dlvhdr opened this issue Jan 23, 2022 · 1 comment

Comments

@dlvhdr
Copy link

dlvhdr commented Jan 23, 2022

I'm using the WM https://github.com/ianyh/Amethyst.
Can this be easily adapted to use with it?

@harsilspatel
Copy link

harsilspatel commented Feb 8, 2022

Much like yourself, I don't use yabai stacks. So, I wanted to try hacking it since a stack is nothing but overlapping windows (i.e windows with same coordinates and dimensions).

I tried two versions but neither of them seem to be working. But my idea was to tell stackline that a set of overlapping windows belong to a same stack. I tried 2 methods but in vain:

  1. Use hammerspoon's built-in tools to query windows (which makes stackline completely independent from yabai)
  2. Query windows configs from yabai (which is running in float mode so stack-index will not be set)

For me it shows the stackline but with only a single icon. I'm unsure if it's an issue with Monterey? Either way, here's the patch for the yabai hack if you want to give it a shot.

diff --git a/stackline/query.lua b/stackline/query.lua
index d5287f0..bae31d1 100644
--- a/stackline/query.lua
+++ b/stackline/query.lua
@@ -130,6 +130,15 @@ local function shouldRestack(new) -- {{{
     log.i('Should not redraw.')
 end -- }}}
 
+local function getPseudoStackId(yabaiWin)
+  local frame = yabaiWin.frame
+  local x = math.floor(frame.x)
+  local y = math.floor(frame.y)
+  local w = math.floor(frame.w)
+  local h = math.floor(frame.h)
+  return table.concat({x, y, w, h}, '|')
+end
+
 local function run(opts) -- {{{
     opts = opts or {}
     local byStack, byApp = groupWindows(stackline.wf:getWindows()) -- set byStack & self.appWindows
@@ -141,10 +150,27 @@ local function run(opts) -- {{{
 
     if shouldRefresh or opts.forceRedraw then
         log.i('Refreshing stackline')
+
         -- TODO: if there's only 1 space, use 'query --windows --space' to reduce chance that parsing fails
         local yabai_cmd = 'query --windows'
 
         yabai(yabai_cmd, function(yabaiRes)
+            -- u.p(yabaiRes)
+
+            local winIdsToPseudoStackId = {}
+            for _, win in ipairs(yabaiRes) do
+              winIdsToPseudoStackId[win.id] = getPseudoStackId(win)
+            end
+
+            local pseudoStackIdToIdx = {}
+            for _, pseudoStackId in pairs(winIdsToPseudoStackId) do
+              pseudoStackIdToIdx[pseudoStackId] = pseudoStackIdToIdx[pseudoStackId] or u.length(pseudoStackIdToIdx) + 1
+            end
+
+            u.each(yabaiRes, function(win)
+              win['stack-index'] = pseudoStackIdToIdx[winIdsToPseudoStackId[win.id]]
+            end)
+
             local winStackIdxs = stackIdMapper(yabaiRes)
             stackline.manager:ingest( -- hand over to stackmanager
                 mergeWinStackIdxs(byStack, winStackIdxs), -- Add the stack indexes from yabai to byStack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants