Updated with master.
Browse files
+11 −5 build.zig
| @@ -4,6 +4,8 @@ const zon = @import("build.zig.zon"); | ||
| 4 | 4 | pub fn build(b: *std.Build) void { |
| 5 | 5 | const target = b.standardTargetOptions(.{}); |
| 6 | 6 | const optimize = b.standardOptimizeOption(.{}); |
| 7 | + const lua_dep = b.dependency("lua", .{}); | |
| 8 | + const lua_headers = lua_dep.path("src/"); | |
| 7 | 9 | |
| 8 | 10 | const exe = b.addExecutable(.{ |
| 9 | 11 | .name = "oxwm", |
| @@ -24,7 +26,7 @@ pub fn build(b: *std.Build) void { | ||
| 24 | 26 | |
| 25 | 27 | exe.use_lld = false; |
| 26 | 28 | |
| 27 | - const lua = buildLua(b, target, optimize); | |
| 29 | + const lua = buildLua(b, lua_dep, target, optimize); | |
| 28 | 30 | exe.linkLibrary(lua); |
| 29 | 31 | exe.linkSystemLibrary("X11"); |
| 30 | 32 | exe.linkSystemLibrary("Xinerama"); |
| @@ -61,6 +63,7 @@ pub fn build(b: *std.Build) void { | ||
| 61 | 63 | }), |
| 62 | 64 | }); |
| 63 | 65 | src_main_unit_tests.use_lld = false; |
| 66 | + src_main_unit_tests.root_module.addIncludePath(lua_headers); | |
| 64 | 67 | src_main_unit_tests.linkLibrary(lua); |
| 65 | 68 | src_main_unit_tests.linkSystemLibrary("X11"); |
| 66 | 69 | src_main_unit_tests.linkSystemLibrary("Xinerama"); |
| @@ -77,11 +80,14 @@ pub fn build(b: *std.Build) void { | ||
| 77 | 80 | }), |
| 78 | 81 | }); |
| 79 | 82 | lua_config_tests.use_lld = false; |
| 80 | - lua_config_tests.root_module.addImport("lua", b.createModule(.{ | |
| 83 | + lua_config_tests.root_module.addIncludePath(lua_headers); | |
| 84 | + const lua_config_module = b.createModule(.{ | |
| 81 | 85 | .root_source_file = b.path("src/config/lua.zig"), |
| 82 | 86 | .target = target, |
| 83 | 87 | .optimize = optimize, |
| 84 | - })); | |
| 88 | + }); | |
| 89 | + lua_config_module.addIncludePath(lua_headers); | |
| 90 | + lua_config_tests.root_module.addImport("lua", lua_config_module); | |
| 85 | 91 | lua_config_tests.linkLibrary(lua); |
| 86 | 92 | lua_config_tests.linkLibC(); |
| 87 | 93 | test_step.dependOn(&b.addRunArtifact(lua_config_tests).step); |
| @@ -159,8 +165,8 @@ fn addXwaylandRun(b: *std.Build, exe: *std.Build.Step.Compile) *std.Build.Step.R | ||
| 159 | 165 | return run_wm; |
| 160 | 166 | } |
| 161 | 167 | |
| 162 | -fn buildLua(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Compile { | |
| 163 | - const lua_src = b.dependency("lua", .{}); | |
| 168 | +fn buildLua(b: *std.Build, lua_dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Compile { | |
| 169 | + const lua_src = lua_dep; | |
| 164 | 170 | const lua = b.addLibrary(.{ |
| 165 | 171 | .name = "lua", |
| 166 | 172 | .root_module = b.createModule(.{ |
+1 −1 build.zig.zon
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | .{ |
| 2 | 2 | .name = .oxwm, |
| 3 | - .version = "0.11.3", | |
| 3 | + .version = "0.11.4", | |
| 4 | 4 | .fingerprint = 0x4b9ef3753914924d, // Changing this has security and trust implications. |
| 5 | 5 | .minimum_zig_version = "0.15.2", |
| 6 | 6 | .dependencies = .{ |
+17 −94 readme.org
| @@ -3,82 +3,20 @@ | ||
| 3 | 3 | |
| 4 | 4 | [[file:./images/oxwm1.png]] |
| 5 | 5 | |
| 6 | -* Table of Contents :toc: | |
| 7 | -- [[#oxwm--dwm-but-better][OXWM — DWM but Better]] | |
| 8 | -- [[#installation][Installation]] | |
| 9 | - - [[#nixos-with-flakes][NixOS (with Flakes)]] | |
| 10 | - - [[#arch-linux][Arch Linux]] | |
| 11 | - - [[#building-from-source][Building from Source]] | |
| 12 | - - [[#setting-up-oxwm][Setting up OXWM]] | |
| 13 | -- [[#configuration][Configuration]] | |
| 14 | - - [[#quick-example][Quick Example]] | |
| 15 | - - [[#features][Features]] | |
| 16 | - - [[#key-configuration-areas][Key Configuration Areas]] | |
| 17 | - - [[#creating-your-config][Creating Your Config]] | |
| 18 | -- [[#contributing][Contributing]] | |
| 19 | -- [[#key-bindings][Key Bindings]] | |
| 20 | -- [[#features-1][Features]] | |
| 21 | -- [[#testing-with-xephyr][Testing with Xephyr]] | |
| 22 | -- [[#project-structure][Project Structure]] | |
| 23 | -- [[#architecture-notes][Architecture Notes]] | |
| 24 | - - [[#lua-configuration-system][Lua Configuration System]] | |
| 25 | - - [[#tag-system][Tag System]] | |
| 26 | - - [[#status-bar][Status Bar]] | |
| 27 | - - [[#layout-system][Layout System]] | |
| 28 | -- [[#current-todo-list][Current Todo List:]] | |
| 29 | - - [[#priority-high-04][PRIORITY High]] | |
| 30 | -- [[#development-roadmap][Development Roadmap]] | |
| 31 | - - [[#current-focus-v080][Current Focus (v0.8.0)]] | |
| 32 | - - [[#completed-features-88][Completed Features]] | |
| 33 | - - [[#future-enhancements-][Future Enhancements]] | |
| 34 | -- [[#license][License]] | |
| 35 | - | |
| 36 | 6 | * OXWM — DWM but Better |
| 37 | 7 | A dynamic window manager written in Zig, inspired by dwm but designed to evolve beyond it. OXWM features a clean, functional Lua API for configuration with hot-reloading support, ditching the suckless philosophy of *"edit + recompile"*. Instead, we focus on lowering friction for users with sane defaults, LSP-powered autocomplete, and instant configuration changes without restarting your X session. |
| 38 | 8 | |
| 39 | 9 | *Documentation:* [[https://ox-docs.vercel.app/][ox-docs.vercel.app]] |
| 40 | 10 | |
| 41 | 11 | * Installation |
| 42 | -** NixOS (with Flakes) | |
| 43 | -*** Adding OXWM to your flake inputs | |
| 44 | -Add oxwm to your =flake.nix= inputs: | |
| 45 | - | |
| 46 | -#+begin_src nix | |
| 47 | -{ | |
| 48 | - inputs = { | |
| 49 | - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | |
| 50 | - oxwm.url = "github:tonybanters/oxwm"; | |
| 51 | - oxwm.inputs.nixpkgs.follows = "nixpkgs"; | |
| 52 | - }; | |
| 53 | - | |
| 54 | - outputs = { self, nixpkgs, oxwm, ... }: { | |
| 55 | - nixosConfigurations.yourhost = nixpkgs.lib.nixosSystem { | |
| 56 | - system = "x86_64-linux"; | |
| 57 | - modules = [ | |
| 58 | - ./configuration.nix | |
| 59 | - oxwm.nixosModules.default | |
| 60 | - ]; | |
| 61 | - }; | |
| 62 | - }; | |
| 63 | -} | |
| 64 | -#+end_src | |
| 65 | - | |
| 66 | -*** Enabling OXWM in configuration.nix | |
| 67 | -Add this to your =configuration.nix=: | |
| 12 | +** NixOS (nixpkgs) | |
| 13 | +Add Oxwm to your =configuration.nix= like so: | |
| 68 | 14 | |
| 69 | 15 | #+begin_src nix |
| 70 | 16 | { config, pkgs, ... }: |
| 71 | 17 | |
| 72 | 18 | { |
| 73 | - services.xserver = { | |
| 74 | - enable = true; | |
| 75 | - | |
| 76 | - windowManager.oxwm.enable = true; | |
| 77 | - }; | |
| 78 | - | |
| 79 | - # Recommended: Install a display manager | |
| 80 | - services.xserver.displayManager.lightdm.enable = true; | |
| 81 | - # Or use another display manager like sddm, gdm, etc. | |
| 19 | + services.xserver.windowManager.oxwm.enable = true; | |
| 82 | 20 | } |
| 83 | 21 | #+end_src |
| 84 | 22 | |
| @@ -87,19 +25,6 @@ After rebuilding your system with =sudo nixos-rebuild switch=, log in via your d | ||
| 87 | 25 | |
| 88 | 26 | On first launch, your initial config file will be automatically created and placed in =~/.config/oxwm/config.lua=. Edit it and reload with =Mod+Shift+R=. |
| 89 | 27 | |
| 90 | -*** Advanced: Using a specific oxwm version | |
| 91 | -If you want to pin or customize the oxwm package: | |
| 92 | - | |
| 93 | -#+begin_src nix | |
| 94 | -{ | |
| 95 | - services.xserver.windowManager.oxwm = { | |
| 96 | - enable = true; | |
| 97 | - # Use a specific version or build with custom options | |
| 98 | - package = oxwm.packages.${pkgs.system}.default; | |
| 99 | - }; | |
| 100 | -} | |
| 101 | -#+end_src | |
| 102 | - | |
| 103 | 28 | *** Development setup with Nix |
| 104 | 29 | For development, use the provided dev shell: |
| 105 | 30 | |
| @@ -112,8 +37,7 @@ cd oxwm | ||
| 112 | 37 | nix develop |
| 113 | 38 | |
| 114 | 39 | # Build and test |
| 115 | -zig build | |
| 116 | -zig build test | |
| 40 | +zig build -Doptimize=ReleaseSmall | |
| 117 | 41 | #+end_src |
| 118 | 42 | |
| 119 | 43 | ** Arch Linux |
| @@ -127,23 +51,29 @@ This will automatically put a desktop session file into your xsessions directory | ||
| 127 | 51 | Manually: |
| 128 | 52 | Install dependencies: |
| 129 | 53 | #+begin_src sh |
| 130 | -sudo pacman -S zig lua libx11 libxft freetype2 fontconfig libxinerama | |
| 54 | +sudo pacman -S zig libx11 libxft freetype2 fontconfig libxinerama | |
| 131 | 55 | #+end_src |
| 132 | 56 | See Build from source |
| 133 | 57 | |
| 134 | 58 | ** Building from Source |
| 59 | +Note, on many BSD systems, the zig compiler will agressively attempt to remove debug symbols which is causing a known linker issue. Please use this method on BSD: | |
| 60 | + | |
| 135 | 61 | #+begin_src sh |
| 136 | 62 | git clone https://github.com/tonybanters/oxwm |
| 137 | 63 | cd oxwm |
| 138 | -zig build -Doptimize=ReleaseFast | |
| 139 | -zig build install-system # installs to /usr/bin, adds desktop file and man page | |
| 64 | +zig build | |
| 140 | 65 | #+end_src |
| 141 | 66 | |
| 142 | -To uninstall: | |
| 67 | +On other legacy distros, just use: | |
| 68 | + | |
| 143 | 69 | #+begin_src sh |
| 144 | -zig build uninstall | |
| 70 | +git clone https://github.com/tonybanters/oxwm | |
| 71 | +cd oxwm | |
| 72 | +zig build -Doptimize=ReleaseSmall --prefix /usr | |
| 145 | 73 | #+end_src |
| 146 | 74 | |
| 75 | + | |
| 76 | + | |
| 147 | 77 | ** Setting up OXWM |
| 148 | 78 | *** Without a display manager (startx) |
| 149 | 79 | Add the following to your =~/.xinitrc=: |
| @@ -204,12 +134,6 @@ oxwm.bar.set_blocks({ | ||
| 204 | 134 | }) |
| 205 | 135 | #+end_src |
| 206 | 136 | |
| 207 | -** Features | |
| 208 | -- *Hot-reload*: Changes take effect immediately with =Mod+Shift+R= (no X restart needed) | |
| 209 | -- *LSP Support*: Full autocomplete and type hints for the API (=oxwm.lua= definitions included) | |
| 210 | -- *Functional API*: Clean, discoverable functions instead of nested tables | |
| 211 | -- *No compilation*: Edit and reload instantly | |
| 212 | - | |
| 213 | 137 | ** Key Configuration Areas |
| 214 | 138 | Edit =~/.config/oxwm/config.lua= to customize: |
| 215 | 139 | - Basic settings (terminal, modkey, tags) |
| @@ -410,8 +334,8 @@ The tiling layout divides the screen into a master area (left half) and stack ar | ||
| 410 | 334 | - Similar to dwm's zoom function (=Mod+Return=) |
| 411 | 335 | - Should work bidirectionally |
| 412 | 336 | * Development Roadmap |
| 413 | -** Current Focus (v0.8.0) | |
| 414 | -- Refactoring to align with dwm's proven patterns | |
| 337 | +** Current Focus (v0.11.3) | |
| 338 | +- Implement featuers such as systray to make the bar more robust. | |
| 415 | 339 | - Improving core window management reliability |
| 416 | 340 | - Maintaining Lua config and bar features while simplifying internals |
| 417 | 341 | |
| @@ -430,7 +354,6 @@ The tiling layout divides the screen into a master area (left half) and stack ar | ||
| 430 | 354 | - [ ] Dynamic monitor hotplugging (currently only on startup) |
| 431 | 355 | - [ ] External bar support (polybar, waybar compatibility) |
| 432 | 356 | - [ ] Additional layouts (deck, spiral, dwindle) |
| 433 | -- [ ] Window minimize/restore | |
| 434 | 357 | |
| 435 | 358 | * License |
| 436 | 359 | [[https://www.gnu.org/licenses/gpl-3.0.en.html][GPL v3]] |
+1 −0 src/config/config.zig
| @@ -200,6 +200,7 @@ pub const Config = struct { | ||
| 200 | 200 | tag_back_and_forth: bool = false, |
| 201 | 201 | hide_vacant_tags: bool = false, |
| 202 | 202 | floating_position: FloatingPosition = .center, |
| 203 | + tiled_resize_mode: bool = false, | |
| 203 | 204 | |
| 204 | 205 | layout_tile_symbol: []const u8 = "[]=", |
| 205 | 206 | layout_monocle_symbol: []const u8 = "[M]", |
+20 −0 src/config/lua.zig
| @@ -321,6 +321,9 @@ fn registerMiscFunctions(state: *c.lua_State) void { | ||
| 321 | 321 | c.lua_pushcfunction(state, luaAutoTile); |
| 322 | 322 | c.lua_setfield(state, -2, "auto_tile"); |
| 323 | 323 | |
| 324 | + c.lua_pushcfunction(state, luaTiledResizeMode); | |
| 325 | + c.lua_setfield(state, -2, "tiled_resize_mode"); | |
| 326 | + | |
| 324 | 327 | c.lua_pushcfunction(state, luaQuit); |
| 325 | 328 | c.lua_setfield(state, -2, "quit"); |
| 326 | 329 | |
| @@ -1113,6 +1116,13 @@ fn luaAutoTile(state: ?*c.lua_State) callconv(.c) c_int { | ||
| 1113 | 1116 | return 0; |
| 1114 | 1117 | } |
| 1115 | 1118 | |
| 1119 | +fn luaTiledResizeMode(state: ?*c.lua_State) callconv(.c) c_int { | |
| 1120 | + const cfg = config orelse return 0; | |
| 1121 | + const s = state orelse return 0; | |
| 1122 | + cfg.tiled_resize_mode = c.lua_toboolean(s, 1) != 0; | |
| 1123 | + return 0; | |
| 1124 | +} | |
| 1125 | + | |
| 1116 | 1126 | fn luaSetLayoutSymbol(state: ?*c.lua_State) callconv(.c) c_int { |
| 1117 | 1127 | const cfg = config orelse return 0; |
| 1118 | 1128 | const s = state orelse return 0; |
| @@ -1392,9 +1402,19 @@ fn keynameToKeysym(name: []const u8) ?u64 { | ||
| 1392 | 1402 | .{ "bracketleft", 0x005b }, |
| 1393 | 1403 | .{ "bracketright", 0x005d }, |
| 1394 | 1404 | .{ "backslash", 0x005c }, |
| 1405 | + .{ "colon", 0x003a }, | |
| 1395 | 1406 | .{ "semicolon", 0x003b }, |
| 1396 | 1407 | .{ "apostrophe", 0x0027 }, |
| 1408 | + .{ "quotedbl", 0x0022 }, | |
| 1409 | + .{ "ampersand", 0x0026 }, | |
| 1410 | + .{ "parenleft", 0x0028 }, | |
| 1411 | + .{ "parenright", 0x0029 }, | |
| 1412 | + .{ "underscore", 0x005f }, | |
| 1397 | 1413 | .{ "grave", 0x0060 }, |
| 1414 | + .{ "agrave", 0x00e0 }, | |
| 1415 | + .{ "egrave", 0x00e8 }, | |
| 1416 | + .{ "ccedilla", 0x00e7 }, | |
| 1417 | + .{ "eacute", 0x00e9 }, | |
| 1398 | 1418 | .{ "Left", 0xff51 }, |
| 1399 | 1419 | .{ "Up", 0xff52 }, |
| 1400 | 1420 | .{ "Right", 0xff53 }, |
+85 −0 src/wm/actions.zig
| @@ -599,6 +599,12 @@ pub fn resizemouse(wm: *WindowManager) void { | ||
| 599 | 599 | |
| 600 | 600 | core.restack(monitor, wm); |
| 601 | 601 | |
| 602 | + // If tiled_resize_mode is enabled and window is tiled, adjust mfact instead | |
| 603 | + if (wm.config.tiled_resize_mode and !client.is_floating) { | |
| 604 | + resizemouseTiled(wm, monitor); | |
| 605 | + return; | |
| 606 | + } | |
| 607 | + | |
| 602 | 608 | if (!client.is_floating) { |
| 603 | 609 | client.is_floating = true; |
| 604 | 610 | } |
| @@ -662,6 +668,85 @@ pub fn resizemouse(wm: *WindowManager) void { | ||
| 662 | 668 | core.arrange(monitor, wm); |
| 663 | 669 | } |
| 664 | 670 | |
| 671 | +/// Resize tiled windows by adjusting mfact with mouse drag (like Super+H/L but with mouse) | |
| 672 | +fn resizemouseTiled(wm: *WindowManager, monitor: *Monitor) void { | |
| 673 | + const grab_result = xlib.XGrabPointer( | |
| 674 | + wm.display.handle, | |
| 675 | + wm.display.root, | |
| 676 | + xlib.False, | |
| 677 | + xlib.ButtonPressMask | xlib.ButtonReleaseMask | xlib.PointerMotionMask, | |
| 678 | + xlib.GrabModeAsync, | |
| 679 | + xlib.GrabModeAsync, | |
| 680 | + xlib.None, | |
| 681 | + wm.cursors.resize, | |
| 682 | + xlib.CurrentTime, | |
| 683 | + ); | |
| 684 | + | |
| 685 | + if (grab_result != xlib.GrabSuccess) { | |
| 686 | + return; | |
| 687 | + } | |
| 688 | + | |
| 689 | + // Get initial pointer position | |
| 690 | + var root_return: xlib.Window = undefined; | |
| 691 | + var child_return: xlib.Window = undefined; | |
| 692 | + var root_x: c_int = undefined; | |
| 693 | + var root_y: c_int = undefined; | |
| 694 | + var win_x: c_int = undefined; | |
| 695 | + var win_y: c_int = undefined; | |
| 696 | + var mask_return: c_uint = undefined; | |
| 697 | + | |
| 698 | + _ = xlib.XQueryPointer( | |
| 699 | + wm.display.handle, | |
| 700 | + wm.display.root, | |
| 701 | + &root_return, | |
| 702 | + &child_return, | |
| 703 | + &root_x, | |
| 704 | + &root_y, | |
| 705 | + &win_x, | |
| 706 | + &win_y, | |
| 707 | + &mask_return, | |
| 708 | + ); | |
| 709 | + | |
| 710 | + const start_x = root_x; | |
| 711 | + const initial_mfact = monitor.mfact; | |
| 712 | + | |
| 713 | + const total_width: f32 = @floatFromInt(monitor.win_w - 2 * monitor.gap_outer_v - monitor.gap_inner_v); | |
| 714 | + | |
| 715 | + var event: xlib.XEvent = undefined; | |
| 716 | + var done = false; | |
| 717 | + var last_time: c_ulong = 0; | |
| 718 | + | |
| 719 | + while (!done) { | |
| 720 | + _ = xlib.XNextEvent(wm.display.handle, &event); | |
| 721 | + | |
| 722 | + switch (event.type) { | |
| 723 | + xlib.MotionNotify => { | |
| 724 | + const motion = &event.xmotion; | |
| 725 | + if ((motion.time - last_time) < (1000 / 60)) { | |
| 726 | + continue; | |
| 727 | + } | |
| 728 | + last_time = motion.time; | |
| 729 | + | |
| 730 | + const delta_x: f32 = @floatFromInt(motion.x_root - start_x); | |
| 731 | + const mfact_delta = delta_x / total_width; | |
| 732 | + const new_mfact = initial_mfact + mfact_delta; | |
| 733 | + | |
| 734 | + if (new_mfact >= 0.05 and new_mfact <= 0.95) { | |
| 735 | + monitor.mfact = new_mfact; | |
| 736 | + monitor.pertag.mfacts[monitor.pertag.curtag] = new_mfact; | |
| 737 | + core.arrange(monitor, wm); | |
| 738 | + } | |
| 739 | + }, | |
| 740 | + xlib.ButtonRelease => { | |
| 741 | + done = true; | |
| 742 | + }, | |
| 743 | + else => {}, | |
| 744 | + } | |
| 745 | + } | |
| 746 | + | |
| 747 | + _ = xlib.XUngrabPointer(wm.display.handle, xlib.CurrentTime); | |
| 748 | +} | |
| 749 | + | |
| 665 | 750 | /// Config-loading callback for wm.reloadConfig(). |
| 666 | 751 | /// Re-initialises Lua and loads the config file (or falls back to defaults). |
| 667 | 752 | pub fn reloadLoadConfig(wm: *WindowManager) void { |
+32 −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), |
| @@ -32,6 +33,7 @@ pub fn handleEvent(event: *xlib.XEvent, wm: *WindowManager) void { | ||
| 32 | 33 | .button_press => handleButtonPress(&event.xbutton, wm), |
| 33 | 34 | .expose => handleExpose(&event.xexpose, wm), |
| 34 | 35 | .property_notify => handlePropertyNotify(&event.xproperty, wm), |
| 36 | + .mapping_notify => handleMappingNotify(&event.xmapping, wm), | |
| 35 | 37 | else => {}, |
| 36 | 38 | } |
| 37 | 39 | } |
| @@ -190,6 +192,27 @@ fn handleExpose(event: *xlib.XExposeEvent, wm: *WindowManager) void { | ||
| 190 | 192 | } |
| 191 | 193 | } |
| 192 | 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 | + | |
| 193 | 216 | fn handleButtonPress(event: *xlib.XButtonEvent, wm: *WindowManager) void { |
| 194 | 217 | std.debug.print("button_press: window=0x{x} subwindow=0x{x}\n", .{ event.window, event.subwindow }); |
| 195 | 218 | |
| @@ -364,3 +387,12 @@ fn handlePropertyNotify(event: *xlib.XPropertyEvent, wm: *WindowManager) void { | ||
| 364 | 387 | core.updateWindowType(client, wm); |
| 365 | 388 | } |
| 366 | 389 | } |
| 390 | + | |
| 391 | +fn handleMappingNotify(event: *xlib.XMappingEvent, wm: *WindowManager) void { | |
| 392 | + _ = xlib.XRefreshKeyboardMapping(event); | |
| 393 | + | |
| 394 | + if (event.request == xlib.MappingKeyboard or event.request == xlib.MappingModifier) { | |
| 395 | + wm.ungrabKeybinds(); | |
| 396 | + wm.grabKeybinds(); | |
| 397 | + } | |
| 398 | +} |
+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"); |
| @@ -239,6 +240,162 @@ pub const WindowManager = struct { | ||
| 239 | 240 | } |
| 240 | 241 | } |
| 241 | 242 | |
| 243 | + pub fn updateGeom(self: *WindowManager) bool { | |
| 244 | + var dirty = false; | |
| 245 | + | |
| 246 | + if (xlib.XineramaIsActive(self.display.handle) != 0) { | |
| 247 | + var n: usize = 0; | |
| 248 | + var m = self.monitors; | |
| 249 | + while (m) |mon| : (m = mon.next) n += 1; | |
| 250 | + | |
| 251 | + var nn: c_int = 0; | |
| 252 | + const info = xlib.XineramaQueryScreens(self.display.handle, &nn); | |
| 253 | + if (info == null) return false; | |
| 254 | + defer _ = xlib.XFree(@ptrCast(info)); | |
| 255 | + | |
| 256 | + const new_count: usize = @intCast(nn); | |
| 257 | + | |
| 258 | + for (n..new_count) |_| { | |
| 259 | + var last = self.monitors; | |
| 260 | + while (last) |mon| { | |
| 261 | + if (mon.next == null) break; | |
| 262 | + last = mon.next; | |
| 263 | + } | |
| 264 | + const new_mon = monitor_mod.create(self.allocator) orelse continue; | |
| 265 | + new_mon.lt[0] = &tiling.layout; | |
| 266 | + new_mon.lt[1] = &monocle.layout; | |
| 267 | + new_mon.lt[2] = &floating.layout; | |
| 268 | + new_mon.lt[3] = &scrolling.layout; | |
| 269 | + new_mon.lt[4] = &grid.layout; | |
| 270 | + for (0..10) |i| { | |
| 271 | + new_mon.pertag.ltidxs[i][0] = new_mon.lt[0]; | |
| 272 | + new_mon.pertag.ltidxs[i][1] = new_mon.lt[1]; | |
| 273 | + new_mon.pertag.ltidxs[i][2] = new_mon.lt[2]; | |
| 274 | + new_mon.pertag.ltidxs[i][3] = new_mon.lt[3]; | |
| 275 | + new_mon.pertag.ltidxs[i][4] = new_mon.lt[4]; | |
| 276 | + } | |
| 277 | + if (last) |l| { | |
| 278 | + l.next = new_mon; | |
| 279 | + } else { | |
| 280 | + self.monitors = new_mon; | |
| 281 | + } | |
| 282 | + } | |
| 283 | + | |
| 284 | + var i: usize = 0; | |
| 285 | + m = self.monitors; | |
| 286 | + while (m != null and i < new_count) : (i += 1) { | |
| 287 | + const mon = m.?; | |
| 288 | + const screen = info[i]; | |
| 289 | + if (i >= n or | |
| 290 | + screen.x_org != mon.mon_x or screen.y_org != mon.mon_y or | |
| 291 | + screen.width != mon.mon_w or screen.height != mon.mon_h) | |
| 292 | + { | |
| 293 | + dirty = true; | |
| 294 | + mon.num = @intCast(i); | |
| 295 | + mon.mon_x = screen.x_org; | |
| 296 | + mon.mon_y = screen.y_org; | |
| 297 | + mon.mon_w = screen.width; | |
| 298 | + mon.mon_h = screen.height; | |
| 299 | + mon.win_x = screen.x_org; | |
| 300 | + mon.win_y = screen.y_org; | |
| 301 | + mon.win_w = screen.width; | |
| 302 | + mon.win_h = screen.height; | |
| 303 | + self.initMonitorGaps(mon); | |
| 304 | + } | |
| 305 | + m = mon.next; | |
| 306 | + } | |
| 307 | + | |
| 308 | + for (new_count..n) |_| { | |
| 309 | + var last: ?*Monitor = null; | |
| 310 | + var iter = self.monitors; | |
| 311 | + while (iter) |mon| { | |
| 312 | + if (mon.next == null) { | |
| 313 | + last = mon; | |
| 314 | + break; | |
| 315 | + } | |
| 316 | + iter = mon.next; | |
| 317 | + } | |
| 318 | + const removed = last orelse continue; | |
| 319 | + | |
| 320 | + while (removed.clients) |c| { | |
| 321 | + dirty = true; | |
| 322 | + removed.clients = c.next; | |
| 323 | + client_mod.detachStack(c); | |
| 324 | + c.monitor = self.monitors; | |
| 325 | + client_mod.attachAside(c); | |
| 326 | + client_mod.attachStack(c); | |
| 327 | + } | |
| 328 | + | |
| 329 | + if (self.selected_monitor == removed) { | |
| 330 | + self.selected_monitor = self.monitors; | |
| 331 | + } | |
| 332 | + | |
| 333 | + var prev: ?*Monitor = null; | |
| 334 | + iter = self.monitors; | |
| 335 | + while (iter) |mon| { | |
| 336 | + if (mon == removed) { | |
| 337 | + if (prev) |p| { | |
| 338 | + p.next = removed.next; | |
| 339 | + } else { | |
| 340 | + self.monitors = removed.next; | |
| 341 | + } | |
| 342 | + break; | |
| 343 | + } | |
| 344 | + prev = mon; | |
| 345 | + iter = mon.next; | |
| 346 | + } | |
| 347 | + monitor_mod.destroy(self.allocator, removed); | |
| 348 | + } | |
| 349 | + | |
| 350 | + tiling.setScreenSize(info[0].width, info[0].height); | |
| 351 | + } else { | |
| 352 | + if (self.monitors == null) { | |
| 353 | + const mon = monitor_mod.create(self.allocator) orelse return false; | |
| 354 | + mon.lt[0] = &tiling.layout; | |
| 355 | + mon.lt[1] = &monocle.layout; | |
| 356 | + mon.lt[2] = &floating.layout; | |
| 357 | + mon.lt[3] = &scrolling.layout; | |
| 358 | + mon.lt[4] = &grid.layout; | |
| 359 | + self.monitors = mon; | |
| 360 | + self.selected_monitor = mon; | |
| 361 | + } | |
| 362 | + | |
| 363 | + const sw = self.display.screenWidth(); | |
| 364 | + const sh = self.display.screenHeight(); | |
| 365 | + | |
| 366 | + if (self.monitors) |mon| { | |
| 367 | + if (mon.mon_w != sw or mon.mon_h != sh) { | |
| 368 | + dirty = true; | |
| 369 | + mon.mon_x = 0; | |
| 370 | + mon.mon_y = 0; | |
| 371 | + mon.mon_w = sw; | |
| 372 | + mon.mon_h = sh; | |
| 373 | + mon.win_x = 0; | |
| 374 | + mon.win_y = 0; | |
| 375 | + mon.win_w = sw; | |
| 376 | + mon.win_h = sh; | |
| 377 | + self.initMonitorGaps(mon); | |
| 378 | + } | |
| 379 | + } | |
| 380 | + | |
| 381 | + tiling.setScreenSize(sw, sh); | |
| 382 | + } | |
| 383 | + | |
| 384 | + if (dirty) { | |
| 385 | + self.selected_monitor = self.monitors; | |
| 386 | + self.selected_monitor = monitor_mod.windowToMonitor(self, self.display.root); | |
| 387 | + } | |
| 388 | + | |
| 389 | + return dirty; | |
| 390 | + } | |
| 391 | + | |
| 392 | + pub fn rebuildBars(self: *WindowManager) void { | |
| 393 | + bar_mod.destroyBars(self.bars, self.display.handle); | |
| 394 | + self.bars = null; | |
| 395 | + self.setupBars(); | |
| 396 | + self.rebuildBarBlocks(); | |
| 397 | + } | |
| 398 | + | |
| 242 | 399 | fn initMonitorGaps(self: *WindowManager, mon: *Monitor) void { |
| 243 | 400 | const cfg = &self.config; |
| 244 | 401 | 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 |
+6 −0 src/x11/xlib.zig
| @@ -139,6 +139,7 @@ pub const None = c.None; | ||
| 139 | 139 | pub const XButtonEvent = c.XButtonEvent; |
| 140 | 140 | pub const XMotionEvent = c.XMotionEvent; |
| 141 | 141 | pub const XExposeEvent = c.XExposeEvent; |
| 142 | +pub const XConfigureEvent = c.XConfigureEvent; | |
| 142 | 143 | |
| 143 | 144 | pub const XineramaIsActive = c.XineramaIsActive; |
| 144 | 145 | pub const XineramaQueryScreens = c.XineramaQueryScreens; |
| @@ -269,3 +270,8 @@ pub const XC_fleur = c.XC_fleur; | ||
| 269 | 270 | pub const XAllowEvents = c.XAllowEvents; |
| 270 | 271 | pub const ReplayPointer = c.ReplayPointer; |
| 271 | 272 | pub const AnyButton = c.AnyButton; |
| 273 | + | |
| 274 | +pub const XMappingEvent = c.XMappingEvent; | |
| 275 | +pub const XRefreshKeyboardMapping = c.XRefreshKeyboardMapping; | |
| 276 | +pub const MappingKeyboard = c.MappingKeyboard; | |
| 277 | +pub const MappingModifier = c.MappingModifier; |
+2 −0 templates/config.lua
| @@ -231,6 +231,8 @@ oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle()) | ||
| 231 | 231 | -- Decrease/Increase master area width |
| 232 | 232 | oxwm.key.bind({ modkey }, "H", oxwm.set_master_factor(-5)) |
| 233 | 233 | oxwm.key.bind({ modkey }, "L", oxwm.set_master_factor(5)) |
| 234 | +-- Enable tiled resize mode: Mod+RMB drag adjusts mfact instead of floating | |
| 235 | +-- oxwm.tiled_resize_mode(true) | |
| 234 | 236 | -- Increment/Decrement number of master windows |
| 235 | 237 | oxwm.key.bind({ modkey }, "I", oxwm.inc_num_master(1)) |
| 236 | 238 | oxwm.key.bind({ modkey }, "P", oxwm.inc_num_master(-1)) |
+4 −0 templates/oxwm.lua
| @@ -41,6 +41,10 @@ function oxwm.set_tags(tags) end | ||
| 41 | 41 | ---@param enabled boolean Enable or disable auto-tiling |
| 42 | 42 | function oxwm.auto_tile(enabled) end |
| 43 | 43 | |
| 44 | +---Enable or disable tiled resize mode (Mod+RMB adjusts mfact instead of floating) | |
| 45 | +---@param enabled boolean Enable or disable tiled resize mode | |
| 46 | +function oxwm.tiled_resize_mode(enabled) end | |
| 47 | + | |
| 44 | 48 | ---Set layout symbol override |
| 45 | 49 | ---@param name string Layout name (e.g., "tiling", "normie", "tabbed", "grid", "monocle") |
| 46 | 50 | ---@param symbol string Symbol to display (e.g., "[T]", "[F]", "[=]") |