Skip to main content

Crate tauri_plugin_steam_overlay_surface

Crate tauri_plugin_steam_overlay_surface 

Source
Expand description

Steam in-game overlay (Shift+Tab) support for Tauri apps.

Steam’s overlay works by injecting gameoverlayrenderer64.dll into the game process and hooking the graphics API’s Present call. A Tauri app never creates a swapchain in its own process (WebView2/WebKit render out-of-process and composite via the OS), so the hook finds nothing and Shift+Tab is a no-op.

This plugin gives Steam a target: a transparent, click-through window covering your main window, with a real in-process wgpu swapchain presenting empty (fully transparent) frames at vsync. Steam composites its overlay UI and notification toasts into those frames at Present time.

§Usage

ⓘ
// 1. In main(), SteamAPI_Init BEFORE building the Tauri app: the
//    injected DLL must be resident before the plugin creates its wgpu
//    device.
let steam = steamworks::Client::init_app(480).ok();

tauri::Builder::default()
  // 2. Register the plugin. It spawns the decoy surface as soon as
  //    your main window exists.
  .plugin(tauri_plugin_steam_overlay_surface::init())
  .setup(move |app| {
    // 3. Forward Steam's GameOverlayActivated callback so the plugin
    //    can hand input to the overlay and back to your game.
    if let Some(client) = &steam {
      let handle = app.handle().clone();
      let cb = client.register_callback(
        move |ev: steamworks::GameOverlayActivated| {
          tauri_plugin_steam_overlay_surface::on_overlay_activated(&handle, ev.active);
        },
      );
      std::mem::forget(cb); // keep registered for the app's lifetime

      // 4. Hook Steam screenshots: the decoy's backbuffer never contains
      //    the game, so Steam's default F12 grab captures nothing.
      //    Provide live frames instead (see capture_screenshot_png).
      client.screenshots().hook_screenshots(true);
      let handle = app.handle().clone();
      let shot_client = client.clone();
      let cb = client.register_callback(move |_: steamworks::screenshots::ScreenshotRequested| {
        if let Some(shot) = tauri_plugin_steam_overlay_surface::capture_screenshot_png(&handle) {
          let _ = shot_client.screenshots().add_screenshot_to_library(
            &shot.path, None, shot.width as i32, shot.height as i32);
        }
      });
      std::mem::forget(cb);
    }
    Ok(())
  })
  .run(tauri::generate_context!())
  .unwrap();

The plugin deliberately has no steamworks dependency — your app owns Steam init and its callback pump, and forwards the one callback the plugin needs. This avoids version coupling between the plugin and your Steamworks bindings.

Requires tauri’s unstable feature (raw, webview-less windows). Windows-only today; on other platforms every call is a graceful no-op.

Structs§

Builder
Configures the plugin before registration.
CapturedScreenshot
A live game frame written to disk as PNG, ready for ISteamScreenshots::AddScreenshotToLibrary.

Constants§

OVERLAY_LABEL
Label of the decoy window this plugin creates.

Functions§

capture_screenshot_png
Capture the configured main window’s live content and write it to a temp PNG. Returns None on capture/encode failure or on non-Windows.
init
Initialize the plugin with default configuration.
on_overlay_activated
Forward Steam’s GameOverlayActivated callback here.
surface_active
Whether the decoy surface is up and presenting. true + Steam’s is_overlay_enabled() means Shift+Tab should visibly work — useful for a settings/QA readout.