Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Lazarus Pascal - macOS - Hide title bar

7 Posts
2 Users
2 Reactions
517 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2728
Topic starter  

Quick and simple way to hide a title bar in Cocoa:

unit Unit1;

{$mode objfpc}{$H+}
{$modeswitch objectivec1}
interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, CocoaAll;

type

  { TForm1 }

  TForm1 = class(TForm)
    procedure FormPaint(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormPaint(Sender: TObject);
var
  MyNSWindow :NSWindow;
begin
  MyNSWindow := NSView(Self.Handle).window; 
  MyNSWindow.setBackgroundColor( NSColor.orangeColor ); // just to demo the effect
  MyNSWindow.setTitlebarAppearsTransparent(true);       // titlebar transparent
  MyNSWindow.setTitleVisibility( NSWindowTitleHidden);  // titlebar hidden
end;

end.

 Regular title bar:

Setting titlebar to transparent, so its color is the same as the window background color:

setTitlebarAppearsTransparent(true);

Setting the titlebar to hidden, which basically hides the caption:

setTitleVisibility( NSWindowTitleHidden);

 

 Anyhoo -- hope this is useful to someone 😁 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Hans, when I run this code I get a basic window, no background color, no changes to title bar. Guess I must be missing something or maybe a version issue.  Lazarus 3.99 with FPC 3.2.2 on 12.7.3. (x64) - any ideas ?


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2728
Topic starter  

I'm as baffled as you are - just rebuild Lazarus from trunk the other day, Lazarus 3.99 (rev main_3_99-1568-gf82869efd6) FPC 3.3.1 aarch64-darwin-cocoa, and it now no longer works on my setup either 😞  -- The demo screenshots were made with my own code.

Had to go Google this and this code seems to work (found it in this Lazarus Forum post):

unit Unit1;

{$mode objfpc}{$H+}
{$modeswitch objectivec1}
interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, CocoaAll;

type

  { TForm1 }

  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);
  private

  public

  end;

const
  NSWindowTitleVisible = 0;
  NSWindowTitleHidden = 1;

type
  NSWindowTitleVisibility = NSInteger;

  NSWindowGlam = objccategory external (NSWindow)
    function titleVisibility: NSWindowTitleVisibility; message 'titleVisibility';
    procedure setTitleVisibility(AVisibility: NSWindowTitleVisibility); message 'setTitleVisibility:';
    function titlebarAppearsTransparent: Boolean; message 'titlebarAppearsTransparent';
    procedure setTitlebarAppearsTransparent(AFlag: Boolean); message 'setTitlebarAppearsTransparent:';
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormShow(Sender: TObject);
var
  MyNSWindow :NSWindow;
begin
  MyNSWindow := NSView(Self.Handle).window;

  MyNSWindow.setBackgroundColor( NSColor.orangeColor ); // just to demo the effect
  MyNSWindow.setTitlebarAppearsTransparent(true);       // titlebar transparent
  MyNSWindow.setTitleVisibility( NSWindowTitleHidden);  // titlebar hidden
end;

end.

Hope this helps 😊 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Thanks, I can't get either of these to run, but also trunk install fails on my machine, so not the same versions as you are running. The main thing I wante d to do was remove the Icon in the title bas and I've found that the following code does that:

 

  {$ifdef LCLCocoa}
  CocoaConfig.CocoaIconUse:=true;
  {$endif}  

   
Hans reacted
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2728
Topic starter  

This mornin, trunk fails to install on my machines as well. For some reason, whatever branch I pick, it keeps failing to build Lazarus (on my M1 and on my Intel Mac).

Anyhoo .... neat find!!
I actually do that with the plist ( yourapplication.app/Contents/Info.plist ), using LSUIElement.
But I can see you method to be quite useful as well 👍 

   <key>LSUIElement</key>
   <string>1</string>

(this prevents the icon from showing in the Dock)


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2728
Topic starter  

p.s. managed to build trunk again this morning.

In case you do not use it yet: check out FPCUpDeluxe - makes building from trunk (and other versions) a lot easier. 😊 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Yes I do use FPCUpDeluxe, and trunk now compiles, the forward declaration problems have gone today 😀 but the code example doesn't work for me, but older Mac OS and X64 CPU - different libraries to your machine.  Thanks for looking into it.


   
Hans reacted
ReplyQuote
Share: