disable menu bar and dock programmatically in mac - macos

i am new to mac programming and i have to perform a task. I need to make an application that will run at startup and cover the complete screen and will not close until my custom passcode is inserted.
The menu bar and dock needs to be hidden behind this application and the application cannot be closed until the information is given.
So far i have written the code that would run at startup . But i cant seem to disable the menu bar and dock and lock all user actions unless he gives the passcode i want.
What to do !!!!

This article contains some good info and links on creating a full-screen app that hides the Dock and menubar.

If you want to hide the Menu-Bar in Swift (Xcode, Mac OS X Application), you do:
NSMenu.setMenuBarVisible(false)
If you want to show the Menu-Bar again:
NSMenu.setMenuBarVisible(true)
Please keep in mind, that "setMenuBarVisible" is a class function and does not exist for instances of a class. So the following line is not possible:
NSApplication.sharedApplication().mainMenu!.setMenuBarVisible(false)
And will result in an error, saying, that the func "setMenuBarVisible" is not defined.

Related

macOS / Qt: Disabling the "Quit" menu item on my application's dock menu

I've writing a macOS application with Qt. This application is a launch agent, meaning that it's launched by launchd and always running in the background. Normally the application only has a menu bar icon, and it doesn't have any open windows or a Dock icon. (i.e. the shared NSApplication instance's activationPolicy property is set to a value of NSApplicationActivationPolicyAccessory.)
However, there are a few menu items available in its menu bar item that open some windows, and when those windows are open the app switches to not being background-only any longer, so it will have a Dock icon and menu bar. (i.e. activationPolicy is changed to NSApplicationActivationPolicyRegular.) With there being a Dock icon, that means it's possible for the user to right-click it and open its menu, and that menu has its default menu item for quitting the application.
Since the app is a launch agent, though, and is intended to always be running, quitting it just causes launchd to relaunch the app. I'd like to disable or remove this menu item if possible, or otherwise prevent the user from being able to quit the app in this manner.
Is there any way to do that? If there's a way to accomplish this purely using Qt's functions that would be great, but if not it's fine for me to use macOS specific functions too.
I should add that because this is a Qt application, I can't use the same method as outlined here because I don't have access to the application's delegate. I would need to use another approach. (For example, it may be possible to swizzle methods on Qt's application delegate, though if there's a cleaner way to accomplish this than I'd much rather do that.)
After doing some more research, I've found that it's not possible to remove the "Quit" menu item from an application's Dock menu, or any of the other standard menu items there as they are created and handled by the Dock itself.
It is possible to stop an application from quitting when the user quits the application via the Dock. In a Qt application the method is to subclass QApplication and override its bool event(QEvent *) method. The overridden method should check for events of type QEvent::Close, call the ignore() method on the event, and then return true. Note though that this will stop the application from quitting via all other conventional methods as well.
edit: It is also possible to tell when the app is being quit via the Dock, at least when using Apple's native API. See: macOS: Is there any way to know when the user has tried to quit an application via its Dock icon?
By using Objective-C method swizzling it's possible to override the applicationShouldTerminate: method of Qt's application delegate and prevent a Qt app from being quit by the dock.

Always show Badge Count in OS X

Apple's own apps such as Reminders show Badge count even if they are not running or after quitting them
Other apps (some even with Helper apps) show badge when they are running, but it disappears as soon as you quit the application
is there a way, user side, or programming side, we can do to always show this badge, even when the app is not running?
I searched a lot in Google, didn't find anything about "always" showing this badge, maybe "badge count" is the wrong keyword
Yes, Create dock Tile Plug-in.
Starting in OS X v10.6, you can customize an application’s Dock tile
icon and menu when the application is not running.
When your application needs to customize the Dock tile, it manipulates the NSDockTile object that was provided to the initial call to the setDockTile: method.
To dynamically change the application's Dock icon, you can draw a Dock icon using a custom view. See Using a Custom View to Draw a Dock Icon.
To add text to a Dock icon, you can apply a badge label. See Changing the Text of a Badge Label.

Simple Mac OS development app

What is the app's icon that appears to the right of the menu bar called?(like the twitter one)
When you press it, it's usually a drop down menu..
I want to implement a similar one in my mac app.. any help where can i start?
The menu icon is a status item, represented by the NSStatusItem class. See the question How to create a menubar application for Mac and its answers for more info.

Is there a way to make changes to the titlebar with GTK2?

I have a desktop application written in Ruby that is using GTK2. It's just a small test application to play with GTK2, but I'm having problems achieving what I want to do. Is there any way using GTK2 to get at the titlebar (apart from setting the title), specifically to either add a button to it (beside the min/max/etc, B in the below diagram) or to add an option to the menu that pops up when you click the icon on the titlebar (A in the below diagram)?
I'm thinking there might not be because GTK is meant to work with many many different window managers, but I just wondered if there was. As a side question, what event does clicking the 'cross' button fire? At the moment if the user clicks that the window disappears but the program doesn't end - I need to capture that event and quit the program.
Thanks for any help, including hitting me over the head and telling me how silly I am.
Note that this is possible in GTK 3.10 and up, by using gtk_window_set_titlebar(). It replaces the window manager's title bar with a custom one. GtkHeaderBar is a good custom title bar class to use.
You can't, however, make it look just like the window manager would, because you won't know which window manager the user is running.
No, the title bar is owned by the window manager and you will typically not have direct access to it.
When the user tries to close the window by clicking the window manager's button, the window will receive the delete event.

bring the application from in focus, by clicking the icon of corresponding application

I was surprised this doesn't happen automatically, but I would like my applications window to be in focus as I click its dock icon, when in minimized mode.
Just to clarify, when I minimize the app, the window goes to dock, but when I click the its corresponding Dock Icon, the window don't come in focus.
Is there anything I am missing?
I am using Qt 4.5.3 on Mac OS X 10.5, 10.6
Thanks for help.
Rahul
First answer: That's the expected behavior of a Mac app. Try Safari for example. An app can be active without showing any window. In that case, only the menu bar at the top shows that the active app is changed. So, unless absolutely necessary, you shouldn't bring the minimized window back unless the user explicitly does so. That's the Mac way!
Second answer: I understand that there are cases where you want to bring the minimized window up. In Cocoa, the application delegate method -applicationDidBicomeActive is called when the application gets the focus, and there you can bring the window up yourself. I'm sure Qt also has a similar event/callback/signal or whatever, but I don't know any Qt ... :p Sorry I can't be of any help.

Resources