feat: add screen magnifier toggle#1116
Conversation
1. Add a new dsettings key `viewZoomEnable` to control whether screen magnifier shortcuts are enabled. 2. Initialize and store a dedicated keybinding config manager so the shortcut manager can read the new keybinding setting at runtime. 3. Apply the magnifier switch during startup by calling `SetViewZoomEnabled`, ensuring the zoom feature state matches persisted configuration immediately after initialization. 4. Listen for `viewZoomEnable` changes in dconfig and dynamically enable or disable the related zoom shortcuts without requiring a restart. 5. Introduce dedicated handling for zoom-related KWin shortcut IDs (`viewZoomIn`, `viewZoomOut`, `viewActualSize`), including adding them only when enabled and removing them when disabled. 6. Prevent zoom shortcuts from being added through the normal KWin shortcut loading flow to avoid duplicate registration and shortcut invalidation during initialization. 7. Control the KWin `zoom` effect through `gdbus` by checking whether the effect is loaded and loading or unloading it based on the configured switch. 8. Use safe fallback behavior by treating the feature as enabled when configuration cannot be read, which helps preserve existing behavior and avoid accidentally disabling magnifier functionality. Log: Added a screen magnifier toggle to dynamically enable or disable zoom shortcuts and the zoom effect Influence: 1. Verify that when `viewZoomEnable` is `true`, `viewZoomIn`, `viewZoomOut`, and `viewActualSize` shortcuts are available and trigger the expected magnifier behavior. 2. Verify that when `viewZoomEnable` is `false`, the related zoom shortcuts are removed and no longer take effect. 3. Test startup behavior with the switch enabled and disabled to confirm the runtime state matches the saved configuration after login or daemon restart. 4. Toggle the setting at runtime and confirm the shortcuts are added or removed immediately without restarting the session. 5. On KWin environments, verify that the `zoom` effect is loaded when enabled and unloaded when disabled. 6. Test fallback behavior when dsettings or `gdbus` access fails, ensuring the daemon does not crash and existing shortcut behavior remains as safe as possible. 7. Verify there is no duplicate shortcut registration or shortcut loss for zoom-related actions during initialization on both X11 and Wayland paths. feat: 添加屏幕放大镜开关 1. 新增 dsettings 配置项 `viewZoomEnable`,用于控制是否启用屏幕放大镜相 关快捷键。 2. 初始化并保存独立的 keybinding 配置管理器,使快捷键管理器能够在运行时 读取该按键绑定配置。 3. 在启动初始化阶段调用 `SetViewZoomEnabled` 应用放大镜开关,确保启动后 缩放功能状态与持久化配置保持一致。 4. 在 dconfig 变更监听中增加对 `viewZoomEnable` 的处理,使相关缩放快捷键 可以在运行时动态启用或禁用,无需重启。 5. 为 KWin 的缩放相关快捷键 ID(`viewZoomIn`、`viewZoomOut`、 `viewActualSize`)增加专门处理逻辑,仅在开关开启时添加,关闭时删除。 6. 在常规 KWin 快捷键加载流程中跳过缩放快捷键,避免初始化阶段重复注册导 致快捷键失效。 7. 通过 `gdbus` 控制 KWin 的 `zoom` 特效,先检查特效加载状态,再根据开关 决定加载或卸载该特效。 8. 对配置读取失败场景采用默认启用的兜底策略,以保持现有行为不变,避免误 关闭放大镜功能。 Log: 新增屏幕放大镜开关,可动态启用或禁用缩放快捷键及缩放特效 Influence: 1. 验证当 `viewZoomEnable` 为 `true` 时,`viewZoomIn`、`viewZoomOut`、 `viewActualSize` 快捷键可用,并能触发预期的放大镜行为。 2. 验证当 `viewZoomEnable` 为 `false` 时,相关缩放快捷键会被移除,且不再 生效。 3. 测试在开关开启和关闭两种情况下的启动行为,确认登录或守护进程重启后运 行时状态与保存配置一致。 4. 在运行时切换该设置,确认无需重启会话即可立即添加或移除对应快捷键。 5. 在 KWin 环境下验证开启时会加载 `zoom` 特效,关闭时会卸载该特效。 6. 测试 dsettings 或 `gdbus` 访问失败时的兜底行为,确保守护进程不会崩 溃,并尽可能保持原有快捷键行为稳定。 7. 验证在 X11 和 Wayland 路径下初始化过程中不会出现缩放快捷键重复注册或 丢失的问题。 PMS: BUG-360027 Change-Id: Ic9d9617178a8bec0427205f18b11d89c97d24d14
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff代码。本次代码变更主要为KWin的缩放快捷键增加了一个可通过DConfig动态控制的启用/禁用开关功能。 整体来看,代码逻辑清晰,功能划分明确。但在语法逻辑、代码质量、性能和安全性方面,有一些值得注意和改进的地方。以下是详细的审查意见: 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
综合改进后的代码示例针对上述意见,以下是修改后的核心代码片段参考:
var viewZoomIds = map[string]struct{}{
"viewZoomIn": {},
"viewZoomOut": {},
"viewActualSize": {},
}
// KWin D-Bus 相关常量
const (
kWinDest = "org.kde.KWin"
kWinEffectsPath = "/Effects"
kWinEffectsIface = "org.kde.kwin.Effects"
)
func (sm *ShortcutManager) IsViewZoomEnabled() bool {
if sm.keybindingConfigMgr == nil {
return true
}
v, err := sm.keybindingConfigMgr.Value(0, constants.DSettingsKeyViewZoomEnable)
if err != nil {
return true
}
// 安全的类型断言
val := v.Value()
if b, ok := val.(bool); ok {
return b
}
logger.Warningf("invalid type for config %s: %T", constants.DSettingsKeyViewZoomEnable, val)
return true
}
func (sm *ShortcutManager) DelViewZoomShortcuts() {
for id := range viewZoomIds {
shortcut := sm.GetByIdType(id, ShortcutTypeWM)
if shortcut != nil {
sm.Delete(shortcut)
}
}
}
func (sm *ShortcutManager) SetViewZoomEnabled(wmObj wm.Wm, enabled bool) {
logger.Debugf("SetViewZoomEnabled: %v", enabled)
gdbusArgs := func(method string) []string {
return []string{"call", "--session", "--dest", kWinDest,
"--object-path", kWinEffectsPath,
"--method", kWinEffectsIface + "." + method, "zoom"}
}
runGdbus := func(method string) {
if _, err := exec.Command("gdbus", gdbusArgs(method)...).Output(); err != nil {
logger.Warningf("Failed to %s zoom effect: %v", method, err)
} else {
logger.Infof("Successfully %s zoom effect", method)
}
}
output, err := exec.Command("gdbus", gdbusArgs("isEffectLoaded")...).Output()
if err != nil {
sm.DelViewZoomShortcuts()
logger.Warning(err)
return
}
// 优化字节处理,减少内存分配
loadzoom := bytes.Contains(bytes.ToLower(output), []byte("true"))
if enabled {
sm.addViewZoomKWin(wmObj)
if !loadzoom {
runGdbus("loadEffect")
}
} else {
sm.DelViewZoomShortcuts()
if loadzoom {
runGdbus("unloadEffect")
}
}
}
// initDconfig 修改建议
func (sm *ShortcutManager) initDconfig() {
// ... 原有逻辑 ...
keybindingConfigPath, err := ds.AcquireManager(0, constants.DSettingsAppID, constants.DSettingsKeyBindingName, "")
if err != nil || keybindingConfigPath == "" {
logger.Warning(err)
// 不要 return,避免阻断后续可能的初始化逻辑
} else {
sm.keybindingConfigMgr, err = configManager.NewManager(bus, keybindingConfigPath)
if err != nil {
logger.Warning(err)
}
}
}希望这些审查意见对你有所帮助!如果有任何疑问,欢迎随时提问。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602, 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 |
viewZoomEnableto control whether screen magnifier shortcuts are enabled.SetViewZoomEnabled, ensuring the zoom feature state matches persisted configuration immediately after initialization.viewZoomEnablechanges in dconfig and dynamically enable or disable the related zoom shortcuts without requiring a restart.viewZoomIn,viewZoomOut,viewActualSize), including adding them only when enabled and removing them when disabled.zoomeffect throughgdbusby checking whether the effect is loaded and loading or unloading it based on the configured switch.Log: Added a screen magnifier toggle to dynamically enable or disable zoom shortcuts and the zoom effect
Influence:
viewZoomEnableistrue,viewZoomIn,viewZoomOut, andviewActualSizeshortcuts are available and trigger the expected magnifier behavior.viewZoomEnableisfalse, the related zoom shortcuts are removed and no longer take effect.zoomeffect is loaded when enabled and unloaded when disabled.gdbusaccess fails, ensuring the daemon does not crash and existing shortcut behavior remains as safe as possible.feat: 添加屏幕放大镜开关
viewZoomEnable,用于控制是否启用屏幕放大镜相 关快捷键。SetViewZoomEnabled应用放大镜开关,确保启动后 缩放功能状态与持久化配置保持一致。viewZoomEnable的处理,使相关缩放快捷键 可以在运行时动态启用或禁用,无需重启。viewZoomIn、viewZoomOut、viewActualSize)增加专门处理逻辑,仅在开关开启时添加,关闭时删除。gdbus控制 KWin 的zoom特效,先检查特效加载状态,再根据开关 决定加载或卸载该特效。Log: 新增屏幕放大镜开关,可动态启用或禁用缩放快捷键及缩放特效
Influence:
viewZoomEnable为true时,viewZoomIn、viewZoomOut、viewActualSize快捷键可用,并能触发预期的放大镜行为。viewZoomEnable为false时,相关缩放快捷键会被移除,且不再 生效。zoom特效,关闭时会卸载该特效。gdbus访问失败时的兜底行为,确保守护进程不会崩 溃,并尽可能保持原有快捷键行为稳定。PMS: BUG-360027
Change-Id: Ic9d9617178a8bec0427205f18b11d89c97d24d14