|
|
@@ -12,7 +12,6 @@ const bar_mod = @import("bar/bar.zig"); |
| 12 |
12 |
const config_mod = @import("config/config.zig"); |
| 13 |
13 |
const lua = @import("config/lua.zig"); |
| 14 |
14 |
|
| 15 |
|
-const Display = display_mod.Display; |
| 16 |
15 |
const Client = client_mod.Client; |
| 17 |
16 |
const Monitor = monitor_mod.Monitor; |
| 18 |
17 |
const WindowManager = wm_mod.WindowManager; |
|
|
@@ -200,7 +199,7 @@ pub fn main() !void { |
| 200 |
199 |
std.debug.print("successfully became window manager\n", .{}); |
| 201 |
200 |
std.debug.print("atoms initialized with EWMH support\n", .{}); |
| 202 |
201 |
|
| 203 |
|
- grab_keybinds(&wm); |
|
202 |
+ wm.grab_keybinds(); |
| 204 |
203 |
scan_existing_windows(&wm); |
| 205 |
204 |
|
| 206 |
205 |
try run_autostart_commands(allocator, wm.config.autostart.items); |
|
|
@@ -271,53 +270,6 @@ fn initialize_default_config(cfg: *config_mod.Config) void { |
| 271 |
270 |
cfg.add_button(.{ .click = .client_win, .mod_mask = mod_key, .button = 3, .action = .resize_mouse }) catch {}; |
| 272 |
271 |
} |
| 273 |
272 |
|
| 274 |
|
-fn grab_keybinds(wm: *WindowManager) void { |
| 275 |
|
- update_numlock_mask(wm); |
| 276 |
|
- const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask }; |
| 277 |
|
- |
| 278 |
|
- _ = xlib.XUngrabKey(wm.display.handle, xlib.AnyKey, xlib.AnyModifier, wm.display.root); |
| 279 |
|
- |
| 280 |
|
- for (wm.config.keybinds.items) |keybind| { |
| 281 |
|
- if (keybind.key_count == 0) continue; |
| 282 |
|
- const first_key = keybind.keys[0]; |
| 283 |
|
- const keycode = xlib.XKeysymToKeycode(wm.display.handle, @intCast(first_key.keysym)); |
| 284 |
|
- if (keycode != 0) { |
| 285 |
|
- for (modifiers) |modifier| { |
| 286 |
|
- _ = xlib.XGrabKey( |
| 287 |
|
- wm.display.handle, |
| 288 |
|
- keycode, |
| 289 |
|
- first_key.mod_mask | modifier, |
| 290 |
|
- wm.display.root, |
| 291 |
|
- xlib.True, |
| 292 |
|
- xlib.GrabModeAsync, |
| 293 |
|
- xlib.GrabModeAsync, |
| 294 |
|
- ); |
| 295 |
|
- } |
| 296 |
|
- } |
| 297 |
|
- } |
| 298 |
|
- |
| 299 |
|
- for (wm.config.buttons.items) |button| { |
| 300 |
|
- if (button.click == .client_win) { |
| 301 |
|
- for (modifiers) |modifier| { |
| 302 |
|
- _ = xlib.XGrabButton( |
| 303 |
|
- wm.display.handle, |
| 304 |
|
- @intCast(button.button), |
| 305 |
|
- button.mod_mask | modifier, |
| 306 |
|
- wm.display.root, |
| 307 |
|
- xlib.True, |
| 308 |
|
- xlib.ButtonPressMask | xlib.ButtonReleaseMask | xlib.PointerMotionMask, |
| 309 |
|
- xlib.GrabModeAsync, |
| 310 |
|
- xlib.GrabModeAsync, |
| 311 |
|
- xlib.None, |
| 312 |
|
- xlib.None, |
| 313 |
|
- ); |
| 314 |
|
- } |
| 315 |
|
- } |
| 316 |
|
- } |
| 317 |
|
- |
| 318 |
|
- std.debug.print("grabbed {d} keybinds from config\n", .{wm.config.keybinds.items.len}); |
| 319 |
|
-} |
| 320 |
|
- |
| 321 |
273 |
fn get_state(window: xlib.Window, wm: *WindowManager) c_long { |
| 322 |
274 |
var actual_type: xlib.Atom = 0; |
| 323 |
275 |
var actual_format: c_int = 0; |
|
|
@@ -734,7 +686,7 @@ fn execute_action(action: config_mod.Action, int_arg: i32, str_arg: ?[]const u8, |
| 734 |
686 |
fn reload_config(wm: *WindowManager) void { |
| 735 |
687 |
std.debug.print("reloading config...\n", .{}); |
| 736 |
688 |
|
| 737 |
|
- ungrab_keybinds(wm); |
|
689 |
+ wm.ungrab_keybinds(); |
| 738 |
690 |
|
| 739 |
691 |
wm.config.keybinds.clearRetainingCapacity(); |
| 740 |
692 |
wm.config.buttons.clearRetainingCapacity(); |
|
|
@@ -763,22 +715,9 @@ fn reload_config(wm: *WindowManager) void { |
| 763 |
715 |
bar_mod.destroy_bars(wm.bars, gpa.allocator(), wm.display.handle); |
| 764 |
716 |
wm.bars = null; |
| 765 |
717 |
wm.setup_bars(); |
| 766 |
|
- rebuild_bar_blocks(wm); |
| 767 |
|
- |
| 768 |
|
- grab_keybinds(wm); |
| 769 |
|
-} |
| 770 |
|
- |
| 771 |
|
-fn rebuild_bar_blocks(wm: *WindowManager) void { |
| 772 |
|
- var current_bar = wm.bars; |
| 773 |
|
- while (current_bar) |bar| { |
| 774 |
|
- bar.clear_blocks(); |
| 775 |
|
- wm.populate_bar_blocks(bar); |
| 776 |
|
- current_bar = bar.next; |
| 777 |
|
- } |
| 778 |
|
-} |
|
718 |
+ wm.rebuild_bar_blocks(); |
| 779 |
719 |
|
| 780 |
|
-fn ungrab_keybinds(wm: *WindowManager) void { |
| 781 |
|
- _ = xlib.XUngrabKey(wm.display.handle, xlib.AnyKey, xlib.AnyModifier, wm.display.root); |
|
720 |
+ wm.grab_keybinds(); |
| 782 |
721 |
} |
| 783 |
722 |
|
| 784 |
723 |
fn spawn_child_setup() void { |
|
|
@@ -1778,28 +1717,8 @@ fn set_client_state(client: *Client, state: c_long, wm: *WindowManager) void { |
| 1778 |
1717 |
_ = xlib.c.XChangeProperty(wm.display.handle, client.window, wm.atoms.wm_state, xlib.XA_ATOM, 32, xlib.PropModeReplace, @ptrCast(&data), 2); |
| 1779 |
1718 |
} |
| 1780 |
1719 |
|
| 1781 |
|
-fn update_numlock_mask(wm: *WindowManager) void { |
| 1782 |
|
- wm.numlock_mask = 0; |
| 1783 |
|
- const modmap = xlib.XGetModifierMapping(wm.display.handle); |
| 1784 |
|
- if (modmap == null) return; |
| 1785 |
|
- defer _ = xlib.XFreeModifiermap(modmap); |
| 1786 |
|
- |
| 1787 |
|
- const numlock_keycode = xlib.XKeysymToKeycode(wm.display.handle, xlib.XK_Num_Lock); |
| 1788 |
|
- |
| 1789 |
|
- var modifier_index: usize = 0; |
| 1790 |
|
- while (modifier_index < 8) : (modifier_index += 1) { |
| 1791 |
|
- var key_index: usize = 0; |
| 1792 |
|
- while (key_index < @as(usize, @intCast(modmap.*.max_keypermod))) : (key_index += 1) { |
| 1793 |
|
- const keycode = modmap.*.modifiermap[modifier_index * @as(usize, @intCast(modmap.*.max_keypermod)) + key_index]; |
| 1794 |
|
- if (keycode == numlock_keycode) { |
| 1795 |
|
- wm.numlock_mask = @as(c_uint, 1) << @intCast(modifier_index); |
| 1796 |
|
- } |
| 1797 |
|
- } |
| 1798 |
|
- } |
| 1799 |
|
-} |
| 1800 |
|
- |
| 1801 |
1720 |
fn grabbuttons(client: *Client, focused: bool, wm: *WindowManager) void { |
| 1802 |
|
- update_numlock_mask(wm); |
|
1721 |
+ wm.update_numlock_mask(); |
| 1803 |
1722 |
const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask }; |
| 1804 |
1723 |
|
| 1805 |
1724 |
_ = xlib.XUngrabButton(wm.display.handle, xlib.AnyButton, xlib.AnyModifier, client.window); |