shithub: rio

Download patch

ref: 33fc3d212508879b7f37709f91085fefd4169a0b
parent: ecafc4e97800a663083f9e75c548267fbade5c8e
author: byte <byteshift@disroot.org>
date: Sat Dec 27 14:09:06 EST 2025

rework, wallctl 'wallset' works

--- a/dat.h
+++ b/dat.h
@@ -209,9 +209,6 @@
 void 		wscrsleep(Window*, uint);
 
 void load_wallpaper(const char* wallpaper_path);
-/* bringing function from rio.c here so it can be called from wallctl.c for redraw */
-/* this is ugly but is there a better way? */
-void resized(void);
 
 struct Dirtab
 {
--- a/data.c
+++ b/data.c
@@ -187,19 +187,34 @@
 };
 
 Image*
-get_wallpaper(const char* path)
+get_wallpaper(const char* wallpath)
 {
-	if(path == nil)
+	if(wallpath == nil)
 		return nil;
+	// cached
 	static Image *img;
+	static char *path;
+
+	//clear cache
+	if(path == nil || strcmp(path, wallpath) != 0){
+		free(path);
+		path = strdup(wallpath);
+		freeimage(img);
+		img = nil;
+	}
+	if(img != nil)
+		return img;
+
 	int fd = open(path, OREAD);
-	if(fd < 0)
+	if(fd < 0){
+		fprint(2, "rio: can't read wallpaper file %s: %r\n", path);
 		return nil;
-	if(img == nil)
-		img = readimage(display, fd, 0);
+	}
+	img = readimage(display, fd, 0);
+	if(img == nil){
+		fprint(2, "can't read wallpaper image from %s: %r\n", path);
+	}
 	close(fd);
-	if(img == nil)
-		fprint(2, "rio: readimage %s: %r\n", path);
 	return img;	
 }
 
--- a/rio.c
+++ b/rio.c
@@ -30,6 +30,7 @@
 Image*	sweep(void);
 Image*	bandsize(Window*);
 Image*	drag(Window*);
+void		resized(void);
 Channel	*exitchan;	/* chan(int) */
 Channel	*winclosechan; /* chan(Window*); */
 Channel	*kbdchan;	/* chan(char*); */
--- a/test
+++ /dev/null
@@ -1,1 +1,0 @@
-this is a test file
\ No newline at end of file
--- a/wallctl.c
+++ b/wallctl.c
@@ -11,7 +11,6 @@
 #include "dat.h"
 #include "fns.h"
 #include <ctype.h>
-#include <stdio.h> //TODO: remove
 
 enum
 {
@@ -61,7 +60,7 @@
 
 	cmd = word(&s, cmds);
 	if(cmd < 0){
-		strcpy(err, "unrecognized wctl command");
+		strcpy(err, "unrecognized wallctl command");
 		return -1;
 	}
 
@@ -68,7 +67,7 @@
 	while(isspace(*s))
 		s++;
 	if(cmd!=WallSet && *s!='\0'){
-		strcpy(err, "extraneous text in wctl message");
+		strcpy(err, "extraneous text in wallctl message");
 		return -1;
 	}
 
@@ -83,29 +82,59 @@
 int
 writewallctl(Xfid *x, char *err)
 {
-	int cmd;
-	char *arg, *tok;
-
+	char *arg;
 	x->data[x->count] = '\0';
+	int cmd = parsewallctl(&arg, x->data, err);
 
-	cmd = parsewallctl(&arg, x->data, err);
-
 	if(cmd < 0)
 		return -1;
 
 	switch(cmd){
 	case WallSet:
-		tok = strchr(arg, '\n');
+	{
+		char *tok = strchr(arg, '\n');
 		if(tok != nil)
 			arg[tok - arg] = '\0';
 		if(wallpath)
 			free(wallpath);
-		wallpath = malloc(strlen(arg));
-		strcpy(wallpath, arg);
+		wallpath = strdup(arg);
+
+		freescrtemps();
+		view = screen;
+		freescreen(wscreen);
+
+		freeimage(background);
+		background = allocimage(display, Rect(0, 0, Dx(screen->r), Dy(screen->r)), screen->chan, 0, 0x000000FF);
+
+		wscreen = allocscreen(screen, background, 0);
+		if(wscreen == nil)
+			error("can't re-allocate screen");
+
+		load_wallpaper(wallpath);
+		draw(view, view->r, background, nil, ZP);
 		
-		//load_wallpaper(wallpath);
-		resized(); //this will set the wallpaper and handle re-drawing
+		for(int n=0; n<nwindow; n++){
+			Window *w = window[n];
+			Rectangle r = w->i->r;
+			int j;
+			for(j=0; j<nhidden; j++)
+				if(w == hidden[j])
+					break;
+			incref(w);
+			
+			Image *im;
+			if(j < nhidden){
+				im = allocimage(display, r, screen->chan, 0, DNofill);
+			} else {
+				im = allocwindow(wscreen, r, Refbackup, DNofill);
+			}
+			if(im!=nil)
+				wsendctlmesg(w, Reshaped, r, im);
+			wclose(w);
+		}
+		flushimage(display, 1);
 		return 1;
+	}
 	}
 
 	return 1;
--- a/wctl.c
+++ b/wctl.c
@@ -11,7 +11,6 @@
 #include "dat.h"
 #include "fns.h"
 #include <ctype.h>
-#include <stdio.h> //TODO: remove
 
 char	Ebadwr[]		= "bad rectangle in wctl request";
 char	Ewalloc[]		= "window allocation failed in wctl request";
--