Skip to content

Commit

Permalink
Macos fixes (#511) part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jul 31, 2023
1 parent 575f9c2 commit 5c10b2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
25 changes: 19 additions & 6 deletions Source/simba.ipc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ TSimbaIPCHeader = record
MessageID: Integer;
end;

TSimbaIPCInputStream = class(TInputPipeStream)
public
function Read(var Buffer; Count: Longint): LongInt; override;
end;

TSimbaIPCServer = class
protected
FInputClient: TOutputPipeStream;
FInputStream: TInputPipeStream;
FOutputClient: TInputPipeStream;
FInputStream: TSimbaIPCInputStream;
FOutputClient: TSimbaIPCInputStream;
FOutputStream: TOutputPipeStream;

FClientID: String;
Expand All @@ -46,7 +51,7 @@ TSimbaIPCServer = class

TSimbaIPCClient = class
protected
FInputStream: TInputPipeStream;
FInputStream: TSimbaIPCInputStream;
FOutputStream: TOutputPipeStream;
FLock: TCriticalSection;

Expand All @@ -67,6 +72,14 @@ implementation
uses
simba.mufasatypes, simba.threading;

function TSimbaIPCInputStream.Read(var Buffer; Count: Longint): longint;
begin
Result := 0;
repeat
Inc(Result, inherited Read(PByte(@Buffer)[Result], Count - Result));
until (Result = Count);
end;

procedure TSimbaIPCServer.Execute;
var
Params: TMemoryStream;
Expand Down Expand Up @@ -142,15 +155,15 @@ constructor TSimbaIPCServer.Create;
if (not CreatePipeHandles(InputHandle, OutputHandle, 4096)) then
raise Exception.Create('Unable to create input pipe');

FInputStream := TInputPipeStream.Create(InputHandle);
FInputStream := TSimbaIPCInputStream.Create(InputHandle);
FInputClient := TOutputPipeStream.Create(DuplicateHandle(OutputHandle));

// Output
if (not CreatePipeHandles(InputHandle, OutputHandle, 4096)) then
raise Exception.Create('Unable to create output pipe');

FOutputStream := TOutputPipeStream.Create(OutputHandle);
FOutputClient := TInputPipeStream.Create(DuplicateHandle(InputHandle));
FOutputClient := TSimbaIPCInputStream.Create(DuplicateHandle(InputHandle));

FClientID := IntToHex(FInputClient.Handle, 16) + IntToHex(FOutputClient.Handle, 16);
FThread := Threaded(@Execute);
Expand Down Expand Up @@ -233,7 +246,7 @@ constructor TSimbaIPCClient.Create(ServerID: String);
FLock := TCriticalSection.Create();

FOutputStream := TOutputPipeStream.Create(StrToInt('$' + Copy(ServerID, 1, 16)));
FInputStream := TInputPipeStream.Create(StrToInt('$' + Copy(ServerID, 16+1, 16)));
FInputStream := TSimbaIPCInputStream.Create(StrToInt('$' + Copy(ServerID, 16+1, 16)));

FParams := TMemoryStream.Create();
FResult := TMemoryStream.Create();
Expand Down
4 changes: 2 additions & 2 deletions Source/simba.nativeinterface_darwin.pas
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ function TSimbaNativeInterface_Darwin.GetWindowImage(Window: TWindowHandle; X, Y
R.Bottom := WindowBounds.Y1 + Y + Height;

if Window = GetDesktopWindow() then
Image := CGWindowListCreateImage(RectToCGRect(R), kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageBoundsIgnoreFraming)
Image := CGWindowListCreateImage(RectToCGRect(R), kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageBoundsIgnoreFraming or kCGWindowImageNominalResolution)
else
Image := CGWindowListCreateImage(RectToCGRect(R), kCGWindowListOptionIncludingWindow, Window, kCGWindowImageBoundsIgnoreFraming);
Image := CGWindowListCreateImage(RectToCGRect(R), kCGWindowListOptionIncludingWindow, Window, kCGWindowImageBoundsIgnoreFraming or kCGWindowImageNominalResolution);

Result := (Image <> nil) and (CGImageGetWidth(Image) = Width) and (CGImageGetHeight(Image) = Height);

Expand Down

0 comments on commit 5c10b2d

Please sign in to comment.