cmsj / blacktree-nocturne

Automatically exported from code.google.com/p/blacktree-nocturne
0 stars 0 forks source link

Request: Global keybinding #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Nocturne could really do with a global keybinding. There would simply be just 
one user-assignable keybinding - to toggle 
day / night mode.

Reasons:
1. Overall, some users are desktop users and therefore don't have a light 
sensor in their computer.
2. Laptop users may want a convenient manual control in addition to the 
auto-sensor.

How to implement:

Global keybindings can't be done in Cocoa. You must use a call which is part of 
the old Carbon API. There are enough 
examples on the web, including a sample project from Apple.

Look for "RegisterEventHotKey" in Carbon API reference

http://developer.apple.com/DOCUMENTATION/Carbon/reference/Carbon_Event_Manager_R
ef/Reference/reference.html

Other Links:

http://developer.apple.com/samplecode/FunkyOverlayWindow/listing7.html
http://www.cocoabuilder.com/archive/message/cocoa/2005/5/10/135502
http://www.red-sweater.com/blog/181/the-cocoa-carbon-advantage
http://stackoverflow.com/questions/324032/how-do-i-get-keyboard-events-in-an-nss
tatuswindowlevel-window-while-
my-applicat
http://forum.soft32.com/mac/hotkey-ftopict44116.html

Original issue reported on code.google.com by dreamc...@gmail.com on 3 Feb 2009 at 7:51

GoogleCodeExporter commented 9 years ago
you could use a quicksilver trigger that runs Nocturne. If it's already running,
running it again toggles between night vision and normal mode.

Original comment by mr.ches...@gmail.com on 26 May 2009 at 6:12

GoogleCodeExporter commented 9 years ago
Thank you for responding on this  - I never knew that.
Please consider this support issue closed :)

Original comment by dreamc...@gmail.com on 26 May 2009 at 7:52

GoogleCodeExporter commented 9 years ago

Original comment by papercr...@gmail.com on 26 May 2009 at 8:00

GoogleCodeExporter commented 9 years ago
there is one small issue with this that i just noticed. when activated through 
the
menu bar icon, the application that currently has focus keeps it. when i 
activate
Nocturne using quicksilver or through a quicksilver trigger, the top application
loses focus and must be re-focused.

Original comment by mr.ches...@gmail.com on 28 May 2009 at 3:54

GoogleCodeExporter commented 9 years ago
I tried a completely different approach: I've added a service method to 
Nocturne.

Then you can assign a global hotkey using System 
Preferences->Keyboard->Shortcut (at
least with Snow Leopard).
This has the charm that the shortcut is really global (i.e. even if Nocturne is 
not
running it will be automatically started).

Here's what I did:
Added to Info.plist:
<key>NSServices</key>
        <array>
                <dict>
            <key>NSKeyEquivalent</key>
            <dict>
                <key>default</key>
                <string>T</string>
            </dict>
                        <key>NSMenuItem</key>
            <dict>
                <key>default</key>
                <string>Nocturne Toggle</string>
            </dict>
                        <key>NSMessage</key>
                        <string>serviceToggle</string>
                        <key>NSPartName</key>
                        <string>Nocturne</string>
                </dict>
        </array>

Added to QSNocturneController.m

- (void)serviceToggle:(NSPasteboard *)pboard userData:(NSString *)userData
error:(NSString **)error {
        [self toggle];
}

and a 
  [[NSApplication sharedApplication] setServicesProvider:self];
to - (void)awakeFromNib

That's it.
Once you have the Nocturne.app in you Applications folder the service will be
automatically added to the System Preference's shortcut menu after login.

Sorry, but I can't provide a patch for this feature alone. I've attached a diff 
with
my acumulated patches so far:
 - Optional automatic disable/re-enable on power-safe
 - Fix for the Tint-Bug
 - Minor fix for some uggly CGSetDisplay... messages poluting the log
 - The service described above

Original comment by untoldw...@googlemail.com on 23 Sep 2009 at 6:21

Attachments:

GoogleCodeExporter commented 9 years ago
I know this is a very old thread, but I've only just got Nocturne and I can't 
work out how to add keyboard shortcut functionality.

I'm glad someone's made some script, but I'm unsure how to implement it . . . 
little help?

Original comment by julezred...@gmail.com on 22 Jan 2012 at 11:17