tony / oxwm

Added helper functions for text properties, urgency, and atomic properties of windows. Browse files
tonybtw committed 2025-12-01 parent ae03894 commit c755274ea93c1e5c92c5a39287f29aefcff42dac
Showing 1 changed file with 114 additions and 0 deletions. UnifiedSplit
+114 −0 src/window_manager.rs
@@ -1544,6 +1544,120 @@ impl WindowManager {
1544 1544 Ok(true)
1545 1545 }
1546 1546
1547 + fn set_urgent(&mut self, window: Window, urgent: bool) -> WmResult<()> {
1548 + if let Some(client) = self.clients.get_mut(&window) {
1549 + client.is_urgent = urgent;
1550 + }
1551 +
1552 + let hints_reply = self.connection.get_property(
1553 + false,
1554 + window,
1555 + AtomEnum::WM_HINTS,
1556 + AtomEnum::WM_HINTS,
1557 + 0,
1558 + 9,
1559 + )?.reply();
1560 +
1561 + if let Ok(hints) = hints_reply {
1562 + if hints.value.len() >= 4 {
1563 + let mut flags = u32::from_ne_bytes([
1564 + hints.value[0],
1565 + hints.value[1],
1566 + hints.value[2],
1567 + hints.value[3],
1568 + ]);
1569 +
1570 + if urgent {
1571 + flags |= 256;
1572 + } else {
1573 + flags &= !256;
1574 + }
1575 +
1576 + let mut new_hints = hints.value.clone();
1577 + new_hints[0..4].copy_from_slice(&flags.to_ne_bytes());
1578 +
1579 + self.connection.change_property(
1580 + PropMode::REPLACE,
1581 + window,
1582 + AtomEnum::WM_HINTS,
1583 + AtomEnum::WM_HINTS,
1584 + 32,
1585 + new_hints.len() as u32 / 4,
1586 + &new_hints,
1587 + )?;
1588 + }
1589 + }
1590 +
1591 + Ok(())
1592 + }
1593 +
1594 + fn get_state(&self, window: Window) -> WmResult<i32> {
1595 + let reply = self.connection.get_property(
1596 + false,
1597 + window,
1598 + self.atoms.wm_state,
1599 + self.atoms.wm_state,
1600 + 0,
1601 + 2,
1602 + )?.reply();
1603 +
1604 + match reply {
1605 + Ok(prop) if !prop.value.is_empty() && prop.value.len() >= 4 => {
1606 + let state = u32::from_ne_bytes([
1607 + prop.value[0],
1608 + prop.value[1],
1609 + prop.value[2],
1610 + prop.value[3],
1611 + ]);
1612 + Ok(state as i32)
1613 + }
1614 + _ => Ok(-1),
1615 + }
1616 + }
1617 +
1618 + fn get_atom_prop(&self, window: Window, property: Atom) -> WmResult<Option<Atom>> {
1619 + let reply = self.connection.get_property(
1620 + false,
1621 + window,
1622 + property,
1623 + AtomEnum::ATOM,
1624 + 0,
1625 + 1,
1626 + )?.reply();
1627 +
1628 + match reply {
1629 + Ok(prop) if !prop.value.is_empty() && prop.value.len() >= 4 => {
1630 + let atom = u32::from_ne_bytes([
1631 + prop.value[0],
1632 + prop.value[1],
1633 + prop.value[2],
1634 + prop.value[3],
1635 + ]);
1636 + Ok(Some(atom))
1637 + }
1638 + _ => Ok(None),
1639 + }
1640 + }
1641 +
1642 + fn get_text_prop(&self, window: Window, atom: Atom) -> WmResult<Option<String>> {
1643 + let reply = self.connection.get_property(
1644 + false,
1645 + window,
1646 + atom,
1647 + AtomEnum::ANY,
1648 + 0,
1649 + 1024,
1650 + )?.reply();
1651 +
1652 + match reply {
1653 + Ok(prop) if !prop.value.is_empty() => {
1654 + let text = String::from_utf8_lossy(&prop.value).to_string();
1655 + Ok(Some(text.trim_end_matches('\0').to_string()))
1656 + }
1657 + _ => Ok(None),
1658 + }
1659 + }
1660 +
1547 1661 fn fullscreen(&mut self) -> WmResult<()> {
1548 1662 if self.show_bar {
1549 1663 let windows: Vec<Window> = self.windows.iter()