1 | /*
|
---|
2 | * Copyright 2012, Haiku, Inc. All Rightrs Reserved
|
---|
3 | * Distributed under the terms of the MIT License.
|
---|
4 | *
|
---|
5 | * Authors:
|
---|
6 | * Philippe Saint-Pierre <stpere@gmail.com>
|
---|
7 | * Pete Goodeve <pete.goodeve
|
---|
8 | */
|
---|
9 |
|
---|
10 |
|
---|
11 | #include <OS.h>
|
---|
12 | #include <InputServerFilter.h>
|
---|
13 | #include <InterfaceDefs.h>
|
---|
14 |
|
---|
15 | #include <new>
|
---|
16 |
|
---|
17 |
|
---|
18 | class CapsLockFilter : public BInputServerFilter {
|
---|
19 | public:
|
---|
20 | CapsLockFilter();
|
---|
21 |
|
---|
22 | virtual filter_result Filter(BMessage* message, BList*);
|
---|
23 |
|
---|
24 | private:
|
---|
25 | bool fCapsLocked;
|
---|
26 | };
|
---|
27 |
|
---|
28 |
|
---|
29 | CapsLockFilter::CapsLockFilter(): fCapsLocked(false)
|
---|
30 | {
|
---|
31 | }
|
---|
32 |
|
---|
33 |
|
---|
34 | filter_result
|
---|
35 | CapsLockFilter::Filter(BMessage* message, BList*)
|
---|
36 | {
|
---|
37 | if (message->what == B_MODIFIERS_CHANGED) {
|
---|
38 | int32 modifiers;
|
---|
39 | message->FindInt32("modifiers", &modifiers);
|
---|
40 | if (modifiers & B_CAPS_LOCK) {
|
---|
41 | if (!fCapsLocked && !(modifiers & B_CONTROL_KEY)) {
|
---|
42 | modifiers &= B_SCROLL_LOCK | B_NUM_LOCK;
|
---|
43 | // clear CAPS -- ignore SHIFT etc.
|
---|
44 | set_keyboard_locks(modifiers);
|
---|
45 | return B_SKIP_MESSAGE;
|
---|
46 | } else
|
---|
47 | fCapsLocked = true;
|
---|
48 | } else
|
---|
49 | fCapsLocked = false;
|
---|
50 | }
|
---|
51 |
|
---|
52 | return B_DISPATCH_MESSAGE;
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | extern "C" _EXPORT BInputServerFilter* instantiate_input_filter();
|
---|
57 |
|
---|
58 | BInputServerFilter*
|
---|
59 | instantiate_input_filter()
|
---|
60 | {
|
---|
61 | return new (std::nothrow) CapsLockFilter();
|
---|
62 | }
|
---|