[PATCH 6/8] Improve monitor selection code

Doug Torrance <[email protected]>
Newsgroups gmane.compw.window-managers.windowmaker.devel
Message-ID <[email protected]>
From: Johannes Holmberg <[email protected]>

- Default to monitor 0 instead of failing if a crazy number is given
- Allow monitor to be specified by osdmonitor in the config file
---
 wmix/config.c | 40 ++++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/wmix/config.c b/wmix/config.c
index 22de1b3..8c9490d 100644
--- a/wmix/config.c
+++ b/wmix/config.c
@@ -111,6 +111,25 @@ void config_release(void)
 	}
 }
 
+void parse_monitor_value(char *value)
+{
+	char *end;
+	long mon = strtol(value, &end, 10);
+	if (end == value + strlen(value)) {
+		if ((mon > INT_MAX) || (mon < -1)) {
+			fprintf(stderr, "wmix:warning: unreasonable monitor number provided, falling back to default\n");
+			config.osd_monitor_number = 0;
+		} else {
+			if (mon == -1)
+				config.osd = 0;
+			else
+				config.osd_monitor_number = (int)mon;
+		}
+	} else {
+		config.osd_monitor_name = strdup(value);
+	}
+}
+
 /*
  * Parse Command-Line options
  *
@@ -183,22 +202,8 @@ void parse_cli_options(int argc, char **argv)
 			config.mixer_device = strdup(optarg);
 			break;
 
-		case 'o': ;
-			char *end;
-			long mon = strtol(optarg, &end, 10);
-			if (end == optarg + strlen(optarg)) {
-				if ((mon > INT_MAX) || (mon < -1)) {
-					fprintf(stderr, "wmix:error: unreasonable monitor number provided\n");
-					error_found = true;
-				} else {
-					if (mon == -1)
-						config.osd = 0;
-					else
-						config.osd_monitor_number = (int)mon;
-				}
-			} else {
-				config.osd_monitor_name = strdup(optarg);
-			}
+		case 'o':
+			parse_monitor_value(optarg);
 			break;
 
 		case 'v':
@@ -355,6 +360,9 @@ void config_read(void)
 				free(config.osd_color);
 			config.osd_color = strdup(value);
 
+		} else if (strcmp(keyword, "osdmonitor") == 0) {
+			parse_monitor_value(value);
+
 		} else if (strcmp(keyword, "scrolltext") == 0) {
 			config.scrolltext = atoi(value);
 
-- 
2.1.4


-- 
To unsubscribe, send mail to [email protected].
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.