From 8a1345ae4b8736eb9d66277b7d95c402e4a71c15 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sun, 17 Mar 2024 11:15:03 -0400 Subject: [PATCH] FIX make network toggles actually work --- bin/xmonad.hs | 5 +-- lib/XMonad/Internal/Command/Desktop.hs | 48 ++++++++++++++++---------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/bin/xmonad.hs b/bin/xmonad.hs index b5679c4..b054dff 100644 --- a/bin/xmonad.hs +++ b/bin/xmonad.hs @@ -832,8 +832,9 @@ externalBindings runIO cleanup db = , -- M- reserved for showing the keymap KeyBinding "M-" "restart xmonad" restartf , KeyBinding "M-" "recompile xmonad" recompilef - , KeyBinding "M-" "select autorandr profile" $ Left $ toX runAutorandrMenu - , KeyBinding "M-" "toggle ethernet" $ Left $ toX runToggleEthernet + , KeyBinding "M-" "select autorandr profile" $ Left $ toX runAutorandrMenu + , KeyBinding "M-" "toggle wifi" $ Left $ toX runToggleWifi + , KeyBinding "M-" "toggle ethernet" $ Left $ toX runToggleNetworking , KeyBinding "M-" "toggle bluetooth" $ Left $ toX $ runToggleBluetooth sys , KeyBinding "M-" "toggle screensaver" $ Left $ toX $ callToggle ses , KeyBinding "M-" "switch gpu" $ Left runOptimusPrompt diff --git a/lib/XMonad/Internal/Command/Desktop.hs b/lib/XMonad/Internal/Command/Desktop.hs index 424f1c0..f01c65a 100644 --- a/lib/XMonad/Internal/Command/Desktop.hs +++ b/lib/XMonad/Internal/Command/Desktop.hs @@ -19,7 +19,8 @@ module XMonad.Internal.Command.Desktop , runVolumeUp , runVolumeMute , runToggleBluetooth - , runToggleEthernet + , runToggleNetworking + , runToggleWifi , runRestart , runRecompile , runAreaCapture @@ -107,6 +108,9 @@ bluetoothPkgs = [Package Official "bluez-utils"] networkManagerPkgs :: [Fulfillment] networkManagerPkgs = [Package Official "networkmanager"] +nmcli :: IODependency_ +nmcli = sysExe networkManagerPkgs "nmcli" + -------------------------------------------------------------------------------- -- Misc constants @@ -304,27 +308,35 @@ runToggleBluetooth cl = #!>> fmtCmd myBluetooth ["power", "$a", ">", "/dev/null"] #!&& fmtNotifyCmd defNoteInfo {body = Just $ Text "bluetooth powered $a"} -runToggleEthernet :: MonadUnliftIO m => Sometimes (m ()) -runToggleEthernet = +runToggleNetworking :: MonadUnliftIO m => Sometimes (m ()) +runToggleNetworking = Sometimes - "ethernet toggle" - xpfEthernet + "network toggle" + (\x -> xpfEthernet x || xpfWireless x) [Subfeature root "nmcli"] where - root = - IORoot cmd $ - And1 (Only readEthernet) $ - Only_ $ - sysExe networkManagerPkgs "nmcli" - -- TODO make this less noisy - cmd iface = + root = IORoot_ cmd $ Only_ nmcli + cmd = S.spawn $ - fmtCmd "nmcli" ["-g", "GENERAL.STATE", "device", "show", iface] - #!| "grep -q disconnected" - #!&& "a=connect" - #!|| "a=disconnect" - #!>> fmtCmd "nmcli" ["device", "$a", iface] - #!&& fmtNotifyCmd defNoteInfo {body = Just $ Text "ethernet \"$a\"ed"} + fmtCmd "nmcli" ["networking"] + #!| "grep -q enabled" + #!&& "a=off" + #!|| "a=on" + #!>> fmtCmd "nmcli" ["networking", "$a"] + #!&& fmtNotifyCmd defNoteInfo {body = Just $ Text "networking switched $a"} + +runToggleWifi :: MonadUnliftIO m => Sometimes (m ()) +runToggleWifi = Sometimes "wifi toggle" xpfWireless [Subfeature root "nmcli"] + where + root = IORoot_ cmd $ Only_ nmcli + cmd = + S.spawn $ + fmtCmd "nmcli" ["radio", "wifi"] + #!| "grep -q enabled" + #!&& "a=off" + #!|| "a=on" + #!>> fmtCmd "nmcli" ["radio", "wifi", "$a"] + #!&& fmtNotifyCmd defNoteInfo {body = Just $ Text "wifi switched $a"} -------------------------------------------------------------------------------- -- Configuration commands