Skip to content

Commit b07a031

Browse files
author
di
committed
[INPUT] mouse absolute position syscall
1 parent 899c617 commit b07a031

8 files changed

Lines changed: 49 additions & 15 deletions

File tree

kernel/graph/tres.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "kernel_processes/windows/launcher.h"
88
#include "console/kio.h"
99
#include "sysregs.h"
10+
#include "ui/graphic_types.h"
1011

1112
clinkedlist_t *window_list;
1213
window_frame *focused_window;
@@ -29,6 +30,25 @@ void init_window_manager(uintptr_t gpu_driver){
2930
main_gpu_driver = (GPUDriver*)gpu_driver;
3031
}
3132

33+
int find_window(void *node, void *key){
34+
if (!node || !key) return -1;
35+
window_frame* frame = (window_frame*)node;
36+
uint16_t wid = *(uint16_t*)key;
37+
if (frame->win_id == wid) return 0;
38+
return -1;
39+
}
40+
41+
gpu_point convert_mouse_position(gpu_point point){
42+
process_t *p = get_current_proc();
43+
clinkedlist_node_t *node = clinkedlist_find(window_list, PHYS_TO_VIRT_P(&p->win_id), (typeof(find_window)*)PHYS_TO_VIRT_P(find_window));
44+
if (node && node->data){
45+
window_frame* frame = (window_frame*)node->data;
46+
if (point.x > frame->x && point.x < frame->x + frame->width && point.y > frame->y && point.y < frame->y + frame->height)
47+
return (gpu_point){ point.x-frame->x, point.y-frame->y};
48+
}
49+
return (gpu_point){};
50+
}
51+
3252
extern "C" void create_window(uint32_t x, uint32_t y, uint32_t width, uint32_t height){
3353
if (win_ids == UINT16_MAX) return;
3454
window_frame *frame = (window_frame*)malloc(sizeof(window_frame));
@@ -45,14 +65,6 @@ extern "C" void create_window(uint32_t x, uint32_t y, uint32_t width, uint32_t h
4565
dirty_windows = true;
4666
}
4767

48-
int find_window(void *node, void *key){
49-
if (!node || !key) return -1;
50-
window_frame* frame = (window_frame*)node;
51-
uint16_t wid = *(uint16_t*)key;
52-
if (frame->win_id == wid) return 0;
53-
return -1;
54-
}
55-
5668
void resize_window(uint32_t width, uint32_t height){
5769
process_t *p = get_current_proc();
5870
clinkedlist_node_t *node = clinkedlist_find(window_list, PHYS_TO_VIRT_P(&p->win_id), (typeof(find_window)*)PHYS_TO_VIRT_P(find_window));

kernel/graph/tres.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ void commit_frame(draw_ctx* frame_ctx, window_frame* frame);
2929
void set_window_focus(uint16_t win_id);
3030
void unset_window_focus();
3131

32+
gpu_point convert_mouse_position(gpu_point p);
33+
3234
extern clinkedlist_t *window_list;
3335

3436
extern uint16_t win_ids;

kernel/kernel_processes/windows/dos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "process/process.h"
4+
#include "ui/graphic_types.h"
45

56
#ifdef __cplusplus
67
extern "C" {

kernel/process/kernel_syscall_impl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ extern bool read_event(kbd_event *event){
3535
return sys_read_event_current(event);
3636
}
3737

38-
extern void get_mouse_status(mouse_input *in){
39-
*in = get_raw_mouse_in();
38+
extern void get_mouse_status(mouse_data *in){
39+
in->raw = get_raw_mouse_in();
40+
in->position = convert_mouse_position(get_mouse_pos());
4041
}
4142

4243
extern uint16_t exec(const char* prog_name, int argc, const char* argv[]){

kernel/process/syscall.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "exceptions/exception_handler.h"
44
#include "console/serial/uart.h"
55
#include "exceptions/irq.h"
6+
#include "mouse_input.h"
7+
#include "process/process.h"
68
#include "process/scheduler.h"
79
#include "memory/page_allocator.h"
810
#include "graph/graphics.h"
@@ -23,6 +25,7 @@
2325
#include "networking/transport_layer/csocket.h"
2426
#include "loading/dwarf.h"
2527
#include "sysregs.h"
28+
#include "ui/graphic_types.h"
2629

2730

2831
int syscall_depth = 0;
@@ -68,8 +71,9 @@ uint64_t syscall_read_shortcut(process_t *ctx){
6871
uint64_t syscall_get_mouse(process_t *ctx){
6972
//TODO: do we want to prevent the process from knowing what the mouse is doing outside the window unless it's explicitly allowed?
7073
if (get_current_proc_pid() != ctx->id) return 0;
71-
mouse_input *inp = (mouse_input*)ctx->PROC_X0;
72-
*inp = get_raw_mouse_in();
74+
mouse_data *inp = (mouse_data*)ctx->PROC_X0;
75+
inp->raw = get_raw_mouse_in();
76+
inp->position = convert_mouse_position(get_mouse_pos());
7377
return 0;
7478
}
7579

@@ -229,9 +233,9 @@ syscall_entry syscalls[] = {
229233
[FREE_CODE] = syscall_free,
230234
[PRINTL_CODE] = syscall_printl,
231235
[READ_KEY_CODE] = syscall_read_key,
232-
[READ_EVENT_CODE] = syscall_read_event ,
236+
[READ_EVENT_CODE] = syscall_read_event,
233237
[READ_SHORTCUT_CODE] = syscall_read_shortcut,
234-
[GET_MOUSE_STATUS_CODE] = syscall_get_mouse ,
238+
[GET_MOUSE_STATUS_CODE] = syscall_get_mouse,
235239
[REQUEST_DRAW_CTX_CODE] = syscall_gpu_request_ctx,
236240
[GPU_FLUSH_DATA_CODE] = syscall_gpu_flush,
237241
[GPU_CHAR_SIZE_CODE] = syscall_char_size,

shared/mouse_input.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "types.h"
4+
#include "ui/graphic_types.h"
45

56
#ifdef __cplusplus
67
extern "C" {
@@ -13,6 +14,15 @@ typedef struct {
1314
int8_t scroll;
1415
} mouse_input;
1516

17+
typedef struct {
18+
mouse_input raw;
19+
gpu_point position;
20+
} mouse_data;
21+
22+
static inline bool mouse_button_down(mouse_data* m, uint8_t button){
23+
return (m->raw.buttons >> button) & 1;
24+
}
25+
1626
#ifdef __cplusplus
1727
}
1828
#endif

shared/syscalls/syscalls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern void free_sized(void *ptr, size_t size);
2121

2222
extern bool read_key(keypress *kp);
2323
extern bool read_event(kbd_event *event);
24-
extern void get_mouse_status(mouse_input *in);
24+
extern void get_mouse_status(mouse_data *in);
2525

2626
extern void sleep(uint64_t time);
2727
extern void halt(int32_t exit_code);

user/default_process.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "default_process.h"
2+
#include "mouse_input.h"
23
#include "syscalls/syscalls.h"
34
#include "input_keycodes.h"
45
#include "std/string.h"
@@ -29,6 +30,9 @@ int img_example() {
2930
ctx.height = info.height+BORDER*2;
3031
request_draw_ctx(&ctx);
3132
while (1) {
33+
mouse_data data;
34+
get_mouse_status(&data);
35+
printf("data.position %ix%i",data.position.x,data.position.y);
3236
keypress kp = {};
3337
// printf("Print console test %f", (get_time()/1000.f));
3438
if (read_key(&kp))

0 commit comments

Comments
 (0)