Add hardware-accelerated OpenGL 3D Maze screensaver (ssmaze.scr) and Display Properties Setup dialog

This commit is contained in:
Carsten
2026-11-28 10:09:04 +01:00
parent 87540631aa
commit 5733e6dead
5 changed files with 1812 additions and 101 deletions
+285 -65
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""Native Windows XP Display Properties (Themes, Desktop Wallpaper, Appearance).""" """Native Windows XP Display Properties (Themes, Desktop Wallpaper, Appearance)."""
import json
import os import os
import subprocess import subprocess
import sys import sys
@@ -62,9 +63,14 @@ class CRTMonitorPreview(Gtk.DrawingArea):
self.theme_info = THEMES[0] self.theme_info = THEMES[0]
self.wall_path = "/usr/local/share/backgrounds/wintc/bliss.jpg" self.wall_path = "/usr/local/share/backgrounds/wintc/bliss.jpg"
self.wall_pb = None self.wall_pb = None
self.ss_mode = None
self.connect("draw", self.on_draw) self.connect("draw", self.on_draw)
self._load_wall() self._load_wall()
def set_screensaver_mode(self, mode):
self.ss_mode = mode
self.queue_draw()
def set_theme(self, theme_tuple): def set_theme(self, theme_tuple):
self.theme_info = theme_tuple self.theme_info = theme_tuple
self.queue_draw() self.queue_draw()
@@ -127,64 +133,67 @@ class CRTMonitorPreview(Gtk.DrawingArea):
cr.rectangle(sx, sy, sw, sh) cr.rectangle(sx, sy, sw, sh)
cr.clip() cr.clip()
# Wallpaper if self.ss_mode and self.ss_mode != "none":
if self.wall_pb: self._draw_screensaver_preview(cr, sx, sy, sw, sh)
Gdk.cairo_set_source_pixbuf(cr, self.wall_pb, sx, sy)
cr.paint()
else: else:
cr.set_source_rgb(0.23, 0.43, 0.65) # Wallpaper
cr.rectangle(sx, sy, sw, sh) if self.wall_pb:
Gdk.cairo_set_source_pixbuf(cr, self.wall_pb, sx, sy)
cr.paint()
else:
cr.set_source_rgb(0.23, 0.43, 0.65)
cr.rectangle(sx, sy, sw, sh)
cr.fill()
_, _, hdr1, hdr2, bg, bar_c, start_c, ihdr = self.theme_info
# Mini inactive window
ix, iy, iw, ih = sx + 10, sy + 10, 104, 62
cr.set_source_rgb(*hex_rgb(bg))
cr.rectangle(ix, iy, iw, ih)
cr.fill() cr.fill()
cr.set_source_rgb(*hex_rgb(ihdr))
cr.rectangle(ix, iy, iw, 13)
cr.fill()
cr.set_source_rgb(*hex_rgb(ihdr))
cr.set_line_width(1)
cr.rectangle(ix + 0.5, iy + 0.5, iw - 1, ih - 1)
cr.stroke()
_, _, hdr1, hdr2, bg, bar_c, start_c, ihdr = self.theme_info # Mini active window
ax, ay, aw, ah = sx + 38, sy + 28, 128, 66
cr.set_source_rgb(*hex_rgb(bg))
cr.rectangle(ax, ay, aw, ah)
cr.fill()
pat = cairo.LinearGradient(ax, ay, ax, ay + 15)
pat.add_color_stop_rgb(0.0, *hex_rgb(hdr2))
pat.add_color_stop_rgb(1.0, *hex_rgb(hdr1))
cr.set_source(pat)
cr.rectangle(ax, ay, aw, 15)
cr.fill()
# Mini close button
cr.set_source_rgb(0.87, 0.28, 0.15)
cr.rectangle(ax + aw - 12, ay + 3, 9, 9)
cr.fill()
# Mini white content box & OK button
cr.set_source_rgb(1, 1, 1)
cr.rectangle(ax + 6, ay + 20, aw - 12, 26)
cr.fill()
cr.set_source_rgb(0.95, 0.94, 0.91)
cr.rectangle(ax + aw - 38, ay + ah - 15, 32, 11)
cr.fill()
cr.set_source_rgb(*hex_rgb(hdr1))
cr.rectangle(ax + 0.5, ay + 0.5, aw - 1, ah - 1)
cr.stroke()
# Mini inactive window # Mini Taskbar + Start button
ix, iy, iw, ih = sx + 10, sy + 10, 104, 62 tb_h = 13
cr.set_source_rgb(*hex_rgb(bg)) cr.set_source_rgb(*hex_rgb(bar_c))
cr.rectangle(ix, iy, iw, ih) cr.rectangle(sx, sy + sh - tb_h, sw, tb_h)
cr.fill() cr.fill()
cr.set_source_rgb(*hex_rgb(ihdr)) cr.set_source_rgb(*hex_rgb(start_c))
cr.rectangle(ix, iy, iw, 13) cr.rectangle(sx, sy + sh - tb_h, 30, tb_h)
cr.fill() cr.fill()
cr.set_source_rgb(*hex_rgb(ihdr))
cr.set_line_width(1)
cr.rectangle(ix + 0.5, iy + 0.5, iw - 1, ih - 1)
cr.stroke()
# Mini active window
ax, ay, aw, ah = sx + 38, sy + 28, 128, 66
cr.set_source_rgb(*hex_rgb(bg))
cr.rectangle(ax, ay, aw, ah)
cr.fill()
pat = cairo.LinearGradient(ax, ay, ax, ay + 15)
pat.add_color_stop_rgb(0.0, *hex_rgb(hdr2))
pat.add_color_stop_rgb(1.0, *hex_rgb(hdr1))
cr.set_source(pat)
cr.rectangle(ax, ay, aw, 15)
cr.fill()
# Mini close button
cr.set_source_rgb(0.87, 0.28, 0.15)
cr.rectangle(ax + aw - 12, ay + 3, 9, 9)
cr.fill()
# Mini white content box & OK button
cr.set_source_rgb(1, 1, 1)
cr.rectangle(ax + 6, ay + 20, aw - 12, 26)
cr.fill()
cr.set_source_rgb(0.95, 0.94, 0.91)
cr.rectangle(ax + aw - 38, ay + ah - 15, 32, 11)
cr.fill()
cr.set_source_rgb(*hex_rgb(hdr1))
cr.rectangle(ax + 0.5, ay + 0.5, aw - 1, ah - 1)
cr.stroke()
# Mini Taskbar + Start button
tb_h = 13
cr.set_source_rgb(*hex_rgb(bar_c))
cr.rectangle(sx, sy + sh - tb_h, sw, tb_h)
cr.fill()
cr.set_source_rgb(*hex_rgb(start_c))
cr.rectangle(sx, sy + sh - tb_h, 30, tb_h)
cr.fill()
cr.restore() cr.restore()
@@ -194,6 +203,101 @@ class CRTMonitorPreview(Gtk.DrawingArea):
cr.rectangle(sx - 0.5, sy - 0.5, sw + 1, sh + 1) cr.rectangle(sx - 0.5, sy - 0.5, sw + 1, sh + 1)
cr.stroke() cr.stroke()
def _draw_screensaver_preview(self, cr, sx, sy, sw, sh):
cr.set_source_rgb(0.0, 0.0, 0.0)
cr.rectangle(sx, sy, sw, sh)
cr.fill()
if self.ss_mode == "maze":
# Classic 3D brick corridor perspective inside CRT
# Ceiling (plaster)
cr.set_source_rgb(0.82, 0.80, 0.75)
cr.move_to(sx, sy)
cr.line_to(sx + sw, sy)
cr.line_to(sx + sw - 54, sy + 36)
cr.line_to(sx + 54, sy + 36)
cr.close_path()
cr.fill()
# Wood floor
cr.set_source_rgb(0.68, 0.50, 0.30)
cr.move_to(sx, sy + sh)
cr.line_to(sx + sw, sy + sh)
cr.line_to(sx + sw - 54, sy + sh - 36)
cr.line_to(sx + 54, sy + sh - 36)
cr.close_path()
cr.fill()
# Left & right brick walls
cr.set_source_rgb(0.56, 0.22, 0.16)
cr.move_to(sx, sy)
cr.line_to(sx + 54, sy + 36)
cr.line_to(sx + 54, sy + sh - 36)
cr.line_to(sx, sy + sh)
cr.close_path()
cr.fill()
cr.set_source_rgb(0.50, 0.19, 0.14)
cr.move_to(sx + sw, sy)
cr.line_to(sx + sw - 54, sy + 36)
cr.line_to(sx + sw - 54, sy + sh - 36)
cr.line_to(sx + sw, sy + sh)
cr.close_path()
cr.fill()
# Far end brick wall
cr.set_source_rgb(0.62, 0.25, 0.19)
cr.rectangle(sx + 54, sy + 36, sw - 108, sh - 72)
cr.fill()
# Mortar lines on far wall
cr.set_source_rgba(0.85, 0.82, 0.76, 0.45)
cr.set_line_width(0.8)
for row in range(1, 5):
yy = sy + 36 + row * (sh - 72) / 5.0
cr.move_to(sx + 54, yy)
cr.line_to(sx + sw - 54, yy)
cr.stroke()
# Floating golden smiley trophy in center
cx, cy = sx + sw / 2.0, sy + sh / 2.0
cr.set_source_rgb(0.98, 0.84, 0.14)
cr.arc(cx, cy, 11, 0, 6.283)
cr.fill()
cr.set_source_rgb(0.1, 0.1, 0.1)
cr.arc(cx - 3.5, cy - 2.5, 1.4, 0, 6.283)
cr.arc(cx + 3.5, cy - 2.5, 1.4, 0, 6.283)
cr.fill()
cr.set_line_width(1.4)
cr.arc(cx, cy + 1, 5.5, 0.4, 2.74)
cr.stroke()
elif self.ss_mode == "starfield":
for i in range(42):
px = sx + ((i * 37) % sw)
py = sy + ((i * 23) % sh)
b = 0.4 + 0.6 * ((i % 5) / 4.0)
cr.set_source_rgb(b, b, b)
cr.rectangle(px, py, 1.8, 1.8)
cr.fill()
elif self.ss_mode == "mystify":
cr.set_line_width(1.0)
for idx, col in enumerate(((0.0, 0.85, 1.0), (1.0, 0.35, 0.85))):
for t in range(4):
cr.set_source_rgba(*col, 0.35 + 0.18 * t)
o = t * 5 + idx * 14
cr.move_to(sx + 20 + o, sy + 18 + t * 3)
cr.line_to(sx + sw - 22 - t * 4, sy + 28 + o * 0.4)
cr.line_to(sx + sw - 34 + t * 2, sy + sh - 18 - t * 3)
cr.line_to(sx + 30 + t * 4, sy + sh - 32 + idx * 8)
cr.close_path()
cr.stroke()
else:
# Windows XP Logo preview
cx, cy = sx + sw / 2.0, sy + sh / 2.0 - 4
for dx, dy, col in [(-14, -10, (0.92, 0.27, 0.14)), (2, -10, (0.47, 0.77, 0.18)),
(-14, 4, (0.15, 0.58, 0.95)), (2, 4, (0.97, 0.76, 0.10))]:
cr.set_source_rgb(*col)
cr.rectangle(cx + dx, cy + dy, 12, 11)
cr.fill()
cr.set_source_rgb(0.88, 0.90, 0.96)
cr.select_font_face("Tahoma", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
cr.set_font_size(10)
cr.move_to(cx - 32, cy + 28)
cr.show_text("Windows XP")
class XPDisplayProperties(Gtk.Window): class XPDisplayProperties(Gtk.Window):
def __init__(self, initial_tab=0): def __init__(self, initial_tab=0):
@@ -233,6 +337,7 @@ class XPDisplayProperties(Gtk.Window):
btns.pack_start(b, False, False, 0) btns.pack_start(b, False, False, 0)
root.pack_end(btns, False, False, 0) root.pack_end(btns, False, False, 0)
self.initial_tab = initial_tab
self.sync_previews() self.sync_previews()
self.connect("key-press-event", lambda _w, ev: Gtk.main_quit() if ev.keyval == Gdk.KEY_Escape else False) self.connect("key-press-event", lambda _w, ev: Gtk.main_quit() if ev.keyval == Gdk.KEY_Escape else False)
self.connect("destroy", Gtk.main_quit) self.connect("destroy", Gtk.main_quit)
@@ -331,22 +436,24 @@ class XPDisplayProperties(Gtk.Window):
box.set_border_width(12) box.set_border_width(12)
ss_conf = Path("/home/carsten/.config/hypr/xp-screensaver.conf") ss_conf = Path("/home/carsten/.config/hypr/xp-screensaver.conf")
cur_ss = ss_conf.read_text(encoding="utf-8").strip() if ss_conf.exists() else "xp-logo" cur_ss = ss_conf.read_text(encoding="utf-8").strip() if ss_conf.exists() else "maze"
if cur_ss not in ("none", "xp-logo", "starfield", "mystify"): if cur_ss not in ("none", "maze", "xp-logo", "starfield", "mystify"):
cur_ss = "xp-logo" cur_ss = "maze"
prev = CRTMonitorPreview() self.ss_preview = CRTMonitorPreview()
self.previews.append(prev) self.ss_preview.set_screensaver_mode(cur_ss)
box.pack_start(prev, False, False, 0) self.previews.append(self.ss_preview)
box.pack_start(self.ss_preview, False, False, 0)
frame = Gtk.Frame(label=" Screen saver ") frame = Gtk.Frame(label=" Screen saver ")
inner = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8) inner = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
inner.set_border_width(10) inner.set_border_width(10)
row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8) row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
self.ss_combo = Gtk.ComboBoxText() self.ss_combo = Gtk.ComboBoxText()
for sid, label in [ for sid, label in [
("none", "(None)"), ("none", "(None)"),
("maze", "3D Maze"),
("xp-logo", "Windows XP"), ("xp-logo", "Windows XP"),
("starfield", "Starfield"), ("starfield", "Starfield"),
("mystify", "Mystify"), ("mystify", "Mystify"),
@@ -355,21 +462,131 @@ class XPDisplayProperties(Gtk.Window):
self.ss_combo.set_active_id(cur_ss) self.ss_combo.set_active_id(cur_ss)
row.pack_start(self.ss_combo, True, True, 0) row.pack_start(self.ss_combo, True, True, 0)
self.ss_settings_btn = Gtk.Button.new_with_label("Settings...")
self.ss_settings_btn.set_size_request(76, 24)
self.ss_settings_btn.set_sensitive(cur_ss == "maze")
self.ss_settings_btn.connect("clicked", self._on_maze_settings)
row.pack_start(self.ss_settings_btn, False, False, 0)
prev_btn = Gtk.Button.new_with_label("Preview") prev_btn = Gtk.Button.new_with_label("Preview")
prev_btn.set_size_request(76, 24) prev_btn.set_size_request(70, 24)
prev_btn.connect("clicked", lambda *_: subprocess.Popen( prev_btn.connect("clicked", lambda *_: subprocess.Popen(
["/home/carsten/.local/bin/xp-screensaver", "--mode", self.ss_combo.get_active_id() or "xp-logo"], ["/home/carsten/.local/bin/xp-screensaver", "--mode", self.ss_combo.get_active_id() or "maze"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)) ))
row.pack_start(prev_btn, False, False, 0) row.pack_start(prev_btn, False, False, 0)
inner.pack_start(row, False, False, 0) inner.pack_start(row, False, False, 0)
note = Gtk.Label(label="Activates automatically after 4 minutes of idle (before lock).", xalign=0) def on_ss_changed(combo):
sid = combo.get_active_id() or "none"
self.ss_preview.set_screensaver_mode(sid)
self.ss_settings_btn.set_sensitive(sid == "maze")
self.ss_combo.connect("changed", on_ss_changed)
note = Gtk.Label(label="Activates automatically after 4 minutes of idle (press M in 3D Maze to toggle map).", xalign=0)
note.set_line_wrap(True)
note.set_max_width_chars(46)
inner.pack_start(note, False, False, 0) inner.pack_start(note, False, False, 0)
frame.add(inner) frame.add(inner)
box.pack_start(frame, False, False, 0) box.pack_start(frame, False, False, 0)
self.notebook.append_page(box, Gtk.Label(label="Screen Saver")) self.notebook.append_page(box, Gtk.Label(label="Screen Saver"))
def _on_maze_settings(self, _btn):
maze_conf = Path("/home/carsten/.config/hypr/xp-maze.json")
cfg = {
"wall": "brick", "floor": "wood", "ceiling": "plaster",
"overlay": True, "flippers": True, "rat": True,
"speed": 1.0, "maze_size": 11,
}
if maze_conf.exists():
try:
cfg.update(json.loads(maze_conf.read_text(encoding="utf-8")))
except Exception:
pass
dlg = Gtk.Dialog(title="3D Maze Setup", transient_for=self, flags=0)
dlg.add_buttons("Cancel", Gtk.ResponseType.CANCEL, "OK", Gtk.ResponseType.OK)
dlg.set_resizable(False)
area = dlg.get_content_area()
area.set_border_width(12)
area.set_spacing(10)
tex_frame = Gtk.Frame(label=" Textures ")
grid = Gtk.Grid(row_spacing=6, column_spacing=10)
grid.set_border_width(8)
def make_combo(opts, cur):
cb = Gtk.ComboBoxText()
for k, lbl in opts:
cb.append(k, lbl)
cb.set_active_id(cur)
if cb.get_active() < 0:
cb.set_active(0)
return cb
wall_cb = make_combo([
("brick", "Brick (Classic)"), ("hedge", "Garden Hedge"),
("stone", "Medieval Stone"), ("wood-dark", "Wood Paneling"),
("psychedelic", "Psychedelic"),
], cfg["wall"])
floor_cb = make_combo([
("wood", "Wood Planks (Classic)"), ("tile", "Checkered Tile"),
("marble", "Marble"), ("brick", "Brick"), ("stone", "Stone"),
], cfg["floor"])
ceil_cb = make_combo([
("plaster", "Acoustic Plaster (Classic)"), ("wood", "Wood Planks"),
("starry", "Starry Night"), ("brick", "Brick"),
], cfg["ceiling"])
grid.attach(Gtk.Label(label="Walls:", xalign=0), 0, 0, 1, 1)
grid.attach(wall_cb, 1, 0, 1, 1)
grid.attach(Gtk.Label(label="Floor:", xalign=0), 0, 1, 1, 1)
grid.attach(floor_cb, 1, 1, 1, 1)
grid.attach(Gtk.Label(label="Ceiling:", xalign=0), 0, 2, 1, 1)
grid.attach(ceil_cb, 1, 2, 1, 1)
tex_frame.add(grid)
area.pack_start(tex_frame, False, False, 0)
opt_frame = Gtk.Frame(label=" Options ")
obox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
obox.set_border_width(8)
chk_overlay = Gtk.CheckButton.new_with_label("Show translucent Maze Overlay map")
chk_overlay.set_active(bool(cfg["overlay"]))
chk_flippers = Gtk.CheckButton.new_with_label("Enable floating 3D ceiling-flipper polyhedra")
chk_flippers.set_active(bool(cfg["flippers"]))
chk_rat = Gtk.CheckButton.new_with_label("Enable roaming Maze Rat")
chk_rat.set_active(bool(cfg["rat"]))
obox.pack_start(chk_overlay, False, False, 0)
obox.pack_start(chk_flippers, False, False, 0)
obox.pack_start(chk_rat, False, False, 0)
sp_row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
sp_row.pack_start(Gtk.Label(label="Walk Speed:", xalign=0), False, False, 0)
sp_scale = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 0.5, 2.0, 0.1)
sp_scale.set_value(float(cfg.get("speed", 1.0)))
sp_scale.set_draw_value(False)
sp_scale.set_size_request(150, -1)
sp_row.pack_start(sp_scale, True, True, 0)
obox.pack_start(sp_row, False, False, 0)
opt_frame.add(obox)
area.pack_start(opt_frame, False, False, 0)
dlg.show_all()
if dlg.run() == Gtk.ResponseType.OK:
new_cfg = {
"wall": wall_cb.get_active_id() or "brick",
"floor": floor_cb.get_active_id() or "wood",
"ceiling": ceil_cb.get_active_id() or "plaster",
"overlay": chk_overlay.get_active(),
"flippers": chk_flippers.get_active(),
"rat": chk_rat.get_active(),
"speed": round(sp_scale.get_value(), 2),
"maze_size": int(cfg.get("maze_size", 11)),
}
maze_conf.write_text(json.dumps(new_cfg, indent=2) + "\n", encoding="utf-8")
dlg.destroy()
def _build_appearance_tab(self): def _build_appearance_tab(self):
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
box.set_border_width(12) box.set_border_width(12)
@@ -513,10 +730,13 @@ def main():
tab = 0 tab = 0
if "--desktop" in sys.argv: if "--desktop" in sys.argv:
tab = 1 tab = 1
elif "--appearance" in sys.argv: elif "--screensaver" in sys.argv:
tab = 2 tab = 2
elif "--appearance" in sys.argv:
tab = 3
win = XPDisplayProperties(initial_tab=tab) win = XPDisplayProperties(initial_tab=tab)
win.show_all() win.show_all()
win.notebook.set_current_page(tab)
Gtk.main() Gtk.main()
+2
View File
@@ -38,6 +38,8 @@ XP_ALIASES = {
"sndvol32.exe": "pavucontrol", "sndvol32.exe": "pavucontrol",
"mspaint": "swappy", "mspaint": "swappy",
"mspaint.exe": "swappy", "mspaint.exe": "swappy",
"ssmaze": "/home/carsten/.local/bin/xp-screensaver --mode maze",
"ssmaze.scr": "/home/carsten/.local/bin/xp-screensaver --mode maze",
} }
+1514 -35
View File
File diff suppressed because it is too large Load Diff
+10
View File
@@ -0,0 +1,10 @@
{
"wall": "brick",
"floor": "wood",
"ceiling": "plaster",
"overlay": true,
"flippers": true,
"rat": true,
"speed": 1.0,
"maze_size": 11
}
+1 -1
View File
@@ -1 +1 @@
xp-logo maze