HelenOS sources
This source file includes following definitions.
- ds_wmclient_create
- ds_wmclient_destroy
- ds_wmclient_get_event
- ds_wmclient_purge_events
- ds_wmclient_post_wnd_added_event
- ds_wmclient_post_wnd_removed_event
- ds_wmclient_post_wnd_changed_event
#include <adt/list.h>
#include <errno.h>
#include <io/log.h>
#include <stdlib.h>
#include "display.h"
#include "window.h"
#include "wmclient.h"
errno_t ds_wmclient_create(ds_display_t *display, ds_wmclient_cb_t *cb,
void *cb_arg, ds_wmclient_t **rwmclient)
{
ds_wmclient_t *wmclient;
wmclient = calloc(1, sizeof(ds_wmclient_t));
if (wmclient == NULL)
return ENOMEM;
list_initialize(&wmclient->events);
wmclient->cb = cb;
wmclient->cb_arg = cb_arg;
ds_display_add_wmclient(display, wmclient);
*rwmclient = wmclient;
return EOK;
}
void ds_wmclient_destroy(ds_wmclient_t *wmclient)
{
ds_wmclient_purge_events(wmclient);
ds_display_remove_wmclient(wmclient);
free(wmclient);
}
errno_t ds_wmclient_get_event(ds_wmclient_t *wmclient, wndmgt_ev_t *event)
{
link_t *link;
ds_wmclient_ev_t *wevent;
link = list_first(&wmclient->events);
if (link == NULL)
return ENOENT;
wevent = list_get_instance(link, ds_wmclient_ev_t, levents);
list_remove(link);
*event = wevent->event;
free(wevent);
return EOK;
}
void ds_wmclient_purge_events(ds_wmclient_t *wmclient)
{
link_t *cur;
link_t *next;
ds_wmclient_ev_t *wevent;
cur = list_first(&wmclient->events);
while (cur != NULL) {
next = list_next(cur, &wmclient->events);
wevent = list_get_instance(cur, ds_wmclient_ev_t, levents);
list_remove(cur);
free(wevent);
cur = next;
}
}
errno_t ds_wmclient_post_wnd_added_event(ds_wmclient_t *wmclient,
sysarg_t wnd_id)
{
ds_wmclient_ev_t *wevent;
log_msg(LOG_DEFAULT, LVL_DEBUG, "wmclient_pos_wnd_added_event "
"wmclient=%p wnd_id=%zu\n", (void *)wmclient, wnd_id);
wevent = calloc(1, sizeof(ds_wmclient_ev_t));
if (wevent == NULL)
return ENOMEM;
wevent->wmclient = wmclient;
wevent->event.etype = wmev_window_added;
wevent->event.wnd_id = wnd_id;
list_append(&wevent->levents, &wmclient->events);
if (wmclient->cb != NULL && wmclient->cb->ev_pending != NULL)
wmclient->cb->ev_pending(wmclient->cb_arg);
return EOK;
}
errno_t ds_wmclient_post_wnd_removed_event(ds_wmclient_t *wmclient,
sysarg_t wnd_id)
{
ds_wmclient_ev_t *wevent;
log_msg(LOG_DEFAULT, LVL_DEBUG, "wmclient_pos_wnd_removed_event "
"wmclient=%p wnd_id=%zu\n", (void *)wmclient, wnd_id);
wevent = calloc(1, sizeof(ds_wmclient_ev_t));
if (wevent == NULL)
return ENOMEM;
wevent->wmclient = wmclient;
wevent->event.etype = wmev_window_removed;
wevent->event.wnd_id = wnd_id;
list_append(&wevent->levents, &wmclient->events);
if (wmclient->cb != NULL && wmclient->cb->ev_pending != NULL)
wmclient->cb->ev_pending(wmclient->cb_arg);
return EOK;
}
errno_t ds_wmclient_post_wnd_changed_event(ds_wmclient_t *wmclient,
sysarg_t wnd_id)
{
ds_wmclient_ev_t *wevent;
log_msg(LOG_DEFAULT, LVL_DEBUG, "wmclient_pos_wnd_changed_event "
"wmclient=%p wnd_id=%zu\n", (void *)wmclient, wnd_id);
wevent = calloc(1, sizeof(ds_wmclient_ev_t));
if (wevent == NULL)
return ENOMEM;
wevent->wmclient = wmclient;
wevent->event.etype = wmev_window_changed;
wevent->event.wnd_id = wnd_id;
list_append(&wevent->levents, &wmclient->events);
if (wmclient->cb != NULL && wmclient->cb->ev_pending != NULL)
wmclient->cb->ev_pending(wmclient->cb_arg);
return EOK;
}
HelenOS homepage, sources at GitHub