Index: uspace/srv/hid/display/window.c
===================================================================
--- uspace/srv/hid/display/window.c	(revision 1a1271dfaa2121286470b22326ac39b1f42e1354)
+++ uspace/srv/hid/display/window.c	(revision 0b7e394d99939661ce387bc7b8b283491437ef4d)
@@ -346,4 +346,374 @@
 }
 
+/** Bring window to top.
+ *
+ * @param wnd Window
+ */
+void ds_window_bring_to_top(ds_window_t *wnd)
+{
+	ds_display_t *disp = wnd->display;
+
+	ds_display_remove_window(wnd);
+	ds_display_add_window(disp, wnd);
+}
+
+/** Get generic graphic context from window.
+ *
+ * @param wnd Window
+ * @return Graphic context
+ */
+gfx_context_t *ds_window_get_ctx(ds_window_t *wnd)
+{
+	return wnd->gc;
+}
+
+/** Paint a window using its backing bitmap.
+ *
+ * @param wnd Window to paint
+ * @param rect Display rectangle to paint to
+ * @return EOK on success or an error code
+ */
+errno_t ds_window_paint(ds_window_t *wnd, gfx_rect_t *rect)
+{
+	gfx_rect_t srect;
+	gfx_rect_t *brect;
+	gfx_rect_t crect;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_paint");
+
+	if (rect != NULL) {
+		gfx_rect_rtranslate(&wnd->dpos, rect, &srect);
+
+		/* Determine if we have anything to do */
+		gfx_rect_clip(&srect, &wnd->rect, &crect);
+		if (gfx_rect_is_empty(&crect))
+			return EOK;
+
+		brect = &srect;
+	} else {
+		brect = NULL;
+	}
+
+	/* This can happen in unit tests */
+	if (wnd->bitmap == NULL)
+		return EOK;
+
+	return gfx_bitmap_render(wnd->bitmap, brect, &wnd->dpos);
+}
+
+/** Start moving a window by mouse drag.
+ *
+ * @param wnd Window
+ * @param event Button press event
+ */
+static void ds_window_start_move(ds_window_t *wnd, pos_event_t *event)
+{
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_start_move (%d, %d)",
+	    (int) event->hpos, (int) event->vpos);
+
+	if (wnd->state != dsw_idle)
+		return;
+
+	wnd->orig_pos.x = event->hpos;
+	wnd->orig_pos.y = event->vpos;
+	wnd->state = dsw_moving;
+}
+
+/** Finish moving a window by mouse drag.
+ *
+ * @param wnd Window
+ * @param event Button release event
+ */
+static void ds_window_finish_move(ds_window_t *wnd, pos_event_t *event)
+{
+	gfx_coord2_t pos;
+	gfx_coord2_t dmove;
+	gfx_coord2_t nwpos;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_finish_move (%d, %d)",
+	    (int) event->hpos, (int) event->vpos);
+
+	if (wnd->state != dsw_moving)
+		return;
+
+	pos.x = event->hpos;
+	pos.y = event->vpos;
+	gfx_coord2_subtract(&pos, &wnd->orig_pos, &dmove);
+
+	gfx_coord2_add(&wnd->dpos, &dmove, &nwpos);
+	wnd->dpos = nwpos;
+	wnd->state = dsw_idle;
+
+	(void) ds_display_paint(wnd->display, NULL);
+}
+
+/** Update window position when moving by mouse drag.
+ *
+ * @param wnd Window
+ * @param event Position update event
+ */
+static void ds_window_update_move(ds_window_t *wnd, pos_event_t *event)
+{
+	gfx_coord2_t pos;
+	gfx_coord2_t dmove;
+	gfx_coord2_t nwpos;
+	gfx_rect_t drect;
+	gfx_color_t *color;
+	gfx_context_t *gc;
+	errno_t rc;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_move (%d, %d)",
+	    (int) event->hpos, (int) event->vpos);
+
+	if (wnd->state != dsw_moving)
+		return;
+
+	gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
+
+	gc = ds_display_get_gc(wnd->display); // XXX
+	if (gc != NULL) {
+		gfx_set_color(gc, wnd->display->bg_color);
+		gfx_fill_rect(gc, &drect);
+	}
+
+	pos.x = event->hpos;
+	pos.y = event->vpos;
+	gfx_coord2_subtract(&pos, &wnd->orig_pos, &dmove);
+
+	gfx_coord2_add(&wnd->dpos, &dmove, &nwpos);
+	gfx_rect_translate(&nwpos, &wnd->rect, &drect);
+
+	wnd->orig_pos = pos;
+	wnd->dpos = nwpos;
+
+	rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
+	if (rc != EOK)
+		return;
+
+	gc = ds_display_get_gc(wnd->display); // XXX
+	if (gc != NULL) {
+		gfx_set_color(gc, color);
+		gfx_fill_rect(gc, &drect);
+	}
+
+	gfx_color_delete(color);
+}
+
+/** Finish resizing a window by mouse drag.
+ *
+ * @param wnd Window
+ * @param event Button release event
+ */
+static void ds_window_finish_resize(ds_window_t *wnd, pos_event_t *event)
+{
+	gfx_coord2_t pos;
+	gfx_coord2_t dresize;
+	gfx_rect_t nrect;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_finish_resize (%d, %d)",
+	    (int) event->hpos, (int) event->vpos);
+
+	if (wnd->state != dsw_resizing)
+		return;
+
+	(void) ds_display_paint(wnd->display, NULL);
+
+	pos.x = event->hpos;
+	pos.y = event->vpos;
+	gfx_coord2_subtract(&pos, &wnd->orig_pos, &dresize);
+
+	/* Compute new rectangle */
+	ds_window_calc_resize(wnd, &dresize, &nrect);
+
+	wnd->state = dsw_idle;
+	ds_client_post_resize_event(wnd->client, wnd, &nrect);
+}
+
+/** Update window position when resizing by mouse drag.
+ *
+ * @param wnd Window
+ * @param event Position update event
+ */
+static void ds_window_update_resize(ds_window_t *wnd, pos_event_t *event)
+{
+	gfx_coord2_t pos;
+	gfx_coord2_t dresize;
+	gfx_rect_t nrect;
+	gfx_rect_t drect;
+	gfx_color_t *color;
+	gfx_context_t *gc;
+	errno_t rc;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_resize (%d, %d)",
+	    (int) event->hpos, (int) event->vpos);
+
+	if (wnd->state != dsw_resizing)
+		return;
+
+	gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
+
+	gc = ds_display_get_gc(wnd->display); // XXX
+	if (gc != NULL) {
+		gfx_set_color(gc, wnd->display->bg_color);
+		gfx_fill_rect(gc, &drect);
+	}
+
+	pos.x = event->hpos;
+	pos.y = event->vpos;
+	gfx_coord2_subtract(&pos, &wnd->orig_pos, &dresize);
+
+	ds_window_calc_resize(wnd, &dresize, &nrect);
+	gfx_rect_translate(&wnd->dpos, &nrect, &drect);
+
+	rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
+	if (rc != EOK)
+		return;
+
+	gc = ds_display_get_gc(wnd->display); // XXX
+	if (gc != NULL) {
+		gfx_set_color(gc, color);
+		gfx_fill_rect(gc, &drect);
+	}
+
+	gfx_color_delete(color);
+}
+
+/** Post keyboard event to window.
+ *
+ * @param wnd Window
+ * @param event Event
+ *
+ * @return EOK on success or an error code
+ */
+errno_t ds_window_post_kbd_event(ds_window_t *wnd, kbd_event_t *event)
+{
+	bool alt_or_shift;
+
+	alt_or_shift = event->mods & (KM_SHIFT | KM_ALT);
+
+	if (event->type == KEY_PRESS && alt_or_shift && event->key == KC_F4) {
+		/* On Alt-F4 or Shift-F4 send close event to the window */
+		ds_client_post_close_event(wnd->client, wnd);
+		return EOK;
+	}
+
+	return ds_client_post_kbd_event(wnd->client, wnd, event);
+}
+
+/** Post position event to window.
+ *
+ * @param wnd Window
+ * @param event Position event
+ */
+errno_t ds_window_post_pos_event(ds_window_t *wnd, pos_event_t *event)
+{
+	pos_event_t tevent;
+	gfx_coord2_t pos;
+	gfx_rect_t drect;
+	bool inside;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG,
+	    "ds_window_post_pos_event type=%d pos=%d,%d\n", event->type,
+	    (int) event->hpos, (int) event->vpos);
+
+	pos.x = event->hpos;
+	pos.y = event->vpos;
+	gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
+	inside = gfx_pix_inside_rect(&pos, &drect);
+
+	if (event->type == POS_PRESS && event->btn_num == 2 && inside)
+		ds_window_start_move(wnd, event);
+
+	if (event->type == POS_RELEASE) {
+		ds_window_finish_move(wnd, event);
+		ds_window_finish_resize(wnd, event);
+	}
+
+	if (event->type == POS_UPDATE) {
+		ds_window_update_move(wnd, event);
+		ds_window_update_resize(wnd, event);
+	}
+
+	/* Transform event coordinates to window-local */
+	tevent = *event;
+	tevent.hpos -= wnd->dpos.x;
+	tevent.vpos -= wnd->dpos.y;
+
+	return ds_client_post_pos_event(wnd->client, wnd, &tevent);
+}
+
+/** Post focus event to window.
+ *
+ * @param wnd Window
+ */
+errno_t ds_window_post_focus_event(ds_window_t *wnd)
+{
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_post_focus_event\n");
+
+	return ds_client_post_focus_event(wnd->client, wnd);
+}
+
+/** Post unfocus event to window.
+ *
+ * @param wnd Window
+ */
+errno_t ds_window_post_unfocus_event(ds_window_t *wnd)
+{
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_post_unfocus_event\n");
+
+	return ds_client_post_unfocus_event(wnd->client, wnd);
+}
+
+/** Start moving a window, detected by client.
+ *
+ * @param wnd Window
+ * @param pos Position where the pointer was when the move started
+ *            relative to the window
+ * @param event Button press event
+ */
+void ds_window_move_req(ds_window_t *wnd, gfx_coord2_t *pos)
+{
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_move_req (%d, %d)",
+	    (int) pos->x, (int) pos->y);
+
+	if (wnd->state != dsw_idle)
+		return;
+
+	gfx_coord2_add(&wnd->dpos, pos, &wnd->orig_pos);
+	wnd->state = dsw_moving;
+}
+
+/** Move window.
+ *
+ * @param wnd Window
+ */
+void ds_window_move(ds_window_t *wnd, gfx_coord2_t *dpos)
+{
+	wnd->dpos = *dpos;
+	(void) ds_display_paint(wnd->display, NULL);
+}
+
+/** Start resizing a window, detected by client.
+ *
+ * @param wnd Window
+ * @param rsztype Resize type (which part of window is being dragged)
+ * @param pos Position where the pointer was when the resize started
+ *            relative to the window
+ * @param event Button press event
+ */
+void ds_window_resize_req(ds_window_t *wnd, display_wnd_rsztype_t rsztype,
+    gfx_coord2_t *pos)
+{
+	log_msg(LOG_DEFAULT, LVL_NOTE, "ds_window_resize_req (%d, %d, %d)",
+	    (int) rsztype, (int) pos->x, (int) pos->y);
+
+	if (wnd->state != dsw_idle)
+		return;
+
+	gfx_coord2_add(&wnd->dpos, pos, &wnd->orig_pos);
+	wnd->state = dsw_resizing;
+	wnd->rsztype = rsztype;
+}
+
 /** Resize window.
  *
@@ -400,364 +770,4 @@
 }
 
-/** Bring window to top.
- *
- * @param wnd Window
- */
-void ds_window_bring_to_top(ds_window_t *wnd)
-{
-	ds_display_t *disp = wnd->display;
-
-	ds_display_remove_window(wnd);
-	ds_display_add_window(disp, wnd);
-}
-
-/** Get generic graphic context from window.
- *
- * @param wnd Window
- * @return Graphic context
- */
-gfx_context_t *ds_window_get_ctx(ds_window_t *wnd)
-{
-	return wnd->gc;
-}
-
-/** Paint a window using its backing bitmap.
- *
- * @param wnd Window to paint
- * @param rect Display rectangle to paint to
- * @return EOK on success or an error code
- */
-errno_t ds_window_paint(ds_window_t *wnd, gfx_rect_t *rect)
-{
-	gfx_rect_t srect;
-	gfx_rect_t *brect;
-	gfx_rect_t crect;
-
-	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_paint");
-
-	if (rect != NULL) {
-		gfx_rect_rtranslate(&wnd->dpos, rect, &srect);
-
-		/* Determine if we have anything to do */
-		gfx_rect_clip(&srect, &wnd->rect, &crect);
-		if (gfx_rect_is_empty(&crect))
-			return EOK;
-
-		brect = &srect;
-	} else {
-		brect = NULL;
-	}
-
-	/* This can happen in unit tests */
-	if (wnd->bitmap == NULL)
-		return EOK;
-
-	return gfx_bitmap_render(wnd->bitmap, brect, &wnd->dpos);
-}
-
-/** Start moving a window by mouse drag.
- *
- * @param wnd Window
- * @param event Button press event
- */
-static void ds_window_start_move(ds_window_t *wnd, pos_event_t *event)
-{
-	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_start_move (%d, %d)",
-	    (int) event->hpos, (int) event->vpos);
-
-	if (wnd->state != dsw_idle)
-		return;
-
-	wnd->orig_pos.x = event->hpos;
-	wnd->orig_pos.y = event->vpos;
-	wnd->state = dsw_moving;
-}
-
-/** Finish moving a window by mouse drag.
- *
- * @param wnd Window
- * @param event Button release event
- */
-static void ds_window_finish_move(ds_window_t *wnd, pos_event_t *event)
-{
-	gfx_coord2_t pos;
-	gfx_coord2_t dmove;
-	gfx_coord2_t nwpos;
-
-	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_finish_move (%d, %d)",
-	    (int) event->hpos, (int) event->vpos);
-
-	if (wnd->state != dsw_moving)
-		return;
-
-	pos.x = event->hpos;
-	pos.y = event->vpos;
-	gfx_coord2_subtract(&pos, &wnd->orig_pos, &dmove);
-
-	gfx_coord2_add(&wnd->dpos, &dmove, &nwpos);
-	wnd->dpos = nwpos;
-	wnd->state = dsw_idle;
-
-	(void) ds_display_paint(wnd->display, NULL);
-}
-
-/** Update window position when moving by mouse drag.
- *
- * @param wnd Window
- * @param event Position update event
- */
-static void ds_window_update_move(ds_window_t *wnd, pos_event_t *event)
-{
-	gfx_coord2_t pos;
-	gfx_coord2_t dmove;
-	gfx_coord2_t nwpos;
-	gfx_rect_t drect;
-	gfx_color_t *color;
-	gfx_context_t *gc;
-	errno_t rc;
-
-	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_move (%d, %d)",
-	    (int) event->hpos, (int) event->vpos);
-
-	if (wnd->state != dsw_moving)
-		return;
-
-	gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
-
-	gc = ds_display_get_gc(wnd->display); // XXX
-	if (gc != NULL) {
-		gfx_set_color(gc, wnd->display->bg_color);
-		gfx_fill_rect(gc, &drect);
-	}
-
-	pos.x = event->hpos;
-	pos.y = event->vpos;
-	gfx_coord2_subtract(&pos, &wnd->orig_pos, &dmove);
-
-	gfx_coord2_add(&wnd->dpos, &dmove, &nwpos);
-	gfx_rect_translate(&nwpos, &wnd->rect, &drect);
-
-	wnd->orig_pos = pos;
-	wnd->dpos = nwpos;
-
-	rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
-	if (rc != EOK)
-		return;
-
-	gc = ds_display_get_gc(wnd->display); // XXX
-	if (gc != NULL) {
-		gfx_set_color(gc, color);
-		gfx_fill_rect(gc, &drect);
-	}
-
-	gfx_color_delete(color);
-}
-
-/** Finish resizing a window by mouse drag.
- *
- * @param wnd Window
- * @param event Button release event
- */
-static void ds_window_finish_resize(ds_window_t *wnd, pos_event_t *event)
-{
-	gfx_coord2_t pos;
-	gfx_coord2_t dresize;
-	gfx_rect_t nrect;
-
-	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_finish_resize (%d, %d)",
-	    (int) event->hpos, (int) event->vpos);
-
-	if (wnd->state != dsw_resizing)
-		return;
-
-	(void) ds_display_paint(wnd->display, NULL);
-
-	pos.x = event->hpos;
-	pos.y = event->vpos;
-	gfx_coord2_subtract(&pos, &wnd->orig_pos, &dresize);
-
-	/* Compute new rectangle */
-	ds_window_calc_resize(wnd, &dresize, &nrect);
-
-	wnd->state = dsw_idle;
-	ds_client_post_resize_event(wnd->client, wnd, &nrect);
-}
-
-/** Update window position when resizing by mouse drag.
- *
- * @param wnd Window
- * @param event Position update event
- */
-static void ds_window_update_resize(ds_window_t *wnd, pos_event_t *event)
-{
-	gfx_coord2_t pos;
-	gfx_coord2_t dresize;
-	gfx_rect_t nrect;
-	gfx_rect_t drect;
-	gfx_color_t *color;
-	gfx_context_t *gc;
-	errno_t rc;
-
-	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_resize (%d, %d)",
-	    (int) event->hpos, (int) event->vpos);
-
-	if (wnd->state != dsw_resizing)
-		return;
-
-	gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
-
-	gc = ds_display_get_gc(wnd->display); // XXX
-	if (gc != NULL) {
-		gfx_set_color(gc, wnd->display->bg_color);
-		gfx_fill_rect(gc, &drect);
-	}
-
-	pos.x = event->hpos;
-	pos.y = event->vpos;
-	gfx_coord2_subtract(&pos, &wnd->orig_pos, &dresize);
-
-	ds_window_calc_resize(wnd, &dresize, &nrect);
-	gfx_rect_translate(&wnd->dpos, &nrect, &drect);
-
-	rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
-	if (rc != EOK)
-		return;
-
-	gc = ds_display_get_gc(wnd->display); // XXX
-	if (gc != NULL) {
-		gfx_set_color(gc, color);
-		gfx_fill_rect(gc, &drect);
-	}
-
-	gfx_color_delete(color);
-}
-
-/** Post keyboard event to window.
- *
- * @param wnd Window
- * @param event Event
- *
- * @return EOK on success or an error code
- */
-errno_t ds_window_post_kbd_event(ds_window_t *wnd, kbd_event_t *event)
-{
-	bool alt_or_shift;
-
-	alt_or_shift = event->mods & (KM_SHIFT | KM_ALT);
-
-	if (event->type == KEY_PRESS && alt_or_shift && event->key == KC_F4) {
-		/* On Alt-F4 or Shift-F4 send close event to the window */
-		ds_client_post_close_event(wnd->client, wnd);
-		return EOK;
-	}
-
-	return ds_client_post_kbd_event(wnd->client, wnd, event);
-}
-
-/** Post position event to window.
- *
- * @param wnd Window
- * @param event Position event
- */
-errno_t ds_window_post_pos_event(ds_window_t *wnd, pos_event_t *event)
-{
-	pos_event_t tevent;
-	gfx_coord2_t pos;
-	gfx_rect_t drect;
-	bool inside;
-
-	log_msg(LOG_DEFAULT, LVL_DEBUG,
-	    "ds_window_post_pos_event type=%d pos=%d,%d\n", event->type,
-	    (int) event->hpos, (int) event->vpos);
-
-	pos.x = event->hpos;
-	pos.y = event->vpos;
-	gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
-	inside = gfx_pix_inside_rect(&pos, &drect);
-
-	if (event->type == POS_PRESS && event->btn_num == 2 && inside)
-		ds_window_start_move(wnd, event);
-
-	if (event->type == POS_RELEASE) {
-		ds_window_finish_move(wnd, event);
-		ds_window_finish_resize(wnd, event);
-	}
-
-	if (event->type == POS_UPDATE) {
-		ds_window_update_move(wnd, event);
-		ds_window_update_resize(wnd, event);
-	}
-
-	/* Transform event coordinates to window-local */
-	tevent = *event;
-	tevent.hpos -= wnd->dpos.x;
-	tevent.vpos -= wnd->dpos.y;
-
-	return ds_client_post_pos_event(wnd->client, wnd, &tevent);
-}
-
-/** Post focus event to window.
- *
- * @param wnd Window
- */
-errno_t ds_window_post_focus_event(ds_window_t *wnd)
-{
-	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_post_focus_event\n");
-
-	return ds_client_post_focus_event(wnd->client, wnd);
-}
-
-/** Post unfocus event to window.
- *
- * @param wnd Window
- */
-errno_t ds_window_post_unfocus_event(ds_window_t *wnd)
-{
-	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_post_unfocus_event\n");
-
-	return ds_client_post_unfocus_event(wnd->client, wnd);
-}
-
-/** Start moving a window, detected by client.
- *
- * @param wnd Window
- * @param pos Position where the pointer was when the move started
- *            relative to the window
- * @param event Button press event
- */
-void ds_window_move_req(ds_window_t *wnd, gfx_coord2_t *pos)
-{
-	log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_move_req (%d, %d)",
-	    (int) pos->x, (int) pos->y);
-
-	if (wnd->state != dsw_idle)
-		return;
-
-	gfx_coord2_add(&wnd->dpos, pos, &wnd->orig_pos);
-	wnd->state = dsw_moving;
-}
-
-/** Start resizing a window, detected by client.
- *
- * @param wnd Window
- * @param rsztype Resize type (which part of window is being dragged)
- * @param pos Position where the pointer was when the resize started
- *            relative to the window
- * @param event Button press event
- */
-void ds_window_resize_req(ds_window_t *wnd, display_wnd_rsztype_t rsztype,
-    gfx_coord2_t *pos)
-{
-	log_msg(LOG_DEFAULT, LVL_NOTE, "ds_window_resize_req (%d, %d, %d)",
-	    (int) rsztype, (int) pos->x, (int) pos->y);
-
-	if (wnd->state != dsw_idle)
-		return;
-
-	gfx_coord2_add(&wnd->dpos, pos, &wnd->orig_pos);
-	wnd->state = dsw_resizing;
-	wnd->rsztype = rsztype;
-}
-
 /** Compute new window rectangle after resize operation.
  *
