| @@ -86,8 +86,8 @@ impl WindowManager { |
| 86 |
.get_property(false, root, net_current_desktop, AtomEnum::CARDINAL, 0, 1)? |
86 |
.get_property(false, root, net_current_desktop, AtomEnum::CARDINAL, 0, 1)? |
| 87 |
.reply() |
87 |
.reply() |
| 88 |
{ |
88 |
{ |
|
|
89 |
+ // I don't undestand this but I got it from dwm->persist_tags patch and it worked. |
| 89 |
Ok(prop) if prop.value.len() >= 4 => { |
90 |
Ok(prop) if prop.value.len() >= 4 => { |
| 90 |
- // I don't undestand this but I got it from dwm->persist_tags patch and it worked. |
|
|
| 91 |
let desktop = u32::from_ne_bytes([ |
91 |
let desktop = u32::from_ne_bytes([ |
| 92 |
prop.value[0], |
92 |
prop.value[0], |
| 93 |
prop.value[1], |
93 |
prop.value[1], |
| @@ -95,29 +95,32 @@ impl WindowManager { |
| 95 |
prop.value[3], |
95 |
prop.value[3], |
| 96 |
]); |
96 |
]); |
| 97 |
if desktop < TAG_COUNT as u32 { |
97 |
if desktop < TAG_COUNT as u32 { |
| 98 |
- println!("Restored selected tag: {}", desktop); |
98 |
+ let mask = tag_mask(desktop as usize); |
| 99 |
- return Ok(tag_mask(desktop as usize)); |
99 |
+ return Ok(mask); |
| 100 |
} |
100 |
} |
| 101 |
} |
101 |
} |
| 102 |
- _ => {} |
102 |
+ Ok(_) => {} |
|
|
103 |
+ Err(e) => { |
|
|
104 |
+ eprintln!("No _NET_CURRENT_DESKTOP property ({})", e); |
|
|
105 |
+ } |
| 103 |
} |
106 |
} |
| 104 |
- |
|
|
| 105 |
- println!("No saved tag, defaulting to tag 0"); |
|
|
| 106 |
Ok(tag_mask(0)) |
107 |
Ok(tag_mask(0)) |
| 107 |
} |
108 |
} |
| 108 |
|
109 |
|
| 109 |
fn scan_existing_windows(&mut self) -> Result<()> { |
110 |
fn scan_existing_windows(&mut self) -> Result<()> { |
| 110 |
let tree = self.connection.query_tree(self.root)?.reply()?; |
111 |
let tree = self.connection.query_tree(self.root)?.reply()?; |
| 111 |
- |
|
|
| 112 |
- println!("=== Scanning existing windows ==="); |
|
|
| 113 |
- println!("Total children: {}", tree.children.len()); |
|
|
| 114 |
- |
|
|
| 115 |
let net_client_info = self |
112 |
let net_client_info = self |
| 116 |
.connection |
113 |
.connection |
| 117 |
.intern_atom(false, b"_NET_CLIENT_INFO")? |
114 |
.intern_atom(false, b"_NET_CLIENT_INFO")? |
| 118 |
.reply()? |
115 |
.reply()? |
| 119 |
.atom; |
116 |
.atom; |
| 120 |
|
117 |
|
|
|
118 |
+ let wm_state_atom = self |
|
|
119 |
+ .connection |
|
|
120 |
+ .intern_atom(false, b"WM_STATE")? |
|
|
121 |
+ .reply()? |
|
|
122 |
+ .atom; |
|
|
123 |
+ |
| 121 |
for &window in &tree.children { |
124 |
for &window in &tree.children { |
| 122 |
if window == self.bar.window() { |
125 |
if window == self.bar.window() { |
| 123 |
continue; |
126 |
continue; |
| @@ -134,13 +137,25 @@ impl WindowManager { |
| 134 |
|
137 |
|
| 135 |
if attrs.map_state == MapState::VIEWABLE { |
138 |
if attrs.map_state == MapState::VIEWABLE { |
| 136 |
let tag = self.get_saved_tag(window, net_client_info)?; |
139 |
let tag = self.get_saved_tag(window, net_client_info)?; |
| 137 |
- println!("Managing VIEWABLE window: {} with tag {:b}", window, tag); |
|
|
| 138 |
self.windows.push(window); |
140 |
self.windows.push(window); |
| 139 |
self.window_tags.insert(window, tag); |
141 |
self.window_tags.insert(window, tag); |
| 140 |
continue; |
142 |
continue; |
| 141 |
} |
143 |
} |
| 142 |
|
144 |
|
| 143 |
if attrs.map_state == MapState::UNMAPPED { |
145 |
if attrs.map_state == MapState::UNMAPPED { |
|
|
146 |
+ let has_wm_state = match self |
|
|
147 |
+ .connection |
|
|
148 |
+ .get_property(false, window, wm_state_atom, AtomEnum::ANY, 0, 2)? |
|
|
149 |
+ .reply() |
|
|
150 |
+ { |
|
|
151 |
+ Ok(prop) => !prop.value.is_empty(), |
|
|
152 |
+ Err(_) => false, |
|
|
153 |
+ }; |
|
|
154 |
+ |
|
|
155 |
+ if !has_wm_state { |
|
|
156 |
+ continue; |
|
|
157 |
+ } |
|
|
158 |
+ |
| 144 |
let has_wm_class = match self |
159 |
let has_wm_class = match self |
| 145 |
.connection |
160 |
.connection |
| 146 |
.get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024)? |
161 |
.get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024)? |
| @@ -152,15 +167,12 @@ impl WindowManager { |
| 152 |
|
167 |
|
| 153 |
if has_wm_class { |
168 |
if has_wm_class { |
| 154 |
let tag = self.get_saved_tag(window, net_client_info)?; |
169 |
let tag = self.get_saved_tag(window, net_client_info)?; |
| 155 |
- println!("Managing UNMAPPED window: {} with tag {:b}", window, tag); |
|
|
| 156 |
self.windows.push(window); |
170 |
self.windows.push(window); |
| 157 |
self.window_tags.insert(window, tag); |
171 |
self.window_tags.insert(window, tag); |
| 158 |
} |
172 |
} |
| 159 |
} |
173 |
} |
| 160 |
} |
174 |
} |
| 161 |
|
175 |
|
| 162 |
- println!("Total managed windows: {}", self.windows.len()); |
|
|
| 163 |
- |
|
|
| 164 |
if let Some(&first) = self.windows.first() { |
176 |
if let Some(&first) = self.windows.first() { |
| 165 |
self.set_focus(Some(first))?; |
177 |
self.set_focus(Some(first))?; |
| 166 |
} |
178 |
} |
| @@ -182,13 +194,17 @@ impl WindowManager { |
| 182 |
prop.value[2], |
194 |
prop.value[2], |
| 183 |
prop.value[3], |
195 |
prop.value[3], |
| 184 |
]); |
196 |
]); |
| 185 |
- println!(" Restored tag from _NET_CLIENT_INFO: {:b}", tags); |
197 |
+ |
| 186 |
- return Ok(tags); |
198 |
+ if tags != 0 && tags < (1 << crate::config::TAG_COUNT) { |
|
|
199 |
+ return Ok(tags); |
|
|
200 |
+ } |
|
|
201 |
+ } |
|
|
202 |
+ Ok(_) => {} |
|
|
203 |
+ Err(e) => { |
|
|
204 |
+ eprintln!("No _NET_CLIENT_INFO property ({})", e); |
| 187 |
} |
205 |
} |
| 188 |
- _ => {} |
|
|
| 189 |
} |
206 |
} |
| 190 |
|
207 |
|
| 191 |
- println!(" No saved tag, using current: {:b}", self.selected_tags); |
|
|
| 192 |
Ok(self.selected_tags) |
208 |
Ok(self.selected_tags) |
| 193 |
} |
209 |
} |
| 194 |
|
210 |
|
| @@ -199,8 +215,7 @@ impl WindowManager { |
| 199 |
.reply()? |
215 |
.reply()? |
| 200 |
.atom; |
216 |
.atom; |
| 201 |
|
217 |
|
| 202 |
- let data = [tag, 0u32]; |
218 |
+ let bytes = tag.to_ne_bytes().to_vec(); |
| 203 |
- let bytes: Vec<u8> = data.iter().flat_map(|&v| v.to_ne_bytes()).collect(); |
|
|
| 204 |
|
219 |
|
| 205 |
self.connection.change_property( |
220 |
self.connection.change_property( |
| 206 |
PropMode::REPLACE, |
221 |
PropMode::REPLACE, |
| @@ -208,6 +223,30 @@ impl WindowManager { |
| 208 |
net_client_info, |
223 |
net_client_info, |
| 209 |
AtomEnum::CARDINAL, |
224 |
AtomEnum::CARDINAL, |
| 210 |
32, |
225 |
32, |
|
|
226 |
+ 1, |
|
|
227 |
+ &bytes, |
|
|
228 |
+ )?; |
|
|
229 |
+ |
|
|
230 |
+ self.connection.flush()?; |
|
|
231 |
+ Ok(()) |
|
|
232 |
+ } |
|
|
233 |
+ |
|
|
234 |
+ fn set_wm_state(&self, window: Window, state: u32) -> Result<()> { |
|
|
235 |
+ let wm_state_atom = self |
|
|
236 |
+ .connection |
|
|
237 |
+ .intern_atom(false, b"WM_STATE")? |
|
|
238 |
+ .reply()? |
|
|
239 |
+ .atom; |
|
|
240 |
+ |
|
|
241 |
+ let data = [state, 0u32]; // No icon window |
|
|
242 |
+ let bytes: Vec<u8> = data.iter().flat_map(|&v| v.to_ne_bytes()).collect(); |
|
|
243 |
+ |
|
|
244 |
+ self.connection.change_property( |
|
|
245 |
+ PropMode::REPLACE, |
|
|
246 |
+ window, |
|
|
247 |
+ wm_state_atom, |
|
|
248 |
+ wm_state_atom, |
|
|
249 |
+ 32, |
| 211 |
2, |
250 |
2, |
| 212 |
&bytes, |
251 |
&bytes, |
| 213 |
)?; |
252 |
)?; |
| @@ -468,6 +507,8 @@ impl WindowManager { |
| 468 |
self.windows.push(event.window); |
507 |
self.windows.push(event.window); |
| 469 |
self.window_tags.insert(event.window, self.selected_tags); |
508 |
self.window_tags.insert(event.window, self.selected_tags); |
| 470 |
|
509 |
|
|
|
510 |
+ self.set_wm_state(event.window, 1)?; |
|
|
511 |
+ |
| 471 |
let _ = self.save_client_tag(event.window, self.selected_tags); |
512 |
let _ = self.save_client_tag(event.window, self.selected_tags); |
| 472 |
|
513 |
|
| 473 |
self.apply_layout()?; |
514 |
self.apply_layout()?; |
| @@ -493,12 +534,7 @@ impl WindowManager { |
| 493 |
} |
534 |
} |
| 494 |
} |
535 |
} |
| 495 |
Event::KeyPress(event) => { |
536 |
Event::KeyPress(event) => { |
| 496 |
- println!("━━━ KeyPress Event ━━━"); |
|
|
| 497 |
- println!("Key code: {}", event.detail); |
|
|
| 498 |
- |
|
|
| 499 |
let (action, arg) = keyboard::handle_key_press(event)?; |
537 |
let (action, arg) = keyboard::handle_key_press(event)?; |
| 500 |
- println!(" -> Matched action: {:?}", action); |
|
|
| 501 |
- |
|
|
| 502 |
match action { |
538 |
match action { |
| 503 |
KeyAction::Quit => return Ok(Some(false)), |
539 |
KeyAction::Quit => return Ok(Some(false)), |
| 504 |
KeyAction::Restart => return Ok(Some(true)), |
540 |
KeyAction::Restart => return Ok(Some(true)), |