[Thread Prev][Thread Next]   >Date Index >Thread Index

[wmx] runtime-config [take one]

Stefan `Sec` Zehl - Mon Feb 16 01:11:28 1998

I proposed that "configurability patch" for wmx, some time ago.
Unfortunately i got sidetracked by 'real work'[tm], so I'm quickly
sending it now, to see what you think of it.

To quickly recap: the options are encoded in the symlink for
~/.wmx/options.

cd ~/.wmx ; ln -s "focus:follow,keyboard:off" options

The options are read when you start up wmx, and when you middle-click on
the root window.

So far i have implemented:

menu: full/part
keyboard: on/off
focus: click/raise/delay-raise/follow

So please tell me what you think :)

CU,
    Sec
-- 
I apologise for the length of this message - Must've booted with the
-vvv switch this morning ...

--- wmx-4/Config.C.orig	Mon Feb 16 00:29:29 1998
+++ wmx-4/Config.C	Mon Feb 16 00:29:29 1998
@@ -0,0 +1,86 @@
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "Config.h"
+
+struct conf config;
+void cfg_read(void);
+
+void cfg_init(void){
+	strcpy(config.options,"");
+
+	strcpy(config.path,getenv("HOME"));         // Path to Options-Link
+	strcat(config.path,"/" CONFIG_COMMAND_MENU "/options");
+
+	config.focus = 0;	// 1 = Click , 2 = Raise, 4 = Autoraise
+	config.kbd = 1;		// 1 = Keyboard on
+	config.menu = 1;	// 0 = no unmapped, 1 = everything
+	config.feedback = 1;	// 0 = no , 1 = yes
+
+	cfg_read(1);
+}
+
+void cfg_read(int startup){
+    char temp[1000];
+    bzero(temp,1000);
+
+    if(readlink(config.path,temp,999)>0){
+	if(strcmp(temp,config.options)!=0) { // Did it change ?
+	    strcpy(config.options,temp);	
+	    cfg_update(temp);
+	}
+    } else
+	if (startup)
+	    printf("No config found\n");
+}
+
+#define OPTION(x) ( (!strncasecmp(s,x,strlen(x))) && (s+=strlen(x)) )
+
+void cfg_update(char *string){
+	char * s,c;
+
+	printf("checking options...",string);
+
+	s = strtok(string,"/");
+	do {
+		printf(">%s< ",s);
+
+		if OPTION("menu:")
+			if OPTION("full")
+				config.menu=1;
+			else if OPTION("part")
+				config.menu=0;
+
+		if OPTION("keyboard:")
+			if OPTION("on")
+				config.kbd=1;
+			else if OPTION("off")
+				config.kbd=0;
+
+		if OPTION("feedback:")
+			if OPTION("on")
+				config.feedback=1;
+			else if OPTION("off")
+				config.feedback=0;
+
+		if OPTION("focus:")
+			if OPTION("click")
+				config.focus = 3;
+			else if OPTION("raise")
+				config.focus = 2;
+			else if OPTION("delay-raise") {
+				config.focus = 2;
+				if OPTION(",") {
+					;// with delay == (atoi)
+				}
+			} else if OPTION("follow")
+				config.focus = 0;
+
+		if ( *s != '\0')
+			printf("\nERROR: '%s' @ position %d\n",s,string-s);
+
+	} while( s = strtok(NULL,"/"));
+	printf ("\n");
+}
--- wmx-4/Config.h.orig	Thu Jan 22 13:24:26 1998
+++ wmx-4/Config.h	Mon Feb 16 00:31:19 1998
@@ -2,6 +2,19 @@
 #ifndef _CONFIG_H_
 #define _CONFIG_H_
 
+struct conf {
+    char options[1000];	// Old options-string
+    char path[1000];	// Path to Options-Link
+    char focus; 	// 1 = Click , 2 = Raise, 4 = Autoraise
+    char kbd;		// 1 = Keyboard on
+    char menu;		// 0 = no unmapped, 1 = everything
+    char feedback;	// 0 = no , 1 = yes
+};
+extern struct conf config;
+void cfg_init(void);
+void cfg_read(int);
+void cfg_update(char * string);
+
 
 // ============================
 // Configuration header for wmx
@@ -33,7 +46,7 @@
 
 // List visible as well as hidden clients on the root menu?  (Visible
 // ones will be towards the bottom of the menu, flush-right.)
-#define CONFIG_EVERYTHING_ON_ROOT_MENU True
+#define CONFIG_EVERYTHING_ON_ROOT_MENU (config.menu & 1)
 
 // Spawn a temporary new shell between the wm and each new process?
 #define CONFIG_EXEC_USING_SHELL   False
@@ -52,9 +65,9 @@
 // the other two False; you'll then get focus-follows, auto-raise, and
 // a delay on auto-raise as configured in the DELAY settings below.
 
-#define CONFIG_CLICK_TO_FOCUS     False
-#define CONFIG_RAISE_ON_FOCUS     False
-#define CONFIG_AUTO_RAISE         False
+#define CONFIG_CLICK_TO_FOCUS     (config.focus & 1)
+#define CONFIG_RAISE_ON_FOCUS     (config.focus & 2)
+#define CONFIG_AUTO_RAISE         (config.focus & 4)
 
 // Delays when using AUTO_RAISE focus method
 // 
@@ -92,7 +105,7 @@
 // ========================
 
 // Allow keyboard control?
-#define CONFIG_USE_KEYBOARD       True
+#define CONFIG_USE_KEYBOARD       (config.kbd & 1)
 
 // This is a keyboard modifier mask as defined in <X11/X.h>.  It's the
 // modifier required for wm controls: e.g. Alt/Left and Alt/Right to
--- wmx-4/General.h.orig	Thu Jan 22 13:15:38 1998
+++ wmx-4/General.h	Mon Feb 16 00:29:29 1998
@@ -10,7 +10,9 @@
 #undef _POSIX_SOURCE
 #endif
 
+#ifndef __FreeBSD__
 #define _POSIX_SOURCE 1
+#endif
 
 #include <stdio.h>
 #include <signal.h>
--- wmx-4/Main.C.orig	Thu Jan 22 13:15:38 1998
+++ wmx-4/Main.C	Mon Feb 16 00:29:30 1998
@@ -3,6 +3,7 @@
 
 #include "Client.h"
 #include "Border.h"
+#include "Config.h"
 
 int main(int argc, char **argv)
 {
@@ -13,6 +14,7 @@
 	fprintf(stderr, "usage: %s\n", argv[0] + (i > 0) + i);
 	exit(2);
     }
+    cfg_init();
     
     WindowManager manager;
     return 0;
--- wmx-4/Makefile.orig	Thu Jan 22 13:28:32 1998
+++ wmx-4/Makefile	Mon Feb 16 00:40:47 1998
@@ -7,7 +7,7 @@
 CC	= gcc
 CCC	= gcc
 CFLAGS	= -g -O2
-OBJECTS	= Border.o Buttons.o Channel.o Client.o Events.o Main.o Manager.o Menu.o Rotated.o
+OBJECTS	= Border.o Buttons.o Channel.o Client.o Events.o Main.o Manager.o Menu.o Rotated.o Config.o
 
 .c.o:
 	$(CC) -c $(CFLAGS) $<
@@ -16,7 +16,7 @@
 	$(CCC) -c $(CFLAGS) $<
 
 wmx:	$(OBJECTS)
-	mv -f wmx wmx.old >& /dev/null || true
+	mv -f wmx wmx.old >/dev/null 2>&1 || true
 	$(CCC) -o wmx $(OBJECTS) $(LIBS)
 
 depend:

Next: