Skip to content

Commit de33851

Browse files
electricfacefly602
authored andcommitted
fix(display): Touch screen config becomes empty after
unplugging/replugging and canceling mapping dialog - Fixes the issue where the touch screen configuration in the control center becomes empty after unplugging/replugging the device and clicking "Cancel" in the mapping dialog - Optimized touch screen mapping management logic - Added debug logs for tracking mapping updates and cleanup - During early system startup, the window manager may not be fully ready. Add a 5-second cooldown period to ensure the touchscreen configuration dialog is shown after the window manager is stable --- fix(display): 在插拔触控屏并取消映射对话框后,触摸屏配置为空 - 修复了在拔插触控屏设备后,若在映射对话框中点击“取消”,会导致控 制中心内的触摸屏配置变为空的问题 - 优化触摸屏映射管理逻辑 - 增加调试日志,便于跟踪映射更新与清理过程 - 在系统启动早期,窗口管理器功能尚未完善,过早调用触摸屏配置对话 框可能导致显示异常。新增 5 秒冷却期机制,确保窗口管理器就绪后再 弹出对话框 PMS: BUG-275135 Log: 修复拔插触控屏,点击取消后,控制中心触控屏配置为空问题 Influence: 控制中心->设备->触控屏
1 parent d91f2ee commit de33851

1 file changed

Lines changed: 91 additions & 10 deletions

File tree

display1/manager.go

Lines changed: 91 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ const (
9595
defaultTemperatureManual = 6500
9696
defaultRotateScreenTimeDelay = 500
9797

98-
cmdTouchscreenDialogBin = "/usr/lib/deepin-daemon/dde-touchscreen-dialog"
98+
touchscreenDialogCooldownSeconds = 5 // Seconds to wait for window manager ready
99+
cmdTouchscreenDialogBin = "/usr/lib/deepin-daemon/dde-touchscreen-dialog"
99100
)
100101

101102
const (
@@ -200,8 +201,10 @@ type Manager struct {
200201
TouchMap map[string]string
201202
touchscreenMap map[string]touchscreenMapValue
202203
// touch.uuid -> touchScreenDialog cmd
203-
touchScreenDialogMap map[string]*exec.Cmd
204-
touchScreenDialogMutex sync.RWMutex
204+
touchScreenDialogMap map[string]*exec.Cmd
205+
touchScreenDialogMutex sync.RWMutex
206+
touchScreenDialogDelayTimer *time.Timer
207+
touchScreenDialogReady bool
205208

206209
CurrentCustomId string
207210
Primary string
@@ -2428,6 +2431,18 @@ func (m *Manager) removeTouchscreenByDeviceNode(deviceNode string) {
24282431
}
24292432

24302433
func (m *Manager) initTouchscreens() {
2434+
// Start cooldown timer for touchscreen dialog
2435+
// Wait for window manager to be ready before showing dialogs
2436+
logger.Debugf("initTouchscreens: start %ds cooldown for touchscreen dialog", touchscreenDialogCooldownSeconds)
2437+
m.touchScreenDialogDelayTimer = time.AfterFunc(touchscreenDialogCooldownSeconds*time.Second, func() {
2438+
m.touchScreenDialogMutex.Lock()
2439+
m.touchScreenDialogReady = true
2440+
m.touchScreenDialogMutex.Unlock()
2441+
logger.Debug("initTouchscreens: cooldown ended, touchscreen dialog ready")
2442+
// Show dialogs for touchscreens without config
2443+
m.showTouchscreenDialogs()
2444+
})
2445+
24312446
_, err := m.dbusDaemon.ConnectNameOwnerChanged(func(name, oldOwner, newOwner string) {
24322447
if name == m.inputDevices.ServiceName_() && newOwner == "" {
24332448
m.setPropTouchscreens(nil)
@@ -2610,14 +2625,23 @@ func (m *Manager) updateTouchscreenMap(outputName string, touchUUID string, auto
26102625
logger.Warning(err)
26112626
}
26122627

2628+
logger.Debugf("updateTouchscreenMap: %s -> %s", touchUUID, outputName)
26132629
m.TouchMap[touchUUID] = outputName
2614-
26152630
err = m.emitPropChangedTouchMap(m.TouchMap)
26162631
if err != nil {
26172632
logger.Warning("failed to emit TouchMap PropChanged:", err)
26182633
}
26192634
}
26202635

2636+
func (m *Manager) pureUpdateTouchMap(outputName string, touchUUID string) {
2637+
logger.Debugf("pureUpdateTouchMap: %s -> %s", touchUUID, outputName)
2638+
m.PropsMu.Lock()
2639+
defer m.PropsMu.Unlock()
2640+
2641+
m.TouchMap[touchUUID] = outputName
2642+
m.emitPropChangedTouchMap(m.TouchMap)
2643+
}
2644+
26212645
func (m *Manager) associateTouch(monitor *Monitor, touchUUID string, auto bool) error {
26222646
m.PropsMu.Lock()
26232647
defer m.PropsMu.Unlock()
@@ -2859,6 +2883,7 @@ func (m *Manager) handleTouchscreenChanged() {
28592883
if err != nil {
28602884
logger.Warning("failed to map touchscreen:", err)
28612885
}
2886+
m.pureUpdateTouchMap(monitor.Name, touch.UUID)
28622887
continue
28632888
}
28642889
}
@@ -2919,6 +2944,39 @@ func (m *Manager) handleTouchscreenChanged() {
29192944
if err != nil {
29202945
logger.Warning("failed to map touchscreen:", err)
29212946
}
2947+
m.pureUpdateTouchMap(monitor.Name, touch.UUID)
2948+
}
2949+
}
2950+
2951+
m.cleanupStaleTouchMap()
2952+
}
2953+
2954+
// cleanupStaleTouchMap removes stale touchscreen mappings from TouchMap
2955+
func (m *Manager) cleanupStaleTouchMap() {
2956+
m.PropsMu.Lock()
2957+
defer m.PropsMu.Unlock()
2958+
2959+
// Build set of currently existing touchscreen UUIDs
2960+
existingUUIDs := make(map[string]bool)
2961+
for _, touch := range m.Touchscreens {
2962+
existingUUIDs[touch.UUID] = true
2963+
}
2964+
2965+
// Check and remove UUIDs that no longer exist in TouchMap
2966+
updated := false
2967+
for touchUUID := range m.TouchMap {
2968+
if !existingUUIDs[touchUUID] {
2969+
logger.Debugf("remove stale touchscreen UUID from TouchMap: %s", touchUUID)
2970+
delete(m.TouchMap, touchUUID)
2971+
updated = true
2972+
}
2973+
}
2974+
2975+
// Emit property changed signal if any deletion occurred
2976+
if updated {
2977+
err := m.emitPropChangedTouchMap(m.TouchMap)
2978+
if err != nil {
2979+
logger.Warning("failed to emit TouchMap PropChanged:", err)
29222980
}
29232981
}
29242982
}
@@ -2946,15 +3004,38 @@ func (m *Manager) initScreenRotation() {
29463004
}
29473005
}
29483006

2949-
// 检查当前连接的所有触控面板, 如果没有映射配置, 那么调用 OSD 弹窗.
3007+
// showTouchscreenDialogs checks all connected touchscreens, if no mapping config exists, show OSD dialog.
29503008
func (m *Manager) showTouchscreenDialogs() {
3009+
m.touchScreenDialogMutex.RLock()
3010+
ready := m.touchScreenDialogReady
3011+
m.touchScreenDialogMutex.RUnlock()
3012+
3013+
if !ready {
3014+
logger.Debug("showTouchscreenDialogs: skip, still in cooldown period")
3015+
return
3016+
}
3017+
3018+
m.doShowTouchscreenDialogs()
3019+
}
3020+
3021+
// doShowTouchscreenDialogs actually shows dialogs for touchscreens without config.
3022+
func (m *Manager) doShowTouchscreenDialogs() {
3023+
// Collect touchscreens that need configuration
3024+
m.PropsMu.RLock()
3025+
var touchscreensNeedConfig []*Touchscreen
29513026
for _, touch := range m.Touchscreens {
29523027
if _, ok := m.touchscreenMap[touch.UUID]; !ok {
2953-
logger.Debug("cannot find touchscreen", touch.UUID, "'s configure, show OSD")
2954-
err := m.showTouchscreenDialog(touch.UUID)
2955-
if err != nil {
2956-
logger.Warning("shotTouchscreenOSD", err)
2957-
}
3028+
touchscreensNeedConfig = append(touchscreensNeedConfig, touch)
3029+
}
3030+
}
3031+
m.PropsMu.RUnlock()
3032+
3033+
// Show dialogs for touchscreens without config
3034+
for _, touch := range touchscreensNeedConfig {
3035+
logger.Debugf("cannot find touchscreen %s configuration, show touchscreen dialog", touch.UUID)
3036+
err := m.showTouchscreenDialog(touch.UUID)
3037+
if err != nil {
3038+
logger.Warning("failed to show touchscreen dialog", err)
29583039
}
29593040
}
29603041
}

0 commit comments

Comments
 (0)