Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
Added the ability to set the screen orientation and allow for the set…
Browse files Browse the repository at this point in the history
…ting of the primary screen. All thats left is to add the ability to rearrange the screens.
  • Loading branch information
Andrew Sampson committed Dec 12, 2016
1 parent a8e32cb commit 44cfd17
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class ResolutionInformation
public int Height { get; set; }
public int BitsPerPixel { get; set; }
public int Frequency { get; set; }
public string Orientation { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#region

using System;
using System.Linq;
using System.Management;
using UlteriusServer.Api.Network.Messages;
using UlteriusServer.Api.Network.Models;
using UlteriusServer.Api.Services.LocalSystem;
using UlteriusServer.Api.Win32;
using UlteriusServer.WebSocketAPI.Authentication;
using vtortola.WebSockets;

#endregion

namespace UlteriusServer.Api.Network.PacketHandlers
{
public class DisplayPacketHandler : PacketHandler
{
private MessageBuilder _builder;
private AuthClient _authClient;
private Packet _packet;
private WebSocket _client;



public override void HandlePacket(Packet packet)
{
_client = packet.Client;
_authClient = packet.AuthClient;
_packet = packet;
_builder = new MessageBuilder(_authClient, _client, _packet.EndPoint, _packet.SyncKey);
switch (_packet.PacketType)
{
case PacketManager.PacketTypes.ChangeDisplayResolution:
ChangeScreenResolution();
break;
case PacketManager.PacketTypes.RotateDisplay:
RotateDisplay();
break;
case PacketManager.PacketTypes.SetPrimaryDisplay:
SetPrimaryDisplay();
break;
case PacketManager.PacketTypes.GetEventLogs:
// GetEventLogs();
break;
}
}

private void SetPrimaryDisplay()
{
var device = _packet.Args[0].ToString();
var message = Display.SetPrimary(device);
var formThread = new
{
message
};
_builder.WriteMessage(formThread);
}

private void RotateDisplay()
{
var width = int.Parse(_packet.Args[0].ToString());
var height = int.Parse(_packet.Args[1].ToString());
var angle = int.Parse(_packet.Args[2].ToString());
var device = _packet.Args[3].ToString();
var message = Display.Rotate(angle, width, height, device);
var formThread = new
{
message
};
_builder.WriteMessage(formThread);
}

private void ChangeScreenResolution()
{

var width = int.Parse(_packet.Args[0].ToString());
var height = int.Parse(_packet.Args[1].ToString());
var bbp = int.Parse(_packet.Args[2].ToString());
var freq = int.Parse(_packet.Args[3].ToString());
var device = _packet.Args[4].ToString();
var message = Display.ChangeResolution(device, width, height, bbp, freq);
var formThread = new
{
message
};
_builder.WriteMessage(formThread);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,65 +44,12 @@ public override void HandlePacket(Packet packet)
case PacketManager.PacketTypes.RequestOsInformation:
GetOperatingSystemInformation();
break;
case PacketManager.PacketTypes.ChangeScreenResolution:
ChangeScreenResolution();
break;

case PacketManager.PacketTypes.GetEventLogs:
// GetEventLogs();
break;
}
}

private void ChangeScreenResolution()
{

var width = int.Parse(_packet.Args[0].ToString());
var height = int.Parse(_packet.Args[1].ToString());
var bbp = int.Parse(_packet.Args[2].ToString());
var freq = int.Parse(_packet.Args[3].ToString());
var device = _packet.Args[4].ToString();


Console.WriteLine(device);
var code = Display.ChangeResolution(device, width, height, bbp, freq);
string message = string.Empty;
switch (code)
{
case Display.DISP_CHANGE.Successful:
message = "Resolution updated.";
break;
case Display.DISP_CHANGE.Restart:
message = "A restart is required for this resolution to take effect.";
break;

case Display.DISP_CHANGE.BadMode:
message = $"{width}x{height}x{bbp}x{freq} is not a supported resolution";
break;
case Display.DISP_CHANGE.BadDualView:
message = "The settings change was unsuccessful because system is DualView capable.";
break;
case Display.DISP_CHANGE.BadFlags:
message = "An invalid set of flags was passed in.";
break;
case Display.DISP_CHANGE.BadParam:
message = "An invalid parameter was passed in. This can include an invalid flag or combination of flags.";
break;
case Display.DISP_CHANGE.Failed:
message = "Resolution failed to update.";
break;
case Display.DISP_CHANGE.NotUpdated:
message = "Unable to write settings to the registry.";
break;
default:
message = "Unknown return value from ChangeDisplaySettings API.";
break;
}
var formThread = new
{
message,
responseCode = code,
};
_builder.WriteMessage(formThread);
}
}
}
10 changes: 8 additions & 2 deletions RemoteTaskServer/Api/Network/PacketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public enum PacketTypes
CtrlAltDel,
RightDown,
RightUp,
ChangeScreenResolution
ChangeDisplayResolution,
RotateDisplay,
SetPrimaryDisplay
}

#endregion
Expand Down Expand Up @@ -183,7 +185,11 @@ public PacketInfo GetPacketInfo(string endpoint)
case "requestgpuinformation":
return new PacketInfo {Type = PacketTypes.RequestGpuInformation, Handler = typeof(GpuPacketHandler)};
case "changescreenresolution":
return new PacketInfo { Type = PacketTypes.ChangeScreenResolution, Handler = typeof(OperatingSystemPacketHandler) };
return new PacketInfo { Type = PacketTypes.ChangeDisplayResolution, Handler = typeof(DisplayPacketHandler) };
case "rotatedisplay":
return new PacketInfo { Type = PacketTypes.RotateDisplay, Handler = typeof(DisplayPacketHandler) };
case "setprimarydisplay":
return new PacketInfo { Type = PacketTypes.SetPrimaryDisplay, Handler = typeof(DisplayPacketHandler) };
case "createfiletree":
return new PacketInfo {Type = PacketTypes.CreateFileTree, Handler = typeof(FilePacketHandler)};
case "requestprocessinformation":
Expand Down
Loading

0 comments on commit 44cfd17

Please sign in to comment.