From e5678819f9b6126ee526c82e2af7d311e1b8a755 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Fri, 8 May 2026 02:29:25 -0700 Subject: [PATCH] Update kanshi-sni input --- nixos/flake.lock | 6 +- .../kanshi-sni-keep-menu-root-alive.patch | 30 ------ .../kanshi-sni-refresh-and-reconnect.patch | 96 ------------------- nixos/sni.nix | 9 +- 4 files changed, 4 insertions(+), 137 deletions(-) delete mode 100644 nixos/patches/kanshi-sni-keep-menu-root-alive.patch delete mode 100644 nixos/patches/kanshi-sni-refresh-and-reconnect.patch diff --git a/nixos/flake.lock b/nixos/flake.lock index 3b172743..950a0e85 100644 --- a/nixos/flake.lock +++ b/nixos/flake.lock @@ -1193,11 +1193,11 @@ ] }, "locked": { - "lastModified": 1770983026, - "narHash": "sha256-l5nxTqh8YeYSWjFZu6067gwpRajSaRiIK7nQ9zwXWFU=", + "lastModified": 1778232476, + "narHash": "sha256-J2fwFSt7Ae39Sp5rlZ/WegIX8uuPuz5PZGcumvXXNmY=", "owner": "taffybar", "repo": "kanshi-sni", - "rev": "a31a95b773c6a9c282a07c9a556f7d7a0ba23ba3", + "rev": "6a4d4b18666fb6ff45f37ae919fdd23d669c0787", "type": "github" }, "original": { diff --git a/nixos/patches/kanshi-sni-keep-menu-root-alive.patch b/nixos/patches/kanshi-sni-keep-menu-root-alive.patch deleted file mode 100644 index 0db37f00..00000000 --- a/nixos/patches/kanshi-sni-keep-menu-root-alive.patch +++ /dev/null @@ -1,30 +0,0 @@ ---- a/src/Kanshi/SNI.hs -+++ b/src/Kanshi/SNI.hs -@@ -42,7 +42,8 @@ - - data SNIState = SNIState - { sniConnection :: MVar (Maybe KanshiConnection) - , sniAppState :: MVar AppState -+ , sniMenuRoot :: MVar Dbusmenu.Menuitem - , sniMenuServer :: Dbusmenu.Server - , sniGLibContext :: GLib.MainContext - } -@@ -77,8 +78,10 @@ - appState <- buildInitialState kanshiConn - connVar <- newMVar kanshiConn - stateVar <- newMVar appState -+ initialRoot <- Dbusmenu.menuitemNew -+ rootVar <- newMVar initialRoot - -- let sniState = SNIState connVar stateVar menuServer context -+ let sniState = SNIState connVar stateVar rootVar menuServer context - - -- Build initial menu - rebuildMenu sniState -@@ -177,6 +179,7 @@ - , onToggleMonitor = handleToggleMonitor sniState - } - newRoot <- buildMenu state actions -+ modifyMVar_ (sniMenuRoot sniState) $ const (pure newRoot) - runOnGLibMain (sniGLibContext sniState) $ - Dbusmenu.serverSetRoot (sniMenuServer sniState) newRoot diff --git a/nixos/patches/kanshi-sni-refresh-and-reconnect.patch b/nixos/patches/kanshi-sni-refresh-and-reconnect.patch deleted file mode 100644 index 920dbb6f..00000000 --- a/nixos/patches/kanshi-sni-refresh-and-reconnect.patch +++ /dev/null @@ -1,96 +0,0 @@ ---- a/src/Kanshi/SNI.hs -+++ b/src/Kanshi/SNI.hs -@@ -28,6 +28,7 @@ - , castPtrToStablePtr - ) - import System.Directory (XdgDirectory(..), doesDirectoryExist, getXdgDirectory) -+import System.FilePath (takeFileName) - import System.FSNotify (Event(..), withManager, watchDir) - import System.IO.Unsafe (unsafePerformIO) - -@@ -46,6 +47,9 @@ - , sniGLibContext :: GLib.MainContext - } - -+refreshIntervalMicros :: Int -+refreshIntervalMicros = 5 * 1000000 -+ - startSNI :: IO () - startSNI = do - let busName = "org.kanshi.SNI" -@@ -96,12 +100,17 @@ - dirExists <- doesDirectoryExist configDir - when dirExists $ - void $ forkIO $ withManager $ \mgr -> do -- void $ watchDir mgr configDir (const True) $ \event -> -+ void $ watchDir mgr configDir (\event -> takeFileName (eventPath event) == "config") $ \event -> - case event of -- Modified {} -> refreshState sniState -- Added {} -> refreshState sniState -+ Modified {} -> safeRefreshState sniState -+ Added {} -> safeRefreshState sniState -+ Removed {} -> safeRefreshState sniState - _ -> pure () - forever $ threadDelay maxBound -+ -+ void $ forkIO $ forever $ do -+ threadDelay refreshIntervalMicros -+ safeRefreshState sniState - - -- Block forever on main thread - forever $ threadDelay maxBound -@@ -171,9 +180,29 @@ - runOnGLibMain (sniGLibContext sniState) $ - Dbusmenu.serverSetRoot (sniMenuServer sniState) newRoot - -+safeRefreshState :: SNIState -> IO () -+safeRefreshState sniState = -+ refreshState sniState `catch` \(_ :: SomeException) -> do -+ resetConnection sniState `catch` \(_ :: SomeException) -> pure () -+ refreshState sniState `catch` \(_ :: SomeException) -> pure () -+ -+ensureUsableConnection :: Maybe KanshiConnection -> IO (Maybe KanshiConnection) -+ensureUsableConnection mConn = -+ case mConn of -+ Nothing -> tryConnect -+ Just conn -> do -+ statusResult <- kanshiStatus conn -+ case statusResult of -+ Right _ -> pure (Just conn) -+ Left _ -> do -+ disconnectKanshi conn -+ tryConnect -+ - refreshState :: SNIState -> IO () - refreshState sniState = do -- mConn <- readMVar (sniConnection sniState) -+ mConn <- modifyMVar (sniConnection sniState) $ \currentConn -> do -+ freshConn <- ensureUsableConnection currentConn -+ pure (freshConn, freshConn) - newState <- buildInitialState mConn - modifyMVar_ (sniAppState sniState) $ const (pure newState) - rebuildMenu sniState ---- a/src/Kanshi/Varlink.hs -+++ b/src/Kanshi/Varlink.hs -@@ -68,11 +68,16 @@ - - varlinkCall :: KanshiConnection -> Value -> IO (Either KanshiError Value) - varlinkCall (KanshiConnection sock) request = do -- sendAll sock $ LBS.toStrict (encode request) <> BS.singleton 0 -- response <- recvUntilNull sock -- case eitherDecodeStrict response of -- Left err -> return $ Left $ ProtocolError $ "JSON decode error: " ++ err -- Right val -> return $ parseVarlinkResponse val -+ result <- try $ do -+ sendAll sock $ LBS.toStrict (encode request) <> BS.singleton 0 -+ recvUntilNull sock -+ case (result :: Either IOException BS.ByteString) of -+ Left err -> -+ return $ Left $ ConnectionFailed $ "Socket I/O failed: " ++ show err -+ Right response -> -+ case eitherDecodeStrict response of -+ Left err -> return $ Left $ ProtocolError $ "JSON decode error: " ++ err -+ Right val -> return $ parseVarlinkResponse val - - recvUntilNull :: Socket -> IO BS.ByteString - recvUntilNull sock = go BS.empty diff --git a/nixos/sni.nix b/nixos/sni.nix index 09c6506a..7c137589 100644 --- a/nixos/sni.nix +++ b/nixos/sni.nix @@ -7,14 +7,7 @@ ... }: let system = pkgs.stdenv.hostPlatform.system; - kanshiSniPackage = inputs.kanshi-sni.packages.${system}.default.overrideAttrs (old: { - patches = - (old.patches or []) - ++ [ - ./patches/kanshi-sni-refresh-and-reconnect.patch - ./patches/kanshi-sni-keep-menu-root-alive.patch - ]; - }); + kanshiSniPackage = inputs.kanshi-sni.packages.${system}.default; in makeEnable config "myModules.sni" true { systemd.user.services.blueman-applet.serviceConfig.ExecStart = lib.mkForce [