Compare commits

..

5 Commits

Author SHA1 Message Date
Kirill Chibisov
e5260da95b Winit version 0.28.0 2023-02-02 06:52:53 +03:00
Kirill Chibisov
3fd73848dd On macOS, fix Ime::Commit persisting
This commit clears the currently marked text on `Ime::Commit`, so
normal `ReceivedCharacter` input can continue.
2023-02-01 18:08:25 +03:00
Samuel
4e1c46fe9e Windows: Fix Alt key press entering menu loop (#2665) 2023-02-01 12:03:58 +01:00
Jack Wright
180a4c7a16 Add WindowExtMacOS::{set_,}option_as_alt
This adds an ability to control left and right `Option` keys to be
treated as `Alt`, thus not producing diacritical marks.

Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
2023-01-31 12:35:49 +03:00
Kirill Chibisov
13613931cf Implement serde ser/deser for Theme 2023-01-31 12:14:15 +03:00
9 changed files with 32 additions and 17 deletions

View File

@@ -8,6 +8,9 @@ And please only add new entries to the top of this list, right below the `# Unre
# Unreleased
# 0.28.0
- On macOS, fixed `Ime::Commit` persisting for all input after interacting with `Ime`.
- On macOS, added `WindowExtMacOS::option_as_alt` and `WindowExtMacOS::set_option_as_alt`.
- On Windows, fix window size for maximized, undecorated windows.
- On Windows and macOS, add `WindowBuilder::with_active`.

View File

@@ -1,6 +1,6 @@
[package]
name = "winit"
version = "0.27.5"
version = "0.28.0"
authors = ["The winit contributors", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "Cross-platform window creation library."
edition = "2021"

View File

@@ -6,7 +6,7 @@
```toml
[dependencies]
winit = "0.27.5"
winit = "0.28.0"
```
## [Documentation](https://docs.rs/winit)

View File

@@ -23,7 +23,7 @@ fn main() {
.build(&event_loop)
.unwrap();
let mut option_as_alt = OptionAsAlt::None;
let mut option_as_alt = window.option_as_alt();
event_loop.run(move |event, _, control_flow| {
control_flow.set_wait();
@@ -46,9 +46,7 @@ fn main() {
OptionAsAlt::Both => OptionAsAlt::None,
};
println!(
"Received Mouse click, toggling option_as_alt to: {option_as_alt:?}"
);
println!("Received Mouse click, toggling option_as_alt to: {option_as_alt:?}");
window.set_option_as_alt(option_as_alt);
}
WindowEvent::ReceivedCharacter(c) => println!("ReceivedCharacter: {c:?}"),

View File

@@ -1,6 +1,7 @@
use objc2::rc::Id;
use std::os::raw::c_void;
use objc2::rc::Id;
use crate::{
event_loop::{EventLoopBuilder, EventLoopWindowTarget},
monitor::MonitorHandle,
@@ -348,6 +349,7 @@ impl<T> EventLoopWindowTargetExtMacOS for EventLoopWindowTarget<T> {
///
/// The default is `None`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum OptionAsAlt {
/// The left `Option` key is treated as `Alt`.
OnlyLeft,

View File

@@ -7,9 +7,6 @@ use objc2::foundation::{
use objc2::rc::{Id, Shared};
use objc2::{extern_class, extern_methods, msg_send_id, ClassType};
pub const NX_DEVICELALTKEYMASK: u32 = 0x00000020;
pub const NX_DEVICERALTKEYMASK: u32 = 0x00000040;
extern_class!(
#[derive(Debug, PartialEq, Eq, Hash)]
pub(crate) struct NSEvent;
@@ -189,6 +186,10 @@ unsafe impl NSCopying for NSEvent {
type Output = NSEvent;
}
// The values are from the https://github.com/apple-oss-distributions/IOHIDFamily/blob/19666c840a6d896468416ff0007040a10b7b46b8/IOHIDSystem/IOKit/hidsystem/IOLLEvent.h#L258-L259
const NX_DEVICELALTKEYMASK: u32 = 0x00000020;
const NX_DEVICERALTKEYMASK: u32 = 0x00000040;
bitflags! {
pub struct NSEventModifierFlags: NSUInteger {
const NSAlphaShiftKeyMask = 1 << 16;

View File

@@ -424,7 +424,8 @@ declare_class!(
let is_control = string.chars().next().map_or(false, |c| c.is_control());
if self.is_ime_enabled() && !is_control {
// Commit only if we have marked text.
if self.hasMarkedText() && self.is_ime_enabled() && !is_control {
self.queue_event(WindowEvent::Ime(Ime::Preedit(String::new(), None)));
self.queue_event(WindowEvent::Ime(Ime::Commit(string)));
self.state.ime_state = ImeState::Commited;
@@ -471,7 +472,8 @@ declare_class!(
OptionAsAlt::OnlyRight if event.ralt_pressed() => true,
OptionAsAlt::Both if ev_mods.alt() => true,
_ => false,
} && !ev_mods.ctrl();
} && !ev_mods.ctrl()
&& !ev_mods.logo();
let characters = get_characters(event, ignore_alt_characters);
self.state.forward_key_to_app = false;
@@ -495,6 +497,8 @@ declare_class!(
// If the text was commited we must treat the next keyboard event as IME related.
if self.state.ime_state == ImeState::Commited {
// Remove any marked text, so normal input can continue.
*self.marked_text = NSMutableAttributedString::new();
self.state.ime_state = ImeState::Enabled;
text_commited = true;
}

View File

@@ -50,10 +50,10 @@ use windows_sys::Win32::{
},
WindowsAndMessaging::{
CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW, GetCursorPos,
GetMessageW, LoadCursorW, MsgWaitForMultipleObjectsEx, PeekMessageW, PostMessageW,
PostThreadMessageW, RegisterClassExW, RegisterWindowMessageA, SetCursor, SetWindowPos,
TranslateMessage, CREATESTRUCTW, GIDC_ARRIVAL, GIDC_REMOVAL, GWL_STYLE, GWL_USERDATA,
HTCAPTION, HTCLIENT, MINMAXINFO, MNC_CLOSE, MSG, MWMO_INPUTAVAILABLE,
GetMenu, GetMessageW, LoadCursorW, MsgWaitForMultipleObjectsEx, PeekMessageW,
PostMessageW, PostThreadMessageW, RegisterClassExW, RegisterWindowMessageA, SetCursor,
SetWindowPos, TranslateMessage, CREATESTRUCTW, GIDC_ARRIVAL, GIDC_REMOVAL, GWL_STYLE,
GWL_USERDATA, HTCAPTION, HTCLIENT, MINMAXINFO, MNC_CLOSE, MSG, MWMO_INPUTAVAILABLE,
NCCALCSIZE_PARAMS, PM_NOREMOVE, PM_QS_PAINT, PM_REMOVE, PT_PEN, PT_TOUCH, QS_ALLEVENTS,
RI_KEY_E0, RI_KEY_E1, RI_MOUSE_WHEEL, SC_MINIMIZE, SC_RESTORE, SIZE_MAXIMIZED,
SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOSIZE, SWP_NOZORDER, WHEEL_DELTA, WINDOWPOS,
@@ -1550,7 +1550,9 @@ unsafe fn public_window_callback_inner<T: 'static>(
},
});
}
if msg == WM_SYSKEYUP {
if msg == WM_SYSKEYUP && GetMenu(window) != 0 {
// let Windows handle event if the window has a native menu, a modal event loop
// is started here on Alt key up.
DefWindowProcW(window, msg, wparam, lparam)
} else {
0

View File

@@ -1490,9 +1490,14 @@ pub enum Fullscreen {
Borderless(Option<MonitorHandle>),
}
/// The theme variant to use.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Theme {
/// Use the light variant.
Light,
/// Use the dark variant.
Dark,
}