A small Rust library that let's you get position and size of the active window on Windows and MacOS

Overview

active-win-pos-rs

A small Rust library that let's you get position and size of the active window on Windows and MacOS

Build

% git clone https://github.com/dimusic/active-win-pos-rs.git
% cd active-win-pos-rs
% cargo build

Example

% cargo run --example simple

Output:

% window position: WindowPosition { x: 733.0, y: 353.0, width: 815.0, height: 583.0 }
Comments
  • Window out of screen ?

    Window out of screen ?

    Hi,

    I'm under "Ubuntu 22.04.1 LTS" whit X11 and I've a big 32/9 screen:

    display_info DisplayInfo { id: 446, x: 0, y: 0, width: 5120, height: 1440, rotation: 0.0, scale_factor: 1.0, is_primary: true }

    if I have 2 separate windows, one taking all place on left on the other on right, I get that: What I really show on my Screen: Capture d’écran du 2022-09-19 21-59-15

    Now what ActiveWindow SHOW:

    LEFT: active window: ActiveWindow { title: "syl21@XPS-8930: ~/projets/debug", process_name: "Gnome-terminal", window_id: "50331658", process_id: 3663, position: WindowPosition { x: 140.0, y: 14.0, width: 2555.0, height: 1453.0, }, }

    RIGHT: active window: ActiveWindow { title: "", process_name: "firefox", window_id: "46137405", process_id: 4593, position: WindowPosition { x: 5158.0, y: 8.0, width: 2567.0, height: 1465.0, }, }

    As you can see they are mistake in RIGHT window position, normaly:

    • x would be like 2695.0
    • y would be 14
    • width same as LEFT
    • height same as LEFT

    Thx for your help ;-)

    opened by Le-Syl21 2
  • FYI: Macos window title is always nil; we use this workaround

    FYI: Macos window title is always nil; we use this workaround

    I wasn't sure where else I should post this - feel free to close the issue.

    However, if you need the macos title and search for a quick workaround, this is what we use.

    
    
    // Raw data is like this:   7) "iTerm2" ASN:0x0-0x18018: (in front)
    pub fn macos_get_active_window() -> String {
      let mut command = shell("lsappinfo | grep front");
      command.stdout(Stdio::piped());
      let output = command.execute_output().unwrap();
      let mut app_name : String = String::from_utf8(output.stdout).unwrap().to_string();
      app_name = app_name.replace("\n", "");
    
      app_name = extract_app_name(app_name);
      return app_name;
    }
    
    
    // Input:
    // "95) \"DayCheckin\" ASN:0x0-0x2aa3aa1: (in front) "
    // Output: DayCheckin
    // "79) \"Code - Insiders\" ASN:0x0-0x2a3ca3a: (in front) "
    // Code - Insiders
    // Test it here: https://rustexp.lpil.uk/
    pub fn extract_app_name(app_name: String) -> String {
        let re = Regex::new(r###""(.*)""###).unwrap();
    
        let extracted_name = match re.captures(&app_name) {
          Some(val) => { val[0].to_string().replace("\"", "") }
          None => {app_name}
        };
    
        extracted_name
    }
    
    
    opened by tillcarlos 2
  • Get window owner's (application) name with kCGWindowOwnerName in case kCGWindowName fails

    Get window owner's (application) name with kCGWindowOwnerName in case kCGWindowName fails

    Hey, so you might've noticed while testing kCGWindowName, that it doesn't provide the window's name for some applications. I did some digging and apparently, it's a common thing in MacOS applications because they have to set this field directly in XQuartz for it to be available.

    I fixed this problem by resulting to using the window owner's name when kCGWindowName fails.

    A question that arises, since I'm exclusively on mac, is what is the actual title field referring to in your implementation on linux and windows. If it's referring to the application name rather than the window name, then you might just want to remove the use of kCGWindowName altogether.

    opened by omerdn1 1
  • Expanding the capabilities of this library

    Expanding the capabilities of this library

    Love the approach and implementation on this!

    I was wondering if you'd be willing to extend the capabilities to allow for fetching of additional window information like window name, class, instance, etc..

    If you're interested, I prefer to incrementally add these additions to this repo instead of forking.

    opened by omerdn1 1
  • Fixed process id mismatch for windows

    Fixed process id mismatch for windows

    Hey, I am not sure whether this was intentional or not but process_id for ActiveWindow was returning the thread id instead of process id on Windows. For a downstream application I am building I needed to get the process_id of the window, so I went ahead and fixed it. Thought you may also be intrested in the fix :)

    opened by MrSupiri 1
  • Added Window Title on Windows

    Added Window Title on Windows

    I have added functionality to get the window title on Windows. Unfortunately, I do not have a Linux or Mac machine set up to do the same for those.

    I am not too up to date on the Rust best practices but L28 seems like a possible race condition to me as the window handle is retrieved again inside the self.get_position() call.

    opened by gertdreyer 1
Releases(0.7.1)
Owner
Dmitry Malkov
Dmitry Malkov
Use Git installed in Bash on Windows/Windows Subsystem for Linux (WSL) from Windows and Visual Studio Code (VSCode)

WSLGit This project provides a small executable that forwards all arguments to git running inside Bash on Windows/Windows Subsystem for Linux (WSL). T

A. R. S. 1.1k Jan 3, 2023
A library to capture the Screen on Linux, MacOS and Windows.

Captis - A library for capturing the screen on Linux, MacOS and Windows It's a fairly simple library that performs good enough, the OS level APIs that

CrewNew.com 17 Dec 23, 2022
A bit like tee, a bit like script, but all with a fake tty. Lets you remote control and watch a process

teetty teetty is a wrapper binary to execute a command in a pty while providing remote control facilities. This allows logging the stdout of a process

Armin Ronacher 259 Jan 3, 2023
Terminal UI for leetcode. Lets you browse questions through different topics. View, solve, run and submit questions from TUI.

Leetcode TUI Use Leetcode in your terminal. Why this TUI: My motivation for creating leetcode-tui stemmed from my preference for tools that are lightw

Akarsh 8 Aug 10, 2023
koyo is a cli tool that lets you run commands as another user. It is similar to doas or sudo.

koyo is a cli tool that lets you run commands as another user. It is similar to doas or sudo.

null 3 Nov 27, 2021
ISG lets you use YouTube as cloud storage for ANY files, not just video

I was working on this instead of my finals, hope you appreciate it. I'll add all relevant executables when I can Infinite-Storage-Glitch AKA ISG (writ

HistidineDwarf 3.6k Feb 23, 2023
⚡️(cd with env) Is a configurable cd wrapper that lets you define your environment per directory.

⚡️cdwe (cd with env) A simple configurable cd wrapper that provides powerful utilities for customizing your envionment per directory. (For ZSH / BASH

teo 20 Aug 6, 2023
An anyrun plugin that lets you search NixOS options.

anyrun-nixos-options An anyrun plugin that lets you search NixOS options. how 2 build? nix build ... or cargo build optionally :) Configuration This p

Michał 4 Aug 24, 2023
Lets you tweak Assassin's Creed Mirage in various ways.

Mirage Tweaks Lets you tweak Assassin's Creed Mirage in various ways. Currently supports adjusting the eject height and sprint speed. Usage Get the la

Assassin's Creed Community 3 Nov 3, 2023
Maccha is an extremely extensible and themable power menu for Windows, macOS, and Linux.

Maccha I hate coffee. Maccha is an extremely extensible and themable power menu for Windows, macOS, and Linux. Plugins Plugins are written in Rust (ot

Kyza 9 May 13, 2023
Simple template to use csr and ssr leptos with tauri for ios/android/windows/macos/linux and web dev

Tailwind-Leptos-Tauri Template Simple template to use csr and ssr leptos with tauri for ios/android/windows/macos/linux and web dev Just clone the rep

Victor Batarse 11 Mar 10, 2024
A todo list from terminal. Compatible with Linux and Windows, not tested on macOS

todocli A todo list from terminal. Compatible with Linux and Windows, not tested on macOS (not planing on support tho). Note: Currently being rewritte

Patommmmm 3 Dec 12, 2022
A minimal window context for Rust on Windows.

winctx A minimal window context for Rust on Windows. I read msdn so you don't have to. This crate provides a minimalistic method for setting up and ru

John-John Tedro 19 Dec 25, 2023
Active Directory data collector for BloodHound written in Rust. 🦀

RustHound Summary Limitation Description How to compile it? Using Makefile Using Dockerfile Using Cargo Linux x86_64 static version Windows static ver

OPENCYBER 575 Apr 25, 2023
Umpteen is a general-purpose programming language currently in active development being bootstrapped from Rust

The Umpteen Programming Language This repository provides the reference implementation for the Umpteen Programming Language, bootstrapped from Rust. U

Katie Janzen 4 Nov 20, 2023
Tracing layer that automatically creates and manages progress bars for active spans.

tracing-indicatif A tracing layer that automatically creates and manages indicatif progress bars for active spans. Progress bars are a great way to ma

Emerson Ford 95 Feb 22, 2023
Nvm - Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Node Version Manager Table of Contents Intro About Installing and Updating Install & Update Script Additional Notes Troubleshooting on Linux Troublesh

nvm.sh 63.8k Jan 7, 2023
Show active TCP connections on a TUI world map.

Maperick Show active TCP connections on a TUI world map. Still WIP, but it's gonna be good. Setup git clone [email protected]:schlunsen/maperick.git cd m

Rasmus Schlünsen 5 Jul 8, 2022
💫 List-rendering component utilizing FLIP position transitions for Leptos

<AnimatedFor /> component for Leptos FLIP animations for element and component groups inspired by Vue's <TransitionGroup>. This crate exports a compon

Kajetan Welc 6 Nov 13, 2023