Index: uspace/lib/gui/window.c
===================================================================
--- uspace/lib/gui/window.c	(revision 61b5b73da4751fa87cc6b1c1d81fe4796bc905e1)
+++ uspace/lib/gui/window.c	(revision 34cb6c8d2f3e38a59a0232921b3ef17208862064)
@@ -56,133 +56,75 @@
 #include <surface.h>
 
-#include "common.h"
 #include "connection.h"
 #include "widget.h"
 #include "window.h"
 
-static sysarg_t border_thickness = 4;
-static sysarg_t bevel_thickness = 1;
+static sysarg_t border_thickness = 5;
 static sysarg_t header_height = 20;
 static sysarg_t header_min_width = 40;
-static sysarg_t close_thickness = 20;
-
-static pixel_t color_highlight = PIXEL(255, 255, 255, 255);
-static pixel_t color_shadow = PIXEL(255, 85, 85, 85);
-static pixel_t color_surface = PIXEL(255, 186, 186, 186);
-
-static pixel_t color_header_focus_highlight = PIXEL(255, 120, 145, 255);
-static pixel_t color_header_focus_shadow = PIXEL(255, 40, 48, 89);
-static pixel_t color_header_focus_surface = PIXEL(255, 88, 106, 196);
-
-static pixel_t color_header_unfocus_highlight = PIXEL(255, 16, 78, 126);
-static pixel_t color_header_unfocus_shadow = PIXEL(255, 5, 26, 42);
-static pixel_t color_header_unfocus_surface = PIXEL(255, 12, 57, 92);
-
-static pixel_t color_caption_focus = PIXEL(255, 255, 255, 255);
-static pixel_t color_caption_unfocus = PIXEL(255, 207, 207, 207);
-
-static void paint_internal(widget_t *widget)
-{
-	surface_t *surface = window_claim(widget->window);
-	if (!surface)
-		window_yield(widget->window);
-	
+static sysarg_t close_width = 20;
+
+static pixel_t border_color = PIXEL(255, 0, 0, 0);
+static pixel_t header_bg_focus_color = PIXEL(255, 88, 106, 196);
+static pixel_t header_fg_focus_color = PIXEL(255, 255, 255, 255);
+static pixel_t header_bg_unfocus_color = PIXEL(255, 12, 57, 92);
+static pixel_t header_fg_unfocus_color = PIXEL(255, 255, 255, 255);
+
+static void paint_internal(widget_t *w)
+{
+	surface_t *surface = window_claim(w->window);
+	if (!surface) {
+		window_yield(w->window);
+	}
+
 	source_t source;
+	font_t font;
+	drawctx_t drawctx;
+
 	source_init(&source);
-	
-	drawctx_t drawctx;
+	font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);
 	drawctx_init(&drawctx, surface);
 	drawctx_set_source(&drawctx, &source);
-	
-	/* Window border outer bevel */
-	
-	draw_bevel(&drawctx, &source, widget->vpos, widget->hpos,
-	    widget->width, widget->height, color_highlight, color_shadow);
-	
-	/* Window border surface */
-	
-	source_set_color(&source, color_surface);
-	drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
-	    widget->width - 2, 2);
-	drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
-	    2, widget->height - 2);
-	drawctx_transfer(&drawctx, widget->hpos + 1,
-	    widget->vpos + widget->height - 3, widget->width - 2, 2);
-	drawctx_transfer(&drawctx, widget->hpos + widget->width - 3,
-	    widget->vpos + 1, 2, widget->height - 4);
-	
-	/* Window border inner bevel */
-	
-	draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3,
-	    widget->width - 6, widget->height - 6, color_shadow,
-	    color_highlight);
-	
-	/* Header bevel */
-	
-	sysarg_t header_hpos = widget->hpos + border_thickness;
-	sysarg_t header_vpos = widget->vpos + border_thickness;
-	sysarg_t header_width = widget->width - 2 * border_thickness -
-	    close_thickness;
-	
-	draw_bevel(&drawctx, &source, header_hpos, header_vpos,
-	    header_width, header_height, widget->window->is_focused ?
-	    color_header_focus_highlight : color_header_unfocus_highlight,
-	    widget->window->is_focused ?
-	    color_header_focus_shadow : color_header_unfocus_shadow);
-	
-	/* Header surface */
-	
-	source_set_color(&source, widget->window->is_focused ?
-	    color_header_focus_surface : color_header_unfocus_surface);
-	drawctx_transfer(&drawctx, header_hpos + 1, header_vpos + 1,
-	    header_width - 2, header_height - 2);
-	
-	/* Close button bevel */
-	
-	sysarg_t close_hpos = widget->hpos + widget->width -
-	    border_thickness - close_thickness;
-	sysarg_t close_vpos = widget->vpos + border_thickness;
-	
-	draw_bevel(&drawctx, &source, close_hpos, close_vpos,
-	    close_thickness, close_thickness, color_highlight, color_shadow);
-	
-	/* Close button surface */
-	
-	source_set_color(&source, color_surface);
-	drawctx_transfer(&drawctx, close_hpos + 1, close_vpos + 1,
-	    close_thickness - 2, close_thickness - 2);
-	
-	/* Close button icon */
-	
-	draw_icon_cross(surface, close_hpos + 3, close_vpos + 3,
-	    color_highlight, color_shadow);
-	
-	/* Window caption */
-	
-	font_t font;
-	font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);
-	
 	drawctx_set_font(&drawctx, &font);
-	source_set_color(&source, widget->window->is_focused ?
-	    color_caption_focus : color_caption_unfocus);
-	
+
+	source_set_color(&source, border_color);
+	drawctx_transfer(&drawctx, w->hpos, w->vpos, border_thickness, w->height);
+	drawctx_transfer(&drawctx, w->hpos + w->width - border_thickness,
+	    w->vpos, border_thickness, w->height);
+	drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, border_thickness);
+	drawctx_transfer(&drawctx, w->hpos,
+	    w->vpos + w->height - border_thickness, w->width, border_thickness);
+
+	source_set_color(&source, 
+	    w->window->is_focused ? header_bg_focus_color : header_bg_unfocus_color);
+	drawctx_transfer(&drawctx,
+	    w->hpos + border_thickness, w->vpos + border_thickness,
+		w->width - 2 * border_thickness, header_height);
+
 	sysarg_t cpt_width;
 	sysarg_t cpt_height;
-	font_get_box(&font, widget->window->caption, &cpt_width, &cpt_height);
-	
-	bool draw_title =
-	    (widget->width >= 2 * border_thickness + 2 * bevel_thickness +
-	    close_thickness + cpt_width);
+	font_get_box(&font, w->window->caption, &cpt_width, &cpt_height);
+	sysarg_t cls_width;
+	sysarg_t cls_height;
+	char cls_pict[] = "x";
+	font_get_box(&font, cls_pict, &cls_width, &cls_height);
+	source_set_color(&source, 
+	    w->window->is_focused ? header_fg_focus_color : header_fg_unfocus_color);
+	sysarg_t cls_x = ((close_width - cls_width) / 2) + w->hpos + w->width -
+	    border_thickness - close_width;
+	sysarg_t cls_y = ((header_height - cls_height) / 2) + w->vpos + border_thickness;
+	drawctx_print(&drawctx, cls_pict, cls_x, cls_y);
+
+	bool draw_title = (w->width >= 2 * border_thickness + close_width + cpt_width);
 	if (draw_title) {
-		sysarg_t cpt_x = ((widget->width - cpt_width) / 2) + widget->hpos;
-		sysarg_t cpt_y = ((header_height - cpt_height) / 2) +
-		    widget->vpos + border_thickness;
-		
-		if (widget->window->caption)
-			drawctx_print(&drawctx, widget->window->caption, cpt_x, cpt_y);
-	}
-	
+		sysarg_t cpt_x = ((w->width - cpt_width) / 2) + w->hpos;
+		sysarg_t cpt_y = ((header_height - cpt_height) / 2) + w->vpos + border_thickness;
+		if (w->window->caption) {
+			drawctx_print(&drawctx, w->window->caption, cpt_x, cpt_y);
+		}
+	}
+
 	font_release(&font);
-	window_yield(widget->window);
+	window_yield(w->window);
 }
 
@@ -196,5 +138,5 @@
 	if (widget->window->is_decorated) {
 		list_foreach(widget->children, link, widget_t, child) {
-			child->rearrange(child,
+			child->rearrange(child, 
 			    widget->hpos + border_thickness,
 			    widget->vpos + border_thickness + header_height,
@@ -269,6 +211,5 @@
 		    (event.vpos >= border_thickness) &&
 		    (event.vpos < border_thickness + header_height);
-		bool close = (header) &&
-		    (event.hpos >= width - border_thickness - close_thickness);
+		bool close = header && (event.hpos >= width - border_thickness - close_width);
 
 		if (top && left && allowed_button) {
@@ -351,5 +292,5 @@
 }
 
-static void handle_signal_event(window_t *win, signal_event_t event)
+static void handle_signal_event(window_t *win, sig_event_t event)
 {
 	widget_t *widget = (widget_t *) event.object;
@@ -362,56 +303,58 @@
 }
 
-static void handle_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y,
-    sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
-{
+static void handle_resize(window_t *win, sysarg_t width, sysarg_t height)
+{
+	int rc;
+	surface_t *old_surface;
+	surface_t *new_surface;
+
 	if (width < 2 * border_thickness + header_min_width) {
 		win_damage(win->osess, 0, 0, 0, 0);
 		return;
 	}
-	
+
 	if (height < 2 * border_thickness + header_height) {
 		win_damage(win->osess, 0, 0, 0, 0);
 		return;
 	}
-	
+
 	/* Allocate resources for new surface. */
-	surface_t *new_surface = surface_create(width, height, NULL,
-	    SURFACE_FLAG_SHARED);
-	if (!new_surface)
+	new_surface = surface_create(width, height, NULL, SURFACE_FLAG_SHARED);
+	if (!new_surface) {
 		return;
-	
+	}
+
 	/* Switch new and old surface. */
 	fibril_mutex_lock(&win->guard);
-	surface_t *old_surface = win->surface;
+	old_surface = win->surface;
 	win->surface = new_surface;
 	fibril_mutex_unlock(&win->guard);
-	
-	/*
-	 * Let all widgets in the tree alter their position and size.
-	 * Widgets might also paint themselves onto the new surface.
-	 */
+
+	/* Let all widgets in the tree alter their position and size. Widgets might
+	 * also paint themselves onto the new surface. */
 	win->root.rearrange(&win->root, 0, 0, width, height);
-	
+
 	fibril_mutex_lock(&win->guard);
 	surface_reset_damaged_region(win->surface);
 	fibril_mutex_unlock(&win->guard);
-	
+
 	/* Inform compositor about new surface. */
-	int rc = win_resize(win->osess, offset_x, offset_y, width, height,
-	    placement_flags, surface_direct_access(new_surface));
-	
+	rc = win_resize(win->osess,
+		width, height, surface_direct_access(new_surface));
+
 	if (rc != EOK) {
 		/* Rollback to old surface. Reverse all changes. */
-		
+
 		sysarg_t old_width = 0;
 		sysarg_t old_height = 0;
-		if (old_surface)
+		if (old_surface) {
 			surface_get_resolution(old_surface, &old_width, &old_height);
-		
+		}
+
 		fibril_mutex_lock(&win->guard);
 		new_surface = win->surface;
 		win->surface = old_surface;
 		fibril_mutex_unlock(&win->guard);
-		
+
 		win->root.rearrange(&win->root, 0, 0, old_width, old_height);
 		
@@ -421,10 +364,12 @@
 			fibril_mutex_unlock(&win->guard);
 		}
-		
+
 		surface_destroy(new_surface);
-	} else {
-		/* Deallocate old surface. */
-		if (old_surface)
-			surface_destroy(old_surface);
+		return;
+	}
+
+	/* Finally deallocate old surface. */
+	if (old_surface) {
+		surface_destroy(old_surface);
 	}
 }
@@ -508,10 +453,8 @@
 			break;
 		case ET_SIGNAL_EVENT:
-			handle_signal_event(win, event->data.signal);
+			handle_signal_event(win, event->data.sig);
 			break;
 		case ET_WINDOW_RESIZE:
-			handle_resize(win, event->data.resize.offset_x,
-			    event->data.resize.offset_y, event->data.resize.width,
-			    event->data.resize.height, event->data.resize.placement_flags);
+			handle_resize(win, event->data.rsz.width, event->data.rsz.height);
 			break;
 		case ET_WINDOW_FOCUS:
@@ -587,10 +530,13 @@
 
 window_t *window_open(const char *winreg, bool is_main, bool is_decorated,
-    const char *caption)
-{
+    const char *caption, sysarg_t x_offset, sysarg_t y_offset)
+{
+	int rc;
+
 	window_t *win = (window_t *) malloc(sizeof(window_t));
-	if (!win)
+	if (!win) {
 		return NULL;
-	
+	}
+
 	win->is_main = is_main;
 	win->is_decorated = is_decorated;
@@ -598,5 +544,4 @@
 	prodcons_initialize(&win->events);
 	fibril_mutex_initialize(&win->guard);
-	
 	widget_init(&win->root, NULL);
 	win->root.window = win;
@@ -610,22 +555,24 @@
 	win->focus = NULL;
 	win->surface = NULL;
-	
+
 	service_id_t reg_dsid;
-	int rc = loc_service_get_id(winreg, &reg_dsid, 0);
+	async_sess_t *reg_sess;
+
+	rc = loc_service_get_id(winreg, &reg_dsid, 0);
 	if (rc != EOK) {
 		free(win);
 		return NULL;
 	}
-	
-	async_sess_t *reg_sess = loc_service_connect(EXCHANGE_SERIALIZE,
-	    reg_dsid, 0);
+
+	reg_sess = loc_service_connect(EXCHANGE_SERIALIZE, reg_dsid, 0);
 	if (reg_sess == NULL) {
 		free(win);
 		return NULL;
 	}
-	
+
 	service_id_t in_dsid;
 	service_id_t out_dsid;
-	rc = win_register(reg_sess, &in_dsid, &out_dsid);
+	
+	rc = win_register(reg_sess, &in_dsid, &out_dsid, x_offset, y_offset);
 	async_hangup(reg_sess);
 	if (rc != EOK) {
@@ -633,5 +580,5 @@
 		return NULL;
 	}
-	
+
 	win->osess = loc_service_connect(EXCHANGE_SERIALIZE, out_dsid, 0);
 	if (win->osess == NULL) {
@@ -639,5 +586,5 @@
 		return NULL;
 	}
-	
+
 	win->isess = loc_service_connect(EXCHANGE_SERIALIZE, in_dsid, 0);
 	if (win->isess == NULL) {
@@ -646,15 +593,15 @@
 		return NULL;
 	}
-	
-	if (caption == NULL)
+
+	if (caption == NULL) {
 		win->caption = NULL;
-	else
+	} else {
 		win->caption = str_dup(caption);
-	
+	}
+
 	return win;
 }
 
-void window_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y,
-    sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
+void window_resize(window_t *win, sysarg_t width, sysarg_t height)
 {
 	window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
@@ -662,9 +609,6 @@
 		link_initialize(&event->link);
 		event->type = ET_WINDOW_RESIZE;
-		event->data.resize.offset_x = offset_x;
-		event->data.resize.offset_y = offset_y;
-		event->data.resize.width = width;
-		event->data.resize.height = height;
-		event->data.resize.placement_flags = placement_flags;
+		event->data.rsz.width = width;
+		event->data.rsz.height = height;
 		prodcons_produce(&win->events, &event->link);
 	}
