objc2-application-services 0.3.2

Bindings to the ApplicationServices framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/knoprocess?language=objc)
pub const kNoProcess: c_uint = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/ksystemprocess?language=objc)
pub const kSystemProcess: c_uint = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kcurrentprocess?language=objc)
pub const kCurrentProcess: c_uint = 2;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/launchflags?language=objc)
pub type LaunchFlags = u16;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/launchcontinue?language=objc)
pub const launchContinue: c_uint = 0x4000;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/launchnofileflags?language=objc)
pub const launchNoFileFlags: c_uint = 0x0800;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/launchuseminimum?language=objc)
pub const launchUseMinimum: c_uint = 0x0400;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/launchdontswitch?language=objc)
pub const launchDontSwitch: c_uint = 0x0200;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/launchallow24bit?language=objc)
pub const launchAllow24Bit: c_uint = 0x0100;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/launchinhibitdaemon?language=objc)
pub const launchInhibitDaemon: c_uint = 0x0080;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/appparameters_themsgevent?language=objc)
#[repr(C, packed(2))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct AppParameters_theMsgEvent {
    pub what: u16,
    pub message: u32,
    pub when: u32,
    pub r#where: Point,
    pub modifiers: u16,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for AppParameters_theMsgEvent {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <u16>::ENCODING,
            <u32>::ENCODING,
            <u32>::ENCODING,
            <Point>::ENCODING,
            <u16>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for AppParameters_theMsgEvent {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/appparameters?language=objc)
#[repr(C, packed(2))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct AppParameters {
    pub theMsgEvent: AppParameters_theMsgEvent,
    pub eventRefCon: u32,
    pub messageLength: u32,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for AppParameters {
    const ENCODING: Encoding = Encoding::Struct(
        "AppParameters",
        &[
            <AppParameters_theMsgEvent>::ENCODING,
            <u32>::ENCODING,
            <u32>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for AppParameters {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/appparametersptr?language=objc)
pub type AppParametersPtr = *mut AppParameters;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/extendedblock?language=objc)
pub const extendedBlock: c_uint = 0x4C43;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modereserved?language=objc)
pub const modeReserved: c_uint = 0x01000000;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modecontrolpanel?language=objc)
pub const modeControlPanel: c_uint = 0x00080000;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modelaunchdontswitch?language=objc)
pub const modeLaunchDontSwitch: c_uint = 0x00040000;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modedeskaccessory?language=objc)
pub const modeDeskAccessory: c_uint = 0x00020000;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modemultilaunch?language=objc)
pub const modeMultiLaunch: c_uint = 0x00010000;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modeneedsuspendresume?language=objc)
pub const modeNeedSuspendResume: c_uint = 0x00004000;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modecanbackground?language=objc)
pub const modeCanBackground: c_uint = 0x00001000;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modedoesactivateonfgswitch?language=objc)
pub const modeDoesActivateOnFGSwitch: c_uint = 0x00000800;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modeonlybackground?language=objc)
pub const modeOnlyBackground: c_uint = 0x00000400;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modegetfrontclicks?language=objc)
pub const modeGetFrontClicks: c_uint = 0x00000200;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modegetappdiedmsg?language=objc)
pub const modeGetAppDiedMsg: c_uint = 0x00000100;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/mode32bitcompatible?language=objc)
pub const mode32BitCompatible: c_uint = 0x00000080;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modehighleveleventaware?language=objc)
pub const modeHighLevelEventAware: c_uint = 0x00000040;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modelocalandremotehlevents?language=objc)
pub const modeLocalAndRemoteHLEvents: c_uint = 0x00000020;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modestationeryaware?language=objc)
pub const modeStationeryAware: c_uint = 0x00000010;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modeusetexteditservices?language=objc)
pub const modeUseTextEditServices: c_uint = 0x00000008;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/modedisplaymanageraware?language=objc)
pub const modeDisplayManagerAware: c_uint = 0x00000004;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/processapplicationtransformstate?language=objc)
pub type ProcessApplicationTransformState = u32;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kprocesstransformtoforegroundapplication?language=objc)
pub const kProcessTransformToForegroundApplication: c_uint = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kprocesstransformtobackgroundapplication?language=objc)
pub const kProcessTransformToBackgroundApplication: c_uint = 2;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kprocesstransformtouielementapplication?language=objc)
pub const kProcessTransformToUIElementApplication: c_uint = 4;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/sizeresourcerec?language=objc)
#[repr(C, packed(2))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SizeResourceRec {
    pub flags: u16,
    pub preferredHeapSize: u32,
    pub minimumHeapSize: u32,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for SizeResourceRec {
    const ENCODING: Encoding = Encoding::Struct(
        "SizeResourceRec",
        &[<u16>::ENCODING, <u32>::ENCODING, <u32>::ENCODING],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for SizeResourceRec {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/sizeresourcerecptr?language=objc)
pub type SizeResourceRecPtr = *mut SizeResourceRec;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/sizeresourcerechandle?language=objc)
pub type SizeResourceRecHandle = *mut SizeResourceRecPtr;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kquitbeforenormaltimemask?language=objc)
pub const kQuitBeforeNormalTimeMask: c_uint = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kquitatnormaltimemask?language=objc)
pub const kQuitAtNormalTimeMask: c_uint = 2;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kquitbeforefbasquitmask?language=objc)
pub const kQuitBeforeFBAsQuitMask: c_uint = 4;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kquitbeforeshellquitsmask?language=objc)
pub const kQuitBeforeShellQuitsMask: c_uint = 8;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kquitbeforeterminatorappquitsmask?language=objc)
pub const kQuitBeforeTerminatorAppQuitsMask: c_uint = 16;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kquitnevermask?language=objc)
pub const kQuitNeverMask: c_uint = 32;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kquitoptionsmask?language=objc)
pub const kQuitOptionsMask: c_uint = 0x7F;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kquitnotquitduringinstallmask?language=objc)
pub const kQuitNotQuitDuringInstallMask: c_uint = 0x0100;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kquitnotquitduringlogoutmask?language=objc)
pub const kQuitNotQuitDuringLogoutMask: c_uint = 0x0200;

extern "C-unwind" {
    /// Return the ProcessSerialNumber of the current application.
    ///
    /// Use [ NSRunningApplication currentApplication]
    ///
    /// Return the canonical process serial number to the caller.
    ///
    /// All applications ( things which can appear in the Dock or which are not documents and are launched by the Finder or Dock ) on Mac OS 10 have a unique process serial number.
    /// This number is created when the application launches, and remains until the application quits. Other system services, like AppleEvents, use the ProcessSerialNumber to specify an
    /// application.
    ///
    /// During launch, every application 'checks in' with the Process Manager. Before this checkin, the application can not receive events or draw to the screen. Prior to Mac OS 10.2, this
    /// 'check in' happened before the applications's main() function was entered. In Mac OS 10.2 and later, this 'check in' does not happen until the first time the application calls a Process
    /// Manager function, or until it enters CFRunLoopRun() for the main runloop. This allows tools and other executables which do not need to receive events to link against more of the higher
    /// level toolbox frameworks, but may cause a problem if the application expects to be able to retrieve events or use CoreGraphics services before this checkin has occurred.-
    ///
    /// An application can force the connection to the Process Manager to be set up by calling any Process Manager routine, but the recommended way to do this is to call
    /// GetCurrentProcess() to ask for the current application's PSN. This will initialize the connection to the Process Manager if it has not already been set up and 'check in' the application
    /// with the system.
    ///
    /// This function is named MacGetCurrentProcess() on non Macintosh platforms and GetCurrentProcess on the Macintosh. However, even Macintosh code can use the
    /// GetCurrentProcess() name since there is a macro which maps back to GetCurrentProcess().
    ///
    /// Lastly, it is usually not necessary to call GetCurrentProcess() to get the 'current' process psn merely to pass it to another Process Manager routine. Instead, just construct a
    /// ProcessSerialNumber with 0 in highLongOfPSN and kCurrentProcess in lowLongOfPSN and pass that. For example, to make the current process the frontmost process, use
    ///
    /// ```text
    /// ProcessSerialNumber psn = { 0, kCurrentProcess };
    /// OSErr err = SetFrontProcess(
    /// &
    /// psn );
    /// ```
    /// If you need to pass a ProcessSerialNumber to another application or use it in an AppleEvent, you do need to get the canonical PSN with this routine.
    ///
    ///
    /// Parameter `pPSN`: where the current processes process serial number is returned
    ///
    /// Returns: An operating system status code.
    ///
    /// # Safety
    ///
    /// `p_psn` must be a valid pointer.
    #[deprecated]
    pub fn GetCurrentProcess(p_psn: *mut ProcessSerialNumber) -> OSErr;
}

extern "C-unwind" {
    /// Return the ProcessSerialNumber of the front application
    ///
    /// DEPRECATED:   Use +[NSWorkspace runningApplications] and look for the entry withisActive == YES.
    ///
    /// Parameter `pPSN`: where the front application process serial number is returned
    ///
    /// Returns: An operating system status code
    ///
    /// # Safety
    ///
    /// `p_psn` must be a valid pointer.
    #[deprecated]
    pub fn GetFrontProcess(p_psn: *mut ProcessSerialNumber) -> OSErr;
}

extern "C-unwind" {
    /// Return the process serial number following the given process
    ///
    /// DEPRECATED:
    /// Use +[NSWorkspace runningApplications:] which returns the full array of all running applications.
    /// If this function is called with the process serial number where { .highLongOfPSN = 0, .lowLongOfPSN = 0 }, this return the process serial number of the first application.
    /// If called with a valid process serial number, it returns the next higher application, or procNotFound when the last process serial number has been returned.
    ///
    /// Parameter `pPSN`: On input, a process serial number; on exit, the next process serial number or { 0, 0 }
    ///
    /// Returns: An operating system status code.  procNotFound signal the previous item was the last application in the array of running applications.
    ///
    /// # Safety
    ///
    /// `p_psn` must be a valid pointer.
    #[deprecated]
    pub fn GetNextProcess(p_psn: *mut ProcessSerialNumber) -> OSErr;
}

/// # Safety
///
/// `psn` must be a valid pointer.
#[deprecated]
#[inline]
pub unsafe extern "C-unwind" fn ProcessInformationCopyDictionary(
    psn: *const ProcessSerialNumber,
    info_to_return: u32,
) -> Option<CFRetained<CFDictionary>> {
    extern "C-unwind" {
        fn ProcessInformationCopyDictionary(
            psn: *const ProcessSerialNumber,
            info_to_return: u32,
        ) -> Option<NonNull<CFDictionary>>;
    }
    let ret = unsafe { ProcessInformationCopyDictionary(psn, info_to_return) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

extern "C-unwind" {
    /// Make the application with the given PSN into the front application, if possible.
    ///
    /// :
    /// To make your own application frontmost, use [[NSApplication activate].
    /// To make another application frontmost, use the activateWithOptions
    /// method of the appropriate NSRunningApplication object for that application.
    ///
    /// Parameter `pPSN`: the ProcessSerialNumber of the application to be made frontmost
    ///
    /// # Safety
    ///
    /// `p_psn` must be a valid pointer.
    #[deprecated]
    pub fn SetFrontProcess(p_psn: *const ProcessSerialNumber) -> OSErr;
}

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/ksetfrontprocessfrontwindowonly?language=objc)
pub const kSetFrontProcessFrontWindowOnly: c_uint = 1 << 0;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/ksetfrontprocesscausedbyuser?language=objc)
pub const kSetFrontProcessCausedByUser: c_uint = 1 << 1;

extern "C-unwind" {
    /// # Safety
    ///
    /// `in_process` must be a valid pointer.
    #[deprecated]
    pub fn SetFrontProcessWithOptions(
        in_process: *const ProcessSerialNumber,
        in_options: OptionBits,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// # Safety
    ///
    /// `psn` must be a valid pointer.
    #[deprecated]
    pub fn WakeUpProcess(psn: *const ProcessSerialNumber) -> OSErr;
}

extern "C-unwind" {
    /// # Safety
    ///
    /// - `psn1` must be a valid pointer.
    /// - `psn2` must be a valid pointer.
    /// - `result` must be a valid pointer.
    #[deprecated]
    pub fn SameProcess(
        psn1: *const ProcessSerialNumber,
        psn2: *const ProcessSerialNumber,
        result: *mut Boolean,
    ) -> OSErr;
}

extern "C-unwind" {
    #[deprecated]
    pub fn ExitToShell();
}

extern "C-unwind" {
    /// # Safety
    ///
    /// `in_process` must be a valid pointer.
    #[deprecated]
    pub fn KillProcess(in_process: *const ProcessSerialNumber) -> OSErr;
}

extern "C-unwind" {
    /// # Safety
    ///
    /// - `psn` must be a valid pointer.
    /// - `name` must be a valid pointer.
    #[deprecated]
    pub fn CopyProcessName(psn: *const ProcessSerialNumber, name: *mut *const CFString)
        -> OSStatus;
}

extern "C-unwind" {
    /// # Safety
    ///
    /// - `psn` must be a valid pointer.
    /// - `pid` must be a valid pointer.
    #[cfg(feature = "libc")]
    #[deprecated]
    pub fn GetProcessPID(psn: *const ProcessSerialNumber, pid: *mut libc::pid_t) -> OSStatus;
}

extern "C-unwind" {
    /// # Safety
    ///
    /// `psn` must be a valid pointer.
    #[cfg(feature = "libc")]
    #[deprecated]
    pub fn GetProcessForPID(pid: libc::pid_t, psn: *mut ProcessSerialNumber) -> OSStatus;
}

/// ***********************************************************************
/// Process Visibility.
/// ***********************************************************************
///
/// # Safety
///
/// `psn` must be a valid pointer.
#[deprecated]
#[inline]
pub unsafe extern "C-unwind" fn IsProcessVisible(psn: *const ProcessSerialNumber) -> bool {
    extern "C-unwind" {
        fn IsProcessVisible(psn: *const ProcessSerialNumber) -> Boolean;
    }
    let ret = unsafe { IsProcessVisible(psn) };
    ret != 0
}

/// # Safety
///
/// `psn` must be a valid pointer.
#[deprecated]
#[inline]
pub unsafe extern "C-unwind" fn ShowHideProcess(
    psn: *const ProcessSerialNumber,
    visible: bool,
) -> OSErr {
    extern "C-unwind" {
        fn ShowHideProcess(psn: *const ProcessSerialNumber, visible: Boolean) -> OSErr;
    }
    unsafe { ShowHideProcess(psn, visible as _) }
}

extern "C-unwind" {
    /// # Safety
    ///
    /// `psn` must be a valid pointer.
    pub fn TransformProcessType(
        psn: *const ProcessSerialNumber,
        transform_state: ProcessApplicationTransformState,
    ) -> OSStatus;
}

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/initdev?language=objc)
pub const initDev: c_uint = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/hitdev?language=objc)
pub const hitDev: c_uint = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/closedev?language=objc)
pub const closeDev: c_uint = 2;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/nuldev?language=objc)
pub const nulDev: c_uint = 3;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/updatedev?language=objc)
pub const updateDev: c_uint = 4;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/activdev?language=objc)
pub const activDev: c_uint = 5;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/deactivdev?language=objc)
pub const deactivDev: c_uint = 6;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/keyevtdev?language=objc)
pub const keyEvtDev: c_uint = 7;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/macdev?language=objc)
pub const macDev: c_uint = 8;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/undodev?language=objc)
pub const undoDev: c_uint = 9;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/cutdev?language=objc)
pub const cutDev: c_uint = 10;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/copydev?language=objc)
pub const copyDev: c_uint = 11;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/pastedev?language=objc)
pub const pasteDev: c_uint = 12;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/cleardev?language=objc)
pub const clearDev: c_uint = 13;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/cursordev?language=objc)
pub const cursorDev: c_uint = 14;

/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/cdevgenerr?language=objc)
pub const cdevGenErr: c_int = -1;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/cdevmemerr?language=objc)
pub const cdevMemErr: c_int = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/cdevreserr?language=objc)
pub const cdevResErr: c_int = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/cdevunset?language=objc)
pub const cdevUnset: c_int = 3;