Skip to content

Commit 4958fe1

Browse files
committed
Onscreen mouse pointer now moves with mouse HW
1 parent ecf22f0 commit 4958fe1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/kernel/kgraphics.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#if ARCH == x86
1919
#include <x86/boot.h>
2020
#include <x86/io.h>
21+
#include <drivers/x86/pc/ps2_devices.h>
2122
#endif
2223

2324
typedef struct GraphicsInfo {
@@ -80,11 +81,17 @@ static void arch_waitForNextVerticalRetrace()
8081

8182
static void draw_cursor (const KGraphicsArea* g)
8283
{
83-
UINT mouse_x = 600; // Some random location at this point
84-
UINT mouse_y = 400;
85-
kgraphics_rect (g, mouse_x, mouse_y, 10, 10, MOUSE_BG_COLOR);
86-
kgraphics_hline (g, mouse_x, mouse_y, 10, 2, MOUSE_FG_COLOR);
87-
kgraphics_vline (g, mouse_x, mouse_y, 10, 2, MOUSE_FG_COLOR);
84+
MousePositionData mdata = mouse_get_packet();
85+
86+
INT mouse_y = (INT)g->height_px / 2 - mdata.y;
87+
INT mouse_x = (INT)g->width_px / 2 + mdata.x;
88+
89+
mouse_x = CLAMP (mouse_x, 0, (INT)g->width_px - 10);
90+
mouse_y = CLAMP (mouse_y, 0, (INT)g->height_px - 10);
91+
92+
kgraphics_rect (g, (UINT)mouse_x, (UINT)mouse_y, 10, 10, MOUSE_BG_COLOR);
93+
kgraphics_hline (g, (UINT)mouse_x, (UINT)mouse_y, 10, 2, MOUSE_FG_COLOR);
94+
kgraphics_vline (g, (UINT)mouse_x, (UINT)mouse_y, 10, 2, MOUSE_FG_COLOR);
8895
}
8996

9097
void kgraphics_drawstring (const KGraphicsArea* g, UINT x, UINT y, const char* text, Color fg,

0 commit comments

Comments
 (0)