about summary refs log tree commit diff
path: root/modules/workstation/windowing/sway/status.cpp
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-06-24 11:46:51 +0000
committerAlyssa Ross <hi@alyssa.is>2021-06-24 11:46:51 +0000
commite7caacc4c122b7641bb66a4c2595289347a4996c (patch)
tree44862012a43a144034b2c7e97b90dec0ce160c6d /modules/workstation/windowing/sway/status.cpp
parent4d482ec26ab9195e17c9f65456d58bb93727ef31 (diff)
downloadnixlib-e7caacc4c122b7641bb66a4c2595289347a4996c.tar
nixlib-e7caacc4c122b7641bb66a4c2595289347a4996c.tar.gz
nixlib-e7caacc4c122b7641bb66a4c2595289347a4996c.tar.bz2
nixlib-e7caacc4c122b7641bb66a4c2595289347a4996c.tar.lz
nixlib-e7caacc4c122b7641bb66a4c2595289347a4996c.tar.xz
nixlib-e7caacc4c122b7641bb66a4c2595289347a4996c.tar.zst
nixlib-e7caacc4c122b7641bb66a4c2595289347a4996c.zip
modules/sway: handle ENODEV in battery status
Diffstat (limited to 'modules/workstation/windowing/sway/status.cpp')
-rw-r--r--modules/workstation/windowing/sway/status.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/modules/workstation/windowing/sway/status.cpp b/modules/workstation/windowing/sway/status.cpp
index f39b13b079d1..f6340f9f8e64 100644
--- a/modules/workstation/windowing/sway/status.cpp
+++ b/modules/workstation/windowing/sway/status.cpp
@@ -141,8 +141,16 @@ int main(void)
 				}
 				batdisplay = true;
 			} catch (const system_error& ex) {
-				if (ex.code().value() != ENOENT)
+				switch (ex.code().value()) {
+				case ENOENT:
+					break;
+				case ENODEV:
+					out << "? ";
+					batdisplay = true;
+					break;
+				default:
 					throw ex;
+				}
 			}
 
 			try {
@@ -150,16 +158,32 @@ int main(void)
 				out << capacity << "%";
 				batdisplay = true;
 			} catch (const system_error& ex) {
-				if (ex.code().value() != ENOENT)
+				switch (ex.code().value()) {
+				case ENOENT:
+					break;
+				case ENODEV:
+					out << "??%";
+					batdisplay = true;
+					break;
+				default:
 					throw ex;
+				}
 
 				try {
 					int charge_now = battery.charge_now();
 					out << charge_now;
 					batdisplay = true;
 				} catch (const system_error& ex) {
-					if (ex.code().value() != ENOENT)
+					switch (ex.code().value()) {
+					case ENOENT:
+						break;
+					case ENODEV:
+						out << "??????";
+						batdisplay = true;
+						break;
+					default:
 						throw ex;
+					}
 				}
 			}