├── .cirrus.yml
├── .gitignore
├── CMakeLists.txt
├── LICENSE
├── README.md
├── qml
├── AppItem.qml
├── DockItem.qml
├── Menu.qml
├── PopupTips.qml
└── main.qml
├── resources.qrc
├── src
├── applicationitem.h
├── applicationmodel.cpp
├── applicationmodel.h
├── docksettings.cpp
├── docksettings.h
├── iconthemeimageprovider.cpp
├── iconthemeimageprovider.h
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── popuptips.cpp
├── popuptips.h
├── processprovider.cpp
├── processprovider.h
├── systemappitem.cpp
├── systemappitem.h
├── systemappmonitor.cpp
├── systemappmonitor.h
├── trashmanager.cpp
├── trashmanager.h
├── utils.cpp
├── utils.h
├── waylandinterface.cpp
├── waylandinterface.h
├── xwindowinterface.cpp
└── xwindowinterface.h
└── svg
└── launcher.svg
/.cirrus.yml:
--------------------------------------------------------------------------------
1 | freebsd_instance:
2 | image: freebsd-12-1-release-amd64
3 |
4 | env:
5 | CIRRUS_CLONE_DEPTH: 1
6 | GITHUB_TOKEN: ENCRYPTED[!0f42e3f70fd51cdeddfe7e98160982fc9efe7e8a26869b725fcd5de05d067a7100b994cf52f0f1b470a983148e0b8ec2!]
7 |
8 | task:
9 | # This name gets reported as a build status in GitHub
10 | name: freebsd-12-1-release-amd64
11 | stateful: false
12 | setup_script:
13 | - pkg install -y curl wget zip pkgconf cmake qt5-qmake qt5-buildtools qt5-quickcontrols2 kf5-kwindowsystem kf5-kwayland
14 | test_script:
15 | - mkdir build ; cd build
16 | - cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
17 | - make -j$(sysctl -n hw.ncpu)
18 | - make DESTDIR=. -j$(sysctl -n hw.ncpu) install
19 | - find System/Dock.app/
20 | - ( cd ./System/ ; zip --symlinks -r ../Dock_FreeBSD.zip Dock.app/ )
21 | # curl --upload-file ./Filer_FreeBSD.zip https://transfer.sh/Filer_FreeBSD.zip
22 | - case "$CIRRUS_BRANCH" in *pull/*) echo skipping since PR ;; * ) wget https://github.com/tcnksm/ghr/files/5247714/ghr.zip ; unzip ghr.zip ; rm ghr.zip ; ./ghr -replace -t "${GITHUB_TOKEN}" -u "${CIRRUS_REPO_OWNER}" -r "${CIRRUS_REPO_NAME}" -c "${CIRRUS_CHANGE_IN_REPO}" continuous "${CIRRUS_WORKING_DIR}"/build/*zip ; esac
23 | only_if: $CIRRUS_TAG != 'continuous'
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # C++ objects and libs
2 | *.slo
3 | *.lo
4 | *.o
5 | *.a
6 | *.la
7 | *.lai
8 | *.so
9 | *.so.*
10 | *.dll
11 | *.dylib
12 |
13 | # Qt-es
14 | object_script.*.Release
15 | object_script.*.Debug
16 | *_plugin_import.cpp
17 | /.qmake.cache
18 | /.qmake.stash
19 | *.pro.user
20 | *.pro.user.*
21 | *.qbs.user
22 | *.qbs.user.*
23 | *.moc
24 | moc_*.cpp
25 | moc_*.h
26 | qrc_*.cpp
27 | ui_*.h
28 | *.qmlc
29 | *.jsc
30 | Makefile*
31 | *build-*
32 | *.qm
33 | *.prl
34 |
35 | # Qt unit tests
36 | target_wrapper.*
37 |
38 | # QtCreator
39 | *.autosave
40 |
41 | # QtCreator Qml
42 | *.qmlproject.user
43 | *.qmlproject.user.*
44 |
45 | # QtCreator CMake
46 | CMakeLists.txt.user*
47 |
48 | # QtCreator 4.8< compilation database
49 | compile_commands.json
50 |
51 | # QtCreator local machine specific files for imported projects
52 | *creator.user*
53 |
54 | build/*
55 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 |
3 | set(PROJECT_NAME Dock)
4 | project(${PROJECT_NAME})
5 |
6 | set(CMAKE_INSTALL_PREFIX "/System/Dock.app")
7 |
8 | set(CMAKE_INCLUDE_CURRENT_DIR ON)
9 | set(CMAKE_AUTOUIC ON)
10 | set(CMAKE_AUTOMOC ON)
11 | set(CMAKE_AUTORCC ON)
12 | set(CMAKE_CXX_STANDARD 11)
13 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
14 |
15 | set(QT Core Widgets Quick QuickControls2 X11Extras DBus)
16 | find_package(Qt5 REQUIRED ${QT})
17 | find_package(KF5WindowSystem REQUIRED)
18 |
19 | set(SRCS
20 | src/applicationitem.h
21 | src/applicationmodel.cpp
22 | src/docksettings.cpp
23 | src/iconthemeimageprovider.cpp
24 | src/main.cpp
25 | src/mainwindow.cpp
26 | src/systemappmonitor.cpp
27 | src/systemappitem.cpp
28 | src/processprovider.cpp
29 | src/popuptips.cpp
30 | src/trashmanager.cpp
31 | src/utils.cpp
32 | src/xwindowinterface.cpp
33 | )
34 |
35 | set(RESOURCES
36 | resources.qrc
37 | )
38 |
39 | add_executable(${PROJECT_NAME} ${SRCS} ${DBUS_SRCS} ${RESOURCES})
40 | target_link_libraries(${PROJECT_NAME}
41 | Qt5::Core
42 | Qt5::Widgets
43 | Qt5::Quick
44 | Qt5::QuickControls2
45 | Qt5::X11Extras
46 | Qt5::DBus
47 |
48 | KF5::WindowSystem
49 | )
50 |
51 | install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
52 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Dock [](https://cirrus-ci.com/github/helloSystem/Dock)
2 |
3 | 
4 |
5 | ## Dependencies
6 |
7 | On Arch Linux:
8 |
9 | ```shell
10 | sudo pacman -S gcc cmake qt5-base qt5-quickcontrols2 kwindowsystem kwayland
11 | ```
12 |
13 | On FreeBSD:
14 |
15 | ```
16 | sudo pkg install -y curl zip pkgconf cmake qt5-qmake qt5-buildtools qt5-quickcontrols2 kf5-kwindowsystem kf5-kwayland
17 | ```
18 |
19 |
20 | ## Build and Install
21 |
22 | ```
23 | mkdir build
24 | cd build
25 | cmake ..
26 | make
27 | sudo make install
28 | ```
29 |
30 | ## Acknowledgments
31 |
32 | Dock is based on https://github.com/cutefishos/dock by rekols.
33 |
34 | ## License
35 |
36 | This project has been licensed by GPLv3.
37 |
--------------------------------------------------------------------------------
/qml/AppItem.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.12
2 | import QtQuick.Controls 2.5
3 | import Qt.labs.platform 1.0
4 |
5 | Item {
6 | id: appItem
7 | width: root.height
8 | height: root.height
9 |
10 | property bool enableActivateDot: true
11 | property bool isActive: model.isActive
12 | property var activateDotColor: "#2E64E6"
13 | property var inactiveDotColor: "#000000"
14 |
15 | property var iconName: model.iconName
16 | property double iconSizeRatio: 0.8
17 | property var iconSource
18 |
19 | signal onClicked
20 |
21 | onXChanged: updateGeometryTimer.start()
22 | onYChanged: updateGeometryTimer.start()
23 |
24 | function updateGeometry() {
25 | appModel.updateGeometries(model.appId, Qt.rect(dockItem.mapToGlobal(0, 0).x,
26 | dockItem.mapToGlobal(0, 0).y,
27 | dockItem.width, dockItem.height))
28 | }
29 |
30 | Timer {
31 | id: updateGeometryTimer
32 | interval: 800
33 | repeat: false
34 |
35 | onTriggered: {
36 | updateGeometry()
37 | }
38 | }
39 |
40 | Menu {
41 | id: contextMenu
42 |
43 | /*
44 | MenuItem {
45 | text: qsTr("Open")
46 | visible: model.windowCount === 0
47 | onTriggered: appModel.openNewInstance(model.appId)
48 | }
49 |
50 |
51 | MenuItem {
52 | text: model.visibleName
53 | visible: model.windowCount > 0
54 | onTriggered: appModel.openNewInstance(model.appId)
55 | }
56 | */
57 |
58 | MenuItem {
59 | // visible: model.visibleName !== {};
60 | // FIXME: Only show this menu item if model.exec is present and not empty; why can't we seem to get model.exec here?
61 | text: model.isPined ? qsTr("Remove ") + model.visibleName + qsTr(" from Dock") : qsTr("Keep ") + model.visibleName + qsTr(" in Dock")
62 | onTriggered: {
63 | model.isPined ? appModel.unPin(model.appId) : appModel.pin(model.appId)
64 | }
65 | }
66 |
67 | MenuItem {
68 | text: qsTr("Close ") + model.visibleName
69 | visible: model.windowCount !== 0
70 | onTriggered: appModel.closeAllByAppId(model.appId)
71 | }
72 | }
73 |
74 | DockItem {
75 | id: dockItem
76 | anchors.fill: parent
77 | iconName: model.iconName
78 | isActive: model.isActive
79 | popupText: model.visibleName
80 | enableActivateDot: model.windowCount !== 0
81 |
82 | onPositionChanged: updateGeometry()
83 | onPressed: updateGeometry()
84 | onClicked: appModel.clicked(model.appId)
85 | onRightClicked: contextMenu.open()
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/qml/DockItem.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.12
2 | import QtQuick.Controls 2.5
3 |
4 | MouseArea {
5 | id: dockItem
6 | width: root.height
7 | height: root.height
8 |
9 | property bool enableActivateDot: true
10 | property bool isActive: false
11 |
12 | property var activateDotColor: root.activateDotColor
13 | property var inactiveDotColor: root.inactiveDotColor
14 |
15 | property var popupText
16 |
17 | property double iconSizeRatio: 0.8
18 | property var iconName
19 |
20 | signal pressed()
21 | signal clicked()
22 | signal rightClicked()
23 |
24 | onClicked: {
25 | if(isActive == false) {
26 | console.log("probono: Show open animation");
27 | openAnimation.start()
28 | }
29 | }
30 |
31 | Image {
32 | id: icon
33 | source: {
34 | return iconName ? iconName.indexOf("/") === 0 || iconName.indexOf("file://") === 0 || iconName.indexOf("qrc") === 0
35 | ? iconName : "image://icontheme/" + iconName : iconName;
36 | }
37 | sourceSize.width: parent.height * iconSizeRatio
38 | sourceSize.height: parent.height * iconSizeRatio
39 | width: sourceSize.width
40 | height: sourceSize.height
41 | smooth: true
42 |
43 | anchors {
44 | horizontalCenter: parent.horizontalCenter
45 | verticalCenter: parent.verticalCenter
46 | }
47 |
48 | states: ["mouseIn", "mouseOut"]
49 | state: "mouseOut"
50 |
51 | SequentialAnimation {
52 | // FIXME: Is there a way to make this animation not confined within the box of the Dock? How?
53 | id: openAnimation
54 | running: false
55 | ParallelAnimation {
56 | NumberAnimation {
57 | target: icon
58 | properties: "scale"
59 | from: 1
60 | to: 5
61 | duration: 350
62 | easing.type: Easing.OutCubic
63 | }
64 | NumberAnimation {
65 | target: icon
66 | properties: "opacity"
67 | from: 1
68 | to: 0
69 | duration: 350
70 | easing.type: Easing.OutCubic
71 | }
72 | }
73 | // After the animation, quickly go back to the normal state
74 | ParallelAnimation {
75 | NumberAnimation {
76 | target: icon
77 | properties: "scale"
78 | from: 5
79 | to: 1
80 | duration: 1
81 | }
82 | NumberAnimation {
83 | target: icon
84 | properties: "opacity"
85 | from: 0
86 | to: 1
87 | duration: 1
88 | }
89 | }
90 | }
91 |
92 | /*
93 | transitions: [
94 | Transition {
95 | from: "*"
96 | to: "mouseIn"
97 |
98 | NumberAnimation {
99 | target: icon
100 | properties: "scale"
101 | from: 1
102 | to: 1.1
103 | duration: 150
104 | easing.type: Easing.OutCubic
105 | }
106 | },
107 | Transition {
108 | from: "*"
109 | to: "mouseOut"
110 |
111 | NumberAnimation {
112 | target: icon
113 | properties: "scale"
114 | from: 1.1
115 | to: 1
116 | duration: 100
117 | easing.type: Easing.InCubic
118 | }
119 | }
120 | ]
121 | */
122 | }
123 |
124 | MouseArea {
125 | id: iconArea
126 | anchors.fill: icon
127 | hoverEnabled: true
128 | acceptedButtons: Qt.LeftButton | Qt.RightButton
129 |
130 | onPressed: dockItem.pressed()
131 |
132 | onClicked: {
133 | if (mouse.button === Qt.LeftButton)
134 | dockItem.clicked()
135 | else if (mouse.button === Qt.RightButton)
136 | dockItem.rightClicked()
137 | }
138 |
139 | onContainsMouseChanged: {
140 | if (containsMouse) {
141 | icon.state = "mouseIn"
142 | popupTips.popup(dockItem.mapToGlobal(0, 0), popupText)
143 | } else {
144 | icon.state = "mouseOut"
145 | popupTips.hide()
146 | }
147 | }
148 | }
149 |
150 | Rectangle {
151 | id: activeDot
152 | width: parent.height * 0.07
153 | height: width
154 | color: isActive ? activateDotColor : inactiveDotColor
155 | radius: height
156 | visible: enableActivateDot
157 |
158 | anchors {
159 | top: icon.bottom
160 | horizontalCenter: parent.horizontalCenter
161 | }
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/qml/Menu.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.0
2 |
3 | Item {
4 | width: 200
5 | height: 200
6 | }
7 |
--------------------------------------------------------------------------------
/qml/PopupTips.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.4
2 | import QtQuick.Controls 2.5
3 | import QtQuick.Layouts 1.3
4 |
5 | Rectangle {
6 | id: root
7 | visible: false
8 |
9 | property int padding: 20
10 |
11 | width: metrics.boundingRect.width + padding
12 | height: metrics.boundingRect.height + padding
13 |
14 | radius: 3
15 | opacity: 0.6
16 | color: "white"
17 | border.color: Settings.darkMode ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.2)
18 | border.width: 1
19 |
20 | Label {
21 | id: label
22 | color: Settings.darkMode ? Qt.rgba(255, 255, 255, 0.7) : Qt.rgba(0, 0, 0, 0.7)
23 | text: "tips"
24 | anchors.centerIn: parent
25 | }
26 |
27 | TextMetrics {
28 | id: metrics
29 | font: label.font
30 | text: label.text
31 | }
32 |
33 | function setText(text) {
34 | label.text = text
35 | }
36 |
37 | function setVisible(visible) {
38 | root.visible = visible
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/qml/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.12
2 | import QtQuick.Controls 2.5
3 | import QtGraphicalEffects 1.0
4 |
5 | Rectangle {
6 | visible: true
7 | id: root
8 |
9 | color: "transparent"
10 |
11 | property color backgroundColor: Settings.darkMode ? Qt.rgba(0, 0, 0, 0.05) : Qt.rgba(255, 255, 255, 0.5)
12 | property color foregroundColor: Settings.darkMode ? "white" : "black"
13 | property color borderColor: Settings.darkMode ? Qt.rgba(255, 255, 255, 0.1) : Qt.rgba(0, 0, 0, 0.05)
14 | property color activateDotColor: Settings.darkMode ? "#4d81ff" : "white"
15 | property color inactiveDotColor: Settings.darkMode ? Qt.rgba(255, 255, 255, 0.6) : Qt.rgba(0, 0, 0, 0.9)
16 |
17 | y: 350
18 | NumberAnimation on y {
19 | to: 0
20 | duration: 5000
21 | easing {type: Easing.OutQuad}
22 | }
23 |
24 | Rectangle {
25 | id: background
26 | anchors.fill: parent
27 | radius: 1
28 | opacity: 0.2
29 | color: "white"
30 | }
31 |
32 |
33 | Item {
34 | id: appList
35 | anchors.left: parent.left
36 | anchors.top: parent.top
37 | width: parent.width - trashItem.width
38 | height: parent.height
39 |
40 | ListView {
41 | id: pageView
42 | anchors.fill: parent
43 | orientation: Qt.Horizontal
44 | snapMode: ListView.SnapOneItem
45 | model: appModel
46 | clip: true
47 |
48 | delegate: AppItem { }
49 | }
50 | }
51 |
52 | DockItem {
53 | id: trashItem
54 | anchors.left: appList.right
55 | anchors.top: parent.top
56 | popupText: qsTr("Trash")
57 |
58 | iconSizeRatio: 0.75
59 | enableActivateDot: false
60 | iconName: "user-trash-empty"
61 |
62 | onClicked: {
63 | process.start("launch", ["Filer", "trash:///"])
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/resources.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | qml/main.qml
4 | qml/DockItem.qml
5 | qml/AppItem.qml
6 | svg/launcher.svg
7 | qml/PopupTips.qml
8 | qml/Menu.qml
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/applicationitem.h:
--------------------------------------------------------------------------------
1 | #ifndef APPLICATIONITEM_H
2 | #define APPLICATIONITEM_H
3 |
4 | #include
5 |
6 | class ApplicationItem
7 | {
8 | public:
9 | // window class
10 | QString id;
11 | // icon name
12 | QString iconName;
13 | // visible name
14 | QString visibleName;
15 | QString desktopPath;
16 | QString exec;
17 |
18 | QList wids;
19 |
20 | int currentActive = 0;
21 | bool isActive = false;
22 | bool isPined = false;
23 |
24 | bool operator==(ApplicationItem item) {
25 | return item.id == this->id;
26 | }
27 | };
28 |
29 | #endif // APPLICATIONITEM_H
30 |
--------------------------------------------------------------------------------
/src/applicationmodel.cpp:
--------------------------------------------------------------------------------
1 | #include "applicationmodel.h"
2 | #include "utils.h"
3 |
4 | #include
5 |
6 | #include "xwindowinterface.h"
7 | #include "utils.h"
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | // X11
20 | #include
21 | #include
22 | #include
23 |
24 |
25 | ApplicationModel::ApplicationModel(QObject *parent)
26 | : QAbstractListModel(parent),
27 | m_iface(XWindowInterface::instance()),
28 | m_sysAppMonitor(SystemAppMonitor::self()),
29 | m_iconSize(36*1/0.8) // probono: Was 88
30 | {
31 | connect(m_iface, &XWindowInterface::windowAdded, this, &ApplicationModel::onWindowAdded);
32 | connect(m_iface, &XWindowInterface::windowRemoved, this, &ApplicationModel::onWindowRemoved);
33 | connect(m_iface, &XWindowInterface::activeChanged, this, &ApplicationModel::onActiveChanged);
34 |
35 | initPinedApplications();
36 |
37 | QTimer::singleShot(100, m_iface, &XWindowInterface::startInitWindows);
38 | }
39 |
40 | int ApplicationModel::rowCount(const QModelIndex &parent) const
41 | {
42 | Q_UNUSED(parent)
43 |
44 | return m_appItems.size();
45 | }
46 |
47 | QHash ApplicationModel::roleNames() const
48 | {
49 | QHash roles;
50 | roles[AppIdRole] = "appId";
51 | roles[IconNameRole] = "iconName";
52 | roles[VisibleNameRole] = "visibleName";
53 | roles[ActiveRole] = "isActive";
54 | roles[WindowCountRole] = "windowCount";
55 | roles[IsPinedRole] = "isPined";
56 | return roles;
57 | }
58 |
59 | QVariant ApplicationModel::data(const QModelIndex &index, int role) const
60 | {
61 | if (!index.isValid())
62 | return QVariant();
63 |
64 | ApplicationItem *item = m_appItems.at(index.row());
65 |
66 | switch (role) {
67 | case AppIdRole:
68 | return item->id;
69 | case IconNameRole:
70 | return item->iconName;
71 | case VisibleNameRole:
72 | return item->visibleName;
73 | case ActiveRole:
74 | return item->isActive;
75 | case WindowCountRole:
76 | return item->wids.count();
77 | case IsPinedRole:
78 | return item->isPined;
79 | default:
80 | return QVariant();
81 | }
82 |
83 | // FIXME: Implement me!
84 | return QVariant();
85 | }
86 |
87 | void ApplicationModel::clicked(const QString &id)
88 | {
89 | ApplicationItem *item = findItemById(id);
90 |
91 | if (!item)
92 | return;
93 |
94 | // Application Item that has been pined,
95 | // We need to open it.
96 | if (item->wids.isEmpty()) {
97 | // open application
98 | openNewInstance(item->id);
99 | }
100 | // Multiple windows have been opened and need to switch between them,
101 | // The logic here needs to be improved.
102 | else if (item->wids.count() > 1) {
103 | item->currentActive++;
104 |
105 | if (item->currentActive == item->wids.count())
106 | item->currentActive = 0;
107 |
108 | m_iface->forceActiveWindow(item->wids.at(item->currentActive));
109 | } else if (m_iface->activeWindow() == item->wids.first()) {
110 | m_iface->minimizeWindow(item->wids.first());
111 | } else {
112 | m_iface->forceActiveWindow(item->wids.first());
113 | }
114 | }
115 |
116 | /*
117 | Split a QString into a QString list obeying quotes.
118 | FIXME: Not all edge cases might be covered, such as filenames that contain ' characters.
119 | Based on https://stackoverflow.com/a/25097755
120 | Input QString --> Foobar Test 'Test Foo' "Test Bar" Test\ Baz
121 | Output QStringList --> "Foobar", "Test", "Test Foo", "Test Bar", "Test Baz"
122 | */
123 | QStringList ApplicationModel::splitCommandLine(const QString & cmdLine)
124 | {
125 | QStringList list;
126 | QString arg;
127 | bool escape = false;
128 | enum { Idle, Arg, QuotedArg } state = Idle;
129 | foreach (QChar const c, cmdLine) {
130 | if (!escape && c == '\\') { escape = true; continue; }
131 | switch (state) {
132 | case Idle:
133 | if (!escape && (c == '"' || c == "'")) state = QuotedArg;
134 | else if (escape || !c.isSpace()) { arg += c; state = Arg; }
135 | break;
136 | case Arg:
137 | if (!escape && (c == '"' || c == "'")) state = QuotedArg;
138 | else if (escape || !c.isSpace()) arg += c;
139 | else { list << arg; arg.clear(); state = Idle; }
140 | break;
141 | case QuotedArg:
142 | if (!escape && (c == '"' || c == "'")) state = arg.isEmpty() ? Idle : Arg;
143 | else arg += c;
144 | break;
145 | }
146 | escape = false;
147 | }
148 | if (!arg.isEmpty()) list << arg;
149 | return list;
150 | }
151 |
152 | bool ApplicationModel::openNewInstance(const QString &appId)
153 | {
154 | ApplicationItem *item = findItemById(appId);
155 |
156 | if (!item)
157 | return false;
158 |
159 | QProcess process;
160 | if (!item->exec.isEmpty()) {
161 | QString argsString = item->exec ; // FIXME: Why don't we get double quotes (") here? At least we do get backslashes (if entered as \\) and single quotes (')
162 | // process.setProgram(args.first());
163 | // args.removeFirst();
164 | // probono: Nah, we use the 'launch' command instead
165 | process.setProgram("launch");
166 |
167 | if (!argsString.isEmpty()) {
168 | // qDebug() << "probono: Dock: argsString:" << argsString;
169 | QStringList args = splitCommandLine(argsString);
170 | // qDebug() << "probono: Dock: args:" << args;
171 | process.setArguments(args);
172 | }
173 |
174 | } else {
175 | process.setProgram(appId);
176 | }
177 |
178 | return process.startDetached();
179 | }
180 |
181 | void ApplicationModel::closeAllByAppId(const QString &appId)
182 | {
183 | ApplicationItem *item = findItemById(appId);
184 |
185 | if (!item)
186 | return;
187 |
188 | for (quint64 wid : item->wids) {
189 | m_iface->closeWindow(wid);
190 | }
191 | }
192 |
193 | void ApplicationModel::pin(const QString &appId)
194 | {
195 | ApplicationItem *item = findItemById(appId);
196 |
197 | if (!item)
198 | return;
199 |
200 | beginResetModel();
201 | item->isPined = true;
202 | endResetModel();
203 |
204 | savePinAndUnPinList();
205 | }
206 |
207 | void ApplicationModel::unPin(const QString &appId)
208 | {
209 | ApplicationItem *item = findItemById(appId);
210 |
211 | if (!item)
212 | return;
213 |
214 | beginResetModel();
215 | item->isPined = false;
216 | endResetModel();
217 |
218 | // Need to be removed after unpin
219 | if (item->wids.isEmpty()) {
220 | int index = indexOf(item->id);
221 | if (index != -1) {
222 | beginRemoveRows(QModelIndex(), index, index);
223 | m_appItems.removeAll(item);
224 | endRemoveRows();
225 | emit countChanged();
226 | }
227 | }
228 |
229 | savePinAndUnPinList();
230 | }
231 |
232 | void ApplicationModel::updateGeometries(const QString &id, QRect rect)
233 | {
234 | ApplicationItem *item = findItemById(id);
235 |
236 | // If not found
237 | if (!item)
238 | return;
239 |
240 | for (quint64 id : item->wids) {
241 | m_iface->setIconGeometry(id, rect);
242 | }
243 | }
244 |
245 | ApplicationItem *ApplicationModel::findItemByWId(quint64 wid)
246 | {
247 | for (ApplicationItem *item : m_appItems) {
248 | for (quint64 winId : item->wids) {
249 | if (winId == wid)
250 | return item;
251 | }
252 | }
253 |
254 | return nullptr;
255 | }
256 |
257 | ApplicationItem *ApplicationModel::findItemById(const QString &id)
258 | {
259 | for (ApplicationItem *item : m_appItems) {
260 | if (item->id == id)
261 | return item;
262 | }
263 |
264 | return nullptr;
265 | }
266 |
267 | bool ApplicationModel::contains(const QString &id)
268 | {
269 | for (ApplicationItem *item : qAsConst(m_appItems)) {
270 | if (item->id == id)
271 | return true;
272 | }
273 |
274 | return false;
275 | }
276 |
277 | int ApplicationModel::indexOf(const QString &id)
278 | {
279 | for (ApplicationItem *item : m_appItems) {
280 | if (item->id == id)
281 | return m_appItems.indexOf(item);
282 | }
283 |
284 | return -1;
285 | }
286 |
287 | void ApplicationModel::initPinedApplications()
288 | {
289 | QSettings settings(QSettings::UserScope, "cyberos", "dock_pinned");
290 | QStringList groups = settings.childGroups();
291 |
292 | for (int i = 0; i < groups.size(); ++i) {
293 | for (const QString &id : groups) {
294 | settings.beginGroup(id);
295 | int index = settings.value("Index").toInt();
296 |
297 | if (index == i) {
298 | beginInsertRows(QModelIndex(), rowCount(), rowCount());
299 | ApplicationItem *item = new ApplicationItem;
300 | item->iconName = settings.value("IconName").toString();
301 | item->visibleName = settings.value("visibleName").toString();
302 | item->exec = settings.value("Exec").toString();
303 | item->desktopPath = settings.value("DesktopPath").toString();
304 | item->id = id;
305 | item->isPined = true;
306 | m_appItems.append(item);
307 | endInsertRows();
308 | emit countChanged();
309 | settings.endGroup();
310 | break;
311 | } else {
312 | settings.endGroup();
313 | }
314 | }
315 | }
316 | }
317 |
318 | void ApplicationModel::savePinAndUnPinList()
319 | {
320 | QSettings settings(QSettings::UserScope, "cyberos", "dock_pinned");
321 | settings.clear();
322 |
323 | int index = 0;
324 |
325 | for (ApplicationItem *item : m_appItems) {
326 | if (item->isPined) {
327 | settings.beginGroup(item->id);
328 | settings.setValue("IconName", item->iconName);
329 | settings.setValue("visibleName", item->visibleName);
330 | settings.setValue("Exec", item->exec);
331 | settings.setValue("Index", index);
332 | settings.setValue("DesktopPath", item->desktopPath);
333 | settings.endGroup();
334 | ++index;
335 | }
336 | }
337 |
338 | settings.sync();
339 | }
340 |
341 | void ApplicationModel::onWindowAdded(quint64 wid)
342 | {
343 | qDebug() << "probono: onWindowAdded";
344 | QMap info = m_iface->requestInfo(wid);
345 | const QString id = info.value("id").toString();
346 |
347 | if (contains(id)) {
348 | for (ApplicationItem *item : m_appItems) {
349 | if (item->id == id) {
350 | // Need to update application active status.
351 | beginResetModel();
352 | item->wids.append(wid);
353 | item->isActive = info.value("active").toBool();
354 | endResetModel();
355 | }
356 | }
357 | } else {
358 | beginInsertRows(QModelIndex(), rowCount(), rowCount());
359 | ApplicationItem *item = new ApplicationItem;
360 | item->id = id;
361 | item->iconName = info.value("iconName").toString();
362 | item->visibleName = info.value("visibleName").toString();
363 | item->isActive = info.value("active").toBool();
364 | item->wids.append(wid);
365 |
366 | qDebug() << "probono: Checking for .app bundle or .AppDir";
367 | KWindowInfo info(wid, NET::WMPid);
368 | if (info.valid()){
369 | qDebug() << "probono: PID:" << info.pid();
370 | QMap processInfo = Utils::instance()->readInfoFromPid(info.pid());
371 |
372 | if(processInfo.value("Icon") != ""){
373 | qDebug() << "probono: Icon:" << processInfo.value("Icon");
374 | item->iconName = "file://" + processInfo.value("Icon");
375 | } else {
376 | // qDebug() << "probono: Icon empty, not using it";
377 | }
378 | if(processInfo.value("Name") != ""){
379 | qDebug() << "probono: Name:" << processInfo.value("Name");
380 | item->visibleName = processInfo.value("Name");
381 | } else {
382 | // qDebug() << "probono: Name empty, not using it";
383 | }
384 | if(processInfo.value("Exec") != ""){
385 | qDebug() << "probono: Exec:" << processInfo.value("Exec");
386 | item->exec = "'" + processInfo.value("Exec") + "'";
387 | } else {
388 | // qDebug() << "probono: Exec empty, not using it";
389 | }
390 | }
391 |
392 |
393 | if(item->exec.isEmpty()) {
394 | QString desktopPath = m_iface->desktopFilePath(wid);
395 | qDebug() << "probono: desktopPath:" << desktopPath;
396 |
397 | if (!desktopPath.isEmpty()) {
398 | qDebug() << "probono: Use information from desktop file";
399 | QMap desktopInfo = Utils::instance()->readInfoFromDesktop(desktopPath);
400 | item->iconName = desktopInfo.value("Icon");
401 | item->visibleName = desktopInfo.value("Name");
402 | item->exec = desktopInfo.value("Exec");
403 | item->desktopPath = desktopPath;
404 | }
405 | }
406 |
407 | m_appItems << item;
408 | endInsertRows();
409 | emit countChanged();
410 | }
411 | }
412 |
413 | void ApplicationModel::onWindowRemoved(quint64 wid)
414 | {
415 | ApplicationItem *item = findItemByWId(wid);
416 |
417 | if (!item)
418 | return;
419 |
420 | // Remove from wid list.
421 | beginResetModel();
422 | item->wids.removeOne(wid);
423 | endResetModel();
424 |
425 | if (item->wids.isEmpty()) {
426 | // If it is not fixed to the dock, need to remove it.
427 | if (!item->isPined) {
428 | int index = indexOf(item->id);
429 |
430 | if (index == -1)
431 | return;
432 |
433 | beginRemoveRows(QModelIndex(), index, index);
434 | m_appItems.removeAll(item);
435 | endRemoveRows();
436 | emit countChanged();
437 | }
438 | }
439 | }
440 |
441 | void ApplicationModel::onActiveChanged(quint64 wid)
442 | {
443 | // Using this method will cause the listview scrollbar to reset.
444 | // beginResetModel();
445 |
446 | for (ApplicationItem *item : m_appItems) {
447 | if (item->isActive != item->wids.contains(wid)) {
448 | item->isActive = item->wids.contains(wid);
449 |
450 | QModelIndex idx = index(indexOf(item->id), 0, QModelIndex());
451 | if (idx.isValid()) {
452 | emit dataChanged(idx, idx);
453 | }
454 | }
455 | }
456 | }
457 |
--------------------------------------------------------------------------------
/src/applicationmodel.h:
--------------------------------------------------------------------------------
1 | #ifndef APPLICATIONMODEL_H
2 | #define APPLICATIONMODEL_H
3 |
4 | #include
5 | #include "applicationitem.h"
6 | #include "systemappmonitor.h"
7 | #include "xwindowinterface.h"
8 |
9 | class ApplicationModel : public QAbstractListModel
10 | {
11 | Q_OBJECT
12 |
13 | public:
14 | enum Roles {
15 | AppIdRole = Qt::UserRole + 1,
16 | IconNameRole,
17 | IconSizeRole,
18 | VisibleNameRole,
19 | ActiveRole,
20 | WindowCountRole,
21 | IsPinedRole
22 | };
23 |
24 | explicit ApplicationModel(QObject *parent = nullptr);
25 |
26 | int rowCount(const QModelIndex &parent = QModelIndex()) const override;
27 | QHash roleNames() const override;
28 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
29 |
30 | Q_INVOKABLE void clicked(const QString &id);
31 |
32 | Q_INVOKABLE bool openNewInstance(const QString &appId);
33 | Q_INVOKABLE void closeAllByAppId(const QString &appId);
34 | Q_INVOKABLE void pin(const QString &appId);
35 | Q_INVOKABLE void unPin(const QString &appId);
36 |
37 | Q_INVOKABLE void updateGeometries(const QString &id, QRect rect);
38 |
39 | int iconSize() { return m_iconSize; }
40 |
41 | signals:
42 | void countChanged();
43 |
44 | private:
45 | ApplicationItem *findItemByWId(quint64 wid);
46 | ApplicationItem *findItemById(const QString &id);
47 | bool contains(const QString &id);
48 | int indexOf(const QString &id);
49 | void initPinedApplications();
50 | void savePinAndUnPinList();
51 | void onWindowAdded(quint64 wid);
52 | void onWindowRemoved(quint64 wid);
53 | void onActiveChanged(quint64 wid);
54 | static QStringList splitCommandLine(const QString & cmdLine);
55 |
56 | private:
57 | XWindowInterface *m_iface;
58 | SystemAppMonitor *m_sysAppMonitor;
59 | QList m_appItems;
60 | int m_iconSize;
61 | };
62 |
63 | #endif // APPLICATIONMODEL_H
64 |
--------------------------------------------------------------------------------
/src/docksettings.cpp:
--------------------------------------------------------------------------------
1 | #include "docksettings.h"
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | static const QString Service = "org.cyber.settings";
10 | static const QString ObjectPath = "/Theme";
11 | static const QString Interface = "org.cyber.Theme";
12 |
13 | static DockSettings *SELF = nullptr;
14 |
15 | DockSettings *DockSettings::self()
16 | {
17 | if (SELF == nullptr)
18 | SELF = new DockSettings;
19 |
20 | return SELF;
21 | }
22 |
23 | DockSettings::DockSettings(QObject *parent)
24 | : QObject(parent)
25 | , m_darkMode(false)
26 | , m_direction(Bottom)
27 | , m_settings(new QSettings(QSettings::UserScope, "cyberos", "dock"))
28 | , m_fileWatcher(new QFileSystemWatcher(this))
29 | {
30 | QDBusServiceWatcher *serviceWatcher = new QDBusServiceWatcher(Service, QDBusConnection::sessionBus(),
31 | QDBusServiceWatcher::WatchForRegistration);
32 | connect(serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [=] {
33 | initDBusSignals();
34 | initData();
35 | });
36 |
37 | initDBusSignals();
38 | initData();
39 | }
40 |
41 | void DockSettings::setDarkMode(bool enable)
42 | {
43 | if (m_darkMode != enable) {
44 | m_darkMode = enable;
45 | emit darkModeChanged();
46 | }
47 | }
48 |
49 | void DockSettings::setDirection(Direction direction)
50 | {
51 | if (m_direction != direction) {
52 | m_direction = direction;
53 | emit directionChanged();
54 | }
55 | }
56 |
57 | void DockSettings::onDBusDarkModeChanged(bool darkMode)
58 | {
59 | m_darkMode = darkMode;
60 |
61 | emit darkModeChanged();
62 | }
63 |
64 | void DockSettings::initDBusSignals()
65 | {
66 | QDBusInterface iface(Service, ObjectPath, Interface, QDBusConnection::sessionBus(), this);
67 |
68 | if (iface.isValid()) {
69 | QDBusConnection::sessionBus().connect(Service, ObjectPath, Interface, "darkModeChanged",
70 | this, SLOT(onDBusDarkModeChanged(bool)));
71 | }
72 | }
73 |
74 | void DockSettings::initData()
75 | {
76 | QDBusInterface iface(Service, ObjectPath, Interface, QDBusConnection::sessionBus(), this);
77 |
78 | if (iface.isValid()) {
79 | m_darkMode = iface.property("isDarkMode").toBool();
80 |
81 | emit darkModeChanged();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/docksettings.h:
--------------------------------------------------------------------------------
1 | #ifndef DOCKSETTINGS_H
2 | #define DOCKSETTINGS_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | class DockSettings : public QObject
9 | {
10 | Q_OBJECT
11 | Q_PROPERTY(bool darkMode READ darkMode NOTIFY darkModeChanged)
12 |
13 | public:
14 | enum Direction {
15 | Left = 0,
16 | Right,
17 | Bottom
18 | };
19 |
20 | static DockSettings *self();
21 | explicit DockSettings(QObject *parent = nullptr);
22 |
23 | bool darkMode() { return m_darkMode; }
24 | void setDarkMode(bool enable);
25 |
26 | void setDirection(Direction direction);
27 |
28 | private slots:
29 | void onDBusDarkModeChanged(bool darkMode);
30 |
31 | private:
32 | void initDBusSignals();
33 | void initData();
34 |
35 | Q_SIGNALS:
36 | void darkModeChanged();
37 | void directionChanged();
38 |
39 | private:
40 | bool m_darkMode;
41 | Direction m_direction;
42 | QSettings *m_settings;
43 | QFileSystemWatcher *m_fileWatcher;
44 | };
45 |
46 | #endif // DOCKSETTINGS_H
47 |
--------------------------------------------------------------------------------
/src/iconthemeimageprovider.cpp:
--------------------------------------------------------------------------------
1 | #include "iconthemeimageprovider.h"
2 | #include
3 |
4 | IconThemeImageProvider::IconThemeImageProvider()
5 | : QQuickImageProvider(QQuickImageProvider::Pixmap)
6 | {
7 | }
8 |
9 | QPixmap IconThemeImageProvider::requestPixmap(const QString &id, QSize *realSize,
10 | const QSize &requestedSize)
11 | {
12 | // Sanitize requested size
13 | QSize size(requestedSize);
14 | if (size.width() < 1)
15 | size.setWidth(1);
16 | if (size.height() < 1)
17 | size.setHeight(1);
18 |
19 | // Return real size
20 | if (realSize)
21 | *realSize = size;
22 |
23 | // Is it a path?
24 | if (id.startsWith(QLatin1Char('/')))
25 | return QPixmap(id).scaled(size);
26 |
27 | // Return icon from theme or fallback to a generic icon
28 | QIcon icon = QIcon::fromTheme(id);
29 | if (icon.isNull())
30 | icon = QIcon::fromTheme(QLatin1String("application-default-icon"));
31 | return icon.pixmap(size);
32 | }
33 |
--------------------------------------------------------------------------------
/src/iconthemeimageprovider.h:
--------------------------------------------------------------------------------
1 | #ifndef ICONTHEMEIMAGEPROVIDER_H
2 | #define ICONTHEMEIMAGEPROVIDER_H
3 |
4 | #include
5 |
6 | class IconThemeImageProvider : public QQuickImageProvider
7 | {
8 | public:
9 | IconThemeImageProvider();
10 |
11 | QPixmap requestPixmap(const QString &id, QSize *realSize, const QSize &requestedSize);
12 | };
13 |
14 | #endif // ICONTHEMEIMAGEPROVIDER_H
15 |
--------------------------------------------------------------------------------
/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "applicationmodel.h"
5 | #include "mainwindow.h"
6 |
7 | int main(int argc, char *argv[])
8 | {
9 | QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
10 | QApplication app(argc, argv);
11 |
12 | MainWindow w;
13 |
14 | return app.exec();
15 | }
16 |
--------------------------------------------------------------------------------
/src/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "iconthemeimageprovider.h"
3 | #include "processprovider.h"
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | #include
18 | #include
19 |
20 | MainWindow::MainWindow(QQuickView *parent)
21 | : QQuickView(parent)
22 | , m_settings(DockSettings::self())
23 | , m_appModel(new ApplicationModel)
24 | , m_popupTips(new PopupTips)
25 | , m_resizeAnimation(new QVariantAnimation(this))
26 | {
27 | setDefaultAlphaBuffer(true);
28 | setColor(Qt::transparent);
29 |
30 | setFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
31 | KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager);
32 | KWindowSystem::setOnDesktop(winId(), NET::OnAllDesktops);
33 | KWindowSystem::setType(winId(), NET::Dock);
34 |
35 | engine()->rootContext()->setContextProperty("appModel", m_appModel);
36 | engine()->rootContext()->setContextProperty("process", new ProcessProvider);
37 | engine()->rootContext()->setContextProperty("popupTips", m_popupTips);
38 | engine()->rootContext()->setContextProperty("Settings", m_settings);
39 | engine()->addImageProvider("icontheme", new IconThemeImageProvider);
40 |
41 | setResizeMode(QQuickView::SizeRootObjectToView);
42 | setClearBeforeRendering(true);
43 | setScreen(qGuiApp->primaryScreen());
44 | setSource(QUrl(QStringLiteral("qrc:/qml/main.qml")));
45 | resizeWindow();
46 |
47 | connect(this, &QQuickView::xChanged, this, &MainWindow::updatePosition);
48 | connect(this, &QQuickView::yChanged, this, &MainWindow::updatePosition);
49 | connect(m_appModel, &ApplicationModel::countChanged, this, &MainWindow::resizeWindow);
50 | connect(m_resizeAnimation, &QVariantAnimation::valueChanged, this, &MainWindow::onResizeValueChanged);
51 | connect(m_resizeAnimation, &QVariantAnimation::finished, this, &MainWindow::updateViewStruts);
52 | }
53 |
54 | void MainWindow::updatePosition()
55 | {
56 | const QRect screenGeometry = screen()->geometry();
57 | QPoint position = {0, 0};
58 | int margin = 0;
59 |
60 | // bottom
61 | position = { screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - height()};
62 | m_maxLength = screenGeometry.width();
63 |
64 | position.setX((screenGeometry.width() - geometry().width()) / 2);
65 |
66 | // left
67 | // position = {screenGeometry.x(), screenGeometry.y()};
68 | // m_maxLength = screenGeometry.height();
69 |
70 | setX(position.x());
71 | setY(position.y() - margin / 2);
72 | }
73 |
74 | void MainWindow::resizeWindow()
75 | {
76 | // Change the window size means that the number of dock items changes
77 | // Need to hide popup tips.
78 | m_popupTips->hide();
79 |
80 | QSize screenSize = screen()->size();
81 |
82 | // Trash
83 | int fixedItemCount = 1;
84 |
85 | // horizontal
86 | int maxWidth = screenSize.width();
87 | int calcWidth = m_appModel->iconSize() * fixedItemCount;
88 |
89 | // Calculate the width to ensure that the window width
90 | // cannot be greater than the screen width.
91 | for (int i = 1; i <= m_appModel->rowCount(); ++i) {
92 | calcWidth += m_appModel->iconSize();
93 |
94 | // Has exceeded the screen width
95 | if (calcWidth >= maxWidth) {
96 | calcWidth -= m_appModel->iconSize();
97 | break;
98 | }
99 | }
100 |
101 | QSize newSize { calcWidth, m_appModel->iconSize() };
102 |
103 | if (m_resizeAnimation->state() == QVariantAnimation::Running) {
104 | m_resizeAnimation->stop();
105 | }
106 |
107 | // Set zoom in and zoom out the ease curve
108 | if (newSize.width() > size().width()) {
109 | m_resizeAnimation->setEasingCurve(QEasingCurve::OutCubic);
110 | } else {
111 | m_resizeAnimation->setEasingCurve(QEasingCurve::InCubic);
112 | }
113 |
114 | // If the window size has not changed, there is no need to resize
115 | if (this->size() != newSize) {
116 | // Disable blur during resizing
117 | XWindowInterface::instance()->enableBlurBehind(this, false);
118 |
119 | // Start the resize animation
120 | m_resizeAnimation->setDuration(1);
121 | m_resizeAnimation->setStartValue(this->size());
122 | m_resizeAnimation->setEndValue(newSize);
123 | m_resizeAnimation->start();
124 | }
125 | setVisible(true);
126 | }
127 |
128 | void MainWindow::updateBlurRegion()
129 | {
130 | const QRect rect { 0, 0, size().width(), size().height() };
131 | XWindowInterface::instance()->enableBlurBehind(this, true, cornerMask(rect, rect.height() * 0.3));
132 | }
133 |
134 | void MainWindow::updateViewStruts()
135 | {
136 | XWindowInterface::instance()->setViewStruts(this, geometry());
137 | }
138 |
139 | void MainWindow::onResizeValueChanged(const QVariant &value)
140 | {
141 | const QSize &s = value.toSize();
142 | setMinimumSize(s);
143 | setMaximumSize(s);
144 | resize(s);
145 | updatePosition();
146 | updateBlurRegion();
147 | }
148 |
149 | QRegion MainWindow::cornerMask(const QRect &rect, const int r)
150 | {
151 | QRegion region;
152 | // middle and borders
153 | region += rect.adjusted(r, 0, -r, 0);
154 | region += rect.adjusted(0, r, 0, -r);
155 |
156 | // top left
157 | QRect corner(rect.topLeft(), QSize(r * 2, r * 2));
158 | region += QRegion(corner, QRegion::Ellipse);
159 |
160 | // top right
161 | corner.moveTopRight(rect.topRight());
162 | region += QRegion(corner, QRegion::Ellipse);
163 |
164 | // bottom left
165 | // corner.moveBottomLeft(rect.bottomLeft());
166 | // region += QRegion(corner, QRegion::Ellipse);
167 |
168 | // bottom right
169 | corner.moveBottomRight(rect.bottomRight());
170 | region += QRegion(corner, QRegion::Ellipse);
171 |
172 | return region;
173 | }
174 |
--------------------------------------------------------------------------------
/src/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | #include "docksettings.h"
9 | #include "applicationmodel.h"
10 | #include "popuptips.h"
11 |
12 | class MainWindow : public QQuickView
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | explicit MainWindow(QQuickView *parent = nullptr);
18 |
19 | private:
20 | void updatePosition();
21 | void resizeWindow();
22 | void updateBlurRegion();
23 | void updateViewStruts();
24 | void onResizeValueChanged(const QVariant &value);
25 |
26 | QRegion cornerMask(const QRect &rect, const int r);
27 |
28 | private:
29 | DockSettings *m_settings;
30 | ApplicationModel *m_appModel;
31 | PopupTips *m_popupTips;
32 | QVariantAnimation *m_resizeAnimation;
33 | int m_maxLength;
34 | };
35 |
36 | #endif // MAINWINDOW_H
37 |
--------------------------------------------------------------------------------
/src/popuptips.cpp:
--------------------------------------------------------------------------------
1 | #include "popuptips.h"
2 | #include "docksettings.h"
3 | #include "xwindowinterface.h"
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | PopupTips::PopupTips(QQuickView *parent)
14 | : QQuickView(parent)
15 | {
16 | engine()->rootContext()->setContextProperty("Settings", DockSettings::self());
17 |
18 | setFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus | Qt::ToolTip);
19 | setResizeMode(QQuickView::SizeViewToRootObject);
20 | setClearBeforeRendering(true);
21 | setDefaultAlphaBuffer(true);
22 | setColor(Qt::transparent);
23 | setSource(QUrl(QStringLiteral("qrc:/qml/PopupTips.qml")));
24 | }
25 |
26 | void PopupTips::popup(const QPointF point, const QString &text)
27 | {
28 | if (text.isEmpty()) {
29 | return hide();
30 | }
31 |
32 | const int padding = 10;
33 |
34 | QMetaObject::invokeMethod(rootObject(), "setText", Q_ARG(QVariant, text));
35 | QMetaObject::invokeMethod(rootObject(), "setVisible", Q_ARG(QVariant, true));
36 |
37 | setVisible(true);
38 | setX(point.x());
39 | setY(point.y() - height() - padding);
40 |
41 | QTimer::singleShot(100, this, &PopupTips::updateBlurRegion);
42 | }
43 |
44 | void PopupTips::hide()
45 | {
46 | setVisible(false);
47 | }
48 |
49 | void PopupTips::updateBlurRegion()
50 | {
51 | QPainterPath path;
52 | path.addRoundedRect(QRect(0, 0, geometry().width(), geometry().height()), 4, 4);
53 | XWindowInterface::instance()->enableBlurBehind(this, true, path.toFillPolygon().toPolygon());
54 | }
55 |
--------------------------------------------------------------------------------
/src/popuptips.h:
--------------------------------------------------------------------------------
1 | #ifndef POPUPTIPSMANAGER_H
2 | #define POPUPTIPSMANAGER_H
3 |
4 | #include
5 |
6 | class PopupTips : public QQuickView
7 | {
8 | Q_OBJECT
9 |
10 | public:
11 | explicit PopupTips(QQuickView *parent = nullptr);
12 |
13 | Q_INVOKABLE void popup(const QPointF point, const QString &text);
14 | Q_INVOKABLE void hide();
15 | Q_INVOKABLE void updateBlurRegion();
16 | };
17 |
18 | #endif // POPUPTIPSMANAGER_H
19 |
--------------------------------------------------------------------------------
/src/processprovider.cpp:
--------------------------------------------------------------------------------
1 | #include "processprovider.h"
2 | #include
3 |
4 | ProcessProvider::ProcessProvider(QObject *parent)
5 | : QObject(parent)
6 | {
7 |
8 | }
9 |
10 | bool ProcessProvider::start(const QString &exec, QStringList args)
11 | {
12 | QProcess process;
13 | process.setProgram(exec);
14 | process.setArguments(args);
15 | return process.startDetached();
16 | }
17 |
--------------------------------------------------------------------------------
/src/processprovider.h:
--------------------------------------------------------------------------------
1 | #ifndef PROCESSPROVIDER_H
2 | #define PROCESSPROVIDER_H
3 |
4 | #include
5 |
6 | class ProcessProvider : public QObject
7 | {
8 | Q_OBJECT
9 |
10 | public:
11 | explicit ProcessProvider(QObject *parent = nullptr);
12 |
13 | Q_INVOKABLE bool start(const QString &exec, QStringList args = QStringList());
14 | };
15 |
16 | #endif // PROCESSPROVIDER_H
17 |
--------------------------------------------------------------------------------
/src/systemappitem.cpp:
--------------------------------------------------------------------------------
1 | #include "systemappitem.h"
2 |
3 | SystemAppItem::SystemAppItem(QObject *parent)
4 | : QObject(parent)
5 | {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/systemappitem.h:
--------------------------------------------------------------------------------
1 | #ifndef SYSTEMAPPITEM_H
2 | #define SYSTEMAPPITEM_H
3 |
4 | #include
5 |
6 | class SystemAppItem : public QObject
7 | {
8 | Q_OBJECT
9 |
10 | public:
11 | explicit SystemAppItem(QObject *parent = nullptr);
12 |
13 | QString path;
14 | QString name;
15 | QString genericName;
16 | QString comment;
17 | QString iconName;
18 | QString startupWMClass;
19 | QString exec;
20 | QStringList args;
21 | };
22 |
23 | #endif // SYSTEMAPPITEM_H
24 |
--------------------------------------------------------------------------------
/src/systemappmonitor.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 ~ 2021 CyberOS Team.
3 | *
4 | * Author: rekols
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include "systemappmonitor.h"
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | static SystemAppMonitor *SELF = nullptr;
29 |
30 | static QByteArray detectDesktopEnvironment()
31 | {
32 | const QByteArray desktop = qgetenv("XDG_CURRENT_DESKTOP");
33 |
34 | if (!desktop.isEmpty())
35 | return desktop.toUpper();
36 |
37 | return QByteArray("UNKNOWN");
38 | }
39 |
40 | SystemAppMonitor *SystemAppMonitor::self()
41 | {
42 | if (SELF == nullptr)
43 | SELF = new SystemAppMonitor;
44 |
45 | return SELF;
46 | }
47 |
48 | SystemAppMonitor::SystemAppMonitor(QObject *parent)
49 | : QObject(parent)
50 | {
51 | QFileSystemWatcher *watcher = new QFileSystemWatcher(this);
52 | QStringList paths = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
53 | for (int i = 0; i < paths.size(); i++) {
54 | watcher->addPath(paths[i]);
55 | }
56 | connect(watcher, &QFileSystemWatcher::directoryChanged, this, &SystemAppMonitor::refresh);
57 | refresh();
58 | }
59 |
60 | SystemAppMonitor::~SystemAppMonitor()
61 | {
62 | while (!m_items.isEmpty())
63 | delete m_items.takeFirst();
64 | }
65 |
66 | SystemAppItem *SystemAppMonitor::find(const QString &filePath)
67 | {
68 | for (SystemAppItem *item : m_items)
69 | if (item->path == filePath)
70 | return item;
71 |
72 | return nullptr;
73 | }
74 |
75 | void SystemAppMonitor::refresh()
76 | {
77 | QStringList addedEntries;
78 | for (SystemAppItem *item : m_items)
79 | addedEntries.append(item->path);
80 |
81 | QStringList allEntries;
82 | QStringList paths = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
83 | for (int i = 0; i < paths.size(); i++) {
84 | QDirIterator it(paths[i], { "*.desktop" }, QDir::NoFilter, QDirIterator::Subdirectories);
85 |
86 | while (it.hasNext()) {
87 | const QString &filePath = it.next();
88 |
89 | if (!QFile::exists(filePath))
90 | continue;
91 |
92 | allEntries.append(filePath);
93 | }
94 | }
95 |
96 | for (const QString &filePath : allEntries) {
97 | if (!addedEntries.contains(filePath)) {
98 | addApplication(filePath);
99 | }
100 | }
101 |
102 | for (SystemAppItem *item : m_items) {
103 | if (!allEntries.contains(item->path)) {
104 | removeApplication(item);
105 | }
106 | }
107 |
108 | emit refreshed();
109 | }
110 |
111 | void SystemAppMonitor::addApplication(const QString &filePath)
112 | {
113 | if (find(filePath))
114 | return;
115 |
116 | QSettings desktop(filePath, QSettings::IniFormat);
117 | desktop.setIniCodec("UTF-8");
118 | desktop.beginGroup("Desktop Entry");
119 |
120 | if (desktop.contains("OnlyShowIn")) {
121 | const QString &value = desktop.value("OnlyShowIn").toString();
122 | if (!value.contains(detectDesktopEnvironment(), Qt::CaseInsensitive)) {
123 | return;
124 | }
125 | }
126 |
127 | if (desktop.value("NoDisplay").toBool() ||
128 | desktop.value("Hidden").toBool()) {
129 | return;
130 | }
131 |
132 | QString appName = desktop.value(QString("Name[%1]").arg(QLocale::system().name())).toString();
133 | QString appExec = desktop.value("Exec").toString();
134 |
135 | if (appName.isEmpty())
136 | appName = desktop.value("Name").toString();
137 |
138 | appExec.remove(QRegularExpression("%."));
139 | appExec.remove(QRegularExpression("^\""));
140 | // appExec.remove(QRegularExpression(" *$"));
141 | appExec = appExec.simplified();
142 |
143 | SystemAppItem *item = new SystemAppItem;
144 | item->path = filePath;
145 | item->name = appName;
146 | item->genericName = desktop.value("GenericName").toString();
147 | item->comment = desktop.value("Comment").toString();
148 | item->iconName = desktop.value("Icon").toString();
149 | item->startupWMClass = desktop.value("StartupWMClass").toString();
150 | item->exec = appExec;
151 | item->args = appExec.split(" ");
152 |
153 | m_items.append(item);
154 | }
155 |
156 | void SystemAppMonitor::removeApplication(SystemAppItem *item)
157 | {
158 | m_items.removeOne(item);
159 | item->deleteLater();
160 | }
161 |
--------------------------------------------------------------------------------
/src/systemappmonitor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 ~ 2021 CyberOS Team.
3 | *
4 | * Author: rekols
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef SYSTEMAPPMONITOR_H
21 | #define SYSTEMAPPMONITOR_H
22 |
23 | #include
24 | #include
25 | #include
26 | #include "systemappitem.h"
27 |
28 | class SystemAppMonitor : public QObject
29 | {
30 | Q_OBJECT
31 |
32 | public:
33 | static SystemAppMonitor *self();
34 |
35 | explicit SystemAppMonitor(QObject *parent = nullptr);
36 | ~SystemAppMonitor();
37 |
38 | SystemAppItem *find(const QString &filePath);
39 | QList applications() { return m_items; }
40 |
41 | signals:
42 | void refreshed();
43 |
44 | private:
45 | void refresh();
46 | void addApplication(const QString &filePath);
47 | void removeApplication(SystemAppItem *item);
48 |
49 | private:
50 | QList m_items;
51 | };
52 |
53 | #endif // SYSTEMAPPMONITOR_H
54 |
--------------------------------------------------------------------------------
/src/trashmanager.cpp:
--------------------------------------------------------------------------------
1 | #include "trashmanager.h"
2 | #include
3 | #include
4 |
5 | const QString TrashDir = QDir::homePath() + "/.local/share/Trash";
6 | const QDir::Filters ItemsShouldCount = QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot;
7 |
8 | TrashManager::TrashManager(QObject *parent)
9 | : QObject(parent),
10 | m_filesWatcher(new QFileSystemWatcher(this)),
11 | m_count(0)
12 | {
13 | onDirectoryChanged();
14 | connect(m_filesWatcher, &QFileSystemWatcher::directoryChanged, this, &TrashManager::onDirectoryChanged, Qt::QueuedConnection);
15 | }
16 |
17 | void TrashManager::emptyTrash()
18 | {
19 |
20 | }
21 |
22 | void TrashManager::openTrash()
23 | {
24 | QProcess::startDetached("gio", QStringList() << "open" << "trash:///");
25 | }
26 |
27 | void TrashManager::onDirectoryChanged()
28 | {
29 | m_filesWatcher->addPath(TrashDir);
30 |
31 | if (QDir(TrashDir + "/files").exists()) {
32 | m_filesWatcher->addPath(TrashDir + "/files");
33 | m_count = QDir(TrashDir + "/files").entryList(ItemsShouldCount).count();
34 | } else {
35 | m_count = 0;
36 | }
37 |
38 | emit countChanged();
39 | }
40 |
--------------------------------------------------------------------------------
/src/trashmanager.h:
--------------------------------------------------------------------------------
1 | #ifndef TRASHMANAGER_H
2 | #define TRASHMANAGER_H
3 |
4 | #include
5 | #include
6 |
7 | class TrashManager : public QObject
8 | {
9 | Q_OBJECT
10 | Q_PROPERTY(int count READ count NOTIFY countChanged)
11 |
12 | public:
13 | explicit TrashManager(QObject *parent = nullptr);
14 |
15 | Q_INVOKABLE void openTrash();
16 | Q_INVOKABLE void emptyTrash();
17 |
18 | int count() { return m_count; }
19 |
20 | Q_SIGNALS:
21 | void countChanged();
22 |
23 | private slots:
24 | void onDirectoryChanged();
25 |
26 | private:
27 | QFileSystemWatcher *m_filesWatcher;
28 | int m_count;
29 | };
30 |
31 | #endif // TRASHMANAGER_H
32 |
--------------------------------------------------------------------------------
/src/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 | #include "systemappmonitor.h"
3 | #include "systemappitem.h"
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 |
14 | static Utils *INSTANCE = nullptr;
15 |
16 | Utils *Utils::instance()
17 | {
18 | if (!INSTANCE)
19 | INSTANCE = new Utils;
20 |
21 | return INSTANCE;
22 | }
23 |
24 | Utils::Utils(QObject *parent)
25 | : QObject(parent)
26 | , m_sysAppMonitor(SystemAppMonitor::self())
27 | {
28 |
29 | }
30 |
31 | // probono: Get launchableExecutable, applicationName, and icon for a given process ID
32 | // from .app bundles and .AppDir directories
33 | QMap Utils::examinePotentialBundlePath(QString path)
34 | {
35 |
36 | qDebug() << "probono: path to be examined:" << path;
37 |
38 | QMap info; // Data structure to be returned
39 | QString launchableExecutable = "";
40 | QString applicationName = "";
41 | QString icon = "";
42 |
43 | QFileInfo fileInfo = QFileInfo(path);
44 | QString nameWithoutSuffix = QFileInfo(fileInfo.completeBaseName()).fileName();
45 |
46 | // (Simplified) GNUstep .app bundle
47 | if (path.toLower().endsWith(".app")) {
48 | QFile executableFile(path.toUtf8() + "/" + nameWithoutSuffix);
49 | if (executableFile.exists() && QFileInfo(executableFile).isExecutable()) {
50 | qDebug() << "probono: We have an .app bundle";
51 | launchableExecutable = QString(path + "/" + nameWithoutSuffix);
52 | applicationName = nameWithoutSuffix;
53 | }
54 |
55 | QFile tiffFile1(path.toUtf8() + "/Resources/" + nameWithoutSuffix.toUtf8() + ".tiff");
56 | if (tiffFile1.exists()) {
57 | icon = QFileInfo(tiffFile1).canonicalFilePath();
58 | }
59 | QFile tiffFile2(path.toUtf8() + "/.dir.tiff");
60 | if (tiffFile2.exists()) {
61 | icon = QFileInfo(tiffFile2).canonicalFilePath();
62 | }
63 | QFile pngFile1(path.toUtf8() + "/Resources/" + nameWithoutSuffix.toUtf8() + ".png");
64 | QFile svgFile1(path.toUtf8() + "/Resources/" + nameWithoutSuffix.toUtf8() + ".svg");
65 | if (svgFile1.exists()) {
66 | qDebug() << "probono: FIXME: There is a svg but we are not using it yet";
67 | }
68 | if (pngFile1.exists()) {
69 | icon = QFileInfo(pngFile1).canonicalFilePath();
70 | }
71 | }
72 |
73 | // ROX AppDir
74 | QFile appRunFile(path.toUtf8() + "/AppRun");
75 | if ((appRunFile.exists()) && QFileInfo(appRunFile).isExecutable()) {
76 | launchableExecutable = QString(path + "/AppRun");
77 | applicationName = nameWithoutSuffix;
78 | qDebug() << "probono: We have an AppDir";
79 |
80 | QFile dirIconFile(path.toUtf8() + "/.DirIcon");
81 | if (dirIconFile.exists()) {
82 | icon = QFileInfo(dirIconFile).canonicalFilePath();
83 | }
84 | }
85 | if(icon != "")
86 | info.insert("Icon", icon);
87 | if(applicationName != "")
88 | info.insert("Name", applicationName);
89 | if(launchableExecutable != "")
90 | info.insert("Exec", launchableExecutable);
91 | return info;
92 | }
93 |
94 | QMap Utils::readInfoFromPid(quint32 pid)
95 | {
96 | QMap info; // Data structure to be returned
97 | QString launchableExecutable = "";
98 | QString applicationName = "";
99 | QString icon = "";
100 |
101 | QStringList args; // Arguments of the proecss determined by pid
102 |
103 | #if __FreeBSD__
104 |
105 | // On FreeBSD, /proc is optional and considered deprecated
106 |
107 | QProcess *p = new QProcess();
108 | p->setProgram("procstat");
109 | QStringList arguments;
110 | arguments << "--libxo=xml,pretty" << "arguments" << QString::number(pid);
111 | p->setArguments(arguments);
112 | p->start();
113 | p->waitForFinished();
114 | QList lines = p->readAllStandardOutput().split('\n');
115 | // TODO: Should probably take only the first three args into consideration
116 | foreach (const QByteArray &line, lines) {
117 | QString arg = QString::fromUtf8(line).trimmed();
118 | if(arg.startsWith("") and arg.endsWith("")) {
119 | arg = arg.replace("", "").replace("", "");
120 | args.append(arg);
121 | }
122 | }
123 |
124 | #else
125 |
126 | // Read cmdline from /proc; make sure to get all zero-delimited parts of it
127 | // because our .app bundle or .AppDir might well be the second argument (e.g., 'python /Some/App.app/App args')
128 | QFile file(QString("/proc/%1/cmdline").arg(pid));
129 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
130 | qDebug() << "Could not open /proc, hence could not get information about the process that belongs to the window";
131 | QList list = file.readAll().split('\0');
132 | list.takeLast(); // Remove extraneous last item
133 |
134 | // Convert to QStringList
135 | foreach (const QByteArray &item, list) {
136 | args.append(QString::fromUtf8(item));
137 | }
138 |
139 | #endif
140 |
141 | qDebug() << "probono: args" << args;
142 | foreach (const QString &part, args) { // FIXME: Consider only the first two parts as possible paths
143 |
144 | // Determine whether we have an AppDir or .app bundle at hand and if yes, get launchableExecutable, applicationName, and icon
145 | // This code is similar to bundle.cpp in Filer; we might consider creating a static library for it
146 |
147 | QString path = QFileInfo(part).canonicalPath(); // Resolve symlinks and get absolute path
148 |
149 | if(QFileInfo(part).exists() == false) {
150 | continue;
151 | }
152 |
153 | info = examinePotentialBundlePath(path);
154 |
155 | if((info.value("Icon") != "") && (info.value("Name") != "") && (info.value("Exec") != "")) {
156 | return info;
157 | }
158 |
159 | // Also check the parent directory because it is not uncommon that the main executable is in a subdirectory
160 | // TODO: "Search up" multiple levels until an .app bundle or .AppDir is found; how?
161 |
162 | QString parent_path = QFileInfo(part + "/../").canonicalPath(); // Resolve symlinks and get absolute path
163 | qDebug() << "probono: Trying parent_path:" << parent_path;
164 | info = examinePotentialBundlePath(parent_path);
165 |
166 | if((info.value("Icon") != "") && (info.value("Name") != "") && (info.value("Exec") != "")) {
167 | return info;
168 | }
169 | }
170 | return info;
171 | }
172 |
173 | QString Utils::cmdFromPid(quint32 pid)
174 | {
175 | QFile file(QString("/proc/%1/cmdline").arg(pid));
176 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
177 | return QString();
178 |
179 | QList list = file.readAll().split('\0');
180 | list.takeLast(); // Remove extraneous last item
181 | // Convert to QStringList
182 | QStringList parts;
183 | foreach (const QByteArray &item, list) {
184 | parts.append(QString::fromUtf8(item));
185 | }
186 |
187 | // QString cmd = QString::fromUtf8(file.readAll()); // probono: This gives only the first part so we need to do something else
188 |
189 | return parts[0];
190 | QString bin;
191 | }
192 |
193 | QString Utils::desktopPathFromMetadata(const QString &appId, quint32 pid, const QString &xWindowWMClassName)
194 | {
195 | qDebug() << "probono: desktopPathFromMetadata";
196 | qDebug() << "probono: appId:" << appId;
197 | qDebug() << "probono: xWindowWMClassName" << xWindowWMClassName;
198 | QString result;
199 |
200 | if (!appId.isEmpty() && !xWindowWMClassName.isEmpty()) {
201 | for (SystemAppItem *item : m_sysAppMonitor->applications()) {
202 | QFileInfo desktopFileInfo(item->path);
203 | bool founded = false;
204 |
205 | if (desktopFileInfo.baseName() == xWindowWMClassName ||
206 | desktopFileInfo.completeBaseName() == xWindowWMClassName)
207 | founded = true;
208 |
209 | // StartupWMClass=STRING
210 | // If true, it is KNOWN that the application will map at least one
211 | // window with the given string as its WM class or WM name hint.
212 | // ref: https://specifications.freedesktop.org/startup-notification-spec/startup-notification-0.1.txt
213 | if (item->startupWMClass.startsWith(appId, Qt::CaseInsensitive) ||
214 | item->startupWMClass.startsWith(xWindowWMClassName, Qt::CaseInsensitive))
215 | founded = true;
216 |
217 | if (!founded && item->iconName.startsWith(xWindowWMClassName, Qt::CaseInsensitive))
218 | founded = true;
219 |
220 | // Try matching mapped name against 'Name'.
221 | if (!founded && item->name.startsWith(xWindowWMClassName, Qt::CaseInsensitive))
222 | founded = true;
223 |
224 | // exec
225 | if (!founded && item->exec.startsWith(xWindowWMClassName, Qt::CaseInsensitive))
226 | founded = true;
227 |
228 | if (!founded && desktopFileInfo.baseName().startsWith(xWindowWMClassName, Qt::CaseInsensitive))
229 | founded = true;
230 |
231 | // Match cmdlind
232 | if (!founded) {
233 | QString cmd = cmdFromPid(pid);
234 | if (!cmd.isEmpty()) {
235 | if (item->exec.startsWith(cmdFromPid(pid), Qt::CaseInsensitive) ||
236 | item->exec.endsWith(cmdFromPid(pid), Qt::CaseInsensitive)) {
237 | founded = true;
238 | }
239 | }
240 | }
241 |
242 | if (founded) {
243 | result = item->path;
244 | break;
245 | }
246 | }
247 | }
248 |
249 | return result;
250 | }
251 |
252 | QMap Utils::readInfoFromDesktop(const QString &desktopFile)
253 | {
254 | QMap info;
255 | for (SystemAppItem *item : m_sysAppMonitor->applications()) {
256 | if (item->path == desktopFile) {
257 | info.insert("Icon", item->iconName);
258 | info.insert("Name", item->name);
259 | info.insert("Exec", item->exec);
260 | }
261 | }
262 |
263 | return info;
264 | }
265 |
--------------------------------------------------------------------------------
/src/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef UTILS_H
2 | #define UTILS_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | class SystemAppMonitor;
9 | class Utils : public QObject
10 | {
11 | Q_OBJECT
12 |
13 | public:
14 | struct AppData
15 | {
16 | QString id; // Application id (*.desktop sans extension).
17 | QString name; // Application name.
18 | QString genericName; // Generic application name.
19 | QIcon icon;
20 | QUrl url;
21 | bool skipTaskbar = false;
22 | };
23 |
24 | enum UrlComparisonMode {
25 | Strict = 0,
26 | IgnoreQueryItems
27 | };
28 |
29 | static Utils *instance();
30 |
31 | explicit Utils(QObject *parent = nullptr);
32 |
33 | QString cmdFromPid(quint32 pid);
34 | QString desktopPathFromMetadata(const QString &appId, quint32 pid = 0,
35 | const QString &xWindowWMClassName = QString());
36 | QMap readInfoFromDesktop(const QString &desktopFile);
37 | QMap readInfoFromPid(quint32 pid);
38 |
39 | private:
40 | SystemAppMonitor *m_sysAppMonitor;
41 | QMap examinePotentialBundlePath(QString path);
42 | };
43 |
44 | #endif // UTILS_H
45 |
--------------------------------------------------------------------------------
/src/waylandinterface.cpp:
--------------------------------------------------------------------------------
1 | #include "waylandinterface.h"
2 |
3 | // Qt
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | // X11
15 | #include
16 |
17 | WaylandInterface::WaylandInterface(QObject *parent)
18 | : QObject(parent)
19 | {
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/waylandinterface.h:
--------------------------------------------------------------------------------
1 | #ifndef WAYLANDINTERFACE_H
2 | #define WAYLANDINTERFACE_H
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | class WaylandInterface : public QObject
15 | {
16 | Q_OBJECT
17 |
18 | public:
19 | explicit WaylandInterface(QObject *parent = nullptr);
20 |
21 | signals:
22 |
23 | };
24 |
25 | #endif // WAYLANDINTERFACE_H
26 |
--------------------------------------------------------------------------------
/src/xwindowinterface.cpp:
--------------------------------------------------------------------------------
1 | #include "xwindowinterface.h"
2 | #include "utils.h"
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | // X11
15 | #include
16 | #include
17 | #include
18 |
19 | static XWindowInterface *INSTANCE = nullptr;
20 |
21 | XWindowInterface *XWindowInterface::instance()
22 | {
23 | if (!INSTANCE)
24 | INSTANCE = new XWindowInterface;
25 |
26 | return INSTANCE;
27 | }
28 |
29 | XWindowInterface::XWindowInterface(QObject *parent)
30 | : QObject(parent)
31 | {
32 | connect(KWindowSystem::self(), &KWindowSystem::windowAdded, this, &XWindowInterface::onWindowadded);
33 | connect(KWindowSystem::self(), &KWindowSystem::windowRemoved, this, &XWindowInterface::windowRemoved);
34 | connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &XWindowInterface::activeChanged);
35 | }
36 |
37 | void XWindowInterface::enableBlurBehind(QWindow *view, bool enable, const QRegion ®ion)
38 | {
39 | KWindowEffects::enableBlurBehind(view->winId(), enable, region);
40 | }
41 |
42 | WId XWindowInterface::activeWindow()
43 | {
44 | return KWindowSystem::activeWindow();
45 | }
46 |
47 | void XWindowInterface::minimizeWindow(WId win)
48 | {
49 | KWindowSystem::minimizeWindow(win);
50 | }
51 |
52 | void XWindowInterface::closeWindow(WId id)
53 | {
54 | // FIXME: Why there is no such thing in KWindowSystem??
55 | NETRootInfo(QX11Info::connection(), NET::CloseWindow).closeWindowRequest(id);
56 | }
57 |
58 | void XWindowInterface::forceActiveWindow(WId win)
59 | {
60 | KWindowSystem::forceActiveWindow(win);
61 | }
62 |
63 | QMap XWindowInterface::requestInfo(quint64 wid)
64 | {
65 | const KWindowInfo winfo { wid, NET::WMFrameExtents
66 | | NET::WMWindowType
67 | | NET::WMGeometry
68 | | NET::WMDesktop
69 | | NET::WMState
70 | | NET::WMName
71 | | NET::WMVisibleName,
72 | NET::WM2WindowClass
73 | | NET::WM2Activities
74 | | NET::WM2AllowedActions
75 | | NET::WM2TransientFor };
76 | QMap result;
77 | const QString winClass = QString(winfo.windowClassClass());
78 |
79 | result.insert("iconName", winClass.toLower());
80 | result.insert("active", wid == KWindowSystem::activeWindow());
81 | result.insert("visibleName", winfo.visibleName());
82 | result.insert("id", winClass);
83 |
84 | return result;
85 | }
86 |
87 | QString XWindowInterface::requestWindowClass(quint64 wid)
88 | {
89 | return KWindowInfo(wid, NET::Supported, NET::WM2WindowClass).windowClassClass();
90 | }
91 |
92 | bool XWindowInterface::isAcceptableWindow(quint64 wid)
93 | {
94 | QFlags ignoreList;
95 | ignoreList |= NET::DesktopMask;
96 | ignoreList |= NET::DockMask;
97 | ignoreList |= NET::SplashMask;
98 | ignoreList |= NET::ToolbarMask;
99 | ignoreList |= NET::MenuMask;
100 | ignoreList |= NET::PopupMenuMask;
101 | ignoreList |= NET::NotificationMask;
102 |
103 | KWindowInfo info(wid, NET::WMWindowType | NET::WMState, NET::WM2TransientFor | NET::WM2WindowClass);
104 |
105 | if (!info.valid())
106 | return false;
107 |
108 | if (NET::typeMatchesMask(info.windowType(NET::AllTypesMask), ignoreList))
109 | return false;
110 |
111 | if (info.hasState(NET::SkipTaskbar) || info.hasState(NET::SkipPager))
112 | return false;
113 |
114 | // WM_TRANSIENT_FOR hint not set - normal window
115 | WId transFor = info.transientFor();
116 | if (transFor == 0 || transFor == wid || transFor == (WId) QX11Info::appRootWindow())
117 | return true;
118 |
119 | info = KWindowInfo(transFor, NET::WMWindowType);
120 |
121 | QFlags normalFlag;
122 | normalFlag |= NET::NormalMask;
123 | normalFlag |= NET::DialogMask;
124 | normalFlag |= NET::UtilityMask;
125 |
126 | return !NET::typeMatchesMask(info.windowType(NET::AllTypesMask), normalFlag);
127 | }
128 |
129 | void XWindowInterface::setViewStruts(QWindow *view, const QRect &rect)
130 | {
131 | NETExtendedStrut strut;
132 | int margin = 1; // probono: was 10
133 |
134 | const auto screen = view->screen();
135 |
136 | const QRect currentScreen {screen->geometry()};
137 | const QRect wholeScreen { {0, 0}, screen->virtualSize() };
138 |
139 | // bottom
140 | const int bottomOffset { wholeScreen.bottom() - currentScreen.bottom() };
141 | strut.bottom_width = rect.height() + bottomOffset + margin;
142 | strut.bottom_start = rect.x();
143 | strut.bottom_end = rect.x() + rect.width();
144 |
145 | KWindowSystem::setExtendedStrut(view->winId(),
146 | strut.left_width, strut.left_start, strut.left_end,
147 | strut.right_width, strut.right_start, strut.right_end,
148 | strut.top_width, strut.top_start, strut.top_end,
149 | strut.bottom_width, strut.bottom_start, strut.bottom_end
150 | );
151 | }
152 |
153 | void XWindowInterface::startInitWindows()
154 | {
155 | for (auto wid : KWindowSystem::self()->windows()) {
156 | onWindowadded(wid);
157 | }
158 | }
159 |
160 | QString XWindowInterface::desktopFilePath(quint64 wid)
161 | {
162 | const KWindowInfo info(wid, NET::Properties(), NET::WM2WindowClass | NET::WM2DesktopFileName);
163 | return Utils::instance()->desktopPathFromMetadata(info.windowClassClass(),
164 | NETWinInfo(QX11Info::connection(), wid,
165 | QX11Info::appRootWindow(),
166 | NET::WMPid,
167 | NET::Properties2()).pid(),
168 | info.windowClassName());
169 | }
170 |
171 | void XWindowInterface::setIconGeometry(quint64 wid, const QRect &rect)
172 | {
173 | NETWinInfo info(QX11Info::connection(),
174 | wid,
175 | (WId) QX11Info::appRootWindow(),
176 | NET::WMIconGeometry,
177 | QFlags(1));
178 | NETRect nrect;
179 | nrect.pos.x = rect.x();
180 | nrect.pos.y = rect.y();
181 | nrect.size.height = rect.height();
182 | nrect.size.width = rect.width();
183 | info.setIconGeometry(nrect);
184 | }
185 |
186 | void XWindowInterface::onWindowadded(quint64 wid)
187 | {
188 | if (isAcceptableWindow(wid)) {
189 | emit windowAdded(wid);
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/src/xwindowinterface.h:
--------------------------------------------------------------------------------
1 | #ifndef XWINDOWINTERFACE_H
2 | #define XWINDOWINTERFACE_H
3 |
4 | #include "applicationitem.h"
5 | #include
6 |
7 | // KLIB
8 | #include
9 | #include
10 |
11 | class XWindowInterface : public QObject
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | static XWindowInterface *instance();
17 | explicit XWindowInterface(QObject *parent = nullptr);
18 |
19 | void enableBlurBehind(QWindow *view, bool enable = true, const QRegion ®ion = QRegion());
20 |
21 | WId activeWindow();
22 | void minimizeWindow(WId win);
23 | void closeWindow(WId id);
24 | void forceActiveWindow(WId win);
25 |
26 | QMap requestInfo(quint64 wid);
27 | QString requestWindowClass(quint64 wid);
28 | bool isAcceptableWindow(quint64 wid);
29 |
30 | void setViewStruts(QWindow *view, const QRect &rect);
31 |
32 | void startInitWindows();
33 |
34 | QString desktopFilePath(quint64 wid);
35 |
36 | void setIconGeometry(quint64 wid, const QRect &rect);
37 |
38 | signals:
39 | void windowAdded(quint64 wid);
40 | void windowRemoved(quint64 wid);
41 | void activeChanged(quint64 wid);
42 |
43 | private:
44 | void onWindowadded(quint64 wid);
45 | };
46 |
47 | #endif // XWINDOWINTERFACE_H
48 |
--------------------------------------------------------------------------------
/svg/launcher.svg:
--------------------------------------------------------------------------------
1 |
2 |
276 |
--------------------------------------------------------------------------------