t-rec-rs
t-rec-rs copied to clipboard
[FEAT] windows support
Implement window grabbing and screenshotting capabilities for windows. The interface that needs to be implemented is very simple and straight forward:
pub fn get_window_id_for(_terminal: String) -> Option<u32> {
// returns the window id / handle for a given name
}
pub fn ls_win() {
// prints out window name and id
}
pub fn capture_window_screenshot(_win_id: u32) -> anyhow::Result<ImageOnHeap> {
// captures the screenshot for a given window id / handle and returns a result of a Box<FlatSamples> image
}
Additionally, some inspiration on the windows APIs in rust can be drawn from here
After seeing your announcement, I've started looking into this.
So far I have it listing windows, and I've started working on the capture steps.
Current issues are:
- Convert is the name of a standard program to convert disks to ntfs. Therefore, no longer depending on Imagemagick is mostly a prerequisite.
- The default command should be different - /bin/sh doesn't exist, but cmd.exe does.
Nice, just a heads up, the API has evolved and must now implement this trait:
use crate::{ImageOnHeap, Result, WindowId, WindowList};
pub trait PlatformApi: Send {
fn calibrate(&mut self, window_id: WindowId) -> Result<()>;
fn window_list(&self) -> Result<WindowList>;
fn capture_window_screenshot(&self, window_id: WindowId) -> Result<ImageOnHeap>;
fn get_active_window(&self) -> Result<WindowId>;
}
Convert is the name of a standard program to convert disks to ntfs. Therefore, no longer depending on Imagemagick is mostly a prerequisite.
why is that an issue?
The default command should be different - /bin/sh doesn't exist, but cmd.exe does.
that should not be that hard, but good point.
PS: convert is just sort of an alias, and the main command that can be used is magick like described here
I have an initial build up at https://github.com/xobs/t-rec-rs/tree/win-support
It mostly steals from the winrt-rs example that is referred to in the previous iteration of the win module. However, it performs a continuous capture, which nicely places a bright yellow border around the window in question.
It doesn't handle borders right now, and the get_active_window() function gets the current active window, instead of the window that you're typing into. This becomes a problem if, for example, you alt-tab while compiling the project, or do sleep 5; cargo run and alt-tab. I'm uncertain of whether this is a problem.
I'll also modify it to use the magick command directly, instead of using the alias. That should fix the issue I was seeing!
There is now a dedicated feature branch for windows-support that is kept in sync with main and will be at some point mature enough to be ready for release.
I discovered this project is good to see that windows support is planned, I would like to add that if a windows version becomes available, it would be interesting to make it available on the winget