Skip to content

Commit af5bac6

Browse files
committed
Add IntelliMouse support to PS/2 driver & support scroll-wheel events
1 parent f94f9f9 commit af5bac6

File tree

25 files changed

+164
-96
lines changed

25 files changed

+164
-96
lines changed

applications/desktop/src/background.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ void background_t::init()
5757
{
5858
onMouseRelease(position);
5959
}
60+
else if(e->type == G_MOUSE_EVENT_LEAVE)
61+
{
62+
onMouseRelease(position);
63+
}
6064
});
6165

6266
selection = g_selection::create();
@@ -217,7 +221,7 @@ void background_t::paint()
217221
auto bounds = this->getBounds();
218222

219223
srand(g_millis());
220-
static int r = rand() % 128 + 50;
224+
static int r = rand() % 100 + 50;
221225

222226
cairo_pattern_t* gradient = cairo_pattern_create_linear(bounds.width * 0.4, 0, bounds.width * 0.8,
223227
bounds.height);

applications/desktop/src/background.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class background_t : virtual public g_canvas
5050
public:
5151
explicit background_t(g_ui_component_id id):
5252
g_component(id),
53-
g_canvas(id), dragItems(false)
53+
g_canvas(id), dragItems(false),
54+
g_focusable_component(id)
5455
{
5556
}
5657

applications/desktop/src/item.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
item_t::item_t(uint32_t id):
2929
g_component(id),
30-
g_canvas(id)
30+
g_canvas(id),
31+
g_focusable_component(id)
3132
{
3233
this->setBufferListener([this]()
3334
{

applications/desktop/src/taskbar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
g_font* font = nullptr;
3131

3232
taskbar_t::taskbar_t(g_ui_component_id id):
33-
g_component(id), g_canvas(id)
33+
g_component(id), g_canvas(id), g_focusable_component(id)
3434
{
3535
textLayoutBuffer = g_text_layouter::getInstance()->initializeBuffer();
3636
}

applications/libinput/inc/libinput/mouse/mouse.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct g_mouse_info
3232
bool button1 = false;
3333
bool button2 = false;
3434
bool button3 = false;
35+
int scroll = 0;
3536
};
3637

3738
class g_mouse

applications/libinput/src/mouse.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ g_mouse_info g_mouse::readMouse(g_fd in)
3535
e.button1 = (packet.flags & (1 << 0));
3636
e.button2 = (packet.flags & (1 << 1));
3737
e.button3 = (packet.flags & (1 << 2));
38+
e.scroll = packet.scroll;
3839
}
3940
return e;
4041
}

applications/libps2/inc/libps2/ps2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ typedef uint8_t ps2_status_t;
3535
/**
3636
* Initializes the PS2 handling.
3737
*/
38-
ps2_status_t ps2Initialize(void(*mouseCallback)(int16_t, int16_t, uint8_t), void(*keyboardCallback)(uint8_t));
38+
ps2_status_t ps2Initialize(void(*mouseCallback)(int16_t, int16_t, uint8_t, int8_t), void(*keyboardCallback)(uint8_t));
3939

4040
#endif

applications/libps2/src/ps2.cpp

Lines changed: 79 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@
2424
#include <ghost.h>
2525
#include <stdio.h>
2626

27-
uint8_t mouse_packet_number = 0;
28-
uint8_t mouse_packet_buffer[4];
27+
uint8_t mousePacketNumber = 0;
28+
uint8_t mousePacketBuffer[4];
29+
bool intelliMouseMode = false; // 4-byte sequences
2930

3031
g_fd keyIrqIn;
3132
g_fd mouseIrqIn;
3233

33-
uint32_t packets_count = 0;
34+
uint32_t packetCount = 0;
3435

35-
void (*registeredMouseCallback)(int16_t, int16_t, uint8_t);
36+
void (*registeredMouseCallback)(int16_t, int16_t, uint8_t, int8_t);
3637
void (*registeredKeyboardCallback)(uint8_t);
3738

38-
ps2_status_t ps2Initialize(void (*mouseCallback)(int16_t, int16_t, uint8_t),
39+
void ps2HandlePacket();
40+
41+
ps2_status_t ps2Initialize(void (*mouseCallback)(int16_t, int16_t, uint8_t, int8_t),
3942
void (*keyboardCallback)(uint8_t))
4043
{
4144

@@ -113,7 +116,7 @@ void ps2CheckForData()
113116
ps2HandleMouseData(value);
114117
}
115118

116-
++packets_count;
119+
++packetCount;
117120
}
118121
}
119122

@@ -158,56 +161,85 @@ ps2_status_t ps2InitializeMouse()
158161
return G_PS2_STATUS_FAILED_INITIALIZE;
159162
}
160163

164+
// enable extended stuff for scrolling
165+
if(ps2WriteToMouse(0xF3) ||
166+
ps2WriteToMouse(200) ||
167+
ps2WriteToMouse(0xF3) ||
168+
ps2WriteToMouse(100) ||
169+
ps2WriteToMouse(0xF3) ||
170+
ps2WriteToMouse(80))
171+
{
172+
intelliMouseMode = false;
173+
klog("failed to enable intellimouse mode");
174+
}
175+
else
176+
{
177+
intelliMouseMode = true;
178+
}
179+
161180
return G_PS2_STATUS_SUCCESS;
162181
}
163182

164183
void ps2HandleMouseData(uint8_t value)
165184
{
166-
167-
switch(mouse_packet_number)
185+
if(mousePacketNumber == 0)
168186
{
169-
case 0:
170-
mouse_packet_buffer[0] = value;
171-
172-
if((value & 0x08) == 0)
173-
{
174-
mouse_packet_number = 0; // otherwise restart the cycle
175-
}
176-
else
177-
{
178-
mouse_packet_number = 1;
179-
}
180-
break;
181-
182-
case 1:
183-
mouse_packet_buffer[1] = value;
184-
mouse_packet_number = 2;
185-
break;
186-
187-
case 2:
188-
mouse_packet_buffer[2] = value;
189-
190-
int8_t flags = mouse_packet_buffer[0];
191-
uint8_t valX = mouse_packet_buffer[1];
192-
uint8_t valY = mouse_packet_buffer[2];
187+
mousePacketBuffer[0] = value;
188+
// The first byte must always have the 4th bit (0x08) set
189+
if((value & 0x08) == 0)
190+
{
191+
mousePacketNumber = 0; // wait for a valid starting byte
192+
}
193+
else
194+
{
195+
mousePacketNumber = 1;
196+
}
197+
}
198+
else if(mousePacketNumber == 1)
199+
{
200+
mousePacketBuffer[1] = value;
201+
mousePacketNumber = 2;
202+
}
203+
else if(mousePacketNumber == 2)
204+
{
205+
if(intelliMouseMode)
206+
{
207+
mousePacketBuffer[2] = value;
208+
mousePacketNumber = 3;
209+
}
210+
else
211+
{
212+
mousePacketBuffer[2] = value;
213+
mousePacketNumber = 0;
214+
ps2HandlePacket();
215+
}
216+
}
217+
else if(mousePacketNumber == 3) // IntelliMouse only
218+
{
219+
mousePacketBuffer[3] = value;
220+
mousePacketNumber = 0;
221+
ps2HandlePacket();
222+
}
223+
}
193224

194-
if((flags & (1 << 6)) || (flags & (1 << 7)))
195-
{
196-
// ignore overflowing values
197-
}
198-
else
199-
{
200-
int16_t offX = (valX | ((flags & 0x10) ? 0xFF00 : 0));
201-
int16_t offY = (valY | ((flags & 0x20) ? 0xFF00 : 0));
225+
void ps2HandlePacket()
226+
{
227+
int8_t flags = mousePacketBuffer[0];
228+
uint8_t valX = mousePacketBuffer[1];
229+
uint8_t valY = mousePacketBuffer[2];
230+
int8_t scroll = intelliMouseMode ? (int8_t) mousePacketBuffer[3] : 0;
202231

203-
if(registeredMouseCallback)
204-
{
205-
registeredMouseCallback(offX, -offY, flags);
206-
}
207-
}
232+
if((flags & (1 << 6)) || (flags & (1 << 7)))
233+
{
234+
// ignore overflowing values
235+
}
236+
else
237+
{
238+
int16_t offX = (valX | ((flags & 0x10) ? 0xFF00 : 0));
239+
int16_t offY = (valY | ((flags & 0x20) ? 0xFF00 : 0));
208240

209-
mouse_packet_number = 0;
210-
break;
241+
if(registeredMouseCallback)
242+
registeredMouseCallback(offX, -offY, flags, scroll);
211243
}
212244
}
213245

applications/libps2driver/inc/libps2driver/ps2driver.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct g_ps2_mouse_packet
7575
int16_t x;
7676
int16_t y;
7777
uint8_t flags;
78+
int8_t scroll;
7879
}__attribute__((packed));
7980

8081
/**

applications/libwindow/inc/libwindow/interface.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ typedef uint8_t g_mouse_event_type;
557557
#define G_MOUSE_EVENT_DRAG ((g_mouse_event_type) 5)
558558
#define G_MOUSE_EVENT_ENTER ((g_mouse_event_type) 6)
559559
#define G_MOUSE_EVENT_LEAVE ((g_mouse_event_type) 7)
560+
#define G_MOUSE_EVENT_SCROLL ((g_mouse_event_type) 8)
560561

561562
typedef struct
562563
{

0 commit comments

Comments
 (0)