Skip to content

Commit 2ef375f

Browse files
committed
Post-rebase fixes
1 parent 48a52e8 commit 2ef375f

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/win/win32_window.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::win::util::to_wstr;
22
use crate::{PhySize, Size, WindowInfo, WindowOpenOptions, WindowScalePolicy};
3-
use raw_window_handle::{RawWindowHandle, Win32WindowHandle};
3+
use raw_window_handle::Win32WindowHandle;
44
use std::cell::Cell;
55
use std::ffi::c_void;
66
use std::ptr::null_mut;
77
use winapi::shared::minwindef::{DWORD, UINT};
88
use winapi::shared::windef::{HWND, RECT};
99
use winapi::um::winuser::{
10-
AdjustWindowRectEx, CreateWindowExW, GetDpiForWindow, KillTimer, PostMessageW,
11-
SetProcessDpiAwarenessContext, SetTimer, SetWindowPos, SWP_NOMOVE, SWP_NOZORDER, WM_USER,
12-
WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW,
10+
AdjustWindowRectEx, CreateWindowExW, GetDpiForWindow, GetFocus, KillTimer, PostMessageW,
11+
SetFocus, SetProcessDpiAwarenessContext, SetTimer, SetWindowPos, SWP_NOMOVE, SWP_NOZORDER,
12+
WM_USER, WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW,
1313
WS_SIZEBOX, WS_VISIBLE,
1414
};
1515

@@ -170,6 +170,17 @@ impl Win32Window {
170170
self.current_size.set(new_size);
171171
}
172172

173+
pub fn has_focus(&self) -> bool {
174+
let focused_window = unsafe { GetFocus() };
175+
focused_window == self.handle
176+
}
177+
178+
pub fn focus(&self) {
179+
unsafe {
180+
SetFocus(self.handle);
181+
}
182+
}
183+
173184
pub fn handle(&self) -> HWND {
174185
self.handle
175186
}

src/win/window.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ impl Window {
9898
self.defer_task(WindowTask::Resize(size))
9999
}
100100

101+
pub fn has_focus(&self) -> bool {
102+
self.win32_window.has_focus()
103+
}
104+
105+
pub fn focus(&self) {
106+
self.win32_window.focus()
107+
}
108+
101109
pub fn set_mouse_cursor(&self, _mouse_cursor: MouseCursor) {
102110
todo!()
103111
}

src/window.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ impl Window {
103103
self.inner().set_mouse_cursor(cursor);
104104
}
105105

106-
pub fn has_focus(&mut self) -> bool {
107-
self.window.has_focus()
106+
pub fn has_focus(&self) -> bool {
107+
self.inner().has_focus()
108108
}
109109

110-
pub fn focus(&mut self) {
111-
self.window.focus()
110+
pub fn focus(&self) {
111+
self.inner().focus()
112112
}
113113

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

0 commit comments

Comments
 (0)