tony / oxwm

Fixed tabbed mode cycling tabs -> update tab bar, and show titles Browse files
tonybtw committed 2025-12-02 parent 4eae09c commit ced2a2a3741eaebe22dada92630629f64f0f4e1d
Showing 2 changed files with 53 additions and 39 deletions. UnifiedSplit
+5 −21 src/tab_bar.rs
@@ -106,7 +106,7 @@ impl TabBar {
106 106 &mut self,
107 107 connection: &RustConnection,
108 108 font: &Font,
109 - windows: &[Window],
109 + windows: &[(Window, String)],
110 110 focused_window: Option<Window>,
111 111 ) -> Result<(), X11Error> {
112 112 connection.change_gc(
@@ -142,7 +142,7 @@ impl TabBar {
142 142 let tab_width = self.width / windows.len() as u16;
143 143 let mut x_position: i16 = 0;
144 144
145 - for (index, &window) in windows.iter().enumerate() {
145 + for (index, &(window, ref title)) in windows.iter().enumerate() {
146 146 let is_focused = Some(window) == focused_window;
147 147 let scheme = if is_focused {
148 148 &self.scheme_selected
@@ -150,11 +150,10 @@ impl TabBar {
150 150 &self.scheme_normal
151 151 };
152 152
153 - let title = self.get_window_title(connection, window);
154 153 let display_title = if title.is_empty() {
155 154 format!("Window {}", index + 1)
156 155 } else {
157 - title
156 + title.clone()
158 157 };
159 158
160 159 let text_width = font.text_width(&display_title);
@@ -213,24 +212,9 @@ impl TabBar {
213 212 }
214 213 }
215 214
216 - fn get_window_title(&self, connection: &RustConnection, window: Window) -> String {
217 - connection
218 - .get_property(false, window, AtomEnum::WM_NAME, AtomEnum::STRING, 0, 1024)
219 - .ok()
220 - .and_then(|cookie| cookie.reply().ok())
221 - .and_then(|reply| {
222 - if reply.value.is_empty() {
223 - None
224 - } else {
225 - std::str::from_utf8(&reply.value).ok().map(|s| s.to_string())
226 - }
227 - })
228 - .unwrap_or_default()
229 - }
230 -
231 215 pub fn get_clicked_window(
232 216 &self,
233 - windows: &[Window],
217 + windows: &[(Window, String)],
234 218 click_x: i16,
235 219 ) -> Option<Window> {
236 220 if windows.is_empty() {
@@ -240,7 +224,7 @@ impl TabBar {
240 224 let tab_width = self.width / windows.len() as u16;
241 225 let tab_index = (click_x as u16 / tab_width) as usize;
242 226
243 - windows.get(tab_index).copied()
227 + windows.get(tab_index).map(|&(win, _)| win)
244 228 }
245 229
246 230 pub fn reposition(
+48 −18 src/window_manager.rs
@@ -42,6 +42,7 @@ struct AtomCache {
42 42 net_wm_window_type_dialog: Atom,
43 43 wm_name: Atom,
44 44 net_wm_name: Atom,
45 + utf8_string: Atom,
45 46 wm_normal_hints: Atom,
46 47 wm_hints: Atom,
47 48 wm_transient_for: Atom,
@@ -94,6 +95,7 @@ impl AtomCache {
94 95
95 96 let wm_name = AtomEnum::WM_NAME.into();
96 97 let net_wm_name = connection.intern_atom(false, b"_NET_WM_NAME")?.reply()?.atom;
98 + let utf8_string = connection.intern_atom(false, b"UTF8_STRING")?.reply()?.atom;
97 99 let wm_normal_hints = AtomEnum::WM_NORMAL_HINTS.into();
98 100 let wm_hints = AtomEnum::WM_HINTS.into();
99 101 let wm_transient_for = AtomEnum::WM_TRANSIENT_FOR.into();
@@ -111,6 +113,7 @@ impl AtomCache {
111 113 net_wm_window_type_dialog,
112 114 wm_name,
113 115 net_wm_name,
116 + utf8_string,
114 117 wm_normal_hints,
115 118 wm_hints,
116 119 wm_transient_for,
@@ -690,23 +693,23 @@ impl WindowManager {
690 693 fn update_tab_bars(&mut self) -> WmResult<()> {
691 694 for (monitor_index, monitor) in self.monitors.iter().enumerate() {
692 695 if let Some(tab_bar) = self.tab_bars.get_mut(monitor_index) {
693 - let visible_windows: Vec<Window> = self
696 + let visible_windows: Vec<(Window, String)> = self
694 697 .windows
695 698 .iter()
696 - .filter(|&&window| {
699 + .filter_map(|&window| {
697 700 if let Some(client) = self.clients.get(&window) {
698 701 if client.monitor_index != monitor_index
699 702 || self.floating_windows.contains(&window)
700 703 || self.fullscreen_windows.contains(&window)
701 704 {
702 - return false;
705 + return None;
706 + }
707 + if (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0 {
708 + return Some((window, client.name.clone()));
703 709 }
704 - (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0
705 - } else {
706 - false
707 710 }
711 + None
708 712 })
709 - .copied()
710 713 .collect();
711 714
712 715 let focused_window = monitor.selected_client;
@@ -2274,6 +2277,7 @@ impl WindowManager {
2274 2277 };
2275 2278
2276 2279 self.focus(Some(next_window))?;
2280 + self.update_tab_bars()?;
2277 2281
2278 2282 Ok(())
2279 2283 }
@@ -2768,6 +2772,7 @@ impl WindowManager {
2768 2772 }
2769 2773 }
2770 2774 self.focus(Some(event.event))?;
2775 + self.update_tab_bars()?;
2771 2776 }
2772 2777 }
2773 2778 Event::MotionNotify(event) => {
@@ -2785,6 +2790,7 @@ impl WindowManager {
2785 2790 let visible = self.visible_windows_on_monitor(monitor_index);
2786 2791 if let Some(&win) = visible.first() {
2787 2792 self.focus(Some(win))?;
2793 + self.update_tab_bars()?;
2788 2794 }
2789 2795 }
2790 2796 }
@@ -2885,24 +2891,24 @@ impl WindowManager {
2885 2891 self.selected_monitor = monitor_index;
2886 2892 }
2887 2893
2888 - let visible_windows: Vec<Window> = self
2894 + let visible_windows: Vec<(Window, String)> = self
2889 2895 .windows
2890 2896 .iter()
2891 - .filter(|&&window| {
2897 + .filter_map(|&window| {
2892 2898 if let Some(client) = self.clients.get(&window) {
2893 2899 if client.monitor_index != monitor_index
2894 2900 || self.floating_windows.contains(&window)
2895 2901 || self.fullscreen_windows.contains(&window)
2896 2902 {
2897 - return false;
2903 + return None;
2898 2904 }
2899 2905 let monitor_tags = self.monitors.get(monitor_index).map(|m| m.tagset[m.selected_tags_index]).unwrap_or(0);
2900 - (client.tags & monitor_tags) != 0
2901 - } else {
2902 - false
2906 + if (client.tags & monitor_tags) != 0 {
2907 + return Some((window, client.name.clone()));
2908 + }
2903 2909 }
2910 + None
2904 2911 })
2905 - .copied()
2906 2912 .collect();
2907 2913
2908 2914 if let Some(clicked_window) = tab_bar.get_clicked_window(&visible_windows, event.event_x) {
@@ -2915,6 +2921,7 @@ impl WindowManager {
2915 2921 }
2916 2922 } else if event.child != x11rb::NONE {
2917 2923 self.focus(Some(event.child))?;
2924 + self.update_tab_bars()?;
2918 2925
2919 2926 if event.detail == ButtonIndex::M1.into() {
2920 2927 self.drag_window(event.child)?;
@@ -3474,19 +3481,42 @@ impl WindowManager {
3474 3481 }
3475 3482
3476 3483 fn update_window_title(&mut self, window: Window) -> WmResult<()> {
3477 - let name = self.connection
3484 + let net_name = self.connection
3485 + .get_property(
3486 + false,
3487 + window,
3488 + self.atoms.net_wm_name,
3489 + self.atoms.utf8_string,
3490 + 0,
3491 + 256,
3492 + )
3493 + .ok()
3494 + .and_then(|cookie| cookie.reply().ok());
3495 +
3496 + if let Some(name) = net_name {
3497 + if !name.value.is_empty() {
3498 + if let Ok(title) = String::from_utf8(name.value.clone()) {
3499 + if let Some(client) = self.clients.get_mut(&window) {
3500 + client.name = title;
3501 + return Ok(());
3502 + }
3503 + }
3504 + }
3505 + }
3506 +
3507 + let wm_name = self.connection
3478 3508 .get_property(
3479 3509 false,
3480 3510 window,
3481 - x11rb::protocol::xproto::AtomEnum::WM_NAME,
3511 + self.atoms.wm_name,
3482 3512 x11rb::protocol::xproto::AtomEnum::STRING,
3483 3513 0,
3484 3514 256,
3485 3515 )?
3486 3516 .reply()?;
3487 3517
3488 - if !name.value.is_empty() {
3489 - if let Ok(title) = String::from_utf8(name.value.clone()) {
3518 + if !wm_name.value.is_empty() {
3519 + if let Ok(title) = String::from_utf8(wm_name.value.clone()) {
3490 3520 if let Some(client) = self.clients.get_mut(&window) {
3491 3521 client.name = title;
3492 3522 }