Well, that works.

This commit is contained in:
Kevin Lange 2012-02-13 16:21:52 -06:00
parent 9e4d78e721
commit c211c61369
2 changed files with 16 additions and 46 deletions

View File

@ -22,15 +22,6 @@
#include "../kernel/include/signal.h"
#if 0
DEFN_SYSCALL2(shm_obtain, 35, char *, int)
DEFN_SYSCALL1(shm_release, 36, char *)
DEFN_SYSCALL2(send_signal, 37, int, int)
DEFN_SYSCALL2(sys_signal, 38, int, int)
DEFN_SYSCALL2(share_fd, 39, int, int)
DEFN_SYSCALL1(get_fd, 40, int)
#endif
DECL_SYSCALL0(mkpipe);
@ -173,7 +164,7 @@ void send_window_event (process_windows_t * pw, uint8_t event, w_window_t packet
// XXX: we have a race condition here
write(pw->event_pipe, &header, sizeof(wins_packet_t));
write(pw->event_pipe, &packet, sizeof(w_window_t));
syscall_send_signal(pw->pid, 35); // SIGWINEVENT
syscall_send_signal(pw->pid, SIGWINEVENT); // SIGWINEVENT
}
void process_window_command (int sig) {
@ -183,11 +174,16 @@ void process_window_command (int sig) {
/* Are there any messages in this process's command pipe? */
struct stat buf;
fstat(pw->command_pipe, &buf);
while (buf.st_size > 0) {
int max_requests_per_cycle = 10;
while ((buf.st_size > 0) && (max_requests_per_cycle > 0)) {
w_window_t wwt;
wins_packet_t header;
read(pw->command_pipe, &header, sizeof(wins_packet_t));
max_requests_per_cycle--;
switch (header.command_type) {
case WC_NEWWINDOW:
printf("[compositor] New window request\n");
@ -265,6 +261,7 @@ void init_request_system () {
}
void process_request () {
fflush(stdout);
if (_request_page->client_done) {
process_windows_t * pw = malloc(sizeof(process_windows_t));
pw->pid = _request_page->client_pid;
@ -272,13 +269,12 @@ void process_request () {
pw->command_pipe = syscall_mkpipe();
pw->windows = list_create();
printf("Created two pipes (%d and %d) and sharing them with %d\n", pw->event_pipe, pw->command_pipe, pw->pid);
_request_page->event_pipe = syscall_share_fd(pw->event_pipe, pw->pid);
_request_page->command_pipe = syscall_share_fd(pw->command_pipe, pw->pid);
_request_page->client_done = 0;
_request_page->server_done = 1;
list_insert(process_list, pw);
printf("A client (%d) replied to\n", pw->pid);
}
}
@ -301,7 +297,6 @@ void delete_process (process_windows_t * pw) {
void init_signal_handlers () {
printf("Accepting SIGWINEVENT with 0x%x...\n", process_window_command);
syscall_sys_signal(SIGWINEVENT, (uintptr_t)process_window_command); // SIGWINEVENT
}
@ -398,9 +393,6 @@ static void test() {
}
void run_startup_item(startup_item * item) {
#if 0 // No printing!
printf("[compositor] Running startup item: %s\n", item->name);
#endif
item->func();
progress += item->time;
}
@ -480,15 +472,12 @@ void init_base_windows () {
pw->windows = list_create();
list_insert(process_list, pw);
#if 1
/* Create the background window */
printf("Creating root window...\n");
window_t * root = init_window(pw, _next_wid++, 0, 0, graphics_width, graphics_height, 0);
window_draw_sprite(root, sprites[1], 0, 0);
redraw_full_window(root);
/* Create the panel */
printf("Creating panel window...\n");
window_t * panel = init_window(pw, _next_wid++, 0, 0, graphics_width, 24, -1);
window_fill(panel, rgb(0,120,230));
init_sprite(2, "/usr/share/panel.bmp", NULL);
@ -496,7 +485,6 @@ void init_base_windows () {
window_draw_sprite(panel, sprites[2], i, 0);
}
redraw_full_window(panel);
#endif
}
int main(int argc, char ** argv) {
@ -538,8 +526,6 @@ int main(int argc, char ** argv) {
init_graphics();
#endif
printf("Loading up base windows.\n");
/* Create the root and panel */
init_base_windows();
@ -551,7 +537,6 @@ int main(int argc, char ** argv) {
if (!fork()) {
waitabit();
printf("Drawing lines~\n");
char * args[] = {"/bin/drawlines", "100","100","300","300",NULL};
execve(args[0], args, NULL);
}
@ -561,16 +546,14 @@ int main(int argc, char ** argv) {
waitabit();
waitabit();
waitabit();
printf("Drawing lines~\n");
char * args[] = {"/bin/drawlines", "200","200","400","400",NULL};
execve(args[0], args, NULL);
}
printf("waiting for clients...\n");
/* Sit in a run loop */
while (1) {
process_request();
process_window_command(0);
//waitabit(); // XXX: Can't we deschedule?
}
// XXX: Better have SIGINT/SIGSTOP handlers

View File

@ -47,8 +47,6 @@ static window_t * get_window (wid_t wid) {
window_t * init_window (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());
@ -67,7 +65,6 @@ window_t * init_window (process_windows_t * pw, wid_t wid, int32_t x, int32_t y,
char key[1024];
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));
@ -86,8 +83,6 @@ window_t * init_window (process_windows_t * pw, wid_t wid, int32_t x, int32_t y,
/*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());
@ -106,7 +101,6 @@ window_t * init_window_client (process_windows_t * pw, wid_t wid, int32_t x, int
char key[1024];
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));
@ -145,7 +139,6 @@ 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) {
printf("window = 0x%x\n", window);
if (!window) {
return;
}
@ -259,7 +252,6 @@ 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, &packet, sizeof(w_window_t));
//syscall_send_signal(process_windows->pid, SIGWINEVENT);
/* Now wait for the command to be processed before returning */
if (wait_for_reply) {
@ -267,22 +259,15 @@ void wins_send_command (wid_t wid, uint16_t left, uint16_t top, uint16_t width,
while((wins_command_recvd & 0xF) != (command & 0xF)) { }
}
#if 0
/* Were we waiting for that? */
if (wins_command_recvd != command) {
fprintf(stderr, "[%d] [window] WARN: Waited for %d, got %d\n", getpid(), command, wins_command_recvd);
}
#endif
UNLOCK(wins_command_lock);
}
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);
printf("[herpaderpderpderpderpderp =======================] Window created!\n");
assert(wins_last_new);
while (!wins_last_new);
return (window_t *)wins_last_new;
}
@ -360,7 +345,6 @@ static void process_window_evt (uint8_t command, w_window_t evt) {
switch (command) {
window_t * window = NULL;
case WE_NEWWINDOW:
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;
break;
@ -462,15 +446,18 @@ int wins_connect() {
/* Mark us as done and wait for the server */
wins_globals->client_done = 1;
while (!wins_globals->server_done);
assert(process_windows && "process_windows was not initialized!");
process_windows->pid = wins_globals->server_pid;
process_windows->event_pipe = syscall_get_fd(wins_globals->event_pipe);
process_windows->command_pipe = syscall_get_fd(wins_globals->command_pipe);
if (process_windows->event_pipe < 0) {
printf("ERROR: Failed to initialize an event pipe!\n");
fprintf(stderr, "ERROR: Failed to initialize an event pipe!\n");
return 1;
}
/* Reset client status for next client */