add focus option to window rules
Browse files
Closes #103
+2 −0 src/config/lua_api.rs
| @@ -392,6 +392,7 @@ fn register_rule_module( | ||
| 392 | 392 | let title: Option<String> = config.get("title").ok(); |
| 393 | 393 | let is_floating: Option<bool> = config.get("floating").ok(); |
| 394 | 394 | let monitor: Option<usize> = config.get("monitor").ok(); |
| 395 | + let focus: Option<bool> = config.get("focus").ok(); | |
| 395 | 396 | |
| 396 | 397 | let tags: Option<u32> = if let Ok(tag_index) = config.get::<i32>("tag") { |
| 397 | 398 | if tag_index > 0 { |
| @@ -408,6 +409,7 @@ fn register_rule_module( | ||
| 408 | 409 | instance, |
| 409 | 410 | title, |
| 410 | 411 | tags, |
| 412 | + focus, | |
| 411 | 413 | is_floating, |
| 412 | 414 | monitor, |
| 413 | 415 | }; |
+1 −0 src/lib.rs
| @@ -34,6 +34,7 @@ pub struct WindowRule { | ||
| 34 | 34 | pub instance: Option<String>, |
| 35 | 35 | pub title: Option<String>, |
| 36 | 36 | pub tags: Option<u32>, |
| 37 | + pub focus: Option<bool>, | |
| 37 | 38 | pub is_floating: Option<bool>, |
| 38 | 39 | pub monitor: Option<usize>, |
| 39 | 40 | } |
+18 −3 src/window_manager.rs
| @@ -1655,6 +1655,7 @@ impl WindowManager { | ||
| 1655 | 1655 | let mut rule_tags: Option<u32> = None; |
| 1656 | 1656 | let mut rule_floating: Option<bool> = None; |
| 1657 | 1657 | let mut rule_monitor: Option<usize> = None; |
| 1658 | + let mut rule_focus = false; | |
| 1658 | 1659 | |
| 1659 | 1660 | for rule in &self.config.window_rules { |
| 1660 | 1661 | if rule.matches(&class, &instance, &title) { |
| @@ -1667,6 +1668,7 @@ impl WindowManager { | ||
| 1667 | 1668 | if rule.monitor.is_some() { |
| 1668 | 1669 | rule_monitor = rule.monitor; |
| 1669 | 1670 | } |
| 1671 | + rule_focus = rule.focus.unwrap_or(false); | |
| 1670 | 1672 | } |
| 1671 | 1673 | } |
| 1672 | 1674 | |
| @@ -1686,14 +1688,27 @@ impl WindowManager { | ||
| 1686 | 1688 | client.monitor_index = monitor_index; |
| 1687 | 1689 | } |
| 1688 | 1690 | |
| 1689 | - let tags = rule_tags.unwrap_or_else(|| { | |
| 1691 | + let monitor_tagset = || { | |
| 1690 | 1692 | self.monitors |
| 1691 | 1693 | .get(client.monitor_index) |
| 1692 | - .map(|m| m.tagset[m.selected_tags_index]) | |
| 1694 | + .map(|m| m.get_selected_tag()) | |
| 1693 | 1695 | .unwrap_or(tag_mask(0)) |
| 1694 | - }); | |
| 1696 | + }; | |
| 1697 | + | |
| 1698 | + let tags = rule_tags.unwrap_or_else(monitor_tagset); | |
| 1695 | 1699 | |
| 1696 | 1700 | client.tags = tags; |
| 1701 | + | |
| 1702 | + // Focus window rule tag if config option is set | |
| 1703 | + if rule_focus && let Some(tag_mask) = rule_tags { | |
| 1704 | + let tag_index = unmask_tag(tag_mask); | |
| 1705 | + let monitor_tagset = monitor_tagset(); | |
| 1706 | + let is_tag_focused = monitor_tagset & tag_mask == tag_mask; | |
| 1707 | + | |
| 1708 | + if !is_tag_focused { | |
| 1709 | + self.view_tag(tag_index)?; | |
| 1710 | + } | |
| 1711 | + } | |
| 1697 | 1712 | } |
| 1698 | 1713 | |
| 1699 | 1714 | Ok(()) |
+1 −0 templates/config.lua
| @@ -144,6 +144,7 @@ oxwm.gaps.set_outer(5, 5) | ||
| 144 | 144 | |
| 145 | 145 | -- Examples (uncomment to use): |
| 146 | 146 | oxwm.rule.add({ instance = "gimp", floating = true }) |
| 147 | +-- oxwm.rule.add({ class = "Alacritty", tag = 9, focus = true }) | |
| 147 | 148 | -- oxwm.rule.add({ class = "firefox", title = "Library", floating = true }) |
| 148 | 149 | -- oxwm.rule.add({ class = "firefox", tag = 2 }) |
| 149 | 150 | -- oxwm.rule.add({ instance = "mpv", floating = true }) |
+1 −1 templates/oxwm.lua
| @@ -51,7 +51,7 @@ function oxwm.set_layout_symbol(name, symbol) end | ||
| 51 | 51 | oxwm.rule = {} |
| 52 | 52 | |
| 53 | 53 | ---Add a window rule |
| 54 | ----@param rule {class: string?, instance: string?, title: string?, role: string?, floating: boolean?, tag: integer?, fullscreen: boolean?} Rule configuration | |
| 54 | +---@param rule {class: string?, instance: string?, title: string?, role: string?, floating: boolean?, tag: integer?, fullscreen: boolean?, focus: boolean?} Rule configuration | |
| 55 | 55 | function oxwm.rule.add(rule) end |
| 56 | 56 | |
| 57 | 57 | ---Quit the window manager |