shithub: qk1

Download patch

ref: 8f12e13c9d1485183666c71eeab428066f0077b6
parent: ee0395513ea7be03d7dc8aae4c0b4bfbb59c0427
author: Konstantinn Bonnet <[email protected]>
date: Mon Jul 13 09:27:44 EDT 2015

grab/ungrab mouse according to menu or console access

ungrab mouse when entering menu or console. grab it again when exiting menu or
console and/or spawning a new server.

--- a/console.c
+++ b/console.c
@@ -37,30 +37,24 @@
 
 extern void M_Menu_Main_f (void);
 
-/*
-================
-Con_ToggleConsole_f
-================
-*/
-void Con_ToggleConsole_f (void)
+
+void
+Con_ToggleConsole_f(void)
 {
-	if (key_dest == key_console)
-	{
-		if (cls.state == ca_connected)
-		{
+	if(key_dest == key_console){
+		if(cls.state == ca_connected){
 			key_dest = key_game;
 			key_lines[edit_line][1] = 0;	// clear any typing
 			key_linepos = 1;
-		}
-		else
-		{
-			M_Menu_Main_f ();
-		}
-	}
-	else
+			IN_Grabm(1);
+		}else
+			M_Menu_Main_f();
+	}else{
 		key_dest = key_console;
-	
-	SCR_EndLoadingPlaque ();
+		IN_Grabm(0);
+	}
+
+	SCR_EndLoadingPlaque();
 	memset(con_times, 0, sizeof con_times);
 }
 
--- a/menu.c
+++ b/menu.c
@@ -217,21 +217,14 @@
 
 int m_save_demonum;
 
-/*
-================
-M_ToggleMenu_f
-================
-*/
-void M_ToggleMenu_f (void)
+void
+M_ToggleMenu_f(void)
 {
 	m_entersound = true;
 
-	IN_Grabm(0);
-	if (key_dest == key_menu)
-	{
-		if (m_state != m_main)
-		{
-			M_Menu_Main_f ();
+	if(key_dest == key_menu){
+		if(m_state != m_main){
+			M_Menu_Main_f();
 			return;
 		}
 		key_dest = key_game;
@@ -238,14 +231,12 @@
 		m_state = m_none;
 		return;
 	}
-	if (key_dest == key_console)
-	{
-		Con_ToggleConsole_f ();
+	if(key_dest == key_console)
+		Con_ToggleConsole_f();
+	else{
+		IN_Grabm(0);
+		M_Menu_Main_f();
 	}
-	else
-	{
-		M_Menu_Main_f ();
-	}
 }
 
 
@@ -293,9 +284,10 @@
 		key_dest = key_game;
 		m_state = m_none;
 		cls.demonum = m_save_demonum;
-		if (cls.demonum != -1 && !cls.demoplayback && cls.state != ca_connected)
-			CL_NextDemo ();
-		IN_Grabm(1);
+		if(cls.state != ca_connected && !cls.demoplayback && cls.demonum != -1)
+			CL_NextDemo();
+		if(cls.state == ca_connected || cls.demoplayback)
+			IN_Grabm(1);
 		break;
 
 	case K_DOWNARROW:
@@ -403,7 +395,6 @@
 				Cbuf_AddText ("disconnect\n");
 			Cbuf_AddText ("maxplayers 1\n");
 			Cbuf_AddText ("map start\n");
-			IN_Grabm(1);
 			break;
 
 		case 1:
@@ -531,7 +522,6 @@
 
 	// issue the load command
 		Cbuf_AddText (va ("load s%d\n", load_cursor) );
-		IN_Grabm(1);
 		return;
 
 	case K_UPARROW:
@@ -3025,85 +3015,66 @@
 	VID_LockBuffer ();
 }
 
-
-void M_Keydown (int key)
+void
+M_Keydown(int key)
 {
-	switch (m_state)
-	{
+	switch(m_state){
 	case m_none:
 		return;
-
 	case m_main:
-		M_Main_Key (key);
-		return;
-
+		M_Main_Key(key);
+		break;
 	case m_singleplayer:
-		M_SinglePlayer_Key (key);
-		return;
-
+		M_SinglePlayer_Key(key);
+		break;
 	case m_load:
-		M_Load_Key (key);
-		return;
-
+		M_Load_Key(key);
+		break;
 	case m_save:
-		M_Save_Key (key);
-		return;
-
+		M_Save_Key(key);
+		break;
 	case m_multiplayer:
-		M_MultiPlayer_Key (key);
-		return;
-
+		M_MultiPlayer_Key(key);
+		break;
 	case m_setup:
-		M_Setup_Key (key);
-		return;
-
+		M_Setup_Key(key);
+		break;
 	case m_net:
-		M_Net_Key (key);
-		return;
-
+		M_Net_Key(key);
+		break;
 	case m_options:
-		M_Options_Key (key);
-		return;
-
+		M_Options_Key(key);
+		break;
 	case m_keys:
-		M_Keys_Key (key);
-		return;
-
+		M_Keys_Key(key);
+		break;
 	case m_video:
-		M_Video_Key (key);
-		return;
-
+		M_Video_Key(key);
+		break;
 	case m_help:
-		M_Help_Key (key);
-		return;
-
+		M_Help_Key(key);
+		break;
 	case m_quit:
-		M_Quit_Key (key);
-		return;
-
+		M_Quit_Key(key);
+		break;
 	case m_serialconfig:
-		M_SerialConfig_Key (key);
-		return;
-
+		M_SerialConfig_Key(key);
+		break;
 	case m_modemconfig:
-		M_ModemConfig_Key (key);
-		return;
-
+		M_ModemConfig_Key(key);
+		break;
 	case m_lanconfig:
-		M_LanConfig_Key (key);
-		return;
-
+		M_LanConfig_Key(key);
+		break;
 	case m_gameoptions:
-		M_GameOptions_Key (key);
-		return;
-
+		M_GameOptions_Key(key);
+		break;
 	case m_search:
-		M_Search_Key (key);
+		M_Search_Key(key);
 		break;
-
 	case m_slist:
-		M_ServerList_Key (key);
-		return;
+		M_ServerList_Key(key);
+		break;
 	}
 }
 
--- a/sv_main.c
+++ b/sv_main.c
@@ -1150,7 +1150,8 @@
 	for (i=0,host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
 		if (host_client->active)
 			SV_SendServerinfo (host_client);
-	
+
+	IN_Grabm(1);
 	Con_DPrintf ("Server spawned.\n");
 }