Removed old fullscreen logic and used i3 logic for fullscreen windows.
Browse files
+62 −190 src/window_manager.rs
| @@ -127,11 +127,9 @@ pub struct WindowManager { | ||
| 127 | 127 | gaps_enabled: bool, |
| 128 | 128 | floating_windows: HashSet<Window>, |
| 129 | 129 | fullscreen_windows: HashSet<Window>, |
| 130 | - floating_geometry_before_fullscreen: HashMap<Window, (i16, i16, u16, u16, u16)>, | |
| 131 | 130 | bars: Vec<Bar>, |
| 132 | 131 | tab_bars: Vec<crate::tab_bar::TabBar>, |
| 133 | 132 | show_bar: bool, |
| 134 | - last_layout: Option<&'static str>, | |
| 135 | 133 | monitors: Vec<Monitor>, |
| 136 | 134 | selected_monitor: usize, |
| 137 | 135 | atoms: AtomCache, |
| @@ -286,11 +284,9 @@ impl WindowManager { | ||
| 286 | 284 | gaps_enabled, |
| 287 | 285 | floating_windows: HashSet::new(), |
| 288 | 286 | fullscreen_windows: HashSet::new(), |
| 289 | - floating_geometry_before_fullscreen: HashMap::new(), | |
| 290 | 287 | bars, |
| 291 | 288 | tab_bars, |
| 292 | 289 | show_bar: true, |
| 293 | - last_layout: None, | |
| 294 | 290 | monitors, |
| 295 | 291 | selected_monitor: 0, |
| 296 | 292 | atoms, |
| @@ -749,13 +745,6 @@ impl WindowManager { | ||
| 749 | 745 | } |
| 750 | 746 | } |
| 751 | 747 | KeyAction::ToggleFullScreen => { |
| 752 | - // Disable gaps and save previous state in config if not already in fullscreen | |
| 753 | - if self.fullscreen_windows.is_empty() { | |
| 754 | - self.config.gaps_enabled = std::mem::take(&mut self.gaps_enabled); | |
| 755 | - } else { | |
| 756 | - self.gaps_enabled = self.config.gaps_enabled; | |
| 757 | - } | |
| 758 | - | |
| 759 | 748 | self.fullscreen()?; |
| 760 | 749 | self.restack()?; |
| 761 | 750 | } |
| @@ -1464,155 +1453,16 @@ impl WindowManager { | ||
| 1464 | 1453 | } |
| 1465 | 1454 | |
| 1466 | 1455 | fn fullscreen(&mut self) -> WmResult<()> { |
| 1467 | - if self.show_bar { | |
| 1468 | - let Some(focused_window) = self | |
| 1469 | - .monitors | |
| 1470 | - .get(self.selected_monitor) | |
| 1471 | - .and_then(|m| m.selected_client) | |
| 1472 | - else { | |
| 1473 | - return Ok(()); | |
| 1474 | - }; | |
| 1475 | - | |
| 1476 | - self.fullscreen_windows.insert(focused_window); | |
| 1477 | - | |
| 1478 | - let windows: Vec<Window> = self | |
| 1479 | - .windows | |
| 1480 | - .iter() | |
| 1481 | - .filter(|&&w| self.is_window_visible(w)) | |
| 1482 | - .copied() | |
| 1483 | - .collect(); | |
| 1484 | - | |
| 1485 | - for window in &windows { | |
| 1486 | - if let Ok(geom) = self.connection.get_geometry(*window)?.reply() { | |
| 1487 | - self.floating_geometry_before_fullscreen.insert( | |
| 1488 | - *window, | |
| 1489 | - (geom.x, geom.y, geom.width, geom.height, geom.border_width), | |
| 1490 | - ); | |
| 1491 | - } | |
| 1492 | - } | |
| 1493 | - | |
| 1494 | - self.last_layout = Some(self.layout.name()); | |
| 1495 | - if let Ok(layout) = layout_from_str("monocle") { | |
| 1496 | - self.layout = layout; | |
| 1497 | - } | |
| 1498 | - self.toggle_bar()?; | |
| 1499 | - self.apply_layout()?; | |
| 1500 | - | |
| 1501 | - for window in &windows { | |
| 1502 | - self.connection.configure_window( | |
| 1503 | - *window, | |
| 1504 | - &x11rb::protocol::xproto::ConfigureWindowAux::new().border_width(0), | |
| 1505 | - )?; | |
| 1506 | - } | |
| 1507 | - | |
| 1508 | - let border_width = self.config.border_width; | |
| 1509 | - let floating_windows: Vec<Window> = windows | |
| 1510 | - .iter() | |
| 1511 | - .filter(|&&w| self.floating_windows.contains(&w)) | |
| 1512 | - .copied() | |
| 1513 | - .collect(); | |
| 1514 | - | |
| 1515 | - for window in floating_windows { | |
| 1516 | - let monitor_idx = self | |
| 1517 | - .clients | |
| 1518 | - .get(&window) | |
| 1519 | - .map(|c| c.monitor_index) | |
| 1520 | - .unwrap_or(self.selected_monitor); | |
| 1521 | - let monitor = &self.monitors[monitor_idx]; | |
| 1522 | - | |
| 1523 | - let (outer_gap_h, outer_gap_v) = if self.gaps_enabled { | |
| 1524 | - ( | |
| 1525 | - self.config.gap_outer_horizontal, | |
| 1526 | - self.config.gap_outer_vertical, | |
| 1527 | - ) | |
| 1528 | - } else { | |
| 1529 | - (0, 0) | |
| 1530 | - }; | |
| 1531 | - | |
| 1532 | - let window_x = monitor.screen_x + outer_gap_h as i32; | |
| 1533 | - let window_y = monitor.screen_y + outer_gap_v as i32; | |
| 1534 | - let window_width = monitor | |
| 1535 | - .screen_width | |
| 1536 | - .saturating_sub(2 * outer_gap_h as i32) | |
| 1537 | - .saturating_sub(2 * border_width as i32); | |
| 1538 | - let window_height = monitor | |
| 1539 | - .screen_height | |
| 1540 | - .saturating_sub(2 * outer_gap_v as i32) | |
| 1541 | - .saturating_sub(2 * border_width as i32); | |
| 1542 | - | |
| 1543 | - self.connection.configure_window( | |
| 1544 | - window, | |
| 1545 | - &x11rb::protocol::xproto::ConfigureWindowAux::new() | |
| 1546 | - .x(window_x) | |
| 1547 | - .y(window_y) | |
| 1548 | - .width(window_width as u32) | |
| 1549 | - .height(window_height as u32), | |
| 1550 | - )?; | |
| 1551 | - } | |
| 1552 | - self.connection.flush()?; | |
| 1553 | - } else { | |
| 1554 | - let Some(focused_window) = self | |
| 1555 | - .monitors | |
| 1556 | - .get(self.selected_monitor) | |
| 1557 | - .and_then(|m| m.selected_client) | |
| 1558 | - else { | |
| 1559 | - return Ok(()); | |
| 1560 | - }; | |
| 1561 | - | |
| 1562 | - self.fullscreen_windows.remove(&focused_window); | |
| 1563 | - | |
| 1564 | - if let Some(last) = self.last_layout | |
| 1565 | - && let Ok(layout) = layout_from_str(last) | |
| 1566 | - { | |
| 1567 | - self.layout = layout; | |
| 1568 | - } | |
| 1569 | - | |
| 1570 | - let windows_to_restore: Vec<Window> = self | |
| 1571 | - .floating_geometry_before_fullscreen | |
| 1572 | - .keys() | |
| 1573 | - .copied() | |
| 1574 | - .collect(); | |
| 1575 | - | |
| 1576 | - for window in windows_to_restore { | |
| 1577 | - if let Some(&(x, y, width, height, border_width)) = | |
| 1578 | - self.floating_geometry_before_fullscreen.get(&window) | |
| 1579 | - { | |
| 1580 | - self.connection.configure_window( | |
| 1581 | - window, | |
| 1582 | - &ConfigureWindowAux::new() | |
| 1583 | - .x(x as i32) | |
| 1584 | - .y(y as i32) | |
| 1585 | - .width(width as u32) | |
| 1586 | - .height(height as u32) | |
| 1587 | - .border_width(border_width as u32), | |
| 1588 | - )?; | |
| 1589 | - | |
| 1590 | - if let Some(c) = self.clients.get_mut(&window) { | |
| 1591 | - c.x_position = x; | |
| 1592 | - c.y_position = y; | |
| 1593 | - c.width = width; | |
| 1594 | - c.height = height; | |
| 1595 | - c.border_width = border_width; | |
| 1596 | - } | |
| 1597 | - | |
| 1598 | - self.floating_geometry_before_fullscreen.remove(&window); | |
| 1599 | - } | |
| 1600 | - } | |
| 1601 | - self.connection.flush()?; | |
| 1602 | - | |
| 1603 | - self.toggle_bar()?; | |
| 1456 | + let Some(focused_window) = self | |
| 1457 | + .monitors | |
| 1458 | + .get(self.selected_monitor) | |
| 1459 | + .and_then(|m| m.selected_client) | |
| 1460 | + else { | |
| 1461 | + return Ok(()); | |
| 1462 | + }; | |
| 1604 | 1463 | |
| 1605 | - if self.layout.name() != "normie" { | |
| 1606 | - self.apply_layout()?; | |
| 1607 | - } else if let Some(bar) = self.bars.get(self.selected_monitor) { | |
| 1608 | - self.connection.configure_window( | |
| 1609 | - bar.window(), | |
| 1610 | - &x11rb::protocol::xproto::ConfigureWindowAux::new() | |
| 1611 | - .stack_mode(x11rb::protocol::xproto::StackMode::ABOVE), | |
| 1612 | - )?; | |
| 1613 | - self.connection.flush()?; | |
| 1614 | - } | |
| 1615 | - } | |
| 1464 | + let is_fullscreen = self.fullscreen_windows.contains(&focused_window); | |
| 1465 | + self.set_window_fullscreen(focused_window, !is_fullscreen)?; | |
| 1616 | 1466 | Ok(()) |
| 1617 | 1467 | } |
| 1618 | 1468 | |
| @@ -1640,11 +1490,15 @@ impl WindowManager { | ||
| 1640 | 1490 | client.is_fullscreen = true; |
| 1641 | 1491 | client.old_state = client.is_floating; |
| 1642 | 1492 | client.old_border_width = client.border_width; |
| 1493 | + client.old_x_position = client.x_position; | |
| 1494 | + client.old_y_position = client.y_position; | |
| 1495 | + client.old_width = client.width; | |
| 1496 | + client.old_height = client.height; | |
| 1643 | 1497 | client.border_width = 0; |
| 1644 | - client.is_floating = true; | |
| 1645 | 1498 | } |
| 1646 | 1499 | |
| 1647 | 1500 | self.fullscreen_windows.insert(window); |
| 1501 | + self.floating_windows.insert(window); | |
| 1648 | 1502 | |
| 1649 | 1503 | self.connection.configure_window( |
| 1650 | 1504 | window, |
| @@ -1671,26 +1525,20 @@ impl WindowManager { | ||
| 1671 | 1525 | |
| 1672 | 1526 | self.fullscreen_windows.remove(&window); |
| 1673 | 1527 | |
| 1528 | + let was_floating = self | |
| 1529 | + .clients | |
| 1530 | + .get(&window) | |
| 1531 | + .map(|c| c.old_state) | |
| 1532 | + .unwrap_or(false); | |
| 1533 | + | |
| 1534 | + if !was_floating { | |
| 1535 | + self.floating_windows.remove(&window); | |
| 1536 | + } | |
| 1537 | + | |
| 1674 | 1538 | if let Some(client) = self.clients.get_mut(&window) { |
| 1675 | 1539 | client.is_fullscreen = false; |
| 1676 | 1540 | client.is_floating = client.old_state; |
| 1677 | 1541 | client.border_width = client.old_border_width; |
| 1678 | - | |
| 1679 | - let x = client.old_x_position; | |
| 1680 | - let y = client.old_y_position; | |
| 1681 | - let w = client.old_width; | |
| 1682 | - let h = client.old_height; | |
| 1683 | - let bw = client.border_width; | |
| 1684 | - | |
| 1685 | - self.connection.configure_window( | |
| 1686 | - window, | |
| 1687 | - &x11rb::protocol::xproto::ConfigureWindowAux::new() | |
| 1688 | - .x(x as i32) | |
| 1689 | - .y(y as i32) | |
| 1690 | - .width(w as u32) | |
| 1691 | - .height(h as u32) | |
| 1692 | - .border_width(bw as u32), | |
| 1693 | - )?; | |
| 1694 | 1542 | } |
| 1695 | 1543 | |
| 1696 | 1544 | self.apply_layout()?; |
| @@ -1699,20 +1547,6 @@ impl WindowManager { | ||
| 1699 | 1547 | Ok(()) |
| 1700 | 1548 | } |
| 1701 | 1549 | |
| 1702 | - fn toggle_bar(&mut self) -> WmResult<()> { | |
| 1703 | - self.show_bar = !self.show_bar; | |
| 1704 | - if let Some(bar) = self.bars.get(self.selected_monitor) { | |
| 1705 | - if self.show_bar { | |
| 1706 | - self.connection.map_window(bar.window())?; | |
| 1707 | - } else { | |
| 1708 | - self.connection.unmap_window(bar.window())?; | |
| 1709 | - } | |
| 1710 | - self.connection.flush()?; | |
| 1711 | - } | |
| 1712 | - self.apply_layout()?; | |
| 1713 | - Ok(()) | |
| 1714 | - } | |
| 1715 | - | |
| 1716 | 1550 | fn get_transient_parent(&self, window: Window) -> Option<Window> { |
| 1717 | 1551 | self.connection |
| 1718 | 1552 | .get_property( |
| @@ -3523,6 +3357,44 @@ impl WindowManager { | ||
| 3523 | 3357 | self.showhide(stack_head)?; |
| 3524 | 3358 | } |
| 3525 | 3359 | |
| 3360 | + for monitor_index in 0..self.monitors.len() { | |
| 3361 | + let monitor = &self.monitors[monitor_index]; | |
| 3362 | + let tags = monitor.tagset[monitor.selected_tags_index]; | |
| 3363 | + | |
| 3364 | + let has_visible_fullscreen = self.fullscreen_windows.iter().any(|&w| { | |
| 3365 | + self.clients.get(&w).map_or(false, |c| { | |
| 3366 | + c.monitor_index == monitor_index && (c.tags & tags) != 0 | |
| 3367 | + }) | |
| 3368 | + }); | |
| 3369 | + | |
| 3370 | + if has_visible_fullscreen { | |
| 3371 | + if let Some(bar) = self.bars.get(monitor_index) { | |
| 3372 | + self.connection.unmap_window(bar.window())?; | |
| 3373 | + } | |
| 3374 | + | |
| 3375 | + for &window in &self.fullscreen_windows { | |
| 3376 | + if let Some(client) = self.clients.get(&window) { | |
| 3377 | + if client.monitor_index == monitor_index && (client.tags & tags) != 0 { | |
| 3378 | + self.connection.configure_window( | |
| 3379 | + window, | |
| 3380 | + &ConfigureWindowAux::new() | |
| 3381 | + .border_width(0) | |
| 3382 | + .x(monitor.screen_x) | |
| 3383 | + .y(monitor.screen_y) | |
| 3384 | + .width(monitor.screen_width as u32) | |
| 3385 | + .height(monitor.screen_height as u32) | |
| 3386 | + .stack_mode(StackMode::ABOVE), | |
| 3387 | + )?; | |
| 3388 | + } | |
| 3389 | + } | |
| 3390 | + } | |
| 3391 | + } else if self.show_bar { | |
| 3392 | + if let Some(bar) = self.bars.get(monitor_index) { | |
| 3393 | + self.connection.map_window(bar.window())?; | |
| 3394 | + } | |
| 3395 | + } | |
| 3396 | + } | |
| 3397 | + | |
| 3526 | 3398 | self.connection.flush()?; |
| 3527 | 3399 | |
| 3528 | 3400 | let is_tabbed = self.layout.name() == LayoutType::Tabbed.as_str(); |