Index: uspace/srv/hid/console/console.c
===================================================================
--- uspace/srv/hid/console/console.c	(revision ce3efa072661e7cca5ddc305768f65fce320e41c)
+++ uspace/srv/hid/console/console.c	(revision 8e7c9fe2061521836dfdd71c2a3c2786b6fefa3e)
@@ -41,5 +41,4 @@
 #include <str_error.h>
 #include <loc.h>
-#include <event.h>
 #include <io/con_srv.h>
 #include <io/kbd_event.h>
@@ -84,4 +83,5 @@
 /** Input server proxy */
 static input_t *input;
+static bool active = false;
 
 /** Session to the output server */
@@ -98,8 +98,8 @@
 static FIBRIL_MUTEX_INITIALIZE(switch_mtx);
 
-static console_t *prev_console = &consoles[0];
 static console_t *active_console = &consoles[0];
-static console_t *kernel_console = &consoles[KERNEL_CONSOLE];
-
+
+static int input_ev_active(input_t *);
+static int input_ev_deactive(input_t *);
 static int input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t);
 static int input_ev_move(input_t *, int, int);
@@ -108,4 +108,6 @@
 
 static input_ev_ops_t input_ev_ops = {
+	.active = input_ev_active,
+	.deactive = input_ev_deactive,
 	.key = input_ev_key,
 	.move = input_ev_move,
@@ -159,5 +161,5 @@
 	fibril_mutex_lock(&cons->mtx);
 	
-	if ((cons == active_console) && (active_console != kernel_console)) {
+	if ((active) && (cons == active_console)) {
 		output_update(output_sess, cons->fbid);
 		output_cursor_update(output_sess, cons->fbid);
@@ -173,5 +175,5 @@
 	fibril_mutex_lock(&cons->mtx);
 	
-	if ((cons == active_console) && (active_console != kernel_console))
+	if ((active) && (cons == active_console))
 		output_cursor_update(output_sess, cons->fbid);
 	
@@ -185,5 +187,5 @@
 	fibril_mutex_lock(&cons->mtx);
 	
-	if ((cons == active_console) && (active_console != kernel_console)) {
+	if ((active) && (cons == active_console)) {
 		output_damage(output_sess, cons->fbid, 0, 0, cons->cols,
 		    cons->rows);
@@ -195,6 +197,22 @@
 }
 
-static void cons_switch(console_t *cons)
-{
+static void cons_switch(unsigned int index)
+{
+	/*
+	 * The first undefined index is reserved
+	 * for switching to the kernel console.
+	 */
+	if (index == CONSOLE_COUNT) {
+		if (console_kcon())
+			active = false;
+		
+		return;
+	}
+	
+	if (index > CONSOLE_COUNT)
+		return;
+	
+	console_t *cons = &consoles[index];
+	
 	fibril_mutex_lock(&switch_mtx);
 	
@@ -204,17 +222,4 @@
 	}
 	
-	if (cons == kernel_console) {
-		output_yield(output_sess);
-		if (!console_kcon()) {
-			output_claim(output_sess);
-			fibril_mutex_unlock(&switch_mtx);
-			return;
-		}
-	}
-	
-	if (active_console == kernel_console)
-		output_claim(output_sess);
-	
-	prev_console = active_console;
 	active_console = cons;
 	
@@ -224,17 +229,19 @@
 }
 
-static console_t *cons_get_active_uspace(void)
-{
-	fibril_mutex_lock(&switch_mtx);
-	
-	console_t *active_uspace = active_console;
-	if (active_uspace == kernel_console)
-		active_uspace = prev_console;
-	
-	assert(active_uspace != kernel_console);
-	
-	fibril_mutex_unlock(&switch_mtx);
-	
-	return active_uspace;
+static int input_ev_active(input_t *input)
+{
+	active = true;
+	output_claim(output_sess);
+	cons_damage(active_console);
+	
+	return EOK;
+}
+
+static int input_ev_deactive(input_t *input)
+{
+	active = false;
+	output_yield(output_sess);
+	
+	return EOK;
 }
 
@@ -242,7 +249,7 @@
     keymod_t mods, wchar_t c)
 {
-	if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) &&
+	if ((key >= KC_F1) && (key <= KC_F1 + CONSOLE_COUNT) &&
 	    ((mods & KM_CTRL) == 0)) {
-		cons_switch(&consoles[key - KC_F1]);
+		cons_switch(key - KC_F1);
 	} else {
 		/* Got key press/release event */
@@ -259,13 +266,5 @@
 		event->c = c;
 		
-		/*
-		 * Kernel console does not read events
-		 * from us, so we will redirect them
-		 * to the (last) active userspace console
-		 * if necessary.
-		 */
-		console_t *target_console = cons_get_active_uspace();
-		
-		prodcons_produce(&target_console->input_pc,
+		prodcons_produce(&active_console->input_pc,
 		    &event->link);
 	}
@@ -509,7 +508,4 @@
 	
 	for (size_t i = 0; i < CONSOLE_COUNT; i++) {
-		if (i == KERNEL_CONSOLE)
-			continue;
-		
 		if (consoles[i].dsid == (service_id_t) IPC_GET_ARG1(*icall)) {
 			cons = &consoles[i];
@@ -556,9 +552,4 @@
 	
 	return EOK;
-}
-
-static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
-{
-	cons_switch(prev_console);
 }
 
@@ -609,54 +600,49 @@
 	output_get_caps(output_sess, &ccaps);
 	
-	/* Inititalize consoles */
-	for (size_t i = 0; i < CONSOLE_COUNT; i++) {
-		consoles[i].index = i;
-		atomic_set(&consoles[i].refcnt, 0);
-		fibril_mutex_initialize(&consoles[i].mtx);
-		prodcons_initialize(&consoles[i].input_pc);
-		consoles[i].char_remains_len = 0;
-		
-		if (i == KERNEL_CONSOLE)
-			continue;
-		
-		consoles[i].cols = cols;
-		consoles[i].rows = rows;
-		consoles[i].ccaps = ccaps;
-		consoles[i].frontbuf =
-		    chargrid_create(cols, rows, CHARGRID_FLAG_SHARED);
-		
-		if (consoles[i].frontbuf == NULL) {
-			printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i);
-			return false;
+	/*
+	 * Inititalize consoles only if there are
+	 * actually some output devices.
+	 */
+	if (ccaps != 0) {
+		for (size_t i = 0; i < CONSOLE_COUNT; i++) {
+			consoles[i].index = i;
+			atomic_set(&consoles[i].refcnt, 0);
+			fibril_mutex_initialize(&consoles[i].mtx);
+			prodcons_initialize(&consoles[i].input_pc);
+			consoles[i].char_remains_len = 0;
+			
+			consoles[i].cols = cols;
+			consoles[i].rows = rows;
+			consoles[i].ccaps = ccaps;
+			consoles[i].frontbuf =
+			    chargrid_create(cols, rows, CHARGRID_FLAG_SHARED);
+			
+			if (consoles[i].frontbuf == NULL) {
+				printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i);
+				return false;
+			}
+			
+			consoles[i].fbid = output_frontbuf_create(output_sess,
+			    consoles[i].frontbuf);
+			if (consoles[i].fbid == 0) {
+				printf("%s: Unable to create frontbuffer %zu\n", NAME, i);
+				return false;
+			}
+			
+			con_srvs_init(&consoles[i].srvs);
+			consoles[i].srvs.ops = &con_ops;
+			consoles[i].srvs.sarg = &consoles[i];
+			
+			char vc[LOC_NAME_MAXLEN + 1];
+			snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
+			
+			if (loc_service_register(vc, &consoles[i].dsid) != EOK) {
+				printf("%s: Unable to register device %s\n", NAME, vc);
+				return false;
+			}
 		}
 		
-		consoles[i].fbid = output_frontbuf_create(output_sess,
-		    consoles[i].frontbuf);
-		if (consoles[i].fbid == 0) {
-			printf("%s: Unable to create frontbuffer %zu\n", NAME, i);
-			return false;
-		}
-		
-		con_srvs_init(&consoles[i].srvs);
-		consoles[i].srvs.ops = &con_ops;
-		consoles[i].srvs.sarg = &consoles[i];
-		
-		char vc[LOC_NAME_MAXLEN + 1];
-		snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
-		
-		if (loc_service_register(vc, &consoles[i].dsid) != EOK) {
-			printf("%s: Unable to register device %s\n", NAME, vc);
-			return false;
-		}
-	}
-	
-	cons_damage(active_console);
-	
-	/* Receive kernel notifications */
-	async_set_interrupt_received(interrupt_received);
-	rc = event_subscribe(EVENT_KCONSOLE, 0);
-	if (rc != EOK)
-		printf("%s: Failed to register kconsole notifications (%s)\n",
-		    NAME, str_error(rc));
+		input_activate(input);
+	}
 	
 	return true;
