9

I am trying to manipulate the windows of macOS. I have found the following URLs:

The links allow for accessing the various windows of an application via the Accessibility API of macOS; more specifically, they use the AXUIElementRef element to re-position windows.

When creating an app for macOS, I have successfully used the following code ...

@implementation CustomWindow

- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
{
    self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
    if(self)
    {
        [self setLevel:kCGDesktopWindowLevel - 1];
        [self setCollectionBehavior:
         (NSWindowCollectionBehaviorCanJoinAllSpaces |
          NSWindowCollectionBehaviorStationary |
          NSWindowCollectionBehaviorIgnoresCycle)];
    }
    return self;
}

// ...

@end

... to put a window on the Desktop level of the screen. What I am looking for is a way to manipulate the same Window level property or the like via a custom Windows Manager application. In other words, I would like to code a windows manager that can manipulate the levels the windows of other applications on screen.

Am, I correct in my findings that this can't be done? Can it be done via Core Graphics?

In addition, I want to change the application that is key and in focus, but I think this can be done.

PLG
  • 448
  • 5
  • 21
  • did you ever get anywhere with this? – m.gansrigler Aug 07 '19 at 09:54
  • 1
    @m.gansrigler I had to do a work around, so no. =( – PLG Aug 08 '19 at 15:09
  • @PLG Any news on this topic? – NFT Master Dec 18 '19 at 06:53
  • @LeadDeveloper I haven't heard of Apple changing APIs on this, but I haven't been actively searching either. – PLG Dec 19 '19 at 10:10
  • Any progress with this? I am keen to know your workaround. I too want to control the window level of other app's windows but can't seem to find a relevant API. – Ram Patra May 24 '20 at 11:50
  • @RamPatra Unless Apple creates the API in the Accessibility API, I don't think it exists. It would be interesting if we could contact Apple and ask them to add the functionality to the API. – PLG May 25 '20 at 09:02

1 Answers1

0

You can't really manipulate the CGWindowLevel of a window (all normal windows are kCGNormalWindowLevel, for example) but if you're looking to change the order of a normal-level window relative to others then you're probably looking for Accessibility's kAXRaiseAction, which you can see in action here.

If you're just looking to see what all the windows on the system are (and their CGWindowLevels, then CGWindowListCopyWindowInfo will give you that information.

numist
  • 517
  • 5
  • 7
  • I assumed it was not possible to manipulate, since I didn't get an answer for 2 years. I was specifically looking for a way to put a window on Desktop level. Thanks for your answer though. Your link to `kAXRaiseAction` might come in handy later. – PLG Sep 28 '20 at 07:38