Commit Graph

119 Commits

Author SHA1 Message Date
Patrick Walton 44d3744515 appkit: Lengthen NSAnyEventMask to (-1 as u64) rather than (-1 as
u32), to fix the problem whereby windows don't reappear and don't appear
on top on startup.

The window restoration feature in Mac OS X from Lion onward prevents
windows from appearing until restoration is complete and the app is
launched. Internally, the persistent UI restorer detects the app launch
by listening to the Carbon event `kAEOpenApplication`, which, as an
Apple event, has the event class `kEventClassAppleEvent`.

Like `-[NSApplication run]` does, Glutin uses the method
`-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]` to
pump the application event loop. The event mask provided is an
`NSEventMask`; events that do not match this mask are filtered out. When
pumping the Carbon event loop, the Cocoa framework internally converts
this `NSEventMask` to a Carbon event mask. The logic to perform this
conversion proceeds in two steps:

1. If the provided `NSEventMask` is exactly equal to `NSAnyEventMask`,
then the rest of the logic is skipped and the resulting Carbon event
mask is a null mask--i.e. a mask that matches all events.

2. Otherwise, the framework constructs a blank Carbon mask--that is, a
mask that matches no events at all. The various bits of the
`NSEventMask` are examined, translated to their Carbon equivalents, and
added to the mask. Then that Carbon mask is returned.

In Glutin prior to this patch, our definition of `NSAnyEventMask` was a
mask that effectively matched all events but was not equal to the real
`NSAnyEventMask` that, for example, `-[NSApplication run]` supplies to
`-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]`. This
means that our code causes the system to take path (2) above, whereas
standard Cocoa apps take path (1). Now it might seem that these paths
are equivalent, but in fact they are very different. This is because
*there are classes of Carbon events that do not correspond to Cocoa
events selectable via `NSEventMask`*. One of these Carbon-only event
types is Apple events.

This fact is what made Glutin apps prior to this patch go wrong. The
Carbon framework would deliver the `kAEOpenApplication` event to the
application, but it was always masked out and ignored because the
`NSEventMask` we supplied to `-[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:]` did not translate to a
Carbon event mask that included Apple events. This, in turn, caused the
persistent UI restorer to never notice that the app finished launching.
Thus the flag that inhibited windows from appearing would never be
cleared, and all windows would end up invisible.

This patch fixes the issue by lengthening `NSAnyEventMask` to its true
64-bit value, allowing the expected Carbon event filter to be used
during app startup and enabling the app startup event to be handled
properly.
2016-06-07 22:23:11 -07:00
Patrick Walton 37b5ce6113 Add bindings to NSInsetRect and NSRectToCGRect, and make various
geometry types copyable.
2016-05-27 13:25:32 -07:00
bors-servo 24f7593061 Auto merge of #125 - pcwalton:menu-additions, r=larsbergstrom
Add bindings for a few more menu-related functions.

Bindings added include:

* `-[NSApplication mainMenu]`
* `-[NSApplication setWindowsMenu:]`
* `+[NSMenu alloc]`
* `-[NSMenu initWithTitle:]`
* `-[NSMenu itemAtIndex:]`

r? @metajack

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/cocoa-rs/125)
<!-- Reviewable:end -->
2016-05-16 10:05:07 -07:00
bors-servo 48342f557c Auto merge of #126 - servo:bitflags, r=Wafflespeanut
Update bitflags to 0.7

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/cocoa-rs/126)
<!-- Reviewable:end -->
2016-05-15 03:26:39 -07:00
Anthony Ramine 20b52d82c4 Update bitflags to 0.7 2016-05-15 12:06:35 +02:00
Patrick Walton 7aa45dc0a5 Add bindings for a few more menu-related functions.
Bindings added include:

* `-[NSApplication mainMenu]`
* `-[NSApplication setWindowsMenu:]`
* `+[NSMenu alloc]`
* `-[NSMenu initWithTitle:]`
* `-[NSMenu itemAtIndex:]`
2016-05-12 16:37:10 -07:00
Patrick Walton e1ac9a3821 Add -[NSApplication setApplicationIconImage:] and `-[NSImage
isValid]`.

These are useful for setting icons.
2016-05-10 18:05:52 -07:00
Patrick Walton 2028cee801 Add the venerable NSRectFill. 2016-05-09 11:02:38 -07:00
Patrick Walton f461b65eda Add autosizing-related methods and constants to NSView. 2016-05-09 11:01:02 -07:00
Corey Farwell 976e6dbc70 Derive common traits for AppKit integer repr enums. 2016-04-28 19:15:23 -04:00
Corey Farwell f037498244 Add NSApplicationActivationPolicyProhibited.
https://developer.apple.com/library/mac/documentation/AppKit/Reference/NSRunningApplication_Class/#//apple_ref/c/tdef/NSApplicationActivationPolicy
2016-04-28 10:35:50 -04:00
Conrad Kramer d874e1d9d8 Added basic NSFastEnumeration implementation 2016-03-31 13:08:05 -07:00
Josh Matthews 768538d630 Merge pull request #116 from fkaa/foundation-nsrange
Add NSRange
2016-02-27 16:48:30 -05:00
Felix Kaaman ff18c50631 Add NSRange 2016-02-27 22:12:50 +01:00
Felix Kaaman e403c78fee Add NSView functions 2016-02-27 22:02:09 +01:00
Paul Rouget f21ffe6dc1 add NSEventTypePressure event type 2016-02-16 13:09:30 +01:00
Patrick Walton bf4879fa00 Add bindings to -[NSWindow standardWindowButton:] and -[NSView
removeFromSuperview].
2016-02-03 14:53:45 -08:00
Patrick Walton 3d09c6517a Add a binding to -[NSView superview]. 2016-02-03 14:15:18 -08:00
hc 20c994ecaa NSImage methods and version bump
added some methods to NSImage and version bump to 0.2.3
2016-01-29 22:22:01 -05:00
hc 36f4d4cab3 NSStatusBar
mostly complete, missing `thickness` property, unsure how to access
this property
2016-01-29 21:29:53 -05:00
hc 5d3fd95607 forgot _ for NSStatusItem setLength
whoops forget to add _ for setLength
2016-01-29 21:06:46 -05:00
hc 94efc59d57 NSStatusItem
NSStatusItem fully implemented
2016-01-29 21:04:49 -05:00
hc a96019726c init status bar button (icon)
the minimum to get a status bar button (icon) to appear
2016-01-29 12:19:51 -05:00
Josh Matthews c21f19bba2 Add various initializing methods for NSString, NSArray, and NSValue. 2015-11-27 10:26:39 -05:00
Simon Génier fe8cc9fcdf Implement objc::Encode for NSRect. 2015-11-16 22:09:00 -05:00
Mathieu Rheaume e8d5c36740 Implement NSString Len + init_str use initWithBytes:length:encoding 2015-09-28 02:42:22 -04:00
Rob.Gowin b82bcbe5c5 Added NSRunningApplication and two associated functions.
Added ability to call [[NSRunningApplication currentApplication]
     activateWithOptions: NSApplicationActivateIgnoringOtherApps]
which is used in the example to fix the missing menu bar when
the example app starts.
2015-09-22 22:34:31 -05:00
bors-servo 22791ddd4d Auto merge of #93 - fkaa:menubar-stuff, r=metajack
Add various methods related to menubars



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/cocoa-rs/93)
<!-- Reviewable:end -->
2015-09-22 13:43:41 -06:00
bors-servo e0f37a07a5 Auto merge of #97 - sgnr:nswindow-managing-responders, r=metajack
Add responder management to NSWindow.

As described [in the documentation for `NSWindow`](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/).

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/cocoa-rs/97)
<!-- Reviewable:end -->
2015-09-22 13:38:07 -06:00
Paul Rouget 99cf2944cb add addSubview method 2015-09-22 09:27:56 +02:00
Paul Rouget 06d64a18c8 Add support for titleVisibility and titlebarAppearsTransparent 2015-09-21 11:28:11 +02:00
Simon Génier fd19702e84 Add responder management to NSWindow. 2015-09-12 14:18:58 -04:00
Felix Kaaman d9d30643ac Add various methods related to menubars 2015-06-29 09:23:48 +02:00
Steven Sheldon 297a2bf749 Add core-graphics dependency. 2015-06-06 01:12:05 -07:00
Jack Moffitt f85d87826e Minor cleanups. 2015-06-03 10:49:18 -06:00
Felix Kaaman 27a09caba9 Add NSAppKitVersionNumber 2015-05-24 15:29:14 +02:00
Felix Kaaman b78a1b828c Add remaining functions to NSOpenGLPixelFormat 2015-04-30 11:20:11 +02:00
Steven Sheldon 8f7351571f Fixed overflow in NSTouchPhase definition. 2015-04-02 08:59:57 -07:00
Steven Sheldon a67cc837b5 Remove unused std_misc feature. 2015-03-28 13:31:16 -07:00
Steven Sheldon 89f0929acf Split a foundation mod from appkit. 2015-03-26 22:18:45 -07:00
Steven Sheldon 0dbaa0502c Removed incorrect casts. 2015-03-21 21:20:01 -07:00
Steven Sheldon 2ba1ebbb36 Use objc crate for runtime functions. 2015-03-21 21:20:01 -07:00
Coeuvre Wong 621242eb22 Added more methods 2015-03-19 09:21:51 +08:00
Jack Moffitt e3f85ff51c Use objc_msgSend_fpret consistently. 2015-03-06 16:12:58 -07:00
Hyeon Kim c0e12fdccf Fix compile warning
1.  You don't need `#![feature(hash)]` anymore.
2.  `CString::from_slice` is deprecated now.
2015-02-27 10:03:15 +09:00
Hyeon Kim 2e4e155aed Fix compile error
'NSEventMask', 'NSEventModifierFlags' are not module, so commands like
below is not valid anymore.

    pub use self::NSEventMask::*;
    pub use self::NSEventModifierFlags::*;
2015-02-27 09:39:45 +09:00
Patrick Walton b8a33f19a1 Use objc_msgSend_fpret for backingStoreFactor.
This mistake led to a bizarre chain reaction in Servo that ultimately
led to a hang only when optimization was enabled.
2015-02-20 22:17:53 -08:00
Glenn Watson d7e68cf6bb Fix an osx internal assertion in NSWindow - ensure the C string is null terminated. 2015-02-18 14:39:15 +10:00
Ivan Ukhov 549f168f26 Fix letter case in NSEventMask 2015-02-10 21:27:30 +01:00
Brendan Zabarauskas 3c737a9f16 Fix NSOpenGLContext init methods
These are instance methods, not class methods
2015-02-10 20:05:18 +11:00