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

Add get_position lua method for window #3006

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

alfa07
Copy link
Contributor

@alfa07 alfa07 commented Jan 25, 2023

These methods allow to implement in Lua moving focus to adjacent windows (aka ActivateWindowDirection). Not sure if this is the right implementation - so I will open an issue to discuss and will use this PR as an illustration.

See #3007 for more context.

Copy link
Owner

@wez wez left a comment

Choose a reason for hiding this comment

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

Thanks for diving in!

Please split this into two PRs; one for the pane direction stuff which I think looks mostly fine, and the other for the window positioning stuff which will need some more discussion and fleshing out to keep the build working on all platforms!

lua-api-crates/mux/src/tab.rs Outdated Show resolved Hide resolved
@alfa07 alfa07 force-pushed the maxim.sokolov/add-get-position branch from 2c0099a to b6f9de7 Compare January 26, 2023 03:49
@alfa07 alfa07 changed the title Add lua methods to access position and pane in the direction Add get_position lua method for window Jan 26, 2023
@alfa07
Copy link
Contributor Author

alfa07 commented Jan 26, 2023

I have split the get_pane_direction into #3011

This one I guess requires implementation for window systems other than MacOS. Any suggestions how to test/proceed?

@alfa07 alfa07 requested a review from wez January 26, 2023 04:53
@wez
Copy link
Owner

wez commented Jan 27, 2023

For Windows, you can use GetWindowRect to get the position. There are a couple of places that call that already that you can probably copypasta.

For X11, there is a GetGeometry request that yields a GetGeometryReply. You can find an example of that in the x11/window.rs file. Note that on some window managers it might be necessary to translate the result to get the correct coordinates. There's an example of that at the bottom of the x11/connection.rs file. I'd suggest skipping that complexity to start and we can see if we need to add it in later.

For Wayland I'd suggest always returning 0,0.

If you don't have linux and windows machines available, I'm fine with you iterating by pushing to this PR to see if things compile; I think that complexity of these methods is low enough that that will probably be fine.

///
/// This is only implemented on backends that allow
/// windows to move themselves (not Wayland).
fn get_window_position(&self) -> Future<ScreenPoint>;
Copy link
Owner

Choose a reason for hiding this comment

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

I wonder, should this be get_window_geometry instead, and return a ScreenRect; since the implementation on all platforms will have the window rectangle, it feels like it might simplify some cases for callers in the future to return it all, especially because right now the window size is tracked in TermWindow based on WindowEvents.

Copy link
Owner

Choose a reason for hiding this comment

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

That way, the wayland implementation could return the dimensions but leave the position at 0,0 and this method would be half-usable. Not super convinced that that is the best idea though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the current API choice favors get_position as we have set_position and get_dimensions calls

@alfa07 alfa07 force-pushed the maxim.sokolov/add-get-position branch from b6f9de7 to f59e41a Compare January 28, 2023 02:01
@alfa07
Copy link
Contributor Author

alfa07 commented Feb 1, 2023

Looks like freebsd-12 failure in CI is unrelated to the commit

@alfa07 alfa07 force-pushed the maxim.sokolov/add-get-position branch from b4d29a9 to 8057fbd Compare February 1, 2023 17:22
@alfa07
Copy link
Contributor Author

alfa07 commented Feb 2, 2023

I have tested that round-tripping coordinates through get_position, set_position works and does not change position of the window (on macos, ubuntu-x11, and windows):

> wezterm.mux.all_windows()[1]:gui_window():get_position()
{
    "x": 722,
    "y": 259,
}
> wezterm.mux.all_windows()[1]:gui_window():set_position(722, 259)
> wezterm.mux.all_windows()[1]:gui_window():get_position()
{
    "x": 722,
    "y": 259,
}

@wez
Copy link
Owner

wez commented Feb 2, 2023

The code looks good!

Following up on my earlier comment, can you try your round tripping test on X11 running i3?
It may be "doing something" to the reported coordinates (See discussion in #2928 (comment)).
If it doesn't return what we expect, 5d5efa0 shows how to translate the coordinates.

Then all that's left is adding a doc page for this new method!

@alfa07 alfa07 force-pushed the maxim.sokolov/add-get-position branch from d48228c to a936615 Compare December 23, 2024 03:02
@alfa07
Copy link
Contributor Author

alfa07 commented Dec 28, 2024

@wez given I test it on i3 is this ready to merge (with all the recent wayland changes)?

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.

3 participants