summaryrefslogtreecommitdiff
path: root/src/w32fns.c
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2022-09-15 14:51:31 +0300
committerEli Zaretskii <eliz@gnu.org>2022-09-15 14:51:31 +0300
commit09e93c4dafc6ffa3e556429757348adfa49a5a83 (patch)
treee96066ed573a0159137371b28059c08cb1157462 /src/w32fns.c
parent6d61d6018c00fd952937966a8cadfd1e7c102efa (diff)
downloademacs-09e93c4dafc6ffa3e556429757348adfa49a5a83.tar.gz
Implement support for 'wallpaper-set' on MS-Windows
* src/w32fns.c (Fw32_set_wallpaper): New primitive. (syms_of_w32fns): Defsubr it. (globals_of_w32fns): Attempt to load SystemParametersInfoW from its DLL at run time. * lisp/image/wallpaper.el (wallpaper-set): Support MS-Windows by calling 'w32-set-wallpaper'. * etc/NEWS: Update and simplify wording of the 'wallpaper-set' entry.
Diffstat (limited to 'src/w32fns.c')
-rw-r--r--src/w32fns.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/w32fns.c b/src/w32fns.c
index 745458d0a03..d9070675a28 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -10447,6 +10447,66 @@ w32_get_resource (const char *key, const char *name, LPDWORD lpdwtype)
return (NULL);
}
+#ifdef WINDOWSNT
+
+/***********************************************************************
+ Wallpaper
+ ***********************************************************************/
+
+typedef BOOL (WINAPI * SystemParametersInfoW_Proc) (UINT,UINT,PVOID,UINT);
+SystemParametersInfoW_Proc system_parameters_info_w_fn = NULL;
+
+DEFUN ("w32-set-wallpaper", Fw32_set_wallpaper, Sw32_set_wallpaper, 1, 1, 0,
+ doc: /* Set the desktop wallpaper image to IMAGE-FILE. */)
+ (Lisp_Object image_file)
+{
+ Lisp_Object encoded = ENCODE_FILE (Fexpand_file_name (image_file, Qnil));
+ char *fname = SSDATA (encoded);
+ BOOL result = false;
+ DWORD err = 0;
+
+ /* UNICOWS.DLL seems to have SystemParametersInfoW, but it doesn't
+ seem to be worth the hassle to support that on Windows 9X for the
+ benefit of this minor feature. Let them use on Windows 9X only
+ image file names that can be encoded by the system codepage. */
+ if (w32_unicode_filenames && system_parameters_info_w_fn)
+ {
+ wchar_t fname_w[MAX_PATH];
+
+ if (filename_to_utf16 (fname, fname_w) != 0)
+ err = ERROR_FILE_NOT_FOUND;
+ else
+ result = SystemParametersInfoW (SPI_SETDESKWALLPAPER, 0, fname_w,
+ SPIF_SENDCHANGE);
+ }
+ else
+ {
+ char fname_a[MAX_PATH];
+
+ if (filename_to_ansi (fname, fname_a) != 0)
+ err = ERROR_FILE_NOT_FOUND;
+ else
+ result = SystemParametersInfoA (SPI_SETDESKWALLPAPER, 0, fname_a,
+ SPIF_SENDCHANGE);
+ }
+ if (!result)
+ {
+ if (err == ERROR_FILE_NOT_FOUND)
+ error ("Wallpaper file %s does not exist or cannot be accessed", fname);
+ else
+ {
+ err = GetLastError ();
+ if (err)
+ error ("Could not set desktop wallpaper: %s", w32_strerror (err));
+ else
+ error ("Could not set desktop wallpaper (wrong image type?)");
+ }
+ }
+
+ return Qnil;
+}
+#endif
+
/***********************************************************************
Initialization
***********************************************************************/
@@ -10926,6 +10986,7 @@ keys when IME input is received. */);
defsubr (&Sx_file_dialog);
#ifdef WINDOWSNT
defsubr (&Ssystem_move_file_to_trash);
+ defsubr (&Sw32_set_wallpaper);
#endif
}
@@ -11179,6 +11240,8 @@ globals_of_w32fns (void)
get_proc_addr (user32_lib, "EnumDisplayMonitors");
get_title_bar_info_fn = (GetTitleBarInfo_Proc)
get_proc_addr (user32_lib, "GetTitleBarInfo");
+ system_parameters_info_w_fn = (SystemParametersInfoW_Proc)
+ get_proc_addr (user32_lib, "SystemParametersInfoW");
{
HMODULE imm32_lib = GetModuleHandle ("imm32.dll");