tony / oxwm

implements #94 : floating spawn position Browse files
Iziram committed 2026-03-07 parent 15a6a02 commit 15d74dce6efe4ba9b120de2a5f546f976f34cfba
Showing 4 changed files with 78 additions and 0 deletions. UnifiedSplit
+41 −0 src/config/config.zig
@@ -105,6 +105,46 @@ pub const MouseButton = struct {
105 action: MouseAction, 105 action: MouseAction,
106 }; 106 };
107 107
108 +pub const FloatingPosition = enum {
109 + top_left,
110 + top_center,
111 + top_right,
112 + center_left,
113 + center,
114 + center_right,
115 + bottom_left,
116 + bottom_center,
117 + bottom_right,
118 +
119 + pub fn fromString(name: []const u8) ?FloatingPosition {
120 + const map = .{
121 + .{ "top-left", .top_left },
122 + .{ "top_left", .top_left },
123 + .{ "top-center", .top_center },
124 + .{ "top_center", .top_center },
125 + .{ "top-middle", .top_center },
126 + .{ "top-right", .top_right },
127 + .{ "top_right", .top_right },
128 + .{ "center-left", .center_left },
129 + .{ "center_left", .center_left },
130 + .{ "center", .center },
131 + .{ "center-right", .center_right },
132 + .{ "center_right", .center_right },
133 + .{ "bottom-left", .bottom_left },
134 + .{ "bottom_left", .bottom_left },
135 + .{ "bottom-center", .bottom_center },
136 + .{ "bottom_center", .bottom_center },
137 + .{ "bottom-middle", .bottom_center },
138 + .{ "bottom-right", .bottom_right },
139 + .{ "bottom_right", .bottom_right },
140 + };
141 + inline for (map) |entry| {
142 + if (std.mem.eql(u8, name, entry[0])) return entry[1];
143 + }
144 + return null;
145 + }
146 +};
147 +
108 pub const ClickAction = struct { 148 pub const ClickAction = struct {
109 command: []const u8, 149 command: []const u8,
110 floating: bool = false, 150 floating: bool = false,
@@ -158,6 +198,7 @@ pub const Config = struct {
158 auto_tile: bool = false, 198 auto_tile: bool = false,
159 tag_back_and_forth: bool = false, 199 tag_back_and_forth: bool = false,
160 hide_vacant_tags: bool = false, 200 hide_vacant_tags: bool = false,
201 + floating_position: FloatingPosition = .center,
161 202
162 layout_tile_symbol: []const u8 = "[]=", 203 layout_tile_symbol: []const u8 = "[]=",
163 layout_monocle_symbol: []const u8 = "[M]", 204 layout_monocle_symbol: []const u8 = "[M]",
+14 −0 src/config/lua.zig
@@ -344,6 +344,9 @@ fn registerMiscFunctions(state: *c.lua_State) void {
344 344
345 c.lua_pushcfunction(state, luaSetTagLayout); 345 c.lua_pushcfunction(state, luaSetTagLayout);
346 c.lua_setfield(state, -2, "set_tag_layout"); 346 c.lua_setfield(state, -2, "set_tag_layout");
347 +
348 + c.lua_pushcfunction(state, luaSetFloatingPosition);
349 + c.lua_setfield(state, -2, "set_floating_position");
347 } 350 }
348 351
349 fn createActionTable(state: *c.lua_State, action_name: [*:0]const u8) void { 352 fn createActionTable(state: *c.lua_State, action_name: [*:0]const u8) void {
@@ -1020,6 +1023,17 @@ fn createBlockTable(state: *c.lua_State, block_type: [*:0]const u8, arg: ?[]cons
1020 } 1023 }
1021 } 1024 }
1022 1025
1026 +fn luaSetFloatingPosition(state: ?*c.lua_State) callconv(.c) c_int {
1027 + const cfg = config orelse return 0;
1028 + const s = state orelse return 0;
1029 + if (getLuaString(s, 1)) |name| {
1030 + if (config_mod.FloatingPosition.fromString(name)) |pos| {
1031 + cfg.floating_position = pos;
1032 + }
1033 + }
1034 + return 0;
1035 +}
1036 +
1023 fn luaSetTerminal(state: ?*c.lua_State) callconv(.c) c_int { 1037 fn luaSetTerminal(state: ?*c.lua_State) callconv(.c) c_int {
1024 const cfg = config orelse return 0; 1038 const cfg = config orelse return 0;
1025 const s = state orelse return 0; 1039 const s = state orelse return 0;
+19 −0 src/wm/core.zig
@@ -6,6 +6,8 @@ const tiling = @import("../layouts/tiling.zig");
6 const scrolling = @import("../layouts/scrolling.zig"); 6 const scrolling = @import("../layouts/scrolling.zig");
7 const window_manager = @import("wm.zig"); 7 const window_manager = @import("wm.zig");
8 8
9 +const config_mod = @import("../config/config.zig");
10 +
9 const Client = client_mod.Client; 11 const Client = client_mod.Client;
10 const Monitor = monitor_mod.Monitor; 12 const Monitor = monitor_mod.Monitor;
11 const WindowManager = window_manager.WindowManager; 13 const WindowManager = window_manager.WindowManager;
@@ -77,6 +79,7 @@ pub fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *Wind
77 client.old_state = client.is_floating; 79 client.old_state = client.is_floating;
78 } 80 }
79 if (client.is_floating) { 81 if (client.is_floating) {
82 + positionFloating(client, monitor, wm.config.floating_position);
80 _ = xlib.XRaiseWindow(wm.display.handle, client.window); 83 _ = xlib.XRaiseWindow(wm.display.handle, client.window);
81 } 84 }
82 85
@@ -437,6 +440,22 @@ pub fn scrollToWindow(client: *Client, animate: bool, wm: *WindowManager) void {
437 } 440 }
438 } 441 }
439 442
443 +fn positionFloating(client: *Client, monitor: *Monitor, pos: config_mod.FloatingPosition) void {
444 + const bw = 2 * client.border_width;
445 + const x: i32 = switch (pos) {
446 + .top_left, .center_left, .bottom_left => monitor.win_x,
447 + .top_center, .center, .bottom_center => monitor.win_x + @divTrunc(monitor.win_w - client.width - bw, 2),
448 + .top_right, .center_right, .bottom_right => monitor.win_x + monitor.win_w - client.width - bw,
449 + };
450 + const y: i32 = switch (pos) {
451 + .top_left, .top_center, .top_right => monitor.win_y,
452 + .center_left, .center, .center_right => monitor.win_y + @divTrunc(monitor.win_h - client.height - bw, 2),
453 + .bottom_left, .bottom_center, .bottom_right => monitor.win_y + monitor.win_h - client.height - bw,
454 + };
455 + client.x = x;
456 + client.y = y;
457 +}
458 +
440 pub fn applyRules(client: *Client, wm: *WindowManager) void { 459 pub fn applyRules(client: *Client, wm: *WindowManager) void {
441 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null }; 460 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null };
442 _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint); 461 _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint);
+4 −0 templates/config.lua
@@ -133,6 +133,10 @@ oxwm.border.set_focused_color(colors.blue)
133 -- Color of unfocused window borders 133 -- Color of unfocused window borders
134 oxwm.border.set_unfocused_color(colors.grey) 134 oxwm.border.set_unfocused_color(colors.grey)
135 135
136 +-- Where floating windows spawn: "top-left", "top-center", "top-right",
137 +-- "center-left", "center", "center-right", "bottom-left", "bottom-center", "bottom-right"
138 +oxwm.set_floating_position("center")
139 +
136 -- Smart Enabled = No border if 1 window 140 -- Smart Enabled = No border if 1 window
137 oxwm.gaps.set_smart(enabled) 141 oxwm.gaps.set_smart(enabled)
138 -- Inner gaps (horizontal, vertical) in pixels 142 -- Inner gaps (horizontal, vertical) in pixels