THIS... IS... SPAAAAARTAAA!!!

This commit is contained in:
Kevin Lange 2012-02-12 19:30:36 -06:00
parent de0bbe739b
commit abf1e5c837
3 changed files with 70 additions and 22 deletions

View File

@ -74,6 +74,17 @@ static window_t * get_window (wid_t wid) {
return NULL; return NULL;
} }
static window_t * get_window_with_process (process_windows_t * pw, wid_t wid) {
foreach (m, pw->windows) {
window_t * w = (window_t *)m->value;
if (w->wid == wid) {
return w;
}
}
return NULL;
}
void init_process_list () { void init_process_list () {
process_list = list_create(); process_list = list_create();
} }
@ -134,7 +145,7 @@ void redraw_window(window_t *window, uint16_t x, uint16_t y, uint16_t width, uin
assert(0 <= y); assert(0 <= y);
assert(y < GFX_H); assert(y < GFX_H);
#endif #endif
fflush(stdout);
GFX(x,y) = ((uint32_t *)window->buffer)[TO_WINDOW_OFFSET(x,y)]; GFX(x,y) = ((uint32_t *)window->buffer)[TO_WINDOW_OFFSET(x,y)];
} }
} }
@ -166,16 +177,13 @@ void send_window_event (process_windows_t * pw, uint8_t event, w_window_t packet
} }
void process_window_command (int sig) { void process_window_command (int sig) {
printf("Received signal!\n");
foreach(n, process_list) { foreach(n, process_list) {
process_windows_t * pw = (process_windows_t *)n->value; process_windows_t * pw = (process_windows_t *)n->value;
printf("Processing PID=%d, pipe=%d\n", pw->pid, pw->command_pipe);
/* Are there any messages in this process's command pipe? */ /* Are there any messages in this process's command pipe? */
struct stat buf; struct stat buf;
fstat(pw->command_pipe, &buf); fstat(pw->command_pipe, &buf);
while (buf.st_size > 0) { while (buf.st_size > 0) {
printf("> Data available!\n");
w_window_t wwt; w_window_t wwt;
wins_packet_t header; wins_packet_t header;
read(pw->command_pipe, &header, sizeof(wins_packet_t)); read(pw->command_pipe, &header, sizeof(wins_packet_t));
@ -184,7 +192,8 @@ void process_window_command (int sig) {
case WC_NEWWINDOW: case WC_NEWWINDOW:
printf("[compositor] New window request\n"); printf("[compositor] New window request\n");
read(pw->command_pipe, &wwt, sizeof(w_window_t)); read(pw->command_pipe, &wwt, sizeof(w_window_t));
init_window(pw, _next_wid++, wwt.left, wwt.top, wwt.width, wwt.height, 0); //XXX: an actual index wwt.wid = _next_wid;
init_window(pw, _next_wid++, wwt.left, wwt.top, wwt.width, wwt.height, 5); //XXX: an actual index
send_window_event(pw, WE_NEWWINDOW, wwt); send_window_event(pw, WE_NEWWINDOW, wwt);
break; break;
@ -201,7 +210,7 @@ void process_window_command (int sig) {
case WC_DAMAGE: case WC_DAMAGE:
read(pw->command_pipe, &wwt, sizeof(w_window_t)); read(pw->command_pipe, &wwt, sizeof(w_window_t));
redraw_window(get_window(wwt.wid), wwt.left, wwt.top, wwt.width, wwt.height); redraw_window(get_window_with_process(pw, wwt.wid), wwt.left, wwt.top, wwt.width, wwt.height);
break; break;
default: default:
@ -215,7 +224,6 @@ void process_window_command (int sig) {
fstat(pw->command_pipe, &buf); fstat(pw->command_pipe, &buf);
} }
} }
printf("Done...\n");
} }
@ -477,7 +485,7 @@ void init_base_windows () {
printf("Creating root window...\n"); printf("Creating root window...\n");
window_t * root = init_window(pw, _next_wid++, 0, 0, graphics_width, graphics_height, 0); window_t * root = init_window(pw, _next_wid++, 0, 0, graphics_width, graphics_height, 0);
window_draw_sprite(root, sprites[1], 0, 0); window_draw_sprite(root, sprites[1], 0, 0);
redraw_full_window(root); //redraw_full_window(root);
/* Create the panel */ /* Create the panel */
printf("Creating panel window...\n"); printf("Creating panel window...\n");
@ -550,7 +558,8 @@ int main(int argc, char ** argv) {
/* Sit in a run loop */ /* Sit in a run loop */
while (1) { while (1) {
process_request(); process_request();
waitabit(); // XXX: Can't we deschedule? process_window_command(0);
//waitabit(); // XXX: Can't we deschedule?
} }
// XXX: Better have SIGINT/SIGSTOP handlers // XXX: Better have SIGINT/SIGSTOP handlers

View File

@ -67,6 +67,46 @@ window_t * init_window (process_windows_t * pw, wid_t wid, int32_t x, int32_t y,
char key[1024]; char key[1024];
SHMKEY(key, 1024, window); SHMKEY(key, 1024, window);
printf("[%d] : %s\n", getpid(), key);
/* And now the fucked up stuff happens */
window->buffer = (uint8_t *)syscall_shm_obtain(key, (width * height * WIN_B));
if (!window->buffer) {
fprintf(stderr, "[%d] [window] Could not create a buffer for a new window for pid %d!", getpid(), pw->pid);
free(window);
return NULL;
}
list_insert(pw->windows, window);
return window;
}
/*XXX ... */
window_t * init_window_client (process_windows_t * pw, wid_t wid, int32_t x, int32_t y, uint16_t width, uint16_t height, uint16_t index) {
printf("Creating window id %d (+%d,%d:%dx%d)\n", wid, x, y, width, height);
window_t * window = malloc(sizeof(window_t));
if (!window) {
fprintf(stderr, "[%d] [window] Could not malloc a window_t!", getpid());
return NULL;
}
window->owner = pw;
window->wid = wid;
window->bufid = 0;
window->width = width;
window->height = height;
window->x = x;
window->y = y;
window->z = index;
char key[1024];
SHMKEY_(key, 1024, window);
printf("[%d] : %s\n", getpid(), key);
/* And now the fucked up stuff happens */ /* And now the fucked up stuff happens */
window->buffer = (uint8_t *)syscall_shm_obtain(key, (width * height * WIN_B)); window->buffer = (uint8_t *)syscall_shm_obtain(key, (width * height * WIN_B));
@ -105,6 +145,10 @@ void free_window (window_t * window) {
void resize_window_buffer (window_t * window, uint16_t left, uint16_t top, uint16_t width, uint16_t height) { void resize_window_buffer (window_t * window, uint16_t left, uint16_t top, uint16_t width, uint16_t height) {
printf("window = 0x%x\n", window);
if (!window) {
return;
}
/* If the window has enlarged, we need to create a new buffer */ /* If the window has enlarged, we need to create a new buffer */
if ((width * height) > (window->width * window->height)) { if ((width * height) > (window->width * window->height)) {
/* Release the old buffer */ /* Release the old buffer */
@ -215,16 +259,13 @@ void wins_send_command (wid_t wid, uint16_t left, uint16_t top, uint16_t width,
write(process_windows->command_pipe, &header, sizeof(wins_packet_t)); write(process_windows->command_pipe, &header, sizeof(wins_packet_t));
write(process_windows->command_pipe, &packet, sizeof(w_window_t)); write(process_windows->command_pipe, &packet, sizeof(w_window_t));
printf("[debug] Sending signal...\n"); //syscall_send_signal(process_windows->pid, SIGWINEVENT);
syscall_send_signal(process_windows->pid, SIGWINEVENT);
/* Now wait for the command to be processed before returning */ /* Now wait for the command to be processed before returning */
if (wait_for_reply) { if (wait_for_reply) {
while((wins_command_recvd & 0xF) != (command & 0xF)) { syscall_send_signal(process_windows->pid, SIGWINEVENT);
printf("0x%x\n", wins_command_recvd); while((wins_command_recvd & 0xF) != (command & 0xF)) { }
}
} }
printf("[debug] Done sending signal?\n");
#if 0 #if 0
/* Were we waiting for that? */ /* Were we waiting for that? */
@ -239,6 +280,7 @@ void wins_send_command (wid_t wid, uint16_t left, uint16_t top, uint16_t width,
window_t * window_create (uint16_t left, uint16_t top, uint16_t width, uint16_t height) { window_t * window_create (uint16_t left, uint16_t top, uint16_t width, uint16_t height) {
wins_send_command(0, left, top, width, height, WC_NEWWINDOW, 1); wins_send_command(0, left, top, width, height, WC_NEWWINDOW, 1);
printf("[herpaderpderpderpderpderp =======================] Window created!\n");
assert(wins_last_new); assert(wins_last_new);
return (window_t *)wins_last_new; return (window_t *)wins_last_new;
@ -318,7 +360,8 @@ static void process_window_evt (uint8_t command, w_window_t evt) {
switch (command) { switch (command) {
window_t * window = NULL; window_t * window = NULL;
case WE_NEWWINDOW: case WE_NEWWINDOW:
window = init_window(process_windows, evt.wid, evt.left, evt.top, evt.width, evt.height, 0); printf("event window %d\n", evt.wid);
window = init_window_client(process_windows, evt.wid, evt.left, evt.top, evt.width, evt.height, 0);
wins_last_new = window; wins_last_new = window;
break; break;
@ -336,7 +379,6 @@ static void process_window_evt (uint8_t command, w_window_t evt) {
} }
static void process_evt (int sig) { static void process_evt (int sig) {
printf("[window] Child processing event signal\n");
/* Are there any messages in this process's event pipe? */ /* Are there any messages in this process's event pipe? */
struct stat buf; struct stat buf;
fstat(process_windows->event_pipe, &buf); fstat(process_windows->event_pipe, &buf);
@ -347,7 +389,7 @@ static void process_evt (int sig) {
read(process_windows->event_pipe, &header, sizeof(wins_packet_t)); read(process_windows->event_pipe, &header, sizeof(wins_packet_t));
/* Determine type, read, and dispatch */ /* Determine type, read, and dispatch */
switch (header.command_type | WE_GROUP_MASK) { switch (header.command_type & WE_GROUP_MASK) {
case WE_MOUSE_EVT: { case WE_MOUSE_EVT: {
w_mouse_t * mevt = malloc(sizeof(w_mouse_t)); 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));
@ -379,7 +421,6 @@ static void process_evt (int sig) {
fstat(process_windows->event_pipe, &buf); fstat(process_windows->event_pipe, &buf);
} }
printf("Done processing events.\n");
} }
void install_signal_handlers () { void install_signal_handlers () {
@ -432,9 +473,6 @@ int wins_connect() {
printf("ERROR: Failed to initialize an event pipe!\n"); printf("ERROR: Failed to initialize an event pipe!\n");
} }
printf("Event pipe initialized on file descriptor #%d\n", process_windows->event_pipe);
printf("Command pipe initialized on file descriptor #%d\n", process_windows->command_pipe);
/* Reset client status for next client */ /* Reset client status for next client */
wins_globals->client_done = 0; wins_globals->client_done = 0;
wins_globals->event_pipe = 0; wins_globals->event_pipe = 0;

View File

@ -112,6 +112,7 @@ typedef struct {
#define SHMKEY(buf,sz,win) snprintf(buf, sz, "%s.%d.%d.%d", WINS_SERVER_IDENTIFIER, win->owner->pid, win->wid, win->bufid); #define SHMKEY(buf,sz,win) snprintf(buf, sz, "%s.%d.%d.%d", WINS_SERVER_IDENTIFIER, win->owner->pid, win->wid, win->bufid);
#define SHMKEY_(buf,sz,win) snprintf(buf, sz, "%s.%d.%d.%d", WINS_SERVER_IDENTIFIER, getpid(), win->wid, win->bufid);
/* Windows */ /* Windows */