Added "geometry" impl to drawin
use std::default::Default;
use std::fmt::{self, Display, Formatter};
use std::rc::Rc;
-use rustwlc::Geometry;
+use rustwlc::{Geometry, Point, Size};
use rlua::{self, Table, Lua, UserData, ToLua, Value};
use super::drawable::Drawable;
use super::property::Property;
@@ -57,7 +57,7 @@ impl <'lua> Drawin<'lua> {
let table = &self.0;
let mut drawable = Drawable::cast(table.get::<_, Table>("drawable")?.into())?;
drawable.set_geometry(state.geometry)?;
- table.set::<_, Table>("drawable", drawable.get_table())?;
+ table.raw_set::<_, Table>("drawable", drawable.get_table())?;
Ok(())
}
@@ -77,6 +77,27 @@ impl <'lua> Drawin<'lua> {
// TODO other things
self.update_drawing()
}
+
+ fn get_geometry(&self) -> rlua::Result<Geometry> {
+ Ok(self.state()?.geometry)
+ }
+
+ fn resize(&mut self, geometry: Geometry) -> rlua::Result<()> {
+ let mut state = self.state()?;
+ let old_geometry = state.geometry;
+ state.geometry = geometry;
+ if state.geometry.size.w <= 0 {
+ state.geometry.size.w = old_geometry.size.w;
+ }
+ if state.geometry.size.h <= 0 {
+ state.geometry.size.h = old_geometry.size.h
+ }
+ state.geometry_dirty = true;
+ self.update_drawing()?;
+ // TODO emit signals
+ // TODO update screen workareas like in awesome? Might not be necessary
+ self.set_state(state)
+ }
}
impl <'lua> ToLua<'lua> for Drawin<'lua> {
@@ -113,6 +134,7 @@ fn object_setup<'lua>(lua: &'lua Lua, builder: ObjectBuilder<'lua>) -> rlua::Res
let table = lua.create_table();
let drawable_table = Drawable::new(lua)?.to_lua(lua)?;
table.set("drawable", drawable_table)?;
+ table.set("geometry", lua.create_function(drawin_geometry))?;
builder.add_to_meta(table)
}
@@ -128,3 +150,27 @@ fn get_visible<'lua>(_: &'lua Lua, table: Table<'lua>) -> rlua::Result<bool> {
drawin.get_visible()
// TODO signal
}
+
+fn drawin_geometry<'lua>(lua: &'lua Lua, (drawin, geometry): (Table<'lua>, Table<'lua>)) -> rlua::Result<Table<'lua>> {
+ let mut drawin = Drawin::cast(drawin.into())?;
+ let w = geometry.get::<_, i32>("width")?;
+ let h = geometry.get::<_, i32>("height")?;
+ let x = geometry.get::<_, i32>("x")?;
+ let y = geometry.get::<_, i32>("y")?;
+ if x > 0 && y > 0 {
+ let geo = Geometry {
+ origin: Point { x, y },
+ size: Size { w: w as u32, h: h as u32 }
+ };
+ drawin.resize(geo)?;
+ }
+ let new_geo = drawin.get_geometry()?;
+ let Size { w, h } = new_geo.size;
+ let Point { x, y } = new_geo.origin;
+ let res = lua.create_table();
+ res.set("x", x)?;
+ res.set("y", y)?;
+ res.set("height", h)?;
+ res.set("width", w)?;
+ Ok(res)
+}
