1 | /*
|
---|
2 | * Copyright 2008, Haiku.
|
---|
3 | * Distributed under the terms of the MIT License.
|
---|
4 | *
|
---|
5 | * Authors:
|
---|
6 | * Philippe Saint-Pierre < stpere@gmail.com >
|
---|
7 | */
|
---|
8 |
|
---|
9 |
|
---|
10 | #include "CapsLockFilter.h"
|
---|
11 |
|
---|
12 | #include <Application.h>
|
---|
13 | #include <OS.h>
|
---|
14 | #include <support/Beep.h>
|
---|
15 | #include <interface/Alert.h>
|
---|
16 |
|
---|
17 | #include <Debug.h>
|
---|
18 |
|
---|
19 | #include <new>
|
---|
20 |
|
---|
21 | #define CALLED() SERIAL_PRINT(("%s\n", __PRETTY_FUNCTION__))
|
---|
22 |
|
---|
23 | extern "C" _EXPORT BInputServerFilter* instantiate_input_filter();
|
---|
24 |
|
---|
25 | /** required C func to build the IS Filter */
|
---|
26 |
|
---|
27 |
|
---|
28 | BInputServerFilter*
|
---|
29 | instantiate_input_filter()
|
---|
30 | {
|
---|
31 | return new (std::nothrow) CapsLockFilter();
|
---|
32 | }
|
---|
33 |
|
---|
34 |
|
---|
35 | // #pragma mark -
|
---|
36 |
|
---|
37 |
|
---|
38 | CapsLockFilter::CapsLockFilter(): _shiftPressed(false)
|
---|
39 | {
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | CapsLockFilter::~CapsLockFilter()
|
---|
44 | {
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | filter_result
|
---|
49 | CapsLockFilter::Filter(BMessage *message, BList *outList)
|
---|
50 | {
|
---|
51 | switch (message->what) {
|
---|
52 | case B_KEY_UP:
|
---|
53 | {
|
---|
54 | int32 key;
|
---|
55 | if (message->FindInt32("key", &key) == B_OK && key == 0x4b)
|
---|
56 | _shiftPressed = false;
|
---|
57 | }
|
---|
58 | break;
|
---|
59 | case B_KEY_DOWN:
|
---|
60 | {
|
---|
61 | int32 key;
|
---|
62 | if (message->FindInt32("key", &key) == B_OK && key == 0x4b)
|
---|
63 | _shiftPressed = true;
|
---|
64 | }
|
---|
65 | break;
|
---|
66 | case B_MODIFIERS_CHANGED:
|
---|
67 | {
|
---|
68 | int32 modifiers;
|
---|
69 | if (!_shiftPressed && message->FindInt32("modifiers", &modifiers) == B_OK && (modifiers & B_CAPS_LOCK ) ) {
|
---|
70 | (new BAlert("Hey", "capslock is disabled.\n", "ok"))->Go(NULL);
|
---|
71 | }
|
---|
72 | return B_SKIP_MESSAGE;
|
---|
73 | // I return always B_SKIP_MESSAGE only to confirm my boolean formula isn't in cause..
|
---|
74 | }
|
---|
75 | break;
|
---|
76 | }
|
---|
77 |
|
---|
78 | return B_DISPATCH_MESSAGE;
|
---|
79 | }
|
---|
80 |
|
---|