JFLib

plat/apple_mac.rs (Apple)#

Source: lib/plat/apple_mac.rs

apple_mac -- windows on macOS: AppKit through the Objective-C runtime (docs/APPLE.md AP4)

Each window is an NSWindow with a view of our class JFView (flipped: y grows downwards) and a
delegate of our class JFWindowDelegate; both carry the window's index in their instance variable.
The view and the delegate never act: they push events into the ring (evq.rs), as win_api.rs does.

  present   the frame (rows of B, G, R, x) becomes a CGImage, the contents of the view's layer
            (copied: the layer keeps the last picture for the window server)
  wait      the own event loop: nextEventMatchingMask until the deadline, sendEvent; wake() from any
            thread signals a run loop source whose callback posts an application-defined event
  sizes     points of AppKit times the window's backingScaleFactor = pixels; the dpi 96 * scale
  keys      NSEvent keyCode -> Windows VK (letters and digits as the layout names them); text
            through NSTextInputClient (dead keys, input methods: E_PREEDIT, E_IME_COMMIT)
  modifiers Command is MOD_CTRL (the library's shortcuts are Ctrl+..), Control MOD_SUPER, Option
            MOD_ALT
  gestures  the trackpad's pinch becomes Ctrl + wheel (120 per 0.2 of magnification), as Windows
            makes it of a touchpad's pinch; two-finger scrolling is the wheel in physical pixels
            (WHEEL_PIXELS)
  settings  a change of the appearance or the accent colour (distributed notifications) and of the
            screens push E_SETTINGS (SET_THEME, SET_MONITORS) for window 0
  frame     PWF_SYSFRAME: the system's title bar; otherwise the content reaches under a transparent
            title bar without its buttons (the app draws its own), HB_DRAG drags the window
  popups    (menus, lists, tooltips that leave the window) borderless non-activating panels, child
            windows of their owner; they never take the keyboard, their pointer input is pushed as
            events of the owner in owner client coordinates (as win_popup.rs does)
  owned     windows with an owner hang on it as child windows while shown: above it, moved with it
  dialogs   file_dialog: NSOpenPanel / NSSavePanel, modal (FD_FOLDER chooses a folder)
  system    monitors (NSScreen), the appearance, the accent colour and the accessibility settings
            (sys_settings_os), custom cursors (NSCursor of an NSBitmapImageRep)
  dnd       apple_mac_dnd.rs: every view a dragging destination, drag_start a dragging session
  the app   apple_mac_app.rs: the main menu (Cmd+Q asks the main window), NSApp's delegate,
            E_POWER / E_SESSION_END (NSWorkspace, SIGTERM), tool windows as panels, printing
  services  apple_mac_services.rs: the status item and notifications, the Dock tile, files the
            system opens with the app, global shortcuts
  a11y      apple_mac_a11y.rs: the accessibility tree as NSAccessibility elements under each view
            (VoiceOver), its notifications
  tests     apple_mac_test.rs: win_test, file_dialog_autoclose (events to our own windows only)

Everything runs on the main thread (AppKit's rule); the state is reached through short borrows
that never span a call into AppKit (AppKit calls back into the view and the delegate).
  • fn theme() -> i32 0 light, 1 dark: jfgui_THEME=light|dark, else the application's appearance

  • fn pen_devices() -> i32

  • fn win_create(title: &str, w_dip: i32, h_dip: i32, flags: u32, owner: i32, x: i32, y: i32) -> i32 see win_api.rs (Windows) for the semantics of every function

  • fn win_destroy(w: i32)

  • fn win_show(w: i32, mode: u32)

  • fn win_activate(w: i32)

  • fn win_enable(w: i32, on: bool) a disabled window takes no input (its owned dialog is modal)

  • fn win_set_rect(w: i32, x: i32, y: i32, cw: i32, ch: i32)

  • fn win_get_rect(w: i32) -> Option<[i32; 4]>

  • fn win_work_area(w: i32) -> Option<[i32; 4]>

  • fn win_set_title(w: i32, title: &str)

  • fn win_state(w: i32) -> u32

  • fn win_cmd(w: i32, cmd: u32)

  • fn win_begin_move(w: i32)

  • fn win_begin_resize(_w: i32, _edges: u32) the system resizes at the edges itself (a resizable window's frame)

  • fn win_show_menu(_w: i32, _x: i32, _y: i32)

  • fn win_size(w: i32) -> (i32, i32)

  • fn win_dpi(w: i32) -> i32

  • fn win_set_min_size(w: i32, w_dip: i32, h_dip: i32)

  • fn win_present(w: i32, f: &Frame, _rects: Option<&[[i32; 4]]>) show the frame in window w (the whole frame; the layer keeps it for the window server)

  • fn win_set_cursor(w: i32, shape: u32)

  • fn win_hit_hook(f: Option<fn(i32, i32, i32) -> u32>)

  • fn win_move_hook(f: Option<fn(i32, &mut [i32; 4])>)

  • fn set_refresh(f: Option<fn()>)

  • fn wait(deadline_us: u64) -> u32 pump AppKit until an event is queued or the deadline passes (0 = poll, u64::MAX = forever); before any window: sleep until the deadline or a wake() (headless)

  • fn popup(slot: u32, owner: i32, rect: Option<[i32; 4]>, f: Option<&Frame>) show / move / present popup slot slot over window owner: rect = x, y, w, h px of the owner's client area (popup pixel 0, 0 = owner pixel x, y); the layer keeps the frame. rect None hides it.

  • fn popup_anchor(_slot: u32, _anchor: [i32; 4], _kind: u32, _nat: [i32; 2]) (§6) how the next popup() hangs at its anchor: the UI places popups on macOS itself

  • fn popup_placed(_slot: u32) -> Option<[i32; 2]> (§6) the platform never moves a popup on macOS

  • fn cursor_create(px: &[u8], w: i32, h: i32, hot_x: i32, hot_y: i32, dpi: i32) -> i32 a cursor from w x h premultiplied 0xAARRGGBB pixels (rows of w * 4 bytes), hot spot in px, drawn for dpi (the window's: its points are px * 96 / dpi) -> CUR_USER0 + k / -1

  • fn cursor_destroy(id: i32) free a custom cursor; windows showing it fall back to the arrow

  • fn cursor_dpi(dpi: i32) -> i32 the dpi to draw a cursor for a window of this dpi (the window's own)

  • fn cursor_probe(_shape: u32, _dpi: i32) -> (u64, i32) (tests, E3) the cursor shown for shape at dpi and the width of a drawn one: not probed on macOS (NSCursor has the shapes but zoom-in, zoom-out and cell, which drawn_cursor makes)

  • fn file_dialog(flags: u32, path: &mut String, exts: &[&str]) -> (i32, u32) the system's Open / Save panel (modal) -> (1 chosen / 0 cancelled / -1 none, index of the chosen extension entry). flags: FD_SAVE, FD_FOLDER (an Open panel for folders), the selected entry in bits 8..15 (FD_EXT_SHIFT); path: the start (a folder, or a file whose folder and, saving, name are taken) in, the chosen path out; exts: ["png=PNG-Bild", "jpg;jpeg"] (see win_filedlg.rs)

  • fn clip_set(fmt: u32, data: &[u8]) -> bool CLIP_TEXT / CLIP_HTML / CLIP_RTF / CLIP_DOCX as clip_set_many; CLIP_PNG: the PNG file; CLIP_IMAGE: a CLIPIMG record (clipimg_pack): its PNG, else a PNG made of its BMP, and the BMP

  • fn clip_set_many(entries: &[(u32, &[u8])]) -> bool several representations of one selection (text formats, cliprich.rs)

  • fn clip_get(fmt: u32) -> Option<Vec<u8>> CLIP_IMAGE: the PNG, else a TIFF (screenshots, Preview) as a PNG, else a BMP (clip_bmp_fix)

  • fn clip_has(fmt: u32) -> bool

  • fn ime_pos(x: i32, y: i32, h: i32) where the input method's candidate window goes: the caret (px of the current window)

Source: docs/API.md in the JFLib repository.