status_item.rs

 1use cocoa::{
 2    appkit::{NSSquareStatusItemLength, NSStatusBar},
 3    base::{id, nil},
 4};
 5use core_foundation::base::TCFType;
 6use core_graphics::color::CGColor;
 7use objc::{msg_send, sel, sel_impl};
 8
 9pub struct StatusItem(id);
10
11impl StatusItem {
12    pub fn add() -> Self {
13        unsafe {
14            let status_bar = NSStatusBar::systemStatusBar(nil);
15            let native_item: id =
16                msg_send![status_bar, statusItemWithLength: NSSquareStatusItemLength];
17            let button: id = msg_send![native_item, button];
18            let layer: id = msg_send![button, layer];
19            let _: () = msg_send![layer, setBackgroundColor: CGColor::rgb(1., 0., 0., 1.).as_concrete_TypeRef()];
20            StatusItem(native_item)
21        }
22    }
23}
24
25impl crate::StatusItem for StatusItem {}