Continued progress on Yutani
This commit is contained in:
parent
60d66da7e6
commit
7009e4ec1c
2
Makefile
2
Makefile
@ -115,7 +115,7 @@ term: system
|
||||
term-kvm: system
|
||||
${EMU} ${EMUARGS} ${EMUKVM} -append "$(VID_QEMU) $(START_SINGLE) $(DISK_ROOT)"
|
||||
term-beta: system
|
||||
${EMU} ${EMUARGS} ${EMUKVM} -append "$(VID_QEMU) start=--single-beta $(DISK_ROOT)"
|
||||
${EMU} ${EMUARGS} ${EMUKVM} -append "$(VID_QEMU) start=--single-beta logtoserial=3 $(DISK_ROOT)"
|
||||
headless: system
|
||||
${EMU} ${EMUARGS} -display none -append "$(START_VGA) $(DISK_ROOT)"
|
||||
|
||||
|
BIN
hdd/usr/share/arrow.png
Normal file
BIN
hdd/usr/share/arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 704 B |
@ -21,6 +21,23 @@ void * hashmap_string_dupe(void * key) {
|
||||
return strdup(key);
|
||||
}
|
||||
|
||||
unsigned int hashmap_int_hash(void * key) {
|
||||
return (unsigned int)key;
|
||||
}
|
||||
|
||||
int hashmap_int_comp(void * a, void * b) {
|
||||
return (int)a == (int)b;
|
||||
}
|
||||
|
||||
void * hashmap_int_dupe(void * key) {
|
||||
return key;
|
||||
}
|
||||
|
||||
static void hashmap_int_free(void * ptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
hashmap_t * hashmap_create(int size) {
|
||||
hashmap_t * map = malloc(sizeof(hashmap_t));
|
||||
|
||||
@ -37,7 +54,23 @@ hashmap_t * hashmap_create(int size) {
|
||||
return map;
|
||||
}
|
||||
|
||||
void * hashmap_set(hashmap_t * map, char * key, void * value) {
|
||||
hashmap_t * hashmap_create_int(int size) {
|
||||
hashmap_t * map = malloc(sizeof(hashmap_t));
|
||||
|
||||
map->hash_func = &hashmap_int_hash;
|
||||
map->hash_comp = &hashmap_int_comp;
|
||||
map->hash_key_dup = &hashmap_int_dupe;
|
||||
map->hash_key_free = &hashmap_int_free;
|
||||
map->hash_val_free = &free;
|
||||
|
||||
map->size = size;
|
||||
map->entries = malloc(sizeof(hashmap_entry_t *) * size);
|
||||
memset(map->entries, 0x00, sizeof(hashmap_entry_t *) * size);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
void * hashmap_set(hashmap_t * map, void * key, void * value) {
|
||||
unsigned int hash = map->hash_func(key) % map->size;
|
||||
|
||||
hashmap_entry_t * x = map->entries[hash];
|
||||
@ -70,7 +103,7 @@ void * hashmap_set(hashmap_t * map, char * key, void * value) {
|
||||
}
|
||||
}
|
||||
|
||||
void * hashmap_get(hashmap_t * map, char * key) {
|
||||
void * hashmap_get(hashmap_t * map, void * key) {
|
||||
unsigned int hash = map->hash_func(key) % map->size;
|
||||
|
||||
hashmap_entry_t * x = map->entries[hash];
|
||||
@ -87,7 +120,7 @@ void * hashmap_get(hashmap_t * map, char * key) {
|
||||
}
|
||||
}
|
||||
|
||||
void * hashmap_remove(hashmap_t * map, char * key) {
|
||||
void * hashmap_remove(hashmap_t * map, void * key) {
|
||||
unsigned int hash = map->hash_func(key) % map->size;
|
||||
|
||||
hashmap_entry_t * x = map->entries[hash];
|
||||
@ -119,7 +152,7 @@ void * hashmap_remove(hashmap_t * map, char * key) {
|
||||
}
|
||||
}
|
||||
|
||||
int hashmap_has(hashmap_t * map, char * key) {
|
||||
int hashmap_has(hashmap_t * map, void * key) {
|
||||
unsigned int hash = map->hash_func(key) % map->size;
|
||||
|
||||
hashmap_entry_t * x = map->entries[hash];
|
||||
|
@ -33,10 +33,11 @@ typedef struct hashmap {
|
||||
} hashmap_t;
|
||||
|
||||
hashmap_t * hashmap_create(int size);
|
||||
void * hashmap_set(hashmap_t * map, char * key, void * value);
|
||||
void * hashmap_get(hashmap_t * map, char * key);
|
||||
void * hashmap_remove(hashmap_t * map, char * key);
|
||||
int hashmap_has(hashmap_t * map, char * key);
|
||||
hashmap_t * hashmap_create_int(int size);
|
||||
void * hashmap_set(hashmap_t * map, void * key, void * value);
|
||||
void * hashmap_get(hashmap_t * map, void * key);
|
||||
void * hashmap_remove(hashmap_t * map, void * key);
|
||||
int hashmap_has(hashmap_t * map, void * key);
|
||||
list_t * hashmap_keys(hashmap_t * map);
|
||||
list_t * hashmap_values(hashmap_t * map);
|
||||
void hashmap_free(hashmap_t * map);
|
||||
|
@ -43,6 +43,8 @@ class CCompiler(object):
|
||||
'"lib/graphics.h"': (None, 'lib/graphics.o', ['<png.h>']),
|
||||
'"lib/kbd.h"': (None, 'lib/kbd.o', []),
|
||||
'"lib/list.h"': (None, 'lib/list.o', []),
|
||||
'"lib/hashmap.h"': (None, 'lib/hashmap.o', ['"lib/list.h"']),
|
||||
'"lib/tree.h"': (None, 'lib/tree.o', ['"lib/list.h"']),
|
||||
'"lib/testing.h"': (None, 'lib/testing.o', []),
|
||||
'"lib/pthread.h"': (None, 'lib/pthread.o', []),
|
||||
'"lib/sha2.h"': (None, 'lib/sha2.o', []),
|
||||
|
@ -11,14 +11,18 @@
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <cairo.h>
|
||||
|
||||
#include "lib/graphics.h"
|
||||
#include "lib/pthread.h"
|
||||
#include "lib/mouse.h"
|
||||
#include "lib/kbd.h"
|
||||
#include "lib/pex.h"
|
||||
#include "lib/yutani.h"
|
||||
#include "lib/hashmap.h"
|
||||
#include "lib/list.h"
|
||||
|
||||
#include "../kernel/include/mouse.h"
|
||||
#include "yutani_int.h"
|
||||
|
||||
/**
|
||||
* Parse arguments
|
||||
@ -27,37 +31,27 @@ int parse_args(int argc, char * argv[]) {
|
||||
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
yutani_wid_t wid;
|
||||
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
||||
uint8_t * buffer;
|
||||
uint32_t bufid;/* We occasionally replace the buffer; each is uniquely-indexed */
|
||||
|
||||
uint8_t focused;
|
||||
|
||||
uint32_t owner;
|
||||
} server_window_t;
|
||||
|
||||
static list_t * windows = NULL;
|
||||
|
||||
static int next_buf_id(void) {
|
||||
static int _next = 0;
|
||||
static int _next = 1;
|
||||
return _next++;
|
||||
}
|
||||
|
||||
static server_window_t * server_window_create(int width, int height, uint32_t owner) {
|
||||
server_window_t * win = malloc(sizeof(server_window_t));
|
||||
static int next_wid(void) {
|
||||
static int _next = 1;
|
||||
return _next++;
|
||||
}
|
||||
|
||||
if (!windows) {
|
||||
windows = list_create();
|
||||
}
|
||||
static yutani_server_window_t * server_window_create(yutani_globals_t * yg, int width, int height, uint32_t owner) {
|
||||
yutani_server_window_t * win = malloc(sizeof(yutani_server_window_t));
|
||||
|
||||
win->wid = next_wid();
|
||||
win->owner = owner;
|
||||
list_insert(windows, win);
|
||||
list_insert(yg->windows, win);
|
||||
hashmap_set(yg->wids_to_windows, (void*)win->wid, win);
|
||||
|
||||
win->x = 0;
|
||||
win->y = 0;
|
||||
win->z = 0;
|
||||
win->width = width;
|
||||
win->height = height;
|
||||
win->bufid = next_buf_id();
|
||||
@ -79,12 +73,17 @@ static server_window_t * server_window_create(int width, int height, uint32_t ow
|
||||
*/
|
||||
void * mouse_input(void * garbage) {
|
||||
int mfd = open("/dev/mouse", O_RDONLY);
|
||||
|
||||
yutani_t * y = yutani_init();
|
||||
mouse_device_packet_t packet;
|
||||
|
||||
while (1) {
|
||||
int r = read(mfd, (char *)&packet, sizeof(mouse_device_packet_t));
|
||||
|
||||
fprintf(stderr, "[mouse] mouse packet get! move %dx%d buttons 0x%x\n", packet.x_difference, packet.y_difference, packet.buttons);
|
||||
if (r > 0) {
|
||||
yutani_msg_t * m = yutani_msg_build_mouse_event(0, &packet);
|
||||
int result = yutani_msg_send(y, m);
|
||||
free(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,14 +98,14 @@ void * keyboard_input(void * garbage) {
|
||||
int kfd = open("/dev/kbd", O_RDONLY);
|
||||
|
||||
yutani_t * y = yutani_init();
|
||||
key_event_t event;
|
||||
|
||||
while (1) {
|
||||
char buf[1];
|
||||
int r = read(kfd, buf, 1);
|
||||
if (r > 0) {
|
||||
key_event_t event;
|
||||
kbd_scancode(buf[0], &event);
|
||||
yutani_msg_t * m = yutani_msg_build_key_event(&event);
|
||||
yutani_msg_t * m = yutani_msg_build_key_event(0, &event);
|
||||
int result = yutani_msg_send(y, m);
|
||||
free(m);
|
||||
}
|
||||
@ -121,7 +120,7 @@ struct font_def {
|
||||
char * path;
|
||||
};
|
||||
|
||||
struct font_def fonts[] = {
|
||||
static struct font_def fonts[] = {
|
||||
FONT("sans-serif", "DejaVuSans.ttf"),
|
||||
FONT("sans-serif.bold", "DejaVuSans-Bold.ttf"),
|
||||
FONT("sans-serif.italic", "DejaVuSans-Oblique.ttf"),
|
||||
@ -133,7 +132,7 @@ struct font_def fonts[] = {
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
char * precacheMemFont(char * ident, char * name) {
|
||||
static char * precache_shmfont(char * ident, char * name) {
|
||||
FILE * f = fopen(name, "r");
|
||||
size_t s = 0;
|
||||
fseek(f, 0, SEEK_END);
|
||||
@ -150,32 +149,190 @@ char * precacheMemFont(char * ident, char * name) {
|
||||
return font;
|
||||
}
|
||||
|
||||
void load_fonts() {
|
||||
static void load_fonts(void) {
|
||||
int i = 0;
|
||||
while (fonts[i].identifier) {
|
||||
fprintf(stderr, "[compositor] Loading font %s -> %s\n", fonts[i].path, fonts[i].identifier);
|
||||
precacheMemFont(fonts[i].identifier, fonts[i].path);
|
||||
precache_shmfont(fonts[i].identifier, fonts[i].path);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
static void redraw_windows(gfx_context_t * framebuffer) {
|
||||
draw_fill(framebuffer, rgb(150,150,240));
|
||||
foreach(node, windows) {
|
||||
server_window_t * win = (void*)node->value;
|
||||
static void draw_cursor(yutani_globals_t * yg) {
|
||||
draw_sprite(yg->backend_ctx, &yg->mouse_sprite, yg->mouse_x / MOUSE_SCALE - MOUSE_OFFSET_X, yg->mouse_y / MOUSE_SCALE - MOUSE_OFFSET_Y);
|
||||
}
|
||||
|
||||
sprite_t tmp;
|
||||
tmp.width = win->width;
|
||||
tmp.height = win->height;
|
||||
tmp.bitmap = (uint32_t*)win->buffer;
|
||||
tmp.alpha = ALPHA_EMBEDDED;
|
||||
tmp.masks = NULL;
|
||||
tmp.blank = 0x0;
|
||||
static void yutani_add_clip(yutani_globals_t * yg, double x, double y, double w, double h) {
|
||||
cairo_rectangle(yg->framebuffer_ctx, x, y, w, h);
|
||||
}
|
||||
|
||||
draw_sprite(framebuffer, &tmp, 0, 0);
|
||||
static void save_cairo_states(yutani_globals_t * yg) {
|
||||
cairo_save(yg->framebuffer_ctx);
|
||||
cairo_save(yg->selectbuffer_ctx);
|
||||
}
|
||||
|
||||
static void restore_cairo_states(yutani_globals_t * yg) {
|
||||
cairo_restore(yg->framebuffer_ctx);
|
||||
cairo_restore(yg->selectbuffer_ctx);
|
||||
}
|
||||
|
||||
static void yutani_set_clip(yutani_globals_t * yg) {
|
||||
cairo_clip(yg->framebuffer_ctx);
|
||||
}
|
||||
|
||||
static int window_is_top(yutani_globals_t * yg, yutani_server_window_t * window) {
|
||||
/* For now, just use simple z-order */
|
||||
return window->z == YUTANI_ZORDER_TOP;
|
||||
}
|
||||
|
||||
static int window_is_bottom(yutani_globals_t * yg, yutani_server_window_t * window) {
|
||||
/* For now, just use simple z-order */
|
||||
return window->z == YUTANI_ZORDER_BOTTOM;
|
||||
}
|
||||
|
||||
static int yutani_blit_window(yutani_globals_t * yg, yutani_server_window_t * window, yutani_server_window_t * modifiers) {
|
||||
|
||||
/* If there are no modifiers to be set, use the window's existing setup */
|
||||
if (!modifiers) {
|
||||
modifiers = window;
|
||||
}
|
||||
|
||||
flip(framebuffer);
|
||||
/* Obtain the previously initialized cairo contexts */
|
||||
cairo_t * cr = yg->framebuffer_ctx;
|
||||
cairo_t * cs = yg->selectbuffer_ctx;
|
||||
|
||||
/* Window stride is always 4 bytes per pixel... */
|
||||
int stride = window->width * 4;
|
||||
|
||||
/* Initialize a cairo surface object for this window */
|
||||
cairo_surface_t * surf = cairo_image_surface_create_for_data(
|
||||
window->buffer, CAIRO_FORMAT_ARGB32, window->width, window->height, stride);
|
||||
|
||||
/* Save cairo contexts for both rendering and selectbuffer */
|
||||
cairo_save(cr);
|
||||
cairo_save(cs);
|
||||
|
||||
/*
|
||||
* Offset the rendering context appropriately for the position of the window
|
||||
* based on the modifier paramters
|
||||
*/
|
||||
cairo_translate(cr, modifiers->x, modifiers->y);
|
||||
cairo_translate(cs, modifiers->x, modifiers->y);
|
||||
|
||||
/* Top and bottom windows can not be rotated. */
|
||||
if (!window_is_top(yg, window) && !window_is_bottom(yg, window)) {
|
||||
/* Calcuate radians from degrees */
|
||||
#if 0
|
||||
double r = window->rotation * M_PI / 180.0;
|
||||
|
||||
/* Rotate the render context about the center of the window */
|
||||
cairo_translate(cr, (int)( window->width / 2), (int)( window->height / 2));
|
||||
cairo_rotate(cr, r);
|
||||
cairo_translate(cr, (int)(-window->width / 2), (int)(-window->height / 2));
|
||||
|
||||
/* Rotate the selectbuffer context about the center of the window */
|
||||
cairo_translate(cs, (int)( window->width / 2), (int)( window->height / 2));
|
||||
cairo_rotate(cs, r);
|
||||
cairo_translate(cs, (int)(-window->width / 2), (int)(-window->height / 2));
|
||||
|
||||
/* Prefer faster filter when rendering rotated windows */
|
||||
cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_FAST);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Paint window */
|
||||
cairo_set_source_surface(cr, surf, 0, 0);
|
||||
cairo_paint(cr);
|
||||
|
||||
/* Clean up */
|
||||
cairo_surface_destroy(surf);
|
||||
|
||||
/* Paint select buffer */
|
||||
cairo_set_source_rgb(cs, 0, ((window->z & 0xFF00) >> 8) / 255.0, (window->z & 0xFF) / 255.0);
|
||||
cairo_rectangle(cs, 0, 0, window->width, window->height);
|
||||
cairo_set_antialias(cs, CAIRO_ANTIALIAS_NONE);
|
||||
cairo_fill(cs);
|
||||
|
||||
/* Restore context stack */
|
||||
cairo_restore(cr);
|
||||
cairo_restore(cs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void redraw_windows(yutani_globals_t * yg) {
|
||||
/* Save the cairo contexts so we can apply clipping */
|
||||
save_cairo_states(yg);
|
||||
int has_updates = 0;
|
||||
|
||||
/* If the mouse has moved, that counts as damage regions */
|
||||
if ((yg->last_mouse_x != yg->mouse_x) || (yg->last_mouse_y != yg->mouse_y)) {
|
||||
has_updates = 1;
|
||||
yutani_add_clip(yg, yg->last_mouse_x / MOUSE_SCALE - MOUSE_OFFSET_X, yg->last_mouse_y / MOUSE_SCALE - MOUSE_OFFSET_Y, 64, 64);
|
||||
yutani_add_clip(yg, yg->mouse_x / MOUSE_SCALE - MOUSE_OFFSET_X, yg->mouse_y / MOUSE_SCALE - MOUSE_OFFSET_Y, 64, 64);
|
||||
}
|
||||
|
||||
/* Calculate damage regions from currently queued updates */
|
||||
while (yg->update_list->length) {
|
||||
node_t * win = list_dequeue(yg->update_list);
|
||||
yutani_server_window_t * window = (yutani_server_window_t *)win->value;
|
||||
|
||||
/* We add a clip region for each window in the update queue */
|
||||
has_updates = 1;
|
||||
yutani_add_clip(yg, window->x, window->y, window->width, window->height);
|
||||
free(win);
|
||||
}
|
||||
|
||||
/* Render */
|
||||
if (has_updates) {
|
||||
|
||||
yutani_set_clip(yg);
|
||||
|
||||
/* Uh, just really quick, let's clear the display to a color... */
|
||||
cairo_set_source_rgb(yg->framebuffer_ctx, 0.6, 0.6, 0.6);
|
||||
cairo_rectangle(yg->framebuffer_ctx, 0, 0, yg->width, yg->height);
|
||||
cairo_fill(yg->framebuffer_ctx);
|
||||
|
||||
/*
|
||||
* In theory, we should restrict this to windows within the clip region,
|
||||
* but calculating that may be more trouble than it's worth;
|
||||
* we also need to render windows in stacking order...
|
||||
*/
|
||||
foreach(node, yg->windows) {
|
||||
yutani_server_window_t * win = (void*)node->value;
|
||||
yutani_blit_window(yg, win, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Draw the cursor.
|
||||
* We may also want to draw other compositor elements, like effects, but those
|
||||
* can also go in the stack order of the windows.
|
||||
*/
|
||||
draw_cursor(yg);
|
||||
|
||||
/* Push our changes to the display */
|
||||
flip(yg->backend_ctx);
|
||||
}
|
||||
|
||||
/* Restore the cairo contexts to reset clip regions */
|
||||
restore_cairo_states(yg);
|
||||
}
|
||||
|
||||
void yutani_cairo_init(yutani_globals_t * yg) {
|
||||
|
||||
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, yg->width);
|
||||
yg->framebuffer_surface = cairo_image_surface_create_for_data(
|
||||
yg->backend_framebuffer, CAIRO_FORMAT_ARGB32, yg->width, yg->height, stride);
|
||||
|
||||
yg->select_framebuffer = malloc(YUTANI_BYTE_DEPTH * yg->width * yg->height);
|
||||
|
||||
yg->selectbuffer_surface = cairo_image_surface_create_for_data(
|
||||
yg->select_framebuffer, CAIRO_FORMAT_ARGB32, yg->width, yg->height, stride);
|
||||
|
||||
yg->framebuffer_ctx = cairo_create(yg->framebuffer_surface);
|
||||
yg->selectbuffer_ctx = cairo_create(yg->selectbuffer_surface);
|
||||
|
||||
yg->update_list = list_create();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,10 +340,15 @@ static void redraw_windows(gfx_context_t * framebuffer) {
|
||||
*/
|
||||
int main(int argc, char * argv[]) {
|
||||
|
||||
gfx_context_t * framebuffer = init_graphics_fullscreen_double_buffer();
|
||||
yutani_globals_t * yg = malloc(sizeof(yutani_globals_t));
|
||||
yg->backend_ctx = init_graphics_fullscreen_double_buffer();
|
||||
yg->width = yg->backend_ctx->width;
|
||||
yg->height = yg->backend_ctx->height;
|
||||
|
||||
draw_fill(framebuffer, rgb(150,150,240));
|
||||
flip(framebuffer);
|
||||
draw_fill(yg->backend_ctx, rgb(150,150,240));
|
||||
flip(yg->backend_ctx);
|
||||
|
||||
yg->backend_framebuffer = yg->backend_ctx->backbuffer;
|
||||
|
||||
FILE * server = pex_bind("compositor");
|
||||
|
||||
@ -194,13 +356,23 @@ int main(int argc, char * argv[]) {
|
||||
load_fonts();
|
||||
fprintf(stderr, "[yutani] Done.\n");
|
||||
|
||||
load_sprite_png(&yg->mouse_sprite, "/usr/share/arrow.png");
|
||||
yg->last_mouse_x = 0;
|
||||
yg->last_mouse_y = 0;
|
||||
yg->mouse_x = yg->width * MOUSE_SCALE / 2;
|
||||
yg->mouse_y = yg->height * MOUSE_SCALE / 2;
|
||||
|
||||
yg->windows = list_create();
|
||||
yg->wids_to_windows = hashmap_create_int(10);
|
||||
|
||||
yutani_cairo_init(yg);
|
||||
|
||||
pthread_t mouse_thread;
|
||||
pthread_create(&mouse_thread, NULL, mouse_input, NULL);
|
||||
|
||||
pthread_t keyboard_thread;
|
||||
pthread_create(&keyboard_thread, NULL, keyboard_input, NULL);
|
||||
|
||||
#if 1
|
||||
if (!fork()) {
|
||||
fprintf(stderr, "Starting Login...\n");
|
||||
if (argc < 2) {
|
||||
@ -210,7 +382,6 @@ int main(int argc, char * argv[]) {
|
||||
execvp(argv[1], &argv[1]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
pex_packet_t * p = calloc(PACKET_SIZE, 1);
|
||||
@ -226,34 +397,82 @@ int main(int argc, char * argv[]) {
|
||||
switch(m->type) {
|
||||
case YUTANI_MSG_HELLO: {
|
||||
fprintf(stderr, "[yutani-server] And hello to you, %08x!\n", p->source);
|
||||
yutani_msg_t * response = yutani_msg_build_welcome(framebuffer->width, framebuffer->height);
|
||||
yutani_msg_t * response = yutani_msg_build_welcome(yg->width, yg->height);
|
||||
pex_send(server, p->source, response->size, (char *)response);
|
||||
free(response);
|
||||
} break;
|
||||
case YUTANI_MSG_WINDOW_NEW: {
|
||||
struct yutani_msg_window_new * wn = (void *)m->data;
|
||||
fprintf(stderr, "[yutani-server] Client %08x requested a new window (%xx%x).\n", p->source, wn->width, wn->height);
|
||||
server_window_t * w = server_window_create(wn->width, wn->height, p->source);
|
||||
yutani_msg_t * response = yutani_msg_build_window_init(w->width, w->height, w->bufid);
|
||||
yutani_server_window_t * w = server_window_create(yg, wn->width, wn->height, p->source);
|
||||
yutani_msg_t * response = yutani_msg_build_window_init(w->wid, w->width, w->height, w->bufid);
|
||||
pex_send(server, p->source, response->size, (char *)response);
|
||||
free(response);
|
||||
} break;
|
||||
case YUTANI_MSG_FLIP: {
|
||||
/* XXX take rect parameters / use a window / something */
|
||||
fprintf(stderr, "[yutani-server] Redraw requested.\n");
|
||||
redraw_windows(framebuffer);
|
||||
struct yutani_msg_flip * wf = (void *)m->data;
|
||||
yutani_server_window_t * w = hashmap_get(yg->wids_to_windows, (void *)wf->wid);
|
||||
if (w) {
|
||||
list_insert(yg->update_list, w);
|
||||
redraw_windows(yg);
|
||||
}
|
||||
} break;
|
||||
case YUTANI_MSG_KEY_EVENT: {
|
||||
/* XXX Verify this is from a valid client */
|
||||
if (windows) {
|
||||
pex_send(server, ((server_window_t *)(windows->head->value))->owner, m->size, (char *)m);
|
||||
/* XXX Verify this is from a valid device client */
|
||||
struct yutani_msg_key_event * ke = (void *)m->data;
|
||||
if (yg->windows->tail) {
|
||||
/* XXX focused window */
|
||||
ke->wid = ((yutani_server_window_t *)(yg->windows->tail->value))->wid;
|
||||
pex_send(server, ((yutani_server_window_t *)(yg->windows->tail->value))->owner, m->size, (char *)m);
|
||||
/* XXX key loggers ;) */
|
||||
}
|
||||
} break;
|
||||
case YUTANI_MSG_MOUSE_EVENT: {
|
||||
/* XXX Verify this is from a valid device client */
|
||||
struct yutani_msg_mouse_event * me = (void *)m->data;
|
||||
|
||||
yg->last_mouse_x = yg->mouse_x;
|
||||
yg->last_mouse_y = yg->mouse_y;
|
||||
|
||||
yg->mouse_x += me->event.x_difference;
|
||||
yg->mouse_y -= me->event.y_difference;
|
||||
|
||||
if (yg->mouse_x < 0) yg->mouse_x = 0;
|
||||
if (yg->mouse_y < 0) yg->mouse_y = 0;
|
||||
if (yg->mouse_x > (yg->width - 1) * MOUSE_SCALE) yg->mouse_x = (yg->width - 1) * MOUSE_SCALE;
|
||||
if (yg->mouse_y > (yg->height - 1) * MOUSE_SCALE) yg->mouse_y = (yg->height - 1) * MOUSE_SCALE;
|
||||
|
||||
redraw_windows(yg);
|
||||
|
||||
} break;
|
||||
case YUTANI_MSG_WINDOW_MOVE: {
|
||||
struct yutani_msg_window_move * wm = (void *)m->data;
|
||||
fprintf(stderr, "[yutani-server] %08x wanted to move window %d\n", p->source, wm->wid);
|
||||
yutani_server_window_t * win = hashmap_get(yg->wids_to_windows, (void*)wm->wid);
|
||||
win->x = wm->x;
|
||||
win->y = wm->y;
|
||||
if (win) {
|
||||
redraw_windows(yg);
|
||||
} else {
|
||||
fprintf(stderr, "[yutani-server] %08x wanted to move window %d, but I can't find it?\n", p->source, wm->wid);
|
||||
}
|
||||
} break;
|
||||
case YUTANI_MSG_WINDOW_CLOSE: {
|
||||
struct yutani_msg_window_close * wc = (void *)m->data;
|
||||
yutani_server_window_t * w = hashmap_get(yg->wids_to_windows, (void *)wc->wid);
|
||||
if (w) {
|
||||
/* XXX free window */
|
||||
hashmap_remove(yg->wids_to_windows, (void *)wc->wid);
|
||||
list_remove(yg->windows, list_index_of(yg->windows, w));
|
||||
list_insert(yg->update_list, w);
|
||||
redraw_windows(yg);
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
fprintf(stderr, "[yutani-server] Unknown type!\n");
|
||||
} break;
|
||||
}
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
72
userspace/gui/compositor/yutani_int.h
Normal file
72
userspace/gui/compositor/yutani_int.h
Normal file
@ -0,0 +1,72 @@
|
||||
#ifndef _YUTANI_INTERNAL_H
|
||||
#define _YUTANI_INTERNAL_H
|
||||
|
||||
#include <cairo.h>
|
||||
#include "lib/yutani.h"
|
||||
#include "lib/list.h"
|
||||
#include "lib/hashmap.h"
|
||||
#include "lib/graphics.h"
|
||||
|
||||
#define MOUSE_SCALE 2
|
||||
#define MOUSE_OFFSET_X 26
|
||||
#define MOUSE_OFFSET_Y 26
|
||||
|
||||
#define YUTANI_ZORDER_TOP 0xFFFF
|
||||
#define YUTANI_ZORDER_BOTTOM 0x0000
|
||||
|
||||
#define YUTANI_BYTE_DEPTH 4
|
||||
|
||||
typedef enum {
|
||||
YUTANI_EFFECT_NONE,
|
||||
YUTANI_EFFECT_FADE_IN,
|
||||
YUTANI_EFFECT_FADE_OUT,
|
||||
YUTANI_EFFECT_MINIMIZE,
|
||||
YUTANI_EFFECT_UNMINIMIZE,
|
||||
} yutani_effect;
|
||||
|
||||
typedef struct {
|
||||
yutani_wid_t wid;
|
||||
|
||||
signed long x;
|
||||
signed long y;
|
||||
unsigned short z;
|
||||
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
||||
uint8_t * buffer;
|
||||
uint32_t bufid;
|
||||
|
||||
uint32_t owner;
|
||||
} yutani_server_window_t;
|
||||
|
||||
typedef struct {
|
||||
/* XXX multiple displays */
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
|
||||
cairo_surface_t * framebuffer_surface;
|
||||
cairo_surface_t * selectbuffer_surface;
|
||||
cairo_t * framebuffer_ctx;
|
||||
cairo_t * selectbuffer_ctx;
|
||||
|
||||
void * select_framebuffer;
|
||||
void * backend_framebuffer;
|
||||
gfx_context_t * backend_ctx;
|
||||
|
||||
signed int mouse_x;
|
||||
signed int mouse_y;
|
||||
|
||||
signed int last_mouse_x;
|
||||
signed int last_mouse_y;
|
||||
|
||||
list_t * windows;
|
||||
hashmap_t * wids_to_windows;
|
||||
|
||||
list_t * update_list;
|
||||
|
||||
sprite_t mouse_sprite;
|
||||
} yutani_globals_t;
|
||||
|
||||
|
||||
#endif /* _YUTANI_INTERNAL_H */
|
@ -216,7 +216,7 @@ int main (int argc, char ** argv) {
|
||||
draw_sprite(ctx, sprites[2], center_x(width), center_y(height));
|
||||
draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - i);
|
||||
flip(ctx);
|
||||
yutani_flip(y);
|
||||
yutani_flip(y, wina);
|
||||
}
|
||||
|
||||
size_t buf_size = wina->width * wina->height * sizeof(uint32_t);
|
||||
@ -335,7 +335,7 @@ int main (int argc, char ** argv) {
|
||||
}
|
||||
|
||||
flip(ctx);
|
||||
yutani_flip(y);
|
||||
yutani_flip(y, wina);
|
||||
|
||||
w_keyboard_t * kbd = NULL;
|
||||
do {
|
||||
@ -393,7 +393,7 @@ int main (int argc, char ** argv) {
|
||||
draw_sprite(ctx, sprites[2], center_x(width), center_y(height));
|
||||
draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - LOGO_FINAL_OFFSET);
|
||||
flip(ctx);
|
||||
yutani_flip(y);
|
||||
yutani_flip(y, wina);
|
||||
|
||||
//teardown_windowing();
|
||||
|
||||
|
@ -689,7 +689,7 @@ void flip_cursor() {
|
||||
} else {
|
||||
render_cursor();
|
||||
}
|
||||
yutani_flip(yctx);
|
||||
yutani_flip(yctx, window);
|
||||
cursor_flipped = 1 - cursor_flipped;
|
||||
}
|
||||
|
||||
@ -756,12 +756,12 @@ uint32_t child_pid = 0;
|
||||
|
||||
void handle_input(char c) {
|
||||
write(fd_master, &c, 1);
|
||||
yutani_flip(yctx);
|
||||
yutani_flip(yctx, window);
|
||||
}
|
||||
|
||||
void handle_input_s(char * c) {
|
||||
write(fd_master, c, strlen(c));
|
||||
yutani_flip(yctx);
|
||||
yutani_flip(yctx, window);
|
||||
}
|
||||
|
||||
void key_event(int ret, key_event_t * event) {
|
||||
@ -1081,7 +1081,9 @@ int main(int argc, char ** argv) {
|
||||
ctx = init_graphics_yutani(window);
|
||||
|
||||
/* Clear to black */
|
||||
draw_fill(ctx, rgb(0,0,0));
|
||||
draw_fill(ctx, rgba(0,0,0,0));
|
||||
|
||||
yutani_window_move(yctx, window, yctx->display_width / 2 - window->width / 2, yctx->display_height / 2 - window->height / 2);
|
||||
|
||||
if (_use_freetype) {
|
||||
int error;
|
||||
@ -1166,10 +1168,12 @@ int main(int argc, char ** argv) {
|
||||
for (uint32_t i = 0; i < r; ++i) {
|
||||
ansi_put(ansi_state, buf[i]);
|
||||
}
|
||||
yutani_flip(yctx);
|
||||
yutani_flip(yctx, window);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
yutani_close(yctx, window);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
1
userspace/lib/mouse.h
Symbolic link
1
userspace/lib/mouse.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../kernel/include/mouse.h
|
@ -6,6 +6,7 @@
|
||||
#include "pex.h"
|
||||
#include "graphics.h"
|
||||
#include "kbd.h"
|
||||
#include "mouse.h"
|
||||
|
||||
yutani_msg_t * yutani_wait_for(yutani_t * y, uint32_t type) {
|
||||
do {
|
||||
@ -42,7 +43,7 @@ yutani_msg_t * yutani_poll(yutani_t * y) {
|
||||
|
||||
yutani_msg_t * yutani_msg_build_hello(void) {
|
||||
size_t s = sizeof(struct yutani_message);
|
||||
yutani_msg_t * msg = malloc(s); /* No extra data for a hello. */
|
||||
yutani_msg_t * msg = malloc(s);
|
||||
|
||||
msg->magic = YUTANI_MSG__MAGIC;
|
||||
msg->type = YUTANI_MSG_HELLO;
|
||||
@ -51,20 +52,24 @@ yutani_msg_t * yutani_msg_build_hello(void) {
|
||||
return msg;
|
||||
}
|
||||
|
||||
yutani_msg_t * yutani_msg_build_flip(void) {
|
||||
size_t s = sizeof(struct yutani_message);
|
||||
yutani_msg_t * msg = malloc(s); /* No extra data for a hello. */
|
||||
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);
|
||||
|
||||
msg->magic = YUTANI_MSG__MAGIC;
|
||||
msg->type = YUTANI_MSG_FLIP;
|
||||
msg->size = s;
|
||||
|
||||
struct yutani_msg_flip * mw = (void *)msg->data;
|
||||
|
||||
mw->wid = wid;
|
||||
|
||||
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);
|
||||
yutani_msg_t * msg = malloc(s); /* No extra data for a hello. */
|
||||
yutani_msg_t * msg = malloc(s);
|
||||
|
||||
msg->magic = YUTANI_MSG__MAGIC;
|
||||
msg->type = YUTANI_MSG_WELCOME;
|
||||
@ -80,7 +85,7 @@ yutani_msg_t * yutani_msg_build_welcome(uint32_t width, uint32_t height) {
|
||||
|
||||
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);
|
||||
yutani_msg_t * msg = malloc(s); /* No extra data for a hello. */
|
||||
yutani_msg_t * msg = malloc(s);
|
||||
|
||||
msg->magic = YUTANI_MSG__MAGIC;
|
||||
msg->type = YUTANI_MSG_WINDOW_NEW;
|
||||
@ -94,9 +99,9 @@ yutani_msg_t * yutani_msg_build_window_new(uint32_t width, uint32_t height) {
|
||||
return msg;
|
||||
}
|
||||
|
||||
yutani_msg_t * yutani_msg_build_window_init(uint32_t width, uint32_t height, uint32_t bufid) {
|
||||
yutani_msg_t * yutani_msg_build_window_init(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_init);
|
||||
yutani_msg_t * msg = malloc(s); /* No extra data for a hello. */
|
||||
yutani_msg_t * msg = malloc(s);
|
||||
|
||||
msg->magic = YUTANI_MSG__MAGIC;
|
||||
msg->type = YUTANI_MSG_WINDOW_INIT;
|
||||
@ -104,6 +109,7 @@ yutani_msg_t * yutani_msg_build_window_init(uint32_t width, uint32_t height, uin
|
||||
|
||||
struct yutani_msg_window_init * mw = (void *)msg->data;
|
||||
|
||||
mw->wid = wid;
|
||||
mw->width = width;
|
||||
mw->height = height;
|
||||
mw->bufid = bufid;
|
||||
@ -111,9 +117,24 @@ yutani_msg_t * yutani_msg_build_window_init(uint32_t width, uint32_t height, uin
|
||||
return msg;
|
||||
}
|
||||
|
||||
yutani_msg_t * yutani_msg_build_key_event(key_event_t * event) {
|
||||
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;
|
||||
}
|
||||
|
||||
yutani_msg_t * yutani_msg_build_key_event(yutani_wid_t wid, key_event_t * event) {
|
||||
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_key_event);
|
||||
yutani_msg_t * msg = malloc(s); /* No extra data for a hello. */
|
||||
yutani_msg_t * msg = malloc(s);
|
||||
|
||||
msg->magic = YUTANI_MSG__MAGIC;
|
||||
msg->type = YUTANI_MSG_KEY_EVENT;
|
||||
@ -121,11 +142,45 @@ yutani_msg_t * yutani_msg_build_key_event(key_event_t * event) {
|
||||
|
||||
struct yutani_msg_key_event * mw = (void *)msg->data;
|
||||
|
||||
mw->wid = wid;
|
||||
memcpy(&mw->event, event, sizeof(key_event_t));
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int yutani_msg_send(yutani_t * y, yutani_msg_t * msg) {
|
||||
return pex_reply(y->sock, msg->size, (char *)msg);
|
||||
}
|
||||
@ -178,6 +233,7 @@ yutani_window_t * yutani_window_create(yutani_t * y, int width, int height) {
|
||||
win->width = mw->width;
|
||||
win->height = mw->height;
|
||||
win->bufid = mw->bufid;
|
||||
win->wid = mw->wid;
|
||||
|
||||
char key[1024];
|
||||
YUTANI_SHMKEY(key, 1024, win);
|
||||
@ -187,12 +243,25 @@ yutani_window_t * yutani_window_create(yutani_t * y, int width, int height) {
|
||||
return win;
|
||||
}
|
||||
|
||||
void yutani_flip(yutani_t * y) {
|
||||
yutani_msg_t * m = yutani_msg_build_flip();
|
||||
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);
|
||||
}
|
||||
|
||||
void yutani_close(yutani_t * y, yutani_window_t * win) {
|
||||
yutani_msg_t * m = yutani_msg_build_window_close(win->wid);
|
||||
int result = yutani_msg_send(y, m);
|
||||
free(m);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
free(m);
|
||||
}
|
||||
|
||||
gfx_context_t * init_graphics_yutani(yutani_window_t * window) {
|
||||
gfx_context_t * out = malloc(sizeof(gfx_context_t));
|
||||
out->width = window->width;
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "graphics.h"
|
||||
#include "kbd.h"
|
||||
#include "mouse.h"
|
||||
|
||||
#define YUTANI_SERVER_IDENTIFIER "sys.compositor"
|
||||
#define YUTANI_SHMKEY(buf,sz,win) snprintf(buf, sz, "%s.%d", YUTANI_SERVER_IDENTIFIER, win->bufid);
|
||||
@ -33,21 +34,42 @@ struct yutani_msg_welcome {
|
||||
uint32_t display_height;
|
||||
};
|
||||
|
||||
struct yutani_msg_flip {
|
||||
yutani_wid_t wid;
|
||||
};
|
||||
|
||||
struct yutani_msg_window_close {
|
||||
yutani_wid_t wid;
|
||||
};
|
||||
|
||||
struct yutani_msg_window_new {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
};
|
||||
|
||||
struct yutani_msg_window_init {
|
||||
yutani_wid_t wid;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t bufid;
|
||||
};
|
||||
|
||||
struct yutani_msg_window_move {
|
||||
yutani_wid_t wid;
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
};
|
||||
|
||||
struct yutani_msg_key_event {
|
||||
yutani_wid_t wid;
|
||||
key_event_t event;
|
||||
};
|
||||
|
||||
struct yutani_msg_mouse_event {
|
||||
yutani_wid_t wid;
|
||||
mouse_device_packet_t event;
|
||||
};
|
||||
|
||||
typedef struct yutani_window {
|
||||
yutani_wid_t wid;
|
||||
|
||||
@ -69,6 +91,11 @@ typedef struct yutani_window {
|
||||
#define YUTANI_MSG_FLIP 0x00000003
|
||||
#define YUTANI_MSG_KEY_EVENT 0x00000004
|
||||
#define YUTANI_MSG_MOUSE_EVENT 0x00000005
|
||||
#define YUTANI_MSG_WINDOW_MOVE 0x00000006
|
||||
#define YUTANI_MSG_WINDOW_CLOSE 0x00000007
|
||||
#define YUTANI_MSG_WINDOW_SHOW 0x00000008
|
||||
#define YUTANI_MSG_WINDOW_HIDE 0x00000009
|
||||
#define YUTANI_MSG_GOODBYE 0x000000F0
|
||||
|
||||
/* Server responses */
|
||||
#define YUTANI_MSG_WELCOME 0x00010001
|
||||
@ -80,15 +107,19 @@ yutani_msg_t * yutani_poll(yutani_t * y);
|
||||
yutani_msg_t * yutani_msg_build_hello(void);
|
||||
yutani_msg_t * yutani_msg_build_welcome(uint32_t width, uint32_t height);
|
||||
yutani_msg_t * yutani_msg_build_window_new(uint32_t width, uint32_t height);
|
||||
yutani_msg_t * yutani_msg_build_window_init(uint32_t width, uint32_t height, uint32_t bufid);
|
||||
yutani_msg_t * yutani_msg_build_flip(void);
|
||||
yutani_msg_t * yutani_msg_build_key_event(key_event_t * event);
|
||||
yutani_msg_t * yutani_msg_build_window_init(yutani_wid_t wid, uint32_t width, uint32_t height, uint32_t bufid);
|
||||
yutani_msg_t * yutani_msg_build_flip(yutani_wid_t);
|
||||
yutani_msg_t * yutani_msg_build_key_event(yutani_wid_t wid, key_event_t * event);
|
||||
yutani_msg_t * yutani_msg_build_mouse_event(yutani_wid_t wid, mouse_device_packet_t * event);
|
||||
yutani_msg_t * yutani_msg_build_window_close(yutani_wid_t wid);
|
||||
|
||||
int yutani_msg_send(yutani_t * y, yutani_msg_t * msg);
|
||||
yutani_t * yutani_context_create(FILE * socket);
|
||||
yutani_t * yutani_init(void);
|
||||
yutani_window_t * yutani_window_create(yutani_t * y, int width, int height);
|
||||
void yutani_flip(yutani_t * y);
|
||||
void yutani_flip(yutani_t * y, yutani_window_t * win);
|
||||
void yutani_window_move(yutani_t * yctx, yutani_window_t * window, int x, int y);
|
||||
void yutani_close(yutani_t * y, yutani_window_t * win);
|
||||
|
||||
gfx_context_t * init_graphics_yutani(yutani_window_t * window);
|
||||
gfx_context_t * init_graphics_yutani_double_buffer(yutani_window_t * window);
|
||||
|
Loading…
Reference in New Issue
Block a user