Skip to content

Commit 9d8777c

Browse files
committed
chore: dconfig to control if trayicon1 register itself as selection manager
允许通过 DConfig 控制 dde-daemon 的 trayicon1 模块是否注册自身为 xembed selectionmanager,默认为仅在 x11 下注册(现状),允许任何时候都注册、 仅x11/仅wayland注册、任何时候都不注册。 Log:
1 parent d37c44c commit 9d8777c

2 files changed

Lines changed: 70 additions & 4 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"magic": "dsg.config.meta",
3+
"version": "1.0",
4+
"contents": {
5+
"traySelectionManagerScope": {
6+
"value": "x11-only",
7+
"serial": 0,
8+
"flags": [],
9+
"name": "traySelectionManagerScope",
10+
"name[zh_CN]": "托盘 Selection Manager 注册范围",
11+
"description": "Control when to register tray selection manager: never, x11-only, wayland-only, always",
12+
"description[zh_CN]": "控制何时注册托盘 Selection Manager:never(不注册)、x11-only(仅 X11)、wayland-only(仅 Wayland)、always(始终注册)",
13+
"permissions": "readwrite",
14+
"visibility": "public"
15+
}
16+
}
17+
}

trayicon1/daemon.go

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

55
package trayicon
66

77
import (
8-
"github.com/godbus/dbus/v5"
98
"os"
109

10+
"github.com/godbus/dbus/v5"
11+
"github.com/linuxdeepin/dde-daemon/common/dconfig"
1112
"github.com/linuxdeepin/dde-daemon/loader"
1213
"github.com/linuxdeepin/go-lib/dbusutil"
1314
"github.com/linuxdeepin/go-lib/log"
@@ -23,6 +24,17 @@ type Daemon struct {
2324

2425
const moduleName = "trayicon"
2526

27+
const (
28+
dconfigAppID = "org.deepin.dde.daemon"
29+
dconfigTrayIconID = "org.deepin.dde.daemon.trayicon"
30+
dconfigKeyTraySelectionScope = "traySelectionManagerScope"
31+
32+
scopeNever = "never"
33+
scopeX11Only = "x11-only"
34+
scopeWaylandOnly = "wayland-only"
35+
scopeAlways = "always"
36+
)
37+
2638
func NewDaemon(logger *log.Logger) *Daemon {
2739
daemon := new(Daemon)
2840
daemon.ModuleBase = loader.NewModuleBase(moduleName, daemon, logger)
@@ -37,6 +49,40 @@ func (d *Daemon) Name() string {
3749
return moduleName
3850
}
3951

52+
func shouldRegisterTraySelectionManager(scope string) bool {
53+
sessionType := os.Getenv("XDG_SESSION_TYPE")
54+
isWayland := sessionType == "wayland"
55+
56+
switch scope {
57+
case scopeNever:
58+
return false
59+
case scopeX11Only:
60+
return !isWayland
61+
case scopeWaylandOnly:
62+
return isWayland
63+
case scopeAlways:
64+
return true
65+
default:
66+
return !isWayland
67+
}
68+
}
69+
70+
func getTraySelectionManagerScope() string {
71+
trayIconDConfig, err := dconfig.NewDConfig(dconfigAppID, dconfigTrayIconID, "")
72+
if err != nil {
73+
logger.Warning("failed to create trayicon dconfig:", err)
74+
return scopeNever
75+
}
76+
77+
scope, err := trayIconDConfig.GetValueString(dconfigKeyTraySelectionScope)
78+
if err != nil {
79+
logger.Warning("failed to get tray selection manager scope:", err)
80+
return scopeNever
81+
}
82+
83+
return scope
84+
}
85+
4086
func (d *Daemon) Start() error {
4187
var err error
4288
service := loader.GetService()
@@ -48,8 +94,10 @@ func (d *Daemon) Start() error {
4894
d.sigLoop = dbusutil.NewSignalLoop(sessionBus, 10)
4995
d.sigLoop.Start()
5096

51-
if os.Getenv("XDG_SESSION_TYPE") != "wayland" {
52-
// init x conn
97+
// Enable this on both x11 and wayland(for xwayland support)
98+
// #region init x conn
99+
scope := getTraySelectionManagerScope()
100+
if shouldRegisterTraySelectionManager(scope) {
53101
XConn, err = x.NewConn()
54102
if err != nil {
55103
return err
@@ -79,6 +127,7 @@ func (d *Daemon) Start() error {
79127
return err
80128
}
81129
}
130+
// #endregion
82131

83132
if os.Getenv("DDE_DISABLE_STATUS_NOTIFIER_WATCHER") != "1" {
84133
d.snw = newStatusNotifierWatcher(service, d.sigLoop)

0 commit comments

Comments
 (0)