jenskutilek / Glyphs-Favourites

A window for quick access to your favourite Glyphs files
MIT License
2 stars 0 forks source link

Cannot drag from Finder to Favourites #2

Open justinpenner opened 5 months ago

justinpenner commented 5 months ago

I suspect this might be an OS version-specific problem, since I'm assuming this hasn't been a problem for you. I'm currently running Monterey 12.6.5.

It's not possible to drag a file from Finder to the Favourites window, because floating windows disappear when their parent application isn't active. So the Favourites window disappears when you activate a Finder window, and then there's nothing to drag your file onto.

There is a slightly tricky workaround, where you can arrange the windows side by side as below, then activate the Glyphs window, then grab the file from Finder in one click and quickly move away so Finder doesn't get activated, then drop it into Favourites.

image

I think switching to vanilla.Window instead of vanilla.FloatingWindow would probably solve this? Unless there's another reason you chose to use a floating window.

schriftgestalt commented 5 months ago

When you are in Finder, start the drag (and keep pressing mouse/trackpad), press Command+Tab, activate Glyphs, drop into the now visible window.

justinpenner commented 5 months ago

When you are in Finder, start the drag (and keep pressing mouse/trackpad), press Command+Tab, activate Glyphs, drop into the now visible window.

Aha! I didn't think of doing it that way. But it's still a little annoying that I need to do that even if Glyphs and Finder are both visible.

Why do floating windows disappear when their parent is inactive, anyway? It doesn't seem intuitive to me. I started with a FloatingWindow for my TalkingLeaves plugin originally, but quickly abandoned it for that reason and others.

florianpircher commented 5 months ago

Why do floating windows disappear when their parent is inactive, anyway? It doesn't seem intuitive to me. I started with a FloatingWindow for my TalkingLeaves plugin originally, but quickly abandoned it for that reason and others.

Good question, this has bothered me a few times as well. You would need to ask Apple, as this behavior is deeply integrated into system window management and difficult to work around.

schriftgestalt commented 5 months ago

It is a bit more interesting. The window disappears because of the hidesOnDeactivate setting. But, if you deactivate that, it will keep in from of all other apps. It seem there is no window level that is above the main window of an app but below all windows of the active app. I "fixed" that for the floating macro panel:

- (void)awakeFromNib {
    NSNotificationCenter *notificationCenter = NSNotificationCenter.defaultCenter;
    [notificationCenter addObserver:self
                           selector:@selector(applicationWillBecomeActive:)
                               name:NSApplicationWillBecomeActiveNotification
                             object:nil];
    [notificationCenter addObserver:self
                           selector:@selector(applicationWillResignActive:)
                               name:NSApplicationWillResignActiveNotification
                             object:nil];
}

- (void)applicationWillBecomeActive:(NSNotification *)notification {
    self.window.level = NSStatusWindowLevel;
}

- (void)applicationWillResignActive:(NSNotification *)notification {
    self.window.level = NSNormalWindowLevel;
}
schriftgestalt commented 5 months ago

A rough python version. (I didn’t try this, so I might have missed something)

from AppKit import NSApplicationWillBecomeActiveNotification, NSApplicationWillResignActiveNotification, NSStatusWindowLevel, NSNormalWindowLevel
from GlyphsApp.plugins import GeneralPlugin

class MyPlugin(GeneralPlugin):

    @objc.python_method
    def setup(self):
        notificationCenter = NSNotificationCenter.defaultCenter()
        notificationCenter.addObserver_selector_name_objcet_(self, "applicationWillBecomeActive:", NSApplicationWillBecomeActiveNotification, None)
        notificationCenter.addObserver_selector_name_objcet_(self, "applicationWillResignActive:", NSApplicationWillResignActiveNotification, None)

    # Don’t add a @objc decorator here as that need to be objc method
    def applicationWillBecomeActive_(self, notification):
        self.window.setLevel_(NSStatusWindowLevel)

    def applicationWillResignActive_(self, notification):
        self.window.setLevel_(NSNormalWindowLevel)
schriftgestalt commented 5 months ago

For a GeneralPlugin you don’t need to deal with removing the observers, for other plugins, that are instantiated multiple times, you need to remove that observers in -()dealloc or def __del__():


- (void)dealloc {
    NSNotificationCenter *notificationCenter = NSNotificationCenter.defaultCenter;
    [notificationCenter removeObserver:self
                                  name:NSApplicationWillBecomeActiveNotification
                                object:nil]; 
    [notificationCenter removeObserver:self
                                  name:NSApplicationWillResignActiveNotification
                                object:nil]; 
}
and in python:
```python
    def __del__(self):
        notificationCenter = NSNotificationCenter.defaultCenter()
        notificationCenter.removeObserver_name_objcet_(self, NSApplicationWillBecomeActiveNotification, None)
        notificationCenter.removeObserver_name_objcet_(self, NSApplicationWillResignActiveNotification, None)
``