PatchworkOS  3984a1d
A non-POSIX operating system.
Loading...
Searching...
No Matches
mouse.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/fs/devfs.h>
4#include <kernel/sched/wait.h>
5#include <kernel/sync/lock.h>
6#include <kernel/utils/fifo.h>
7
8#include <stdint.h>
9#include <sys/kbd.h>
10#include <sys/proc.h>
11
12/**
13 * @brief Mouse driver abstraction.
14 * @defgroup kernel_drivers_abstract_mouse Mouse Abstraction
15 * @ingroup kernel_drivers_abstract
16 *
17 * Mouse devices are exposed as a `/dev/mouse/[id]/` directory, containing the below files.
18 *
19 * ## name
20 *
21 * A read-only file that contains the driver defined name of the mouse device.
22 *
23 * ## events
24 *
25 * A readable and pollable file that provides a stream of mouse events represented as integer values suffixed with a
26 * single character indicating the type of the event.
27 *
28 * The ´x` and `y` characters indicate movement in the X and Y directions respectively, the `_` and `^` represent a
29 * button press and release respectively, and the `z` character represents a scroll event.
30 *
31 * Buttons are represented as their button number starting from `1` where `1` is the left button, `2` is the right
32 * button, and `3` is the middle button.
33 *
34 * The below example shows a press of the left mouse button, moving the mouse `10` units in the X direction and `-5`
35 * units in the Y direction, releasing the left mouse button, and then scrolling `3` units.
36 *
37 * ```
38 * 1_10x-5y1^3z
39 * ```
40 *
41 * If no events are available to read, the read call will block until an event is available unless the file is opened in
42 * non-blocking mode in which case the read will fail with `EAGAIN`.
43 *
44 * @note The format is specified such that if `scan()` is used with "%u%c" the `scan()` call does not require any
45 * "ungets".
46 *
47 * @{
48 */
49
50/**
51 * @brief Size of the mouse client buffer.
52 */
53#define MOUSE_CLIENT_BUFFER_SIZE 512
54
55/**
56 * @brief Keyboard event client structure.
57 * @struct mouse_client_t
58 */
65
66/**
67 * @brief Mouse structure.
68 * @struct mouse_t
69 */
79
80/**
81 * @brief Allocate and initialize a mouse structure.
82 *
83 * Will make the mouse available under `/dev/mouse/[id]`.
84 *
85 * @param name Driver specified name of the mouse device.
86 * @return On success, the new mouse structure. On failure, `NULL` and `errno` is set.
87 */
88mouse_t* mouse_new(const char* name);
89
90/**
91 * @brief Free and deinitialize a mouse structure.
92 *
93 * Removes the mouse from `/dev/mouse/[id]`.
94 *
95 * @param mouse Pointer to the mouse structure to free.
96 */
98
99/**
100 * @brief Push a mouse button press event to the mouse event queue.
101 *
102 * @param mouse Pointer to the mouse structure.
103 * @param button Button to press.
104 */
105void mouse_press(mouse_t* mouse, uint32_t button);
106
107/**
108 * @brief Push a mouse button release event to the mouse event queue.
109 *
110 * @param mouse Pointer to the mouse structure.
111 * @param button Button to release.
112 */
113void mouse_release(mouse_t* mouse, uint32_t button);
114
115/**
116 * @brief Push a mouse movement in the X direction to the mouse event queue.
117 *
118 * @param mouse Pointer to the mouse structure.
119 * @param delta Amount to move in the X direction.
120 */
121void mouse_move_x(mouse_t* mouse, int64_t delta);
122
123/**
124 * @brief Push a mouse movement in the Y direction to the mouse event queue.
125 *
126 * @param mouse Pointer to the mouse structure.
127 * @param delta Amount to move in the Y direction.
128 */
129void mouse_move_y(mouse_t* mouse, int64_t delta);
130
131/**
132 * @brief Push a mouse scroll event to the mouse event queue.
133 *
134 * @param mouse Pointer to the mouse structure.
135 * @param delta Amount to scroll.
136 */
137void mouse_scroll(mouse_t* mouse, int64_t delta);
138
139/** @} */
#define MAX_PATH
Maximum length of filepaths.
Definition MAX_PATH.h:11
static fd_t mouse
Definition dwm.c:24
#define MOUSE_CLIENT_BUFFER_SIZE
Size of the mouse client buffer.
Definition mouse.h:53
mouse_t * mouse_new(const char *name)
Allocate and initialize a mouse structure.
Definition mouse.c:144
void mouse_free(mouse_t *mouse)
Free and deinitialize a mouse structure.
Definition mouse.c:219
void mouse_press(mouse_t *mouse, uint32_t button)
Push a mouse button press event to the mouse event queue.
Definition mouse.c:246
void mouse_release(mouse_t *mouse, uint32_t button)
Push a mouse button release event to the mouse event queue.
Definition mouse.c:264
void mouse_scroll(mouse_t *mouse, int64_t delta)
Push a mouse scroll event to the mouse event queue.
Definition mouse.c:318
void mouse_move_x(mouse_t *mouse, int64_t delta)
Push a mouse movement in the X direction to the mouse event queue.
Definition mouse.c:282
void mouse_move_y(mouse_t *mouse, int64_t delta)
Push a mouse movement in the Y direction to the mouse event queue.
Definition mouse.c:300
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__INT64_TYPE__ int64_t
Definition stdint.h:16
Directory entry structure.
Definition dentry.h:153
FIFO Buffer.
Definition fifo.h:20
A entry in a doubly linked list.
Definition list.h:35
A doubly linked list.
Definition list.h:47
A simple ticket lock implementation.
Definition lock.h:44
Keyboard event client structure.
Definition mouse.h:60
fifo_t fifo
Definition mouse.h:62
list_entry_t entry
Definition mouse.h:61
Mouse structure.
Definition mouse.h:71
list_t files
Definition mouse.h:77
list_t clients
Definition mouse.h:74
wait_queue_t waitQueue
Definition mouse.h:73
dentry_t * dir
Definition mouse.h:76
lock_t lock
Definition mouse.h:75
The primitive that threads block on.
Definition wait.h:182