Recent

Author Topic: How to make Cocoa respond to Dark Theme (Mojave/High Sierra)  (Read 14445 times)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: How to make Cocoa respond to Dark Theme (Mojave/High Sierra)
« Reply #15 on: September 19, 2018, 03:41:33 pm »
From examples (Swift etc) I have seen, the second parameter (aSelector:SEL) is used to point to a function.
The only thing I found was:
You can use fpc intrinsic ObjCSelector.
You can find the code you're looking for in cocoawsforms
(the code is showin in comments)

Code: [Select]
NSNotificationCenter.defaultCenter.addObserver_selector_name_object(cnt, objcselector('didResignKeyNotification:'), NSWindowDidResignKeyNotification, cnt.window);

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: How to make Cocoa respond to Dark Theme (Mojave/High Sierra)
« Reply #16 on: September 20, 2018, 01:00:30 am »
ok. I see now. So "automatic" is not so automatic after all.
I'll be updating Cocoa WS to support DarkMode out of the box.

In the mean time, what you need is to update you Info.plist (which resides within your project's bundle).
Code: [Select]
  cd project1.app
  cd Contents
  open Info.plist
You need to add a new key entry, named: NSRequiresAquaSystemAppearance
and specify "false" to it. (it should be of Bool type)

After that, save Info.plist and start the application.

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
Re: How to make Cocoa respond to Dark Theme (Mojave/High Sierra)
« Reply #17 on: September 20, 2018, 02:15:49 pm »

Thanks Dmitry!


However, the code results in an "illegal qualifier" for:
Code: Pascal  [Select][+][-]
  1. NSNotificationCenter.defaultCenter.addObserver_selector_name_object
Awesome, your .plist suggestion works! The Dark theme is applied right away at startup, but (obviously when looking at the code) your MacOSFormProps is not catching that and always assumes we're starting with using the Aqua theme. Not intended as criticism, just thought I'd mention it.


I'll patiently wait for your Cocoa WS modifications.


P.s. seems your Mac may still be Mojave suitable with a little patcher tool (http://dosdude1.com/mojave/) - not sure how reliable this will be with the final release of course.

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
Re: How to make Cocoa respond to Dark Theme (Mojave/High Sierra)
« Reply #18 on: September 20, 2018, 02:17:36 pm »
Not sure if this is good info or not:
I noticed in Mojave that when testing an application, I have to restart the VM otherwise it will just run the previous (cached?) version of the application one wants to test.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: How to make Cocoa respond to Dark Theme (Mojave/High Sierra)
« Reply #19 on: September 20, 2018, 02:32:20 pm »
Awesome, your .plist suggestion works!
cool.
Could you please make a screenshot of Info.plist editor? Just want to put onto the wiki.

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
Re: How to make Cocoa respond to Dark Theme (Mojave/High Sierra)
« Reply #20 on: September 20, 2018, 03:06:39 pm »
Of course, no problem.
Did you mean something like this?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: How to make Cocoa respond to Dark Theme (Mojave/High Sierra)
« Reply #21 on: September 20, 2018, 07:00:06 pm »
yeah, that will work too.

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
Re: How to make Cocoa respond to Dark Theme (Mojave/High Sierra)
« Reply #22 on: September 21, 2018, 12:58:16 pm »
Since "selectedMenuItemColor" is depreciated since Apple prefers to use a gradient draw NSVisualEffectView, would it be an option to look at NSColor.controlAccentColor? It's not defined in NSColor.inc yet (/fpcsrc/packages/cocoaint/src/appkit) ...

 

TinyPortal © 2005-2018