Skip to content

Commit

Permalink
fix dpi awareness issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Nov 25, 2021
1 parent 2f0b0ef commit 878f115
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 52 deletions.
13 changes: 12 additions & 1 deletion ControllerHelper/ControllerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,18 @@ public void UpdateStatus(bool status)
});
}


public void UpdateScreen()
{
PipeClient.SendMessage(new PipeMessage
{
Code = PipeCode.CLIENT_SIZE_DETAILS,
args = new Dictionary<string, string>
{
{ "Bounds.Width", Convert.ToString(Screen.PrimaryScreen.Bounds.Width) },
{ "Bounds.Height", Convert.ToString(Screen.PrimaryScreen.Bounds.Height) }
}
});
}

public void UpdateController(Dictionary<string, string> args)
{
Expand Down
1 change: 1 addition & 0 deletions ControllerHelper/PipeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private void OnServerMessage(NamedPipeConnection<PipeMessage, PipeMessage> conne
case PipeCode.SERVER_CONNECTED:
connected = true;
helper.UpdateStatus(true);
helper.UpdateScreen();
break;

case PipeCode.SERVER_TOAST:
Expand Down
95 changes: 47 additions & 48 deletions ControllerService/ControllerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,86 +171,85 @@ public void UpdateSettings(Dictionary<string, string> args)
foreach(KeyValuePair<string, string> 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;
}
}
Expand Down
15 changes: 12 additions & 3 deletions ControllerService/DS4Touch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions ControllerService/PipeServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -157,6 +160,10 @@ private void OnClientMessage(NamedPipeConnection<PipeMessage, PipeMessage> 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;
Expand Down

0 comments on commit 878f115

Please sign in to comment.