-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathNSEventModifierFlagsHolder.h
More file actions
65 lines (45 loc) · 2.36 KB
/
NSEventModifierFlagsHolder.h
File metadata and controls
65 lines (45 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (C) 2017-2024 Michael Kazakov. Subject to GNU General Public License version 3.
#pragma once
#include <cstdint>
#ifdef __OBJC__
#include <AppKit/AppKit.h>
#endif
namespace nc::utility {
struct NSEventModifierFlagsHolder {
std::uint8_t flags = 0;
constexpr NSEventModifierFlagsHolder() noexcept = default;
#ifdef __OBJC__
constexpr NSEventModifierFlagsHolder(NSEventModifierFlags _flags) noexcept
#else
constexpr NSEventModifierFlagsHolder(unsigned long _flags) noexcept
#endif
: flags(((_flags & flag_mask) >> offset) & 0xFF)
{
}
[[nodiscard]] constexpr bool is_empty() const noexcept { return flags == 0; }
[[nodiscard]] constexpr bool is_capslock() const noexcept { return flags & (flag_caps_lock >> offset); }
[[nodiscard]] constexpr bool is_shift() const noexcept { return flags & (flag_shift >> offset); }
[[nodiscard]] constexpr bool is_control() const noexcept { return flags & (flag_control >> offset); }
[[nodiscard]] constexpr bool is_option() const noexcept { return flags & (flag_option >> offset); }
[[nodiscard]] constexpr bool is_command() const noexcept { return flags & (flag_command >> offset); }
[[nodiscard]] constexpr bool is_numpad() const noexcept { return flags & (flag_numeric_pad >> offset); }
[[nodiscard]] constexpr bool is_help() const noexcept { return flags & (flag_help >> offset); }
[[nodiscard]] constexpr bool is_func() const noexcept { return flags & (flag_function >> offset); }
constexpr bool operator==(const NSEventModifierFlagsHolder &_rhs) const noexcept = default;
#ifdef __OBJC__
constexpr operator NSEventModifierFlags() const noexcept { return static_cast<std::uint64_t>(flags) << offset; }
#endif
private:
static void check_flag_values();
static constexpr int offset = 16;
static constexpr unsigned long flag_caps_lock = 1ul << 16;
static constexpr unsigned long flag_shift = 1ul << 17;
static constexpr unsigned long flag_control = 1ul << 18;
static constexpr unsigned long flag_option = 1ul << 19;
static constexpr unsigned long flag_command = 1ul << 20;
static constexpr unsigned long flag_numeric_pad = 1ul << 21;
static constexpr unsigned long flag_help = 1ul << 22;
static constexpr unsigned long flag_function = 1ul << 23;
static constexpr unsigned long flag_mask = 0xffff0000ul;
};
} // namespace nc::utility