diff options
author | Dave Reisner <dreisner@archlinux.org> | 2013-04-30 17:22:53 -0400 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2013-04-30 17:22:53 -0400 |
commit | 92e4b9772a46f4b40b47df44fd3964c868e3c12f (patch) | |
tree | 4bbfedde9f1a19c9d6f5496c2b1a611066366d51 | |
parent | 30cd5880addf928908817f5e433ea993c83db912 (diff) | |
download | mirror-ponymix-92e4b9772a46f4b40b47df44fd3964c868e3c12f.tar.gz mirror-ponymix-92e4b9772a46f4b40b47df44fd3964c868e3c12f.tar.bz2 mirror-ponymix-92e4b9772a46f4b40b47df44fd3964c868e3c12f.zip |
implement --max-volume to override baked in defaults
Solves GH#19.
-rw-r--r-- | ponymix.1 | 4 | ||||
-rw-r--r-- | ponymix.cc | 25 |
2 files changed, 28 insertions, 1 deletions
@@ -14,6 +14,10 @@ is used. Cards can be specified by name or numeric index. .IP "\fB\-d\fR, \fB\-\-device\fR \fIDEVICE\fR" Specify a device other than the default. Devices can be specified by name or numeric index. +.IP "\fB\-\-max\-volume\fR \fIVALUE\fR" +Override the maximum volume ponymix will allow. This is baked in to be 100 +using the \fBincrease\fR and \fBdecrease\fR methods, and 150 via +\fBset-volume\fR. .IP "\fB\-N\fR, \fB\-\-notify\fR" Create a libnotify notification for volume change events instead of printing the new volume to standard output. Requires compile time support for libnotify. @@ -56,8 +56,21 @@ static const char* opt_action; static const char* opt_device; static const char* opt_card; static bool opt_notify; +static long opt_maxvolume; static Color color; +static int xstrtol(const char *str, long *out) { + char *end = nullptr; + + if (str == nullptr || *str == '\0') return -1; + errno = 0; + + *out = strtol(str, &end, 10); + if (errno || str == end || (end && *end)) return -1; + + return 0; +} + static const char* type_to_string(enum DeviceType t) { switch (t) { case DEVTYPE_SINK: @@ -319,7 +332,7 @@ static int adj_volume(PulseClient& ponymix, // Allow setting the volume over 100, but don't "clip" the level back down to // 100 on adjustment. - ponymix.SetVolumeRange(0, std::max(device->Volume(), 100)); + ponymix.SetVolumeRange(0, std::max(device->Volume(), (int)opt_maxvolume)); return !(ponymix.*adjust)(*device, delta); } @@ -488,6 +501,7 @@ static void usage() { " -d, --device DEVICE target device (index or name)\n" " -t, --devtype TYPE device type\n" " -N, --notify use libnotify to announce volume changes\n" + " --max-volume VALUE use VALUE as max volume\n" " --source alias to -t source\n" " --input alais to -t source\n" " --sink alias to -t sink\n" @@ -572,6 +586,7 @@ bool parse_options(int argc, char** argv) { { "input", no_argument, 0, 0x103 }, { "sink-input", no_argument, 0, 0x104 }, { "source-output", no_argument, 0, 0x105 }, + { "max-volume", required_argument, 0, 0x106 }, { 0, 0, 0, 0 }, }; @@ -618,6 +633,13 @@ bool parse_options(int argc, char** argv) { opt_devtype = DEVTYPE_SOURCE_OUTPUT; opt_listrestrict = true; break; + case 0x106: + if (xstrtol(optarg, &opt_maxvolume) < 0) { + fprintf(stderr, "error: invalid max volume: %s: must be a positive integer\n", + optarg); + return false; + } + break; default: return false; } @@ -636,6 +658,7 @@ int main(int argc, char* argv[]) { opt_action = "defaults"; opt_devtype = DEVTYPE_SINK; opt_device = defaults.sink.c_str(); + opt_maxvolume = 100; if (!parse_options(argc, argv)) return 1; argc -= optind; |