3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
1 |
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
|
2 |
/*
|
|
3 |
* Copyright (C) 2013 Canonical Ltd
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License version 3 as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*
|
|
17 |
* Authored by: Marco Trevisan <marco.trevisan@canonical.com>
|
|
18 |
*/
|
|
19 |
||
3566.5.240
by Marco Trevisan (Treviño)
decorations_pch: include sigc |
20 |
#include <sigc++/adaptors/hide.h> |
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
21 |
#include "DecorationsWindowButton.h" |
3566.5.121
by Marco Trevisan (Treviño)
DecorationsWindowButton: remove from the Window::Impl namespace |
22 |
#include "DecorationsDataPool.h" |
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
23 |
|
3566.7.10
by Brandon Schaefer
* Update the window button scale |
24 |
#include "unity-shared/UnitySettings.h" |
25 |
#include "unity-shared/WindowManager.h" |
|
26 |
||
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
27 |
namespace unity |
28 |
{
|
|
29 |
namespace decoration |
|
30 |
{
|
|
31 |
||
4163.3.2
by Marco Trevisan (Treviño)
DecorationsWindowButton: make type a property and update texture on change |
32 |
WindowButton::WindowButton(CompWindow* win, WindowButtonType wbt) |
33 |
: type(wbt) |
|
3566.5.92
by Marco Trevisan (Treviño)
DecorationsWindowButton: add pressed button state |
34 |
, pressed_(false) |
3566.5.95
by Marco Trevisan (Treviño)
DecorationsWindowButton: don't draw as pressed a button when mouse is outside it |
35 |
, was_pressed_(false) |
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
36 |
, win_(win) |
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
37 |
{
|
3566.5.121
by Marco Trevisan (Treviño)
DecorationsWindowButton: remove from the Window::Impl namespace |
38 |
auto cb = sigc::hide(sigc::mem_fun(this, &WindowButton::UpdateTexture)); |
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
39 |
mouse_owner.changed.connect(cb); |
40 |
focused.changed.connect(cb); |
|
3680.1.81
by Marco Trevisan (Treviño)
DecorationsWindowButton: use scaled Window Button textures, enjoy the visual quality! |
41 |
scale.changed.connect(cb); |
4163.3.2
by Marco Trevisan (Treviño)
DecorationsWindowButton: make type a property and update texture on change |
42 |
type.changed.connect(cb); |
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
43 |
UpdateTexture(); |
44 |
}
|
|
45 |
||
3566.5.121
by Marco Trevisan (Treviño)
DecorationsWindowButton: remove from the Window::Impl namespace |
46 |
void WindowButton::UpdateTexture() |
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
47 |
{
|
4163.3.2
by Marco Trevisan (Treviño)
DecorationsWindowButton: make type a property and update texture on change |
48 |
SetTexture(DataPool::Get()->ButtonTexture(scale(), type(), GetCurrentState())); |
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
49 |
}
|
50 |
||
3566.5.121
by Marco Trevisan (Treviño)
DecorationsWindowButton: remove from the Window::Impl namespace |
51 |
WidgetState WindowButton::GetCurrentState() const |
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
52 |
{
|
53 |
if (focused()) |
|
54 |
{
|
|
3566.5.92
by Marco Trevisan (Treviño)
DecorationsWindowButton: add pressed button state |
55 |
if (mouse_owner() && pressed_) |
56 |
{
|
|
57 |
return WidgetState::PRESSED; |
|
58 |
}
|
|
3566.5.96
by Marco Trevisan (Treviño)
DecorationsWindowButton: don't damage or update texture if we're switching with the current one. |
59 |
else if (mouse_owner() && !was_pressed_) |
3566.5.92
by Marco Trevisan (Treviño)
DecorationsWindowButton: add pressed button state |
60 |
{
|
61 |
return WidgetState::PRELIGHT; |
|
62 |
}
|
|
63 |
else
|
|
64 |
{
|
|
65 |
return WidgetState::NORMAL; |
|
66 |
}
|
|
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
67 |
}
|
68 |
else
|
|
69 |
{
|
|
3566.5.92
by Marco Trevisan (Treviño)
DecorationsWindowButton: add pressed button state |
70 |
if (mouse_owner() && pressed_) |
71 |
{
|
|
72 |
return WidgetState::BACKDROP_PRESSED; |
|
73 |
}
|
|
3566.5.96
by Marco Trevisan (Treviño)
DecorationsWindowButton: don't damage or update texture if we're switching with the current one. |
74 |
else if (mouse_owner() && !was_pressed_) |
3566.5.92
by Marco Trevisan (Treviño)
DecorationsWindowButton: add pressed button state |
75 |
{
|
76 |
return WidgetState::BACKDROP_PRELIGHT; |
|
77 |
}
|
|
78 |
else
|
|
79 |
{
|
|
80 |
return WidgetState::BACKDROP; |
|
81 |
}
|
|
82 |
}
|
|
83 |
}
|
|
84 |
||
3649.1.1
by Marco Trevisan (Treviño)
DecorationsInputMixer: pass Timestamp to events |
85 |
void WindowButton::ButtonDownEvent(CompPoint const& p, unsigned button, Time) |
3566.5.92
by Marco Trevisan (Treviño)
DecorationsWindowButton: add pressed button state |
86 |
{
|
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
87 |
if (!pressed_ && button <= Button3) |
3566.5.92
by Marco Trevisan (Treviño)
DecorationsWindowButton: add pressed button state |
88 |
{
|
89 |
pressed_ = true; |
|
3566.5.95
by Marco Trevisan (Treviño)
DecorationsWindowButton: don't draw as pressed a button when mouse is outside it |
90 |
was_pressed_ = true; |
3566.5.92
by Marco Trevisan (Treviño)
DecorationsWindowButton: add pressed button state |
91 |
UpdateTexture(); |
92 |
}
|
|
93 |
}
|
|
94 |
||
3649.1.1
by Marco Trevisan (Treviño)
DecorationsInputMixer: pass Timestamp to events |
95 |
void WindowButton::ButtonUpEvent(CompPoint const& p, unsigned button, Time timestamp) |
3566.5.92
by Marco Trevisan (Treviño)
DecorationsWindowButton: add pressed button state |
96 |
{
|
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
97 |
if (pressed_ && button <= Button3) |
3566.5.92
by Marco Trevisan (Treviño)
DecorationsWindowButton: add pressed button state |
98 |
{
|
99 |
pressed_ = false; |
|
100 |
UpdateTexture(); |
|
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
101 |
|
4163.3.2
by Marco Trevisan (Treviño)
DecorationsWindowButton: make type a property and update texture on change |
102 |
switch (type()) |
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
103 |
{
|
104 |
case WindowButtonType::CLOSE: |
|
105 |
if (win_->actions() & CompWindowActionCloseMask) |
|
3649.1.1
by Marco Trevisan (Treviño)
DecorationsInputMixer: pass Timestamp to events |
106 |
win_->close(timestamp); |
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
107 |
break; |
108 |
case WindowButtonType::MINIMIZE: |
|
109 |
if (win_->actions() & CompWindowActionMinimizeMask) |
|
110 |
win_->minimize(); |
|
111 |
break; |
|
112 |
case WindowButtonType::MAXIMIZE: |
|
4163.3.4
by Marco Trevisan (Treviño)
DecorationsWindowButton: add specific cases for Unmaximize type, adding/removing flags |
113 |
switch (button) |
114 |
{
|
|
115 |
case Button1: |
|
116 |
if (win_->actions() & (CompWindowActionMaximizeHorzMask|CompWindowActionMaximizeVertMask)) |
|
117 |
win_->maximize(MAXIMIZE_STATE); |
|
118 |
break; |
|
119 |
case Button2: |
|
120 |
if (win_->actions() & CompWindowActionMaximizeVertMask) |
|
121 |
{
|
|
122 |
if (!(win_->state() & CompWindowStateMaximizedVertMask)) |
|
123 |
win_->maximize(win_->state() | CompWindowStateMaximizedVertMask); |
|
124 |
}
|
|
125 |
break; |
|
126 |
case Button3: |
|
127 |
if (win_->actions() & CompWindowActionMaximizeHorzMask) |
|
128 |
{
|
|
129 |
if (!(win_->state() & CompWindowStateMaximizedHorzMask)) |
|
130 |
win_->maximize(win_->state() | CompWindowStateMaximizedHorzMask); |
|
131 |
}
|
|
132 |
break; |
|
133 |
}
|
|
134 |
break; |
|
4163.3.2
by Marco Trevisan (Treviño)
DecorationsWindowButton: make type a property and update texture on change |
135 |
case WindowButtonType::UNMAXIMIZE: |
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
136 |
switch (button) |
137 |
{
|
|
138 |
case Button1: |
|
4163.3.7
by Marco Trevisan (Treviño)
DecorationsWindowButton: fix case indentation |
139 |
win_->maximize(0); |
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
140 |
break; |
141 |
case Button2: |
|
142 |
if (win_->actions() & CompWindowActionMaximizeVertMask) |
|
143 |
{
|
|
144 |
if (!(win_->state() & CompWindowStateMaximizedVertMask)) |
|
4163.3.4
by Marco Trevisan (Treviño)
DecorationsWindowButton: add specific cases for Unmaximize type, adding/removing flags |
145 |
win_->maximize(win_->state() | CompWindowStateMaximizedVertMask); |
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
146 |
else
|
4163.3.4
by Marco Trevisan (Treviño)
DecorationsWindowButton: add specific cases for Unmaximize type, adding/removing flags |
147 |
win_->maximize(win_->state() & ~CompWindowStateMaximizedVertMask); |
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
148 |
}
|
149 |
break; |
|
150 |
case Button3: |
|
151 |
if (win_->actions() & CompWindowActionMaximizeHorzMask) |
|
152 |
{
|
|
153 |
if (!(win_->state() & CompWindowStateMaximizedHorzMask)) |
|
4163.3.4
by Marco Trevisan (Treviño)
DecorationsWindowButton: add specific cases for Unmaximize type, adding/removing flags |
154 |
win_->maximize(win_->state() | CompWindowStateMaximizedHorzMask); |
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
155 |
else
|
4163.3.4
by Marco Trevisan (Treviño)
DecorationsWindowButton: add specific cases for Unmaximize type, adding/removing flags |
156 |
win_->maximize(win_->state() & ~CompWindowStateMaximizedHorzMask); |
3566.5.100
by Marco Trevisan (Treviño)
DecorationsWindowButton: correctly handle mouse-up events and perform the relative action |
157 |
}
|
158 |
break; |
|
159 |
}
|
|
160 |
default: |
|
161 |
break; |
|
162 |
}
|
|
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
163 |
}
|
3566.5.95
by Marco Trevisan (Treviño)
DecorationsWindowButton: don't draw as pressed a button when mouse is outside it |
164 |
|
165 |
was_pressed_ = false; |
|
166 |
}
|
|
167 |
||
3649.1.1
by Marco Trevisan (Treviño)
DecorationsInputMixer: pass Timestamp to events |
168 |
void WindowButton::MotionEvent(CompPoint const& p, Time) |
3566.5.95
by Marco Trevisan (Treviño)
DecorationsWindowButton: don't draw as pressed a button when mouse is outside it |
169 |
{
|
170 |
if (pressed_) |
|
171 |
{
|
|
172 |
if (!Geometry().contains(p)) |
|
173 |
{
|
|
174 |
pressed_ = false; |
|
175 |
UpdateTexture(); |
|
176 |
}
|
|
177 |
}
|
|
178 |
else if (was_pressed_) |
|
179 |
{
|
|
180 |
if (Geometry().contains(p)) |
|
181 |
{
|
|
182 |
pressed_ = true; |
|
183 |
UpdateTexture(); |
|
184 |
}
|
|
185 |
}
|
|
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
186 |
}
|
187 |
||
3566.5.209
by Marco Trevisan (Treviño)
DecorationsWindowButton: add introspection details |
188 |
std::string WindowButton::GetName() const |
189 |
{
|
|
4163.3.2
by Marco Trevisan (Treviño)
DecorationsWindowButton: make type a property and update texture on change |
190 |
switch (type()) |
3566.5.209
by Marco Trevisan (Treviño)
DecorationsWindowButton: add introspection details |
191 |
{
|
192 |
case WindowButtonType::CLOSE: |
|
193 |
return "CloseWindowButton"; |
|
194 |
case WindowButtonType::MINIMIZE: |
|
195 |
return "MinimizeWindowButton"; |
|
196 |
case WindowButtonType::MAXIMIZE: |
|
197 |
return "MaximizeWindowButton"; |
|
198 |
case WindowButtonType::UNMAXIMIZE: |
|
199 |
return "UnmaximizeWindowButton"; |
|
200 |
default: |
|
201 |
return "WindowButton"; |
|
202 |
}
|
|
203 |
}
|
|
204 |
||
205 |
void WindowButton::AddProperties(debug::IntrospectionData& data) |
|
206 |
{
|
|
207 |
TexturedItem::AddProperties(data); |
|
208 |
data.add("pressed", pressed_); |
|
209 |
||
210 |
switch(GetCurrentState()) |
|
211 |
{
|
|
212 |
case WidgetState::NORMAL: |
|
213 |
data.add("state", "normal"); |
|
214 |
break; |
|
215 |
case WidgetState::PRELIGHT: |
|
216 |
data.add("state", "prelight"); |
|
217 |
break; |
|
218 |
case WidgetState::PRESSED: |
|
219 |
data.add("state", "pressed"); |
|
220 |
break; |
|
221 |
case WidgetState::DISABLED: |
|
222 |
data.add("state", "disabled"); |
|
223 |
break; |
|
224 |
case WidgetState::BACKDROP: |
|
225 |
data.add("state", "backdrop"); |
|
226 |
break; |
|
227 |
case WidgetState::BACKDROP_PRELIGHT: |
|
228 |
data.add("state", "backdrop_prelight"); |
|
229 |
break; |
|
230 |
case WidgetState::BACKDROP_PRESSED: |
|
231 |
data.add("state", "backdrop_pressed"); |
|
232 |
break; |
|
233 |
default: |
|
234 |
data.add("state", "unknown"); |
|
235 |
}
|
|
236 |
}
|
|
237 |
||
3566.5.89
by Marco Trevisan (Treviño)
DecorationsWindowButton: move definition of Window::Button in external file |
238 |
} // decoration namespace |
239 |
} // unity namespace |