Commit cd60cc79 authored by Jeremy Soller's avatar Jeremy Soller

Redo method of getting paths

parent 4c3941e1
......@@ -2,7 +2,7 @@
name = "orbclient"
description = "The Orbital Client Library"
repository = "https://github.com/redox-os/orbclient"
version = "0.1.21"
version = "0.1.22"
license-file = "LICENSE"
readme = "README.md"
keywords = ["orbital", "redox", "ui"]
......
#![crate_name="orbclient"]
#![crate_type="lib"]
#![cfg_attr(target_os = "redox", feature(asm))]
#![cfg_attr(target_os = "redox", feature(file_path))]
#![feature(const_fn)]
#![deny(warnings)]
......
use std::env;
use std::fs::File;
use std::os::unix::io::AsRawFd;
use super::syscall;
pub fn get_display_size() -> Result<(u32, u32), String> {
let display_path = try!(env::var("DISPLAY").or(Err("DISPLAY not set")));
match File::open(&display_path) {
Ok(display) => {
let path = display.path().map(|path| path.into_os_string().into_string().unwrap_or(String::new())).unwrap_or(String::new());
let mut buf: [u8; 4096] = [0; 4096];
let count = syscall::fpath(display.as_raw_fd() as usize, &mut buf).map_err(|err| format!("{}", err))?;
let path = unsafe { String::from_utf8_unchecked(Vec::from(&buf[..count])) };
let res = path.split(":").nth(1).unwrap_or("");
let width = res.split("/").nth(1).unwrap_or("").parse::<u32>().unwrap_or(0);
let height = res.split("/").nth(2).unwrap_or("").parse::<u32>().unwrap_or(0);
......
extern crate syscall;
pub use self::display::*;
pub use self::window::*;
......
extern crate syscall;
use std::cmp;
use std::{cmp, mem, slice, thread};
use std::fs::File;
use std::io::*;
use std::mem;
use std::io::Read;
use std::os::unix::io::{AsRawFd, RawFd};
use std::slice;
use std::thread;
use super::syscall;
#[cfg(target_arch = "x86")]
#[inline(always)]
......@@ -86,22 +83,22 @@ impl Window {
// TODO: Replace with smarter mechanism, maybe a move event?
pub fn sync_path(&mut self) {
if let Ok(path) = self.file.path() {
let mut buf: [u8; 4096] = [0; 4096];
if let Ok(count) = syscall::fpath(self.file.as_raw_fd() as usize, &mut buf) {
let path = unsafe { String::from_utf8_unchecked(Vec::from(&buf[..count])) };
// orbital:/x/y/w/h/t
if let Some(path_str) = path.to_str() {
let mut parts = path_str.split('/').skip(1);
if let Some(x) = parts.next() {
self.x = x.parse::<i32>().unwrap_or(0);
}
if let Some(y) = parts.next() {
self.y = y.parse::<i32>().unwrap_or(0);
}
if let Some(w) = parts.next() {
self.w = w.parse::<u32>().unwrap_or(0);
}
if let Some(h) = parts.next() {
self.h = h.parse::<u32>().unwrap_or(0);
}
let mut parts = path.split('/').skip(1);
if let Some(x) = parts.next() {
self.x = x.parse::<i32>().unwrap_or(0);
}
if let Some(y) = parts.next() {
self.y = y.parse::<i32>().unwrap_or(0);
}
if let Some(w) = parts.next() {
self.w = w.parse::<u32>().unwrap_or(0);
}
if let Some(h) = parts.next() {
self.h = h.parse::<u32>().unwrap_or(0);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment