HelenOS sources
This source file includes following definitions.
- wnd_close
- display_cfg_create
- display_cfg_open
- display_cfg_populate
- display_cfg_destroy
#include <gfx/coord.h>
#include <stdio.h>
#include <stdlib.h>
#include <ui/fixed.h>
#include <ui/resource.h>
#include <ui/tabset.h>
#include <ui/ui.h>
#include <ui/window.h>
#include "display-cfg.h"
#include "seats.h"
static void wnd_close(ui_window_t *, void *);
static ui_window_cb_t window_cb = {
.close = wnd_close
};
static void wnd_close(ui_window_t *window, void *arg)
{
display_cfg_t *dcfg = (display_cfg_t *) arg;
ui_quit(dcfg->ui);
}
errno_t display_cfg_create(const char *display_spec, display_cfg_t **rdcfg)
{
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
display_cfg_t *dcfg = NULL;
gfx_rect_t rect;
ui_resource_t *ui_res;
errno_t rc;
dcfg = calloc(1, sizeof(display_cfg_t));
if (dcfg == NULL) {
printf("Out of memory.\n");
return ENOMEM;
}
rc = ui_create(display_spec, &ui);
if (rc != EOK) {
printf("Error creating UI on display %s.\n", display_spec);
goto error;
}
ui_wnd_params_init(¶ms);
params.caption = "Display Configuration";
if (ui_is_textmode(ui)) {
params.rect.p0.x = 0;
params.rect.p0.y = 0;
params.rect.p1.x = 70;
params.rect.p1.y = 23;
} else {
params.rect.p0.x = 0;
params.rect.p0.y = 0;
params.rect.p1.x = 470;
params.rect.p1.y = 350;
}
dcfg->ui = ui;
rc = ui_window_create(ui, ¶ms, &window);
if (rc != EOK) {
printf("Error creating window.\n");
goto error;
}
ui_window_set_cb(window, &window_cb, (void *)dcfg);
dcfg->window = window;
ui_res = ui_window_get_res(window);
rc = ui_fixed_create(&dcfg->fixed);
if (rc != EOK) {
printf("Error creating fixed layout.\n");
return rc;
}
rc = ui_tab_set_create(ui_res, &dcfg->tabset);
if (rc != EOK) {
printf("Error creating tab set.\n");
return rc;
}
ui_window_get_app_rect(window, &rect);
ui_tab_set_set_rect(dcfg->tabset, &rect);
rc = ui_fixed_add(dcfg->fixed, ui_tab_set_ctl(dcfg->tabset));
if (rc != EOK) {
printf("Error adding control to layout.\n");
return rc;
}
rc = dcfg_seats_create(dcfg, &dcfg->seats);
if (rc != EOK)
goto error;
ui_window_add(window, ui_fixed_ctl(dcfg->fixed));
*rdcfg = dcfg;
return EOK;
error:
if (dcfg->seats != NULL)
dcfg_seats_destroy(dcfg->seats);
if (dcfg->tabset != NULL)
ui_tab_set_destroy(dcfg->tabset);
if (dcfg->fixed != NULL)
ui_fixed_destroy(dcfg->fixed);
if (dcfg->ui != NULL)
ui_destroy(ui);
free(dcfg);
return rc;
}
errno_t display_cfg_open(display_cfg_t *dcfg, const char *dcfg_svc)
{
errno_t rc;
rc = dispcfg_open(dcfg_svc, NULL, NULL, &dcfg->dispcfg);
if (rc != EOK) {
printf("Error opening display configuration service.\n");
goto error;
}
return EOK;
error:
return rc;
}
errno_t display_cfg_populate(display_cfg_t *dcfg)
{
errno_t rc;
rc = dcfg_seats_populate(dcfg->seats);
if (rc != EOK)
return rc;
rc = ui_window_paint(dcfg->window);
if (rc != EOK) {
printf("Error painting window.\n");
return rc;
}
return EOK;
}
void display_cfg_destroy(display_cfg_t *dcfg)
{
if (dcfg->dispcfg != NULL)
dispcfg_close(dcfg->dispcfg);
ui_window_destroy(dcfg->window);
ui_destroy(dcfg->ui);
}
HelenOS homepage, sources at GitHub