about summary refs log tree commit diff
path: root/src/engine
diff options
context:
space:
mode:
authorJohan Althoff <teetow@gmail.com>2007-08-07 18:28:51 +0000
committerJohan Althoff <teetow@gmail.com>2007-08-07 18:28:51 +0000
commit0c7e1fc6abef36bf41504fcae730b361d515c606 (patch)
tree0fffb8bdf3af6bc301dce339dc07e65d98590dff /src/engine
parentf38f0f49d54f124ed385c609789bf834bbfde6cb (diff)
downloadzcatch-0c7e1fc6abef36bf41504fcae730b361d515c606.tar.gz
zcatch-0c7e1fc6abef36bf41504fcae730b361d515c606.zip
fixed window focusing stuff, much better now.
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/client/client.cpp37
-rw-r--r--src/engine/client/gfx.cpp5
-rw-r--r--src/engine/interface.h2
3 files changed, 38 insertions, 6 deletions
diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp
index 730aac6c..dc0a02d0 100644
--- a/src/engine/client/client.cpp
+++ b/src/engine/client/client.cpp
@@ -38,6 +38,7 @@ static net_client net;
 static netaddr4 master_server;
 static netaddr4 server_address;
 static const char *server_spam_address=0;
+static int window_must_refocus = 0;
 
 // --- input wrappers ---
 static int keyboard_state[2][input::last];
@@ -872,11 +873,30 @@ static void client_run(const char *direct_connect_server)
 		// update input
 		inp_update();
 		
-		//
-		if(input::pressed(input::f1))
-			input::set_mouse_mode(input::mode_absolute);
-		if(input::pressed(input::f2))
-			input::set_mouse_mode(input::mode_relative);
+		// refocus
+		if(!gfx_window_active())
+		{
+			if(window_must_refocus == 0)
+			{
+				input::set_mouse_mode(input::mode_absolute);
+			}
+			window_must_refocus = 1;
+		}
+
+		if(window_must_refocus && gfx_window_active())
+		{
+			if(window_must_refocus < 3)
+			{
+				input::set_mouse_mode(input::mode_absolute);
+				window_must_refocus++;
+			}
+
+			if(inp_button_pressed(input::mouse_1))
+			{
+				input::set_mouse_mode(input::mode_relative);
+				window_must_refocus = 0;
+			}
+		}
 
 		// screenshot button
 		if(inp_key_down(input::f10))
@@ -885,6 +905,11 @@ static void client_run(const char *direct_connect_server)
 		// panic button
 		if(config.debug)
 		{
+			if(input::pressed(input::f1))
+				input::set_mouse_mode(input::mode_absolute);
+			if(input::pressed(input::f2))
+				input::set_mouse_mode(input::mode_relative);
+
 			if(input::pressed(input::lctrl) && input::pressed('Q'))
 				break;
 		
@@ -915,7 +940,7 @@ static void client_run(const char *direct_connect_server)
 			break;
 
 		// be nice
-		if(config.cpu_throttle)
+		if(config.cpu_throttle || !gfx_window_active())
 			thread_sleep(1);
 		
 		if(reporttime < time_get())
diff --git a/src/engine/client/gfx.cpp b/src/engine/client/gfx.cpp
index 1e11bb04..1c871e28 100644
--- a/src/engine/client/gfx.cpp
+++ b/src/engine/client/gfx.cpp
@@ -213,6 +213,11 @@ bool gfx_init()
 }
 
 
+int gfx_window_active()
+{
+	return context.active()?1:0;
+}
+
 
 video_mode fakemodes[] = {
 	{320,240,8,8,8}, {400,300,8,8,8}, {640,480,8,8,8},
diff --git a/src/engine/interface.h b/src/engine/interface.h
index 7809d810..1f8a02b7 100644
--- a/src/engine/interface.h
+++ b/src/engine/interface.h
@@ -71,6 +71,8 @@ void gfx_swap(); // NOT EXPOSED
 int gfx_get_video_modes(video_mode *list, int maxcount);
 void gfx_set_vsync(int val);
 
+int gfx_window_active();
+
 // textures
 /*
 	Function: gfx_load_texture