Porting a Tiling Window Manager Extenstion to C++ (Bismuth): Part-2 (getting closest relative window)
Hi everyone! In this blog, I will be discussing the algorithm used in Bismuth to find the closest relative window to be focused for focusWindowByDirection
event. If you haven’t read the previous blog, make sure to give it a read here.
Recap from the previous blog
Let’s start with a quick recap though, in the previous blog, we discussed:
focusWindowByDirection
requires the following information:
direction
(from the user) - can be one of:right, left, top/up, bottom/down
.activeWindow
(from the current session) - this is needed sincefocusWindowByDirection
event is a relative event to your current focused window.- Neighbor window candidates (
neighborCandidates
) to your current window (activeWindow
) and the given direction (direction
).
// declaration
std::vector<Window> Engine::getNeighborCandidates(const FocusDirection &direction, const Window &basisWindow);
// use
std::vector<Window> neighborCandidates = getNeighborCandidates(direction, basisWindow);
- From these neighbor candidates (
neighborCandidates
), we will now find the closest relative window corner. To me, it was tricky to understand at first, so we’ll be discussing this in detail over in the later sections. - Once we know the closest relative window corner, we’ll try to find the window which satisfies the corner condition.
- If there were multiple found, we’ll return the first one based on the time-stamp (last used)
Understanding the scenario
I want to start off with a visual, took me some time to draw it, but in case it doesn’t look good, I’m sorry! My drawing teacher in the high school tried his best, but…