Index: uspace/app/terminal/main.c
===================================================================
--- uspace/app/terminal/main.c	(revision 26653c9e91e1fc92d3b3036b30cf3df560627090)
+++ uspace/app/terminal/main.c	(revision dcfd422dba88d6b14bf3fabca029117aa9922b5e)
@@ -40,11 +40,42 @@
 #define NAME  "terminal"
 
+/** Print syntax. */
+static void print_syntax(void)
+{
+	printf("Syntax: %s [-d <display>]\n", NAME);
+}
+
 int main(int argc, char *argv[])
 {
+	const char *display_svc = DISPLAY_DEFAULT;
 	display_t *display = NULL;
 	terminal_t *terminal = NULL;
 	errno_t rc;
+	int i;
 
-	rc = display_open(DISPLAY_DEFAULT, &display);
+	i = 1;
+	while (i < argc && argv[i][0] == '-') {
+		if (str_cmp(argv[i], "-d") == 0) {
+			++i;
+			if (i >= argc) {
+				printf("Argument missing.\n");
+				print_syntax();
+				return 1;
+			}
+
+			display_svc = argv[i++];
+		} else {
+			printf("Invalid option '%s'.\n", argv[i]);
+			print_syntax();
+			return 1;
+		}
+	}
+
+	if (i < argc) {
+		print_syntax();
+		return 1;
+	}
+
+	rc = display_open(display_svc, &display);
 	if (rc != EOK) {
 		printf("%s: Error opening display.\n", NAME);
Index: uspace/app/terminal/terminal.c
===================================================================
--- uspace/app/terminal/terminal.c	(revision 26653c9e91e1fc92d3b3036b30cf3df560627090)
+++ uspace/app/terminal/terminal.c	(revision dcfd422dba88d6b14bf3fabca029117aa9922b5e)
@@ -50,4 +50,6 @@
 #include <stdlib.h>
 #include <str.h>
+#include <ui/resource.h>
+#include <ui/wdecor.h>
 
 #include "terminal.h"
@@ -100,8 +102,24 @@
 };
 
+static void terminal_close_event(void *);
+static void terminal_focus_event(void *);
 static void terminal_kbd_event(void *, kbd_event_t *);
+static void terminal_pos_event(void *, pos_event_t *);
+static void terminal_unfocus_event(void *);
 
 static display_wnd_cb_t terminal_wnd_cb = {
-	.kbd_event = terminal_kbd_event
+	.close_event = terminal_close_event,
+	.focus_event = terminal_focus_event,
+	.kbd_event = terminal_kbd_event,
+	.pos_event = terminal_pos_event,
+	.unfocus_event = terminal_unfocus_event
+};
+
+static void terminal_wd_close(ui_wdecor_t *, void *);
+static void terminal_wd_move(ui_wdecor_t *, void *, gfx_coord2_t *);
+
+static ui_wdecor_cb_t wdecor_cb = {
+	.close = terminal_wd_close,
+	.move = terminal_wd_move
 };
 
@@ -305,4 +323,5 @@
 	pixelmap_t pixelmap;
 	gfx_bitmap_alloc_t alloc;
+	gfx_coord2_t pos;
 	errno_t rc;
 
@@ -360,5 +379,7 @@
 
 	if (update) {
-		(void) gfx_bitmap_render(term->bmp, &term->update, NULL);
+		pos.x = 4;
+		pos.y = 26;
+		(void) gfx_bitmap_render(term->bmp, &term->update, &pos);
 
 		term->update.p0.x = 0;
@@ -655,5 +676,27 @@
 }
 
-/* Got key press/release event */
+/** Handle window close event. */
+static void terminal_close_event(void *arg)
+{
+	terminal_t *term = (terminal_t *) arg;
+
+	(void) term;
+
+	// XXX This is not really a clean way of terminating
+	exit(0);
+}
+
+/** Handle window focus event. */
+static void terminal_focus_event(void *arg)
+{
+	terminal_t *term = (terminal_t *) arg;
+
+	if (term->wdecor != NULL) {
+		ui_wdecor_set_active(term->wdecor, true);
+		ui_wdecor_paint(term->wdecor);
+	}
+}
+
+/** Handle window keyboard event */
 static void terminal_kbd_event(void *arg, kbd_event_t *kbd_event)
 {
@@ -665,4 +708,27 @@
 
 	terminal_queue_cons_event(term, &event);
+}
+
+/** Handle window position event */
+static void terminal_pos_event(void *arg, pos_event_t *event)
+{
+	terminal_t *term = (terminal_t *) arg;
+
+	/* Make sure we don't process events until fully initialized */
+	if (term->wdecor == NULL)
+		return;
+
+	ui_wdecor_pos_event(term->wdecor, event);
+}
+
+/** Handle window unfocus event. */
+static void terminal_unfocus_event(void *arg)
+{
+	terminal_t *term = (terminal_t *) arg;
+
+	if (term->wdecor != NULL) {
+		ui_wdecor_set_active(term->wdecor, false);
+		ui_wdecor_paint(term->wdecor);
+	}
 }
 
@@ -688,4 +754,33 @@
 #endif
 
+/** Window decoration requested window closure.
+ *
+ * @param wdecor Window decoration
+ * @param arg Argument (demo)
+ */
+static void terminal_wd_close(ui_wdecor_t *wdecor, void *arg)
+{
+	terminal_t *term = (terminal_t *) arg;
+
+	(void) term;
+
+	// XXX This is not really a clean way of terminating
+	exit(0);
+}
+
+/** Window decoration requested window move.
+ *
+ * @param wdecor Window decoration
+ * @param arg Argument (demo)
+ * @param pos Position where the title bar was pressed
+ */
+static void terminal_wd_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos)
+{
+	terminal_t *term = (terminal_t *) arg;
+
+	if (term->window != NULL)
+		(void) display_window_move_req(term->window, pos);
+}
+
 static void term_connection(ipc_call_t *icall, void *arg)
 {
@@ -716,4 +811,7 @@
 	gfx_bitmap_params_t params;
 	display_wnd_params_t wparams;
+	gfx_rect_t rect;
+	gfx_coord2_t off;
+	gfx_rect_t wrect;
 	errno_t rc;
 
@@ -756,9 +854,18 @@
 	}
 
+	rect.p0.x = 0;
+	rect.p0.y = 0;
+	rect.p1.x = width;
+	rect.p1.y = height;
+
 	display_wnd_params_init(&wparams);
-	wparams.rect.p0.x = 0;
-	wparams.rect.p0.y = 0;
-	wparams.rect.p1.x = width;
-	wparams.rect.p1.y = height;
+
+	/*
+	 * Compute window rectangle such that application area corresponds
+	 * to rect
+	 */
+	ui_wdecor_rect_from_app(&rect, &wrect);
+	off = wrect.p0;
+	gfx_rect_rtranslate(&off, &wrect, &wparams.rect);
 
 	rc = display_window_create(display, &wparams, &terminal_wnd_cb,
@@ -775,4 +882,21 @@
 	}
 
+	rc = ui_resource_create(term->gc, &term->ui_res);
+	if (rc != EOK) {
+		printf("Error creating UI.\n");
+		goto error;
+	}
+
+	rc = ui_wdecor_create(term->ui_res, "Terminal", &term->wdecor);
+	if (rc != EOK) {
+		printf("Error creating window decoration.\n");
+		goto error;
+	}
+
+	ui_wdecor_set_rect(term->wdecor, &wparams.rect);
+	ui_wdecor_set_cb(term->wdecor, &wdecor_cb, (void *) term);
+
+	(void) ui_wdecor_paint(term->wdecor);
+
 	gfx_bitmap_params_init(&params);
 	params.rect.p0.x = 0;
@@ -827,4 +951,8 @@
 	return EOK;
 error:
+	if (term->wdecor != NULL)
+		ui_wdecor_destroy(term->wdecor);
+	if (term->ui_res != NULL)
+		ui_resource_destroy(term->ui_res);
 	if (term->gc != NULL)
 		gfx_context_delete(term->gc);
Index: uspace/app/terminal/terminal.h
===================================================================
--- uspace/app/terminal/terminal.h	(revision 26653c9e91e1fc92d3b3036b30cf3df560627090)
+++ uspace/app/terminal/terminal.h	(revision dcfd422dba88d6b14bf3fabca029117aa9922b5e)
@@ -50,4 +50,6 @@
 #include <stdatomic.h>
 #include <str.h>
+#include <ui/resource.h>
+#include <ui/wdecor.h>
 
 #define UTF8_CHAR_BUFFER_SIZE  (STR_BOUNDS(1) + 1)
@@ -60,4 +62,7 @@
 	sysarg_t h;
 	gfx_rect_t update;
+
+	ui_resource_t *ui_res;
+	ui_wdecor_t *wdecor;
 
 	fibril_mutex_t mtx;
Index: uspace/lib/ui/include/ui/wdecor.h
===================================================================
--- uspace/lib/ui/include/ui/wdecor.h	(revision 26653c9e91e1fc92d3b3036b30cf3df560627090)
+++ uspace/lib/ui/include/ui/wdecor.h	(revision dcfd422dba88d6b14bf3fabca029117aa9922b5e)
@@ -52,4 +52,5 @@
 extern errno_t ui_wdecor_paint(ui_wdecor_t *);
 extern void ui_wdecor_pos_event(ui_wdecor_t *, pos_event_t *);
+extern void ui_wdecor_rect_from_app(gfx_rect_t *, gfx_rect_t *);
 
 #endif
Index: uspace/lib/ui/src/wdecor.c
===================================================================
--- uspace/lib/ui/src/wdecor.c	(revision 26653c9e91e1fc92d3b3036b30cf3df560627090)
+++ uspace/lib/ui/src/wdecor.c	(revision dcfd422dba88d6b14bf3fabca029117aa9922b5e)
@@ -271,4 +271,21 @@
 }
 
+/** Get outer rectangle from application area rectangle.
+ *
+ * Note that this needs to work just based on a UI, without having an actual
+ * window decoration, since we need it in order to create the window
+ * and its decoration.
+ *
+ * @param app Application area rectangle
+ * @param rect Place to store (outer) window decoration rectangle
+ */
+void ui_wdecor_rect_from_app(gfx_rect_t *app, gfx_rect_t *rect)
+{
+	rect->p0.x = app->p0.x - 4;
+	rect->p0.y = app->p0.y - 22 - 4;
+	rect->p1.x = app->p1.x + 4;
+	rect->p1.y = app->p1.y + 4;
+}
+
 /** Handle window decoration position event.
  *
Index: uspace/lib/ui/test/wdecor.c
===================================================================
--- uspace/lib/ui/test/wdecor.c	(revision 26653c9e91e1fc92d3b3036b30cf3df560627090)
+++ uspace/lib/ui/test/wdecor.c	(revision dcfd422dba88d6b14bf3fabca029117aa9922b5e)
@@ -310,4 +310,5 @@
 }
 
+/** ui_wdecor_get_geom() produces the correct geometry */
 PCUT_TEST(get_geom)
 {
@@ -349,4 +350,23 @@
 
 	ui_wdecor_destroy(wdecor);
+}
+
+/** ui_wdecor_rect_from_app() correctly converts application to window rect */
+PCUT_TEST(rect_from_app)
+{
+	gfx_rect_t arect;
+	gfx_rect_t rect;
+
+	arect.p0.x = 14;
+	arect.p0.y = 46;
+	arect.p1.x = 96;
+	arect.p1.y = 196;
+
+	ui_wdecor_rect_from_app(&arect, &rect);
+
+	PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
+	PCUT_ASSERT_INT_EQUALS(20, rect.p0.y);
+	PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
+	PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
 }
 
