source: mainline/uspace/lib/ui/src/ui.c@ f7a90df

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f7a90df was f7a90df, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Prototype UI and window classes

It is difficult to do any useful testing on ui_window without a real
display_t. Without display, there is no window, without window no GC,
without GC no UI resource.

As a compromise, in case of unit test, create UI with display == NULL,
in which case create window with NULL dwindow and a dummy GC
(so we have valid UI resource).

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Copyright (c) 2020 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libui
30 * @{
31 */
32/**
33 * @file User interface
34 */
35
36#include <display.h>
37#include <errno.h>
38#include <stdlib.h>
39#include <ui/ui.h>
40#include "../private/ui.h"
41
42/** Create new user interface.
43 *
44 * @param ospec Output specification or @c UI_DISPLAY_DEFAULT to use
45 * the default output
46 * @param rui Place to store pointer to new UI
47 * @return EOK on success or an error code
48 */
49errno_t ui_create(const char *ospec, ui_t **rui)
50{
51 errno_t rc;
52 display_t *display;
53 ui_t *ui;
54
55 rc = display_open(ospec, &display);
56 if (rc != EOK)
57 return rc;
58
59 rc = ui_create_disp(display, &ui);
60 if (rc != EOK) {
61 display_close(display);
62 return rc;
63 }
64
65 ui->display = display;
66 ui->myoutput = true;
67 return EOK;
68}
69
70/** Create new user interface using display service.
71 *
72 * @param disp Display
73 * @param rui Place to store pointer to new UI
74 * @return EOK on success or an error code
75 */
76errno_t ui_create_disp(display_t *disp, ui_t **rui)
77{
78 ui_t *ui;
79
80 ui = calloc(1, sizeof(ui_t));
81 if (ui == NULL)
82 return ENOMEM;
83
84 ui->display = disp;
85 *rui = ui;
86 return EOK;
87}
88
89/** Destroy user interface.
90 *
91 * @param ui User interface or @c NULL
92 */
93void ui_destroy(ui_t *ui)
94{
95 if (ui == NULL)
96 return;
97
98 if (ui->myoutput)
99 display_close(ui->display);
100 free(ui);
101}
102
103/** @}
104 */
Note: See TracBrowser for help on using the repository browser.