Detecting Full screen applications on mac - macos

I am developing a simple application in Cocoa, and I want to detect whether any application is running in full screen mode. Is this possible?
Through runningApplications API, I can get various informations but there is no specific property related to full screen mode. Does any one know how to detect it? Is there any carbon event or API for this?

I ran into this in the spring and spent forever trying to get it to work. I ended up packaging my code up into a little GitHub project, but I completely forgot to share it here.
https://github.com/shinypb/FullScreenDetector
Hope this is useful for someone.

Anyways after trying out so many options and digging into the NSWorkspace i have found way through which we can achieve this their is notification
"NSWorkspaceActiveSpaceDidChangeNotification"
Apple doc says "Posted when a Spaces change has occurred." so by using we can register for it. along with this we need to use the NSWindow's property "isOnActiveSpace" , so by this we can detect when application enters full screen mode and exits from it.

You want to key-value observe -[NSApplication currentSystemPresentationOptions]. When the active app is in full-screen mode, that property will include NSApplicationPresentationFullScreen.

Related

CTFontManagerRegister... for a 3rd-party app

This is a bit basic but I have been struggling finding good documentation around NSFontManager and CTFontManager to achieve this. So here's the scenario:
Keynote (or any other existent app from a different developer) opens a file which uses a font that's not activated.
My app has the font and I use CTFontManagerRegisterFontURLs or one of the similar methods to get it activated.
Keynote gets a notification that the font is now available.
I would imagine there's a NSFontManager notification for missing fonts, but haven't found anything. The notifications seem to be within the sandbox of my own app. Does anyone here have an idea where I can find anything that does this (or almost does this)?
Thank you so much.

CGEventTap mouse event position overwrite only possible when running app as root user?

I am developing a macOS app which takes control of the cursor. I am using a CGEvent Tap and I am adding some arithmetic to the CGEvents in order to offset the final mouse position. Although the app is in principle working as expected, in some cases - more specifically: when running the app with certain popular illustration software and using a stylus pen - the app is producing some flickering 'ghost' positions for the mouse at its original location. The good thing is, this problem can be resolved when running the app while being logged in as root user. I have read quite some SO posts but this particular post addresses the issue best:
https://stackoverflow.com/a/9899901/5066660
As described in this post the issue is probably:
Unfortunately, the CGEventTapCreate() doc says:
Only processes running as the root user may locate an event tap at the point where HID events enter the window server; for other users, this function returns NULL.
Well the function is definitely not returning null because the tap is in effect. Also I tried all possible combinations of arguments for that function, but they all act the same. Further down in that post it is proposed to tackle the problem as follows:
Perhaps you can spin this functionality off into a separate process that has super-user permissions, leaving the rest of your app in normal user mode? I believe there's also a way to request root permissions for just a specific action taken by your program.
Now if this is a possible solution I would love to implement it! So my question is: how? I've stumbled upon running scripts with elevated permissions, but not just CoreGraphics code as for example an CGEventTap. Is this possible? Could anybody give me an example of how this could be accomplished, or any other solution to the problem?
All help is welcome, thank you very very much.
From Apple documentation:
Event taps receive key up and key down events if one of the following conditions is true:
- The current process is running as the root user.
- Access for assistive devices is enabled. In OS X v10.4, you can enable this feature using System Preferences, Universal Access panel, Keyboard view.
So giving the the application Accessibility rights solved it for me (no need to run as admin). This can be achieved System Preferences -> Security & Privacy -> Accessibility and add you program there.

Detect global paste events in cocoa

within my app I'd like to know when something is pasted from the clipboard, even if it does not happen in my application. So if a copy happens in let's say Safari and the paste is happening in let's say TextEdit, then I'd like to get a notification of that in my own application. Is this anyhow possible?
I found two articles on hooking API calls on Mac OS
Is it possible to hook API calls on Mac OS?
and
Hooking Cocoa API?
but i have no idea if this can help me.
Any help is appreciated!
Thanks a lot!
You can observe the keyboard input using Quartz Event Services or Carbon Event Manager.
Note that sandboxing your app will break this feature.

OSX Carbon: Quartz event taps to get keyboard input

I want to get Keyboard Input on OSX using c++ without using Cocoa, deprecated Carbon UPP handlers and if possible without using IOHID since that's alot of extra work.
I allready implemented a simple mouse class using quartz event taps and it works like a charm and now I'd like to use them to implement a keyboard class. Anyways as the reference states under CGEventTapCreate:
http://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
you can only access key events if one of the following is true:
The current process is running as the root user.
Access for assistive devices is enabled. In Mac OS X v10.4, you can
enable this feature using System Preferences, Universal Access
panel, Keyboard view.
that is a very serious limitation since I also want my application to work without any weird settings. Is there any way to work around this? If not, is there any alternative to using Taps in Carbon?
Thanks!
The easiest way is to use the semi-deprecated Carbon function RegisterEventHotKey, see this SO Q&A, for example.
If not, you need to live with that restriction. The restriction is there to prevent a bad person to install keylogger behind the scenes. You need to ask the user to open the preferences, type the admin password etc.
You could try to use AXMakeProcessTrusted. This is supposed to be the same as Access for assistive devices on a per process basis.

How to get a list of all open NSWindow from all running application?

Is there a way to get list of open or visible NSWindow from mac desktop?
Note that not all windows are necessarily NSWindows, and that NSWindow only provides an interface to windows in your own address space.
The supported way to access every window is the CGWindow API. Take a look at the Son of Grab sample code to see how it's done.
You can use the accessibility API (accessibility must be enabled under System Preferences for it to work) to get information on windows (and other UI elements) from other processes. This question might be just what you're looking for.
ALL running applications? No. You can only get the NSWindows of your own app. You may be able to use Universal Access or Core Graphics APIs to get some information about windows of other apps, but not full access.

Resources