Fixed clients not going fullscreen by advertising _NET_SUPPORTED on root window so clients know EWMH features are available
Browse files
+63 −6 src/window_manager.rs
| @@ -32,6 +32,7 @@ pub fn unmask_tag(mask: TagMask) -> usize { | |||
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | struct AtomCache { | 34 | struct AtomCache { |
| 35 | + net_supported: Atom, | ||
| 35 | net_current_desktop: Atom, | 36 | net_current_desktop: Atom, |
| 36 | net_client_info: Atom, | 37 | net_client_info: Atom, |
| 37 | wm_state: Atom, | 38 | wm_state: Atom, |
| @@ -49,6 +50,11 @@ struct AtomCache { | |||
| 49 | 50 | ||
| 50 | impl AtomCache { | 51 | impl AtomCache { |
| 51 | fn new(connection: &RustConnection) -> WmResult<Self> { | 52 | fn new(connection: &RustConnection) -> WmResult<Self> { |
| 53 | + let net_supported = connection | ||
| 54 | + .intern_atom(false, b"_NET_SUPPORTED")? | ||
| 55 | + .reply()? | ||
| 56 | + .atom; | ||
| 57 | + | ||
| 52 | let net_current_desktop = connection | 58 | let net_current_desktop = connection |
| 53 | .intern_atom(false, b"_NET_CURRENT_DESKTOP")? | 59 | .intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
| 54 | .reply()? | 60 | .reply()? |
| @@ -103,6 +109,7 @@ impl AtomCache { | |||
| 103 | .atom; | 109 | .atom; |
| 104 | 110 | ||
| 105 | Ok(Self { | 111 | Ok(Self { |
| 112 | + net_supported, | ||
| 106 | net_current_desktop, | 113 | net_current_desktop, |
| 107 | net_client_info, | 114 | net_client_info, |
| 108 | wm_state, | 115 | wm_state, |
| @@ -265,6 +272,31 @@ impl WindowManager { | |||
| 265 | 272 | ||
| 266 | let atoms = AtomCache::new(&connection)?; | 273 | let atoms = AtomCache::new(&connection)?; |
| 267 | 274 | ||
| 275 | + let supported_atoms: Vec<Atom> = vec![ | ||
| 276 | + atoms.net_supported, | ||
| 277 | + atoms.net_wm_state, | ||
| 278 | + atoms.net_wm_state_fullscreen, | ||
| 279 | + atoms.net_wm_window_type, | ||
| 280 | + atoms.net_wm_window_type_dialog, | ||
| 281 | + atoms.net_active_window, | ||
| 282 | + atoms.net_wm_name, | ||
| 283 | + atoms.net_current_desktop, | ||
| 284 | + atoms.net_client_info, | ||
| 285 | + ]; | ||
| 286 | + let supported_bytes: Vec<u8> = supported_atoms | ||
| 287 | + .iter() | ||
| 288 | + .flat_map(|a| a.to_ne_bytes()) | ||
| 289 | + .collect(); | ||
| 290 | + connection.change_property( | ||
| 291 | + PropMode::REPLACE, | ||
| 292 | + root, | ||
| 293 | + atoms.net_supported, | ||
| 294 | + AtomEnum::ATOM, | ||
| 295 | + 32, | ||
| 296 | + supported_atoms.len() as u32, | ||
| 297 | + &supported_bytes, | ||
| 298 | + )?; | ||
| 299 | + | ||
| 268 | let overlay = ErrorOverlay::new( | 300 | let overlay = ErrorOverlay::new( |
| 269 | &connection, | 301 | &connection, |
| 270 | &screen, | 302 | &screen, |
| @@ -1450,6 +1482,25 @@ impl WindowManager { | |||
| 1450 | } | 1482 | } |
| 1451 | } | 1483 | } |
| 1452 | 1484 | ||
| 1485 | + fn get_window_atom_list_property(&self, window: Window, property: Atom) -> WmResult<Vec<Atom>> { | ||
| 1486 | + let reply = self | ||
| 1487 | + .connection | ||
| 1488 | + .get_property(false, window, property, AtomEnum::ATOM, 0, 32)? | ||
| 1489 | + .reply(); | ||
| 1490 | + | ||
| 1491 | + match reply { | ||
| 1492 | + Ok(prop) if !prop.value.is_empty() => { | ||
| 1493 | + let atoms: Vec<Atom> = prop | ||
| 1494 | + .value | ||
| 1495 | + .chunks_exact(4) | ||
| 1496 | + .map(|chunk| u32::from_ne_bytes([chunk[0], chunk[1], chunk[2], chunk[3]])) | ||
| 1497 | + .collect(); | ||
| 1498 | + Ok(atoms) | ||
| 1499 | + } | ||
| 1500 | + _ => Ok(Vec::new()), | ||
| 1501 | + } | ||
| 1502 | + } | ||
| 1503 | + | ||
| 1453 | fn fullscreen(&mut self) -> WmResult<()> { | 1504 | fn fullscreen(&mut self) -> WmResult<()> { |
| 1454 | let Some(focused_window) = self | 1505 | let Some(focused_window) = self |
| 1455 | .monitors | 1506 | .monitors |
| @@ -3170,10 +3221,14 @@ impl WindowManager { | |||
| 3170 | } | 3221 | } |
| 3171 | 3222 | ||
| 3172 | if event.type_ == self.atoms.net_wm_state { | 3223 | if event.type_ == self.atoms.net_wm_state { |
| 3173 | - if let Some(data) = event.data.as_data32().get(1) | 3224 | + let data = event.data.as_data32(); |
| 3174 | - && *data == self.atoms.net_wm_state_fullscreen | 3225 | + let atom1 = data.get(1).copied().unwrap_or(0); |
| 3226 | + let atom2 = data.get(2).copied().unwrap_or(0); | ||
| 3227 | + | ||
| 3228 | + if atom1 == self.atoms.net_wm_state_fullscreen | ||
| 3229 | + || atom2 == self.atoms.net_wm_state_fullscreen | ||
| 3175 | { | 3230 | { |
| 3176 | - let action = event.data.as_data32()[0]; | 3231 | + let action = data[0]; |
| 3177 | let fullscreen = match action { | 3232 | let fullscreen = match action { |
| 3178 | 1 => true, | 3233 | 1 => true, |
| 3179 | 0 => false, | 3234 | 0 => false, |
| @@ -3181,6 +3236,7 @@ impl WindowManager { | |||
| 3181 | _ => return Ok(Control::Continue), | 3236 | _ => return Ok(Control::Continue), |
| 3182 | }; | 3237 | }; |
| 3183 | self.set_window_fullscreen(event.window, fullscreen)?; | 3238 | self.set_window_fullscreen(event.window, fullscreen)?; |
| 3239 | + self.restack()?; | ||
| 3184 | } | 3240 | } |
| 3185 | } else if event.type_ == self.atoms.net_active_window { | 3241 | } else if event.type_ == self.atoms.net_active_window { |
| 3186 | let selected_window = self | 3242 | let selected_window = self |
| @@ -3712,10 +3768,11 @@ impl WindowManager { | |||
| 3712 | } | 3768 | } |
| 3713 | 3769 | ||
| 3714 | fn update_window_type(&mut self, window: Window) -> WmResult<()> { | 3770 | fn update_window_type(&mut self, window: Window) -> WmResult<()> { |
| 3715 | - if let Ok(Some(state_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_state) | 3771 | + if let Ok(state_atoms) = self.get_window_atom_list_property(window, self.atoms.net_wm_state) |
| 3716 | - && state_atom == self.atoms.net_wm_state_fullscreen | ||
| 3717 | { | 3772 | { |
| 3718 | - self.set_window_fullscreen(window, true)?; | 3773 | + if state_atoms.contains(&self.atoms.net_wm_state_fullscreen) { |
| 3774 | + self.set_window_fullscreen(window, true)?; | ||
| 3775 | + } | ||
| 3719 | } | 3776 | } |
| 3720 | 3777 | ||
| 3721 | if let Ok(Some(type_atom)) = | 3778 | if let Ok(Some(type_atom)) = |