@@ -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
101102const (
@@ -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
24302433func (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+
26212645func (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 .
29503008func (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