Index: uspace/srv/hid/console/gcons.c
===================================================================
--- uspace/srv/hid/console/gcons.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
+++ uspace/srv/hid/console/gcons.c	(revision f4f866c362e11c16ac8b6212e491af00b0bed2f2)
@@ -54,5 +54,30 @@
 #define STATUS_HEIGHT  48
 
-#define MAIN_COLOR  0xffffff
+#define COLOR_MAIN        0xffffff
+#define COLOR_FOREGROUND  0x202020
+#define COLOR_BACKGROUND  0xffffff
+
+extern char _binary_gfx_helenos_ppm_start[0];
+extern int _binary_gfx_helenos_ppm_size;
+extern char _binary_gfx_nameic_ppm_start[0];
+extern int _binary_gfx_nameic_ppm_size;
+
+extern char _binary_gfx_anim_1_ppm_start[0];
+extern int _binary_gfx_anim_1_ppm_size;
+extern char _binary_gfx_anim_2_ppm_start[0];
+extern int _binary_gfx_anim_2_ppm_size;
+extern char _binary_gfx_anim_3_ppm_start[0];
+extern int _binary_gfx_anim_3_ppm_size;
+extern char _binary_gfx_anim_4_ppm_start[0];
+extern int _binary_gfx_anim_4_ppm_size;
+
+extern char _binary_gfx_cons_selected_ppm_start[0];
+extern int _binary_gfx_cons_selected_ppm_size;
+extern char _binary_gfx_cons_idle_ppm_start[0];
+extern int _binary_gfx_cons_idle_ppm_size;
+extern char _binary_gfx_cons_has_data_ppm_start[0];
+extern int _binary_gfx_cons_has_data_ppm_size;
+extern char _binary_gfx_cons_kernel_ppm_start[0];
+extern int _binary_gfx_cons_kernel_ppm_size;
 
 static bool use_gcons = false;
@@ -82,10 +107,10 @@
 static size_t active_console = 0;
 
-size_t mouse_x;
-size_t mouse_y;
-
-bool btn_pressed;
-size_t btn_x;
-size_t btn_y;
+static ipcarg_t mouse_x = 0;
+static ipcarg_t mouse_y= 0;
+
+static bool btn_pressed = false;
+static ipcarg_t btn_x = 0;
+static ipcarg_t btn_y = 0;
 
 static void vp_switch(int vp)
@@ -95,5 +120,5 @@
 
 /** Create view port */
-static int vp_create(size_t x, size_t y, size_t width, size_t height)
+static int vp_create(ipcarg_t x, ipcarg_t y, ipcarg_t width, ipcarg_t height)
 {
 	return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
@@ -112,5 +137,5 @@
 
 /** Transparent putchar */
-static void tran_putch(wchar_t ch, size_t col, size_t row)
+static void tran_putch(wchar_t ch, ipcarg_t col, ipcarg_t row)
 {
 	async_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
@@ -259,14 +284,17 @@
 void gcons_mouse_move(ssize_t dx, ssize_t dy)
 {
-	mouse_x = limit(mouse_x + dx, 0, xres);
-	mouse_y = limit(mouse_y + dy, 0, yres);
-
+	ssize_t nx = (ssize_t) mouse_x + dx;
+	ssize_t ny = (ssize_t) mouse_y + dy;
+	
+	mouse_x = (size_t) limit(nx, 0, xres);
+	mouse_y = (size_t) limit(ny, 0, yres);
+	
 	if (active_console != KERNEL_CONSOLE)
 		async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
 }
 
-static int gcons_find_conbut(int x, int y)
-{
-	int status_start = STATUS_START + (xres - 800) / 2;
+static int gcons_find_conbut(ipcarg_t x, ipcarg_t y)
+{
+	ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
 	
 	if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
@@ -278,8 +306,14 @@
 	if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
 		return -1;
+	
 	if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
 		return -1;
 	
-	return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
+	ipcarg_t btn = (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
+	
+	if (btn < CONSOLE_COUNT)
+		return btn;
+	
+	return -1;
 }
 
@@ -287,11 +321,15 @@
  *
  * @param state New state (true - pressed, false - depressed)
+ *
  */
 int gcons_mouse_btn(bool state)
 {
-	int conbut;
+	/* Ignore mouse clicks if no buttons
+	   are drawn at all */
+	if (xres < 800)
+		return -1;
 	
 	if (state) {
-		conbut = gcons_find_conbut(mouse_x, mouse_y);
+		int conbut = gcons_find_conbut(mouse_x, mouse_y);
 		if (conbut != -1) {
 			btn_pressed = true;
@@ -307,5 +345,5 @@
 	btn_pressed = false;
 	
-	conbut = gcons_find_conbut(mouse_x, mouse_y);
+	int conbut = gcons_find_conbut(mouse_x, mouse_y);
 	if (conbut == gcons_find_conbut(btn_x, btn_y))
 		return conbut;
@@ -313,5 +351,4 @@
 	return -1;
 }
-
 
 /** Draw a PPM pixmap to framebuffer
@@ -321,12 +358,10 @@
  * @param x Coordinate of upper left corner
  * @param y Coordinate of upper left corner
- */
-static void draw_pixmap(char *logo, size_t size, int x, int y)
-{
-	char *shm;
-	int rc;
-	
+ *
+ */
+static void draw_pixmap(char *logo, size_t size, ipcarg_t x, ipcarg_t y)
+{
 	/* Create area */
-	shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
+	char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
 	    MAP_ANONYMOUS, 0, 0);
 	if (shm == MAP_FAILED)
@@ -336,5 +371,5 @@
 	
 	/* Send area */
-	rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
+	int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
 	if (rc)
 		goto exit;
@@ -356,19 +391,12 @@
 }
 
-extern char _binary_gfx_helenos_ppm_start[0];
-extern int _binary_gfx_helenos_ppm_size;
-extern char _binary_gfx_nameic_ppm_start[0];
-extern int _binary_gfx_nameic_ppm_size;
-
 /** Redraws console graphics */
 void gcons_redraw_console(void)
 {
-	int i;
-	
 	if (!use_gcons)
 		return;
 	
 	vp_switch(0);
-	set_rgb_color(MAIN_COLOR, MAIN_COLOR);
+	set_rgb_color(COLOR_MAIN, COLOR_MAIN);
 	clear();
 	draw_pixmap(_binary_gfx_helenos_ppm_start,
@@ -377,4 +405,5 @@
 	    (size_t) &_binary_gfx_nameic_ppm_size, 5, 17);
 	
+	unsigned int i;
 	for (i = 0; i < CONSOLE_COUNT; i++)
 		redraw_state(i);
@@ -393,10 +422,6 @@
 static int make_pixmap(char *data, size_t size)
 {
-	char *shm;
-	int rc;
-	int pxid = -1;
-	
 	/* Create area */
-	shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
+	char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
 	    MAP_ANONYMOUS, 0, 0);
 	if (shm == MAP_FAILED)
@@ -405,6 +430,8 @@
 	memcpy(shm, data, size);
 	
+	int pxid = -1;
+	
 	/* Send area */
-	rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
+	int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
 	if (rc)
 		goto exit;
@@ -432,16 +459,8 @@
 }
 
-extern char _binary_gfx_anim_1_ppm_start[0];
-extern int _binary_gfx_anim_1_ppm_size;
-extern char _binary_gfx_anim_2_ppm_start[0];
-extern int _binary_gfx_anim_2_ppm_size;
-extern char _binary_gfx_anim_3_ppm_start[0];
-extern int _binary_gfx_anim_3_ppm_size;
-extern char _binary_gfx_anim_4_ppm_start[0];
-extern int _binary_gfx_anim_4_ppm_size;
-
 static void make_anim(void)
 {
-	int an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
+	int an = async_req_1_0(fbphone, FB_ANIM_CREATE,
+	    cstatus_vp[KERNEL_CONSOLE]);
 	if (an < 0)
 		return;
@@ -467,13 +486,4 @@
 	animation = an;
 }
-
-extern char _binary_gfx_cons_selected_ppm_start[0];
-extern int _binary_gfx_cons_selected_ppm_size;
-extern char _binary_gfx_cons_idle_ppm_start[0];
-extern int _binary_gfx_cons_idle_ppm_size;
-extern char _binary_gfx_cons_has_data_ppm_start[0];
-extern int _binary_gfx_cons_has_data_ppm_size;
-extern char _binary_gfx_cons_kernel_ppm_start[0];
-extern int _binary_gfx_cons_kernel_ppm_size;
 
 /** Initialize nice graphical console environment */
@@ -500,5 +510,5 @@
 	
 	/* Create status buttons */
-	size_t status_start = STATUS_START + (xres - 800) / 2;
+	ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
 	size_t i;
 	for (i = 0; i < CONSOLE_COUNT; i++) {
@@ -511,5 +521,5 @@
 		
 		vp_switch(cstatus_vp[i]);
-		set_rgb_color(0x202020, 0xffffff);
+		set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND);
 	}
 	
