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

[Viewer] Make search for X11 window IDs more robust #2417

Merged
merged 4 commits into from
Jun 20, 2022
Merged

[Viewer] Make search for X11 window IDs more robust #2417

merged 4 commits into from
Jun 20, 2022

Conversation

ejmastnak
Copy link
Contributor

This PR addresses and solves #2415, wherein the variable b:vimtex.viewer.xwin_id would sometimes be set to an X11 window ID that was not the ID of the actual viewer. The issue is solved on my end (Arch Linux 5.18.2 with Zathura), but it would be prudent to test on other systems.

The PR is a refactor of existing code more than anything else; here is a quick summary:

  • Move winID-searching logic (by viewer PID, name and class) to three dedicated functions (to avoid code repetition; see 5671b1a for details)
  • Makes the xdo_get_id function in _template.vim attempt search by PID and search by window name before attempting search by class (previously only search by class was used).

More details in the commit messages.

refer: #2415

Elijan Mastnak added 3 commits June 20, 2022 11:57
This commit adds three new functions:

- `xdo_find_win_id_by_class`,
- `xdo_find_win_id_by_name`, and
- `xdo_find_win_id_by_pid`,

which will later be called from `xdo_exists` and `xdo_get_id` for the
purposes of identifying a viewer's X11 window ID.
Motivation: similar winID-finding logic is used by both `xdo_exists` and
`xdo_get_id`, so it makes sense to outsource this to "atomic" functions
to avoid code repetition.

TODO: refactor `xdo_exists` and `xdo_get_id` to actually use the new
functions.
This commit outsources the existing X11 window ID finding code in the
`xdo_exists` function to the dedicated functions
`xdo_find_win_id_by_pid` and `xdo_find_win_id_by_pid` introduced
previously in commit c036aa5.

There should be no externally visible change in VimTeX's behavior as a
result of this commit.
This commit makes the `xdo_get_id` function attempt to search for a
viewer's X11 window ID in the following order
1. By viewer's PID
2. By viewer's window name
3. By viewer's class

Previously, `xdo_get_id` only attempted a search by viewer class, which
could lead to unexpected results. For details see
[#2415](#2415)

refer: [#2415](#2415)
@lervag
Copy link
Owner

lervag commented Jun 20, 2022

Thanks! I think this looks very good and is almost ready for merge already. I only had a few minor comments and suggestions.

@lervag
Copy link
Owner

lervag commented Jun 20, 2022

Thanks! I made a few adjustments on top, I hope you don't mind. Let me know if I accidentily broke something :p

@ejmastnak
Copy link
Contributor Author

Thanks! I made a few adjustments on top, I hope you don't mind. Let me know if I accidentily broke something :p

Looks good! Just tested locally and everything seems to work. Thanks for your suggestions and help implementing this!

@lervag
Copy link
Owner

lervag commented Jun 20, 2022

My pleasure; and thanks to you for both the issue and the PR contribution! :)

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.

2 participants