View Javadoc
1   /*
2    * Copyright 2021-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.jna.platform.mac;
6   
7   import com.sun.jna.Library;
8   import com.sun.jna.Native;
9   import com.sun.jna.Structure;
10  import com.sun.jna.Structure.FieldOrder;
11  import com.sun.jna.platform.mac.CoreFoundation.CFArrayRef;
12  import com.sun.jna.platform.mac.CoreFoundation.CFDictionaryRef;
13  
14  import oshi.util.Util;
15  
16  /**
17   * The Core Graphics framework is based on the Quartz advanced drawing engine. It provides low-level, lightweight 2D
18   * rendering with unmatched output fidelity. You use this framework to handle path-based drawing, transformations, color
19   * management, offscreen rendering, patterns, gradients and shadings, image data management, image creation, and image
20   * masking, as well as PDF document creation, display, and parsing.
21   * <p>
22   * In macOS, Core Graphics also includes services for working with display hardware, low-level user input events, and
23   * the windowing system.
24   */
25  public interface CoreGraphics extends Library {
26  
27      CoreGraphics INSTANCE = Native.load("CoreGraphics", CoreGraphics.class);
28  
29      int kCGNullWindowID = 0;
30  
31      int kCGWindowListOptionAll = 0;
32      int kCGWindowListOptionOnScreenOnly = 1 << 0;
33      int kCGWindowListOptionOnScreenAboveWindow = 1 << 1;
34      int kCGWindowListOptionOnScreenBelowWindow = 1 << 2;
35      int kCGWindowListOptionIncludingWindow = 1 << 3;
36      int kCGWindowListExcludeDesktopElements = 1 << 4;
37  
38      /**
39       * A point with X and Y coordinates
40       */
41      @FieldOrder({ "x", "y" })
42      class CGPoint extends Structure {
43          public double x;
44          public double y;
45  
46      }
47  
48      /**
49       * A size with width and height
50       */
51      @FieldOrder({ "width", "height" })
52      class CGSize extends Structure {
53          public double width;
54          public double height;
55      }
56  
57      /**
58       * A rectangle with origin and size
59       */
60      @FieldOrder({ "origin", "size" })
61      class CGRect extends Structure implements AutoCloseable {
62          public CGPoint origin;
63          public CGSize size;
64  
65          @Override
66          public void close() {
67              Util.freeMemory(getPointer());
68          }
69      }
70  
71      CFArrayRef CGWindowListCopyWindowInfo(int option, int relativeToWindow);
72  
73      boolean CGRectMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGRect rect);
74  }