Some simplifications

timeout_old
Tassilo Horn 3 years ago
parent d83acacea0
commit 22fa8591c7
  1. 54
      src/cmds.rs
  2. 26
      src/con.rs
  3. 2
      src/layout.rs

@ -196,27 +196,25 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
match args.cmd {
SwayrCommand::SwitchToUrgentOrLRUWindow => {
switch_to_urgent_or_lru_window(Some(&*props.read().unwrap()))
}
SwayrCommand::SwitchWindow => {
switch_window(Some(&*props.read().unwrap()))
switch_to_urgent_or_lru_window(&*props.read().unwrap())
}
SwayrCommand::SwitchWindow => switch_window(&*props.read().unwrap()),
SwayrCommand::NextWindow { windows } => focus_window_in_direction(
Direction::Forward,
windows,
Some(&*props.read().unwrap()),
&*props.read().unwrap(),
Box::new(always_true),
),
SwayrCommand::PrevWindow { windows } => focus_window_in_direction(
Direction::Backward,
windows,
Some(&*props.read().unwrap()),
&*props.read().unwrap(),
Box::new(always_true),
),
SwayrCommand::NextTiledWindow { windows } => focus_window_in_direction(
Direction::Forward,
windows,
Some(&*props.read().unwrap()),
&*props.read().unwrap(),
Box::new(|w: &con::Window| {
!w.is_floating() && w.is_child_of_tiled_container()
}),
@ -224,7 +222,7 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
SwayrCommand::PrevTiledWindow { windows } => focus_window_in_direction(
Direction::Backward,
windows,
Some(&*props.read().unwrap()),
&*props.read().unwrap(),
Box::new(|w: &con::Window| {
!w.is_floating() && w.is_child_of_tiled_container()
}),
@ -233,7 +231,7 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
focus_window_in_direction(
Direction::Forward,
windows,
Some(&*props.read().unwrap()),
&*props.read().unwrap(),
Box::new(|w: &con::Window| {
!w.is_floating()
&& w.is_child_of_tabbed_or_stacked_container()
@ -244,7 +242,7 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
focus_window_in_direction(
Direction::Backward,
windows,
Some(&*props.read().unwrap()),
&*props.read().unwrap(),
Box::new(|w: &con::Window| {
!w.is_floating()
&& w.is_child_of_tabbed_or_stacked_container()
@ -255,7 +253,7 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
focus_window_in_direction(
Direction::Forward,
windows,
Some(&*props.read().unwrap()),
&*props.read().unwrap(),
Box::new(|w: &con::Window| w.is_floating()),
)
}
@ -263,7 +261,7 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
focus_window_in_direction(
Direction::Backward,
windows,
Some(&*props.read().unwrap()),
&*props.read().unwrap(),
Box::new(|w: &con::Window| w.is_floating()),
)
}
@ -271,25 +269,25 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
focus_similar_window_in_direction(
Direction::Forward,
windows,
Some(&*props.read().unwrap()),
&*props.read().unwrap(),
)
}
SwayrCommand::PrevSimilarWindow { windows } => {
focus_similar_window_in_direction(
Direction::Backward,
windows,
Some(&*props.read().unwrap()),
&*props.read().unwrap(),
)
}
SwayrCommand::QuitWindow => quit_window(Some(&*props.read().unwrap())),
SwayrCommand::QuitWindow => quit_window(&*props.read().unwrap()),
SwayrCommand::SwitchWorkspace => {
switch_workspace(Some(&*props.read().unwrap()))
switch_workspace(&*props.read().unwrap())
}
SwayrCommand::SwitchWorkspaceOrWindow => {
switch_workspace_or_window(Some(&*props.read().unwrap()))
switch_workspace_or_window(&*props.read().unwrap())
}
SwayrCommand::QuitWorkspaceOrWindow => {
quit_workspace_or_window(Some(&*props.read().unwrap()))
quit_workspace_or_window(&*props.read().unwrap())
}
SwayrCommand::TileWorkspace { floating } => {
tile_current_workspace(floating, false)
@ -381,7 +379,7 @@ pub fn get_tree() -> s::Node {
}
pub fn switch_to_urgent_or_lru_window(
extra_props: Option<&HashMap<i64, con::ExtraProps>>,
extra_props: &HashMap<i64, con::ExtraProps>,
) {
let root = get_tree();
let windows = con::get_windows(&root, false, extra_props);
@ -397,7 +395,7 @@ pub fn switch_to_urgent_or_lru_window(
}
}
pub fn switch_window(extra_props: Option<&HashMap<i64, con::ExtraProps>>) {
pub fn switch_window(extra_props: &HashMap<i64, con::ExtraProps>) {
let root = get_tree();
let windows = con::get_windows(&root, true, extra_props);
@ -414,7 +412,7 @@ pub enum Direction {
pub fn focus_window_in_direction(
dir: Direction,
consider_wins: &ConsiderWindows,
extra_props: Option<&HashMap<i64, con::ExtraProps>>,
extra_props: &HashMap<i64, con::ExtraProps>,
pred: Box<dyn Fn(&con::Window) -> bool>,
) {
let root = get_tree();
@ -471,7 +469,7 @@ pub fn focus_window_in_direction(
pub fn focus_similar_window_in_direction(
dir: Direction,
consider_wins: &ConsiderWindows,
extra_props: Option<&HashMap<i64, con::ExtraProps>>,
extra_props: &HashMap<i64, con::ExtraProps>,
) {
let root = get_tree();
let windows = con::get_windows(&root, false, extra_props);
@ -507,7 +505,7 @@ pub fn focus_similar_window_in_direction(
}
}
pub fn switch_workspace(extra_props: Option<&HashMap<i64, con::ExtraProps>>) {
pub fn switch_workspace(extra_props: &HashMap<i64, con::ExtraProps>) {
let root = get_tree();
let workspaces = con::get_workspaces(&root, false, extra_props);
@ -518,9 +516,7 @@ pub fn switch_workspace(extra_props: Option<&HashMap<i64, con::ExtraProps>>) {
}
}
pub fn switch_workspace_or_window(
extra_props: Option<&HashMap<i64, con::ExtraProps>>,
) {
pub fn switch_workspace_or_window(extra_props: &HashMap<i64, con::ExtraProps>) {
let root = get_tree();
let workspaces = con::get_workspaces(&root, true, extra_props);
let ws_or_wins = con::WsOrWin::from_workspaces(&workspaces);
@ -537,7 +533,7 @@ pub fn switch_workspace_or_window(
}
}
pub fn quit_window(extra_props: Option<&HashMap<i64, con::ExtraProps>>) {
pub fn quit_window(extra_props: &HashMap<i64, con::ExtraProps>) {
let root = get_tree();
let windows = con::get_windows(&root, true, extra_props);
@ -546,9 +542,7 @@ pub fn quit_window(extra_props: Option<&HashMap<i64, con::ExtraProps>>) {
}
}
pub fn quit_workspace_or_window(
extra_props: Option<&HashMap<i64, con::ExtraProps>>,
) {
pub fn quit_workspace_or_window(extra_props: &HashMap<i64, con::ExtraProps>) {
let root = get_tree();
let workspaces = con::get_workspaces(&root, true, extra_props);
let ws_or_wins = con::WsOrWin::from_workspaces(&workspaces);

@ -316,7 +316,7 @@ impl<'a> DisplayFormat for Window<'a> {
fn build_windows<'a>(
root: &'a s::Node,
include_scratchpad_windows: bool,
extra_props: Option<&HashMap<i64, ExtraProps>>,
extra_props: &HashMap<i64, ExtraProps>,
) -> Vec<Window<'a>> {
let mut v = vec![];
for workspace in root.workspaces() {
@ -327,7 +327,7 @@ fn build_windows<'a>(
for n in workspace.windows() {
v.push(Window {
node: n,
extra_props: extra_props.and_then(|m| m.get(&n.id).cloned()),
extra_props: extra_props.get(&n.id).cloned(),
workspace,
})
}
@ -338,7 +338,7 @@ fn build_windows<'a>(
fn build_workspaces<'a>(
root: &'a s::Node,
include_scratchpad: bool,
extra_props: Option<&HashMap<i64, ExtraProps>>,
extra_props: &HashMap<i64, ExtraProps>,
) -> Vec<Workspace<'a>> {
let mut v = vec![];
for workspace in root.workspaces() {
@ -353,19 +353,22 @@ fn build_workspaces<'a>(
.iter()
.map(|w| Window {
node: w,
extra_props: extra_props.and_then(|m| m.get(&w.id).cloned()),
extra_props: extra_props.get(&w.id).cloned(),
workspace,
})
.collect();
wins.sort();
if !extra_props.is_empty() {
wins.sort();
}
v.push(Workspace {
node: workspace,
extra_props: extra_props
.and_then(|m| m.get(&workspace.id).cloned()),
extra_props: extra_props.get(&workspace.id).cloned(),
windows: wins,
})
}
v.sort();
if !extra_props.is_empty() {
v.sort();
}
v
}
@ -373,11 +376,10 @@ fn build_workspaces<'a>(
pub fn get_windows<'a>(
root: &'a s::Node,
include_scratchpad_windows: bool,
extra_props: Option<&HashMap<i64, ExtraProps>>,
extra_props: &HashMap<i64, ExtraProps>,
) -> Vec<Window<'a>> {
let extra_props_given = extra_props.is_some();
let mut wins = build_windows(root, include_scratchpad_windows, extra_props);
if extra_props_given {
if !extra_props.is_empty() {
wins.sort();
}
wins
@ -387,7 +389,7 @@ pub fn get_windows<'a>(
pub fn get_workspaces<'a>(
root: &'a s::Node,
include_scratchpad: bool,
extra_props: Option<&HashMap<i64, ExtraProps>>,
extra_props: &HashMap<i64, ExtraProps>,
) -> Vec<Workspace<'a>> {
let mut workspaces =
build_workspaces(root, include_scratchpad, extra_props);

@ -134,7 +134,7 @@ pub fn relayout_current_workspace(
>,
) -> s::Fallible<()> {
let root = cmds::get_tree();
let workspaces = con::get_workspaces(&root, false, None);
let workspaces = con::get_workspaces(&root, false, &HashMap::new());
if let Some(cur_ws) = workspaces.iter().find(|ws| ws.is_current()) {
if let Ok(mut con) = s::Connection::new() {
let mut moved_wins: Vec<&con::Window> = vec![];

Loading…
Cancel
Save