├── .clog.toml
├── .gitignore
├── .gitlab-ci.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── data
├── com.deepin.menu.Manager.xml
├── com.deepin.menu.Menu.xml
└── com.deepin.menu.service
├── debian
├── changelog
├── compat
├── control
├── copyright
├── rules
└── source
│ └── format
├── deepin-menu.desktop
├── deepin-menu.pro
├── deepin_menu
├── DBusInterfaces.py
├── __init__.py
└── menu.py
├── images.qrc
├── images
├── arrow-light-hover.png
├── arrow-light-inactive.png
├── arrow-light.png
├── check_dark_hover.png
├── check_dark_inactive.png
├── check_dark_normal.png
├── check_light_hover.png
├── check_light_inactive.png
└── check_light_normal.png
└── src
├── dabstractmenu.cpp
├── dabstractmenu.h
├── dbus_manager_adaptor.cpp
├── dbus_manager_adaptor.h
├── dbus_menu_adaptor.cpp
├── dbus_menu_adaptor.h
├── ddesktopmenu.cpp
├── ddesktopmenu.h
├── ddockmenu.cpp
├── ddockmenu.h
├── dmenuapplication.cpp
├── dmenuapplication.h
├── dmenubase.cpp
├── dmenubase.h
├── dmenucontent.cpp
├── dmenucontent.h
├── main.cpp
├── manager_object.cpp
├── manager_object.h
├── menu_object.cpp
├── menu_object.h
├── utils.cpp
└── utils.h
/.clog.toml:
--------------------------------------------------------------------------------
1 | [clog]
2 | repository = "https://github.com/linuxdeepin/deepin-menu"
3 | from-latest-tag = true
4 |
5 | changelog = "CHANGELOG.md"
6 |
7 | [sections]
8 | Others = ["chore"]
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .#*
2 | *.pyc
3 | *.pyo
4 | deepin_menu.egg-info
5 | build
6 | dist
7 | core
8 | *.o
9 | moc_*
10 | qrc_*.cpp
11 | deepin-menu.pro.user*
12 |
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | include:
2 | - remote: 'https://gitlab.deepin.io/dev-tools/letmeci/raw/master/gitlab-ci/dde.yml'
3 |
4 |
5 | variables:
6 | CPPCHECK: "true"
7 | CODESPELL: "true"
8 | PKG_NAME: "deepin-menu"
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 | ### 3.4.6 (2019-04-28)
3 |
4 |
5 | #### Others
6 |
7 | * set isScaled default value to true ([f2f6de0a](https://github.com/linuxdeepin/deepin-menu/commit/f2f6de0acd5a663183b4df29ff4d337f39723b9b))
8 |
9 |
10 |
11 |
12 | ### 3.4.5 (2019-04-28)
13 |
14 |
15 | #### Features
16 |
17 | * **menu:** Add a description of whether to scale ([aefb41b1](https://github.com/linuxdeepin/deepin-menu/commit/aefb41b1525653b88fee1e116c0b9100c04f2fa6))
18 |
19 |
20 |
21 |
22 | ## 3.4.4 (2019-04-25)
23 |
24 |
25 |
26 |
27 |
28 | ### 3.4.3 (2019-04-12)
29 |
30 |
31 | #### Bug Fixes
32 |
33 | * **pos:** HiDPI screen coordinates ([8d3cae29](https://github.com/linuxdeepin/deepin-menu/commit/8d3cae292312fc56b16e610afb8bb65641fcaefc))
34 |
35 |
36 |
37 |
38 | ### 3.4.2 (2019-04-12)
39 |
40 |
41 | #### Bug Fixes
42 |
43 | * position shift when use kwin ([c86bbfd4](https://github.com/linuxdeepin/deepin-menu/commit/c86bbfd4643ceef903b1469ee4847b1cba770711))
44 |
45 |
46 |
47 |
48 | ### 3.4.1 (2018-12-07)
49 |
50 |
51 | #### Features
52 |
53 | * support touchscreen ([18abfd60](https://github.com/linuxdeepin/deepin-menu/commit/18abfd60a9291c34c200ce3a8aa50ccf0cd99d39))
54 |
55 |
56 |
57 |
58 | ## 3.4.0 (2018-09-07)
59 |
60 |
61 | #### Bug Fixes
62 |
63 | * not hide menu when unregisterMenu ([cba7f135](https://github.com/linuxdeepin/deepin-menu/commit/cba7f135edbdbaa7df903f43dea86a0cfbafb038))
64 |
65 |
66 |
67 |
68 | ### 3.3.10 (2018-07-20)
69 |
70 |
71 | #### Bug Fixes
72 |
73 | * not emit signal ([af266ccf](https://github.com/linuxdeepin/deepin-menu/commit/af266ccf7ecc615f7dc2035969694de3606ef384))
74 |
75 |
76 |
77 |
78 | ### 3.3.9 (2018-07-20)
79 |
80 |
81 | #### Bug Fixes
82 |
83 | * wrong menu style on Qt 5.10.x ([d423e499](https://github.com/linuxdeepin/deepin-menu/commit/d423e499dbb9e4fd1a5c46a5311909776bbd6313))
84 |
85 |
86 |
87 |
88 | ### 3.3.8 (2018-06-13)
89 |
90 |
91 | #### Bug Fixes
92 |
93 | * **subment:** submenu not send invoked singnals ([8fbf86d8](https://github.com/linuxdeepin/deepin-menu/commit/8fbf86d8b34371f10fb8af1f71ee308294633191))
94 |
95 |
96 |
97 |
98 | ## 3.3.7 (2018-05-31)
99 |
100 |
101 | #### Bug Fixes
102 |
103 | * menu dead lock on destructor ([a865d4f9](https://github.com/linuxdeepin/deepin-menu/commit/a865d4f9040e0f0102aaa9ce68d5d8a399349b46))
104 |
105 |
106 |
107 |
108 | ## 3.3.6 (2018-05-30)
109 |
110 | * Minor bug fixes.
111 |
112 |
113 |
114 | ## 3.3.5 (2018-05-29)
115 |
116 | * Fix menu unregister but not notify signals emitted
117 |
118 |
119 |
120 | ## 3.3.4 (2018-05-24)
121 |
122 |
123 | #### Features
124 |
125 | * Add oom score ([aeda7e58](https://github.com/linuxdeepin/deepin-menu/commit/aeda7e58658184c1305b2114fa20fd9248de2d61))
126 |
127 | #### Bug Fixes
128 |
129 | * not click ([82196c3a](https://github.com/linuxdeepin/deepin-menu/commit/82196c3a4a14ff189f06831d02bc1f844b5ba53b))
130 | * use DRegionMonitor replace all grab ([5dc5e63f](https://github.com/linuxdeepin/deepin-menu/commit/5dc5e63f24973d17ec371ef9e10cc0387b738997))
131 | * click outside the menu to hide ([2a4f2f30](https://github.com/linuxdeepin/deepin-menu/commit/2a4f2f3093daadf4b751f705aa3b3583f3238a0d))
132 |
133 |
134 |
135 |
136 | ## 3.3.3 (2018-05-04)
137 |
138 |
139 | #### Bug Fixes
140 |
141 | * desktop menu cannot hide ([80505421](https://github.com/linuxdeepin/deepin-menu/commit/80505421a26d704e9c819829651bc684412c6394))
142 |
143 |
144 |
145 |
146 | ### 3.3.2 (2018-03-26)
147 |
148 |
149 | #### Bug Fixes
150 |
151 | * prevent memory leaks, use QPointer for MenuObject ([7511080e](https://github.com/linuxdeepin/deepin-menu/commit/7511080ec142709b7f5bdefba84627c2ad82f234))
152 | * crash cause menu adapter double free ([41a9b79a](https://github.com/linuxdeepin/deepin-menu/commit/41a9b79a8734cbd04b9194647420f81e52633ff3))
153 |
154 |
155 |
156 |
157 | ### 3.3.1 (2018-03-22)
158 |
159 |
160 | #### Bug Fixes
161 |
162 | * **ddesktopmenu:** remove BypassWindowManagerHint ([92779b8c](https://github.com/linuxdeepin/deepin-menu/commit/92779b8ca7228c8fa5206acc554459aa8da6737d))
163 |
164 |
165 |
166 |
167 | ## 3.3.0 (2018-03-08)
168 |
169 |
170 | #### Bug Fixes
171 |
172 | * deepin-menu isn't counted as DE component ([200f2a77](https://github.com/linuxdeepin/deepin-menu/commit/200f2a77740149c6fa5d7ca0aa513cb194098d58))
173 | * Adapt lintian ([83f836e2](https://github.com/linuxdeepin/deepin-menu/commit/83f836e2a762a80b4fbec20eac39a316c894329a))
174 | * **ddesktopmenu:** remove DReigonMonitor ([a541e01a](https://github.com/linuxdeepin/deepin-menu/commit/a541e01a1b09d60cb6c46defaec5e85096ddc3d3))
175 | * **debian:** remove useless depend ([9e459981](https://github.com/linuxdeepin/deepin-menu/commit/9e45998180cfa55a9c1136772621acbca851474c))
176 | * **desktopmenu:** add accessible name for desktopmenu ([0f220778](https://github.com/linuxdeepin/deepin-menu/commit/0f220778c806f36a66aaa705f91390b4704e26b4))
177 | * **dockmenu:**
178 | * set border alpha is 0 ([a1d3388b](https://github.com/linuxdeepin/deepin-menu/commit/a1d3388b97418f717124897ae61b3126f36f93b7))
179 | * remove use DRegionMonitor ([abc53564](https://github.com/linuxdeepin/deepin-menu/commit/abc535647ef8bf00e8ba77eb838cd593e28ae761))
180 | * reduce delay time ([417d90d2](https://github.com/linuxdeepin/deepin-menu/commit/417d90d2af4338abf7e0cf259b3e7dd507e78cc6))
181 |
182 | #### Others
183 |
184 | * remove autostart desktop file ([09e65bd7](https://github.com/linuxdeepin/deepin-menu/commit/09e65bd7bd46c9aa6cdd1b205aa4e4f7be33ef0c))
185 |
186 |
187 |
188 |
189 | ## 3.2.0 (2017-11-28)
190 |
191 |
192 | #### Bug Fixes
193 |
194 | * **dockmenu:** multi screen coordinates are not correct ([e2d60cfe](https://github.com/linuxdeepin/deepin-menu/commit/e2d60cfe9d5591cb48665b8ea584da7f96c1c1d8))
195 |
196 |
197 |
198 |
199 | ### 3.1.8 (2017-11-06)
200 |
201 |
202 | #### Features
203 |
204 | * font size change with system font settings ([642f4c6a](https://github.com/linuxdeepin/deepin-menu/commit/642f4c6ad8a55fb35a8bfaf0bd3fe3efc8060862))
205 |
206 | #### Bug Fixes
207 |
208 | * desktop menu hide immediately after showing ([79faf768](https://github.com/linuxdeepin/deepin-menu/commit/79faf768bf20c34a93adb6c73a4d742c5310aedd))
209 | * **dock menu:** no spacing between items ([fd39cc14](https://github.com/linuxdeepin/deepin-menu/commit/fd39cc144b39f2fe80335fb304ed64762252ed1a))
210 |
211 |
212 |
213 |
214 | ### 3.1.7 (2017-10-24)
215 |
216 |
217 | #### Others
218 |
219 | * setup .clog.toml ([f751c10c](https://github.com/linuxdeepin/deepin-menu/commit/f751c10c3dbed6d920a1af2b297c38809e3e7853))
220 |
221 | #### Bug Fixes
222 |
223 | * support hidpi of ddesktopmenu ([56a8cfc3](https://github.com/linuxdeepin/deepin-menu/commit/56a8cfc365eb5c2d5612f158d8db6716cec41a43))
224 |
225 | #### Features
226 |
227 | * support hiDPI use DRegionMonitor ([bd5c8229](https://github.com/linuxdeepin/deepin-menu/commit/bd5c8229728d4429444ed9061d6b9cfe2f604eba))
228 | * **hidpi:** add basic hidpi support ([77c46c63](https://github.com/linuxdeepin/deepin-menu/commit/77c46c63f55ec8f510bab4db4e0c276c6a94e7a6))
229 |
230 |
231 |
232 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Deepin Menu
2 |
3 | Deepin Menu is the unified menu service for Deepin Desktop Environment.
4 |
5 | ## Dependencies
6 |
7 | ### Build dependencies
8 |
9 | * Qt (>= 5.10)
10 | * dtkwidget (>= 2.0.6)
11 |
12 | ### Runtime dependencies
13 |
14 | * DBus
15 | * Qt5 (>= 5.10)
16 | * Qt5-Widgets
17 | * Qt5-Gui
18 | * Qt5-DBus
19 | * dtkwidget (>=2.0.6)
20 |
21 | ## Installation
22 |
23 | ### Build from source code
24 |
25 | 1. Make sure you have installed all dependencies.
26 |
27 | 2. Build:
28 | ```
29 | $ cd deepin-menu
30 | $ mkdir build
31 | $ cd build
32 | $ qmake ..
33 | $ make
34 | ```
35 |
36 | 3. Install:
37 | ```
38 | $ sudo make install
39 | ```
40 |
41 | ## Usage
42 |
43 | Run the binary, the two DBus interfaces com.deepin.Menu.Manager and com.deepin.Menu it provides should
44 | be sufficient to explain itself. More details on the data structure it uses needs to be done.
45 |
46 | ## Getting help
47 |
48 | You may also find these channels useful if you encounter any other issues:
49 |
50 | * [Gitter](https://gitter.im/orgs/linuxdeepin/rooms)
51 | * [IRC Channel](https://webchat.freenode.net/?channels=deepin)
52 | * [Official Forum](https://bbs.deepin.org/)
53 | * [Wiki](http://wiki.deepin.org/)
54 |
55 | ## License
56 |
57 | Deepin Menu is licensed under [GPLv3](LICENSE).
58 |
--------------------------------------------------------------------------------
/data/com.deepin.menu.Manager.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/data/com.deepin.menu.Menu.xml:
--------------------------------------------------------------------------------
1 |
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 |
--------------------------------------------------------------------------------
/data/com.deepin.menu.service:
--------------------------------------------------------------------------------
1 | [D-BUS Service]
2 | Name=com.deepin.menu
3 | Exec=/usr/bin/deepin-menu
4 |
--------------------------------------------------------------------------------
/debian/changelog:
--------------------------------------------------------------------------------
1 | deepin-menu (3.0.4-1) stable; urgency=low
2 |
3 | * Autobuild Tag 3.0.4
4 |
5 | -- TagBuilder Fri, 12 Aug 2016 18:59:32 +0000
6 |
7 | deepin-menu (3.0.3-1) stable; urgency=low
8 |
9 | * Autobuild Tag 3.0.3
10 |
11 | -- TagBuilder Wed, 20 Jul 2016 07:20:30 +0000
12 |
13 | deepin-menu (3.0.2-1) stable; urgency=low
14 |
15 | * Autobuild Tag 3.0.2
16 |
17 | -- TagBuilder Fri, 22 Jan 2016 19:37:39 +0000
18 |
19 | deepin-menu (3.0.1-1) stable; urgency=low
20 |
21 | * Autobuild Tag 3.0.1
22 |
23 | -- TagBuilder Tue, 12 Jan 2016 19:51:31 +0000
24 |
25 | deepin-menu (3.0.0-1) stable; urgency=low
26 |
27 | * Autobuild Tag 3.0.0
28 |
29 | -- TagBuilder Mon, 28 Dec 2015 21:06:03 +0000
30 |
31 | deepin-menu (2.90.2-1) stable; urgency=low
32 |
33 | * Autobuild Tag 2.90.2
34 |
35 | -- TagBuilder Wed, 09 Dec 2015 22:06:30 +0000
36 |
37 | deepin-menu (2.90.1-2) stable; urgency=low
38 |
39 | * Rebuild Version 2.90.1
40 |
41 | -- TagBuilder Fri, 20 Nov 2015 09:50:48 +0000
42 |
43 | deepin-menu (2.90.1-1) stable; urgency=low
44 |
45 | * Autobuild Tag 2.90.1
46 |
47 | -- TagBuilder Fri, 20 Nov 2015 09:50:26 +0000
48 |
49 | deepin-menu (2.3.0-1) stable; urgency=low
50 |
51 | * Autobuild Tag 2.3.0-1
52 |
53 | -- TagBuilder Wed, 01 Jul 2015 09:32:07 +0000
54 |
55 | deepin-menu (0.0.0) unstable; urgency=medium
56 |
57 | * Unstable release.
58 |
59 | -- 宋文武 Thu, 13 Nov 2014 16:05:26 +0800
60 |
--------------------------------------------------------------------------------
/debian/compat:
--------------------------------------------------------------------------------
1 | 9
2 |
--------------------------------------------------------------------------------
/debian/control:
--------------------------------------------------------------------------------
1 | Source: deepin-menu
2 | Priority: extra
3 | Section: devel
4 | Maintainer: Deepin Packages Builder
5 | Build-Depends: debhelper (>= 9),
6 | pkg-config,
7 | qt5-qmake,
8 | libdtkwidget-dev,
9 | libdtkgui-dev,
10 | qtbase5-private-dev,
11 | libglib2.0-dev,
12 | libxrender-dev,
13 | libmtdev-dev,
14 | libfontconfig1-dev,
15 | libfreetype6-dev,
16 | libegl1-mesa-dev,
17 | libqt5xdgiconloader-dev,
18 | libqt5svg5-dev
19 | Standards-Version: 3.9.8
20 | Homepage: https://github.com/linuxdeepin/deepin-menu
21 |
22 | Package: deepin-menu
23 | Architecture: any
24 | Depends: ${shlibs:Depends}, ${misc:Depends}, qttranslations5-l10n
25 | Description: Deepin menu service
26 | Deepin menu service for building beautiful menus.
27 |
--------------------------------------------------------------------------------
/debian/copyright:
--------------------------------------------------------------------------------
1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2 | Upstream-Name: deepin-menu
3 |
4 | Files: *
5 | Copyright: 2017 Deepin Technology Co., Ltd.
6 | License: GPL-3+
7 | This package is free software; you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation; either version 3 of the License, or
10 | (at your option) any later version.
11 | .
12 | This package is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 | .
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see
19 | .
20 | On Debian systems, the complete text of the GNU General
21 | Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
22 |
--------------------------------------------------------------------------------
/debian/rules:
--------------------------------------------------------------------------------
1 | #!/usr/bin/make -f
2 | # -*- makefile -*-
3 | # Sample debian/rules that uses debhelper.
4 | # This file was originally written by Joey Hess and Craig Small.
5 | # As a special exception, when this file is copied by dh-make into a
6 | # dh-make output file, you may use that output file without restriction.
7 | # This special exception was added by Craig Small in version 0.37 of dh-make.
8 |
9 | # Uncomment this to turn on verbose mode.
10 | #export DH_VERBOSE=1
11 | export QT_SELECT=5
12 |
13 | %:
14 | dh $@ --parallel
15 |
--------------------------------------------------------------------------------
/debian/source/format:
--------------------------------------------------------------------------------
1 | 3.0 (native)
2 |
--------------------------------------------------------------------------------
/deepin-menu.desktop:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Type=Application
3 | Name=Deepin Menu
4 | Exec=/usr/bin/deepin-menu
5 | NoDisplay=true
6 | OnlyShowIn=Deepin
7 | X-Deepin-DEComponent=true
8 |
--------------------------------------------------------------------------------
/deepin-menu.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2014-08-14T14:55:09
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui dbus dtkwidget
8 |
9 | greaterThan(QT_MINOR_VERSION, 7): QT += gui-private
10 | else: QT += platformsupport-private
11 |
12 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
13 |
14 | TARGET = deepin-menu
15 | TEMPLATE = app
16 |
17 | CONFIG += c++11 link_pkgconfig
18 |
19 | SOURCES += src/main.cpp \
20 | src/ddesktopmenu.cpp \
21 | src/utils.cpp \
22 | src/dmenucontent.cpp \
23 | src/dbus_manager_adaptor.cpp \
24 | src/dbus_menu_adaptor.cpp \
25 | src/manager_object.cpp \
26 | src/menu_object.cpp \
27 | src/ddockmenu.cpp \
28 | src/dmenuapplication.cpp \
29 | src/dabstractmenu.cpp
30 |
31 | HEADERS += \
32 | src/ddesktopmenu.h \
33 | src/utils.h \
34 | src/dmenucontent.h \
35 | src/dbus_manager_adaptor.h \
36 | src/dbus_menu_adaptor.h \
37 | src/manager_object.h \
38 | src/menu_object.h \
39 | src/ddockmenu.h \
40 | src/dmenuapplication.h \
41 | src/dabstractmenu.h
42 |
43 | dbus.path = /usr/share/dbus-1/services
44 | dbus.files = data/com.deepin.menu.service
45 |
46 | RESOURCES += \
47 | images.qrc
48 |
49 | target.path = /usr/bin
50 | INSTALLS += target dbus
51 |
--------------------------------------------------------------------------------
/deepin_menu/DBusInterfaces.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 |
4 | # Copyright (C) 2015 Deepin Technology Co., Ltd.
5 | #
6 | # This program is free software; you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation; either version 3 of the License, or
9 | # (at your option) any later version.
10 |
11 | from PyQt5.QtCore import pyqtSignal
12 | from PyQt5.QtDBus import QDBusAbstractInterface, QDBusConnection, QDBusReply
13 |
14 | class MenuManagerInterface(QDBusAbstractInterface):
15 |
16 | def __init__(self):
17 | super(MenuManagerInterface, self).__init__("com.deepin.menu",
18 | "/com/deepin/menu",
19 | "com.deepin.menu.Manager",
20 | QDBusConnection.sessionBus(),
21 | None)
22 |
23 | def registerMenu(self):
24 | return self.call('RegisterMenu')
25 |
26 | def unregisterMenu(self, objPath):
27 | self.call('UnregisterMenu', objPath)
28 |
29 | class MenuObjectInterface(QDBusAbstractInterface):
30 |
31 | ItemInvoked = pyqtSignal(str, bool)
32 | ItemTextSet = pyqtSignal(str, str)
33 | ItemActivitySet = pyqtSignal(str, bool)
34 | ItemCheckedSet = pyqtSignal(str, bool)
35 | MenuUnregistered = pyqtSignal()
36 |
37 | def __init__(self, path):
38 | super(MenuObjectInterface, self).__init__("com.deepin.menu",
39 | path,
40 | "com.deepin.menu.Menu",
41 | QDBusConnection.sessionBus(),
42 | None)
43 |
44 | def showMenu(self, jsonContent):
45 | self.asyncCall('ShowMenu', jsonContent)
46 |
47 | def setItemText(self, id, value):
48 | self.asyncCall('SetItemText', id, value)
49 |
50 | def setItemActivity(self, id, value):
51 | self.asyncCall('SetItemActivity', id, value)
52 |
53 | def setItemChecked(self, id, value):
54 | self.asyncCall('SetItemChecked', id, value)
55 |
56 | class XMouseAreaInterface(QDBusAbstractInterface):
57 |
58 | ButtonPress = pyqtSignal(int, int, int, int)
59 | KeyPress = pyqtSignal(str, int, int, int)
60 | MotionMove = pyqtSignal(int, int, int)
61 |
62 | def __init__(self):
63 | super(XMouseAreaInterface, self).__init__("com.deepin.api.XMouseArea",
64 | "/com/deepin/api/XMouseArea",
65 | "com.deepin.api.XMouseArea",
66 | QDBusConnection.sessionBus(),
67 | None)
68 |
69 | def registerArea(self, x1, x2, y1, y2, flag):
70 | msg = self.call("RegisterArea", x1, x2, y1, y2, flag)
71 | print msg.errorName(), msg.errorMessage()
72 | reply = QDBusReply(msg)
73 | return reply.value()
74 |
75 | def unregisterArea(self, id):
76 | self.call("UnregisterArea", id)
77 |
78 | class DisplayPropertyInterface(QDBusAbstractInterface):
79 | def __init__(self):
80 | super(DisplayPropertyInterface, self).__init__(
81 | "com.deepin.daemon.Display",
82 | "/com/deepin/daemon/Display",
83 | "org.freedesktop.DBus.Properties",
84 | QDBusConnection.sessionBus(),
85 | None)
86 |
87 | def getPrimaryRect(self):
88 | msg = self.call("Get", "com.deepin.daemon.Display", "PrimaryRect")
89 | reply = QDBusReply(msg)
90 | return reply.value()
91 |
--------------------------------------------------------------------------------
/deepin_menu/__init__.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 |
4 | # Copyright (C) 2015 Deepin Technology Co., Ltd.
5 | #
6 | # This program is free software; you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation; either version 3 of the License, or
9 | # (at your option) any later version.
10 |
--------------------------------------------------------------------------------
/deepin_menu/menu.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 |
4 | # Copyright (C) 2015 Deepin Technology Co., Ltd.
5 | #
6 | # This program is free software; you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation; either version 3 of the License, or
9 | # (at your option) any later version.
10 |
11 | import json
12 | from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal
13 | from PyQt5.QtDBus import QDBusReply
14 | from DBusInterfaces import MenuManagerInterface, MenuObjectInterface
15 |
16 | def parseMenuItem(menuItem):
17 | assert len(menuItem) >= 2
18 | result = MenuItem(menuItem[0], menuItem[1])
19 | if len(menuItem) > 2:
20 | result.setIcons(menuItem[2])
21 | if len(menuItem) > 3:
22 | result.setSubMenu(parseMenu(Menu(is_root=False), menuItem[3]))
23 | if len(menuItem) > 4:
24 | result.extra = menuItem[4]
25 | return result
26 |
27 | def parseMenu(obj, menu):
28 | result = obj
29 | for menuItem in menu:
30 | if menuItem == None:
31 | result.addMenuItem(MenuSeparator())
32 | elif isinstance(menuItem, MenuItem):
33 | result.addMenuItem(menuItem)
34 | else:
35 | result.addMenuItem(parseMenuItem(menuItem))
36 | return result
37 |
38 | def validateItemGroupInfo(item, groupId, groupType):
39 | info = item.id.split(":")
40 | item.id = "%s:%s:%s" % (groupId, groupType, info[-1])
41 |
42 | class MenuItem(QObject):
43 | def __init__(self, id, text, icons=None, subMenu=None,
44 | isActive=True, isCheckable=False, checked=False, showCheckmark=True, extra=""):
45 | super(MenuItem, self).__init__()
46 | self.id = id
47 | self.text = text
48 | self.extra = extra
49 | self.icons = icons or ()
50 | self.subMenu = subMenu or Menu(is_root=False)
51 | self.isActive = isActive
52 | self.isCheckable = isCheckable
53 | self.checked = checked
54 | self.showCheckmark = self.isCheckable and showCheckmark
55 |
56 | @property
57 | def serializableContent(self):
58 | iconNormal = ""
59 | iconHover = ""
60 | iconInactive = ""
61 |
62 | if len(self.icons) > 0:
63 | iconNormal = self.icons[0]
64 | iconHover = self.icons[0]
65 | iconInactive = self.icons[0]
66 | if len(self.icons) > 1:
67 | iconHover = self.icons[1]
68 | if len(self.icons) > 2:
69 | iconInactive = self.icons[2]
70 |
71 | return {"itemId": self.id,
72 | "itemIcon": iconNormal,
73 | "itemIconHover": iconHover,
74 | "itemIconInactive": iconInactive,
75 | "itemText": self.text,
76 | "itemExtra": self.extra,
77 | "itemSubMenu": self.subMenu.serializableItemList,
78 | "isActive": self.isActive,
79 | "isCheckable": self.isCheckable,
80 | "checked": self.checked,
81 | "showCheckmark": self.showCheckmark}
82 |
83 | def setSubMenu(self, menu):
84 | self.subMenu = menu
85 |
86 | def setIcons(self, icons):
87 | self.icons = icons
88 |
89 | @property
90 | def hasSubMenu(self):
91 | return len(self.subMenu.items) != 0
92 |
93 | def __str__(self):
94 | return json.dumps(self.serializableContent)
95 |
96 | class CheckableMenuItem(MenuItem):
97 | def __init__(self, id, text, checked=False, showCheckmark=True, extra=""):
98 | super(CheckableMenuItem, self).__init__(id, text, isCheckable=True,
99 | checked=checked, showCheckmark=showCheckmark, extra=extra)
100 |
101 | class MenuSeparator(MenuItem):
102 | def __init__(self):
103 | super(MenuSeparator, self).__init__("", "", isActive=False)
104 |
105 | class Menu(QObject):
106 | itemClicked = pyqtSignal(str, bool)
107 | menuDismissed = pyqtSignal()
108 |
109 | def __init__(self, items=None, is_root=True, checkableMenu=False,
110 | singleCheck=False):
111 | super(Menu, self).__init__()
112 | self.items = []
113 | if items:
114 | parseMenu(self, items)
115 | if is_root:
116 | self.managerIface = MenuManagerInterface()
117 | self.menuIface = None
118 | self.checkableMenu = checkableMenu
119 | self.singleCheck = singleCheck
120 |
121 | @property
122 | def serializableItemList(self):
123 | items= []
124 | for item in self.items:
125 | items.append(item.serializableContent)
126 | return {"items": items,
127 | "checkableMenu": self.checkableMenu,
128 | "singleCheck": self.singleCheck}
129 |
130 | def addMenuItem(self, item):
131 | self.items.append(item)
132 |
133 | def addMenuItems(self, items):
134 | for item in items:
135 | self.addMenuItem(item)
136 |
137 | def getItemById(self, id):
138 | for item in self.items:
139 | if item.hasSubMenu:
140 | if item.subMenu.getItemById(id):
141 | return item.subMenu.getItemById(id)
142 | if item.id == id:
143 | return item
144 | return None
145 |
146 | def setItemActivity(self, id, value):
147 | item = self.getItemById(id)
148 | if item:
149 | item.isActive = value
150 | if self.menuIface:
151 | self.menuIface.setItemActivity(id, value)
152 |
153 | def setItemText(self, id, value):
154 | item = self.getItemById(id)
155 | if item:
156 | item.text = value
157 | if self.menuIface:
158 | self.menuIface.setItemText(id, value)
159 |
160 | def showRectMenu(self, x, y):
161 | msg = self.managerIface.registerMenu()
162 | reply = QDBusReply(msg)
163 | self.menuIface = MenuObjectInterface(reply.value())
164 | self.menuIface.showMenu(json.dumps({"x": x,
165 | "y": y,
166 | "isDockMenu": False,
167 | "menuJsonContent": str(self)}))
168 | self.menuIface.ItemInvoked.connect(self.itemInvokedSlot)
169 | self.menuIface.MenuUnregistered.connect(self.menuUnregisteredSlot)
170 |
171 | def showDockMenu(self, x, y, cornerDirection="down"):
172 | msg = self.managerIface.registerMenu()
173 | reply = QDBusReply(msg)
174 | self.menuIface = MenuObjectInterface(reply.value())
175 | self.menuIface.showMenu(json.dumps({"x": x,
176 | "y": y,
177 | "isDockMenu": True,
178 | "cornerDirection": cornerDirection,
179 | "menuJsonContent": str(self)}))
180 | self.menuIface.ItemInvoked.connect(self.itemInvokedSlot)
181 | self.menuIface.MenuUnregistered.connect(self.menuUnregisteredSlot)
182 |
183 | @pyqtSlot(str, bool)
184 | def itemInvokedSlot(self, itemId, checked):
185 | self.itemClicked.emit(itemId, checked)
186 |
187 | @pyqtSlot()
188 | def menuUnregisteredSlot(self):
189 | self.menuDismissed.emit()
190 |
191 | def __str__(self):
192 | return json.dumps(self.serializableItemList)
193 |
194 | class CheckboxMenu(Menu):
195 | def __init__(self, groupId, items):
196 | self.groupId = groupId
197 | super(CheckboxMenu, self).__init__(items, checkableMenu=True,
198 | singleCheck=False)
199 |
200 | def addMenuItem(self, item):
201 | validateItemGroupInfo(item, self.groupId, "checkbox")
202 | item.isCheckable = True
203 | item.showCheckmark = True
204 | self.items.append(item)
205 |
206 | class RadioButtonMenu(Menu):
207 | def __init__(self, groupId, items):
208 | self.groupId = groupId
209 | super(RadioButtonMenu, self).__init__(items, checkableMenu=True,
210 | singleCheck=True)
211 |
212 | def addMenuItem(self, item):
213 | validateItemGroupInfo(item, self.groupId, "radio")
214 | item.isCheckable = True
215 | item.showCheckmark = True
216 | self.items.append(item)
217 |
218 | if __name__ == "__main__":
219 | import sys
220 | from PyQt5.QtCore import QCoreApplication
221 |
222 | app = QCoreApplication([])
223 |
224 | @pyqtSlot(str, bool)
225 | def invoked(s, c):
226 | print "id: ", s, ", checked: ", c
227 | # menu.setItemText("id_nonactive", "hello")
228 | # menu.setItemActivity("id_nonactive", True)
229 |
230 | @pyqtSlot()
231 | def dismissed():
232 | print "dismissed"
233 |
234 | # 1)
235 | # driver = MenuItem("id_driver", "Driver", "/usr/share/icons/Deepin/apps/16/preferences-driver.png")
236 | # display = MenuItem("id_display", "Display", "/usr/share/icons/Deepin/apps/16/preferences-display.png")
237 | # show = Menu()
238 | # show.addMenuItem(MenuItem("id_sub_display", "Display", "/usr/share/icons/Deepin/apps/16/preferences-display.png"))
239 | # display.setSubMenu(show)
240 | # menu = Menu(is_root=True)
241 | # menu.addMenuItems([driver, display])
242 | # menu.showMenu(200, 200)
243 |
244 | # 2)
245 | menu = Menu([("id_driver", "Driver", ("/usr/share/icons/Deepin/apps/16/preferences-display.png",)),
246 | None,
247 | ("id_display", "_Display", (), [("display_sub1", "Display One"), ("display_sub2", "Display Two"),]),
248 | ("id_radio", "RadioButtonMenu"),
249 | ("id_checkbox", "_CheckBoxMenu"),
250 | ("id_extra", "_ExtraTest", (), [], "Ctrl-X"),
251 | MenuSeparator(),
252 | CheckableMenuItem("radio_group_2:radio:radio2_sub1", "One"),
253 | CheckableMenuItem("radio_group_2:radio:radio2_sub2", "Two"),
254 | None,
255 | CheckableMenuItem("checkbox_group_2:checkbox:checkbox2_sub1", "One"),
256 | CheckableMenuItem("checkbox_group_2:checkbox:checkbox2_sub2", "Two"),
257 | None,
258 | MenuItem("id_nonactive", "NotActive", isActive=False),
259 | CheckableMenuItem("id_check", "CheckMe", True)], is_root=True,)
260 | radio_sub = RadioButtonMenu("radio_group_1", [("id_radio1", "Radio One"), ("id_radio2", "Radio Two"),])
261 | checkbox_sub = CheckboxMenu("checkbox_group_1", [("id_checkbox1", "Checkbox One"), ("id_checkbox2", "Checkbox Two")])
262 | menu.getItemById("id_radio").setSubMenu(radio_sub)
263 | menu.getItemById("id_checkbox").setSubMenu(checkbox_sub)
264 | # menu.getItemById("id_radio2").showCheckmark = False
265 | menu.itemClicked.connect(invoked)
266 | menu.menuDismissed.connect(dismissed)
267 | menu.showRectMenu(300, 300)
268 | #menu.showDockMenu(1366, 768)
269 |
270 | sys.exit(app.exec_())
271 |
--------------------------------------------------------------------------------
/images.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/arrow-light.png
4 | images/arrow-light-hover.png
5 | images/arrow-light-inactive.png
6 | images/check_dark_hover.png
7 | images/check_dark_inactive.png
8 | images/check_dark_normal.png
9 | images/check_light_hover.png
10 | images/check_light_inactive.png
11 | images/check_light_normal.png
12 |
13 |
14 |
--------------------------------------------------------------------------------
/images/arrow-light-hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martyr-deepin/deepin-menu/5846d95d5e79325dac9159bf415d3d5f220c8794/images/arrow-light-hover.png
--------------------------------------------------------------------------------
/images/arrow-light-inactive.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martyr-deepin/deepin-menu/5846d95d5e79325dac9159bf415d3d5f220c8794/images/arrow-light-inactive.png
--------------------------------------------------------------------------------
/images/arrow-light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martyr-deepin/deepin-menu/5846d95d5e79325dac9159bf415d3d5f220c8794/images/arrow-light.png
--------------------------------------------------------------------------------
/images/check_dark_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martyr-deepin/deepin-menu/5846d95d5e79325dac9159bf415d3d5f220c8794/images/check_dark_hover.png
--------------------------------------------------------------------------------
/images/check_dark_inactive.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martyr-deepin/deepin-menu/5846d95d5e79325dac9159bf415d3d5f220c8794/images/check_dark_inactive.png
--------------------------------------------------------------------------------
/images/check_dark_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martyr-deepin/deepin-menu/5846d95d5e79325dac9159bf415d3d5f220c8794/images/check_dark_normal.png
--------------------------------------------------------------------------------
/images/check_light_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martyr-deepin/deepin-menu/5846d95d5e79325dac9159bf415d3d5f220c8794/images/check_light_hover.png
--------------------------------------------------------------------------------
/images/check_light_inactive.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martyr-deepin/deepin-menu/5846d95d5e79325dac9159bf415d3d5f220c8794/images/check_light_inactive.png
--------------------------------------------------------------------------------
/images/check_light_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martyr-deepin/deepin-menu/5846d95d5e79325dac9159bf415d3d5f220c8794/images/check_light_normal.png
--------------------------------------------------------------------------------
/src/dabstractmenu.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #include "dabstractmenu.h"
21 |
22 | #include
23 |
24 | DAbstractMenu::DAbstractMenu()
25 | {
26 |
27 | }
28 |
29 | void DAbstractMenu::releaseFocus()
30 | {
31 |
32 | }
33 |
34 | void DAbstractMenu::setItems(QJsonArray)
35 | {
36 |
37 | }
38 |
39 | void DAbstractMenu::setItemActivity(const QString &, bool)
40 | {
41 |
42 | }
43 |
44 | void DAbstractMenu::setItemChecked(const QString &, bool)
45 | {
46 |
47 | }
48 |
49 | void DAbstractMenu::setItemText(const QString &, const QString &)
50 | {
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/dabstractmenu.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #ifndef DABSTRACTMENU_H
21 | #define DABSTRACTMENU_H
22 |
23 | #include
24 |
25 | class DAbstractMenu
26 | {
27 | public:
28 | explicit DAbstractMenu();
29 |
30 | public:
31 | virtual void releaseFocus();
32 |
33 | virtual void setItems(QJsonArray items);
34 |
35 | virtual void setItemActivity(const QString &itemId, bool isActive);
36 | virtual void setItemChecked(const QString &itemId, bool checked);
37 | virtual void setItemText(const QString &itemId, const QString &text);
38 | };
39 |
40 | #endif // DABSTRACTMENU_H
41 |
--------------------------------------------------------------------------------
/src/dbus_manager_adaptor.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | /*
21 | * This file was generated by qdbusxml2cpp version 0.8
22 | * Command line was: qdbusxml2cpp -c ManagerAdaptor -a dbus_manager_adaptor.h:dbus_manager_adaptor.cpp com.deepin.menu.Manager.xml
23 | *
24 | * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
25 | *
26 | * This is an auto-generated file.
27 | * Do not edit! All changes made to it will be lost.
28 | */
29 |
30 | #include "dbus_manager_adaptor.h"
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 |
39 | /*
40 | * Implementation of adaptor class ManagerAdaptor
41 | */
42 |
43 | ManagerAdaptor::ManagerAdaptor(QObject *parent)
44 | : QDBusAbstractAdaptor(parent)
45 | {
46 | // constructor
47 | setAutoRelaySignals(true);
48 | }
49 |
50 | ManagerAdaptor::~ManagerAdaptor()
51 | {
52 | // destructor
53 | }
54 |
55 | QDBusObjectPath ManagerAdaptor::RegisterMenu()
56 | {
57 | // handle method call com.deepin.menu.Manager.RegisterMenu
58 | QDBusObjectPath menuObjectPath;
59 | QMetaObject::invokeMethod(parent(), "RegisterMenu", Q_RETURN_ARG(QDBusObjectPath, menuObjectPath));
60 | return menuObjectPath;
61 | }
62 |
63 | void ManagerAdaptor::UnregisterMenu(const QString &menuObjectPath)
64 | {
65 | // handle method call com.deepin.menu.Manager.UnregisterMenu
66 | QMetaObject::invokeMethod(parent(), "UnregisterMenu", Q_ARG(QString, menuObjectPath));
67 | }
68 |
69 |
--------------------------------------------------------------------------------
/src/dbus_manager_adaptor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | /*
21 | * This file was generated by qdbusxml2cpp version 0.8
22 | * Command line was: qdbusxml2cpp -c ManagerAdaptor -a dbus_manager_adaptor.h:dbus_manager_adaptor.cpp com.deepin.menu.Manager.xml
23 | *
24 | * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
25 | *
26 | * This is an auto-generated file.
27 | * This file may have been hand-edited. Look for HAND-EDIT comments
28 | * before re-generating it.
29 | */
30 |
31 | #ifndef DBUS_MANAGER_ADAPTOR_H_1405666337
32 | #define DBUS_MANAGER_ADAPTOR_H_1405666337
33 |
34 | #include
35 | #include
36 | QT_BEGIN_NAMESPACE
37 | class QByteArray;
38 | template class QList;
39 | template class QMap;
40 | class QString;
41 | class QStringList;
42 | class QVariant;
43 | QT_END_NAMESPACE
44 |
45 | /*
46 | * Adaptor class for interface com.deepin.menu.Manager
47 | */
48 | class ManagerAdaptor: public QDBusAbstractAdaptor
49 | {
50 | Q_OBJECT
51 | Q_CLASSINFO("D-Bus Interface", "com.deepin.menu.Manager")
52 | Q_CLASSINFO("D-Bus Introspection", ""
53 | " \n"
54 | " \n"
55 | " \n"
56 | " \n"
57 | " \n"
58 | " \n"
59 | " \n"
60 | " \n"
61 | "")
62 | public:
63 | ManagerAdaptor(QObject *parent);
64 | virtual ~ManagerAdaptor();
65 |
66 | public: // PROPERTIES
67 | public Q_SLOTS: // METHODS
68 | QDBusObjectPath RegisterMenu();
69 | void UnregisterMenu(const QString &menuObjectPath);
70 | Q_SIGNALS: // SIGNALS
71 | };
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/src/dbus_menu_adaptor.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | /*
21 | * This file was generated by qdbusxml2cpp version 0.8
22 | * Command line was: qdbusxml2cpp -c MenuAdaptor -a dbus_menu_adaptor.h:dbus_menu_adaptor.cpp com.deepin.menu.Menu.xml
23 | *
24 | * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
25 | *
26 | * This is an auto-generated file.
27 | * Do not edit! All changes made to it will be lost.
28 | */
29 |
30 | #include "dbus_menu_adaptor.h"
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 |
39 | /*
40 | * Implementation of adaptor class MenuAdaptor
41 | */
42 |
43 | MenuAdaptor::MenuAdaptor(QObject *parent)
44 | : QDBusAbstractAdaptor(parent)
45 | {
46 | // constructor
47 | setAutoRelaySignals(true);
48 | }
49 |
50 | MenuAdaptor::~MenuAdaptor()
51 | {
52 | // destructor
53 | }
54 |
55 | void MenuAdaptor::SetItemActivity(const QString &itemId, bool isActive)
56 | {
57 | // handle method call com.deepin.menu.Menu.SetItemActivity
58 | QMetaObject::invokeMethod(parent(), "SetItemActivity", Q_ARG(QString, itemId), Q_ARG(bool, isActive));
59 | }
60 |
61 | void MenuAdaptor::SetItemChecked(const QString &itemId, bool checked)
62 | {
63 | // handle method call com.deepin.menu.Menu.SetItemChecked
64 | QMetaObject::invokeMethod(parent(), "SetItemChecked", Q_ARG(QString, itemId), Q_ARG(bool, checked));
65 | }
66 |
67 | void MenuAdaptor::SetItemText(const QString &itemId, const QString &text)
68 | {
69 | // handle method call com.deepin.menu.Menu.SetItemText
70 | QMetaObject::invokeMethod(parent(), "SetItemText", Q_ARG(QString, itemId), Q_ARG(QString, text));
71 | }
72 |
73 | void MenuAdaptor::ShowMenu(const QString &menuJsonContent)
74 | {
75 | // handle method call com.deepin.menu.Menu.ShowMenu
76 | QMetaObject::invokeMethod(parent(), "ShowMenu", Q_ARG(QString, menuJsonContent));
77 | }
78 |
79 |
--------------------------------------------------------------------------------
/src/dbus_menu_adaptor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | /*
21 | * This file was generated by qdbusxml2cpp version 0.8
22 | * Command line was: qdbusxml2cpp -c MenuAdaptor -a dbus_menu_adaptor.h:dbus_menu_adaptor.cpp com.deepin.menu.Menu.xml
23 | *
24 | * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
25 | *
26 | * This is an auto-generated file.
27 | * This file may have been hand-edited. Look for HAND-EDIT comments
28 | * before re-generating it.
29 | */
30 |
31 | #ifndef DBUS_MENU_ADAPTOR_H_1405666344
32 | #define DBUS_MENU_ADAPTOR_H_1405666344
33 |
34 | #include
35 | #include
36 | QT_BEGIN_NAMESPACE
37 | class QByteArray;
38 | template class QList;
39 | template class QMap;
40 | class QString;
41 | class QStringList;
42 | class QVariant;
43 | QT_END_NAMESPACE
44 |
45 | /*
46 | * Adaptor class for interface com.deepin.menu.Menu
47 | */
48 | class MenuAdaptor: public QDBusAbstractAdaptor
49 | {
50 | Q_OBJECT
51 | Q_CLASSINFO("D-Bus Interface", "com.deepin.menu.Menu")
52 | Q_CLASSINFO("D-Bus Introspection", ""
53 | " \n"
54 | " \n"
55 | " \n"
56 | " \n"
57 | " \n"
58 | " \n"
59 | " \n"
60 | " \n"
61 | " \n"
62 | " \n"
63 | " \n"
64 | " \n"
65 | " \n"
66 | " \n"
67 | " \n"
68 | " \n"
69 | " \n"
70 | " \n"
71 | " \n"
72 | " \n"
73 | " \n"
74 | " \n"
75 | "")
76 | public:
77 | MenuAdaptor(QObject *parent);
78 | virtual ~MenuAdaptor();
79 |
80 | public: // PROPERTIES
81 | public Q_SLOTS: // METHODS
82 | void SetItemActivity(const QString &itemId, bool isActive);
83 | void SetItemChecked(const QString &itemId, bool checked);
84 | void SetItemText(const QString &itemId, const QString &text);
85 | void ShowMenu(const QString &menuJsonContent);
86 | Q_SIGNALS: // SIGNALS
87 | void ItemInvoked(const QString &itemId, bool checked);
88 | void MenuUnregistered();
89 | };
90 |
91 | #endif
92 |
--------------------------------------------------------------------------------
/src/ddesktopmenu.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #include "ddesktopmenu.h"
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | DDesktopMenu::DDesktopMenu()
33 | : QMenu()
34 | , m_monitor(new DRegionMonitor(this))
35 | {
36 | setAccessibleName("DesktopMenu");
37 |
38 | // NOTE(hualet): don't change those window flags, if you delete below line, deepin-menu
39 | // won't even show working with deepin-terminal.
40 | setWindowFlags(windowFlags() | Qt::ToolTip);
41 |
42 | connect(m_monitor, &DRegionMonitor::buttonPress, this, [=] (const QPoint &p) {
43 | for (auto *menu : m_ownMenus)
44 | if (menu->geometry().contains(p))
45 | return;
46 |
47 | QTimer::singleShot(100, this, &DDesktopMenu::hide);
48 | });
49 | }
50 |
51 | DDesktopMenu::~DDesktopMenu()
52 | {
53 | m_monitor->unregisterRegion();
54 | releaseKeyboard();
55 | }
56 |
57 | void DDesktopMenu::setItems(QJsonArray items)
58 | {
59 | addActionFromJson(this, items);
60 | }
61 |
62 | void DDesktopMenu::setItemActivity(const QString &itemId, bool isActive)
63 | {
64 | QAction *action = this->action(itemId);
65 | if (action) {
66 | action->setEnabled(isActive);
67 | }
68 | }
69 |
70 | void DDesktopMenu::setItemChecked(const QString &itemId, bool checked)
71 | {
72 | QAction *action = this->action(itemId);
73 | if (action) {
74 | action->setChecked(checked);
75 | }
76 | }
77 |
78 | void DDesktopMenu::setItemText(const QString &itemId, const QString &text)
79 | {
80 | QAction *action = this->action(itemId);
81 | if (action) {
82 | action->setText(text);
83 | }
84 | }
85 |
86 | void DDesktopMenu::showMenu(const QPoint pos, bool isScaled)
87 | {
88 | QPoint handlePos = pos;
89 | if (isScaled) {
90 | handlePos = pos * devicePixelRatioF();
91 | }
92 |
93 | // 因为.dde_env已经不包含qt的缩放环境变量,所以收到的都是原始坐标
94 | QList oldList = qApp->screens();
95 |
96 | // 得到坐标所在的屏幕
97 | for (auto it = oldList.constBegin(); it != oldList.constEnd(); ++it) {
98 | QScreen const * currentScreen = (*it);
99 | QRect rect = currentScreen->handle()->geometry();
100 | const QPoint point = rect.topLeft();
101 |
102 | if (rect.contains(handlePos)) {
103 | // 计算接收坐标距离当前屏幕左边缘的长宽
104 | // 保持原始的topleft和在当前屏幕内坐标的偏移就可以正常显示了
105 | QMenu::popup(QPoint(rect.topLeft() + (handlePos - point) / devicePixelRatioF()));
106 | break;
107 | }
108 | }
109 | }
110 |
111 | void DDesktopMenu::showEvent(QShowEvent *e)
112 | {
113 | QMenu::showEvent(e);
114 |
115 | m_monitor->registerRegion();
116 |
117 | QTimer::singleShot(100, this, [=] {
118 | activateWindow();
119 | grabKeyboard();
120 | });
121 | }
122 |
123 | void DDesktopMenu::hideEvent(QHideEvent *e)
124 | {
125 | QMenu::hideEvent(e);
126 |
127 | m_monitor->unregisterRegion();
128 | releaseKeyboard();
129 | }
130 |
131 | void DDesktopMenu::keyPressEvent(QKeyEvent *event)
132 | {
133 | if (event->key() == Qt::Key_Escape) {
134 | hide();
135 | }
136 |
137 | QMenu::keyPressEvent(event);
138 | }
139 |
140 | QAction *DDesktopMenu::action(const QString &id)
141 | {
142 | for (QAction *action : actions()) {
143 | if (action->property("itemId") == id) {
144 | return action;
145 | }
146 | }
147 |
148 | return nullptr;
149 | }
150 |
151 | void DDesktopMenu::addActionFromJson(QMenu *menu, const QJsonArray &items)
152 | {
153 | m_ownMenus << menu;
154 |
155 | foreach (QJsonValue item, items) {
156 | QJsonObject itemObj = item.toObject();
157 | const QString itemText = itemObj["itemText"].toString().replace("_", QString()).replace(QRegExp("\\([^)]+\\)"), QString());
158 | const QString itemIcon = itemObj["itemIcon"].toString();
159 |
160 | const QJsonObject subMenuJson = itemObj["itemSubMenu"].toObject();
161 | const QJsonArray subMenuItemsJson = subMenuJson["items"].toArray();
162 |
163 | QAction *action = nullptr;
164 | if (subMenuItemsJson.count()) {
165 |
166 | QMenu *subMenu = new QMenu(menu);
167 | action = menu->addMenu(subMenu);
168 | addActionFromJson(subMenu, subMenuItemsJson);
169 | } else if (itemText.isEmpty()) {
170 | menu->addSeparator();
171 | continue;
172 | } else {
173 | action = new QAction(menu);
174 | menu->addAction(action);
175 | }
176 |
177 | action->setText(itemText);
178 | action->setIcon(QIcon(itemIcon));
179 |
180 | action->setEnabled(itemObj["isActive"].toBool());
181 | action->setCheckable(itemObj["isCheckable"].toBool());
182 | action->setChecked(itemObj["checked"].toBool());
183 |
184 | action->setProperty("itemId", itemObj["itemId"].toString());
185 |
186 | connect(action, &QAction::triggered, menu, [=] (const bool checked) {
187 | const QString id = action->property("itemId").toString();
188 |
189 | releaseFocus();
190 | releaseMouse();
191 | releaseKeyboard();
192 | emit itemClicked(id, checked);
193 |
194 | hide();
195 | });
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/src/ddesktopmenu.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #ifndef DDESKTOPMENU_H
21 | #define DDESKTOPMENU_H
22 |
23 | #include
24 | #include
25 |
26 | #include "dabstractmenu.h"
27 |
28 | DWIDGET_USE_NAMESPACE
29 |
30 | class DDesktopMenu : public QMenu, public DAbstractMenu
31 | {
32 | Q_OBJECT
33 | public:
34 | explicit DDesktopMenu();
35 | ~DDesktopMenu();
36 |
37 | void setItems(QJsonArray items) Q_DECL_OVERRIDE;
38 |
39 | void setItemActivity(const QString &itemId, bool isActive) Q_DECL_OVERRIDE;
40 | void setItemChecked(const QString &itemId, bool checked) Q_DECL_OVERRIDE;
41 | void setItemText(const QString &itemId, const QString &text) Q_DECL_OVERRIDE;
42 |
43 | void showMenu(const QPoint pos, bool isScaled);
44 |
45 | signals:
46 | void itemClicked(const QString &id, bool checked);
47 |
48 | protected:
49 | void showEvent(QShowEvent *e) Q_DECL_OVERRIDE;
50 | void hideEvent(QHideEvent *e) Q_DECL_OVERRIDE;
51 | void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
52 |
53 | private:
54 | QAction *action(const QString &id);
55 | void addActionFromJson(QMenu *menu, const QJsonArray &items);
56 | DRegionMonitor *m_monitor;
57 | QList m_ownMenus;
58 | };
59 |
60 | #endif // DDESKTOPMENU_H
61 |
--------------------------------------------------------------------------------
/src/ddockmenu.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | #include "ddockmenu.h"
33 | #include "dmenucontent.h"
34 | #include "utils.h"
35 |
36 | DDockMenu::DDockMenu(DDockMenu *parent)
37 | : DArrowRectangle(DArrowRectangle::ArrowBottom, parent)
38 | , m_menuContent(new DMenuContent(this))
39 | , m_monitor(new DRegionMonitor(this))
40 | {
41 | setAttribute(Qt::WA_InputMethodEnabled, false);
42 |
43 | setMouseTracking(true);
44 |
45 | m_wmHelper = DWindowManagerHelper::instance();
46 |
47 | connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &DDockMenu::onWMCompositeChanged);
48 |
49 | onWMCompositeChanged();
50 |
51 | setAccessibleName("DockMenu");
52 | setBackgroundColor(DBlurEffectWidget::DarkColor);
53 | setMargin(0);
54 | setArrowWidth(18);
55 | setArrowHeight(10);
56 |
57 | normalStyle = ItemStyle{Qt::transparent,
58 | Qt::white,
59 | QColor("#646464"),
60 | ":/images/check_dark_normal.png",
61 | ":/images/arrow-dark.png"};
62 | hoverStyle = ItemStyle{QColor("#2ca7f8"),
63 | Qt::white,
64 | QColor("#646464"),
65 | ":/images/check_dark_hover.png",
66 | ":/images/arrow-dark.png"};
67 | inactiveStyle = ItemStyle{Qt::transparent,
68 | QColor("#646464"),
69 | QColor("#646464"),
70 | ":/images/check_dark_inactive.png",
71 | ":/images/arrow-dark.png"};
72 |
73 | connect(m_monitor, &DRegionMonitor::buttonPress, this, [=] (const QPoint &p) {
74 | if (geometry().contains(p)) {
75 | // The action performed is not from QAction and needs to be postponed because the menu requires a hover style.
76 | QTimer::singleShot(100, this, [=] {
77 | m_menuContent->processButtonClick(p);
78 | });
79 | } else {
80 | qDebug() << "window deactivate, destroy menu";
81 | destroyAll();
82 | }
83 | });
84 | }
85 |
86 | DDockMenu::~DDockMenu()
87 | {
88 | m_monitor->unregisterRegion();
89 | setVisible(false);
90 | releaseFocus();
91 | releaseKeyboard();
92 | }
93 |
94 | void DDockMenu::setItems(QJsonArray items)
95 | {
96 | m_menuContent->setCurrentIndex(-1);
97 | m_menuContent->clearActions();
98 |
99 | foreach (QJsonValue item, items) {
100 | QJsonObject itemObj = item.toObject();
101 |
102 | QAction *action = new QAction(m_menuContent);
103 | QString itemText = itemObj["itemText"].toString().replace("_", QString()).replace(QRegExp("\\([^)]+\\)"), QString());
104 |
105 | action->setText(itemText);
106 | action->setEnabled(itemObj["isActive"].toBool());
107 | action->setCheckable(itemObj["isCheckable"].toBool() || Utils::menuItemCheckableFromId(itemObj["itemId"].toString()));
108 | action->setChecked(itemObj["checked"].toBool());
109 | action->setProperty("itemId", itemObj["itemId"].toString());
110 | action->setProperty("itemIcon", itemObj["itemIcon"].toString());
111 | action->setProperty("itemIconHover", itemObj["itemIconHover"].toString());
112 | action->setProperty("itemIconInactive", itemObj["itemIconInactive"].toString());
113 | action->setProperty("itemSubMenu", itemObj["itemSubMenu"].toObject());
114 |
115 | m_menuContent->addAction(action);
116 | }
117 |
118 | // adjust its size according to its content.
119 | m_menuContent->setFixedSize(m_menuContent->contentWidth(),
120 | m_menuContent->contentHeight());
121 |
122 |
123 | setContent(m_menuContent);
124 |
125 | resizeWithContent();
126 | }
127 |
128 | DDockMenu *DDockMenu::getRootMenu()
129 | {
130 | return this;
131 | }
132 |
133 | void DDockMenu::showSubMenu(int, int, const QJsonObject &)
134 | {
135 |
136 | }
137 |
138 | bool DDockMenu::event(QEvent *event)
139 | {
140 | if (event->type() == QEvent::WindowDeactivate) {
141 | // NOTE(sbw): test if we have mouse handle
142 | if (rect().contains(mapFromGlobal(QCursor::pos())))
143 | {
144 | activateWindow();
145 | } else {
146 | qDebug() << "window deactivate, destroy menu";
147 | destroyAll();
148 | }
149 | }
150 |
151 | if (event->type() == QEvent::Move) {
152 | qDebug() << pos();
153 | }
154 |
155 | return DArrowRectangle::event(event);
156 | }
157 |
158 | void DDockMenu::showEvent(QShowEvent *e)
159 | {
160 | Q_ASSERT(!m_monitor->registered());
161 | m_monitor->registerRegion();
162 |
163 | QTimer::singleShot(100, this, [=] {
164 | if (!isVisible())
165 | return;
166 | if (!isActiveWindow())
167 | activateWindow();
168 |
169 | grabKeyboard();
170 | });
171 |
172 | DArrowRectangle::showEvent(e);
173 | }
174 |
175 | void DDockMenu::hideEvent(QHideEvent *event)
176 | {
177 | DArrowRectangle::hideEvent(event);
178 |
179 | m_monitor->unregisterRegion();
180 | releaseKeyboard();
181 | }
182 |
183 | void DDockMenu::mouseMoveEvent(QMouseEvent *event)
184 | {
185 | DArrowRectangle::mouseMoveEvent(event);
186 |
187 | m_menuContent->processCursorMove(mapToGlobal(event->pos()));
188 | }
189 |
190 | void DDockMenu::keyPressEvent(QKeyEvent *event)
191 | {
192 | DArrowRectangle::keyPressEvent(event);
193 |
194 | switch (event->key()) {
195 | case Qt::Key_Escape:
196 | destroyAll();
197 | break;
198 | case Qt::Key_Return:
199 | case Qt::Key_Enter:
200 | m_menuContent->doCurrentAction();
201 | break;
202 | case Qt::Key_Up:
203 | m_menuContent->selectPrevious();
204 | break;
205 | case Qt::Key_Down:
206 | m_menuContent->selectNext();
207 | break;
208 | default:
209 | break;
210 | }
211 | }
212 |
213 | /**
214 | * @brief DDockMenu::menuUnderPoint
215 | * @param point is a global position.
216 | * @return
217 | */
218 | DDockMenu *DDockMenu::menuUnderPoint(const QPoint point)
219 | {
220 | return geometry().contains(point) ? this : nullptr;
221 | }
222 |
223 | void DDockMenu::releaseFocus()
224 | {
225 | qDebug() << Q_FUNC_INFO << this;
226 |
227 | releaseMouse();
228 | releaseKeyboard();
229 | }
230 |
231 | void DDockMenu::destroyAll()
232 | {
233 | // NOTE(hualet): the events processed by this menu is actually delivered by
234 | // xmousearea which is xrecord backed, so if we destroy this window too
235 | // early, say immediately after mouse clicks, the actual events will go to
236 | // the window behide the menu(desktop for example).
237 | QTimer::singleShot(100, this, [this] {
238 | qApp->processEvents();
239 | deleteLater();
240 | });
241 | }
242 |
243 | void DDockMenu::onWMCompositeChanged()
244 | {
245 | if (m_wmHelper->hasComposite())
246 | setBorderColor(QColor(255, 255, 255, 0));
247 | else
248 | setBorderColor(QColor("#2C3238"));
249 | }
250 |
--------------------------------------------------------------------------------
/src/ddockmenu.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #ifndef DDOCKMENU_H
21 | #define DDOCKMENU_H
22 |
23 | #include "dabstractmenu.h"
24 | #include
25 | #include
26 | #include
27 |
28 | DWIDGET_USE_NAMESPACE
29 | DGUI_USE_NAMESPACE
30 |
31 | struct ItemStyle {
32 | QColor itemBackgroundColor;
33 | QColor itemTextColor;
34 | QColor itemShortcutColor;
35 | QString checkmarkIcon;
36 | QString subMenuIndicatorIcon;
37 | };
38 |
39 | class DMenuContent;
40 | class DDockMenu : public DArrowRectangle, public DAbstractMenu
41 | {
42 | Q_OBJECT
43 | public:
44 | explicit DDockMenu(DDockMenu *parent = nullptr);
45 | ~DDockMenu() override;
46 |
47 | void setItems(QJsonArray items) Q_DECL_OVERRIDE;
48 |
49 | void releaseFocus() Q_DECL_OVERRIDE;
50 |
51 | void destroyAll();
52 |
53 | signals:
54 | void itemClicked(const QString &id, bool checked);
55 |
56 | private slots:
57 | void onWMCompositeChanged();
58 |
59 | private:
60 | DDockMenu *getRootMenu();
61 | DDockMenu *menuUnderPoint(const QPoint point);
62 | void showSubMenu(int x, int y, const QJsonObject &obj );
63 |
64 | protected:
65 | bool event(QEvent *event) Q_DECL_OVERRIDE;
66 | void showEvent(QShowEvent *e) Q_DECL_OVERRIDE;
67 | void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE;
68 | void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
69 | void keyPressEvent(QKeyEvent *event) override;
70 |
71 | private:
72 | friend class DMenuContent;
73 | DMenuContent *m_menuContent;
74 |
75 | ItemStyle normalStyle;
76 | ItemStyle hoverStyle;
77 | ItemStyle inactiveStyle;
78 | DRegionMonitor *m_monitor;
79 | DWindowManagerHelper *m_wmHelper;
80 | };
81 |
82 | #endif // DDOCKMENU_H
83 |
--------------------------------------------------------------------------------
/src/dmenuapplication.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #include "dmenuapplication.h"
21 |
22 | DMenuApplication::DMenuApplication(int &argc, char *argv[]) :
23 | DApplication(argc, argv)
24 | {
25 |
26 | }
27 |
28 | void DMenuApplication::quitApplication(const QString &)
29 | {
30 | this->quit();
31 | }
32 |
--------------------------------------------------------------------------------
/src/dmenuapplication.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #ifndef DMENUAPPLICATION_H
21 | #define DMENUAPPLICATION_H
22 |
23 | #include
24 |
25 | DWIDGET_USE_NAMESPACE
26 |
27 | class DMenuApplication : public DApplication
28 | {
29 | Q_OBJECT
30 | public:
31 | explicit DMenuApplication(int &, char**);
32 |
33 | public slots:
34 | void quitApplication(const QString&);
35 | };
36 |
37 | #endif // DMENUAPPLICATION_H
38 |
--------------------------------------------------------------------------------
/src/dmenubase.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | #include
37 |
38 | #include "dmenubase.h"
39 | #include "dmenucontent.h"
40 | #include "utils.h"
41 |
42 | #define GRAB_FOCUS_TRY_TIMES 100
43 |
44 | DMenuBase::DMenuBase(QWidget *parent) :
45 | QWidget(parent, Qt::Tool | Qt::BypassWindowManagerHint),
46 | _subMenu(NULL),
47 | _radius(4),
48 | _shadowMargins(QMargins(0, 0, 0, 0))
49 | {
50 | this->setAttribute(Qt::WA_TranslucentBackground);
51 |
52 | queryXIExtension();
53 |
54 | _dropShadow = new QGraphicsDropShadowEffect(this);
55 | _dropShadow->setColor(QColor::fromRgbF(0, 0, 0, 0.2));
56 | _dropShadow->setXOffset(0);
57 | _dropShadow->setYOffset(6);
58 | this->setGraphicsEffect(_dropShadow);
59 |
60 | _grabFocusTimer = new QTimer(this);
61 | _grabFocusTimer->setSingleShot(true);
62 | }
63 |
64 | // getters and setters
65 | int DMenuBase::radius()
66 | {
67 | return _radius;
68 | }
69 |
70 | void DMenuBase::setRadius(int radius)
71 | {
72 | if (_radius != radius) {
73 | _radius = radius;
74 |
75 | emit radiusChanged(radius);
76 | }
77 | }
78 |
79 | QMargins DMenuBase::shadowMargins()
80 | {
81 | return _shadowMargins;
82 | }
83 |
84 | void DMenuBase::setShadowMargins(QMargins shadowMargins)
85 | {
86 | if (_shadowMargins != shadowMargins) {
87 | _shadowMargins = shadowMargins;
88 | _dropShadow->setBlurRadius(qMax(qMax(_shadowMargins.left(), _shadowMargins.top()),
89 | qMax(_shadowMargins.right(), _shadowMargins.bottom())));
90 |
91 | emit shadowMarginsChanged(shadowMargins);
92 | }
93 | }
94 |
95 | QMargins DMenuBase::menuContentMargins()
96 | {
97 | return _menuContentMargins;
98 | }
99 |
100 | void DMenuBase::setMenuContentMargins(QMargins margins)
101 | {
102 | if(_menuContentMargins != margins) {
103 | _menuContentMargins = margins;
104 |
105 | emit menuContentMarginsChanged(margins);
106 | }
107 | }
108 |
109 | int DMenuBase::itemLeftSpacing()
110 | {
111 | return _itemLeftSpacing;
112 | }
113 |
114 | void DMenuBase::setItemLeftSpacing(int spacing)
115 | {
116 | if (_itemLeftSpacing != spacing) {
117 | _itemLeftSpacing = spacing;
118 |
119 | emit itemLeftSpacingChanged(spacing);
120 | }
121 | }
122 |
123 | int DMenuBase::itemCenterSpacing()
124 | {
125 | return _itemCenterSpacing;
126 | }
127 |
128 | void DMenuBase::setItemCenterSpacing(int spacing)
129 | {
130 | if (_itemCenterSpacing != spacing) {
131 | _itemCenterSpacing = spacing;
132 |
133 | emit itemCenterSpacingChanged(spacing);
134 | }
135 | }
136 |
137 | int DMenuBase::itemRightSpacing()
138 | {
139 | return _itemRightSpacing;
140 | }
141 |
142 | void DMenuBase::setItemRightSpacing(int spacing)
143 | {
144 | if (_itemRightSpacing != spacing) {
145 | _itemRightSpacing = spacing;
146 |
147 | emit itemRightSpacingChanged(spacing);
148 | }
149 | }
150 |
151 | QSharedPointer DMenuBase::menuContent()
152 | {
153 | return _menuContent;
154 | }
155 |
156 | void DMenuBase::setMenuContent(QSharedPointer content)
157 | {
158 | _menuContent = content;
159 | _menuContent->setContentsMargins(_menuContentMargins);
160 |
161 | QHBoxLayout *layout = new QHBoxLayout(this);
162 | layout->setContentsMargins(QMargins(0, _menuContentMargins.top(), 0, _menuContentMargins.bottom()));
163 | layout->addWidget(_menuContent.data());
164 |
165 | this->setLayout(layout);
166 | }
167 |
168 | DMenuBase* DMenuBase::subMenu()
169 | {
170 | return _subMenu;
171 | }
172 |
173 | void DMenuBase::setContent(QJsonArray items)
174 | {
175 | Q_ASSERT(this->menuContent());
176 | this->menuContent()->setCurrentIndex(-1);
177 | this->menuContent()->clearActions();
178 |
179 | foreach (QJsonValue item, items) {
180 | QJsonObject itemObj = item.toObject();
181 |
182 | QAction *action = new QAction(this->menuContent().data());
183 | QString itemText = itemObj["itemText"].toString().replace("_", QString()).replace(QRegExp("\\([^)]+\\)"), QString());/*.replace(regexp, navKeyWrapper)*/;
184 |
185 | action->setText(itemText);
186 | action->setEnabled(itemObj["isActive"].toBool());
187 | action->setCheckable(itemObj["isCheckable"].toBool() || Utils::menuItemCheckableFromId(itemObj["itemId"].toString()));
188 | action->setChecked(itemObj["checked"].toBool());
189 | action->setProperty("itemId", itemObj["itemId"].toString());
190 | action->setProperty("itemIcon", itemObj["itemIcon"].toString());
191 | action->setProperty("itemIconHover", itemObj["itemIconHover"].toString());
192 | action->setProperty("itemIconInactive", itemObj["itemIconInactive"].toString());
193 | action->setProperty("itemSubMenu", itemObj["itemSubMenu"].toObject());
194 | // action->setProperty("itemNavKey", navKey);
195 |
196 | _menuContent->addAction(action);
197 | }
198 |
199 | // adjust its size according to its content.
200 | this->resize(_menuContent->contentWidth()
201 | + _shadowMargins.left()
202 | + _shadowMargins.right()
203 | + _menuContentMargins.left()
204 | + _menuContentMargins.right()
205 | + this->contentsMargins().left() - _shadowMargins.left()
206 | + this->contentsMargins().right() - _shadowMargins.right(),
207 | _menuContent->contentHeight()
208 | + _shadowMargins.top()
209 | + _shadowMargins.bottom()
210 | + _menuContentMargins.top()
211 | + _menuContentMargins.bottom()
212 | + this->contentsMargins().top() - _shadowMargins.top()
213 | + this->contentsMargins().bottom() - _shadowMargins.bottom());
214 | }
215 |
216 | void DMenuBase::destroyAll()
217 | {
218 | releaseFocus();
219 |
220 | if(this->parent()) {
221 | DMenuBase *parent = qobject_cast(this->parent());
222 | Q_ASSERT(parent);
223 | parent->destroyAll();
224 | } else {
225 | this->deleteLater();
226 | }
227 | }
228 |
229 | void DMenuBase::grabFocus()
230 | {
231 | if (mouseGrabber() == menuContent().data()
232 | && keyboardGrabber() == menuContent().data())
233 | {
234 | // the menu already grabs the focus, no need
235 | // to do it again.
236 | return;
237 | }
238 |
239 | grabFocusSlot();
240 | connect(_grabFocusTimer, SIGNAL(timeout()), this, SLOT(grabFocusSlot()));
241 | }
242 |
243 | void DMenuBase::releaseFocus()
244 | {
245 | if (mouseGrabber())
246 | mouseGrabber()->releaseMouse();
247 | if (keyboardGrabber())
248 | keyboardGrabber()->releaseKeyboard();
249 | }
250 |
251 | bool DMenuBase::grabFocusInternal(int tryTimes)
252 | {
253 | QWindow *window = this->menuContent()->windowHandle();
254 | if (!window)
255 | if (const QWidget *nativeParent = this->menuContent()->nativeParentWidget())
256 | window = nativeParent->windowHandle();
257 | // grab pointer
258 | int i = 0;
259 | while(!window->setMouseGrabEnabled(true) && i < tryTimes) {
260 | QThread::msleep(10);
261 | i++;
262 | }
263 | if (i >= tryTimes) {
264 | qWarning() << QString("GrabMouse Failed after trying %1 times").arg(i);
265 | } else {
266 | qDebug() << QString("GrabMouse tries %1").arg(i);
267 | }
268 | this->menuContent()->grabMouse();
269 |
270 | // grab keyboard
271 | int j = 0;
272 | while(!window->setKeyboardGrabEnabled(true) && j < tryTimes) {
273 | QThread::msleep(10);
274 | j++;
275 | }
276 | if (j >= tryTimes) {
277 | qWarning() << QString("GrabKeyboard Failed after trying %1 times").arg(j);
278 | } else {
279 | qDebug() << QString("GrabKeyboard tries %1").arg(j);
280 | }
281 | this->menuContent()->grabKeyboard();
282 |
283 | return (i < tryTimes) && (j < tryTimes);
284 | }
285 |
286 | void DMenuBase::grabFocusSlot()
287 | {
288 | if (!grabFocusInternal(1)) {
289 | _grabFocusTimer->start();
290 | }
291 | }
292 |
293 | DMenuBase *DMenuBase::menuUnderPoint(QPoint point)
294 | {
295 | if(this->parent()) {
296 | DMenuBase *parent = qobject_cast(this->parent());
297 | Q_ASSERT(parent);
298 |
299 | return parent->menuUnderPoint(point);
300 | } else {
301 | DMenuBase *result = NULL;
302 | DMenuBase *subMenu =this;
303 | while (subMenu) {
304 | // remove the shadow margin, so clicks on the shadow won't be eaten by us.
305 | if (Utils::pointInRect(point, subMenu->geometry().marginsRemoved(subMenu->shadowMargins()))) {
306 | // shouldn't return here, otherwise the old menus are able to steal focus from
307 | // the younger ones even if they are at the bottom of the stack.
308 | result = subMenu;
309 | }
310 | subMenu = subMenu->subMenu();
311 | }
312 | return result;
313 | }
314 | }
315 |
316 | void DMenuBase::setItemActivity(const QString &itemId, bool isActive)
317 | {
318 | QString prop("%1Activity");
319 | this->setProperty(prop.arg(itemId).toLatin1(), isActive);
320 | this->updateAll();
321 | }
322 |
323 | void DMenuBase::setItemChecked(const QString &itemId, bool checked)
324 | {
325 | QString prop("%1Checked");
326 | this->setProperty(prop.arg(itemId).toLatin1(), checked);
327 | this->updateAll();
328 | }
329 |
330 | void DMenuBase::setItemText(const QString &itemId, const QString &text)
331 | {
332 | QString prop("%1Text");
333 | this->setProperty(prop.arg(itemId).toLatin1(), text);
334 | this->updateAll();
335 | }
336 |
337 | const DMenuBase::ItemStyle DMenuBase::normalStyle()
338 | {
339 | return _normalStyle;
340 | }
341 |
342 | const DMenuBase::ItemStyle DMenuBase::hoverStyle()
343 | {
344 | return _hoverStyle;
345 | }
346 |
347 | const DMenuBase::ItemStyle DMenuBase::inactiveStyle()
348 | {
349 | return _inactiveStyle;
350 | }
351 |
352 | DMenuBase *DMenuBase::getRootMenu()
353 | {
354 | QObject *root = this;
355 | while (root) {
356 | if (root->parent()) {
357 | root = root->parent();
358 | } else {
359 | break;
360 | }
361 | }
362 |
363 | DMenuBase *result = qobject_cast(root);
364 | Q_ASSERT(result);
365 |
366 | return result;
367 | }
368 |
369 | // override methods
370 | bool DMenuBase::nativeEvent(const QByteArray &eventType, void *message, long *)
371 | {
372 | if (eventType=="xcb_generic_event_t") {
373 | xcb_generic_event_t *event = static_cast(message);
374 | const uint8_t responseType = event->response_type & ~0x80;
375 |
376 | xXIDeviceEvent *ev = reinterpret_cast(event);
377 | // qDebug() << ev->detail << Button1Mask << Button3Mask << Button2Mask;
378 | if (ev->detail !=0 && ev->detail != 1 && ev->detail != 2 && ev->detail != 3) {
379 | // drop all mouse events with button other than left button
380 | // or right button;
381 | return false;
382 | }
383 |
384 | if (isXIType(event, xiOpCode, XI_ButtonPress) || isXIType(event, xiOpCode, XI_TouchBegin)) {
385 | // qDebug() << "nativeEvent XI_ButtonPress" << fixed1616ToReal(ev->root_x) <<
386 | // fixed1616ToReal(ev->root_y);
387 | if (!this->menuUnderPoint(QPoint(fixed1616ToReal(ev->root_x),
388 | fixed1616ToReal(ev->root_y)))) {
389 | this->destroyAll();
390 | }
391 | } else if (isXIType(event, xiOpCode, XI_ButtonRelease)) {
392 | // qDebug() << "nativeEvent XI_ButtonRelease" << fixed1616ToReal(ev->root_x) <<
393 | // fixed1616ToReal(ev->root_y);
394 | if (this->menuUnderPoint(QPoint(fixed1616ToReal(ev->root_x),
395 | fixed1616ToReal(ev->root_y))) && _menuContent){
396 | _menuContent->doCurrentAction();
397 | }
398 | } else if (isXIType(event, xiOpCode, XI_Motion)) {
399 | // qDebug() << "nativeEvent XI_Motion" << fixed1616ToReal(ev->root_x) <<
400 | // fixed1616ToReal(ev->root_y);
401 | DMenuBase *menuUnderPoint = this->menuUnderPoint(
402 | QPoint(fixed1616ToReal(ev->root_x), fixed1616ToReal(ev->root_y)));
403 | if (menuUnderPoint) {
404 | menuUnderPoint->grabFocus();
405 | }
406 | }
407 | }
408 |
409 | return false;
410 | }
411 |
412 | void DMenuBase::queryXIExtension()
413 | {
414 | XQueryExtension((Display *)QX11Info::display(), "XInputExtension", &xiOpCode, &xiEventBase, &xiErrorBase);
415 | qDebug() << "xiOpCode: " << xiOpCode;
416 | }
417 |
418 | bool DMenuBase::isXIEvent(xcb_generic_event_t *event, int opCode)
419 | {
420 | qt_xcb_ge_event_t *e = (qt_xcb_ge_event_t *)event;
421 | return e->extension == opCode;
422 | }
423 |
424 | bool DMenuBase::isXIType(xcb_generic_event_t *event, int opCode, uint16_t type)
425 | {
426 | if (!isXIEvent(event, opCode))
427 | return false;
428 |
429 | xXIGenericDeviceEvent *xiEvent = reinterpret_cast(event);
430 | return xiEvent->evtype == type;
431 | }
432 |
433 | qreal DMenuBase::fixed1616ToReal(FP1616 val)
434 | {
435 | return (qreal(val >> 16)) + (val & 0xFFFF) / (qreal)0xFFFF;
436 | }
437 |
438 | // private methods
439 | void DMenuBase::updateAll()
440 | {
441 | DMenuBase *subMenu = this;
442 | while (subMenu) {
443 | subMenu->update();
444 | subMenu = subMenu->subMenu();
445 | }
446 | }
447 |
--------------------------------------------------------------------------------
/src/dmenubase.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #ifndef DMENUBASE_H
21 | #define DMENUBASE_H
22 |
23 | // this event type was added in libxcb 1.10,
24 | // but we support also older version
25 | #ifndef XCB_GE_GENERIC
26 | #define XCB_GE_GENERIC 35
27 | #endif
28 |
29 | #include
30 | #include
31 | #include
32 |
33 | #include
34 | #include
35 |
36 | // Starting from the xcb version 1.9.3 struct xcb_ge_event_t has changed:
37 | // - "pad0" became "extension"
38 | // - "pad1" and "pad" became "pad0"
39 | // New and old version of this struct share the following fields:
40 | typedef struct qt_xcb_ge_event_t {
41 | uint8_t response_type;
42 | uint8_t extension;
43 | uint16_t sequence;
44 | uint32_t length;
45 | uint16_t event_type;
46 | } qt_xcb_ge_event_t;
47 |
48 | class QColor;
49 | class QTimer;
50 | class QMargins;
51 | class QJsonArray;
52 | class QByteArray;
53 | class DMenuContent;
54 | class DMenuBase : public QWidget
55 | {
56 | Q_OBJECT
57 |
58 | public:
59 | explicit DMenuBase(QWidget *parent = 0);
60 |
61 | struct ItemStyle {
62 | QColor itemBackgroundColor;
63 | QColor itemTextColor;
64 | QColor itemShortcutColor;
65 | QString checkmarkIcon;
66 | QString subMenuIndicatorIcon;
67 | };
68 |
69 | Q_PROPERTY(int radius READ radius WRITE setRadius NOTIFY radiusChanged)
70 | Q_PROPERTY(QMargins shadowMargins READ shadowMargins WRITE setShadowMargins NOTIFY shadowMarginsChanged)
71 | Q_PROPERTY(QMargins menuContentMargins READ menuContentMargins WRITE setMenuContentMargins NOTIFY menuContentMarginsChanged)
72 | Q_PROPERTY(int itemLeftSpacing READ itemLeftSpacing WRITE setItemLeftSpacing NOTIFY itemLeftSpacingChanged)
73 | Q_PROPERTY(int itemCenterSpacing READ itemCenterSpacing WRITE setItemCenterSpacing NOTIFY itemCenterSpacingChanged)
74 | Q_PROPERTY(int itemRightSpacing READ itemRightSpacing WRITE setItemRightSpacing NOTIFY itemRightSpacingChanged)
75 |
76 | int radius();
77 | void setRadius(int);
78 | QMargins shadowMargins();
79 | void setShadowMargins(QMargins);
80 | QMargins menuContentMargins();
81 | void setMenuContentMargins(QMargins);
82 |
83 | int itemLeftSpacing();
84 | void setItemLeftSpacing(int);
85 | int itemCenterSpacing();
86 | void setItemCenterSpacing(int);
87 | int itemRightSpacing();
88 | void setItemRightSpacing(int);
89 |
90 | QSharedPointer menuContent();
91 | void setMenuContent(QSharedPointer content);
92 |
93 | DMenuBase *subMenu();
94 |
95 | void setContent(QJsonArray items);
96 | void destroyAll();
97 | void grabFocus();
98 | void releaseFocus();
99 | DMenuBase *menuUnderPoint(QPoint);
100 | DMenuBase *getRootMenu();
101 |
102 | void setItemActivity(const QString &itemId, bool isActive);
103 | void setItemChecked(const QString &itemId, bool checked);
104 | void setItemText(const QString &itemId, const QString &text);
105 |
106 | const ItemStyle normalStyle();
107 | const ItemStyle hoverStyle();
108 | const ItemStyle inactiveStyle();
109 |
110 | virtual void setPosition(int, int) = 0;
111 | virtual void showSubMenu(int, int, QJsonObject) = 0;
112 |
113 | signals:
114 | void radiusChanged(int radius);
115 | void shadowMarginsChanged(QMargins shadowWidth);
116 | void menuContentMarginsChanged(QMargins menuContentMargins);
117 | void itemBackgroundColorChanged(QColor itemBackgroundColor);
118 | void itemTextColorChanged(QColor itemTextColor);
119 | void itemShortcutColorChanged(QColor itemShortcutColor);
120 | void itemLeftSpacingChanged(int itemLeftSpacing);
121 | void itemCenterSpacingChanged(int itemCenterSpacing);
122 | void itemRightSpacingChanged(int itemRightSpacing);
123 |
124 | void itemClicked(QString id, bool checked);
125 |
126 | protected:
127 | DMenuBase *_subMenu;
128 | ItemStyle _normalStyle;
129 | ItemStyle _hoverStyle;
130 | ItemStyle _inactiveStyle;
131 |
132 | virtual bool nativeEvent(const QByteArray &, void *, long *);
133 |
134 | private slots:
135 | void grabFocusSlot();
136 |
137 | private:
138 | int xiErrorBase;
139 | int xiEventBase;
140 | int xiOpCode;
141 |
142 | int _radius;
143 | QMargins _shadowMargins;
144 | QMargins _menuContentMargins;
145 |
146 | int _itemLeftSpacing;
147 | int _itemCenterSpacing;
148 | int _itemRightSpacing;
149 |
150 | QSharedPointer _menuContent;
151 | QGraphicsDropShadowEffect *_dropShadow;
152 | QTimer *_grabFocusTimer;
153 |
154 | void queryXIExtension();
155 | bool isXIEvent(xcb_generic_event_t *event, int opCode);
156 | bool isXIType(xcb_generic_event_t *event, int opCode, uint16_t type);
157 | qreal fixed1616ToReal(FP1616 val);
158 |
159 | bool grabFocusInternal(int);
160 | void updateAll();
161 | };
162 |
163 | #endif // DMENUBASE_H
164 |
--------------------------------------------------------------------------------
/src/dmenucontent.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | #include "utils.h"
37 | #include "dmenucontent.h"
38 | #include "ddockmenu.h"
39 |
40 | #define MENU_ITEM_MAX_WIDTH 500
41 | #define SEPARATOR_HEIGHT 6
42 | #define MENU_ITEM_TOP_BOTTOM_PADDING 2
43 |
44 | static const int LeftRightPadding = 20;
45 | static const int TopBottomPadding = 4;
46 |
47 | DMenuContent::DMenuContent(DDockMenu *parent) :
48 | QWidget(parent),
49 | _currentIndex(-1)
50 | {
51 | this->setMouseTracking(true);
52 | }
53 |
54 | int DMenuContent::currentIndex()
55 | {
56 | return _currentIndex;
57 | }
58 |
59 | void DMenuContent::setCurrentIndex(int index)
60 | {
61 | if (index < 0 || _currentIndex == index) return;
62 |
63 | _currentIndex = index;
64 | this->update();
65 |
66 | if (index < 0 || index >= this->actions().count()) return;
67 |
68 | DDockMenu *parent = qobject_cast(this->parent());
69 | Q_ASSERT(parent);
70 |
71 | QAction *action = this->actions().at(index);
72 | QRect actionRect = this->getRectOfActionAtIndex(index);
73 | QPoint point = this->mapToGlobal(QPoint(this->width(), actionRect.y()));
74 | QString itemId = action->property("itemId").toString();
75 |
76 | QString prop("%1Active");
77 | QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1());
78 | bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool();
79 |
80 | QJsonObject subMenuJsonObj = active ?
81 | this->actions().at(index)->property("itemSubMenu").value()
82 | : QJsonObject();
83 | parent->showSubMenu(point.x(), point.y(), subMenuJsonObj);
84 | }
85 |
86 | int DMenuContent::contentWidth()
87 | {
88 | int result = 0;
89 |
90 | QFontMetrics metrics(font());
91 |
92 | foreach (QAction *action, this->actions()) {
93 | result = qMax(result, metrics.width(action->text()));
94 | }
95 |
96 | return qMin(MENU_ITEM_MAX_WIDTH, result + 10 + LeftRightPadding*2);
97 | }
98 |
99 | int DMenuContent::contentHeight()
100 | {
101 | int result = 0;
102 |
103 | QFontMetrics fm(font());
104 | foreach (QAction *action, this->actions()) {
105 | if (action->text().isEmpty()) {
106 | result += SEPARATOR_HEIGHT;
107 | } else {
108 | result += fm.height() + MENU_ITEM_TOP_BOTTOM_PADDING * 2;
109 | }
110 | }
111 |
112 | return (result + TopBottomPadding * 2);
113 | }
114 |
115 | void DMenuContent::doCurrentAction()
116 | {
117 | if (_currentIndex < 0 || _currentIndex >= this->actions().count()) return;
118 |
119 | DDockMenu *parent = qobject_cast(this->parent());
120 | Q_ASSERT(parent);
121 |
122 | QAction *currentAction = this->actions().at(_currentIndex);
123 | QString itemId = currentAction->property("itemId").toString();
124 | QString prop("%1Checked");
125 | QVariant checkedCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1());
126 | bool checked = checkedCache.isNull() ? currentAction->isChecked() : checkedCache.toBool();
127 | bool currentActionHasSubMenu = currentAction->property("itemSubMenu").value()["items"].toArray().count() != 0;
128 | prop = QString("%1Activity");
129 | QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1());
130 | bool active = activeCache.isNull() ? currentAction->isEnabled() : activeCache.toBool();
131 |
132 | if (!active || currentAction->text().isEmpty() || currentActionHasSubMenu) return;
133 |
134 | if (currentAction->isCheckable()) {
135 | if (checked) {
136 | this->doUnCheck(_currentIndex);
137 | } else {
138 | this->doCheck(_currentIndex);
139 | }
140 | } else {
141 | parent->releaseFocus();
142 |
143 | this->sendItemClickedSignal(currentAction->property("itemId").toString(), false);
144 | }
145 | qDebug() << "do action, destroy all";
146 | parent->destroyAll();
147 | }
148 |
149 | // override methods
150 | void DMenuContent::paintEvent(QPaintEvent *)
151 | {
152 | DDockMenu *parent = qobject_cast(this->parent());
153 |
154 | QPainter painter(this);
155 |
156 | for(int i = 0; i < this->actions().count(); i++) {
157 | QAction *action = this->actions().at(i);
158 | QRect actionRect = this->getRectOfActionAtIndex(i);
159 | QString itemId = action->property("itemId").toString();
160 |
161 | QString prop("%1Activity");
162 | QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1());
163 | bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool();
164 | ItemStyle itemStyle = active ? i == _currentIndex ? parent->hoverStyle : parent->normalStyle : parent->inactiveStyle;
165 |
166 | // indicates that this item is a separator
167 | if (action->text().isEmpty()) {
168 | int topLineX1 = actionRect.x() + 4;
169 | int topLineY1 = actionRect.y() + (actionRect.height() - 2) / 2;
170 | int topLineX2 = actionRect.x() + actionRect.width() - 4;
171 | int topLineY2 = actionRect.y() + (actionRect.height() - 2) / 2;
172 | int bottomLineX1 = topLineX1;
173 | int bottomLineY1 = topLineY1 + 1;
174 | int bottomLineX2 = topLineX2;
175 | int bottomLineY2 = topLineY1 + 1;
176 | painter.setPen(QPen(QColor::fromRgbF(0, 0, 0, 0.1)));
177 | painter.drawLine(topLineX1, topLineY1, topLineX2, topLineY2);
178 | painter.setPen(QPen(QColor::fromRgbF(1, 1, 1, 0.1)));
179 | painter.drawLine(bottomLineX1, bottomLineY1, bottomLineX2, bottomLineY2);
180 | } else {
181 | painter.fillRect(actionRect, QBrush(itemStyle.itemBackgroundColor));
182 | painter.setPen(QPen(itemStyle.itemTextColor));
183 |
184 | // draw text
185 | QString prop("%1Text");
186 | QVariant textCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1());
187 | QString text = textCache.isNull() ? action->text() : textCache.toString();
188 | QString elidedText = elideText(text, actionRect.width() - LeftRightPadding * 2);
189 |
190 | QTextOption option;
191 | option.setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
192 |
193 | QRect textRect(actionRect);
194 | textRect.adjust(LeftRightPadding, 0, -LeftRightPadding, 0);
195 | painter.drawText(textRect, elidedText, option);
196 | }
197 | }
198 |
199 | painter.end();
200 | }
201 |
202 | void DMenuContent::processCursorMove(const QPoint &p)
203 | {
204 | int index = itemIndexUnderEvent(p);
205 | setCurrentIndex(index);
206 | }
207 |
208 | void DMenuContent::processButtonClick(const QPoint &p)
209 | {
210 | DDockMenu *parent = qobject_cast(this->parent());
211 | if (parent) {
212 | DDockMenu *menu = parent->menuUnderPoint(p);
213 | qDebug() << "menu geometry is " << parent->geometry();
214 | if (menu) {
215 | doCurrentAction();
216 | } else {
217 | qDebug() << "no menu under mouse event: " << p.x() << p.y() << ", destroy menus.";
218 | parent->destroyAll();
219 | }
220 | }
221 | }
222 |
223 | // private methods
224 | QRect DMenuContent::getRectOfActionAtIndex(int index)
225 | {
226 | QFontMetrics fm(font());
227 |
228 | auto getItemHeight = [this, &fm](const int i) {
229 | QAction *action = this->actions().at(i);
230 | if (action->text().isEmpty()) {
231 | return SEPARATOR_HEIGHT;
232 | } else {
233 | return fm.height() + MENU_ITEM_TOP_BOTTOM_PADDING * 2;
234 | }
235 | };
236 |
237 | int previousHeight = TopBottomPadding;
238 | int itemHeight = getItemHeight(index);
239 |
240 | for (int i = 0; i < index; i++) {
241 | int height = getItemHeight(i);
242 | previousHeight += height;
243 | }
244 |
245 | return QRect(0, previousHeight, this->width(), itemHeight);
246 | }
247 |
248 | void DMenuContent::clearActions()
249 | {
250 | foreach (QAction *action, this->actions()) {
251 | this->removeAction(action);
252 | }
253 | }
254 |
255 | int DMenuContent::getNextItemsHasShortcut(int startPos, QString keyText) {
256 | if (keyText.isEmpty()) return -1;
257 |
258 | DDockMenu *parent = qobject_cast(this->parent());
259 | Q_ASSERT(parent);
260 |
261 | for (int i = qMax(startPos, 0); i < this->actions().count(); i++) {
262 | QString itemId(this->actions().at(i)->property("itemId").toString());
263 | QAction *action = this->actions().at(i);
264 |
265 | QString prop("%1Active");
266 | QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1());
267 | bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool();
268 |
269 | // a trick here, using currentIndex as the cursor.
270 | if (active && keyText == this->actions().at(i)->property("itemNavKey").toString().toLower()){
271 | return i;
272 | }
273 | }
274 |
275 | // we do the check another time to support wrapping.
276 | for (int i = 0; i < this->actions().count(); i++) {
277 | QString itemId(this->actions().at(i)->property("itemId").toString());
278 | QAction *action = this->actions().at(i);
279 |
280 | QString prop("%1Active");
281 | QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1());
282 | bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool();
283 |
284 | if (active && keyText == this->actions().at(i)->property("itemNavKey").toString().toLower()) {
285 | return i;
286 | }
287 | }
288 | return -1;
289 | }
290 |
291 | void DMenuContent::selectPrevious()
292 | {
293 | DDockMenu *parent = qobject_cast(this->parent());
294 | Q_ASSERT(parent);
295 |
296 | for (int i = currentIndex() - 1; i >= 0; i--) {
297 | QAction * action = actions().at(i);
298 |
299 | QString itemId(action->property("itemId").toString());
300 |
301 | QString prop("%1Active");
302 | QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1());
303 | bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool();
304 |
305 | if (active && !action->text().isEmpty()) {
306 | setCurrentIndex(i);
307 | break;
308 | }
309 | }
310 | }
311 |
312 | void DMenuContent::selectNext()
313 | {
314 | DDockMenu *parent = qobject_cast(this->parent());
315 | Q_ASSERT(parent);
316 |
317 | for (int i = currentIndex() + 1; i < actions().count(); i++) {
318 | QAction * action = actions().at(i);
319 |
320 | QString itemId(action->property("itemId").toString());
321 |
322 | QString prop("%1Active");
323 | QVariant activeCache = parent->getRootMenu()->property(prop.arg(itemId).toLatin1());
324 | bool active = activeCache.isNull() ? action->isEnabled() : activeCache.toBool();
325 |
326 | if (active && !action->text().isEmpty()) {
327 | setCurrentIndex(i);
328 | break;
329 | }
330 | }
331 | }
332 |
333 | void DMenuContent::doCheck(int index) {
334 |
335 | DDockMenu *parent = qobject_cast(this->parent());
336 | Q_ASSERT(parent);
337 |
338 | QAction *action = this->actions().at(index);
339 | QString itemId = action->property("itemId").toString();
340 | parent->getRootMenu()->setItemChecked(itemId, true);
341 | this->sendItemClickedSignal(itemId, true);
342 |
343 | if (Utils::menuItemCheckableFromId(itemId)) {
344 | QStringList components = itemId.split(':');
345 | QString group = components.at(0);
346 |
347 | foreach (QAction *act, this->actions()) {
348 | QString _itemId = act->property("itemId").toString();
349 |
350 | if (act != action && Utils::menuItemCheckableFromId(_itemId)) {
351 | QStringList _components = _itemId.split(':');
352 | QString _group = _components.at(0);
353 | QString _type = _components.at(1);
354 |
355 | if (_type == "radio" && _group == group) {
356 | parent->getRootMenu()->setItemChecked(_itemId, false);
357 | }
358 | }
359 | }
360 | }
361 |
362 | this->update();
363 | }
364 |
365 | void DMenuContent::doUnCheck(int index)
366 | {
367 | DDockMenu *parent = qobject_cast(this->parent());
368 | Q_ASSERT(parent);
369 |
370 | QAction *action = this->actions().at(index);
371 | QString itemId = action->property("itemId").toString();
372 |
373 | if (Utils::menuItemCheckableFromId(itemId)) {
374 | QStringList components = itemId.split(':');
375 | QString group = components.at(0);
376 | QString type = components.at(1);
377 |
378 | if (type == "radio") {
379 | bool hasNoCheck = true;
380 |
381 | foreach (QAction *act, this->actions()) {
382 | QString _itemId = act->property("itemId").toString();
383 |
384 | if (Utils::menuItemCheckableFromId(_itemId) && _itemId != itemId) {
385 | QStringList components = _itemId.split(':');
386 | QString _group = components.at(0);
387 | QString _type = components.at(1);
388 |
389 | if (group == _group && _type == "radio") {
390 | QString prop("%1Checked");
391 | QVariant checkedCache = parent->getRootMenu()->property(prop.arg(_itemId).toLatin1());
392 | bool checked = checkedCache.isNull() ? act->isChecked() : checkedCache.toBool();
393 |
394 | hasNoCheck = hasNoCheck && !checked;
395 | }
396 | }
397 | }
398 |
399 | if (!hasNoCheck) {
400 | parent->getRootMenu()->setItemChecked(itemId, false);
401 | this->sendItemClickedSignal(action->property("itemId").toString(), false);
402 | } else {
403 | parent->getRootMenu()->setItemChecked(itemId, true);
404 | this->sendItemClickedSignal(action->property("itemId").toString(), true);
405 | }
406 | } else {
407 | parent->getRootMenu()->setItemChecked(itemId, false);
408 | this->sendItemClickedSignal(action->property("itemId").toString(), false);
409 | }
410 | } else {
411 | parent->getRootMenu()->setItemChecked(itemId, false);
412 | this->sendItemClickedSignal(action->property("itemId").toString(), false);
413 | }
414 |
415 | this->update();
416 | }
417 |
418 | void DMenuContent::sendItemClickedSignal(QString id, bool checked)
419 | {
420 | DDockMenu *root = qobject_cast(this->parent());
421 | Q_ASSERT(root);
422 | while (root) {
423 | if (!root->parent()) {
424 | qDebug() << Q_FUNC_INFO << "itemClicked";
425 |
426 | // NOTE(sbw): ensure mouse/keyboard released before send itemClicked,
427 | root->releaseMouse();
428 | root->releaseFocus();
429 | root->releaseKeyboard();
430 | root->itemClicked(id, checked);
431 | break;
432 | } else {
433 | root = qobject_cast(root->parent());
434 | Q_ASSERT(root);
435 | }
436 | }
437 | }
438 |
439 | int DMenuContent::itemIndexUnderEvent(QPoint point) const
440 | {
441 | DDockMenu *parent = qobject_cast(this->parent());
442 | Q_ASSERT(parent);
443 |
444 | const QPoint lPoint = mapFromGlobal(point);
445 |
446 | DDockMenu *menuUnderCursor = parent->menuUnderPoint(point);
447 | if (menuUnderCursor == parent) {
448 | int previousHeight = (y() + TopBottomPadding);
449 |
450 | QFontMetrics fm(font());
451 | for (int i = 0; i < this->actions().count(); i++) {
452 | QAction *action = this->actions().at(i);
453 |
454 | int itemHeight = action->text().isEmpty() ? SEPARATOR_HEIGHT
455 | : (fm.height() + MENU_ITEM_TOP_BOTTOM_PADDING * 2);
456 |
457 | QRect itemRect(x(), previousHeight, width(), itemHeight);
458 |
459 | if (itemRect.contains(lPoint)) {
460 | return i;
461 | } else {
462 | previousHeight += itemHeight;
463 | }
464 | }
465 | }
466 |
467 | return -1;
468 | }
469 |
470 | QString DMenuContent::elideText(QString source, int maxWidth) const
471 | {
472 | QFontMetrics metrics(font());
473 |
474 | if (metrics.width(source) < maxWidth) {
475 | return source;
476 | } else {
477 | return metrics.elidedText(source, Qt::ElideRight, maxWidth);
478 | }
479 | }
480 |
--------------------------------------------------------------------------------
/src/dmenucontent.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #ifndef DMENUCONTENT_H
21 | #define DMENUCONTENT_H
22 |
23 | #include
24 | #include
25 |
26 | class QRect;
27 | class DDockMenu;
28 | class DMenuContent : public QWidget
29 | {
30 | Q_OBJECT
31 | public:
32 | explicit DMenuContent(DDockMenu *parent = 0);
33 |
34 | int contentWidth();
35 | int contentHeight();
36 |
37 | int currentIndex();
38 | void setCurrentIndex(int);
39 |
40 | void clearActions();
41 | void doCurrentAction();
42 |
43 | protected:
44 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
45 |
46 | private:
47 | friend class DDockMenu;
48 | void processCursorMove(const QPoint &p);
49 | void processButtonClick(const QPoint &p);
50 |
51 | private:
52 | int _iconWidth;
53 | int _shortcutWidth;
54 | int _subMenuIndicatorWidth;
55 |
56 | int _currentIndex;
57 | QRect getRectOfActionAtIndex(int);
58 | int getNextItemsHasShortcut(int, QString);
59 | void selectPrevious();
60 | void selectNext();
61 | void doCheck(int);
62 | void doUnCheck(int);
63 | void sendItemClickedSignal(QString, bool);
64 | int itemIndexUnderEvent(QPoint point) const;
65 | QString elideText(QString source, int maxWidth) const;
66 | };
67 |
68 | #endif // DMENUCONTENT_H
69 |
--------------------------------------------------------------------------------
/src/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #include
21 |
22 | #include
23 | #include
24 |
25 | #include "dbus_manager_adaptor.h"
26 | #include "manager_object.h"
27 | #include "dmenuapplication.h"
28 |
29 | #define MENU_SERVICE_NAME "com.deepin.menu"
30 | #define MENU_SERVICE_PATH "/com/deepin/menu"
31 |
32 | DCORE_USE_NAMESPACE
33 | DWIDGET_USE_NAMESPACE
34 |
35 | int main(int argc, char *argv[])
36 | {
37 | DApplication::loadDXcbPlugin();
38 | DMenuApplication app(argc, argv);
39 | app.setOrganizationName("deepin");
40 | app.setApplicationName("deepin-menu");
41 | app.setApplicationVersion("2.0");
42 |
43 | #if DTK_VERSION >= DTK_VERSION_CHECK(2, 0, 9, 0)
44 | app.setOOMScoreAdj(500);
45 | #endif
46 |
47 | DLogManager::registerConsoleAppender();
48 | DLogManager::registerFileAppender();
49 |
50 | ManagerObject managerObject;
51 | ManagerAdaptor manager(&managerObject);
52 |
53 | QDBusConnection connection = QDBusConnection::sessionBus();
54 | connection.interface()->registerService(MENU_SERVICE_NAME,
55 | QDBusConnectionInterface::ReplaceExistingService,
56 | QDBusConnectionInterface::AllowReplacement);
57 | connection.registerObject(MENU_SERVICE_PATH, &managerObject);
58 | DMenuApplication::connect(connection.interface(), SIGNAL(serviceUnregistered(QString)),
59 | &app, SLOT(quitApplication(QString)));
60 |
61 | return app.exec();
62 | }
63 |
--------------------------------------------------------------------------------
/src/manager_object.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "dbus_menu_adaptor.h"
25 | #include "manager_object.h"
26 |
27 | ManagerObject::ManagerObject(QObject *parent) :
28 | QObject(parent)
29 | {
30 | menuObjectPath = "";
31 | menuObject = nullptr;
32 | menuAdaptor = nullptr;
33 | }
34 |
35 | QDBusObjectPath ManagerObject::RegisterMenu()
36 | {
37 | UnregisterMenu();
38 |
39 | if (!menuAdaptor.isNull())
40 | menuAdaptor->deleteLater();
41 |
42 | menuRegisterGuard.lock();
43 |
44 | QString uuid = QUuid::createUuid().toString();
45 | uuid = uuid.replace("{", "");
46 | uuid = uuid.replace("}", "");
47 | uuid = uuid.replace("-", "_");
48 | menuObjectPath = "/com/deepin/menu/" + uuid;
49 |
50 | menuObject = new MenuObject;
51 | menuAdaptor = new MenuAdaptor(menuObject);
52 |
53 | connect(menuObject.data(), &MenuObject::destroyed, this, &ManagerObject::menuObjectDestroiedSlot, Qt::QueuedConnection);
54 |
55 | QDBusConnection connection = QDBusConnection::sessionBus();
56 | connection.registerObject(menuObjectPath, menuObject);
57 |
58 | QDBusObjectPath result(menuObjectPath);
59 |
60 | menuRegisterGuard.unlock();
61 |
62 | return result;
63 | }
64 |
65 | void ManagerObject::UnregisterMenu()
66 | {
67 | UnregisterMenu(menuObjectPath);
68 | }
69 |
70 | void ManagerObject::UnregisterMenu(const QString &)
71 | {
72 | if (menuObject.isNull() && menuObjectPath.isEmpty())
73 | return;
74 |
75 | menuRegisterGuard.lock();
76 |
77 | if (!menuObject.isNull() || !menuObjectPath.isEmpty())
78 | {
79 | if (!menuObject.isNull())
80 | delete menuObject;
81 |
82 | menuObject.clear();
83 | menuObjectPath.clear();
84 | }
85 |
86 | menuRegisterGuard.unlock();
87 | }
88 |
89 | // private slots
90 | void ManagerObject::menuObjectDestroiedSlot()
91 | {
92 | if (!menuObject.isNull())
93 | menuObject->deleteLater();
94 |
95 | QDBusConnection connection = QDBusConnection::sessionBus();
96 | connection.unregisterObject(menuObjectPath);
97 | }
98 |
--------------------------------------------------------------------------------
/src/manager_object.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #ifndef MANAGER_OBJECT_H
21 | #define MANAGER_OBJECT_H
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include
29 | #include
30 |
31 | class ManagerObject : public QObject
32 | {
33 | Q_OBJECT
34 | public:
35 | explicit ManagerObject(QObject *parent = 0);
36 |
37 | signals:
38 |
39 | public slots:
40 | QDBusObjectPath RegisterMenu();
41 | void UnregisterMenu();
42 | void UnregisterMenu(const QString &menuObjectPath);
43 |
44 | private:
45 | QMutex menuRegisterGuard;
46 | QPointer menuObject;
47 | QPointer menuAdaptor;
48 | QString menuObjectPath;
49 |
50 | private slots:
51 | void menuObjectDestroiedSlot();
52 | };
53 |
54 | #endif // MANAGER_OBJECT_H
55 |
--------------------------------------------------------------------------------
/src/menu_object.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 |
30 | #include "menu_object.h"
31 | #include "ddesktopmenu.h"
32 | #include "ddockmenu.h"
33 |
34 | static DArrowRectangle::ArrowDirection DirectionFromString(QString direction) {
35 | if (direction == "top") {
36 | return DArrowRectangle::ArrowTop;
37 | } else if (direction == "left") {
38 | return DArrowRectangle::ArrowLeft;
39 | } else if (direction == "right") {
40 | return DArrowRectangle::ArrowRight;
41 | }
42 |
43 | return DArrowRectangle::ArrowBottom;
44 | }
45 |
46 | MenuObject::MenuObject():
47 | QObject(),
48 | m_dockMenu(nullptr),
49 | m_desktopMenu(nullptr)
50 | {
51 |
52 | }
53 |
54 | MenuObject::~MenuObject()
55 | {
56 | if (!m_dockMenu.isNull()) {
57 | delete m_dockMenu;
58 | }
59 |
60 | if (!m_desktopMenu.isNull()) {
61 | delete m_desktopMenu;
62 | }
63 | }
64 |
65 | void MenuObject::SetItemActivity(const QString &itemId, bool isActive)
66 | {
67 | if (!m_dockMenu.isNull()) m_dockMenu->setItemActivity(itemId, isActive);
68 | if (!m_desktopMenu.isNull()) m_desktopMenu->setItemActivity(itemId, isActive);
69 | }
70 |
71 | void MenuObject::SetItemChecked(const QString &itemId, bool checked)
72 | {
73 | if (!m_dockMenu.isNull()) m_dockMenu->setItemChecked(itemId, checked);
74 | if (!m_desktopMenu.isNull()) m_desktopMenu->setItemChecked(itemId, checked);
75 | }
76 |
77 | void MenuObject::SetItemText(const QString &itemId, const QString &text)
78 | {
79 | if (!m_dockMenu.isNull()) m_dockMenu->setItemText(itemId, text);
80 | if (!m_desktopMenu.isNull()) m_desktopMenu->setItemText(itemId, text);
81 | }
82 |
83 | void MenuObject::ShowMenu(const QString &menuJsonContent)
84 | {
85 | QByteArray bytes;
86 | bytes.append(menuJsonContent);
87 | QJsonDocument menuDocument = QJsonDocument::fromJson(bytes);
88 | QJsonObject jsonObj = menuDocument.object();
89 |
90 | int x = jsonObj["x"].toDouble();
91 | int y = jsonObj["y"].toDouble();
92 | QString direction = jsonObj["direction"].toString();
93 |
94 | if(jsonObj["isDockMenu"].toBool()) {
95 | m_dockMenu = new DDockMenu;
96 | connect(m_dockMenu, &DDockMenu::destroyed, this, &MenuObject::menuDismissedSlot, Qt::QueuedConnection);
97 | connect(m_dockMenu, &DDockMenu::itemClicked, this, &MenuObject::ItemInvoked);
98 | } else {
99 | m_desktopMenu = new DDesktopMenu;
100 | connect(m_desktopMenu, &DDesktopMenu::aboutToHide, this, &MenuObject::menuDismissedSlot, Qt::QueuedConnection);
101 | connect(m_desktopMenu, &DDesktopMenu::itemClicked, this, &MenuObject::ItemInvoked);
102 | }
103 |
104 | bytes.clear();
105 | bytes.append(jsonObj["menuJsonContent"].toString());
106 | QJsonDocument menuContent = QJsonDocument::fromJson(bytes);
107 | QJsonObject menuContentObj = menuContent.object();
108 |
109 | if (!m_dockMenu.isNull()) {
110 | m_dockMenu->setArrowDirection(DirectionFromString(direction));
111 | m_dockMenu->setItems(menuContentObj["items"].toArray());
112 | m_dockMenu->show(x, y);
113 | } else if (!m_desktopMenu.isNull()) {
114 | m_desktopMenu->setItems(menuContentObj["items"].toArray());
115 |
116 | // 在Qt 5.10.x上, 菜单 show 之前没有被polish, 导致 dstyle 中无法将菜单设置为"圆角+模糊"样式
117 | if (m_desktopMenu->style() && !m_desktopMenu->testAttribute(Qt::WA_WState_Polished)) {
118 | m_desktopMenu->style()->polish(m_desktopMenu);
119 | }
120 |
121 | bool isScaled = true;
122 | if (!jsonObj["isScaled"].isNull()) {
123 | isScaled = jsonObj["isScaled"].toBool();
124 | }
125 |
126 | m_desktopMenu->showMenu(QPoint(x, y), isScaled);
127 | }
128 | }
129 |
130 | void MenuObject::menuDismissedSlot()
131 | {
132 | emit MenuUnregistered();
133 |
134 | if (!m_dockMenu.isNull()) {
135 | m_dockMenu->deleteLater();
136 | m_dockMenu = nullptr;
137 | }
138 |
139 | if (!m_desktopMenu.isNull()) {
140 | m_desktopMenu->deleteLater();
141 | m_desktopMenu = nullptr;
142 | }
143 |
144 | deleteLater();
145 | }
146 |
--------------------------------------------------------------------------------
/src/menu_object.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #ifndef MENU_OBJECT_H
21 | #define MENU_OBJECT_H
22 |
23 | #include
24 | #include
25 |
26 | class DDockMenu;
27 | class DDesktopMenu;
28 | class MenuObject : public QObject
29 | {
30 | Q_OBJECT
31 | public:
32 | MenuObject();
33 | ~MenuObject();
34 |
35 | signals:
36 | void ItemInvoked(const QString &itemId, bool checked);
37 | void MenuUnregistered();
38 |
39 | public slots:
40 | void SetItemActivity(const QString &itemId, bool isActive);
41 | void SetItemChecked(const QString &itemId, bool checked);
42 | void SetItemText(const QString &itemId, const QString &text);
43 |
44 | void ShowMenu(const QString &menuJsonContent);
45 |
46 | private slots:
47 | void menuDismissedSlot();
48 |
49 | private:
50 | QPointer m_dockMenu;
51 | QPointer m_desktopMenu;
52 | };
53 |
54 | #endif // MENU_OBJECT_H
55 |
--------------------------------------------------------------------------------
/src/utils.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #include "utils.h"
21 |
22 | namespace Utils {
23 |
24 | bool menuItemCheckableFromId(QString id)
25 | {
26 | return id.split(':').count() == 3;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
3 | *
4 | * Author: Hualet Wang .
18 | */
19 |
20 | #ifndef UTILS_H
21 | #define UTILS_H
22 |
23 | #include
24 | #include
25 |
26 | #define DISPLAY_SERVICE "com.deepin.daemon.Display"
27 | #define DISPLAY_PATH "/com/deepin/daemon/Display"
28 | #define PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
29 | #define DISPLAY_INTERFACE "com.deepin.daemon.Display"
30 | #define MONITOR_INTERFACE "com.deepin.daemon.Display.Monitor"
31 |
32 | class QString;
33 |
34 | namespace Utils {
35 |
36 | bool menuItemCheckableFromId(QString id);
37 |
38 | }
39 |
40 | #endif // UTILS_H
41 |
--------------------------------------------------------------------------------