Skip to content

Conversation

@slowhei
Copy link
Contributor

@slowhei slowhei commented Jan 18, 2026

Apple's CoreGraphics framework provides an API for displays (laptop screens, external monitors, etc.) and the mouse cursor. It also provides many other things, but these two use cases are the motivation behind this PR.

My new core:sys/darwin/CoreGraphics package is mostly straightforward; foreign import the Core Graphics framework and translate the C types into Odin types.

But there is one decision I made that is worth mentioning; I made core:sys/darwin/Foundation import core:sys/darwin/CoreGraphics. This means that CoreGraphics is not allowed to import Foundation, which would be a problem if CoreGraphics used, for example, NSObject. I searched the C headers of Core Graphics and did not find any types prefixed with NS, so we are safe there, but there is a chance of running into cyclic imports when adding more bindings for CoreGraphics in the future. If that happens, we can duplicate a couple type definitions or define a third package containing shared type definitions. Not the end of the world.

Other than that, I added a couple bindings for Foundation. And all new bindings, including for Core Graphics, have been run on my machine to verify that they work.

This is my first time proposing a new Odin package. Is there anything I should do relating to package documentation?

@laytan
Copy link
Collaborator

laytan commented Jan 22, 2026

Shouldn't this dependency be the other way around? CoreGraphics depending on Foundation makes way more sense than the other way around.

@slowhei
Copy link
Contributor Author

slowhei commented Jan 22, 2026

Core Graphics is a C API that defines the types CGFloat, CGPoint, CGRect, and CGSize that Foundation uses. Additionally, in Foundation's Obj-C header files, Core Graphics gets imported (e.g. in NSGeometry.h), but the opposite never happens.

(Note: If we want to be really precise, CGFloat and the other types I mentioned actually usually get defined in Core Foundation in CFCGTypes.h. But Core Graphics contains duplicate definitions of these types in CGBase.h that are wrapped in #ifndef CF_DEFINES_CG_TYPES, meaning Core Graphics defines these types itself if Core Foundation is never imported.)

@laytan
Copy link
Collaborator

laytan commented Jan 22, 2026

Aha, I do like CoreFoundation better, it just seems wrong to me how it is now.

So can we put these shared types in CoreFoundation and have both Foundation and CoreGraphics use them instead?

This matches where Darwin's C header files defines these types
@slowhei
Copy link
Contributor Author

slowhei commented Jan 23, 2026

That makes sense to me. I have moved the shared type definitions into CoreFoundation.

@laytan laytan merged commit 85e2e32 into odin-lang:master Jan 23, 2026
8 checks passed
nowhereware pushed a commit to nowhereware/Odin that referenced this pull request Jan 24, 2026
* Add Darwin mouse cursor-related bindings

Create CoreGraphics package in the process

* Remove unneeded semicolons

* Define some CG types in CoreFoundation instead

This matches where Darwin's C header files defines these types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants