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

Fix Center Window Frame function #121

Merged
merged 3 commits into from
Sep 13, 2021
Merged

Fix Center Window Frame function #121

merged 3 commits into from
Sep 13, 2021

Conversation

jaidetree
Copy link
Collaborator

@jaidetree jaidetree commented Sep 12, 2021

Fixes #119

Allows you to add something like the following to your config.fnl:

{
  ;; ...
        :modules {:windows  {:center-ratio "50:60"}}
  ;; ...
}

Then you can use the center-window-frame window modal action to use it like the following:

2021-09-12 19 09 24

Creates an advisable function called windows.position-window-center that takes the center-ratio config string and the target window. It is responsible for parsing the center-ratio string into numbers, and applying them to the target window. The advisable function gives users the option of overriding it to parse the center-ratio string in a different format and apply the calculation differently if needed.

If an option is not set, defaults to 80:50 which is a percentage of the screen. This is nearly identical to the previous version defaults.

windows.fnl Outdated
@@ -89,15 +90,39 @@
(: (hs.window.focusedWindow) :maximize 0)
(highlight-active-window))

(defn position-window-center
[ratio-str window]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the screen should probably be passed in.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this position-window-center-on-screen, though I think the name now is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about doing that, but was thinking that really depends on the implementation. The default behavior is to use the active screen, but users may want it to cycle between screens or pick the main screen, or any other logic to select a screen. The ratio-str and window are the only facts that are safe to assume for anticipated use-cases.

Though I suppose it could accept the current screen as a default and not use it but if you are aiming to implement advice then it's kind of a waste to have it query the screens again twice.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By making the screen an arg we assuming less. We can make center-window-frame provide (hs.screen.primaryScreen) by default.

By having more of the knobs in the args it also makes advising easier, since you can write one that just modifies the arguments instead of having to duplicate the logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a good point there. Pushed!

@jaidetree jaidetree merged commit cad25d7 into master Sep 13, 2021
@jaidetree jaidetree deleted the fix/center-window branch September 13, 2021 00:24
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

Successfully merging this pull request may close these issues.

center-window-frame doesn't work nicely on ultra-wide screen
2 participants