Skip to content
This repository has been archived by the owner on Jan 11, 2020. It is now read-only.

Commit

Permalink
Fixes #156, #152 Popups are not part of tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Timidger committed Dec 9, 2016
1 parent b2642b1 commit d884071
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
47 changes: 27 additions & 20 deletions src/layout/actions/layout.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::cmp;

use petgraph::graph::NodeIndex;
use rustwlc::{Geometry, Point, Size, ResizeEdge};
use rustwlc::{Geometry, Point, Size, ResizeEdge, ViewType};

use super::super::{LayoutTree, TreeError};
use super::super::commands::CommandResult;
use super::super::core::container::{Container, ContainerType, Layout};
use super::super::core::container::{Container, ContainerType, Layout, Handle};
use uuid::Uuid;

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
Expand Down Expand Up @@ -243,6 +243,10 @@ impl LayoutTree {
}
let output_ix = try!(self.tree.ancestor_of_type(node_ix, ContainerType::Output)
.map_err(|err| TreeError::PetGraph(err)));
let handle = match self.tree[node_ix].get_handle() {
Some(Handle::View(view)) => view,
_ => unreachable!()
};
let output_size = match self.tree[output_ix] {
Container::Output { handle, .. } => {
handle.get_resolution().expect("Output had no resolution")
Expand All @@ -254,25 +258,28 @@ impl LayoutTree {
try!(container.set_floating(true)
.map_err(|_| TreeError::UuidWrongType(id, vec!(ContainerType::View,
ContainerType::Container))));
let new_geometry = Geometry {
size: Size {
h: output_size.h / 2,
w: output_size.w / 2
// We float pop-ups as soon as they spawn, this is so we don't resize them
if handle.get_type() == ViewType::empty() {
let new_geometry = Geometry {
size: Size {
h: output_size.h / 2,
w: output_size.w / 2
},
origin: Point {
x: (output_size.w / 2 - output_size.w / 4) as i32 ,
y: (output_size.h / 2 - output_size.h / 4) as i32
}
};
match *container {
Container::View { handle, .. } => {
handle.set_geometry(ResizeEdge::empty(), new_geometry);
},
origin: Point {
x: (output_size.w / 2 - output_size.w / 4) as i32 ,
y: (output_size.h / 2 - output_size.h / 4) as i32
}
};
match *container {
Container::View { handle, .. } => {
handle.set_geometry(ResizeEdge::empty(), new_geometry);
},
Container::Container { ref mut geometry, .. } => {
*geometry = new_geometry
},
_ => return Err(TreeError::UuidWrongType(id, vec!(ContainerType::View,
ContainerType::Container)))
Container::Container { ref mut geometry, .. } => {
*geometry = new_geometry
},
_ => return Err(TreeError::UuidWrongType(id, vec!(ContainerType::View,
ContainerType::Container)))
}
}
}
let root_ix = self.tree.root_ix();
Expand Down
13 changes: 9 additions & 4 deletions src/layout/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ impl Tree {

/// Adds a view to the workspace of the active container
pub fn add_view(&mut self, view: WlcView) -> CommandResult {
// TODO Move this out of commands
let tree = &mut self.0;
let output = view.get_output();
if tree.get_active_container().is_none() {
Expand All @@ -276,14 +277,14 @@ impl Tree {
let v_type = view.get_type();
let v_class = view.get_class();
// If it is empty, don't add to tree
if v_type != ViewType::empty() {
/*if v_type != ViewType::empty() {
// Now focused on something outside the tree,
// have to unset the active container
if !tree.active_is_root() {
tree.unset_active_container();
}
return Ok(())
}
}*/
if v_class.as_str() == "Background" {
info!("Setting background: {}", view.get_title());
view.send_to_back();
Expand All @@ -297,8 +298,12 @@ impl Tree {
view.set_geometry(ResizeEdge::empty(), fullscreen);
return Ok(());
}
try!(tree.add_view(view));
tree.normalize_view(view);
let c_id = try!(tree.add_view(view)).get_id();
if v_type != ViewType::empty() {
try!(tree.float_container(c_id));
} else {
tree.normalize_view(view);
}
tree.layout_active_of(ContainerType::Workspace);
Ok(())
}
Expand Down
5 changes: 3 additions & 2 deletions src/layout/core/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl LayoutTree {
}

/// Add a new view container with the given WlcView to the active container
pub fn add_view(&mut self, view: WlcView) -> CommandResult {
pub fn add_view(&mut self, view: WlcView) -> Result<&Container, TreeError> {
if let Some(mut active_ix) = self.active_container {
let parent_ix = self.tree.parent_of(active_ix)
.expect("Active container had no parent");
Expand All @@ -258,7 +258,8 @@ impl LayoutTree {
true);
self.tree.set_child_pos(view_ix, prev_pos);
self.validate();
return self.set_active_node(view_ix)
try!(self.set_active_node(view_ix));
return Ok(&self.tree[view_ix])
}
self.validate();
Err(TreeError::NoActiveContainer)
Expand Down

0 comments on commit d884071

Please sign in to comment.