t-rec-rs icon indicating copy to clipboard operation
t-rec-rs copied to clipboard

[FEAT] windows support

Open sassman opened this issue 5 years ago • 7 comments

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

sassman avatar Oct 10 '20 20:10 sassman

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:

  1. Convert is the name of a standard program to convert disks to ntfs. Therefore, no longer depending on Imagemagick is mostly a prerequisite.
  2. The default command should be different - /bin/sh doesn't exist, but cmd.exe does.

xobs avatar Dec 31 '20 10:12 xobs

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.

sassman avatar Dec 31 '20 10:12 sassman

PS: convert is just sort of an alias, and the main command that can be used is magick like described here

sassman avatar Dec 31 '20 10:12 sassman

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.

xobs avatar Jan 01 '21 09:01 xobs

I'll also modify it to use the magick command directly, instead of using the alias. That should fix the issue I was seeing!

xobs avatar Jan 01 '21 09:01 xobs

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.

sassman avatar Jan 03 '21 13:01 sassman

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

jos3s avatar Apr 06 '21 19:04 jos3s