Skip to content

Commit

Permalink
Window server: better mouse handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Twometer committed Apr 13, 2021
1 parent 1af69bc commit 3e7bff8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion kernel/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ int sys$$sleep(void *param)
{
uint32_t timeout = *(uint32_t *)(param);
auto thread = Thread::Current();
thread->Sleep(timeout * 1000);
thread->Sleep(timeout);
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions libc/include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C"
#endif

unsigned int sleep(unsigned int seconds);
unsigned int usleep(unsigned int microseconds);
int chdir(const char *path);
char *getcwd(char *buf, size_t size);

Expand Down
9 changes: 8 additions & 1 deletion libc/unistd.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#include <sys/syscall.h>
#include <unistd.h>

unsigned int usleep(unsigned int microseconds)
{
microseconds /= 1000; // Sleep takes ms
return syscall(SYS_SLEEP, &microseconds);
}

unsigned int sleep(unsigned int seconds)
{
return syscall(SYS_SLEEP, &seconds);
seconds *= 1000;
return syscall(SYS_SLEEP, &seconds); // Sleep takes ms
}

int chdir(const char *path)
Expand Down
8 changes: 6 additions & 2 deletions userland/sakura/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ int main(int argc, char **argv)
}
}

if (mouse_poll(&mouse) == 0)
while (mouse_poll(&mouse) == 0)
{
float scale = mouse.dx + mouse.dy;

mouse_x += mouse.dx;
mouse_y -= mouse.dy;
if (mouse_x < 0)
Expand All @@ -171,13 +173,15 @@ int main(int argc, char **argv)
mouse_y = height - 1;
}



size_t baseidx = mouse_y * framebuf.pitch + mouse_x * 4;
framebuf.buffer[baseidx] = 0xff;
framebuf.buffer[baseidx + 1] = 0x00;
framebuf.buffer[baseidx + 2] = 0x00;

framebuf_flush_all();
sleep(0);
usleep(1000);
}

thread_join(result);
Expand Down

0 comments on commit 3e7bff8

Please sign in to comment.