Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set canBecomeKeyWindow?

I have removed the title bar of a window with:

self.window?.styleMask = NSBorderlessWindowMask
self.window?.movableByWindowBackground = true

Now the text fields are not working and are disabled because without title bar canBecomeKeyWindow is set to false, as specified in the official documentation.

I have tried:

self.window?.makeKeyWindow()

But it is not working. How I can set it to true?

like image 811
Abhishek Avatar asked Sep 02 '25 17:09

Abhishek


1 Answers

If a variable is read-only (i.e. { get }, rather than { get set }) you can't set it (... = ...), you can only read it. To make sure it's returning the value you want when you do read it, you need to subclass the class in question, override the relevant property, and return that value:

class PPWindow: NSWindow {

    override var canBecomeKeyWindow: Bool {
        return true
    }
}
like image 88
Paul Patterson Avatar answered Sep 05 '25 08:09

Paul Patterson