Skip to content

feat(matic): improve power management for lid close and AC power - #1140

Merged
shunkakinoki merged 2 commits into
mainfrom
feat/matic-power-management
Mar 17, 2026
Merged

feat(matic): improve power management for lid close and AC power#1140
shunkakinoki merged 2 commits into
mainfrom
feat/matic-power-management

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Mar 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Ignore lid close via logind so hypridle's 30-min idle timer handles suspension instead of immediate suspend on lid close
  • Skip auto-suspend in hypridle when connected to AC power

Test plan

  • Close lid while on battery — machine should stay on, then suspend after 30 min idle
  • Close lid while plugged in — machine should not suspend
  • Verify 30-min idle suspend still works on battery with screen open

🤖 Generated with Claude Code


Summary by cubic

Improve power management on matic: ignore lid close in logind and only suspend after 30‑minute idle on battery; never auto‑suspend on AC. Also move matic NixOS docs from root README.md to @matic/readme.md.

  • New Features

    • services.logind: set HandleLidSwitch and HandleLidSwitchExternalPower to ignore so hypridle controls suspend.
    • hypridle: suspend after 30 minutes only when AC*/online is 0; skip suspend on AC.
  • Refactors

    • Moved matic NixOS setup docs from README.md to @matic/readme.md.

Written for commit 9e0a8f9. Summary will update on new commits.

Copilot AI review requested due to automatic review settings March 17, 2026 09:53
@mesa-dot-dev

mesa-dot-dev Bot commented Mar 17, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the power management behavior for the 'matic' host, specifically addressing how the system handles lid closure and AC power. The changes aim to provide a more user-friendly experience by preventing immediate suspension on lid close and ensuring the system remains active when plugged into AC power, while still maintaining idle suspension on battery.

Highlights

  • Lid Close Behavior: Configured logind to ignore lid close events, allowing hypridle to manage suspension based on an idle timer instead of immediate suspension.
  • AC Power Suspension: Modified hypridle's 30-minute idle suspension timer to only trigger when the system is running on battery power, preventing suspension when connected to AC.
Changelog
  • config/hyprland/hypridle.conf
    • Updated the 30-minute idle timeout listener to conditionally suspend the system only if it is not connected to AC power.
  • named-hosts/matic/default.nix
    • Added logind settings to ignore HandleLidSwitch and HandleLidSwitchExternalPower events, delegating lid-close behavior to hypridle.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai

coderabbitai Bot commented Mar 17, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@shunkakinoki has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 5 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 479ef2c8-f33f-4c85-9147-f2e8d0a8fdfd

📥 Commits

Reviewing files that changed from the base of the PR and between 0aa523e and 9e0a8f9.

📒 Files selected for processing (2)
  • @matic/readme.md
  • README.md
📝 Walkthrough

Walkthrough

Power management configuration updates across two files: hypridle.conf now suspends only on battery by checking AC power status, while default.nix configures the system to ignore lid switch events and defer suspension handling to the idle timer.

Changes

Cohort / File(s) Summary
Power Suspend Behavior
config/hyprland/hypridle.conf
Modified suspend command to check AC power status before suspending; only suspends when not plugged into AC power (battery mode).
Lid Switch Handling
named-hosts/matic/default.nix
Configured login manager to ignore lid switch events in both normal and external power scenarios, delegating suspension control to the hypridle idle timer.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit hops with glee so bright,
The laptop stays awake when plugged just right!
Lid closed? No fear, no sudden sleep,
Idle timers watch—those secrets keep.
Smart power now, both wise and free! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main changes: improving power management for lid close handling and AC power detection across two configuration files.
Description check ✅ Passed The description clearly explains the purpose and implementation details of the changes, with a concrete test plan that covers the expected behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/matic-power-management
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mesa-dot-dev

mesa-dot-dev Bot commented Mar 17, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Improved power management on matic by delegating lid close suspension to hypridle and preventing automatic suspend when connected to AC power.

What changed?

  • config/hyprland/hypridle.conf: Modified the 30-minute system suspend listener to activate only when on battery power.
  • named-hosts/matic/default.nix: Configured services.logind to ignore lid close events (HandleLidSwitch and HandleLidSwitchExternalPower set to "ignore") to allow hypridle to manage suspension.

Description generated by Mesa. Update settings

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves power management on the 'matic' host by delegating lid-close actions to hypridle and preventing auto-suspension when on AC power. The changes are logical and correctly implemented. I've added a couple of suggestions for minor improvements: one to simplify the AC power check in hypridle.conf for better efficiency and robustness, and another to remove a redundant configuration line in default.nix for conciseness.

listener {
timeout = 1800
on-timeout = systemctl suspend
on-timeout = bash -c 'cat /sys/class/power_supply/AC*/online | grep -q 1 || systemctl suspend'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The command to check for AC power can be simplified by using grep directly on the file, which avoids the need for cat and a pipe. This is slightly more efficient. I've also added 2>/dev/null to suppress potential error messages if the power supply path doesn't exist, making the execution cleaner.

    on-timeout = bash -c 'grep -q 1 /sys/class/power_supply/AC*/online 2>/dev/null || systemctl suspend'

Comment on lines +136 to +137
services.logind.settings.Login.HandleLidSwitch = "ignore";
services.logind.settings.Login.HandleLidSwitchExternalPower = "ignore";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The HandleLidSwitchExternalPower setting is redundant here. According to the logind.conf documentation, if HandleLidSwitchExternalPower is not set, it defaults to the value of HandleLidSwitch. Since you are setting both to ignore, you can safely remove the HandleLidSwitchExternalPower line to make the configuration more concise.

        services.logind.settings.Login.HandleLidSwitch = "ignore";

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts power-management behavior on the matic host so lid-close no longer triggers an immediate suspend via logind, and Hyprland’s idle daemon (hypridle) only suspends when on battery power.

Changes:

  • Configure systemd-logind to ignore lid-close events (on battery and external power) so idle timers control suspension.
  • Update hypridle’s 30-minute suspend listener to conditionally suspend only when not on AC power.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
named-hosts/matic/default.nix Sets logind lid-switch handling to ignore so lid close doesn’t force immediate suspend.
config/hyprland/hypridle.conf Adds an AC-power check before running systemctl suspend for the 30-minute idle action.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

listener {
timeout = 1800
on-timeout = systemctl suspend
on-timeout = bash -c 'cat /sys/class/power_supply/AC*/online | grep -q 1 || systemctl suspend'

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="named-hosts/matic/default.nix">

<violation number="1" location="named-hosts/matic/default.nix:136">
P2: Delegating lid-close handling entirely to `hypridle` breaks suspend at the greeter/logout path. Since `hypridle` only runs inside a logged-in Hyprland session, closing the lid before login or after logout will now be ignored and the laptop stays awake.</violation>
</file>

<file name="config/hyprland/hypridle.conf">

<violation number="1" location="config/hyprland/hypridle.conf:31">
P2: This AC-power check only matches `online=1`, but the kernel ABI also allows `online=2` for programmable external supplies. On those chargers, the idle action will still suspend while plugged in.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

# Power button behavior - lock screen instead of shutdown
services.logind.settings.Login.HandlePowerKey = "lock";
# Ignore lid close — let hypridle's 30-min idle timer handle suspension
services.logind.settings.Login.HandleLidSwitch = "ignore";

@cubic-dev-ai cubic-dev-ai Bot Mar 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Delegating lid-close handling entirely to hypridle breaks suspend at the greeter/logout path. Since hypridle only runs inside a logged-in Hyprland session, closing the lid before login or after logout will now be ignored and the laptop stays awake.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At named-hosts/matic/default.nix, line 136:

<comment>Delegating lid-close handling entirely to `hypridle` breaks suspend at the greeter/logout path. Since `hypridle` only runs inside a logged-in Hyprland session, closing the lid before login or after logout will now be ignored and the laptop stays awake.</comment>

<file context>
@@ -132,6 +132,9 @@ inputs.nixpkgs.lib.nixosSystem {
         # Power button behavior - lock screen instead of shutdown
         services.logind.settings.Login.HandlePowerKey = "lock";
+        # Ignore lid close — let hypridle's 30-min idle timer handle suspension
+        services.logind.settings.Login.HandleLidSwitch = "ignore";
+        services.logind.settings.Login.HandleLidSwitchExternalPower = "ignore";
 
</file context>
Fix with Cubic

listener {
timeout = 1800
on-timeout = systemctl suspend
on-timeout = bash -c 'cat /sys/class/power_supply/AC*/online | grep -q 1 || systemctl suspend'

@cubic-dev-ai cubic-dev-ai Bot Mar 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This AC-power check only matches online=1, but the kernel ABI also allows online=2 for programmable external supplies. On those chargers, the idle action will still suspend while plugged in.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/hyprland/hypridle.conf, line 31:

<comment>This AC-power check only matches `online=1`, but the kernel ABI also allows `online=2` for programmable external supplies. On those chargers, the idle action will still suspend while plugged in.</comment>

<file context>
@@ -25,8 +25,8 @@ listener {
 listener {
     timeout = 1800
-    on-timeout = systemctl suspend
+    on-timeout = bash -c 'cat /sys/class/power_supply/AC*/online | grep -q 1 || systemctl suspend'
 }
</file context>
Suggested change
on-timeout = bash -c 'cat /sys/class/power_supply/AC*/online | grep -q 1 || systemctl suspend'
on-timeout = bash -c 'grep -Eq "^(1|2)$" /sys/class/power_supply/AC*/online || systemctl suspend'
Fix with Cubic

@shunkakinoki
shunkakinoki enabled auto-merge (squash) March 17, 2026 10:02
@shunkakinoki
shunkakinoki disabled auto-merge March 17, 2026 10:03
@shunkakinoki
shunkakinoki merged commit 3d2f57b into main Mar 17, 2026
26 checks passed
@shunkakinoki
shunkakinoki deleted the feat/matic-power-management branch March 17, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants