Index: uspace/app/viewer/viewer.c
===================================================================
--- uspace/app/viewer/viewer.c	(revision c1b8ad4ada46d00160a9a334f11c6017bff4e8b9)
+++ uspace/app/viewer/viewer.c	(revision c064b58528b1a0e1c74fe2790f8ddddcb03b3e84)
@@ -51,4 +51,7 @@
 #define WINDOW_HEIGHT  768
 
+#define DECORATION_WIDTH	8
+#define DECORATION_HEIGHT	28
+
 static size_t imgs_count;
 static size_t imgs_current = 0;
@@ -59,5 +62,9 @@
 static canvas_t *canvas = NULL;
 
-static bool img_load(const char *);
+static surface_coord_t img_width;
+static surface_coord_t img_height;
+
+static bool img_load(const char *, surface_t **);
+static bool img_setup(surface_t *);
 
 static void on_keyboard_event(widget_t *widget, void *data)
@@ -88,12 +95,18 @@
 	
 	if (update) {
-		if (!img_load(imgs[imgs_current])) {
+		surface_t *lsface;
+
+		if (!img_load(imgs[imgs_current], &lsface)) {
 			printf("Cannot load image \"%s\".\n", imgs[imgs_current]);
-			exit(2);
-		}
-	}
-}
-
-static bool img_load(const char *fname)
+			exit(4);
+		}
+		if (!img_setup(lsface)) {
+			printf("Cannot setup image \"%s\".\n", imgs[imgs_current]);
+			exit(6);
+		}
+	}
+}
+
+static bool img_load(const char *fname, surface_t **p_local_surface)
 {
 	int fd = open(fname, O_RDONLY);
@@ -123,6 +136,6 @@
 	close(fd);
 	
-	surface_t *local_surface = decode_tga(tga, stat.size, 0);
-	if (local_surface == NULL) {
+	*p_local_surface = decode_tga(tga, stat.size, 0);
+	if (*p_local_surface == NULL) {
 		free(tga);
 		return false;
@@ -130,5 +143,12 @@
 	
 	free(tga);
-	
+
+	surface_get_resolution(*p_local_surface, &img_width, &img_height);
+	
+	return true;
+}
+
+static bool img_setup(surface_t *local_surface)
+{
 	if (canvas != NULL) {
 		if (!update_canvas(canvas, local_surface)) {
@@ -138,5 +158,5 @@
 	} else {
 		canvas = create_canvas(window_root(main_window),
-		    WINDOW_WIDTH, WINDOW_HEIGHT, local_surface);
+		    img_width, img_height, local_surface);
 		if (canvas == NULL) {
 			surface_destroy(local_surface);
@@ -151,5 +171,4 @@
 	
 	surface = local_surface;
-	
 	return true;
 }
@@ -157,4 +176,10 @@
 int main(int argc, char *argv[])
 {
+	window_flags_t flags;
+	surface_t *lsface;
+	bool fullscreen;
+	sysarg_t dwidth;
+	sysarg_t dheight;
+
 	if (argc < 2) {
 		printf("Compositor server not specified.\n");
@@ -166,16 +191,10 @@
 		return 1;
 	}
-	
-	main_window = window_open(argv[1], WINDOW_MAIN, "viewer");
-	if (!main_window) {
-		printf("Cannot open main window.\n");
-		return 2;
-	}
-	
+
 	imgs_count = argc - 2;
 	imgs = calloc(imgs_count, sizeof(char *));
 	if (imgs == NULL) {
 		printf("Out of memory.\n");
-		return 3;
+		return 2;
 	}
 	
@@ -184,15 +203,42 @@
 		if (imgs[i] == NULL) {
 			printf("Out of memory.\n");
-			return 4;
-		}
-	}
-	
-	if (!img_load(imgs[imgs_current])) {
+			return 3;
+		}
+	}
+
+	if (!img_load(imgs[imgs_current], &lsface)) {
 		printf("Cannot load image \"%s\".\n", imgs[imgs_current]);
-		return 2;
-	}
-	
-	window_resize(main_window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,
-	    WINDOW_PLACEMENT_ABSOLUTE);
+		return 4;
+	}
+
+	fullscreen = ((img_width == WINDOW_WIDTH) &&
+	    (img_height == WINDOW_HEIGHT));
+
+	flags = WINDOW_MAIN;
+	if (!fullscreen)
+		flags |= WINDOW_DECORATED;
+
+	main_window = window_open(argv[1], flags, "viewer");
+	if (!main_window) {
+		printf("Cannot open main window.\n");
+		return 5;
+	}
+	
+	
+	if (!img_setup(lsface)) {
+		printf("Cannot setup image \"%s\".\n", imgs[imgs_current]);
+		return 6;
+	}
+
+	if (!fullscreen) {
+		dwidth = DECORATION_WIDTH;
+		dheight = DECORATION_HEIGHT;
+	} else {
+		dwidth = 0;
+		dheight = 0;
+	}
+
+	window_resize(main_window, 0, 0, img_width + dwidth,
+	    img_height + dheight, WINDOW_PLACEMENT_ANY);
 	window_exec(main_window);
 	
