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 | let title: Option<String> = config.get("title").ok(); | 392 | let title: Option<String> = config.get("title").ok(); |
| 393 | let is_floating: Option<bool> = config.get("floating").ok(); | 393 | let is_floating: Option<bool> = config.get("floating").ok(); |
| 394 | let monitor: Option<usize> = config.get("monitor").ok(); | 394 | let monitor: Option<usize> = config.get("monitor").ok(); |
| 395 | + let focus: Option<bool> = config.get("focus").ok(); | ||
| 395 | 396 | ||
| 396 | let tags: Option<u32> = if let Ok(tag_index) = config.get::<i32>("tag") { | 397 | let tags: Option<u32> = if let Ok(tag_index) = config.get::<i32>("tag") { |
| 397 | if tag_index > 0 { | 398 | if tag_index > 0 { |
| @@ -408,6 +409,7 @@ fn register_rule_module( | |||
| 408 | instance, | 409 | instance, |
| 409 | title, | 410 | title, |
| 410 | tags, | 411 | tags, |
| 412 | + focus, | ||
| 411 | is_floating, | 413 | is_floating, |
| 412 | monitor, | 414 | monitor, |
| 413 | }; | 415 | }; |
+1 −0 src/lib.rs
| @@ -34,6 +34,7 @@ pub struct WindowRule { | |||
| 34 | pub instance: Option<String>, | 34 | pub instance: Option<String>, |
| 35 | pub title: Option<String>, | 35 | pub title: Option<String>, |
| 36 | pub tags: Option<u32>, | 36 | pub tags: Option<u32>, |
| 37 | + pub focus: Option<bool>, | ||
| 37 | pub is_floating: Option<bool>, | 38 | pub is_floating: Option<bool>, |
| 38 | pub monitor: Option<usize>, | 39 | pub monitor: Option<usize>, |
| 39 | } | 40 | } |
+18 −3 src/window_manager.rs
| @@ -1655,6 +1655,7 @@ impl WindowManager { | |||
| 1655 | let mut rule_tags: Option<u32> = None; | 1655 | let mut rule_tags: Option<u32> = None; |
| 1656 | let mut rule_floating: Option<bool> = None; | 1656 | let mut rule_floating: Option<bool> = None; |
| 1657 | let mut rule_monitor: Option<usize> = None; | 1657 | let mut rule_monitor: Option<usize> = None; |
| 1658 | + let mut rule_focus = false; | ||
| 1658 | 1659 | ||
| 1659 | for rule in &self.config.window_rules { | 1660 | for rule in &self.config.window_rules { |
| 1660 | if rule.matches(&class, &instance, &title) { | 1661 | if rule.matches(&class, &instance, &title) { |
| @@ -1667,6 +1668,7 @@ impl WindowManager { | |||
| 1667 | if rule.monitor.is_some() { | 1668 | if rule.monitor.is_some() { |
| 1668 | rule_monitor = rule.monitor; | 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 | client.monitor_index = monitor_index; | 1688 | client.monitor_index = monitor_index; |
| 1687 | } | 1689 | } |
| 1688 | 1690 | ||
| 1689 | - let tags = rule_tags.unwrap_or_else(|| { | 1691 | + let monitor_tagset = || { |
| 1690 | self.monitors | 1692 | self.monitors |
| 1691 | .get(client.monitor_index) | 1693 | .get(client.monitor_index) |
| 1692 | - .map(|m| m.tagset[m.selected_tags_index]) | 1694 | + .map(|m| m.get_selected_tag()) |
| 1693 | .unwrap_or(tag_mask(0)) | 1695 | .unwrap_or(tag_mask(0)) |
| 1694 | - }); | 1696 | + }; |
| 1697 | + | ||
| 1698 | + let tags = rule_tags.unwrap_or_else(monitor_tagset); | ||
| 1695 | 1699 | ||
| 1696 | client.tags = tags; | 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 | Ok(()) | 1714 | Ok(()) |
+1 −0 templates/config.lua
| @@ -144,6 +144,7 @@ oxwm.gaps.set_outer(5, 5) | |||
| 144 | 144 | ||
| 145 | -- Examples (uncomment to use): | 145 | -- Examples (uncomment to use): |
| 146 | oxwm.rule.add({ instance = "gimp", floating = true }) | 146 | oxwm.rule.add({ instance = "gimp", floating = true }) |
| 147 | +-- oxwm.rule.add({ class = "Alacritty", tag = 9, focus = true }) | ||
| 147 | -- oxwm.rule.add({ class = "firefox", title = "Library", floating = true }) | 148 | -- oxwm.rule.add({ class = "firefox", title = "Library", floating = true }) |
| 148 | -- oxwm.rule.add({ class = "firefox", tag = 2 }) | 149 | -- oxwm.rule.add({ class = "firefox", tag = 2 }) |
| 149 | -- oxwm.rule.add({ instance = "mpv", floating = true }) | 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 | oxwm.rule = {} | 51 | oxwm.rule = {} |
| 52 | 52 | ||
| 53 | ---Add a window rule | 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 | function oxwm.rule.add(rule) end | 55 | function oxwm.rule.add(rule) end |
| 56 | 56 | ||
| 57 | ---Quit the window manager | 57 | ---Quit the window manager |