tony / oxwm

Added xrandr support via updating configurenotify (similar to how dwm handles it) Browse files
tonybanters committed 2026-03-27 parent 66d1a2c commit 7d789a9b43097805dc1e0ab1380e33bb0e333565
Showing 4 changed files with 181 additions and 1 deletions. UnifiedSplit
+22 −0 src/wm/handlers.zig
@@ -22,6 +22,7 @@ pub fn handleEvent(event: *xlib.XEvent, wm: *WindowManager) void {
22 22 switch (event_type) {
23 23 .map_request => handleMapRequest(&event.xmaprequest, wm),
24 24 .configure_request => handleConfigureRequest(&event.xconfigurerequest, wm),
25 + .configure_notify => handleConfigureNotify(&event.xconfigure, wm),
25 26 .key_press => handleKeyPress(&event.xkey, wm),
26 27 .destroy_notify => handleDestroyNotify(&event.xdestroywindow, wm),
27 28 .unmap_notify => handleUnmapNotify(&event.xunmap, wm),
@@ -191,6 +192,27 @@ fn handleExpose(event: *xlib.XExposeEvent, wm: *WindowManager) void {
191 192 }
192 193 }
193 194
195 +fn handleConfigureNotify(event: *xlib.XConfigureEvent, wm: *WindowManager) void {
196 + if (event.window != wm.display.root) return;
197 +
198 + const dirty = wm.updateGeom();
199 + if (dirty) {
200 + wm.rebuildBars();
201 + var mon = wm.monitors;
202 + while (mon) |m| {
203 + var c = m.clients;
204 + while (c) |client| {
205 + if (client.is_fullscreen) {
206 + tiling.resizeClient(client, m.mon_x, m.mon_y, m.mon_w, m.mon_h);
207 + }
208 + c = client.next;
209 + }
210 + core.arrange(m, wm);
211 + mon = m.next;
212 + }
213 + }
214 +}
215 +
194 216 fn handleButtonPress(event: *xlib.XButtonEvent, wm: *WindowManager) void {
195 217 std.debug.print("button_press: window=0x{x} subwindow=0x{x}\n", .{ event.window, event.subwindow });
196 218
+157 −0 src/wm/wm.zig
@@ -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
+1 −1 src/x11/display.zig
@@ -35,7 +35,7 @@ pub const Display = struct {
35 35 _ = xlib.XSelectInput(
36 36 self.handle,
37 37 self.root,
38 - xlib.SubstructureRedirectMask | xlib.SubstructureNotifyMask | xlib.ButtonPressMask | xlib.PointerMotionMask | xlib.EnterWindowMask,
38 + xlib.SubstructureRedirectMask | xlib.SubstructureNotifyMask | xlib.StructureNotifyMask | xlib.ButtonPressMask | xlib.PointerMotionMask | xlib.EnterWindowMask,
39 39 );
40 40 _ = xlib.XSync(self.handle, xlib.False);
41 41
+1 −0 src/x11/xlib.zig
@@ -138,6 +138,7 @@ pub const None = c.None;
138 138 pub const XButtonEvent = c.XButtonEvent;
139 139 pub const XMotionEvent = c.XMotionEvent;
140 140 pub const XExposeEvent = c.XExposeEvent;
141 +pub const XConfigureEvent = c.XConfigureEvent;
141 142
142 143 pub const XineramaIsActive = c.XineramaIsActive;
143 144 pub const XineramaQueryScreens = c.XineramaQueryScreens;