mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:17:35 +00:00
WindowServer: Support PNG wallpapers.
Fix up /bin/pape so it tells the WindowServer which wallpaper file to use.
This commit is contained in:
parent
fe25f957e5
commit
e4dfd5a3a4
15 changed files with 150 additions and 12890 deletions
|
@ -10,6 +10,8 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <AK/FileSystemPath.h>
|
||||
#include <LibGUI/GDesktop.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
|
||||
static bool flag_show_all = false;
|
||||
static int show_all();
|
||||
|
@ -23,6 +25,8 @@ static void usage()
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
GApplication app(argc, argv);
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "a")) != -1) {
|
||||
switch (opt) {
|
||||
|
@ -67,50 +71,9 @@ int show_all()
|
|||
return 0;
|
||||
}
|
||||
|
||||
static String read_var(const String& name)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("/proc/sys/");
|
||||
builder.append(name);
|
||||
auto path = builder.to_string();
|
||||
int fd = open(path.characters(), O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
exit(1);
|
||||
}
|
||||
char buffer[BUFSIZ];
|
||||
int nread = read(fd, buffer, sizeof(buffer));
|
||||
close(fd);
|
||||
if (nread < 0) {
|
||||
perror("read");
|
||||
exit(1);
|
||||
}
|
||||
return String(buffer, nread, Chomp);
|
||||
}
|
||||
|
||||
static void write_var(const String& name, const String& value)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("/proc/sys/");
|
||||
builder.append(name);
|
||||
auto path = builder.to_string();
|
||||
int fd = open(path.characters(), O_WRONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
exit(1);
|
||||
}
|
||||
int nwritten = write(fd, value.characters(), value.length());
|
||||
if (nwritten < 0) {
|
||||
perror("read");
|
||||
exit(1);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
int show_current()
|
||||
{
|
||||
FileSystemPath path(read_var("wm_wallpaper"));
|
||||
printf("%s\n", path.basename().characters());
|
||||
printf("%s\n", GDesktop::the().wallpaper().characters());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -119,7 +82,10 @@ int set_pape(const char* name)
|
|||
StringBuilder builder;
|
||||
builder.append("/res/wallpapers/");
|
||||
builder.append(name);
|
||||
|
||||
write_var("wm_wallpaper", builder.to_string());
|
||||
String path = builder.to_string();
|
||||
if (!GDesktop::the().set_wallpaper(path)) {
|
||||
fprintf(stderr, "pape: Failed to set wallpaper %s\n", path.characters());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue