From 82348d51320b89281407e1cb0e18ce0022189144 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 10 Jul 2025 11:42:37 -0400 Subject: [PATCH] From https://www.jwz.org/xscreensaver/xscreensaver-6.12.tar.gz -rw-rw-r-- 1 zblaxell zblaxell 25177935 Jul 7 15:51 xscreensaver-6.12.tar.gz ab363c2373ff3fe8436afeee344195c7ac1e7d09 xscreensaver-6.12.tar.gz --- OSX/Randomizer.plist | 10 +- OSX/SaverRunner.plist | 10 +- OSX/Updater.plist | 10 +- OSX/XScreenSaver.plist | 10 +- OSX/bindist.rtf | 4 +- OSX/iSaverRunner.plist | 10 +- OSX/tvSaverRunner.plist | 10 +- README | 6 +- configure | 23 +- configure.ac | 36 +- driver/Makefile.in | 244 ++++++++--- driver/XScreenSaver.ad.in | 4 +- driver/demo-Gtk.c | 138 +++--- driver/dialog.c | 8 +- driver/dpms.c | 137 ++++-- driver/fade.c | 307 ++++++++++++- driver/prefsw.c | 7 +- driver/subprocs.c | 60 ++- driver/types.h | 15 +- driver/wayland-dpms.c | 411 ++++++++++++++++++ driver/wayland-dpms.h | 22 + driver/wayland-dpy.c | 151 +++++++ driver/wayland-dpy.h | 39 ++ driver/wayland-dpyI.h | 25 ++ driver/wayland-idle.c | 197 +++------ driver/wayland-idle.h | 28 +- .../wayland-protocols/dpms-client-protocol.h | 284 ++++++++++++ driver/wayland-protocols/dpms-protocol.c | 59 +++ driver/wayland-protocols/dpms.xml | 82 ++++ .../ext-idle-notify-v1-client-protocol.h | 0 .../ext-idle-notify-v1-protocol.c | 0 .../ext-idle-notify-v1.xml | 0 .../idle-client-protocol.h | 0 .../{ => wayland-protocols}/idle-protocol.c | 0 driver/{ => wayland-protocols}/idle.xml | 15 +- ...r-management-unstable-v1-client-protocol.h | 313 +++++++++++++ ...ut-power-management-unstable-v1-protocol.c | 76 ++++ ...lr-output-power-management-unstable-v1.xml | 128 ++++++ .../xdg-shell-v1-client-protocol.h | 0 .../xdg-shell-v1-protocol.c | 0 driver/{ => wayland-protocols}/xdg-shell.xml | 0 driver/windows.c | 20 +- driver/xscreensaver-gfx.c | 47 +- driver/xscreensaver.c | 67 +-- driver/xscreensaver.h | 5 +- driver/xscreensaver.man | 17 +- hacks/config/README | 4 +- hacks/glx/Makefile.in | 6 +- hacks/glx/mapscroller.c | 49 ++- hacks/glx/mapscroller.pl | 2 +- hacks/glx/xlock-gl-utils.c | 197 +-------- hacks/glx/xscreensaver-gl-visual.c | 3 +- hacks/screenhack.c | 21 +- hacks/xlockmoreI.h | 9 +- hacks/xscreensaver-getimage.c | 76 +++- po/POTFILES.in | 2 +- utils/Makefile.in | 13 +- utils/colorbars.c | 52 ++- utils/screenshot.c | 43 +- utils/version.h | 6 +- utils/visual-gl.c | 253 ++++++++++- utils/visual-gl.h | 44 ++ utils/visual.h | 10 +- xscreensaver.spec | 2 +- 64 files changed, 3118 insertions(+), 709 deletions(-) create mode 100644 driver/wayland-dpms.c create mode 100644 driver/wayland-dpms.h create mode 100644 driver/wayland-dpy.c create mode 100644 driver/wayland-dpy.h create mode 100644 driver/wayland-dpyI.h create mode 100644 driver/wayland-protocols/dpms-client-protocol.h create mode 100644 driver/wayland-protocols/dpms-protocol.c create mode 100644 driver/wayland-protocols/dpms.xml rename driver/{ => wayland-protocols}/ext-idle-notify-v1-client-protocol.h (100%) rename driver/{ => wayland-protocols}/ext-idle-notify-v1-protocol.c (100%) rename driver/{ => wayland-protocols}/ext-idle-notify-v1.xml (100%) rename driver/{ => wayland-protocols}/idle-client-protocol.h (100%) rename driver/{ => wayland-protocols}/idle-protocol.c (100%) rename driver/{ => wayland-protocols}/idle.xml (70%) create mode 100644 driver/wayland-protocols/wlr-output-power-management-unstable-v1-client-protocol.h create mode 100644 driver/wayland-protocols/wlr-output-power-management-unstable-v1-protocol.c create mode 100644 driver/wayland-protocols/wlr-output-power-management-unstable-v1.xml rename driver/{ => wayland-protocols}/xdg-shell-v1-client-protocol.h (100%) rename driver/{ => wayland-protocols}/xdg-shell-v1-protocol.c (100%) rename driver/{ => wayland-protocols}/xdg-shell.xml (100%) create mode 100644 utils/visual-gl.h diff --git a/OSX/Randomizer.plist b/OSX/Randomizer.plist index 01e6eae9..4be91473 100644 --- a/OSX/Randomizer.plist +++ b/OSX/Randomizer.plist @@ -17,7 +17,7 @@ CFBundleSignature ???? CFBundleVersion - 6.11 + 6.12 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSPrincipalClass @@ -25,12 +25,12 @@ LSApplicationCategoryType public.app-category.entertainment CFBundleShortVersionString - 6.11 + 6.12 CFBundleLongVersionString - 6.11 + 6.12 CFBundleGetInfoString - 6.11 + 6.12 NSHumanReadableCopyright - 6.11 + 6.12 diff --git a/OSX/SaverRunner.plist b/OSX/SaverRunner.plist index c9dbcf88..5018dfaf 100644 --- a/OSX/SaverRunner.plist +++ b/OSX/SaverRunner.plist @@ -17,7 +17,7 @@ CFBundleSignature ???? CFBundleVersion - 6.11 + 6.12 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSPrincipalClass @@ -25,13 +25,13 @@ LSApplicationCategoryType public.app-category.entertainment CFBundleShortVersionString - 6.11 + 6.12 CFBundleLongVersionString - 6.11 + 6.12 CFBundleGetInfoString - 6.11 + 6.12 NSHumanReadableCopyright - 6.11 + 6.12 NSMainNibFile SaverRunner CFBundleIconFile diff --git a/OSX/Updater.plist b/OSX/Updater.plist index f923b227..3e748a27 100644 --- a/OSX/Updater.plist +++ b/OSX/Updater.plist @@ -17,7 +17,7 @@ CFBundleSignature ???? CFBundleVersion - 6.11 + 6.12 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSPrincipalClass @@ -25,13 +25,13 @@ LSApplicationCategoryType public.app-category.entertainment CFBundleShortVersionString - 6.11 + 6.12 CFBundleLongVersionString - 6.11 + 6.12 CFBundleGetInfoString - 6.11 + 6.12 NSHumanReadableCopyright - 6.11 + 6.12 NSMainNibFile Updater CFBundleIconFile diff --git a/OSX/XScreenSaver.plist b/OSX/XScreenSaver.plist index 7b6dceb7..ff870205 100644 --- a/OSX/XScreenSaver.plist +++ b/OSX/XScreenSaver.plist @@ -17,7 +17,7 @@ CFBundleSignature ???? CFBundleVersion - 6.11 + 6.12 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSPrincipalClass @@ -25,13 +25,13 @@ LSApplicationCategoryType public.app-category.entertainment CFBundleShortVersionString - 6.11 + 6.12 CFBundleLongVersionString - 6.11 + 6.12 CFBundleGetInfoString - 6.11 + 6.12 NSHumanReadableCopyright - 6.11 + 6.12 NSMainNibFile SaverRunner diff --git a/OSX/bindist.rtf b/OSX/bindist.rtf index 383cf49c..3c249e87 100644 --- a/OSX/bindist.rtf +++ b/OSX/bindist.rtf @@ -16,8 +16,8 @@ \b0 by Jamie Zawinski\ and many others\ \ -version 6.11\ -01-Jul-2025\ +version 6.12\ +07-Jul-2025\ \ {\field{\*\fldinst{HYPERLINK "https://www.jwz.org/xscreensaver/"}}{\fldrslt \cf2 \ul \ulc2 https://www.jwz.org/xscreensaver/}}\ \pard\pardeftab720 diff --git a/OSX/iSaverRunner.plist b/OSX/iSaverRunner.plist index b1f7bd23..12df7001 100644 --- a/OSX/iSaverRunner.plist +++ b/OSX/iSaverRunner.plist @@ -17,17 +17,17 @@ CFBundleSignature ???? CFBundleVersion - 6.11 + 6.12 LSApplicationCategoryType public.app-category.entertainment CFBundleShortVersionString - 6.11 + 6.12 CFBundleLongVersionString - 6.11 + 6.12 CFBundleGetInfoString - 6.11 + 6.12 NSHumanReadableCopyright - 6.11 + 6.12 NSMainNibFile iSaverRunner CFBundleDisplayName diff --git a/OSX/tvSaverRunner.plist b/OSX/tvSaverRunner.plist index 0c650777..5ccbe808 100644 --- a/OSX/tvSaverRunner.plist +++ b/OSX/tvSaverRunner.plist @@ -17,17 +17,17 @@ CFBundleSignature ???? CFBundleVersion - 6.11 + 6.12 LSApplicationCategoryType public.app-category.entertainment CFBundleShortVersionString - 6.11 + 6.12 CFBundleLongVersionString - 6.11 + 6.12 CFBundleGetInfoString - 6.11 + 6.12 NSHumanReadableCopyright - 6.11 + 6.12 CFBundleDisplayName ${PRODUCT_NAME} CFBundleIcons diff --git a/README b/README index 82b1769a..9fc2c315 100644 --- a/README +++ b/README @@ -39,7 +39,7 @@ To compile for a Unix system with X11: perl pkg-config gettext intltool libx11 libxext libxi libxt libxft libxinerama libxrandr libxxf86vm libgl libglu libgle libgtk-3 - libgdk-pixbuf2.0 libjpeg libxml2 libpam libsystemd elogind + libgdk-pixbuf2.0 libjpeg libxml2 libpam libsystemd elogind libwayland BSD systems might need gmake instead of make. @@ -69,10 +69,14 @@ Interested in writing a new screen saver? Version History =============================================================================== +6.12 * X11: DPMS works on Wayland. + * X11: Fading uses GL now which should be more performant. + 6.11 * X11: Now supports Wayland (blanking only, not locking). * X11: More reliable and timely DPMS activation. * X11: Dead keys work in password input. * X11: Fixed a couple of minor Y2038 bugs. + 6.10 * New hacks, `dumpsterfire', `hopffibration', `platonicfolding' and `klondike'. * Rewrote the VT100 emulator for 'apple2' and 'phosphor'. diff --git a/configure b/configure index f52c29b5..894999ee 100755 --- a/configure +++ b/configure @@ -687,7 +687,10 @@ SETCAP_HACKS SETUID_HACKS SETUID_AUTH PROG_SETCAP +WAYLAND_GTK_OBJS +WAYLAND_DPMS_OBJS WAYLAND_IDLE_OBJS +WAYLAND_DPY_OBJS WAYLAND_GEN WAYLAND_DATADIR WAYLAND_LIBS @@ -698,6 +701,8 @@ PASSWD_LIBS XINERAMA_LIBS XDPMS_LIBS GLE_LIBS +GFX_GL_OBJS +GL_CFLAGS GL_LIBS PTY_LIBS HACK_LIBS @@ -13487,9 +13492,9 @@ if test "$with_wayland" = yes; then pkgs='' ok="yes" - pkg_check_version wayland-server 1.0 - pkg_check_version wayland-client 1.0 - pkg_check_version wayland-scanner 1.0 + pkg_check_version wayland-server 1.8 + pkg_check_version wayland-client 1.8 + #pkg_check_version wayland-scanner 1.8 ac_wayland_version_string="$vers" have_wayland="$ok" wayland_pkgs="$pkgs" @@ -13524,12 +13529,18 @@ printf "%s\n" "$ac_cv_wayland_config_libs" >&6; } WAYLAND_DATADIR="" WAYLAND_GEN="" + WAYLAND_DPY_OBJS="" WAYLAND_IDLE_OBJS="" + WAYLAND_DPMS_OBJS="" + WAYLAND_GTK_OBJS="" if test "$have_wayland" = yes; then WAYLAND_DATADIR=`$pkg_config --variable=prefix wayland-client` WAYLAND_DATADIR="$WAYLAND_DATADIR/share" WAYLAND_GEN='$(WAYLAND_GEN_HDRS) $(WAYLAND_GEN_SRCS)' + WAYLAND_DPY_OBJS='$(WAYLAND_DPY_OBJS_1)' WAYLAND_IDLE_OBJS='$(WAYLAND_IDLE_OBJS_1)' + WAYLAND_DPMS_OBJS='$(WAYLAND_DPMS_OBJS_1)' + WAYLAND_GTK_OBJS='$(WAYLAND_GTK_OBJS_1)' fi if test "$have_wayland" = yes; then @@ -18247,6 +18258,9 @@ fi printf "%s\n" "#define HAVE_GL 1" >>confdefs.h + GL_CFLAGS="-DUSE_GL" + GFX_GL_OBJS='$(GFX_GL_OBJS_1)' + # OpenGL 1.0 didn't have multiple textures. ac_save_CPPFLAGS="$CPPFLAGS" @@ -22937,6 +22951,9 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi +# Since there is no .in file to force its creation in a different build dir +test -d driver/wayland-protocols || mkdir driver/wayland-protocols + ############################################################################### # # Print some warnings at the end. diff --git a/configure.ac b/configure.ac index 914b7b4e..423ea450 100644 --- a/configure.ac +++ b/configure.ac @@ -1,18 +1,7 @@ -# configure.in --- xscreensaver, Copyright © 1997-2025 Jamie Zawinski. +# configure.ac --- xscreensaver, Copyright © 1997-2025 Jamie Zawinski. # -# Note: upgrading past 2.69_5 breaks the world, mostly the po/ shitshow. AC_PREREQ([2.69]) - -# If you accidentally upgraded autoconf, re-install the 2019-08-23 version: -# -# git clone --single-branch https://github.com/macports/macports-ports.git -# cd macports-ports/ -# git checkout 1d802b48a7b00b6c154e971119a2a309550c79c2 -# cd devel/autoconf -# sudo port install -# port installed autoconf - AC_INIT AC_CONFIG_SRCDIR([driver/subprocs.c]) AC_CONFIG_HEADERS([config.h]) @@ -2228,9 +2217,9 @@ if test "$with_wayland" = yes; then pkgs='' ok="yes" - pkg_check_version wayland-server 1.0 - pkg_check_version wayland-client 1.0 - pkg_check_version wayland-scanner 1.0 + pkg_check_version wayland-server 1.8 + pkg_check_version wayland-client 1.8 + #pkg_check_version wayland-scanner 1.8 ac_wayland_version_string="$vers" have_wayland="$ok" wayland_pkgs="$pkgs" @@ -2247,12 +2236,18 @@ if test "$with_wayland" = yes; then WAYLAND_DATADIR="" WAYLAND_GEN="" + WAYLAND_DPY_OBJS="" WAYLAND_IDLE_OBJS="" + WAYLAND_DPMS_OBJS="" + WAYLAND_GTK_OBJS="" if test "$have_wayland" = yes; then WAYLAND_DATADIR=`$pkg_config --variable=prefix wayland-client` WAYLAND_DATADIR="$WAYLAND_DATADIR/share" WAYLAND_GEN='$(WAYLAND_GEN_HDRS) $(WAYLAND_GEN_SRCS)' + WAYLAND_DPY_OBJS='$(WAYLAND_DPY_OBJS_1)' WAYLAND_IDLE_OBJS='$(WAYLAND_IDLE_OBJS_1)' + WAYLAND_DPMS_OBJS='$(WAYLAND_DPMS_OBJS_1)' + WAYLAND_GTK_OBJS='$(WAYLAND_GTK_OBJS_1)' fi if test "$have_wayland" = yes; then @@ -3518,6 +3513,8 @@ if test "$with_gl" = yes; then if test "$have_gl" = yes; then AC_DEFINE(HAVE_GL) + GL_CFLAGS="-DUSE_GL" + GFX_GL_OBJS='$(GFX_GL_OBJS_1)' # OpenGL 1.0 didn't have multiple textures. AC_CHECK_X_LIB($gl_lib_1, glBindTexture, [AC_DEFINE(HAVE_GLBINDTEXTURE)], @@ -4515,6 +4512,8 @@ AC_SUBST(JPEG_LIBS) AC_SUBST(HACK_LIBS) AC_SUBST(PTY_LIBS) AC_SUBST(GL_LIBS) +AC_SUBST(GL_CFLAGS) +AC_SUBST(GFX_GL_OBJS) AC_SUBST(GLE_LIBS) AC_SUBST(XDPMS_LIBS) AC_SUBST(PTHREAD_LIBS) @@ -4526,7 +4525,10 @@ AC_SUBST(WAYLAND_CFLAGS) AC_SUBST(WAYLAND_LIBS) AC_SUBST(WAYLAND_DATADIR) AC_SUBST(WAYLAND_GEN) +AC_SUBST(WAYLAND_DPY_OBJS) AC_SUBST(WAYLAND_IDLE_OBJS) +AC_SUBST(WAYLAND_DPMS_OBJS) +AC_SUBST(WAYLAND_GTK_OBJS) AC_SUBST(PROG_SETCAP) AC_SUBST(SETUID_AUTH) AC_SUBST(SETUID_HACKS) @@ -4602,6 +4604,10 @@ AC_CONFIG_FILES([Makefile driver/XScreenSaver.ad]) AC_OUTPUT +# Since there is no .in file to force its creation in a different build dir +test -d driver/wayland-protocols || mkdir driver/wayland-protocols + + ############################################################################### # # Print some warnings at the end. diff --git a/driver/Makefile.in b/driver/Makefile.in index 2dccc60f..a013b82d 100644 --- a/driver/Makefile.in +++ b/driver/Makefile.in @@ -38,21 +38,45 @@ WAYLAND_LIBS = @WAYLAND_LIBS@ WAYLAND_DATADIR = @WAYLAND_DATADIR@ WAYLAND_GEN = @WAYLAND_GEN@ -WAYLAND_GEN_XML = xdg-shell.xml \ - ext-idle-notify-v1.xml \ - idle.xml -WAYLAND_GEN_HDRS = xdg-shell-v1-client-protocol.h \ - ext-idle-notify-v1-client-protocol.h \ - idle-client-protocol.h -WAYLAND_GEN_SRCS = xdg-shell-v1-protocol.c \ - ext-idle-notify-v1-protocol.c \ - idle-protocol.c +WAYLAND_PROTO = wayland-protocols +WAYLAND_GEN_XML = $(WAYLAND_PROTO)/xdg-shell.xml \ + $(WAYLAND_PROTO)/ext-idle-notify-v1.xml \ + $(WAYLAND_PROTO)/idle.xml \ + $(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1.xml \ + $(WAYLAND_PROTO)/dpms.xml + +WAYLAND_GEN_HDRS = $(WAYLAND_PROTO)/xdg-shell-v1-client-protocol.h \ + $(WAYLAND_PROTO)/ext-idle-notify-v1-client-protocol.h \ + $(WAYLAND_PROTO)/idle-client-protocol.h \ + $(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1-client-protocol.h \ + $(WAYLAND_PROTO)/dpms-client-protocol.h + +WAYLAND_GEN_SRCS = $(WAYLAND_PROTO)/xdg-shell-v1-protocol.c \ + $(WAYLAND_PROTO)/ext-idle-notify-v1-protocol.c \ + $(WAYLAND_PROTO)/idle-protocol.c \ + $(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1-protocol.c \ + $(WAYLAND_PROTO)/dpms-protocol.c + +WAYLAND_DPY_OBJS = @WAYLAND_DPY_OBJS@ +WAYLAND_DPY_SRCS = wayland-dpy.c +WAYLAND_DPY_OBJS_1 = wayland-dpy.o WAYLAND_IDLE_OBJS = @WAYLAND_IDLE_OBJS@ WAYLAND_IDLE_SRCS = wayland-idle.c WAYLAND_IDLE_OBJS_1 = wayland-idle.o \ - ext-idle-notify-v1-protocol.o \ - idle-protocol.o + $(WAYLAND_PROTO)/ext-idle-notify-v1-protocol.o \ + $(WAYLAND_PROTO)/idle-protocol.o + +WAYLAND_DPMS_OBJS = @WAYLAND_DPMS_OBJS@ +WAYLAND_DPMS_SRCS = wayland-dpms.c +WAYLAND_DPMS_OBJS_1 = wayland-dpms.o \ + $(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1-protocol.o \ + $(WAYLAND_PROTO)/dpms-protocol.o + +WAYLAND_GTK_OBJS = @WAYLAND_GTK_OBJS@ +WAYLAND_GTK_SRCS = wayland-dpms.c +WAYLAND_GTK_OBJS_1 = $(WAYLAND_DPY_OBJS) $(WAYLAND_IDLE_OBJS) \ + $(WAYLAND_DPMS_OBJS) HACKDIR = @HACKDIR@ HACK_CONF_DIR = @HACK_CONF_DIR@ @@ -123,17 +147,20 @@ XML_LIBS = @XML_LIBS@ DAEMON_DEFS = -DDEFAULT_PATH_PREFIX='"@HACKDIR@"' -DAD_DIR='"$(AD_DIR)"' DAEMON_SRCS = xscreensaver.c blurb.c atoms.c clientmsg.c xinput.c prefs.c \ - $(WAYLAND_IDLE_SRCS) + $(WAYLAND_DPY_SRCS) $(WAYLAND_IDLE_SRCS) DAEMON_OBJS = xscreensaver.o blurb.o atoms.o clientmsg.o xinput.o prefs.o \ - $(UTILS_BIN)/xmu.o $(WAYLAND_IDLE_OBJS) + $(UTILS_BIN)/xmu.o $(WAYLAND_DPY_OBJS) $(WAYLAND_IDLE_OBJS) DAEMON_LIBS = $(LIBS_PRE) $(XINPUT_LIBS) -lX11 $(WAYLAND_LIBS) $(LIBS_POST) -GFX_DEFS = -DLOCALEDIR=\"$(localedir)\" +GFX_DEFS = @GL_CFLAGS@ -DLOCALEDIR=\"$(localedir)\" +SUBP_DEFS = @GL_CFLAGS@ GFX_SRCS = xscreensaver-gfx.c screens.c windows.c subprocs.c \ - exec.c prefsw.c dpms.c fade.c exts.c atomswm.c + exec.c prefsw.c dpms.c fade.c exts.c atomswm.c \ + $(WAYLAND_DPY_SRCS) $(WAYLAND_DPMS_SRCS) GFX_OBJS = xscreensaver-gfx.o screens.o windows.o subprocs.o \ exec.o prefsw.o dpms.o fade.o exts.o atomswm.o \ prefs.o blurb.o atoms.o clientmsg.o xinput.o \ + $(WAYLAND_DPY_OBJS) $(WAYLAND_DPMS_OBJS) \ $(UTILS_BIN)/xmu.o \ $(UTILS_BIN)/yarandom.o \ $(UTILS_BIN)/resources.o \ @@ -146,9 +173,13 @@ GFX_OBJS = xscreensaver-gfx.o screens.o windows.o subprocs.o \ $(UTILS_BIN)/xft.o \ $(UTILS_BIN)/utf8wc.o \ $(UTILS_BIN)/xshm.o \ - $(UTILS_BIN)/aligned_malloc.o + $(UTILS_BIN)/aligned_malloc.o \ + $(GFX_GL_OBJS) +GFX_GL_OBJS = @GFX_GL_OBJS@ +GFX_GL_OBJS_1 = $(UTILS_BIN)/visual-gl.o $(UTILS_BIN)/pow2.o GFX_LIBS = $(LIBS_PRE) $(XFT_LIBS) $(XDPMS_LIBS) $(XINERAMA_LIBS) \ - @SAVER_LIBS@ -lXt -lX11 -lXext -lXi $(LIBS_POST) $(INTL_LIBS) + @SAVER_LIBS@ -lXt -lX11 -lXext -lXi @GL_LIBS@ \ + $(WAYLAND_LIBS) $(LIBS_POST) $(INTL_LIBS) PWENT_SRCS = passwd-pwent.c PWENT_OBJS = passwd-pwent.o @@ -199,7 +230,7 @@ GTK_SRCS = demo-Gtk.c demo-Gtk-conf.c GTK_OBJS = demo-Gtk.o demo-Gtk-conf.o demo-Gtk-resources.o \ blurb.o exec.o prefs.o prefsw.o dpms.o remote.o screens.o \ clientmsg.o atoms.o \ - $(WAYLAND_IDLE_OBJS) \ + $(WAYLAND_GTK_OBJS) \ $(UTILS_BIN)/xmu.o \ $(UTILS_BIN)/resources.o \ $(UTILS_BIN)/visual.o \ @@ -241,7 +272,8 @@ DESKS = xscreensaver.desktop xscreensaver.service HDRS = XScreenSaver_ad.h XScreenSaver_Xm_ad.h \ xscreensaver.h prefs.h remote.h exec.h \ demo-Gtk-conf.h auth.h types.h blurb.h atoms.h clientmsg.h \ - screens.h xinput.h fade.h wayland-idle.h \ + screens.h xinput.h fade.h wayland-dpy.h wayland-dpyI.h \ + wayland-idle.h wayland-dpms.h \ $(WAYLAND_GEN_HDRS) MENA = xscreensaver.man xscreensaver-settings.man \ xscreensaver-command.man @@ -676,32 +708,6 @@ uninstall-xml: rm -f $(install_prefix)$(HACK_CONF_DIR)/README -# Generate .c and .h files for various Wayland APIs. -# -xdg-shell.xml: $(WAYLAND_DATADIR)/wayland-protocols/stable/xdg-shell/xdg-shell.xml - cp -p $< $@ -xdg-shell-v1-client-protocol.h: xdg-shell.xml - wayland-scanner client-header < $< > $@ -xdg-shell-v1-protocol.c: xdg-shell.xml - wayland-scanner private-code < $< > $@ - -ext-idle-notify-v1.xml: \ - $(WAYLAND_DATADIR)/wayland-protocols/staging/ext-idle-notify/ext-idle-notify-v1.xml - cp -p $< $@ -ext-idle-notify-v1-client-protocol.h: ext-idle-notify-v1.xml - wayland-scanner client-header < $< > $@ -ext-idle-notify-v1-protocol.c: ext-idle-notify-v1.xml - wayland-scanner private-code < $< > $@ - -# org_kde_kwin_idle -- I don't know why this isn't in WAYLAND_DATADIR -#idle.xml: $(WAYLAND_DATADIR)/wayland-protocols/stable/ext-idle-notify/idle.xml -# cp -p $< $@ -idle-client-protocol.h: idle.xml - wayland-scanner client-header < $< > $@ -idle-protocol.c: idle.xml - wayland-scanner private-code < $< > $@ - - ############################################################################## # # Clean and dependencies @@ -832,6 +838,8 @@ $(UTILS_BIN)/font-retry.o: $(UTILS_SRC)/font-retry.c $(UTILS_BIN)/xshm.o: $(UTILS_SRC)/xshm.c $(UTILS_BIN)/aligned_malloc.o: $(UTILS_SRC)/aligned_malloc.c $(UTILS_BIN)/screenshot.o: $(UTILS_SRC)/screenshot.c +$(UTILS_BIN)/visual-gl.o: $(UTILS_SRC)/visual-gl.c +$(UTILS_BIN)/pow2.o: $(UTILS_SRC)/pow2.c UTIL_OBJS = $(UTILS_BIN)/overlay.o \ @@ -852,7 +860,9 @@ UTIL_OBJS = $(UTILS_BIN)/overlay.o \ $(UTILS_BIN)/font-retry.o \ $(UTILS_BIN)/xshm.o \ $(UTILS_BIN)/aligned_malloc.o \ - $(UTILS_BIN)/screenshot.o + $(UTILS_BIN)/screenshot.o \ + $(UTILS_BIN)/visual-gl.o \ + $(UTILS_BIN)/pow2.o $(UTIL_OBJS): $(MAKE2CC) -C $(UTILS_BIN) $(@F) @@ -870,9 +880,11 @@ CC_ALL=$(INCLUDES) $(DEFS) $(CPPFLAGS) $(CFLAGS) $(X_CFLAGS) .c.o: $(CC) -c $(CC_ALL) $< -# # subprocs takes an extra -D option. -# subprocs.o: subprocs.c -# $(CC) -c $(CC_ALL) $(SUBP_DEFS) $< +# subprocs takes an extra -D option. +subprocs.o: subprocs.c + $(CC) -c $(CC_ALL) $(SUBP_DEFS) $< +fade.o: fade.c + $(CC) -c $(CC_ALL) $(SUBP_DEFS) $< # xscreensaver takes an extra -D option. xscreensaver.o: xscreensaver.c @@ -979,6 +991,114 @@ XScreenSaver_Xm_ad.h:: @INTLTOOL_SERVICE_RULE@ +############################################################################## +# +# Wayland protocols +# +############################################################################## + +# Generate .c and .h files for various Wayland APIs. +# +# Since this stuff never changes and is small, the tar file includes the +# generated files in $(srcdir), so that client builds probably won't ever +# need to run "wayland-scanner". But we print a warning if the system's +# XML files exist and differ from our own. + +# "xdg-shell" isn't used yet but probably will be. +# +$(srcdir)/$(WAYLAND_PROTO)/xdg-shell.xml:: + @\ + F=$(WAYLAND_DATADIR)/wayland-protocols/stable/xdg-shell/xdg-shell.xml ; \ + if [ -e "$$F" ] && ! cmp -s "$$F" $@ ; then \ + echo "WARNING: $$F and $@ differ" >&2 ; \ + fi +$(srcdir)/$(WAYLAND_PROTO)/xdg-shell-v1-client-protocol.h: \ +$(srcdir)/$(WAYLAND_PROTO)/xdg-shell.xml + wayland-scanner client-header < $< > $@ +$(srcdir)/$(WAYLAND_PROTO)/xdg-shell-v1-protocol.c: \ +$(srcdir)/$(WAYLAND_PROTO)/xdg-shell.xml + wayland-scanner private-code < $< > $@ +$(WAYLAND_PROTO)/xdg-shell-v1-protocol.o: \ +$(srcdir)/$(WAYLAND_PROTO)/xdg-shell-v1-protocol.c + $(CC) -c $(CC_ALL) $< -o $@ + +# "idle-notify-v1" for wayland-idle.c +# +$(srcdir)/$(WAYLAND_PROTO)/ext-idle-notify-v1.xml:: + @\ + F=$(WAYLAND_DATADIR)/wayland-protocols/staging/ext-idle-notify/ext-idle-notify-v1.xml ; \ + if [ -e "$$F" ] && ! cmp -s "$$F" $@ ; then \ + echo "WARNING: $$F and $@ differ" >&2 ; \ + fi +$(srcdir)/$(WAYLAND_PROTO)/ext-idle-notify-v1-client-protocol.h: \ +$(srcdir)/$(WAYLAND_PROTO)/ext-idle-notify-v1.xml + wayland-scanner client-header < $< > $@ +$(srcdir)/$(WAYLAND_PROTO)/ext-idle-notify-v1-protocol.c: \ +$(srcdir)/$(WAYLAND_PROTO)/ext-idle-notify-v1.xml + wayland-scanner private-code < $< > $@ +$(WAYLAND_PROTO)/ext-idle-notify-v1-protocol.o: \ +$(srcdir)/$(WAYLAND_PROTO)/ext-idle-notify-v1-protocol.c + $(CC) -c $(CC_ALL) $< -o $@ + +# "kde-idle" for wayland-idle.c +# "apt install plasma-wayland-protocols" to get the system XML file. +# +$(srcdir)/$(WAYLAND_PROTO)/idle.xml:: + @\ + F="$(WAYLAND_DATADIR)/plasma-wayland-protocols/idle.xml" ; \ + if [ -e "$$F" ] && ! cmp -s "$$F" $@ ; then \ + echo "WARNING: $$F and $@ differ" >&2 ; \ + fi +$(srcdir)/$(WAYLAND_PROTO)/idle-client-protocol.h: \ +$(srcdir)/$(WAYLAND_PROTO)/idle.xml + wayland-scanner client-header < $< > $@ +$(srcdir)/$(WAYLAND_PROTO)/idle-protocol.c: \ +$(srcdir)/$(WAYLAND_PROTO)/idle.xml + wayland-scanner private-code < $< > $@ +$(WAYLAND_PROTO)/idle-protocol.o: \ +$(srcdir)/$(WAYLAND_PROTO)/idle-protocol.c + $(CC) -c $(CC_ALL) $< -o $@ + +# "wlr-output-power-management" for wayland-dpms.c +# I don't know what to install to get this into $(WAYLAND_DATADIR) +# +$(srcdir)/$(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1.xml:: + @\ + F="$(WAYLAND_DATADIR)/wayland-protocols/staging/wlr-output-power-management-unstable-v1.xml" ; \ + if [ -e "$$F" ] && ! cmp -s "$$F" $@ ; then \ + echo "WARNING: $$F and $@ differ" >&2 ; \ + fi +$(srcdir)/$(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1-client-protocol.h: \ +$(srcdir)/$(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1.xml + wayland-scanner client-header < $< > $@ +$(srcdir)/$(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1-protocol.c: \ +$(srcdir)/$(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1.xml + wayland-scanner private-code < $< > $@ +$(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1-protocol.o: \ +$(srcdir)/$(WAYLAND_PROTO)/wlr-output-power-management-unstable-v1-protocol.c + $(CC) -c $(CC_ALL) $< -o $@ + +# "kde-dpms" for wayland-idle.c +# "apt install plasma-wayland-protocols" to get the system XML file. +# +$(srcdir)/$(WAYLAND_PROTO)/dpms.xml:: + @\ + F="$(WAYLAND_DATADIR)/plasma-wayland-protocols/dpms.xml" ; \ + if [ -e "$$F" ] && ! cmp -s "$$F" $@ ; then \ + echo "WARNING: $$F and $@ differ" >&2 ; \ + fi +$(srcdir)/$(WAYLAND_PROTO)/dpms-client-protocol.h: \ +$(srcdir)/$(WAYLAND_PROTO)/dpms.xml + wayland-scanner client-header < $< > $@ +$(srcdir)/$(WAYLAND_PROTO)/dpms-protocol.c: \ +$(srcdir)/$(WAYLAND_PROTO)/dpms.xml + wayland-scanner private-code < $< > $@ +$(WAYLAND_PROTO)/dpms-protocol.o: \ +$(srcdir)/$(WAYLAND_PROTO)/dpms-protocol.c + $(CC) -c $(CC_ALL) $< -o $@ + + + ############################################################################## # # Debugging utilities, not built by default @@ -1028,7 +1148,7 @@ TEST_FADE_OBJS = test-fade.o fade.o blurb.o atoms.o clientmsg.o xinput.o \ $(UTILS_BIN)/visual.o $(UTILS_BIN)/resources.o $(UTILS_BIN)/usleep.o \ $(UTILS_BIN)/logo.o $(UTILS_BIN)/minixpm.o $(UTILS_BIN)/xshm.o \ $(UTILS_BIN)/xmu.o $(UTILS_BIN)/aligned_malloc.o \ - $(UTILS_BIN)/screenshot.o + $(UTILS_BIN)/screenshot.o $(GFX_GL_OBJS) test-fade: $(TEST_FADE_OBJS) $(CC) $(LDFLAGS) -o $@ $(TEST_FADE_OBJS) $(GFX_LIBS) @@ -1112,6 +1232,8 @@ fade.o: $(srcdir)/blurb.h fade.o: $(srcdir)/clientmsg.h fade.o: ../config.h fade.o: $(srcdir)/fade.h +fade.o: $(UTILS_SRC)/pow2.h +fade.o: $(UTILS_SRC)/screenshot.h fade.o: $(UTILS_SRC)/usleep.h fade.o: $(UTILS_SRC)/visual.h fade.o: $(UTILS_SRC)/xmu.h @@ -1194,11 +1316,29 @@ test-xkb.o: ../config.h test-yarandom.o: $(srcdir)/blurb.h test-yarandom.o: ../config.h test-yarandom.o: $(UTILS_SRC)/yarandom.h +wayland-dpms.o: $(srcdir)/blurb.h +wayland-dpms.o: ../config.h +wayland-dpms.o: $(srcdir)/types.h +wayland-dpms.o: $(srcdir)/wayland-dpms.h +wayland-dpms.o: $(srcdir)/wayland-dpyI.h +wayland-dpms.o: $(srcdir)/wayland-dpy.h +wayland-dpms.o: $(srcdir)/wayland-protocols/dpms-client-protocol.h +wayland-dpms.o: $(srcdir)/wayland-protocols/wlr-output-power-management-unstable-v1-client-protocol.h +wayland-dpy.o: $(srcdir)/blurb.h +wayland-dpy.o: $(srcdir)/blurb.h +wayland-dpy.o: ../config.h +wayland-dpy.o: ../config.h +wayland-dpy.o: $(srcdir)/wayland-dpyI.h +wayland-dpy.o: $(srcdir)/wayland-dpyI.h +wayland-dpy.o: $(srcdir)/wayland-dpy.h +wayland-dpy.o: $(srcdir)/wayland-dpy.h wayland-idle.o: $(srcdir)/blurb.h wayland-idle.o: ../config.h -wayland-idle.o: $(srcdir)/ext-idle-notify-v1-client-protocol.h -wayland-idle.o: $(srcdir)/idle-client-protocol.h +wayland-idle.o: $(srcdir)/wayland-dpyI.h +wayland-idle.o: $(srcdir)/wayland-dpy.h wayland-idle.o: $(srcdir)/wayland-idle.h +wayland-idle.o: $(srcdir)/wayland-protocols/ext-idle-notify-v1-client-protocol.h +wayland-idle.o: $(srcdir)/wayland-protocols/idle-client-protocol.h windows.o: $(srcdir)/atoms.h windows.o: $(srcdir)/blurb.h windows.o: ../config.h diff --git a/driver/XScreenSaver.ad.in b/driver/XScreenSaver.ad.in index 08b9699e..6abaef22 100644 --- a/driver/XScreenSaver.ad.in +++ b/driver/XScreenSaver.ad.in @@ -4,8 +4,8 @@ ! a screen saver and locker for the X window system ! by Jamie Zawinski ! -! version 6.11 -! 01-Jul-2025 +! version 6.12 +! 07-Jul-2025 ! ! See "man xscreensaver" for more info. The latest version is always ! available at https://www.jwz.org/xscreensaver/ diff --git a/driver/demo-Gtk.c b/driver/demo-Gtk.c index 6ff4ecd6..6f0727da 100644 --- a/driver/demo-Gtk.c +++ b/driver/demo-Gtk.c @@ -69,6 +69,7 @@ #include "blurb.h" #include "xscreensaver-intl.h" #include "version.h" + #include "types.h" #include "resources.h" /* for parse_time() */ #include "remote.h" /* for xscreensaver_command() */ @@ -80,12 +81,13 @@ #include "screenshot.h" #include "xmu.h" +#include "demo-Gtk-conf.h" + #ifdef HAVE_WAYLAND # include "wayland-idle.h" +# include "wayland-dpms.h" #endif -#include "demo-Gtk-conf.h" - /* from exec.c */ extern void exec_command (const char *shell, const char *command, int nice); @@ -125,6 +127,12 @@ typedef struct { Pixmap screenshot; Visual *gl_visual; +# ifdef HAVE_WAYLAND + wayland_dpy *wayland_dpy; + wayland_idle *wayland_idle; + wayland_dpms *wayland_dpms; +# endif + conf_data *cdata; /* private data for per-hack configuration */ Bool debug_p; /* whether to print diagnostics */ @@ -132,6 +140,7 @@ typedef struct { Bool flushing_p; /* flag for breaking recursion loops */ Bool saving_p; /* flag for breaking recursion loops */ Bool dpms_supported_p; /* Whether XDPMS is available */ + Bool dpms_partial_p; /* Whether DPMS only supports "Off" */ Bool grabbing_supported_p; /* Whether "Grab Desktop" and "Fade" work */ char *desired_preview_cmd; /* subprocess we intend to run */ @@ -1513,7 +1522,7 @@ flush_dialog_changes_and_save (state *s) if (changed) { if (s->dpy) - sync_server_dpms_settings (s->dpy, p); + sync_server_dpms_settings_1 (s->dpy, p); demo_write_init_file (s, p); /* Tell the xscreensaver daemon to wake up and reload the init file, @@ -1602,8 +1611,12 @@ dpms_sanity_cb (GtkWidget *widget, gpointer user_data) (double) ((LOWER) + 59) / (60 * 1000)) MINUTES (standby, timeout, dpms_standby_spinbutton); MINUTES (suspend, standby, dpms_suspend_spinbutton); - MINUTES (off, standby, dpms_off_spinbutton); - MINUTES (off, suspend, dpms_off_spinbutton); + if (!s->dpms_partial_p) + { + /* Since standby and suspend are not editable, ignore them. */ + MINUTES (off, standby, dpms_off_spinbutton); + MINUTES (off, suspend, dpms_off_spinbutton); + } # undef MINUTES return GDK_EVENT_PROPAGATE; @@ -2564,6 +2577,7 @@ populate_prefs_page (state *s) saver_preferences *p = &s->prefs; Bool can_lock_p = TRUE; + Bool dpms_full_p; # ifdef NO_LOCKING can_lock_p = FALSE; @@ -2610,16 +2624,14 @@ populate_prefs_page (state *s) # define TOGGLE_ACTIVE(NAME,ACTIVEP) \ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (win->NAME), (ACTIVEP)) - TOGGLE_ACTIVE (lock_button, p->lock_p); - TOGGLE_ACTIVE (dpms_button, p->dpms_enabled_p && s->dpms_supported_p); - TOGGLE_ACTIVE (dpms_quickoff_button, (p->dpms_quickoff_p && - s->dpms_supported_p)); - TOGGLE_ACTIVE (grab_desk_button, (p->grab_desktop_p && - s->grabbing_supported_p)); - TOGGLE_ACTIVE (grab_video_button, p->grab_video_p); - TOGGLE_ACTIVE (grab_image_button, p->random_image_p); - TOGGLE_ACTIVE (fade_button, p->fade_p && s->grabbing_supported_p); - TOGGLE_ACTIVE (unfade_button, p->unfade_p && s->grabbing_supported_p); + TOGGLE_ACTIVE (lock_button, p->lock_p); + TOGGLE_ACTIVE (dpms_button, p->dpms_enabled_p); + TOGGLE_ACTIVE (dpms_quickoff_button, p->dpms_quickoff_p); + TOGGLE_ACTIVE (grab_desk_button, p->grab_desktop_p); + TOGGLE_ACTIVE (grab_video_button, p->grab_video_p); + TOGGLE_ACTIVE (grab_image_button, p->random_image_p); + TOGGLE_ACTIVE (fade_button, p->fade_p); + TOGGLE_ACTIVE (unfade_button, p->unfade_p); switch (p->tmode) { @@ -2744,16 +2756,17 @@ populate_prefs_page (state *s) /* DPMS */ + dpms_full_p = s->dpms_supported_p && !s->dpms_partial_p; SENSITIZE (dpms_button, s->dpms_supported_p); - SENSITIZE (dpms_standby_label, s->dpms_supported_p && p->dpms_enabled_p); - SENSITIZE (dpms_standby_mlabel, s->dpms_supported_p && p->dpms_enabled_p); - SENSITIZE (dpms_standby_spinbutton,s->dpms_supported_p && p->dpms_enabled_p); - SENSITIZE (dpms_suspend_label, s->dpms_supported_p && p->dpms_enabled_p); - SENSITIZE (dpms_suspend_mlabel, s->dpms_supported_p && p->dpms_enabled_p); - SENSITIZE (dpms_suspend_spinbutton,s->dpms_supported_p && p->dpms_enabled_p); - SENSITIZE (dpms_off_label, s->dpms_supported_p && p->dpms_enabled_p); - SENSITIZE (dpms_off_mlabel, s->dpms_supported_p && p->dpms_enabled_p); - SENSITIZE (dpms_off_spinbutton, s->dpms_supported_p && p->dpms_enabled_p); + SENSITIZE (dpms_standby_label, p->dpms_enabled_p && dpms_full_p); + SENSITIZE (dpms_standby_mlabel, p->dpms_enabled_p && dpms_full_p); + SENSITIZE (dpms_standby_spinbutton,p->dpms_enabled_p && dpms_full_p); + SENSITIZE (dpms_suspend_label, p->dpms_enabled_p && dpms_full_p); + SENSITIZE (dpms_suspend_mlabel, p->dpms_enabled_p && dpms_full_p); + SENSITIZE (dpms_suspend_spinbutton,p->dpms_enabled_p && dpms_full_p); + SENSITIZE (dpms_off_label, p->dpms_enabled_p && s->dpms_supported_p); + SENSITIZE (dpms_off_mlabel, p->dpms_enabled_p && s->dpms_supported_p); + SENSITIZE (dpms_off_spinbutton, p->dpms_enabled_p && s->dpms_supported_p); SENSITIZE (dpms_quickoff_button, s->dpms_supported_p); /* Fading @@ -4287,40 +4300,31 @@ the_network_is_not_the_computer (gpointer data) if (s->backend != X11_BACKEND) { # ifdef HAVE_WAYLAND - /* Connect to the Wayland server in the same way that the XScreenSaver - daemon will, and if we are in a state where the daemon won't work - properly, pop up a dialog box explaining why. + /* If we are in a state where the daemon won't work properly, pop up a + dialog box explaining why. */ - const char *wayland_err = 0; - wayland_state *wayland = wayland_idle_init (NULL, NULL, &wayland_err); - - if (s->debug_p && wayland_err) - fprintf (stderr, "%s: wayland: %s\n", blurb(), wayland_err); - - if (wayland) /* Connected to Wayland, have necessary extensions. */ + if (s->wayland_idle) + ; /* Connected to Wayland and can detect activity. */ + else if (s->wayland_dpy) { - wayland_idle_free (wayland); + /* Connected but the necessary extensions are missing. */ + warning_dialog (s->window, _("Warning"), + _("Wayland error: idle detection is impossible. " + "The XScreenSaver daemon will not work.\n")); } - else if (wayland_err && !strcmp (wayland_err, "connection failed")) + else if (getenv ("WAYLAND_DISPLAY") || getenv ("WAYLAND_SOCKET")) { - if (getenv ("WAYLAND_DISPLAY") || getenv ("WAYLAND_SOCKET")) - { - warning_dialog (s->window, _("Warning"), - _("Unable to connect to the Wayland server. " - "The XScreenSaver daemon will not work.\n")); - } - /* Otherwise, presumably running under real X11. */ + /* Running under Wayland, but unable to connect. */ + warning_dialog (s->window, _("Warning"), + _("Unable to connect to the Wayland server. " + "The XScreenSaver daemon will not work.\n")); } - else if (wayland_err) + else { - /* Connected but the necessary extensions are missing. */ - char msg [1024]; - sprintf (msg, - _("Wayland error:\n\n" - "%.100s\n\n" - "The XScreenSaver daemon will not work.\n"), - wayland_err); - warning_dialog (s->window, _("Warning"), msg); + if (verbose_p) + fprintf (stderr, + "%s: wayland: connection failed; assuming real X11\n", + blurb()); } # else /* !HAVE_WAYLAND */ if (s->debug_p) @@ -5134,11 +5138,35 @@ xscreensaver_window_realize (GtkWidget *self, gpointer user_data) # endif } +# ifdef HAVE_WAYLAND + /* Connect to the Wayland server in the same way that xscreensaver + and xscreensaver-gfx will, to see if blanking and DPMS will work. + */ + s->wayland_dpy = wayland_dpy_connect(); + s->wayland_idle = wayland_idle_init (s->wayland_dpy, NULL, NULL); + s->wayland_dpms = wayland_dpms_init (s->wayland_dpy); +# endif /* HAVE_WAYLAND */ + s->multi_screen_p = multi_screen_p (s->dpy); /* Let's see if the server supports DPMS. */ s->dpms_supported_p = FALSE; + s->dpms_partial_p = TRUE; + +# ifdef HAVE_WAYLAND + if (s->wayland_dpms) + { + s->dpms_supported_p = TRUE; + s->dpms_partial_p = TRUE; + } + else if (s->wayland_dpy) + { + s->dpms_supported_p = FALSE; + } + else +# endif /* HAVE_WAYLAND */ + # ifdef HAVE_DPMS_EXTENSION { int op = 0, event = 0, error = 0; @@ -5169,12 +5197,11 @@ xscreensaver_window_realize (GtkWidget *self, gpointer user_data) { const char *prog = "grim"; char *desk = getenv ("XDG_CURRENT_DESKTOP"); -fprintf(stderr,"##A %s\n", desk); if (desk && (strcasestr (desk, "GNOME") || - strcasestr (desk, "KDE"))) + strcasestr (desk, "KDE") || + strcasestr (desk, "plasma"))) { -fprintf(stderr,"##B %s\n", desk); s->grabbing_supported_p = False; if (s->debug_p) fprintf (stderr, @@ -5183,7 +5210,6 @@ fprintf(stderr,"##B %s\n", desk); } else if (! on_path_p (prog)) { -fprintf(stderr,"##C %s\n", desk); s->grabbing_supported_p = False; if (s->debug_p) fprintf (stderr, diff --git a/driver/dialog.c b/driver/dialog.c index 4a258056..7b433674 100644 --- a/driver/dialog.c +++ b/driver/dialog.c @@ -2179,12 +2179,12 @@ handle_keypress (window_state *ws, XKeyEvent *event, Bool filter_p) Status s = 0; KeySym keysym2 = 0; int size2 = Xutf8LookupString (ws->ic, (XKeyPressedEvent *) event, - decoded2, sizeof(decoded2)-1 - , &keysym2, &s); + decoded2, sizeof(decoded2)-1, + &keysym2, &s); decoded2[size2] = 0; switch (s) { - case XLookupChars: /* Set 'c2' to a UTF8 string */ + case XLookupChars: /* Set 'decoded2' to a UTF8 string */ if (*decoded2) { strcpy ((char *) decoded, (char *) decoded2); @@ -2205,7 +2205,7 @@ handle_keypress (window_state *ws, XKeyEvent *event, Bool filter_p) } break; case XLookupNone: /* No input yet */ - case XBufferOverflow: /* 'c2' was too small */ + case XBufferOverflow: /* 'decoded2' was too small */ break; default: abort(); diff --git a/driver/dpms.c b/driver/dpms.c index 613ed06e..2a23221b 100644 --- a/driver/dpms.c +++ b/driver/dpms.c @@ -21,6 +21,10 @@ #include "xscreensaver.h" +#ifdef HAVE_WAYLAND +# include "wayland-dpms.h" +#endif + /* Disable the X11 built-in screen saver. This is not directly related to DPMS, but it does need to be prevented from fighting with us. */ @@ -52,15 +56,25 @@ disable_builtin_saver (Display *dpy) #ifndef HAVE_DPMS_EXTENSION /* almost the whole file */ void -sync_server_dpms_settings (Display *dpy, struct saver_preferences *p) +sync_server_dpms_settings (saver_info *si) +{ + sync_server_dpms_settings_1 (si->dpy, &si->prefs); +} + +void +sync_server_dpms_settings_1 (Display *dpy, struct saver_preferences *p) { disable_builtin_saver (dpy); if (p->verbose_p) fprintf (stderr, "%s: DPMS not supported at compile time\n", blurb()); } -Bool monitor_powered_on_p (Display *dpy) +Bool monitor_powered_on_p (saver_info *si) { +# ifdef HAVE_WAYLAND + if (si->wayland_dpms) + return wayland_monitor_powered_on_p (si->wayland_dpms); +# endif if (verbose_p > 1) fprintf (stderr, "%s: DPMS disabled at compile time, assuming monitor on\n", @@ -70,6 +84,11 @@ Bool monitor_powered_on_p (Display *dpy) void monitor_power_on (saver_info *si, Bool on_p) { +# ifdef HAVE_WAYLAND + if (si->wayland_dpms) + wayland_monitor_power_on (si->wayland_dpms, on_p); + else +# endif if (verbose_p > 1) fprintf (stderr, "%s: DPMS disabled at compile time, not turning monitor %s\n", @@ -94,7 +113,32 @@ ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error) void -sync_server_dpms_settings (Display *dpy, struct saver_preferences *p) +sync_server_dpms_settings (saver_info *si) +{ +# ifdef HAVE_WAYLAND /* The XDPMS extension is definitely not available */ + if (si->wayland_dpy) + { + disable_builtin_saver (si->dpy); + return; + } +# endif /* HAVE_WAYLAND */ + + /* If the monitor is currently powered off, defer any changes until we are + next called while it is powered on. Making changes to the DPMS settings + can have the side-effect of powering the monitor back on. + */ + if (! monitor_powered_on_p (si)) + { + if (verbose_p > 1) + fprintf (stderr, "%s: DPMS: monitor off, skipping sync\n", blurb()); + return; + } + + sync_server_dpms_settings_1 (si->dpy, &si->prefs); +} + +void +sync_server_dpms_settings_1 (Display *dpy, struct saver_preferences *p) { int event = 0, error = 0; BOOL o_enabled = False; @@ -112,17 +156,6 @@ sync_server_dpms_settings (Display *dpy, struct saver_preferences *p) Bool verbose_p = p->verbose_p; static Bool warned_p = False; - /* If the monitor is currently powered off, defer any changes until we are - next called while it is powered on. Making changes to the DPMS settings - can have the side-effect of powering the monitor back on. - */ - if (! monitor_powered_on_p (dpy)) - { - if (verbose_p > 1) - fprintf (stderr, "%s: DPMS: monitor off, skipping sync\n", blurb()); - return; - } - changed_p = disable_builtin_saver (dpy); if (dpms_quickoff_p && !off_secs) @@ -241,14 +274,23 @@ sync_server_dpms_settings (Display *dpy, struct saver_preferences *p) } Bool -monitor_powered_on_p (Display *dpy) +monitor_powered_on_p (saver_info *si) { Bool result; int event_number, error_number; BOOL onoff = False; CARD16 state; - if (!DPMSQueryExtension(dpy, &event_number, &error_number)) +# ifdef HAVE_WAYLAND + + if (si->wayland_dpms) + return wayland_monitor_powered_on_p (si->wayland_dpms); + else if (si->wayland_dpy) + return True; /* Wayland server does not support DPMS */ + +# endif /* HAVE_WAYLAND */ + + if (!DPMSQueryExtension(si->dpy, &event_number, &error_number)) { /* Server doesn't know -- assume the monitor is on. */ if (verbose_p > 1) @@ -257,7 +299,7 @@ monitor_powered_on_p (Display *dpy) result = True; } - else if (!DPMSCapable(dpy)) + else if (!DPMSCapable(si->dpy)) { /* Server says the monitor doesn't do power management -- so it's on. */ if (verbose_p > 1) @@ -268,7 +310,7 @@ monitor_powered_on_p (Display *dpy) else { - DPMSInfo(dpy, &state, &onoff); + DPMSInfo(si->dpy, &state, &onoff); if (!onoff) { /* Server says DPMS is disabled -- so the monitor is on. */ @@ -301,11 +343,29 @@ void monitor_power_on (saver_info *si, Bool on_p) { Bool verbose_p = si->prefs.verbose_p; - if ((!!on_p) != monitor_powered_on_p (si->dpy)) + if ((!!on_p) != monitor_powered_on_p (si)) { XErrorHandler old_handler; int event_number, error_number; static Bool warned_p = False; + +# ifdef HAVE_WAYLAND + if (si->wayland_dpms) + { + wayland_monitor_power_on (si->wayland_dpms, on_p); + return; + } + else if (si->wayland_dpy) + { + if (verbose_p > 1 || (verbose_p && !warned_p)) + fprintf (stderr, + "%s: wayland: unable to power %s monitor\n", + blurb(), (on_p ? "on" : "off")); + warned_p = True; + return; + } +# endif /* HAVE_WAYLAND */ + if (!DPMSQueryExtension(si->dpy, &event_number, &error_number) || !DPMSCapable(si->dpy)) { @@ -340,7 +400,7 @@ monitor_power_on (saver_info *si, Bool on_p) if (verbose_p > 1 && error_handler_hit_p) fprintf (stderr, "%s: DPMSForceLevel got an X11 error\n", blurb()); - if ((!!on_p) != monitor_powered_on_p (si->dpy)) /* double-check */ + if ((!!on_p) != monitor_powered_on_p (si)) /* double-check */ fprintf (stderr, "%s: DPMSForceLevel(dpy, %s) did not change monitor power state\n", blurb(), @@ -355,31 +415,58 @@ monitor_power_on (saver_info *si, Bool on_p) /* Force the server DPMS state to be what the wall clock says it should be. */ void -brute_force_dpms (Display *dpy, struct saver_preferences *p, - time_t activity_time) +brute_force_dpms (saver_info *si, time_t activity_time) { + Display *dpy = si->dpy; + saver_preferences *p = &si->prefs; XErrorHandler old_handler; int event_number, error_number; BOOL onoff = False; CARD16 state; CARD16 target; time_t age = time ((time_t *) 0) - activity_time; + Bool enabled_p = (p->dpms_enabled_p && p->mode != DONT_BLANK); if (activity_time == 0) /* Auth dialog is visible */ target = DPMSModeOn; else if (p->mode == BLANK_ONLY && p->dpms_quickoff_p) target = DPMSModeOff; - else if (p->dpms_off && age >= (p->dpms_off / 1000)) + else if (enabled_p && p->dpms_off && age >= (p->dpms_off / 1000)) target = DPMSModeOff; - else if (p->dpms_suspend && age >= (p->dpms_suspend / 1000)) + else if (enabled_p && p->dpms_suspend && age >= (p->dpms_suspend / 1000)) target = DPMSModeSuspend; - else if (p->dpms_standby && age >= (p->dpms_standby / 1000)) + else if (enabled_p && p->dpms_standby && age >= (p->dpms_standby / 1000)) target = DPMSModeStandby; else /* We have no opinion about the desired DPMS state, so if it is off, leave it off. It may have been powered down manually with xset. */ return; +# ifdef HAVE_WAYLAND + { + Bool have = monitor_powered_on_p (si); + Bool want = (target == DPMSModeOn); + + if (have == want) + ; + else if (si->wayland_dpms) + { + wayland_monitor_power_on (si->wayland_dpms, want); + if (p->verbose_p) + fprintf (stderr, "%s: powered %s monitor\n", blurb(), + (want ? "on" : "off")); + return; + } + else if (si->wayland_dpy) + { + if (verbose_p) + fprintf (stderr, "%s: wayland: unable to power %s monitor\n", + blurb(), (want ? "on" : "off")); + return; + } + } +# endif /* HAVE_WAYLAND */ + if (!DPMSQueryExtension (dpy, &event_number, &error_number) || !DPMSCapable (dpy)) return; diff --git a/driver/fade.c b/driver/fade.c index c3d2df75..c2898940 100644 --- a/driver/fade.c +++ b/driver/fade.c @@ -37,13 +37,10 @@ by running "xscreensaver-getimage" which in turn runs "grim", if it is installed, which it might not be. - In summary, everything is terrible because X11 doesn't support alpha. - + - OpenGL: This is like XSHM but uses OpenGL for rendering. Faster, but + same screenshot- and Wayland-related downsides. - Another thing to consider is to implement fading with OpenGL: put the - screen shot in a textured quad and just change its color for fading. - That should be efficient on both X11 and Wayland. However it would - require linking the OpenGL libraries into "xscreensaver-gfx". + In summary, everything is terrible because X11 doesn't support alpha. The fade process goes like this: @@ -93,14 +90,30 @@ # include #endif /* !HAVE_JWXYZ */ +#ifdef USE_GL +# include +# include +# ifdef HAVE_EGL +# include +# include +# else +# include +# endif +#endif /* USE_GL */ + #include "blurb.h" #include "visual.h" +#ifdef USE_GL +#include "visual-gl.h" +#endif #include "usleep.h" #include "fade.h" #include "xshm.h" #include "atoms.h" #include "clientmsg.h" #include "xmu.h" +#include "pow2.h" +#include "screenshot.h" /* Since gamma fading doesn't work on the Raspberry Pi, probably the single most popular desktop Linux system these days, let's not use this fade @@ -133,9 +146,6 @@ typedef struct { } fade_state; -/* #### There's a bunch of duplicated code in the back half of the - four _fade and _whack functions that could probably be combined. - */ #ifdef HAVE_SGI_VC_EXTENSION static int sgi_gamma_fade (XtAppContext, Display *, Window *wins, int count, double secs, Bool out_p); @@ -1516,21 +1526,36 @@ randr_whack_gamma (Display *dpy, int screen, randr_gamma_info *info, /**************************************************************************** - XSHM screen-shot fading + XSHM or OpenGL screenshot fading + This module does one or the other, depending on USE_GL ****************************************************************************/ typedef struct { - GC gc; Window window; + XImage *src; Pixmap screenshot; - XImage *src, *intermediate; +# ifndef USE_GL + XImage *intermediate; + GC gc; +# else /* USE_GL */ + GLuint texid; + GLfloat texw, texh; +# ifdef HAVE_EGL + egl_data *glx_context; +# else + GLXContext glx_context; +# endif +# endif /* USE_GL */ } xshm_fade_info; +#ifdef USE_GL +static int opengl_whack (Display *, xshm_fade_info *, float ratio); +#else static int xshm_whack (Display *, XShmSegmentInfo *, xshm_fade_info *, float ratio); - +#endif /* Grab a screenshot and return it. It will be the size and extent of the given window. @@ -1544,6 +1569,7 @@ xshm_screenshot_grab (Display *dpy, Window window, XWindowAttributes xgwa; Pixmap pixmap = 0; Bool external_p = False; + double start = double_time(); # ifdef HAVE_MACOS_X11 external_p = True; @@ -1551,6 +1577,12 @@ xshm_screenshot_grab (Display *dpy, Window window, external_p = getenv ("WAYLAND_DISPLAY") || getenv ("WAYLAND_SOCKET"); # endif + if (from_desktop_p) + { + Pixmap p = screenshot_load (dpy, window, verbose_p); + if (p) return p; + } + XGetWindowAttributes (dpy, window, &xgwa); pixmap = XCreatePixmap (dpy, window, xgwa.width, xgwa.height, xgwa.depth); if (!pixmap) return None; @@ -1640,10 +1672,77 @@ xshm_screenshot_grab (Display *dpy, Window window, } # endif /* HAVE_MACOS_X11 */ + { + double elapsed = double_time() - start; + char late[100]; + if (elapsed >= 0.75) + sprintf (late, " -- took %.1f seconds", elapsed); + else + *late = 0; + + if (verbose_p || !pixmap || *late) + fprintf (stderr, "%s: %s screenshot 0x%lx %dx%d" + " for window 0x%lx%s\n", blurb(), + (pixmap ? "saved" : "failed to save"), + (unsigned long) pixmap, xgwa.width, xgwa.height, + (unsigned long) window, + late); + } + return pixmap; } +#ifdef USE_GL +static void +opengl_make_current (Display *dpy, xshm_fade_info *info) +{ +# ifdef HAVE_EGL + egl_data *d = info->glx_context; + if (! eglMakeCurrent (d->egl_display, d->egl_surface, d->egl_surface, + d->egl_context)) + abort(); +# else /* !HAVE_EGL */ + glXMakeCurrent (dpy, info->window, info->glx_context); +# endif /* !HAVE_EGL */ + +} + +/* report a GL error. */ +static Bool +check_gl_error (const char *type) +{ + char buf[100]; + GLenum i; + const char *e; + switch ((i = glGetError())) { + case GL_NO_ERROR: return False; + case GL_INVALID_ENUM: e = "invalid enum"; break; + case GL_INVALID_VALUE: e = "invalid value"; break; + case GL_INVALID_OPERATION: e = "invalid operation"; break; + case GL_STACK_OVERFLOW: e = "stack overflow"; break; + case GL_STACK_UNDERFLOW: e = "stack underflow"; break; + case GL_OUT_OF_MEMORY: e = "out of memory"; break; +#ifdef GL_INVALID_FRAMEBUFFER_OPERATION + case GL_INVALID_FRAMEBUFFER_OPERATION: + e = "invalid framebuffer operation"; + break; +#endif +#ifdef GL_TABLE_TOO_LARGE_EXT + case GL_TABLE_TOO_LARGE_EXT: e = "table too large"; break; +#endif +#ifdef GL_TEXTURE_TOO_LARGE_EXT + case GL_TEXTURE_TOO_LARGE_EXT: e = "texture too large"; break; +#endif + default: + e = buf; sprintf (buf, "unknown error %d", (int) i); break; + } + fprintf (stderr, "%s: %s error: %s\n", progname, type, e); + return True; +} +#endif /* USE_GL */ + + /* Returns: 0: faded normally 1: canceled by user activity @@ -1657,7 +1756,9 @@ xshm_fade (XtAppContext app, Display *dpy, int screen; int status = -1; xshm_fade_info *info = 0; +# ifndef USE_GL XShmSegmentInfo shm_info; +# endif Window saver_window = 0; XErrorHandler old_handler = 0; @@ -1665,9 +1766,13 @@ xshm_fade (XtAppContext app, Display *dpy, old_handler = XSetErrorHandler (ignore_all_errors_ehandler); error_handler_hit_p = False; +# ifdef USE_GL if (verbose_p > 1) - fprintf (stderr, "%s: SHM fade %s\n", - blurb(), (out_p ? "out" : "in")); + fprintf (stderr, "%s: GL fade %s\n", blurb(), (out_p ? "out" : "in")); +# else /* !USE_GL */ + if (verbose_p > 1) + fprintf (stderr, "%s: SHM fade %s\n", blurb(), (out_p ? "out" : "in")); +# endif /* !USE_GL */ info = (xshm_fade_info *) calloc(nwindows, sizeof(*info)); if (!info) goto FAIL; @@ -1684,22 +1789,45 @@ xshm_fade (XtAppContext app, Display *dpy, { XWindowAttributes xgwa; Window root; - XGCValues gcv; - unsigned long attrmask = 0; + Visual *visual; XSetWindowAttributes attrs; + unsigned long attrmask = 0; +# ifndef USE_GL + XGCValues gcv; +# endif /* USE_GL */ XGetWindowAttributes (dpy, saver_windows[screen], &xgwa); root = RootWindowOfScreen (xgwa.screen); +# ifdef USE_GL + visual = get_gl_visual (xgwa.screen); +# else /* !USE_GL */ + visual = xgwa.visual; +# endif /* !USE_GL */ +# ifdef USE_GL info[screen].src = - create_xshm_image (dpy, xgwa.visual, xgwa.depth, + XCreateImage (dpy, visual, 32, ZPixmap, 0, NULL, + xgwa.width, xgwa.height, 32, 0); + if (!info[screen].src) goto FAIL; + info[screen].src->data = (char *) + malloc (info[screen].src->height * info[screen].src->bytes_per_line); + info[screen].src->bitmap_bit_order = + info[screen].src->byte_order = MSBFirst; + + while (glGetError() != GL_NO_ERROR) + ; /* Flush */ + +# else /* !USE_GL */ + info[screen].src = + create_xshm_image (dpy, visual, xgwa.depth, ZPixmap, &shm_info, xgwa.width, xgwa.height); if (!info[screen].src) goto FAIL; info[screen].intermediate = - create_xshm_image (dpy, xgwa.visual, xgwa.depth, + create_xshm_image (dpy, visual, xgwa.depth, ZPixmap, &shm_info, xgwa.width, xgwa.height); if (!info[screen].intermediate) goto FAIL; +# endif /* !USE_GL */ if (!out_p) { @@ -1722,12 +1850,82 @@ xshm_fade (XtAppContext app, Display *dpy, info[screen].window = XCreateWindow (dpy, root, xgwa.x, xgwa.y, xgwa.width, xgwa.height, xgwa.border_width, xgwa.depth, - InputOutput, xgwa.visual, + InputOutput, visual, attrmask, &attrs); if (!info[screen].window) goto FAIL; /* XSelectInput (dpy, info[screen].window, KeyPressMask | ButtonPressMask); */ +# ifdef USE_GL + /* Copy the screenshot pixmap to the texture XImage */ + XGetSubImage (dpy, info[screen].screenshot, + 0, 0, xgwa.width, xgwa.height, + ~0L, ZPixmap, info[screen].src, 0, 0); + + /* Convert 0RGB to RGBA */ + { + XImage *ximage = info[screen].src; + int x, y; + for (y = 0; y < ximage->height; y++) + for (x = 0; x < ximage->width; x++) + { + unsigned long p = XGetPixel (ximage, x, y); + unsigned long a = 0xFF; + /* unsigned long a = (p >> 24) & 0xFF; */ + unsigned long r = (p >> 16) & 0xFF; + unsigned long g = (p >> 8) & 0xFF; + unsigned long b = (p >> 0) & 0xFF; + p = (r << 24) | (g << 16) | (b << 8) | (a << 0); + XPutPixel (ximage, x, y, p); + } + } + + /* Connect the window to an OpenGL context */ + info[screen].glx_context = + openGL_context_for_window (xgwa.screen, info[screen].window); + opengl_make_current (dpy, &info[screen]); + if (check_gl_error ("connect")) goto FAIL; + + glEnable (GL_TEXTURE_2D); + glEnable (GL_NORMALIZE); + glGenTextures (1, &info[screen].texid); + glBindTexture (GL_TEXTURE_2D, info[screen].texid); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glPixelStorei (GL_UNPACK_ALIGNMENT, 1); + if (check_gl_error ("bind texture")) goto FAIL; + + { + int tex_width = (GLsizei) to_pow2 (info[screen].src->width); + int tex_height = (GLsizei) to_pow2 (info[screen].src->height); + /* Create power of 2 empty texture */ + glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, 0); + if (check_gl_error ("glTexImage2D")) goto FAIL; + /* Load our non-power-of-2 image data into it. */ + glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, + info[screen].src->width, info[screen].src->height, + GL_RGBA, GL_UNSIGNED_BYTE, info[screen].src->data); + if (check_gl_error ("glTexSubImage2D")) goto FAIL; + info[screen].texw = info[screen].src->width / (GLfloat) tex_width; + info[screen].texh = info[screen].src->height / (GLfloat) tex_height; + } + + glViewport (0, 0, xgwa.width, xgwa.height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho (0, 1, 1, 0, -1, 1); + glMatrixMode (GL_MODELVIEW); + glLoadIdentity(); + glClearColor (0, 0, 0, 1); + glClear (GL_COLOR_BUFFER_BIT); + glFrontFace (GL_CCW); + if (check_gl_error ("GL setup")) goto FAIL; + +# else /* !USE_GL */ /* Copy the screenshot pixmap to the source image */ if (! get_xshm_image (dpy, info[screen].screenshot, info[screen].src, 0, 0, ~0L, &shm_info)) @@ -1735,6 +1933,7 @@ xshm_fade (XtAppContext app, Display *dpy, gcv.function = GXcopy; info[screen].gc = XCreateGC (dpy, info[screen].window, GCFunction, &gcv); +# endif /* !USE_GL */ } /* If we're fading out from the desktop, save our screen shots for later use. @@ -1759,6 +1958,7 @@ xshm_fade (XtAppContext app, Display *dpy, for (screen = 0; screen < nwindows; screen++) { +# ifndef USE_GL if (out_p) /* Copy the screenshot to the fader window */ XSetWindowBackgroundPixmap (dpy, info[screen].window, @@ -1768,6 +1968,7 @@ xshm_fade (XtAppContext app, Display *dpy, XSetWindowBackgroundPixmap (dpy, info[screen].window, None); XSetWindowBackground (dpy, info[screen].window, BlackPixel (dpy, 0)); } +# endif /* USE_GL */ XMapRaised (dpy, info[screen].window); @@ -1799,8 +2000,13 @@ xshm_fade (XtAppContext app, Display *dpy, if (!out_p) ratio = 1-ratio; for (screen = 0; screen < nwindows; screen++) +# ifdef USE_GL + if (opengl_whack (dpy, &info[screen], ratio)) + goto FAIL; +# else /* !USE_GL */ if (xshm_whack (dpy, &shm_info, &info[screen], ratio)) goto FAIL; +# endif /* !USE_GL */ if (error_handler_hit_p) goto FAIL; @@ -1861,14 +2067,23 @@ xshm_fade (XtAppContext app, Display *dpy, { for (screen = 0; screen < nwindows; screen++) { +# ifdef USE_GL + if (info[screen].src) + XDestroyImage (info[screen].src); + if (info[screen].texid) + glDeleteTextures (1, &info[screen].texid); + openGL_destroy_context (dpy, info[screen].glx_context); +# else /* !USE_GL */ if (info[screen].src) destroy_xshm_image (dpy, info[screen].src, &shm_info); if (info[screen].intermediate) destroy_xshm_image (dpy, info[screen].intermediate, &shm_info); - if (info[screen].window) - defer_XDestroyWindow (app, dpy, info[screen].window); if (info[screen].gc) XFreeGC (dpy, info[screen].gc); +# endif /* !USE_GL */ + + if (info[screen].window) + defer_XDestroyWindow (app, dpy, info[screen].window); } free (info); } @@ -1890,13 +2105,58 @@ xshm_fade (XtAppContext app, Display *dpy, if (error_handler_hit_p) status = -1; if (verbose_p > 1 && status) +# ifdef HAVE_GL + fprintf (stderr, "%s: GL fade %s failed\n", + blurb(), (out_p ? "out" : "in")); +# else /* !HAVE_GL */ fprintf (stderr, "%s: SHM fade %s failed\n", blurb(), (out_p ? "out" : "in")); +# endif /* !HAVE_GL */ return status; } +#ifdef USE_GL + +static int +opengl_whack (Display *dpy, xshm_fade_info *info, float ratio) +{ + GLfloat w = info->texw; + GLfloat h = info->texh; + + opengl_make_current (dpy, info); + glBindTexture (GL_TEXTURE_2D, info->texid); + glClear (GL_COLOR_BUFFER_BIT); + + if (ratio < 0) ratio = 0; + if (ratio > 1) ratio = 1; + + glColor3f (ratio, ratio, ratio); + + glBegin (GL_QUADS); + glTexCoord2f (0, 0); glVertex3f (0, 0, 0); + glTexCoord2f (0, h); glVertex3f (0, 1, 0); + glTexCoord2f (w, h); glVertex3f (1, 1, 0); + glTexCoord2f (w, 0); glVertex3f (1, 0, 0); + glEnd(); + glFinish(); + +# ifdef HAVE_EGL + if (! eglSwapBuffers (info->glx_context->egl_display, + info->glx_context->egl_surface)) + return True; +# else + glXSwapBuffers (dpy, info->window); +# endif + + if (check_gl_error ("gl whack")) return True; + return False; +} + + +#else /* !USE_GL */ + static int xshm_whack (Display *dpy, XShmSegmentInfo *shm_info, xshm_fade_info *info, float ratio) @@ -1925,3 +2185,6 @@ xshm_whack (Display *dpy, XShmSegmentInfo *shm_info, XSync (dpy, False); return 0; } + +#endif /* !USE_GL */ + diff --git a/driver/prefsw.c b/driver/prefsw.c index 7fd732bd..8b708c40 100644 --- a/driver/prefsw.c +++ b/driver/prefsw.c @@ -1340,7 +1340,7 @@ stop_the_insanity (saver_preferences *p) p->fade_p = False; if (! p->fade_p) p->unfade_p = False; - /* DPMS settings may be zero, but otherwise, if they < 10 sec or negative, + /* DPMS settings may be zero, but otherwise, if they're < 10 sec or negative, set them to 2 minutes. */ # define THROTTLE(FIELD) \ if (p->FIELD != 0 && ((long) p->FIELD) < 10 * 1000) \ @@ -1360,8 +1360,9 @@ stop_the_insanity (saver_preferences *p) p->FIELD = p->LOWER THROTTLE (dpms_standby, timeout); THROTTLE (dpms_suspend, dpms_standby); - THROTTLE (dpms_off, dpms_standby); - THROTTLE (dpms_off, dpms_suspend); +/* This requires a check for dpms_partial_p which demo-Gtk.c sets. */ +/* THROTTLE (dpms_off, dpms_standby); */ +/* THROTTLE (dpms_off, dpms_suspend); */ #undef THROTTLE if (p->dpms_standby == 0 && /* if *all* are 0, then DPMS is disabled */ diff --git a/driver/subprocs.c b/driver/subprocs.c index f6b70af9..827146a9 100644 --- a/driver/subprocs.c +++ b/driver/subprocs.c @@ -48,6 +48,11 @@ # define _(S) (S) #endif +#if defined(USE_GL) && !defined(HAVE_EGL) +# include /* For GLXContext in visual-gl.h */ +# include +#endif + #include "xscreensaver.h" #include "exec.h" #include "yarandom.h" @@ -55,6 +60,9 @@ #include "atoms.h" #include "screenshot.h" +#ifdef USE_GL +# include "visual-gl.h" +#endif enum job_status { job_running, /* the process is still alive */ @@ -433,7 +441,7 @@ saver_sigterm_handler (int sig) catch_signal (sig, SIG_DFL); /* The first time a signal fires, inform Xt of that so that it will run - xt_signal_handler(). "XtNoticeSignal is the only Intrinsics function + xt_sigterm_handler(). "XtNoticeSignal is the only Intrinsics function that can safely be called from a signal handler". */ if (xt_sigterm_id) XtNoticeSignal (xt_sigterm_id); @@ -498,6 +506,26 @@ xt_sigterm_handler (XtPointer data, XtSignalId *id) abort(); } +#ifdef HAVE_WAYLAND +/* Called when the Wayland socket drops our connection. + We should also die with a SIGPIPE from the XWayland X11 socket, + and also a SIGTERM from xscreensaver, so it's a death race. + */ +static void +gfx_wayland_exit (void *closure) +{ + saver_info *si = (saver_info *) closure; + int i; + si->terminating_p = True; + for (i = 0; i < si->nscreens; i++) + { + saver_screen_info *ssi = &si->screens[i]; + kill_screenhack (ssi); + } + exit (1); +} +#endif /* HAVE_WAYLAND */ + /* SIGCHLD handling. Basically the same deal as SIGTERM. */ @@ -683,6 +711,11 @@ init_sigchld (saver_info *si) xt_sigchld_id = XtAppAddSignal (si->app, xt_sigchld_handler, si); xt_sigterm_id = XtAppAddSignal (si->app, xt_sigterm_handler, si); + +# ifdef HAVE_WAYLAND + if (si->wayland_dpy) + wayland_dpy_atexit (si->wayland_dpy, gfx_wayland_exit, si); +# endif /* HAVE_WAYLAND */ } @@ -845,7 +878,7 @@ spawn_screenhack (saver_screen_info *ssi) saver_preferences *p = &si->prefs; XFlush (si->dpy); - if (!monitor_powered_on_p (si->dpy)) + if (!monitor_powered_on_p (si)) { if (si->prefs.verbose_p) fprintf (stderr, @@ -1159,6 +1192,27 @@ any_screenhacks_running_p (saver_info *si) } +#ifdef USE_GL + +Visual * +get_best_gl_visual (saver_info *si, Screen *screen) +{ + saver_preferences *p = &si->prefs; + Visual *v = get_gl_visual (screen); + if (!v) + fprintf (stderr, "%s: %d: no GL visual!\n", blurb(), + screen_number (screen)); + else if (p->verbose_p) + fprintf (stderr, "%s: %d: GL visual is 0x%X%s\n", + blurb(), screen_number (screen), + (unsigned int) XVisualIDFromVisual (v), + (v == DefaultVisualOfScreen (screen) + ? " (default)" : "")); + return v; +} + +#else /* !USE_GL */ + /* Fork "xscreensaver-gl-visual" and wait for it to print the IDs of the GL visual that should be used on this screen. */ @@ -1330,3 +1384,5 @@ get_best_gl_visual (saver_info *si, Screen *screen) abort(); } + +#endif /* !USE_GL */ diff --git a/driver/types.h b/driver/types.h index 3ddbed67..6e48b682 100644 --- a/driver/types.h +++ b/driver/types.h @@ -12,6 +12,10 @@ #ifndef __XSCREENSAVER_TYPES_H__ #define __XSCREENSAVER_TYPES_H__ +#ifdef HAVE_WAYLAND +# include "wayland-dpy.h" +#endif + typedef struct saver_info saver_info; typedef struct screenhack screenhack; @@ -123,6 +127,12 @@ struct saver_info { char *version; saver_preferences prefs; +# ifdef HAVE_WAYLAND + wayland_dpy *wayland_dpy; + wayland_idle *wayland_idle; + wayland_dpms *wayland_dpms; +# endif /* HAVE_WAYLAND */ + int nscreens; int ssi_count; saver_screen_info *screens; @@ -206,8 +216,9 @@ struct saver_screen_info { /* From dpms.c */ -extern void sync_server_dpms_settings (Display *, struct saver_preferences *); -extern void brute_force_dpms (Display *, struct saver_preferences *, time_t); +extern void sync_server_dpms_settings (saver_info *); +extern void sync_server_dpms_settings_1 (Display *, struct saver_preferences *); +extern void brute_force_dpms (saver_info *, time_t); const char *init_file_name (void); diff --git a/driver/wayland-dpms.c b/driver/wayland-dpms.c new file mode 100644 index 00000000..536a86b2 --- /dev/null +++ b/driver/wayland-dpms.c @@ -0,0 +1,411 @@ +/* xscreensaver, Copyright © 2025 Jamie Zawinski + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. No representations are made about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * Detecting and changing whether monitors are powered on under Wayland. + * What was ~50 lines of code under X11 (with error checking!) is now 360+. + * Wayland is incredible (pej., obs.) + * + * This code uses either the "wlr-output-power-management-unstable-v1" or + * "org-kde-kwin-dpms-manager" protocol. Without one of these, XScreenSaver + * cannot power down the screen after the configured timeout, and cannot know + * to stop running hacks on a powered-down screen. + * + * These protocols are, of course, not supported by GNOME. As is traditional. + * + * Also! Under "wlr", the monitors are not automatically turned back on when + * there is user activity. So if this program crashes with the screens off, + * good luck getting them to turn back on. KDE does the right thing. + * + * GNOME does the following crap, because they have never seen a Wayland + * protocol that they didn't think should be replaced with DBus instead: + * + * busctl --user set-property \ + * org.gnome.Mutter.DisplayConfig \ + * /org/gnome/Mutter/DisplayConfig \ + * org.gnome.Mutter.DisplayConfig PowerSaveMode \ + * i \ + * [ "0" or "1" ] + * + * So that's nice. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#ifdef HAVE_UNISTD_H +# include +#endif + +#include +#include +#include + +#include +#include + +#include +#include +#include "wayland-protocols/wlr-output-power-management-unstable-v1-client-protocol.h" +#include "wayland-protocols/dpms-client-protocol.h" + +#include "wayland-dpyI.h" +#include "wayland-dpms.h" +#include "types.h" +#include "blurb.h" + +struct wayland_dpms { + wayland_dpy *parent; + struct wl_registry *reg; + struct zwlr_output_power_manager_v1 *wlr_mgr; + struct org_kde_kwin_dpms_manager *kde_mgr; + struct wl_list outputs; +}; + +typedef struct dpms_output { + struct wl_list link; + + struct wl_output *wl_output; + char *name; + Bool wl_done; /* wl_output: all info about this output has been sent */ + + struct zwlr_output_power_v1 *wlr_out; + enum zwlr_output_power_v1_mode wlr_mode; + Bool wlr_failed; /* I have no idea what this means */ + + struct org_kde_kwin_dpms *kde_out; + enum org_kde_kwin_dpms_mode kde_mode; + Bool kde_done; + +} dpms_output; + + +static void +wl_handle_name (void *data, struct wl_output *wl_output, const char *name) +{ + dpms_output *out = (dpms_output *) data; + if (out->name) free (out->name); + out->name = strdup (name); + if (verbose_p > 2) + fprintf (stderr, "%s: wayland: dpms: output %s\n", blurb(), name); +} + +/* Even though we don't use any of these callback functions, they have to + be included in the listener or it crashes. How very. */ + +static void +wl_handle_geometry (void *data, struct wl_output *wl_output, + int32_t x, int32_t y, + int32_t physical_width, int32_t physical_height, + int32_t subpixel, const char *make, const char* model, + int32_t transform) +{ +} + +static void +wl_handle_mode (void *data, struct wl_output *wl_output, + uint32_t flags, int32_t width, int32_t height, int32_t refresh) +{ +} + +static void +wl_handle_scale (void *data, struct wl_output *wl_output, int32_t scale) +{ +} + +static void +wl_handle_description (void *data, struct wl_output *wl_output, + const char *desc) +{ +} + +static void +wl_handle_done (void *data, struct wl_output *wl_output) +{ + dpms_output *out = (dpms_output *) data; + out->wl_done = True; +} + + +static void +wlr_handle_mode (void *data, + struct zwlr_output_power_v1 *wlr_output_power, + enum zwlr_output_power_v1_mode mode) +{ + dpms_output *out = (dpms_output *) data; + out->wlr_mode = mode; + if (verbose_p > 2) + fprintf (stderr, "%s: wayland: dpms: output %s is %s\n", blurb(), + out->name, + (out->wlr_mode == ZWLR_OUTPUT_POWER_V1_MODE_ON ? "on" : "off")); +} + +static void +wlr_handle_failed (void *data, struct zwlr_output_power_v1 *wlr_output_power) +{ + dpms_output *out = (dpms_output *) data; + out->wlr_failed = True; + if (verbose_p > 2) + fprintf (stderr, "%s: wayland: dpms: output %s is FAILED?\n", blurb(), + out->name); +} + + +static void +kde_handle_supported (void *data, struct org_kde_kwin_dpms *dpms, + uint32_t supported) +{ +} + +static void +kde_handle_mode (void *data, struct org_kde_kwin_dpms *dpms, uint32_t mode) +{ + dpms_output *out = (dpms_output *) data; + out->kde_mode = mode; + if (verbose_p > 2) + fprintf (stderr, "%s: wayland: dpms: output %s is %s\n", blurb(), + out->name, + (out->kde_mode == ORG_KDE_KWIN_DPMS_MODE_ON ? "on" : + out->kde_mode == ORG_KDE_KWIN_DPMS_MODE_STANDBY ? "standby" : + out->kde_mode == ORG_KDE_KWIN_DPMS_MODE_SUSPEND ? "suspend" : + out->kde_mode == ORG_KDE_KWIN_DPMS_MODE_OFF ? "off" : + "???")); +} + +static void +kde_handle_done (void *data, struct org_kde_kwin_dpms *dpms) +{ + dpms_output *out = (dpms_output *) data; + out->kde_done = True; +} + + +/* This is an iterator for all of the extensions that Wayland provides, + so we can find the ones we are interested in. + */ +static void +handle_global (void *data, struct wl_registry *reg, + uint32_t name, const char *iface, uint32_t version) +{ + wayland_dpms *state = (wayland_dpms *) data; + + if (!strcmp (iface, wl_output_interface.name)) + { + static const struct wl_output_listener wl_listener = { + .name = wl_handle_name, + .geometry = wl_handle_geometry, + .mode = wl_handle_mode, + .scale = wl_handle_scale, + .description = wl_handle_description, + .done = wl_handle_done, + }; + static const struct zwlr_output_power_v1_listener wlr_listener = { + .mode = wlr_handle_mode, + .failed = wlr_handle_failed, + }; + static const struct org_kde_kwin_dpms_listener kde_listener = { + .supported = kde_handle_supported, + .mode = kde_handle_mode, + .done = kde_handle_done, + }; + + dpms_output *out = (dpms_output *) calloc (sizeof (*out), 1); + wl_list_insert (&state->outputs, &out->link); + + if (verbose_p > 2) + fprintf (stderr, "%s: wayland: dpms: found: %s\n", blurb(), iface); + + /* First listener: properties of the wl_output object. */ + out->wl_output = wl_registry_bind (reg, name, &wl_output_interface, + version); + wl_output_add_listener (out->wl_output, &wl_listener, out); + + if (state->wlr_mgr) + { + /* Second listener: changes to its DPMS state. */ + out->wlr_out = + zwlr_output_power_manager_v1_get_output_power (state->wlr_mgr, + out->wl_output); + zwlr_output_power_v1_add_listener (out->wlr_out, &wlr_listener, out); + } + else if (state->kde_mgr) + { + /* Second listener: changes to its DPMS state. */ + out->kde_out = + org_kde_kwin_dpms_manager_get (state->kde_mgr, out->wl_output); + org_kde_kwin_dpms_add_listener (out->kde_out, &kde_listener, out); + } + } + else if (!strcmp (iface, zwlr_output_power_manager_v1_interface.name)) + { + if (verbose_p) + fprintf (stderr, "%s: wayland: dpms: found: %s\n", blurb(), iface); + state->wlr_mgr = + wl_registry_bind (reg, name, &zwlr_output_power_manager_v1_interface, + version); + } + else if (!strcmp (iface, org_kde_kwin_dpms_manager_interface.name)) + { + if (verbose_p) + fprintf (stderr, "%s: wayland: dpms: found: %s\n", blurb(), iface); + state->kde_mgr = + wl_registry_bind (reg, name, &org_kde_kwin_dpms_manager_interface, + version); + } +} + + +static void +handle_global_remove (void *data, struct wl_registry *registry, uint32_t name) +{ +} + + +wayland_dpms * +wayland_dpms_init (wayland_dpy *dpy) +{ + static const struct wl_registry_listener listener = { + .global = handle_global, + .global_remove = handle_global_remove, + }; + wayland_dpms *state; + if (!dpy) return NULL; + + state = (wayland_dpms *) calloc (sizeof (*state), 1); + state->parent = dpy; + wl_list_init (&state->outputs); + + state->reg = wl_display_get_registry (dpy->dpy); + wl_registry_add_listener (state->reg, &listener, state); + + /* Do the first round trip to load the wl_outputs. */ + wayland_dpy_process_events (dpy, true); + + /* Now do more round trips until we have all the info about them. FFS! */ + while (1) + { + Bool all_done = True; + dpms_output *out; + wl_list_for_each (out, &state->outputs, link) + { + if (!out->wl_done) + all_done = False; + if (state->kde_mgr && !out->kde_done) + all_done = False; + } + if (all_done) break; + wayland_dpy_process_events (dpy, true); + } + + if (!state->wlr_mgr && !state->kde_mgr) + { + fprintf (stderr, + "%s: wayland: dpms: server doesn't implement \"%s\" or \"%s\"\n", + blurb(), + zwlr_output_power_manager_v1_interface.name, + org_kde_kwin_dpms_manager_interface.name); + wayland_dpms_free (state); + return NULL; + } + + return state; +} + + +void +wayland_dpms_free (wayland_dpms *state) +{ + dpms_output *out, *tmp; + wl_list_for_each_safe (out, tmp, &state->outputs, link) + { + wl_list_remove (&out->link); + /* #### out->wl_output ? */ + /* #### out->zwlr_output_power_v1, etc ? */ + free (out); + } + + /* #### state->reg ? */ + /* #### state->zwlr_output_power_manager_v1, etc ? */ + free (state); +} + + +/* True if any head is enabled. + */ +Bool +wayland_monitor_powered_on_p (wayland_dpms *state) +{ + Bool on_p = False; + dpms_output *out; + + if (!state) return on_p; + + wayland_dpy_process_events (state->parent, True); + wl_list_for_each (out, &state->outputs, link) + { + if (out->wlr_out) + { + if (out->wlr_mode == ZWLR_OUTPUT_POWER_V1_MODE_ON) + on_p = True; + } + else if (out->kde_out) + { + if (out->kde_mode == ORG_KDE_KWIN_DPMS_MODE_ON) + on_p = True; + } + else + abort(); + } + + return on_p; +} + + +/* Set all heads to 'enabled' or 'disabled'. + */ +void +wayland_monitor_power_on (wayland_dpms *state, Bool on_p) +{ + enum zwlr_output_power_v1_mode wlr_target = + (on_p ? ZWLR_OUTPUT_POWER_V1_MODE_ON : ZWLR_OUTPUT_POWER_V1_MODE_OFF); + enum org_kde_kwin_dpms_mode kde_target = + (on_p ? ORG_KDE_KWIN_DPMS_MODE_ON : ORG_KDE_KWIN_DPMS_MODE_OFF); + dpms_output *out; + + if (!state) return; + + wl_list_for_each (out, &state->outputs, link) + { + if (out->wlr_out) + { + if (out->wlr_mode == wlr_target) + continue; + else + zwlr_output_power_v1_set_mode (out->wlr_out, wlr_target); + } + else if (out->kde_out) + { + if (out->kde_mode == kde_target) + continue; + else + org_kde_kwin_dpms_set (out->kde_out, kde_target); + } + else + abort(); + + if (verbose_p > 2) + fprintf (stderr, "%s: wayland: dpms: set output %s to %s\n", blurb(), + out->name, (on_p ? "on" : "off")); + } + + wayland_dpy_process_events (state->parent, True); +} + diff --git a/driver/wayland-dpms.h b/driver/wayland-dpms.h new file mode 100644 index 00000000..207a068d --- /dev/null +++ b/driver/wayland-dpms.h @@ -0,0 +1,22 @@ +/* xscreensaver, Copyright © 2025 Jamie Zawinski + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. No representations are made about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + */ + +#ifndef __XSCREENSAVER_WAYLAND_DPMS_H__ +#define __XSCREENSAVER_WAYLAND_DPMS_H__ + +/* Binds to Wayland DPMS-detection protocols and returns an opaque state + object on success. */ +extern wayland_dpms *wayland_dpms_init (wayland_dpy *dpy); +Bool wayland_monitor_powered_on_p (wayland_dpms *); +void wayland_monitor_power_on (wayland_dpms *, Bool on_p); +extern void wayland_dpms_free (wayland_dpms *); + +#endif /* __XSCREENSAVER_WAYLAND_DPMS_H__ */ diff --git a/driver/wayland-dpy.c b/driver/wayland-dpy.c new file mode 100644 index 00000000..db5c922e --- /dev/null +++ b/driver/wayland-dpy.c @@ -0,0 +1,151 @@ +/* xscreensaver, Copyright © 2025 Jamie Zawinski + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. No representations are made about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * Connecting to a Wayland server, and a few connection-related utilities. + * The various other wayland-*.c modules (idle, dpms, etc.) build on this. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#ifdef HAVE_UNISTD_H +# include +#endif + +#include +#include +#include +#include +#include +#include "wayland-dpyI.h" +#include "blurb.h" + +/* Dispatch any events that have been read. */ +static int +handle_event (int fd, uint32_t mask, void *data) +{ + wayland_dpy *state = (wayland_dpy *) data; + int count = 0; + + if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) + { + fprintf (stderr, "%s: Wayland connection closed\n", blurb()); + if (state->atexit_cb) + (*state->atexit_cb) (state->atexit_closure); + exit (1); + } + + if (mask & WL_EVENT_READABLE) + count = wl_display_dispatch (state->dpy); + + if (mask & WL_EVENT_WRITABLE) + wl_display_flush (state->dpy); + + if (mask == 0) + { + count = wl_display_dispatch_pending (state->dpy); + wl_display_flush (state->dpy); + } + + return count; +} + + +/* Connects to Wayland and returns an opaque state object on success. */ +wayland_dpy * +wayland_dpy_connect (void) +{ + wayland_dpy *state = (wayland_dpy *) calloc (sizeof (*state), 1); + state->dpy = wl_display_connect (NULL); + if (!state->dpy) + { + free (state); + return NULL; + } + + if (verbose_p) + fprintf (stderr, "%s: wayland: server connected\n", blurb()); + + state->event_loop = wl_event_loop_create(); + + { /* Tell the event loop to select() on the display connection. */ + struct wl_event_source *source = + wl_event_loop_add_fd (state->event_loop, + wl_display_get_fd (state->dpy), + WL_EVENT_READABLE, handle_event, state); + wl_event_source_check (source); + /* #### Do I need to free 'source'? */ + } + + wayland_dpy_process_events (state, 0); + return state; +} + +int +wayland_dpy_get_fd (wayland_dpy *state) +{ + return wl_display_get_fd (state->dpy); +} + + +static void +sync_cb (void *data, struct wl_callback *cb, uint32_t serial) +{ + int *done = data; + *done = 1; + wl_callback_destroy (cb); +} + +/* Handle any notifications from the Wayland server and run callbacks. + If sync_p, blocks until all outstanding events have been processed. + */ +void +wayland_dpy_process_events (wayland_dpy *state, int sync_p) +{ + struct wl_callback *cb; + int done = 0, ret = 0; + + /* Process all outstanding events without blocking. */ + wl_event_loop_dispatch (state->event_loop, 0); + + /* Block until we get our own ACK, meaning queue is flushed. */ + if (sync_p) + { + static const struct wl_callback_listener listener = { sync_cb }; + cb = wl_display_sync (state->dpy); + wl_callback_add_listener (cb, &listener, &done); + while (ret != -1 && !done) + ret = wl_display_dispatch (state->dpy); + if (!done) + wl_callback_destroy (cb); + } +} + +void +wayland_dpy_close (wayland_dpy *state) +{ + wl_display_disconnect (state->dpy); + if (state->event_loop) + wl_event_loop_destroy (state->event_loop); + free (state); + if (verbose_p) + fprintf (stderr, "%s: wayland: disconnected\n", blurb()); +} + +void +wayland_dpy_atexit (wayland_dpy *dpy, + void (*cb) (void *closure), + void *closure) +{ + dpy->atexit_cb = cb; + dpy->atexit_closure = closure; +} diff --git a/driver/wayland-dpy.h b/driver/wayland-dpy.h new file mode 100644 index 00000000..585dce07 --- /dev/null +++ b/driver/wayland-dpy.h @@ -0,0 +1,39 @@ +/* xscreensaver, Copyright © 2025 Jamie Zawinski + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. No representations are made about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + */ + +#ifndef __XSCREENSAVER_WAYLAND_DPY_H__ +#define __XSCREENSAVER_WAYLAND_DPY_H__ + +typedef struct wayland_dpy wayland_dpy; +typedef struct wayland_idle wayland_idle; +typedef struct wayland_dpms wayland_dpms; + +/* Connects to Wayland and returns a state object on success. */ +extern wayland_dpy *wayland_dpy_connect (void); + +/* Returns the file descriptor of the Wayland display connection. + You may select on this to see if it needs attention. */ +extern int wayland_dpy_get_fd (wayland_dpy *); + +/* Handle any notifications from the Wayland server and run callbacks. + If sync_p, blocks until all outstanding events have been processed. + */ +extern void wayland_dpy_process_events (wayland_dpy *, int sync_p); + +/* Run this callback when the Wayland server drops the connection. */ +extern void wayland_dpy_atexit (wayland_dpy *, + void (*cb) (void *closure), + void *closure); + +/* Shut it all down. */ +extern void wayland_dpy_close (wayland_dpy *); + +#endif /* __XSCREENSAVER_WAYLAND_DPY_H__ */ diff --git a/driver/wayland-dpyI.h b/driver/wayland-dpyI.h new file mode 100644 index 00000000..0220ade3 --- /dev/null +++ b/driver/wayland-dpyI.h @@ -0,0 +1,25 @@ +/* xscreensaver, Copyright © 2025 Jamie Zawinski + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. No representations are made about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + */ + +#ifndef __XSCREENSAVER_WAYLAND_DPYI_H__ +#define __XSCREENSAVER_WAYLAND_DPYI_H__ + +#include "wayland-dpy.h" + +struct wayland_dpy { + struct wl_display *dpy; + struct wl_event_loop *event_loop; + + void (*atexit_cb) (void *closure); + void *atexit_closure; +}; + +#endif /* __XSCREENSAVER_WAYLAND_DPYI_H__ */ diff --git a/driver/wayland-idle.c b/driver/wayland-idle.c index 39acd20d..734e35eb 100644 --- a/driver/wayland-idle.c +++ b/driver/wayland-idle.c @@ -10,6 +10,8 @@ * * Detecting idleness via a connection to the Wayland server and the * "idle-notify-v1" protocol: https://wayland.app/protocols/ext-idle-notify-v1 + * If the Wayland server does not implement this protocol, XScreenSaver cannot + * function. KDE implements it, but GNOME does not. */ #ifdef HAVE_CONFIG_H @@ -24,17 +26,19 @@ #include #include #include -/* #include */ + #include #include -/* #include */ -#include "ext-idle-notify-v1-client-protocol.h" -#include "idle-client-protocol.h" -#include "wayland-idle.h" + #include "blurb.h" +#include "wayland-dpyI.h" +#include "wayland-idle.h" +#include "wayland-protocols/ext-idle-notify-v1-client-protocol.h" +#include "wayland-protocols/idle-client-protocol.h" -struct wayland_state { +struct wayland_idle { + wayland_dpy *parent; struct wl_display *dpy; struct wl_registry *reg; struct wl_event_loop *event_loop; @@ -57,20 +61,20 @@ struct wayland_state { static void seat_handle_capabilities (void *data, struct wl_seat *seat, uint32_t caps) { - wayland_state *state = (wayland_state *) data; + wayland_idle *state = (wayland_idle *) data; state->seat_caps = caps; if (verbose_p > 2) - fprintf (stderr, "%s: wayland: seat caps: 0x%02lX\n", blurb(), + fprintf (stderr, "%s: wayland: idle: seat caps: 0x%02lX\n", blurb(), (unsigned long) caps); } static void seat_handle_name (void *data, struct wl_seat *seat, const char *name) { - wayland_state *state = (wayland_state *) data; + wayland_idle *state = (wayland_idle *) data; state->seat_name = strdup (name); if (verbose_p > 2) - fprintf (stderr, "%s: wayland: seat name: \"%s\"\n", blurb(), name); + fprintf (stderr, "%s: wayland: idle: seat name: \"%s\"\n", blurb(), name); } @@ -81,7 +85,7 @@ static void handle_global (void *data, struct wl_registry *reg, uint32_t name, const char *iface, uint32_t version) { - wayland_state *state = (wayland_state *) data; + wayland_idle *state = (wayland_idle *) data; if (!strcmp (iface, wl_seat_interface.name)) { @@ -90,21 +94,21 @@ handle_global (void *data, struct wl_registry *reg, .capabilities = seat_handle_capabilities, }; if (verbose_p > 2) - fprintf (stderr, "%s: wayland: found: %s\n", blurb(), iface); + fprintf (stderr, "%s: wayland: idle: found: %s\n", blurb(), iface); state->seat = wl_registry_bind (reg, name, &wl_seat_interface, version); wl_seat_add_listener (state->seat, &seat_listener, state); } else if (!strcmp (iface, ext_idle_notifier_v1_interface.name)) { if (verbose_p) - fprintf (stderr, "%s: wayland: found: %s\n", blurb(), iface); + fprintf (stderr, "%s: wayland: idle: found: %s\n", blurb(), iface); state->ext_idle_notifier = wl_registry_bind (reg, name, &ext_idle_notifier_v1_interface, 1); } else if (!strcmp (iface, org_kde_kwin_idle_interface.name)) { if (verbose_p) - fprintf (stderr, "%s: wayland: found: %s\n", blurb(), iface); + fprintf (stderr, "%s: wayland: idle: found: %s\n", blurb(), iface); state->kde_idle_manager = wl_registry_bind (reg, name, &org_kde_kwin_idle_interface, 1); } @@ -120,60 +124,64 @@ handle_global_remove (void *data, struct wl_registry *registry, uint32_t name) static void ext_handle_idled (void *data, struct ext_idle_notification_v1 *note) { - /* wayland_state *state = (wayland_state *) data; */ + /* wayland_idle *state = (wayland_idle *) data; */ if (verbose_p > 2) - fprintf (stderr, "%s: wayland: ext_idle: idle notification\n", blurb()); + fprintf (stderr, "%s: wayland: idle: ext_idle notification\n", blurb()); } /* Called when the user is no longer idle. */ static void ext_handle_resumed (void *data, struct ext_idle_notification_v1 *note) { - wayland_state *state = (wayland_state *) data; + wayland_idle *state = (wayland_idle *) data; if (verbose_p > 2) - fprintf (stderr, "%s: wayland: ext_idle: active notification\n", blurb()); + fprintf (stderr, "%s: wayland: idle: ext_idle active notification\n", + blurb()); (*state->activity_cb) (state->closure); } static void kde_handle_idle (void *data, struct org_kde_kwin_idle_timeout *timer) { - /* wayland_state *state = (wayland_state *) data; */ + /* wayland_idle *state = (wayland_idle *) data; */ if (verbose_p > 2) - fprintf (stderr, "%s: wayland: kde_idle: idle notification\n", blurb()); + fprintf (stderr, "%s: wayland: idle: kde_idle notification\n", blurb()); } static void kde_handle_resumed (void *data, struct org_kde_kwin_idle_timeout *timer) { - wayland_state *state = (wayland_state *) data; + wayland_idle *state = (wayland_idle *) data; if (verbose_p > 2) - fprintf (stderr, "%s: wayland: kde_idle: active notification\n", blurb()); + fprintf (stderr, "%s: wayland: idle: kde_idle active notification\n", + blurb()); (*state->activity_cb) (state->closure); } static void -destroy_timer (wayland_state *state) +destroy_timer (wayland_idle *state) { if (state->ext_idle_notification) { ext_idle_notification_v1_destroy (state->ext_idle_notification); state->ext_idle_notification = 0; if (verbose_p > 2) - fprintf (stderr, "%s: wayland: destroyed kde_idle timer\n", blurb()); + fprintf (stderr, "%s: wayland: idle: destroyed kde_idle timer\n", + blurb()); } if (state->kde_idle_timer) { org_kde_kwin_idle_timeout_release (state->kde_idle_timer); state->kde_idle_timer = 0; if (verbose_p > 2) - fprintf (stderr, "%s: wayland: destroyed ext_idle timer\n", blurb()); + fprintf (stderr, "%s: wayland: idle: destroyed ext_idle timer\n", + blurb()); } } static void -register_timer (wayland_state *state, int timeout) +register_timer (wayland_idle *state, int timeout) { destroy_timer (state); if (state->ext_idle_notifier) @@ -192,7 +200,8 @@ register_timer (wayland_state *state, int timeout) &ext_idle_notification_listener, state); if (verbose_p > 2) - fprintf (stderr, "%s: wayland: registered ext_idle timer\n", blurb()); + fprintf (stderr, "%s: wayland: idle: registered ext_idle timer\n", + blurb()); } else { @@ -210,143 +219,71 @@ register_timer (wayland_state *state, int timeout) &kde_idle_timer_listener, state); if (verbose_p > 2) - fprintf (stderr, "%s: wayland: registered kde_idle timer\n", blurb()); - } -} - - -/* Dispatch any events that have been read. */ -static int -dpy_handle_event (int fd, uint32_t mask, void *data) -{ - wayland_state *state = (wayland_state *) data; - int count = 0; - - if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) - { - /* Nothing good can come of this... */ + fprintf (stderr, "%s: wayland: idle: registered kde_idle timer\n", + blurb()); } - - if (mask & WL_EVENT_READABLE) - count = wl_display_dispatch (state->dpy); - - if (mask & WL_EVENT_WRITABLE) - wl_display_flush (state->dpy); - - if (mask == 0) - { - count = wl_display_dispatch_pending (state->dpy); - wl_display_flush (state->dpy); - } - - return count; } -/* Connects to Wayland and returns an opaque state object on success. - When user activity is detected, the callback will be run with the - provided object as its argument. On failure, returns NULL and - an error message. +/* Binds to Wayland idle-detection protocols and returns an opaque state + object on success. When user activity is detected, the callback will + be run with the provided object as its argument. */ -wayland_state * -wayland_idle_init (void (*activity_cb) (void *closure), - void *closure, - const char **error_ret) +wayland_idle * +wayland_idle_init (wayland_dpy *dpy, + void (*activity_cb) (void *closure), + void *closure) { - wayland_state *state = (wayland_state *) calloc (sizeof (*state), 1); - state->activity_cb = activity_cb; - state->closure = closure; + wayland_idle *state; + static const struct wl_registry_listener listener = { + .global = handle_global, + .global_remove = handle_global_remove, + }; - state->dpy = wl_display_connect (NULL); - if (!state->dpy) - { - free (state); - if (error_ret) *error_ret = "connection failed"; - return NULL; - } + if (!dpy) return NULL; - if (verbose_p) - fprintf (stderr, "%s: wayland: server connected\n", blurb()); - - state->reg = wl_display_get_registry (state->dpy); + state = (wayland_idle *) calloc (sizeof (*state), 1); + state->parent = dpy; + state->activity_cb = activity_cb; + state->closure = closure; - { - static const struct wl_registry_listener listener = { - .global = handle_global, - .global_remove = handle_global_remove, - }; - wl_registry_add_listener (state->reg, &listener, state); - } + state->reg = wl_display_get_registry (dpy->dpy); + wl_registry_add_listener (state->reg, &listener, state); - wl_display_roundtrip (state->dpy); /* First time to register seats */ - wl_display_roundtrip (state->dpy); /* Second time to register timers */ + /* It takes two round trips: first to register seats, then timers. */ + wayland_dpy_process_events (dpy, true); if (! state->seat) { wayland_idle_free (state); - if (error_ret) *error_ret = "server has no seats"; + fprintf (stderr, "%s: wayland: idle: server has no seats\n", blurb()); return NULL; } if (! (state->kde_idle_manager || state->ext_idle_notifier)) { - static char err[300]; - sprintf (err, "server doesn't implement \"%.100s\" or \"%.100s\"", + fprintf (stderr, + "%s: wayland: idle: server doesn't implement \"%s\" or \"%s\"\n", + blurb(), ext_idle_notifier_v1_interface.name, org_kde_kwin_idle_interface.name); wayland_idle_free (state); - if (error_ret) *error_ret = err; return NULL; } - state->event_loop = wl_event_loop_create(); - - { /* Tell the event loop to select() on the display connection. */ - struct wl_event_source *source = - wl_event_loop_add_fd (state->event_loop, - wl_display_get_fd (state->dpy), - WL_EVENT_READABLE, - dpy_handle_event, - state); - wl_event_source_check (source); - /* #### Do I need to free 'source'? */ - } - register_timer (state, 1000); /* milliseconds */ - wayland_idle_process_events (state); - - if (error_ret) *error_ret = 0; return state; } -int -wayland_idle_get_fd (wayland_state *state) -{ - return wl_display_get_fd (state->dpy); -} - - -/* Handle any notifications from the Wayland server and run callbacks. - */ -void -wayland_idle_process_events (wayland_state *state) -{ - /* Process all outstanding events without blocking. */ - wl_event_loop_dispatch (state->event_loop, 0); -} - - void -wayland_idle_free (wayland_state *state) +wayland_idle_free (wayland_idle *state) { - wl_display_disconnect (state->dpy); - if (state->event_loop) - wl_event_loop_destroy (state->event_loop); if (state->seat_name) free (state->seat_name); + /* #### state->reg ? */ + /* #### state->seat ? */ + /* #### state->ext_idle_notifier, etc ? */ free (state); - if (verbose_p) - fprintf (stderr, "%s: wayland: disconnected\n", blurb()); } diff --git a/driver/wayland-idle.h b/driver/wayland-idle.h index 7fb1df56..0d97b37b 100644 --- a/driver/wayland-idle.h +++ b/driver/wayland-idle.h @@ -12,26 +12,16 @@ #ifndef __XSCREENSAVER_WAYLAND_IDLE_H__ #define __XSCREENSAVER_WAYLAND_IDLE_H__ -typedef struct wayland_state wayland_state; - -/* Connects to Wayland and returns an opaque state object on success. - When user activity is detected, the callback will be run with the - provided object as its argument. On failure, returns NULL and - an error message. +/* Binds to Wayland idle-detection protocols and returns an opaque state + object on success. When user activity is detected, the callback will + be run with the provided object as its argument. */ -extern wayland_state * -wayland_idle_init (void (*activity_cb) (void *closure), - void *closure, - const char **error_ret); - -/* Returns the file descriptor of the Wayland display connection. - You may select on this to see if it needs attention. */ -extern int wayland_idle_get_fd (wayland_state *); - -/* Handle any notifications from the Wayland server and run callbacks. */ -extern void wayland_idle_process_events (wayland_state *); +extern wayland_idle * +wayland_idle_init (wayland_dpy *dpy, + void (*activity_cb) (void *closure), + void *closure); /* Shut it all down. */ -extern void wayland_idle_free (wayland_state *); +extern void wayland_idle_free (wayland_idle *); -#endif /* __XSCREENSAVER_WAYLAND_H__ */ +#endif /* __XSCREENSAVER_WAYLAND_IDLE_H__ */ diff --git a/driver/wayland-protocols/dpms-client-protocol.h b/driver/wayland-protocols/dpms-client-protocol.h new file mode 100644 index 00000000..16b7ad26 --- /dev/null +++ b/driver/wayland-protocols/dpms-client-protocol.h @@ -0,0 +1,284 @@ +/* Generated by wayland-scanner 1.23.1 */ + +#ifndef DPMS_CLIENT_PROTOCOL_H +#define DPMS_CLIENT_PROTOCOL_H + +#include +#include +#include "wayland-client.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @page page_dpms The dpms protocol + * @section page_ifaces_dpms Interfaces + * - @subpage page_iface_org_kde_kwin_dpms_manager - Output dpms manager + * - @subpage page_iface_org_kde_kwin_dpms - Dpms for a wl_output + * @section page_copyright_dpms Copyright + *
+ *
+ * SPDX-FileCopyrightText: 2015 Martin Gräßlin
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ * 
+ */ +struct org_kde_kwin_dpms; +struct org_kde_kwin_dpms_manager; +struct wl_output; + +#ifndef ORG_KDE_KWIN_DPMS_MANAGER_INTERFACE +#define ORG_KDE_KWIN_DPMS_MANAGER_INTERFACE +/** + * @page page_iface_org_kde_kwin_dpms_manager org_kde_kwin_dpms_manager + * @section page_iface_org_kde_kwin_dpms_manager_desc Description + * + * The Dpms manager allows to get a org_kde_kwin_dpms for a given wl_output. + * The org_kde_kwin_dpms provides the currently used VESA Display Power Management + * Signaling state (see https://en.wikipedia.org/wiki/VESA_Display_Power_Management_Signaling ). + * In addition it allows to request a state change. A compositor is not obliged to honor it + * and will normally automatically switch back to on state. + * @section page_iface_org_kde_kwin_dpms_manager_api API + * See @ref iface_org_kde_kwin_dpms_manager. + */ +/** + * @defgroup iface_org_kde_kwin_dpms_manager The org_kde_kwin_dpms_manager interface + * + * The Dpms manager allows to get a org_kde_kwin_dpms for a given wl_output. + * The org_kde_kwin_dpms provides the currently used VESA Display Power Management + * Signaling state (see https://en.wikipedia.org/wiki/VESA_Display_Power_Management_Signaling ). + * In addition it allows to request a state change. A compositor is not obliged to honor it + * and will normally automatically switch back to on state. + */ +extern const struct wl_interface org_kde_kwin_dpms_manager_interface; +#endif +#ifndef ORG_KDE_KWIN_DPMS_INTERFACE +#define ORG_KDE_KWIN_DPMS_INTERFACE +/** + * @page page_iface_org_kde_kwin_dpms org_kde_kwin_dpms + * @section page_iface_org_kde_kwin_dpms_desc Description + * + * This interface provides information about the VESA DPMS state for a wl_output. + * It gets created through the request get on the org_kde_kwin_dpms_manager interface. + * + * On creating the resource the server will push whether DPSM is supported for the output, + * the currently used DPMS state and notifies the client through the done event once all + * states are pushed. Whenever a state changes the set of changes is committed with the + * done event. + * @section page_iface_org_kde_kwin_dpms_api API + * See @ref iface_org_kde_kwin_dpms. + */ +/** + * @defgroup iface_org_kde_kwin_dpms The org_kde_kwin_dpms interface + * + * This interface provides information about the VESA DPMS state for a wl_output. + * It gets created through the request get on the org_kde_kwin_dpms_manager interface. + * + * On creating the resource the server will push whether DPSM is supported for the output, + * the currently used DPMS state and notifies the client through the done event once all + * states are pushed. Whenever a state changes the set of changes is committed with the + * done event. + */ +extern const struct wl_interface org_kde_kwin_dpms_interface; +#endif + +#define ORG_KDE_KWIN_DPMS_MANAGER_GET 0 + + +/** + * @ingroup iface_org_kde_kwin_dpms_manager + */ +#define ORG_KDE_KWIN_DPMS_MANAGER_GET_SINCE_VERSION 1 + +/** @ingroup iface_org_kde_kwin_dpms_manager */ +static inline void +org_kde_kwin_dpms_manager_set_user_data(struct org_kde_kwin_dpms_manager *org_kde_kwin_dpms_manager, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) org_kde_kwin_dpms_manager, user_data); +} + +/** @ingroup iface_org_kde_kwin_dpms_manager */ +static inline void * +org_kde_kwin_dpms_manager_get_user_data(struct org_kde_kwin_dpms_manager *org_kde_kwin_dpms_manager) +{ + return wl_proxy_get_user_data((struct wl_proxy *) org_kde_kwin_dpms_manager); +} + +static inline uint32_t +org_kde_kwin_dpms_manager_get_version(struct org_kde_kwin_dpms_manager *org_kde_kwin_dpms_manager) +{ + return wl_proxy_get_version((struct wl_proxy *) org_kde_kwin_dpms_manager); +} + +/** @ingroup iface_org_kde_kwin_dpms_manager */ +static inline void +org_kde_kwin_dpms_manager_destroy(struct org_kde_kwin_dpms_manager *org_kde_kwin_dpms_manager) +{ + wl_proxy_destroy((struct wl_proxy *) org_kde_kwin_dpms_manager); +} + +/** + * @ingroup iface_org_kde_kwin_dpms_manager + * + * Factory request to get the org_kde_kwin_dpms for a given wl_output. + */ +static inline struct org_kde_kwin_dpms * +org_kde_kwin_dpms_manager_get(struct org_kde_kwin_dpms_manager *org_kde_kwin_dpms_manager, struct wl_output *output) +{ + struct wl_proxy *id; + + id = wl_proxy_marshal_flags((struct wl_proxy *) org_kde_kwin_dpms_manager, + ORG_KDE_KWIN_DPMS_MANAGER_GET, &org_kde_kwin_dpms_interface, wl_proxy_get_version((struct wl_proxy *) org_kde_kwin_dpms_manager), 0, NULL, output); + + return (struct org_kde_kwin_dpms *) id; +} + +#ifndef ORG_KDE_KWIN_DPMS_MODE_ENUM +#define ORG_KDE_KWIN_DPMS_MODE_ENUM +enum org_kde_kwin_dpms_mode { + ORG_KDE_KWIN_DPMS_MODE_ON = 0, + ORG_KDE_KWIN_DPMS_MODE_STANDBY = 1, + ORG_KDE_KWIN_DPMS_MODE_SUSPEND = 2, + ORG_KDE_KWIN_DPMS_MODE_OFF = 3, +}; +#endif /* ORG_KDE_KWIN_DPMS_MODE_ENUM */ + +/** + * @ingroup iface_org_kde_kwin_dpms + * @struct org_kde_kwin_dpms_listener + */ +struct org_kde_kwin_dpms_listener { + /** + * Event indicating whether DPMS is supported on the wl_output + * + * This event gets pushed on binding the resource and indicates + * whether the wl_output supports DPMS. There are operation modes + * of a Wayland server where DPMS might not make sense (e.g. nested + * compositors). + * @param supported Boolean value whether DPMS is supported (1) for the wl_output or not (0) + */ + void (*supported)(void *data, + struct org_kde_kwin_dpms *org_kde_kwin_dpms, + uint32_t supported); + /** + * Event indicating used DPMS mode + * + * This mode gets pushed on binding the resource and provides the + * currently used DPMS mode. It also gets pushed if DPMS is not + * supported for the wl_output, in that case the value will be On. + * + * The event is also pushed whenever the state changes. + * @param mode The new currently used mode + */ + void (*mode)(void *data, + struct org_kde_kwin_dpms *org_kde_kwin_dpms, + uint32_t mode); + /** + * All changes are pushed + * + * This event gets pushed on binding the resource once all other + * states are pushed. + * + * In addition it gets pushed whenever a state changes to tell the + * client that all state changes have been pushed. + */ + void (*done)(void *data, + struct org_kde_kwin_dpms *org_kde_kwin_dpms); +}; + +/** + * @ingroup iface_org_kde_kwin_dpms + */ +static inline int +org_kde_kwin_dpms_add_listener(struct org_kde_kwin_dpms *org_kde_kwin_dpms, + const struct org_kde_kwin_dpms_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) org_kde_kwin_dpms, + (void (**)(void)) listener, data); +} + +#define ORG_KDE_KWIN_DPMS_SET 0 +#define ORG_KDE_KWIN_DPMS_RELEASE 1 + +/** + * @ingroup iface_org_kde_kwin_dpms + */ +#define ORG_KDE_KWIN_DPMS_SUPPORTED_SINCE_VERSION 1 +/** + * @ingroup iface_org_kde_kwin_dpms + */ +#define ORG_KDE_KWIN_DPMS_MODE_SINCE_VERSION 1 +/** + * @ingroup iface_org_kde_kwin_dpms + */ +#define ORG_KDE_KWIN_DPMS_DONE_SINCE_VERSION 1 + +/** + * @ingroup iface_org_kde_kwin_dpms + */ +#define ORG_KDE_KWIN_DPMS_SET_SINCE_VERSION 1 +/** + * @ingroup iface_org_kde_kwin_dpms + */ +#define ORG_KDE_KWIN_DPMS_RELEASE_SINCE_VERSION 1 + +/** @ingroup iface_org_kde_kwin_dpms */ +static inline void +org_kde_kwin_dpms_set_user_data(struct org_kde_kwin_dpms *org_kde_kwin_dpms, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) org_kde_kwin_dpms, user_data); +} + +/** @ingroup iface_org_kde_kwin_dpms */ +static inline void * +org_kde_kwin_dpms_get_user_data(struct org_kde_kwin_dpms *org_kde_kwin_dpms) +{ + return wl_proxy_get_user_data((struct wl_proxy *) org_kde_kwin_dpms); +} + +static inline uint32_t +org_kde_kwin_dpms_get_version(struct org_kde_kwin_dpms *org_kde_kwin_dpms) +{ + return wl_proxy_get_version((struct wl_proxy *) org_kde_kwin_dpms); +} + +/** @ingroup iface_org_kde_kwin_dpms */ +static inline void +org_kde_kwin_dpms_destroy(struct org_kde_kwin_dpms *org_kde_kwin_dpms) +{ + wl_proxy_destroy((struct wl_proxy *) org_kde_kwin_dpms); +} + +/** + * @ingroup iface_org_kde_kwin_dpms + * + * Requests that the compositor puts the wl_output into the passed mode. The compositor + * is not obliged to change the state. In addition the compositor might leave the mode + * whenever it seems suitable. E.g. the compositor might return to On state on user input. + * + * The client should not assume that the mode changed after requesting a new mode. + * Instead the client should listen for the mode event. + */ +static inline void +org_kde_kwin_dpms_set(struct org_kde_kwin_dpms *org_kde_kwin_dpms, uint32_t mode) +{ + wl_proxy_marshal_flags((struct wl_proxy *) org_kde_kwin_dpms, + ORG_KDE_KWIN_DPMS_SET, NULL, wl_proxy_get_version((struct wl_proxy *) org_kde_kwin_dpms), 0, mode); +} + +/** + * @ingroup iface_org_kde_kwin_dpms + */ +static inline void +org_kde_kwin_dpms_release(struct org_kde_kwin_dpms *org_kde_kwin_dpms) +{ + wl_proxy_marshal_flags((struct wl_proxy *) org_kde_kwin_dpms, + ORG_KDE_KWIN_DPMS_RELEASE, NULL, wl_proxy_get_version((struct wl_proxy *) org_kde_kwin_dpms), WL_MARSHAL_FLAG_DESTROY); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/driver/wayland-protocols/dpms-protocol.c b/driver/wayland-protocols/dpms-protocol.c new file mode 100644 index 00000000..7ff88a0b --- /dev/null +++ b/driver/wayland-protocols/dpms-protocol.c @@ -0,0 +1,59 @@ +/* Generated by wayland-scanner 1.23.1 */ + +/* + * SPDX-FileCopyrightText: 2015 Martin Gräßlin + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include +#include +#include +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface org_kde_kwin_dpms_interface; +extern const struct wl_interface wl_output_interface; + +static const struct wl_interface *dpms_types[] = { + NULL, + &org_kde_kwin_dpms_interface, + &wl_output_interface, +}; + +static const struct wl_message org_kde_kwin_dpms_manager_requests[] = { + { "get", "no", dpms_types + 1 }, +}; + +WL_PRIVATE const struct wl_interface org_kde_kwin_dpms_manager_interface = { + "org_kde_kwin_dpms_manager", 1, + 1, org_kde_kwin_dpms_manager_requests, + 0, NULL, +}; + +static const struct wl_message org_kde_kwin_dpms_requests[] = { + { "set", "u", dpms_types + 0 }, + { "release", "", dpms_types + 0 }, +}; + +static const struct wl_message org_kde_kwin_dpms_events[] = { + { "supported", "u", dpms_types + 0 }, + { "mode", "u", dpms_types + 0 }, + { "done", "", dpms_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface org_kde_kwin_dpms_interface = { + "org_kde_kwin_dpms", 1, + 2, org_kde_kwin_dpms_requests, + 3, org_kde_kwin_dpms_events, +}; + diff --git a/driver/wayland-protocols/dpms.xml b/driver/wayland-protocols/dpms.xml new file mode 100644 index 00000000..6839c072 --- /dev/null +++ b/driver/wayland-protocols/dpms.xml @@ -0,0 +1,82 @@ + + + + + + The Dpms manager allows to get a org_kde_kwin_dpms for a given wl_output. + The org_kde_kwin_dpms provides the currently used VESA Display Power Management + Signaling state (see https://en.wikipedia.org/wiki/VESA_Display_Power_Management_Signaling ). + In addition it allows to request a state change. A compositor is not obliged to honor it + and will normally automatically switch back to on state. + + + + Factory request to get the org_kde_kwin_dpms for a given wl_output. + + + + + + + + This interface provides information about the VESA DPMS state for a wl_output. + It gets created through the request get on the org_kde_kwin_dpms_manager interface. + + On creating the resource the server will push whether DPSM is supported for the output, + the currently used DPMS state and notifies the client through the done event once all + states are pushed. Whenever a state changes the set of changes is committed with the + done event. + + + + This event gets pushed on binding the resource and indicates whether the wl_output + supports DPMS. There are operation modes of a Wayland server where DPMS might not + make sense (e.g. nested compositors). + + + + + + + + + + + + This mode gets pushed on binding the resource and provides the currently used + DPMS mode. It also gets pushed if DPMS is not supported for the wl_output, in that + case the value will be On. + + The event is also pushed whenever the state changes. + + + + + + This event gets pushed on binding the resource once all other states are pushed. + + In addition it gets pushed whenever a state changes to tell the client that all + state changes have been pushed. + + + + + Requests that the compositor puts the wl_output into the passed mode. The compositor + is not obliged to change the state. In addition the compositor might leave the mode + whenever it seems suitable. E.g. the compositor might return to On state on user input. + + The client should not assume that the mode changed after requesting a new mode. + Instead the client should listen for the mode event. + + + + + + + + + diff --git a/driver/ext-idle-notify-v1-client-protocol.h b/driver/wayland-protocols/ext-idle-notify-v1-client-protocol.h similarity index 100% rename from driver/ext-idle-notify-v1-client-protocol.h rename to driver/wayland-protocols/ext-idle-notify-v1-client-protocol.h diff --git a/driver/ext-idle-notify-v1-protocol.c b/driver/wayland-protocols/ext-idle-notify-v1-protocol.c similarity index 100% rename from driver/ext-idle-notify-v1-protocol.c rename to driver/wayland-protocols/ext-idle-notify-v1-protocol.c diff --git a/driver/ext-idle-notify-v1.xml b/driver/wayland-protocols/ext-idle-notify-v1.xml similarity index 100% rename from driver/ext-idle-notify-v1.xml rename to driver/wayland-protocols/ext-idle-notify-v1.xml diff --git a/driver/idle-client-protocol.h b/driver/wayland-protocols/idle-client-protocol.h similarity index 100% rename from driver/idle-client-protocol.h rename to driver/wayland-protocols/idle-client-protocol.h diff --git a/driver/idle-protocol.c b/driver/wayland-protocols/idle-protocol.c similarity index 100% rename from driver/idle-protocol.c rename to driver/wayland-protocols/idle-protocol.c diff --git a/driver/idle.xml b/driver/wayland-protocols/idle.xml similarity index 70% rename from driver/idle.xml rename to driver/wayland-protocols/idle.xml index 92d9989c..575c7eb9 100644 --- a/driver/idle.xml +++ b/driver/wayland-protocols/idle.xml @@ -1,20 +1,9 @@ . + SPDX-License-Identifier: LGPL-2.1-or-later ]]> diff --git a/driver/wayland-protocols/wlr-output-power-management-unstable-v1-client-protocol.h b/driver/wayland-protocols/wlr-output-power-management-unstable-v1-client-protocol.h new file mode 100644 index 00000000..84a402cc --- /dev/null +++ b/driver/wayland-protocols/wlr-output-power-management-unstable-v1-client-protocol.h @@ -0,0 +1,313 @@ +/* Generated by wayland-scanner 1.23.1 */ + +#ifndef WLR_OUTPUT_POWER_MANAGEMENT_UNSTABLE_V1_CLIENT_PROTOCOL_H +#define WLR_OUTPUT_POWER_MANAGEMENT_UNSTABLE_V1_CLIENT_PROTOCOL_H + +#include +#include +#include "wayland-client.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @page page_wlr_output_power_management_unstable_v1 The wlr_output_power_management_unstable_v1 protocol + * Control power management modes of outputs + * + * @section page_desc_wlr_output_power_management_unstable_v1 Description + * + * This protocol allows clients to control power management modes + * of outputs that are currently part of the compositor space. The + * intent is to allow special clients like desktop shells to power + * down outputs when the system is idle. + * + * To modify outputs not currently part of the compositor space see + * wlr-output-management. + * + * Warning! The protocol described in this file is experimental and + * backward incompatible changes may be made. Backward compatible changes + * may be added together with the corresponding interface version bump. + * Backward incompatible changes are done by bumping the version number in + * the protocol and interface names and resetting the interface version. + * Once the protocol is to be declared stable, the 'z' prefix and the + * version number in the protocol and interface names are removed and the + * interface version number is reset. + * + * @section page_ifaces_wlr_output_power_management_unstable_v1 Interfaces + * - @subpage page_iface_zwlr_output_power_manager_v1 - manager to create per-output power management + * - @subpage page_iface_zwlr_output_power_v1 - adjust power management mode for an output + * @section page_copyright_wlr_output_power_management_unstable_v1 Copyright + *
+ *
+ * Copyright © 2019 Purism SPC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ * 
+ */ +struct wl_output; +struct zwlr_output_power_manager_v1; +struct zwlr_output_power_v1; + +#ifndef ZWLR_OUTPUT_POWER_MANAGER_V1_INTERFACE +#define ZWLR_OUTPUT_POWER_MANAGER_V1_INTERFACE +/** + * @page page_iface_zwlr_output_power_manager_v1 zwlr_output_power_manager_v1 + * @section page_iface_zwlr_output_power_manager_v1_desc Description + * + * This interface is a manager that allows creating per-output power + * management mode controls. + * @section page_iface_zwlr_output_power_manager_v1_api API + * See @ref iface_zwlr_output_power_manager_v1. + */ +/** + * @defgroup iface_zwlr_output_power_manager_v1 The zwlr_output_power_manager_v1 interface + * + * This interface is a manager that allows creating per-output power + * management mode controls. + */ +extern const struct wl_interface zwlr_output_power_manager_v1_interface; +#endif +#ifndef ZWLR_OUTPUT_POWER_V1_INTERFACE +#define ZWLR_OUTPUT_POWER_V1_INTERFACE +/** + * @page page_iface_zwlr_output_power_v1 zwlr_output_power_v1 + * @section page_iface_zwlr_output_power_v1_desc Description + * + * This object offers requests to set the power management mode of + * an output. + * @section page_iface_zwlr_output_power_v1_api API + * See @ref iface_zwlr_output_power_v1. + */ +/** + * @defgroup iface_zwlr_output_power_v1 The zwlr_output_power_v1 interface + * + * This object offers requests to set the power management mode of + * an output. + */ +extern const struct wl_interface zwlr_output_power_v1_interface; +#endif + +#define ZWLR_OUTPUT_POWER_MANAGER_V1_GET_OUTPUT_POWER 0 +#define ZWLR_OUTPUT_POWER_MANAGER_V1_DESTROY 1 + + +/** + * @ingroup iface_zwlr_output_power_manager_v1 + */ +#define ZWLR_OUTPUT_POWER_MANAGER_V1_GET_OUTPUT_POWER_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_output_power_manager_v1 + */ +#define ZWLR_OUTPUT_POWER_MANAGER_V1_DESTROY_SINCE_VERSION 1 + +/** @ingroup iface_zwlr_output_power_manager_v1 */ +static inline void +zwlr_output_power_manager_v1_set_user_data(struct zwlr_output_power_manager_v1 *zwlr_output_power_manager_v1, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) zwlr_output_power_manager_v1, user_data); +} + +/** @ingroup iface_zwlr_output_power_manager_v1 */ +static inline void * +zwlr_output_power_manager_v1_get_user_data(struct zwlr_output_power_manager_v1 *zwlr_output_power_manager_v1) +{ + return wl_proxy_get_user_data((struct wl_proxy *) zwlr_output_power_manager_v1); +} + +static inline uint32_t +zwlr_output_power_manager_v1_get_version(struct zwlr_output_power_manager_v1 *zwlr_output_power_manager_v1) +{ + return wl_proxy_get_version((struct wl_proxy *) zwlr_output_power_manager_v1); +} + +/** + * @ingroup iface_zwlr_output_power_manager_v1 + * + * Create an output power management mode control that can be used to + * adjust the power management mode for a given output. + */ +static inline struct zwlr_output_power_v1 * +zwlr_output_power_manager_v1_get_output_power(struct zwlr_output_power_manager_v1 *zwlr_output_power_manager_v1, struct wl_output *output) +{ + struct wl_proxy *id; + + id = wl_proxy_marshal_flags((struct wl_proxy *) zwlr_output_power_manager_v1, + ZWLR_OUTPUT_POWER_MANAGER_V1_GET_OUTPUT_POWER, &zwlr_output_power_v1_interface, wl_proxy_get_version((struct wl_proxy *) zwlr_output_power_manager_v1), 0, NULL, output); + + return (struct zwlr_output_power_v1 *) id; +} + +/** + * @ingroup iface_zwlr_output_power_manager_v1 + * + * All objects created by the manager will still remain valid, until their + * appropriate destroy request has been called. + */ +static inline void +zwlr_output_power_manager_v1_destroy(struct zwlr_output_power_manager_v1 *zwlr_output_power_manager_v1) +{ + wl_proxy_marshal_flags((struct wl_proxy *) zwlr_output_power_manager_v1, + ZWLR_OUTPUT_POWER_MANAGER_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) zwlr_output_power_manager_v1), WL_MARSHAL_FLAG_DESTROY); +} + +#ifndef ZWLR_OUTPUT_POWER_V1_MODE_ENUM +#define ZWLR_OUTPUT_POWER_V1_MODE_ENUM +enum zwlr_output_power_v1_mode { + /** + * Output is turned off. + */ + ZWLR_OUTPUT_POWER_V1_MODE_OFF = 0, + /** + * Output is turned on, no power saving + */ + ZWLR_OUTPUT_POWER_V1_MODE_ON = 1, +}; +#endif /* ZWLR_OUTPUT_POWER_V1_MODE_ENUM */ + +#ifndef ZWLR_OUTPUT_POWER_V1_ERROR_ENUM +#define ZWLR_OUTPUT_POWER_V1_ERROR_ENUM +enum zwlr_output_power_v1_error { + /** + * nonexistent power save mode + */ + ZWLR_OUTPUT_POWER_V1_ERROR_INVALID_MODE = 1, +}; +#endif /* ZWLR_OUTPUT_POWER_V1_ERROR_ENUM */ + +/** + * @ingroup iface_zwlr_output_power_v1 + * @struct zwlr_output_power_v1_listener + */ +struct zwlr_output_power_v1_listener { + /** + * Report a power management mode change + * + * Report the power management mode change of an output. + * + * The mode event is sent after an output changed its power + * management mode. The reason can be a client using set_mode or + * the compositor deciding to change an output's mode. This event + * is also sent immediately when the object is created so the + * client is informed about the current power management mode. + * @param mode the output's new power management mode + */ + void (*mode)(void *data, + struct zwlr_output_power_v1 *zwlr_output_power_v1, + uint32_t mode); + /** + * object no longer valid + * + * This event indicates that the output power management mode + * control is no longer valid. This can happen for a number of + * reasons, including: - The output doesn't support power + * management - Another client already has exclusive power + * management mode control for this output - The output disappeared + * + * Upon receiving this event, the client should destroy this + * object. + */ + void (*failed)(void *data, + struct zwlr_output_power_v1 *zwlr_output_power_v1); +}; + +/** + * @ingroup iface_zwlr_output_power_v1 + */ +static inline int +zwlr_output_power_v1_add_listener(struct zwlr_output_power_v1 *zwlr_output_power_v1, + const struct zwlr_output_power_v1_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) zwlr_output_power_v1, + (void (**)(void)) listener, data); +} + +#define ZWLR_OUTPUT_POWER_V1_SET_MODE 0 +#define ZWLR_OUTPUT_POWER_V1_DESTROY 1 + +/** + * @ingroup iface_zwlr_output_power_v1 + */ +#define ZWLR_OUTPUT_POWER_V1_MODE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_output_power_v1 + */ +#define ZWLR_OUTPUT_POWER_V1_FAILED_SINCE_VERSION 1 + +/** + * @ingroup iface_zwlr_output_power_v1 + */ +#define ZWLR_OUTPUT_POWER_V1_SET_MODE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_output_power_v1 + */ +#define ZWLR_OUTPUT_POWER_V1_DESTROY_SINCE_VERSION 1 + +/** @ingroup iface_zwlr_output_power_v1 */ +static inline void +zwlr_output_power_v1_set_user_data(struct zwlr_output_power_v1 *zwlr_output_power_v1, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) zwlr_output_power_v1, user_data); +} + +/** @ingroup iface_zwlr_output_power_v1 */ +static inline void * +zwlr_output_power_v1_get_user_data(struct zwlr_output_power_v1 *zwlr_output_power_v1) +{ + return wl_proxy_get_user_data((struct wl_proxy *) zwlr_output_power_v1); +} + +static inline uint32_t +zwlr_output_power_v1_get_version(struct zwlr_output_power_v1 *zwlr_output_power_v1) +{ + return wl_proxy_get_version((struct wl_proxy *) zwlr_output_power_v1); +} + +/** + * @ingroup iface_zwlr_output_power_v1 + * + * Set an output's power save mode to the given mode. The mode change + * is effective immediately. If the output does not support the given + * mode a failed event is sent. + */ +static inline void +zwlr_output_power_v1_set_mode(struct zwlr_output_power_v1 *zwlr_output_power_v1, uint32_t mode) +{ + wl_proxy_marshal_flags((struct wl_proxy *) zwlr_output_power_v1, + ZWLR_OUTPUT_POWER_V1_SET_MODE, NULL, wl_proxy_get_version((struct wl_proxy *) zwlr_output_power_v1), 0, mode); +} + +/** + * @ingroup iface_zwlr_output_power_v1 + * + * Destroys the output power management mode control object. + */ +static inline void +zwlr_output_power_v1_destroy(struct zwlr_output_power_v1 *zwlr_output_power_v1) +{ + wl_proxy_marshal_flags((struct wl_proxy *) zwlr_output_power_v1, + ZWLR_OUTPUT_POWER_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) zwlr_output_power_v1), WL_MARSHAL_FLAG_DESTROY); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/driver/wayland-protocols/wlr-output-power-management-unstable-v1-protocol.c b/driver/wayland-protocols/wlr-output-power-management-unstable-v1-protocol.c new file mode 100644 index 00000000..c5e671f0 --- /dev/null +++ b/driver/wayland-protocols/wlr-output-power-management-unstable-v1-protocol.c @@ -0,0 +1,76 @@ +/* Generated by wayland-scanner 1.23.1 */ + +/* + * Copyright © 2019 Purism SPC + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_output_interface; +extern const struct wl_interface zwlr_output_power_v1_interface; + +static const struct wl_interface *wlr_output_power_management_unstable_v1_types[] = { + NULL, + &zwlr_output_power_v1_interface, + &wl_output_interface, +}; + +static const struct wl_message zwlr_output_power_manager_v1_requests[] = { + { "get_output_power", "no", wlr_output_power_management_unstable_v1_types + 1 }, + { "destroy", "", wlr_output_power_management_unstable_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwlr_output_power_manager_v1_interface = { + "zwlr_output_power_manager_v1", 1, + 2, zwlr_output_power_manager_v1_requests, + 0, NULL, +}; + +static const struct wl_message zwlr_output_power_v1_requests[] = { + { "set_mode", "u", wlr_output_power_management_unstable_v1_types + 0 }, + { "destroy", "", wlr_output_power_management_unstable_v1_types + 0 }, +}; + +static const struct wl_message zwlr_output_power_v1_events[] = { + { "mode", "u", wlr_output_power_management_unstable_v1_types + 0 }, + { "failed", "", wlr_output_power_management_unstable_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwlr_output_power_v1_interface = { + "zwlr_output_power_v1", 1, + 2, zwlr_output_power_v1_requests, + 2, zwlr_output_power_v1_events, +}; + diff --git a/driver/wayland-protocols/wlr-output-power-management-unstable-v1.xml b/driver/wayland-protocols/wlr-output-power-management-unstable-v1.xml new file mode 100644 index 00000000..20dbb776 --- /dev/null +++ b/driver/wayland-protocols/wlr-output-power-management-unstable-v1.xml @@ -0,0 +1,128 @@ + + + + Copyright © 2019 Purism SPC + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + + + This protocol allows clients to control power management modes + of outputs that are currently part of the compositor space. The + intent is to allow special clients like desktop shells to power + down outputs when the system is idle. + + To modify outputs not currently part of the compositor space see + wlr-output-management. + + Warning! The protocol described in this file is experimental and + backward incompatible changes may be made. Backward compatible changes + may be added together with the corresponding interface version bump. + Backward incompatible changes are done by bumping the version number in + the protocol and interface names and resetting the interface version. + Once the protocol is to be declared stable, the 'z' prefix and the + version number in the protocol and interface names are removed and the + interface version number is reset. + + + + + This interface is a manager that allows creating per-output power + management mode controls. + + + + + Create an output power management mode control that can be used to + adjust the power management mode for a given output. + + + + + + + + All objects created by the manager will still remain valid, until their + appropriate destroy request has been called. + + + + + + + This object offers requests to set the power management mode of + an output. + + + + + + + + + + + + + + Set an output's power save mode to the given mode. The mode change + is effective immediately. If the output does not support the given + mode a failed event is sent. + + + + + + + Report the power management mode change of an output. + + The mode event is sent after an output changed its power + management mode. The reason can be a client using set_mode or the + compositor deciding to change an output's mode. + This event is also sent immediately when the object is created + so the client is informed about the current power management mode. + + + + + + + This event indicates that the output power management mode control + is no longer valid. This can happen for a number of reasons, + including: + - The output doesn't support power management + - Another client already has exclusive power management mode control + for this output + - The output disappeared + + Upon receiving this event, the client should destroy this object. + + + + + + Destroys the output power management mode control object. + + + + diff --git a/driver/xdg-shell-v1-client-protocol.h b/driver/wayland-protocols/xdg-shell-v1-client-protocol.h similarity index 100% rename from driver/xdg-shell-v1-client-protocol.h rename to driver/wayland-protocols/xdg-shell-v1-client-protocol.h diff --git a/driver/xdg-shell-v1-protocol.c b/driver/wayland-protocols/xdg-shell-v1-protocol.c similarity index 100% rename from driver/xdg-shell-v1-protocol.c rename to driver/wayland-protocols/xdg-shell-v1-protocol.c diff --git a/driver/xdg-shell.xml b/driver/wayland-protocols/xdg-shell.xml similarity index 100% rename from driver/xdg-shell.xml rename to driver/wayland-protocols/xdg-shell.xml diff --git a/driver/windows.c b/driver/windows.c index c30a0ea7..119241f2 100644 --- a/driver/windows.c +++ b/driver/windows.c @@ -479,20 +479,25 @@ blank_screen (saver_info *si) Bool grabbing_supported_p = True; initialize_screensaver_window (si); - sync_server_dpms_settings (si->dpy, p); + sync_server_dpms_settings (si); /* Under Wayland, we can only grab screenshots if "grim" is installed, and even so, there's no way to grab screenshots under GNOME or KDE. See comment in xscreensaver-getimage.c, and discussion thread here: https://www.jwz.org/blog/2025/06/wayland-screenshots/#comment-260326 */ - if (getenv ("WAYLAND_DISPLAY") || getenv ("WAYLAND_SOCKET")) + if ( +# ifdef HAVE_WAYLAND + si->wayland_dpy || +# endif + (getenv ("WAYLAND_DISPLAY") || getenv ("WAYLAND_SOCKET"))) { const char *prog = "grim"; char *desk = getenv ("XDG_CURRENT_DESKTOP"); if (desk && (strcasestr (desk, "GNOME") || - strcasestr (desk, "KDE"))) + strcasestr (desk, "KDE") || + strcasestr (desk, "plasma"))) { grabbing_supported_p = False; if (p->verbose_p || p->fade_p || p->unfade_p || p->grab_desktop_p) @@ -526,6 +531,8 @@ blank_screen (saver_info *si) ssi->screenshot = screenshot_grab (si->dpy, ssi->screensaver_window, False, p->verbose_p); + if (ssi->screenshot) + screenshot_save (si->dpy, ssi->screensaver_window, ssi->screenshot); } if (p->fade_p && @@ -1058,17 +1065,16 @@ static void watchdog_timer (XtPointer closure, XtIntervalId *id) { saver_info *si = (saver_info *) closure; - saver_preferences *p = &si->prefs; Bool running_p, on_p, terminating_p; /* If the DPMS settings on the server have changed, change them back to what ~/.xscreensaver says they should be. */ - sync_server_dpms_settings (si->dpy, p); + sync_server_dpms_settings (si); /* If the wall clock tells us that the monitor should be powered off now, and the auth dialog is not currently on screen, make sure that the monitor is off. */ - brute_force_dpms (si->dpy, p, + brute_force_dpms (si, (si->auth_p ? 0 : si->activity_time)); @@ -1080,7 +1086,7 @@ watchdog_timer (XtPointer closure, XtIntervalId *id) raise_windows (si); running_p = any_screenhacks_running_p (si); - on_p = monitor_powered_on_p (si->dpy); + on_p = monitor_powered_on_p (si); terminating_p = si->terminating_p; if (running_p && !on_p) { diff --git a/driver/xscreensaver-gfx.c b/driver/xscreensaver-gfx.c index b6e6c6ab..76de5bd9 100644 --- a/driver/xscreensaver-gfx.c +++ b/driver/xscreensaver-gfx.c @@ -51,6 +51,11 @@ # include #endif +#ifdef HAVE_WAYLAND +# include "wayland-dpy.h" +# include "wayland-dpms.h" +#endif + #include "xscreensaver.h" #include "version.h" #include "atoms.h" @@ -103,7 +108,7 @@ maybe_reload_init_file (saver_info *si) /* If the DPMS settings in the init file have changed, change the settings on the server to match. This also would have happened at the watchdog timer. */ - sync_server_dpms_settings (si->dpy, p); + sync_server_dpms_settings (si); } } @@ -193,14 +198,13 @@ connect_to_server (saver_info *si) } else { - if (p->verbose_p || - !(getenv ("WAYLAND_DISPLAY") || getenv ("WAYLAND_SOCKET"))) + if (p->verbose_p) fprintf (stderr, "%s: xscreensaver does not seem to be running!\n", blurb()); - /* Under normal circumstances, that window should have been created - by the "xscreensaver" process. But if for some reason someone - has run "xscreensaver-gfx" directly (Wayland?) we need this window + /* Under normal circumstances, that window should have been created by + the "xscreensaver" process. But if for some reason someone has run + "xscreensaver-gfx" directly (Wayland swayidle?) we need this window to exist for ClientMessages to be receivable. So let's make one. */ XClassHint class_hints; @@ -222,14 +226,16 @@ connect_to_server (saver_info *si) daemon_window = XCreateWindow (si->dpy, RootWindow (si->dpy, 0), 0, 0, 1, 1, 0, DefaultDepth (si->dpy, 0), InputOutput, - DefaultVisual (si->dpy, 0), attrmask, &attrs); + DefaultVisual (si->dpy, 0), + attrmask, &attrs); XStoreName (si->dpy, daemon_window, "XScreenSaver GFX"); XSetClassHint (si->dpy, daemon_window, &class_hints); XChangeProperty (si->dpy, daemon_window, XA_WM_COMMAND, XA_STRING, 8, PropModeReplace, (unsigned char *) progname, strlen (progname)); - XChangeProperty (si->dpy, daemon_window, XA_SCREENSAVER_VERSION, XA_STRING, - 8, PropModeReplace, (unsigned char *) version_number, + XChangeProperty (si->dpy, daemon_window, XA_SCREENSAVER_VERSION, + XA_STRING, 8, PropModeReplace, + (unsigned char *) version_number, strlen (version_number)); XChangeProperty (si->dpy, daemon_window, XA_SCREENSAVER_ID, XA_STRING, 8, PropModeReplace, (unsigned char *) id, strlen (id)); @@ -451,6 +457,16 @@ debug_multiscreen_timer (XtPointer closure, XtIntervalId *id) #endif /* DEBUG_MULTISCREEN */ +#ifdef HAVE_WAYLAND +static void +wayland_dpy_cb (XtPointer closure, int *source, XtInputId *id) +{ + saver_info *si = (saver_info *) closure; + wayland_dpy_process_events (si->wayland_dpy, False); +} +#endif /* HAVE_WAYLAND */ + + static void main_loop (saver_info *si, Bool init_p) { @@ -459,6 +475,19 @@ main_loop (saver_info *si, Bool init_p) if (init_p && p->verbose_p) print_available_extensions (si); +# ifdef HAVE_WAYLAND + si->wayland_dpy = wayland_dpy_connect(); + if (si->wayland_dpy) + { + /* Process input on the Wayland socket. */ + int fd = wayland_dpy_get_fd (si->wayland_dpy); + XtAppAddInput (si->app, fd, + (XtPointer) (XtInputReadMask | XtInputExceptMask), + wayland_dpy_cb, (XtPointer) si); + si->wayland_dpms = wayland_dpms_init (si->wayland_dpy); + } +# endif /* HAVE_WAYLAND */ + initialize_randr (si); update_screen_layout (si); diff --git a/driver/xscreensaver.c b/driver/xscreensaver.c index c30d651f..b0c637e3 100644 --- a/driver/xscreensaver.c +++ b/driver/xscreensaver.c @@ -237,6 +237,7 @@ #include #ifdef HAVE_WAYLAND +# include "wayland-dpy.h" # include "wayland-idle.h" #endif @@ -356,6 +357,15 @@ saver_exit (int status) } +#ifdef HAVE_WAYLAND +static void +saver_wayland_exit (void *closure) +{ + saver_exit (1); +} +#endif + + static void catch_signal (int sig, RETSIGTYPE (*handler) (int)) { @@ -1526,39 +1536,33 @@ main_loop (Display *dpy) # ifdef HAVE_WAYLAND Bool wayland_active_p = False; - const char *wayland_err = 0; - wayland_state *wayland = wayland_idle_init (wayland_activity_cb, - &wayland_active_p, - &wayland_err); - if (wayland) + wayland_dpy *wdpy = wayland_dpy_connect(); + wayland_idle *widle = wayland_idle_init (wdpy, + wayland_activity_cb, + &wayland_active_p); + if (widle) { - wayland_p = True; /* Connected to Wayland */ + wayland_p = True; /* Connected to Wayland and can detect activity. */ } - else if (wayland_err && !strcmp (wayland_err, "connection failed")) + else if (wdpy) { - if (getenv ("WAYLAND_DISPLAY") || getenv ("WAYLAND_SOCKET")) - { - /* Running under Wayland, but unable to connect. */ - fprintf (stderr, "%s: wayland: %s\n", blurb(), wayland_err); - exit (1); - } - else - { - /* Running under real X11, presumably. */ - if (verbose_p) - fprintf (stderr, "%s: wayland: %s (assuming real X11)\n", - blurb(), wayland_err); - } + /* Connected to Wayland, but no idle protocols available. */ + fprintf (stderr, "%s: wayland: idle detection is impossible.\n", + blurb()); + exit (1); } - else if (wayland_err) + else if (getenv ("WAYLAND_DISPLAY") || getenv ("WAYLAND_SOCKET")) { - /* Connected to Wayland, but initialization failed. */ - fprintf (stderr, "%s: wayland: %s\n", blurb(), wayland_err); + /* Running under Wayland, but unable to connect. */ + fprintf (stderr, "%s: wayland: connection failed\n", blurb()); exit (1); } else - abort(); - + { + if (verbose_p) + fprintf (stderr, "%s: wayland: connection failed; assuming real X11\n", + blurb()); + } # else /* !HAVE_WAYLAND */ if (getenv ("WAYLAND_DISPLAY") || getenv ("WAYLAND_SOCKET")) @@ -1575,6 +1579,11 @@ main_loop (Display *dpy) if (! init_xinput (dpy, &xi_opcode)) saver_exit (1); +# ifdef HAVE_WAYLAND + if (wdpy) + wayland_dpy_atexit (wdpy, saver_wayland_exit, NULL); +# endif + /* Disable server built-in screen saver. */ XSetScreenSaver (dpy, 0, 0, 0, 0); XForceScreenSaver (dpy, ScreenSaverReset); @@ -1715,9 +1724,9 @@ main_loop (Display *dpy) # ifdef HAVE_WAYLAND /* Stop blocking if there is activity on either the X11 socket or the Wayland socket. */ - if (wayland) + if (wdpy) { - int wfd = wayland_idle_get_fd (wayland); + int wfd = wayland_dpy_get_fd (wdpy); FD_SET (wfd, &in_fds); fd = MAX (xfd, wfd); } @@ -2122,9 +2131,9 @@ main_loop (Display *dpy) # ifdef HAVE_WAYLAND - if (wayland) + if (wdpy) { - wayland_idle_process_events (wayland); + wayland_dpy_process_events (wdpy, False); if (wayland_active_p) { active_at = now; diff --git a/driver/xscreensaver.h b/driver/xscreensaver.h index a3e4926c..ce302b0b 100644 --- a/driver/xscreensaver.h +++ b/driver/xscreensaver.h @@ -39,9 +39,8 @@ extern char *progclass; extern Bool ensure_no_screensaver_running (Display *, Screen *); /* Display Power Management System (DPMS) interface. */ -extern Bool monitor_powered_on_p (Display *); -extern void monitor_power_on (saver_info *si, Bool on_p); - +extern Bool monitor_powered_on_p (saver_info *); +extern void monitor_power_on (saver_info *, Bool on_p); /* ======================================================================= blanking diff --git a/driver/xscreensaver.man b/driver/xscreensaver.man index 2131a541..72ba13d5 100644 --- a/driver/xscreensaver.man +++ b/driver/xscreensaver.man @@ -338,16 +338,19 @@ This is because the GNOME compositor does not support either of the Wayland protocols that allow us to tell when the user is idle. It works with KDE and most other compositors, however. .TP 3 -\fB2:\fP Even a single pixel of mouse motion will cause the screen to -un-blank: there is no pointer hysteresis. +\fB2:\fP No mouse hystersis. + +Even a single pixel of mouse motion will cause the screen to un-blank. + .TP 3 -\fB2:\fP Fading in and out might not work; hacks that grab and manipulate -a desktop screenshot might not work. +\fB3:\fP Fading and screenshots might not work. -Under Wayland, these features depend on the program +Under Wayland, Fading in and out, and allowing hacks to grab and +manipulate a desktop screenshot, depend on the program +.BR grim (1) +being installed to grab screenshots for us. And .BR grim (1) -being installed to grab screenshots for us. And \fBgrim\fP doesn't work -under the GNOME or KDE compositors. +doesn't work under the GNOME or KDE compositors. .RE For XScreenSaver to be able to lock, you will need to switch off diff --git a/hacks/config/README b/hacks/config/README index e1400fc9..1177e6c4 100644 --- a/hacks/config/README +++ b/hacks/config/README @@ -4,8 +4,8 @@ a screen saver and locker for the X window system by Jamie Zawinski - version 6.11 - 01-Jul-2025 + version 6.12 + 07-Jul-2025 https://www.jwz.org/xscreensaver/ diff --git a/hacks/glx/Makefile.in b/hacks/glx/Makefile.in index 043ff6ec..d6b7dc93 100644 --- a/hacks/glx/Makefile.in +++ b/hacks/glx/Makefile.in @@ -27,7 +27,7 @@ HACK_CONF_DIR = @HACK_CONF_DIR@ CC = @CC@ CFLAGS = @CFLAGS@ LDFLAGS = @LDFLAGS@ -DEFS = -DSTANDALONE -DUSE_GL @DEFS@ +DEFS = -DSTANDALONE @GL_CFLAGS@ @DEFS@ LIBS = @LIBS@ PERL = @PERL@ @@ -633,7 +633,7 @@ xscreensaver-gl-visual: $(GLH1) $(GLH2) # These hacks use a slightly-differently-compiled variant of recanim.c. # This is how to make the the other .o file from it. # -XLM_CFLAGS=-DUSE_GL $(INCLUDES) $(DEFS) $(CPPFLAGS) $(CFLAGS) $(X_CFLAGS) +XLM_CFLAGS=@GL_CFLAGS@ $(INCLUDES) $(DEFS) $(CPPFLAGS) $(CFLAGS) $(X_CFLAGS) recanim-gl.o: $(HACK_SRC)/recanim.c $(CC) -o $@ -c $(XLM_CFLAGS) $(HACK_SRC)/recanim.c @@ -5386,10 +5386,12 @@ xlock-gl-utils.o: $(UTILS_SRC)/grabclient.h xlock-gl-utils.o: $(UTILS_SRC)/hsv.h xlock-gl-utils.o: $(UTILS_SRC)/resources.h xlock-gl-utils.o: $(UTILS_SRC)/usleep.h +xlock-gl-utils.o: $(UTILS_SRC)/visual-gl.h xlock-gl-utils.o: $(UTILS_SRC)/visual.h xlock-gl-utils.o: $(UTILS_SRC)/xft.h xlock-gl-utils.o: $(UTILS_SRC)/yarandom.h xlock-gl-utils.o: $(HACK_SRC)/xlockmoreI.h xscreensaver-gl-visual.o: ../../config.h +xscreensaver-gl-visual.o: $(UTILS_SRC)/visual-gl.h xscreensaver-gl-visual.o: $(UTILS_SRC)/visual.h diff --git a/hacks/glx/mapscroller.c b/hacks/glx/mapscroller.c index d40fa355..659ae14a 100644 --- a/hacks/glx/mapscroller.c +++ b/hacks/glx/mapscroller.c @@ -1,4 +1,4 @@ -/* mapscroller, Copyright © 2021-2023 Jamie Zawinski +/* mapscroller, Copyright © 2021-2025 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -89,6 +89,7 @@ typedef struct { typedef struct { GLXContext *glx_context; char *url_template; + char *loader; int map_level; GLfloat speed; int duration; @@ -102,7 +103,7 @@ typedef struct { Bool ocean_p; enum { FADE_OUT, RUN } mode; - time_t change_time; + time_t start_time, change_time; double opacity; pid_t pid; @@ -658,7 +659,7 @@ fork_loader (ModeInfo *mi) int fd1[2], fd2[2]; int ac = 0; - av[ac++] = get_string_resource (mi->dpy, "loaderProgram", "Program"); + av[ac++] = bp->loader; if (verbose_p == 1) av[ac++] = "-v"; if (verbose_p == 2) av[ac++] = "-vv"; else if (verbose_p == 3) av[ac++] = "-vvv"; @@ -1097,6 +1098,7 @@ init_map (ModeInfo *mi) bp->font_data = load_texture_font (mi->dpy, "titleFont"); + bp->loader = get_string_resource (mi->dpy, "loaderProgram", "Program"); bp->url_template = url_template_arg; if (!bp->url_template || !*bp->url_template || @@ -1155,7 +1157,8 @@ init_map (ModeInfo *mi) bp->mode = RUN; bp->opacity = 1; - bp->change_time = time ((time_t *) 0); + bp->start_time = time ((time_t *) 0); + bp->change_time = bp->start_time; fork_loader (mi); reshape_map (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); @@ -1187,6 +1190,7 @@ draw_map (ModeInfo *mi) map_configuration *bp = &bps[MI_SCREEN(mi)]; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); + time_t now = time ((time_t *) 0); if (!bp->glx_context) return; @@ -1275,7 +1279,6 @@ draw_map (ModeInfo *mi) if (!strcasecmp (origin_arg, "random") || !strcasecmp (origin_arg, "random-city")) { - time_t now = time ((time_t *) 0); if (force_change_p || (bp->mode == RUN && now > bp->change_time + bp->duration)) @@ -1407,24 +1410,36 @@ draw_map (ModeInfo *mi) MI_WIDTH(mi), MI_HEIGHT(mi), 1, buf); } - if (bp->dead_p) + if (bp->dead_p || + (bp->tile_count == 0 && + now >= bp->start_time + 5)) { - static char buf[1024] = ""; - if (! *buf) - { - char *s = get_string_resource (mi->dpy, "loaderProgram", "Program"); - sprintf (buf, "\n\n\n\n\n\n%.100s subprocess died.", s); - free (s); - if (bp->tile_count < 10) - strcat (buf, - " Is Perl broken? Maybe try:\n\n" - "sudo cpan LWP::Simple LWP::Protocol::https Mozilla::CA"); - } + char buf[1024]; + char *s = buf; + *s = 0; + strcat (s, "\n\n\n\n\n\n"); + s += strlen (s); + if (bp->dead_p) + sprintf (s, "%.100s subprocess died.", bp->loader); + else + sprintf (s, "%.100s subprocess produced no tiles.", bp->loader); + s += strlen (s); + + if (! bp->dead_p) + strcat (s, " Network problem?"); + s += strlen (s); + + if (bp->tile_count < 10) + strcat (s, + " Is Perl broken? Maybe try:\n\n" + "sudo cpan LWP::Simple LWP::Protocol::https Mozilla::CA"); + glColor3f (0.3, 0.3, 0.3); print_texture_label (mi->dpy, bp->font_data, MI_WIDTH(mi), MI_HEIGHT(mi), 0, buf); } + if (mi->fps_p && !bp->dead_p) { if (!MI_IS_WIREFRAME(mi)) diff --git a/hacks/glx/mapscroller.pl b/hacks/glx/mapscroller.pl index 984cf4d6..f8a22c10 100755 --- a/hacks/glx/mapscroller.pl +++ b/hacks/glx/mapscroller.pl @@ -29,7 +29,7 @@ BEGIN { eval 'use LWP::Simple' } my $progname = $0; $progname =~ s@.*/@@g; $progname =~ s@\.pl$@@g; -my ($version) = ('$Revision: 1.9 $' =~ m/\s(\d[.\d]+)\s/s); +my ($version) = ('$Revision: 1.10 $' =~ m/\s(\d[.\d]+)\s/s); my $verbose = 0; my $url_template = undef; diff --git a/hacks/glx/xlock-gl-utils.c b/hacks/glx/xlock-gl-utils.c index bd9c990e..1d349206 100644 --- a/hacks/glx/xlock-gl-utils.c +++ b/hacks/glx/xlock-gl-utils.c @@ -18,6 +18,7 @@ #ifdef HAVE_GL /* whole file */ +#include "visual-gl.h" #include "texfont.h" #ifndef isupper @@ -28,27 +29,6 @@ #endif -# ifndef HAVE_EGL -/* Gag -- we use this to turn X errors from glXCreateContext() into - something that will actually make sense to the user. - */ -static XErrorHandler orig_ehandler = 0; -static Bool got_error = 0; - -static int -BadValue_ehandler (Display *dpy, XErrorEvent *error) -{ - if (error->error_code == BadValue) - { - got_error = True; - return 0; - } - else - return orig_ehandler (dpy, error); -} -#endif /* !HAVE_EGL */ - - #ifndef HAVE_JWZGLES # undef glEnable void (* glEnable_fn) (GLuint) = glEnable; @@ -72,9 +52,6 @@ init_GL(ModeInfo * mi) Display *dpy = mi->dpy; Window window = mi->window; Screen *screen = mi->xgwa.screen; - Visual *visual = mi->xgwa.visual; - XVisualInfo vi_in, *vi_out; - int out_count; if (mi->glx_context) { glXMakeCurrent (dpy, window, mi->glx_context); @@ -88,177 +65,7 @@ init_GL(ModeInfo * mi) mi->xlmft->jwzgles_make_current (mi->jwzgles_state); # endif - vi_in.screen = screen_number (screen); - vi_in.visualid = XVisualIDFromVisual (visual); - vi_out = XGetVisualInfo (dpy, VisualScreenMask|VisualIDMask, - &vi_in, &out_count); - if (! vi_out) abort (); - -# ifdef HAVE_EGL - { - egl_data *d = (egl_data *) calloc (1, sizeof(*d)); - - /* The correct EGL config has been selected by utils/visual-gl.c - (via hacks/glx/xscreensaver-gl-visual) by calling get_egl_config() - from get_gl_visual and returning the corresponding X11 Visual. - That visual is the one that was used to create our window. We will - pass the corresponding visual ID to get_egl_config() to obtain the - same configuration here. */ - unsigned int vid = XVisualIDFromVisual (visual); - - const EGLint ctxattr1[] = { -# ifdef HAVE_JWZGLES - EGL_CONTEXT_MAJOR_VERSION, 1, /* Request an OpenGL ES 1.1 context. */ - EGL_CONTEXT_MINOR_VERSION, 1, -# else - EGL_CONTEXT_MAJOR_VERSION, 1, /* Request an OpenGL 1.3 context. */ - EGL_CONTEXT_MINOR_VERSION, 3, -# endif - EGL_NONE - }; - const EGLint *ctxattr = ctxattr1; - -# ifdef HAVE_GLES3 - const EGLint ctxattr3[] = { - EGL_CONTEXT_MAJOR_VERSION, 3, /* Request an OpenGL ES 3.0 context. */ - EGL_CONTEXT_MINOR_VERSION, 0, - EGL_NONE - }; - - if (get_boolean_resource (dpy, "prefersGLSL", "PrefersGLSL")) - ctxattr = ctxattr3; -# endif /* HAVE_GLES3 */ - - /* This is re-used, no need to close it. */ - d->egl_display = eglGetPlatformDisplay (EGL_PLATFORM_X11_KHR, - (void *) dpy, NULL); - if (!d->egl_display) - { - fprintf (stderr, "%s: eglGetPlatformDisplay failed\n", progname); - abort(); - } - - get_egl_config (dpy, d->egl_display, vid, &d->egl_config); - if (!d->egl_config) - { - /* get_egl_config already printed this: - fprintf (stderr, "%s: no matching EGL config for X11 visual 0x%lx\n", - progname, vi_out->visualid); */ - /* returning 0 might be reasonable, but makes all the GL hacks - simply draw nothing in a loop. */ - exit (1); - } - - d->egl_surface = eglCreatePlatformWindowSurface (d->egl_display, - d->egl_config, - &window, NULL); - if (! d->egl_surface) - { - fprintf (stderr, "%s: eglCreatePlatformWindowSurface failed:" - " window 0x%lx visual 0x%x\n", progname, window, vid); - abort(); - } - -#ifdef HAVE_JWZGLES - /* This call is not strictly necessary to get an OpenGL ES context - since the default API is EGL_OPENGL_ES_API, but it makes our - intention clear. - */ - if (!eglBindAPI (EGL_OPENGL_ES_API)) - { - fprintf (stderr, "%s: eglBindAPI failed\n", progname); - } -#else /* !HAVE_JWZGLES */ - /* This is necessary to get a OpenGL context instead of an OpenGLES - context. - */ - if (!eglBindAPI (EGL_OPENGL_API)) - { - fprintf (stderr, "%s: eglBindAPI failed\n", progname); - } -#endif /* !HAVE_JWZGLES */ - - d->egl_context = eglCreateContext (d->egl_display, d->egl_config, - EGL_NO_CONTEXT, ctxattr); - -# ifdef HAVE_GLES3 - /* If creation of a GLES 3.0 context failed, fall back to GLES 1.x. */ - if (!d->egl_context && ctxattr != ctxattr1) - { - /* fprintf (stderr, "%s: eglCreateContext 3.0 failed\n", progname); */ - d->egl_context = eglCreateContext (d->egl_display, d->egl_config, - EGL_NO_CONTEXT, ctxattr1); - } -# endif /* HAVE_GLES3 */ - - if (!d->egl_context) - { - fprintf (stderr, "%s: eglCreateContext failed\n", progname); - abort(); - } - - /* describe_gl_visual (stderr, screen, visual, False); */ - - mi->glx_context = d; /* #### leaked */ - - glXMakeCurrent (dpy, window, mi->glx_context); - } -# else /* GLX */ - { - XSync (dpy, False); - orig_ehandler = XSetErrorHandler (BadValue_ehandler); - mi->glx_context = glXCreateContext (dpy, vi_out, 0, GL_TRUE); - XSync (dpy, False); - XSetErrorHandler (orig_ehandler); - if (got_error) - mi->glx_context = 0; - } - - if (!mi->glx_context) - { - fprintf(stderr, "%s: couldn't create GL context for visual 0x%x.\n", - progname, (unsigned int) XVisualIDFromVisual (visual)); - exit(1); - } - - glXMakeCurrent (dpy, window, mi->glx_context); - - { - GLboolean rgba_mode = 0; - glGetBooleanv(GL_RGBA_MODE, &rgba_mode); - if (!rgba_mode) - { - glIndexi (WhitePixelOfScreen (screen)); - glClearIndex (BlackPixelOfScreen (screen)); - } - } -# endif /* GLX */ - - XFree((char *) vi_out); - - - /* jwz: the doc for glDrawBuffer says "The initial value is GL_FRONT - for single-buffered contexts, and GL_BACK for double-buffered - contexts." However, I find that this is not always the case, - at least with Mesa 3.4.2 -- sometimes the default seems to be - GL_FRONT even when glGet(GL_DOUBLEBUFFER) is true. So, let's - make sure. - - Oh, hmm -- maybe this only happens when we are re-using the - xscreensaver window, and the previous GL hack happened to die with - the other buffer selected? I'm not sure. Anyway, this fixes it. - */ - { - GLboolean d = False; - glGetBooleanv (GL_DOUBLEBUFFER, &d); - if (d) - glDrawBuffer (GL_BACK); - else - glDrawBuffer (GL_FRONT); - } - - /* Sometimes glDrawBuffer() throws "invalid op". Dunno why. Ignore. */ - clear_gl_error (); + mi->glx_context = openGL_context_for_window (screen, window); /* Process the -background argument. */ { diff --git a/hacks/glx/xscreensaver-gl-visual.c b/hacks/glx/xscreensaver-gl-visual.c index 9fc3b81f..653aa141 100644 --- a/hacks/glx/xscreensaver-gl-visual.c +++ b/hacks/glx/xscreensaver-gl-visual.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2000-2021 by Jamie Zawinski +/* xscreensaver, Copyright © 2000-2025 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -31,6 +31,7 @@ #include #include "visual.h" +#include "visual-gl.h" char *progname = 0; char *progclass = "XScreenSaver"; diff --git a/hacks/screenhack.c b/hacks/screenhack.c index 6a582e07..a127a7de 100644 --- a/hacks/screenhack.c +++ b/hacks/screenhack.c @@ -290,7 +290,8 @@ MapNotify_event_p (Display *dpy, XEvent *event, XPointer window) } -static Atom XA_WM_PROTOCOLS, XA_WM_DELETE_WINDOW, XA_NET_WM_PID; +static Atom XA_WM_PROTOCOLS, XA_WM_DELETE_WINDOW, XA_NET_WM_PID, + XA_NET_WM_PING; /* Dead-trivial event handling: exits if "q" or "ESC" are typed. Exit if the WM_PROTOCOLS WM_DELETE_WINDOW ClientMessage is received. @@ -327,7 +328,18 @@ screenhack_handle_event_1 (Display *dpy, XEvent *event) fprintf (stderr, "%s: unknown ClientMessage %s received!\n", progname, s); } - else if (event->xclient.data.l[0] != XA_WM_DELETE_WINDOW) + else if (event->xclient.data.l[0] == XA_WM_DELETE_WINDOW) + { + return False; /* exit */ + } + else if (event->xclient.data.l[0] == XA_NET_WM_PING) + { + event->xclient.window = DefaultRootWindow (dpy); + if (! XSendEvent (dpy, event->xclient.window, False, + PropertyChangeMask, event)) + fprintf (stderr, "%s: WM_PONG failed\n", progname); + } + else { char *s1 = XGetAtomName(dpy, event->xclient.message_type); char *s2 = XGetAtomName(dpy, event->xclient.data.l[0]); @@ -336,10 +348,6 @@ screenhack_handle_event_1 (Display *dpy, XEvent *event) fprintf (stderr, "%s: unknown ClientMessage %s[%s] received!\n", progname, s1, s2); } - else - { - return False; /* exit */ - } } break; } @@ -812,6 +820,7 @@ main (int argc, char **argv) XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False); XA_WM_DELETE_WINDOW = XInternAtom (dpy, "WM_DELETE_WINDOW", False); XA_NET_WM_PID = XInternAtom (dpy, "_NET_WM_PID", False); + XA_NET_WM_PING = XInternAtom (dpy, "_NET_WM_PING", False); { char *v = (char *) strdup(strchr(screensaver_id, ' ')); diff --git a/hacks/xlockmoreI.h b/hacks/xlockmoreI.h index 3892e58e..be536e5b 100644 --- a/hacks/xlockmoreI.h +++ b/hacks/xlockmoreI.h @@ -1,5 +1,5 @@ /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules. - * xscreensaver, Copyright (c) 1997-2021 Jamie Zawinski + * xscreensaver, Copyright © 1997-2025 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -44,13 +44,6 @@ typedef struct ModeInfo ModeInfo; #endif /* !HAVE_EGL */ #if defined(HAVE_EGL) && defined(USE_GL) - typedef struct egl_data { - EGLDisplay egl_display; - EGLSurface egl_surface; - EGLContext egl_context; /* Unused */ - EGLConfig egl_config; /* Unused */ - } egl_data; - extern Bool glXMakeCurrent (Display *, GLXDrawable, GLXContext); extern void glXSwapBuffers (Display *, GLXDrawable); #endif /* HAVE_EGL && USE_GL */ diff --git a/hacks/xscreensaver-getimage.c b/hacks/xscreensaver-getimage.c index 36468879..39eb8722 100644 --- a/hacks/xscreensaver-getimage.c +++ b/hacks/xscreensaver-getimage.c @@ -68,6 +68,66 @@ or KDE. They invented their own, incompatible APIs, which always play a camera noise and flash the screen white, and might also pop up a confirmation dialog. + + --------------------------------------------------------------------- + + Further notes on the Wayland screen-grabbing situation... + Which is absolute bugfuck insanity, I might add... + + Rather than exec'ing "grim", which may not be installed, we could + instead connect to the Wayland server directly and do the thing that + grim does, but that is an *enormous* amount of code, requiring four + or five nonstandard "staging" protocols: + + - "ext-image-capture-source-v1" and its required companion + "ext-image-copy-capture-v1" (and why they aren't the same thing, + I could not tell you); + - And "ext-foreign-toplevel-list-v1" which they also depend on; + - And "zxdg-output-manager-v1", because without that, a "wl_output" + will tell you its size but not its position. It's + Heisenbergisterical! + + Once you've done that, you have to figure out what rectangle you want + from the source outputs. Easy right? Except that they might be rotated, + mirrored or scaled arbitrarily (e.g. "retina"), and you have to + recapitulate that in the grabbed image. Look at the madness in grim's + render.c. + + So pretty much the only part you can leave out is the "write a PNG + file" bit. The rest of grim's ~1,800 lines of code is insanely + complicated and sadly necessary. + + It would be easier for me to just include grim with XScreenSaver. + + + Grim does not support GNOME or KDE, which provide four (4) different + interfaces for us to also not support: + + - GNOME has a DBus endpoint, "org.gnome.Shell.Screenshot", but it's + not clear to me whether it is possible to use it without an + interactive dialog popping up, a shutter sound, and a screen flash: + https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/data/dbus-interfaces/org.gnome.Shell.Screenshot.xml + + - KDE also has a DBus endpoint, "org.kde.KWin.ScreenShot2", which + says: "The application that requests the screenshot must have the + org.kde.KWin.ScreenShot2 interface listed in the + X-KDE-DBUS-Restricted-Interfaces desktop file entry." This may also + do the mandatory "ask for permission, shutter sound, flash" thing + that GNOME does, I can't tell: + https://invent.kde.org/plasma/kwin/-/blob/master/src/plugins/screenshot/org.kde.KWin.ScreenShot2.xml + + - Supposedly KDE and GNOME also support the DBus endpoint + "org.freedesktop.portal.Screenshot", but I imagine that's just a + wrapper around their native versions with all the same downsides: + https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Screenshot.html + + - Back in the Wayland world, there is "kde-zkde-screencast-unstable" + https://wayland.app/protocols/kde-zkde-screencast-unstable-v1 + Does this one require the user to click OK first? Probably, but who + can tell? + + More discussion and links in this thread: + https://www.jwz.org/blog/2025/06/wayland-screenshots/#comment-260369 */ #include "utils.h" @@ -96,9 +156,7 @@ #include "xmu.h" #include "vroot.h" #include "../driver/prefs.h" - -#include "../driver/blurb.c" /* Eh, this is awful but so what */ - +#include "../driver/blurb.c" #ifndef _XSCREENSAVER_VROOT_H_ # error Error! You have an old version of vroot.h! Check -I args. @@ -1122,11 +1180,10 @@ get_filename_1 (Screen *screen, Window window, sprintf (rect, "%d,%d,%d,%d", xgwa.x, xgwa.y, xgwa.width, xgwa.height); av[ac++] = GETIMAGE_SCREEN_PROGRAM; /* "screencapture" */ - av[ac++] = "-x"; /* no sound */ - av[ac++] = "-C"; /* capture mouse */ - av[ac++] = "-R"; /* rect */ + av[ac++] = "-x"; /* no sound */ + av[ac++] = "-R"; /* rect */ av[ac++] = rect; - av[ac++] = "-t"; /* file type */ + av[ac++] = "-t"; /* file type */ av[ac++] = "png"; av[ac++] = outfile; @@ -1135,10 +1192,9 @@ get_filename_1 (Screen *screen, Window window, sprintf (rect, "%d,%d %dx%d", xgwa.x, xgwa.y, xgwa.width, xgwa.height); av[ac++] = GETIMAGE_SCREEN_PROGRAM; /* "grim" */ - av[ac++] = "-c"; /* capture mouse */ - av[ac++] = "-g"; /* geometry */ + av[ac++] = "-g"; /* geometry */ av[ac++] = rect; - av[ac++] = "-t"; /* file type */ + av[ac++] = "-t"; /* file type */ av[ac++] = "png"; av[ac++] = outfile; # else diff --git a/po/POTFILES.in b/po/POTFILES.in index cc017eea..d3ea9ee6 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,4 +1,4 @@ -# Auto-generated: Tue Jul 1 18:29:55 PDT 2025 +# Auto-generated: Mon Jul 7 12:46:55 PDT 2025 driver/demo-Gtk-conf.c driver/demo-Gtk.c driver/demo.ui diff --git a/utils/Makefile.in b/utils/Makefile.in index 74781cdc..16190f74 100644 --- a/utils/Makefile.in +++ b/utils/Makefile.in @@ -1,4 +1,4 @@ -# utils/Makefile.in --- xscreensaver, Copyright © 1997-2023 Jamie Zawinski. +# utils/Makefile.in --- xscreensaver, Copyright © 1997-2025 Jamie Zawinski. # the `../configure' script generates `utils/Makefile' from this file. @@ -117,11 +117,11 @@ OBJS = alpha.o colors.o grabclient.o hsv.o \ async_netdb.o xft.o xftwrap.o utf8wc.o pow2.o font-retry.o \ screenshot.o HDRS = alpha.h colors.h grabclient.h hsv.h resources.h \ - spline.h usleep.h utils.h version.h visual.h vroot.h xmu.h \ - yarandom.h erase.h xshm.h xdbe.h colorbars.h minixpm.h \ - xscreensaver-intl.h textclient.h aligned_malloc.h \ - thread_util.h async_netdb.h xft.h xftwrap.h utf8wc.h pow2.h \ - font-retry.h queue.h screenshot.h + spline.h usleep.h utils.h version.h visual.h visual-gl.h \ + vroot.h xmu.h yarandom.h erase.h xshm.h xdbe.h colorbars.h \ + minixpm.h xscreensaver-intl.h textclient.h aligned_malloc.h \ + thread_util.h async_netdb.h xft.h xftwrap.h utf8wc.h pow2.h \ + font-retry.h queue.h screenshot.h STAR = * LOGOS = images/$(STAR).xpm \ images/$(STAR).png \ @@ -287,6 +287,7 @@ utf8wc.o: $(srcdir)/utf8wc.h visual-gl.o: ../config.h visual-gl.o: $(srcdir)/resources.h visual-gl.o: $(srcdir)/utils.h +visual-gl.o: $(srcdir)/visual-gl.h visual-gl.o: $(srcdir)/visual.h visual.o: ../config.h visual.o: $(srcdir)/resources.h diff --git a/utils/colorbars.c b/utils/colorbars.c index 3e2bc871..a5b11276 100644 --- a/utils/colorbars.c +++ b/utils/colorbars.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2001-2018 Jamie Zawinski +/* xscreensaver, Copyright © 2001-2025 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -18,6 +18,8 @@ #include "colorbars.h" #include "../hacks/ximage-loader.h" +#define LGBTQIA +#ifndef LGBTQIA /* SMPTE ECR-1-1978 */ static const char * const colors[7][18] = { { "#CCCCCC", "#FFFF00", "#00FFFF", "#00FF00", /* tall bars */ "#FF00FF", "#FF0000", "#0000FF", "#000000", @@ -45,11 +47,57 @@ static const char * const colors[7][18] = { "#FFFFFF", "#FFFFFF", "#FFFFFF", "#0000AD", "#0000AD", "#0000AD", "#131313", "#131313", "#131313", - "#000000", "#000000", "#262626", + "#000000", "#131313", "#262626", /* ramp */ "#000000", "#000000", "#000000" } }; +#else /* LGBTQIA pride flag colorbars designed by + Cable Contributes to Life -- + https://web.archive.org/web/20250701065803/https://bsky.app/profile/cctl.me/post/3lsthzde3h22g + "The first set of columns use the colors of the gay pride flag, + with the addition of the original SMPTE color on the final column. + The second set of columns contains two pride flags: the pansexual + flag horizontally, and the asexual flag flipped and horizontal. + The final set of columns contains the three colors of the + transgender flag and the two POC-inclusive colors, followed by + the original bar gradient from the SMPTE ECR-1-1978 pattern." + */ + +static const char * const colors[7][18] = { + { "#E40303", "#FF8C00", "#FFED00", "#008026", /* tall bars, pride */ + "#004CFF", "#732982", "#0000FF", + 0 + }, { + "#FF218C", "#FFD800", "#21B1FF", "#800080", /* short bars, pan a */ + "#FFFFFF", "#A3A3A3", "#000000", + 0 + }, { + "#000000", 0 /* blank */ + }, { + "#FFFFFF", "#EEEEEE", "#DDDDDD", "#CCCCCC", /* gray ramp */ + "#BBBBBB", "#AAAAAA", "#999999", "#888888", + "#777777", "#666666", "#555555", "#444444", + "#333333", "#222222", "#111111", "#000000" + }, { + "#000000", "#111111", "#222222", "#333333", /* gray rev ramp */ + "#444444", "#555555", "#666666", "#777777", + "#888888", "#999999", "#AAAAAA", "#BBBBBB", + "#CCCCCC", "#DDDDDD", "#EEEEEE", "#FFFFFF" + }, { + "#000000", 0 /* blank */ + }, { + "#5BCEFA", "#5BCEFA", "#5BCEFA", /* trans poc */ + "#F5A9B8", "#F5A9B8", "#F5A9B8", + "#FFFFFF", "#FFFFFF", "#FFFFFF", + "#613704", "#613704", "#613704", + "#000000", "#131313", "#262626", /* ramp */ + "#000000", "#000000", "#000000" + } +}; +#endif /* LGBTQIA */ + + static const int heights[7] = { 63, 10, 1, 5, 5, 1, 15 }; /* percentages */ diff --git a/utils/screenshot.c b/utils/screenshot.c index 85c67194..b51784b4 100644 --- a/utils/screenshot.c +++ b/utils/screenshot.c @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef HAVE_SYS_WAIT_H # include /* for waitpid() and associated macros */ @@ -84,6 +85,21 @@ ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error) } +static double +double_time (void) +{ + struct timeval now; +# ifdef GETTIMEOFDAY_TWO_ARGS + struct timezone tzp; + gettimeofday(&now, &tzp); +# else + gettimeofday(&now); +# endif + + return (now.tv_sec + ((double) now.tv_usec * 0.000001)); +} + + /* Grab a screenshot and return it. It will be the size and extent of the given window, or the full screen, as requested. @@ -102,6 +118,7 @@ screenshot_grab (Display *dpy, Window window, Bool full_screen_p, struct { int x, y, x2, y2; } root, win; XErrorHandler old_handler; Bool external_p = False; + double start = double_time(); XGetWindowAttributes (dpy, window, &win_xgwa); root_window = XRootWindowOfScreen (win_xgwa.screen); @@ -247,13 +264,24 @@ screenshot_grab (Display *dpy, Window window, Bool full_screen_p, XFreeGC (dpy, gc); } - if (verbose_p || !pixmap) - fprintf (stderr, "%s: %s screenshot 0x%lx %dx%d" - " for window 0x%lx %dx%d+%d+%d\n", blurb(), - (pixmap ? "saved" : "failed to save"), - (unsigned long) pixmap, win_xgwa.width, win_xgwa.height, - (unsigned long) window, - owin_xgwa.width, owin_xgwa.height, owin_xgwa.x, owin_xgwa.y); + { + double elapsed = double_time() - start; + char late[100]; + if (elapsed >= 0.75) + sprintf (late, " -- took %.1f seconds", elapsed); + else + *late = 0; + + if (verbose_p || !pixmap || *late) + fprintf (stderr, "%s: %s screenshot 0x%lx %dx%d" + " for window 0x%lx %dx%d+%d+%d%s\n", blurb(), + (pixmap ? "saved" : "failed to save"), + (unsigned long) pixmap, win_xgwa.width, win_xgwa.height, + (unsigned long) window, + owin_xgwa.width, owin_xgwa.height, owin_xgwa.x, owin_xgwa.y, + late); + } + return pixmap; } @@ -413,5 +441,6 @@ screenshot_load (Display *dpy, Window window, Bool verbose_p) (unsigned long) window, win_xgwa.width, win_xgwa.height, win_xgwa.x, win_xgwa.y, (unsigned long) screenshot, root.w, root.h); + return p2; } diff --git a/utils/version.h b/utils/version.h index 791a40a6..fb37b051 100644 --- a/utils/version.h +++ b/utils/version.h @@ -1,4 +1,4 @@ static const char screensaver_id[] = - "@(#)xscreensaver 6.11 (01-Jul-2025), by Jamie Zawinski (jwz@jwz.org)"; -#define XSCREENSAVER_VERSION "6.11" -#define XSCREENSAVER_RELEASED 1751396400 + "@(#)xscreensaver 6.12 (07-Jul-2025), by Jamie Zawinski (jwz@jwz.org)"; +#define XSCREENSAVER_VERSION "6.12" +#define XSCREENSAVER_RELEASED 1751914800 diff --git a/utils/visual-gl.c b/utils/visual-gl.c index dd8b994f..6b394298 100644 --- a/utils/visual-gl.c +++ b/utils/visual-gl.c @@ -33,7 +33,8 @@ # endif #endif /* HAVE_GL */ -#include "visual.h" /* after EGL/egl.h */ +#include "visual.h" +#include "visual-gl.h" /* after EGL/egl.h */ #undef countof #define countof(x) (sizeof(x)/sizeof(*(x))) @@ -485,7 +486,7 @@ describe_gl_visual (FILE *f, Screen *screen, Visual *visual, (value == GLX_NONE_EXT ? "none" : value == GLX_SLOW_VISUAL_EXT ? "slow" : value == GLX_NON_CONFORMANT_EXT ? "non-conformant" : - "???"); + "???")); # else fprintf (f, " GLX rating: %s\n", (value == GLX_NONE_EXT ? "none" : @@ -604,3 +605,251 @@ validate_gl_visual (FILE *out, Screen *screen, const char *window_desc, #endif /* !HAVE_GL */ } + + +# ifndef HAVE_EGL +/* Gag -- we use this to turn X errors from glXCreateContext() into + something that will actually make sense to the user. + */ +static XErrorHandler orig_ehandler = 0; +static Bool got_error = 0; + +static int +BadValue_ehandler (Display *dpy, XErrorEvent *error) +{ + if (error->error_code == BadValue) + { + got_error = True; + return 0; + } + else + return orig_ehandler (dpy, error); +} +#endif /* !HAVE_EGL */ + + +/* Initializes OpenGL and returns a GLXContext or egl_data for the window. + The window is assumed to have been created with the proper visual. + */ +#ifdef HAVE_EGL +egl_data *openGL_context_for_window (Screen *screen, Window window) +#else +GLXContext openGL_context_for_window (Screen *screen, Window window) +#endif +{ + Display *dpy = DisplayOfScreen (screen); + XWindowAttributes xgwa; + Visual *visual; + XVisualInfo vi_in, *vi_out; + int out_count; + +# ifdef HAVE_EGL + egl_data *egl_data_ret = NULL; +# else + GLXContext glx_context = NULL; +# endif + + XGetWindowAttributes (dpy, window, &xgwa); + visual = xgwa.visual; + + vi_in.screen = screen_number (screen); + vi_in.visualid = XVisualIDFromVisual (visual); + vi_out = XGetVisualInfo (dpy, VisualScreenMask|VisualIDMask, + &vi_in, &out_count); + if (! vi_out) abort (); + +# ifdef HAVE_EGL + { + egl_data *d = (egl_data *) calloc (1, sizeof(*d)); + + /* The correct EGL config has been selected by calling get_egl_config() + from get_gl_visual and returning the corresponding X11 Visual. + That visual is the one that was used to create the window. We will + pass the corresponding visual ID to get_egl_config() to obtain the + same configuration here. */ + unsigned int vid = XVisualIDFromVisual (visual); + + const EGLint ctxattr1[] = { +# ifdef HAVE_JWZGLES + EGL_CONTEXT_MAJOR_VERSION, 1, /* Request an OpenGL ES 1.1 context. */ + EGL_CONTEXT_MINOR_VERSION, 1, +# else + EGL_CONTEXT_MAJOR_VERSION, 1, /* Request an OpenGL 1.3 context. */ + EGL_CONTEXT_MINOR_VERSION, 3, +# endif + EGL_NONE + }; + const EGLint *ctxattr = ctxattr1; + +# ifdef HAVE_GLES3 + const EGLint ctxattr3[] = { + EGL_CONTEXT_MAJOR_VERSION, 3, /* Request an OpenGL ES 3.0 context. */ + EGL_CONTEXT_MINOR_VERSION, 0, + EGL_NONE + }; + + if (get_boolean_resource (dpy, "prefersGLSL", "PrefersGLSL")) + ctxattr = ctxattr3; +# endif /* HAVE_GLES3 */ + + /* This is re-used, no need to close it. */ + d->egl_display = eglGetPlatformDisplay (EGL_PLATFORM_X11_KHR, + (void *) dpy, NULL); + if (!d->egl_display) + { + fprintf (stderr, "%s: eglGetPlatformDisplay failed\n", progname); + abort(); + } + + get_egl_config (dpy, d->egl_display, vid, &d->egl_config); + if (!d->egl_config) + { + /* get_egl_config already printed this: + fprintf (stderr, "%s: no matching EGL config for X11 visual 0x%lx\n", + progname, vi_out->visualid); */ + /* returning 0 might be reasonable, but makes all the GL hacks + simply draw nothing in a loop. */ + exit (1); + } + + d->egl_surface = eglCreatePlatformWindowSurface (d->egl_display, + d->egl_config, + &window, NULL); + if (! d->egl_surface) + { + fprintf (stderr, "%s: eglCreatePlatformWindowSurface failed:" + " window 0x%lx visual 0x%x\n", progname, window, vid); + abort(); + } + +#ifdef HAVE_JWZGLES + /* This call is not strictly necessary to get an OpenGL ES context + since the default API is EGL_OPENGL_ES_API, but it makes our + intention clear. + */ + if (!eglBindAPI (EGL_OPENGL_ES_API)) + { + fprintf (stderr, "%s: eglBindAPI failed\n", progname); + } +#else /* !HAVE_JWZGLES */ + /* This is necessary to get a OpenGL context instead of an OpenGLES + context. + */ + if (!eglBindAPI (EGL_OPENGL_API)) + { + fprintf (stderr, "%s: eglBindAPI failed\n", progname); + } +#endif /* !HAVE_JWZGLES */ + + d->egl_context = eglCreateContext (d->egl_display, d->egl_config, + EGL_NO_CONTEXT, ctxattr); + +# ifdef HAVE_GLES3 + /* If creation of a GLES 3.0 context failed, fall back to GLES 1.x. */ + if (!d->egl_context && ctxattr != ctxattr1) + { + /* fprintf (stderr, "%s: eglCreateContext 3.0 failed\n", progname); */ + d->egl_context = eglCreateContext (d->egl_display, d->egl_config, + EGL_NO_CONTEXT, ctxattr1); + } +# endif /* HAVE_GLES3 */ + + if (!d->egl_context) + { + fprintf (stderr, "%s: eglCreateContext failed\n", progname); + abort(); + } + + /* describe_gl_visual (stderr, screen, visual, False); */ + + if (! eglMakeCurrent (d->egl_display, d->egl_surface, d->egl_surface, + d->egl_context)) + abort(); + + egl_data_ret = d; + } +# else /* GLX */ + { + XSync (dpy, False); + orig_ehandler = XSetErrorHandler (BadValue_ehandler); + glx_context = glXCreateContext (dpy, vi_out, 0, GL_TRUE); + XSync (dpy, False); + XSetErrorHandler (orig_ehandler); + if (got_error) + glx_context = 0; + } + + if (!glx_context) + { + fprintf(stderr, "%s: couldn't create GL context for visual 0x%x.\n", + progname, (unsigned int) XVisualIDFromVisual (visual)); + exit(1); + } + + glXMakeCurrent (dpy, window, glx_context); + + { + GLboolean rgba_mode = 0; + glGetBooleanv(GL_RGBA_MODE, &rgba_mode); + if (!rgba_mode) + { + glIndexi (WhitePixelOfScreen (screen)); + glClearIndex (BlackPixelOfScreen (screen)); + } + } +# endif /* GLX */ + + XFree((char *) vi_out); + + + /* jwz: the doc for glDrawBuffer says "The initial value is GL_FRONT + for single-buffered contexts, and GL_BACK for double-buffered + contexts." However, I find that this is not always the case, + at least with Mesa 3.4.2 -- sometimes the default seems to be + GL_FRONT even when glGet(GL_DOUBLEBUFFER) is true. So, let's + make sure. + + Oh, hmm -- maybe this only happens when we are re-using the + xscreensaver window, and the previous GL hack happened to die with + the other buffer selected? I'm not sure. Anyway, this fixes it. + */ + { + GLboolean d = False; + glGetBooleanv (GL_DOUBLEBUFFER, &d); + if (d) + glDrawBuffer (GL_BACK); + else + glDrawBuffer (GL_FRONT); + } + + /* Sometimes glDrawBuffer() throws "invalid op". Dunno why. Ignore. */ + while (glGetError() != GL_NO_ERROR) + ; + +# ifdef HAVE_EGL + return egl_data_ret; +# else + return glx_context; +# endif +} + +#ifdef HAVE_EGL + +void +openGL_destroy_context (Display *dpy, egl_data *data) +{ + eglDestroyContext (data->egl_display, data->egl_context); + eglDestroySurface (data->egl_display, data->egl_surface); + eglTerminate (data->egl_display); + free (data); +} + +#else /* HAVE_EGL */ + +void +openGL_destroy_context (Display *dpy, GLXContext ctx) +{ + glXDestroyContext (dpy, ctx); +} + +#endif /* HAVE_EGL */ diff --git a/utils/visual-gl.h b/utils/visual-gl.h new file mode 100644 index 00000000..a9fea75e --- /dev/null +++ b/utils/visual-gl.h @@ -0,0 +1,44 @@ +/* xscreensaver, Copyright © 2025 Jamie Zawinski + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. No representations are made about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + */ + +#ifndef __VISUAL_GL_H__ +#define __VISUAL_GL_H__ + +extern Visual *get_gl_visual (Screen *); +extern void describe_gl_visual (FILE *, Screen *, Visual *, Bool priv_cmap_p); +extern Bool validate_gl_visual (FILE *, Screen *, const char *, Visual *); + +#ifdef HAVE_EGL + +# ifdef __egl_h_ /* EGL/egl.h included */ + +extern void get_egl_config (Display *, EGLDisplay *, EGLint vid, EGLConfig *); + +typedef struct egl_data { + EGLDisplay egl_display; + EGLSurface egl_surface; + EGLContext egl_context; + EGLConfig egl_config; +} egl_data; + +egl_data *openGL_context_for_window (Screen *, Window); +void openGL_destroy_context (Display *, egl_data *); + +# endif /* __egl_h_ */ + +#else /* !HAVE_EGL -- GLX */ + +GLXContext openGL_context_for_window (Screen *, Window); +void openGL_destroy_context (Display *, GLXContext); + +#endif /* !HAVE_EGL */ + +#endif /* __VISUAL_GL_H__ */ diff --git a/utils/visual.h b/utils/visual.h index 4fd1b95a..9d90044b 100644 --- a/utils/visual.h +++ b/utils/visual.h @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright © 1993-2021 Jamie Zawinski +/* xscreensaver, Copyright © 1993-2025 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -29,12 +29,4 @@ extern void visual_rgb_masks (Screen *screen, Visual *visual, unsigned long *green_mask, unsigned long *blue_mask); -extern Visual *get_gl_visual (Screen *); -extern void describe_gl_visual (FILE *, Screen *, Visual *, Bool priv_cmap_p); -extern Bool validate_gl_visual (FILE *, Screen *, const char *, Visual *); - -#ifdef __egl_h_ /* EGL/egl.h included */ -extern void get_egl_config (Display *, EGLDisplay *, EGLint vid, EGLConfig *); -#endif - #endif /* __VISUAL_H__ */ diff --git a/xscreensaver.spec b/xscreensaver.spec index 3f13e517..afbb9119 100644 --- a/xscreensaver.spec +++ b/xscreensaver.spec @@ -1,5 +1,5 @@ %define name xscreensaver -%define version 6.11 +%define version 6.12 Summary: X screen saver and locker Name: %{name} -- 2.47.3