Show wallpapers as a justified gallery in the picker drawer

Back to the drawer picker, now with justified rows: each thumbnail keeps
its aspect ratio (read from the file header by the scan) and every row
fills the width. Arrows move in two dimensions, click or Enter applies,
✦ marks outline wallpapers. Drops the full-screen preview picker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-11-08 22:57:08 +01:00
1 parent 2a41cde6f5
commit ebace10767
7 files changed
+240 -278

No files matched your search

+37 -1
View File
@@ -92,6 +92,41 @@ def apply(req):
else:raise ValueError('No active wallpaper provider')
return {'backend':backend,'path':str(path),'providerPath':str(path)}
def image_size(path):
"""(width, height) from the file header, or None. Standard library only:
the picker lays thumbnails out by aspect ratio before any is decoded."""
import struct
try:
with open(path,'rb') as f:
head=f.read(32)
if head[:8]==b'\x89PNG\r\n\x1a\n':
return struct.unpack('>II',head[16:24])
if head[:2]==b'BM':
w,h=struct.unpack('<ii',head[18:26]);return (abs(w),abs(h))
if head[:4]==b'RIFF' and head[8:12]==b'WEBP':
kind=head[12:16]
if kind==b'VP8 ':
w,h=struct.unpack('<HH',head[26:30]);return (w&0x3fff,h&0x3fff)
if kind==b'VP8L':
b=head[21:25];return (1+(((b[1]&0x3f)<<8)|b[0]),1+(((b[3]&0xf)<<10)|(b[2]<<2)|((b[1]&0xc0)>>6)))
if kind==b'VP8X':
return (1+int.from_bytes(head[24:27],'little'),1+int.from_bytes(head[27:30],'little'))
return None
if head[:2]==b'\xff\xd8':
f.seek(2)
while True:
marker=f.read(2)
if len(marker)<2 or marker[0]!=0xff:return None
while marker[1]==0xff:marker=marker[:1]+f.read(1)
if marker[1] in (0xd8,0x01) or 0xd0<=marker[1]<=0xd7:continue
length=struct.unpack('>H',f.read(2))[0]
if marker[1] in (0xc0,0xc1,0xc2,0xc3,0xc5,0xc6,0xc7,0xc9,0xca,0xcb,0xcd,0xce,0xcf):
h,w=struct.unpack('>xHH',f.read(5));return (w,h)
f.seek(length-2,1)
except (OSError,struct.error):
return None
return None
def scan(req):
found={};errors=[]
for directory in (req.get('directories') or [str(Path.home()/'Pictures/Wallpapers')]):
@@ -99,7 +134,8 @@ def scan(req):
try:
for entry in base.iterdir():
if entry.is_file() and entry.suffix.lower() in IMAGES:
resolved=entry.resolve();found[str(resolved)]={'path':str(resolved),'url':resolved.as_uri(),'name':entry.name}
resolved=entry.resolve();size=image_size(resolved)
found[str(resolved)]={'path':str(resolved),'url':resolved.as_uri(),'name':entry.name,'width':size[0] if size else 0,'height':size[1] if size else 0}
if len(found)>=1000:break
except OSError as error:errors.append(str(error))
if len(found)>=1000:break