aschuch / axstatusitempopup Goto Github PK
View Code? Open in Web Editor NEWNSStatusItem that shows a little NSPopover when clicked.
NSStatusItem that shows a little NSPopover when clicked.
The icon in the status bar will not appear. This code should solve the issue.
- (void)drawRect:(NSRect)dirtyRect{
[self.statusItem drawStatusBarBackgroundInRect:dirtyRect withHighlight:self.isActive];
NSImage *icon = self.isActive ? self.alternateImage : self.image;
NSSize iconSize = [icon size];
NSRect bounds = self.bounds;
CGFloat iconX = roundf((NSWidth(bounds) - iconSize.width) / 2);
CGFloat iconY = roundf((NSHeight(bounds) - iconSize.height) / 2);
NSPoint iconPoint = NSMakePoint(iconX, iconY);
[icon drawAtPoint:iconPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
In addition I would change the declaration of the private interface. I saw this code in PR #7
Clicking the close button in the demo causes popover to fade out, then in again, then out.
To see it more clearly, close the settings window when it opens.
Running Yosemite 10.10.2
Hi,
Is there a simple way to hide the popover when it loses focus? For example if the user clicks anywhere else but inside the window or on another status bar item?
Hi there,
The component crashes if the user (for what ever reason) double clicks the NSStatusItem to close the popover. This is a fixed hidePopover method:
- (void)hidePopover
{
if (_popover && _popover.isShown && self.active) {
[_popover close];
[NSEvent removeMonitor:_popoverTransiencyMonitor];
}
self.active = NO;
}
Hello,
I'm making little app using your class, and when enter full screen with some application then the status bar hides and popover remains there and when i change the contentviewcontroller the popover just slides to left. Can you help me?
Thanks for help, have a nice day
I noticed that triple-clicking on the menu bar icon causes a crash in the UI thread. After some debugging, I have found the cause & a (potential) fix.
Original:
- (void)hidePopover
{
self.active = NO;
if (_popover && _popover.isShown) {
[_popover close];
[NSEvent removeMonitor:_popoverTransiencyMonitor];
}
}
Fix:
- (void)hidePopover
{
self.active = NO;
if (_popover && _popover.isShown) {
[_popover close];
if (nil != _popoverTransiencyMonitor) {
[NSEvent removeMonitor:_popoverTransiencyMonitor];
_popoverTransiencyMonitor = nil;
}
}
}
From the Apple Docs:
_Remove the specified event monitor. You must ensure that eventMonitor is removed only once. Removing the same eventMonitor instance multiple times results in an over-release condition, even in a Garbage Collected environment._
as seen here: http://cl.ly/image/0I0K1w0J0k13
I'm wondering if you could give a quick example of how to use this from inside Swift? I have created the MyProject-Bridging-Header.h
containing #import "AXStatusItemPopup.h"
and can now do the following:
var image = NSImage(named: "cloud")
var altImage = NSImage(named: "cloudgrey")
var myPopup = AXStatusItemPopup()
but that's as far as I can work out. Xcode's autocomplete suggests the following, which makes no sense to me and doesn't seem to align with any of the methods defined on AXStatusItemPopup:
myPopup.view(<#view: NSView?#>, stringForToolTip: <#NSToolTipTag#>, point: NSPoint, userData: <#CMutableVoidPointer#>)
I've used AXStatusItemPopup in my Swift app and it worked great until Xcode 6 b5, where it still compiles fine, but when I click the icon in the menubar, my app crashes with EXC_BAD_ACCESS
at the following line in AXStatusItemPopup.m
:
[_popover showRelativeToRect:self.frame ofView:self preferredEdge:NSMinYEdge];
I'd be incredibly grateful if someone had a moment to pull in my code and have a look. I've tried everything I can think of without success.
The code is at https://github.com/jeff-h/duckdns
Hey, thanks for sharing this great class! It's very helpful for me to figure out NSPopover, as I'm still unfamiliar with obj-c. I'm running into a bit of a problem trying to use it though. Buttons, text fields, etc. in the popover remain inactive after the popover gets shown. In fact, text fields seem to be completely uneditable.
I'm pretty sure this isn't anything specific to my project, since the same problem occurs when I add a text field to the demo project (see screenshot).
I've spent a while trying to figure out what's going wrong, but I have no idea. My only thought right now is that perhaps it's because the NSPopover
is being called by an NSViewController
, rather than an NSWindowController <NSPopoverDelegate>
(but again, I'm unfamiliar with obj-c, so this may be irrelevant).
Hello first forgive me if this issue is completely irrelevant with the AXStatusItemPopup, but i have a problem in yosemite.
i have made 2 views inside the popover viewcontroller , an apple's ABPersonView and ABPeoplePickerView so i can select and display a contact.
When i switch to dark mode From general -> Use dark menu bar and Dock, these 2 views are not displayed correctly. (They have black artifacts or the letters are not shown correctly)
https://www.dropbox.com/s/4wsx18uno4zh672/nodarkmode.png?dl=0
https://www.dropbox.com/s/ocwh7fxrot7ziak/darkmode.png?dl=0
https://www.dropbox.com/s/4cjxcmivetsjqyi/issue.zip?dl=0
Do you know or have any hints as why this is happening?
I am quite new to cocoa and unable to figure this out, Is it a view drawing issue or something else.
I ve shared the project file and 2 before and after pictures that show the issue.
I've just installed 10.10 and notice that my popup window is opening on first run in the lower left hand side of the screen. When I click the icon in my menubar things revert to correct behaviour, with the popup positioned directly underneath the icon in the menubar.
Is anyone else seeing this?
Fair warning: I'm new to Obj-C and all that it entails.
I have made a minimum example here using CocoaPods: https://github.com/rasmuslp/AXStatusItemPopupCrash
Just download zip, open workspace, build/run, and press on cloud in menubar.
For me, this stalls on line 161:
[_popover showRelativeToRect:self.frame ofView:self preferredEdge:NSMinYEdge];
With the message
2014-01-06 21:30:40.791 AXStatusItemPopupCrash[12696:303] -[NSLock view]: unrecognized selector sent to instance 0x6000000deca0
2014-01-06 21:30:40.792 AXStatusItemPopupCrash[12696:303] -[NSLock view]: unrecognized selector sent to instance 0x6000000deca0
2014-01-06 21:30:40.795 AXStatusItemPopupCrash[12696:303] (
0 CoreFoundation 0x00007fff8d71b41c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff880f1e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8d71e2ed -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff8d6795b2 ___forwarding___ + 1010
4 CoreFoundation 0x00007fff8d679138 _CF_forwarding_prep_0 + 120
5 AppKit 0x00007fff926b83a2 -[NSPopover showRelativeToRect:ofView:preferredEdge:] + 172
6 AXStatusItemPopupCrash 0x0000000100001d61 -[AXStatusItemPopup showPopoverAnimated:] + 513
7 AXStatusItemPopupCrash 0x0000000100001b57 -[AXStatusItemPopup showPopover] + 55
8 AXStatusItemPopupCrash 0x0000000100001655 -[AXStatusItemPopup mouseDown:] + 101
9 AppKit 0x00007fff92614d9a forwardMethod + 122
10 AppKit 0x00007fff92697373 -[NSControl mouseDown:] + 1080
11 AppKit 0x00007fff92618d08 -[NSWindow sendEvent:] + 11296
12 AppKit 0x00007fff9271411b -[NSStatusBarWindow sendEvent:] + 247
13 AppKit 0x00007fff92a8b461 -[NSStatusItemReplicant _retargetEvent:fromWindow:] + 765
14 AppKit 0x00007fff927140f5 -[NSStatusBarWindow sendEvent:] + 209
15 AppKit 0x00007fff925b7744 -[NSApplication sendEvent:] + 2021
16 AppKit 0x00007fff92407a29 -[NSApplication run] + 646
17 AppKit 0x00007fff923f2803 NSApplicationMain + 940
18 AXStatusItemPopupCrash 0x0000000100001042 main + 34
19 libdyld.dylib 0x00007fff88ff75fd start + 1
)
Sometimes, instead of NSLock, I get the error on the runloop queue:
2014-01-06 21:32:41.093 AXStatusItemPopupCrash[12776:303] -[OS_dispatch_queue_runloop view]: unrecognized selector sent to instance 0x6080000ca100
<snip>
If I remove the Pod of AXStatusItemPopup, and add the two files to the root group of the project, then it works like expected. Hence, it seems to be related to the podspec or a consequence thereof.
Any idea whats going on here ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.