Ignore:
Timestamp:
12/21/09 22:11:47 (15 years ago)
Author:
Nicholas Riley
Message:

Keyboard-accessible and better-behaving volume slider.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/PSVolumeController.m

    r584 r595  
    1010#import "NJRSoundManager.h"
    1111#import "NJRNonCenteringWindow.h"
     12#include <Carbon/Carbon.h>
    1213
    1314@interface NSMenu (SnowLeopardAdditions)
     
    5657            }
    5758            [menu setAllowsContextMenuPlugIns: NO];
     59            // replace with http://waffle.wootest.net/2007/08/07/popping-up-a-menu-in-cocoa/
    5860            [menu popUpMenuPositioningItem: nil atLocation: point inView: view];
    5961            [menu release];
     
    100102- (IBAction)volumeSet:(NSSlider *)sender;
    101103{
     104    // XXX don't delay preview for keyboard adjustment
    102105    [delegate volumeController: self didSetVolume: [sender floatValue]];
    103     if (NSEventMaskFromType([[NSApp currentEvent] type]) & (NSLeftMouseUpMask | NSRightMouseUpMask | NSOtherMouseUpMask))
     106    NSLog(@"%@", [NSApp currentEvent]);
     107    unsigned eventMask = NSEventMaskFromType([[NSApp currentEvent] type]);
     108    // The event may simply be a mouse-up: close the menu.
     109    if (eventMask & (NSLeftMouseUpMask | NSRightMouseDownMask | NSOtherMouseDownMask))
     110        [menu cancelTracking];
     111    // On a quick click, the event may be a mouse down but the mouse button is no longer down.
     112    if (!(eventMask & (NSLeftMouseDownMask | NSRightMouseDownMask | NSOtherMouseDownMask)))
     113        return;
     114    // 10.6+: use [NSEvent pressedMouseButtons] instead
     115    if (GetCurrentButtonState() == 0)
    104116        [menu cancelTracking];
    105117}
Note: See TracChangeset for help on using the changeset viewer.