Skip to content

Commit

Permalink
Post-rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopyl committed Mar 25, 2024
1 parent 48a52e8 commit 2ef375f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
19 changes: 15 additions & 4 deletions src/win/win32_window.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::win::util::to_wstr;
use crate::{PhySize, Size, WindowInfo, WindowOpenOptions, WindowScalePolicy};
use raw_window_handle::{RawWindowHandle, Win32WindowHandle};
use raw_window_handle::Win32WindowHandle;
use std::cell::Cell;
use std::ffi::c_void;
use std::ptr::null_mut;
use winapi::shared::minwindef::{DWORD, UINT};
use winapi::shared::windef::{HWND, RECT};
use winapi::um::winuser::{
AdjustWindowRectEx, CreateWindowExW, GetDpiForWindow, KillTimer, PostMessageW,
SetProcessDpiAwarenessContext, SetTimer, SetWindowPos, SWP_NOMOVE, SWP_NOZORDER, WM_USER,
WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW,
AdjustWindowRectEx, CreateWindowExW, GetDpiForWindow, GetFocus, KillTimer, PostMessageW,
SetFocus, SetProcessDpiAwarenessContext, SetTimer, SetWindowPos, SWP_NOMOVE, SWP_NOZORDER,
WM_USER, WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW,
WS_SIZEBOX, WS_VISIBLE,
};

Expand Down Expand Up @@ -170,6 +170,17 @@ impl Win32Window {
self.current_size.set(new_size);
}

pub fn has_focus(&self) -> bool {
let focused_window = unsafe { GetFocus() };
focused_window == self.handle
}

pub fn focus(&self) {
unsafe {
SetFocus(self.handle);
}
}

pub fn handle(&self) -> HWND {
self.handle
}
Expand Down
8 changes: 8 additions & 0 deletions src/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ impl Window {
self.defer_task(WindowTask::Resize(size))
}

pub fn has_focus(&self) -> bool {
self.win32_window.has_focus()
}

pub fn focus(&self) {
self.win32_window.focus()
}

pub fn set_mouse_cursor(&self, _mouse_cursor: MouseCursor) {
todo!()
}
Expand Down
8 changes: 4 additions & 4 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ impl Window {
self.inner().set_mouse_cursor(cursor);
}

pub fn has_focus(&mut self) -> bool {
self.window.has_focus()
pub fn has_focus(&self) -> bool {
self.inner().has_focus()
}

pub fn focus(&mut self) {
self.window.focus()
pub fn focus(&self) {
self.inner().focus()
}

/// If provided, then an OpenGL context will be created for this window. You'll be able to
Expand Down

0 comments on commit 2ef375f

Please sign in to comment.