diff --git a/ControllerHelper/ControllerHelper.cs b/ControllerHelper/ControllerHelper.cs index 98a3d17ba..7a93bda7c 100644 --- a/ControllerHelper/ControllerHelper.cs +++ b/ControllerHelper/ControllerHelper.cs @@ -242,7 +242,18 @@ public void UpdateStatus(bool status) }); } - + public void UpdateScreen() + { + PipeClient.SendMessage(new PipeMessage + { + Code = PipeCode.CLIENT_SIZE_DETAILS, + args = new Dictionary + { + { "Bounds.Width", Convert.ToString(Screen.PrimaryScreen.Bounds.Width) }, + { "Bounds.Height", Convert.ToString(Screen.PrimaryScreen.Bounds.Height) } + } + }); + } public void UpdateController(Dictionary args) { diff --git a/ControllerHelper/PipeClient.cs b/ControllerHelper/PipeClient.cs index 6ff6ba6e7..67c9918cd 100644 --- a/ControllerHelper/PipeClient.cs +++ b/ControllerHelper/PipeClient.cs @@ -68,6 +68,7 @@ private void OnServerMessage(NamedPipeConnection conne case PipeCode.SERVER_CONNECTED: connected = true; helper.UpdateStatus(true); + helper.UpdateScreen(); break; case PipeCode.SERVER_TOAST: diff --git a/ControllerService/ControllerService.cs b/ControllerService/ControllerService.cs index bd9807fda..5704b568f 100644 --- a/ControllerService/ControllerService.cs +++ b/ControllerService/ControllerService.cs @@ -171,86 +171,85 @@ public void UpdateSettings(Dictionary args) foreach(KeyValuePair pair in args) { string name = pair.Key; - string value = pair.Value; + string property = pair.Value; SettingsProperty setting = Properties.Settings.Default.Properties[name]; - - if (setting == null) - continue; - - object OldValue = Properties.Settings.Default[name].ToString(); - object NewValue; - - TypeCode typeCode = Type.GetTypeCode(setting.PropertyType); - switch (typeCode) + if (setting != null) { - case TypeCode.Boolean: - NewValue = bool.Parse(value); - OldValue = bool.Parse((string)OldValue); - break; - case TypeCode.Single: - case TypeCode.Decimal: - NewValue = float.Parse(value); - OldValue = float.Parse((string)OldValue); - break; - case TypeCode.Int16: - case TypeCode.Int32: - case TypeCode.Int64: - NewValue = int.Parse(value); - OldValue = int.Parse((string)OldValue); - break; - case TypeCode.UInt16: - case TypeCode.UInt32: - case TypeCode.UInt64: - NewValue = uint.Parse(value); - OldValue = uint.Parse((string)OldValue); - break; - default: - NewValue = value; - OldValue = (string)OldValue; - break; - } + object prev_value = Properties.Settings.Default[name].ToString(); + object value; - Properties.Settings.Default[name] = NewValue; - ApplySetting(name, OldValue, NewValue, typeCode); + TypeCode typeCode = Type.GetTypeCode(setting.PropertyType); + switch (typeCode) + { + case TypeCode.Boolean: + value = bool.Parse(property); + prev_value = bool.Parse((string)prev_value); + break; + case TypeCode.Single: + case TypeCode.Decimal: + value = float.Parse(property); + prev_value = float.Parse((string)prev_value); + break; + case TypeCode.Int16: + case TypeCode.Int32: + case TypeCode.Int64: + value = int.Parse(property); + prev_value = int.Parse((string)prev_value); + break; + case TypeCode.UInt16: + case TypeCode.UInt32: + case TypeCode.UInt64: + value = uint.Parse(property); + prev_value = uint.Parse((string)prev_value); + break; + default: + value = property; + prev_value = (string)prev_value; + break; + } + + Properties.Settings.Default[name] = value; + ApplySetting(name, prev_value, value); + } } Properties.Settings.Default.Save(); } - private void ApplySetting(string name, object OldValue, object NewValue, TypeCode typeCode) + private void ApplySetting(string name, object prev_value, object value) { - if (OldValue.ToString() != NewValue.ToString()) + if (prev_value.ToString() != value.ToString()) { - logger.LogInformation("{0} set to {1}", name, NewValue.ToString()); + logger.LogInformation("{0} set to {1}", name, value.ToString()); switch (name) { case "HIDcloaked": - Hidder.SetCloaking((bool)NewValue); - HIDcloaked = (bool)NewValue; + Hidder.SetCloaking((bool)value); + HIDcloaked = (bool)value; break; case "HIDuncloakonclose": - HIDuncloakonclose = (bool)NewValue; + HIDuncloakonclose = (bool)value; break; case "HIDmode": // todo break; case "HIDrate": - PhysicalController.SetPollRate((int)NewValue); + PhysicalController.SetPollRate((int)value); break; case "DSUEnabled": - switch((bool)NewValue) + switch((bool)value) { case true: DSUServer.Start(); break; case false: DSUServer.Stop(); break; } break; case "DSUip": - DSUServer.ip = (string)NewValue; + DSUServer.ip = (string)value; break; case "DSUport": - DSUServer.port = (int)NewValue; + DSUServer.port = (int)value; break; } } diff --git a/ControllerService/DS4Touch.cs b/ControllerService/DS4Touch.cs index 804c69418..0d8cbaee4 100644 --- a/ControllerService/DS4Touch.cs +++ b/ControllerService/DS4Touch.cs @@ -30,11 +30,11 @@ public struct TrackPadTouch private short TouchX, TouchY; public bool OutputClickButton; + private float BoundsWidth, BoundsHeight; + public DS4Touch() { - // get screen size - RatioWidth = (float)TOUCHPAD_WIDTH / (float)Screen.PrimaryScreen.Bounds.Width; - RatioHeight = (float)TOUCHPAD_HEIGHT / (float)Screen.PrimaryScreen.Bounds.Height; + UpdateRatio(TOUCHPAD_WIDTH, TOUCHPAD_HEIGHT); // default values TrackPadTouch0.RawTrackingNum = TOUCH0_ID + TOUCH_DISABLE; @@ -43,6 +43,15 @@ public DS4Touch() TouchPacketCounter++; } + public void UpdateRatio(float w, float h) + { + BoundsWidth = w; + BoundsHeight = h; + + RatioWidth = (float)TOUCHPAD_WIDTH / BoundsWidth; + RatioHeight = (float)TOUCHPAD_HEIGHT / BoundsHeight; + } + public void OnMouseUp(short X, short Y, int Button) { if (X != -1) TouchX = (short)(X * RatioWidth); diff --git a/ControllerService/PipeServer.cs b/ControllerService/PipeServer.cs index 3211aeabf..ad06a5d63 100644 --- a/ControllerService/PipeServer.cs +++ b/ControllerService/PipeServer.cs @@ -50,6 +50,9 @@ public enum PipeCode CLIENT_HIDDER_UNREG = 10, // Sent to server to unregister applications // args: ... + + CLIENT_SIZE_DETAILS = 11, // Sent to server to update screen details + // args: width, height } public class PipeServer @@ -157,6 +160,10 @@ private void OnClientMessage(NamedPipeConnection conne service.PhysicalController.touch.OnMouseMove(short.Parse(message.args["X"]), short.Parse(message.args["Y"]), int.Parse(message.args["Button"])); break; + case PipeCode.CLIENT_SIZE_DETAILS: + service.PhysicalController.touch.UpdateRatio(float.Parse(message.args["Bounds.Width"]), float.Parse(message.args["Bounds.Height"])); + break; + case PipeCode.CLIENT_SETTINGS: service.UpdateSettings(message.args); break;