From 8808ed5bfe8cdb4b3577925ce923420c85ded36a Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 10 Nov 2024 04:33:50 -0600 Subject: [PATCH] misc --- .cargo/config.toml | 2 +- .../horizon_api/src/widgets/label.hb | 2 +- sysdata/libraries/intouch/src/events.hb | 8 +++--- sysdata/libraries/intouch/src/lib.hb | 26 +++++-------------- sysdata/programs/horizon/src/main.hb | 15 ++++++++--- sysdata/programs/ps2_mouse_driver/src/main.hb | 26 ++++++++++++++----- sysdata/system_config.toml | 3 +++ 7 files changed, 47 insertions(+), 35 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index c5b12ffd..e85de27f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,3 @@ [alias] -repbuild = "run --manifest-path ./repbuild/Cargo.toml -r -- " +repbuild = "run --manifest-path ./repbuild/Cargo.toml -- " dev = "run --manifest-path ./dev/Cargo.toml -r --" diff --git a/sysdata/libraries/horizon_api/src/widgets/label.hb b/sysdata/libraries/horizon_api/src/widgets/label.hb index 5a02f157..106e452c 100644 --- a/sysdata/libraries/horizon_api/src/widgets/label.hb +++ b/sysdata/libraries/horizon_api/src/widgets/label.hb @@ -31,7 +31,7 @@ render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: V } new_label := fn(text: ^u8): Label { - text_surface := render.new_surface(1000, 20) + text_surface := render.new_surface(1024, 20) text_length := string.length(text) label := Label.(3, true, text_surface, text, text_length) return label diff --git a/sysdata/libraries/intouch/src/events.hb b/sysdata/libraries/intouch/src/events.hb index 0ede6d5f..c26fb958 100644 --- a/sysdata/libraries/intouch/src/events.hb +++ b/sysdata/libraries/intouch/src/events.hb @@ -11,12 +11,12 @@ KeyEvent := struct { key: KeyCode, } -MouseEvent := struct { +MouseEvent := packed struct { x_change: i8, y_change: i8, - left: u8, - middle: u8, - right: u8, + left: bool, + middle: bool, + right: bool, } GamepadEvent := struct {} \ No newline at end of file diff --git a/sysdata/libraries/intouch/src/lib.hb b/sysdata/libraries/intouch/src/lib.hb index e6a5dc78..dca49d40 100644 --- a/sysdata/libraries/intouch/src/lib.hb +++ b/sysdata/libraries/intouch/src/lib.hb @@ -6,34 +6,20 @@ events := @use("events.hb"); .{KeyEvent, MouseEvent} := events recieve_key_event := fn(): ?KeyEvent { - mem_page := memory.request_page(1) - - buf_id := buffer.search("PS/2 Keyboard\0") - - // Read out of the keyboard buffer here - buffer.recv(KeyEvent, buf_id, mem_page) - - key_event := KeyEvent.(0, 0, 2) - // return key_event - - // return null + return null } recieve_mouse_event := fn(): ?MouseEvent { - mem_page := memory.request_page(1) + mevent := MouseEvent.(0, 0, false, false, false) buf_id := buffer.search("PS/2 Mouse\0") // Read out of the Mouse buffer here - buffer.recv(MouseEvent, buf_id, mem_page) - if *mem_page != 0 { - log.info("Mouse events\0") - dx := @as(i8, @bitcast(*mem_page)) - dy := @as(i8, @bitcast(*(mem_page + 1))) - mevent := MouseEvent.(dx, dy, 0, 0, 0) + buffer.recv(MouseEvent, buf_id, @bitcast(&mevent)) + + if mevent.x_change != 0 | mevent.y_change != 0 | mevent.left | mevent.middle | mevent.right { return mevent } - // log.error("No mouse events\0") - return MouseEvent.(0, 0, 0, 0, 0) + return null } \ No newline at end of file diff --git a/sysdata/programs/horizon/src/main.hb b/sysdata/programs/horizon/src/main.hb index d1da4b25..b146c961 100644 --- a/sysdata/programs/horizon/src/main.hb +++ b/sysdata/programs/horizon/src/main.hb @@ -65,8 +65,7 @@ main := fn(): int { // key_event := intouch.recieve_key_event(); // log.info("before mouse event check\0"); - render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white) - { + if false { // Scroll bar :ThumbsUp: render.put_rect(screen, .(100, 100), .(100, 10), render.white) render.put_filled_rect(screen, .(110, 100), .(20, 10), render.white) @@ -78,6 +77,7 @@ main := fn(): int { { pos := Vec2(uint).(1, screen.height - 21) render_label_to_surface(screen, text_label, font, pos) + render.put_rect(screen, .(0, screen.height - 21), .(screen.width - 1, screen.height - 1), render.white) } { @@ -111,8 +111,17 @@ main := fn(): int { } mouse_y -= change_y - set_label_text(text_label, "Mouse Moved\0") + if mouse_event.left { + set_label_text(text_label, "LEFT CLICK\0") + } else if mouse_event.middle { + set_label_text(text_label, "MIDDLE CLICK\0") + } else if mouse_event.right { + set_label_text(text_label, "RIGHT CLICK\0") + } } + + render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white) + // render mouse render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.white) // Send events to focused window diff --git a/sysdata/programs/ps2_mouse_driver/src/main.hb b/sysdata/programs/ps2_mouse_driver/src/main.hb index d2343808..43544faa 100644 --- a/sysdata/programs/ps2_mouse_driver/src/main.hb +++ b/sysdata/programs/ps2_mouse_driver/src/main.hb @@ -118,17 +118,32 @@ main := fn(): int { set_up_mouse() continue } + event := MouseEvent.(0, 0, false, false, false) changes := button_states ^ status & 7 if (changes & LeftButton.id) != 0 { - button_event(LeftButton, (status & LeftButton.id) != 0) - } - if (changes & RightButton.id) != 0 { - button_event(RightButton, (status & RightButton.id) != 0) + if (status & LeftButton.id) != 0 { + event.left = true + } else { + event.left = false + } } + if (changes & MiddleButton.id) != 0 { - button_event(MiddleButton, (status & MiddleButton.id) != 0) + if (status & MiddleButton.id) != 0 { + event.middle = true + } else { + event.middle = false + } + } + + if (changes & RightButton.id) != 0 { + if (status & RightButton.id) != 0 { + event.right = true + } else { + event.right = false + } } button_states ^= changes @@ -145,7 +160,6 @@ main := fn(): int { y_change := @as(i8, @bitcast(dy.value)) x_change := @as(i8, @bitcast(dx.value)) - event := MouseEvent.(0, 0, 0, 0, 0) event.x_change = x_change event.y_change = y_change diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 2e9996ce..1992a800 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -30,3 +30,6 @@ path = "boot:///horizon.hbf" [boot.limine.ableos.modules.ps2_mouse_driver] path = "boot:///ps2_mouse_driver.hbf" + +# [boot.limine.ableos.modules.ps2_keyboard_driver] +# path = "boot:///ps2_keyboard_driver.hbf"