Skip to content

Loading and calling AppKit #44

@aplavin

Description

@aplavin

I took a code snippet calling AppKit from an old version of ObjectiveC.jl and adapted it to the current one. Specifically, I needed [NSApp setActivationPolicy].
Not sure if it looks reasonable already or should be written better? I'm not really familiar with ObjectiveC itself...
Here's the code in question, seems very verbose:

using ObjectiveC: id, Object, NSString, NSObject, @objc, @objcwrapper
@objcwrapper NSApplication <: NSObject
function show_gl_icon_in_dock(show::Bool)
    path = "/System/Library/Frameworks/AppKit.framework"

    path = NSString(path)
    bundle = @objc [NSBundle bundleWithPath:path::id{NSString}]::id{Object}
    loaded = @objc [bundle::id{Object} load]::id{Object}

    NSApp = Base.bitcast(id{Object}, cglobal(:NSApp, Ptr{Cvoid}) |> unsafe_load)
    @objc [NSApplication sharedApplication]::id{Object}
    NSApplicationActivationPolicyRegular   = 0
    NSApplicationActivationPolicyAccessory = 1
    val = show ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory
    @objc [NSApp::id{Object} setActivationPolicy:val::Int]::id{Object}
end

(at https://github.com/JuliaAPlavin/MakieExtra.jl/blob/000000006524e0a0729128be0a0681f081cff0aa/src/MakieExtra.jl#L69-L85)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions