]> git.localhorst.tv Git - blank.git/blobdiff - src/client/client.cpp
better handling of focus and input
[blank.git] / src / client / client.cpp
index 08f62112f49e36ccbc18cd376a58fd17ca8645cf..f0a3f35c7b984825d2dcffbc4c529a8c0d9815cb 100644 (file)
@@ -80,8 +80,24 @@ InteractiveState::InteractiveState(MasterState &master, uint32_t player_id)
        }
 }
 
-void InteractiveState::OnEnter() {
-       master.GetEnv().window.GrabMouse();
+void InteractiveState::OnResume() {
+       OnFocus();
+}
+
+void InteractiveState::OnPause() {
+       OnBlur();
+}
+
+void InteractiveState::OnFocus() {
+       if (master.GetConfig().input.mouse) {
+               master.GetEnv().window.GrabMouse();
+       }
+       interface.Unlock();
+}
+
+void InteractiveState::OnBlur() {
+       master.GetEnv().window.ReleaseMouse();
+       interface.Lock();
 }
 
 void InteractiveState::Handle(const SDL_Event &event) {
@@ -323,7 +339,9 @@ void InteractiveState::Exit() {
 }
 
 void InteractiveState::OnLineSubmit(const string &line) {
-       master.GetClient().SendMessage(1, 0, line);
+       if (!line.empty()) {
+               master.GetClient().SendMessage(1, 0, line);
+       }
 }