| @@ -1,20 +1,14 @@ |
| 1 |
const std = @import("std"); |
1 |
const std = @import("std"); |
| 2 |
const VERSION = "v0.11.2"; |
2 |
const VERSION = "v0.11.2"; |
| 3 |
-const Atoms = @import("x11/atoms.zig").Atoms; |
3 |
+const wm_mod = @import("wm.zig"); |
| 4 |
-const kchord = @import("keyboard/chord.zig"); |
|
|
| 5 |
const display_mod = @import("x11/display.zig"); |
4 |
const display_mod = @import("x11/display.zig"); |
| 6 |
const events = @import("x11/events.zig"); |
5 |
const events = @import("x11/events.zig"); |
| 7 |
const xlib = @import("x11/xlib.zig"); |
6 |
const xlib = @import("x11/xlib.zig"); |
| 8 |
const client_mod = @import("client.zig"); |
7 |
const client_mod = @import("client.zig"); |
| 9 |
const monitor_mod = @import("monitor.zig"); |
8 |
const monitor_mod = @import("monitor.zig"); |
| 10 |
const tiling = @import("layouts/tiling.zig"); |
9 |
const tiling = @import("layouts/tiling.zig"); |
| 11 |
-const monocle = @import("layouts/monocle.zig"); |
|
|
| 12 |
-const floating = @import("layouts/floating.zig"); |
|
|
| 13 |
const scrolling = @import("layouts/scrolling.zig"); |
10 |
const scrolling = @import("layouts/scrolling.zig"); |
| 14 |
-const grid = @import("layouts/grid.zig"); |
|
|
| 15 |
-const animations = @import("animations.zig"); |
|
|
| 16 |
const bar_mod = @import("bar/bar.zig"); |
11 |
const bar_mod = @import("bar/bar.zig"); |
| 17 |
-const blocks_mod = @import("bar/blocks/blocks.zig"); |
|
|
| 18 |
const config_mod = @import("config/config.zig"); |
12 |
const config_mod = @import("config/config.zig"); |
| 19 |
const lua = @import("config/lua.zig"); |
13 |
const lua = @import("config/lua.zig"); |
| 20 |
const overlay_mod = @import("overlay.zig"); |
14 |
const overlay_mod = @import("overlay.zig"); |
| @@ -22,50 +16,47 @@ const overlay_mod = @import("overlay.zig"); |
| 22 |
const Display = display_mod.Display; |
16 |
const Display = display_mod.Display; |
| 23 |
const Client = client_mod.Client; |
17 |
const Client = client_mod.Client; |
| 24 |
const Monitor = monitor_mod.Monitor; |
18 |
const Monitor = monitor_mod.Monitor; |
|
|
19 |
+const WindowManager = wm_mod.WindowManager; |
| 25 |
|
20 |
|
| 26 |
-var running: bool = true; |
|
|
| 27 |
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
21 |
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| 28 |
|
22 |
|
| 29 |
-var atoms: Atoms = undefined; |
|
|
| 30 |
-var wm_check_window: xlib.Window = undefined; |
|
|
| 31 |
- |
|
|
| 32 |
-const Cursors = struct { |
|
|
| 33 |
- normal: xlib.Cursor, |
|
|
| 34 |
- resize: xlib.Cursor, |
|
|
| 35 |
- move: xlib.Cursor, |
|
|
| 36 |
- |
|
|
| 37 |
- fn init(display: *Display) Cursors { |
|
|
| 38 |
- return .{ |
|
|
| 39 |
- .normal = xlib.XCreateFontCursor(display.handle, xlib.XC_left_ptr), |
|
|
| 40 |
- .resize = xlib.XCreateFontCursor(display.handle, xlib.XC_sizing), |
|
|
| 41 |
- .move = xlib.XCreateFontCursor(display.handle, xlib.XC_fleur), |
|
|
| 42 |
- }; |
|
|
| 43 |
- } |
|
|
| 44 |
-}; |
|
|
| 45 |
- |
|
|
| 46 |
-var cursors: Cursors = undefined; |
|
|
| 47 |
- |
|
|
| 48 |
const NormalState: c_long = 1; |
23 |
const NormalState: c_long = 1; |
| 49 |
const WithdrawnState: c_long = 0; |
24 |
const WithdrawnState: c_long = 0; |
| 50 |
const IconicState: c_long = 3; |
25 |
const IconicState: c_long = 3; |
| 51 |
const IsViewable: c_int = 2; |
26 |
const IsViewable: c_int = 2; |
| 52 |
const snap_distance: i32 = 32; |
27 |
const snap_distance: i32 = 32; |
| 53 |
|
28 |
|
| 54 |
-var numlock_mask: c_uint = 0; |
29 |
+// Remaining module-level state |
| 55 |
|
30 |
|
|
|
31 |
+/// Config built from Lua, passed into WindowManager.init. |
| 56 |
var config: config_mod.Config = undefined; |
32 |
var config: config_mod.Config = undefined; |
|
|
33 |
+/// Path to the loaded config file, kept for hot-reload. |
| 57 |
var config_path_global: ?[]const u8 = null; |
34 |
var config_path_global: ?[]const u8 = null; |
| 58 |
|
35 |
|
| 59 |
-/// Interim pointer to the X11 display, used only by `arrange` until the |
36 |
+/// TODO(wm-refactor): move into WindowManager, waiting on handle_key_press |
| 60 |
-/// WindowManager struct refactor moves display ownership there properly. |
37 |
+/// and execute_action being converted to methods. |
|
|
38 |
+var chord = @import("keyboard/chord.zig").ChordState{}; |
|
|
39 |
+ |
|
|
40 |
+/// TODO(wm-refactor): remove once all callers are WindowManager methods. |
|
|
41 |
+/// Aliases wm.atoms so existing functions that take display but not wm |
|
|
42 |
+/// can still reach atom values without requiring a full signature change. |
|
|
43 |
+var atoms: @import("x11/atoms.zig").Atoms = undefined; |
|
|
44 |
+ |
|
|
45 |
+/// TODO(wm-refactor): move into WindowManager, waiting on arrange() becoming |
|
|
46 |
+/// a method so it can access self.display directly. |
| 61 |
var wm_display: ?*Display = null; |
47 |
var wm_display: ?*Display = null; |
| 62 |
|
48 |
|
| 63 |
-var scroll_animation: animations.Scroll_Animation = .{}; |
49 |
+/// TODO(wm-refactor): remove once all callers are WindowManager methods. |
| 64 |
-var animation_config: animations.Animation_Config = .{ .duration_ms = 150, .easing = .ease_out }; |
50 |
+/// Used only by functions that need to invalidate bars but don't yet receive |
|
|
51 |
+/// wm as a parameter. |
|
|
52 |
+var wm_ptr: ?*WindowManager = null; |
| 65 |
|
53 |
|
| 66 |
-var chord = kchord.ChordState{}; |
54 |
+/// TODO(wm-refactor): move into WindowManager. |
|
|
55 |
+var numlock_mask: c_uint = 0; |
| 67 |
|
56 |
|
| 68 |
-var keybind_overlay: ?*overlay_mod.Keybind_Overlay = null; |
57 |
+/// File descriptor of the X11 connection, used in spawn_child_setup. |
|
|
58 |
+/// Set from wm.x11_fd after init. |
|
|
59 |
+var x11_fd: c_int = -1; |
| 69 |
|
60 |
|
| 70 |
fn print_help() void { |
61 |
fn print_help() void { |
| 71 |
std.debug.print( |
62 |
std.debug.print( |
| @@ -98,6 +89,7 @@ fn get_config_path(allocator: std.mem.Allocator) ![]u8 { |
| 98 |
const home = std.posix.getenv("HOME") orelse return error.CouldNotGetHomeDir; |
89 |
const home = std.posix.getenv("HOME") orelse return error.CouldNotGetHomeDir; |
| 99 |
break :blk try std.fs.path.join(allocator, &.{ home, ".config" }); |
90 |
break :blk try std.fs.path.join(allocator, &.{ home, ".config" }); |
| 100 |
}; |
91 |
}; |
|
|
92 |
+ // TODO: wtf is this shit |
| 101 |
defer if (std.posix.getenv("XDG_CONFIG_HOME") == null) allocator.free(config_home); |
93 |
defer if (std.posix.getenv("XDG_CONFIG_HOME") == null) allocator.free(config_home); |
| 102 |
|
94 |
|
| 103 |
const config_path = try std.fs.path.join(allocator, &.{ config_home, "oxwm", "config.lua" }); |
95 |
const config_path = try std.fs.path.join(allocator, &.{ config_home, "oxwm", "config.lua" }); |
| @@ -201,7 +193,6 @@ pub fn main() !void { |
| 201 |
std.debug.print("oxwm starting\n", .{}); |
193 |
std.debug.print("oxwm starting\n", .{}); |
| 202 |
|
194 |
|
| 203 |
config = config_mod.Config.init(allocator); |
195 |
config = config_mod.Config.init(allocator); |
| 204 |
- defer config.deinit(); |
|
|
| 205 |
|
196 |
|
| 206 |
if (lua.init(&config)) { |
197 |
if (lua.init(&config)) { |
| 207 |
const loaded = if (std.fs.cwd().statFile(config_path)) |_| |
198 |
const loaded = if (std.fs.cwd().statFile(config_path)) |_| |
| @@ -223,229 +214,34 @@ pub fn main() !void { |
| 223 |
initialize_default_config(); |
214 |
initialize_default_config(); |
| 224 |
} |
215 |
} |
| 225 |
|
216 |
|
| 226 |
- var display = Display.open() catch |err| { |
217 |
+ var wm = WindowManager.init(allocator, config, config_path_global) catch |err| { |
| 227 |
- std.debug.print("failed to open display: {}\n", .{err}); |
218 |
+ std.debug.print("failed to start window manager: {}\n", .{err}); |
| 228 |
return; |
219 |
return; |
| 229 |
}; |
220 |
}; |
| 230 |
- defer display.close(); |
221 |
+ defer wm.deinit(); |
| 231 |
- |
|
|
| 232 |
- x11_fd = xlib.XConnectionNumber(display.handle); |
|
|
| 233 |
- wm_display = &display; |
|
|
| 234 |
|
222 |
|
| 235 |
- std.debug.print("display opened: screen={d} root=0x{x}\n", .{ display.screen, display.root }); |
223 |
+ // Propagate values that transitional code in this file still reads |
| 236 |
- std.debug.print("screen size: {d}x{d}\n", .{ display.screen_width(), display.screen_height() }); |
224 |
+ // from module-level vars. These will be removed soon. |
| 237 |
- |
225 |
+ x11_fd = wm.x11_fd; |
| 238 |
- display.become_window_manager() catch |err| { |
226 |
+ wm_display = &wm.display; |
| 239 |
- std.debug.print("failed to become window manager: {}\n", .{err}); |
227 |
+ wm_ptr = &wm; |
| 240 |
- return; |
228 |
+ atoms = wm.atoms; |
| 241 |
- }; |
|
|
| 242 |
|
229 |
|
|
|
230 |
+ std.debug.print("display opened: screen={d} root=0x{x}\n", .{ wm.display.screen, wm.display.root }); |
| 243 |
std.debug.print("successfully became window manager\n", .{}); |
231 |
std.debug.print("successfully became window manager\n", .{}); |
| 244 |
- |
|
|
| 245 |
- const atoms_result = Atoms.init(display.handle, display.root); |
|
|
| 246 |
- atoms = atoms_result.atoms; |
|
|
| 247 |
- wm_check_window = atoms_result.check_window; |
|
|
| 248 |
std.debug.print("atoms initialized with EWMH support\n", .{}); |
232 |
std.debug.print("atoms initialized with EWMH support\n", .{}); |
| 249 |
|
233 |
|
| 250 |
- cursors = Cursors.init(&display); |
234 |
+ grab_keybinds(&wm.display); |
| 251 |
- _ = xlib.XDefineCursor(display.handle, display.root, cursors.normal); |
235 |
+ scan_existing_windows(&wm.display); |
| 252 |
- monitor_mod.init(allocator); |
|
|
| 253 |
- tiling.set_display(display.handle); |
|
|
| 254 |
- tiling.set_screen_size(display.screen_width(), display.screen_height()); |
|
|
| 255 |
- |
|
|
| 256 |
- setup_monitors(&display); |
|
|
| 257 |
- setup_bars(allocator, &display); |
|
|
| 258 |
- setup_overlay(allocator, &display); |
|
|
| 259 |
- grab_keybinds(&display); |
|
|
| 260 |
- scan_existing_windows(&display); |
|
|
| 261 |
|
236 |
|
| 262 |
try run_autostart_commands(allocator, config.autostart.items); |
237 |
try run_autostart_commands(allocator, config.autostart.items); |
| 263 |
std.debug.print("entering event loop\n", .{}); |
238 |
std.debug.print("entering event loop\n", .{}); |
| 264 |
- run_event_loop(&display); |
239 |
+ run_event_loop(&wm); |
| 265 |
- |
|
|
| 266 |
- bar_mod.destroy_bars(allocator, display.handle); |
|
|
| 267 |
- |
|
|
| 268 |
- var mon = monitor_mod.monitors; |
|
|
| 269 |
- while (mon) |m| { |
|
|
| 270 |
- const next = m.next; |
|
|
| 271 |
- monitor_mod.destroy(m); |
|
|
| 272 |
- mon = next; |
|
|
| 273 |
- } |
|
|
| 274 |
- |
|
|
| 275 |
- if (keybind_overlay) |overlay| { |
|
|
| 276 |
- overlay.deinit(allocator); |
|
|
| 277 |
- } |
|
|
| 278 |
|
240 |
|
| 279 |
lua.deinit(); |
241 |
lua.deinit(); |
| 280 |
std.debug.print("oxwm exiting\n", .{}); |
242 |
std.debug.print("oxwm exiting\n", .{}); |
| 281 |
} |
243 |
} |
| 282 |
|
244 |
|
| 283 |
-fn setup_bars(allocator: std.mem.Allocator, display: *Display) void { |
|
|
| 284 |
- var current_monitor = monitor_mod.monitors; |
|
|
| 285 |
- var last_bar: ?*bar_mod.Bar = null; |
|
|
| 286 |
- |
|
|
| 287 |
- while (current_monitor) |monitor| { |
|
|
| 288 |
- const bar = bar_mod.Bar.create(allocator, display.handle, display.screen, monitor, config); |
|
|
| 289 |
- if (bar) |created_bar| { |
|
|
| 290 |
- if (tiling.bar_height == 0) { |
|
|
| 291 |
- tiling.set_bar_height(created_bar.height); |
|
|
| 292 |
- } |
|
|
| 293 |
- |
|
|
| 294 |
- if (config.blocks.items.len > 0) { |
|
|
| 295 |
- for (config.blocks.items) |cfg_block| { |
|
|
| 296 |
- const block = config_block_to_bar_block(cfg_block); |
|
|
| 297 |
- created_bar.add_block(block); |
|
|
| 298 |
- } |
|
|
| 299 |
- } else { |
|
|
| 300 |
- created_bar.add_block(blocks_mod.Block.init_ram("", 5, 0x7aa2f7, true)); |
|
|
| 301 |
- created_bar.add_block(blocks_mod.Block.init_static(" | ", 0x666666, false)); |
|
|
| 302 |
- created_bar.add_block(blocks_mod.Block.init_datetime("", "%H:%M", 1, 0x0db9d7, true)); |
|
|
| 303 |
- } |
|
|
| 304 |
- |
|
|
| 305 |
- if (last_bar) |prev| { |
|
|
| 306 |
- prev.next = created_bar; |
|
|
| 307 |
- } else { |
|
|
| 308 |
- bar_mod.bars = created_bar; |
|
|
| 309 |
- } |
|
|
| 310 |
- last_bar = created_bar; |
|
|
| 311 |
- std.debug.print("bar created for monitor {d}\n", .{monitor.num}); |
|
|
| 312 |
- } |
|
|
| 313 |
- current_monitor = monitor.next; |
|
|
| 314 |
- } |
|
|
| 315 |
-} |
|
|
| 316 |
- |
|
|
| 317 |
-fn setup_overlay(allocator: std.mem.Allocator, display: *Display) void { |
|
|
| 318 |
- keybind_overlay = overlay_mod.Keybind_Overlay.init(display.handle, display.screen, display.root, config.font, allocator); |
|
|
| 319 |
-} |
|
|
| 320 |
- |
|
|
| 321 |
-fn config_block_to_bar_block(cfg: config_mod.Block) blocks_mod.Block { |
|
|
| 322 |
- return switch (cfg.block_type) { |
|
|
| 323 |
- .static => blocks_mod.Block.init_static(cfg.format, cfg.color, cfg.underline), |
|
|
| 324 |
- .datetime => blocks_mod.Block.init_datetime(cfg.format, cfg.datetime_format orelse "%H:%M", cfg.interval, cfg.color, cfg.underline), |
|
|
| 325 |
- .ram => blocks_mod.Block.init_ram(cfg.format, cfg.interval, cfg.color, cfg.underline), |
|
|
| 326 |
- .shell => blocks_mod.Block.init_shell(cfg.format, cfg.command orelse "", cfg.interval, cfg.color, cfg.underline), |
|
|
| 327 |
- .battery => blocks_mod.Block.init_battery( |
|
|
| 328 |
- cfg.format_charging orelse "", |
|
|
| 329 |
- cfg.format_discharging orelse "", |
|
|
| 330 |
- cfg.format_full orelse "", |
|
|
| 331 |
- cfg.battery_name orelse "BAT0", |
|
|
| 332 |
- cfg.interval, |
|
|
| 333 |
- cfg.color, |
|
|
| 334 |
- cfg.underline, |
|
|
| 335 |
- ), |
|
|
| 336 |
- .cpu_temp => blocks_mod.Block.init_cpu_temp( |
|
|
| 337 |
- cfg.format, |
|
|
| 338 |
- cfg.thermal_zone orelse "thermal_zone0", |
|
|
| 339 |
- cfg.interval, |
|
|
| 340 |
- cfg.color, |
|
|
| 341 |
- cfg.underline, |
|
|
| 342 |
- ), |
|
|
| 343 |
- }; |
|
|
| 344 |
-} |
|
|
| 345 |
- |
|
|
| 346 |
-fn setup_monitors(display: *Display) void { |
|
|
| 347 |
- std.debug.print("checking xinerama...\n", .{}); |
|
|
| 348 |
- if (xlib.XineramaIsActive(display.handle) != 0) { |
|
|
| 349 |
- std.debug.print("xinerama is active!\n", .{}); |
|
|
| 350 |
- var screen_count: c_int = 0; |
|
|
| 351 |
- const screens = xlib.XineramaQueryScreens(display.handle, &screen_count); |
|
|
| 352 |
- |
|
|
| 353 |
- if (screen_count > 0 and screens != null) { |
|
|
| 354 |
- var prev_monitor: ?*Monitor = null; |
|
|
| 355 |
- var index: usize = 0; |
|
|
| 356 |
- |
|
|
| 357 |
- while (index < @as(usize, @intCast(screen_count))) : (index += 1) { |
|
|
| 358 |
- const screen = screens[index]; |
|
|
| 359 |
- const mon = monitor_mod.create() orelse continue; |
|
|
| 360 |
- |
|
|
| 361 |
- mon.num = @intCast(index); |
|
|
| 362 |
- mon.mon_x = screen.x_org; |
|
|
| 363 |
- mon.mon_y = screen.y_org; |
|
|
| 364 |
- mon.mon_w = screen.width; |
|
|
| 365 |
- mon.mon_h = screen.height; |
|
|
| 366 |
- mon.win_x = screen.x_org; |
|
|
| 367 |
- mon.win_y = screen.y_org; |
|
|
| 368 |
- mon.win_w = screen.width; |
|
|
| 369 |
- mon.win_h = screen.height; |
|
|
| 370 |
- mon.lt[0] = &tiling.layout; |
|
|
| 371 |
- mon.lt[1] = &monocle.layout; |
|
|
| 372 |
- mon.lt[2] = &floating.layout; |
|
|
| 373 |
- mon.lt[3] = &scrolling.layout; |
|
|
| 374 |
- mon.lt[4] = &grid.layout; |
|
|
| 375 |
- for (0..10) |i| { |
|
|
| 376 |
- mon.pertag.ltidxs[i][0] = mon.lt[0]; |
|
|
| 377 |
- mon.pertag.ltidxs[i][1] = mon.lt[1]; |
|
|
| 378 |
- mon.pertag.ltidxs[i][2] = mon.lt[2]; |
|
|
| 379 |
- mon.pertag.ltidxs[i][3] = mon.lt[3]; |
|
|
| 380 |
- mon.pertag.ltidxs[i][4] = mon.lt[4]; |
|
|
| 381 |
- } |
|
|
| 382 |
- |
|
|
| 383 |
- init_monitor_gaps(mon); |
|
|
| 384 |
- |
|
|
| 385 |
- if (prev_monitor) |prev| { |
|
|
| 386 |
- prev.next = mon; |
|
|
| 387 |
- } else { |
|
|
| 388 |
- monitor_mod.monitors = mon; |
|
|
| 389 |
- } |
|
|
| 390 |
- prev_monitor = mon; |
|
|
| 391 |
- |
|
|
| 392 |
- std.debug.print("monitor {d}: {d}x{d} at ({d},{d})\n", .{ index, mon.mon_w, mon.mon_h, mon.mon_x, mon.mon_y }); |
|
|
| 393 |
- } |
|
|
| 394 |
- |
|
|
| 395 |
- monitor_mod.selected_monitor = monitor_mod.monitors; |
|
|
| 396 |
- _ = xlib.XFree(@ptrCast(screens)); |
|
|
| 397 |
- return; |
|
|
| 398 |
- } |
|
|
| 399 |
- } else { |
|
|
| 400 |
- std.debug.print("xinerama not active, using single monitor\n", .{}); |
|
|
| 401 |
- } |
|
|
| 402 |
- |
|
|
| 403 |
- const mon = monitor_mod.create() orelse return; |
|
|
| 404 |
- mon.mon_x = 0; |
|
|
| 405 |
- mon.mon_y = 0; |
|
|
| 406 |
- mon.mon_w = display.screen_width(); |
|
|
| 407 |
- mon.mon_h = display.screen_height(); |
|
|
| 408 |
- mon.win_x = 0; |
|
|
| 409 |
- mon.win_y = 0; |
|
|
| 410 |
- mon.win_w = display.screen_width(); |
|
|
| 411 |
- mon.win_h = display.screen_height(); |
|
|
| 412 |
- mon.lt[0] = &tiling.layout; |
|
|
| 413 |
- mon.lt[1] = &monocle.layout; |
|
|
| 414 |
- mon.lt[2] = &floating.layout; |
|
|
| 415 |
- mon.lt[3] = &scrolling.layout; |
|
|
| 416 |
- mon.lt[4] = &grid.layout; |
|
|
| 417 |
- for (0..10) |i| { |
|
|
| 418 |
- mon.pertag.ltidxs[i][0] = mon.lt[0]; |
|
|
| 419 |
- mon.pertag.ltidxs[i][1] = mon.lt[1]; |
|
|
| 420 |
- mon.pertag.ltidxs[i][2] = mon.lt[2]; |
|
|
| 421 |
- mon.pertag.ltidxs[i][3] = mon.lt[3]; |
|
|
| 422 |
- mon.pertag.ltidxs[i][4] = mon.lt[4]; |
|
|
| 423 |
- } |
|
|
| 424 |
- |
|
|
| 425 |
- init_monitor_gaps(mon); |
|
|
| 426 |
- |
|
|
| 427 |
- monitor_mod.monitors = mon; |
|
|
| 428 |
- monitor_mod.selected_monitor = mon; |
|
|
| 429 |
- std.debug.print("monitor created: {d}x{d}\n", .{ mon.mon_w, mon.mon_h }); |
|
|
| 430 |
-} |
|
|
| 431 |
- |
|
|
| 432 |
-fn init_monitor_gaps(mon: *Monitor) void { |
|
|
| 433 |
- const any_gap_nonzero = config.gap_inner_h != 0 or config.gap_inner_v != 0 or |
|
|
| 434 |
- config.gap_outer_h != 0 or config.gap_outer_v != 0; |
|
|
| 435 |
- |
|
|
| 436 |
- if (config.gaps_enabled and any_gap_nonzero) { |
|
|
| 437 |
- mon.gap_inner_h = config.gap_inner_h; |
|
|
| 438 |
- mon.gap_inner_v = config.gap_inner_v; |
|
|
| 439 |
- mon.gap_outer_h = config.gap_outer_h; |
|
|
| 440 |
- mon.gap_outer_v = config.gap_outer_v; |
|
|
| 441 |
- } else { |
|
|
| 442 |
- mon.gap_inner_h = 0; |
|
|
| 443 |
- mon.gap_inner_v = 0; |
|
|
| 444 |
- mon.gap_outer_h = 0; |
|
|
| 445 |
- mon.gap_outer_v = 0; |
|
|
| 446 |
- } |
|
|
| 447 |
-} |
|
|
| 448 |
- |
|
|
| 449 |
fn make_keybind(mod: u32, key: u64, action: config_mod.Action) config_mod.Keybind { |
245 |
fn make_keybind(mod: u32, key: u64, action: config_mod.Action) config_mod.Keybind { |
| 450 |
var kb: config_mod.Keybind = .{ .action = action }; |
246 |
var kb: config_mod.Keybind = .{ .action = action }; |
| 451 |
kb.keys[0] = .{ .mod_mask = mod, .keysym = key }; |
247 |
kb.keys[0] = .{ .mod_mask = mod, .keysym = key }; |
| @@ -634,35 +430,34 @@ fn scan_existing_windows(display: *Display) void { |
| 634 |
} |
430 |
} |
| 635 |
} |
431 |
} |
| 636 |
|
432 |
|
| 637 |
-fn run_event_loop(display: *Display) void { |
433 |
+fn run_event_loop(wm: *WindowManager) void { |
| 638 |
- const fd = xlib.XConnectionNumber(display.handle); |
|
|
| 639 |
var fds = [_]std.posix.pollfd{ |
434 |
var fds = [_]std.posix.pollfd{ |
| 640 |
- .{ .fd = fd, .events = std.posix.POLL.IN, .revents = 0 }, |
435 |
+ .{ .fd = wm.x11_fd, .events = std.posix.POLL.IN, .revents = 0 }, |
| 641 |
}; |
436 |
}; |
| 642 |
|
437 |
|
| 643 |
- _ = xlib.XSync(display.handle, xlib.False); |
438 |
+ _ = xlib.XSync(wm.display.handle, xlib.False); |
| 644 |
|
439 |
|
| 645 |
- while (running) { |
440 |
+ while (wm.running) { |
| 646 |
- while (xlib.XPending(display.handle) > 0) { |
441 |
+ while (xlib.XPending(wm.display.handle) > 0) { |
| 647 |
- var event = display.next_event(); |
442 |
+ var event = wm.display.next_event(); |
| 648 |
- handle_event(display, &event); |
443 |
+ handle_event(&wm.display, &event, wm); |
| 649 |
} |
444 |
} |
| 650 |
|
445 |
|
| 651 |
- tick_animations(); |
446 |
+ tick_animations(wm); |
| 652 |
|
447 |
|
| 653 |
- var current_bar = bar_mod.bars; |
448 |
+ var current_bar = wm.bars; |
| 654 |
while (current_bar) |bar| { |
449 |
while (current_bar) |bar| { |
| 655 |
bar.update_blocks(); |
450 |
bar.update_blocks(); |
| 656 |
- bar.draw(display.handle, &config.tags, config); |
451 |
+ bar.draw(wm.display.handle, wm.config); |
| 657 |
current_bar = bar.next; |
452 |
current_bar = bar.next; |
| 658 |
} |
453 |
} |
| 659 |
|
454 |
|
| 660 |
- const poll_timeout: i32 = if (scroll_animation.is_active()) 16 else 1000; |
455 |
+ const poll_timeout: i32 = if (wm.scroll_animation.is_active()) 16 else 1000; |
| 661 |
_ = std.posix.poll(&fds, poll_timeout) catch 0; |
456 |
_ = std.posix.poll(&fds, poll_timeout) catch 0; |
| 662 |
} |
457 |
} |
| 663 |
} |
458 |
} |
| 664 |
|
459 |
|
| 665 |
-fn handle_event(display: *Display, event: *xlib.XEvent) void { |
460 |
+fn handle_event(display: *Display, event: *xlib.XEvent, wm: *WindowManager) void { |
| 666 |
const event_type = events.get_event_type(event); |
461 |
const event_type = events.get_event_type(event); |
| 667 |
|
462 |
|
| 668 |
if (event_type == .button_press) { |
463 |
if (event_type == .button_press) { |
| @@ -672,15 +467,15 @@ fn handle_event(display: *Display, event: *xlib.XEvent) void { |
| 672 |
switch (event_type) { |
467 |
switch (event_type) { |
| 673 |
.map_request => handle_map_request(display, &event.xmaprequest), |
468 |
.map_request => handle_map_request(display, &event.xmaprequest), |
| 674 |
.configure_request => handle_configure_request(display, &event.xconfigurerequest), |
469 |
.configure_request => handle_configure_request(display, &event.xconfigurerequest), |
| 675 |
- .key_press => handle_key_press(display, &event.xkey), |
470 |
+ .key_press => handle_key_press(display, &event.xkey, wm), |
| 676 |
.destroy_notify => handle_destroy_notify(display, &event.xdestroywindow), |
471 |
.destroy_notify => handle_destroy_notify(display, &event.xdestroywindow), |
| 677 |
.unmap_notify => handle_unmap_notify(display, &event.xunmap), |
472 |
.unmap_notify => handle_unmap_notify(display, &event.xunmap), |
| 678 |
- .enter_notify => handle_enter_notify(display, &event.xcrossing), |
473 |
+ .enter_notify => handle_enter_notify(display, &event.xcrossing, wm), |
| 679 |
.focus_in => handle_focus_in(display, &event.xfocus), |
474 |
.focus_in => handle_focus_in(display, &event.xfocus), |
| 680 |
- .motion_notify => handle_motion_notify(display, &event.xmotion), |
475 |
+ .motion_notify => handle_motion_notify(display, &event.xmotion, wm), |
| 681 |
.client_message => handle_client_message(display, &event.xclient), |
476 |
.client_message => handle_client_message(display, &event.xclient), |
| 682 |
- .button_press => handle_button_press(display, &event.xbutton), |
477 |
+ .button_press => handle_button_press(display, &event.xbutton, wm), |
| 683 |
- .expose => handle_expose(display, &event.xexpose), |
478 |
+ .expose => handle_expose(display, &event.xexpose, wm), |
| 684 |
.property_notify => handle_property_notify(display, &event.xproperty), |
479 |
.property_notify => handle_property_notify(display, &event.xproperty), |
| 685 |
else => {}, |
480 |
else => {}, |
| 686 |
} |
481 |
} |
| @@ -843,42 +638,37 @@ fn handle_configure_request(display: *Display, event: *xlib.XConfigureRequestEve |
| 843 |
_ = xlib.XSync(display.handle, xlib.False); |
638 |
_ = xlib.XSync(display.handle, xlib.False); |
| 844 |
} |
639 |
} |
| 845 |
|
640 |
|
| 846 |
-fn reset_chord_state(display_handle: *xlib.Display) void { |
641 |
+fn handle_key_press(display: *Display, event: *xlib.XKeyEvent, wm: *WindowManager) void { |
| 847 |
- chord.reset(display_handle); |
|
|
| 848 |
-} |
|
|
| 849 |
- |
|
|
| 850 |
-fn handle_key_press(display: *Display, event: *xlib.XKeyEvent) void { |
|
|
| 851 |
const keysym = xlib.XKeycodeToKeysym(display.handle, @intCast(event.keycode), 0); |
642 |
const keysym = xlib.XKeycodeToKeysym(display.handle, @intCast(event.keycode), 0); |
| 852 |
|
643 |
|
| 853 |
- if (keybind_overlay) |overlay| { |
644 |
+ if (wm.overlay) |overlay| { |
| 854 |
- if (overlay.handle_key(keysym)) { |
645 |
+ if (overlay.handle_key(keysym)) return; |
| 855 |
- return; |
|
|
| 856 |
- } |
|
|
| 857 |
} |
646 |
} |
| 858 |
|
647 |
|
| 859 |
const clean_state = event.state & ~@as(c_uint, xlib.LockMask | xlib.Mod2Mask); |
648 |
const clean_state = event.state & ~@as(c_uint, xlib.LockMask | xlib.Mod2Mask); |
| 860 |
- const current_time = std.time.milliTimestamp(); |
|
|
| 861 |
|
649 |
|
| 862 |
- if (chord.index > 0 and (current_time - chord.last_timestamp) > kchord.timeout_ms) { |
650 |
+ if (wm.chord.is_timed_out()) { |
| 863 |
- reset_chord_state(display.handle); |
651 |
+ wm.chord.reset(display.handle); |
| 864 |
} |
652 |
} |
| 865 |
|
653 |
|
| 866 |
- _ = chord.push(.{ .mod_mask = clean_state, .keysym = keysym }); |
654 |
+ _ = wm.chord.push(.{ .mod_mask = clean_state, .keysym = keysym }); |
| 867 |
|
655 |
|
| 868 |
for (config.keybinds.items) |keybind| { |
656 |
for (config.keybinds.items) |keybind| { |
| 869 |
if (keybind.key_count == 0) continue; |
657 |
if (keybind.key_count == 0) continue; |
| 870 |
|
658 |
|
| 871 |
- if (keybind.key_count == chord.index) { |
659 |
+ if (keybind.key_count == wm.chord.index) { |
| 872 |
var matches = true; |
660 |
var matches = true; |
| 873 |
for (0..keybind.key_count) |i| { |
661 |
for (0..keybind.key_count) |i| { |
| 874 |
- if (chord.keys[i].keysym != keybind.keys[i].keysym or chord.keys[i].mod_mask != keybind.keys[i].mod_mask) { |
662 |
+ if (wm.chord.keys[i].keysym != keybind.keys[i].keysym or |
|
|
663 |
+ wm.chord.keys[i].mod_mask != keybind.keys[i].mod_mask) |
|
|
664 |
+ { |
| 875 |
matches = false; |
665 |
matches = false; |
| 876 |
break; |
666 |
break; |
| 877 |
} |
667 |
} |
| 878 |
} |
668 |
} |
| 879 |
if (matches) { |
669 |
if (matches) { |
| 880 |
- execute_action(display, keybind.action, keybind.int_arg, keybind.str_arg); |
670 |
+ execute_action(display, keybind.action, keybind.int_arg, keybind.str_arg, wm); |
| 881 |
- reset_chord_state(display.handle); |
671 |
+ wm.chord.reset(display.handle); |
| 882 |
return; |
672 |
return; |
| 883 |
} |
673 |
} |
| 884 |
} |
674 |
} |
| @@ -886,10 +676,12 @@ fn handle_key_press(display: *Display, event: *xlib.XKeyEvent) void { |
| 886 |
|
676 |
|
| 887 |
var has_partial_match = false; |
677 |
var has_partial_match = false; |
| 888 |
for (config.keybinds.items) |keybind| { |
678 |
for (config.keybinds.items) |keybind| { |
| 889 |
- if (keybind.key_count > chord.index) { |
679 |
+ if (keybind.key_count > wm.chord.index) { |
| 890 |
var matches = true; |
680 |
var matches = true; |
| 891 |
- for (0..chord.index) |i| { |
681 |
+ for (0..wm.chord.index) |i| { |
| 892 |
- if (chord.keys[i].keysym != keybind.keys[i].keysym or chord.keys[i].mod_mask != keybind.keys[i].mod_mask) { |
682 |
+ if (wm.chord.keys[i].keysym != keybind.keys[i].keysym or |
|
|
683 |
+ wm.chord.keys[i].mod_mask != keybind.keys[i].mod_mask) |
|
|
684 |
+ { |
| 893 |
matches = false; |
685 |
matches = false; |
| 894 |
break; |
686 |
break; |
| 895 |
} |
687 |
} |
| @@ -902,32 +694,30 @@ fn handle_key_press(display: *Display, event: *xlib.XKeyEvent) void { |
| 902 |
} |
694 |
} |
| 903 |
|
695 |
|
| 904 |
if (has_partial_match) { |
696 |
if (has_partial_match) { |
| 905 |
- chord.grab_keyboard(display.handle, display.root); |
697 |
+ wm.chord.grab_keyboard(display.handle, display.root); |
| 906 |
- } else if (!has_partial_match) { |
698 |
+ } else { |
| 907 |
- reset_chord_state(display.handle); |
699 |
+ wm.chord.reset(display.handle); |
| 908 |
} |
700 |
} |
| 909 |
} |
701 |
} |
| 910 |
|
702 |
|
| 911 |
-fn execute_action(display: *Display, action: config_mod.Action, int_arg: i32, str_arg: ?[]const u8) void { |
703 |
+fn execute_action(display: *Display, action: config_mod.Action, int_arg: i32, str_arg: ?[]const u8, wm: *WindowManager) void { |
| 912 |
switch (action) { |
704 |
switch (action) { |
| 913 |
.spawn_terminal => spawn_terminal(), |
705 |
.spawn_terminal => spawn_terminal(), |
| 914 |
.spawn => { |
706 |
.spawn => { |
| 915 |
- if (str_arg) |cmd| { |
707 |
+ if (str_arg) |cmd| spawn_command(cmd); |
| 916 |
- spawn_command(cmd); |
|
|
| 917 |
- } |
|
|
| 918 |
}, |
708 |
}, |
| 919 |
.kill_client => kill_focused(display), |
709 |
.kill_client => kill_focused(display), |
| 920 |
.quit => { |
710 |
.quit => { |
| 921 |
std.debug.print("quit keybind pressed\n", .{}); |
711 |
std.debug.print("quit keybind pressed\n", .{}); |
| 922 |
- running = false; |
712 |
+ wm.running = false; |
| 923 |
}, |
713 |
}, |
| 924 |
- .reload_config => reload_config(display), |
714 |
+ .reload_config => reload_config(display, wm), |
| 925 |
- .restart => reload_config(display), |
715 |
+ .restart => reload_config(display, wm), |
| 926 |
.show_keybinds => { |
716 |
.show_keybinds => { |
| 927 |
- if (keybind_overlay) |overlay| { |
717 |
+ if (wm.overlay) |overlay| { |
| 928 |
- const mon = monitor_mod.selected_monitor orelse monitor_mod.monitors; |
718 |
+ const mon = wm.selected_monitor orelse wm.monitors; |
| 929 |
if (mon) |m| { |
719 |
if (mon) |m| { |
| 930 |
- overlay.toggle(m.mon_x, m.mon_y, m.mon_w, m.mon_h, &config); |
720 |
+ overlay.toggle(m.mon_x, m.mon_y, m.mon_w, m.mon_h, &wm.config); |
| 931 |
} |
721 |
} |
| 932 |
} |
722 |
} |
| 933 |
}, |
723 |
}, |
| @@ -967,16 +757,12 @@ fn execute_action(display: *Display, action: config_mod.Action, int_arg: i32, st |
| 967 |
}, |
757 |
}, |
| 968 |
.focus_monitor => focusmon(display, int_arg), |
758 |
.focus_monitor => focusmon(display, int_arg), |
| 969 |
.send_to_monitor => sendmon(display, int_arg), |
759 |
.send_to_monitor => sendmon(display, int_arg), |
| 970 |
- .scroll_left => { |
760 |
+ .scroll_left => scroll_layout(-1, wm), |
| 971 |
- scroll_layout(-1); |
761 |
+ .scroll_right => scroll_layout(1, wm), |
| 972 |
- }, |
|
|
| 973 |
- .scroll_right => { |
|
|
| 974 |
- scroll_layout(1); |
|
|
| 975 |
- }, |
|
|
| 976 |
} |
762 |
} |
| 977 |
} |
763 |
} |
| 978 |
|
764 |
|
| 979 |
-fn reload_config(display: *Display) void { |
765 |
+fn reload_config(display: *Display, wm: *WindowManager) void { |
| 980 |
std.debug.print("reloading config...\n", .{}); |
766 |
std.debug.print("reloading config...\n", .{}); |
| 981 |
|
767 |
|
| 982 |
ungrab_keybinds(display); |
768 |
ungrab_keybinds(display); |
| @@ -1005,27 +791,19 @@ fn reload_config(display: *Display) void { |
| 1005 |
initialize_default_config(); |
791 |
initialize_default_config(); |
| 1006 |
} |
792 |
} |
| 1007 |
|
793 |
|
| 1008 |
- bar_mod.destroy_bars(gpa.allocator(), display.handle); |
794 |
+ bar_mod.destroy_bars(wm.bars, gpa.allocator(), display.handle); |
| 1009 |
- setup_bars(gpa.allocator(), display); |
795 |
+ wm.bars = null; |
| 1010 |
- rebuild_bar_blocks(); |
796 |
+ wm.setup_bars(); |
|
|
797 |
+ rebuild_bar_blocks(wm); |
| 1011 |
|
798 |
|
| 1012 |
grab_keybinds(display); |
799 |
grab_keybinds(display); |
| 1013 |
} |
800 |
} |
| 1014 |
|
801 |
|
| 1015 |
-fn rebuild_bar_blocks() void { |
802 |
+fn rebuild_bar_blocks(wm: *WindowManager) void { |
| 1016 |
- var current_bar = bar_mod.bars; |
803 |
+ var current_bar = wm.bars; |
| 1017 |
while (current_bar) |bar| { |
804 |
while (current_bar) |bar| { |
| 1018 |
bar.clear_blocks(); |
805 |
bar.clear_blocks(); |
| 1019 |
- if (config.blocks.items.len > 0) { |
806 |
+ wm.populate_bar_blocks(bar); |
| 1020 |
- for (config.blocks.items) |cfg_block| { |
|
|
| 1021 |
- const block = config_block_to_bar_block(cfg_block); |
|
|
| 1022 |
- bar.add_block(block); |
|
|
| 1023 |
- } |
|
|
| 1024 |
- } else { |
|
|
| 1025 |
- bar.add_block(blocks_mod.Block.init_ram("", 5, 0x7aa2f7, true)); |
|
|
| 1026 |
- bar.add_block(blocks_mod.Block.init_static(" | ", 0x666666, false)); |
|
|
| 1027 |
- bar.add_block(blocks_mod.Block.init_datetime("", "%H:%M", 1, 0x0db9d7, true)); |
|
|
| 1028 |
- } |
|
|
| 1029 |
current_bar = bar.next; |
807 |
current_bar = bar.next; |
| 1030 |
} |
808 |
} |
| 1031 |
} |
809 |
} |
| @@ -1034,10 +812,6 @@ fn ungrab_keybinds(display: *Display) void { |
| 1034 |
_ = xlib.XUngrabKey(display.handle, xlib.AnyKey, xlib.AnyModifier, display.root); |
812 |
_ = xlib.XUngrabKey(display.handle, xlib.AnyKey, xlib.AnyModifier, display.root); |
| 1035 |
} |
813 |
} |
| 1036 |
|
814 |
|
| 1037 |
-/// File descriptor for the X11 connection. Set once after the display is |
|
|
| 1038 |
-/// opened and used only in post-fork child setup to close the inherited fd. |
|
|
| 1039 |
-var x11_fd: c_int = -1; |
|
|
| 1040 |
- |
|
|
| 1041 |
fn spawn_child_setup() void { |
815 |
fn spawn_child_setup() void { |
| 1042 |
_ = std.c.setsid(); |
816 |
_ = std.c.setsid(); |
| 1043 |
if (x11_fd >= 0) std.posix.close(@intCast(x11_fd)); |
817 |
if (x11_fd >= 0) std.posix.close(@intCast(x11_fd)); |
| @@ -1173,7 +947,7 @@ fn toggle_view(display: *Display, tag_mask: u32) void { |
| 1173 |
|
947 |
|
| 1174 |
focus_top_client(display, monitor); |
948 |
focus_top_client(display, monitor); |
| 1175 |
arrange(monitor); |
949 |
arrange(monitor); |
| 1176 |
- bar_mod.invalidate_bars(); |
950 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 1177 |
} |
951 |
} |
| 1178 |
} |
952 |
} |
| 1179 |
|
953 |
|
| @@ -1185,7 +959,7 @@ fn toggle_client_tag(display: *Display, tag_mask: u32) void { |
| 1185 |
client.tags = new_tags; |
959 |
client.tags = new_tags; |
| 1186 |
focus_top_client(display, monitor); |
960 |
focus_top_client(display, monitor); |
| 1187 |
arrange(monitor); |
961 |
arrange(monitor); |
| 1188 |
- bar_mod.invalidate_bars(); |
962 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 1189 |
} |
963 |
} |
| 1190 |
} |
964 |
} |
| 1191 |
|
965 |
|
| @@ -1309,7 +1083,7 @@ fn view(display: *Display, tag_mask: u32) void { |
| 1309 |
|
1083 |
|
| 1310 |
focus_top_client(display, monitor); |
1084 |
focus_top_client(display, monitor); |
| 1311 |
arrange(monitor); |
1085 |
arrange(monitor); |
| 1312 |
- bar_mod.invalidate_bars(); |
1086 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 1313 |
std.debug.print("view: tag_mask={d}\n", .{monitor.tagset[monitor.sel_tags]}); |
1087 |
std.debug.print("view: tag_mask={d}\n", .{monitor.tagset[monitor.sel_tags]}); |
| 1314 |
} |
1088 |
} |
| 1315 |
|
1089 |
|
| @@ -1365,7 +1139,7 @@ fn tag_client(display: *Display, tag_mask: u32) void { |
| 1365 |
client.tags = tag_mask; |
1139 |
client.tags = tag_mask; |
| 1366 |
focus_top_client(display, monitor); |
1140 |
focus_top_client(display, monitor); |
| 1367 |
arrange(monitor); |
1141 |
arrange(monitor); |
| 1368 |
- bar_mod.invalidate_bars(); |
1142 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 1369 |
std.debug.print("tag_client: window=0x{x} tag_mask={d}\n", .{ client.window, tag_mask }); |
1143 |
std.debug.print("tag_client: window=0x{x} tag_mask={d}\n", .{ client.window, tag_mask }); |
| 1370 |
} |
1144 |
} |
| 1371 |
|
1145 |
|
| @@ -1485,7 +1259,7 @@ fn cycle_layout() void { |
| 1485 |
monitor.scroll_offset = 0; |
1259 |
monitor.scroll_offset = 0; |
| 1486 |
} |
1260 |
} |
| 1487 |
arrange(monitor); |
1261 |
arrange(monitor); |
| 1488 |
- bar_mod.invalidate_bars(); |
1262 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 1489 |
if (monitor.lt[monitor.sel_lt]) |layout| { |
1263 |
if (monitor.lt[monitor.sel_lt]) |layout| { |
| 1490 |
std.debug.print("cycle_layout: {s}\n", .{layout.symbol}); |
1264 |
std.debug.print("cycle_layout: {s}\n", .{layout.symbol}); |
| 1491 |
} |
1265 |
} |
| @@ -1516,7 +1290,7 @@ fn set_layout(layout_name: ?[]const u8) void { |
| 1516 |
monitor.scroll_offset = 0; |
1290 |
monitor.scroll_offset = 0; |
| 1517 |
} |
1291 |
} |
| 1518 |
arrange(monitor); |
1292 |
arrange(monitor); |
| 1519 |
- bar_mod.invalidate_bars(); |
1293 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 1520 |
if (monitor.lt[monitor.sel_lt]) |layout| { |
1294 |
if (monitor.lt[monitor.sel_lt]) |layout| { |
| 1521 |
std.debug.print("set_layout: {s}\n", .{layout.symbol}); |
1295 |
std.debug.print("set_layout: {s}\n", .{layout.symbol}); |
| 1522 |
} |
1296 |
} |
| @@ -1530,7 +1304,7 @@ fn set_layout_index(index: u32) void { |
| 1530 |
monitor.scroll_offset = 0; |
1304 |
monitor.scroll_offset = 0; |
| 1531 |
} |
1305 |
} |
| 1532 |
arrange(monitor); |
1306 |
arrange(monitor); |
| 1533 |
- bar_mod.invalidate_bars(); |
1307 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 1534 |
if (monitor.lt[monitor.sel_lt]) |layout| { |
1308 |
if (monitor.lt[monitor.sel_lt]) |layout| { |
| 1535 |
std.debug.print("set_layout_index: {s}\n", .{layout.symbol}); |
1309 |
std.debug.print("set_layout_index: {s}\n", .{layout.symbol}); |
| 1536 |
} |
1310 |
} |
| @@ -1591,7 +1365,7 @@ fn snap_y(client: *Client, new_y: i32, monitor: *Monitor) i32 { |
| 1591 |
return new_y; |
1365 |
return new_y; |
| 1592 |
} |
1366 |
} |
| 1593 |
|
1367 |
|
| 1594 |
-fn movemouse(display: *Display) void { |
1368 |
+fn movemouse(display: *Display, wm: *WindowManager) void { |
| 1595 |
const monitor = monitor_mod.selected_monitor orelse return; |
1369 |
const monitor = monitor_mod.selected_monitor orelse return; |
| 1596 |
const client = monitor.sel orelse return; |
1370 |
const client = monitor.sel orelse return; |
| 1597 |
|
1371 |
|
| @@ -1622,7 +1396,7 @@ fn movemouse(display: *Display) void { |
| 1622 |
xlib.GrabModeAsync, |
1396 |
xlib.GrabModeAsync, |
| 1623 |
xlib.GrabModeAsync, |
1397 |
xlib.GrabModeAsync, |
| 1624 |
xlib.None, |
1398 |
xlib.None, |
| 1625 |
- cursors.move, |
1399 |
+ wm.cursors.move, |
| 1626 |
xlib.CurrentTime, |
1400 |
xlib.CurrentTime, |
| 1627 |
); |
1401 |
); |
| 1628 |
|
1402 |
|
| @@ -1698,7 +1472,7 @@ fn movemouse(display: *Display) void { |
| 1698 |
} |
1472 |
} |
| 1699 |
} |
1473 |
} |
| 1700 |
|
1474 |
|
| 1701 |
-fn resizemouse(display: *Display) void { |
1475 |
+fn resizemouse(display: *Display, wm: *WindowManager) void { |
| 1702 |
const monitor = monitor_mod.selected_monitor orelse return; |
1476 |
const monitor = monitor_mod.selected_monitor orelse return; |
| 1703 |
const client = monitor.sel orelse return; |
1477 |
const client = monitor.sel orelse return; |
| 1704 |
|
1478 |
|
| @@ -1720,7 +1494,7 @@ fn resizemouse(display: *Display) void { |
| 1720 |
xlib.GrabModeAsync, |
1494 |
xlib.GrabModeAsync, |
| 1721 |
xlib.GrabModeAsync, |
1495 |
xlib.GrabModeAsync, |
| 1722 |
xlib.None, |
1496 |
xlib.None, |
| 1723 |
- cursors.resize, |
1497 |
+ wm.cursors.resize, |
| 1724 |
xlib.CurrentTime, |
1498 |
xlib.CurrentTime, |
| 1725 |
); |
1499 |
); |
| 1726 |
|
1500 |
|
| @@ -1771,12 +1545,11 @@ fn resizemouse(display: *Display) void { |
| 1771 |
arrange(monitor); |
1545 |
arrange(monitor); |
| 1772 |
} |
1546 |
} |
| 1773 |
|
1547 |
|
| 1774 |
-fn handle_expose(display: *Display, event: *xlib.XExposeEvent) void { |
1548 |
+fn handle_expose(display: *Display, event: *xlib.XExposeEvent, wm: *WindowManager) void { |
| 1775 |
if (event.count != 0) return; |
1549 |
if (event.count != 0) return; |
| 1776 |
- |
1550 |
+ if (bar_mod.window_to_bar(wm.bars, event.window)) |bar| { |
| 1777 |
- if (bar_mod.window_to_bar(event.window)) |bar| { |
|
|
| 1778 |
bar.invalidate(); |
1551 |
bar.invalidate(); |
| 1779 |
- bar.draw(display.handle, &config.tags, config); |
1552 |
+ bar.draw(display.handle, wm.config); |
| 1780 |
} |
1553 |
} |
| 1781 |
} |
1554 |
} |
| 1782 |
|
1555 |
|
| @@ -1792,7 +1565,7 @@ fn clean_mask(mask: c_uint) c_uint { |
| 1792 |
return mask & ~(lock | numlock_mask) & (shift | ctrl | mod1 | mod2 | mod3 | mod4 | mod5); |
1565 |
return mask & ~(lock | numlock_mask) & (shift | ctrl | mod1 | mod2 | mod3 | mod4 | mod5); |
| 1793 |
} |
1566 |
} |
| 1794 |
|
1567 |
|
| 1795 |
-fn handle_button_press(display: *Display, event: *xlib.XButtonEvent) void { |
1568 |
+fn handle_button_press(display: *Display, event: *xlib.XButtonEvent, wm: *WindowManager) void { |
| 1796 |
std.debug.print("button_press: window=0x{x} subwindow=0x{x}\n", .{ event.window, event.subwindow }); |
1569 |
std.debug.print("button_press: window=0x{x} subwindow=0x{x}\n", .{ event.window, event.subwindow }); |
| 1797 |
|
1570 |
|
| 1798 |
const clicked_monitor = monitor_mod.window_to_monitor(display.handle, display.root, event.window); |
1571 |
const clicked_monitor = monitor_mod.window_to_monitor(display.handle, display.root, event.window); |
| @@ -1806,8 +1579,8 @@ fn handle_button_press(display: *Display, event: *xlib.XButtonEvent) void { |
| 1806 |
} |
1579 |
} |
| 1807 |
} |
1580 |
} |
| 1808 |
|
1581 |
|
| 1809 |
- if (bar_mod.window_to_bar(event.window)) |bar| { |
1582 |
+ if (bar_mod.window_to_bar(wm.bars, event.window)) |bar| { |
| 1810 |
- const clicked_tag = bar.handle_click(event.x, &config.tags); |
1583 |
+ const clicked_tag = bar.handle_click(display.handle, event.x, wm.config); |
| 1811 |
if (clicked_tag) |tag_index| { |
1584 |
if (clicked_tag) |tag_index| { |
| 1812 |
const tag_mask: u32 = @as(u32, 1) << @intCast(tag_index); |
1585 |
const tag_mask: u32 = @as(u32, 1) << @intCast(tag_index); |
| 1813 |
view(display, tag_mask); |
1586 |
view(display, tag_mask); |
| @@ -1830,8 +1603,8 @@ fn handle_button_press(display: *Display, event: *xlib.XButtonEvent) void { |
| 1830 |
const button_clean_mask = clean_mask(button.mod_mask); |
1603 |
const button_clean_mask = clean_mask(button.mod_mask); |
| 1831 |
if (clean_state == button_clean_mask and event.button == button.button) { |
1604 |
if (clean_state == button_clean_mask and event.button == button.button) { |
| 1832 |
switch (button.action) { |
1605 |
switch (button.action) { |
| 1833 |
- .move_mouse => movemouse(display), |
1606 |
+ .move_mouse => movemouse(display, wm), |
| 1834 |
- .resize_mouse => resizemouse(display), |
1607 |
+ .resize_mouse => resizemouse(display, wm), |
| 1835 |
.toggle_floating => { |
1608 |
.toggle_floating => { |
| 1836 |
if (click_client) |found_client| { |
1609 |
if (click_client) |found_client| { |
| 1837 |
found_client.is_floating = !found_client.is_floating; |
1610 |
found_client.is_floating = !found_client.is_floating; |
| @@ -1933,10 +1706,11 @@ fn unmanage(display: *Display, client: *Client) void { |
| 1933 |
|
1706 |
|
| 1934 |
client_mod.destroy(gpa.allocator(), client); |
1707 |
client_mod.destroy(gpa.allocator(), client); |
| 1935 |
update_client_list(display); |
1708 |
update_client_list(display); |
| 1936 |
- bar_mod.invalidate_bars(); |
1709 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 1937 |
} |
1710 |
} |
| 1938 |
|
1711 |
|
| 1939 |
-fn handle_enter_notify(display: *Display, event: *xlib.XCrossingEvent) void { |
1712 |
+fn handle_enter_notify(display: *Display, event: *xlib.XCrossingEvent, wm: *WindowManager) void { |
|
|
1713 |
+ _ = wm; |
| 1940 |
if ((event.mode != xlib.NotifyNormal or event.detail == xlib.NotifyInferior) and event.window != display.root) { |
1714 |
if ((event.mode != xlib.NotifyNormal or event.detail == xlib.NotifyInferior) and event.window != display.root) { |
| 1941 |
return; |
1715 |
return; |
| 1942 |
} |
1716 |
} |
| @@ -1977,22 +1751,18 @@ fn set_focus(display: *Display, client: *Client) void { |
| 1977 |
_ = send_event(display, client, atoms.wm_take_focus); |
1751 |
_ = send_event(display, client, atoms.wm_take_focus); |
| 1978 |
} |
1752 |
} |
| 1979 |
|
1753 |
|
| 1980 |
-var last_motion_monitor: ?*Monitor = null; |
1754 |
+fn handle_motion_notify(display: *Display, event: *xlib.XMotionEvent, wm: *WindowManager) void { |
| 1981 |
- |
1755 |
+ if (event.window != display.root) return; |
| 1982 |
-fn handle_motion_notify(display: *Display, event: *xlib.XMotionEvent) void { |
|
|
| 1983 |
- if (event.window != display.root) { |
|
|
| 1984 |
- return; |
|
|
| 1985 |
- } |
|
|
| 1986 |
|
1756 |
|
| 1987 |
const target_mon = monitor_mod.rect_to_monitor(event.x_root, event.y_root, 1, 1); |
1757 |
const target_mon = monitor_mod.rect_to_monitor(event.x_root, event.y_root, 1, 1); |
| 1988 |
- if (target_mon != last_motion_monitor and last_motion_monitor != null) { |
1758 |
+ if (target_mon != wm.last_motion_monitor and wm.last_motion_monitor != null) { |
| 1989 |
if (monitor_mod.selected_monitor) |selmon| { |
1759 |
if (monitor_mod.selected_monitor) |selmon| { |
| 1990 |
unfocus_client(display, selmon.sel, true); |
1760 |
unfocus_client(display, selmon.sel, true); |
| 1991 |
} |
1761 |
} |
| 1992 |
monitor_mod.selected_monitor = target_mon; |
1762 |
monitor_mod.selected_monitor = target_mon; |
| 1993 |
focus(display, null); |
1763 |
focus(display, null); |
| 1994 |
} |
1764 |
} |
| 1995 |
- last_motion_monitor = target_mon; |
1765 |
+ wm.last_motion_monitor = target_mon; |
| 1996 |
} |
1766 |
} |
| 1997 |
|
1767 |
|
| 1998 |
fn handle_property_notify(display: *Display, event: *xlib.XPropertyEvent) void { |
1768 |
fn handle_property_notify(display: *Display, event: *xlib.XPropertyEvent) void { |
| @@ -2016,7 +1786,7 @@ fn handle_property_notify(display: *Display, event: *xlib.XPropertyEvent) void { |
| 2016 |
client.hints_valid = false; |
1786 |
client.hints_valid = false; |
| 2017 |
} else if (event.atom == xlib.XA_WM_HINTS) { |
1787 |
} else if (event.atom == xlib.XA_WM_HINTS) { |
| 2018 |
update_wm_hints(display, client); |
1788 |
update_wm_hints(display, client); |
| 2019 |
- bar_mod.invalidate_bars(); |
1789 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 2020 |
} else if (event.atom == xlib.XA_WM_NAME or event.atom == atoms.net_wm_name) { |
1790 |
} else if (event.atom == xlib.XA_WM_NAME or event.atom == atoms.net_wm_name) { |
| 2021 |
update_title(display, client); |
1791 |
update_title(display, client); |
| 2022 |
} else if (event.atom == atoms.net_wm_window_type) { |
1792 |
} else if (event.atom == atoms.net_wm_window_type) { |
| @@ -2140,15 +1910,15 @@ fn focus(display: *Display, target_client: ?*Client) void { |
| 2140 |
|
1910 |
|
| 2141 |
if (focus_client) |client| { |
1911 |
if (focus_client) |client| { |
| 2142 |
if (is_scrolling_layout(current_selmon)) { |
1912 |
if (is_scrolling_layout(current_selmon)) { |
| 2143 |
- scroll_to_window(client, true); |
1913 |
+ scroll_to_window(client, true, wm_ptr orelse return); |
| 2144 |
} |
1914 |
} |
| 2145 |
} |
1915 |
} |
| 2146 |
|
1916 |
|
| 2147 |
- bar_mod.invalidate_bars(); |
1917 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 2148 |
} |
1918 |
} |
| 2149 |
|
1919 |
|
| 2150 |
fn restack(display: *Display, monitor: *Monitor) void { |
1920 |
fn restack(display: *Display, monitor: *Monitor) void { |
| 2151 |
- bar_mod.invalidate_bars(); |
1921 |
+ if (wm_ptr) |wm| wm.invalidate_bars(); |
| 2152 |
const selected_client = monitor.sel orelse return; |
1922 |
const selected_client = monitor.sel orelse return; |
| 2153 |
|
1923 |
|
| 2154 |
if (selected_client.is_floating or monitor.lt[monitor.sel_lt] == null) { |
1924 |
if (selected_client.is_floating or monitor.lt[monitor.sel_lt] == null) { |
| @@ -2177,7 +1947,7 @@ fn restack(display: *Display, monitor: *Monitor) void { |
| 2177 |
} |
1947 |
} |
| 2178 |
|
1948 |
|
| 2179 |
fn arrange(monitor: *Monitor) void { |
1949 |
fn arrange(monitor: *Monitor) void { |
| 2180 |
- // TODO: display will become a WindowManager field; for now |
1950 |
+ // TODO(wm-refactor): display will become a WindowManager field; for now |
| 2181 |
// we use a module-level pointer set once after the display is opened. |
1951 |
// we use a module-level pointer set once after the display is opened. |
| 2182 |
if (wm_display) |display| { |
1952 |
if (wm_display) |display| { |
| 2183 |
showhide(display, monitor); |
1953 |
showhide(display, monitor); |
| @@ -2192,11 +1962,11 @@ fn arrange(monitor: *Monitor) void { |
| 2192 |
} |
1962 |
} |
| 2193 |
} |
1963 |
} |
| 2194 |
|
1964 |
|
| 2195 |
-fn tick_animations() void { |
1965 |
+fn tick_animations(wm: *WindowManager) void { |
| 2196 |
- if (!scroll_animation.is_active()) return; |
1966 |
+ if (!wm.scroll_animation.is_active()) return; |
| 2197 |
|
1967 |
|
| 2198 |
- const monitor = monitor_mod.selected_monitor orelse return; |
1968 |
+ const monitor = wm.selected_monitor orelse return; |
| 2199 |
- if (scroll_animation.update()) |new_offset| { |
1969 |
+ if (wm.scroll_animation.update()) |new_offset| { |
| 2200 |
monitor.scroll_offset = new_offset; |
1970 |
monitor.scroll_offset = new_offset; |
| 2201 |
arrange(monitor); |
1971 |
arrange(monitor); |
| 2202 |
} |
1972 |
} |
| @@ -2209,32 +1979,32 @@ fn is_scrolling_layout(monitor: *Monitor) bool { |
| 2209 |
return false; |
1979 |
return false; |
| 2210 |
} |
1980 |
} |
| 2211 |
|
1981 |
|
| 2212 |
-fn scroll_layout(direction: i32) void { |
1982 |
+fn scroll_layout(direction: i32, wm: *WindowManager) void { |
| 2213 |
- const monitor = monitor_mod.selected_monitor orelse return; |
1983 |
+ const monitor = wm.selected_monitor orelse return; |
| 2214 |
if (!is_scrolling_layout(monitor)) return; |
1984 |
if (!is_scrolling_layout(monitor)) return; |
| 2215 |
|
1985 |
|
| 2216 |
const scroll_step = scrolling.get_scroll_step(monitor); |
1986 |
const scroll_step = scrolling.get_scroll_step(monitor); |
| 2217 |
const max_scroll = scrolling.get_max_scroll(monitor); |
1987 |
const max_scroll = scrolling.get_max_scroll(monitor); |
| 2218 |
|
1988 |
|
| 2219 |
- const current = if (scroll_animation.is_active()) |
1989 |
+ const current = if (wm.scroll_animation.is_active()) |
| 2220 |
- scroll_animation.target() |
1990 |
+ wm.scroll_animation.target() |
| 2221 |
else |
1991 |
else |
| 2222 |
monitor.scroll_offset; |
1992 |
monitor.scroll_offset; |
| 2223 |
|
1993 |
|
| 2224 |
var target = current + direction * scroll_step; |
1994 |
var target = current + direction * scroll_step; |
| 2225 |
target = @max(0, @min(target, max_scroll)); |
1995 |
target = @max(0, @min(target, max_scroll)); |
| 2226 |
|
1996 |
|
| 2227 |
- scroll_animation.start(monitor.scroll_offset, target, animation_config); |
1997 |
+ wm.scroll_animation.start(monitor.scroll_offset, target, wm.animation_config); |
| 2228 |
} |
1998 |
} |
| 2229 |
|
1999 |
|
| 2230 |
-fn scroll_to_window(client: *Client, animate: bool) void { |
2000 |
+fn scroll_to_window(client: *Client, animate: bool, wm: *WindowManager) void { |
| 2231 |
const monitor = client.monitor orelse return; |
2001 |
const monitor = client.monitor orelse return; |
| 2232 |
if (!is_scrolling_layout(monitor)) return; |
2002 |
if (!is_scrolling_layout(monitor)) return; |
| 2233 |
|
2003 |
|
| 2234 |
const target = scrolling.get_target_scroll_for_window(monitor, client); |
2004 |
const target = scrolling.get_target_scroll_for_window(monitor, client); |
| 2235 |
|
2005 |
|
| 2236 |
if (animate) { |
2006 |
if (animate) { |
| 2237 |
- scroll_animation.start(monitor.scroll_offset, target, animation_config); |
2007 |
+ wm.scroll_animation.start(monitor.scroll_offset, target, wm.animation_config); |
| 2238 |
} else { |
2008 |
} else { |
| 2239 |
monitor.scroll_offset = target; |
2009 |
monitor.scroll_offset = target; |
| 2240 |
arrange(monitor); |
2010 |
arrange(monitor); |