Index: uspace/lib/ui/src/dummygc.c
===================================================================
--- uspace/lib/ui/src/dummygc.c	(revision f7a90df6adfcf1a8e402e71eed9795cd4e9eabf6)
+++ uspace/lib/ui/src/dummygc.c	(revision f7a90df6adfcf1a8e402e71eed9795cd4e9eabf6)
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2020 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libui
+ * @{
+ */
+/**
+ * @file Dummy graphic context
+ */
+
+#include <gfx/context.h>
+#include <gfx/coord.h>
+#include <mem.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include "../private/dummygc.h"
+
+static errno_t dummygc_set_color(void *, gfx_color_t *);
+static errno_t dummygc_fill_rect(void *, gfx_rect_t *);
+static errno_t dummygc_bitmap_create(void *, gfx_bitmap_params_t *,
+    gfx_bitmap_alloc_t *, void **);
+static errno_t dummygc_bitmap_destroy(void *);
+static errno_t dummygc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
+static errno_t dummygc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
+
+/** Dummy GC operations */
+gfx_context_ops_t dummygc_ops = {
+	.set_color = dummygc_set_color,
+	.fill_rect = dummygc_fill_rect,
+	.bitmap_create = dummygc_bitmap_create,
+	.bitmap_destroy = dummygc_bitmap_destroy,
+	.bitmap_render = dummygc_bitmap_render,
+	.bitmap_get_alloc = dummygc_bitmap_get_alloc
+};
+
+/** Create dummy GC.
+ *
+ * @param rdgc Place to store pointer to new dummy GC
+ * @return EOK on success, ENOMEM if out of memory
+ */
+errno_t dummygc_create(dummy_gc_t **rdgc)
+{
+	dummy_gc_t *dgc;
+	gfx_context_t *gc;
+	errno_t rc;
+
+	dgc = calloc(1, sizeof(dummy_gc_t));
+	if (dgc == NULL)
+		return ENOMEM;
+
+	rc = gfx_context_new(&dummygc_ops, dgc, &gc);
+	if (rc != EOK) {
+		free(dgc);
+		return rc;
+	}
+
+	dgc->gc = gc;
+	*rdgc = dgc;
+	return EOK;
+}
+
+/** Destroy dummy GC.
+ *
+ * @param dgc Dummy GC
+ */
+void dummygc_destroy(dummy_gc_t *dgc)
+{
+	gfx_context_delete(dgc->gc);
+	free(dgc);
+}
+
+/** Get generic graphic context from dummy GC.
+ *
+ * @param dgc Dummy GC
+ * @return Graphic context
+ */
+gfx_context_t *dummygc_get_ctx(dummy_gc_t *dgc)
+{
+	return dgc->gc;
+}
+
+/** Set color on dummy GC
+ *
+ * @param arg Argument (dummy_gc_t)
+ * @param color Color
+ * @return EOK on success or an error code
+ */
+static errno_t dummygc_set_color(void *arg, gfx_color_t *color)
+{
+	(void) arg;
+	(void) color;
+	return EOK;
+}
+
+/** Fill rectangle on dummy GC
+ *
+ * @param arg Argument (dummy_gc_t)
+ * @param rect Rectangle
+ * @return EOK on success or an error code
+ */
+static errno_t dummygc_fill_rect(void *arg, gfx_rect_t *rect)
+{
+	(void) arg;
+	(void) rect;
+	return EOK;
+}
+
+/** Create bitmap on dummy GC
+ *
+ * @param arg Argument (dummy_gc_t)
+ * @param params Bitmap parameters
+ * @param alloc Bitmap allocation info or @c NULL
+ * @param rbm Place to store pointer to new bitmap
+ * @return EOK on success or an error code
+ */
+static errno_t dummygc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
+    gfx_bitmap_alloc_t *alloc, void **rbm)
+{
+	dummy_gc_t *dgc = (dummy_gc_t *) arg;
+	dummygc_bitmap_t *tbm;
+
+	tbm = calloc(1, sizeof(dummygc_bitmap_t));
+	if (tbm == NULL)
+		return ENOMEM;
+
+	if (alloc == NULL) {
+		tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
+		    sizeof(uint32_t);
+		tbm->alloc.off0 = 0;
+		tbm->alloc.pixels = calloc(sizeof(uint32_t),
+		    (params->rect.p1.x - params->rect.p0.x) *
+		    (params->rect.p1.y - params->rect.p0.y));
+		tbm->myalloc = true;
+		if (tbm->alloc.pixels == NULL) {
+			free(tbm);
+			return ENOMEM;
+		}
+	} else {
+		tbm->alloc = *alloc;
+	}
+
+	tbm->dgc = dgc;
+	dgc->bm_created = true;
+	dgc->bm_params = *params;
+	dgc->bm_pixels = tbm->alloc.pixels;
+	*rbm = (void *)tbm;
+	return EOK;
+}
+
+/** Destroy bitmap on dummy GC
+ *
+ * @param bm Bitmap
+ * @return EOK on success or an error code
+ */
+static errno_t dummygc_bitmap_destroy(void *bm)
+{
+	dummygc_bitmap_t *tbm = (dummygc_bitmap_t *)bm;
+	if (tbm->myalloc)
+		free(tbm->alloc.pixels);
+	tbm->dgc->bm_destroyed = true;
+	free(tbm);
+	return EOK;
+}
+
+/** Render bitmap on dummy GC
+ *
+ * @param bm Bitmap
+ * @param srect Source rectangle or @c NULL
+ * @param offs Offset or @c NULL
+ * @return EOK on success or an error code
+ */
+static errno_t dummygc_bitmap_render(void *bm, gfx_rect_t *srect,
+    gfx_coord2_t *offs)
+{
+	dummygc_bitmap_t *tbm = (dummygc_bitmap_t *)bm;
+	tbm->dgc->bm_rendered = true;
+	tbm->dgc->bm_srect = *srect;
+	tbm->dgc->bm_offs = *offs;
+	return EOK;
+}
+
+/** Get bitmap allocation info on dummy GC
+ *
+ * @param bm Bitmap
+ * @param alloc Place to store allocation info
+ * @return EOK on success or an error code
+ */
+static errno_t dummygc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
+{
+	dummygc_bitmap_t *tbm = (dummygc_bitmap_t *)bm;
+	*alloc = tbm->alloc;
+	tbm->dgc->bm_got_alloc = true;
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/ui/src/ui.c
===================================================================
--- uspace/lib/ui/src/ui.c	(revision f7a90df6adfcf1a8e402e71eed9795cd4e9eabf6)
+++ uspace/lib/ui/src/ui.c	(revision f7a90df6adfcf1a8e402e71eed9795cd4e9eabf6)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2020 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libui
+ * @{
+ */
+/**
+ * @file User interface
+ */
+
+#include <display.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <ui/ui.h>
+#include "../private/ui.h"
+
+/** Create new user interface.
+ *
+ * @param ospec Output specification or @c UI_DISPLAY_DEFAULT to use
+ *              the default output
+ * @param rui Place to store pointer to new UI
+ * @return EOK on success or an error code
+ */
+errno_t ui_create(const char *ospec, ui_t **rui)
+{
+	errno_t rc;
+	display_t *display;
+	ui_t *ui;
+
+	rc = display_open(ospec, &display);
+	if (rc != EOK)
+		return rc;
+
+	rc = ui_create_disp(display, &ui);
+	if (rc != EOK) {
+		display_close(display);
+		return rc;
+	}
+
+	ui->display = display;
+	ui->myoutput = true;
+	return EOK;
+}
+
+/** Create new user interface using display service.
+ *
+ * @param disp Display
+ * @param rui Place to store pointer to new UI
+ * @return EOK on success or an error code
+ */
+errno_t ui_create_disp(display_t *disp, ui_t **rui)
+{
+	ui_t *ui;
+
+	ui = calloc(1, sizeof(ui_t));
+	if (ui == NULL)
+		return ENOMEM;
+
+	ui->display = disp;
+	*rui = ui;
+	return EOK;
+}
+
+/** Destroy user interface.
+ *
+ * @param ui User interface or @c NULL
+ */
+void ui_destroy(ui_t *ui)
+{
+	if (ui == NULL)
+		return;
+
+	if (ui->myoutput)
+		display_close(ui->display);
+	free(ui);
+}
+
+/** @}
+ */
Index: uspace/lib/ui/src/window.c
===================================================================
--- uspace/lib/ui/src/window.c	(revision f7a90df6adfcf1a8e402e71eed9795cd4e9eabf6)
+++ uspace/lib/ui/src/window.c	(revision f7a90df6adfcf1a8e402e71eed9795cd4e9eabf6)
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2020 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libui
+ * @{
+ */
+/**
+ * @file Window
+ */
+
+#include <display.h>
+#include <errno.h>
+#include <gfx/context.h>
+#include <mem.h>
+#include <stdlib.h>
+#include <ui/resource.h>
+#include <ui/wdecor.h>
+#include <ui/window.h>
+#include "../private/dummygc.h"
+#include "../private/ui.h"
+#include "../private/window.h"
+
+/** Initialize window parameters structure.
+ *
+ * Window parameters structure must always be initialized using this function
+ * first.
+ *
+ * @param params Window parameters structure
+ */
+void ui_window_params_init(ui_window_params_t *params)
+{
+	memset(params, 0, sizeof(ui_window_params_t));
+}
+
+/** Create new window.
+ *
+ * @param ui User interface
+ * @param params Window parameters
+ * @param rwindow Place to store pointer to new window
+ * @return EOK on success or an error code
+ */
+errno_t ui_window_create(ui_t *ui, ui_window_params_t *params,
+    ui_window_t **rwindow)
+{
+	ui_window_t *window;
+	display_wnd_params_t dparams;
+	display_window_t *dwindow = NULL;
+	gfx_context_t *gc = NULL;
+	ui_resource_t *res = NULL;
+	ui_wdecor_t *wdecor = NULL;
+	dummy_gc_t *dgc = NULL;
+	errno_t rc;
+
+	window = calloc(1, sizeof(ui_window_t));
+	if (window == NULL)
+		return ENOMEM;
+
+	display_wnd_params_init(&dparams);
+
+	if (ui->display != NULL) {
+		rc = display_window_create(ui->display, &dparams, NULL, NULL,
+		    &dwindow);
+		if (rc != EOK)
+			goto error;
+
+		rc = display_window_get_gc(dwindow, &gc);
+		if (rc != EOK)
+			goto error;
+	} else {
+		/* Needed for unit tests */
+		rc = dummygc_create(&dgc);
+		if (rc != EOK)
+			goto error;
+
+		gc = dummygc_get_ctx(dgc);
+	}
+
+	rc = ui_resource_create(gc, &res);
+	if (rc != EOK)
+		goto error;
+
+	rc = ui_wdecor_create(res, params->caption, &wdecor);
+	if (rc != EOK)
+		goto error;
+
+	window->ui = ui;
+	window->dwindow = dwindow;
+	window->gc = gc;
+	window->res = res;
+	window->wdecor = wdecor;
+	*rwindow = window;
+	return EOK;
+error:
+	if (wdecor != NULL)
+		ui_wdecor_destroy(wdecor);
+	if (res != NULL)
+		ui_resource_destroy(res);
+	if (dgc != NULL)
+		dummygc_destroy(dgc);
+	if (dwindow != NULL)
+		display_window_destroy(dwindow);
+	free(window);
+	return rc;
+}
+
+/** Destroy window.
+ *
+ * @param window Window or @c NULL
+ */
+void ui_window_destroy(ui_window_t *window)
+{
+	if (window == NULL)
+		return;
+
+	ui_wdecor_destroy(window->wdecor);
+	ui_resource_destroy(window->res);
+	gfx_context_delete(window->gc);
+	display_window_destroy(window->dwindow);
+	free(window);
+}
+
+/** @}
+ */
