objective c - Follow an NSStatusItem with a window - incorrect position when switching to a taller display -
the problem: have follow app's nsstatusitem popup/window right beneath it.
the general solution (like it's suggested here or here) add custom view nsstatusitem , view's window's frame (statusitem.view.window.frame), , connect move event through nswindowdidmovenotification notification of statusitem.view.window.
this solution works 99% unless user connects external display taller previous display (for example mac book user connects external monitor), in case statusitem.view.window.frame incorrect, x coordinate correct y coordinate same in smaller screen!
i've checked , of menubar apps have popup window when click status item misplaced i've described.
my solution don't use y coordinate frame use corresponding nsscreen's visibleframe's height this:
nsscreen *screenwithmenubar = [[nsscreen screens] objectatindex:0]; if( screenwithmenubar ) { // correct top position 'screen menubar's height // workaround: without window off-placed when user plugs in external display, // display more height nsrect visiblerect = [screenwithmenubar visibleframe]; originpoint.y = visiblerect.size.height + visiblerect.origin.y; }
as stated in official apple documentation the first screen should screen contains menubar should work, seems of hack me.
have guys experienced bug? have found better solution?
Comments
Post a Comment