forked from linuxdeepin/dde-daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale.go
107 lines (94 loc) · 3.09 KB
/
scale.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: jouyouyun <jouyouwen717@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package appearance
import (
"sync/atomic"
"github.com/godbus/dbus"
notifications "github.com/linuxdeepin/go-dbus-factory/org.freedesktop.notifications"
"pkg.deepin.io/lib/gettext"
)
func (m *Manager) getScaleFactor() float64 {
scaleFactor, err := m.xSettings.GetScaleFactor(dbus.FlagNoAutoStart)
if err != nil {
logger.Warning("failed to get scale factor:", err)
scaleFactor = 1.0
}
return scaleFactor
}
func (m *Manager) setScaleFactor(scale float64) error {
err := m.xSettings.SetScaleFactor(dbus.FlagNoAutoStart, scale)
if err != nil {
logger.Warning("failed to set scale factor:", err)
}
return err
}
var notifyId uint32
const icon = "dialog-window-scale"
func handleSetScaleFactorDone() {
const (
expireTimeout = 15 * 1000
requestLogout = "dbus-send,--type=method_call,--dest=com.deepin.SessionManager,/com/deepin/SessionManager,com.deepin.SessionManager.RequestLogout"
)
body := gettext.Tr("Log out for display scaling settings to take effect")
summary := gettext.Tr("Set successfully")
sessionBus, err := dbus.SessionBus()
if err != nil {
logger.Warning(err)
return
}
nid := atomic.LoadUint32(¬ifyId)
notifier := notifications.NewNotifications(sessionBus)
nid, err = notifier.Notify(0, "dde-control-center", nid,
icon, summary, body,
[]string{"_logout", gettext.Tr("Log Out Now"), "_later", gettext.Tr("Later")},
map[string]dbus.Variant{
"x-deepin-action-_logout": dbus.MakeVariant(requestLogout),
"x-deepin-action-_later": dbus.MakeVariant(""),
}, expireTimeout)
if err != nil {
logger.Warning(err)
} else {
atomic.StoreUint32(¬ifyId, nid)
}
}
func handleSetScaleFactorStarted() {
body := gettext.Tr("Setting display scaling")
summary := gettext.Tr("Display scaling")
sessionBus, err := dbus.SessionBus()
if err != nil {
logger.Warning(err)
return
}
nid := atomic.LoadUint32(¬ifyId)
notifier := notifications.NewNotifications(sessionBus)
nid, err = notifier.Notify(0, "dde-control-center", nid,
icon, summary, body,
nil, nil, 0)
if err != nil {
logger.Warning(err)
} else {
atomic.StoreUint32(¬ifyId, nid)
}
}
func (m *Manager) setScreenScaleFactors(factors map[string]float64) error {
return m.xSettings.SetScreenScaleFactors(dbus.FlagNoAutoStart, factors)
}
func (m *Manager) getScreenScaleFactors() (map[string]float64, error) {
return m.xSettings.GetScreenScaleFactors(dbus.FlagNoAutoStart)
}