Merge lp:~lukas-kde/unity8/activateWindows into lp:unity8
- activateWindows
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~lukas-kde/unity8/activateWindows |
Merge into: | lp:unity8 |
Diff against target: |
2494 lines (+1893/-154) 33 files modified
CMakeLists.txt (+1/-1) debian/control (+6/-4) debian/copyright (+21/-0) debian/unity8-private.install (+1/-0) plugins/CMakeLists.txt (+1/-0) plugins/Cursor/3rd_party/CMakeLists.txt (+1/-0) plugins/Cursor/3rd_party/xcursor/CMakeLists.txt (+15/-0) plugins/Cursor/3rd_party/xcursor/xcursor.c (+968/-0) plugins/Cursor/3rd_party/xcursor/xcursor.h (+65/-0) plugins/Cursor/CMakeLists.txt (+28/-0) plugins/Cursor/Cursor.qml (+12/-0) plugins/Cursor/CursorImageProvider.cpp (+191/-0) plugins/Cursor/CursorImageProvider.h (+76/-0) plugins/Cursor/MousePointer.cpp (+125/-0) plugins/Cursor/MousePointer.h (+59/-0) plugins/Cursor/plugin.cpp (+39/-0) plugins/Cursor/plugin.h (+33/-0) plugins/Cursor/qmldir (+3/-0) qml/Greeter/Greeter.qml (+1/-1) qml/Launcher/Launcher.qml (+1/-0) qml/Panel/Panel.qml (+1/-0) qml/Shell.qml (+14/-7) qml/Stages/DecoratedWindow.qml (+6/-3) qml/Stages/DesktopStage.qml (+10/-10) qml/Stages/WindowDecoration.qml (+33/-4) qml/Stages/WindowResizeArea.qml (+135/-62) tests/mocks/CMakeLists.txt (+1/-0) tests/mocks/Cursor/CMakeLists.txt (+1/-0) tests/mocks/Cursor/Cursor.qml (+20/-0) tests/mocks/Cursor/qmldir (+2/-0) tests/qmltests/CMakeLists.txt (+1/-1) tests/qmltests/Stages/tst_WindowResizeArea.qml (+18/-61) tests/qmltests/tst_OrientedShell.qml (+4/-0) |
To merge this branch: | bzr merge lp:~lukas-kde/unity8/activateWindows |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Needs Fixing | |
Daniel d'Andrada (community) | Needs Fixing | ||
Review via email: mp+274878@code.launchpad.net |
This proposal has been superseded by a proposal from 2015-10-19.
Commit message
Correctly activate windows from spread and when clicking their decoration
Description of the change
Activate/focus windows when clicking on their decoration and raise/restore them
when activating from the spread.
* Are there any related MPs required for this MP to build/function as expected? Please list.
No
* Did you perform an exploratory manual test run of your code change and any related functionality?
Yes
* Did you make sure that your branch does not contain spurious tags?
Yes
* If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
Yes
* If you changed the UI, has there been a design review?
N/A
Daniel d'Andrada (dandrader) wrote : | # |
Lukáš Tinkl (lukas-kde) wrote : | # |
> Please follow the commit message format as explained here:
> https:/
Should be fine now
Daniel d'Andrada (dandrader) wrote : | # |
Could you please add qml tests to cover those use cases you mention (ie active focus when clicking on decoration and raise/restore when activation from spread)?
I believe we already have a test for the first one (focus when clicking decoration). We had similar problems in the past before. Should investigate why it passes now even though there's a bug there (maybe it tests only with touches and not with mouse clicks, don't know).
Daniel d'Andrada (dandrader) wrote : | # |
Oh, and it's worth making lp:~unity-team/unity8/mousePointer from silo 022 a prerequisite as it makes a lot of changes in this code.
Daniel d'Andrada (dandrader) wrote : | # |
> > Please follow the commit message format as explained here:
> > https:/
>
> Should be fine now
Yes, thanks!
- 2006. By Lukáš Tinkl
-
merge lp:~unity-team/unity8/mousePointer, fix conflicts, move the logic
- 2007. By Lukáš Tinkl
-
fix warning
- 2008. By Lukáš Tinkl
-
fix immediate grab cursor when just clicking
- 2009. By Lukáš Tinkl
- 2010. By Lukáš Tinkl
-
reaise the window on resize click too
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:2005
http://
Executed test runs:
UNSTABLE: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 2011. By Lukáš Tinkl
-
rename unminimize() to restore()
maintan the focus stack to switch between the apps when an app
is minimized or restored - 2012. By Lukáš Tinkl
-
update the focus stack when the focused app id changes
- 2013. By Lukáš Tinkl
-
add a test for clicking to get focus (instead of tap)
simplify the foreach loops
- 2014. By Lukáš Tinkl
-
provide shortcuts for common window operations
- 2015. By Lukáš Tinkl
-
don't special case for dash, clear and reset the focus stack when we minimizeAll()
- 2016. By Lukáš Tinkl
-
add tests for maximize and minimize an app
- 2017. By Lukáš Tinkl
-
always focus the first app in the stack, based on recency
- 2018. By Lukáš Tinkl
-
add tests for minimizeAll and close
- 2019. By Lukáš Tinkl
-
add tests for maximizeLeft/Right
- 2020. By Lukáš Tinkl
-
simplify code, minimize delta
- 2021. By Lukáš Tinkl
-
merge trunk
- 2022. By Lukáš Tinkl
- 2023. By Lukáš Tinkl
-
display the maximized window's title in the panel, next to the buttons
- 2024. By Lukáš Tinkl
-
merge prereq to fix failing tests
- 2025. By Lukáš Tinkl
-
elide the window title in the title bar
- 2026. By Lukáš Tinkl
-
silence warnings
- 2027. By Lukáš Tinkl
-
fix issues found by mzanetti
additionally properly restore windows from minimized state to the correct
previous state (maximized, maximizedLeft/Right) - 2028. By Lukáš Tinkl
-
fix restoring the apps from spread to the correct state and size
potential fix for the Alt+F4 shortcut problem
- 2029. By Lukáš Tinkl
-
fix click to focus
- 2030. By Lukáš Tinkl
-
take the panel height into account when semimaximizing windows
- 2031. By Lukáš Tinkl
-
add a test to prove smashing all the 4 cursor keys together does nothing :)
- 2032. By Lukáš Tinkl
-
make sure to play the minimized animation before switching focus to next
- 2033. By Lukáš Tinkl
-
merge trunk
- 2034. By Lukáš Tinkl
-
cleanup
- 2035. By Lukáš Tinkl
-
cleanup
Unmerged revisions
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2015-09-30 16:49:52 +0000 | |||
3 | +++ CMakeLists.txt 2015-10-19 14:53:23 +0000 | |||
4 | @@ -57,7 +57,7 @@ | |||
5 | 57 | find_package(Qt5Concurrent 5.2 REQUIRED) | 57 | find_package(Qt5Concurrent 5.2 REQUIRED) |
6 | 58 | find_package(Qt5Sql 5.2 REQUIRED) | 58 | find_package(Qt5Sql 5.2 REQUIRED) |
7 | 59 | 59 | ||
9 | 60 | pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application>=8) | 60 | pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=9) |
10 | 61 | 61 | ||
11 | 62 | # Standard install paths | 62 | # Standard install paths |
12 | 63 | include(GNUInstallDirs) | 63 | include(GNUInstallDirs) |
13 | 64 | 64 | ||
14 | === modified file 'debian/control' | |||
15 | --- debian/control 2015-09-23 18:15:40 +0000 | |||
16 | +++ debian/control 2015-10-19 14:53:23 +0000 | |||
17 | @@ -25,10 +25,11 @@ | |||
18 | 25 | libpay2-dev, | 25 | libpay2-dev, |
19 | 26 | libpulse-dev, | 26 | libpulse-dev, |
20 | 27 | libqmenumodel-dev (>= 0.2.9), | 27 | libqmenumodel-dev (>= 0.2.9), |
21 | 28 | libqt5svg5-dev, | ||
22 | 28 | libqt5xmlpatterns5-dev, | 29 | libqt5xmlpatterns5-dev, |
23 | 29 | libsystemsettings-dev, | 30 | libsystemsettings-dev, |
24 | 30 | libudev-dev, | 31 | libudev-dev, |
26 | 31 | libunity-api-dev (>= 7.100), | 32 | libunity-api-dev (>= 7.101), |
27 | 32 | libusermetricsoutput1-dev, | 33 | libusermetricsoutput1-dev, |
28 | 33 | libxcb1-dev, | 34 | libxcb1-dev, |
29 | 34 | pkg-config, | 35 | pkg-config, |
30 | @@ -87,7 +88,8 @@ | |||
31 | 87 | Package: unity8 | 88 | Package: unity8 |
32 | 88 | Architecture: any | 89 | Architecture: any |
33 | 89 | Provides: indicator-renderer, | 90 | Provides: indicator-renderer, |
35 | 90 | Depends: gsettings-desktop-schemas, | 91 | Depends: dmz-cursor-theme, |
36 | 92 | gsettings-desktop-schemas, | ||
37 | 91 | libcap2-bin, | 93 | libcap2-bin, |
38 | 92 | libglib2.0-bin, | 94 | libglib2.0-bin, |
39 | 93 | qmenumodel-qml (>= 0.2.9), | 95 | qmenumodel-qml (>= 0.2.9), |
40 | @@ -125,7 +127,7 @@ | |||
41 | 125 | qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 1.1.1239) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 1.1.1239), | 127 | qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 1.1.1239) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 1.1.1239), |
42 | 126 | qtdeclarative5-unity-notifications-plugin (>= 0.1.2) | unity-notifications-impl, | 128 | qtdeclarative5-unity-notifications-plugin (>= 0.1.2) | unity-notifications-impl, |
43 | 127 | ubuntu-thumbnailer-impl-0, | 129 | ubuntu-thumbnailer-impl-0, |
45 | 128 | unity-application-impl-8, | 130 | unity-application-impl-9, |
46 | 129 | unity-notifications-impl-3, | 131 | unity-notifications-impl-3, |
47 | 130 | unity-plugin-scopes | unity-scopes-impl, | 132 | unity-plugin-scopes | unity-scopes-impl, |
48 | 131 | unity-scopes-impl-7, | 133 | unity-scopes-impl-7, |
49 | @@ -171,7 +173,7 @@ | |||
50 | 171 | Depends: ${misc:Depends}, | 173 | Depends: ${misc:Depends}, |
51 | 172 | ${shlibs:Depends}, | 174 | ${shlibs:Depends}, |
52 | 173 | Provides: unity-application-impl, | 175 | Provides: unity-application-impl, |
54 | 174 | unity-application-impl-8, | 176 | unity-application-impl-9, |
55 | 175 | Replaces: unity8-autopilot (<< 8.02+15.04.20150422-0ubuntu1) | 177 | Replaces: unity8-autopilot (<< 8.02+15.04.20150422-0ubuntu1) |
56 | 176 | Description: Fake environment for running Unity 8 shell | 178 | Description: Fake environment for running Unity 8 shell |
57 | 177 | Provides fake implementations of some QML modules used by Unity 8 shell | 179 | Provides fake implementations of some QML modules used by Unity 8 shell |
58 | 178 | 180 | ||
59 | === modified file 'debian/copyright' | |||
60 | --- debian/copyright 2014-06-11 15:36:51 +0000 | |||
61 | +++ debian/copyright 2015-10-19 14:53:23 +0000 | |||
62 | @@ -60,3 +60,24 @@ | |||
63 | 60 | packaging of this file. Please review the following information to | 60 | packaging of this file. Please review the following information to |
64 | 61 | ensure the GNU General Public License version 3.0 requirements will be | 61 | ensure the GNU General Public License version 3.0 requirements will be |
65 | 62 | met: http://www.gnu.org/copyleft/gpl.html. | 62 | met: http://www.gnu.org/copyleft/gpl.html. |
66 | 63 | |||
67 | 64 | Files: plugins/Cursor/3rd_party/xcursor/xcursor.* | ||
68 | 65 | Copyright: 2002 Keith Packard | ||
69 | 66 | License: Keith Packard | ||
70 | 67 | Permission to use, copy, modify, distribute, and sell this software and its | ||
71 | 68 | documentation for any purpose is hereby granted without fee, provided that | ||
72 | 69 | the above copyright notice appear in all copies and that both that | ||
73 | 70 | copyright notice and this permission notice appear in supporting | ||
74 | 71 | documentation, and that the name of Keith Packard not be used in | ||
75 | 72 | advertising or publicity pertaining to distribution of the software without | ||
76 | 73 | specific, written prior permission. Keith Packard makes no | ||
77 | 74 | representations about the suitability of this software for any purpose. It | ||
78 | 75 | is provided "as is" without express or implied warranty. | ||
79 | 76 | . | ||
80 | 77 | KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
81 | 78 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | ||
82 | 79 | EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
83 | 80 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | ||
84 | 81 | DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
85 | 82 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
86 | 83 | PERFORMANCE OF THIS SOFTWARE. | ||
87 | 63 | 84 | ||
88 | === modified file 'debian/unity8-private.install' | |||
89 | --- debian/unity8-private.install 2015-09-02 09:30:32 +0000 | |||
90 | +++ debian/unity8-private.install 2015-10-19 14:53:23 +0000 | |||
91 | @@ -1,6 +1,7 @@ | |||
92 | 1 | usr/lib/*/libunity8-private.* | 1 | usr/lib/*/libunity8-private.* |
93 | 2 | usr/lib/*/unity8/libUbuntuGestures* | 2 | usr/lib/*/unity8/libUbuntuGestures* |
94 | 3 | usr/lib/*/unity8/qml/AccountsService | 3 | usr/lib/*/unity8/qml/AccountsService |
95 | 4 | usr/lib/*/unity8/qml/Cursor | ||
96 | 4 | usr/lib/*/unity8/qml/Dash | 5 | usr/lib/*/unity8/qml/Dash |
97 | 5 | usr/lib/*/unity8/qml/GlobalShortcut | 6 | usr/lib/*/unity8/qml/GlobalShortcut |
98 | 6 | usr/lib/*/unity8/qml/Greeter | 7 | usr/lib/*/unity8/qml/Greeter |
99 | 7 | 8 | ||
100 | === modified file 'plugins/CMakeLists.txt' | |||
101 | --- plugins/CMakeLists.txt 2015-09-02 09:30:32 +0000 | |||
102 | +++ plugins/CMakeLists.txt 2015-10-19 14:53:23 +0000 | |||
103 | @@ -12,6 +12,7 @@ | |||
104 | 12 | endmacro() | 12 | endmacro() |
105 | 13 | 13 | ||
106 | 14 | add_subdirectory(AccountsService) | 14 | add_subdirectory(AccountsService) |
107 | 15 | add_subdirectory(Cursor) | ||
108 | 15 | add_subdirectory(GlobalShortcut) | 16 | add_subdirectory(GlobalShortcut) |
109 | 16 | add_subdirectory(Greeter) | 17 | add_subdirectory(Greeter) |
110 | 17 | add_subdirectory(IntegratedLightDM) | 18 | add_subdirectory(IntegratedLightDM) |
111 | 18 | 19 | ||
112 | === added directory 'plugins/Cursor' | |||
113 | === added directory 'plugins/Cursor/3rd_party' | |||
114 | === added file 'plugins/Cursor/3rd_party/CMakeLists.txt' | |||
115 | --- plugins/Cursor/3rd_party/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
116 | +++ plugins/Cursor/3rd_party/CMakeLists.txt 2015-10-19 14:53:23 +0000 | |||
117 | @@ -0,0 +1,1 @@ | |||
118 | 1 | add_subdirectory(xcursor) | ||
119 | 0 | 2 | ||
120 | === added directory 'plugins/Cursor/3rd_party/xcursor' | |||
121 | === added file 'plugins/Cursor/3rd_party/xcursor/CMakeLists.txt' | |||
122 | --- plugins/Cursor/3rd_party/xcursor/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
123 | +++ plugins/Cursor/3rd_party/xcursor/CMakeLists.txt 2015-10-19 14:53:23 +0000 | |||
124 | @@ -0,0 +1,15 @@ | |||
125 | 1 | add_definitions(-D_DEFAULT_SOURCE=1) | ||
126 | 2 | |||
127 | 3 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") | ||
128 | 4 | |||
129 | 5 | set( | ||
130 | 6 | XCURSOR_SOURCES | ||
131 | 7 | |||
132 | 8 | xcursor.c | ||
133 | 9 | ) | ||
134 | 10 | |||
135 | 11 | add_library( | ||
136 | 12 | xcursorloader-static STATIC | ||
137 | 13 | |||
138 | 14 | ${XCURSOR_SOURCES} | ||
139 | 15 | ) | ||
140 | 0 | 16 | ||
141 | === added file 'plugins/Cursor/3rd_party/xcursor/xcursor.c' | |||
142 | --- plugins/Cursor/3rd_party/xcursor/xcursor.c 1970-01-01 00:00:00 +0000 | |||
143 | +++ plugins/Cursor/3rd_party/xcursor/xcursor.c 2015-10-19 14:53:23 +0000 | |||
144 | @@ -0,0 +1,968 @@ | |||
145 | 1 | /* | ||
146 | 2 | * Copyright © 2002 Keith Packard | ||
147 | 3 | * | ||
148 | 4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
149 | 5 | * documentation for any purpose is hereby granted without fee, provided that | ||
150 | 6 | * the above copyright notice appear in all copies and that both that | ||
151 | 7 | * copyright notice and this permission notice appear in supporting | ||
152 | 8 | * documentation, and that the name of Keith Packard not be used in | ||
153 | 9 | * advertising or publicity pertaining to distribution of the software without | ||
154 | 10 | * specific, written prior permission. Keith Packard makes no | ||
155 | 11 | * representations about the suitability of this software for any purpose. It | ||
156 | 12 | * is provided "as is" without express or implied warranty. | ||
157 | 13 | * | ||
158 | 14 | * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
159 | 15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | ||
160 | 16 | * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
161 | 17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | ||
162 | 18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
163 | 19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
164 | 20 | * PERFORMANCE OF THIS SOFTWARE. | ||
165 | 21 | */ | ||
166 | 22 | |||
167 | 23 | #include "xcursor.h" | ||
168 | 24 | #include <stdio.h> | ||
169 | 25 | #include <stdlib.h> | ||
170 | 26 | #include <string.h> | ||
171 | 27 | #include <dirent.h> | ||
172 | 28 | |||
173 | 29 | /* | ||
174 | 30 | * From libXcursor/include/X11/extensions/Xcursor.h | ||
175 | 31 | */ | ||
176 | 32 | |||
177 | 33 | #define XcursorTrue 1 | ||
178 | 34 | #define XcursorFalse 0 | ||
179 | 35 | |||
180 | 36 | /* | ||
181 | 37 | * Cursor files start with a header. The header | ||
182 | 38 | * contains a magic number, a version number and a | ||
183 | 39 | * table of contents which has type and offset information | ||
184 | 40 | * for the remaining tables in the file. | ||
185 | 41 | * | ||
186 | 42 | * File minor versions increment for compatible changes | ||
187 | 43 | * File major versions increment for incompatible changes (never, we hope) | ||
188 | 44 | * | ||
189 | 45 | * Chunks of the same type are always upward compatible. Incompatible | ||
190 | 46 | * changes are made with new chunk types; the old data can remain under | ||
191 | 47 | * the old type. Upward compatible changes can add header data as the | ||
192 | 48 | * header lengths are specified in the file. | ||
193 | 49 | * | ||
194 | 50 | * File: | ||
195 | 51 | * FileHeader | ||
196 | 52 | * LISTofChunk | ||
197 | 53 | * | ||
198 | 54 | * FileHeader: | ||
199 | 55 | * CARD32 magic magic number | ||
200 | 56 | * CARD32 header bytes in file header | ||
201 | 57 | * CARD32 version file version | ||
202 | 58 | * CARD32 ntoc number of toc entries | ||
203 | 59 | * LISTofFileToc toc table of contents | ||
204 | 60 | * | ||
205 | 61 | * FileToc: | ||
206 | 62 | * CARD32 type entry type | ||
207 | 63 | * CARD32 subtype entry subtype (size for images) | ||
208 | 64 | * CARD32 position absolute file position | ||
209 | 65 | */ | ||
210 | 66 | |||
211 | 67 | #define XCURSOR_MAGIC 0x72756358 /* "Xcur" LSBFirst */ | ||
212 | 68 | |||
213 | 69 | /* | ||
214 | 70 | * Current Xcursor version number. Will be substituted by configure | ||
215 | 71 | * from the version in the libXcursor configure.ac file. | ||
216 | 72 | */ | ||
217 | 73 | |||
218 | 74 | #define XCURSOR_LIB_MAJOR 1 | ||
219 | 75 | #define XCURSOR_LIB_MINOR 1 | ||
220 | 76 | #define XCURSOR_LIB_REVISION 13 | ||
221 | 77 | #define XCURSOR_LIB_VERSION ((XCURSOR_LIB_MAJOR * 10000) + \ | ||
222 | 78 | (XCURSOR_LIB_MINOR * 100) + \ | ||
223 | 79 | (XCURSOR_LIB_REVISION)) | ||
224 | 80 | |||
225 | 81 | /* | ||
226 | 82 | * This version number is stored in cursor files; changes to the | ||
227 | 83 | * file format require updating this version number | ||
228 | 84 | */ | ||
229 | 85 | #define XCURSOR_FILE_MAJOR 1 | ||
230 | 86 | #define XCURSOR_FILE_MINOR 0 | ||
231 | 87 | #define XCURSOR_FILE_VERSION ((XCURSOR_FILE_MAJOR << 16) | (XCURSOR_FILE_MINOR)) | ||
232 | 88 | #define XCURSOR_FILE_HEADER_LEN (4 * 4) | ||
233 | 89 | #define XCURSOR_FILE_TOC_LEN (3 * 4) | ||
234 | 90 | |||
235 | 91 | typedef struct _XcursorFileToc { | ||
236 | 92 | XcursorUInt type; /* chunk type */ | ||
237 | 93 | XcursorUInt subtype; /* subtype (size for images) */ | ||
238 | 94 | XcursorUInt position; /* absolute position in file */ | ||
239 | 95 | } XcursorFileToc; | ||
240 | 96 | |||
241 | 97 | typedef struct _XcursorFileHeader { | ||
242 | 98 | XcursorUInt magic; /* magic number */ | ||
243 | 99 | XcursorUInt header; /* byte length of header */ | ||
244 | 100 | XcursorUInt version; /* file version number */ | ||
245 | 101 | XcursorUInt ntoc; /* number of toc entries */ | ||
246 | 102 | XcursorFileToc *tocs; /* table of contents */ | ||
247 | 103 | } XcursorFileHeader; | ||
248 | 104 | |||
249 | 105 | /* | ||
250 | 106 | * The rest of the file is a list of chunks, each tagged by type | ||
251 | 107 | * and version. | ||
252 | 108 | * | ||
253 | 109 | * Chunk: | ||
254 | 110 | * ChunkHeader | ||
255 | 111 | * <extra type-specific header fields> | ||
256 | 112 | * <type-specific data> | ||
257 | 113 | * | ||
258 | 114 | * ChunkHeader: | ||
259 | 115 | * CARD32 header bytes in chunk header + type header | ||
260 | 116 | * CARD32 type chunk type | ||
261 | 117 | * CARD32 subtype chunk subtype | ||
262 | 118 | * CARD32 version chunk type version | ||
263 | 119 | */ | ||
264 | 120 | |||
265 | 121 | #define XCURSOR_CHUNK_HEADER_LEN (4 * 4) | ||
266 | 122 | |||
267 | 123 | typedef struct _XcursorChunkHeader { | ||
268 | 124 | XcursorUInt header; /* bytes in chunk header */ | ||
269 | 125 | XcursorUInt type; /* chunk type */ | ||
270 | 126 | XcursorUInt subtype; /* chunk subtype (size for images) */ | ||
271 | 127 | XcursorUInt version; /* version of this type */ | ||
272 | 128 | } XcursorChunkHeader; | ||
273 | 129 | |||
274 | 130 | /* | ||
275 | 131 | * Here's a list of the known chunk types | ||
276 | 132 | */ | ||
277 | 133 | |||
278 | 134 | /* | ||
279 | 135 | * Comments consist of a 4-byte length field followed by | ||
280 | 136 | * UTF-8 encoded text | ||
281 | 137 | * | ||
282 | 138 | * Comment: | ||
283 | 139 | * ChunkHeader header chunk header | ||
284 | 140 | * CARD32 length bytes in text | ||
285 | 141 | * LISTofCARD8 text UTF-8 encoded text | ||
286 | 142 | */ | ||
287 | 143 | |||
288 | 144 | #define XCURSOR_COMMENT_TYPE 0xfffe0001 | ||
289 | 145 | #define XCURSOR_COMMENT_VERSION 1 | ||
290 | 146 | #define XCURSOR_COMMENT_HEADER_LEN (XCURSOR_CHUNK_HEADER_LEN + (1 *4)) | ||
291 | 147 | #define XCURSOR_COMMENT_COPYRIGHT 1 | ||
292 | 148 | #define XCURSOR_COMMENT_LICENSE 2 | ||
293 | 149 | #define XCURSOR_COMMENT_OTHER 3 | ||
294 | 150 | #define XCURSOR_COMMENT_MAX_LEN 0x100000 | ||
295 | 151 | |||
296 | 152 | typedef struct _XcursorComment { | ||
297 | 153 | XcursorUInt version; | ||
298 | 154 | XcursorUInt comment_type; | ||
299 | 155 | char *comment; | ||
300 | 156 | } XcursorComment; | ||
301 | 157 | |||
302 | 158 | /* | ||
303 | 159 | * Each cursor image occupies a separate image chunk. | ||
304 | 160 | * The length of the image header follows the chunk header | ||
305 | 161 | * so that future versions can extend the header without | ||
306 | 162 | * breaking older applications | ||
307 | 163 | * | ||
308 | 164 | * Image: | ||
309 | 165 | * ChunkHeader header chunk header | ||
310 | 166 | * CARD32 width actual width | ||
311 | 167 | * CARD32 height actual height | ||
312 | 168 | * CARD32 xhot hot spot x | ||
313 | 169 | * CARD32 yhot hot spot y | ||
314 | 170 | * CARD32 delay animation delay | ||
315 | 171 | * LISTofCARD32 pixels ARGB pixels | ||
316 | 172 | */ | ||
317 | 173 | |||
318 | 174 | #define XCURSOR_IMAGE_TYPE 0xfffd0002 | ||
319 | 175 | #define XCURSOR_IMAGE_VERSION 1 | ||
320 | 176 | #define XCURSOR_IMAGE_HEADER_LEN (XCURSOR_CHUNK_HEADER_LEN + (5*4)) | ||
321 | 177 | #define XCURSOR_IMAGE_MAX_SIZE 0x7fff /* 32767x32767 max cursor size */ | ||
322 | 178 | |||
323 | 179 | typedef struct _XcursorFile XcursorFile; | ||
324 | 180 | |||
325 | 181 | struct _XcursorFile { | ||
326 | 182 | void *closure; | ||
327 | 183 | int (*read) (XcursorFile *file, unsigned char *buf, int len); | ||
328 | 184 | int (*write) (XcursorFile *file, unsigned char *buf, int len); | ||
329 | 185 | int (*seek) (XcursorFile *file, long offset, int whence); | ||
330 | 186 | }; | ||
331 | 187 | |||
332 | 188 | typedef struct _XcursorComments { | ||
333 | 189 | int ncomment; /* number of comments */ | ||
334 | 190 | XcursorComment **comments; /* array of XcursorComment pointers */ | ||
335 | 191 | } XcursorComments; | ||
336 | 192 | |||
337 | 193 | /* | ||
338 | 194 | * From libXcursor/src/file.c | ||
339 | 195 | */ | ||
340 | 196 | |||
341 | 197 | static XcursorImage * | ||
342 | 198 | XcursorImageCreate (int width, int height) | ||
343 | 199 | { | ||
344 | 200 | XcursorImage *image; | ||
345 | 201 | |||
346 | 202 | image = malloc (sizeof (XcursorImage) + | ||
347 | 203 | width * height * sizeof (XcursorPixel)); | ||
348 | 204 | if (!image) | ||
349 | 205 | return NULL; | ||
350 | 206 | image->version = XCURSOR_IMAGE_VERSION; | ||
351 | 207 | image->pixels = (XcursorPixel *) (image + 1); | ||
352 | 208 | image->size = width > height ? width : height; | ||
353 | 209 | image->width = width; | ||
354 | 210 | image->height = height; | ||
355 | 211 | image->delay = 0; | ||
356 | 212 | return image; | ||
357 | 213 | } | ||
358 | 214 | |||
359 | 215 | static void | ||
360 | 216 | XcursorImageDestroy (XcursorImage *image) | ||
361 | 217 | { | ||
362 | 218 | free (image); | ||
363 | 219 | } | ||
364 | 220 | |||
365 | 221 | static XcursorImages * | ||
366 | 222 | XcursorImagesCreate (int size) | ||
367 | 223 | { | ||
368 | 224 | XcursorImages *images; | ||
369 | 225 | |||
370 | 226 | images = malloc (sizeof (XcursorImages) + | ||
371 | 227 | size * sizeof (XcursorImage *)); | ||
372 | 228 | if (!images) | ||
373 | 229 | return NULL; | ||
374 | 230 | images->nimage = 0; | ||
375 | 231 | images->images = (XcursorImage **) (images + 1); | ||
376 | 232 | images->name = NULL; | ||
377 | 233 | return images; | ||
378 | 234 | } | ||
379 | 235 | |||
380 | 236 | void | ||
381 | 237 | XcursorImagesDestroy (XcursorImages *images) | ||
382 | 238 | { | ||
383 | 239 | int n; | ||
384 | 240 | |||
385 | 241 | if (!images) | ||
386 | 242 | return; | ||
387 | 243 | |||
388 | 244 | for (n = 0; n < images->nimage; n++) | ||
389 | 245 | XcursorImageDestroy (images->images[n]); | ||
390 | 246 | if (images->name) | ||
391 | 247 | free (images->name); | ||
392 | 248 | free (images); | ||
393 | 249 | } | ||
394 | 250 | |||
395 | 251 | static void | ||
396 | 252 | XcursorImagesSetName (XcursorImages *images, const char *name) | ||
397 | 253 | { | ||
398 | 254 | char *new; | ||
399 | 255 | |||
400 | 256 | if (!images || !name) | ||
401 | 257 | return; | ||
402 | 258 | |||
403 | 259 | new = malloc (strlen (name) + 1); | ||
404 | 260 | |||
405 | 261 | if (!new) | ||
406 | 262 | return; | ||
407 | 263 | |||
408 | 264 | strcpy (new, name); | ||
409 | 265 | if (images->name) | ||
410 | 266 | free (images->name); | ||
411 | 267 | images->name = new; | ||
412 | 268 | } | ||
413 | 269 | |||
414 | 270 | static XcursorBool | ||
415 | 271 | _XcursorReadUInt (XcursorFile *file, XcursorUInt *u) | ||
416 | 272 | { | ||
417 | 273 | unsigned char bytes[4]; | ||
418 | 274 | |||
419 | 275 | if (!file || !u) | ||
420 | 276 | return XcursorFalse; | ||
421 | 277 | |||
422 | 278 | if ((*file->read) (file, bytes, 4) != 4) | ||
423 | 279 | return XcursorFalse; | ||
424 | 280 | *u = ((bytes[0] << 0) | | ||
425 | 281 | (bytes[1] << 8) | | ||
426 | 282 | (bytes[2] << 16) | | ||
427 | 283 | (bytes[3] << 24)); | ||
428 | 284 | return XcursorTrue; | ||
429 | 285 | } | ||
430 | 286 | |||
431 | 287 | static void | ||
432 | 288 | _XcursorFileHeaderDestroy (XcursorFileHeader *fileHeader) | ||
433 | 289 | { | ||
434 | 290 | free (fileHeader); | ||
435 | 291 | } | ||
436 | 292 | |||
437 | 293 | static XcursorFileHeader * | ||
438 | 294 | _XcursorFileHeaderCreate (int ntoc) | ||
439 | 295 | { | ||
440 | 296 | XcursorFileHeader *fileHeader; | ||
441 | 297 | |||
442 | 298 | if (ntoc > 0x10000) | ||
443 | 299 | return NULL; | ||
444 | 300 | fileHeader = malloc (sizeof (XcursorFileHeader) + | ||
445 | 301 | ntoc * sizeof (XcursorFileToc)); | ||
446 | 302 | if (!fileHeader) | ||
447 | 303 | return NULL; | ||
448 | 304 | fileHeader->magic = XCURSOR_MAGIC; | ||
449 | 305 | fileHeader->header = XCURSOR_FILE_HEADER_LEN; | ||
450 | 306 | fileHeader->version = XCURSOR_FILE_VERSION; | ||
451 | 307 | fileHeader->ntoc = ntoc; | ||
452 | 308 | fileHeader->tocs = (XcursorFileToc *) (fileHeader + 1); | ||
453 | 309 | return fileHeader; | ||
454 | 310 | } | ||
455 | 311 | |||
456 | 312 | static XcursorFileHeader * | ||
457 | 313 | _XcursorReadFileHeader (XcursorFile *file) | ||
458 | 314 | { | ||
459 | 315 | XcursorFileHeader head, *fileHeader; | ||
460 | 316 | XcursorUInt skip; | ||
461 | 317 | unsigned int n; | ||
462 | 318 | |||
463 | 319 | if (!file) | ||
464 | 320 | return NULL; | ||
465 | 321 | |||
466 | 322 | if (!_XcursorReadUInt (file, &head.magic)) | ||
467 | 323 | return NULL; | ||
468 | 324 | if (head.magic != XCURSOR_MAGIC) | ||
469 | 325 | return NULL; | ||
470 | 326 | if (!_XcursorReadUInt (file, &head.header)) | ||
471 | 327 | return NULL; | ||
472 | 328 | if (!_XcursorReadUInt (file, &head.version)) | ||
473 | 329 | return NULL; | ||
474 | 330 | if (!_XcursorReadUInt (file, &head.ntoc)) | ||
475 | 331 | return NULL; | ||
476 | 332 | skip = head.header - XCURSOR_FILE_HEADER_LEN; | ||
477 | 333 | if (skip) | ||
478 | 334 | if ((*file->seek) (file, skip, SEEK_CUR) == EOF) | ||
479 | 335 | return NULL; | ||
480 | 336 | fileHeader = _XcursorFileHeaderCreate (head.ntoc); | ||
481 | 337 | if (!fileHeader) | ||
482 | 338 | return NULL; | ||
483 | 339 | fileHeader->magic = head.magic; | ||
484 | 340 | fileHeader->header = head.header; | ||
485 | 341 | fileHeader->version = head.version; | ||
486 | 342 | fileHeader->ntoc = head.ntoc; | ||
487 | 343 | for (n = 0; n < fileHeader->ntoc; n++) | ||
488 | 344 | { | ||
489 | 345 | if (!_XcursorReadUInt (file, &fileHeader->tocs[n].type)) | ||
490 | 346 | break; | ||
491 | 347 | if (!_XcursorReadUInt (file, &fileHeader->tocs[n].subtype)) | ||
492 | 348 | break; | ||
493 | 349 | if (!_XcursorReadUInt (file, &fileHeader->tocs[n].position)) | ||
494 | 350 | break; | ||
495 | 351 | } | ||
496 | 352 | if (n != fileHeader->ntoc) | ||
497 | 353 | { | ||
498 | 354 | _XcursorFileHeaderDestroy (fileHeader); | ||
499 | 355 | return NULL; | ||
500 | 356 | } | ||
501 | 357 | return fileHeader; | ||
502 | 358 | } | ||
503 | 359 | |||
504 | 360 | static XcursorBool | ||
505 | 361 | _XcursorSeekToToc (XcursorFile *file, | ||
506 | 362 | XcursorFileHeader *fileHeader, | ||
507 | 363 | int toc) | ||
508 | 364 | { | ||
509 | 365 | if (!file || !fileHeader || \ | ||
510 | 366 | (*file->seek) (file, fileHeader->tocs[toc].position, SEEK_SET) == EOF) | ||
511 | 367 | return XcursorFalse; | ||
512 | 368 | return XcursorTrue; | ||
513 | 369 | } | ||
514 | 370 | |||
515 | 371 | static XcursorBool | ||
516 | 372 | _XcursorFileReadChunkHeader (XcursorFile *file, | ||
517 | 373 | XcursorFileHeader *fileHeader, | ||
518 | 374 | int toc, | ||
519 | 375 | XcursorChunkHeader *chunkHeader) | ||
520 | 376 | { | ||
521 | 377 | if (!file || !fileHeader || !chunkHeader) | ||
522 | 378 | return XcursorFalse; | ||
523 | 379 | if (!_XcursorSeekToToc (file, fileHeader, toc)) | ||
524 | 380 | return XcursorFalse; | ||
525 | 381 | if (!_XcursorReadUInt (file, &chunkHeader->header)) | ||
526 | 382 | return XcursorFalse; | ||
527 | 383 | if (!_XcursorReadUInt (file, &chunkHeader->type)) | ||
528 | 384 | return XcursorFalse; | ||
529 | 385 | if (!_XcursorReadUInt (file, &chunkHeader->subtype)) | ||
530 | 386 | return XcursorFalse; | ||
531 | 387 | if (!_XcursorReadUInt (file, &chunkHeader->version)) | ||
532 | 388 | return XcursorFalse; | ||
533 | 389 | /* sanity check */ | ||
534 | 390 | if (chunkHeader->type != fileHeader->tocs[toc].type || | ||
535 | 391 | chunkHeader->subtype != fileHeader->tocs[toc].subtype) | ||
536 | 392 | return XcursorFalse; | ||
537 | 393 | return XcursorTrue; | ||
538 | 394 | } | ||
539 | 395 | |||
540 | 396 | #define dist(a,b) ((a) > (b) ? (a) - (b) : (b) - (a)) | ||
541 | 397 | |||
542 | 398 | static XcursorDim | ||
543 | 399 | _XcursorFindBestSize (XcursorFileHeader *fileHeader, | ||
544 | 400 | XcursorDim size, | ||
545 | 401 | int *nsizesp) | ||
546 | 402 | { | ||
547 | 403 | unsigned int n; | ||
548 | 404 | int nsizes = 0; | ||
549 | 405 | XcursorDim bestSize = 0; | ||
550 | 406 | XcursorDim thisSize; | ||
551 | 407 | |||
552 | 408 | if (!fileHeader || !nsizesp) | ||
553 | 409 | return 0; | ||
554 | 410 | |||
555 | 411 | for (n = 0; n < fileHeader->ntoc; n++) | ||
556 | 412 | { | ||
557 | 413 | if (fileHeader->tocs[n].type != XCURSOR_IMAGE_TYPE) | ||
558 | 414 | continue; | ||
559 | 415 | thisSize = fileHeader->tocs[n].subtype; | ||
560 | 416 | if (!bestSize || dist (thisSize, size) < dist (bestSize, size)) | ||
561 | 417 | { | ||
562 | 418 | bestSize = thisSize; | ||
563 | 419 | nsizes = 1; | ||
564 | 420 | } | ||
565 | 421 | else if (thisSize == bestSize) | ||
566 | 422 | nsizes++; | ||
567 | 423 | } | ||
568 | 424 | *nsizesp = nsizes; | ||
569 | 425 | return bestSize; | ||
570 | 426 | } | ||
571 | 427 | |||
572 | 428 | static int | ||
573 | 429 | _XcursorFindImageToc (XcursorFileHeader *fileHeader, | ||
574 | 430 | XcursorDim size, | ||
575 | 431 | int count) | ||
576 | 432 | { | ||
577 | 433 | unsigned int toc; | ||
578 | 434 | XcursorDim thisSize; | ||
579 | 435 | |||
580 | 436 | if (!fileHeader) | ||
581 | 437 | return 0; | ||
582 | 438 | |||
583 | 439 | for (toc = 0; toc < fileHeader->ntoc; toc++) | ||
584 | 440 | { | ||
585 | 441 | if (fileHeader->tocs[toc].type != XCURSOR_IMAGE_TYPE) | ||
586 | 442 | continue; | ||
587 | 443 | thisSize = fileHeader->tocs[toc].subtype; | ||
588 | 444 | if (thisSize != size) | ||
589 | 445 | continue; | ||
590 | 446 | if (!count) | ||
591 | 447 | break; | ||
592 | 448 | count--; | ||
593 | 449 | } | ||
594 | 450 | if (toc == fileHeader->ntoc) | ||
595 | 451 | return -1; | ||
596 | 452 | return toc; | ||
597 | 453 | } | ||
598 | 454 | |||
599 | 455 | static XcursorImage * | ||
600 | 456 | _XcursorReadImage (XcursorFile *file, | ||
601 | 457 | XcursorFileHeader *fileHeader, | ||
602 | 458 | int toc) | ||
603 | 459 | { | ||
604 | 460 | XcursorChunkHeader chunkHeader; | ||
605 | 461 | XcursorImage head; | ||
606 | 462 | XcursorImage *image; | ||
607 | 463 | int n; | ||
608 | 464 | XcursorPixel *p; | ||
609 | 465 | |||
610 | 466 | if (!file || !fileHeader) | ||
611 | 467 | return NULL; | ||
612 | 468 | |||
613 | 469 | if (!_XcursorFileReadChunkHeader (file, fileHeader, toc, &chunkHeader)) | ||
614 | 470 | return NULL; | ||
615 | 471 | if (!_XcursorReadUInt (file, &head.width)) | ||
616 | 472 | return NULL; | ||
617 | 473 | if (!_XcursorReadUInt (file, &head.height)) | ||
618 | 474 | return NULL; | ||
619 | 475 | if (!_XcursorReadUInt (file, &head.xhot)) | ||
620 | 476 | return NULL; | ||
621 | 477 | if (!_XcursorReadUInt (file, &head.yhot)) | ||
622 | 478 | return NULL; | ||
623 | 479 | if (!_XcursorReadUInt (file, &head.delay)) | ||
624 | 480 | return NULL; | ||
625 | 481 | /* sanity check data */ | ||
626 | 482 | if (head.width >= 0x10000 || head.height > 0x10000) | ||
627 | 483 | return NULL; | ||
628 | 484 | if (head.width == 0 || head.height == 0) | ||
629 | 485 | return NULL; | ||
630 | 486 | if (head.xhot > head.width || head.yhot > head.height) | ||
631 | 487 | return NULL; | ||
632 | 488 | |||
633 | 489 | /* Create the image and initialize it */ | ||
634 | 490 | image = XcursorImageCreate (head.width, head.height); | ||
635 | 491 | if (image == NULL) | ||
636 | 492 | return NULL; | ||
637 | 493 | if (chunkHeader.version < image->version) | ||
638 | 494 | image->version = chunkHeader.version; | ||
639 | 495 | image->size = chunkHeader.subtype; | ||
640 | 496 | image->xhot = head.xhot; | ||
641 | 497 | image->yhot = head.yhot; | ||
642 | 498 | image->delay = head.delay; | ||
643 | 499 | n = image->width * image->height; | ||
644 | 500 | p = image->pixels; | ||
645 | 501 | while (n--) | ||
646 | 502 | { | ||
647 | 503 | if (!_XcursorReadUInt (file, p)) | ||
648 | 504 | { | ||
649 | 505 | XcursorImageDestroy (image); | ||
650 | 506 | return NULL; | ||
651 | 507 | } | ||
652 | 508 | p++; | ||
653 | 509 | } | ||
654 | 510 | return image; | ||
655 | 511 | } | ||
656 | 512 | |||
657 | 513 | static XcursorImages * | ||
658 | 514 | XcursorXcFileLoadImages (XcursorFile *file, int size) | ||
659 | 515 | { | ||
660 | 516 | XcursorFileHeader *fileHeader; | ||
661 | 517 | XcursorDim bestSize; | ||
662 | 518 | int nsize; | ||
663 | 519 | XcursorImages *images; | ||
664 | 520 | int n; | ||
665 | 521 | int toc; | ||
666 | 522 | |||
667 | 523 | if (!file || size < 0) | ||
668 | 524 | return NULL; | ||
669 | 525 | fileHeader = _XcursorReadFileHeader (file); | ||
670 | 526 | if (!fileHeader) | ||
671 | 527 | return NULL; | ||
672 | 528 | bestSize = _XcursorFindBestSize (fileHeader, (XcursorDim) size, &nsize); | ||
673 | 529 | if (!bestSize) | ||
674 | 530 | { | ||
675 | 531 | _XcursorFileHeaderDestroy (fileHeader); | ||
676 | 532 | return NULL; | ||
677 | 533 | } | ||
678 | 534 | images = XcursorImagesCreate (nsize); | ||
679 | 535 | if (!images) | ||
680 | 536 | { | ||
681 | 537 | _XcursorFileHeaderDestroy (fileHeader); | ||
682 | 538 | return NULL; | ||
683 | 539 | } | ||
684 | 540 | for (n = 0; n < nsize; n++) | ||
685 | 541 | { | ||
686 | 542 | toc = _XcursorFindImageToc (fileHeader, bestSize, n); | ||
687 | 543 | if (toc < 0) | ||
688 | 544 | break; | ||
689 | 545 | images->images[images->nimage] = _XcursorReadImage (file, fileHeader, | ||
690 | 546 | toc); | ||
691 | 547 | if (!images->images[images->nimage]) | ||
692 | 548 | break; | ||
693 | 549 | images->nimage++; | ||
694 | 550 | } | ||
695 | 551 | _XcursorFileHeaderDestroy (fileHeader); | ||
696 | 552 | if (images->nimage != nsize) | ||
697 | 553 | { | ||
698 | 554 | XcursorImagesDestroy (images); | ||
699 | 555 | images = NULL; | ||
700 | 556 | } | ||
701 | 557 | return images; | ||
702 | 558 | } | ||
703 | 559 | |||
704 | 560 | static int | ||
705 | 561 | _XcursorStdioFileRead (XcursorFile *file, unsigned char *buf, int len) | ||
706 | 562 | { | ||
707 | 563 | FILE *f = file->closure; | ||
708 | 564 | return fread (buf, 1, len, f); | ||
709 | 565 | } | ||
710 | 566 | |||
711 | 567 | static int | ||
712 | 568 | _XcursorStdioFileWrite (XcursorFile *file, unsigned char *buf, int len) | ||
713 | 569 | { | ||
714 | 570 | FILE *f = file->closure; | ||
715 | 571 | return fwrite (buf, 1, len, f); | ||
716 | 572 | } | ||
717 | 573 | |||
718 | 574 | static int | ||
719 | 575 | _XcursorStdioFileSeek (XcursorFile *file, long offset, int whence) | ||
720 | 576 | { | ||
721 | 577 | FILE *f = file->closure; | ||
722 | 578 | return fseek (f, offset, whence); | ||
723 | 579 | } | ||
724 | 580 | |||
725 | 581 | static void | ||
726 | 582 | _XcursorStdioFileInitialize (FILE *stdfile, XcursorFile *file) | ||
727 | 583 | { | ||
728 | 584 | file->closure = stdfile; | ||
729 | 585 | file->read = _XcursorStdioFileRead; | ||
730 | 586 | file->write = _XcursorStdioFileWrite; | ||
731 | 587 | file->seek = _XcursorStdioFileSeek; | ||
732 | 588 | } | ||
733 | 589 | |||
734 | 590 | static XcursorImages * | ||
735 | 591 | XcursorFileLoadImages (FILE *file, int size) | ||
736 | 592 | { | ||
737 | 593 | XcursorFile f; | ||
738 | 594 | |||
739 | 595 | if (!file) | ||
740 | 596 | return NULL; | ||
741 | 597 | |||
742 | 598 | _XcursorStdioFileInitialize (file, &f); | ||
743 | 599 | return XcursorXcFileLoadImages (&f, size); | ||
744 | 600 | } | ||
745 | 601 | |||
746 | 602 | /* | ||
747 | 603 | * From libXcursor/src/library.c | ||
748 | 604 | */ | ||
749 | 605 | |||
750 | 606 | #ifndef ICONDIR | ||
751 | 607 | #define ICONDIR "/usr/X11R6/lib/X11/icons" | ||
752 | 608 | #endif | ||
753 | 609 | |||
754 | 610 | #ifndef XCURSORPATH | ||
755 | 611 | #define XCURSORPATH "~/.icons:/usr/share/icons:/usr/share/pixmaps:~/.cursors:/usr/share/cursors/xorg-x11:"ICONDIR | ||
756 | 612 | #endif | ||
757 | 613 | |||
758 | 614 | static const char * | ||
759 | 615 | XcursorLibraryPath (void) | ||
760 | 616 | { | ||
761 | 617 | static const char *path; | ||
762 | 618 | |||
763 | 619 | if (!path) | ||
764 | 620 | { | ||
765 | 621 | path = getenv ("XCURSOR_PATH"); | ||
766 | 622 | if (!path) | ||
767 | 623 | path = XCURSORPATH; | ||
768 | 624 | } | ||
769 | 625 | return path; | ||
770 | 626 | } | ||
771 | 627 | |||
772 | 628 | static void | ||
773 | 629 | _XcursorAddPathElt (char *path, const char *elt, int len) | ||
774 | 630 | { | ||
775 | 631 | int pathlen = strlen (path); | ||
776 | 632 | |||
777 | 633 | /* append / if the path doesn't currently have one */ | ||
778 | 634 | if (path[0] == '\0' || path[pathlen - 1] != '/') | ||
779 | 635 | { | ||
780 | 636 | strcat (path, "/"); | ||
781 | 637 | pathlen++; | ||
782 | 638 | } | ||
783 | 639 | if (len == -1) | ||
784 | 640 | len = strlen (elt); | ||
785 | 641 | /* strip leading slashes */ | ||
786 | 642 | while (len && elt[0] == '/') | ||
787 | 643 | { | ||
788 | 644 | elt++; | ||
789 | 645 | len--; | ||
790 | 646 | } | ||
791 | 647 | strncpy (path + pathlen, elt, len); | ||
792 | 648 | path[pathlen + len] = '\0'; | ||
793 | 649 | } | ||
794 | 650 | |||
795 | 651 | static char * | ||
796 | 652 | _XcursorBuildThemeDir (const char *dir, const char *theme) | ||
797 | 653 | { | ||
798 | 654 | const char *colon; | ||
799 | 655 | const char *tcolon; | ||
800 | 656 | char *full; | ||
801 | 657 | char *home; | ||
802 | 658 | int dirlen; | ||
803 | 659 | int homelen; | ||
804 | 660 | int themelen; | ||
805 | 661 | int len; | ||
806 | 662 | |||
807 | 663 | if (!dir || !theme) | ||
808 | 664 | return NULL; | ||
809 | 665 | |||
810 | 666 | colon = strchr (dir, ':'); | ||
811 | 667 | if (!colon) | ||
812 | 668 | colon = dir + strlen (dir); | ||
813 | 669 | |||
814 | 670 | dirlen = colon - dir; | ||
815 | 671 | |||
816 | 672 | tcolon = strchr (theme, ':'); | ||
817 | 673 | if (!tcolon) | ||
818 | 674 | tcolon = theme + strlen (theme); | ||
819 | 675 | |||
820 | 676 | themelen = tcolon - theme; | ||
821 | 677 | |||
822 | 678 | home = NULL; | ||
823 | 679 | homelen = 0; | ||
824 | 680 | if (*dir == '~') | ||
825 | 681 | { | ||
826 | 682 | home = getenv ("HOME"); | ||
827 | 683 | if (!home) | ||
828 | 684 | return NULL; | ||
829 | 685 | homelen = strlen (home); | ||
830 | 686 | dir++; | ||
831 | 687 | dirlen--; | ||
832 | 688 | } | ||
833 | 689 | |||
834 | 690 | /* | ||
835 | 691 | * add space for any needed directory separators, one per component, | ||
836 | 692 | * and one for the trailing null | ||
837 | 693 | */ | ||
838 | 694 | len = 1 + homelen + 1 + dirlen + 1 + themelen + 1; | ||
839 | 695 | |||
840 | 696 | full = malloc (len); | ||
841 | 697 | if (!full) | ||
842 | 698 | return NULL; | ||
843 | 699 | full[0] = '\0'; | ||
844 | 700 | |||
845 | 701 | if (home) | ||
846 | 702 | _XcursorAddPathElt (full, home, -1); | ||
847 | 703 | _XcursorAddPathElt (full, dir, dirlen); | ||
848 | 704 | _XcursorAddPathElt (full, theme, themelen); | ||
849 | 705 | return full; | ||
850 | 706 | } | ||
851 | 707 | |||
852 | 708 | static char * | ||
853 | 709 | _XcursorBuildFullname (const char *dir, const char *subdir, const char *file) | ||
854 | 710 | { | ||
855 | 711 | char *full; | ||
856 | 712 | |||
857 | 713 | if (!dir || !subdir || !file) | ||
858 | 714 | return NULL; | ||
859 | 715 | |||
860 | 716 | full = malloc (strlen (dir) + 1 + strlen (subdir) + 1 + strlen (file) + 1); | ||
861 | 717 | if (!full) | ||
862 | 718 | return NULL; | ||
863 | 719 | full[0] = '\0'; | ||
864 | 720 | _XcursorAddPathElt (full, dir, -1); | ||
865 | 721 | _XcursorAddPathElt (full, subdir, -1); | ||
866 | 722 | _XcursorAddPathElt (full, file, -1); | ||
867 | 723 | return full; | ||
868 | 724 | } | ||
869 | 725 | |||
870 | 726 | static const char * | ||
871 | 727 | _XcursorNextPath (const char *path) | ||
872 | 728 | { | ||
873 | 729 | char *colon = strchr (path, ':'); | ||
874 | 730 | |||
875 | 731 | if (!colon) | ||
876 | 732 | return NULL; | ||
877 | 733 | return colon + 1; | ||
878 | 734 | } | ||
879 | 735 | |||
880 | 736 | #define XcursorWhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\n') | ||
881 | 737 | #define XcursorSep(c) ((c) == ';' || (c) == ',') | ||
882 | 738 | |||
883 | 739 | static char * | ||
884 | 740 | _XcursorThemeInherits (const char *full) | ||
885 | 741 | { | ||
886 | 742 | char line[8192]; | ||
887 | 743 | char *result = NULL; | ||
888 | 744 | FILE *f; | ||
889 | 745 | |||
890 | 746 | if (!full) | ||
891 | 747 | return NULL; | ||
892 | 748 | |||
893 | 749 | f = fopen (full, "r"); | ||
894 | 750 | if (f) | ||
895 | 751 | { | ||
896 | 752 | while (fgets (line, sizeof (line), f)) | ||
897 | 753 | { | ||
898 | 754 | if (!strncmp (line, "Inherits", 8)) | ||
899 | 755 | { | ||
900 | 756 | char *l = line + 8; | ||
901 | 757 | char *r; | ||
902 | 758 | while (*l == ' ') l++; | ||
903 | 759 | if (*l != '=') continue; | ||
904 | 760 | l++; | ||
905 | 761 | while (*l == ' ') l++; | ||
906 | 762 | result = malloc (strlen (l) + 1); | ||
907 | 763 | if (result) | ||
908 | 764 | { | ||
909 | 765 | r = result; | ||
910 | 766 | while (*l) | ||
911 | 767 | { | ||
912 | 768 | while (XcursorSep(*l) || XcursorWhite (*l)) l++; | ||
913 | 769 | if (!*l) | ||
914 | 770 | break; | ||
915 | 771 | if (r != result) | ||
916 | 772 | *r++ = ':'; | ||
917 | 773 | while (*l && !XcursorWhite(*l) && | ||
918 | 774 | !XcursorSep(*l)) | ||
919 | 775 | *r++ = *l++; | ||
920 | 776 | } | ||
921 | 777 | *r++ = '\0'; | ||
922 | 778 | } | ||
923 | 779 | break; | ||
924 | 780 | } | ||
925 | 781 | } | ||
926 | 782 | fclose (f); | ||
927 | 783 | } | ||
928 | 784 | return result; | ||
929 | 785 | } | ||
930 | 786 | |||
931 | 787 | static FILE * | ||
932 | 788 | XcursorScanTheme (const char *theme, const char *name) | ||
933 | 789 | { | ||
934 | 790 | FILE *f = NULL; | ||
935 | 791 | char *full; | ||
936 | 792 | char *dir; | ||
937 | 793 | const char *path; | ||
938 | 794 | char *inherits = NULL; | ||
939 | 795 | const char *i; | ||
940 | 796 | |||
941 | 797 | if (!theme || !name) | ||
942 | 798 | return NULL; | ||
943 | 799 | |||
944 | 800 | /* | ||
945 | 801 | * Scan this theme | ||
946 | 802 | */ | ||
947 | 803 | for (path = XcursorLibraryPath (); | ||
948 | 804 | path && f == NULL; | ||
949 | 805 | path = _XcursorNextPath (path)) | ||
950 | 806 | { | ||
951 | 807 | dir = _XcursorBuildThemeDir (path, theme); | ||
952 | 808 | if (dir) | ||
953 | 809 | { | ||
954 | 810 | full = _XcursorBuildFullname (dir, "cursors", name); | ||
955 | 811 | if (full) | ||
956 | 812 | { | ||
957 | 813 | f = fopen (full, "r"); | ||
958 | 814 | free (full); | ||
959 | 815 | } | ||
960 | 816 | if (!f && !inherits) | ||
961 | 817 | { | ||
962 | 818 | full = _XcursorBuildFullname (dir, "", "index.theme"); | ||
963 | 819 | if (full) | ||
964 | 820 | { | ||
965 | 821 | inherits = _XcursorThemeInherits (full); | ||
966 | 822 | free (full); | ||
967 | 823 | } | ||
968 | 824 | } | ||
969 | 825 | free (dir); | ||
970 | 826 | } | ||
971 | 827 | } | ||
972 | 828 | /* | ||
973 | 829 | * Recurse to scan inherited themes | ||
974 | 830 | */ | ||
975 | 831 | for (i = inherits; i && f == NULL; i = _XcursorNextPath (i)) | ||
976 | 832 | f = XcursorScanTheme (i, name); | ||
977 | 833 | if (inherits != NULL) | ||
978 | 834 | free (inherits); | ||
979 | 835 | return f; | ||
980 | 836 | } | ||
981 | 837 | |||
982 | 838 | XcursorImages * | ||
983 | 839 | XcursorLibraryLoadImages (const char *file, const char *theme, int size) | ||
984 | 840 | { | ||
985 | 841 | FILE *f = NULL; | ||
986 | 842 | XcursorImages *images = NULL; | ||
987 | 843 | |||
988 | 844 | if (!file) | ||
989 | 845 | return NULL; | ||
990 | 846 | |||
991 | 847 | if (theme) | ||
992 | 848 | f = XcursorScanTheme (theme, file); | ||
993 | 849 | if (!f) | ||
994 | 850 | f = XcursorScanTheme ("default", file); | ||
995 | 851 | if (f) | ||
996 | 852 | { | ||
997 | 853 | images = XcursorFileLoadImages (f, size); | ||
998 | 854 | if (images) | ||
999 | 855 | XcursorImagesSetName (images, file); | ||
1000 | 856 | fclose (f); | ||
1001 | 857 | } | ||
1002 | 858 | return images; | ||
1003 | 859 | } | ||
1004 | 860 | |||
1005 | 861 | static void | ||
1006 | 862 | load_all_cursors_from_dir(const char *path, int size, | ||
1007 | 863 | void (*load_callback)(XcursorImages *, void *), | ||
1008 | 864 | void *user_data) | ||
1009 | 865 | { | ||
1010 | 866 | FILE *f; | ||
1011 | 867 | DIR *dir = opendir(path); | ||
1012 | 868 | struct dirent *ent; | ||
1013 | 869 | char *full; | ||
1014 | 870 | XcursorImages *images; | ||
1015 | 871 | |||
1016 | 872 | if (!dir) | ||
1017 | 873 | return; | ||
1018 | 874 | |||
1019 | 875 | for(ent = readdir(dir); ent; ent = readdir(dir)) { | ||
1020 | 876 | #ifdef _DIRENT_HAVE_D_TYPE | ||
1021 | 877 | if (ent->d_type != DT_UNKNOWN && | ||
1022 | 878 | (ent->d_type != DT_REG && ent->d_type != DT_LNK)) | ||
1023 | 879 | continue; | ||
1024 | 880 | #endif | ||
1025 | 881 | |||
1026 | 882 | full = _XcursorBuildFullname(path, "", ent->d_name); | ||
1027 | 883 | if (!full) | ||
1028 | 884 | continue; | ||
1029 | 885 | |||
1030 | 886 | f = fopen(full, "r"); | ||
1031 | 887 | if (!f) { | ||
1032 | 888 | free(full); | ||
1033 | 889 | continue; | ||
1034 | 890 | } | ||
1035 | 891 | |||
1036 | 892 | images = XcursorFileLoadImages(f, size); | ||
1037 | 893 | |||
1038 | 894 | if (images) { | ||
1039 | 895 | XcursorImagesSetName(images, ent->d_name); | ||
1040 | 896 | load_callback(images, user_data); | ||
1041 | 897 | } | ||
1042 | 898 | |||
1043 | 899 | fclose (f); | ||
1044 | 900 | free(full); | ||
1045 | 901 | } | ||
1046 | 902 | |||
1047 | 903 | closedir(dir); | ||
1048 | 904 | } | ||
1049 | 905 | |||
1050 | 906 | /** Load all the cursor of a theme | ||
1051 | 907 | * | ||
1052 | 908 | * This function loads all the cursor images of a given theme and its | ||
1053 | 909 | * inherited themes. Each cursor is loaded into an XcursorImages object | ||
1054 | 910 | * which is passed to the caller's load callback. If a cursor appears | ||
1055 | 911 | * more than once across all the inherited themes, the load callback | ||
1056 | 912 | * will be called multiple times, with possibly different XcursorImages | ||
1057 | 913 | * object which have the same name. The user is expected to destroy the | ||
1058 | 914 | * XcursorImages objects passed to the callback with | ||
1059 | 915 | * XcursorImagesDestroy(). | ||
1060 | 916 | * | ||
1061 | 917 | * \param theme The name of theme that should be loaded | ||
1062 | 918 | * \param size The desired size of the cursor images | ||
1063 | 919 | * \param load_callback A callback function that will be called | ||
1064 | 920 | * for each cursor loaded. The first parameter is the XcursorImages | ||
1065 | 921 | * object representing the loaded cursor and the second is a pointer | ||
1066 | 922 | * to data provided by the user. | ||
1067 | 923 | * \param user_data The data that should be passed to the load callback | ||
1068 | 924 | */ | ||
1069 | 925 | void | ||
1070 | 926 | xcursor_load_theme(const char *theme, int size, | ||
1071 | 927 | void (*load_callback)(XcursorImages *, void *), | ||
1072 | 928 | void *user_data) | ||
1073 | 929 | { | ||
1074 | 930 | char *full, *dir; | ||
1075 | 931 | char *inherits = NULL; | ||
1076 | 932 | const char *path, *i; | ||
1077 | 933 | |||
1078 | 934 | if (!theme) | ||
1079 | 935 | theme = "default"; | ||
1080 | 936 | |||
1081 | 937 | for (path = XcursorLibraryPath(); | ||
1082 | 938 | path; | ||
1083 | 939 | path = _XcursorNextPath(path)) { | ||
1084 | 940 | dir = _XcursorBuildThemeDir(path, theme); | ||
1085 | 941 | if (!dir) | ||
1086 | 942 | continue; | ||
1087 | 943 | |||
1088 | 944 | full = _XcursorBuildFullname(dir, "cursors", ""); | ||
1089 | 945 | |||
1090 | 946 | if (full) { | ||
1091 | 947 | load_all_cursors_from_dir(full, size, load_callback, | ||
1092 | 948 | user_data); | ||
1093 | 949 | free(full); | ||
1094 | 950 | } | ||
1095 | 951 | |||
1096 | 952 | if (!inherits) { | ||
1097 | 953 | full = _XcursorBuildFullname(dir, "", "index.theme"); | ||
1098 | 954 | if (full) { | ||
1099 | 955 | inherits = _XcursorThemeInherits(full); | ||
1100 | 956 | free(full); | ||
1101 | 957 | } | ||
1102 | 958 | } | ||
1103 | 959 | |||
1104 | 960 | free(dir); | ||
1105 | 961 | } | ||
1106 | 962 | |||
1107 | 963 | for (i = inherits; i; i = _XcursorNextPath(i)) | ||
1108 | 964 | xcursor_load_theme(i, size, load_callback, user_data); | ||
1109 | 965 | |||
1110 | 966 | if (inherits) | ||
1111 | 967 | free(inherits); | ||
1112 | 968 | } | ||
1113 | 0 | 969 | ||
1114 | === added file 'plugins/Cursor/3rd_party/xcursor/xcursor.h' | |||
1115 | --- plugins/Cursor/3rd_party/xcursor/xcursor.h 1970-01-01 00:00:00 +0000 | |||
1116 | +++ plugins/Cursor/3rd_party/xcursor/xcursor.h 2015-10-19 14:53:23 +0000 | |||
1117 | @@ -0,0 +1,65 @@ | |||
1118 | 1 | /* | ||
1119 | 2 | * Copyright © 2002 Keith Packard | ||
1120 | 3 | * | ||
1121 | 4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
1122 | 5 | * documentation for any purpose is hereby granted without fee, provided that | ||
1123 | 6 | * the above copyright notice appear in all copies and that both that | ||
1124 | 7 | * copyright notice and this permission notice appear in supporting | ||
1125 | 8 | * documentation, and that the name of Keith Packard not be used in | ||
1126 | 9 | * advertising or publicity pertaining to distribution of the software without | ||
1127 | 10 | * specific, written prior permission. Keith Packard makes no | ||
1128 | 11 | * representations about the suitability of this software for any purpose. It | ||
1129 | 12 | * is provided "as is" without express or implied warranty. | ||
1130 | 13 | * | ||
1131 | 14 | * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
1132 | 15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | ||
1133 | 16 | * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
1134 | 17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | ||
1135 | 18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
1136 | 19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
1137 | 20 | * PERFORMANCE OF THIS SOFTWARE. | ||
1138 | 21 | */ | ||
1139 | 22 | |||
1140 | 23 | #ifndef XCURSOR_H | ||
1141 | 24 | #define XCURSOR_H | ||
1142 | 25 | |||
1143 | 26 | #include <stdint.h> | ||
1144 | 27 | |||
1145 | 28 | |||
1146 | 29 | typedef int XcursorBool; | ||
1147 | 30 | typedef uint32_t XcursorUInt; | ||
1148 | 31 | |||
1149 | 32 | typedef XcursorUInt XcursorDim; | ||
1150 | 33 | typedef XcursorUInt XcursorPixel; | ||
1151 | 34 | |||
1152 | 35 | typedef struct _XcursorImage { | ||
1153 | 36 | XcursorUInt version; /* version of the image data */ | ||
1154 | 37 | XcursorDim size; /* nominal size for matching */ | ||
1155 | 38 | XcursorDim width; /* actual width */ | ||
1156 | 39 | XcursorDim height; /* actual height */ | ||
1157 | 40 | XcursorDim xhot; /* hot spot x (must be inside image) */ | ||
1158 | 41 | XcursorDim yhot; /* hot spot y (must be inside image) */ | ||
1159 | 42 | XcursorUInt delay; /* animation delay to next frame (ms) */ | ||
1160 | 43 | XcursorPixel *pixels; /* pointer to pixels */ | ||
1161 | 44 | } XcursorImage; | ||
1162 | 45 | |||
1163 | 46 | /* | ||
1164 | 47 | * Other data structures exposed by the library API | ||
1165 | 48 | */ | ||
1166 | 49 | typedef struct _XcursorImages { | ||
1167 | 50 | int nimage; /* number of images */ | ||
1168 | 51 | XcursorImage **images; /* array of XcursorImage pointers */ | ||
1169 | 52 | char *name; /* name used to load images */ | ||
1170 | 53 | } XcursorImages; | ||
1171 | 54 | |||
1172 | 55 | XcursorImages * | ||
1173 | 56 | XcursorLibraryLoadImages (const char *file, const char *theme, int size); | ||
1174 | 57 | |||
1175 | 58 | void | ||
1176 | 59 | XcursorImagesDestroy (XcursorImages *images); | ||
1177 | 60 | |||
1178 | 61 | void | ||
1179 | 62 | xcursor_load_theme(const char *theme, int size, | ||
1180 | 63 | void (*load_callback)(XcursorImages *, void *), | ||
1181 | 64 | void *user_data); | ||
1182 | 65 | #endif | ||
1183 | 0 | 66 | ||
1184 | === added file 'plugins/Cursor/CMakeLists.txt' | |||
1185 | --- plugins/Cursor/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1186 | +++ plugins/Cursor/CMakeLists.txt 2015-10-19 14:53:23 +0000 | |||
1187 | @@ -0,0 +1,28 @@ | |||
1188 | 1 | add_subdirectory(3rd_party) | ||
1189 | 2 | |||
1190 | 3 | include_directories( | ||
1191 | 4 | ${CMAKE_CURRENT_SOURCE_DIR} | ||
1192 | 5 | ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/xcursor | ||
1193 | 6 | ${Qt5Gui_PRIVATE_INCLUDE_DIRS} | ||
1194 | 7 | ) | ||
1195 | 8 | |||
1196 | 9 | set(QMLPLUGIN_SRC | ||
1197 | 10 | plugin.cpp | ||
1198 | 11 | MousePointer.cpp | ||
1199 | 12 | CursorImageProvider.cpp | ||
1200 | 13 | # We need to run moc on this header | ||
1201 | 14 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirMousePointerInterface.h | ||
1202 | 15 | ) | ||
1203 | 16 | |||
1204 | 17 | add_library(Cursor-qml SHARED | ||
1205 | 18 | ${QMLPLUGIN_SRC} | ||
1206 | 19 | ) | ||
1207 | 20 | |||
1208 | 21 | target_link_libraries(Cursor-qml | ||
1209 | 22 | xcursorloader-static | ||
1210 | 23 | ${QT5PLATFORM_SUPPORT_LDFLAGS} | ||
1211 | 24 | ) | ||
1212 | 25 | |||
1213 | 26 | qt5_use_modules(Cursor-qml Qml Quick DBus Network Gui Sql Concurrent Svg) | ||
1214 | 27 | |||
1215 | 28 | add_unity8_plugin(Cursor 1.0 Cursor TARGETS Cursor-qml) | ||
1216 | 0 | 29 | ||
1217 | === added file 'plugins/Cursor/Cursor.qml' | |||
1218 | --- plugins/Cursor/Cursor.qml 1970-01-01 00:00:00 +0000 | |||
1219 | +++ plugins/Cursor/Cursor.qml 2015-10-19 14:53:23 +0000 | |||
1220 | @@ -0,0 +1,12 @@ | |||
1221 | 1 | import QtQuick 2.4 | ||
1222 | 2 | import Cursor 1.0 // For MousePointer | ||
1223 | 3 | |||
1224 | 4 | MousePointer { | ||
1225 | 5 | id: mousePointer | ||
1226 | 6 | |||
1227 | 7 | Image { | ||
1228 | 8 | x: -mousePointer.hotspotX | ||
1229 | 9 | y: -mousePointer.hotspotY | ||
1230 | 10 | source: "image://cursor/" + mousePointer.themeName + "/" + mousePointer.cursorName | ||
1231 | 11 | } | ||
1232 | 12 | } | ||
1233 | 0 | 13 | ||
1234 | === added file 'plugins/Cursor/CursorImageProvider.cpp' | |||
1235 | --- plugins/Cursor/CursorImageProvider.cpp 1970-01-01 00:00:00 +0000 | |||
1236 | +++ plugins/Cursor/CursorImageProvider.cpp 2015-10-19 14:53:23 +0000 | |||
1237 | @@ -0,0 +1,191 @@ | |||
1238 | 1 | /* | ||
1239 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
1240 | 3 | * | ||
1241 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1242 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1243 | 6 | * the Free Software Foundation. | ||
1244 | 7 | * | ||
1245 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1246 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1247 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1248 | 11 | * Lesser General Public License for more details. | ||
1249 | 12 | * | ||
1250 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1251 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1252 | 15 | */ | ||
1253 | 16 | |||
1254 | 17 | #include "CursorImageProvider.h" | ||
1255 | 18 | |||
1256 | 19 | #include <QDebug> | ||
1257 | 20 | #include <QFile> | ||
1258 | 21 | #include <QPainter> | ||
1259 | 22 | #include <QSvgRenderer> | ||
1260 | 23 | |||
1261 | 24 | CursorImageProvider *CursorImageProvider::m_instance = nullptr; | ||
1262 | 25 | |||
1263 | 26 | ///// | ||
1264 | 27 | // BuiltInCursorImage | ||
1265 | 28 | |||
1266 | 29 | BuiltInCursorImage::BuiltInCursorImage() | ||
1267 | 30 | { | ||
1268 | 31 | const char *svgString = | ||
1269 | 32 | "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" | ||
1270 | 33 | "<svg" | ||
1271 | 34 | " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"" | ||
1272 | 35 | " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" | ||
1273 | 36 | " xmlns:svg=\"http://www.w3.org/2000/svg\"" | ||
1274 | 37 | " xmlns=\"http://www.w3.org/2000/svg\"" | ||
1275 | 38 | " version=\"1.1\">" | ||
1276 | 39 | " <path" | ||
1277 | 40 | " style=\"fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:40;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1\"" | ||
1278 | 41 | " d=\"M 20.504,50.94931 460.42533,518.14486 266.47603,515.61948 366.48114,719.16522 274.05218,770.68296 172.53185,559.56112 20.504,716.13476 Z\" />" | ||
1279 | 42 | "</svg>"; | ||
1280 | 43 | |||
1281 | 44 | qimage = QImage(20, 32, QImage::Format_ARGB32); | ||
1282 | 45 | QPainter imagePainter(&qimage); | ||
1283 | 46 | |||
1284 | 47 | QSvgRenderer *svgRenderer = new QSvgRenderer(QByteArray(svgString)); | ||
1285 | 48 | svgRenderer->render(&imagePainter); | ||
1286 | 49 | delete svgRenderer; | ||
1287 | 50 | } | ||
1288 | 51 | |||
1289 | 52 | ///// | ||
1290 | 53 | // XCursorImage | ||
1291 | 54 | |||
1292 | 55 | XCursorImage::XCursorImage(const QString &theme, const QString &file) | ||
1293 | 56 | : xcursorImages(nullptr) | ||
1294 | 57 | { | ||
1295 | 58 | xcursorImages = XcursorLibraryLoadImages(QFile::encodeName(file), QFile::encodeName(theme), 32); | ||
1296 | 59 | if (!xcursorImages) { | ||
1297 | 60 | return; | ||
1298 | 61 | } | ||
1299 | 62 | |||
1300 | 63 | bool loaded = false; | ||
1301 | 64 | for (int i = 0; i < xcursorImages->nimage && !loaded; ++i) { | ||
1302 | 65 | XcursorImage *xcursorImage = xcursorImages->images[i]; | ||
1303 | 66 | if (xcursorImage->size == 32) { | ||
1304 | 67 | |||
1305 | 68 | qimage = QImage((uchar*)xcursorImage->pixels, | ||
1306 | 69 | xcursorImage->width, xcursorImage->height, QImage::Format_ARGB32); | ||
1307 | 70 | |||
1308 | 71 | hotspot.setX(xcursorImage->xhot); | ||
1309 | 72 | hotspot.setY(xcursorImage->yhot); | ||
1310 | 73 | |||
1311 | 74 | loaded = true; | ||
1312 | 75 | } | ||
1313 | 76 | } | ||
1314 | 77 | } | ||
1315 | 78 | |||
1316 | 79 | XCursorImage::~XCursorImage() | ||
1317 | 80 | { | ||
1318 | 81 | XcursorImagesDestroy(xcursorImages); | ||
1319 | 82 | } | ||
1320 | 83 | |||
1321 | 84 | ///// | ||
1322 | 85 | // CursorImageProvider | ||
1323 | 86 | |||
1324 | 87 | CursorImageProvider::CursorImageProvider() | ||
1325 | 88 | : QQuickImageProvider(QQuickImageProvider::Image) | ||
1326 | 89 | { | ||
1327 | 90 | if (m_instance) { | ||
1328 | 91 | qFatal("Cannot have multiple CursorImageProvider instances"); | ||
1329 | 92 | } | ||
1330 | 93 | m_instance = this; | ||
1331 | 94 | } | ||
1332 | 95 | |||
1333 | 96 | CursorImageProvider::~CursorImageProvider() | ||
1334 | 97 | { | ||
1335 | 98 | { | ||
1336 | 99 | QList< QMap<QString, CursorImage*> > cursorList = m_cursors.values(); | ||
1337 | 100 | |||
1338 | 101 | for (int i = 0; i < cursorList.count(); ++i) { | ||
1339 | 102 | QList<CursorImage*> cursorImageList = cursorList[i].values(); | ||
1340 | 103 | for (int j = 0; j < cursorImageList.count(); ++j) { | ||
1341 | 104 | delete cursorImageList[j]; | ||
1342 | 105 | } | ||
1343 | 106 | } | ||
1344 | 107 | } | ||
1345 | 108 | |||
1346 | 109 | m_cursors.clear(); | ||
1347 | 110 | m_instance = nullptr; | ||
1348 | 111 | } | ||
1349 | 112 | |||
1350 | 113 | QImage CursorImageProvider::requestImage(const QString &cursorThemeAndName, QSize *size, const QSize & /*requestedSize*/) | ||
1351 | 114 | { | ||
1352 | 115 | CursorImage *cursorImage = fetchCursor(cursorThemeAndName); | ||
1353 | 116 | size->setWidth(cursorImage->qimage.width()); | ||
1354 | 117 | size->setHeight(cursorImage->qimage.height()); | ||
1355 | 118 | |||
1356 | 119 | return cursorImage->qimage; | ||
1357 | 120 | } | ||
1358 | 121 | |||
1359 | 122 | QPoint CursorImageProvider::hotspot(const QString &themeName, const QString &cursorName) | ||
1360 | 123 | { | ||
1361 | 124 | CursorImage *cursorImage = fetchCursor(themeName, cursorName); | ||
1362 | 125 | if (cursorImage) { | ||
1363 | 126 | return cursorImage->hotspot; | ||
1364 | 127 | } else { | ||
1365 | 128 | return QPoint(0,0); | ||
1366 | 129 | } | ||
1367 | 130 | } | ||
1368 | 131 | |||
1369 | 132 | CursorImage *CursorImageProvider::fetchCursor(const QString &cursorThemeAndName) | ||
1370 | 133 | { | ||
1371 | 134 | QString themeName; | ||
1372 | 135 | QString cursorName; | ||
1373 | 136 | { | ||
1374 | 137 | QStringList themeAndNameList = cursorThemeAndName.split("/"); | ||
1375 | 138 | if (themeAndNameList.size() != 2) { | ||
1376 | 139 | return nullptr; | ||
1377 | 140 | } | ||
1378 | 141 | themeName = themeAndNameList[0]; | ||
1379 | 142 | cursorName = themeAndNameList[1]; | ||
1380 | 143 | } | ||
1381 | 144 | |||
1382 | 145 | return fetchCursor(themeName, cursorName); | ||
1383 | 146 | } | ||
1384 | 147 | |||
1385 | 148 | CursorImage *CursorImageProvider::fetchCursor(const QString &themeName, const QString &cursorName) | ||
1386 | 149 | { | ||
1387 | 150 | CursorImage *cursorImage = fetchCursorHelper(themeName, cursorName); | ||
1388 | 151 | |||
1389 | 152 | // Try some fallbacks | ||
1390 | 153 | if (cursorImage->qimage.isNull()) { | ||
1391 | 154 | if (cursorName == "ibeam") { | ||
1392 | 155 | qDebug() << "CursorImageProvider: \"ibeam\" not found, falling back to \"xterm\""; | ||
1393 | 156 | cursorImage = fetchCursorHelper(themeName, "xterm"); | ||
1394 | 157 | } else if (cursorName == "xterm") { | ||
1395 | 158 | qDebug() << "CursorImageProvider: \"xterm\" not found, falling back to \"ibeam\""; | ||
1396 | 159 | cursorImage = fetchCursorHelper(themeName, "ibeam"); | ||
1397 | 160 | } | ||
1398 | 161 | } | ||
1399 | 162 | |||
1400 | 163 | // if it all fails, there must be at least a left_ptr | ||
1401 | 164 | if (cursorImage->qimage.isNull() && cursorName != "left_ptr") { | ||
1402 | 165 | qDebug() << "CursorImageProvider:" << cursorName | ||
1403 | 166 | << "not found (nor its fallbacks, if any). Going for \"left_ptr\" as a last resort."; | ||
1404 | 167 | cursorImage = fetchCursorHelper(themeName, "left_ptr"); | ||
1405 | 168 | } | ||
1406 | 169 | |||
1407 | 170 | if (cursorImage->qimage.isNull()) { | ||
1408 | 171 | // finally, go for the built-in cursor | ||
1409 | 172 | qWarning() << "CursorImageProvider: couldn't find any cursors. Using the built-in one"; | ||
1410 | 173 | if (!m_builtInCursorImage) { | ||
1411 | 174 | m_builtInCursorImage.reset(new BuiltInCursorImage); | ||
1412 | 175 | } | ||
1413 | 176 | cursorImage = m_builtInCursorImage.data(); | ||
1414 | 177 | } | ||
1415 | 178 | |||
1416 | 179 | return cursorImage; | ||
1417 | 180 | } | ||
1418 | 181 | |||
1419 | 182 | CursorImage *CursorImageProvider::fetchCursorHelper(const QString &themeName, const QString &cursorName) | ||
1420 | 183 | { | ||
1421 | 184 | QMap<QString, CursorImage*> &themeCursors = m_cursors[themeName]; | ||
1422 | 185 | |||
1423 | 186 | if (!themeCursors.contains(cursorName)) { | ||
1424 | 187 | themeCursors[cursorName] = new XCursorImage(themeName, cursorName); | ||
1425 | 188 | } | ||
1426 | 189 | |||
1427 | 190 | return themeCursors[cursorName]; | ||
1428 | 191 | } | ||
1429 | 0 | 192 | ||
1430 | === added file 'plugins/Cursor/CursorImageProvider.h' | |||
1431 | --- plugins/Cursor/CursorImageProvider.h 1970-01-01 00:00:00 +0000 | |||
1432 | +++ plugins/Cursor/CursorImageProvider.h 2015-10-19 14:53:23 +0000 | |||
1433 | @@ -0,0 +1,76 @@ | |||
1434 | 1 | /* | ||
1435 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
1436 | 3 | * | ||
1437 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1438 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1439 | 6 | * the Free Software Foundation. | ||
1440 | 7 | * | ||
1441 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1442 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1443 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1444 | 11 | * Lesser General Public License for more details. | ||
1445 | 12 | * | ||
1446 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1447 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1448 | 15 | */ | ||
1449 | 16 | |||
1450 | 17 | #ifndef CURSORIMAGEPROVIDER_H | ||
1451 | 18 | #define CURSORIMAGEPROVIDER_H | ||
1452 | 19 | |||
1453 | 20 | #include <QQuickImageProvider> | ||
1454 | 21 | #include <QScopedPointer> | ||
1455 | 22 | |||
1456 | 23 | // xcursor static lib | ||
1457 | 24 | extern "C" | ||
1458 | 25 | { | ||
1459 | 26 | #include <xcursor.h> | ||
1460 | 27 | } | ||
1461 | 28 | |||
1462 | 29 | class CursorImage { | ||
1463 | 30 | public: | ||
1464 | 31 | virtual ~CursorImage() {} | ||
1465 | 32 | |||
1466 | 33 | QImage qimage; | ||
1467 | 34 | QPoint hotspot; | ||
1468 | 35 | }; | ||
1469 | 36 | |||
1470 | 37 | class XCursorImage : public CursorImage { | ||
1471 | 38 | public: | ||
1472 | 39 | XCursorImage(const QString &theme, const QString &file); | ||
1473 | 40 | virtual ~XCursorImage(); | ||
1474 | 41 | |||
1475 | 42 | XcursorImages *xcursorImages; | ||
1476 | 43 | }; | ||
1477 | 44 | |||
1478 | 45 | class BuiltInCursorImage : public CursorImage { | ||
1479 | 46 | public: | ||
1480 | 47 | BuiltInCursorImage(); | ||
1481 | 48 | }; | ||
1482 | 49 | |||
1483 | 50 | class CursorImageProvider : public QQuickImageProvider | ||
1484 | 51 | { | ||
1485 | 52 | public: | ||
1486 | 53 | CursorImageProvider(); | ||
1487 | 54 | virtual ~CursorImageProvider(); | ||
1488 | 55 | |||
1489 | 56 | static CursorImageProvider *instance() { return m_instance; } | ||
1490 | 57 | |||
1491 | 58 | |||
1492 | 59 | QImage requestImage(const QString &cursorName, QSize *size, const QSize &requestedSize) override; | ||
1493 | 60 | |||
1494 | 61 | QPoint hotspot(const QString &themeName, const QString &cursorName); | ||
1495 | 62 | |||
1496 | 63 | private: | ||
1497 | 64 | CursorImage *fetchCursor(const QString &cursorThemeAndName); | ||
1498 | 65 | CursorImage *fetchCursor(const QString &themeName, const QString &cursorName); | ||
1499 | 66 | CursorImage *fetchCursorHelper(const QString &themeName, const QString &cursorName); | ||
1500 | 67 | |||
1501 | 68 | // themeName -> (cursorName -> cursorImage) | ||
1502 | 69 | QMap<QString, QMap<QString, CursorImage*> > m_cursors; | ||
1503 | 70 | |||
1504 | 71 | QScopedPointer<CursorImage> m_builtInCursorImage; | ||
1505 | 72 | |||
1506 | 73 | static CursorImageProvider *m_instance; | ||
1507 | 74 | }; | ||
1508 | 75 | |||
1509 | 76 | #endif // CURSORIMAGEPROVIDER_H | ||
1510 | 0 | 77 | ||
1511 | === added file 'plugins/Cursor/MousePointer.cpp' | |||
1512 | --- plugins/Cursor/MousePointer.cpp 1970-01-01 00:00:00 +0000 | |||
1513 | +++ plugins/Cursor/MousePointer.cpp 2015-10-19 14:53:23 +0000 | |||
1514 | @@ -0,0 +1,125 @@ | |||
1515 | 1 | /* | ||
1516 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
1517 | 3 | * | ||
1518 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1519 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1520 | 6 | * the Free Software Foundation. | ||
1521 | 7 | * | ||
1522 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1523 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1524 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1525 | 11 | * Lesser General Public License for more details. | ||
1526 | 12 | * | ||
1527 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1528 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1529 | 15 | */ | ||
1530 | 16 | |||
1531 | 17 | #include "MousePointer.h" | ||
1532 | 18 | #include "CursorImageProvider.h" | ||
1533 | 19 | |||
1534 | 20 | // Unity API | ||
1535 | 21 | #include <unity/shell/application/MirPlatformCursor.h> | ||
1536 | 22 | |||
1537 | 23 | #include <QQuickWindow> | ||
1538 | 24 | #include <QGuiApplication> | ||
1539 | 25 | |||
1540 | 26 | #include <qpa/qwindowsysteminterface.h> | ||
1541 | 27 | |||
1542 | 28 | MousePointer::MousePointer(QQuickItem *parent) | ||
1543 | 29 | : MirMousePointerInterface(parent) | ||
1544 | 30 | , m_cursorName("left_ptr") | ||
1545 | 31 | , m_themeName("default") | ||
1546 | 32 | , m_hotspotX(0) | ||
1547 | 33 | , m_hotspotY(0) | ||
1548 | 34 | { | ||
1549 | 35 | } | ||
1550 | 36 | |||
1551 | 37 | void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::MouseButtons buttons, | ||
1552 | 38 | Qt::KeyboardModifiers modifiers) | ||
1553 | 39 | { | ||
1554 | 40 | if (!parentItem()) { | ||
1555 | 41 | return; | ||
1556 | 42 | } | ||
1557 | 43 | |||
1558 | 44 | qreal newX = x() + movement.x(); | ||
1559 | 45 | if (newX < 0) { | ||
1560 | 46 | newX = 0; | ||
1561 | 47 | } else if (newX > parentItem()->width()) { | ||
1562 | 48 | newX = parentItem()->width(); | ||
1563 | 49 | } | ||
1564 | 50 | setX(newX); | ||
1565 | 51 | |||
1566 | 52 | qreal newY = y() + movement.y(); | ||
1567 | 53 | if (newY < 0) { | ||
1568 | 54 | newY = 0; | ||
1569 | 55 | } else if (newY > parentItem()->height()) { | ||
1570 | 56 | newY = parentItem()->height(); | ||
1571 | 57 | } | ||
1572 | 58 | setY(newY); | ||
1573 | 59 | |||
1574 | 60 | QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0)); | ||
1575 | 61 | QWindowSystemInterface::handleMouseEvent(window(), timestamp, scenePosition /*local*/, scenePosition /*global*/, | ||
1576 | 62 | buttons, modifiers); | ||
1577 | 63 | } | ||
1578 | 64 | |||
1579 | 65 | void MousePointer::itemChange(ItemChange change, const ItemChangeData &value) | ||
1580 | 66 | { | ||
1581 | 67 | if (change == ItemSceneChange) { | ||
1582 | 68 | registerWindow(value.window); | ||
1583 | 69 | } | ||
1584 | 70 | } | ||
1585 | 71 | |||
1586 | 72 | void MousePointer::registerWindow(QWindow *window) | ||
1587 | 73 | { | ||
1588 | 74 | if (m_registeredWindow && window != m_registeredWindow) { | ||
1589 | 75 | auto previousCursor = dynamic_cast<MirPlatformCursor*>(m_registeredWindow->screen()->handle()->cursor()); | ||
1590 | 76 | if (previousCursor) { | ||
1591 | 77 | previousCursor->setMousePointer(nullptr); | ||
1592 | 78 | } else { | ||
1593 | 79 | qCritical("QPlatformCursor is not a MirPlatformCursor! Cursor module only works in a Mir server."); | ||
1594 | 80 | } | ||
1595 | 81 | } | ||
1596 | 82 | |||
1597 | 83 | m_registeredWindow = window; | ||
1598 | 84 | |||
1599 | 85 | if (m_registeredWindow) { | ||
1600 | 86 | auto cursor = dynamic_cast<MirPlatformCursor*>(window->screen()->handle()->cursor()); | ||
1601 | 87 | if (cursor) { | ||
1602 | 88 | cursor->setMousePointer(this); | ||
1603 | 89 | } else { | ||
1604 | 90 | qCritical("QPlaformCursor is not a MirPlatformCursor! Cursor module only works in Mir."); | ||
1605 | 91 | } | ||
1606 | 92 | } | ||
1607 | 93 | } | ||
1608 | 94 | |||
1609 | 95 | void MousePointer::setCursorName(const QString &cursorName) | ||
1610 | 96 | { | ||
1611 | 97 | if (cursorName != m_cursorName) { | ||
1612 | 98 | m_cursorName = cursorName; | ||
1613 | 99 | Q_EMIT cursorNameChanged(m_cursorName); | ||
1614 | 100 | updateHotspot(); | ||
1615 | 101 | } | ||
1616 | 102 | } | ||
1617 | 103 | |||
1618 | 104 | void MousePointer::updateHotspot() | ||
1619 | 105 | { | ||
1620 | 106 | QPoint newHotspot = CursorImageProvider::instance()->hotspot(m_themeName, m_cursorName); | ||
1621 | 107 | |||
1622 | 108 | if (m_hotspotX != newHotspot.x()) { | ||
1623 | 109 | m_hotspotX = newHotspot.x(); | ||
1624 | 110 | Q_EMIT hotspotXChanged(m_hotspotX); | ||
1625 | 111 | } | ||
1626 | 112 | |||
1627 | 113 | if (m_hotspotY != newHotspot.y()) { | ||
1628 | 114 | m_hotspotY = newHotspot.y(); | ||
1629 | 115 | Q_EMIT hotspotYChanged(m_hotspotY); | ||
1630 | 116 | } | ||
1631 | 117 | } | ||
1632 | 118 | |||
1633 | 119 | void MousePointer::setThemeName(const QString &themeName) | ||
1634 | 120 | { | ||
1635 | 121 | if (m_themeName != themeName) { | ||
1636 | 122 | m_themeName = themeName; | ||
1637 | 123 | Q_EMIT themeNameChanged(m_themeName); | ||
1638 | 124 | } | ||
1639 | 125 | } | ||
1640 | 0 | 126 | ||
1641 | === added file 'plugins/Cursor/MousePointer.h' | |||
1642 | --- plugins/Cursor/MousePointer.h 1970-01-01 00:00:00 +0000 | |||
1643 | +++ plugins/Cursor/MousePointer.h 2015-10-19 14:53:23 +0000 | |||
1644 | @@ -0,0 +1,59 @@ | |||
1645 | 1 | /* | ||
1646 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
1647 | 3 | * | ||
1648 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1649 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1650 | 6 | * the Free Software Foundation. | ||
1651 | 7 | * | ||
1652 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1653 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1654 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1655 | 11 | * Lesser General Public License for more details. | ||
1656 | 12 | * | ||
1657 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1658 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1659 | 15 | */ | ||
1660 | 16 | |||
1661 | 17 | #ifndef MOUSEPOINTER_H | ||
1662 | 18 | #define MOUSEPOINTER_H | ||
1663 | 19 | |||
1664 | 20 | // Qt | ||
1665 | 21 | #include <QPointer> | ||
1666 | 22 | #include <QWindow> | ||
1667 | 23 | |||
1668 | 24 | // Unity API | ||
1669 | 25 | #include <unity/shell/application/MirMousePointerInterface.h> | ||
1670 | 26 | |||
1671 | 27 | class MousePointer : public MirMousePointerInterface { | ||
1672 | 28 | Q_OBJECT | ||
1673 | 29 | public: | ||
1674 | 30 | MousePointer(QQuickItem *parent = nullptr); | ||
1675 | 31 | |||
1676 | 32 | void setCursorName(const QString &qtCursorName) override; | ||
1677 | 33 | QString cursorName() const override { return m_cursorName; } | ||
1678 | 34 | |||
1679 | 35 | void setThemeName(const QString &themeName) override; | ||
1680 | 36 | QString themeName() const override { return m_themeName; } | ||
1681 | 37 | |||
1682 | 38 | qreal hotspotX() const override { return m_hotspotX; } | ||
1683 | 39 | qreal hotspotY() const override { return m_hotspotY; } | ||
1684 | 40 | |||
1685 | 41 | public Q_SLOTS: | ||
1686 | 42 | void handleMouseEvent(ulong timestamp, QPointF movement, Qt::MouseButtons buttons, | ||
1687 | 43 | Qt::KeyboardModifiers modifiers) override; | ||
1688 | 44 | |||
1689 | 45 | protected: | ||
1690 | 46 | void itemChange(ItemChange change, const ItemChangeData &value) override; | ||
1691 | 47 | |||
1692 | 48 | private: | ||
1693 | 49 | void registerWindow(QWindow *window); | ||
1694 | 50 | void updateHotspot(); | ||
1695 | 51 | |||
1696 | 52 | QPointer<QWindow> m_registeredWindow; | ||
1697 | 53 | QString m_cursorName; | ||
1698 | 54 | QString m_themeName; | ||
1699 | 55 | int m_hotspotX; | ||
1700 | 56 | int m_hotspotY; | ||
1701 | 57 | }; | ||
1702 | 58 | |||
1703 | 59 | #endif // MOUSEPOINTER_H | ||
1704 | 0 | 60 | ||
1705 | === added file 'plugins/Cursor/plugin.cpp' | |||
1706 | --- plugins/Cursor/plugin.cpp 1970-01-01 00:00:00 +0000 | |||
1707 | +++ plugins/Cursor/plugin.cpp 2015-10-19 14:53:23 +0000 | |||
1708 | @@ -0,0 +1,39 @@ | |||
1709 | 1 | /* | ||
1710 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
1711 | 3 | * | ||
1712 | 4 | * This program is free software; you can redistribute it and/or modify | ||
1713 | 5 | * it under the terms of the GNU General Public License as published by | ||
1714 | 6 | * the Free Software Foundation; version 3. | ||
1715 | 7 | * | ||
1716 | 8 | * This program is distributed in the hope that it will be useful, | ||
1717 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1718 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1719 | 11 | * GNU General Public License for more details. | ||
1720 | 12 | * | ||
1721 | 13 | * You should have received a copy of the GNU General Public License | ||
1722 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1723 | 15 | */ | ||
1724 | 16 | |||
1725 | 17 | // Qt | ||
1726 | 18 | #include <QtQml/qqml.h> | ||
1727 | 19 | #include <QQmlContext> | ||
1728 | 20 | |||
1729 | 21 | // self | ||
1730 | 22 | #include "plugin.h" | ||
1731 | 23 | |||
1732 | 24 | // local | ||
1733 | 25 | #include "CursorImageProvider.h" | ||
1734 | 26 | #include "MousePointer.h" | ||
1735 | 27 | |||
1736 | 28 | void CursorPlugin::registerTypes(const char *uri) | ||
1737 | 29 | { | ||
1738 | 30 | Q_ASSERT(uri == QLatin1String("Cursor")); | ||
1739 | 31 | qmlRegisterType<MousePointer>(uri, 1, 0, "MousePointer"); | ||
1740 | 32 | } | ||
1741 | 33 | |||
1742 | 34 | void CursorPlugin::initializeEngine(QQmlEngine *engine, const char *uri) | ||
1743 | 35 | { | ||
1744 | 36 | QQmlExtensionPlugin::initializeEngine(engine, uri); | ||
1745 | 37 | |||
1746 | 38 | engine->addImageProvider(QLatin1String("cursor"), new CursorImageProvider()); | ||
1747 | 39 | } | ||
1748 | 0 | 40 | ||
1749 | === added file 'plugins/Cursor/plugin.h' | |||
1750 | --- plugins/Cursor/plugin.h 1970-01-01 00:00:00 +0000 | |||
1751 | +++ plugins/Cursor/plugin.h 2015-10-19 14:53:23 +0000 | |||
1752 | @@ -0,0 +1,33 @@ | |||
1753 | 1 | /* | ||
1754 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
1755 | 3 | * | ||
1756 | 4 | * This program is free software; you can redistribute it and/or modify | ||
1757 | 5 | * it under the terms of the GNU General Public License as published by | ||
1758 | 6 | * the Free Software Foundation; version 3. | ||
1759 | 7 | * | ||
1760 | 8 | * This program is distributed in the hope that it will be useful, | ||
1761 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1762 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1763 | 11 | * GNU General Public License for more details. | ||
1764 | 12 | * | ||
1765 | 13 | * You should have received a copy of the GNU General Public License | ||
1766 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1767 | 15 | */ | ||
1768 | 16 | |||
1769 | 17 | #ifndef CURSOR_PLUGIN_H | ||
1770 | 18 | #define CURSOR_PLUGIN_H | ||
1771 | 19 | |||
1772 | 20 | #include <QtQml/QQmlEngine> | ||
1773 | 21 | #include <QtQml/QQmlExtensionPlugin> | ||
1774 | 22 | |||
1775 | 23 | class CursorPlugin : public QQmlExtensionPlugin | ||
1776 | 24 | { | ||
1777 | 25 | Q_OBJECT | ||
1778 | 26 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") | ||
1779 | 27 | |||
1780 | 28 | public: | ||
1781 | 29 | void registerTypes(const char *uri) override; | ||
1782 | 30 | void initializeEngine(QQmlEngine *engine, const char *uri) override; | ||
1783 | 31 | }; | ||
1784 | 32 | |||
1785 | 33 | #endif // CURSOR_PLUGIN_H | ||
1786 | 0 | 34 | ||
1787 | === added file 'plugins/Cursor/qmldir' | |||
1788 | --- plugins/Cursor/qmldir 1970-01-01 00:00:00 +0000 | |||
1789 | +++ plugins/Cursor/qmldir 2015-10-19 14:53:23 +0000 | |||
1790 | @@ -0,0 +1,3 @@ | |||
1791 | 1 | module Cursor | ||
1792 | 2 | plugin Cursor-qml | ||
1793 | 3 | Cursor 1.0 Cursor.qml | ||
1794 | 0 | 4 | ||
1795 | === modified file 'qml/Greeter/Greeter.qml' | |||
1796 | --- qml/Greeter/Greeter.qml 2015-09-02 13:06:56 +0000 | |||
1797 | +++ qml/Greeter/Greeter.qml 2015-10-19 14:53:23 +0000 | |||
1798 | @@ -251,7 +251,7 @@ | |||
1799 | 251 | 251 | ||
1800 | 252 | // event eater | 252 | // event eater |
1801 | 253 | // Nothing should leak to items behind the greeter | 253 | // Nothing should leak to items behind the greeter |
1803 | 254 | MouseArea { anchors.fill: parent } | 254 | MouseArea { anchors.fill: parent; hoverEnabled: true } |
1804 | 255 | 255 | ||
1805 | 256 | Loader { | 256 | Loader { |
1806 | 257 | id: loader | 257 | id: loader |
1807 | 258 | 258 | ||
1808 | === modified file 'qml/Launcher/Launcher.qml' | |||
1809 | --- qml/Launcher/Launcher.qml 2015-09-02 14:18:40 +0000 | |||
1810 | +++ qml/Launcher/Launcher.qml 2015-10-19 14:53:23 +0000 | |||
1811 | @@ -188,6 +188,7 @@ | |||
1812 | 188 | bottom: parent.bottom | 188 | bottom: parent.bottom |
1813 | 189 | } | 189 | } |
1814 | 190 | enabled: root.shadeBackground && root.state == "visible" | 190 | enabled: root.shadeBackground && root.state == "visible" |
1815 | 191 | visible: enabled // otherwise it will get in the way of cursor selection for some reason | ||
1816 | 191 | onPressed: { | 192 | onPressed: { |
1817 | 192 | root.state = "" | 193 | root.state = "" |
1818 | 193 | } | 194 | } |
1819 | 194 | 195 | ||
1820 | === modified file 'qml/Panel/Panel.qml' | |||
1821 | --- qml/Panel/Panel.qml 2015-06-29 03:58:22 +0000 | |||
1822 | +++ qml/Panel/Panel.qml 2015-10-19 14:53:23 +0000 | |||
1823 | @@ -48,6 +48,7 @@ | |||
1824 | 48 | MouseArea { | 48 | MouseArea { |
1825 | 49 | anchors.fill: parent | 49 | anchors.fill: parent |
1826 | 50 | onClicked: if (indicators.fullyOpened) indicators.hide(); | 50 | onClicked: if (indicators.fullyOpened) indicators.hide(); |
1827 | 51 | hoverEnabled: true // should also eat hover events, otherwise they will pass through | ||
1828 | 51 | } | 52 | } |
1829 | 52 | } | 53 | } |
1830 | 53 | 54 | ||
1831 | 54 | 55 | ||
1832 | === modified file 'qml/Shell.qml' | |||
1833 | --- qml/Shell.qml 2015-09-22 14:23:44 +0000 | |||
1834 | +++ qml/Shell.qml 2015-10-19 14:53:23 +0000 | |||
1835 | @@ -41,6 +41,7 @@ | |||
1836 | 41 | import Unity.Session 0.1 | 41 | import Unity.Session 0.1 |
1837 | 42 | import Unity.DashCommunicator 0.1 | 42 | import Unity.DashCommunicator 0.1 |
1838 | 43 | import Unity.Indicators 0.1 as Indicators | 43 | import Unity.Indicators 0.1 as Indicators |
1839 | 44 | import Cursor 1.0 | ||
1840 | 44 | 45 | ||
1841 | 45 | 46 | ||
1842 | 46 | Item { | 47 | Item { |
1843 | @@ -63,7 +64,7 @@ | |||
1844 | 63 | function updateFocusedAppOrientationAnimated() { | 64 | function updateFocusedAppOrientationAnimated() { |
1845 | 64 | applicationsDisplayLoader.item.updateFocusedAppOrientationAnimated(); | 65 | applicationsDisplayLoader.item.updateFocusedAppOrientationAnimated(); |
1846 | 65 | } | 66 | } |
1848 | 66 | property bool hasMouse | 67 | property bool hasMouse: false |
1849 | 67 | 68 | ||
1850 | 68 | // to be read from outside | 69 | // to be read from outside |
1851 | 69 | readonly property int mainAppWindowOrientationAngle: | 70 | readonly property int mainAppWindowOrientationAngle: |
1852 | @@ -190,11 +191,6 @@ | |||
1853 | 190 | onScreenshotTriggered: screenGrabber.capture(); | 191 | onScreenshotTriggered: screenGrabber.capture(); |
1854 | 191 | } | 192 | } |
1855 | 192 | 193 | ||
1856 | 193 | ScreenGrabber { | ||
1857 | 194 | id: screenGrabber | ||
1858 | 195 | z: dialogs.z + 10 | ||
1859 | 196 | } | ||
1860 | 197 | |||
1861 | 198 | GlobalShortcut { | 194 | GlobalShortcut { |
1862 | 199 | // dummy shortcut to force creation of GlobalShortcutRegistry before WindowKeyFilter | 195 | // dummy shortcut to force creation of GlobalShortcutRegistry before WindowKeyFilter |
1863 | 200 | } | 196 | } |
1864 | @@ -684,9 +680,20 @@ | |||
1865 | 684 | onShowHome: showHome() | 680 | onShowHome: showHome() |
1866 | 685 | } | 681 | } |
1867 | 686 | 682 | ||
1868 | 683 | ScreenGrabber { | ||
1869 | 684 | id: screenGrabber | ||
1870 | 685 | z: dialogs.z + 10 | ||
1871 | 686 | } | ||
1872 | 687 | |||
1873 | 688 | Cursor { | ||
1874 | 689 | id: cursor | ||
1875 | 690 | visible: shell.hasMouse | ||
1876 | 691 | z: screenGrabber.z + 1 | ||
1877 | 692 | } | ||
1878 | 693 | |||
1879 | 687 | Rectangle { | 694 | Rectangle { |
1880 | 688 | id: shutdownFadeOutRectangle | 695 | id: shutdownFadeOutRectangle |
1882 | 689 | z: screenGrabber.z + 10 | 696 | z: cursor.z + 1 |
1883 | 690 | enabled: false | 697 | enabled: false |
1884 | 691 | visible: false | 698 | visible: false |
1885 | 692 | color: "black" | 699 | color: "black" |
1886 | 693 | 700 | ||
1887 | === modified file 'qml/Stages/DecoratedWindow.qml' | |||
1888 | --- qml/Stages/DecoratedWindow.qml 2015-09-08 10:32:28 +0000 | |||
1889 | +++ qml/Stages/DecoratedWindow.qml 2015-10-19 14:53:23 +0000 | |||
1890 | @@ -31,9 +31,10 @@ | |||
1891 | 31 | property bool highlightShown: false | 31 | property bool highlightShown: false |
1892 | 32 | property real shadowOpacity: 1 | 32 | property real shadowOpacity: 1 |
1893 | 33 | 33 | ||
1897 | 34 | signal close(); | 34 | signal close() |
1898 | 35 | signal maximize(); | 35 | signal maximize() |
1899 | 36 | signal minimize(); | 36 | signal minimize() |
1900 | 37 | signal decorationPressed() | ||
1901 | 37 | 38 | ||
1902 | 38 | BorderImage { | 39 | BorderImage { |
1903 | 39 | anchors { | 40 | anchors { |
1904 | @@ -61,6 +62,7 @@ | |||
1905 | 61 | 62 | ||
1906 | 62 | WindowDecoration { | 63 | WindowDecoration { |
1907 | 63 | id: decoration | 64 | id: decoration |
1908 | 65 | target: root.parent | ||
1909 | 64 | objectName: application ? "appWindowDecoration_" + application.appId : "appWindowDecoration_null" | 66 | objectName: application ? "appWindowDecoration_" + application.appId : "appWindowDecoration_null" |
1910 | 65 | anchors { left: parent.left; top: parent.top; right: parent.right } | 67 | anchors { left: parent.left; top: parent.top; right: parent.right } |
1911 | 66 | height: units.gu(3) | 68 | height: units.gu(3) |
1912 | @@ -68,6 +70,7 @@ | |||
1913 | 68 | onClose: root.close(); | 70 | onClose: root.close(); |
1914 | 69 | onMaximize: root.maximize(); | 71 | onMaximize: root.maximize(); |
1915 | 70 | onMinimize: root.minimize(); | 72 | onMinimize: root.minimize(); |
1916 | 73 | onPressed: root.decorationPressed(); | ||
1917 | 71 | visible: decorationShown | 74 | visible: decorationShown |
1918 | 72 | } | 75 | } |
1919 | 73 | 76 | ||
1920 | 74 | 77 | ||
1921 | === modified file 'qml/Stages/DesktopStage.qml' | |||
1922 | --- qml/Stages/DesktopStage.qml 2015-09-18 15:28:07 +0000 | |||
1923 | +++ qml/Stages/DesktopStage.qml 2015-10-19 14:53:23 +0000 | |||
1924 | @@ -86,6 +86,11 @@ | |||
1925 | 86 | var index = indexOf(focusedAppId); | 86 | var index = indexOf(focusedAppId); |
1926 | 87 | return index >= 0 && index < appRepeater.count ? appRepeater.itemAt(index) : null | 87 | return index >= 0 && index < appRepeater.count ? appRepeater.itemAt(index) : null |
1927 | 88 | } | 88 | } |
1928 | 89 | onFocusedAppDelegateChanged: { // restore the window from minimization when we focus it (e.g. using spread) | ||
1929 | 90 | if (priv.focusedAppDelegate && priv.focusedAppDelegate.minimized) { | ||
1930 | 91 | priv.focusedAppDelegate.unmaximize() | ||
1931 | 92 | } | ||
1932 | 93 | } | ||
1933 | 89 | 94 | ||
1934 | 90 | function indexOf(appId) { | 95 | function indexOf(appId) { |
1935 | 91 | for (var i = 0; i < ApplicationManager.count; i++) { | 96 | for (var i = 0; i < ApplicationManager.count; i++) { |
1936 | @@ -138,9 +143,6 @@ | |||
1937 | 138 | height: units.gu(50) | 143 | height: units.gu(50) |
1938 | 139 | focus: model.appId === priv.focusedAppId | 144 | focus: model.appId === priv.focusedAppId |
1939 | 140 | 145 | ||
1940 | 141 | readonly property int minWidth: units.gu(10) | ||
1941 | 142 | readonly property int minHeight: units.gu(10) | ||
1942 | 143 | |||
1943 | 144 | property bool maximized: false | 146 | property bool maximized: false |
1944 | 145 | property bool minimized: false | 147 | property bool minimized: false |
1945 | 146 | 148 | ||
1946 | @@ -215,15 +217,12 @@ | |||
1947 | 215 | when: index == spread.highlightedIndex && blurLayer.ready | 217 | when: index == spread.highlightedIndex && blurLayer.ready |
1948 | 216 | } | 218 | } |
1949 | 217 | 219 | ||
1952 | 218 | WindowMoveResizeArea { | 220 | WindowResizeArea { |
1951 | 219 | id: windowMoveResizeArea | ||
1953 | 220 | target: appDelegate | 221 | target: appDelegate |
1957 | 221 | minWidth: appDelegate.minWidth | 222 | minWidth: units.gu(10) |
1958 | 222 | minHeight: appDelegate.minHeight | 223 | minHeight: units.gu(10) |
1959 | 223 | resizeHandleWidth: units.gu(2) | 224 | borderThickness: units.gu(2) |
1960 | 224 | windowId: model.appId // FIXME: Change this to point to windowId once we have such a thing | 225 | windowId: model.appId // FIXME: Change this to point to windowId once we have such a thing |
1961 | 225 | |||
1962 | 226 | onPressed: { ApplicationManager.focusApplication(model.appId) } | ||
1963 | 227 | } | 226 | } |
1964 | 228 | 227 | ||
1965 | 229 | DecoratedWindow { | 228 | DecoratedWindow { |
1966 | @@ -240,6 +239,7 @@ | |||
1967 | 240 | onClose: ApplicationManager.stopApplication(model.appId) | 239 | onClose: ApplicationManager.stopApplication(model.appId) |
1968 | 241 | onMaximize: appDelegate.maximize() | 240 | onMaximize: appDelegate.maximize() |
1969 | 242 | onMinimize: appDelegate.minimize() | 241 | onMinimize: appDelegate.minimize() |
1970 | 242 | onDecorationPressed: ApplicationManager.focusApplication(model.appId) | ||
1971 | 243 | } | 243 | } |
1972 | 244 | } | 244 | } |
1973 | 245 | } | 245 | } |
1974 | 246 | 246 | ||
1975 | === modified file 'qml/Stages/WindowDecoration.qml' | |||
1976 | --- qml/Stages/WindowDecoration.qml 2015-03-13 19:18:35 +0000 | |||
1977 | +++ qml/Stages/WindowDecoration.qml 2015-10-19 14:53:23 +0000 | |||
1978 | @@ -1,5 +1,5 @@ | |||
1979 | 1 | /* | 1 | /* |
1981 | 2 | * Copyright (C) 2014 Canonical, Ltd. | 2 | * Copyright (C) 2014-2015 Canonical, Ltd. |
1982 | 3 | * | 3 | * |
1983 | 4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
1984 | 5 | * it under the terms of the GNU General Public License as published by | 5 | * it under the terms of the GNU General Public License as published by |
1985 | @@ -12,25 +12,54 @@ | |||
1986 | 12 | * | 12 | * |
1987 | 13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
1988 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1989 | 15 | * | ||
1990 | 16 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
1991 | 17 | */ | 15 | */ |
1992 | 18 | 16 | ||
1993 | 19 | import QtQuick 2.3 | 17 | import QtQuick 2.3 |
1994 | 18 | import Unity.Application 0.1 // For Mir singleton | ||
1995 | 20 | import Ubuntu.Components 1.1 | 19 | import Ubuntu.Components 1.1 |
1996 | 21 | import "../Components" | 20 | import "../Components" |
1997 | 22 | 21 | ||
1999 | 23 | Item { | 22 | MouseArea { |
2000 | 24 | id: root | 23 | id: root |
2001 | 25 | clip: true | 24 | clip: true |
2002 | 26 | 25 | ||
2003 | 26 | property Item target | ||
2004 | 27 | property alias title: titleLabel.text | 27 | property alias title: titleLabel.text |
2005 | 28 | property bool active: false | 28 | property bool active: false |
2006 | 29 | hoverEnabled: true | ||
2007 | 29 | 30 | ||
2008 | 30 | signal close() | 31 | signal close() |
2009 | 31 | signal minimize() | 32 | signal minimize() |
2010 | 32 | signal maximize() | 33 | signal maximize() |
2011 | 33 | 34 | ||
2012 | 35 | QtObject { | ||
2013 | 36 | id: priv | ||
2014 | 37 | property real distanceX | ||
2015 | 38 | property real distanceY | ||
2016 | 39 | property bool dragging | ||
2017 | 40 | } | ||
2018 | 41 | |||
2019 | 42 | onPressedChanged: { | ||
2020 | 43 | if (pressed) { | ||
2021 | 44 | var pos = mapToItem(root.target, mouseX, mouseY); | ||
2022 | 45 | priv.distanceX = pos.x; | ||
2023 | 46 | priv.distanceY = pos.y; | ||
2024 | 47 | priv.dragging = true; | ||
2025 | 48 | } else { | ||
2026 | 49 | priv.dragging = false; | ||
2027 | 50 | Mir.cursorName = ""; | ||
2028 | 51 | } | ||
2029 | 52 | } | ||
2030 | 53 | |||
2031 | 54 | onPositionChanged: { | ||
2032 | 55 | if (priv.dragging) { | ||
2033 | 56 | Mir.cursorName = "grabbing"; | ||
2034 | 57 | var pos = mapToItem(root.target.parent, mouseX, mouseY); | ||
2035 | 58 | root.target.x = pos.x - priv.distanceX; | ||
2036 | 59 | root.target.y = pos.y - priv.distanceY; | ||
2037 | 60 | } | ||
2038 | 61 | } | ||
2039 | 62 | |||
2040 | 34 | Rectangle { | 63 | Rectangle { |
2041 | 35 | anchors.fill: parent | 64 | anchors.fill: parent |
2042 | 36 | anchors.bottomMargin: -radius | 65 | anchors.bottomMargin: -radius |
2043 | 37 | 66 | ||
2044 | === renamed file 'qml/Stages/WindowMoveResizeArea.qml' => 'qml/Stages/WindowResizeArea.qml' | |||
2045 | --- qml/Stages/WindowMoveResizeArea.qml 2015-09-08 10:32:28 +0000 | |||
2046 | +++ qml/Stages/WindowResizeArea.qml 2015-10-19 14:53:23 +0000 | |||
2047 | @@ -12,18 +12,19 @@ | |||
2048 | 12 | * | 12 | * |
2049 | 13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
2050 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2051 | 15 | * | ||
2052 | 16 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
2053 | 17 | */ | 15 | */ |
2054 | 18 | 16 | ||
2055 | 19 | import QtQuick 2.3 | 17 | import QtQuick 2.3 |
2056 | 20 | import Ubuntu.Components 1.1 | 18 | import Ubuntu.Components 1.1 |
2057 | 21 | import Utils 0.1 | 19 | import Utils 0.1 |
2058 | 20 | import Unity.Application 0.1 // for Mir.cursorName | ||
2059 | 22 | 21 | ||
2060 | 23 | MouseArea { | 22 | MouseArea { |
2061 | 24 | id: root | 23 | id: root |
2062 | 25 | anchors.fill: target | 24 | anchors.fill: target |
2064 | 26 | anchors.margins: -resizeHandleWidth | 25 | anchors.margins: -borderThickness |
2065 | 26 | |||
2066 | 27 | hoverEnabled: true | ||
2067 | 27 | 28 | ||
2068 | 28 | property var windowStateStorage: WindowStateStorage | 29 | property var windowStateStorage: WindowStateStorage |
2069 | 29 | 30 | ||
2070 | @@ -31,24 +32,10 @@ | |||
2071 | 31 | // The area will anchor to it and manage move and resize events | 32 | // The area will anchor to it and manage move and resize events |
2072 | 32 | property Item target: null | 33 | property Item target: null |
2073 | 33 | property string windowId: "" | 34 | property string windowId: "" |
2075 | 34 | property int resizeHandleWidth: 0 | 35 | property int borderThickness: 0 |
2076 | 35 | property int minWidth: 0 | 36 | property int minWidth: 0 |
2077 | 36 | property int minHeight: 0 | 37 | property int minHeight: 0 |
2078 | 37 | 38 | ||
2079 | 38 | QtObject { | ||
2080 | 39 | id: priv | ||
2081 | 40 | readonly property int windowWidth: root.width - root.resizeHandleWidth * 2 | ||
2082 | 41 | readonly property int windowHeight: root.height - resizeHandleWidth * 2 | ||
2083 | 42 | |||
2084 | 43 | property var startPoint | ||
2085 | 44 | |||
2086 | 45 | property bool resizeTop: false | ||
2087 | 46 | property bool resizeBottom: false | ||
2088 | 47 | property bool resizeLeft: false | ||
2089 | 48 | property bool resizeRight: false | ||
2090 | 49 | |||
2091 | 50 | } | ||
2092 | 51 | |||
2093 | 52 | Component.onCompleted: { | 39 | Component.onCompleted: { |
2094 | 53 | var windowState = windowStateStorage.getGeometry(root.windowId, Qt.rect(target.x, target.y, target.width, target.height)) | 40 | var windowState = windowStateStorage.getGeometry(root.windowId, Qt.rect(target.x, target.y, target.width, target.height)) |
2095 | 54 | if (windowState !== undefined) { | 41 | if (windowState !== undefined) { |
2096 | @@ -59,51 +46,137 @@ | |||
2097 | 59 | } | 46 | } |
2098 | 60 | } | 47 | } |
2099 | 61 | 48 | ||
2100 | 62 | onPressed: { | ||
2101 | 63 | priv.startPoint = Qt.point(mouse.x, mouse.y); | ||
2102 | 64 | priv.resizeTop = mouseY < root.resizeHandleWidth; | ||
2103 | 65 | priv.resizeBottom = mouseY > (root.height - root.resizeHandleWidth); | ||
2104 | 66 | priv.resizeLeft = mouseX < root.resizeHandleWidth; | ||
2105 | 67 | priv.resizeRight = mouseX > (root.width - root.resizeHandleWidth); | ||
2106 | 68 | } | ||
2107 | 69 | |||
2108 | 70 | onPositionChanged: { | ||
2109 | 71 | var currentPoint = Qt.point(mouse.x, mouse.y); | ||
2110 | 72 | var mouseDiff = Qt.point(currentPoint.x - priv.startPoint.x, currentPoint.y - priv.startPoint.y); | ||
2111 | 73 | var moveDiff = Qt.point(0, 0); | ||
2112 | 74 | var sizeDiff = Qt.point(0, 0); | ||
2113 | 75 | var maxSizeDiff = Qt.point(root.minWidth - root.target.width, root.minHeight - root.target.height) | ||
2114 | 76 | |||
2115 | 77 | if (priv.resizeTop || priv.resizeBottom || priv.resizeLeft || priv.resizeRight) { | ||
2116 | 78 | if (priv.resizeTop) { | ||
2117 | 79 | sizeDiff.y = Math.max(maxSizeDiff.y, -currentPoint.y + priv.startPoint.y) | ||
2118 | 80 | moveDiff.y = -sizeDiff.y | ||
2119 | 81 | } | ||
2120 | 82 | if (priv.resizeBottom) { | ||
2121 | 83 | sizeDiff.y = Math.max(maxSizeDiff.y, currentPoint.y - priv.startPoint.y) | ||
2122 | 84 | priv.startPoint.y += sizeDiff.y | ||
2123 | 85 | } | ||
2124 | 86 | if (priv.resizeLeft) { | ||
2125 | 87 | sizeDiff.x = Math.max(maxSizeDiff.x, -currentPoint.x + priv.startPoint.x) | ||
2126 | 88 | moveDiff.x = -sizeDiff.x | ||
2127 | 89 | } | ||
2128 | 90 | if (priv.resizeRight) { | ||
2129 | 91 | sizeDiff.x = Math.max(maxSizeDiff.x, currentPoint.x - priv.startPoint.x) | ||
2130 | 92 | priv.startPoint.x += sizeDiff.x | ||
2131 | 93 | } | ||
2132 | 94 | |||
2133 | 95 | target.x += moveDiff.x; | ||
2134 | 96 | target.y += moveDiff.y; | ||
2135 | 97 | target.width += sizeDiff.x; | ||
2136 | 98 | target.height += sizeDiff.y; | ||
2137 | 99 | } else { | ||
2138 | 100 | target.x += mouseDiff.x; | ||
2139 | 101 | target.y += mouseDiff.y; | ||
2140 | 102 | } | ||
2141 | 103 | |||
2142 | 104 | } | ||
2143 | 105 | |||
2144 | 106 | Component.onDestruction: { | 49 | Component.onDestruction: { |
2145 | 107 | windowStateStorage.saveGeometry(root.windowId, Qt.rect(target.x, target.y, target.width, target.height)) | 50 | windowStateStorage.saveGeometry(root.windowId, Qt.rect(target.x, target.y, target.width, target.height)) |
2146 | 108 | } | 51 | } |
2147 | 52 | |||
2148 | 53 | QtObject { | ||
2149 | 54 | id: d | ||
2150 | 55 | property bool leftBorder: false | ||
2151 | 56 | property bool rightBorder: false | ||
2152 | 57 | property bool topBorder: false | ||
2153 | 58 | property bool bottomBorder: false | ||
2154 | 59 | |||
2155 | 60 | property bool dragging: false | ||
2156 | 61 | property real startMousePosX | ||
2157 | 62 | property real startMousePosY | ||
2158 | 63 | property real startX | ||
2159 | 64 | property real startY | ||
2160 | 65 | property real startWidth | ||
2161 | 66 | property real startHeight | ||
2162 | 67 | |||
2163 | 68 | property string cursorName: { | ||
2164 | 69 | if (root.containsMouse || root.pressed) { | ||
2165 | 70 | if (leftBorder && !topBorder && !bottomBorder) { | ||
2166 | 71 | return "left_side"; | ||
2167 | 72 | } else if (rightBorder && !topBorder && !bottomBorder) { | ||
2168 | 73 | return "right_side"; | ||
2169 | 74 | } else if (topBorder && !leftBorder && !rightBorder) { | ||
2170 | 75 | return "top_side"; | ||
2171 | 76 | } else if (bottomBorder && !leftBorder && !rightBorder) { | ||
2172 | 77 | return "bottom_side"; | ||
2173 | 78 | } else if (leftBorder && topBorder) { | ||
2174 | 79 | return "top_left_corner"; | ||
2175 | 80 | } else if (leftBorder && bottomBorder) { | ||
2176 | 81 | return "bottom_left_corner"; | ||
2177 | 82 | } else if (rightBorder && topBorder) { | ||
2178 | 83 | return "top_right_corner"; | ||
2179 | 84 | } else if (rightBorder && bottomBorder) { | ||
2180 | 85 | return "bottom_right_corner"; | ||
2181 | 86 | } else { | ||
2182 | 87 | return ""; | ||
2183 | 88 | } | ||
2184 | 89 | } else { | ||
2185 | 90 | return ""; | ||
2186 | 91 | } | ||
2187 | 92 | } | ||
2188 | 93 | onCursorNameChanged: { | ||
2189 | 94 | Mir.cursorName = cursorName; | ||
2190 | 95 | } | ||
2191 | 96 | |||
2192 | 97 | function updateBorders() { | ||
2193 | 98 | leftBorder = mouseX <= borderThickness; | ||
2194 | 99 | rightBorder = mouseX >= width - borderThickness; | ||
2195 | 100 | topBorder = mouseY <= borderThickness; | ||
2196 | 101 | bottomBorder = mouseY >= height - borderThickness; | ||
2197 | 102 | } | ||
2198 | 103 | } | ||
2199 | 104 | |||
2200 | 105 | onPressedChanged: { | ||
2201 | 106 | var pos = mapToItem(target.parent, mouseX, mouseY); | ||
2202 | 107 | |||
2203 | 108 | if (pressed) { | ||
2204 | 109 | d.updateBorders(); | ||
2205 | 110 | var pos = mapToItem(root.target.parent, mouseX, mouseY); | ||
2206 | 111 | d.startMousePosX = pos.x; | ||
2207 | 112 | d.startMousePosY = pos.y; | ||
2208 | 113 | d.startX = target.x; | ||
2209 | 114 | d.startY = target.y; | ||
2210 | 115 | d.startWidth = target.width; | ||
2211 | 116 | d.startHeight = target.height; | ||
2212 | 117 | d.dragging = true; | ||
2213 | 118 | } else { | ||
2214 | 119 | d.dragging = false; | ||
2215 | 120 | if (containsMouse) { | ||
2216 | 121 | d.updateBorders(); | ||
2217 | 122 | } | ||
2218 | 123 | } | ||
2219 | 124 | } | ||
2220 | 125 | |||
2221 | 126 | onEntered: { | ||
2222 | 127 | if (!pressed) { | ||
2223 | 128 | d.updateBorders(); | ||
2224 | 129 | } | ||
2225 | 130 | } | ||
2226 | 131 | |||
2227 | 132 | onPositionChanged: { | ||
2228 | 133 | if (!pressed) { | ||
2229 | 134 | d.updateBorders(); | ||
2230 | 135 | } | ||
2231 | 136 | |||
2232 | 137 | if (!d.dragging) { | ||
2233 | 138 | return; | ||
2234 | 139 | } | ||
2235 | 140 | |||
2236 | 141 | var pos = mapToItem(target.parent, mouse.x, mouse.y); | ||
2237 | 142 | |||
2238 | 143 | var deltaX = pos.x - d.startMousePosX; | ||
2239 | 144 | var deltaY = pos.y - d.startMousePosY; | ||
2240 | 145 | |||
2241 | 146 | if (d.leftBorder) { | ||
2242 | 147 | var newTargetX = d.startX + deltaX; | ||
2243 | 148 | if (target.x + target.width > newTargetX + minWidth) { | ||
2244 | 149 | target.width = target.x + target.width - newTargetX; | ||
2245 | 150 | target.x = newTargetX; | ||
2246 | 151 | } else { | ||
2247 | 152 | target.x = target.x + target.width - minWidth; | ||
2248 | 153 | target.width = minWidth; | ||
2249 | 154 | } | ||
2250 | 155 | |||
2251 | 156 | } else if (d.rightBorder) { | ||
2252 | 157 | if (d.startWidth + deltaX >= minWidth) { | ||
2253 | 158 | target.width = d.startWidth + deltaX; | ||
2254 | 159 | } else { | ||
2255 | 160 | target.width = minWidth; | ||
2256 | 161 | } | ||
2257 | 162 | } | ||
2258 | 163 | |||
2259 | 164 | if (d.topBorder) { | ||
2260 | 165 | var newTargetY = d.startY + deltaY; | ||
2261 | 166 | if (target.y + target.height > newTargetY + minHeight) { | ||
2262 | 167 | target.height = target.y + target.height - newTargetY; | ||
2263 | 168 | target.y = newTargetY; | ||
2264 | 169 | } else { | ||
2265 | 170 | target.y = target.y + target.height - minHeight; | ||
2266 | 171 | target.height = minHeight; | ||
2267 | 172 | } | ||
2268 | 173 | |||
2269 | 174 | } else if (d.bottomBorder) { | ||
2270 | 175 | if (d.startHeight + deltaY >= minHeight) { | ||
2271 | 176 | target.height = d.startHeight + deltaY; | ||
2272 | 177 | } else { | ||
2273 | 178 | target.height = minHeight; | ||
2274 | 179 | } | ||
2275 | 180 | } | ||
2276 | 181 | } | ||
2277 | 109 | } | 182 | } |
2278 | 110 | 183 | ||
2279 | === modified file 'tests/mocks/CMakeLists.txt' | |||
2280 | --- tests/mocks/CMakeLists.txt 2015-08-06 22:45:56 +0000 | |||
2281 | +++ tests/mocks/CMakeLists.txt 2015-10-19 14:53:23 +0000 | |||
2282 | @@ -29,6 +29,7 @@ | |||
2283 | 29 | endmacro() | 29 | endmacro() |
2284 | 30 | 30 | ||
2285 | 31 | add_subdirectory(AccountsService) | 31 | add_subdirectory(AccountsService) |
2286 | 32 | add_subdirectory(Cursor) | ||
2287 | 32 | add_subdirectory(GSettings.1.0) | 33 | add_subdirectory(GSettings.1.0) |
2288 | 33 | add_subdirectory(indicator-service) | 34 | add_subdirectory(indicator-service) |
2289 | 34 | add_subdirectory(libusermetrics) | 35 | add_subdirectory(libusermetrics) |
2290 | 35 | 36 | ||
2291 | === added directory 'tests/mocks/Cursor' | |||
2292 | === added file 'tests/mocks/Cursor/CMakeLists.txt' | |||
2293 | --- tests/mocks/Cursor/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
2294 | +++ tests/mocks/Cursor/CMakeLists.txt 2015-10-19 14:53:23 +0000 | |||
2295 | @@ -0,0 +1,1 @@ | |||
2296 | 1 | add_unity8_mock(Cursor 1.0 Cursor PREFIX mocks) | ||
2297 | 0 | 2 | ||
2298 | === added file 'tests/mocks/Cursor/Cursor.qml' | |||
2299 | --- tests/mocks/Cursor/Cursor.qml 1970-01-01 00:00:00 +0000 | |||
2300 | +++ tests/mocks/Cursor/Cursor.qml 2015-10-19 14:53:23 +0000 | |||
2301 | @@ -0,0 +1,20 @@ | |||
2302 | 1 | /* | ||
2303 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
2304 | 3 | * | ||
2305 | 4 | * This program is free software; you can redistribute it and/or modify | ||
2306 | 5 | * it under the terms of the GNU General Public License as published by | ||
2307 | 6 | * the Free Software Foundation; version 3. | ||
2308 | 7 | * | ||
2309 | 8 | * This program is distributed in the hope that it will be useful, | ||
2310 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2311 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2312 | 11 | * GNU General Public License for more details. | ||
2313 | 12 | * | ||
2314 | 13 | * You should have received a copy of the GNU General Public License | ||
2315 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2316 | 15 | */ | ||
2317 | 16 | |||
2318 | 17 | import QtQuick 2.4 | ||
2319 | 18 | |||
2320 | 19 | Item { | ||
2321 | 20 | } | ||
2322 | 0 | 21 | ||
2323 | === added file 'tests/mocks/Cursor/qmldir' | |||
2324 | --- tests/mocks/Cursor/qmldir 1970-01-01 00:00:00 +0000 | |||
2325 | +++ tests/mocks/Cursor/qmldir 2015-10-19 14:53:23 +0000 | |||
2326 | @@ -0,0 +1,2 @@ | |||
2327 | 1 | module Cursor | ||
2328 | 2 | Cursor 1.0 Cursor.qml | ||
2329 | 0 | 3 | ||
2330 | === modified file 'tests/qmltests/CMakeLists.txt' | |||
2331 | --- tests/qmltests/CMakeLists.txt 2015-09-19 07:37:52 +0000 | |||
2332 | +++ tests/qmltests/CMakeLists.txt 2015-10-19 14:53:23 +0000 | |||
2333 | @@ -78,7 +78,7 @@ | |||
2334 | 78 | add_unity8_qmltest(Stages SurfaceContainer) | 78 | add_unity8_qmltest(Stages SurfaceContainer) |
2335 | 79 | add_unity8_qmltest(Stages SessionContainer) | 79 | add_unity8_qmltest(Stages SessionContainer) |
2336 | 80 | add_unity8_qmltest(Stages TabletStage) | 80 | add_unity8_qmltest(Stages TabletStage) |
2338 | 81 | add_unity8_qmltest(Stages WindowMoveResizeArea) | 81 | add_unity8_qmltest(Stages WindowResizeArea) |
2339 | 82 | add_unity8_qmltest(Stages Splash) | 82 | add_unity8_qmltest(Stages Splash) |
2340 | 83 | add_unity8_qmltest(Tutorial Tutorial LIGHTDM) | 83 | add_unity8_qmltest(Tutorial Tutorial LIGHTDM) |
2341 | 84 | add_unity8_qmltest(Wizard Wizard ENVIRONMENT "OXIDE_NO_SANDBOX=1") | 84 | add_unity8_qmltest(Wizard Wizard ENVIRONMENT "OXIDE_NO_SANDBOX=1") |
2342 | 85 | 85 | ||
2343 | === renamed file 'tests/qmltests/Stages/tst_WindowMoveResizeArea.qml' => 'tests/qmltests/Stages/tst_WindowResizeArea.qml' | |||
2344 | --- tests/qmltests/Stages/tst_WindowMoveResizeArea.qml 2015-09-07 13:45:50 +0000 | |||
2345 | +++ tests/qmltests/Stages/tst_WindowResizeArea.qml 2015-10-19 14:53:23 +0000 | |||
2346 | @@ -17,7 +17,7 @@ | |||
2347 | 17 | import QtQuick 2.1 | 17 | import QtQuick 2.1 |
2348 | 18 | import QtQuick.Layouts 1.1 | 18 | import QtQuick.Layouts 1.1 |
2349 | 19 | import QtTest 1.0 | 19 | import QtTest 1.0 |
2351 | 20 | import Unity.Test 0.1 as UT | 20 | import Unity.Test 0.1 |
2352 | 21 | import ".." | 21 | import ".." |
2353 | 22 | import "../../../qml/Stages" | 22 | import "../../../qml/Stages" |
2354 | 23 | import Ubuntu.Components 0.1 | 23 | import Ubuntu.Components 0.1 |
2355 | @@ -36,8 +36,8 @@ | |||
2356 | 36 | 36 | ||
2357 | 37 | Item { | 37 | Item { |
2358 | 38 | id: fakeWindow | 38 | id: fakeWindow |
2361 | 39 | property alias minWidth: moveResizeArea.minWidth | 39 | property alias minWidth: windowResizeArea.minWidth |
2362 | 40 | property alias minHeight: moveResizeArea.minHeight | 40 | property alias minHeight: windowResizeArea.minHeight |
2363 | 41 | x: units.gu(20) | 41 | x: units.gu(20) |
2364 | 42 | y: units.gu(20) | 42 | y: units.gu(20) |
2365 | 43 | height: units.gu(20) | 43 | height: units.gu(20) |
2366 | @@ -47,23 +47,27 @@ | |||
2367 | 47 | onWindowHeightChanged: height = windowHeight | 47 | onWindowHeightChanged: height = windowHeight |
2368 | 48 | onWindowWidthChanged: width = windowWidth | 48 | onWindowWidthChanged: width = windowWidth |
2369 | 49 | 49 | ||
2372 | 50 | WindowMoveResizeArea { | 50 | WindowResizeArea { |
2373 | 51 | id: moveResizeArea | 51 | id: windowResizeArea |
2374 | 52 | target: fakeWindow | 52 | target: fakeWindow |
2376 | 53 | resizeHandleWidth: units.gu(0.5) | 53 | borderThickness: units.gu(2) |
2377 | 54 | minWidth: units.gu(15) | 54 | minWidth: units.gu(15) |
2378 | 55 | minHeight: units.gu(10) | 55 | minHeight: units.gu(10) |
2379 | 56 | windowId: "test-window-id" | 56 | windowId: "test-window-id" |
2380 | 57 | } | 57 | } |
2381 | 58 | 58 | ||
2382 | 59 | Rectangle { | 59 | Rectangle { |
2384 | 60 | anchors.fill: moveResizeArea | 60 | anchors.fill: windowResizeArea |
2385 | 61 | color: "red" | 61 | color: "red" |
2386 | 62 | } | 62 | } |
2387 | 63 | 63 | ||
2388 | 64 | Rectangle { | 64 | Rectangle { |
2389 | 65 | anchors.fill: fakeWindow | 65 | anchors.fill: fakeWindow |
2390 | 66 | color: "blue" | 66 | color: "blue" |
2391 | 67 | MouseArea { | ||
2392 | 68 | anchors.fill: parent | ||
2393 | 69 | hoverEnabled: true | ||
2394 | 70 | } | ||
2395 | 67 | } | 71 | } |
2396 | 68 | } | 72 | } |
2397 | 69 | } | 73 | } |
2398 | @@ -73,8 +77,13 @@ | |||
2399 | 73 | sourceComponent: fakeWindowComponent | 77 | sourceComponent: fakeWindowComponent |
2400 | 74 | } | 78 | } |
2401 | 75 | 79 | ||
2404 | 76 | UT.UnityTestCase { | 80 | MouseTouchEmulationCheckbox { |
2405 | 77 | name: "WindowMoveResizeArea" | 81 | checked: false |
2406 | 82 | color: "black" | ||
2407 | 83 | } | ||
2408 | 84 | |||
2409 | 85 | UnityTestCase { | ||
2410 | 86 | name: "WindowResizeArea" | ||
2411 | 78 | when: windowShown | 87 | when: windowShown |
2412 | 79 | 88 | ||
2413 | 80 | function init() { | 89 | function init() { |
2414 | @@ -84,34 +93,6 @@ | |||
2415 | 84 | fakeWindow.height = units.gu(20) | 93 | fakeWindow.height = units.gu(20) |
2416 | 85 | } | 94 | } |
2417 | 86 | 95 | ||
2418 | 87 | function test_dragWindow_data() { | ||
2419 | 88 | return [ | ||
2420 | 89 | { tag: "up", dx: 0, dy: units.gu(-10) }, | ||
2421 | 90 | { tag: "down", dx: 0, dy: units.gu(10) }, | ||
2422 | 91 | { tag: "left", dx: units.gu(-10), dy: 0 }, | ||
2423 | 92 | { tag: "right", dx: units.gu(10), dy: 0 }, | ||
2424 | 93 | { tag: "right/down", dx: units.gu(10), dy: units.gu(10) }, | ||
2425 | 94 | { tag: "left/down", dx: units.gu(-10), dy: units.gu(10) } | ||
2426 | 95 | ] | ||
2427 | 96 | } | ||
2428 | 97 | |||
2429 | 98 | function test_dragWindow(data) { | ||
2430 | 99 | var initialWindowX = fakeWindow.x; | ||
2431 | 100 | var initialWindowY = fakeWindow.y; | ||
2432 | 101 | var initialWindowWidth = fakeWindow.width | ||
2433 | 102 | var initialWindowHeight = fakeWindow.height | ||
2434 | 103 | |||
2435 | 104 | var startDragX = initialWindowX + fakeWindow.width / 2; | ||
2436 | 105 | var startDragY = initialWindowY + fakeWindow.height / 2; | ||
2437 | 106 | mouseFlick(root, startDragX, startDragY, startDragX + data.dx, startDragY + data.dy, true, true, units.gu(.5), 10) | ||
2438 | 107 | |||
2439 | 108 | tryCompare(fakeWindow, "x", initialWindowX + data.dx) | ||
2440 | 109 | tryCompare(fakeWindow, "y", initialWindowX + data.dy) | ||
2441 | 110 | |||
2442 | 111 | compare(fakeWindow.height, initialWindowHeight); | ||
2443 | 112 | compare(fakeWindow.width, initialWindowWidth); | ||
2444 | 113 | } | ||
2445 | 114 | |||
2446 | 115 | function test_resizeWindowRightBottom_data() { | 96 | function test_resizeWindowRightBottom_data() { |
2447 | 116 | return [ | 97 | return [ |
2448 | 117 | { tag: "width", dx: units.gu(10), dy: 0 }, | 98 | { tag: "width", dx: units.gu(10), dy: 0 }, |
2449 | @@ -166,30 +147,6 @@ | |||
2450 | 166 | compare(fakeWindow.y, Math.min(initialWindowY + data.dy, initialWindowY + maxMoveY)); | 147 | compare(fakeWindow.y, Math.min(initialWindowY + data.dy, initialWindowY + maxMoveY)); |
2451 | 167 | } | 148 | } |
2452 | 168 | 149 | ||
2453 | 169 | function test_saveRestorePosition() { | ||
2454 | 170 | var initialWindowX = fakeWindow.x; | ||
2455 | 171 | var initialWindowY = fakeWindow.y; | ||
2456 | 172 | var initialWindowWidth = fakeWindow.width; | ||
2457 | 173 | var initialWindowHeight = fakeWindow.height; | ||
2458 | 174 | |||
2459 | 175 | var moveDelta = units.gu(5); | ||
2460 | 176 | var startDragX = initialWindowX + fakeWindow.width / 2; | ||
2461 | 177 | var startDragY = initialWindowY + fakeWindow.height / 2; | ||
2462 | 178 | mouseFlick(root, startDragX, startDragY, startDragX + moveDelta, startDragY + moveDelta, true, true, units.gu(.5), 10) | ||
2463 | 179 | |||
2464 | 180 | tryCompare(fakeWindow, "x", initialWindowX + moveDelta) | ||
2465 | 181 | tryCompare(fakeWindow, "y", initialWindowX + moveDelta) | ||
2466 | 182 | |||
2467 | 183 | // This will destroy the window and recreate it | ||
2468 | 184 | windowLoader.active = false; | ||
2469 | 185 | waitForRendering(root); | ||
2470 | 186 | windowLoader.active = true; | ||
2471 | 187 | |||
2472 | 188 | // Make sure it's again where we left it before destroying | ||
2473 | 189 | tryCompare(fakeWindow, "x", initialWindowX + moveDelta) | ||
2474 | 190 | tryCompare(fakeWindow, "y", initialWindowX + moveDelta) | ||
2475 | 191 | } | ||
2476 | 192 | |||
2477 | 193 | function test_saveRestoreSize() { | 150 | function test_saveRestoreSize() { |
2478 | 194 | var initialWindowX = fakeWindow.x; | 151 | var initialWindowX = fakeWindow.x; |
2479 | 195 | var initialWindowY = fakeWindow.y; | 152 | var initialWindowY = fakeWindow.y; |
2480 | 196 | 153 | ||
2481 | === modified file 'tests/qmltests/tst_OrientedShell.qml' | |||
2482 | --- tests/qmltests/tst_OrientedShell.qml 2015-09-21 13:37:47 +0000 | |||
2483 | +++ tests/qmltests/tst_OrientedShell.qml 2015-10-19 14:53:23 +0000 | |||
2484 | @@ -264,6 +264,10 @@ | |||
2485 | 264 | text: "Usage Mode" | 264 | text: "Usage Mode" |
2486 | 265 | model: ["Staged", "Windowed", "Automatic"] | 265 | model: ["Staged", "Windowed", "Automatic"] |
2487 | 266 | } | 266 | } |
2488 | 267 | MouseTouchEmulationCheckbox { | ||
2489 | 268 | checked: true | ||
2490 | 269 | color: "white" | ||
2491 | 270 | } | ||
2492 | 267 | Button { | 271 | Button { |
2493 | 268 | text: "Switch fullscreen" | 272 | text: "Switch fullscreen" |
2494 | 269 | activeFocusOnPress: false | 273 | activeFocusOnPress: false |
Please follow the commit message format as explained here: https:/ /wiki.ubuntu. com/Process/ Merges/ Checklists/ Unity8