805 lines
38 KiB
Diff
805 lines
38 KiB
Diff
From 427082b52f1ec2cf91bcdf1e976e2433e90a072a Mon Sep 17 00:00:00 2001
|
||
From: huangjiawen <huangjiawen@kylinsec.com.cn>
|
||
Date: Wed, 29 Mar 2023 14:01:24 +0800
|
||
Subject: [PATCH 2/2] feature(menu): Add UI for modal power options
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
- 添加模态电源选项功能界面
|
||
Related #67101
|
||
|
||
Signed-off-by: huangjiawen <huangjiawen@kylinsec.com.cn>
|
||
---
|
||
config.h.in | 1 +
|
||
icons/kiran-power-hibernate.svg | 42 ++++++
|
||
icons/kiran-power-lock_screen.svg | 42 ++++++
|
||
icons/kiran-power-logout.svg | 42 ++++++
|
||
icons/kiran-power-reboot.svg | 42 ++++++
|
||
icons/kiran-power-shutdown.svg | 42 ++++++
|
||
icons/kiran-power-suspend.svg | 42 ++++++
|
||
icons/kiran-power-switch_user.svg | 42 ++++++
|
||
src/menu/menu-applet-window.cpp | 21 ++-
|
||
src/menu/menu-applet-window.h | 2 +
|
||
src/menu/menu-power-button.cpp | 19 +++
|
||
src/menu/menu-power-button.h | 6 +
|
||
src/menu/menu-power-dialog.cpp | 216 ++++++++++++++++++++++++++++++
|
||
src/menu/menu-power-dialog.h | 43 ++++++
|
||
14 files changed, 601 insertions(+), 1 deletion(-)
|
||
create mode 100644 icons/kiran-power-hibernate.svg
|
||
create mode 100644 icons/kiran-power-lock_screen.svg
|
||
create mode 100644 icons/kiran-power-logout.svg
|
||
create mode 100644 icons/kiran-power-reboot.svg
|
||
create mode 100644 icons/kiran-power-shutdown.svg
|
||
create mode 100644 icons/kiran-power-suspend.svg
|
||
create mode 100644 icons/kiran-power-switch_user.svg
|
||
create mode 100644 src/menu/menu-power-dialog.cpp
|
||
create mode 100644 src/menu/menu-power-dialog.h
|
||
|
||
diff --git a/config.h.in b/config.h.in
|
||
index 33b04f2..7369f6f 100644
|
||
--- a/config.h.in
|
||
+++ b/config.h.in
|
||
@@ -5,4 +5,5 @@
|
||
#define PACKAGE_VERSION "@PROJECT_VERSION@"
|
||
#define GETTEXT_PACKAGE PACKAGE_NAME
|
||
#define COPYRIGHT "Copyright ©2020 KylinSec. All rights reserved."
|
||
+#cmakedefine POWER_DIALOG
|
||
|
||
diff --git a/icons/kiran-power-hibernate.svg b/icons/kiran-power-hibernate.svg
|
||
new file mode 100644
|
||
index 0000000..146b603
|
||
--- /dev/null
|
||
+++ b/icons/kiran-power-hibernate.svg
|
||
@@ -0,0 +1,42 @@
|
||
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
||
+ <metadata><?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
||
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c138 79.159824, 2016/09/14-01:09:01 ">
|
||
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||
+ <rdf:Description rdf:about=""
|
||
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/">
|
||
+ <xmp:CreatorTool>Adobe Photoshop CC 2017 (Windows)</xmp:CreatorTool>
|
||
+ </rdf:Description>
|
||
+ </rdf:RDF>
|
||
+</x:xmpmeta>
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+<?xpacket end="w"?></metadata>
|
||
+<defs>
|
||
+ <style>
|
||
+ .cls-1 {
|
||
+ fill: #fff;
|
||
+ fill-rule: evenodd;
|
||
+ }
|
||
+ </style>
|
||
+ </defs>
|
||
+ <path id="睡眠" class="cls-1" d="M960.047,552c-0.364,0-.743-0.014-1.121-0.044a16.052,16.052,0,0,1-.873-31.941,1.779,1.779,0,0,1,1.5,3.011,9.487,9.487,0,0,0,13.419,13.411,1.8,1.8,0,0,1,2.037-.32,1.77,1.77,0,0,1,.976,1.818A16.044,16.044,0,0,1,960.047,552h0Zm-4.512-28.407a13.154,13.154,0,1,0,16.883,16.873,12.4,12.4,0,0,1-16.883-16.873h0Zm0,0" transform="translate(-943.985 -520)"/>
|
||
+</svg>
|
||
diff --git a/icons/kiran-power-lock_screen.svg b/icons/kiran-power-lock_screen.svg
|
||
new file mode 100644
|
||
index 0000000..0dea8ec
|
||
--- /dev/null
|
||
+++ b/icons/kiran-power-lock_screen.svg
|
||
@@ -0,0 +1,42 @@
|
||
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
||
+ <metadata><?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
||
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c138 79.159824, 2016/09/14-01:09:01 ">
|
||
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||
+ <rdf:Description rdf:about=""
|
||
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/">
|
||
+ <xmp:CreatorTool>Adobe Photoshop CC 2017 (Windows)</xmp:CreatorTool>
|
||
+ </rdf:Description>
|
||
+ </rdf:RDF>
|
||
+</x:xmpmeta>
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+<?xpacket end="w"?></metadata>
|
||
+<defs>
|
||
+ <style>
|
||
+ .cls-1 {
|
||
+ fill: #fff;
|
||
+ fill-rule: evenodd;
|
||
+ }
|
||
+ </style>
|
||
+ </defs>
|
||
+ <path id="锁屏" class="cls-1" d="M1056.72,533.141h-19.88v-8.363a2.165,2.165,0,0,1,2.23-2.091h9.86a2.165,2.165,0,0,1,2.23,2.091v9.539a0.308,0.308,0,0,0,.32.3h2.22a0.308,0.308,0,0,0,.32-0.3v-9.539a4.942,4.942,0,0,0-5.09-4.779h-9.86a4.936,4.936,0,0,0-5.09,4.779v8.363h-2.71a1.234,1.234,0,0,0-1.27,1.194V550.8a1.234,1.234,0,0,0,1.27,1.2h25.45a1.237,1.237,0,0,0,1.28-1.2V534.335a1.237,1.237,0,0,0-1.28-1.194h0Zm-1.59,16.17h-22.27V535.828h22.27v13.483Zm0,0" transform="translate(-1028 -520)"/>
|
||
+</svg>
|
||
diff --git a/icons/kiran-power-logout.svg b/icons/kiran-power-logout.svg
|
||
new file mode 100644
|
||
index 0000000..b7a1645
|
||
--- /dev/null
|
||
+++ b/icons/kiran-power-logout.svg
|
||
@@ -0,0 +1,42 @@
|
||
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
||
+ <metadata><?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
||
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c138 79.159824, 2016/09/14-01:09:01 ">
|
||
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||
+ <rdf:Description rdf:about=""
|
||
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/">
|
||
+ <xmp:CreatorTool>Adobe Photoshop CC 2017 (Windows)</xmp:CreatorTool>
|
||
+ </rdf:Description>
|
||
+ </rdf:RDF>
|
||
+</x:xmpmeta>
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+<?xpacket end="w"?></metadata>
|
||
+<defs>
|
||
+ <style>
|
||
+ .cls-1 {
|
||
+ fill: #fff;
|
||
+ fill-rule: evenodd;
|
||
+ }
|
||
+ </style>
|
||
+ </defs>
|
||
+ <path id="注销" class="cls-1" d="M891.874,536.262l-5.807,4.667a0.328,0.328,0,0,1-.532-0.262V537.5H872.686a0.332,0.332,0,0,1-.328-0.333v-2.334a0.332,0.332,0,0,1,.328-0.333h12.849v-3.167a0.327,0.327,0,0,1,.532-0.262l5.807,4.667A0.335,0.335,0,0,1,891.874,536.262Zm-0.757-10.487h-2.2a0.321,0.321,0,0,1-.315-0.321v-2.575H862.828v26.242H888.6v-2.575a0.321,0.321,0,0,1,.315-0.321h2.2a0.318,0.318,0,0,1,.315.321v4.175A1.266,1.266,0,0,1,890.172,552H861.256A1.266,1.266,0,0,1,860,550.721V521.279A1.266,1.266,0,0,1,861.256,520h28.92a1.266,1.266,0,0,1,1.256,1.279v4.175A0.318,0.318,0,0,1,891.117,525.775Z" transform="translate(-860 -520)"/>
|
||
+</svg>
|
||
diff --git a/icons/kiran-power-reboot.svg b/icons/kiran-power-reboot.svg
|
||
new file mode 100644
|
||
index 0000000..98de3b5
|
||
--- /dev/null
|
||
+++ b/icons/kiran-power-reboot.svg
|
||
@@ -0,0 +1,42 @@
|
||
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
||
+ <metadata><?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
||
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c138 79.159824, 2016/09/14-01:09:01 ">
|
||
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||
+ <rdf:Description rdf:about=""
|
||
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/">
|
||
+ <xmp:CreatorTool>Adobe Photoshop CC 2017 (Windows)</xmp:CreatorTool>
|
||
+ </rdf:Description>
|
||
+ </rdf:RDF>
|
||
+</x:xmpmeta>
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+<?xpacket end="w"?></metadata>
|
||
+<defs>
|
||
+ <style>
|
||
+ .cls-1 {
|
||
+ fill: #fff;
|
||
+ fill-rule: evenodd;
|
||
+ }
|
||
+ </style>
|
||
+ </defs>
|
||
+ <path id="重启" class="cls-1" d="M801.848,549.493a16.657,16.657,0,0,0,6.152-13,16.007,16.007,0,1,0-32,0,16.646,16.646,0,0,0,5.9,12.793,0.318,0.318,0,0,0,.456-0.053l1.576-2.083a0.338,0.338,0,0,0-.048-0.458,12.6,12.6,0,0,1-.936-0.874,13.172,13.172,0,0,1-2.744-4.195,13.6,13.6,0,0,1,0-10.265,13.172,13.172,0,0,1,2.744-4.195,12.739,12.739,0,0,1,4.068-2.829,12.508,12.508,0,0,1,9.964,0,12.739,12.739,0,0,1,4.068,2.829,13.172,13.172,0,0,1,2.744,4.195,13.631,13.631,0,0,1,0,10.269,13.229,13.229,0,0,1-3.916,5.267l-1.628-2.149a0.317,0.317,0,0,0-.564.124l-1.584,6.69a0.329,0.329,0,0,0,.308.408l6.68,0.033a0.329,0.329,0,0,0,.252-0.532Zm0,0" transform="translate(-776 -520)"/>
|
||
+</svg>
|
||
diff --git a/icons/kiran-power-shutdown.svg b/icons/kiran-power-shutdown.svg
|
||
new file mode 100644
|
||
index 0000000..e36fa4a
|
||
--- /dev/null
|
||
+++ b/icons/kiran-power-shutdown.svg
|
||
@@ -0,0 +1,42 @@
|
||
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
||
+ <metadata><?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
||
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c138 79.159824, 2016/09/14-01:09:01 ">
|
||
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||
+ <rdf:Description rdf:about=""
|
||
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/">
|
||
+ <xmp:CreatorTool>Adobe Photoshop CC 2017 (Windows)</xmp:CreatorTool>
|
||
+ </rdf:Description>
|
||
+ </rdf:RDF>
|
||
+</x:xmpmeta>
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+<?xpacket end="w"?></metadata>
|
||
+<defs>
|
||
+ <style>
|
||
+ .cls-1 {
|
||
+ fill: #fff;
|
||
+ fill-rule: evenodd;
|
||
+ }
|
||
+ </style>
|
||
+ </defs>
|
||
+ <path id="关机" class="cls-1" d="M707.963,552a16.023,16.023,0,0,1-7.139-30.342,0.3,0.3,0,0,1,.429.267V524.3a0.593,0.593,0,0,1-.278.5,13.321,13.321,0,0,0-2.3,1.844,13.188,13.188,0,1,0,18.644,0,13,13,0,0,0-2.3-1.844,0.609,0.609,0,0,1-.279-0.5v-2.378a0.3,0.3,0,0,1,.431-0.266A16.022,16.022,0,0,1,707.963,552Zm1.217-14.223h-2.372a0.3,0.3,0,0,1-.3-0.3V520.294a0.3,0.3,0,0,1,.3-0.3h2.372a0.3,0.3,0,0,1,.3.3V537.48A0.3,0.3,0,0,1,709.18,537.776Z" transform="translate(-692 -520)"/>
|
||
+</svg>
|
||
diff --git a/icons/kiran-power-suspend.svg b/icons/kiran-power-suspend.svg
|
||
new file mode 100644
|
||
index 0000000..c6ea79b
|
||
--- /dev/null
|
||
+++ b/icons/kiran-power-suspend.svg
|
||
@@ -0,0 +1,42 @@
|
||
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
||
+ <metadata><?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
||
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c138 79.159824, 2016/09/14-01:09:01 ">
|
||
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||
+ <rdf:Description rdf:about=""
|
||
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/">
|
||
+ <xmp:CreatorTool>Adobe Photoshop CC 2017 (Windows)</xmp:CreatorTool>
|
||
+ </rdf:Description>
|
||
+ </rdf:RDF>
|
||
+</x:xmpmeta>
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+<?xpacket end="w"?></metadata>
|
||
+<defs>
|
||
+ <style>
|
||
+ .cls-1 {
|
||
+ fill: #fff;
|
||
+ fill-rule: evenodd;
|
||
+ }
|
||
+ </style>
|
||
+ </defs>
|
||
+ <path id="待机" class="cls-1" d="M1227.71,532.418h-9.3a0.289,0.289,0,0,0-.29.287v1.718a0.289,0.289,0,0,0,.29.287h9.3a0.289,0.289,0,0,0,.29-0.287v-1.718a0.289,0.289,0,0,0-.29-0.287h0Zm-4.87,4.87h-4.43a0.289,0.289,0,0,0-.29.287v1.718a0.289,0.289,0,0,0,.29.287h4.43a0.289,0.289,0,0,0,.29-0.287v-1.718a0.289,0.289,0,0,0-.29-0.287h0Zm-12.12-8.075h-1.57a0.4,0.4,0,0,0-.41.4v8.88a0.384,0.384,0,0,0,.17.322l5.41,3.889a0.4,0.4,0,0,0,.56-0.086l0.94-1.257v0a0.4,0.4,0,0,0-.09-0.559l-4.61-3.28v-7.906a0.4,0.4,0,0,0-.4-0.4h0Zm0,0,11.9,12.583h-2.1a0.6,0.6,0,0,0-.51.276,11.592,11.592,0,0,1-9.8,5.336,11.6,11.6,0,0,1-4.5-.9,11.524,11.524,0,0,1-6.16-6.073,11.287,11.287,0,0,1,0-8.88,11.524,11.524,0,0,1,6.16-6.073,11.676,11.676,0,0,1,12.69,2.445,11.785,11.785,0,0,1,1.61,2,0.6,0.6,0,0,0,.51.276h2.1a0.322,0.322,0,0,0,.29-0.476,14,14,0,1,0,0,12.547,0.326,0.326,0,0,0-.29-0.477h0Zm0,0" transform="translate(-1196 -520)"/>
|
||
+</svg>
|
||
diff --git a/icons/kiran-power-switch_user.svg b/icons/kiran-power-switch_user.svg
|
||
new file mode 100644
|
||
index 0000000..42d584a
|
||
--- /dev/null
|
||
+++ b/icons/kiran-power-switch_user.svg
|
||
@@ -0,0 +1,42 @@
|
||
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
||
+ <metadata><?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
||
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c138 79.159824, 2016/09/14-01:09:01 ">
|
||
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||
+ <rdf:Description rdf:about=""
|
||
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/">
|
||
+ <xmp:CreatorTool>Adobe Photoshop CC 2017 (Windows)</xmp:CreatorTool>
|
||
+ </rdf:Description>
|
||
+ </rdf:RDF>
|
||
+</x:xmpmeta>
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+
|
||
+<?xpacket end="w"?></metadata>
|
||
+<defs>
|
||
+ <style>
|
||
+ .cls-1 {
|
||
+ fill: #fff;
|
||
+ fill-rule: evenodd;
|
||
+ }
|
||
+ </style>
|
||
+ </defs>
|
||
+ <path id="切换用户" class="cls-1" d="M1144,551.671a0.324,0.324,0,0,1-.32.329h-2.24a0.318,0.318,0,0,1-.32-0.308,9.125,9.125,0,0,0-18.24,0,0.318,0.318,0,0,1-.32.308h-2.24a0.324,0.324,0,0,1-.32-0.329,11.993,11.993,0,0,1,6.96-10.571,8.005,8.005,0,1,1,10.07,0,12.108,12.108,0,0,1,3.46,2.416A11.9,11.9,0,0,1,1144,551.671Zm-6.88-16.791a5.084,5.084,0,0,0-1.53-3.656,5.163,5.163,0,0,0-3.64-1.464A5.12,5.12,0,1,0,1137.12,534.88Zm-6.21-10.02a9.907,9.907,0,0,0-2.21.5,0.315,0.315,0,0,1-.37-0.128,5.181,5.181,0,0,0-.82-0.976,5.122,5.122,0,0,0-7.07,7.412,4.969,4.969,0,0,0,1.48,1,0.335,0.335,0,0,1,.18.352,9.522,9.522,0,0,0-.18,1.86,9.24,9.24,0,0,0,.06,1.056,0.316,0.316,0,0,1-.24.348,9.132,9.132,0,0,0-6.86,8.528,0.311,0.311,0,0,1-.32.308h-2.24a0.323,0.323,0,0,1-.32-0.328,11.9,11.9,0,0,1,3.51-8.16,12.108,12.108,0,0,1,3.46-2.416,8,8,0,1,1,12.19-9.82A0.318,0.318,0,0,1,1130.91,524.86Z" transform="translate(-1112 -520)"/>
|
||
+</svg>
|
||
diff --git a/src/menu/menu-applet-window.cpp b/src/menu/menu-applet-window.cpp
|
||
index 81397a4..2637eca 100644
|
||
--- a/src/menu/menu-applet-window.cpp
|
||
+++ b/src/menu/menu-applet-window.cpp
|
||
@@ -21,14 +21,16 @@
|
||
#include "lib/base.h"
|
||
#include "menu-app-launcher-button.h"
|
||
#include "menu-power-button.h"
|
||
+#include "menu-power-dialog.h"
|
||
#include "window-manager.h"
|
||
-
|
||
+#include "global.h"
|
||
#include <glibmm/i18n.h>
|
||
#include <unistd.h>
|
||
#include <iostream>
|
||
#include "global.h"
|
||
#include "menu-apps-container.h"
|
||
#include "recent-files-widget.h"
|
||
+#include "config.h"
|
||
|
||
#define NEW_APPS_MAX_SIZE 3
|
||
|
||
@@ -643,6 +645,18 @@ Gtk::Button *MenuAppletWindow::create_launcher_button(const std::string &icon_na
|
||
return button;
|
||
}
|
||
|
||
+Gtk::Button *MenuAppletWindow::create_power_dialog_button()
|
||
+{
|
||
+ MenuPowerButton *button;
|
||
+ button = Gtk::make_managed<MenuPowerButton>();
|
||
+
|
||
+ set_transient_for(*this);
|
||
+
|
||
+ button->signal_menu_hide().connect(sigc::mem_fun(*this, &Gtk::Widget::hide));
|
||
+
|
||
+ return button;
|
||
+}
|
||
+
|
||
void MenuAppletWindow::add_sidebar_buttons()
|
||
{
|
||
Gtk::Separator *separator;
|
||
@@ -685,7 +699,12 @@ void MenuAppletWindow::add_sidebar_buttons()
|
||
"mate-system-monitor");
|
||
side_box->add(*launcher_btn);
|
||
|
||
+
|
||
+#ifdef POWER_DIALOG
|
||
+ auto power_btn = create_power_dialog_button();
|
||
+#else
|
||
auto power_btn = Gtk::make_managed<MenuPowerButton>();
|
||
+#endif
|
||
side_box->add(*power_btn);
|
||
|
||
side_box->show_all();
|
||
diff --git a/src/menu/menu-applet-window.h b/src/menu/menu-applet-window.h
|
||
index 7a4d66d..d34cf5d 100644
|
||
--- a/src/menu/menu-applet-window.h
|
||
+++ b/src/menu/menu-applet-window.h
|
||
@@ -242,4 +242,6 @@ private:
|
||
Gtk::Button *create_page_button(const char *icon_resource,
|
||
const char *tooltip,
|
||
int page_index);
|
||
+
|
||
+ Gtk::Button *create_power_dialog_button();
|
||
};
|
||
diff --git a/src/menu/menu-power-button.cpp b/src/menu/menu-power-button.cpp
|
||
index 0237153..622481b 100644
|
||
--- a/src/menu/menu-power-button.cpp
|
||
+++ b/src/menu/menu-power-button.cpp
|
||
@@ -13,7 +13,10 @@
|
||
*/
|
||
|
||
#include "menu-power-button.h"
|
||
+#include "menu-power-dialog.h"
|
||
#include <glibmm/i18n.h>
|
||
+#include <gtkmm/menu.h>
|
||
+
|
||
#include "kiran-helper.h"
|
||
|
||
MenuPowerButton::MenuPowerButton() : menu(nullptr)
|
||
@@ -32,7 +35,12 @@ MenuPowerButton::MenuPowerButton() : menu(nullptr)
|
||
|
||
MenuPowerButton::~MenuPowerButton()
|
||
{
|
||
+#ifdef POWER_DIALOG
|
||
+ delete dialog_;
|
||
+#else
|
||
delete menu;
|
||
+#endif
|
||
+
|
||
}
|
||
|
||
void MenuPowerButton::on_clicked()
|
||
@@ -42,10 +50,21 @@ void MenuPowerButton::on_clicked()
|
||
if (menu)
|
||
delete menu;
|
||
|
||
+#ifdef POWER_DIALOG
|
||
+ dialog_ = new MenuPowerDialog();
|
||
+ dialog_->show_all();
|
||
+#else
|
||
menu = new MenuPowerMenu();
|
||
menu->attach_to_widget(*this);
|
||
menu->show_all();
|
||
menu->popup_at_widget(this, Gdk::GRAVITY_SOUTH_EAST, Gdk::GRAVITY_SOUTH_WEST, event);
|
||
+#endif
|
||
|
||
gdk_event_free(event);
|
||
}
|
||
+
|
||
+
|
||
+sigc::signal<void> MenuPowerButton::signal_menu_hide()
|
||
+{
|
||
+ return m_signal_menu_hide;
|
||
+}
|
||
diff --git a/src/menu/menu-power-button.h b/src/menu/menu-power-button.h
|
||
index fb94225..82151b0 100644
|
||
--- a/src/menu/menu-power-button.h
|
||
+++ b/src/menu/menu-power-button.h
|
||
@@ -16,6 +16,7 @@
|
||
#define MENU_POWER_BUTTON_H
|
||
|
||
#include <gtkmm.h>
|
||
+#include "config.h"
|
||
#include "menu-power-menu.h"
|
||
|
||
class MenuPowerButton : public Gtk::Button
|
||
@@ -23,13 +24,18 @@ class MenuPowerButton : public Gtk::Button
|
||
public:
|
||
MenuPowerButton();
|
||
~MenuPowerButton();
|
||
+ sigc::signal<void> signal_menu_hide();
|
||
|
||
protected:
|
||
virtual void on_clicked() override;
|
||
+ sigc::signal<void> m_signal_menu_hide;
|
||
|
||
private:
|
||
Gtk::Image icon;
|
||
Gtk::Menu *menu;
|
||
+#ifdef POWER_DIALOG
|
||
+ Gtk::Window *dialog_;
|
||
+#endif
|
||
};
|
||
|
||
#endif // MENU_POWER_BUTTON_H
|
||
diff --git a/src/menu/menu-power-dialog.cpp b/src/menu/menu-power-dialog.cpp
|
||
new file mode 100644
|
||
index 0000000..1d75cf1
|
||
--- /dev/null
|
||
+++ b/src/menu/menu-power-dialog.cpp
|
||
@@ -0,0 +1,216 @@
|
||
+/**
|
||
+ * Copyright (c) 2020 ~ 2021 KylinSec Co., Ltd.
|
||
+ * kiran-cc-daemon is licensed under Mulan PSL v2.
|
||
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||
+ * You may obtain a copy of Mulan PSL v2 at:
|
||
+ * http://license.coscl.org.cn/MulanPSL2
|
||
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||
+ * See the Mulan PSL v2 for more details.
|
||
+ *
|
||
+ * Author: huangjiawen <huangjiawen@kylinos.com.cn>
|
||
+ */
|
||
+
|
||
+#include "menu-power-dialog.h"
|
||
+#include <glibmm/i18n.h>
|
||
+#include <gtk3-log-i.h>
|
||
+#include <gtkmm/menu.h>
|
||
+#include <iostream>
|
||
+#include "global.h"
|
||
+#include "kiran-helper.h"
|
||
+#include "kiran-power.h"
|
||
+
|
||
+MenuPowerDialog::MenuPowerDialog()
|
||
+{
|
||
+ Gtk::HeaderBar *dialog_header_bar;
|
||
+ Gtk::Frame *dialog_frame;
|
||
+ Gtk::Box *dialog_vbox;
|
||
+ Gtk::Box *dialog_hbox;
|
||
+ Gtk::Grid *dialog_grid;
|
||
+
|
||
+ dialog_header_bar = Gtk::make_managed<Gtk::HeaderBar>();
|
||
+ dialog_header_bar->set_decoration_layout("menu,icon:close");
|
||
+ dialog_header_bar->set_show_close_button();
|
||
+ set_titlebar(*dialog_header_bar);
|
||
+
|
||
+ set_modal();
|
||
+ set_title(_("Shutdown"));
|
||
+ set_border_width(5);
|
||
+ set_icon_name("kiran-power-shutdown");
|
||
+ set_position(Gtk::WIN_POS_CENTER);
|
||
+
|
||
+ dialog_frame = Gtk::make_managed<Gtk::Frame>();
|
||
+ dialog_frame->set_shadow_type(Gtk::SHADOW_OUT);
|
||
+ add(*dialog_frame);
|
||
+
|
||
+ Gdk::RGBA color;
|
||
+ color.set_rgba(0.20, 0.20, 0.20, 1);
|
||
+ dialog_header_bar->override_background_color(color, Gtk::STATE_FLAG_NORMAL);
|
||
+ dialog_frame->override_background_color(color, Gtk::STATE_FLAG_NORMAL);
|
||
+
|
||
+ dialog_vbox = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_VERTICAL);
|
||
+ dialog_vbox->set_border_width(20);
|
||
+ dialog_frame->add(*dialog_vbox);
|
||
+
|
||
+ dialog_hbox = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_HORIZONTAL);
|
||
+ dialog_hbox->set_border_width(35);
|
||
+ dialog_vbox->pack_start(*dialog_hbox, Gtk::PACK_EXPAND_PADDING);
|
||
+
|
||
+ dialog_grid = Gtk::make_managed<Gtk::Grid>();
|
||
+ dialog_grid->set_row_spacing(5);
|
||
+ dialog_grid->set_column_spacing(10);
|
||
+ dialog_hbox->pack_start(*dialog_grid, Gtk::PACK_EXPAND_PADDING);
|
||
+
|
||
+ add_power_button(dialog_grid);
|
||
+
|
||
+ get_style_context()->add_class("power-menu-dialog");
|
||
+}
|
||
+
|
||
+void MenuPowerDialog::add_power_button(Gtk::Grid *dialog_grid)
|
||
+{
|
||
+ gint space = 0;
|
||
+ auto power = KiranPower::get_default();
|
||
+
|
||
+ if (power->can_shutdown())
|
||
+ {
|
||
+ space += 1;
|
||
+ add_button("kiran-power-shutdown", "Shutdown", dialog_grid, space, &MenuPowerDialog::do_shutdown);
|
||
+ }
|
||
+
|
||
+ if (power->can_reboot())
|
||
+ {
|
||
+ space += 1;
|
||
+ add_button("kiran-power-reboot", "Reboot", dialog_grid, space, &MenuPowerDialog::do_reboot);
|
||
+ }
|
||
+
|
||
+ if (power->can_logout())
|
||
+ {
|
||
+ space += 1;
|
||
+ add_button("kiran-power-logout", "Logout", dialog_grid, space, &MenuPowerDialog::do_logout);
|
||
+ }
|
||
+
|
||
+ if (power->can_hibernate())
|
||
+ {
|
||
+ space += 1;
|
||
+ add_button("kiran-power-hibernate", "Hibernate", dialog_grid, space, &MenuPowerDialog::do_hibernate);
|
||
+ }
|
||
+
|
||
+ if (power->can_lock_screen())
|
||
+ {
|
||
+ space += 1;
|
||
+ add_button("kiran-power-lock_screen", "Lock screen", dialog_grid, space, &MenuPowerDialog::do_lock_screen);
|
||
+ }
|
||
+
|
||
+ if (power->can_switch_user())
|
||
+ {
|
||
+ space += 1;
|
||
+ add_button("kiran-power-switch_user", "Switch user", dialog_grid, space, &MenuPowerDialog::do_switch_user);
|
||
+ }
|
||
+
|
||
+ if (power->can_suspend())
|
||
+ {
|
||
+ space += 1;
|
||
+ add_button("kiran-power-suspend", "Suspend", dialog_grid, space, &MenuPowerDialog::do_suspend);
|
||
+ }
|
||
+}
|
||
+
|
||
+MenuPowerDialog::~MenuPowerDialog()
|
||
+{
|
||
+}
|
||
+
|
||
+void MenuPowerDialog::add_button(const char *button_icon_name,
|
||
+ const char *button_name,
|
||
+ Gtk::Grid *dialog_grid,
|
||
+ int space,
|
||
+ void (MenuPowerDialog::*power_func)())
|
||
+{
|
||
+ Gtk::Button *power_button;
|
||
+ Gtk::Label *power_label;
|
||
+
|
||
+ power_button = Gtk::make_managed<Gtk::Button>();
|
||
+ power_button->set_size_request(60, 40);
|
||
+ power_button->set_image_from_icon_name(button_icon_name, Gtk::ICON_SIZE_DND);
|
||
+ power_button->set_relief(Gtk::RELIEF_NONE);
|
||
+ power_button->signal_clicked().connect(sigc::mem_fun(*this, power_func));
|
||
+
|
||
+ dialog_grid->attach(*power_button, space, 0, 1, 1);
|
||
+
|
||
+ power_label = Gtk::make_managed<Gtk::Label>(_(button_name));
|
||
+ dialog_grid->attach(*power_label, space, 1, 1, 1);
|
||
+}
|
||
+
|
||
+void MenuPowerDialog::do_reboot()
|
||
+{
|
||
+ auto power = KiranPower::get_default();
|
||
+
|
||
+ power->reboot();
|
||
+
|
||
+ return;
|
||
+}
|
||
+
|
||
+void MenuPowerDialog::do_logout()
|
||
+{
|
||
+ auto power = KiranPower::get_default();
|
||
+
|
||
+ power->logout(LOGOUT_MODE_NOW);
|
||
+
|
||
+ return;
|
||
+}
|
||
+
|
||
+void MenuPowerDialog::do_shutdown()
|
||
+{
|
||
+ auto power = KiranPower::get_default();
|
||
+
|
||
+ power->shutdown();
|
||
+
|
||
+ return;
|
||
+}
|
||
+
|
||
+void MenuPowerDialog::do_hibernate()
|
||
+{
|
||
+ auto power = KiranPower::get_default();
|
||
+
|
||
+ power->hibernate();
|
||
+
|
||
+ return;
|
||
+}
|
||
+void MenuPowerDialog::do_suspend()
|
||
+{
|
||
+ auto power = KiranPower::get_default();
|
||
+
|
||
+ power->suspend();
|
||
+
|
||
+ return;
|
||
+}
|
||
+
|
||
+void MenuPowerDialog::do_switch_user()
|
||
+{
|
||
+ auto power = KiranPower::get_default();
|
||
+
|
||
+ if (power->get_graphical_ntvs() >= power->get_ntvs_total())
|
||
+ {
|
||
+ KLOG_DEBUG("Total ntvs: %d, graphical ntvs: %d.", power->get_ntvs_total(), power->get_graphical_ntvs());
|
||
+
|
||
+ Gtk::MessageDialog dialog(_("The logined users reach the maximum limit at the same time, "
|
||
+ "you cannot switch to the greeter interface, Please log off some logined users first."),
|
||
+ true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true);
|
||
+ dialog.set_title(_("System Warning"));
|
||
+ dialog.run();
|
||
+ }
|
||
+ else
|
||
+ {
|
||
+ power->switch_user();
|
||
+ }
|
||
+
|
||
+ return;
|
||
+}
|
||
+
|
||
+void MenuPowerDialog::do_lock_screen()
|
||
+{
|
||
+ auto power = KiranPower::get_default();
|
||
+
|
||
+ power->lock_screen();
|
||
+
|
||
+ return;
|
||
+}
|
||
diff --git a/src/menu/menu-power-dialog.h b/src/menu/menu-power-dialog.h
|
||
new file mode 100644
|
||
index 0000000..471ab42
|
||
--- /dev/null
|
||
+++ b/src/menu/menu-power-dialog.h
|
||
@@ -0,0 +1,43 @@
|
||
+/**
|
||
+ * Copyright (c) 2020 ~ 2021 KylinSec Co., Ltd.
|
||
+ * kiran-cc-daemon is licensed under Mulan PSL v2.
|
||
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||
+ * You may obtain a copy of Mulan PSL v2 at:
|
||
+ * http://license.coscl.org.cn/MulanPSL2
|
||
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||
+ * See the Mulan PSL v2 for more details.
|
||
+ *
|
||
+ * Author: huangjiawen <huangjiawen@kylinos.com.cn>
|
||
+ */
|
||
+
|
||
+#ifndef MENU_POWER_DIALOG_H
|
||
+#define MENU_POWER_DIALOG_H
|
||
+
|
||
+#include <gtkmm.h>
|
||
+#include "kiran-opacity-menu.h"
|
||
+
|
||
+class MenuPowerDialog : public Gtk::Window
|
||
+{
|
||
+public:
|
||
+ MenuPowerDialog();
|
||
+ ~MenuPowerDialog() override;
|
||
+ void do_shutdown();
|
||
+ void do_reboot();
|
||
+ void do_logout();
|
||
+ void do_lock();
|
||
+ void do_hibernate();
|
||
+ void do_suspend();
|
||
+ void do_switch_user();
|
||
+ void do_lock_screen();
|
||
+
|
||
+ void add_power_button(Gtk::Grid *dialog_grid);
|
||
+ void add_button(const char *button_icon_name,
|
||
+ const char *button_name,
|
||
+ Gtk::Grid *dialog_grid,
|
||
+ int space,
|
||
+ void (MenuPowerDialog::*power_func)());
|
||
+};
|
||
+
|
||
+#endif // MENU_POWER_DIALOG_H
|
||
--
|
||
2.33.0
|
||
|