Skip to content

Commit

Permalink
add Output releate data struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
harryfei committed May 31, 2020
1 parent b938136 commit 9077139
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions rust_src/remacs-bindings/src/main.rs
Expand Up @@ -240,6 +240,7 @@ fn run_bindgen(path: &str) {
.generate_inline_functions(true)
.derive_default(true)
.ctypes_prefix("::libc")
.no_copy("wr_output")
// we define these ourselves, for various reasons
.blacklist_item("Lisp_Object")
.blacklist_item("emacs_globals")
Expand Down
6 changes: 6 additions & 0 deletions rust_src/src/webrender/display_info.rs
Expand Up @@ -41,3 +41,9 @@ impl Drop for DisplayInfo {

pub type DisplayInfoRef = ExternalPtr<DisplayInfo>;
unsafe impl Sync for DisplayInfoRef {}

impl Default for DisplayInfoRef {
fn default() -> Self {
Self::new(ptr::null_mut())
}
}
1 change: 1 addition & 0 deletions rust_src/src/webrender/mod.rs
@@ -1,3 +1,4 @@
pub mod display_info;
pub mod frame;
pub mod output;
pub mod term;
41 changes: 41 additions & 0 deletions rust_src/src/webrender/output.rs
@@ -0,0 +1,41 @@
use libc;
use std::ptr;

use crate::{lisp::ExternalPtr, remacs_sys::wr_output};

use super::display_info::DisplayInfoRef;

#[derive(Default)]
pub struct OutputInner {
pub display_info: DisplayInfoRef,
}

pub type OutputInnerRef = ExternalPtr<OutputInner>;

pub type Output = wr_output;
impl Output {
pub fn new() -> Self {
let mut output = Output::default();

let inner = Box::new(OutputInner::default());
output.inner = Box::into_raw(inner) as *mut libc::c_void;

output
}

pub fn get_inner(&self) -> OutputInnerRef {
OutputInnerRef::new(self.inner as *mut OutputInner)
}
}

impl Drop for Output {
fn drop(&mut self) {
if self.inner != ptr::null_mut() {
unsafe {
Box::from_raw(self.inner as *mut OutputInner);
}
}
}
}

pub type OutputRef = ExternalPtr<Output>;
10 changes: 4 additions & 6 deletions rust_src/src/wrterm.rs
Expand Up @@ -12,18 +12,16 @@ use crate::{
remacs_sys::globals,
remacs_sys::resource_types::{RES_TYPE_NUMBER, RES_TYPE_STRING, RES_TYPE_SYMBOL},
remacs_sys::{
block_input, font, hashtest_eql, make_hash_table, unblock_input, wr_output, x_get_arg,
Display, Fcopy_alist, Fprovide, Pixmap, Qminibuffer, Qname, Qnil, Qparent_id, Qt,
Qterminal, Qunbound, Qwr, Qx, WRImage, Window, XColor, XrmDatabase, DEFAULT_REHASH_SIZE,
block_input, font, hashtest_eql, make_hash_table, unblock_input, x_get_arg, Display,
Fcopy_alist, Fprovide, Pixmap, Qminibuffer, Qname, Qnil, Qparent_id, Qt, Qterminal,
Qunbound, Qwr, Qx, WRImage, Window, XColor, XrmDatabase, DEFAULT_REHASH_SIZE,
DEFAULT_REHASH_THRESHOLD,
},
webrender::frame::create_frame,
webrender::term::wr_term_init,
webrender::{frame::create_frame, output::OutputRef, term::wr_term_init},
};

pub use crate::webrender::display_info::{DisplayInfo, DisplayInfoRef};

pub type OutputRef = ExternalPtr<wr_output>;
pub type DisplayRef = ExternalPtr<Display>;
pub type ImageRef = ExternalPtr<WRImage>;

Expand Down
2 changes: 2 additions & 0 deletions src/wrterm.h
Expand Up @@ -116,6 +116,8 @@ struct wr_output
/* This is the Emacs structure for the X display this frame is on. */
struct wr_display_info *display_info;

/* Inner perporty in Rust */
void *inner;
};

typedef struct wr_output wr_output;
Expand Down

0 comments on commit 9077139

Please sign in to comment.