ukui-sni/ 0000775 0001750 0001750 00000000000 15160527101 011242 5 ustar feng feng ukui-sni/dbus/ 0000775 0001750 0001750 00000000000 15153755017 012212 5 ustar feng feng ukui-sni/dbus/org.freedesktop.DBus.Properties.xml 0000664 0001750 0001750 00000002210 15153755017 021017 0 ustar feng feng
ukui-sni/dbus/org.kde.StatusNotifierWatcher.xml 0000664 0001750 0001750 00000003132 15153755017 020564 0 ustar feng feng
ukui-sni/dbus/org.kde.StatusNotifierItem.xml 0000664 0001750 0001750 00000006504 15153755017 020073 0 ustar feng feng
ukui-sni/LICENSE 0000664 0001750 0001750 00000105755 15153755017 012277 0 ustar feng feng GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
ukui-sni/README.md 0000664 0001750 0001750 00000000643 15153755017 012537 0 ustar feng feng # ukui-sni
#### 介绍
ukui-sni是ukui桌面环境中系统托盘服务相关功能的集合。
托盘功能基于[ukui4托盘协议](https://yayqg9ul2g.feishu.cn/docx/Q1Ptd8S0VoKryFxUQFxcbRS4n4g)。
#### status-notifier-host
用于实现可视化托盘区域功能的接口。
#### status-notifier-watcher
sni协议中的Watcher服务实现。
#### ukui-system-tray
可视化托盘插件(会显示在任务栏上) ukui-sni/man/ 0000775 0001750 0001750 00000000000 15153755611 012030 5 ustar feng feng ukui-sni/man/xembed-sni-proxy.1 0000664 0001750 0001750 00000000461 15153755611 015325 0 ustar feng feng .TH XEMBED-SNI-PROXY 1
.SH NAME
xembed-sni-proxy \- XEmbed to Status Notifier Item proxy
.SH SYNOPSIS
.B xembed-sni-proxy
.SH DESCRIPTION
.B xembed-sni-proxy
converts legacy XEmbed system tray icons to the Status Notifier Item protocol.
.SH SEE ALSO
.BR ukui-sni-watcher (1)
.SH AUTHOR
KylinSoft Co., Ltd. ukui-sni/man/ukui-sni-watcher.1 0000664 0001750 0001750 00000000503 15153755611 015307 0 ustar feng feng .TH UKUI-SNI-WATCHER 1
.SH NAME
ukui-sni-watcher \- Status Notifier Item watcher
.SH SYNOPSIS
.B ukui-sni-watcher
.SH DESCRIPTION
.B ukui-sni-watcher
is a backend service that implements the Status Notifier Item protocol for the UKUI desktop environment.
.SH SEE ALSO
.BR xembed-sni-proxy (1)
.SH AUTHOR
KylinSoft Co., Ltd. ukui-sni/ukui-system-tray/ 0000775 0001750 0001750 00000000000 15153755611 014531 5 ustar feng feng ukui-sni/ukui-system-tray/translations/ 0000775 0001750 0001750 00000000000 15153755611 017252 5 ustar feng feng ukui-sni/ukui-system-tray/translations/ukui-system-tray_zh_CN.ts 0000664 0001750 0001750 00000001026 15153755611 024156 0 ustar feng feng
TrayViewFolding display icon折叠显示图标Expand hidden icon展开隐藏图标
ukui-sni/ukui-system-tray/widget/ 0000775 0001750 0001750 00000000000 15153755017 016014 5 ustar feng feng ukui-sni/ukui-system-tray/widget/ui/ 0000775 0001750 0001750 00000000000 15153755611 016431 5 ustar feng feng ukui-sni/ukui-system-tray/widget/ui/ControlPanel.qml 0000664 0001750 0001750 00000007436 15153755611 021556 0 ustar feng feng import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQml.Models 2.15
import org.ukui.systemTray 1.0
import org.ukui.quick.items 1.0 as UkuiItems
ListView {
id: controlPanelView
height: dropArea.isHorizontal ? dropArea.scaleFactor * 40 : count * dropArea.scaleFactor * 26 + (count - 1) * spacing;
width: dropArea.isHorizontal ? count * dropArea.scaleFactor * 26 + (count - 1) * spacing : dropArea.scaleFactor * 40
orientation: dropArea.isHorizontal ? ListView.Horizontal : ListView.Vertical
layoutDirection: ListView.RightToLeft
verticalLayoutDirection: ListView.Qt.BottomToTop
spacing: 0
interactive: false
model: DelegateModel {
id: panelModel
model: ControlPanelModel
delegate: MouseArea {
width: dropArea.isHorizontal ? dropArea.scaleFactor * 26 : dropArea.scaleFactor * 40
height: dropArea.isHorizontal ? dropArea.scaleFactor * 40 : dropArea.scaleFactor * 26
acceptedButtons: Qt.LeftButton | Qt.RightButton
hoverEnabled: true
Accessible.role: Accessible.Button
Accessible.description: "This is a ukui-system-tray button of ukui-sni"
Accessible.name: model.Id === undefined ? "" : "ukui-system-tray_" + model.Id
Component.onCompleted: {
Qt.callLater(()=>{
Accessible.name = Qt.binding(function () {
return model.Id === undefined ? "" : "ukui-system-tray_" + model.Id;
});
});
}
UkuiItems.Icon {
id: icon
anchors.centerIn: parent
width: Math.round(dropArea.scaleFactor * (dropArea.onTopBar ? 20 : 16))
height: Math.round(dropArea.scaleFactor * (dropArea.onTopBar ? 20 : 16))
mode: UkuiItems.Icon.AutoHighlight
source: model.Icon
Component.onCompleted: {
Qt.callLater(()=>{
source = Qt.binding(function () {return model.Icon});
});
}
}
UkuiItems.Tooltip {
id: tooltip
anchors.fill: parent
mainText: model.ToolTipTitle === undefined ? "" : model.ToolTipTitle.length === 0 ? model.Title : model.ToolTipTitle
posFollowCursor: false
location: {
switch(dropArea.panelPos) {
case UkuiItems.Types.Bottom:
return UkuiItems.Dialog.BottomEdge;
case UkuiItems.Types.Left:
return UkuiItems.Dialog.LeftEdge;
case UkuiItems.Types.Top:
return UkuiItems.Dialog.TopEdge;
case UkuiItems.Types.Right:
return UkuiItems.Dialog.RightEdge;
}
}
margin: dropArea.isHorizontal ? (dropArea.height - control.height)/2 + 8 : (dropArea.width - control.width)/2 + 8
Component.onCompleted: {
Qt.callLater(()=>{
mainText = Qt.binding(function () {
return model.ToolTipTitle === undefined ? "" : model.ToolTipTitle.length === 0 ? model.Title : model.ToolTipTitle;
});
});
}
}
onClicked: {
if (mouse.button === Qt.LeftButton) {
panelModel.model.activate(index);
}
if (mouse.button === Qt.RightButton) {
panelModel.model.showContextMenu(panelModel.modelIndex(index), showDropArea);
dropArea.callMenu = true;
}
}
}
}
}
ukui-sni/ukui-system-tray/widget/ui/TrayView.qml 0000664 0001750 0001750 00000060752 15153755611 020730 0 ustar feng feng import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQml.Models 2.15
import QtQuick.Layouts 1.15
import org.ukui.systemTray 1.0
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.quick.platform 1.0 as Platform
DropArea {
property real scaleFactor
property real itemWidth
property real itemHeight
property real itemLong
property real itemShort
property real controlPanelWidth: isHorizontal ? controlPanelLength : itemLong
property real controlPanelHeight: isHorizontal ? itemLong : controlPanelLength
property int controlPanelLength: scaleFactor * getControlPanelLength()
property bool isHorizontal: true
property int panelPos
property int dragType
property bool inserted: false
property int targetIndex
property int indexInFold
property bool isOverLength: false
property bool callMenu: false
property int showCount: 11
property int maxLength: dropArea.isHorizontal
? parent.parent.Layout.maximumWidth
: parent.parent.Layout.maximumHeight
height: isHorizontal ? parent.height : flowArea.height
width: isHorizontal ? flowArea.width : parent.width
MouseArea {
z: 1
anchors.fill: parent
acceptedButtons: {
let button = Qt.NoButton;
if (FunctionControl.disableMouseLeftButton) {
button |= Qt.LeftButton
}
if (FunctionControl.disableMouseRightButton) {
button |= Qt.RightButton
}
return button;
}
enabled: FunctionControl.disableMouseLeftButton | FunctionControl.disableMouseRightButton
}
onItemShortChanged: {
trayview.viewWidth = trayview.calculateLength();
}
onControlPanelLengthChanged: {
trayview.viewWidth = trayview.calculateLength();
}
onPanelPosChanged: {
foldWindow.hide();
trayview.isFold = false;
}
onMaxLengthChanged: {
getShowCount();
}
GroupModel {
id: showModel
modelType: ItemGroupModel.Show
showCount: dropArea.showCount
}
GroupModel {
id: foldModel
modelType: ItemGroupModel.Fold
showCount: dropArea.showCount
}
function getShowCount() {
dropArea.showCount = maxLength / (dropArea.itemShort + trayview.viewSpacing) - 2;
}
function getControlPanelLength() {
switch(ControlPanelModel.rowCount) {
case 0:
return 0;
case 1:
return 32;
case 2:
return 58;
case 3:
return 84;
default:
return 0;
}
}
Item {id: dragItem}
Flow {
id: flowArea
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
flow: dropArea.isHorizontal ? GridLayout.LeftToRight : GridLayout.TopToBottom
spacing: trayview.viewSpacing
DropArea {
width: foldItem.visible ? dropArea.itemWidth : 0
height: foldItem.visible ? dropArea.itemHeight : 0
onEntered: {
}
onDropped: {
if (drag.source.rootId !== dropArea) return;
if (dragType === 1) {
if (trayModel.count > dropArea.showCount) return;
ItemModel.setOrderInGroup(foldModel, foldModel.index(foldBase.sourceIndex,0), 0)
ItemModel.setSeparateIndex(showModel.currentSeparateIndex + 1);
}
if (dragType === 0) {
ItemModel.setOrderInGroup(showModel, showModel.index(trayview.sourceIndex, 0), trayModel.items.count - 1);
ItemModel.setSeparateIndex(showModel.currentSeparateIndex - 1);
dropArea.panelActive = false;
}
}
UkuiItems.DtThemeBackground {
id: foldItem
visible: !foldBase.isEmpty
clip: true
useStyleTransparency: false
anchors.fill: parent
backgroundColor: foldControl.containsPress ? Platform.GlobalTheme.kComponentAlphaClick
: foldControl.containsMouse ? Platform.GlobalTheme.kComponentAlphaHover
: Platform.GlobalTheme.kContainGeneralAlphaNormal
radius: dropArea.onTopBar ? 0 : Platform.GlobalTheme.kRadiusNormal
TrayIcon {
id: foldControl
Accessible.role: Accessible.Button
Accessible.description: "This is a foldControl button on ukui-system-tray of ukui-sni"
Accessible.name: "foldControl-button"
width: dropArea.itemWidth
height: dropArea.itemHeight
appIcon: showModel.foldIcon()
iconRotation: appIconRotation()
hoverEnabled: true
enabled: foldItem.visible
acceptedButtons: Qt.LeftButton | Qt.RightButton
UkuiItems.Tooltip {
anchors.fill: parent
mainText: trayview.isFold ? qsTr("Folding display icon") : qsTr("Expand hidden icon")
posFollowCursor: false
location: {
switch(dropArea.panelPos) {
case UkuiItems.Types.Bottom:
return UkuiItems.Dialog.BottomEdge;
case UkuiItems.Types.Left:
return UkuiItems.Dialog.LeftEdge;
case UkuiItems.Types.Top:
return UkuiItems.Dialog.TopEdge;
case UkuiItems.Types.Right:
return UkuiItems.Dialog.RightEdge;
}
}
margin: dropArea.isHorizontal ? (dropArea.height - foldControl.height)/2 + 8 : (dropArea.width - foldControl.width)/2 + 8
}
onClicked: {
if (mouse.button === Qt.LeftButton) {
foldWindowReply();
}
}
function appIconRotation() {
if (dropArea.panelPos === UkuiItems.Types.Left) {
return trayview.isFold ? 180 : 0;
} else if (dropArea.panelPos === UkuiItems.Types.Top) {
return trayview.isFold ? 270 : 90;
} else if (dropArea.panelPos === UkuiItems.Types.Right) {
return trayview.isFold ? 0 : 180;
} else if (dropArea.panelPos === UkuiItems.Types.Bottom) {
return trayview.isFold ? 90 : 270;
}
return 0;
}
function foldWindowReply() {
if (trayview.isFold) {
foldWindow.hide();
trayview.isFold = false;
} else {
if (!foldBase.isEmpty) {
updateFoldWindowPosition();
foldWindow.show();
}
trayview.isFold = true;
}
}
function updateFoldWindowPosition() {
if (dropArea.panelPos === UkuiItems.Types.Left) {
foldWindow.slideWindow.fromEdge = Platform.WindowProxy.LeftEdge
foldWindow.location = UkuiItems.Types.LeftEdge
} else if (dropArea.panelPos === UkuiItems.Types.Top) {
foldWindow.slideWindow.fromEdge = Platform.WindowProxy.TopEdge
foldWindow.location = UkuiItems.Types.TopEdge
} else if (dropArea.panelPos === UkuiItems.Types.Right) {
foldWindow.slideWindow.fromEdge = Platform.WindowProxy.RightEdge
foldWindow.location = UkuiItems.Types.RightEdge
} else if (dropArea.panelPos === UkuiItems.Types.Bottom) {
foldWindow.slideWindow.fromEdge = Platform.WindowProxy.BottomEdge
foldWindow.location = UkuiItems.Types.BottomEdge
}
foldWindow.margin = dropArea.isHorizontal ? (dropArea.height - foldItem.height)/2 + 8 : (dropArea.width - foldItem.width)/2 + 8;
}
}
UkuiItems.Dialog {
id: foldWindow
visualParent: foldItem
mainItem: foldBase
enableWindowBlur: true
type: Platform.WindowType.SystemWindow
slideWindow.offset: 0
minimumWidth: foldBase.width
maximumWidth: minimumWidth
minimumHeight: foldBase.height
maximumHeight: minimumHeight
FoldArea {
id: foldBase
foldWindowVisible: foldWindow.visible
onFoldAreaDragFinshed: fromIndex => {
if (dropArea.inserted) {
if (dropArea.dragType === 1) {
dropArea.inserted = false;
if (trayview.itemAtIndex(dropArea.targetIndex).isFixed) return;
trayModel.items.remove(dropArea.targetIndex);
ItemModel.setOrderBetweenGroups(foldModel,
foldModel.index(dropArea.isOverLength ? fromIndex + 1 : fromIndex, 0),
showModel,
dropArea.targetIndex);
ItemModel.setSeparateIndex(showModel.currentSeparateIndex + 1);
}
}
}
onIsEmptyChanged: {
foldItem.visible = !foldBase.isEmpty;
foldWindow.hide();
trayview.isFold = false;
}
}
onVisibleChanged: {
dropArea.panelActive = foldWindow.visible;
}
onActiveFocusItemChanged: {
if (foldControl.pressed) return;
if (trayview.isFold) {
if (activeFocusItem === null) {
foldWindow.hide();
trayview.isFold = false;
}
}
}
}
}
}
ListView {
id: trayview
property string idSelect: ""
property bool isFold: false
property int sortIndex
property int sourceIndex
property real viewWidth: 0
property int viewSpacing: dropArea.onTopBar ? 6 : 0
height: dropArea.isHorizontal ? dropArea.itemHeight : viewWidth
width: dropArea.isHorizontal ? viewWidth : dropArea.itemWidth
orientation: dropArea.isHorizontal ? ListView.Horizontal : ListView.Vertical
layoutDirection: ListView.RightToLeft
verticalLayoutDirection: ListView.Qt.BottomToTop
spacing: viewSpacing
interactive: false
onViewSpacingChanged: {
trayview.viewWidth = trayview.calculateLength();
dropArea.getShowCount();
}
Component.onCompleted: {
var i = trayview.calculateLength();
viewWidth = i;
}
displaced: Transition {
SequentialAnimation {
ScriptAction {
script: {
trayview.viewWidth = trayview.calculateLength();
}
}
NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuad; duration: 200 }
NumberAnimation { properties: "z"; to: 1; easing.type: Easing.OutQuad; duration: 1 }
ScriptAction {
script: {
trayview.viewWidth += 1;
trayview.viewWidth -= 1;
}
}
}
}
move: Transition {
ScriptAction {
script: {
trayview.viewWidth = trayview.calculateLength();
}
}
NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuad; duration: 200 }
NumberAnimation { properties: "z"; to: 0; easing.type: Easing.OutQuad; duration: 1 }
}
ListView.onAdd: SequentialAnimation {
ScriptAction {
script: {
trayview.viewWidth = trayview.calculateLength();
}
}
}
ListView.onRemove: SequentialAnimation {
ScriptAction {
script: {
trayview.viewWidth = trayview.calculateLength();
}
}
}
model: DelegateModel {
id: trayModel
model: showModel
groups: DelegateModelGroup {
name: "foldItems"
includeByDefault: false
}
delegate: Item {
id: showDropArea
property int visualIndex: DelegateModel.itemsIndex
property bool isFixed: model.Fixed === undefined ? false : model.Fixed
property bool isControlPanel: ControlPanelModel.rowCount > 1 && model.Id === "ukui-sidebar"
width: isControlPanel ? dropArea.controlPanelWidth : dropArea.itemWidth
height: isControlPanel ? dropArea.controlPanelHeight : dropArea.itemHeight
clip: true
Binding { target: control; property: "selectIndex"; value: visualIndex}
UkuiItems.DtThemeBackground {
id: controlBase
clip: true
useStyleTransparency: false
anchors.fill: parent
backgroundColor: control.containsPress ? Platform.GlobalTheme.kComponentAlphaClick
: control.containsMouse ? Platform.GlobalTheme.kComponentAlphaHover
: Platform.GlobalTheme.kContainGeneralAlphaNormal
radius: dropArea.onTopBar ? 0 : Platform.GlobalTheme.kRadiusNormal
TrayIcon {
id: control
Accessible.role: Accessible.Button
Accessible.description: "This is a ukui-system-tray button of ukui-sni"
Accessible.name: model.Id === undefined ? "" : "ukui-system-tray_" + model.Id
property int selectIndex: 0
property var rootId: dropArea
anchors.fill: parent
appStatus: model.Status === undefined ? "" : model.Status
appAttentionMovieName: model.AttentionMovieName === undefined ? "" : model.AttentionMovieName
appIcon: model.Icon
appAttentionIcon: model.AttentionIcon
appOverlayIcon: model.OverlayIcon
showControlPanel: showDropArea.isControlPanel
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
Drag.active: false
Drag.hotSpot.x: width / 2
Drag.hotSpot.y: height / 2
Drag.dragType: Drag.Automatic
Drag.mimeData: {
"source": "ukui-system-tray"
}
drag.target: model.Fixed ? null : dragItem
drag.onActiveChanged: {
if (drag.active) {
toStartDrag();
control.opacity = 0;
exited();
}
Drag.active = drag.active;
}
UkuiItems.Tooltip {
id: tooltip
anchors.fill: parent
mainText: model.ToolTipTitle === undefined ? "" : model.ToolTipTitle.length === 0 ? model.Title : model.ToolTipTitle
posFollowCursor: false
visible: !control.showControlPanel
location: {
switch(dropArea.panelPos) {
case UkuiItems.Types.Bottom:
return UkuiItems.Dialog.BottomEdge;
case UkuiItems.Types.Left:
return UkuiItems.Dialog.LeftEdge;
case UkuiItems.Types.Top:
return UkuiItems.Dialog.TopEdge;
case UkuiItems.Types.Right:
return UkuiItems.Dialog.RightEdge;
}
}
margin: dropArea.isHorizontal ? (dropArea.height - control.height)/2 + 8 : (dropArea.width - control.width)/2 + 8
}
onClicked: {
if (mouse.button === Qt.LeftButton) {
trayModel.model.onActivate(trayModel.modelIndex(index));
}
if (mouse.button === Qt.RightButton) {
trayModel.model.onContextMenu(trayModel.modelIndex(index), showDropArea);
dropArea.callMenu = true;
}
}
onPressed: {
if (model.Fixed) return;
if (mouse.button === Qt.LeftButton) {
control.grabToImage(function(result) {
control.Drag.imageSource = result.url;
})
}
}
Drag.onDragFinished: {
control.opacity = 1
foldItem.visible = !foldBase.isEmpty;
dropArea.panelActive = false;
if (dropArea.dragType === 0) {
if (trayview.itemAtIndex(visualIndex).isFixed) return;
ItemModel.setOrderInGroup(showModel, showModel.index(trayview.sourceIndex, 0), visualIndex);
}
}
function toStartDrag() {
foldWindow.hide();
trayview.isFold = false;
trayview.sourceIndex = selectIndex;
dropArea.dragType = 0;
if (!foldItem.visible) foldItem.visible = true;
dropArea.panelActive = true;
}
}
}
}
onCountChanged: {
trayview.viewWidth = trayview.calculateLength();
}
}
function calculateLength() {
if (ControlPanelModel.rowCount > 1) {
update();
return trayModel.count * dropArea.itemShort + (trayModel.count - 1) * trayview.viewSpacing
+ (dropArea.controlPanelLength - dropArea.itemShort);
} else {
return trayModel.count * dropArea.itemShort + (trayModel.count - 1) * trayview.viewSpacing;
}
}
}
}
function changeFoldWindowPosition() {
if (foldWindow.visible) {
foldWindow.updatePosition();
}
}
onPositionChanged: drag => {
if (drag.source.rootId !== dropArea) return;
var target = getTarget(drag.x, drag.y);
if (target === -1) return;
if (dropArea.dragType === 0) {
if (trayview.itemAtIndex(target).isFixed) return;
trayModel.items.move(drag.source.selectIndex, target);
} else if (dropArea.dragType === 1) {
if (trayview.itemAtIndex(target).isFixed) return;
dropArea.targetIndex = target;
if (dropArea.inserted) {
var i = target
trayModel.items.move(drag.source.selectIndex, target)
drag.source.selectIndex = i
} else {
dropArea.inserted = true;
dropArea.indexInFold = drag.source.selectIndex;
if (trayModel.count > dropArea.showCount) {
dropArea.isOverLength = true;
showModel.currentSeparateIndex--;
foldModel.currentSeparateIndex--;
} else {
dropArea.isOverLength = false;
}
drag.source.selectIndex = target;
trayModel.items.insert(target, {});
}
}
}
onExited: {
if (dropArea.inserted) {
if (dropArea.isOverLength) {
showModel.currentSeparateIndex++;
foldModel.currentSeparateIndex++;
}
trayModel.items.remove(dropArea.targetIndex);
dropArea.inserted = false;
drag.source.selectIndex = dropArea.indexInFold;
}
}
function getTarget(x, y) {
switch (dropArea.panelPos) {
case UkuiItems.Types.Top:
case UkuiItems.Types.Bottom:
return trayview.indexAt((x + trayview.contentX - trayview.x), y);
case UkuiItems.Types.Left:
case UkuiItems.Types.Right:
return trayview.indexAt(x, y + trayview.contentY - trayview.y);
default:
return -1;
}
}
function menuStateChange(state) {
if (dropArea.callMenu) {
dropArea.panelActive = foldWindow.visible ? true : state;
dropArea.callMenu = state;
}
}
Component.onCompleted: {
ItemModel.menuStateChanged.connect(menuStateChange);
}
Component.onDestruction: {
ItemModel.menuStateChanged.disconnect(menuStateChange);
}
}
ukui-sni/ukui-system-tray/widget/ui/FoldArea.qml 0000664 0001750 0001750 00000017742 15153755611 020634 0 ustar feng feng import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQml.Models 2.15
import org.ukui.systemTray 1.0
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.quick.platform 1.0 as Platform
DropArea {
property bool isEmpty: foldAreaModel.count > 0 ? false : true
property int sourceIndex
property bool foldWindowVisible: false
signal foldAreaDragFinshed(int selectIndex)
width: foldAreaModel.count > 5 ? foldView.cellWidth * 5 + 8 : foldAreaModel.count * foldView.cellWidth + 8
height: (foldAreaModel.count % 5) === 0 ?
Math.floor((foldAreaModel.count / 5)) * foldView.cellHeight + 8 : Math.floor((foldAreaModel.count / 5) + 1) * foldView.cellHeight + 8
UkuiItems.DtThemeBackground {
anchors.fill: parent
backgroundColor: Platform.GlobalTheme.baseActive
GridView {
id: foldView
property string idSelect: ""
anchors.fill: parent
anchors.topMargin: 4
anchors.leftMargin: 4
cellWidth: dropArea.scaleFactor * 40
cellHeight: dropArea.scaleFactor * 40
interactive: false
moveDisplaced: Transition {
NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuad; duration: 200 }
NumberAnimation { properties: "z"; to: 1; easing.type: Easing.OutQuad; duration: 1 }
}
model: DelegateModel {
id: foldAreaModel
model: foldModel
delegate: DropArea {
property int vIndex: DelegateModel.itemsIndex
id: foldDropArea
width: foldView.cellWidth
height: foldView.cellHeight
clip: true
GridView.onAdd: SequentialAnimation {
NumberAnimation {target: foldDropArea; property: "scale"; from: 0; to: 1; duration: 250; easing.type: Easing.InOutQuad}
}
onDropped: {
if (drag.source.rootId !== dropArea) return;
ItemModel.setOrderInGroup(foldModel, foldModel.index(foldBase.sourceIndex, 0), drag.source.selectIndex);
}
onEntered: {
if (drag.source.rootId !== dropArea) return;
foldAreaModel.items.move(drag.source.selectIndex, vIndex)
}
Binding { target: controlFold; property: "selectIndex"; value: vIndex}
UkuiItems.DtThemeBackground {
id: controlBaseFold
clip: true
useStyleTransparency: false
anchors.fill: parent
backgroundColor: controlFold.containsPress ? Platform.GlobalTheme.kComponentAlphaClick
: controlFold.containsMouse ? Platform.GlobalTheme.kComponentAlphaHover
: Platform.GlobalTheme.kContainGeneralAlphaNormal
radius: Platform.GlobalTheme.kRadiusNormal
TrayIcon {
id: controlFold
Accessible.role: Accessible.Button
Accessible.description: "This is a ukui-system-tray button of ukui-sni"
Accessible.name: model.Id === undefined ? "" : "ukui-system-tray_" + model.Id
property int selectIndex: 0
property var rootId: dropArea
anchors.fill: parent
appStatus: model.Status
appAttentionMovieName: model.AttentionMovieName
appIcon: model.Icon
appAttentionIcon: model.AttentionIcon
appOverlayIcon: model.OverlayIcon
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
Drag.active: false
Drag.hotSpot.x: width / 2
Drag.hotSpot.y: height / 2
Drag.dragType: Drag.Automatic
Drag.mimeData: {
"source": "ukui-system-tray"
}
drag.target: controlFold;
drag.onActiveChanged: {
if (drag.active) {
toStartDrag();
controlFold.opacity = 0;
exited();
} else {
x = 0;
y = 0;
}
Drag.active = drag.active;
}
UkuiItems.Tooltip {
id: tooltip
anchors.fill: parent
mainText: model.ToolTipTitle.length === 0 ? model.Title : model.ToolTipTitle
posFollowCursor: false
active: foldWindowVisible
location: {
switch (dropArea.panelPos) {
case UkuiItems.Types.Bottom:
case UkuiItems.Types.Left:
case UkuiItems.Types.Right:
return UkuiItems.Dialog.BottomEdge;
case UkuiItems.Types.Top:
return UkuiItems.Dialog.TopEdge;
}
}
margin: 8
}
onClicked: {
if (mouse.button === Qt.LeftButton) {
foldAreaModel.model.onActivate(foldAreaModel.modelIndex(index));
}
if (mouse.button === Qt.RightButton) {
foldAreaModel.model.onContextMenu(foldAreaModel.modelIndex(index), foldDropArea);
}
}
onPressed: {
if (mouse.button === Qt.LeftButton) {
controlFold.grabToImage(function(result) {
controlFold.Drag.imageSource = result.url;
})
}
}
onReleased: {
}
Drag.onDragFinished: {
if (dropArea.inserted) {
foldAreaDragFinshed(foldBase.sourceIndex);
} else {
controlFold.parent = controlBaseFold;
controlFold.opacity = 1
if (foldBase.sourceIndex === vIndex) return;
ItemModel.setOrderInGroup(foldModel, foldModel.index(foldBase.sourceIndex, 0), vIndex);
}
}
function toStartDrag() {
x = controlFold.mapToItem(foldView,0,0).x;
y = controlFold.mapToItem(foldView,0,0).y;
foldBase.sourceIndex = vIndex;
dropArea.dragType = 1;
}
}
}
}
}
}
}
}
ukui-sni/ukui-system-tray/widget/ui/main.qml 0000664 0001750 0001750 00000002360 15153755611 020071 0 ustar feng feng import QtQuick 2.15
import QtQuick.Layouts 1.15
import org.ukui.quick.widgets 1.0
import org.ukui.quick.items 1.0
WidgetItem {
property bool isHorizontal: (Widget.orientation === Types.Horizontal)
property int pos: Widget.container.position
property real ratio: parent.ratio ? parent.ratio : 1
Layout.fillWidth: !isHorizontal
Layout.fillHeight: isHorizontal
Layout.preferredWidth: childrenRect.width
Layout.preferredHeight: childrenRect.height
clip: true
Widget.active: dropArea.panelActive
TrayView {
id: dropArea
property bool panelActive: false
property bool onTopBar: parent.height < 40
scaleFactor: parent.ratio
isHorizontal: parent.isHorizontal
itemWidth: onTopBar ? 28 : isHorizontal ?
scaleFactor * 32 : scaleFactor * 40
itemHeight: onTopBar ? 28 : isHorizontal ?
scaleFactor * 40 : scaleFactor * 32
itemLong: onTopBar ? 28 : scaleFactor * 40
itemShort: onTopBar ? 28 : scaleFactor * 32
panelPos: parent.pos
}
onWidthChanged: {
dropArea.changeFoldWindowPosition();
}
onHeightChanged: {
dropArea.changeFoldWindowPosition();
}
}
ukui-sni/ukui-system-tray/widget/ui/TrayIcon.qml 0000664 0001750 0001750 00000003350 15153755017 020675 0 ustar feng feng import QtQuick 2.15
import QtQuick.Controls 2.15
import org.ukui.systemTray 1.0
import org.ukui.quick.items 1.0 as UkuiItems
MouseArea {
id: control
property string appStatus: ""
property string appAttentionMovieName: ""
property var appIcon
property var appAttentionIcon
property var appOverlayIcon
property int iconRotation: 0
property real iconRatio: dropArea.onTopBar ? 24 : 16
property bool showControlPanel: false
Item {
id: trayitem
anchors.fill: parent
rotation: control.iconRotation
Loader {
anchors.centerIn: parent
sourceComponent: showControlPanel ?
controlPanelComponent : ((control.appStatus === "NeedsAttention") && (control.appAttentionMovieName !== ""))
? movieComponent : iconComponent
}
Component {
id: iconComponent
UkuiItems.Icon {
width: Math.round(dropArea.scaleFactor * iconRatio)
height: Math.round(dropArea.scaleFactor * iconRatio)
source: (control.appStatus === "NeedsAttention") ? control.appAttentionIcon : control.appIcon
mode: UkuiItems.Icon.AutoHighlight
// overlayIcon: appOverlayIcon
// isInverseColor: false
}
}
Component {
id: movieComponent
AnimatedImage {
width: Math.round(dropArea.scaleFactor * iconRatio)
height: Math.round(dropArea.scaleFactor * iconRatio)
source: control.appAttentionMovieName
}
}
Component {
id: controlPanelComponent
ControlPanel {}
}
}
}
ukui-sni/ukui-system-tray/widget/metadata.json 0000664 0001750 0001750 00000001101 15153755017 020460 0 ustar feng feng {
"Authors": [
{
"Name": "gjq",
"Email": "guojiaqi@kylinos.cn"
}
],
"Id": "org.ukui.systemTray",
"Icon": "ukui-menu",
"Name": "ukui-system-tray",
"Name[zh_CN]": "系统托盘",
"Tooltip": "system tray",
"Tooltip[zh_CN]": "系统托盘",
"Description": "system tray",
"Description[zh_CN]": "系统托盘",
"Version": "1.0",
"Website": "https://ukui.org",
"BugReport": "https://gitee.com/openkylin/ukui-panel/issues",
"ShowIn": "Panel",
"Contents": {
"Main": "ui/main.qml",
"I18n": "translations/ukui-system-tray"
}
}
ukui-sni/ukui-system-tray/CMakeLists.txt 0000664 0001750 0001750 00000005111 15153755611 017267 0 ustar feng feng cmake_minimum_required(VERSION 3.14)
project(ukui-system-tray)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_MICRO 0)
set(UKUI_SYSTEM_TRAY_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui Widgets Quick LinguistTools DBus REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets Quick LinguistTools DBus REQUIRED)
find_package(ukui-quick COMPONENTS framework platform)
find_package(ukui-search REQUIRED)
set(PROJECT_SOURCES
plugin/system-tray-plugin.h plugin/system-tray-plugin.cpp
plugin/tray-items-model.h plugin/tray-items-model.cpp
plugin/tray-item.h plugin/tray-item.cpp
plugin/item-group-model.h plugin/item-group-model.cpp
plugin/security-function-control.h plugin/security-function-control.cpp
plugin/items-filter-model.h plugin/items-filter-model.cpp
plugin/control-panel-model.cpp
plugin/control-panel-model.h
)
include_directories(${CMAKE_SOURCE_DIR}/status-notifier-host)
file(GLOB TS_FILES translations/*.ts)
set(UKUI_SYSTEM_TRAY_TRANSLATION_DIR "/usr/share/ukui/widgets/org.ukui.systemTray/translations")
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TS_FILES} OPTIONS -no-obsolete -no-ui-lines)
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${QRC_FILES} ${QM_FILES})
else()
qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TS_FILES} OPTIONS -no-obsolete -no-ui-lines)
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${QRC_FILES} ${QM_FILES})
endif()
target_compile_definitions(${PROJECT_NAME}
PRIVATE $<$,$>:QT_QML_DEBUG>
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_MAJOR_VERSION}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::DBus
ukui-sni-host
ukui-quick::framework
ukui-quick::platform
ukui-search
)
install(DIRECTORY "widget/" DESTINATION "/usr/share/ukui/widgets/org.ukui.systemTray")
install(FILES "plugin/qmldir" DESTINATION "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/qt${QT_VERSION_MAJOR}/qml/org/ukui/systemTray")
install(FILES ${QM_FILES} DESTINATION ${UKUI_SYSTEM_TRAY_TRANSLATION_DIR})
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/qt${QT_VERSION_MAJOR}/qml/org/ukui/systemTray")
ukui-sni/ukui-system-tray/plugin/ 0000775 0001750 0001750 00000000000 15153755611 016027 5 ustar feng feng ukui-sni/ukui-system-tray/plugin/qmldir 0000664 0001750 0001750 00000000063 15153755017 017241 0 ustar feng feng module org.ukui.systemTray
plugin ukui-system-tray
ukui-sni/ukui-system-tray/plugin/control-panel-model.cpp 0000664 0001750 0001750 00000005373 15153755611 022416 0 ustar feng feng /*
* Copyright (C) 2025, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*
*/
#include "control-panel-model.h"
#include
#include
#include
#include
#include
static std::once_flag onceFlag;
static ControlPanelModel* g_instance = nullptr;
ControlPanelModel* ControlPanelModel::self()
{
std::call_once(onceFlag, [ & ] {
g_instance = new ControlPanelModel();
});
return g_instance;
}
void ControlPanelModel::activate(int modelIndex)
{
Q_UNUSED(modelIndex);
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.ukui.Sidebar"),
QStringLiteral("/org/ukui/Sidebar"),
QStringLiteral("org.ukui.Sidebar"),
QStringLiteral("shortcutsActive"));
QDBusConnection::sessionBus().send(message);
}
void ControlPanelModel::showContextMenu(const QModelIndex &index, QQuickItem *item)
{
m_sourceModel->showContextMenu(mapToSource(index), item);
}
bool ControlPanelModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
return m_sourceModel->getControlPanelItems().contains(sourceIndex.data(TrayItemsModel::Id).toString());
}
bool ControlPanelModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{
return m_sourceModel->getControlPanelItems().indexOf(source_left.data(TrayItemsModel::Id).toString())
< m_sourceModel->getControlPanelItems().indexOf(source_right.data(TrayItemsModel::Id).toString());
}
ControlPanelModel::ControlPanelModel(QObject* parent)
{
QSortFilterProxyModel::setSourceModel(TrayItemsModel::instance());
m_sourceModel = TrayItemsModel::instance();
connect(this, &QAbstractItemModel::rowsInserted, this, &ControlPanelModel::rowCountChanged);
connect(this, &QAbstractItemModel::rowsRemoved, this, &ControlPanelModel::rowCountChanged);
sort(0);
}
ukui-sni/ukui-system-tray/plugin/control-panel-model.h 0000664 0001750 0001750 00000003134 15153755611 022054 0 ustar feng feng /*
* Copyright (C) 2025, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*
*/
#ifndef CONTROL_PANEL_MODEL_H
#define CONTROL_PANEL_MODEL_H
#include
#include "tray-items-model.h"
#include "items-filter-model.h"
class QQuickItem;
class ControlPanelModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
public:
static ControlPanelModel* self();
Q_INVOKABLE void activate(int modelIndex);
Q_INVOKABLE void showContextMenu(const QModelIndex &index, QQuickItem *item);
Q_SIGNALS:
void rowCountChanged();
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
private:
explicit ControlPanelModel(QObject* parent = nullptr);
TrayItemsModel* m_sourceModel = nullptr;
};
#endif //CONTROL_PANEL_MODEL_H
ukui-sni/ukui-system-tray/plugin/tray-item.cpp 0000664 0001750 0001750 00000013255 15153755017 020454 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: youdiansaodongxi
*
*/
#include "tray-item.h"
#include "status-notifier-item.h"
#include
#include
QIcon extractIcon(const QIcon&icon, const QIcon&defaultValue)
{
return icon.isNull() ? defaultValue : icon;
}
class TrayItemPrivate
{
public:
QString m_source;
QString m_desktop;
UkuiSni::StatusNotifierItem* m_item {nullptr};
bool m_fixed {false};
bool m_recordOrder {false};
bool m_isReady {false};
QQuickItem *m_parentItem {nullptr};
};
TrayItem::TrayItem(const QString&itemSource, QObject* parent) : QObject(parent), d(new TrayItemPrivate)
{
d->m_source = itemSource;
d->m_item = UkuiSni::StatusNotifierHost::self()->itemForService(d->m_source);
connect(d->m_item, &UkuiSni::StatusNotifierItem::dataUpdated, this, &TrayItem::dataUpdated);
connect(d->m_item, &UkuiSni::StatusNotifierItem::contextMenuReady, this, &TrayItem::contextMenuReady, Qt::QueuedConnection);
connect(d->m_item, &UkuiSni::StatusNotifierItem::activateResult, this, &TrayItem::activateResult);
connect(d->m_item, &UkuiSni::StatusNotifierItem::menuStateChange, this, &TrayItem::menuStateChanged);
}
TrayItem::~TrayItem()
{
if(d) {
delete d;
d = nullptr;
}
}
QString TrayItem::service() const
{
if (d->m_item) {
return d->m_item->service();
}
return {};
}
QIcon TrayItem::attentionIcon() const
{
if (d->m_item) {
return d->m_item->attentionIcon().isNull() ? icon() : d->m_item->attentionIcon();
}
return {};
}
QString TrayItem::attentionIconName() const
{
if(d->m_item) {
return d->m_item->attentionIconName();
}
return {};
}
QString TrayItem::attentionMovieName() const
{
if(d->m_item) {
return d->m_item->attentionMovieName();
}
return {};
}
QString TrayItem::category() const
{
if(d->m_item) {
return d->m_item->category();
}
return {};
}
QIcon TrayItem::icon() const
{
if (d->m_item) {
return d->m_item->icon().isNull()? QIcon::fromTheme("application-x-executable") : d->m_item->icon();
}
return {};
}
QString TrayItem::iconName() const
{
if(d->m_item) {
return d->m_item->iconName();
}
return {};
}
QString TrayItem::iconThemePath() const
{
if(d->m_item) {
return d->m_item->iconThemePath();
}
return {};
}
QString TrayItem::id() const
{
if(d->m_item) {
return d->m_item->id();
}
return {};
}
bool TrayItem::itemIsMenu() const
{
if(d->m_item) {
return d->m_item->itemIsMenu();
}
return false;
}
QIcon TrayItem::overlayIcon() const
{
if(d->m_item) {
return d->m_item->overlayIcon();
}
return {};
}
QString TrayItem::overlayIconName() const
{
if(d->m_item) {
return d->m_item->overlayIconName();
}
return {};
}
QString TrayItem::status() const
{
if(d->m_item) {
return d->m_item->status();
}
return "Passive";
}
QString TrayItem::title() const
{
if(d->m_item) {
return d->m_item->title();
}
return {};
}
QString TrayItem::toolTipSubTitle() const
{
if(d->m_item) {
return d->m_item->toolTipSubTitle();
}
return {};
}
QString TrayItem::toolTipTitle() const
{
if(d->m_item) {
return d->m_item->toolTipTitle();
}
return {};
}
QString TrayItem::windowId() const
{
if(d->m_item) {
return d->m_item->windowId();
}
return {};
}
QString TrayItem::desktop() const
{
return d->m_desktop;
}
uint TrayItem::pid() const
{
return d->m_item->pid();
}
bool TrayItem::fixed() const
{
return d->m_fixed;
}
void TrayItem::setFixed(bool fixed)
{
d->m_fixed = fixed;
}
bool TrayItem::recordOrder() const
{
return d->m_recordOrder;
}
void TrayItem::setRecordOrder(bool recordOrder)
{
d->m_recordOrder = recordOrder;
}
void TrayItem::setParentItem(QQuickItem *item)
{
d->m_parentItem = item;
}
void TrayItem::setDesktop(const QString &desktop)
{
d->m_desktop = desktop;
}
QString TrayItem::source() const
{
return d->m_source;
}
void TrayItem::contextMenu(int x, int y)
{
d->m_item->contextMenu(x, y);
}
void TrayItem::activate(int x, int y)
{
d->m_item->activate(x, y);
}
void TrayItem::secondaryActivate(int x, int y)
{
d->m_item->secondaryActivate(x, y);
}
void TrayItem::scroll(int delta, const QString &direction)
{
d->m_item->scroll(delta, direction);
}
void TrayItem::provideXdgActivationToken(const QString &token)
{
d->m_item->provideXdgActivationToken(token);
}
void TrayItem::dataUpdated()
{
if (!d->m_isReady) {
if (d->m_item->id() != "") {
d->m_isReady = true;
Q_EMIT itemReady(this);
}
}
Q_EMIT itemDataChanged(d->m_source);
}
void TrayItem::contextMenuReady(QMenu *menu)
{
if(menu && !menu->isEmpty()) {
menu->winId();
if(menu->windowHandle() && d->m_parentItem) {
menu->windowHandle()->setTransientParent(d->m_parentItem->window());
}
menu->popup(QCursor::pos());
}
}
ukui-sni/ukui-system-tray/plugin/security-function-control.cpp 0000664 0001750 0001750 00000020544 15153755017 023710 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: youdiansaodongxi
*
*/
#include "security-function-control.h"
#include "function-control.h"
SecurityFunctionControl *SecurityFunctionControl::instance()
{
static SecurityFunctionControl instance(nullptr);
return &instance;
}
bool SecurityFunctionControl::disableMouseLeftButton() const
{
return m_disableMouseLeftButton;
}
bool SecurityFunctionControl::disableMouseRightButton() const
{
return m_disableMouseRightButton;
}
bool SecurityFunctionControl::disableMouseHover() const
{
return m_disableMouseHover;
}
QStringList SecurityFunctionControl::appWhiteList() const
{
return m_appWhiteList;
}
QStringList SecurityFunctionControl::appBlackList() const
{
return m_appBlackList;
}
QStringList SecurityFunctionControl::leftClickBlackList() const
{
return m_leftClickBlackList;
}
QStringList SecurityFunctionControl::rightClickBlackList() const
{
return m_rightClickBlackList;
}
bool SecurityFunctionControl::canAppDisplay(const QString &desktop) const
{
if (!m_appWhiteList.isEmpty()) {
if (!std::any_of(m_appWhiteList.constBegin(), m_appWhiteList.constEnd(), [&](const QString& app) {
return desktop.endsWith(app);
})) {
return false;
}
}
if (!m_appBlackList.isEmpty()) {
if (std::any_of(m_appBlackList.constBegin(), m_appBlackList.constEnd(), [&](const QString& app) {
return desktop.endsWith(app);
})) {
return false;
}
}
return true;
}
bool SecurityFunctionControl::canLeftClick(const QString &desktop) const
{
if (!m_leftClickBlackList.isEmpty()) {
if (std::any_of(m_leftClickBlackList.constBegin(), m_leftClickBlackList.constEnd(), [&](const QString& app) {
return desktop.endsWith(app);
})) {
return false;
}
}
return true;
}
bool SecurityFunctionControl::canRightClick(const QString &desktop) const
{
if (!m_rightClickBlackList.isEmpty()) {
if (std::any_of(m_rightClickBlackList.constBegin(), m_rightClickBlackList.constEnd(), [&](const QString& app) {
return desktop.endsWith(app);
})) {
return false;
}
}
return true;
}
bool SecurityFunctionControl::controlEnabled() const
{
return m_controlEnabled;
}
SecurityFunctionControl::SecurityFunctionControl(QObject *parent) : QObject(parent)
{
UkuiQuick::FunctionControl::instance()->addWatch(QStringLiteral("ukui-sni-v11"));
onFunctionControlChanged("ukui-sni-v11", false);
connect(UkuiQuick::FunctionControl::instance(), &UkuiQuick::FunctionControl::functionControlChanged, this, [&](const QString &name) {
onFunctionControlChanged(name);
});
connect(UkuiQuick::FunctionControl::instance(), &UkuiQuick::FunctionControl::functionControlExit, this, [&]() {
onFunctionControlChanged(QStringLiteral("ukui-sni-v11"), true);
});
}
bool SecurityFunctionControl::compareListBySort(QStringList &list1, QStringList &list2)
{
if (list1.size() != list2.size())
return false;
list1.sort();
list2.sort();
return list1 == list2;
}
void SecurityFunctionControl::onFunctionControlChanged(const QString &name, bool exit)
{
if (name != QStringLiteral("ukui-sni-v11")) {
return;
}
//管控中有值时,设置为管控值,否则设置为配置文件中的值
auto config = exit ? QJsonObject(): UkuiQuick::FunctionControl::instance()->functionControlObject(name).value(name).toObject();
qDebug() << "ukui-sni function control config:" << config;
bool controlEnabled = !config.isEmpty();
if (m_controlEnabled != controlEnabled) {
m_controlEnabled = controlEnabled;
Q_EMIT controlEnabledChanged(m_controlEnabled);
}
//禁用左键点击
if (config.contains(QStringLiteral("disableMouseLeftButton"))) {
bool disableMouseLeftButton = config.value(QStringLiteral("disableMouseLeftButton")).toBool();
if (m_disableMouseLeftButton != disableMouseLeftButton) {
m_disableMouseLeftButton = disableMouseLeftButton;
Q_EMIT disableMouseLeftButtonChanged();
}
} else {
if (m_disableMouseLeftButton != false) {
m_disableMouseLeftButton = false;
Q_EMIT disableMouseLeftButtonChanged();
}
}
//禁用右键点击
if (config.contains(QStringLiteral("disableMouseRightButton"))) {
bool disableMouseRightButton = config.value(QStringLiteral("disableMouseRightButton")).toBool();
if (m_disableMouseRightButton != disableMouseRightButton) {
m_disableMouseRightButton = disableMouseRightButton;
Q_EMIT disableMouseRightButtonChanged();
}
} else {
if (m_disableMouseRightButton != false) {
m_disableMouseRightButton = false;
Q_EMIT disableMouseRightButtonChanged();
}
}
//禁用鼠标悬浮
if (config.contains(QStringLiteral("disableMouseHover"))) {
bool disableMouseHover = config.value(QStringLiteral("disableMouseHover")).toBool();
if (m_disableMouseHover != disableMouseHover) {
m_disableMouseHover = disableMouseHover;
Q_EMIT disableMouseHoverChanged();
}
} else {
if (m_disableMouseHover != false) {
m_disableMouseHover = false;
Q_EMIT disableMouseHoverChanged();
}
}
//应用白名单
if (config.contains(QStringLiteral("appWhiteList"))) {
QStringList appWhiteList;
for (QVariant &app : config.value(QStringLiteral("appWhiteList")).toArray().toVariantList()) {
appWhiteList.append(app.toString());
}
if (!compareListBySort(m_appWhiteList, appWhiteList)) {
m_appWhiteList = appWhiteList;
Q_EMIT appWhiteListChanged();
}
} else if (!m_appWhiteList.isEmpty()) {
m_appWhiteList.clear();
Q_EMIT appWhiteListChanged();
}
//应用黑名单
if (config.contains(QStringLiteral("appBlackList"))) {
QStringList appBlackList;
for (QVariant &app : config.value(QStringLiteral("appBlackList")).toArray().toVariantList()) {
appBlackList.append(app.toString());
}
if (!compareListBySort(m_appBlackList, appBlackList)) {
m_appBlackList= appBlackList;
Q_EMIT appBlackListChanged();
}
} else if (!m_appBlackList.isEmpty()) {
m_appBlackList.clear();
Q_EMIT appBlackListChanged();
}
//左键点击黑名单
if (config.contains(QStringLiteral("leftClickBlackList"))) {
QStringList leftClickBlackList;
for (QVariant &app : config.value(QStringLiteral("leftClickBlackList")).toArray().toVariantList()) {
leftClickBlackList.append(app.toString());
}
if (!compareListBySort(m_leftClickBlackList, leftClickBlackList)) {
m_leftClickBlackList = leftClickBlackList;
Q_EMIT leftClickBlackListChanged();
}
} else if (!m_leftClickBlackList.isEmpty()) {
m_leftClickBlackList.clear();
Q_EMIT leftClickBlackListChanged();
}
//右键点击黑名单
if (config.contains(QStringLiteral("rightClickBlackList"))) {
QStringList rightClickBlackList;
for (QVariant &app : config.value(QStringLiteral("rightClickBlackList")).toArray().toVariantList()) {
rightClickBlackList.append(app.toString());
}
if (!compareListBySort(m_rightClickBlackList, rightClickBlackList)) {
m_rightClickBlackList = rightClickBlackList;
Q_EMIT rightClickBlackListChanged();
}
} else if (!m_rightClickBlackList.isEmpty()) {
m_rightClickBlackList.clear();
Q_EMIT rightClickBlackListChanged();
}
}
ukui-sni/ukui-system-tray/plugin/items-filter-model.h 0000664 0001750 0001750 00000003604 15153755017 021705 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: youdiansaodongxi
*
*/
#ifndef ITEMSFILTERMODEL_H
#define ITEMSFILTERMODEL_H
#include
#include
class TrayItemsModel;
class ItemGroupModel;
class ItemsFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
static ItemsFilterModel *instance();
QVariant data(const QModelIndex &index, int role) const override;
Q_INVOKABLE void activate(const QModelIndex &index);
Q_INVOKABLE void showContextMenu(const QModelIndex &index, QQuickItem *item);
Q_INVOKABLE void setOrderInGroup(ItemGroupModel *group, const QModelIndex &groupIndex, int order);
Q_INVOKABLE void setOrderBetweenGroups(ItemGroupModel *fromGroup, const QModelIndex &beginIndex, ItemGroupModel *toGroup, int order);
Q_INVOKABLE void setSeparateIndex(int index);
Q_INVOKABLE int getSeparateIndex();
void setOrder(const QModelIndex &index, int order);
Q_SIGNALS:
void menuStateChanged(bool state);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
private:
ItemsFilterModel(QObject *parent = nullptr);
TrayItemsModel *m_sourceModel = nullptr;
};
#endif // ITEMSFILTERMODEL_H
ukui-sni/ukui-system-tray/plugin/tray-item.h 0000664 0001750 0001750 00000003416 15153755017 020117 0 ustar feng feng #ifndef TRAYITEM_H
#define TRAYITEM_H
#include
#include
#include
#include "status-notifier-host.h"
class TrayItemPrivate;
class TrayItem : public QObject
{
Q_OBJECT
public:
explicit TrayItem(const QString& itemSource, QObject* parent = nullptr);
~TrayItem();
QString source() const;
QString service() const;
QIcon attentionIcon() const;
QString attentionIconName() const;
QString attentionMovieName() const;
QString category() const;
QIcon icon() const;
QString iconName() const;
QString iconThemePath() const;
QString id() const;
bool itemIsMenu() const;
QIcon overlayIcon() const;
QString overlayIconName() const;
QString status() const;
QString title() const;
QString toolTipSubTitle() const;
QString toolTipTitle() const;
QString windowId() const;
QString desktop() const;
uint pid() const;
/**
* fixed in system tray
*/
bool fixed() const;
void setFixed(bool fixed);
/**
* need record relative order
*/
bool recordOrder() const;
void setRecordOrder(bool recordOrder);
void setParentItem(QQuickItem *item);
void setDesktop(const QString & desktop);
void contextMenu(int x, int y);
void activate(int x, int y);
void secondaryActivate(int x, int y);
void scroll(int delta, const QString &direction);
void provideXdgActivationToken(const QString &token);
public Q_SLOTS:
void dataUpdated();
void contextMenuReady(QMenu *menu);
Q_SIGNALS:
void itemDataChanged(const QString &source);
void activateResult(bool success);
void itemReady(TrayItem* item);
void menuStateChanged(bool state);
private:
TrayItemPrivate *d = nullptr;
void getDesktop();
};
#endif // TRAYITEM_H
ukui-sni/ukui-system-tray/plugin/tray-items-model.h 0000664 0001750 0001750 00000005175 15153755017 021404 0 ustar feng feng #ifndef TRAYITEMSMODEL_H
#define TRAYITEMSMODEL_H
#include
#include
#include
#include
#include
#include
#include "status-notifier-host.h"
#include "status-notifier-item.h"
#include "tray-item.h"
#include "application-info.h"
class ItemGroupModel;
class TrayItemsModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Role {
Service,
AttentionIcon,
AttentionIconName,
AttentionMovieName,
Category,
Icon,
IconName,
IconThemePath,
Id,
ItemIsMenu,
OverlayIcon,
OverlayIconName,
Status,
Title,
ToolTipSubTitle,
ToolTipTitle,
WindowId,
Fixed,
RecordOrder,
Row,
Desktop
};
Q_ENUM(Role)
static TrayItemsModel *instance();
~TrayItemsModel();
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash roleNames() const override;
void activate(const QModelIndex &index);
void showContextMenu(const QModelIndex &index, QQuickItem *item);
void setOrderInGroup(ItemGroupModel *group, const QModelIndex &groupIndex, int order);
void setOrderBetweenGroups(ItemGroupModel *fromGroup, const QModelIndex &beginIndex, ItemGroupModel *toGroup, int order);
void setSeparateIndex(int index);
int getSeparateIndex();
QStringList getControlPanelItems();
void setOrder(const QModelIndex &index, int order);
Q_SIGNALS:
void separateIndexChanged();
void menuStateChanged(bool state);
private Q_SLOTS:
void addSource(const QString &source);
void removeSource(const QString &source);
void insertItem(TrayItem* item);
void dataUpdated(const QString &sourceName);
void controlStateChanged(bool controlState);
private:
TrayItemsModel(QObject *parent = nullptr);
UkuiSni::StatusNotifierHost *m_sniHost = nullptr;
UkuiSearch::ApplicationInfo *m_applicationInfo = nullptr;
UkuiQuick::Config *m_config {nullptr};
QVector m_item;
QStringList m_fixList;
QStringList m_orderList;
QStringList m_hideList;
QStringList m_controlPanelList;
QStringList m_canHideList;
int m_currentSeparateIndex = 7;
int m_separateIndex = 7;
QMap m_itemInfo;
static QVariant extractIcon(const QIcon &icon, const QVariant &defaultValue = QVariant());
QString getDesktop(const uint & pid);
int indexOfSource(const QString &source) const;
void removeItem(const QString &source);
};
#endif // TRAYITEMSMODEL_H
ukui-sni/ukui-system-tray/plugin/tray-items-model.cpp 0000664 0001750 0001750 00000041010 15153755611 021723 0 ustar feng feng /*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: youdiansaodongxi
*
*/
#include "tray-items-model.h"
#include "item-group-model.h"
#include "security-function-control.h"
#include
#include
#include
#include
#include
static std::once_flag onceFlag;
static TrayItemsModel* g_instance = nullptr;
static const QStringList DEFAULT_ORDERED_ITEMS = {"ukui-bluetooth",
"Fcitx",
"kylin-virtual-keyboard",
"kylin-vpn"};
static const QStringList DEFAULT_FIXED_ITEMS = {"ukui-sidebar"};
static const QStringList DEFAULT_CONTROL_PANEL_ITEMS = {"ukui-power-manager-tray",
"ukui-volume-control-applet-qt",
"kylin-nm"};
static const QStringList DEFAULT_CAN_HIDE_ITEMS = {"ukui-bluetooth",
"Fcitx"};
TrayItemsModel *TrayItemsModel::instance()
{
std::call_once(onceFlag, [ & ] {
g_instance = new TrayItemsModel();
});
return g_instance;
}
TrayItemsModel::~TrayItemsModel()
{
if (!m_applicationInfo) {
delete m_applicationInfo;
m_applicationInfo = nullptr;
}
g_instance = nullptr;
}
TrayItemsModel::TrayItemsModel(QObject *parent) : QAbstractListModel(parent)
{
if (!m_config) {
m_config = UkuiQuick::ConfigLoader::getConfig("org.ukui.systemTray");
}
const auto &data = m_config->data();
//get separateIndex
if (!data.contains(QStringLiteral("separateIndex"))) {
m_config->setValue(QStringLiteral("separateIndex"), m_separateIndex);
} else {
m_separateIndex = m_config->getValue("separateIndex").toInt();
}
//fixed items
if (!data.contains(QStringLiteral("fixedItems"))) {
m_fixList = DEFAULT_FIXED_ITEMS;
m_config->setValue(QStringLiteral("fixedItems"), DEFAULT_FIXED_ITEMS);
} else {
m_fixList = m_config->getValue("fixedItems").toStringList();
}
//showed items
if (!data.contains(QStringLiteral("version"))) {
m_config->setValue(QStringLiteral("version"), QStringLiteral("1.0"));
m_orderList = DEFAULT_ORDERED_ITEMS;
m_config->setValue(QStringLiteral("orderedItems"), DEFAULT_ORDERED_ITEMS);
} else {
if (!data.contains(QStringLiteral("orderedItems"))) {
m_orderList = DEFAULT_ORDERED_ITEMS;
m_config->setValue(QStringLiteral("orderedItems"), DEFAULT_ORDERED_ITEMS);
} else {
m_orderList = m_config->getValue(QStringLiteral("orderedItems")).toStringList();
}
}
//hide items
m_hideList = m_config->getValue(QStringLiteral("trayIconsInhibited")).toStringList();
//2.x版本号校验
QString version = m_config->getValue("version").toString();
if (QVersionNumber::fromString(version).majorVersion() < 2) {
m_controlPanelList = DEFAULT_CONTROL_PANEL_ITEMS;
m_config->setValue("controlPanelItems", DEFAULT_CONTROL_PANEL_ITEMS);
for (const QString & item : DEFAULT_CONTROL_PANEL_ITEMS) {
m_fixList.removeAll(item);
m_orderList.removeAll(item);
m_hideList.removeAll(item);
}
m_config->setValue("fixedItems", m_fixList);
m_config->setValue("orderedItems", m_orderList);
m_config->setValue("trayIconsInhibited", m_hideList);
m_config->setValue("version", "2.0");
} else {
m_controlPanelList = m_config->getValue("controlPanelItems").toStringList();
}
//2.1版本号校验,新增trayIconsCanInhibited
if (QVersionNumber::fromString(version).minorVersion() < 1) {
m_config->setValue("version", "2.1");
}
//2.2版本号校验,从可隐藏列表中移除vpn
if (QVersionNumber::fromString(version).minorVersion() < 2) {
m_hideList.removeAll("kylin-vpn");
m_config->setValue("trayIconsInhibited", m_hideList);
m_config->setValue("version", "2.2");
}
//固定的items放在order items的前面
m_orderList = m_fixList + m_orderList;
m_sniHost = UkuiSni::StatusNotifierHost::self();
m_sniHost->registerHost();
m_applicationInfo = new UkuiSearch::ApplicationInfo;
connect(m_config, &UkuiQuick::Config::configChanged, this, [=] {
QStringList hidelist = m_config->getValue(QStringLiteral("trayIconsInhibited")).toStringList();
for (QString &itemId : hidelist) {
if (!m_hideList.contains(itemId)) { //处理新增的隐藏
m_hideList.append(itemId);
QStringList sourceList = m_itemInfo.keys(itemId);
for (QString &itemSource : sourceList) {
removeItem(itemSource);
}
}
}
QStringList list = m_hideList;
for (QString &itemId : list) {
if (!hidelist.contains(itemId)) { //处理新增的显示
m_hideList.removeOne(itemId);
QStringList sourceList = m_itemInfo.keys(itemId);
for (QString &itemSource : sourceList) {
addSource(itemSource);
}
}
}
});
connect(m_sniHost, &UkuiSni::StatusNotifierHost::itemAdded, this, &TrayItemsModel::addSource);
connect(m_sniHost, &UkuiSni::StatusNotifierHost::itemRemoved, this, &TrayItemsModel::removeSource);
connect(SecurityFunctionControl::instance(),
&SecurityFunctionControl::controlEnabledChanged, this, &TrayItemsModel::controlStateChanged);
for (auto &service : m_sniHost->services()) {
addSource(service);
}
m_config->forceSync();
}
int TrayItemsModel::rowCount(const QModelIndex &parent) const
{
return m_item.length();
}
QVariant TrayItemsModel::data(const QModelIndex &index, int role) const
{
int i = index.row();
if ((i < 0) || (i >= m_item.length())) {
return QVariant();
}
TrayItem* item = m_item[i];
switch (static_cast(role)) {
case Role::Service:
return item->service();
case Role::AttentionIcon:
return item->attentionIcon();
case Role::AttentionIconName:
return item->attentionIconName();
case Role::AttentionMovieName:
return item->attentionMovieName();
case Role::Category:
return item->category();
case Role::Icon:
return item->icon();
case Role::IconName:
return item->iconName();
case Role::IconThemePath:
return item->iconThemePath();
case Role::Id:
return item->id();
case Role::ItemIsMenu:
return item->itemIsMenu();
case Role::OverlayIcon:
return item->overlayIcon();
case Role::OverlayIconName:
return item->overlayIconName();
case Role::Status:
return item->status();
case Role::Title:
return item->title();
case Role::ToolTipSubTitle:
return item->toolTipSubTitle();
case Role::ToolTipTitle:
return item->toolTipTitle();
case Role::WindowId:
return item->windowId();
case Role::Fixed:
return item->fixed();
case Role::RecordOrder:
return item->recordOrder();
case Role::Row:
return index.row();
case Role::Desktop:
return item->desktop();
default:
return {};
}
}
QHash TrayItemsModel::roleNames() const
{
QHash roles = QAbstractItemModel::roleNames();
QMetaEnum e = metaObject()->enumerator(metaObject()->indexOfEnumerator("Role"));
for (int i = 0; i < e.keyCount(); ++i) {
roles.insert(e.value(i), e.key(i));
}
return roles;
}
void TrayItemsModel::activate(const QModelIndex &index)
{
if (!index.isValid()) return;
m_item.at(index.row())->activate(QCursor::pos().x(), QCursor::pos().y());
}
void TrayItemsModel::showContextMenu(const QModelIndex &index, QQuickItem *item)
{
if (!index.isValid()) return;
m_item.at(index.row())->setParentItem(item);
m_item.at(index.row())->contextMenu(QCursor::pos().x(), QCursor::pos().y());
}
QVariant TrayItemsModel::extractIcon(const QIcon &icon, const QVariant &defaultValue)
{
if (!icon.isNull()) {
return icon;
} else {
return defaultValue;
}
}
QString TrayItemsModel::getDesktop(const uint &pid)
{
QString desktop;
m_applicationInfo->tranPidToDesktopFp(pid, desktop);
return desktop;
}
int TrayItemsModel::indexOfSource(const QString &source) const
{
for (int i = 0; i < rowCount(QModelIndex()); i++) {
if (m_item[i]->source() == source) {
return i;
}
}
return -1;
}
void TrayItemsModel::removeItem(const QString &source)
{
int i = indexOfSource(source);
if (i >= 0) {
auto item = m_item.at(i);
beginRemoveRows({}, i, i);
m_item.removeAt(i);
endRemoveRows();
if (item) {
item->disconnect();
item->deleteLater();
}
}
Q_EMIT dataChanged(index(i, 0, {}), index(m_item.size() - 1, 0, {}), {Role::Row});
}
void TrayItemsModel::setOrderInGroup(ItemGroupModel *group, const QModelIndex &groupIndex, int order)
{
int end = group->groupEnd();
int newOrder = group->groupBegin() + order;
if(newOrder > end) {
newOrder = end;
}
setOrder(group->mapToSource(groupIndex), newOrder);
}
void TrayItemsModel::setOrderBetweenGroups(ItemGroupModel *fromGroup, const QModelIndex &beginIndex, ItemGroupModel *toGroup, int order)
{
int newOrder = toGroup->groupBegin() + order;
if(newOrder > toGroup->groupEnd()) {
newOrder = toGroup->groupEnd() + 1;
}
setOrder(fromGroup->mapToSource(beginIndex), newOrder);
}
void TrayItemsModel::setSeparateIndex(int index)
{
m_separateIndex = index;
if (m_separateIndex > m_item.length() - 1) {
m_separateIndex = m_item.length() - 1;
}
Q_EMIT separateIndexChanged();
m_config->setValue(QStringLiteral("separateIndex"), index);
m_config->forceSync();
}
void TrayItemsModel::setOrder(const QModelIndex &index, int order)
{
int oldRow = index.row();
if ((oldRow < 0) || (oldRow >= m_item.length())) {
return;
}
auto item = m_item.at(oldRow);
if(item->fixed()) {
return;
}
if(oldRow == order) {
return;
}
QString id = m_item.at(index.row())->id();
if(order > oldRow) {
if(item->recordOrder()) {
QString idBefore;
for(int row = order; row > oldRow; --row) {
if(m_item.at(row)->recordOrder()) {
idBefore = m_item.at(row)->id();
break;
}
}
if(!idBefore.isEmpty()) {
int targetOrder = m_orderList.indexOf(idBefore);
m_orderList.insert(targetOrder, m_orderList.takeAt(m_orderList.indexOf(id)));
m_config->setValue(QStringLiteral("orderedItems"), QStringList(m_orderList.mid(m_fixList.size())));
}
}
beginMoveRows(index.parent(), oldRow, oldRow, index.parent(), order + 1);
m_item.insert(order, m_item.takeAt(oldRow));
endMoveRows();
Q_EMIT dataChanged(this->index(oldRow, 0), this->index(order, 0), {Role::Row});
} else {
if(item->recordOrder()) {
QString idAfter;
for(int row = order; row < oldRow; ++row) {
if(m_item.at(row)->recordOrder()) {
idAfter = m_item.at(row)->id();
break;
}
}
if(!idAfter.isEmpty()) {
int targetOrder = m_orderList.indexOf(idAfter);
m_orderList.insert(targetOrder, m_orderList.takeAt(m_orderList.indexOf(id)));
m_config->setValue(QStringLiteral("orderedItems"), QStringList(m_orderList.mid(m_fixList.size())));
}
}
beginMoveRows(index.parent(), oldRow, oldRow, index.parent(), order);
m_item.insert(order, m_item.takeAt(oldRow));
endMoveRows();
Q_EMIT dataChanged(this->index(order, 0), this->index(oldRow, 0), {Role::Row});
}
m_config->forceSync();
}
int TrayItemsModel::getSeparateIndex()
{
return m_separateIndex;
}
QStringList TrayItemsModel::getControlPanelItems()
{
return m_controlPanelList;
}
void TrayItemsModel::addSource(const QString &source)
{
for (TrayItem* &trayItem : m_item) {
if (trayItem->source() == source) {
return;
}
}
auto item = new TrayItem(source);
if (SecurityFunctionControl::instance()->controlEnabled()) {
item->setDesktop(getDesktop(item->pid()));
}
connect(item, &TrayItem::itemReady, this, &TrayItemsModel::insertItem);
if (item->id() != "") {
insertItem(item);
}
}
void TrayItemsModel::removeSource(const QString &source)
{
QString id = m_itemInfo.value(source);
if (DEFAULT_CAN_HIDE_ITEMS.contains(id)) {
m_canHideList.removeAll(id);
m_config->setValue("trayIconsCanInhibited", m_canHideList);
}
m_itemInfo.remove(source);
removeItem(source);
}
void TrayItemsModel::insertItem(TrayItem* item)
{
if (m_item.contains(item)) return;
m_itemInfo.insert(item->source(), item->id());
if (DEFAULT_CAN_HIDE_ITEMS.contains(item->id())) {
if (!m_canHideList.contains(item->id())) {
m_canHideList.append(item->id());
m_config->setValue("trayIconsCanInhibited", m_canHideList);
}
}
if (m_hideList.contains(item->id())) {
removeItem(item->source());
return;
}
int order = m_item.size();
for(const QString &id : m_orderList) {
if(id == item->id()) {
int index = m_orderList.indexOf(id);
if(index <= m_fixList.size() - 1) {
item->setFixed(true);
} else {
item->setRecordOrder(true);
}
//index为0表示第一个
if(index == 0) {
order = 0;
} else if(index > 0){
bool find = false;
//寻找前一个item所在的位置,前一个item未注册时寻找再前一个的位置
for(int preIndex = index - 1; preIndex >= 0 && !find; preIndex--) {
QString preId = m_orderList.at(preIndex);
for(int i = 0; i < m_item.size(); i++) {
if(m_item.at(i)->id() == preId) {
order = i + 1;
find = true;
break;
}
}
}
//找不到放到第一个
if(!find) {
order = 0;
}
}
break;
}
}
beginInsertRows(QModelIndex(), order, order);
m_item.insert(order, item);
endInsertRows();
Q_EMIT dataChanged(index(order, 0, {}), index(m_item.size() - 1, 0, {}), {Role::Row});
connect(item, &TrayItem::itemDataChanged, this, &TrayItemsModel::dataUpdated);
connect(item, &TrayItem::menuStateChanged, this, &TrayItemsModel::menuStateChanged);
}
void TrayItemsModel::dataUpdated(const QString &sourceName)
{
for (TrayItem* &trayItem : m_item) {
if (trayItem->source() == sourceName) {
int i = indexOfSource(sourceName);
if (i >= 0) {
Q_EMIT dataChanged(index(i, 0, {}), index(i, 0, {}));
}
return;
}
}
}
void TrayItemsModel::controlStateChanged(bool controlState)
{
if (controlState) {
for (int i = 0; i < rowCount(QModelIndex()); i++) {
if (m_item[i]->desktop() != "") continue;
m_item[i]->setDesktop(getDesktop(m_item[i]->pid()));
Q_EMIT dataChanged(index(i, 0, {}), index(i, 0, {}), {Role::Desktop});
}
}
}
ukui-sni/ukui-system-tray/plugin/items-filter-model.cpp 0000664 0001750 0001750 00000007220 15153755017 022236 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: youdiansaodongxi
*
*/
#include "items-filter-model.h"
#include "tray-items-model.h"
#include "item-group-model.h"
#include "security-function-control.h"
#include
ItemsFilterModel *ItemsFilterModel::instance()
{
static ItemsFilterModel model;
return &model;
}
QVariant ItemsFilterModel::data(const QModelIndex &index, int role) const
{
return sourceModel()->data(mapToSource(index), role);
}
void ItemsFilterModel::activate(const QModelIndex &index)
{
if (SecurityFunctionControl::instance()->canLeftClick(index.data(TrayItemsModel::Desktop).toString())) {
m_sourceModel->activate(mapToSource(index));
}
}
void ItemsFilterModel::showContextMenu(const QModelIndex &index, QQuickItem *item)
{
if (SecurityFunctionControl::instance()->canRightClick(index.data(TrayItemsModel::Desktop).toString())) {
m_sourceModel->showContextMenu(mapToSource(index), item);
}
}
void ItemsFilterModel::setOrderInGroup(ItemGroupModel *group, const QModelIndex &groupIndex, int order)
{
int end = group->groupEnd();
int newOrder = group->groupBegin() + order;
if(newOrder > end) {
newOrder = end;
}
m_sourceModel->setOrder(mapToSource(group->mapToSource(groupIndex)),
mapToSource(this->index(newOrder, 0)).row());
}
void ItemsFilterModel::setOrderBetweenGroups(ItemGroupModel *fromGroup, const QModelIndex &beginIndex, ItemGroupModel *toGroup, int order)
{
int newOrder = toGroup->groupBegin() + order;
if(newOrder > toGroup->groupEnd()) {
newOrder = toGroup->groupEnd() + 1;
}
m_sourceModel->setOrder(mapToSource(fromGroup->mapToSource(beginIndex)),
mapToSource(this->index(newOrder, 0)).row());
}
void ItemsFilterModel::setSeparateIndex(int index)
{
if (index > rowCount() - 1) {
index = rowCount() - 1;
}
m_sourceModel->setSeparateIndex(index);
}
int ItemsFilterModel::getSeparateIndex()
{
return m_sourceModel->getSeparateIndex();
}
bool ItemsFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent);
return SecurityFunctionControl::instance()->canAppDisplay(sourceIndex.data(TrayItemsModel::Desktop).toString()) &&
!m_sourceModel->getControlPanelItems().contains(sourceIndex.data(TrayItemsModel::Id).toString());
}
ItemsFilterModel::ItemsFilterModel(QObject *parent) : QSortFilterProxyModel(parent)
{
setSourceModel(TrayItemsModel::instance());
m_sourceModel = TrayItemsModel::instance();
connect(m_sourceModel, &TrayItemsModel::menuStateChanged, this, &ItemsFilterModel::menuStateChanged);
connect(SecurityFunctionControl::instance(), &SecurityFunctionControl::appWhiteListChanged, this, &ItemsFilterModel::invalidateFilter);
connect(SecurityFunctionControl::instance(), &SecurityFunctionControl::appBlackListChanged, this, &ItemsFilterModel::invalidateFilter);
}
ukui-sni/ukui-system-tray/plugin/system-tray-plugin.cpp 0000664 0001750 0001750 00000003331 15153755017 022330 0 ustar feng feng /*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*
*/
#include "system-tray-plugin.h"
#include "items-filter-model.h"
#include "item-group-model.h"
#include "security-function-control.h"
#include "control-panel-model.h"
#include
#include
void SystemTrayPlugin::registerTypes(const char *uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.ukui.systemTray"));
qmlRegisterUncreatableType(uri,1,0,"ItemGroupModel", "");
qmlRegisterType(uri, 1, 0, "GroupModel");
qmlRegisterSingletonType(uri,1,0,"ItemModel", [] (QQmlEngine *, QJSEngine *) -> QObject* {
return ItemsFilterModel::instance();
});
qmlRegisterSingletonType(uri,1,0,"FunctionControl", [] (QQmlEngine *, QJSEngine *) -> QObject* {
return SecurityFunctionControl::instance();
});
qmlRegisterSingletonType(uri,1,0,"ControlPanelModel", [] (QQmlEngine *, QJSEngine *) -> QObject* {
return ControlPanelModel::self();
});
}
ukui-sni/ukui-system-tray/plugin/system-tray-plugin.h 0000664 0001750 0001750 00000000517 15153755017 022000 0 ustar feng feng #ifndef UKUI_PANEL_START_MENU_PLUGIN_H
#define UKUI_PANEL_START_MENU_PLUGIN_H
#include
class SystemTrayPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
void registerTypes(const char *uri) override;
};
#endif //UKUI_PANEL_START_MENU_PLUGIN_H
ukui-sni/ukui-system-tray/plugin/security-function-control.h 0000664 0001750 0001750 00000005250 15153755017 023352 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: youdiansaodongxi
*
*/
#ifndef SECURITYFUNCTIONCONTROL_H
#define SECURITYFUNCTIONCONTROL_H
#include
#include
#include
class SecurityFunctionControl : public QObject
{
Q_OBJECT
public:
static SecurityFunctionControl *instance();
Q_PROPERTY(bool disableMouseLeftButton READ disableMouseLeftButton NOTIFY disableMouseLeftButtonChanged)
Q_PROPERTY(bool disableMouseRightButton READ disableMouseRightButton NOTIFY disableMouseRightButtonChanged)
Q_PROPERTY(bool disableMouseHover READ disableMouseHover NOTIFY disableMouseHoverChanged)
bool disableMouseLeftButton() const;
bool disableMouseRightButton() const;
bool disableMouseHover() const;
QStringList appWhiteList() const;
QStringList appBlackList() const;
QStringList leftClickBlackList() const;
QStringList rightClickBlackList() const;
bool canAppDisplay(const QString &desktop) const;
bool canLeftClick(const QString &desktop) const;
bool canRightClick(const QString &desktop) const;
bool controlEnabled() const;
Q_SIGNALS:
void disableMouseLeftButtonChanged();
void disableMouseRightButtonChanged();
void disableMouseHoverChanged();
void appWhiteListChanged();
void appBlackListChanged();
void leftClickBlackListChanged();
void rightClickBlackListChanged();
void controlEnabledChanged(bool controlEnabled);
private:
explicit SecurityFunctionControl(QObject *parent = nullptr);
bool compareListBySort(QStringList &list1, QStringList &list2);
bool m_disableMouseLeftButton {false};
bool m_disableMouseRightButton {false};
bool m_disableMouseHover {false};
QStringList m_appWhiteList {};
QStringList m_appBlackList {};
QStringList m_leftClickBlackList {};
QStringList m_rightClickBlackList {};
bool m_controlEnabled {false};
private Q_SLOTS:
void onFunctionControlChanged(const QString& name, bool exit = false);
};
#endif // SECURITYFUNCTIONCONTROL_H
ukui-sni/ukui-system-tray/plugin/item-group-model.cpp 0000664 0001750 0001750 00000010160 15153755017 021717 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: youdiansaodongxi
*
*/
#include "item-group-model.h"
#include "tray-items-model.h"
#include "items-filter-model.h"
#include "security-function-control.h"
#include
#include
ItemGroupModel::ItemGroupModel(QObject *parent) : QSortFilterProxyModel(parent)
{
QSortFilterProxyModel::setSourceModel(ItemsFilterModel::instance());
m_sourceModel = ItemsFilterModel::instance();
setFilterRole(TrayItemsModel::Row);
connect(TrayItemsModel::instance(), &TrayItemsModel::separateIndexChanged, this, &ItemGroupModel::onSeparateIndexChanged);
setCurrentSeparateIndex(m_sourceModel->getSeparateIndex());
}
void ItemGroupModel::setModelType(GroupType type)
{
m_groupType = type;
}
ItemGroupModel::GroupType ItemGroupModel::getModelType()
{
return m_groupType;
}
int ItemGroupModel::currentSeparateIndex()
{
return m_currentSeparateIndex;
}
void ItemGroupModel::setCurrentSeparateIndex(int index)
{
if (index < 0) return;
m_currentSeparateIndex = index;
invalidateFilter();
Q_EMIT currentSeparateIndexChanged();
}
int ItemGroupModel::showCount()
{
return m_showCount;
}
void ItemGroupModel::setShowCount(int index)
{
m_showCount = index <= 0 ? 0 : index;
onShowCountChanged();
Q_EMIT showCountChanged();
}
void ItemGroupModel::onActivate(const QModelIndex &index)
{
m_sourceModel->activate(mapToSource(index));
}
void ItemGroupModel::onContextMenu(const QModelIndex &index, QQuickItem *item)
{
m_sourceModel->showContextMenu(mapToSource(index), item);
}
QVariant ItemGroupModel::data(const QModelIndex &index, int role) const
{
return sourceModel()->data(mapToSource(index), role);
}
QVariant ItemGroupModel::foldIcon()
{
return QIcon::fromTheme("ukui-end-symbolic");
}
int ItemGroupModel::groupBegin() const
{
if (m_groupType == GroupType::Show) {
return 0;
} else if (m_groupType == GroupType::Fold) {
return m_currentSeparateIndex + 1;
}
}
int ItemGroupModel::groupEnd() const
{
if (m_groupType == GroupType::Show) {
return m_currentSeparateIndex;
} else if (m_groupType == GroupType::Fold) {
return m_sourceModel->rowCount(QModelIndex()) - 1;
}
}
bool ItemGroupModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
if (m_groupType == GroupType::Show) {
return source_row >= 0 && source_row <= m_currentSeparateIndex;
} else if (m_groupType == GroupType::Fold) {
return source_row > m_currentSeparateIndex && source_row <= (m_sourceModel->rowCount(QModelIndex()) - 1);
}
return true;
}
void ItemGroupModel::onShowCountChanged()
{
if (m_showCount < m_currentSeparateIndex) {
if (m_showCount <= 0) {
setCurrentSeparateIndex(0);
} else {
setCurrentSeparateIndex(m_showCount);
}
} else {
if (m_currentSeparateIndex != m_sourceModel->getSeparateIndex()) {
if (m_sourceModel->getSeparateIndex() < m_showCount) {
setCurrentSeparateIndex(m_sourceModel->getSeparateIndex());
} else {
setCurrentSeparateIndex(m_showCount);
}
}
}
Q_EMIT currentSeparateIndexChanged();
}
void ItemGroupModel::onSeparateIndexChanged()
{
setCurrentSeparateIndex(m_showCount < m_sourceModel->getSeparateIndex() ?
m_showCount : m_sourceModel->getSeparateIndex());
Q_EMIT currentSeparateIndexChanged();
}
ukui-sni/ukui-system-tray/plugin/item-group-model.h 0000664 0001750 0001750 00000003415 15153755017 021371 0 ustar feng feng #ifndef ITEMGROUPMODEL_H
#define ITEMGROUPMODEL_H
#include
#include
#include
#include
#include
#include
#include "tray-item.h"
class ItemsFilterModel;
class ItemGroupModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(GroupType modelType READ getModelType WRITE setModelType)
Q_PROPERTY(int currentSeparateIndex READ currentSeparateIndex WRITE setCurrentSeparateIndex NOTIFY currentSeparateIndexChanged)
Q_PROPERTY(int showCount READ showCount WRITE setShowCount NOTIFY showCountChanged)
public:
enum GroupType {Show, Fold};
Q_ENUM(GroupType)
explicit ItemGroupModel(QObject *parent = nullptr);
void setModelType(GroupType type);
GroupType getModelType();
int currentSeparateIndex();
void setCurrentSeparateIndex(int index);
int showCount();
void setShowCount(int index);
QVariant data(const QModelIndex &index, int role) const override;
Q_INVOKABLE void onActivate(const QModelIndex &index);
Q_INVOKABLE void onContextMenu(const QModelIndex &index, QQuickItem *item);
Q_INVOKABLE QVariant foldIcon();
Q_INVOKABLE int groupBegin() const;
Q_INVOKABLE int groupEnd() const;
Q_SIGNALS:
void currentSeparateIndexChanged();
void showCountChanged();
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
private:
void onShowCountChanged();
void onSeparateIndexChanged();
QHash m_order;
ItemsFilterModel *m_sourceModel = nullptr;
int m_groupBegin = 0;
int m_groupEnd = 0;
GroupType m_groupType = GroupType::Show;
int m_currentSeparateIndex = 0;
int m_showCount = 0;
};
#endif // ITEMGROUPMODEL_H
ukui-sni/CMakeLists.txt 0000664 0001750 0001750 00000001452 15153755611 014017 0 ustar feng feng cmake_minimum_required(VERSION 3.14)
project(ukui-sni VERSION 1.0 LANGUAGES C CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core DBus Network Gui Widgets Quick REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core DBus Network Gui Widgets Quick REQUIRED)
if (QT_VERSION_MAJOR EQUAL 5)
find_package(Qt5 COMPONENTS X11Extras REQUIRED)
elseif (QT_VERSION_MAJOR EQUAL 6)
find_package(Qt6 COMPONENTS GuiPrivate REQUIRED)
endif()
add_subdirectory(status-notifier-watcher)
add_subdirectory(status-notifier-host)
add_subdirectory(ukui-system-tray)
add_subdirectory(xembed-sni-proxy)
if(BUILD_TEST)
add_subdirectory(test)
endif()
ukui-sni/status-notifier-host/ 0000775 0001750 0001750 00000000000 15153755611 015370 5 ustar feng feng ukui-sni/status-notifier-host/status-notifier-host.h 0000664 0001750 0001750 00000002761 15153755017 021662 0 ustar feng feng /*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*
*/
#ifndef UKUI_SNI_STATUS_NOTIFIER_HOST_H
#define UKUI_SNI_STATUS_NOTIFIER_HOST_H
#include
#include "status-notifier-item.h"
namespace UkuiSni {
class StatusNotifierHostPrivate;
class StatusNotifierHost : public QObject
{
Q_OBJECT
public:
static StatusNotifierHost *self();
~StatusNotifierHost() override;
void registerHost();
QList items();
const QList services() const;
UkuiSni::StatusNotifierItem *itemForService(const QString service);
Q_SIGNALS:
void itemAdded(const QString &service);
void itemRemoved(const QString &service);
private:
explicit StatusNotifierHost(QObject *parent = nullptr);
StatusNotifierHostPrivate *d = nullptr;
};
}
#endif //UKUI_SNI_STATUS_NOTIFIER_HOST_H
ukui-sni/status-notifier-host/ukui-sni-host.pc.in 0000664 0001750 0001750 00000000443 15153755017 021041 0 ustar feng feng prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib/@CMAKE_LIBRARY_ARCHITECTURE@
includedir=${prefix}/include/ukui-sni-host
Name: ukui-sni-host
Description: ukui-sni-host header files
URL: https://www.ukui.org/
Version: @VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -lukui-sni-host ukui-sni/status-notifier-host/status-notifier-item-private.h 0000664 0001750 0001750 00000006073 15153755017 023313 0 ustar feng feng /*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*
*/
#ifndef UKUI_SNI_STATUS_NOTIFIER_ITEM_PRIVATE_H
#define UKUI_SNI_STATUS_NOTIFIER_ITEM_PRIVATE_H
#include
#include
#include "dbusmenu-importer.h"
#include "dbus-types.h"
#include "statusnotifieritem_interface.h"
namespace UkuiSni {
class UkuiDBusMenuImporter : public DBusMenuImporter
{
public:
UkuiDBusMenuImporter(const QString &service, const QString &path, QObject *parent = 0);
protected:
QIcon iconForName(const QString & iconName) override;
};
class StatusNotifierItemPrivate : public QObject
{
friend class StatusNotifierItem;
Q_OBJECT
public:
explicit StatusNotifierItemPrivate(const QString &service, StatusNotifierItem *q, QObject *parent = nullptr);
void init();
void contextMenu(int x, int y);
void activate(int x, int y);
void secondaryActivate(int x, int y);
void scroll(int delta, const QString &direction);
void provideXdgActivationToken(const QString &token);
private Q_SLOTS:
void refresh();
void performRefresh();
void syncStatus(const QString &status);
void refreshMenu();
void refreshCallback(QDBusPendingCallWatcher *call);
void activateCallback(QDBusPendingCallWatcher *call);
private:
QIcon loadIcon(const QVariantMap &properties, const QString &iconName, const QString &pixmapKey);
QPixmap DbusImageStructToPixmap(const DbusImageStruct &image) const;
QIcon imageVectorToPixmap(const DbusImageVector &vector) const;
static QString displayFormPid(int pid);
QTimer m_refreshTimer;
bool m_refreshing : 1;
bool m_needsReRefreshing : 1;
bool m_valid = false;
QString m_serviceNamePath;
QString m_serviceName;
UkuiDBusMenuImporter *m_menuImporter = nullptr;
int m_pendingMenuToShow = 0;
org::kde::StatusNotifierItem *m_statusNotifierItemInterface = nullptr;
QIcon m_attentionIcon;
QString m_attentionIconName;
QString m_attentionMovieName;
QString m_category;
QIcon m_icon;
QString m_iconName;
QString m_iconThemePath;
QString m_id;
bool m_itemIsMenu{};
QIcon m_overlayIcon;
QString m_overlayIconName;
QString m_status;
QString m_title;
QIcon m_toolTipIcon;
QString m_toolTipSubTitle;
QString m_toolTipTitle;
QString m_windowId;
QString m_display;
uint m_pid = 0;
StatusNotifierItem *q;
};
}
#endif //UKUI_SNI_STATUS_NOTIFIER_ITEM_PRIVATE_H
ukui-sni/status-notifier-host/status-notifier-item.cpp 0000664 0001750 0001750 00000037457 15153755611 022210 0 ustar feng feng /*
SPDX-FileCopyrightText: 2009 Marco Martin
SPDX-FileCopyrightText: 2009 Matthieu Gallien
SPDX-FileCopyrightText: 2023 iaom
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "status-notifier-item.h"
#include "status-notifier-item-private.h"
#include
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include
#else
#include
#endif
#include
#include
using namespace UkuiSni;
UkuiDBusMenuImporter::UkuiDBusMenuImporter(const QString &service, const QString &path, QObject *parent)
:DBusMenuImporter(service, path, parent)
{
}
QIcon UkuiDBusMenuImporter::iconForName(const QString &iconName)
{
return QIcon::fromTheme(iconName);
}
StatusNotifierItemPrivate::StatusNotifierItemPrivate(const QString &service, StatusNotifierItem *q, QObject *parent)
: QObject(parent)
, m_refreshing(false)
, m_needsReRefreshing(false)
, q(q)
{
m_serviceNamePath = service;
}
void StatusNotifierItemPrivate::init()
{
qDBusRegisterMetaType();
qDBusRegisterMetaType();
qDBusRegisterMetaType();
//service = service name + path(/StatusNotifierItem)
int slash = m_serviceNamePath.indexOf('/');
QString path;
if (slash == -1) {
m_serviceName = m_serviceNamePath;
path = QStringLiteral("/StatusNotifierItem");
} else {
m_serviceName = m_serviceNamePath.left(slash);
path = m_serviceNamePath.mid(slash);
}
m_display = displayFormPid(m_serviceNamePath.section("-", 1, 1).toInt());
m_statusNotifierItemInterface = new org::kde::StatusNotifierItem(m_serviceName, path, QDBusConnection::sessionBus());
m_refreshTimer.setSingleShot(true);
m_refreshTimer.setInterval(10);
connect(&m_refreshTimer, &QTimer::timeout, this, &StatusNotifierItemPrivate::performRefresh);
if (!m_serviceName.isEmpty() && m_statusNotifierItemInterface->isValid()) {
connect(m_statusNotifierItemInterface, &OrgKdeStatusNotifierItem::NewTitle, this, &StatusNotifierItemPrivate::refresh);
connect(m_statusNotifierItemInterface, &OrgKdeStatusNotifierItem::NewIcon, this, &StatusNotifierItemPrivate::refresh);
connect(m_statusNotifierItemInterface, &OrgKdeStatusNotifierItem::NewAttentionIcon, this, &StatusNotifierItemPrivate::refresh);
connect(m_statusNotifierItemInterface, &OrgKdeStatusNotifierItem::NewOverlayIcon, this, &StatusNotifierItemPrivate::refresh);
connect(m_statusNotifierItemInterface, &OrgKdeStatusNotifierItem::NewToolTip, this, &StatusNotifierItemPrivate::refresh);
connect(m_statusNotifierItemInterface, &OrgKdeStatusNotifierItem::NewStatus, this, &StatusNotifierItemPrivate::syncStatus);
connect(m_statusNotifierItemInterface, &OrgKdeStatusNotifierItem::NewMenu, this, &StatusNotifierItemPrivate::refreshMenu);
refresh();
} else {
qWarning() << "Invalid notifierItemService:" << m_serviceNamePath;
m_valid = false;
}
}
void StatusNotifierItemPrivate::contextMenu(int x, int y)
{
if (m_menuImporter) {
m_menuImporter->updateMenu();
m_pendingMenuToShow ++;
} else {
qWarning() << "DBusMenu interface not available, falling back to calling ContextMenu()";
if (m_statusNotifierItemInterface && m_statusNotifierItemInterface->isValid()) {
m_statusNotifierItemInterface->call(QDBus::NoBlock, QStringLiteral("ContextMenu"), x, y);
}
}
}
void StatusNotifierItemPrivate::activate(int x, int y)
{
if (m_statusNotifierItemInterface && m_statusNotifierItemInterface->isValid()) {
QDBusMessage message = QDBusMessage::createMethodCall(m_statusNotifierItemInterface->service(),
m_statusNotifierItemInterface->path(),
m_statusNotifierItemInterface->interface(),
QStringLiteral("Activate"));
message << x << y;
QDBusPendingCall call = m_statusNotifierItemInterface->connection().asyncCall(message);
auto *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &StatusNotifierItemPrivate::activateCallback);
}
}
void StatusNotifierItemPrivate::refresh()
{
if (!m_refreshTimer.isActive()) {
m_refreshTimer.start();
}
}
void StatusNotifierItemPrivate::performRefresh()
{
if (m_refreshing) {
m_needsReRefreshing = true;
return;
}
m_refreshing = true;
QDBusMessage message = QDBusMessage::createMethodCall(m_statusNotifierItemInterface->service(),
m_statusNotifierItemInterface->path(),
QStringLiteral("org.freedesktop.DBus.Properties"),
QStringLiteral("GetAll"));
message << m_statusNotifierItemInterface->interface();
QDBusPendingCall call = m_statusNotifierItemInterface->connection().asyncCall(message);
auto *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &StatusNotifierItemPrivate::refreshCallback);
}
void StatusNotifierItemPrivate::syncStatus(const QString &status)
{
m_status = status;
Q_EMIT q->dataUpdated();
}
void StatusNotifierItemPrivate::refreshMenu()
{
if (m_menuImporter) {
delete m_menuImporter;
m_menuImporter = nullptr;
}
refresh();
}
void StatusNotifierItemPrivate::refreshCallback(QDBusPendingCallWatcher *call)
{
m_refreshing = false;
if (m_needsReRefreshing) {
m_needsReRefreshing = false;
performRefresh();
call->deleteLater();
return;
}
QDBusPendingReply reply = *call;
if (reply.isError()) {
m_valid = false;
qDebug() << "Fail to refresh" << m_serviceName;
} else {
QVariantMap properties = reply.argumentAt<0>();
m_category = properties[QStringLiteral("Category")].toString();
m_id = properties[QStringLiteral("Id")].toString();
m_title = properties[QStringLiteral("Title")].toString();
m_status = properties[QStringLiteral("Status")].toString();
m_windowId = properties[QStringLiteral("WindowId")].toString();
m_itemIsMenu = properties[QStringLiteral("ItemIsMenu")].toBool();
m_attentionMovieName = properties[QStringLiteral("AttentionMovieName")].toString();
m_iconThemePath = properties[QStringLiteral("IconThemePath")].toString();
//TODO support overlayIcon
m_overlayIcon = loadIcon(properties, m_overlayIconName, QStringLiteral("OverlayIconPixmap"));
m_overlayIconName = properties[QStringLiteral("OverlayIconName")].toString();
m_iconName = properties[QStringLiteral("IconName")].toString();
m_icon = loadIcon(properties, m_iconName, QStringLiteral("IconPixmap"));
m_attentionIconName = properties[QStringLiteral("AttentionIconName")].toString();
m_attentionIcon = loadIcon(properties, m_attentionIconName, QStringLiteral("AttentionIconPixmap"));
DbusToolTipStruct toolTip;
properties[QStringLiteral("ToolTip")].value() >> toolTip;
if (toolTip.title.isEmpty()) {
m_toolTipTitle = QString();
m_toolTipSubTitle = QString();
m_toolTipIcon = QIcon();
} else {
QIcon toolTipIcon;
if (toolTip.image.empty()) {
toolTipIcon = QIcon::fromTheme(toolTip.icon);
} else {
toolTipIcon = imageVectorToPixmap(toolTip.image);
}
m_toolTipTitle = toolTip.title;
m_toolTipSubTitle = toolTip.subTitle;
if (toolTipIcon.isNull() || toolTipIcon.availableSizes().isEmpty()) {
m_toolTipIcon = QIcon();
} else {
m_toolTipIcon = toolTipIcon;
}
}
// Menu
if (!m_menuImporter) {
QString menuObjectPath = properties[QStringLiteral("Menu")].value().path();
if (!menuObjectPath.isEmpty()) {
if (menuObjectPath == QLatin1String("/NO_DBUSMENU")) {
qWarning() << "DBusMenu disabled for this item" << m_serviceNamePath;
} else {
m_menuImporter = new UkuiDBusMenuImporter(m_statusNotifierItemInterface->service(), menuObjectPath, this);
connect(m_menuImporter, &UkuiDBusMenuImporter::menuUpdated, this, [this](QMenu *menu) {
if(m_pendingMenuToShow && menu == m_menuImporter->menu()) {
--m_pendingMenuToShow;
Q_EMIT q->contextMenuReady(m_menuImporter->menu());
}
});
if (m_menuImporter->menu()) {
connect(m_menuImporter->menu(), &QMenu::aboutToShow, this, [this] {
Q_EMIT q->menuStateChange(true);
});
connect(m_menuImporter->menu(), &QMenu::aboutToHide, this, [this] {
Q_EMIT q->menuStateChange(false);
});
}
}
}
}
}
Q_EMIT q->dataUpdated();
call->deleteLater();
}
QIcon StatusNotifierItemPrivate::loadIcon(const QVariantMap &properties, const QString &iconName, const QString &pixmapKey)
{
if(!m_iconThemePath.isEmpty()) {
auto list = QIcon::fallbackSearchPaths();
list.append(m_iconThemePath);
list.removeDuplicates();
QIcon::setFallbackSearchPaths(list);
}
if(!iconName.isEmpty()) {
QIcon icon = QIcon::fromTheme(iconName);
if(!icon.isNull()) {
return icon;
}
}
DbusImageVector image;
properties[pixmapKey].value() >> image;
if(!image.isEmpty()) {
QIcon icon = imageVectorToPixmap(image);
if(!icon.isNull()) {
return icon;
}
}
return {};
}
QPixmap StatusNotifierItemPrivate::DbusImageStructToPixmap(const DbusImageStruct &image) const
{
// swap from network byte order if we are little endian
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
uint *uintBuf = (uint *)image.data.data();
for (uint i = 0; i < image.data.size() / sizeof(uint); ++i) {
*uintBuf = ntohl(*uintBuf);
++uintBuf;
}
}
if (image.width == 0 || image.height == 0) {
return {};
}
// avoid a deep copy of the image data
// we need to keep a reference to the image.data alive for the lifespan of the image, even if the image is copied
// we create a new QByteArray with a shallow copy of the original data on the heap, then delete this in the QImage cleanup
auto dataRef = new QByteArray(image.data);
QImage iconImage(
reinterpret_cast(dataRef->data()),
image.width,
image.height,
QImage::Format_ARGB32,
[](void *ptr) {
delete static_cast(ptr);
},
dataRef);
return QPixmap::fromImage(iconImage);
}
QIcon StatusNotifierItemPrivate::imageVectorToPixmap(const DbusImageVector &vector) const
{
QIcon icon;
for (const auto & i : vector) {
icon.addPixmap(DbusImageStructToPixmap(i));
}
return icon;
}
void StatusNotifierItemPrivate::activateCallback(QDBusPendingCallWatcher *call)
{
QDBusPendingReply reply = *call;
Q_EMIT q->activateResult(!reply.isError());
call->deleteLater();
}
void StatusNotifierItemPrivate::secondaryActivate(int x, int y)
{
if (m_statusNotifierItemInterface && m_statusNotifierItemInterface->isValid()) {
m_statusNotifierItemInterface->call(QDBus::NoBlock, QStringLiteral("SecondaryActivate"), x, y);
}
}
void StatusNotifierItemPrivate::scroll(int delta, const QString &direction)
{
if (m_statusNotifierItemInterface && m_statusNotifierItemInterface->isValid()) {
m_statusNotifierItemInterface->call(QDBus::NoBlock, QStringLiteral("Scroll"), delta, direction);
}
}
void StatusNotifierItemPrivate::provideXdgActivationToken(const QString &token)
{
if (m_statusNotifierItemInterface && m_statusNotifierItemInterface->isValid()) {
m_statusNotifierItemInterface->ProvideXdgActivationToken(token);
}
}
QString StatusNotifierItemPrivate::displayFormPid(int pid)
{
QFile environFile(QStringLiteral("/proc/%1/environ").arg(QString::number(pid)));
if (environFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
const QByteArray DISPLAY = QX11Info::isPlatformX11()? QByteArrayLiteral("DISPLAY") : QByteArrayLiteral("WAYLAND_DISPLAY");
const auto lines = environFile.readAll().split('\0');
for (const QByteArray &line : lines) {
const int equalsIdx = line.indexOf('=');
if (equalsIdx <= 0) {
continue;
}
const QByteArray key = line.left(equalsIdx);
if (key == DISPLAY) {
const QByteArray value = line.mid(equalsIdx + 1);
return value;
}
}
}
return {};
}
StatusNotifierItem::StatusNotifierItem(QObject *parent) : QObject(parent)
,d(new StatusNotifierItemPrivate({}, this, this))
{
}
StatusNotifierItem::StatusNotifierItem(const QString &service, QObject *parent): QObject(parent)
,d(new StatusNotifierItemPrivate(service, this, this))
{
d->init();
}
void StatusNotifierItem::setServiceName(const QString &service)
{
if(d) {
delete d;
}
d = new StatusNotifierItemPrivate(service, this, this);
d->init();
}
void StatusNotifierItem::setPid(const uint &pid)
{
d->m_pid = pid;
}
void StatusNotifierItem::contextMenu(int x, int y)
{
d->contextMenu(x, y);
}
void StatusNotifierItem::activate(int x, int y)
{
d->activate(x, y);
}
void StatusNotifierItem::secondaryActivate(int x, int y)
{
d->secondaryActivate(x, y);
}
void StatusNotifierItem::scroll(int delta, const QString &direction)
{
d->scroll(delta, direction);
}
void StatusNotifierItem::provideXdgActivationToken(const QString &token)
{
d->provideXdgActivationToken(token);
}
QString StatusNotifierItem::service()
{
return d->m_serviceName;
}
QIcon StatusNotifierItem::attentionIcon() const
{
return d->m_attentionIcon;
}
QString StatusNotifierItem::attentionIconName() const
{
return d->m_attentionIconName;
}
QString StatusNotifierItem::attentionMovieName() const
{
return d->m_attentionMovieName;
}
QString StatusNotifierItem::category() const
{
return d->m_category;
}
QIcon StatusNotifierItem::icon() const
{
return d->m_icon;
}
QString StatusNotifierItem::iconName() const
{
return d->m_iconName;
}
QString StatusNotifierItem::id() const
{
return d->m_id;
}
bool StatusNotifierItem::itemIsMenu() const
{
return d->m_itemIsMenu;
}
QIcon StatusNotifierItem::overlayIcon() const
{
return d->m_overlayIcon;
}
QString StatusNotifierItem::overlayIconName() const
{
return d->m_overlayIconName;
}
QString StatusNotifierItem::status() const
{
return d->m_status;
}
QString StatusNotifierItem::title() const
{
return d->m_title;
}
QVariant StatusNotifierItem::toolTipIcon() const
{
return d->m_toolTipIcon;
}
QString StatusNotifierItem::toolTipSubTitle() const
{
return d->m_toolTipSubTitle;
}
QString StatusNotifierItem::toolTipTitle() const
{
return d->m_toolTipTitle;
}
QString StatusNotifierItem::windowId() const
{
return d->m_windowId;
}
QString StatusNotifierItem::display() const
{
return d->m_display;
}
uint StatusNotifierItem::pid() const
{
return d->m_pid;
}
QString StatusNotifierItem::iconThemePath() const
{
return d->m_iconThemePath;
}
ukui-sni/status-notifier-host/CMakeLists.txt 0000664 0001750 0001750 00000010165 15153755611 020133 0 ustar feng feng project(ukui-sni-host VERSION 1.0 LANGUAGES C CXX)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_MICRO 0)
set(UKUI_SNI_HOST_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO})
include_directories(../common)
set(ukui-sni-host_LIB_SRCS
status-notifier-host.cpp
../common/dbus-types.cpp
status-notifier-item.cpp
status-notifier-item-private.h
libdbusmenu-qt/dbusmenu-importer.cpp
libdbusmenu-qt/dbusmenu-importer.h
libdbusmenu-qt/dbusmenu-shortcut_p.cpp
libdbusmenu-qt/dbusmenu-shortcut_p.h
libdbusmenu-qt/dbusmenu-types_p.cpp
libdbusmenu-qt/dbusmenu-types_p.h
libdbusmenu-qt/utils.cpp
libdbusmenu-qt/utils_p.h
)
set(HEADERS
status-notifier-host.h
status-notifier-item.h
)
set(statusnotifierwatcher_xml ../dbus/org.kde.StatusNotifierWatcher.xml)
set_source_files_properties(${statusnotifierwatcher_xml} PROPERTIES
NO_NAMESPACE false
INCLUDE "../common/dbus-types.h"
)
qt_add_dbus_interface(ukui-sni-host_LIB_SRCS ${statusnotifierwatcher_xml} statusnotifierwatcher_interface)
qt_add_dbus_interface(ukui-sni-host_LIB_SRCS ../dbus/org.freedesktop.DBus.Properties.xml dbusproperties)
set(statusnotifieritem_xml ../dbus/org.kde.StatusNotifierItem.xml)
set_source_files_properties(${statusnotifieritem_xml} PROPERTIES
NO_NAMESPACE false
INCLUDE "../common/dbus-types.h"
CLASSNAME OrgKdeStatusNotifierItem
)
qt_add_dbus_interface(ukui-sni-host_LIB_SRCS ${statusnotifieritem_xml} statusnotifieritem_interface)
set_source_files_properties(libdbusmenu-qt/com.canonical.dbusmenu.xml PROPERTIES
NO_NAMESPACE true
INCLUDE "dbusmenu-types_p.h"
CLASSNAME DBusMenuInterface
)
qt_add_dbus_interface(ukui-sni-host_LIB_SRCS libdbusmenu-qt/com.canonical.dbusmenu.xml dbusmenu_interface)
include_directories(../common libdbusmenu-qt)
add_library(${PROJECT_NAME} SHARED ${ukui-sni-host_LIB_SRCS})
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${UKUI_SNI_HOST_VERSION}
SOVERSION ${VERSION_MAJOR}
OUTPUT_NAME ${PROJECT_NAME}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
)
if (QT_VERSION_MAJOR EQUAL 5)
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt5::X11Extras
)
elseif(QT_VERSION_MAJOR EQUAL 6)
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt6::GuiPrivate
)
endif()
include(CMakePackageConfigHelpers)
set(CMAKE_CONFIG_INSTALL_DIR "/usr/share/cmake/ukui-sni-host")
set(HEADERS_INSTALL_DIR /usr/include/ukui-sni-host)
set(PC_INSTALL_DIR "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig")
target_include_directories(${PROJECT_NAME} PUBLIC $)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/ukui-sni-host-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/ukui-sni-host-config.cmake"
INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR})
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/ukui-sni-host-config-version.cmake
VERSION ${LIBUKUI_SEARCH_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/ukui-sni-host.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/ukui-sni-host.pc"
INSTALL_DESTINATION ${PC_INSTALL_DIR})
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}
PUBLIC_HEADER DESTINATION ${HEADERS_INSTALL_DIR}
LIBRARY DESTINATION /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
)
install(EXPORT ${PROJECT_NAME}
FILE ${PROJECT_NAME}-targets.cmake
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR})
install(FILES ${HEADERS} DESTINATION ${HEADERS_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/ukui-sni-host.pc DESTINATION ${PC_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ukui-sni-host-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/ukui-sni-host-config-version.cmake
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR})
ukui-sni/status-notifier-host/status-notifier-item.h 0000664 0001750 0001750 00000004503 15153755017 021637 0 ustar feng feng /*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*
*/
#ifndef UKUI_SNI_STATUS_NOTIFIER_ITEM_H
#define UKUI_SNI_STATUS_NOTIFIER_ITEM_H
#include
#include
namespace UkuiSni {
class StatusNotifierItemPrivate;
class StatusNotifierItem: public QObject
{
Q_OBJECT
public:
explicit StatusNotifierItem(QObject *parent = nullptr);
explicit StatusNotifierItem(const QString &service, QObject *parent = nullptr);
Q_DISABLE_COPY(StatusNotifierItem)
//service name + path
void setServiceName(const QString &service);
void setPid(const uint &pid);
void contextMenu(int x, int y);
void activate(int x, int y);
void secondaryActivate(int x, int y);
void scroll(int delta, const QString &direction);
void provideXdgActivationToken(const QString &token);
QString service();
QIcon attentionIcon() const;
QString attentionIconName() const;
QString attentionMovieName() const;
QString category() const;
QIcon icon() const;
QString iconName() const;
QString iconThemePath() const;
QString id() const;
bool itemIsMenu() const;
QIcon overlayIcon() const;
QString overlayIconName() const;
QString status() const;
QString title() const;
QVariant toolTipIcon() const;
QString toolTipSubTitle() const;
QString toolTipTitle() const;
QString windowId() const;
QString display() const;
uint pid() const;
Q_SIGNALS:
void contextMenuReady(QMenu *menu);
void activateResult(bool success);
void dataUpdated();
void menuStateChange(bool state);
private:
StatusNotifierItemPrivate *d = nullptr;
};
}
#endif //UKUI_SNI_STATUS_NOTIFIER_ITEM_H
ukui-sni/status-notifier-host/ukui-sni-host-config.cmake.in 0000664 0001750 0001750 00000000411 15153755017 022755 0 ustar feng feng @PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(Qt@QT_VERSION_MAJOR@Core)
find_dependency(Qt@QT_VERSION_MAJOR@Widgets)
if(TARGET Qt6::Core)
find_dependency(Qt6Core5Compat)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/ukui-sni-host-targets.cmake") ukui-sni/status-notifier-host/libdbusmenu-qt/ 0000775 0001750 0001750 00000000000 15153755017 020323 5 ustar feng feng ukui-sni/status-notifier-host/libdbusmenu-qt/com.canonical.dbusmenu.xml 0000664 0001750 0001750 00000004171 15153755017 025375 0 ustar feng feng
ukui-sni/status-notifier-host/libdbusmenu-qt/dbusmenu-shortcut_p.cpp 0000664 0001750 0001750 00000004700 15153755017 025042 0 ustar feng feng /* This file is part of the dbusmenu-qt library
SPDX-FileCopyrightText: 2009 Canonical
SPDX-FileContributor: Aurelien Gateau
SPDX-FileContributor: iaom
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "dbusmenu-shortcut_p.h"
// Qt
#include
static const int QT_COLUMN = 0;
static const int DM_COLUMN = 1;
static void processKeyTokens(QStringList *tokens, int srcCol, int dstCol)
{
struct Row {
const char *zero;
const char *one;
const char *operator[](int col) const
{
return col == 0 ? zero : one;
}
};
static const Row table[] = {{"Meta", "Super"},
{"Ctrl", "Control"},
// Special cases for compatibility with libdbusmenu-glib which uses
// "plus" for "+" and "minus" for "-".
// cf https://bugs.launchpad.net/libdbusmenu-qt/+bug/712565
{"+", "plus"},
{"-", "minus"},
{nullptr, nullptr}};
const Row *ptr = table;
for (; ptr->zero != nullptr; ++ptr) {
const char *from = (*ptr)[srcCol];
const char *to = (*ptr)[dstCol];
tokens->replaceInStrings(from, to);
}
}
DBusMenuShortcut DBusMenuShortcut::fromKeySequence(const QKeySequence &sequence)
{
QString string = sequence.toString();
DBusMenuShortcut shortcut;
QStringList tokens = string.split(QStringLiteral(", "));
Q_FOREACH (QString token, tokens) {
// Hack: Qt::CTRL | Qt::Key_Plus is turned into the string "Ctrl++",
// but we don't want the call to token.split() to consider the
// second '+' as a separator so we replace it with its final value.
token.replace(QLatin1String("++"), QLatin1String("+plus"));
QStringList keyTokens = token.split('+');
processKeyTokens(&keyTokens, QT_COLUMN, DM_COLUMN);
shortcut << keyTokens;
}
return shortcut;
}
QKeySequence DBusMenuShortcut::toKeySequence() const
{
QStringList tmp;
Q_FOREACH (const QStringList &keyTokens_, *this) {
QStringList keyTokens = keyTokens_;
processKeyTokens(&keyTokens, DM_COLUMN, QT_COLUMN);
tmp << keyTokens.join(QLatin1String("+"));
}
QString string = tmp.join(QLatin1String(", "));
return QKeySequence::fromString(string);
}
ukui-sni/status-notifier-host/libdbusmenu-qt/dbusmenu-importer.h 0000664 0001750 0001750 00000004724 15153755017 024164 0 ustar feng feng /* This file is part of the dbusmenu-qt library
SPDX-FileCopyrightText: 2009 Canonical
SPDX-FileContributor: Aurelien Gateau
SPDX-FileContributor: iaom
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
// Qt
#include
class QAction;
class QDBusPendingCallWatcher;
class QIcon;
class QMenu;
class DBusMenuImporterPrivate;
/**
* A DBusMenuImporter instance can recreate a menu serialized over DBus by
* DBusMenuExporter
*/
class DBusMenuImporter : public QObject
{
Q_OBJECT
public:
/**
* Creates a DBusMenuImporter listening over DBus on service, path
*/
DBusMenuImporter(const QString &service, const QString &path, QObject *parent = nullptr);
~DBusMenuImporter() override;
QAction *actionForId(int id) const;
/**
* The menu created from listening to the DBusMenuExporter over DBus
*/
QMenu *menu() const;
public Q_SLOTS:
/**
* Load the menu
*
* Will Q_EMIT menuUpdated() when complete.
* This should be done before showing a menu
*/
void updateMenu();
void updateMenu(QMenu *menu);
Q_SIGNALS:
/**
* Emitted after a call to updateMenu().
* @see updateMenu()
*/
void menuUpdated(QMenu *menu);
/**
* Emitted when the exporter was asked to activate an action
*/
void actionActivationRequested(QAction *);
protected:
/**
* Must create a menu, may be customized to fit host appearance.
* Default implementation creates a simple QMenu.
*/
virtual QMenu *createMenu(QWidget *parent);
/**
* Must convert a name into an icon.
* Default implementation returns a null icon.
*/
virtual QIcon iconForName(const QString &);
private Q_SLOTS:
void sendClickedEvent(int);
void slotMenuAboutToShow();
void slotMenuAboutToHide();
void slotAboutToShowDBusCallFinished(QDBusPendingCallWatcher *);
void slotItemActivationRequested(int id, uint timestamp);
void processPendingLayoutUpdates();
void slotLayoutUpdated(uint revision, int parentId);
void slotGetLayoutFinished(QDBusPendingCallWatcher *);
private:
Q_DISABLE_COPY(DBusMenuImporter)
DBusMenuImporterPrivate *const d;
friend class DBusMenuImporterPrivate;
// Use Q_PRIVATE_SLOT to avoid exposing DBusMenuItemList
Q_PRIVATE_SLOT(d, void slotItemsPropertiesUpdated(const DBusMenuItemList &updatedList, const DBusMenuItemKeysList &removedList))
};
ukui-sni/status-notifier-host/libdbusmenu-qt/dbusmenu-types_p.cpp 0000664 0001750 0001750 00000006625 15153755017 024343 0 ustar feng feng /* This file is part of the dbusmenu-qt library
SPDX-FileCopyrightText: 2009 Canonical
SPDX-FileContributor: Aurelien Gateau
SPDX-FileContributor: iaom
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "dbusmenu-types_p.h"
// Local
#include "dbusmenu-shortcut_p.h"
// Qt
#include
#include
//// DBusMenuItem
QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItem &obj)
{
argument.beginStructure();
argument << obj.id << obj.properties;
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuItem &obj)
{
argument.beginStructure();
argument >> obj.id >> obj.properties;
argument.endStructure();
return argument;
}
//// DBusMenuItemKeys
QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItemKeys &obj)
{
argument.beginStructure();
argument << obj.id << obj.properties;
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuItemKeys &obj)
{
argument.beginStructure();
argument >> obj.id >> obj.properties;
argument.endStructure();
return argument;
}
//// DBusMenuLayoutItem
QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuLayoutItem &obj)
{
argument.beginStructure();
argument << obj.id << obj.properties;
argument.beginArray(qMetaTypeId());
Q_FOREACH (const DBusMenuLayoutItem &child, obj.children) {
argument << QDBusVariant(QVariant::fromValue(child));
}
argument.endArray();
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuLayoutItem &obj)
{
argument.beginStructure();
argument >> obj.id >> obj.properties;
argument.beginArray();
while (!argument.atEnd()) {
QDBusVariant dbusVariant;
argument >> dbusVariant;
QDBusArgument childArgument = dbusVariant.variant().value();
DBusMenuLayoutItem child;
childArgument >> child;
obj.children.append(child);
}
argument.endArray();
argument.endStructure();
return argument;
}
//// DBusMenuShortcut
QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuShortcut &obj)
{
argument.beginArray(qMetaTypeId());
typename QList::ConstIterator it = obj.constBegin();
typename QList::ConstIterator end = obj.constEnd();
for (; it != end; ++it)
argument << *it;
argument.endArray();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuShortcut &obj)
{
argument.beginArray();
obj.clear();
while (!argument.atEnd()) {
QStringList item;
argument >> item;
obj.push_back(item);
}
argument.endArray();
return argument;
}
void DBusMenuTypes_register()
{
static bool registered = false;
if (registered) {
return;
}
qDBusRegisterMetaType();
qDBusRegisterMetaType();
qDBusRegisterMetaType();
qDBusRegisterMetaType();
qDBusRegisterMetaType();
qDBusRegisterMetaType();
qDBusRegisterMetaType();
registered = true;
}
ukui-sni/status-notifier-host/libdbusmenu-qt/dbusmenu-shortcut_p.h 0000664 0001750 0001750 00000001070 15153755017 024504 0 ustar feng feng /* This file is part of the dbusmenu-qt library
SPDX-FileCopyrightText: 2009 Canonical
SPDX-FileContributor: Aurelien Gateau
SPDX-FileContributor: iaom
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
// Qt
#include
#include
class QKeySequence;
class DBusMenuShortcut : public QList
{
public:
QKeySequence toKeySequence() const;
static DBusMenuShortcut fromKeySequence(const QKeySequence &);
};
Q_DECLARE_METATYPE(DBusMenuShortcut)
ukui-sni/status-notifier-host/libdbusmenu-qt/dbusmenu-types_p.h 0000664 0001750 0001750 00000004004 15153755017 023775 0 ustar feng feng /* This file is part of the dbusmenu-qt library
SPDX-FileCopyrightText: 2009 Canonical
SPDX-FileContributor: Aurelien Gateau
SPDX-FileContributor: iaom
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
// Qt
#include
#include
#include
class QDBusArgument;
//// DBusMenuItem
/**
* Internal struct used to communicate on DBus
*/
struct DBusMenuItem {
int id;
QVariantMap properties;
};
Q_DECLARE_METATYPE(DBusMenuItem)
QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItem &item);
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuItem &item);
typedef QList DBusMenuItemList;
Q_DECLARE_METATYPE(DBusMenuItemList)
//// DBusMenuItemKeys
/**
* Represents a list of keys for a menu item
*/
struct DBusMenuItemKeys {
int id;
QStringList properties;
};
Q_DECLARE_METATYPE(DBusMenuItemKeys)
QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItemKeys &);
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuItemKeys &);
typedef QList DBusMenuItemKeysList;
Q_DECLARE_METATYPE(DBusMenuItemKeysList)
//// DBusMenuLayoutItem
/**
* Represents an item with its children. GetLayout() returns a
* DBusMenuLayoutItemList.
*/
struct DBusMenuLayoutItem;
struct DBusMenuLayoutItem {
int id;
QVariantMap properties;
QList children;
};
Q_DECLARE_METATYPE(DBusMenuLayoutItem)
QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuLayoutItem &);
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuLayoutItem &);
typedef QList DBusMenuLayoutItemList;
Q_DECLARE_METATYPE(DBusMenuLayoutItemList)
//// DBusMenuShortcut
class DBusMenuShortcut;
QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuShortcut &);
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuShortcut &);
void DBusMenuTypes_register(); ukui-sni/status-notifier-host/libdbusmenu-qt/utils.cpp 0000664 0001750 0001750 00000002561 15153755017 022173 0 ustar feng feng /* This file is part of the dbusmenu-qt library
SPDX-FileCopyrightText: 2010 Canonical
SPDX-FileContributor: Aurelien Gateau
SPDX-FileContributor: iaom
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "utils_p.h"
// Qt
#include
QString swapMnemonicChar(const QString &in, const char src, const char dst)
{
QString out;
bool mnemonicFound = false;
for (int pos = 0; pos < in.length();) {
QChar ch = in[pos];
if (ch == src) {
if (pos == in.length() - 1) {
// 'src' at the end of string, skip it
++pos;
} else {
if (in[pos + 1] == src) {
// A real 'src'
out += src;
pos += 2;
} else if (!mnemonicFound) {
// We found the mnemonic
mnemonicFound = true;
out += dst;
++pos;
} else {
// We already have a mnemonic, just skip the char
++pos;
}
}
} else if (ch == dst) {
// Escape 'dst'
out += dst;
out += dst;
++pos;
} else {
out += ch;
++pos;
}
}
return out;
}
ukui-sni/status-notifier-host/libdbusmenu-qt/utils_p.h 0000664 0001750 0001750 00000000700 15153755017 022150 0 ustar feng feng /* This file is part of the dbusmenu-qt library
SPDX-FileCopyrightText: 2010 Canonical
SPDX-FileContributor: Aurelien Gateau
SPDX-FileContributor: iaom
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
class QString;
/**
* Swap mnemonic char: Qt uses '&', while dbusmenu uses '_'
*/
QString swapMnemonicChar(const QString &in, const char src, const char dst);
ukui-sni/status-notifier-host/libdbusmenu-qt/dbusmenu-importer.cpp 0000664 0001750 0001750 00000040722 15153755017 024515 0 ustar feng feng /* This file is part of the dbusmenu-qt library
SPDX-FileCopyrightText: 2009 Canonical
SPDX-FileContributor: Aurelien Gateau
SPDX-FileContributor: iaom
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "dbusmenu-importer.h"
// Qt
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
// Local
#include "dbusmenu-shortcut_p.h"
#include "dbusmenu-types_p.h"
#include "utils_p.h"
// Generated
#include "dbusmenu_interface.h"
//#define BENCHMARK
#ifdef BENCHMARK
static QTime sChrono;
#endif
#define DMRETURN_IF_FAIL(cond) \
if (!(cond)) { \
qWarning() << "Condition failed: " #cond; \
return; \
}
static const char *DBUSMENU_PROPERTY_ID = "_dbusmenu_id";
static const char *DBUSMENU_PROPERTY_ICON_NAME = "_dbusmenu_icon_name";
static const char *DBUSMENU_PROPERTY_ICON_DATA_HASH = "_dbusmenu_icon_data_hash";
static QAction *createKdeTitle(QAction *action, QWidget *parent)
{
QToolButton *titleWidget = new QToolButton(nullptr);
QFont font = titleWidget->font();
font.setBold(true);
titleWidget->setFont(font);
titleWidget->setIcon(action->icon());
titleWidget->setText(action->text());
titleWidget->setDown(true);
titleWidget->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
QWidgetAction *titleAction = new QWidgetAction(parent);
titleAction->setDefaultWidget(titleWidget);
return titleAction;
}
class DBusMenuImporterPrivate
{
public:
DBusMenuImporter *q;
DBusMenuInterface *m_interface;
QMenu *m_menu;
using ActionForId = QMap>;
ActionForId m_actionForId;
QTimer *m_pendingLayoutUpdateTimer;
QSet m_idsRefreshedByAboutToShow;
QSet m_pendingLayoutUpdates;
QDBusPendingCallWatcher *refresh(int id)
{
auto call = m_interface->GetLayout(id, 1, QStringList());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, q);
watcher->setProperty(DBUSMENU_PROPERTY_ID, id);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, q, &DBusMenuImporter::slotGetLayoutFinished);
return watcher;
}
QMenu *createMenu(QWidget *parent)
{
QMenu *menu = q->createMenu(parent);
return menu;
}
/**
* Init all the immutable action properties here
* TODO: Document immutable properties?
*
* Note: we remove properties we handle from the map (using QMap::take()
* instead of QMap::value()) to avoid warnings about these properties in
* updateAction()
*/
QAction *createAction(int id, const QVariantMap &_map, QWidget *parent)
{
QVariantMap map = _map;
QAction *action = new QAction(parent);
action->setProperty(DBUSMENU_PROPERTY_ID, id);
QString type = map.take(QStringLiteral("type")).toString();
if (type == QLatin1String("separator")) {
action->setSeparator(true);
}
if (map.take(QStringLiteral("children-display")).toString() == QLatin1String("submenu")) {
QMenu *menu = createMenu(parent);
action->setMenu(menu);
}
QString toggleType = map.take(QStringLiteral("toggle-type")).toString();
if (!toggleType.isEmpty()) {
action->setCheckable(true);
if (toggleType == QLatin1String("radio")) {
QActionGroup *group = new QActionGroup(action);
group->addAction(action);
}
}
bool isKdeTitle = map.take(QStringLiteral("x-kde-title")).toBool();
updateAction(action, map, map.keys());
if (isKdeTitle) {
action = createKdeTitle(action, parent);
}
return action;
}
/**
* Update mutable properties of an action. A property may be listed in
* requestedProperties but not in map, this means we should use the default value
* for this property.
*
* @param action the action to update
* @param map holds the property values
* @param requestedProperties which properties has been requested
*/
void updateAction(QAction *action, const QVariantMap &map, const QStringList &requestedProperties)
{
Q_FOREACH (const QString &key, requestedProperties) {
updateActionProperty(action, key, map.value(key));
}
}
void updateActionProperty(QAction *action, const QString &key, const QVariant &value)
{
if (key == QLatin1String("label")) {
updateActionLabel(action, value);
} else if (key == QLatin1String("enabled")) {
updateActionEnabled(action, value);
} else if (key == QLatin1String("toggle-state")) {
updateActionChecked(action, value);
} else if (key == QLatin1String("icon-name")) {
updateActionIconByName(action, value);
} else if (key == QLatin1String("icon-data")) {
updateActionIconByData(action, value);
} else if (key == QLatin1String("visible")) {
updateActionVisible(action, value);
} else if (key == QLatin1String("shortcut")) {
updateActionShortcut(action, value);
} else {
qDebug() << "Unhandled property update" << key;
}
}
void updateActionLabel(QAction *action, const QVariant &value)
{
QString text = swapMnemonicChar(value.toString(), '_', '&');
action->setText(text);
}
void updateActionEnabled(QAction *action, const QVariant &value)
{
action->setEnabled(value.isValid() ? value.toBool() : true);
}
void updateActionChecked(QAction *action, const QVariant &value)
{
if (action->isCheckable() && value.isValid()) {
action->setChecked(value.toInt() == 1);
}
}
void updateActionIconByName(QAction *action, const QVariant &value)
{
const QString iconName = value.toString();
const QString previous = action->property(DBUSMENU_PROPERTY_ICON_NAME).toString();
if (previous == iconName) {
return;
}
action->setProperty(DBUSMENU_PROPERTY_ICON_NAME, iconName);
if (iconName.isEmpty()) {
action->setIcon(QIcon());
return;
}
action->setIcon(q->iconForName(iconName));
}
void updateActionIconByData(QAction *action, const QVariant &value)
{
const QByteArray data = value.toByteArray();
uint dataHash = qHash(data);
uint previousDataHash = action->property(DBUSMENU_PROPERTY_ICON_DATA_HASH).toUInt();
if (previousDataHash == dataHash) {
return;
}
action->setProperty(DBUSMENU_PROPERTY_ICON_DATA_HASH, dataHash);
QPixmap pix;
if (!pix.loadFromData(data)) {
qDebug() << "Failed to decode icon-data property for action" << action->text();
action->setIcon(QIcon());
return;
}
action->setIcon(QIcon(pix));
}
void updateActionVisible(QAction *action, const QVariant &value)
{
action->setVisible(value.isValid() ? value.toBool() : true);
}
void updateActionShortcut(QAction *action, const QVariant &value)
{
QDBusArgument arg = value.value();
DBusMenuShortcut dmShortcut;
arg >> dmShortcut;
QKeySequence keySequence = dmShortcut.toKeySequence();
action->setShortcut(keySequence);
}
QMenu *menuForId(int id) const
{
if (id == 0) {
return q->menu();
}
QAction *action = m_actionForId.value(id);
if (!action) {
return nullptr;
}
return action->menu();
}
void slotItemsPropertiesUpdated(const DBusMenuItemList &updatedList, const DBusMenuItemKeysList &removedList);
void sendEvent(int id, const QString &eventId)
{
m_interface->Event(id, eventId, QDBusVariant(QString()), 0u);
}
};
DBusMenuImporter::DBusMenuImporter(const QString &service, const QString &path, QObject *parent)
: QObject(parent)
, d(new DBusMenuImporterPrivate)
{
DBusMenuTypes_register();
d->q = this;
d->m_interface = new DBusMenuInterface(service, path, QDBusConnection::sessionBus(), this);
d->m_menu = nullptr;
d->m_pendingLayoutUpdateTimer = new QTimer(this);
d->m_pendingLayoutUpdateTimer->setSingleShot(true);
connect(d->m_pendingLayoutUpdateTimer, &QTimer::timeout, this, &DBusMenuImporter::processPendingLayoutUpdates);
connect(d->m_interface, &DBusMenuInterface::LayoutUpdated, this, &DBusMenuImporter::slotLayoutUpdated);
connect(d->m_interface, &DBusMenuInterface::ItemActivationRequested, this, &DBusMenuImporter::slotItemActivationRequested);
connect(d->m_interface,
&DBusMenuInterface::ItemsPropertiesUpdated,
this,
[this](const DBusMenuItemList &updatedList, const DBusMenuItemKeysList &removedList) {
d->slotItemsPropertiesUpdated(updatedList, removedList);
});
d->refresh(0);
}
DBusMenuImporter::~DBusMenuImporter()
{
// Do not use "delete d->m_menu": even if we are being deleted we should
// leave enough time for the menu to finish what it was doing, for example
// if it was being displayed.
d->m_menu->deleteLater();
delete d;
}
void DBusMenuImporter::slotLayoutUpdated(uint revision, int parentId)
{
Q_UNUSED(revision)
if (d->m_idsRefreshedByAboutToShow.remove(parentId)) {
return;
}
d->m_pendingLayoutUpdates << parentId;
if (!d->m_pendingLayoutUpdateTimer->isActive()) {
d->m_pendingLayoutUpdateTimer->start();
}
}
void DBusMenuImporter::processPendingLayoutUpdates()
{
QSet ids = d->m_pendingLayoutUpdates;
d->m_pendingLayoutUpdates.clear();
Q_FOREACH (int id, ids) {
d->refresh(id);
}
}
QMenu *DBusMenuImporter::menu() const
{
if (!d->m_menu) {
d->m_menu = d->createMenu(nullptr);
}
return d->m_menu;
}
void DBusMenuImporterPrivate::slotItemsPropertiesUpdated(const DBusMenuItemList &updatedList, const DBusMenuItemKeysList &removedList)
{
Q_FOREACH (const DBusMenuItem &item, updatedList) {
QAction *action = m_actionForId.value(item.id);
if (!action) {
// We don't know this action. It probably is in a menu we haven't fetched yet.
continue;
}
QVariantMap::ConstIterator it = item.properties.constBegin(), end = item.properties.constEnd();
for (; it != end; ++it) {
updateActionProperty(action, it.key(), it.value());
}
}
Q_FOREACH (const DBusMenuItemKeys &item, removedList) {
QAction *action = m_actionForId.value(item.id);
if (!action) {
// We don't know this action. It probably is in a menu we haven't fetched yet.
continue;
}
Q_FOREACH (const QString &key, item.properties) {
updateActionProperty(action, key, QVariant());
}
}
}
QAction *DBusMenuImporter::actionForId(int id) const
{
return d->m_actionForId.value(id);
}
void DBusMenuImporter::slotItemActivationRequested(int id, uint /*timestamp*/)
{
QAction *action = d->m_actionForId.value(id);
DMRETURN_IF_FAIL(action);
actionActivationRequested(action);
}
void DBusMenuImporter::slotGetLayoutFinished(QDBusPendingCallWatcher *watcher)
{
int parentId = watcher->property(DBUSMENU_PROPERTY_ID).toInt();
watcher->deleteLater();
QMenu *menu = d->menuForId(parentId);
QDBusPendingReply reply = *watcher;
if (!reply.isValid()) {
qDebug() << reply.error().message();
if (menu) {
Q_EMIT menuUpdated(menu);
}
return;
}
#ifdef BENCHMARK
DMDEBUG << "- items received:" << sChrono.elapsed() << "ms";
#endif
DBusMenuLayoutItem rootItem = reply.argumentAt<1>();
if (!menu) {
qDebug() << "No menu for id" << parentId;
return;
}
// remove outdated actions
QSet newDBusMenuItemIds;
newDBusMenuItemIds.reserve(rootItem.children.count());
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
for (const DBusMenuLayoutItem &item : qAsConst(rootItem.children)) {
#else
for (const DBusMenuLayoutItem &item : std::as_const(rootItem.children)) {
#endif
newDBusMenuItemIds << item.id;
}
for (QAction *action : menu->actions()) {
int id = action->property(DBUSMENU_PROPERTY_ID).toInt();
if (!newDBusMenuItemIds.contains(id)) {
d->m_actionForId.remove(id);
}
}
menu->clear();
// insert or update new actions into our menu
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
for (const DBusMenuLayoutItem &dbusMenuItem : qAsConst(rootItem.children)) {
#else
for (const DBusMenuLayoutItem &dbusMenuItem : std::as_const(rootItem.children)) {
#endif
DBusMenuImporterPrivate::ActionForId::Iterator it = d->m_actionForId.find(dbusMenuItem.id);
int id = dbusMenuItem.id;
auto action = d->createAction(id, dbusMenuItem.properties, menu);
if (it == d->m_actionForId.end()) {
d->m_actionForId.insert(id, action);
} else {
delete *it;
*it = action;
}
connect(action, &QAction::triggered, this, [id, this]() {
sendClickedEvent(id);
});
if (QMenu *menuAction = action->menu()) {
connect(menuAction, &QMenu::aboutToShow, this, &DBusMenuImporter::slotMenuAboutToShow, Qt::UniqueConnection);
updateMenu(menuAction);
}
connect(menu, &QMenu::aboutToHide, this, &DBusMenuImporter::slotMenuAboutToHide, Qt::UniqueConnection);
menu->addAction(action);
}
Q_EMIT menuUpdated(menu);
}
void DBusMenuImporter::sendClickedEvent(int id)
{
d->sendEvent(id, QStringLiteral("clicked"));
}
void DBusMenuImporter::updateMenu()
{
updateMenu(DBusMenuImporter::menu());
}
void DBusMenuImporter::updateMenu(QMenu *menu)
{
Q_ASSERT(menu);
QAction *action = menu->menuAction();
Q_ASSERT(action);
int id = action->property(DBUSMENU_PROPERTY_ID).toInt();
auto call = d->m_interface->AboutToShow(id);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
watcher->setProperty(DBUSMENU_PROPERTY_ID, id);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &DBusMenuImporter::slotAboutToShowDBusCallFinished);
// Firefox deliberately ignores "aboutToShow" whereas Qt ignores" opened", so we'll just send both all the time...
d->sendEvent(id, QStringLiteral("opened"));
}
void DBusMenuImporter::slotAboutToShowDBusCallFinished(QDBusPendingCallWatcher *watcher)
{
int id = watcher->property(DBUSMENU_PROPERTY_ID).toInt();
watcher->deleteLater();
QMenu *menu = d->menuForId(id);
if (!menu) {
return;
}
QDBusPendingReply reply = *watcher;
if (reply.isError()) {
qDebug() << "Call to AboutToShow() failed:" << reply.error().message();
Q_EMIT menuUpdated(menu);
return;
}
// Note, this isn't used by Qt's QPT - but we get a LayoutChanged emitted before
// this returns, which equates to the same thing
bool needRefresh = reply.argumentAt<0>();
if (needRefresh || menu->actions().isEmpty()) {
d->m_idsRefreshedByAboutToShow << id;
d->refresh(id);
} else {
Q_EMIT menuUpdated(menu);
}
}
void DBusMenuImporter::slotMenuAboutToHide()
{
QMenu *menu = qobject_cast(sender());
Q_ASSERT(menu);
QAction *action = menu->menuAction();
Q_ASSERT(action);
int id = action->property(DBUSMENU_PROPERTY_ID).toInt();
d->sendEvent(id, QStringLiteral("closed"));
}
void DBusMenuImporter::slotMenuAboutToShow()
{
QMenu *menu = qobject_cast(sender());
Q_ASSERT(menu);
updateMenu(menu);
}
QMenu *DBusMenuImporter::createMenu(QWidget *parent)
{
return new QMenu(parent);
}
QIcon DBusMenuImporter::iconForName(const QString & /*name*/)
{
return QIcon();
}
#include "moc_dbusmenu-importer.cpp"
ukui-sni/status-notifier-host/status-notifier-host.cpp 0000664 0001750 0001750 00000023337 15153755017 022217 0 ustar feng feng /*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*
*/
#include
#include
#include "status-notifier-host.h"
#include "status-notifier-item.h"
#include "statusnotifierwatcher_interface.h"
#include "dbusproperties.h"
namespace UkuiSni {
static std::once_flag flag;
static StatusNotifierHost *s_self;
static const QString s_watcherServiceName(QStringLiteral("org.kde.StatusNotifierWatcher"));
class StatusNotifierHostPrivate : public QObject
{
friend class StatusNotifierHost;
Q_OBJECT
public:
explicit StatusNotifierHostPrivate(StatusNotifierHost *q);
~StatusNotifierHostPrivate();
void registerHost();
private:
void serviceChange(const QString &name, const QString &oldOwner, const QString &newOwner);
void registerHost(const QString &service);
void unregisterHost(const QString &service);
void itemRegistered(const QString &service);
void itemUnregistered(const QString &service);
void removeAllItems();
QString displayFromPid(uint pid);
org::kde::StatusNotifierWatcher *m_statusNotifierWatcher = nullptr;
QString m_serviceName;
static const int s_protocolVersion = 0;
QHash m_registeredItems;
StatusNotifierHost *q = nullptr;
QString m_display;
QString m_sessionType;
};
StatusNotifierHostPrivate::StatusNotifierHostPrivate(StatusNotifierHost *q) : QObject(q), q(q)
{
if(QString(getenv("XDG_SESSION_TYPE")) == "wayland") {
m_sessionType = "wayland";
m_display = getenv("WAYLAND_DISPLAY");
} else {
m_sessionType = "x11";
m_display = getenv("DISPLAY");
}
qDebug() << "Current DISPLAY: " << m_display << "XDG_SESSION_TYPE" << m_sessionType;
}
StatusNotifierHostPrivate::~StatusNotifierHostPrivate()
{
}
void StatusNotifierHostPrivate::registerHost()
{
if (QDBusConnection::sessionBus().isConnected()) {
m_serviceName = "org.kde.StatusNotifierHost-" + QString::number(QCoreApplication::applicationPid());
QDBusConnection::sessionBus().registerService(m_serviceName);
auto *watcher = new QDBusServiceWatcher(s_watcherServiceName,
QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForOwnerChange,
this);
connect(watcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &StatusNotifierHostPrivate::serviceChange);
registerHost(s_watcherServiceName);
}
}
void StatusNotifierHostPrivate::serviceChange(const QString &name, const QString &oldOwner, const QString &newOwner)
{
qDebug() << "Service" << name << "status change, old owner:" << oldOwner << "new:" << newOwner;
if (newOwner.isEmpty()) {
unregisterHost(name);
} else if (oldOwner.isEmpty()) {
registerHost(name);
}
}
void StatusNotifierHostPrivate::registerHost(const QString &service)
{
if (service == s_watcherServiceName) {
if(m_statusNotifierWatcher) {
delete m_statusNotifierWatcher;
m_statusNotifierWatcher = nullptr;
}
m_statusNotifierWatcher = new org::kde::StatusNotifierWatcher(s_watcherServiceName,
QStringLiteral("/StatusNotifierWatcher"),
QDBusConnection::sessionBus(),
this);
if (m_statusNotifierWatcher->isValid()) {
m_statusNotifierWatcher->call(QDBus::NoBlock, QStringLiteral("RegisterStatusNotifierHost"), m_serviceName);
connect(m_statusNotifierWatcher, QOverload::of(&OrgKdeStatusNotifierWatcherInterface::StatusNotifierItemRegistered),
this, &StatusNotifierHostPrivate::itemRegistered);
connect(m_statusNotifierWatcher, QOverload::of(&OrgKdeStatusNotifierWatcherInterface::StatusNotifierItemUnregistered),
this, &StatusNotifierHostPrivate::itemUnregistered);
OrgFreedesktopDBusPropertiesInterface propertiesIface(m_statusNotifierWatcher->service(),
m_statusNotifierWatcher->path(),
m_statusNotifierWatcher->connection());
QDBusPendingReply pendingItems = propertiesIface.Get(m_statusNotifierWatcher->interface(), "RegisteredStatusNotifierItems");
auto *watcher = new QDBusPendingCallWatcher(pendingItems, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [&, watcher]() {
watcher->deleteLater();
QDBusReply reply = *watcher;
QStringList registeredItems = reply.value().variant().toStringList();
for(const QString &service : registeredItems) {
if (!m_registeredItems.contains(service)) {
itemRegistered(service);
}
}
});
} else {
if(m_statusNotifierWatcher) {
delete m_statusNotifierWatcher;
m_statusNotifierWatcher = nullptr;
}
qDebug() << "Status notifier Watcher not reachable";
}
}
}
void StatusNotifierHostPrivate::unregisterHost(const QString &service)
{
if (service == s_watcherServiceName) {
removeAllItems();
if(m_statusNotifierWatcher) {
delete m_statusNotifierWatcher;
m_statusNotifierWatcher = nullptr;
}
}
}
void StatusNotifierHostPrivate::itemRegistered(const QString &service)
{
if(!m_registeredItems.contains(service)) {
QString realService;
int slash = service.indexOf('/');
if (slash == 0) {
qWarning() << "Invalid service:" << service;
return;
} else if(slash > 0){
realService = service.left(slash);
} else {
realService = service;
}
uint pid = 0;
if(realService.contains(QStringLiteral("org.ukui.proxy.StatusNotifierItem"))) {
QString pidStr = realService.section("-", 1, 1);
if(!pidStr.isEmpty()) {
pid = pidStr.toUInt();
}
} else {
QDBusReply pidReply = QDBusConnection::sessionBus().interface()->servicePid(realService);
if(pidReply.isValid()) {
pid = pidReply.value();
}
}
QString display = pid > 0 ? displayFromPid(pid) : "";
if(m_display != display && !display.isEmpty()) {
return;
}
auto *item = new StatusNotifierItem(service);
item->setPid(pid);
m_registeredItems.insert(service, item);
Q_EMIT q->itemAdded(service);
qDebug() << "Registering sni" << service;
}
}
void StatusNotifierHostPrivate::itemUnregistered(const QString &service)
{
if (m_registeredItems.contains(service)) {
Q_EMIT q->itemRemoved(service);
auto item = m_registeredItems.value(service);
item->disconnect();
item->deleteLater();
m_registeredItems.remove(service);
}
}
void StatusNotifierHostPrivate::removeAllItems()
{
for(const QString &service : m_registeredItems.keys()) {
delete m_registeredItems.value(service);
m_registeredItems.remove(service);
Q_EMIT q->itemRemoved(service);
}
}
QString StatusNotifierHostPrivate::displayFromPid(uint pid)
{
QFile environFile(QStringLiteral("/proc/%1/environ").arg(QString::number(pid)));
if (environFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
const QByteArray DISPLAY = m_sessionType == "wayland" ? QByteArrayLiteral("WAYLAND_DISPLAY")
: QByteArrayLiteral("DISPLAY");
const auto lines = environFile.readAll().split('\0');
for (const QByteArray &line : lines) {
const int equalsIdx = line.indexOf('=');
if (equalsIdx <= 0) {
continue;
}
const QByteArray key = line.left(equalsIdx);
if (key == DISPLAY) {
const QByteArray value = line.mid(equalsIdx + 1);
return value;
}
}
}
return {};
}
StatusNotifierHost *StatusNotifierHost::self()
{
std::call_once(flag, [ & ] {
s_self = new StatusNotifierHost();
});
return s_self;
}
StatusNotifierHost::StatusNotifierHost(QObject *parent): QObject(parent), d(new StatusNotifierHostPrivate(this))
{
}
StatusNotifierHost::~StatusNotifierHost()
{
}
QList StatusNotifierHost::items()
{
return d->m_registeredItems.values();
}
const QList StatusNotifierHost::services() const
{
return d->m_registeredItems.keys();
}
StatusNotifierItem *StatusNotifierHost::itemForService(const QString service)
{
return d->m_registeredItems.value(service);
}
void StatusNotifierHost::registerHost()
{
d->registerHost();
}
}
#include "status-notifier-host.moc"
ukui-sni/common/ 0000775 0001750 0001750 00000000000 15153755017 012545 5 ustar feng feng ukui-sni/common/dbus-types.h 0000664 0001750 0001750 00000001431 15153755017 015014 0 ustar feng feng /*
SPDX-FileCopyrightText: 2009 Marco Martin
SPDX-FileCopyrightText: 2023 iaom
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include
#include "typedefs.h"
const QDBusArgument &operator<<(QDBusArgument &argument, const DbusImageStruct &icon);
const QDBusArgument &operator>>(const QDBusArgument &argument, DbusImageStruct &icon);
const QDBusArgument &operator<<(QDBusArgument &argument, const DbusImageVector &iconVector);
const QDBusArgument &operator>>(const QDBusArgument &argument, DbusImageVector &iconVector);
const QDBusArgument &operator<<(QDBusArgument &argument, const DbusToolTipStruct &toolTip);
const QDBusArgument &operator>>(const QDBusArgument &argument, DbusToolTipStruct &toolTip);
ukui-sni/common/typedefs.h 0000664 0001750 0001750 00000001454 15153755017 014545 0 ustar feng feng /*
SPDX-FileCopyrightText: 2009 Marco Martin
SPDX-FileCopyrightText: 2023 iaom
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include
#include
#include
#include
#include
#include
struct DbusImageStruct {
DbusImageStruct(){};
explicit DbusImageStruct(const QImage &image);
int width;
int height;
QByteArray data;
};
typedef QVector DbusImageVector;
struct DbusToolTipStruct {
QString icon;
DbusImageVector image;
QString title;
QString subTitle;
};
typedef QList UintList;
Q_DECLARE_METATYPE(UintList)
Q_DECLARE_METATYPE(DbusImageStruct)
Q_DECLARE_METATYPE(DbusImageVector)
Q_DECLARE_METATYPE(DbusToolTipStruct)
ukui-sni/common/dbus-types.cpp 0000664 0001750 0001750 00000007115 15153755017 015354 0 ustar feng feng /*
SPDX-FileCopyrightText: 2009 Marco Martin
SPDX-FileCopyrightText: 2023 iaom
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "dbus-types.h"
#include
#include
DbusImageStruct::DbusImageStruct(const QImage &image)
{
width = image.size().width();
height = image.size().height();
if (image.format() == QImage::Format_ARGB32) {
data = QByteArray((char *)image.bits(), image.sizeInBytes());
} else {
QImage image32 = image.convertToFormat(QImage::Format_ARGB32);
data = QByteArray((char *)image32.bits(), image32.sizeInBytes());
}
// swap to network byte order if we are little endian
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
quint32 *uintBuf = (quint32 *)data.data();
for (uint i = 0; i < data.size() / sizeof(quint32); ++i) {
*uintBuf = qToBigEndian(*uintBuf);
++uintBuf;
}
}
}
// Marshall the ImageStruct data into a D-BUS argument
const QDBusArgument &operator<<(QDBusArgument &argument, const DbusImageStruct &icon)
{
argument.beginStructure();
argument << icon.width;
argument << icon.height;
argument << icon.data;
argument.endStructure();
return argument;
}
#include
// Retrieve the ImageStruct data from the D-BUS argument
const QDBusArgument &operator>>(const QDBusArgument &argument, DbusImageStruct &icon)
{
qint32 width = 0;
qint32 height = 0;
QByteArray data;
if (argument.currentType() == QDBusArgument::StructureType) {
argument.beginStructure();
argument >> width;
argument >> height;
argument >> data;
argument.endStructure();
}
icon.width = width;
icon.height = height;
icon.data = data;
return argument;
}
// Marshall the ImageVector data into a D-BUS argument
const QDBusArgument &operator<<(QDBusArgument &argument, const DbusImageVector &iconVector)
{
argument.beginArray(qMetaTypeId());
for (int i = 0; i < iconVector.size(); ++i) {
argument << iconVector[i];
}
argument.endArray();
return argument;
}
// Retrieve the ImageVector data from the D-BUS argument
const QDBusArgument &operator>>(const QDBusArgument &argument, DbusImageVector &iconVector)
{
iconVector.clear();
if (argument.currentType() == QDBusArgument::ArrayType) {
argument.beginArray();
while (!argument.atEnd()) {
DbusImageStruct element;
argument >> element;
iconVector.append(element);
}
argument.endArray();
}
return argument;
}
// Marshall the ToolTipStruct data into a D-BUS argument
const QDBusArgument &operator<<(QDBusArgument &argument, const DbusToolTipStruct &toolTip)
{
argument.beginStructure();
argument << toolTip.icon;
argument << toolTip.image;
argument << toolTip.title;
argument << toolTip.subTitle;
argument.endStructure();
return argument;
}
// Retrieve the ToolTipStruct data from the D-BUS argument
const QDBusArgument &operator>>(const QDBusArgument &argument, DbusToolTipStruct &toolTip)
{
QString icon;
DbusImageVector image;
QString title;
QString subTitle;
if (argument.currentType() == QDBusArgument::StructureType) {
argument.beginStructure();
argument >> icon;
argument >> image;
argument >> title;
argument >> subTitle;
argument.endStructure();
}
toolTip.icon = icon;
toolTip.image = image;
toolTip.title = title;
toolTip.subTitle = subTitle;
return argument;
} ukui-sni/status-notifier-watcher/ 0000775 0001750 0001750 00000000000 15153755611 016050 5 ustar feng feng ukui-sni/status-notifier-watcher/ukui-sni-watcher.desktop 0000664 0001750 0001750 00000000344 15153755017 022643 0 ustar feng feng [Desktop Entry]
Name=ukui-sni-watcher
Name[zh_CN]=ukui-sni-watcher
Name[zh_TW]=ukui-sni-watcher
Exec=ukui-sni-watcher
Type=Application
OnlyShowIn=UKUI;
NoDisplay=true
X-UKUI-AutoRestart=true
X-UKUI-Autostart-Phase=Initialization ukui-sni/status-notifier-watcher/CMakeLists.txt 0000664 0001750 0001750 00000004376 15153755017 020622 0 ustar feng feng project(ukui-sni-watcher VERSION 1.0 LANGUAGES C CXX)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_MICRO 0)
set(UKUI_SNI_WATCHER_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO})
set(3rdParties_DIR ../3rd-parties/qtsingleapplication/src/)
configure_file (ukui-sni-watcher-config.h.in ukui-sni-watcher-config.h @ONLY)
include_directories(../common)
include_directories(../)
set(ukuiSNIWatcher_SRCS
${3rdParties_DIR}qtsinglecoreapplication.h
${3rdParties_DIR}qtsinglecoreapplication.cpp
${3rdParties_DIR}qtlocalpeer.h
${3rdParties_DIR}qtlocalpeer.cpp
watcher.cpp
watcher.h
watcher-private.h
status-notifier-watcher-application.cpp
status-notifier-watcher-application.h
../log-utils.cpp ../log-utils.h
main.cpp)
set_source_files_properties(../dbus/org.kde.StatusNotifierWatcher.xml PROPERTIES
NO_NAMESPACE false
INCLUDE "./watcher-private.h"
CLASSNAME StatusNotifierWatcherAdaptor
)
if(COMMAND qt_add_dbus_adaptor)
qt_add_dbus_adaptor(ukuiSNIWatcher_SRCS ../dbus/org.kde.StatusNotifierWatcher.xml watcher-private.h WatcherPrivate)
else()
qt5_add_dbus_adaptor(ukuiSNIWatcher_SRCS ../dbus/org.kde.StatusNotifierWatcher.xml watcher-private.h WatcherPrivate)
endif()
set(STATUS_NOTIFIER_ITEM_XML ../dbus/org.kde.StatusNotifierItem.xml)
set_source_files_properties(${STATUS_NOTIFIER_ITEM_XML} PROPERTIES
NO_NAMESPACE false
INCLUDE "../common/typedefs.h"
CLASSNAME OrgKdeStatusNotifierItemInterface
)
if(COMMAND qt_add_dbus_interface)
qt_add_dbus_interface(ukuiSNIWatcher_SRCS ../dbus/org.kde.StatusNotifierItem.xml statusnotifieriteminterface)
else()
qt5_add_dbus_interface(ukuiSNIWatcher_SRCS ../dbus/org.kde.StatusNotifierItem.xml statusnotifieriteminterface)
endif()
add_executable(${PROJECT_NAME} ${ukuiSNIWatcher_SRCS})
target_include_directories(${PROJECT_NAME} PUBLIC ${3rdParties_DIR})
target_link_libraries(${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Gui
)
install(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin)
install(FILES ukui-sni-watcher.desktop DESTINATION /etc/xdg/autostart) ukui-sni/status-notifier-watcher/main.cpp 0000664 0001750 0001750 00000002130 15153755017 017474 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*/
#include "status-notifier-watcher-application.h"
#include "log-utils.h"
int main(int argc, char *argv[])
{
LogUtils::initLogFile("ukui-sni-watcher");
qInstallMessageHandler(LogUtils::messageOutput);
StatusNotifierWatcherApplication app(argc, argv);
if(app.isRunning()) {
return 0;
}
return StatusNotifierWatcherApplication::exec();
}
ukui-sni/status-notifier-watcher/watcher-private.h 0000664 0001750 0001750 00000004546 15153755017 021337 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*/
#ifndef UKUI_SNI_WATCHER_PRIVATE_H
#define UKUI_SNI_WATCHER_PRIVATE_H
#include
#include
#include
#include
#include
#include "typedefs.h"
class WatcherPrivate : public QObject, protected QDBusContext
{
Q_OBJECT
Q_PROPERTY(QStringList RegisteredStatusNotifierItems READ RegisteredStatusNotifierItems)
Q_PROPERTY(UintList RegisteredStatusNotifierItemPids READ RegisteredStatusNotifierItemPids)
Q_PROPERTY(bool IsStatusNotifierHostRegistered READ IsStatusNotifierHostRegistered)
Q_PROPERTY(int ProtocolVersion READ ProtocolVersion)
public:
explicit WatcherPrivate(QObject *parent = nullptr);
~WatcherPrivate() override;
QStringList RegisteredStatusNotifierItems() const;
UintList RegisteredStatusNotifierItemPids() const;
bool IsStatusNotifierHostRegistered() const;
int ProtocolVersion() const;
public Q_SLOTS:
void RegisterStatusNotifierItem(const QString &service);
void RegisterStatusNotifierHost(const QString &service);
Q_SIGNALS:
void StatusNotifierItemRegistered(const QString &service);
void StatusNotifierHostRegistered();
void StatusNotifierItemUnregistered(const QString &service);
void StatusNotifierHostUnregistered();
void StatusNotifierItemRegistered(quint32 pid);
void StatusNotifierItemUnregistered(quint32 pid);
private:
void serviceUnregistered(const QString &service);
QDBusServiceWatcher *m_serviceWatcher = nullptr;
QMultiMap m_registeredServices; // notifierItemId->pid
QSet m_statusNotifierHostServices;
};
#endif //UKUI_SNI_WATCHER_PRIVATE_H
ukui-sni/status-notifier-watcher/status-notifier-watcher-application.h 0000664 0001750 0001750 00000002426 15153755017 025321 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*/
#ifndef UKUI_SNI_STATUS_NOTIFIER_WATCHER_APPLICATION_H
#define UKUI_SNI_STATUS_NOTIFIER_WATCHER_APPLICATION_H
#include
#include "qtsinglecoreapplication.h"
class StatusNotifierWatcherApplication : public QtSingleCoreApplication
{
Q_OBJECT
public:
StatusNotifierWatcherApplication(int &argc, char *argv[], const QString &applicationName = "ukui-sni-watcher");
~StatusNotifierWatcherApplication();
protected Q_SLOTS:
void parseCmd(const QString& msg, bool isPrimary);
};
#endif //UKUI_SNI_STATUS_NOTIFIER_WATCHER_APPLICATION_H
ukui-sni/status-notifier-watcher/watcher.cpp 0000664 0001750 0001750 00000013123 15153755611 020211 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*/
#include "watcher-private.h"
#include "statusnotifierwatcheradaptor.h"
#include "statusnotifieriteminterface.h"
#include "watcher.h"
WatcherPrivate::WatcherPrivate(QObject *parent) : QObject(parent)
{
qDBusRegisterMetaType();
new StatusNotifierWatcherAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerObject(QStringLiteral("/StatusNotifierWatcher"), this);
dbus.registerService(QStringLiteral("org.kde.StatusNotifierWatcher"));
m_serviceWatcher = new QDBusServiceWatcher(this);
m_serviceWatcher->setConnection(dbus);
m_serviceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &WatcherPrivate::serviceUnregistered);
}
WatcherPrivate::~WatcherPrivate()
{
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService(QStringLiteral("org.kde.StatusNotifierWatcher"));
}
QStringList WatcherPrivate::RegisteredStatusNotifierItems() const
{
return m_registeredServices.keys();
}
UintList WatcherPrivate::RegisteredStatusNotifierItemPids() const
{
QStringList pidList = m_registeredServices.values();
pidList.removeDuplicates();
pidList.removeAll("0");
QList pids;
for(const QString &pid : pidList) {
pids.append(pid.toUInt());
}
return pids;
}
bool WatcherPrivate::IsStatusNotifierHostRegistered() const
{
// return !m_statusNotifierHostServices.isEmpty();
return true;
}
int WatcherPrivate::ProtocolVersion() const
{
return 0;
}
void WatcherPrivate::RegisterStatusNotifierItem(const QString &service)
{
QString realService;
QString path;
int slash = service.indexOf('/');
if (slash == 0) {
realService = message().service();
path = service;
} else if(slash > 0){
realService = service.left(slash);
path = service.mid(slash);
} else {
realService = service;
path = QStringLiteral("/StatusNotifierItem");
}
QString notifierItemId = realService + path;
if (m_registeredServices.contains(notifierItemId)) {
return;
}
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(realService).value()) {
// check if the service has registered a SystemTray object
org::kde::StatusNotifierItem item(realService, path, QDBusConnection::sessionBus());
if (item.isValid()) {
qDebug() << "Registering" << notifierItemId << "to system tray";
m_serviceWatcher->addWatchedService(realService);
//get Pid for item
QString pid = "0";
if(realService.contains(QStringLiteral("org.ukui.proxy.StatusNotifierItem"))) {
QString pidStr = realService.section("-", 1, 1);
if(!pidStr.isEmpty()) {
pid = pidStr;
}
} else {
QDBusReply pidReply = connection().interface()->servicePid(message().service());
if(pidReply.isValid()) {
pid = QString::number(pidReply.value());
}
}
m_registeredServices.insert(notifierItemId, pid);
Q_EMIT StatusNotifierItemRegistered(notifierItemId);
if(pid.toUInt() > 0) {
Q_EMIT StatusNotifierItemRegistered(pid.toUInt());
}
}
}
}
void WatcherPrivate::RegisterStatusNotifierHost(const QString &service)
{
if (service.contains(QLatin1String("org.kde.StatusNotifierHost-")) && QDBusConnection::sessionBus().interface()->isServiceRegistered(service).value()
&& !m_statusNotifierHostServices.contains(service)) {
qDebug() << "Registering" << service << "as system tray";
m_statusNotifierHostServices.insert(service);
m_serviceWatcher->addWatchedService(service);
Q_EMIT StatusNotifierHostRegistered();
}
}
void WatcherPrivate::serviceUnregistered(const QString &service)
{
qDebug() << "Service " << service << "unregistered";
m_serviceWatcher->removeWatchedService(service);
const QString match = service + QLatin1Char('/');
for(const QString &servicePath : m_registeredServices.keys()) {
if(servicePath.startsWith(match)) {
QString pid = m_registeredServices.take(servicePath);
Q_EMIT StatusNotifierItemUnregistered(servicePath);
if(!m_registeredServices.values().contains(pid) && pid.toUInt() > 0) {
Q_EMIT StatusNotifierItemUnregistered(pid.toUInt());
}
}
}
if (m_statusNotifierHostServices.contains(service)) {
m_statusNotifierHostServices.remove(service);
Q_EMIT StatusNotifierHostUnregistered();
}
}
Watcher &Watcher::self()
{
static Watcher self;
return self;
}
Watcher::Watcher(): d(new WatcherPrivate)
{
}
Watcher::~Watcher()
{
if(d) {
delete d;
d = nullptr;
}
}
ukui-sni/status-notifier-watcher/ukui-sni-watcher-config.h.in 0000664 0001750 0001750 00000002027 15153755017 023271 0 ustar feng feng /*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*/
#ifndef NOTIFICATION_SERVER_CONFIG_H_IN
#define NOTIFICATION_SERVER_CONFIG_H_IN
#define VERSION_MAJOR "@VERSION_MAJOR@"
#define VERSION_MINOR "@VERSION_MINOR@"
#define VERSION_MICRO "@VERSION_MICRO@"
#define UKUI_SNI_WATCHER_VERSION "@UKUI_SNI_WATCHER_VERSION@"
#endif // UKUI_SNI_WATCHER_CONFIG_H ukui-sni/status-notifier-watcher/watcher.h 0000664 0001750 0001750 00000002015 15153755017 017654 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*/
#ifndef UKUI_SNI_WATCHER_H
#define UKUI_SNI_WATCHER_H
#include
class WatcherPrivate;
class Watcher
{
public:
static Watcher &self();
~Watcher();
private:
explicit Watcher();
Q_DISABLE_COPY(Watcher)
WatcherPrivate *d = nullptr;
};
#endif //UKUI_SNI_WATCHER_H
ukui-sni/status-notifier-watcher/status-notifier-watcher-application.cpp 0000664 0001750 0001750 00000004451 15153755017 025654 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*/
#include
#include
#include
#include "status-notifier-watcher-application.h"
#include
#include "ukui-sni-watcher-config.h"
#include "watcher.h"
StatusNotifierWatcherApplication::StatusNotifierWatcherApplication(int &argc, char **argv,
const QString &applicationName)
: QtSingleCoreApplication(applicationName, argc, argv)
{
setApplicationVersion(UKUI_SNI_WATCHER_VERSION);
qApp->setProperty("IS_UKUI_NOTIFICATION_SERVER", QVariant(true));
if (!this->isRunning()) {
connect(this, &QtSingleCoreApplication::messageReceived, [=](QString msg) {
this->parseCmd(std::move(msg), true);
});
Watcher::self();
}
parseCmd(arguments().join(" ").toUtf8(), !isRunning());
}
void StatusNotifierWatcherApplication::parseCmd(const QString& msg, bool isPrimary)
{
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption quitOption(QStringList()<<"q"<<"quit", tr("Quit ukui-sni-watcher"));
parser.addOption(quitOption);
if (isPrimary) {
const QStringList args = QString(msg).split(' ');
parser.process(args);
if (parser.isSet(quitOption)) {
qApp->quit();
return;
}
}
else {
if (arguments().count() < 2) {
parser.showHelp();
}
parser.process(arguments());
sendMessage(msg);
}
}
StatusNotifierWatcherApplication::~StatusNotifierWatcherApplication()
{
}
ukui-sni/log-utils.h 0000664 0001750 0001750 00000002432 15153755611 013346 0 ustar feng feng /*
* Copyright (C) 2024, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*
*/
#ifndef LOGUTILS_H
#define LOGUTILS_H
#include
class LogUtils
{
public:
static void initLogFile(const QString &fileName);
static void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg);
private:
static void checkLogFile();
static bool checkFileSize(const QString &fileName);
static void clearFile(const QString &fileName);
static quint64 m_startUpTime;
static int m_logFileId;
static QString m_logFileName;
static QString m_currentLogFile;
};
#endif // LOGUTILS_H
ukui-sni/cmake/ 0000775 0001750 0001750 00000000000 15153755017 012335 5 ustar feng feng ukui-sni/cmake/find-modules/ 0000775 0001750 0001750 00000000000 15153755017 014723 5 ustar feng feng ukui-sni/cmake/find-modules/FindXCB.cmake 0000664 0001750 0001750 00000001603 15153755017 017142 0 ustar feng feng include(FeatureSummary)
set_package_properties(XCB PROPERTIES
URL "https://xcb.freedesktop.org/"
DESCRIPTION "X protocol C-language Binding")
find_package(PkgConfig)
pkg_check_modules(PC_XCB xcb ${XCB_FIND_COMPONENTS})
find_library(XCB_LIBRARIES xcb HINTS ${PC_XCB_LIBRARY_DIRS})
find_path(XCB_INCLUDE_DIRS xcb/xcb.h PATH_SUFFIXES xcb HINTS ${PC_XCB_INCLUDE_DIRS})
foreach(COMPONENT ${XCB_FIND_COMPONENTS})
find_library(XCB_LIBRARIES_${COMPONENT} ${COMPONENT} HINTS ${PC_XCB_LIBRARY_DIRS})
list(APPEND XCB_LIBRARIES ${XCB_LIBRARIES_${COMPONENT}})
mark_as_advanced(XCB_LIBRARIES_${COMPONENT})
endforeach(COMPONENT ${XCB_FIND_COMPONENTS})
set(XCB_DEFINITIONS ${PC_XCB_CFLAGS_OTHER})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(XCB DEFAULT_MSG XCB_LIBRARIES XCB_INCLUDE_DIRS)
mark_as_advanced(XCB_INCLUDE_DIRS XCB_LIBRARIES XCB_DEFINITIONS) ukui-sni/xembed-sni-proxy/ 0000775 0001750 0001750 00000000000 15153755611 014467 5 ustar feng feng ukui-sni/xembed-sni-proxy/xtest-sender.h 0000664 0001750 0001750 00000000647 15153755017 017274 0 ustar feng feng /* Wrap XLIB code in a new file as it defines keywords that conflict with Qt
SPDX-FileCopyrightText: 2017 David Edmundson
SPDX-FileCopyrightText: 2023 iaom
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#pragma once
typedef struct _XDisplay Display;
void sendXTestPressed(Display *display, int button);
void sendXTestReleased(Display *display, int button);
ukui-sni/xembed-sni-proxy/xcb-utils.h 0000664 0001750 0001750 00000005371 15153755017 016560 0 ustar feng feng /*
SPDX-FileCopyrightText: 2012, 2013 Martin Graesslin
SPDX-FileCopyrightText: 2015 David Edmudson
SPDX-FileCopyrightText: 2023 iaom
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include
#include
#include
#include
#include
#include
#include
#include
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include
#else
#include
#endif
#include
/** XEMBED messages */
#define XEMBED_EMBEDDED_NOTIFY 0
#define XEMBED_WINDOW_ACTIVATE 1
#define XEMBED_WINDOW_DEACTIVATE 2
#define XEMBED_REQUEST_FOCUS 3
#define XEMBED_FOCUS_IN 4
#define XEMBED_FOCUS_OUT 5
#define XEMBED_FOCUS_NEXT 6
#define XEMBED_FOCUS_PREV 7
namespace Xcb
{
class Atom
{
public:
explicit Atom(const QByteArray &name, bool onlyIfExists = false, xcb_connection_t *c = QX11Info::connection())
: m_connection(c)
, m_retrieved(false)
, m_cookie(xcb_intern_atom_unchecked(m_connection, onlyIfExists, name.length(), name.constData()))
, m_atom(XCB_ATOM_NONE)
, m_name(name)
{
}
Atom() = delete;
Atom(const Atom &) = delete;
~Atom()
{
if (!m_retrieved && m_cookie.sequence) {
xcb_discard_reply(m_connection, m_cookie.sequence);
}
}
operator xcb_atom_t() const
{
(const_cast(this))->getReply();
return m_atom;
}
bool isValid()
{
getReply();
return m_atom != XCB_ATOM_NONE;
}
bool isValid() const
{
(const_cast(this))->getReply();
return m_atom != XCB_ATOM_NONE;
}
inline const QByteArray &name() const
{
return m_name;
}
private:
void getReply()
{
if (m_retrieved || !m_cookie.sequence) {
return;
}
UniqueCPointer reply(xcb_intern_atom_reply(m_connection, m_cookie, nullptr));
if (reply) {
m_atom = reply->atom;
}
m_retrieved = true;
}
xcb_connection_t *m_connection;
bool m_retrieved;
xcb_intern_atom_cookie_t m_cookie;
xcb_atom_t m_atom;
QByteArray m_name;
};
class Atoms
{
public:
Atoms()
: xembedAtom("_XEMBED")
, selectionAtom(xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", QX11Info::appScreen()))
, opcodeAtom("_NET_SYSTEM_TRAY_OPCODE")
, messageData("_NET_SYSTEM_TRAY_MESSAGE_DATA")
, visualAtom("_NET_SYSTEM_TRAY_VISUAL")
{
}
Atom xembedAtom;
Atom selectionAtom;
Atom opcodeAtom;
Atom messageData;
Atom visualAtom;
};
extern Atoms *atoms;
} // namespace Xcb
ukui-sni/xembed-sni-proxy/xtest-sender.cpp 0000664 0001750 0001750 00000001044 15153755017 017617 0 ustar feng feng /* Wrap XLIB code in a new file as it defines keywords that conflict with Qt
SPDX-FileCopyrightText: 2017 David Edmundson
SPDX-FileCopyrightText: 2023 iaom
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "xtest-sender.h"
#include
void sendXTestPressed(Display *display, int button)
{
XTestFakeButtonEvent(display, button, true, 0);
}
void sendXTestReleased(Display *display, int button)
{
XTestFakeButtonEvent(display, button, false, 0);
}
ukui-sni/xembed-sni-proxy/sni-proxy.h 0000664 0001750 0001750 00000010077 15153755611 016615 0 ustar feng feng /*
Holds one embedded window, registers as DBus entry
SPDX-FileCopyrightText: 2015 David Edmundson
SPDX-FileCopyrightText: 2019 Konrad Materka
SPDX-FileCopyrightText: 2023 iaom
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#pragma once
#include
#include
#include
#include
#include
#include
#include
#include
#include "typedefs.h"
class SNIProxy : public QObject
{
Q_OBJECT
Q_PROPERTY(QString Category READ Category)
Q_PROPERTY(QString Id READ Id)
Q_PROPERTY(QString Title READ Title)
Q_PROPERTY(QString Status READ Status)
Q_PROPERTY(int WindowId READ WindowId)
Q_PROPERTY(QDBusObjectPath Menu READ Menu)
Q_PROPERTY(bool ItemIsMenu READ ItemIsMenu)
Q_PROPERTY(DbusImageVector IconPixmap READ IconPixmap)
public:
explicit SNIProxy(xcb_window_t wid, QObject *parent = nullptr);
~SNIProxy() override;
void update();
void resizeWindow(const uint16_t width, const uint16_t height) const;
/**
* @return the category of the application associated to this item
* @see Category
*/
QString Category() const;
/**
* @return the id of this item
*/
QString Id() const;
/**
* @return the title of this item
*/
QString Title() const;
/**
* @return The status of this item
* @see Status
*/
QString Status() const;
/**
* @return The id of the main window of the application that controls the item
*/
int WindowId() const;
QDBusObjectPath Menu() const;
/**
* @return The item only support the context menu, the visualization should prefer sending ContextMenu() instead of Activate()
*/
bool ItemIsMenu() const;
/**
* @return a serialization of the icon data
*/
DbusImageVector IconPixmap() const;
public Q_SLOTS:
// interaction
/**
* Shows the context menu associated to this item
* at the desired screen position
*/
void ContextMenu(int x, int y);
/**
* Shows the main widget and try to position it on top
* of the other windows, if the widget is already visible, hide it.
*/
void Activate(int x, int y);
/**
* The user activated the item in an alternate way (for instance with middle mouse button, this depends from the systray implementation)
*/
void SecondaryActivate(int x, int y);
/**
* Inform this item that the mouse wheel was used on its representation
*/
void Scroll(int delta, const QString &orientation);
void ProvideXdgActivationToken(const QString &token);
Q_SIGNALS:
/**
* Inform the systemtray that the own main icon has been changed,
* so should be reloaded
*/
void NewIcon();
/**
* Inform the systemtray that there is a new icon to be used as overlay
*/
void NewOverlayIcon();
/**
* Inform the systemtray that the requesting attention icon
* has been changed, so should be reloaded
*/
void NewAttentionIcon();
/**
* Inform the systemtray that something in the tooltip has been changed
*/
void NewToolTip();
/**
* Signal the new status when it has been changed
* @see Status
*/
void NewStatus(const QString &status);
private:
enum InjectMode {
Direct,
XTest,
};
QSize calculateClientWindowSize() const;
void sendClick(uint8_t mouseButton, int x, int y);
QImage getImageNonComposite() const;
bool isTransparentImage(const QImage &image) const;
QImage convertFromNative(xcb_image_t *xcbImage) const;
QPoint calculateClickPoint() const;
void setActiveForInput(bool active) const;
uint getPid(const xcb_window_t windowId);
QDBusConnection m_dbus;
xcb_window_t m_windowId;
xcb_window_t m_containerWid;
static int s_serviceCount;
QPixmap m_pixmap;
bool sendingClickEvent;
InjectMode m_injectMode;
xcb_atom_t m_pidAtom;
QMap m_pidToProxyCount;
};
ukui-sni/xembed-sni-proxy/fdo-selection-manager.cpp 0000664 0001750 0001750 00000017640 15153755611 021346 0 ustar feng feng /*
Registers as a embed container
SPDX-FileCopyrightText: 2015 David Edmundson