about summary refs log tree commit diff
path: root/modules/workstation/windowing/sway/status.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/workstation/windowing/sway/status.cpp')
-rw-r--r--modules/workstation/windowing/sway/status.cpp56
1 files changed, 38 insertions, 18 deletions
diff --git a/modules/workstation/windowing/sway/status.cpp b/modules/workstation/windowing/sway/status.cpp
index ff15995ed1d2..f39b13b079d1 100644
--- a/modules/workstation/windowing/sway/status.cpp
+++ b/modules/workstation/windowing/sway/status.cpp
@@ -51,6 +51,7 @@ public:
 	fs::path path();
 	BatteryStatus status();
 	int capacity();
+	int charge_now();
 
 private:
 	string m_name;
@@ -89,6 +90,11 @@ int Battery::capacity()
 	return stoi(attr("capacity"));
 }
 
+int Battery::charge_now()
+{
+	return stoi(attr("charge_now"));
+}
+
 string Battery::attr(string name)
 {
 	// Use read() to make sure this is done in a single read syscall,
@@ -120,31 +126,45 @@ int main(void)
 				continue;
 
 			Battery battery (name);
-			BatteryStatus status;
-			int capacity;
+			auto batdisplay = false;
 
 			try {
-				status = battery.status();
-				capacity = battery.capacity();
+				switch (battery.status()) {
+				case Charging:
+					out << "↑";
+					break;
+				case Discharging:
+					out << "↓";
+					break;
+				default:
+					out << " ";
+				}
+				batdisplay = true;
 			} catch (const system_error& ex) {
-				if (ex.code().value() == ENOENT)
-					continue;
-
-				throw ex;
+				if (ex.code().value() != ENOENT)
+					throw ex;
 			}
 
-			switch (status) {
-			case Charging:
-				out << "↑";
-				break;
-			case Discharging:
-				out << "↓";
-				break;
-			default:
-				out << " ";
+			try {
+				int capacity = battery.capacity();
+				out << capacity << "%";
+				batdisplay = true;
+			} catch (const system_error& ex) {
+				if (ex.code().value() != ENOENT)
+					throw ex;
+
+				try {
+					int charge_now = battery.charge_now();
+					out << charge_now;
+					batdisplay = true;
+				} catch (const system_error& ex) {
+					if (ex.code().value() != ENOENT)
+						throw ex;
+				}
 			}
 
-			out << capacity << "%  ";
+			if (batdisplay)
+				out << "  ";
 		}
 
 		auto t = time(nullptr);