A minimal window context for Rust on Windows.

Related tags

Command-line winctx
Overview

winctx

github crates.io docs.rs build status

A minimal window context for Rust on Windows.

I read msdn so you don't have to.

The showcase popup menu

This crate provides a minimalistic method for setting up and running a window. A window on windows is more like a generic application framework and doesn't actually need to have any visible elements, but is necessary to do many of the productive things you might want to do on Windows.

Some example of this are:

There are a few additional APIs provided by this crate because they are also useful:

This crate is an amalgamation and cleanup of code I've copied back and forth between my projects, so it is fairly opinionated to things I personally find useful. Not everything will be possible, but if there is something you're missing and hate being happy enjoy Windows programming feel free to open an issue or a pull request.


Example

The primary purpose of this crate is to:

  • Define a window and its capabilities. I.e. if it should have a context menu or receive clipboard events.
  • Handle incoming Events from the window.

The basic loop looks like this:

use std::pin::pin;

use tokio::signal::ctrl_c;
use winctx::{Event, CreateWindow};

const ICON: &[u8] = include_bytes!("tokio.ico");

let mut window = CreateWindow::new("se.tedro.Example")
    .window_name("Example Application");

let icon = window.icons().insert_buffer(ICON, 22, 22);

let area = window.new_area().icon(icon);

let menu = area.popup_menu();

let first = menu.push_entry("Example Application").id();
menu.push_separator();
let quit = menu.push_entry("Quit").id();
menu.set_default(first);

let (sender, mut event_loop) = window
    .build()
    .await?;

let mut ctrl_c = pin!(ctrl_c());
let mut shutdown = false;

loop {
    let event = tokio::select! {
        _ = ctrl_c.as_mut(), if !shutdown => {
            sender.shutdown();
            shutdown = true;
            continue;
        }
        event = event_loop.tick() => {
            event?
        }
    };

    match event {
        Event::MenuItemClicked { item_id, .. } => {
            println!("Menu entry clicked: {item_id:?}");

            if item_id == quit {
                sender.shutdown();
            }
        }
        Event::Shutdown { .. } => {
            println!("Window shut down");
            break;
        }
        _ => {}
    }
}
You might also like...
Windows Capture Simple Screen Capture for Windows 🔥

Windows Capture   Windows Capture is a highly efficient Rust library that enables you to effortlessly capture the screen using the Graphics Capture AP

Cross platfrom window and framebuffer crate for Rust

minifb is a cross platform library written in Rust and that makes it easy to setup a window and to (optional) display a 32-bit pixel buffer. It also m

skyWM is an extensible tiling window manager written in Rust. skyWM has a clear and distinct focus adhering to the KISS and Unix philosophy.
skyWM is an extensible tiling window manager written in Rust. skyWM has a clear and distinct focus adhering to the KISS and Unix philosophy.

Please note: skyWM is currently in heavy development and is not usable as of yet. Documentation and versions will change quickly. skyWM skyWM is an ex

A library that creates a terminal-like window with feature-packed drawing of text and easy input handling. MIRROR.

BearLibTerminal provides a pseudoterminal window with a grid of character cells and a simple yet powerful API for flexible textual output and uncompli

My Window Manager
My Window Manager

mwm My window manager that is a work in progress. Currently hacky Installation Clone this repo then: cargo build --release Put the binary in your pat

A fully modular window manager, extremely extensibile and easily approachable.

AquariWM is a fully modular window manager, allowing extreme extensibility while remaining easily approachable. Installation AquariWM is currently in

Use raw-window-handle 0.5 with crates that depend on 0.4.

OldHasRawWindowHandleWrapper Wrap any type that implements HasRawWindowHandle and HasRawDisplayHandle from raw-window-handle 0.5 in OldHasRawWindowHan

A collection of tools for i3 that assist in window, workspace and output operations.

i3-valet A collection of tools for i3 that assist in window, workspace and output operations. i3-valet can be run directly from the command line or as

An i3/Sway utility to switch focus to your last focused window. Alt+Tab in i3

i3-back An i3/Sway utility to switch focus to your last focused window. Allows for behavior similar to Alt+Tab on other desktop environments. Features

Comments
  • Break up event and generate MouseEvent

    Break up event and generate MouseEvent

    This adds two controls:

    • A popup menu can specify which types of mouse clicks it wants to react to: left, right, or both.
    • Mouse-drive events includes event metadata. Note that it might not be fully populated (e.g. notification clicks).
    enhancement 
    opened by udoprog 0
  • Improve clipboard logic and window construction

    Improve clipboard logic and window construction

    Following some of the notes in this bug report.

    Now we utilize GetUpdatedClipboardFormats to enumerate available clipboard formats without having to open the clipboard, allowing us to clobber the global resource a bit less than before to determine whether there is something from the clipboard we want.

    I've also implemented a debounce logic, which doesn't permit clipboard events unless they are at least 25ms apart. The retry timer has also been tightened to 25ms.

    enhancement 
    opened by udoprog 0
Releases(0.0.15)
  • 0.0.15(Dec 17, 2023)

    What's Changed

    • Break up event and generate MouseEvent by @udoprog in https://github.com/udoprog/winctx/pull/3

    Full Changelog: https://github.com/udoprog/winctx/compare/0.0.13...0.0.15

    Source code(tar.gz)
    Source code(zip)
  • 0.0.13(Dec 17, 2023)

  • 0.0.12(Dec 17, 2023)

    To improve the ergonomics of the APIs and reduce the number of public types you have to import, most APIs have switched to using builders.

    Full Changelog: https://github.com/udoprog/winctx/compare/0.0.11...0.0.12

    Source code(tar.gz)
    Source code(zip)
  • 0.0.11(Dec 16, 2023)

  • 0.0.10(Dec 16, 2023)

    What's Changed

    • Improve clipboard logic and window construction by @udoprog in https://github.com/udoprog/winctx/pull/1

    Full Changelog: https://github.com/udoprog/winctx/compare/0.0.9...0.0.10

    Source code(tar.gz)
    Source code(zip)
Owner
John-John Tedro
Same username on Telegram, Twitter. setbac on Discord and Twitch. Hit me up if you want to talk!
John-John Tedro
A small Rust library that let's you get position and size of the active window on Windows and MacOS

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

Dmitry Malkov 21 Jan 6, 2023
Utility to tile floating hypr windows on a grid, for those times you don't want a fullscreen tiled window.

hypr-gridtile Have you caught the Hyprland bug? Well then I have an additional gimmick for you! This is a useful little utility which tiles floating w

Derek Anderson 3 Nov 11, 2024
a Rust library implementing safe, lightweight context switches, without relying on kernel services

libfringe libfringe is a library implementing safe, lightweight context switches, without relying on kernel services. It can be used in hosted environ

edef 473 Dec 28, 2022
🐢 Atuin replaces your existing shell history with a SQLite database, and records additional context for your commands

Atuin replaces your existing shell history with a SQLite database, and records additional context for your commands. Additionally, it provides optional and fully encrypted synchronisation of your history between machines, via an Atuin server.

Ellie Huxtable 4.6k Jan 1, 2023
CtrlG - A Command Line Context Switcher

CtrlG - A Command Line Context Switcher CtrlG is a tool to quickly switch contexts to another directory, using a fuzzy finder. If enabled, ctrlg can c

Mat Jones 23 Dec 7, 2022
Solving context limits when working with AI LLM models by implementing a "chunkable" attribute on your prompt structs.

Promptize Promptize attempts to solve the issues with context limits when working with AI systems. It allows a user to add an attribute to their struc

Dan Nelson 5 Jul 18, 2023
Windows-rs - Rust for Windows

Rust for Windows The windows crate lets you call any Windows API past, present, and future using code generated on the fly directly from the metadata

Microsoft 7.7k Dec 30, 2022
Use Thunk to build your Rust program that runs on old Windows platforms, support Windows XP and more!

Use Thunk to build your Rust program that runs on old platforms. Thunk uses VC-LTL5 and YY-Thunks to build programs that support old platforms. So, ho

null 6 May 21, 2023
Switch windows of same app with alt + ` on windows pc.

Windows Switcher Switch windows of same app with alt + ` on windows pc. 250k single file executable downloaded from Github Release. No installation re

null 172 Dec 10, 2022
Check if the process is running inside Windows Subsystem for Linux (Bash on Windows)

is-wsl Check if the process is running inside Windows Subsystem for Linux (Bash on Windows) Inspired by sindresorhus/is-wsl and made for Rust lang. Ca

Sean Larkin 6 Jan 31, 2023