gimp but for windows: a wayland compositor
git clone https://github.com/m-col/wimp
Files | Refs | Readme

Commit 52e867d5e384272dba6bf7c40e3dafd2ed940e88
Parent: 4f209b64b5ce30a8d36567d524faba1e4c36e430
Author: mcol <mcol@posteo.net>
Date: 2021-01-30 01:51:53 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-01-30 01:51:53 +0000

Set desks with single value, and have desk-specific background/border opts

wimp.conf Modified

@@ -7,8 +7,6 @@
 #             ██              ██
 #             ██
 # 
-# example wimp configuration file
-#
 # All possible options are described here. Lines that start with '#' are
 # ignored. Options that are commented out contain their default values.
 #
@@ -17,12 +15,23 @@
 #   $XDG_CONFIG_HOME/.config/wimp/config
 #   $HOME/.config/wimp/config
 
+# This will be executed after setting up the compositor.
+#auto_start ${XDG_CONFIG_HOME:-$HOME}/.config/wimp/autostart
 
-## General settings
-
-# These specify the min and max magnification bounds when zooming.
-#zoom_min 0.5
-#zoom_max 3
+#desks 2
+#desk 1 background #5D479D
+#desk 1 borders normal #3e3e73
+#desk 1 borders focus #998dd1
+#desk 1 borders width 4
+#desk 2 background #3e3e73
+#desk 2 borders normal #5D479D
+#desk 2 borders focus #998dd1
+#desk 2 borders width 6
+desk 1 background ~/path/to/tiling-image.png
+
+# Magnification bounds
+#zoom_min 0.1
+#zoom_max 10
 
 # Set the colour for the mark setter/getter indicator
 #mark_indicator #000000
@@ -30,15 +39,16 @@
 # Whether to allow VT switching: on or off.
 #vt_switching on
 
+# natural or reverse scrolling
+#scroll_direction natural
+
 
-## Bindings
+## Key bindings
 
-# Set the modifier key used for bindings
 # Can be one of: Shift, Caps, Ctrl, Alt, Mod2, Mod3, Logo, Mod5
 #set_modifier Logo
 
-# Define key bindings
-# additional modifiers, key, action(, data)
+# additional modifiers, key, action
 bind	Ctrl	Escape		shutdown
 bind	Ctrl	r		reload_config
 
@@ -84,29 +94,3 @@
 bind		scroll		pan_desk_mouse
 bind	Shift	scroll		zoom_mouse
 bind		drag1		move_window
-
-# Scroll direction. Can be one of: natural, reverse
-#scroll_direction natural
-
-# Set an auto-start script. This will be executed after setting up the compositor.
-#auto_start ${XDG_CONFIG_HOME:-$HOME}/.config/wimp/autostart
-
-
-## Configure desks
-
-# Commands until a further desk is added pertain to desk 1.
-
-# This can be a path to a png image, or a colour in the form #rrggbb.
-background ~/pattern.png
-
-# window border colors
-borders focus #998dd1
-borders normal #3e3e73
-borders width 4
-
-# This adds another desk. Following commands will apply to this desk.
-add_desk
-background #3e3e73
-borders normal #1f1c32
-borders focus #406794
-borders width 5

src/main.c Modified

@@ -24,7 +24,6 @@
 
 
 struct wimp wimp = {
-    .mark_waiting = false,
     .on_mouse_motion = NULL,
     .on_mouse_scroll = NULL,
     .on_drag1 = NULL,
@@ -32,6 +31,7 @@
     .on_drag3 = NULL,
     .can_steal_focus = true,
     .desk_count = 0,
+    .mark_waiting = false,
     .mark_indicator.box.width = 25,
     .mark_indicator.box.height = 25,
     .mark_indicator.box.x = 0,
@@ -157,7 +157,6 @@
     wl_list_init(&wimp.key_bindings);
     wl_list_init(&wimp.mouse_bindings);
     wl_list_init(&wimp.marks);
-    add_desk();
 
     // configure
     locate_config();

src/desk.h Modified

@@ -3,7 +3,7 @@
 
 #include "types.h"
 
-void add_desk();
+void configure_desks(int wanted);
 void set_desk(struct desk *desk);
 void view_to_desk(struct view *view, int index);
 

src/desk.c Modified

@@ -4,7 +4,7 @@
 #include "types.h"
 
 
-void add_desk() {
+static void add_desk() {
     struct desk *desk = calloc(1, sizeof(struct desk));
     wl_list_insert(wimp.desks.prev, &desk->link);
     wl_list_init(&desk->views);
@@ -24,6 +24,32 @@
 }
 
 
+static void remove_desk() {
+    struct desk *last = wl_container_of(wimp.desks.next, last, link);
+    if (last == wimp.current_desk) {
+	set_desk(wl_container_of(wimp.desks.next, last, link));
+    }
+    struct view *view, *tview;
+    wl_list_for_each_safe(view, tview, &last->views, link) {
+	view_to_desk(view, 0);
+    };
+    wl_list_init(&last->link);
+    wl_list_remove(&last->link);
+    free(last->wallpaper);
+    free(last);
+    wimp.desk_count--;
+}
+
+void configure_desks(int wanted) {
+    while (wanted > wimp.desk_count) {
+	add_desk();
+    }
+    while (wanted < wimp.desk_count) {
+	remove_desk();
+    }
+}
+
+
 void set_desk(struct desk *desk) {
     struct view *view;
     wimp.can_steal_focus = false;

src/config.c Modified

@@ -18,13 +18,22 @@
 
 
 static const char *DEFAULT_CONFIG =  "\n\
-zoom_min 0.5\n\
-zoom_max 3\n\
+desks 2\n\
+desk 1 background #5D479D\n\
+desk 1 borders normal #3e3e73\n\
+desk 1 borders focus #998dd1\n\
+desk 1 borders width 4\n\
+desk 2 background #3e3e73\n\
+desk 2 borders normal #5D479D\n\
+desk 2 borders focus #998dd1\n\
+desk 2 borders width 6\n\
+zoom_min 0.1\n\
+zoom_max 10\n\
 mark_indicator #000000\n\
 vt_switching on\n\
+scroll_direction natural\n\
 set_modifier Logo\n\
 bind Ctrl Escape shutdown\n\
-scroll_direction natural\n\
 ";
 
 
@@ -288,9 +297,7 @@
 }
 
 
-static void set_wallpaper(char *wallpaper) {
-    struct desk *desk = wl_container_of(wimp.desks.prev, desk, link);
-
+static void set_wallpaper(struct desk *desk, char *wallpaper) {
     // wallpaper is a colour
     if (strlen(wallpaper) == 7 && wallpaper[0] == '#') {
 	assign_colour(wallpaper, desk->background);
@@ -397,65 +404,135 @@
     char *s;
     char linebuf[1024];
     int line = 0;
+    int index;
+    static bool a = true;
 
     while (fgets(linebuf, sizeof(linebuf), stream)) {
 	line++;
 	if (!(s = strtok(linebuf, " \t\n\r")) || s[0] == '#') {
 	    continue;
 	}
-	if (!strcasecmp(s, "add_desk")) {
-	    add_desk();
-	} else if (!strcasecmp(s, "background")) {
-	    if ((s = strtok(NULL, " \t\n\r"))) {
-		set_wallpaper(s);
+
+	// desks <int>
+	if (!strcasecmp(s, "desks")) {
+	    if ((s = strtok(NULL, " \t\n\r")) && is_number(s)) {
+		configure_desks(strtod(s, NULL));
 	    }
-	} else if (!strcasecmp(s, "set_modifier")) {
-	    if ((s = strtok(NULL, " \t\n\r"))) {
-		enum wlr_keyboard_modifier mod = get(mods, s);
-		if (mod)
-		    wimp.mod = mod;
-		else
-		    wlr_log(WLR_ERROR, "Config line %i: invalid modifier name '%s'.", line, s);
+	}
+
+	// desk ...
+	else if (!strcasecmp(s, "desk")) {
+	    if ((s = strtok(NULL, " \t\n\r")) && is_number(s)) {
+		index = strtod(s, NULL) - 1;
+		s = strtok(NULL, " \t\n\r");
+		struct desk *desk;
+		bool found = false;
+		wl_list_for_each(desk, &wimp.desks, link) {
+		    if (desk->index == index) {
+			found = true;
+			break;
+		    }
+		}
+		if (!found) {
+		    continue;
+		}
+
+		// desk <index> background #rrggbb
+		// desk <index> background ~/path/to/image.png
+		if (!strcasecmp(s, "background")) {
+		    if ((s = strtok(NULL, " \t\n\r"))) {
+			set_wallpaper(desk, s);
+		    }
+		}
+
+		// borders [desk] [focus|normal] #rrggbb
+		// borders [desk] width <int>
+		else if (!strcasecmp(s, "borders")) {
+		    s = strtok(NULL, " \t\n\r");
+		    if (!strcasecmp(s, "normal")) {
+			assign_colour(strtok(NULL, " \t\n\r"), desk->border_normal);
+		    }
+		    else if (!strcasecmp(s, "focus")) {
+			assign_colour(strtok(NULL, " \t\n\r"), desk->border_focus);
+		    }
+		    else if (!strcasecmp(s, "width")) {
+			if ((s = strtok(NULL, " \t\n\r")) && is_number(s)) {
+			    desk->border_width = strtod(s, NULL);
+			}
+		    }
+		}
 	    }
-	} else if (!strcasecmp(s, "zoom_min")) {
+	}
+
+	// zoom_min <float>
+	else if (!strcasecmp(s, "zoom_min")) {
 	    if ((s = strtok(NULL, " \t\n\r")) && is_number(s)) {
 		wimp.zoom_min = strtod(s, NULL);
+		printf("%f\n", wimp.zoom_min);
 	    }
-	} else if (!strcasecmp(s, "zoom_max")) {
+	}
+
+	// zoom_max <float>
+	else if (!strcasecmp(s, "zoom_max")) {
 	    if ((s = strtok(NULL, " \t\n\r")) && is_number(s)) {
 		wimp.zoom_max = strtod(s, NULL);
 	    }
-	} else if (!strcasecmp(s, "bind")) {
-	    add_binding(strtok(NULL, ""), line);
-	} else if (!strcasecmp(s, "mark_indicator")) {
+	}
+
+	// mark_indicator #rrggbb
+	else if (!strcasecmp(s, "mark_indicator")) {
 	    assign_colour(strtok(NULL, " \t\n\r"), wimp.mark_indicator.colour);
-	} else if (!strcasecmp(s, "vt_switching")) {
+	    wimp.mark_indicator.box.x = 0;
+	    wimp.mark_indicator.box.y = 0;
+	}
+
+	// vt_switching [off|on]
+	else if (!strcasecmp(s, "vt_switching")) {
 	    s = strtok(NULL, " \t\n\r");
 	    if (!strcasecmp(s, "off"))
 		wimp.vt_switching = false;
 	    else if (!strcasecmp(s, "on"))
 		wimp.vt_switching = true;
-	} else if (!strcasecmp(s, "borders")) {
-	    s = strtok(NULL, " \t\n\r");
-	    struct desk *desk = wl_container_of(wimp.desks.prev, desk, link);
-	    if (!strcasecmp(s, "normal"))
-		assign_colour(strtok(NULL, " \t\n\r"), desk->border_normal);
-	    else if (!strcasecmp(s, "focus"))
-		assign_colour(strtok(NULL, " \t\n\r"), desk->border_focus);
-	    else if (!strcasecmp(s, "width"))
-		if ((s = strtok(NULL, " \t\n\r")) && is_number(s))
-		    desk->border_width = strtod(s, NULL);
-	} else if (!strcasecmp(s, "auto_start")) {
-	    wimp.auto_start = strdup(strtok(NULL, " \t\n\r"));
-	} else if (!strcasecmp(s, "scroll_direction")) {
+	}
+
+	// scroll_direciton [natural|reverse]
+	else if (!strcasecmp(s, "scroll_direction")) {
 	    s = strtok(NULL, " \t\n\r");
 	    if (!strcasecmp(s, "natural"))
 		wimp.reverse_scrolling = false;
 	    else if (!strcasecmp(s, "reverse"))
 		wimp.reverse_scrolling = true;
-	} else {
+	}
+
+	// e.g.: set_modifier logo
+	else if (!strcasecmp(s, "set_modifier")) {
+	    if ((s = strtok(NULL, " \t\n\r"))) {
+		enum wlr_keyboard_modifier mod = get(mods, s);
+		if (mod)
+		    wimp.mod = mod;
+		else
+		    wlr_log(WLR_ERROR, "Config line %i: invalid modifier name '%s'.", line, s);
+	    }
+	}
+
+	// bind [<modifiers>] <key> <action>
+	else if (!strcasecmp(s, "bind")) {
+	    add_binding(strtok(NULL, ""), line);
+	}
+
+	// auto_start ~/script/to/execute.sh
+	else if (!strcasecmp(s, "auto_start")) {
+	    wimp.auto_start = strdup(strtok(NULL, " \t\n\r"));
+	}
+
+	// other non-empty, non-commented lines
+	else {
 	    wlr_log(WLR_ERROR, "Config line %i: unknown option '%s'.", line, s);
 	}
+	if (wimp.mark_waiting && a) {
+	    printf("%i\n", line);
+	    a = false;
+	}
     }
 }