-
Notifications
You must be signed in to change notification settings - Fork 0
/
scroll_ifilter.cpp
159 lines (126 loc) · 3.49 KB
/
scroll_ifilter.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <InputServerFilter.h>
#include <Message.h>
#include <Messenger.h>
#include <String.h>
#include <Window.h>
class ScrollInputFilter : public BInputServerFilter
{
public:
ScrollInputFilter();
virtual ~ScrollInputFilter();
virtual status_t InitCheck();
virtual filter_result Filter(BMessage *message, BList *outList);
private:
bool fInitScrolling;
BPoint fCurrentMousePosition;
#ifdef DCLOG
void SendDebugString(BString& str);
#endif
};
ScrollInputFilter::ScrollInputFilter()
{
#ifdef DCLOG
BString log("ScrollInputFilter()");
SendDebugString(log);
#endif
fInitScrolling = false;
}
ScrollInputFilter::~ScrollInputFilter()
{
}
status_t ScrollInputFilter::InitCheck()
{
#ifdef DCLOG
BString log("InitCheck()");
SendDebugString(log);
#endif
return B_OK;
}
filter_result
ScrollInputFilter::Filter(BMessage *message, BList *outList)
{
BString log;
if (message->what==B_MOUSE_DOWN) {
#ifdef DCLOG
log = "B_MOUSE_DOWN: start";
SendDebugString(log);
#endif
fInitScrolling = false;
int32 buttons;
if (message->FindInt32("buttons", &buttons) != B_OK)
return B_DISPATCH_MESSAGE;
if (buttons != B_PRIMARY_MOUSE_BUTTON)
return B_DISPATCH_MESSAGE;
if (message->FindPoint("where", &fCurrentMousePosition) != B_OK)
return B_DISPATCH_MESSAGE;
#ifdef DCLOG
log << "current_mouse_position (" << current_mouse_position.x << ","
<< current_mouse_position.y << ")";
SendDebugString(log);
#endif
int32 modifiers;
if (message->FindInt32("modifiers", &modifiers) != B_OK)
return B_DISPATCH_MESSAGE;
if (!(modifiers & (B_COMMAND_KEY | B_SHIFT_KEY)))
return B_DISPATCH_MESSAGE;
fInitScrolling = true;
#ifdef DCLOG
log = "B_MOUSE_DOWN: init_scrolling = true";
SendDebugString(log);
#endif
return B_SKIP_MESSAGE;
}
if (message->what==B_MOUSE_UP) {
fInitScrolling = false;
#ifdef DCLOG
log = "B_MOUSE_UP: start_scrolling_combo = false";
SendDebugString(log);
#endif
return B_DISPATCH_MESSAGE;
}
if (message->what==B_MOUSE_MOVED && fInitScrolling==true) {
#ifdef DCLOG
log = "B_MOUSE_MOVED: scrolling simulation initiated";
SendDebugString(log);
#endif
BPoint newMousePosition;
float deltay;
if (message->FindPoint("where", &newMousePosition) != B_OK)
return B_DISPATCH_MESSAGE;
deltay = newMousePosition.y - fCurrentMousePosition.y;
#ifdef DCLOG
log = "B_MOUSE_MOVED: ";
log << "fCurrentMousePosition (" << fCurrentMousePosition.y << " - "
<< "newMousePosition (" << newMousePosition.y;
log << " - FindPoint(where): " << deltay;
SendDebugString(log);
#endif
// TODO: adding the message to outList fires a kernel panic
// investigate further and do it properly
// BMessage wheel_message(B_MOUSE_WHEEL_CHANGED);
// wheel_message.AddFloat("be:wheel_delta_y",deltay);
// outList->AddItem(&wheel_message);
message->what = B_MOUSE_WHEEL_CHANGED;
message->AddFloat("be:wheel_delta_y",deltay);
#ifdef DCLOG
log = "B_MOUSE_MOVED: outList->AddItem(&wheel_message)";
SendDebugString(log);
#endif
return B_DISPATCH_MESSAGE;
}
return B_DISPATCH_MESSAGE;
}
#ifdef DCLOG
void
ScrollInputFilter::SendDebugString(BString& str) {
BMessenger messenger("application/x-vnd.Genio-DebugConsole");
BMessage message('dbug');
message.AddString("dbug_text", str);
message.AddString("dbug_source", "scroll_ifilter");
if (messenger.IsValid())
messenger.SendMessage(&message);
}
#endif
extern "C" BInputServerFilter* instantiate_input_filter() {
return new(std::nothrow) ScrollInputFilter();
}