Index: uspace/app/viewer/viewer.c
===================================================================
--- uspace/app/viewer/viewer.c	(revision 0a411bbf1272315b83832bcd3aaef4b9720c1bd6)
+++ uspace/app/viewer/viewer.c	(revision 0ffa40a7f0accdb5ebdcdf9d8a74a5512a956a5f)
@@ -56,5 +56,5 @@
 static char **imgs;
 
-static ui_window_t *window;
+static ui_window_t *window = NULL;
 static gfx_bitmap_t *bitmap = NULL;
 static ui_image_t *image = NULL;
@@ -90,8 +90,9 @@
     kbd_event_t *event)
 {
+	viewer_t *viewer = (viewer_t *)arg;
 	bool update = false;
 
 	if ((event->type == KEY_PRESS) && (event->c == 'q'))
-		exit(0);
+		ui_quit(viewer->ui);
 
 	if ((event->type == KEY_PRESS) && (event->key == KC_PAGE_DOWN)) {
@@ -216,5 +217,5 @@
 int main(int argc, char *argv[])
 {
-	const char *display_spec = UI_DISPLAY_DEFAULT;
+	const char *display_spec = UI_ANY_DEFAULT;
 	gfx_bitmap_t *lbitmap;
 	gfx_rect_t lrect;
@@ -277,4 +278,7 @@
 	}
 
+	if (ui_is_fullscreen(ui))
+		fullscreen = true;
+
 	viewer.ui = ui;
 
@@ -298,5 +302,5 @@
 	if (rc != EOK) {
 		printf("Error creating window.\n");
-		return 1;
+		goto error;
 	}
 
@@ -307,5 +311,5 @@
 	if (!img_load(window_gc, imgs[imgs_current], &lbitmap, &lrect)) {
 		printf("Cannot load image \"%s\".\n", imgs[imgs_current]);
-		return 1;
+		goto error;
 	}
 
@@ -322,5 +326,5 @@
 		if (rc != EOK) {
 			printf("Error resizing window.\n");
-			return 1;
+			goto error;
 		}
 	}
@@ -328,5 +332,5 @@
 	if (!img_setup(window_gc, lbitmap, &lrect)) {
 		printf("Cannot setup image \"%s\".\n", imgs[imgs_current]);
-		return 1;
+		goto error;
 	}
 
@@ -334,10 +338,18 @@
 	if (rc != EOK) {
 		printf("Error painting window.\n");
-		return 1;
+		goto error;
 	}
 
 	ui_run(ui);
 
+	ui_window_destroy(window);
+	ui_destroy(ui);
+
 	return 0;
+error:
+	if (window != NULL)
+		ui_window_destroy(window);
+	ui_destroy(ui);
+	return 1;
 }
 
