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

Feature: introduce "Window Mode" for selecting windows under Hyprland #20

Merged
merged 26 commits into from
Aug 9, 2023

Conversation

Syndelis
Copy link
Contributor

@Syndelis Syndelis commented Aug 2, 2023

About the PR

Resolves #4

This PR introduces two new feature flags: window-selection and hyprland-window-selection. The former provides an API for compositor-specific implementations, while the latter is an implementation for Hyprland.

The window-selection feature allows for a new mode to be used, "Window Mode", which no longer allows for the mouse to draw selections, but rather to have the selection be drawn around clicked windows (much similar to how "Monitor Mode" works).

Tab's cycle order for mode is now Display → Window → Rectangle. Additionally, going from "Window Mode" to "Rectangle Mode" preserves the selection around the last selected window. It's worth noting that this is only true when the flag is enabled, otherwise all remains the same.

In addition to this mode, new command line options are introduced to allow for a non-interactive usage of the program. Although it was noted on #4 that one should use grim directly when interactiveness is not desired, now that the program is able to find windows I think this becomes relevant again. The command line options are mutually exclusive and listed below:

  • --active-window: Pre-selects the currently focused window;
  • --window-under-cursor: Pre-selects the window that's under the cursor. This may be different than focused window depending on the user's compositor and settings, but for Hyprland they yield the same results;
  • --window-search: Pre-selects the first window that matches a condition. The condition is made up of a search parameter and a search value. The search parameter can be the window's title, class, initial title or initial class. The search value is a regex which will be matched against the search paramenter;

While these 3 mutually exclusive options work fine for interactive work (i.e. the program's default behavior), they can be used along with the new CLI argument --auto-capture to allow for non-interactive window capturing. For example, a simple command to capture the currently focused window can be achieved with watershot --active-window --auto-capture directory ~/Pictures.

Extras

This PR also updates the wgpu and wgpu_text dependencies. Rustc kept complaining that wgpu_text::section and wgpu_text::font didn't exist and, while I couldn't find any PR mentioning this change, I could find that the re-exports for what was used in this project were available under wgpu_text::glyph_brush.

Closing Note

I've tried my best to abstract away the Hyprland-specific stuff under generic APIs so that others can implement the same functionalities for Sway, GNOME, etc. without having the re-invent the wheel. I hope that it achieves its goal!

Syndelis added 11 commits July 31, 2023 21:33
feat: add hyprland window mode support
I couldn't find a reference on the documentation for these imports
existing, but apparently they stopped suddenly. Also I had to bump
wgpu's and wgpu_text's versions
windows can be pre-selected by one the three options:
- being focused
- by cursor position
- by (title, initial title, class, initial class)-matching regex
this requires a cli selection method to have been made
Copy link
Owner

@Kirottu Kirottu left a comment

Choose a reason for hiding this comment

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

In general this is neat work, if you want I can address my comments myself or you can also tackle them by yourself if you wish.

src/window/mod.rs Outdated Show resolved Hide resolved
src/window/mod.rs Outdated Show resolved Hide resolved
src/window/mod.rs Show resolved Hide resolved
src/types.rs Show resolved Hide resolved
src/window/hyprland.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/runtime_data.rs Outdated Show resolved Hide resolved
@Syndelis
Copy link
Contributor Author

Syndelis commented Aug 4, 2023

In general this is neat work, if you want I can address my comments myself or you can also tackle them by yourself if you wish.

Thanks for the review, @Kirottu! While I can handle most comments myself fairly quickly, I'd like to ask you for a general direction about the mouse coordinates you mentioned!

@Syndelis
Copy link
Contributor Author

Syndelis commented Aug 5, 2023

I've made some commits addressing most suggestions, @Kirottu, but did leave one question about the mouse position one.

Also, I didn't want to mark anything resolved because you may want to leave new comments on those ones, so feel free to "Mark resolved" whatever you feel has been correctly addressed!

@Syndelis Syndelis requested a review from Kirottu August 5, 2023 20:38
src/main.rs Outdated Show resolved Hide resolved
src/runtime_data.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
src/window/mod.rs Outdated Show resolved Hide resolved
src/window/mod.rs Outdated Show resolved Hide resolved
src/window/mod.rs Show resolved Hide resolved
src/sctk_impls/pointer_handler.rs Outdated Show resolved Hide resolved
src/sctk_impls/keyboard_handler.rs Outdated Show resolved Hide resolved
src/runtime_data.rs Outdated Show resolved Hide resolved
@Syndelis
Copy link
Contributor Author

Syndelis commented Aug 9, 2023

I believe I've managed to address all the review comments this time around, please double check though!

Once again, thanks for all the suggestions, @Kirottu !

@Syndelis Syndelis requested a review from Kirottu August 9, 2023 00:09
@Kirottu
Copy link
Owner

Kirottu commented Aug 9, 2023

There seems to be a bit of a regression with the ability to move a rectangular selection from its center area being broken now.

@Syndelis
Copy link
Contributor Author

Syndelis commented Aug 9, 2023

There seems to be a bit of a regression with the ability to move a rectangular selection from its center area being broken now.

I'll take a look at it

@Syndelis
Copy link
Contributor Author

Syndelis commented Aug 9, 2023

There seems to be a bit of a regression with the ability to move a rectangular selection from its center area being broken now.

Should be fixed by 4190bdd

@Syndelis Syndelis requested a review from Kirottu August 9, 2023 15:29
@Kirottu
Copy link
Owner

Kirottu commented Aug 9, 2023

Alright, I think this is in good enough shape to be merged now. Many thanks for the great work!

@Kirottu Kirottu merged commit f5a76dd into Kirottu:master Aug 9, 2023
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.

Support for "instant" mode
2 participants