|
|
@@ -6,6 +6,7 @@ const xlib = @import("../x11/xlib.zig"); |
| 6 |
6 |
const atoms_mod = @import("../x11/atoms.zig"); |
| 7 |
7 |
const chord_mod = @import("../keyboard/chord.zig"); |
| 8 |
8 |
const monitor_mod = @import("../monitor.zig"); |
|
9 |
+const client_mod = @import("../client.zig"); |
| 9 |
10 |
const bar_mod = @import("../bar/bar.zig"); |
| 10 |
11 |
const blocks_mod = @import("../bar/blocks/blocks.zig"); |
| 11 |
12 |
const config_mod = @import("../config/config.zig"); |
|
|
@@ -241,6 +242,162 @@ pub const WindowManager = struct { |
| 241 |
242 |
} |
| 242 |
243 |
} |
| 243 |
244 |
|
|
245 |
+ pub fn updateGeom(self: *WindowManager) bool { |
|
246 |
+ var dirty = false; |
|
247 |
+ |
|
248 |
+ if (xlib.XineramaIsActive(self.display.handle) != 0) { |
|
249 |
+ var n: usize = 0; |
|
250 |
+ var m = self.monitors; |
|
251 |
+ while (m) |mon| : (m = mon.next) n += 1; |
|
252 |
+ |
|
253 |
+ var nn: c_int = 0; |
|
254 |
+ const info = xlib.XineramaQueryScreens(self.display.handle, &nn); |
|
255 |
+ if (info == null) return false; |
|
256 |
+ defer _ = xlib.XFree(@ptrCast(info)); |
|
257 |
+ |
|
258 |
+ const new_count: usize = @intCast(nn); |
|
259 |
+ |
|
260 |
+ for (n..new_count) |_| { |
|
261 |
+ var last = self.monitors; |
|
262 |
+ while (last) |mon| { |
|
263 |
+ if (mon.next == null) break; |
|
264 |
+ last = mon.next; |
|
265 |
+ } |
|
266 |
+ const new_mon = monitor_mod.create(self.allocator) orelse continue; |
|
267 |
+ new_mon.lt[0] = &tiling.layout; |
|
268 |
+ new_mon.lt[1] = &monocle.layout; |
|
269 |
+ new_mon.lt[2] = &floating.layout; |
|
270 |
+ new_mon.lt[3] = &scrolling.layout; |
|
271 |
+ new_mon.lt[4] = &grid.layout; |
|
272 |
+ for (0..10) |i| { |
|
273 |
+ new_mon.pertag.ltidxs[i][0] = new_mon.lt[0]; |
|
274 |
+ new_mon.pertag.ltidxs[i][1] = new_mon.lt[1]; |
|
275 |
+ new_mon.pertag.ltidxs[i][2] = new_mon.lt[2]; |
|
276 |
+ new_mon.pertag.ltidxs[i][3] = new_mon.lt[3]; |
|
277 |
+ new_mon.pertag.ltidxs[i][4] = new_mon.lt[4]; |
|
278 |
+ } |
|
279 |
+ if (last) |l| { |
|
280 |
+ l.next = new_mon; |
|
281 |
+ } else { |
|
282 |
+ self.monitors = new_mon; |
|
283 |
+ } |
|
284 |
+ } |
|
285 |
+ |
|
286 |
+ var i: usize = 0; |
|
287 |
+ m = self.monitors; |
|
288 |
+ while (m != null and i < new_count) : (i += 1) { |
|
289 |
+ const mon = m.?; |
|
290 |
+ const screen = info[i]; |
|
291 |
+ if (i >= n or |
|
292 |
+ screen.x_org != mon.mon_x or screen.y_org != mon.mon_y or |
|
293 |
+ screen.width != mon.mon_w or screen.height != mon.mon_h) |
|
294 |
+ { |
|
295 |
+ dirty = true; |
|
296 |
+ mon.num = @intCast(i); |
|
297 |
+ mon.mon_x = screen.x_org; |
|
298 |
+ mon.mon_y = screen.y_org; |
|
299 |
+ mon.mon_w = screen.width; |
|
300 |
+ mon.mon_h = screen.height; |
|
301 |
+ mon.win_x = screen.x_org; |
|
302 |
+ mon.win_y = screen.y_org; |
|
303 |
+ mon.win_w = screen.width; |
|
304 |
+ mon.win_h = screen.height; |
|
305 |
+ self.initMonitorGaps(mon); |
|
306 |
+ } |
|
307 |
+ m = mon.next; |
|
308 |
+ } |
|
309 |
+ |
|
310 |
+ for (new_count..n) |_| { |
|
311 |
+ var last: ?*Monitor = null; |
|
312 |
+ var iter = self.monitors; |
|
313 |
+ while (iter) |mon| { |
|
314 |
+ if (mon.next == null) { |
|
315 |
+ last = mon; |
|
316 |
+ break; |
|
317 |
+ } |
|
318 |
+ iter = mon.next; |
|
319 |
+ } |
|
320 |
+ const removed = last orelse continue; |
|
321 |
+ |
|
322 |
+ while (removed.clients) |c| { |
|
323 |
+ dirty = true; |
|
324 |
+ removed.clients = c.next; |
|
325 |
+ client_mod.detachStack(c); |
|
326 |
+ c.monitor = self.monitors; |
|
327 |
+ client_mod.attachAside(c); |
|
328 |
+ client_mod.attachStack(c); |
|
329 |
+ } |
|
330 |
+ |
|
331 |
+ if (self.selected_monitor == removed) { |
|
332 |
+ self.selected_monitor = self.monitors; |
|
333 |
+ } |
|
334 |
+ |
|
335 |
+ var prev: ?*Monitor = null; |
|
336 |
+ iter = self.monitors; |
|
337 |
+ while (iter) |mon| { |
|
338 |
+ if (mon == removed) { |
|
339 |
+ if (prev) |p| { |
|
340 |
+ p.next = removed.next; |
|
341 |
+ } else { |
|
342 |
+ self.monitors = removed.next; |
|
343 |
+ } |
|
344 |
+ break; |
|
345 |
+ } |
|
346 |
+ prev = mon; |
|
347 |
+ iter = mon.next; |
|
348 |
+ } |
|
349 |
+ monitor_mod.destroy(self.allocator, removed); |
|
350 |
+ } |
|
351 |
+ |
|
352 |
+ tiling.setScreenSize(info[0].width, info[0].height); |
|
353 |
+ } else { |
|
354 |
+ if (self.monitors == null) { |
|
355 |
+ const mon = monitor_mod.create(self.allocator) orelse return false; |
|
356 |
+ mon.lt[0] = &tiling.layout; |
|
357 |
+ mon.lt[1] = &monocle.layout; |
|
358 |
+ mon.lt[2] = &floating.layout; |
|
359 |
+ mon.lt[3] = &scrolling.layout; |
|
360 |
+ mon.lt[4] = &grid.layout; |
|
361 |
+ self.monitors = mon; |
|
362 |
+ self.selected_monitor = mon; |
|
363 |
+ } |
|
364 |
+ |
|
365 |
+ const sw = self.display.screenWidth(); |
|
366 |
+ const sh = self.display.screenHeight(); |
|
367 |
+ |
|
368 |
+ if (self.monitors) |mon| { |
|
369 |
+ if (mon.mon_w != sw or mon.mon_h != sh) { |
|
370 |
+ dirty = true; |
|
371 |
+ mon.mon_x = 0; |
|
372 |
+ mon.mon_y = 0; |
|
373 |
+ mon.mon_w = sw; |
|
374 |
+ mon.mon_h = sh; |
|
375 |
+ mon.win_x = 0; |
|
376 |
+ mon.win_y = 0; |
|
377 |
+ mon.win_w = sw; |
|
378 |
+ mon.win_h = sh; |
|
379 |
+ self.initMonitorGaps(mon); |
|
380 |
+ } |
|
381 |
+ } |
|
382 |
+ |
|
383 |
+ tiling.setScreenSize(sw, sh); |
|
384 |
+ } |
|
385 |
+ |
|
386 |
+ if (dirty) { |
|
387 |
+ self.selected_monitor = self.monitors; |
|
388 |
+ self.selected_monitor = monitor_mod.windowToMonitor(self, self.display.root); |
|
389 |
+ } |
|
390 |
+ |
|
391 |
+ return dirty; |
|
392 |
+ } |
|
393 |
+ |
|
394 |
+ pub fn rebuildBars(self: *WindowManager) void { |
|
395 |
+ bar_mod.destroyBars(self.bars, self.display.handle); |
|
396 |
+ self.bars = null; |
|
397 |
+ self.setupBars(); |
|
398 |
+ self.rebuildBarBlocks(); |
|
399 |
+ } |
|
400 |
+ |
| 244 |
401 |
fn initMonitorGaps(self: *WindowManager, mon: *Monitor) void { |
| 245 |
402 |
const cfg = &self.config; |
| 246 |
403 |
const any_gap_nonzero = cfg.gap_inner_h != 0 or cfg.gap_inner_v != 0 or |