fix: pertag sel_lt was not pre-defined with default layout value
Browse files
+43 −65 src/wm/wm.zig
| @@ -158,48 +158,57 @@ pub const WindowManager = struct { | |||
| 158 | self.config.deinit(); | 158 | self.config.deinit(); |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | + const layouts = [_]*const monitor_mod.Layout{ | ||
| 162 | + &tiling.layout, | ||
| 163 | + &monocle.layout, | ||
| 164 | + &floating.layout, | ||
| 165 | + &scrolling.layout, | ||
| 166 | + &grid.layout, | ||
| 167 | + }; | ||
| 168 | + | ||
| 169 | + fn initMonitor(self: *WindowManager, mon: *Monitor, num: usize, x: i16, y: i16, w: c_int, h: c_int) void { | ||
| 170 | + mon.num = @intCast(num); | ||
| 171 | + mon.mon_x = x; | ||
| 172 | + mon.mon_y = y; | ||
| 173 | + mon.mon_w = w; | ||
| 174 | + mon.mon_h = h; | ||
| 175 | + mon.win_x = x; | ||
| 176 | + mon.win_y = y; | ||
| 177 | + mon.win_w = w; | ||
| 178 | + mon.win_h = h; | ||
| 179 | + | ||
| 180 | + for (&mon.lt, layouts) |*slot, layout| { | ||
| 181 | + slot.* = layout; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + if (std.meta.stringToEnum(config_mod.Layouts, self.config.layout)) |value| { | ||
| 185 | + mon.sel_lt = @intFromEnum(value); | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + for (0..10) |i| { | ||
| 189 | + for (0..layouts.len) |j| { | ||
| 190 | + mon.pertag.ltidxs[i][j] = mon.lt[j]; | ||
| 191 | + } | ||
| 192 | + mon.pertag.sellts[i] = mon.sel_lt; | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + self.initMonitorGaps(mon); | ||
| 196 | + } | ||
| 197 | + | ||
| 161 | fn setupMonitors(self: *WindowManager) void { | 198 | fn setupMonitors(self: *WindowManager) void { |
| 162 | if (xlib.XineramaIsActive(self.display.handle) != 0) { | 199 | if (xlib.XineramaIsActive(self.display.handle) != 0) { |
| 163 | var screen_count: c_int = 0; | 200 | var screen_count: c_int = 0; |
| 164 | const screens = xlib.XineramaQueryScreens(self.display.handle, &screen_count); | 201 | const screens = xlib.XineramaQueryScreens(self.display.handle, &screen_count); |
| 202 | + defer if (screens != null) { | ||
| 203 | + _ = xlib.XFree(@ptrCast(screens)); | ||
| 204 | + }; | ||
| 165 | 205 | ||
| 166 | if (screen_count > 0 and screens != null) { | 206 | if (screen_count > 0 and screens != null) { |
| 167 | var prev_monitor: ?*Monitor = null; | 207 | var prev_monitor: ?*Monitor = null; |
| 168 | - var index: usize = 0; | 208 | + for (0..@as(usize, @intCast(screen_count))) |index| { |
| 169 | - | ||
| 170 | - while (index < @as(usize, @intCast(screen_count))) : (index += 1) { | ||
| 171 | const screen = screens[index]; | 209 | const screen = screens[index]; |
| 172 | const mon = monitor_mod.create(self.allocator) orelse continue; | 210 | const mon = monitor_mod.create(self.allocator) orelse continue; |
| 173 | - | 211 | + self.initMonitor(mon, index, screen.x_org, screen.y_org, screen.width, screen.height); |
| 174 | - mon.num = @intCast(index); | ||
| 175 | - mon.mon_x = screen.x_org; | ||
| 176 | - mon.mon_y = screen.y_org; | ||
| 177 | - mon.mon_w = screen.width; | ||
| 178 | - mon.mon_h = screen.height; | ||
| 179 | - mon.win_x = screen.x_org; | ||
| 180 | - mon.win_y = screen.y_org; | ||
| 181 | - mon.win_w = screen.width; | ||
| 182 | - mon.win_h = screen.height; | ||
| 183 | - | ||
| 184 | - mon.lt[@intFromEnum(config_mod.Layouts.tiling)] = &tiling.layout; | ||
| 185 | - mon.lt[@intFromEnum(config_mod.Layouts.monocle)] = &monocle.layout; | ||
| 186 | - mon.lt[@intFromEnum(config_mod.Layouts.floating)] = &floating.layout; | ||
| 187 | - mon.lt[@intFromEnum(config_mod.Layouts.scrolling)] = &scrolling.layout; | ||
| 188 | - mon.lt[@intFromEnum(config_mod.Layouts.grid)] = &grid.layout; | ||
| 189 | - | ||
| 190 | - if (std.meta.stringToEnum(config_mod.Layouts, self.config.layout)) |value| { | ||
| 191 | - mon.sel_lt = @intFromEnum(value); | ||
| 192 | - } | ||
| 193 | - | ||
| 194 | - for (0..10) |i| { | ||
| 195 | - mon.pertag.ltidxs[i][0] = mon.lt[0]; | ||
| 196 | - mon.pertag.ltidxs[i][1] = mon.lt[1]; | ||
| 197 | - mon.pertag.ltidxs[i][2] = mon.lt[2]; | ||
| 198 | - mon.pertag.ltidxs[i][3] = mon.lt[3]; | ||
| 199 | - mon.pertag.ltidxs[i][4] = mon.lt[4]; | ||
| 200 | - } | ||
| 201 | - | ||
| 202 | - self.initMonitorGaps(mon); | ||
| 203 | 212 | ||
| 204 | if (prev_monitor) |prev| { | 213 | if (prev_monitor) |prev| { |
| 205 | prev.next = mon; | 214 | prev.next = mon; |
| @@ -209,43 +218,12 @@ pub const WindowManager = struct { | |||
| 209 | } | 218 | } |
| 210 | prev_monitor = mon; | 219 | prev_monitor = mon; |
| 211 | } | 220 | } |
| 212 | - | ||
| 213 | - _ = xlib.XFree(@ptrCast(screens)); | ||
| 214 | } | 221 | } |
| 215 | } | 222 | } |
| 216 | 223 | ||
| 217 | - // Fallback: single monitor covering the full screen. | ||
| 218 | if (self.monitors == null) { | 224 | if (self.monitors == null) { |
| 219 | const mon = monitor_mod.create(self.allocator) orelse return; | 225 | const mon = monitor_mod.create(self.allocator) orelse return; |
| 220 | - mon.num = 0; | 226 | + self.initMonitor(mon, 0, 0, 0, self.display.screenWidth(), self.display.screenHeight()); |
| 221 | - mon.mon_x = 0; | ||
| 222 | - mon.mon_y = 0; | ||
| 223 | - mon.mon_w = self.display.screenWidth(); | ||
| 224 | - mon.mon_h = self.display.screenHeight(); | ||
| 225 | - mon.win_x = 0; | ||
| 226 | - mon.win_y = 0; | ||
| 227 | - mon.win_w = mon.mon_w; | ||
| 228 | - mon.win_h = mon.mon_h; | ||
| 229 | - | ||
| 230 | - mon.lt[@intFromEnum(config_mod.Layouts.tiling)] = &tiling.layout; | ||
| 231 | - mon.lt[@intFromEnum(config_mod.Layouts.monocle)] = &monocle.layout; | ||
| 232 | - mon.lt[@intFromEnum(config_mod.Layouts.floating)] = &floating.layout; | ||
| 233 | - mon.lt[@intFromEnum(config_mod.Layouts.scrolling)] = &scrolling.layout; | ||
| 234 | - mon.lt[@intFromEnum(config_mod.Layouts.grid)] = &grid.layout; | ||
| 235 | - | ||
| 236 | - if (std.meta.stringToEnum(config_mod.Layouts, self.config.layout)) |value| { | ||
| 237 | - mon.sel_lt = @intFromEnum(value); | ||
| 238 | - } | ||
| 239 | - | ||
| 240 | - for (0..10) |i| { | ||
| 241 | - mon.pertag.ltidxs[i][0] = mon.lt[0]; | ||
| 242 | - mon.pertag.ltidxs[i][1] = mon.lt[1]; | ||
| 243 | - mon.pertag.ltidxs[i][2] = mon.lt[2]; | ||
| 244 | - mon.pertag.ltidxs[i][3] = mon.lt[3]; | ||
| 245 | - mon.pertag.ltidxs[i][4] = mon.lt[4]; | ||
| 246 | - } | ||
| 247 | - | ||
| 248 | - self.initMonitorGaps(mon); | ||
| 249 | self.monitors = mon; | 227 | self.monitors = mon; |
| 250 | self.selected_monitor = mon; | 228 | self.selected_monitor = mon; |
| 251 | } | 229 | } |