Gieta Laksmana
  • Blog
  • Profile
  • Projects
    • VR World Arcade
    • Punch For Fun
    • Spectrum
    • Dimension Battle
  • Resume

Main and Key Windows Shenanigans

8/18/2018

0 Comments

 
Not sure if this is the case in general, or just some corner case that I hit while being unlucky.

What I found is that when an app becomes active, there has to be 1 main window on the same space as the current key window. However, this only happens to me when Displays Have Separate spaces is enabled while having multi monitor setup:
Picture
​My specific scenario:
  • Have 2 monitors A and B
  • Create an app with 2 windows:
    • Window 1: can become main window and key window
    • Window 2: can become key window, cannot become main window
  • Move Window 1 to Monitor A
  • Move Window 2 to Monitor B
  • Deactivate the app by going to another app (Finder or something)
  • Click Window 2 on Monitor B to activate the app

Expectation:
  • Window 2 is activated and is the key window (have highlight on the window title bar)
Actual observed behavior:
  • Window 2 is activated
  • Then immediately after that, Window 1 is activated

This produce a jarring effect where clicking on a window actually activates another window and shift the active window to that window instead.

One solution is to make Window 2 to be able to become main window, but there might be a case where you might not want that.
0 Comments

NSWindow positioning shenanigans

8/4/2018

0 Comments

 
You're playing around with NSWindow, and you find this function called setFrame, setFrameOrigin, and setFrameTopLeftPoint. You feel like you are the king of the world when the thought of being able to move your window anywhere programmatically consume you. Except that when you realized that Cocoa stops you from doing that.

Cocoa allows you to move the window anywhere using those functions, except when your window starts going above the menu bar.

For instance, consider the following scenario:
  • Screen Configuration:
    • Resolution at 1280 x 800
    • Menu bar height = 22 pixel
    • Which means, the menu bar starts at y = 778 (Cocoa coordinate start at the bottom left)
  • Your Window:
    • Size is 100 x 100

When you call window.setFrameTopLeftPoint with the position of (x: 100, y: 800) your window's top left will actually be positioned at (x: 100, y: 778), right under the menu bar.

Same goes with the other setFrame* variants, your window will be pushed down until no part of your window is above the menu bar.

This is of course unless your window is the size (or bigger) than the screen, in which case it has no choice.
0 Comments

    Archives

    September 2018
    August 2018
    July 2018
    September 2017
    July 2017
    November 2016
    October 2016
    September 2016
    June 2016
    May 2016
    March 2016

    Categories

    All
    Shenanigans
    Software Engineering
    Swift
    Vr
    Xcode

    RSS Feed

Powered by Create your own unique website with customizable templates.