-
Notifications
You must be signed in to change notification settings - Fork 106
fix: skip screensaver tasks on wayland sessions #1000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The code was modified to skip adding screensaver tasks when running under Wayland sessions (detected by XDG_SESSION_TYPE=wayland environment variable). This change is necessary because in treeland (Wayland compositor), screensaver management is handled by treeland itself, and the backend should not control screensaver functionality. The condition ensures that screensaver tasks are only added for non-Wayland sessions (like X11). Influence: 1. Test power save plan updates on Wayland sessions to verify screensaver tasks are not added 2. Test on X11 sessions to ensure screensaver tasks are still added as before 3. Verify that other power management tasks (lock, sleep, etc.) continue to work normally 4. Test with different screenSaverStartDelay values to ensure conditional logic works correctly 5. Verify environment variable detection works properly in different session types fix: 在 Wayland 会话中跳过屏保任务 修改了代码,在 Wayland 会话(通过 XDG_SESSION_TYPE=wayland 环境变量检 测)下跳过添加屏保任务。这个变更是必要的,因为在 treeland(Wayland 合成 器)中,屏保管理由 treeland 自行处理,后端不应控制屏保功能。这个条件确保 屏保任务只被添加到非 Wayland 会话(如 X11)中。 Influence: 1. 在 Wayland 会话中测试电源保存计划更新,验证屏保任务未被添加 2. 在 X11 会话中测试,确保屏保任务仍像以前一样被添加 3. 验证其他电源管理任务(锁定、休眠等)继续正常工作 4. 使用不同的 screenSaverStartDelay 值测试,确保条件逻辑正常工作 5. 验证环境变量检测在不同会话类型中正常工作
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds an environment-based guard so that screensaver tasks are only scheduled on non-Wayland sessions, leaving other power management tasks unchanged. Sequence diagram for powerSavePlan.Update screensaver scheduling on Wayland vs non-WaylandsequenceDiagram
participant Caller
participant powerSavePlan
participant OS_Env
participant TaskScheduler
Caller->>powerSavePlan: Update(screenSaverStartDelay, lockDelay, ...)
activate powerSavePlan
powerSavePlan->>powerSavePlan: canAddToTasks(screenSaverStart, screenSaverStartDelay, tasks)
alt screenSaverStartDelay <= 0 or cannot add
powerSavePlan-->>Caller: return without adding screensaver task
else screenSaverStartDelay > 0 and can add
powerSavePlan->>OS_Env: Getenv(XDG_SESSION_TYPE)
OS_Env-->>powerSavePlan: sessionType
alt sessionType == wayland
powerSavePlan->>TaskScheduler: do not append screenSaverStart task
else sessionType != wayland
powerSavePlan->>TaskScheduler: append metaTask screenSaverStart with delay
TaskScheduler-->>powerSavePlan: tasks updated
end
powerSavePlan-->>Caller: return with updated tasks
end
deactivate powerSavePlan
Updated class diagram for powerSavePlan screensaver task schedulingclassDiagram
class powerSavePlan {
+Update(screenSaverStartDelay int, lockDelay int, otherDelay int)
+startScreensaver()
}
class metaTask {
+string name
+int delay
+function fn
}
class OSEnvironment {
+Getenv(key string) string
}
powerSavePlan "1" --> "*" metaTask : schedules
powerSavePlan --> OSEnvironment : reads XDG_SESSION_TYPE
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- Calling
os.Getenv("XDG_SESSION_TYPE")insideUpdateon every invocation may be unnecessarily repetitive; consider reading and caching the session type once (or passing it in) and reusing that value when building tasks. - The
"wayland"string is currently hard-coded; consider centralizing this session-type check in a helper (e.g.,isWaylandSession()) to avoid magic strings and make it easier to adapt if additional Wayland variants or detection logic are needed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Calling `os.Getenv("XDG_SESSION_TYPE")` inside `Update` on every invocation may be unnecessarily repetitive; consider reading and caching the session type once (or passing it in) and reusing that value when building tasks.
- The `"wayland"` string is currently hard-coded; consider centralizing this session-type check in a helper (e.g., `isWaylandSession()`) to avoid magic strings and make it easier to adapt if additional Wayland variants or detection logic are needed.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review这段代码的修改意图是:在 Wayland 会话环境下(具体是针对 treeland 窗口管理器),由窗口管理器自行管理屏保逻辑,因此后端服务不再添加屏保启动的任务。 以下是对该代码修改的详细审查意见,包括语法逻辑、代码质量、性能和安全方面的建议: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
总结与重构建议为了提高代码的健壮性和可读性,建议对代码进行如下微调: // 定义常量
const (
TaskNameScreenSaverStart = "screenSaverStart"
EnvSessionType = "XDG_SESSION_TYPE"
SessionTypeWayland = "wayland"
)
// 可选:增加辅助函数提高可读性
func isWaylandSession() bool {
return os.Getenv(EnvSessionType) == SessionTypeWayland
}
// 在 Update 函数中使用
if screenSaverStartDelay > 0 && canAddToTasks(TaskNameScreenSaverStart, screenSaverStartDelay, tasks) {
// treeland 下屏保由 treeland 自行管理,后端不控制。
// 注意:如果未来有其他 Wayland 合成器不支持自行管理,此处逻辑可能需要调整。
if !isWaylandSession() {
tasks = append(tasks, metaTask{
name: TaskNameScreenSaverStart,
delay: screenSaverStartDelay,
fn: psp.startScreensaver,
})
}
}核心建议: |
|
TAG Bot New tag: 6.1.72 |
The code was modified to skip adding screensaver tasks when running under Wayland sessions (detected by XDG_SESSION_TYPE=wayland environment variable). This change is necessary because in treeland (Wayland compositor), screensaver management is handled by treeland itself, and the backend should not control screensaver functionality. The condition ensures that screensaver tasks are only added for non-Wayland sessions (like X11).
Influence:
fix: 在 Wayland 会话中跳过屏保任务
修改了代码,在 Wayland 会话(通过 XDG_SESSION_TYPE=wayland 环境变量检 测)下跳过添加屏保任务。这个变更是必要的,因为在 treeland(Wayland 合成
器)中,屏保管理由 treeland 自行处理,后端不应控制屏保功能。这个条件确保
屏保任务只被添加到非 Wayland 会话(如 X11)中。
Influence:
Summary by Sourcery
Bug Fixes: