Skip to content

Commit 3cfc09b

Browse files
author
altermo
committed
feat: resize root term window when screen size changes
1 parent c12055d commit 3cfc09b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lua/nxwm/init.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function M.term_supported()
4040
local info=x11.term_get_info()
4141
return info.xpixel~=0 and info.ypixel~=0
4242
end
43-
function M.term_set_size()
44-
x11.win_position(x11.term_root,0,0,x11.screen_get_size())
43+
function M.term_set_size(width,height)
44+
x11.win_position(x11.term_root,0,0,width,height)
4545
end
4646

4747
function M.win_update_all(event)
@@ -194,10 +194,13 @@ function M.step()
194194
M.key_handle(ev.win,ev.key,ev.mod)
195195
elseif ev.type=='destroy' then
196196
M.win_del_buf(ev.win)
197-
elseif ev.type=='_update' then ---HACK: see x11.lua
198-
M.win_update_all()
199197
elseif ev.type=='focus' then
200198
M.win_goto(ev.win)
199+
elseif ev.type=='resize' then
200+
if ev.win==x11.true_root then
201+
M.term_set_size(ev.width,ev.height)
202+
end
203+
M.win_update_all()
201204
elseif ev.type=='other' then
202205
if M.conf.verbose then
203206
vim.notify('event not handled '..x11.code_to_name[ev.type_id],vim.log.levels.INFO)
@@ -216,7 +219,7 @@ function M.start()
216219
vim.api.nvim_create_autocmd({'WinEnter','BufWinEnter','TabEnter'},{callback=function ()
217220
vim.schedule_wrap(M.win_update_all)('enter')
218221
end,group=M.augroup})
219-
M.term_set_size()
222+
M.term_set_size(x11.screen_get_size())
220223
local function t()
221224
if not x11.display then return end
222225
M.step()

lua/nxwm/x11.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function M.start()
166166
end
167167
M.display=display
168168
M.true_root=root
169-
xlib.XSelectInput(M.display,root,bit.bor(xlib.SubstructureRedirectMask,xlib.SubstructureNotifyMask))
169+
xlib.XSelectInput(M.display,root,bit.bor(xlib.SubstructureRedirectMask,xlib.SubstructureNotifyMask,xlib.StructureNotifyMask))
170170
xlib.XSync(M.display,0)
171171
M.term_root=M._term_get_id()
172172
end
@@ -196,13 +196,13 @@ function M.step()
196196
changes[0].width=cev.width
197197
changes[0].height=cev.height
198198
xlib.XConfigureWindow(M.display,cev.window,cev.value_mask,changes)
199-
---HACK: some windows actually resize themselves, not just send a request
200-
---Will be removed when a proper configuration system is implemented
201-
return {type='_update'}
199+
return
202200
elseif ev.type==xlib.KeyRelease then
203201
return {type='key',mod=ev.xkey.state,key=ev.xkey.keycode,win=ev.xkey.window}
204202
elseif ev.type==xlib.DestroyNotify then
205203
return {type='destroy',win=ev.xdestroywindow.window}
204+
elseif ev.type==xlib.ConfigureNotify then
205+
return {type='resize',win=ev.xconfigure.window,width=ev.xconfigure.width,height=ev.xconfigure.height}
206206
elseif ev.type==xlib.ButtonPress then
207207
xlib.XAllowEvents(M.display,xlib.ReplayPointer,xlib.CurrentTime);
208208
return {type='focus',win=ev.xbutton.window}

0 commit comments

Comments
 (0)