|
|
@@ -226,6 +226,29 @@ fn make_keybind_str(mod: u32, key: u64, action: config_mod.Action, str_arg: []co |
| 226 |
226 |
return kb; |
| 227 |
227 |
} |
| 228 |
228 |
|
|
229 |
+/// Config-loading callback for wm.reload_config(). |
|
230 |
+/// Re-initialises Lua and loads the config file (or falls back to defaults). |
|
231 |
+fn reload_load_config(wm: *WindowManager) void { |
|
232 |
+ lua.deinit(); |
|
233 |
+ _ = lua.init(&wm.config); |
|
234 |
+ |
|
235 |
+ const loaded = if (wm.config_path) |path| |
|
236 |
+ lua.load_file(path) |
|
237 |
+ else |
|
238 |
+ lua.load_config(); |
|
239 |
+ |
|
240 |
+ if (loaded) { |
|
241 |
+ if (wm.config_path) |path| { |
|
242 |
+ std.debug.print("reloaded config from {s}\n", .{path}); |
|
243 |
+ } else { |
|
244 |
+ std.debug.print("reloaded config from ~/.config/oxwm/config.lua\n", .{}); |
|
245 |
+ } |
|
246 |
+ } else { |
|
247 |
+ std.debug.print("reload failed, restoring defaults\n", .{}); |
|
248 |
+ initialize_default_config(&wm.config); |
|
249 |
+ } |
|
250 |
+} |
|
251 |
+ |
| 229 |
252 |
fn initialize_default_config(cfg: *config_mod.Config) void { |
| 230 |
253 |
const mod_key: u32 = 1 << 6; |
| 231 |
254 |
const shift_key: u32 = 1 << 0; |
|
|
@@ -521,8 +544,8 @@ fn execute_action(action: config_mod.Action, int_arg: i32, str_arg: ?[]const u8, |
| 521 |
544 |
std.debug.print("quit keybind pressed\n", .{}); |
| 522 |
545 |
wm.running = false; |
| 523 |
546 |
}, |
| 524 |
|
- .reload_config => reload_config(wm), |
| 525 |
|
- .restart => reload_config(wm), |
|
547 |
+ .reload_config => wm.reload_config(reload_load_config), |
|
548 |
+ .restart => wm.reload_config(reload_load_config), |
| 526 |
549 |
.show_keybinds => { |
| 527 |
550 |
if (wm.overlay) |overlay| { |
| 528 |
551 |
const mon = wm.selected_monitor orelse wm.monitors; |
|
|
@@ -572,43 +595,6 @@ fn execute_action(action: config_mod.Action, int_arg: i32, str_arg: ?[]const u8, |
| 572 |
595 |
} |
| 573 |
596 |
} |
| 574 |
597 |
|
| 575 |
|
-fn reload_config(wm: *WindowManager) void { |
| 576 |
|
- std.debug.print("reloading config...\n", .{}); |
| 577 |
|
- |
| 578 |
|
- wm.ungrab_keybinds(); |
| 579 |
|
- |
| 580 |
|
- wm.config.keybinds.clearRetainingCapacity(); |
| 581 |
|
- wm.config.buttons.clearRetainingCapacity(); |
| 582 |
|
- wm.config.rules.clearRetainingCapacity(); |
| 583 |
|
- wm.config.blocks.clearRetainingCapacity(); |
| 584 |
|
- |
| 585 |
|
- lua.deinit(); |
| 586 |
|
- _ = lua.init(&wm.config); |
| 587 |
|
- |
| 588 |
|
- const loaded = if (wm.config_path) |path| |
| 589 |
|
- lua.load_file(path) |
| 590 |
|
- else |
| 591 |
|
- lua.load_config(); |
| 592 |
|
- |
| 593 |
|
- if (loaded) { |
| 594 |
|
- if (wm.config_path) |path| { |
| 595 |
|
- std.debug.print("reloaded config from {s}\n", .{path}); |
| 596 |
|
- } else { |
| 597 |
|
- std.debug.print("reloaded config from ~/.config/oxwm/config.lua\n", .{}); |
| 598 |
|
- } |
| 599 |
|
- } else { |
| 600 |
|
- std.debug.print("reload failed, restoring defaults\n", .{}); |
| 601 |
|
- initialize_default_config(&wm.config); |
| 602 |
|
- } |
| 603 |
|
- |
| 604 |
|
- bar_mod.destroy_bars(wm.bars, gpa.allocator(), wm.display.handle); |
| 605 |
|
- wm.bars = null; |
| 606 |
|
- wm.setup_bars(); |
| 607 |
|
- wm.rebuild_bar_blocks(); |
| 608 |
|
- |
| 609 |
|
- wm.grab_keybinds(); |
| 610 |
|
-} |
| 611 |
|
- |
| 612 |
598 |
fn spawn_child_setup() void { |
| 613 |
599 |
_ = std.c.setsid(); |
| 614 |
600 |
if (x11_fd >= 0) std.posix.close(@intCast(x11_fd)); |