Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T03:39:01.916Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

gpui_macos.rs

138 lines · 2.9 KB · rust
1#![cfg(target_os = "macos")]
2//! macOS platform implementation for GPUI.
3//!
4//! macOS screens have a y axis that goes up from the bottom of the screen and
5//! an origin at the bottom left of the main display.
6
7mod dispatcher;
8mod display;
9mod display_link;
10mod events;
11mod keyboard;
12mod pasteboard;
13mod system_notifications;
14
15#[cfg(feature = "screen-capture")]
16mod screen_capture;
17
18mod metal_atlas;
19pub mod metal_renderer;
20
21use metal_renderer as renderer;
22
23#[cfg(feature = "font-kit")]
24mod open_type;
25
26#[cfg(feature = "font-kit")]
27mod text_system;
28
29mod platform;
30mod window;
31mod window_appearance;
32
33use cocoa::{
34    base::{id, nil},
35    foundation::{NSAutoreleasePool, NSNotFound, NSString, NSUInteger},
36};
37
38use objc::runtime::{BOOL, NO, YES};
39use std::{
40    ffi::{CStr, c_char},
41    ops::Range,
42};
43
44pub(crate) use dispatcher::*;
45pub(crate) use display::*;
46pub(crate) use display_link::*;
47pub(crate) use keyboard::*;
48pub(crate) use platform::*;
49pub(crate) use window::*;
50
51#[cfg(feature = "font-kit")]
52pub(crate) use text_system::*;
53
54pub use platform::MacPlatform;
55
56trait BoolExt {
57    fn to_objc(self) -> BOOL;
58}
59
60impl BoolExt for bool {
61    fn to_objc(self) -> BOOL {
62        if self { YES } else { NO }
63    }
64}
65
66trait NSStringExt {
67    unsafe fn to_str(&self) -> &str;
68}
69
70impl NSStringExt for id {
71    unsafe fn to_str(&self) -> &str {
72        unsafe {
73            let cstr = self.UTF8String();
74            if cstr.is_null() {
75                ""
76            } else {
77                CStr::from_ptr(cstr as *mut c_char).to_str().unwrap()
78            }
79        }
80    }
81}
82
83#[repr(C)]
84#[derive(Copy, Clone, Debug)]
85struct NSRange {
86    pub location: NSUInteger,
87    pub length: NSUInteger,
88}
89
90impl NSRange {
91    fn invalid() -> Self {
92        Self {
93            location: NSNotFound as NSUInteger,
94            length: 0,
95        }
96    }
97
98    fn is_valid(&self) -> bool {
99        self.location != NSNotFound as NSUInteger
100    }
101
102    fn to_range(self) -> Option<Range<usize>> {
103        if self.is_valid() {
104            let start = self.location as usize;
105            let end = start + self.length as usize;
106            Some(start..end)
107        } else {
108            None
109        }
110    }
111}
112
113impl From<Range<usize>> for NSRange {
114    fn from(range: Range<usize>) -> Self {
115        NSRange {
116            location: range.start as NSUInteger,
117            length: range.len() as NSUInteger,
118        }
119    }
120}
121
122unsafe impl objc::Encode for NSRange {
123    fn encode() -> objc::Encoding {
124        let encoding = format!(
125            "{{NSRange={}{}}}",
126            NSUInteger::encode().as_str(),
127            NSUInteger::encode().as_str()
128        );
129        unsafe { objc::Encoding::from_str(&encoding) }
130    }
131}
132
133/// Allow NSString::alloc use here because it sets autorelease
134#[allow(clippy::disallowed_methods)]
135unsafe fn ns_string(string: &str) -> id {
136    unsafe { NSString::alloc(nil).init_str(string).autorelease() }
137}
138
Served at tenant.openagents/omega Member data and write actions are omitted.