Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ use objc::rc::autoreleasepool;
use objc::rc::{StrongPtr, WeakPtr};
use objc::runtime::{Class, Object, Sel};

use std::{mem, ops::Deref, raw};
use std::{mem, ops::Deref};

/// Meta data for a trait object
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct TraitObject {
pub data: *mut (),
pub vtable: *mut (),
}

bitflags::bitflags! {
struct NSKeyValueObservingOptions: NSUInteger {
Expand All @@ -23,7 +30,7 @@ fn get_callback(self_obj: &Object) -> *mut dyn Fn(id) {
unsafe {
let data: *mut libc::c_void = *self_obj.get_ivar("_data");
let vtable: *mut libc::c_void = *self_obj.get_ivar("_vtable");
let trait_obj = raw::TraitObject {
let trait_obj = TraitObject {
data: data.cast::<()>(),
vtable: vtable.cast::<()>(),
};
Expand Down Expand Up @@ -99,7 +106,7 @@ impl KeyValueObserver {
unsafe {
let boxed = Box::new(closure);
let callback: *const dyn Fn(*mut Object) = Box::into_raw(boxed);
let trait_obj: raw::TraitObject = mem::transmute(callback);
let trait_obj: TraitObject = mem::transmute(callback);
let observer: id = msg_send![*RUST_KVO_HELPER, new];
(*observer).set_ivar("_data", trait_obj.data.cast::<libc::c_void>());
(*observer).set_ivar("_vtable", trait_obj.vtable.cast::<libc::c_void>());
Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(raw)]
#![allow(non_snake_case)]

mod app;
Expand Down Expand Up @@ -27,6 +26,10 @@ struct Options {
/// Does not print the initial value, only prints actual changes.
#[structopt(short = "o", long = "only-changes")]
only_changes: bool,

/// Disable listening to the `quit` command.
#[structopt(short = "n", long = "no-input")]
no_input: bool,
}

fn handle_quit() -> Result<(), Error> {
Expand All @@ -44,7 +47,9 @@ fn handle_quit() -> Result<(), Error> {

fn main() -> Result<(), Error> {
let options = Options::from_args();
handle_quit()?;
if !options.no_input {
handle_quit()?;
}
app::run(!options.only_changes || options.exit, move |appearance| {
if let Some(command) = options.command.as_ref() {
let cmd = format!("{} {}", command, appearance);
Expand Down