Skip to content

Commit d388f8e

Browse files
authored
Merge pull request #104 from KaiNorberg/develop
Develop
2 parents d0b3021 + 6ab18d3 commit d388f8e

47 files changed

Lines changed: 1469 additions & 1383 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/kernel/drivers/abstract/kbd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ typedef struct kbd kbd_t;
3636
* If no events are available to read, the read call will block until an event is available unless the file is opened in
3737
* non-blocking mode in which case the read will fail with `EAGAIN`.
3838
*
39-
* @note The format is specified such that if `scan()` is used with "%u%c" the `scan()` call does not require any "ungets".
39+
* @note The format is specified such that if `scan()` is used with "%u%c" the `scan()` call does not require any
40+
* "ungets".
4041
*
4142
* @see libstd_sys_kbd for keycode definitions.
4243
*

include/kernel/drivers/abstract/mouse.h

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,34 @@
1515
* @ingroup kernel_drivers_abstract
1616
*
1717
* Mouse devices are exposed as a `/dev/mouse/[id]/` directory, containing the below files.
18-
*
18+
*
1919
* ## name
20-
*
20+
*
2121
* A read-only file that contains the driver defined name of the mouse device.
22-
*
22+
*
2323
* ## events
24-
*
25-
* A readable and pollable file that provides a stream of mouse events represented as integer values suffixed with a single character indicating the type of the event.
26-
*
27-
* The ´x` and `y` characters indicate movement in the X and Y directions respectively, the `_` and `^` represent a button press and release respectively, and the `z` character represents a scroll event.
28-
*
29-
* Buttons are represented as their button number starting from `1` where `1` is the left button, `2` is the right button, and `3` is the middle button.
30-
*
31-
* The below example shows a press of the left mouse button, moving the mouse `10` units in the X direction and `-5` units in the Y direction, releasing the left mouse button, and then scrolling `3` units.
32-
*
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+
*
3337
* ```
3438
* 1_10x-5y1^3z
3539
* ```
36-
*
40+
*
3741
* If no events are available to read, the read call will block until an event is available unless the file is opened in
3842
* non-blocking mode in which case the read will fail with `EAGAIN`.
3943
*
40-
* @note The format is specified such that if `scan()` is used with "%u%c" the `scan()` call does not require any "ungets".
44+
* @note The format is specified such that if `scan()` is used with "%u%c" the `scan()` call does not require any
45+
* "ungets".
4146
*
4247
* @{
4348
*/
@@ -93,39 +98,39 @@ void mouse_free(mouse_t* mouse);
9398

9499
/**
95100
* @brief Push a mouse button press event to the mouse event queue.
96-
*
101+
*
97102
* @param mouse Pointer to the mouse structure.
98103
* @param button Button to press.
99104
*/
100105
void mouse_press(mouse_t* mouse, uint32_t button);
101106

102107
/**
103108
* @brief Push a mouse button release event to the mouse event queue.
104-
*
109+
*
105110
* @param mouse Pointer to the mouse structure.
106111
* @param button Button to release.
107112
*/
108113
void mouse_release(mouse_t* mouse, uint32_t button);
109114

110115
/**
111116
* @brief Push a mouse movement in the X direction to the mouse event queue.
112-
*
117+
*
113118
* @param mouse Pointer to the mouse structure.
114119
* @param delta Amount to move in the X direction.
115120
*/
116121
void mouse_move_x(mouse_t* mouse, int64_t delta);
117122

118123
/**
119124
* @brief Push a mouse movement in the Y direction to the mouse event queue.
120-
*
125+
*
121126
* @param mouse Pointer to the mouse structure.
122127
* @param delta Amount to move in the Y direction.
123128
*/
124129
void mouse_move_y(mouse_t* mouse, int64_t delta);
125130

126131
/**
127132
* @brief Push a mouse scroll event to the mouse event queue.
128-
*
133+
*
129134
* @param mouse Pointer to the mouse structure.
130135
* @param delta Amount to scroll.
131136
*/

include/libpatchwork/event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ typedef struct
172172
typedef enum
173173
{
174174
MOUSE_NONE = 0, ///< None
175-
MOUSE_LEFT = (1 << 1), ///< Left mouse button
175+
MOUSE_LEFT = (1 << 1), ///< Left mouse button
176176
MOUSE_RIGHT = (1 << 2), ///< Right mouse button
177177
MOUSE_MIDDLE = (1 << 3), ///< Middle mouse button
178178
} mouse_buttons_t;

src/boxes/core/dwm/dwm.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,10 @@ static void dwm_handle_mouse_event(int64_t x, int64_t y, mouse_buttons_t buttons
630630

631631
static void dwm_mouse_read(void)
632632
{
633-
static mouse_buttons_t prevHeld = MOUSE_NONE;
633+
static mouse_buttons_t buttons = MOUSE_NONE;
634634

635635
int64_t x = 0;
636636
int64_t y = 0;
637-
mouse_buttons_t buttons = 0;
638-
639-
bool received = false;
640637
while (1)
641638
{
642639
int64_t value;
@@ -649,7 +646,7 @@ static void dwm_mouse_read(void)
649646
}
650647
break;
651648
}
652-
649+
653650
switch (suffix)
654651
{
655652
case 'x':
@@ -659,25 +656,35 @@ static void dwm_mouse_read(void)
659656
y += value;
660657
break;
661658
case '_':
659+
if (x != 0 || y != 0)
660+
{
661+
dwm_handle_mouse_event(x, y, buttons);
662+
x = 0;
663+
y = 0;
664+
}
662665
buttons |= (1 << value);
666+
dwm_handle_mouse_event(0, 0, buttons);
663667
break;
664668
case '^':
669+
if (x != 0 || y != 0)
670+
{
671+
dwm_handle_mouse_event(x, y, buttons);
672+
x = 0;
673+
y = 0;
674+
}
665675
buttons &= ~(1 << value);
676+
dwm_handle_mouse_event(0, 0, buttons);
666677
break;
667678
default:
668679
printf("dwm: unknown mouse event suffix '%c'\n", suffix);
669680
break;
670681
}
671-
672-
received = true;
673682
}
674683

675-
if (!received)
684+
if (x != 0 || y != 0)
676685
{
677-
return;
686+
dwm_handle_mouse_event(x, y, buttons);
678687
}
679-
680-
dwm_handle_mouse_event(x, y, buttons);
681688
}
682689

683690
static void dwm_poll_ctx_update(void)

src/kernel/drivers/abstract/kbd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void kbd_free(kbd_t* kbd)
234234
}
235235

236236
static void kbd_broadcast(kbd_t* kbd, const char* string, size_t length)
237-
{
237+
{
238238
LOCK_SCOPE(&kbd->lock);
239239

240240
kbd_client_t* client;

src/kernel/drivers/abstract/mouse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void mouse_free(mouse_t* mouse)
228228
}
229229

230230
static void mouse_broadcast(mouse_t* mouse, const char* string, size_t length)
231-
{
231+
{
232232
LOCK_SCOPE(&mouse->lock);
233233

234234
mouse_client_t* client;

src/kernel/log/log.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ static lock_t lock = LOCK_CREATE();
2626

2727
static char klogBuffer[CONFIG_KLOG_SIZE];
2828
static uint64_t klogHead = 0;
29-
static wait_queue_t klogQueue = WAIT_QUEUE_CREATE(klogQueue);
3029
static dentry_t* klog = NULL;
3130

3231
static char lineBuffer[LOG_MAX_BUFFER] = {0};
@@ -45,20 +44,13 @@ static const char* levelNames[] = {
4544

4645
static size_t klog_read(file_t* file, void* buffer, size_t count, size_t* offset)
4746
{
47+
UNUSED(file);
48+
4849
LOCK_SCOPE(&lock);
4950

5051
if (*offset >= klogHead)
5152
{
52-
if (file->mode & MODE_NONBLOCK)
53-
{
54-
errno = EAGAIN;
55-
return ERR;
56-
}
57-
58-
if (WAIT_BLOCK_LOCK(&klogQueue, &lock, *offset < klogHead))
59-
{
60-
return ERR;
61-
}
53+
return 0;
6254
}
6355

6456
for (size_t i = 0; i < count; i++)
@@ -83,21 +75,9 @@ static size_t klog_write(file_t* file, const void* buffer, size_t count, size_t*
8375
return count;
8476
}
8577

86-
static wait_queue_t* klog_poll(file_t* file, poll_events_t* revents)
87-
{
88-
LOCK_SCOPE(&lock);
89-
90-
if (file->pos < klogHead)
91-
{
92-
*revents |= POLLIN;
93-
}
94-
return &klogQueue;
95-
}
96-
9778
static file_ops_t klogOps = {
9879
.read = klog_read,
9980
.write = klog_write,
100-
.poll = klog_poll,
10181
};
10282

10383
static void log_splash(void)
@@ -151,7 +131,6 @@ static void log_write(const char* string, uint64_t length)
151131
{
152132
klogBuffer[klogHead++ % CONFIG_KLOG_SIZE] = string[i];
153133
}
154-
wait_unblock(&klogQueue, WAIT_ALL, EOK);
155134

156135
#if CONFIG_LOG_SERIAL
157136
for (uint64_t i = 0; i < length; i++)

src/libstd/common/digits.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22

33
const char _digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
44

5-
const char _xdigits[] = "0123456789ABCDEF";
5+
const char _xdigits[] = "0123456789abcdef";
6+
7+
const char _Xdigits[] = "0123456789ABCDEF";
8+
9+
const char _digitPairs[] =
10+
"000102030405060708091011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556"
11+
"57585960616263646566676869707172737475767778798081828384858687888990919293949596979899";

src/libstd/common/digits.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,26 @@ extern const char _digits[];
77

88
extern const char _xdigits[];
99

10+
extern const char _Xdigits[];
11+
12+
extern const char _digitPairs[];
13+
1014
static inline uint8_t _digit_to_int(char c)
1115
{
1216
return _asciiTable[(unsigned char)c].digit;
1317
}
18+
19+
static inline char _int_to_digit(uint8_t i)
20+
{
21+
return _digits[i];
22+
}
23+
24+
static inline char _int_to_xdigit(uint8_t i)
25+
{
26+
return _xdigits[i];
27+
}
28+
29+
static inline char _int_to_Xdigit(uint8_t i)
30+
{
31+
return _Xdigits[i];
32+
}

src/libstd/common/format.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)