2014-04-06 05:36:07 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <syscall.h>
|
|
|
|
|
|
|
|
#include "yutani.h"
|
|
|
|
#include "pex.h"
|
|
|
|
#include "graphics.h"
|
2014-04-06 06:26:49 +04:00
|
|
|
#include "kbd.h"
|
2014-04-07 05:21:35 +04:00
|
|
|
#include "mouse.h"
|
2014-04-14 05:28:42 +04:00
|
|
|
#include "hashmap.h"
|
2014-04-17 10:50:57 +04:00
|
|
|
#include "list.h"
|
2014-04-06 05:36:07 +04:00
|
|
|
|
|
|
|
yutani_msg_t * yutani_wait_for(yutani_t * y, uint32_t type) {
|
|
|
|
do {
|
|
|
|
yutani_msg_t * out;
|
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
char tmp[MAX_PACKET_SIZE];
|
|
|
|
size = pex_recv(y->sock, tmp);
|
|
|
|
out = malloc(size);
|
|
|
|
memcpy(out, tmp, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (out->type == type) {
|
|
|
|
return out;
|
|
|
|
} else {
|
2014-04-17 10:50:57 +04:00
|
|
|
list_insert(y->queued, out);
|
2014-04-06 05:36:07 +04:00
|
|
|
}
|
|
|
|
} while (1); /* XXX: (!y->abort) */
|
|
|
|
}
|
|
|
|
|
2014-04-17 05:29:49 +04:00
|
|
|
size_t yutani_query(yutani_t * y) {
|
2014-04-17 10:50:57 +04:00
|
|
|
if (y->queued->length > 0) return 1;
|
2014-04-17 05:29:49 +04:00
|
|
|
return pex_query(y->sock);
|
|
|
|
}
|
|
|
|
|
2014-04-06 06:26:49 +04:00
|
|
|
yutani_msg_t * yutani_poll(yutani_t * y) {
|
|
|
|
yutani_msg_t * out;
|
2014-04-17 10:50:57 +04:00
|
|
|
|
|
|
|
if (y->queued->length > 0) {
|
|
|
|
node_t * node = list_dequeue(y->queued);
|
|
|
|
out = (yutani_msg_t *)node->value;
|
|
|
|
free(node);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2014-04-06 06:26:49 +04:00
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
char tmp[MAX_PACKET_SIZE];
|
|
|
|
size = pex_recv(y->sock, tmp);
|
|
|
|
out = malloc(size);
|
|
|
|
memcpy(out, tmp, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2014-04-17 05:29:49 +04:00
|
|
|
yutani_msg_t * yutani_poll_async(yutani_t * y) {
|
|
|
|
if (yutani_query(y) > 0) {
|
|
|
|
return yutani_poll(y);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-06 05:36:07 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_hello(void) {
|
|
|
|
size_t s = sizeof(struct yutani_message);
|
2014-04-07 05:21:35 +04:00
|
|
|
yutani_msg_t * msg = malloc(s);
|
2014-04-06 05:36:07 +04:00
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_HELLO;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:21:35 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_flip(yutani_wid_t wid) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_flip);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
2014-04-06 05:36:07 +04:00
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_FLIP;
|
|
|
|
msg->size = s;
|
|
|
|
|
2014-04-07 05:21:35 +04:00
|
|
|
struct yutani_msg_flip * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->wid = wid;
|
|
|
|
|
2014-04-06 05:36:07 +04:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_msg_t * yutani_msg_build_welcome(uint32_t width, uint32_t height) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_welcome);
|
2014-04-07 05:21:35 +04:00
|
|
|
yutani_msg_t * msg = malloc(s);
|
2014-04-06 05:36:07 +04:00
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_WELCOME;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_welcome * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->display_width = width;
|
|
|
|
mw->display_height = height;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_msg_t * yutani_msg_build_window_new(uint32_t width, uint32_t height) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_window_new);
|
2014-04-07 05:21:35 +04:00
|
|
|
yutani_msg_t * msg = malloc(s);
|
2014-04-06 05:36:07 +04:00
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_WINDOW_NEW;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_window_new * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->width = width;
|
|
|
|
mw->height = height;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:21:35 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_window_init(yutani_wid_t wid, uint32_t width, uint32_t height, uint32_t bufid) {
|
2014-04-06 05:36:07 +04:00
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_window_init);
|
2014-04-07 05:21:35 +04:00
|
|
|
yutani_msg_t * msg = malloc(s);
|
2014-04-06 05:36:07 +04:00
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_WINDOW_INIT;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_window_init * mw = (void *)msg->data;
|
|
|
|
|
2014-04-07 05:21:35 +04:00
|
|
|
mw->wid = wid;
|
2014-04-06 05:36:07 +04:00
|
|
|
mw->width = width;
|
|
|
|
mw->height = height;
|
|
|
|
mw->bufid = bufid;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:21:35 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_window_close(yutani_wid_t wid) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_window_close);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_WINDOW_CLOSE;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_flip * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->wid = wid;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-15 08:03:23 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_key_event(yutani_wid_t wid, key_event_t * event, key_event_state_t * state) {
|
2014-04-06 06:26:49 +04:00
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_key_event);
|
2014-04-07 05:21:35 +04:00
|
|
|
yutani_msg_t * msg = malloc(s);
|
2014-04-06 06:26:49 +04:00
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_KEY_EVENT;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_key_event * mw = (void *)msg->data;
|
|
|
|
|
2014-04-07 05:21:35 +04:00
|
|
|
mw->wid = wid;
|
2014-04-06 06:26:49 +04:00
|
|
|
memcpy(&mw->event, event, sizeof(key_event_t));
|
2014-04-15 08:03:23 +04:00
|
|
|
memcpy(&mw->state, state, sizeof(key_event_state_t));
|
2014-04-06 06:26:49 +04:00
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:21:35 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_mouse_event(yutani_wid_t wid, mouse_device_packet_t * event) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_mouse_event);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_MOUSE_EVENT;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_mouse_event * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->wid = wid;
|
|
|
|
memcpy(&mw->event, event, sizeof(mouse_device_packet_t));
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_msg_t * yutani_msg_build_window_move(yutani_wid_t wid, int32_t x, int32_t y) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_window_move);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_WINDOW_MOVE;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_window_move * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->wid = wid;
|
|
|
|
mw->x = x;
|
|
|
|
mw->y = y;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-07 07:42:29 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_window_stack(yutani_wid_t wid, int z) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_window_stack);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_WINDOW_STACK;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_window_stack * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->wid = wid;
|
|
|
|
mw->z = z;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-14 05:28:42 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_window_focus_change(yutani_wid_t wid, int focused) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_window_focus_change);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_WINDOW_FOCUS_CHANGE;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_window_focus_change * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->wid = wid;
|
|
|
|
mw->focused = focused;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-15 10:24:44 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_window_mouse_event(yutani_wid_t wid, int32_t new_x, int32_t new_y, int32_t old_x, int32_t old_y, uint8_t buttons, uint8_t command) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_window_mouse_event);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_WINDOW_MOUSE_EVENT;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_window_mouse_event * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->wid = wid;
|
|
|
|
mw->new_x = new_x;
|
|
|
|
mw->new_y = new_y;
|
|
|
|
mw->old_x = old_x;
|
|
|
|
mw->old_y = old_y;
|
|
|
|
mw->buttons = buttons;
|
|
|
|
mw->command = command;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-16 11:00:52 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_flip_region(yutani_wid_t wid, int32_t x, int32_t y, int32_t width, int32_t height) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_flip_region);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_FLIP_REGION;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_flip_region * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->wid = wid;
|
|
|
|
mw->x = x;
|
|
|
|
mw->y = y;
|
|
|
|
mw->width = width;
|
|
|
|
mw->height = height;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-17 10:50:57 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_window_resize(uint32_t type, yutani_wid_t wid, uint32_t width, uint32_t height, uint32_t bufid) {
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_window_resize);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = type;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_window_resize * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->wid = wid;
|
|
|
|
mw->width = width;
|
|
|
|
mw->height = height;
|
|
|
|
mw->bufid = bufid;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-18 11:18:19 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_window_advertise(yutani_wid_t wid, char * name) {
|
|
|
|
size_t n;
|
|
|
|
if (name) {
|
|
|
|
n = strlen(name) + 1;
|
|
|
|
} else {
|
|
|
|
n = 1;
|
|
|
|
}
|
|
|
|
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_window_advertise) + n;
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_WINDOW_ADVERTISE;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
struct yutani_msg_window_advertise * mw = (void *)msg->data;
|
|
|
|
|
|
|
|
mw->wid = wid;
|
|
|
|
mw->size = n-1;
|
|
|
|
if (n > 1) {
|
|
|
|
memcpy(mw->name, name, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_msg_t * yutani_msg_build_subscribe(void) {
|
|
|
|
size_t s = sizeof(struct yutani_message);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_SUBSCRIBE;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_msg_t * yutani_msg_build_unsubscribe(void) {
|
|
|
|
size_t s = sizeof(struct yutani_message);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_UNSUBSCRIBE;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_msg_t * yutani_msg_build_query_windows(void) {
|
|
|
|
size_t s = sizeof(struct yutani_message);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_QUERY_WINDOWS;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_msg_t * yutani_msg_build_notify(void) {
|
|
|
|
size_t s = sizeof(struct yutani_message);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_NOTIFY;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-19 06:23:45 +04:00
|
|
|
yutani_msg_t * yutani_msg_build_session_end(void) {
|
|
|
|
size_t s = sizeof(struct yutani_message);
|
|
|
|
yutani_msg_t * msg = malloc(s);
|
|
|
|
|
|
|
|
msg->magic = YUTANI_MSG__MAGIC;
|
|
|
|
msg->type = YUTANI_MSG_SESSION_END;
|
|
|
|
msg->size = s;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-04-06 05:36:07 +04:00
|
|
|
int yutani_msg_send(yutani_t * y, yutani_msg_t * msg) {
|
|
|
|
return pex_reply(y->sock, msg->size, (char *)msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_t * yutani_context_create(FILE * socket) {
|
|
|
|
yutani_t * out = malloc(sizeof(yutani_t));
|
|
|
|
|
|
|
|
out->sock = socket;
|
|
|
|
out->display_width = 0;
|
|
|
|
out->display_height = 0;
|
2014-04-14 05:28:42 +04:00
|
|
|
out->windows = hashmap_create_int(10);
|
2014-04-17 10:50:57 +04:00
|
|
|
out->queued = list_create();
|
2014-04-06 05:36:07 +04:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_t * yutani_init(void) {
|
|
|
|
/* XXX: Display, etc? */
|
2014-04-13 05:59:43 +04:00
|
|
|
if (!getenv("DISPLAY")) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
FILE * c = pex_connect(getenv("DISPLAY"));
|
2014-04-06 05:36:07 +04:00
|
|
|
|
|
|
|
if (!c) return NULL; /* Connection failed. */
|
|
|
|
|
|
|
|
yutani_t * y = yutani_context_create(c);
|
|
|
|
yutani_msg_t * m = yutani_msg_build_hello();
|
|
|
|
int result = yutani_msg_send(y, m);
|
|
|
|
free(m);
|
|
|
|
|
|
|
|
m = yutani_wait_for(y, YUTANI_MSG_WELCOME);
|
|
|
|
struct yutani_msg_welcome * mw = (void *)&m->data;
|
|
|
|
y->display_width = mw->display_width;
|
|
|
|
y->display_height = mw->display_height;
|
|
|
|
free(m);
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_window_t * yutani_window_create(yutani_t * y, int width, int height) {
|
|
|
|
yutani_window_t * win = malloc(sizeof(yutani_window_t));
|
|
|
|
|
|
|
|
yutani_msg_t * m = yutani_msg_build_window_new(width, height);
|
|
|
|
int result = yutani_msg_send(y, m);
|
2014-04-06 11:30:00 +04:00
|
|
|
free(m);
|
2014-04-06 05:36:07 +04:00
|
|
|
|
|
|
|
m = yutani_wait_for(y, YUTANI_MSG_WINDOW_INIT);
|
|
|
|
struct yutani_msg_window_init * mw = (void *)&m->data;
|
|
|
|
|
|
|
|
win->width = mw->width;
|
|
|
|
win->height = mw->height;
|
|
|
|
win->bufid = mw->bufid;
|
2014-04-07 05:21:35 +04:00
|
|
|
win->wid = mw->wid;
|
2014-04-14 05:28:42 +04:00
|
|
|
win->focused = 0;
|
|
|
|
|
|
|
|
hashmap_set(y->windows, (void*)win->wid, win);
|
2014-04-06 05:36:07 +04:00
|
|
|
|
|
|
|
char key[1024];
|
|
|
|
YUTANI_SHMKEY(key, 1024, win);
|
|
|
|
|
|
|
|
size_t size = (width * height * 4);
|
|
|
|
win->buffer = (uint8_t *)syscall_shm_obtain(key, &size);
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:21:35 +04:00
|
|
|
void yutani_flip(yutani_t * y, yutani_window_t * win) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_flip(win->wid);
|
|
|
|
int result = yutani_msg_send(y, m);
|
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
2014-04-16 11:00:52 +04:00
|
|
|
void yutani_flip_region(yutani_t * yctx, yutani_window_t * win, int32_t x, int32_t y, int32_t width, int32_t height) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_flip_region(win->wid, x, y, width, height);
|
|
|
|
int result = yutani_msg_send(yctx, m);
|
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:21:35 +04:00
|
|
|
void yutani_close(yutani_t * y, yutani_window_t * win) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_window_close(win->wid);
|
2014-04-06 05:36:07 +04:00
|
|
|
int result = yutani_msg_send(y, m);
|
2014-04-06 11:30:00 +04:00
|
|
|
free(m);
|
2014-04-06 05:36:07 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 05:21:35 +04:00
|
|
|
void yutani_window_move(yutani_t * yctx, yutani_window_t * window, int x, int y) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_window_move(window->wid, x, y);
|
|
|
|
int reuslt = yutani_msg_send(yctx, m);
|
2014-04-07 07:42:29 +04:00
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void yutani_set_stack(yutani_t * yctx, yutani_window_t * window, int z) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_window_stack(window->wid, z);
|
|
|
|
int reuslt = yutani_msg_send(yctx, m);
|
2014-04-17 10:50:57 +04:00
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void yutani_window_resize(yutani_t * yctx, yutani_window_t * window, uint32_t width, uint32_t height) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_window_resize(YUTANI_MSG_RESIZE_REQUEST, window->wid, width, height, 0);
|
|
|
|
int result = yutani_msg_send(yctx, m);
|
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void yutani_window_resize_offer(yutani_t * yctx, yutani_window_t * window, uint32_t width, uint32_t height) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_window_resize(YUTANI_MSG_RESIZE_OFFER, window->wid, width, height, 0);
|
|
|
|
int result = yutani_msg_send(yctx, m);
|
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void yutani_window_resize_accept(yutani_t * yctx, yutani_window_t * window, uint32_t width, uint32_t height) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_window_resize(YUTANI_MSG_RESIZE_ACCEPT, window->wid, width, height, 0);
|
|
|
|
int result = yutani_msg_send(yctx, m);
|
|
|
|
free(m);
|
|
|
|
|
|
|
|
/* Now wait for the new bufid */
|
|
|
|
m = yutani_wait_for(yctx, YUTANI_MSG_RESIZE_BUFID);
|
|
|
|
struct yutani_msg_window_resize * wr = (void*)m->data;
|
|
|
|
|
|
|
|
if (window->wid != wr->wid) {
|
|
|
|
/* I am not sure what to do here. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the window */
|
|
|
|
window->width = wr->width;
|
|
|
|
window->height = wr->height;
|
|
|
|
window->oldbufid = window->bufid;
|
|
|
|
window->bufid = wr->bufid;
|
|
|
|
free(m);
|
|
|
|
|
|
|
|
/* Allocate the buffer */
|
|
|
|
{
|
|
|
|
char key[1024];
|
|
|
|
YUTANI_SHMKEY(key, 1024, window);
|
|
|
|
|
|
|
|
size_t size = (window->width * window->height * 4);
|
|
|
|
window->buffer = (uint8_t *)syscall_shm_obtain(key, &size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void yutani_window_resize_done(yutani_t * yctx, yutani_window_t * window) {
|
|
|
|
/* Destroy the old buffer */
|
|
|
|
{
|
|
|
|
char key[1024];
|
|
|
|
YUTANI_SHMKEY_EXP(key, 1024, window->oldbufid);
|
|
|
|
syscall_shm_release(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
yutani_msg_t * m = yutani_msg_build_window_resize(YUTANI_MSG_RESIZE_DONE, window->wid, window->width, window->height, window->bufid);
|
|
|
|
int result = yutani_msg_send(yctx, m);
|
2014-04-07 05:21:35 +04:00
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
2014-04-18 11:18:19 +04:00
|
|
|
void yutani_window_advertise(yutani_t * yctx, yutani_window_t * window, char * name) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_window_advertise(window->wid, name);
|
|
|
|
int result = yutani_msg_send(yctx, m);
|
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void yutani_subscribe_windows(yutani_t * y) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_subscribe();
|
|
|
|
int result = yutani_msg_send(y, m);
|
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void yutani_unsubscribe_windows(yutani_t * y) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_unsubscribe();
|
|
|
|
int result = yutani_msg_send(y, m);
|
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void yutani_query_windows(yutani_t * y) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_query_windows();
|
|
|
|
int result = yutani_msg_send(y, m);
|
2014-04-19 06:23:45 +04:00
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void yutani_session_end(yutani_t * y) {
|
|
|
|
yutani_msg_t * m = yutani_msg_build_session_end();
|
|
|
|
int result = yutani_msg_send(y, m);
|
2014-04-18 11:18:19 +04:00
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
2014-04-06 05:36:07 +04:00
|
|
|
gfx_context_t * init_graphics_yutani(yutani_window_t * window) {
|
|
|
|
gfx_context_t * out = malloc(sizeof(gfx_context_t));
|
|
|
|
out->width = window->width;
|
|
|
|
out->height = window->height;
|
|
|
|
out->depth = 32;
|
|
|
|
out->size = GFX_H(out) * GFX_W(out) * GFX_B(out);
|
|
|
|
out->buffer = window->buffer;
|
|
|
|
out->backbuffer = out->buffer;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx_context_t * init_graphics_yutani_double_buffer(yutani_window_t * window) {
|
|
|
|
gfx_context_t * out = init_graphics_yutani(window);
|
|
|
|
out->backbuffer = malloc(sizeof(uint32_t) * GFX_W(out) * GFX_H(out));
|
|
|
|
return out;
|
|
|
|
}
|
2014-04-06 06:26:49 +04:00
|
|
|
|
2014-04-07 00:25:04 +04:00
|
|
|
void reinit_graphics_yutani(gfx_context_t * out, yutani_window_t * window) {
|
|
|
|
out->width = window->width;
|
|
|
|
out->height = window->height;
|
|
|
|
out->depth = 32;
|
|
|
|
out->size = GFX_H(out) * GFX_W(out) * GFX_B(out);
|
|
|
|
if (out->buffer == out->backbuffer) {
|
|
|
|
out->buffer = window->buffer;
|
|
|
|
out->backbuffer = out->buffer;
|
|
|
|
} else {
|
|
|
|
out->buffer = window->buffer;
|
|
|
|
out->backbuffer = realloc(out->backbuffer, sizeof(uint32_t) * GFX_W(out) * GFX_H(out));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|