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 &mut self, 106 &mut self,
107 connection: &RustConnection, 107 connection: &RustConnection,
108 font: &Font, 108 font: &Font,
109 - windows: &[Window], 109 + windows: &[(Window, String)],
110 focused_window: Option<Window>, 110 focused_window: Option<Window>,
111 ) -> Result<(), X11Error> { 111 ) -> Result<(), X11Error> {
112 connection.change_gc( 112 connection.change_gc(
@@ -142,7 +142,7 @@ impl TabBar {
142 let tab_width = self.width / windows.len() as u16; 142 let tab_width = self.width / windows.len() as u16;
143 let mut x_position: i16 = 0; 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 let is_focused = Some(window) == focused_window; 146 let is_focused = Some(window) == focused_window;
147 let scheme = if is_focused { 147 let scheme = if is_focused {
148 &self.scheme_selected 148 &self.scheme_selected
@@ -150,11 +150,10 @@ impl TabBar {
150 &self.scheme_normal 150 &self.scheme_normal
151 }; 151 };
152 152
153 - let title = self.get_window_title(connection, window);
154 let display_title = if title.is_empty() { 153 let display_title = if title.is_empty() {
155 format!("Window {}", index + 1) 154 format!("Window {}", index + 1)
156 } else { 155 } else {
157 - title 156 + title.clone()
158 }; 157 };
159 158
160 let text_width = font.text_width(&display_title); 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 pub fn get_clicked_window( 215 pub fn get_clicked_window(
232 &self, 216 &self,
233 - windows: &[Window], 217 + windows: &[(Window, String)],
234 click_x: i16, 218 click_x: i16,
235 ) -> Option<Window> { 219 ) -> Option<Window> {
236 if windows.is_empty() { 220 if windows.is_empty() {
@@ -240,7 +224,7 @@ impl TabBar {
240 let tab_width = self.width / windows.len() as u16; 224 let tab_width = self.width / windows.len() as u16;
241 let tab_index = (click_x as u16 / tab_width) as usize; 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 pub fn reposition( 230 pub fn reposition(
+48 −18 src/window_manager.rs
@@ -42,6 +42,7 @@ struct AtomCache {
42 net_wm_window_type_dialog: Atom, 42 net_wm_window_type_dialog: Atom,
43 wm_name: Atom, 43 wm_name: Atom,
44 net_wm_name: Atom, 44 net_wm_name: Atom,
45 + utf8_string: Atom,
45 wm_normal_hints: Atom, 46 wm_normal_hints: Atom,
46 wm_hints: Atom, 47 wm_hints: Atom,
47 wm_transient_for: Atom, 48 wm_transient_for: Atom,
@@ -94,6 +95,7 @@ impl AtomCache {
94 95
95 let wm_name = AtomEnum::WM_NAME.into(); 96 let wm_name = AtomEnum::WM_NAME.into();
96 let net_wm_name = connection.intern_atom(false, b"_NET_WM_NAME")?.reply()?.atom; 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 let wm_normal_hints = AtomEnum::WM_NORMAL_HINTS.into(); 99 let wm_normal_hints = AtomEnum::WM_NORMAL_HINTS.into();
98 let wm_hints = AtomEnum::WM_HINTS.into(); 100 let wm_hints = AtomEnum::WM_HINTS.into();
99 let wm_transient_for = AtomEnum::WM_TRANSIENT_FOR.into(); 101 let wm_transient_for = AtomEnum::WM_TRANSIENT_FOR.into();
@@ -111,6 +113,7 @@ impl AtomCache {
111 net_wm_window_type_dialog, 113 net_wm_window_type_dialog,
112 wm_name, 114 wm_name,
113 net_wm_name, 115 net_wm_name,
116 + utf8_string,
114 wm_normal_hints, 117 wm_normal_hints,
115 wm_hints, 118 wm_hints,
116 wm_transient_for, 119 wm_transient_for,
@@ -690,23 +693,23 @@ impl WindowManager {
690 fn update_tab_bars(&mut self) -> WmResult<()> { 693 fn update_tab_bars(&mut self) -> WmResult<()> {
691 for (monitor_index, monitor) in self.monitors.iter().enumerate() { 694 for (monitor_index, monitor) in self.monitors.iter().enumerate() {
692 if let Some(tab_bar) = self.tab_bars.get_mut(monitor_index) { 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 .windows 697 .windows
695 .iter() 698 .iter()
696 - .filter(|&&window| { 699 + .filter_map(|&window| {
697 if let Some(client) = self.clients.get(&window) { 700 if let Some(client) = self.clients.get(&window) {
698 if client.monitor_index != monitor_index 701 if client.monitor_index != monitor_index
699 || self.floating_windows.contains(&window) 702 || self.floating_windows.contains(&window)
700 || self.fullscreen_windows.contains(&window) 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 .collect(); 713 .collect();
711 714
712 let focused_window = monitor.selected_client; 715 let focused_window = monitor.selected_client;
@@ -2274,6 +2277,7 @@ impl WindowManager {
2274 }; 2277 };
2275 2278
2276 self.focus(Some(next_window))?; 2279 self.focus(Some(next_window))?;
2280 + self.update_tab_bars()?;
2277 2281
2278 Ok(()) 2282 Ok(())
2279 } 2283 }
@@ -2768,6 +2772,7 @@ impl WindowManager {
2768 } 2772 }
2769 } 2773 }
2770 self.focus(Some(event.event))?; 2774 self.focus(Some(event.event))?;
2775 + self.update_tab_bars()?;
2771 } 2776 }
2772 } 2777 }
2773 Event::MotionNotify(event) => { 2778 Event::MotionNotify(event) => {
@@ -2785,6 +2790,7 @@ impl WindowManager {
2785 let visible = self.visible_windows_on_monitor(monitor_index); 2790 let visible = self.visible_windows_on_monitor(monitor_index);
2786 if let Some(&win) = visible.first() { 2791 if let Some(&win) = visible.first() {
2787 self.focus(Some(win))?; 2792 self.focus(Some(win))?;
2793 + self.update_tab_bars()?;
2788 } 2794 }
2789 } 2795 }
2790 } 2796 }
@@ -2885,24 +2891,24 @@ impl WindowManager {
2885 self.selected_monitor = monitor_index; 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 .windows 2895 .windows
2890 .iter() 2896 .iter()
2891 - .filter(|&&window| { 2897 + .filter_map(|&window| {
2892 if let Some(client) = self.clients.get(&window) { 2898 if let Some(client) = self.clients.get(&window) {
2893 if client.monitor_index != monitor_index 2899 if client.monitor_index != monitor_index
2894 || self.floating_windows.contains(&window) 2900 || self.floating_windows.contains(&window)
2895 || self.fullscreen_windows.contains(&window) 2901 || self.fullscreen_windows.contains(&window)
2896 { 2902 {
2897 - return false; 2903 + return None;
2898 } 2904 }
2899 let monitor_tags = self.monitors.get(monitor_index).map(|m| m.tagset[m.selected_tags_index]).unwrap_or(0); 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 2906 + if (client.tags & monitor_tags) != 0 {
2901 - } else { 2907 + return Some((window, client.name.clone()));
2902 - false 2908 + }
2903 } 2909 }
2910 + None
2904 }) 2911 })
2905 - .copied()
2906 .collect(); 2912 .collect();
2907 2913
2908 if let Some(clicked_window) = tab_bar.get_clicked_window(&visible_windows, event.event_x) { 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 } else if event.child != x11rb::NONE { 2922 } else if event.child != x11rb::NONE {
2917 self.focus(Some(event.child))?; 2923 self.focus(Some(event.child))?;
2924 + self.update_tab_bars()?;
2918 2925
2919 if event.detail == ButtonIndex::M1.into() { 2926 if event.detail == ButtonIndex::M1.into() {
2920 self.drag_window(event.child)?; 2927 self.drag_window(event.child)?;
@@ -3474,19 +3481,42 @@ impl WindowManager {
3474 } 3481 }
3475 3482
3476 fn update_window_title(&mut self, window: Window) -> WmResult<()> { 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 .get_property( 3508 .get_property(
3479 false, 3509 false,
3480 window, 3510 window,
3481 - x11rb::protocol::xproto::AtomEnum::WM_NAME, 3511 + self.atoms.wm_name,
3482 x11rb::protocol::xproto::AtomEnum::STRING, 3512 x11rb::protocol::xproto::AtomEnum::STRING,
3483 0, 3513 0,
3484 256, 3514 256,
3485 )? 3515 )?
3486 .reply()?; 3516 .reply()?;
3487 3517
3488 - if !name.value.is_empty() { 3518 + if !wm_name.value.is_empty() {
3489 - if let Ok(title) = String::from_utf8(name.value.clone()) { 3519 + if let Ok(title) = String::from_utf8(wm_name.value.clone()) {
3490 if let Some(client) = self.clients.get_mut(&window) { 3520 if let Some(client) = self.clients.get_mut(&window) {
3491 client.name = title; 3521 client.name = title;
3492 } 3522 }