changeset 34:080f4e97709b

misc: add args for mpd and background
author David Demelier <markand@malikania.fr>
date Mon, 30 Apr 2018 20:46:39 +0200
parents f4c4e7161f81
children 72274722586f
files dmenu-background/main.cpp dmenu-mpc/main.cpp
diffstat 2 files changed, 30 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/dmenu-background/main.cpp	Mon Apr 30 13:13:51 2018 +0200
+++ b/dmenu-background/main.cpp	Mon Apr 30 20:46:39 2018 +0200
@@ -50,7 +50,7 @@
 
 // {{{ open
 
-config open()
+auto open() -> config
 {
     const auto section = dmenu::config("background");
     const auto path = section.get("path").get_value();
@@ -66,7 +66,18 @@
 
 // {{{ select
 
-std::vector<std::string> select_list(const fs::path& path)
+auto select_args() -> std::vector<std::string>
+{
+    const auto section = dmenu::config("background");
+    const auto it = section.find("args");
+
+    if (it == section.end())
+        return { "-p background", "-l 16" };
+
+    return *it;
+}
+
+auto select_list(const fs::path& path) -> std::vector<std::string> 
 {
     std::vector<std::string> result;
 
@@ -78,12 +89,12 @@
     return result;
 }
 
-std::string select(const fs::path& base)
+auto select(const fs::path& base) -> std::string 
 {
     auto path = base;
 
     for (;;) {
-        const auto selection = dmenu::run({ "-l 16", "-p background" }, select_list(path));
+        const auto selection = dmenu::run(select_args(), select_list(path));
 
         if (selection.empty())
             return selection;
@@ -111,6 +122,7 @@
 
 // }}}
 
+
 // {{{ apply
 
 void apply(const std::string& command, const std::string& file)
--- a/dmenu-mpc/main.cpp	Mon Apr 30 13:13:51 2018 +0200
+++ b/dmenu-mpc/main.cpp	Mon Apr 30 20:46:39 2018 +0200
@@ -280,21 +280,30 @@
 
 // {{{ menu
 
+auto menu_args() -> std::vector<std::string>
+{
+    const auto section = dmenu::config("mpc");
+    const auto it = section.find("args");
+
+    if (it == section.end())
+        return { "-p mpc", "-l 16" };
+
+    return *it;
+}
+
 boost::optional<std::string> menu()
 {
     static const std::vector<std::string> lines{
-        "add...",
-        "",
+        "add",
         "play",
         "pause",
         "stop",
         "next",
         "previous",
-        "",
         "clear"
     };
 
-    const auto selection = dmenu::run({ "-l 16", "-p mpc" }, lines);
+    const auto selection = dmenu::run(menu_args(), lines);
 
     if (selection.empty())
         return boost::none;
@@ -312,7 +321,7 @@
         if (auto selection = menu()) {
             auto conn = connect();
 
-            if (*selection == "add...")
+            if (*selection == "add")
                 add(conn.get());
             else if (*selection == "play")
                 play(conn.get());