Skip to content

Commit

Permalink
feat: support per-monitor dpi awareness v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ACK72 committed Sep 18, 2023
1 parent 915ac9d commit 190566e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "PlayBridge"
version = "0.2.2"
version = "0.2.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
image = "*"
spin_sleep = "*"
windows = {version = "*", features = ["Win32_Foundation", "Win32_Graphics_Gdi", "Win32_Storage_Xps", "Win32_UI_WindowsAndMessaging"]}
windows = {version = "*", features = ["Win32_Foundation", "Win32_Graphics_Gdi", "Win32_Storage_Xps", "Win32_UI_HiDpi", "Win32_UI_WindowsAndMessaging"]}
17 changes: 9 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{env, mem, io::*, time::Duration};
use image::{DynamicImage, RgbaImage, codecs::png::PngEncoder, imageops::FilterType};
use windows::{
core::*, Win32::{Foundation::*, Graphics::Gdi::*, Storage::Xps::*, UI::WindowsAndMessaging::*}
core::*, Win32::{Foundation::*, Graphics::Gdi::*, Storage::Xps::*, UI::HiDpi::*, UI::WindowsAndMessaging::*}
};

const TITLE: PCWSTR = w!("명일방주");
Expand All @@ -11,6 +11,8 @@ const HEIGHT: f32 = 720.0;
const POLL: i32 = 1000 / 250;

fn main() {
unsafe { SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2).unwrap() };

let args: Vec<String> = env::args().collect();
let command = args.join(" ");

Expand Down Expand Up @@ -118,15 +120,14 @@ fn input_keyevent(keycode: i32) {
}

fn capture() -> DynamicImage {
let (main, w, h) = get_gpg_info();
let main = unsafe { FindWindowW(PCWSTR::null(), TITLE) };
let hwnd = unsafe { FindWindowExA(main, HWND(0), s!("subWin"), PCSTR::null()) };

let hdc = unsafe { GetDC(HWND(0)) };
let logical_height = unsafe { GetDeviceCaps( hdc, VERTRES) };
let physical_height = unsafe { GetDeviceCaps( hdc, DESKTOPVERTRES) };
let dpi = physical_height as f32 / logical_height as f32;
let mut rect = RECT::default();
let _ = unsafe { GetWindowRect(hwnd, &mut rect) };

let width = (w as f32 * dpi).ceil() as i32;
let height = (h as f32 * dpi).ceil() as i32;
let width = rect.right - rect.left;
let height = rect.bottom - rect.top;

let mut binfo = BITMAPINFO {
bmiHeader: BITMAPINFOHEADER {
Expand Down

0 comments on commit 190566e

Please sign in to comment.