shithub: rio

Download patch

ref: e9cfa1cdb931d4a611deac188a3f16e12603f57e
parent: e26ee012fd345ffc63182b8e28f0bc86a532d887
author: byte <byteshift@disroot.org>
date: Fri Dec 26 19:53:23 EST 2025

adding wallctl, drawing with errors for now

--- a/dat.h
+++ b/dat.h
@@ -4,6 +4,7 @@
 	Qscreen,
 	Qsnarf,
 	Qwctl,
+	Qwallctl,
 	Qtap,
 	Qwsys,		/* directory of window directories */
 	Qwsysdir,		/* window directory, child of wsys */
@@ -208,6 +209,9 @@
 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
 {
@@ -310,6 +314,7 @@
 Image	*paletextcol;
 Image	*sizecol;
 int	reverse;	/* there are no pastel paints in the dungeons and dragons world -- rob pike */
+char *wallpath;
 
 Window	**window;
 Window	*wkeyboard;	/* window of simulated keyboard */
--- a/data.c
+++ b/data.c
@@ -10,6 +10,7 @@
 #include <fcall.h>
 #include "dat.h"
 #include "fns.h"
+#include <stdio.h>
 
 Cursor crosscursor = {
 	{-7, -7},
@@ -194,7 +195,7 @@
 	int fd = open(path, OREAD);
 	if(fd < 0)
 		return nil;
-	if (img == nil)
+	if(img == nil)
 		img = readimage(display, fd, 0);
 	close(fd);
 	if(img == nil)
@@ -210,7 +211,7 @@
 
   	Image* img = get_wallpaper(path);
 	if (img == nil) {
-		fprint(2, "can't read wallpaper from %s", path);
+		fprint(2, "can't read wallpaper from %s: %r\n", path);
 		return;
 	}
 
--- a/fns.h
+++ b/fns.h
@@ -3,6 +3,7 @@
 void	freescrtemps(void);
 int	parsewctl(char**, Rectangle, Rectangle*, int*, int*, int*, int*, char**, char*, char*);
 int	writewctl(Xfid*, char*);
+int writewallctl(Xfid*, char*);
 Window *new(Image*, int, int, int, char*, char*, char**);
 void	riosetcursor(Cursor*);
 int	min(int, int);
--- a/fsys.c
+++ b/fsys.c
@@ -25,6 +25,7 @@
 	{ "screen",		QTFILE,	Qscreen,		0400 },
 	{ "snarf",		QTFILE,	Qsnarf,		0600 },
 	{ "wctl",		QTFILE,	Qwctl,		0600 },
+	{ "wallctl",	QTFILE,	Qwallctl,	0600 },
 	{ "kbdtap",	QTFILE,	Qtap,	0660 },
 	{ "wsys",		QTDIR,	Qwsys,		0500|DMDIR },
 
--- a/mkfile
+++ b/mkfile
@@ -12,6 +12,7 @@
 	wctl.$O\
 	wind.$O\
 	xfid.$O\
+	wallctl.$O\
 
 HFILES=dat.h\
 	fns.h\
--- a/rio.c
+++ b/rio.c
@@ -30,7 +30,6 @@
 Image*	sweep(void);
 Image*	bandsize(Window*);
 Image*	drag(Window*);
-void		resized(void);
 Channel	*exitchan;	/* chan(int) */
 Channel	*winclosechan; /* chan(Window*); */
 Channel	*kbdchan;	/* chan(char*); */
@@ -44,7 +43,6 @@
 Channel* initkbd(void);
 
 char		*fontname;
-char		*wallpaper_path;
 
 enum
 {
@@ -137,7 +135,7 @@
 		fontname = EARGF(usage());
 		break;
 	case 'w':
-		wallpaper_path = EARGF(usage());
+		wallpath = EARGF(usage());
 		break;
 	case 'i':
 		initstr = EARGF(usage());
@@ -186,7 +184,7 @@
 		fprint(2, "rio: can't open display: %r\n");
 		exits("display open");
 	}
-	iconinit(wallpaper_path);
+	iconinit(wallpath);
 
 	exitchan = chancreate(sizeof(int), 0);
 	winclosechan = chancreate(sizeof(Window*), 0);
@@ -667,7 +665,7 @@
 	freescreen(wscreen);
 
 	/* reset background for the new resolution */
-	if(wallpaper_path){
+	if(wallpath){
 		freeimage(background);
 		background = allocimage(display, Rect(0, 0, Dx(screen->r), Dy(screen->r)), screen->chan, 0, 0x000000FF);
 	}
@@ -675,7 +673,7 @@
 	wscreen = allocscreen(screen, background, 0);
 	if(wscreen == nil)
 		error("can't re-allocate screen");
-	load_wallpaper(wallpaper_path); //draws on "background"
+	load_wallpaper(wallpath); //draws on "background"
 	draw(view, view->r, background, nil, ZP);
 	o = subpt(viewr.max, viewr.min);
 	n = subpt(view->clipr.max, view->clipr.min);
--- /dev/null
+++ b/wallctl.c
@@ -1,0 +1,107 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <thread.h>
+#include <cursor.h>
+#include <mouse.h>
+#include <keyboard.h>
+#include <frame.h>
+#include <fcall.h>
+#include <plumb.h>
+#include "dat.h"
+#include "fns.h"
+#include <ctype.h>
+#include <stdio.h> //TODO: remove
+
+enum
+{
+	WallSet,
+	WallReset,
+	WallTile,
+	WallFitW,
+	WallFitH
+};
+
+static char *cmds[] = {
+	[WallSet] = "wallset",
+	[WallReset] = "wallreset",
+	[WallTile] = "walltile",
+	[WallFitW] = "wallfitw",
+	[WallFitH] = "wallfith",
+	nil
+};
+
+
+static
+int
+word(char **sp, char *tab[])
+{
+	char *s, *t;
+	int i;
+
+	s = *sp;
+	while(isspace(*s))
+		s++;
+	t = s;
+	while(*s!='\0' && !isspace(*s))
+		s++;
+	for(i=0; tab[i]!=nil; i++)
+		if(strncmp(tab[i], t, strlen(tab[i])) == 0){
+			*sp = s;
+			return i;
+	}
+	return -1;
+}
+
+
+int
+parsewallctl(char **argp, char *s, char *err)
+{
+	int cmd;
+
+	cmd = word(&s, cmds);
+	if(cmd < 0){
+		strcpy(err, "unrecognized wctl command");
+		return -1;
+	}
+
+	while(isspace(*s))
+		s++;
+	if(cmd!=WallSet && *s!='\0'){
+		strcpy(err, "extraneous text in wctl message");
+		return -1;
+	}
+
+	if(argp)
+		*argp = s;
+	else
+		strcpy(err, "missing or bad wallctl parameter, need path");
+
+	return cmd;
+}
+
+int
+writewallctl(Xfid *x, char *err)
+{
+	int cmd;
+	char *arg, *tok;
+
+	x->data[x->count] = '\0';
+
+	cmd = parsewallctl(&arg, x->data, err);
+
+	if(cmd < 0)
+		return -1;
+
+	switch(cmd){
+	case WallSet:
+		tok = strchr(arg, '\n');
+		if(tok != nil)
+			arg[tok - arg] = '\0';
+		wallpath = arg;
+		resized(); //this will set the wallpaper and handle re-drawing
+		return 1;
+	}
+
+	return 1;
+}
--- a/wctl.c
+++ b/wctl.c
@@ -11,6 +11,7 @@
 #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";
@@ -30,6 +31,7 @@
 	Hide,
 	Unhide,
 	Delete,
+	WallpaperSet
 };
 
 static char *cmds[] = {
@@ -45,6 +47,7 @@
 	[Hide]	= "hide",
 	[Unhide]	= "unhide",
 	[Delete]	= "delete",
+	[WallpaperSet] = "wallset",
 	nil
 };
 
@@ -486,6 +489,8 @@
 	switch(cmd){
 	case New:
 		return wctlnew(r, arg, pid, hideit, scrollit, dir, err);
+	case WallpaperSet:
+		return 1;
 	case Set:
 		if(pid > 0)
 			wsetpid(w, pid, 0);
--- a/xfid.c
+++ b/xfid.c
@@ -591,6 +591,13 @@
 			return;
 		}
 		break;
+	
+	case Qwallctl:
+		if(writewallctl(x, err) < 0){
+			filsysrespond(x->fs, x, &fc, err);
+			return;
+		}
+		break;
 
 	case Qtap:
 		if(cnt < 2){
--