HelenOS sources
This source file includes following definitions.
- ds_client_create
- ds_client_destroy
- ds_client_add_window
- ds_client_remove_window
- ds_client_find_window
- ds_client_first_window
- ds_client_next_window
- ds_client_get_event
- ds_client_purge_window_events
- ds_client_post_close_event
- ds_client_post_focus_event
- ds_client_post_kbd_event
- ds_client_post_pos_event
- ds_client_post_resize_event
- ds_client_post_unfocus_event
#include <adt/list.h>
#include <errno.h>
#include <stdlib.h>
#include "client.h"
#include "display.h"
#include "seat.h"
#include "window.h"
errno_t ds_client_create(ds_display_t *display, ds_client_cb_t *cb,
void *cb_arg, ds_client_t **rclient)
{
ds_client_t *client;
client = calloc(1, sizeof(ds_client_t));
if (client == NULL)
return ENOMEM;
list_initialize(&client->windows);
list_initialize(&client->events);
client->cb = cb;
client->cb_arg = cb_arg;
ds_display_add_client(display, client);
*rclient = client;
return EOK;
}
void ds_client_destroy(ds_client_t *client)
{
ds_window_t *window;
window = ds_client_first_window(client);
while (window != NULL) {
ds_window_destroy(window);
window = ds_client_first_window(client);
}
assert(list_empty(&client->windows));
ds_display_remove_client(client);
free(client);
}
void ds_client_add_window(ds_client_t *client, ds_window_t *wnd)
{
assert(wnd->client == NULL);
assert(!link_used(&wnd->lcwindows));
wnd->client = client;
wnd->id = client->display->next_wnd_id++;
list_append(&wnd->lcwindows, &client->windows);
}
void ds_client_remove_window(ds_window_t *wnd)
{
ds_seat_t *seat;
seat = ds_display_first_seat(wnd->display);
while (seat != NULL) {
ds_seat_evac_wnd_refs(seat, wnd);
seat = ds_display_next_seat(seat);
}
ds_client_purge_window_events(wnd->client, wnd);
list_remove(&wnd->lcwindows);
wnd->client = NULL;
}
ds_window_t *ds_client_find_window(ds_client_t *client, ds_wnd_id_t id)
{
ds_window_t *wnd;
wnd = ds_client_first_window(client);
while (wnd != NULL) {
if (wnd->id == id)
return wnd;
wnd = ds_client_next_window(wnd);
}
return NULL;
}
ds_window_t *ds_client_first_window(ds_client_t *client)
{
link_t *link = list_first(&client->windows);
if (link == NULL)
return NULL;
return list_get_instance(link, ds_window_t, lcwindows);
}
ds_window_t *ds_client_next_window(ds_window_t *wnd)
{
link_t *link = list_next(&wnd->lcwindows, &wnd->client->windows);
if (link == NULL)
return NULL;
return list_get_instance(link, ds_window_t, lcwindows);
}
errno_t ds_client_get_event(ds_client_t *client, ds_window_t **ewindow,
display_wnd_ev_t *event)
{
link_t *link;
ds_window_ev_t *wevent;
link = list_first(&client->events);
if (link == NULL)
return ENOENT;
wevent = list_get_instance(link, ds_window_ev_t, levents);
list_remove(link);
*ewindow = wevent->window;
*event = wevent->event;
free(wevent);
return EOK;
}
void ds_client_purge_window_events(ds_client_t *client,
ds_window_t *window)
{
link_t *cur;
link_t *next;
ds_window_ev_t *wevent;
cur = list_first(&client->events);
while (cur != NULL) {
next = list_next(cur, &client->events);
wevent = list_get_instance(cur, ds_window_ev_t, levents);
if (wevent->window == window)
list_remove(cur);
cur = next;
}
}
errno_t ds_client_post_close_event(ds_client_t *client, ds_window_t *ewindow)
{
ds_window_ev_t *wevent;
wevent = calloc(1, sizeof(ds_window_ev_t));
if (wevent == NULL)
return ENOMEM;
wevent->window = ewindow;
wevent->event.etype = wev_close;
list_append(&wevent->levents, &client->events);
if (client->cb != NULL && client->cb->ev_pending != NULL)
client->cb->ev_pending(client->cb_arg);
return EOK;
}
errno_t ds_client_post_focus_event(ds_client_t *client, ds_window_t *ewindow,
display_wnd_focus_ev_t *event)
{
ds_window_ev_t *wevent;
wevent = calloc(1, sizeof(ds_window_ev_t));
if (wevent == NULL)
return ENOMEM;
wevent->window = ewindow;
wevent->event.etype = wev_focus;
wevent->event.ev.focus = *event;
list_append(&wevent->levents, &client->events);
if (client->cb != NULL && client->cb->ev_pending != NULL)
client->cb->ev_pending(client->cb_arg);
return EOK;
}
errno_t ds_client_post_kbd_event(ds_client_t *client, ds_window_t *ewindow,
kbd_event_t *event)
{
ds_window_ev_t *wevent;
wevent = calloc(1, sizeof(ds_window_ev_t));
if (wevent == NULL)
return ENOMEM;
wevent->window = ewindow;
wevent->event.etype = wev_kbd;
wevent->event.ev.kbd = *event;
list_append(&wevent->levents, &client->events);
client->cb->ev_pending(client->cb_arg);
return EOK;
}
errno_t ds_client_post_pos_event(ds_client_t *client, ds_window_t *ewindow,
pos_event_t *event)
{
ds_window_ev_t *wevent;
wevent = calloc(1, sizeof(ds_window_ev_t));
if (wevent == NULL)
return ENOMEM;
wevent->window = ewindow;
wevent->event.etype = wev_pos;
wevent->event.ev.pos = *event;
list_append(&wevent->levents, &client->events);
if (client->cb != NULL && client->cb->ev_pending != NULL)
client->cb->ev_pending(client->cb_arg);
return EOK;
}
errno_t ds_client_post_resize_event(ds_client_t *client, ds_window_t *ewindow,
gfx_rect_t *rect)
{
ds_window_ev_t *wevent;
wevent = calloc(1, sizeof(ds_window_ev_t));
if (wevent == NULL)
return ENOMEM;
wevent->window = ewindow;
wevent->event.etype = wev_resize;
wevent->event.ev.resize.rect = *rect;
list_append(&wevent->levents, &client->events);
if (client->cb != NULL && client->cb->ev_pending != NULL)
client->cb->ev_pending(client->cb_arg);
return EOK;
}
errno_t ds_client_post_unfocus_event(ds_client_t *client, ds_window_t *ewindow,
display_wnd_unfocus_ev_t *event)
{
ds_window_ev_t *wevent;
wevent = calloc(1, sizeof(ds_window_ev_t));
if (wevent == NULL)
return ENOMEM;
wevent->window = ewindow;
wevent->event.etype = wev_unfocus;
wevent->event.ev.unfocus = *event;
list_append(&wevent->levents, &client->events);
if (client->cb != NULL && client->cb->ev_pending != NULL)
client->cb->ev_pending(client->cb_arg);
return EOK;
}
HelenOS homepage, sources at GitHub