mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
generate-alt-random: wait for SIGWINCH if width/height is 0
If width/height (that is, the *pixel* values) are 0, that means we are early (or that foot is slow) - we’ve managed to reach this point before the foot window has been mapped. Or rather, before foot has loaded the primary fonts and calculated the cell geometry. But that, and the initial mapping of the window is tightly coupled. To handle this case, detect when width or height is 0, an then wait for SIGWINCH before trying again.
This commit is contained in:
parent
da5a3bae3e
commit
44b8bd2364
1 changed files with 24 additions and 6 deletions
|
|
@ -2,8 +2,9 @@
|
||||||
import argparse
|
import argparse
|
||||||
import enum
|
import enum
|
||||||
import fcntl
|
import fcntl
|
||||||
import struct
|
|
||||||
import random
|
import random
|
||||||
|
import signal
|
||||||
|
import struct
|
||||||
import sys
|
import sys
|
||||||
import termios
|
import termios
|
||||||
|
|
||||||
|
|
@ -38,11 +39,28 @@ def main():
|
||||||
out = opts.out if opts.out is not None else sys.stdout
|
out = opts.out if opts.out is not None else sys.stdout
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lines, cols, height, width = struct.unpack(
|
def dummy(*args):
|
||||||
'HHHH',
|
"""Need a handler installed for sigwait() to trigger."""
|
||||||
fcntl.ioctl(sys.stdout.fileno(),
|
pass
|
||||||
termios.TIOCGWINSZ,
|
signal.signal(signal.SIGWINCH, dummy)
|
||||||
struct.pack('HHHH', 0, 0, 0, 0)))
|
|
||||||
|
while True:
|
||||||
|
lines, cols, height, width = struct.unpack(
|
||||||
|
'HHHH',
|
||||||
|
fcntl.ioctl(sys.stdout.fileno(),
|
||||||
|
termios.TIOCGWINSZ,
|
||||||
|
struct.pack('HHHH', 0, 0, 0, 0)))
|
||||||
|
|
||||||
|
if width > 0 and height > 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
# We’re early; the foot window hasn’t been mapped yet. Or,
|
||||||
|
# to be more precise, fonts haven’t yet been loaded,
|
||||||
|
# meaning it doesn’t have any cell geometry yet.
|
||||||
|
signal.sigwait([signal.SIGWINCH])
|
||||||
|
|
||||||
|
signal.signal(signal.SIGWINCH, signal.SIG_DFL)
|
||||||
|
|
||||||
except OSError:
|
except OSError:
|
||||||
lines = None
|
lines = None
|
||||||
cols = None
|
cols = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue