shithub: picker

Download patch

ref: 6dac36c4e56535f09dc8b4e7218059e335bf9e9f
parent: 2dc7bd15eb2a52b6c5a7bb32eb4cdbe60fa180be
author: Sigrid Haflínudóttir <[email protected]>
date: Sat Mar 14 22:00:50 EDT 2020

switch buttons, move menu options, add "exit" menu option

--- a/picker.c
+++ b/picker.c
@@ -109,10 +109,7 @@
 	},
 };
 
-static char *menu2i[nelem(spaces)+3] = {
-	"snarf",
-	"snarf all",
-};
+static char *menu2i[nelem(spaces)+4];
 static Menu menu2 = { .item = menu2i };
 
 static Color *colors;
@@ -396,7 +393,10 @@
 	}
 
 	for (i = 0; i < nelem(spaces); i++)
-		menu2i[i+2] = spaces[i].name;
+		menu2i[i] = spaces[i].name;
+	menu2i[i++] = "snarf";
+	menu2i[i++] = "snarf all";
+	menu2i[i] = "exit";
 
 	if (initdraw(nil, nil, "picker") < 0)
 		sysfatal("initdraw: %r");
@@ -466,9 +466,11 @@
 						goto next;
 					}
 				}
-			} else if (m.buttons == 2 && (i = menuhit(2, mctl, &menu2, nil)) >= 0) {
-				if (i >= 2) {
-					space = &spaces[i-2];
+			} else if (m.buttons == 4 && (i = menuhit(3, mctl, &menu2, nil)) >= 0) {
+				if (i == nelem(spaces)+2)
+					goto end;
+				if (i < nelem(spaces)) {
+					space = &spaces[i];
 					space->fromrgb(c->rgba, c->v);
 					for (i = 0; i < 3; i++)
 						c->v[i] = MAX(0.0, MIN(space->max[i], c->v[i]));
@@ -477,7 +479,7 @@
 
 				int f;
 				if ((f = open("/dev/snarf", OWRITE)) >= 0) {
-					if (i == 0) {
+					if (i == nelem(spaces)) {
 						write(f, hex, strlen(hex));
 					} else {
 						for (i = 0; i < ncolors; i++) {
@@ -488,7 +490,7 @@
 					}
 					close(f);
 				}
-			} else if (m.buttons == 4) {
+			} else if (m.buttons == 2) {
 				strcpy(buf, hex);
 				if (enter(nchan < 4 ? "rgb:" : "rgba:", buf, sizeof(buf), mctl, kctl, nil) > 0) {
 					u = c->u;
--- a/picker.man
+++ b/picker.man
@@ -32,8 +32,8 @@
 .I RGBA
 mode.
 .PP
-Different color spaces are provided and accessible through middle
-button menu, or as command line arguments:
+Different color spaces are accessible through right button menu, or as
+command line arguments:
 .TP
 .B -s
 HSLuv.
@@ -45,7 +45,7 @@
 RGB.
 .PP
 Switching between palette can be done by either a mouse click, or
-left/right arrows on the keyboard. With the right button click you
+left/right arrows on the keyboard. With the middle button click you
 can enter color as
 .I RGB(A)
 manually.