Skip to content

Commit 13e18c4

Browse files
committed
Various minor fixes
1 parent 911bfc1 commit 13e18c4

6 files changed

Lines changed: 42 additions & 7 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ uuid = { version = "1", features = ["v4"], default-features = false }
3333
[features]
3434
default = ["runas"]
3535
runas = []
36+
doc-cfg = []
3637

3738
[package.metadata.docs.rs]
3839
targets = ["x86_64-pc-windows-msvc"]
40+
all-features = true

src/hotkey.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ pub enum HotkeyModifier {
3131
/// A set of [`HotkeyModifier`]s.
3232
pub type HotkeyModifiers = BitFlags<HotkeyModifier>;
3333

34-
impl std::fmt::Display for HotkeyModifier {
35-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34+
impl fmt::Display for HotkeyModifier {
35+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3636
write!(f, "{}", self.to_str())
3737
}
3838
}

src/icon.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
fs,
2+
fmt, fs,
33
path::{Path, PathBuf},
44
};
55

@@ -32,6 +32,12 @@ impl Icon {
3232
}
3333
}
3434

35+
impl fmt::Display for Icon {
36+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37+
write!(f, "{}@{}", self.path.display(), self.index)
38+
}
39+
}
40+
3541
impl From<PathBuf> for Icon {
3642
fn from(path: PathBuf) -> Self {
3743
Self::new(path)

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![cfg(windows)]
2+
#![cfg_attr(feature = "doc-cfg", featre(doc_cfg))]
23
#![warn(clippy::pedantic)]
34
#![allow(
45
clippy::missing_errors_doc,

src/shortcut.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ use windows::{
1515
core::{Interface, PCWSTR},
1616
};
1717

18+
#[cfg(feature = "runas")]
19+
use crate::runas;
1820
use crate::{
1921
Hotkey, Icon, Result, WindowState,
2022
buf_utils::{com_get_optional_path, com_get_optional_string},
2123
com::{self, ComResultExt},
2224
};
23-
#[cfg(feature = "runas")]
24-
use crate::runas;
2525

2626
/// Represents a Windows shortcut (`.lnk`) file.
2727
///

src/virtual_key.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const fn convert(key: VIRTUAL_KEY) -> u8 {
1010
}
1111

1212
/// Represents a Win32 virtual-key code.
13-
/// Unknown values are captured in the `Other(u8)` variant.
13+
///
14+
/// Unknown values are captured in the [`Other`](VirtualKey::Other) variant.
15+
///
1416
/// See: <https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes>
1517
#[repr(u8)]
1618
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
@@ -197,7 +199,7 @@ impl VirtualKey {
197199
/// Return a short, human-friendly string for this key.
198200
///
199201
/// For known keys this returns a borrowed `&'static str`. For unknown
200-
/// values (`Other(u8)`) this returns an owned string like `VK_0xNN`.
202+
/// values ([`Other`](VirtualKey::Other) this returns an owned string like `VK_0xNN`.
201203
#[must_use]
202204
pub fn to_str(&self) -> Cow<'static, str> {
203205
match self {
@@ -323,6 +325,30 @@ impl VirtualKey {
323325
pub fn from_raw(vk: u8) -> Self {
324326
Self::from_primitive(vk)
325327
}
328+
329+
#[must_use]
330+
pub fn is_modifier(self) -> bool {
331+
matches!(
332+
self,
333+
Self::Shift
334+
| Self::Control
335+
| Self::Menu
336+
| Self::LShift
337+
| Self::RShift
338+
| Self::LControl
339+
| Self::RControl
340+
| Self::LMenu
341+
| Self::RMenu
342+
)
343+
}
344+
345+
#[must_use]
346+
pub fn is_mouse(self) -> bool {
347+
matches!(
348+
self,
349+
Self::LButton | Self::RButton | Self::MButton | Self::XButton1 | Self::XButton2
350+
)
351+
}
326352
}
327353

328354
impl fmt::Display for VirtualKey {

0 commit comments

Comments
 (0)