Separate pthread; add mouse move events?
This commit is contained in:
parent
3e70898674
commit
0eaf3a99a3
@ -2,7 +2,7 @@ CC = i686-pc-toaru-gcc
|
||||
CPP = i686-pc-toaru-g++
|
||||
CFLAGS = -std=c99 -O3 -m32 -Wa,--32 -Xlinker --eh-frame-hdr
|
||||
CPPFLAGS = -O3 -m32 -Wa,--32
|
||||
EXTRAFLAGS = -s
|
||||
EXTRAFLAGS = -g
|
||||
EXECUTABLES = $(patsubst %.c,%.o,$(wildcard lib/*.c)) $(patsubst %.c,../hdd/bin/%,$(wildcard *.c)) $(patsubst %.cpp,../hdd/bin/%,$(wildcard *.cpp))
|
||||
|
||||
BEG = ../util/mk-beg
|
||||
@ -19,7 +19,7 @@ FREETYPE_LIB = ../util/toaru-toolchain/i686-pc-toaru/lib/libfreetype.a
|
||||
LIBM = ../util/toaru-toolchain/i686-pc-toaru/lib/libm.a
|
||||
|
||||
TARGETDIR = ../hdd/bin/
|
||||
ETARGETS = terminal login compositor view game-win drawlines glogin julia-win solver donut wallpaper panel glock clock-win
|
||||
ETARGETS = terminal login compositor view game-win drawlines glogin julia-win solver donut wallpaper panel glock clock-win draw
|
||||
FTARGETS = $(ETARGETS:%=$(TARGETDIR)%)
|
||||
|
||||
.PHONY: all clean
|
||||
@ -31,9 +31,9 @@ clean:
|
||||
@-rm -f ${EXECUTABLES}
|
||||
@${ENDRM} "RM" "Cleaned userspace full-toolchain applications."
|
||||
|
||||
${FTARGETS}: $(TARGETDIR)% : %.c lib/graphics.o lib/list.o lib/window.o lib/sha2.o lib/decorations.o
|
||||
${FTARGETS}: $(TARGETDIR)% : %.c lib/graphics.o lib/list.o lib/window.o lib/sha2.o lib/decorations.o lib/pthread.o
|
||||
@${BEG} "CC" "$@ $< [w/libs]"
|
||||
@${CC} ${CFLAGS} ${EXTRAFLAGS} ${FREETYPE_INC} -o $@ $< lib/graphics.o lib/list.o lib/window.o lib/sha2.o lib/decorations.o ${LIBM} ${FREETYPE_LIB} ${ERRORS}
|
||||
@${CC} ${CFLAGS} ${EXTRAFLAGS} ${FREETYPE_INC} -o $@ $< lib/graphics.o lib/list.o lib/window.o lib/sha2.o lib/decorations.o lib/pthread.o ${LIBM} ${FREETYPE_LIB} ${ERRORS}
|
||||
@${END} "CC" "$< [w/libs]"
|
||||
|
||||
$(TARGETDIR)%: %.cpp
|
||||
|
@ -19,14 +19,13 @@
|
||||
#include "lib/list.h"
|
||||
#include "lib/graphics.h"
|
||||
#include "lib/window.h"
|
||||
#include "lib/pthread.h"
|
||||
|
||||
#include "../kernel/include/signal.h"
|
||||
#include "../kernel/include/mouse.h"
|
||||
|
||||
DECL_SYSCALL0(mkpipe);
|
||||
DEFN_SYSCALL0(mousedevice, 33);
|
||||
DEFN_SYSCALL3(clone, 30, uintptr_t, uintptr_t, void *);
|
||||
DEFN_SYSCALL0(gettid, 41);
|
||||
|
||||
void spin_lock(int volatile * lock) {
|
||||
while(__sync_lock_test_and_set(lock, 0x01)) {
|
||||
@ -38,35 +37,6 @@ void spin_unlock(int volatile * lock) {
|
||||
__sync_lock_release(lock);
|
||||
}
|
||||
|
||||
int clone(uintptr_t,uintptr_t,void*) __attribute__((alias("syscall_clone")));
|
||||
int gettid() __attribute__((alias("syscall_gettid")));
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
char * stack;
|
||||
void * ret_val;
|
||||
} pthread_t;
|
||||
typedef unsigned int pthread_attr_t;
|
||||
|
||||
#define PTHREAD_STACK_SIZE 10240
|
||||
|
||||
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *(*start_routine)(void *), void * arg) {
|
||||
char * stack = malloc(PTHREAD_STACK_SIZE);
|
||||
uintptr_t stack_top = (uintptr_t)stack + PTHREAD_STACK_SIZE;
|
||||
thread->stack = stack;
|
||||
thread->id = clone(stack_top, (uintptr_t)start_routine, arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pthread_exit(void * value) {
|
||||
/* Perform nice cleanup */
|
||||
#if 0
|
||||
/* XXX: LOCK */
|
||||
free(stack);
|
||||
/* XXX: Return value!? */
|
||||
#endif
|
||||
__asm__ ("jmp 0xFFFFB00F"); /* Force thread exit */
|
||||
}
|
||||
|
||||
sprite_t * sprites[128];
|
||||
|
||||
@ -77,6 +47,7 @@ sprite_t * sprites[128];
|
||||
list_t * process_list;
|
||||
|
||||
int32_t mouse_x, mouse_y;
|
||||
int32_t click_x, click_y;
|
||||
#define MOUSE_SCALE 10
|
||||
#define MOUSE_OFFSET_X 26
|
||||
#define MOUSE_OFFSET_Y 26
|
||||
@ -437,6 +408,22 @@ void send_keyboard_event (process_windows_t * pw, uint8_t event, w_keyboard_t pa
|
||||
write(pw->event_pipe, &header, sizeof(wins_packet_t));
|
||||
write(pw->event_pipe, &packet, sizeof(w_keyboard_t));
|
||||
syscall_send_signal(pw->pid, SIGWINEVENT); // SIGWINEVENT
|
||||
syscall_yield();
|
||||
}
|
||||
|
||||
void send_mouse_event (process_windows_t * pw, uint8_t event, w_mouse_t * packet) {
|
||||
/* Construct the header */
|
||||
wins_packet_t header;
|
||||
header.magic = WINS_MAGIC;
|
||||
header.command_type = event;
|
||||
header.packet_size = sizeof(w_mouse_t);
|
||||
|
||||
/* Send them */
|
||||
// XXX: we have a race condition here
|
||||
write(pw->event_pipe, &header, sizeof(wins_packet_t));
|
||||
write(pw->event_pipe, packet, sizeof(w_mouse_t));
|
||||
//syscall_send_signal(pw->pid, SIGWINEVENT); // SIGWINEVENT
|
||||
syscall_yield();
|
||||
}
|
||||
|
||||
void process_window_command (int sig) {
|
||||
@ -879,6 +866,8 @@ void * process_requests(void * garbage) {
|
||||
|
||||
mouse_x = MOUSE_SCALE * graphics_width / 2;
|
||||
mouse_y = MOUSE_SCALE * graphics_height / 2;
|
||||
click_x = 0;
|
||||
click_y = 0;
|
||||
|
||||
uint16_t _mouse_state = 0;
|
||||
window_t * _mouse_window = NULL;
|
||||
@ -951,8 +940,8 @@ void * process_requests(void * garbage) {
|
||||
_mouse_win_x = _mouse_window->x;
|
||||
_mouse_win_y = _mouse_window->y;
|
||||
|
||||
int32_t click_x = mouse_x / MOUSE_SCALE - _mouse_win_x;
|
||||
int32_t click_y = mouse_y / MOUSE_SCALE - _mouse_win_y;
|
||||
click_x = mouse_x / MOUSE_SCALE - _mouse_win_x;
|
||||
click_y = mouse_y / MOUSE_SCALE - _mouse_win_y;
|
||||
|
||||
printf("Mouse down at @ %d,%d = %d,%d\n", mouse_x, mouse_y, click_x, click_y);
|
||||
}
|
||||
@ -997,8 +986,8 @@ void * process_requests(void * garbage) {
|
||||
_mouse_win_x = _mouse_window->x;
|
||||
_mouse_win_y = _mouse_window->y;
|
||||
|
||||
int32_t click_x = mouse_x / MOUSE_SCALE - _mouse_win_x;
|
||||
int32_t click_y = mouse_y / MOUSE_SCALE - _mouse_win_y;
|
||||
click_x = mouse_x / MOUSE_SCALE - _mouse_win_x;
|
||||
click_y = mouse_y / MOUSE_SCALE - _mouse_win_y;
|
||||
|
||||
printf("Mouse up at @ %d,%d = %d,%d\n", mouse_x, mouse_y, click_x, click_y);
|
||||
#if 0 /* Resizing */
|
||||
@ -1020,13 +1009,25 @@ void * process_requests(void * garbage) {
|
||||
#endif
|
||||
} else {
|
||||
/* Still down */
|
||||
|
||||
w_mouse_t _packet;
|
||||
_packet.wid = _mouse_window->wid;
|
||||
|
||||
_mouse_win_x = _mouse_window->x;
|
||||
_mouse_win_y = _mouse_window->y;
|
||||
|
||||
int32_t click_x = mouse_x / MOUSE_SCALE - _mouse_win_x;
|
||||
int32_t click_y = mouse_y / MOUSE_SCALE - _mouse_win_y;
|
||||
_packet.old_x = click_x;
|
||||
_packet.old_y = click_y;
|
||||
|
||||
printf("Mouse move to @ %d,%d = %d,%d\n", mouse_x, mouse_y, click_x, click_y);
|
||||
click_x = mouse_x / MOUSE_SCALE - _mouse_win_x;
|
||||
click_y = mouse_y / MOUSE_SCALE - _mouse_win_y;
|
||||
|
||||
_packet.new_x = click_x;
|
||||
_packet.new_y = click_y;
|
||||
|
||||
_packet.buttons = packet->buttons;
|
||||
|
||||
send_mouse_event(_mouse_window->owner, WE_MOUSEMOVE, &_packet);
|
||||
#if 0
|
||||
redraw_bounding_box_r(_mouse_window, _mouse_win_x_p, _mouse_win_y_p, 0);
|
||||
_mouse_win_x_p = _mouse_win_x + (mouse_x - _mouse_init_x) / MOUSE_SCALE;
|
||||
|
46
userspace/draw.c
Normal file
46
userspace/draw.c
Normal file
@ -0,0 +1,46 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lib/window.h"
|
||||
#include "lib/graphics.h"
|
||||
|
||||
int main (int argc, char ** argv) {
|
||||
int left = 30;
|
||||
int top = 30;
|
||||
|
||||
int width = 450;
|
||||
int height = 450;
|
||||
|
||||
setup_windowing();
|
||||
|
||||
/* Do something with a window */
|
||||
window_t * wina = window_create(left, top, width, height);
|
||||
window_fill(wina, rgb(255,255,255));
|
||||
init_graphics_window(wina);
|
||||
|
||||
win_use_threaded_handler();
|
||||
|
||||
while (1) {
|
||||
w_keyboard_t * kbd = poll_keyboard();
|
||||
if (kbd != NULL) {
|
||||
if (kbd->key == 'q') {
|
||||
break;
|
||||
}
|
||||
free(kbd);
|
||||
}
|
||||
w_mouse_t * mouse = poll_mouse();
|
||||
if (mouse != NULL) {
|
||||
if (mouse->buttons & MOUSE_BUTTON_LEFT) {
|
||||
if (mouse->old_x >= 0 && mouse->new_x >= 0 && mouse->old_y >= 0 && mouse->new_y >= 0 &&
|
||||
mouse->old_x < width && mouse->new_x < width && mouse->old_y < width && mouse->new_y < width) {
|
||||
draw_line(mouse->old_x, mouse->new_x, mouse->old_y, mouse->new_y, rgb(255,0,0));
|
||||
}
|
||||
}
|
||||
free(mouse);
|
||||
}
|
||||
syscall_yield();
|
||||
}
|
||||
|
||||
teardown_windowing();
|
||||
|
||||
return 0;
|
||||
}
|
@ -8,40 +8,7 @@
|
||||
|
||||
#include "lib/window.h"
|
||||
#include "lib/graphics.h"
|
||||
|
||||
DEFN_SYSCALL3(clone, 30, uintptr_t, uintptr_t, void *);
|
||||
DEFN_SYSCALL0(gettid, 41);
|
||||
|
||||
int clone(uintptr_t,uintptr_t,void*) __attribute__((alias("syscall_clone")));
|
||||
int gettid() __attribute__((alias("syscall_gettid")));
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
char * stack;
|
||||
void * ret_val;
|
||||
} pthread_t;
|
||||
typedef unsigned int pthread_attr_t;
|
||||
|
||||
#define PTHREAD_STACK_SIZE 10240
|
||||
|
||||
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *(*start_routine)(void *), void * arg) {
|
||||
char * stack = malloc(PTHREAD_STACK_SIZE);
|
||||
uintptr_t stack_top = (uintptr_t)stack + PTHREAD_STACK_SIZE;
|
||||
thread->stack = stack;
|
||||
thread->id = clone(stack_top, (uintptr_t)start_routine, arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pthread_exit(void * value) {
|
||||
/* Perform nice cleanup */
|
||||
#if 0
|
||||
/* XXX: LOCK */
|
||||
free(stack);
|
||||
/* XXX: Return value!? */
|
||||
#endif
|
||||
__asm__ ("jmp 0xFFFFB00F"); /* Force thread exit */
|
||||
}
|
||||
|
||||
#include "lib/pthread.h"
|
||||
|
||||
sprite_t * sprites[128];
|
||||
sprite_t alpha_tmp;
|
||||
|
30
userspace/lib/pthread.c
Normal file
30
userspace/lib/pthread.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "pthread.h"
|
||||
|
||||
DEFN_SYSCALL3(clone, 30, uintptr_t, uintptr_t, void *);
|
||||
DEFN_SYSCALL0(gettid, 41);
|
||||
|
||||
#define PTHREAD_STACK_SIZE 10240
|
||||
|
||||
int clone(uintptr_t,uintptr_t,void*) __attribute__((alias("syscall_clone")));
|
||||
int gettid() __attribute__((alias("syscall_gettid")));
|
||||
|
||||
|
||||
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *(*start_routine)(void *), void * arg) {
|
||||
char * stack = malloc(PTHREAD_STACK_SIZE);
|
||||
uintptr_t stack_top = (uintptr_t)stack + PTHREAD_STACK_SIZE;
|
||||
thread->stack = stack;
|
||||
thread->id = clone(stack_top, (uintptr_t)start_routine, arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pthread_exit(void * value) {
|
||||
/* Perform nice cleanup */
|
||||
#if 0
|
||||
/* XXX: LOCK */
|
||||
free(stack);
|
||||
/* XXX: Return value!? */
|
||||
#endif
|
||||
__asm__ ("jmp 0xFFFFB00F"); /* Force thread exit */
|
||||
}
|
23
userspace/lib/pthread.h
Normal file
23
userspace/lib/pthread.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef PTHREAD_H
|
||||
#define PTHREAD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <syscall.h>
|
||||
|
||||
DECL_SYSCALL3(clone, uintptr_t, uintptr_t, void *);
|
||||
DECL_SYSCALL0(gettid);
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
char * stack;
|
||||
void * ret_val;
|
||||
} pthread_t;
|
||||
typedef unsigned int pthread_attr_t;
|
||||
|
||||
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *(*start_routine)(void *), void * arg);
|
||||
void pthread_exit(void * value);
|
||||
|
||||
int clone(uintptr_t,uintptr_t,void*);
|
||||
int gettid();
|
||||
|
||||
#endif
|
@ -14,6 +14,7 @@
|
||||
#include "../../kernel/include/signal.h"
|
||||
|
||||
#include "window.h"
|
||||
#include "pthread.h"
|
||||
|
||||
FILE *fdopen(int fildes, const char *mode);
|
||||
|
||||
@ -368,15 +369,15 @@ uint8_t volatile mouse_evt_buffer_lock;
|
||||
list_t * mouse_evt_buffer;
|
||||
|
||||
w_mouse_t * poll_mouse () {
|
||||
w_mouse_t * evt;
|
||||
w_mouse_t * evt = NULL;
|
||||
|
||||
LOCK(mouse_evt_buffer_lock);
|
||||
//LOCK(mouse_evt_buffer_lock);
|
||||
if (mouse_evt_buffer->length > 0) {
|
||||
node_t * n = list_dequeue(mouse_evt_buffer);
|
||||
evt = (w_mouse_t *)n->value;
|
||||
free(n);
|
||||
}
|
||||
UNLOCK(mouse_evt_buffer_lock);
|
||||
//UNLOCK(mouse_evt_buffer_lock);
|
||||
|
||||
return evt;
|
||||
}
|
||||
@ -384,6 +385,11 @@ w_mouse_t * poll_mouse () {
|
||||
static void process_mouse_evt (uint8_t command, w_mouse_t * evt) {
|
||||
/* Push the event onto a buffer for the process to poll */
|
||||
//LOCK(mouse_evt_buffer_lock);
|
||||
if (mouse_evt_buffer->length > 5000) {
|
||||
node_t * n = list_dequeue(mouse_evt_buffer);
|
||||
free(n->value);
|
||||
free(n);
|
||||
}
|
||||
list_insert(mouse_evt_buffer, evt);
|
||||
//UNLOCK(mouse_evt_buffer_lock);
|
||||
}
|
||||
@ -430,7 +436,7 @@ static void process_evt (int sig) {
|
||||
switch (header.command_type & WE_GROUP_MASK) {
|
||||
case WE_MOUSE_EVT: {
|
||||
w_mouse_t * mevt = malloc(sizeof(w_mouse_t));
|
||||
read(process_windows->event_pipe, &mevt, sizeof(w_mouse_t));
|
||||
read(process_windows->event_pipe, mevt, sizeof(w_mouse_t));
|
||||
process_mouse_evt(header.command_type, mevt);
|
||||
break;
|
||||
}
|
||||
@ -469,6 +475,23 @@ void install_signal_handlers () {
|
||||
mouse_evt_buffer = list_create();
|
||||
}
|
||||
|
||||
static void ignore(int sig) {
|
||||
return;
|
||||
}
|
||||
|
||||
void * win_threaded_event_processor(void * garbage) {
|
||||
while (1) {
|
||||
process_evt (0);
|
||||
syscall_yield();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void win_use_threaded_handler() {
|
||||
syscall_sys_signal(SIGWINEVENT, (uintptr_t)ignore); // SIGWINEVENT
|
||||
pthread_t event_thread;
|
||||
pthread_create(&event_thread, NULL, win_threaded_event_processor, NULL);
|
||||
}
|
||||
|
||||
/* Initial Connection */
|
||||
|
||||
|
@ -181,5 +181,6 @@ void window_fill(window_t *window, uint32_t color);
|
||||
void init_graphics_window(window_t * window);
|
||||
void init_graphics_window_double_buffer(window_t * window);
|
||||
|
||||
void win_use_threaded_handler();
|
||||
|
||||
#endif
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "lib/graphics.h"
|
||||
#include "lib/window.h"
|
||||
#include "lib/decorations.h"
|
||||
#include "lib/pthread.h"
|
||||
|
||||
#define FONT_SIZE 13
|
||||
|
||||
@ -487,40 +488,6 @@ DEFN_SYSCALL0(mousedevice, 33);
|
||||
DECL_SYSCALL2(dup2, int, int);
|
||||
DECL_SYSCALL0(mkpipe);
|
||||
|
||||
DEFN_SYSCALL3(clone, 30, uintptr_t, uintptr_t, void *);
|
||||
DEFN_SYSCALL0(gettid, 41);
|
||||
|
||||
int clone(uintptr_t,uintptr_t,void*) __attribute__((alias("syscall_clone")));
|
||||
int gettid() __attribute__((alias("syscall_gettid")));
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
char * stack;
|
||||
void * ret_val;
|
||||
} pthread_t;
|
||||
typedef unsigned int pthread_attr_t;
|
||||
|
||||
#define PTHREAD_STACK_SIZE 10240
|
||||
|
||||
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *(*start_routine)(void *), void * arg) {
|
||||
char * stack = malloc(PTHREAD_STACK_SIZE);
|
||||
uintptr_t stack_top = (uintptr_t)stack + PTHREAD_STACK_SIZE;
|
||||
thread->stack = stack;
|
||||
thread->id = clone(stack_top, (uintptr_t)start_routine, arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pthread_exit(void * value) {
|
||||
/* Perform nice cleanup */
|
||||
#if 0
|
||||
/* XXX: LOCK */
|
||||
free(stack);
|
||||
/* XXX: Return value!? */
|
||||
#endif
|
||||
__asm__ ("jmp 0xFFFFB00F"); /* Force thread exit */
|
||||
}
|
||||
|
||||
|
||||
uint16_t term_width = 0;
|
||||
uint16_t term_height = 0;
|
||||
uint16_t char_width = 8;
|
||||
|
Loading…
Reference in New Issue
Block a user