kitty icon indicating copy to clipboard operation
kitty copied to clipboard

Add window resize to absolute values

Open ershov opened this issue 2 years ago • 8 comments
trafficstars

This is a proof-of-concept for enabling the 'split' layout to use the 'bias' option and allowing to specify the absolute values for 'resize_window' command.

The 'bias' option was previously ignored by 'splits' layout, now it's possible to do:

enabled_layouts splits:bias=90

Only increments or decrements were previously accepted. 'width' and 'height' are for absolute percentages:

map <KEY>          resize_window width 20
map <KEY>          resize_window height 70

The issue is mentioned here: https://github.com/kovidgoyal/kitty/issues/6382

Please let me know if this kind of change can potentially be accepted.

ershov avatar Jun 22 '23 09:06 ershov

By absolute sizes do you mean size in cells or size in bias units?

If you mean size in cells, there are various problems. If you set the size in cells for multiple windows and they conflict, what happens? What happens on an OS window resize, when an absolute size cannot be respected because there isnt enough space?

You could possibly mean "absolute" in the sense that specifying a size in cells will adjust the corresponding bias to achieve that size, and that's all. If that's the case I am OK with it.

But note that to be acceptable such a PR has to work for all layouts not just splits.

kovidgoyal avatar Jun 22 '23 09:06 kovidgoyal

That's by far about an absolute bias value. In the current implementation, there's no way to specify that other than changing the global layout setting which will forcedly reshape all existing windows.

I was looking for something similar to 'resize_window' for one window but in the sense of absolute value (not relative increments/decrements).

The current solution allows to set absolute 'bias' for a window in a split. But I can see a relatively simple solution like adding units suffix (like 'px', 'pt', 'cells', '%') to the number argument. This feature might come later as an incremental improvement after an initial solution.

Regarding all other layouts, I agree that consistency is important. I can see how it can be implemented as a more general case in the base class for all layouts.

Does it also imply adding support for 'bias' option to all layouts or it's a separate thing?

What do you think about this feature?

ershov avatar Jun 22 '23 10:06 ershov

On Thu, Jun 22, 2023 at 03:43:48AM -0700, Yury Ershov wrote:

That's by far about an absolute bias value. In the current implementation, there's no way to specify that other than changing the global layout setting which will forcedly reshape all existing windows.

I am OK with that.

I was looking for something similar to 'resize_window' for one window but in the sense of absolute value (not relative increments/decrements).

The current solution allows to set absolute 'bias' for a window in a split. But I can see a relatively simple solution like adding units suffix (like 'px', 'pt', 'cells', '%') to the number argument. This feature might come later as an incremental improvement after an initial solution.

Just cells absolute and relative are fine as far as I am concerned. Indeed since windows only have sizes in cells, you cant really use other units they will get rounded to nearest cells anyway.

Regarding all other layouts, I agree that consistency is important. I can see how it can be implemented as a more general case in the base class for all layouts.

Yes in order for me to consider a PR it has to be implemented for all layouts.

Does it also imply adding support for 'bias' option to all layouts or it's a separate thing?

All layouts internally use bias already otherwise they would not be resizeable at all. Except for the stack layout, obviously.

What do you think about this feature?

I'm OK with reviewing a PR for it.

kovidgoyal avatar Jun 22 '23 11:06 kovidgoyal

Just cells absolute and relative are fine as far as I am concerned. Indeed since windows only have sizes in cells, you cant really use other units they will get rounded to nearest cells anyway.

Is it ok to start with just bias value (which is equal to percent) and adding cells later as a separate PR?

Yes in order for me to consider a PR it has to be implemented for all layouts.

Sounds good.

Does it also imply adding support for 'bias' option to all layouts or it's a separate thing?

All layouts internally use bias already otherwise they would not be resizeable at all. Except for the stack layout, obviously.

Ah yes, I mean, bias is used internally but not every layout supports the 'bias' option as a parameter to 'enabled_layouts'. Are you also looking to enable it for all layouts too? This also might go as a separate PR as it's an independent feature which would be good for consistency.

ershov avatar Jun 22 '23 21:06 ershov

On Thu, Jun 22, 2023 at 02:20:23PM -0700, Yury Ershov wrote:

Just cells absolute and relative are fine as far as I am concerned. Indeed since windows only have sizes in cells, you cant really use other units they will get rounded to nearest cells anyway.

Is it ok to start with just bias value (which is equal to percent) and adding cells later as a separate PR?

It's fine to start with bias but not that bias is only a percent in the case of two windows involved. If there are more than two then it is no longer a percent.

Yes in order for me to consider a PR it has to be implemented for all layouts.

Sounds good.

Does it also imply adding support for 'bias' option to all layouts or it's a separate thing?

All layouts internally use bias already otherwise they would not be resizeable at all. Except for the stack layout, obviously.

Ah yes, I mean, bias is used internally but not every layout supports the 'bias' option as a parameter to 'enabled_layouts'. Are you also looking to enable it for all layouts too? This also might go as a separate PR as it's an independent feature which would be good for consistency.

One cannot have bias as a parameter for all layouts, it is meaningless for some layouts such as stack/horiontal/vertical, it only really works for splits/vertical/horizontal. And I dont much see the point of it for splits, why would you want every split you make to start out already biased?

kovidgoyal avatar Jun 23 '23 01:06 kovidgoyal

One cannot have bias as a parameter for all layouts, it is meaningless for some layouts such as stack/horiontal/vertical, it only really works for splits/vertical/horizontal. And I dont much see the point of it for splits, why would you want every split you make to start out already biased?

Since I use 'splits' a lot, I can tell that I expected it to be more consistent. If it has the 'bias' parameter, I don't see why it ignores it in options to 'enabled_layouts splits:bias=X'.

One of possible uses is: when I open a secondary window, I might prefer it to be smaller than the main one. One of the ways to achieve it would be to specify the 'bias' parameter.

By the way, the 'Pair' currently doesn't clear its 'bias' when one of windows is closed. It leads to an odd behavior of recalling the last 'bias' on the next split.

To reproduce:

  1. Enable 'splits' layout.
  2. Split the window in two.
  3. Resize one of the windows.
  4. Close one of splits.
  5. Open a split again.

Result: the split ratio is not 1:1 but the same as it was adjusted.

ershov avatar Jun 23 '23 08:06 ershov

On Fri, Jun 23, 2023 at 01:09:20AM -0700, Yury Ershov wrote:

One cannot have bias as a parameter for all layouts, it is meaningless for some layouts such as stack/horiontal/vertical, it only really works for splits/vertical/horizontal. And I dont much see the point of it for splits, why would you want every split you make to start out already biased?

Since I use 'splits' a lot, I can tell that I expected it to be more consistent. If it has the 'bias' parameter, I don't see why it ignores it in options to 'enabled_layouts splits:bias=X'.

One of possible uses is: when I open a secondary window, I might prefer it to be smaller than the main one. One of the ways to achieve it would be to specify the 'bias' parameter.

But setting an overall bias means that every split you open in that layout will be biased.

By the way, the 'Pair' currently doesn't clear its 'bias' when one of windows is closed. It leads to an odd behavior of recalling the last 'bias' on the next split.

Yes, that's by design. If you want a pair of windows biased, I dont see why closing one of them neccessarily means you no longer want the bias.

kovidgoyal avatar Jun 23 '23 08:06 kovidgoyal

Yes, that's by design. If you want a pair of windows biased, I dont see why closing one of them neccessarily means you no longer want the bias.

Ok but the bias is not saved for the next split level.

ershov avatar Jun 23 '23 08:06 ershov