Merge lp:~3v1n0/unity/panel-p-window-buttons into lp:~3v1n0/unity/panel-p-indicators-view
- panel-p-window-buttons
- Merge into panel-p-indicators-view
Proposed by
Marco Trevisan (Treviño)
Status: | Merged |
---|---|
Approved by: | Marco Trevisan (Treviño) |
Approved revision: | no longer in the source branch. |
Merge reported by: | Marco Trevisan (Treviño) |
Merged at revision: | not available |
Proposed branch: | lp:~3v1n0/unity/panel-p-window-buttons |
Merge into: | lp:~3v1n0/unity/panel-p-indicators-view |
Diff against target: |
1037 lines (+620/-232) 2 files modified
plugins/unityshell/src/WindowButtons.cpp (+587/-220) plugins/unityshell/src/WindowButtons.h (+33/-12) |
To merge this branch: | bzr merge lp:~3v1n0/unity/panel-p-window-buttons |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Penhey (community) | Approve | ||
Marco Trevisan (Treviño) | Pending | ||
Review via email: mp+100123@code.launchpad.net |
Commit message
Description of the change
Window Buttons changes, see https:/
To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
That is coming... ;)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'plugins/unityshell/src/WindowButtons.cpp' |
2 | --- plugins/unityshell/src/WindowButtons.cpp 2012-03-21 12:31:11 +0000 |
3 | +++ plugins/unityshell/src/WindowButtons.cpp 2012-04-04 20:17:24 +0000 |
4 | @@ -1,6 +1,6 @@ |
5 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
6 | /* |
7 | - * Copyright (C) 2010 Canonical Ltd |
8 | + * Copyright (C) 2010-2012 Canonical Ltd |
9 | * |
10 | * This program is free software: you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 3 as |
12 | @@ -15,125 +15,139 @@ |
13 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
14 | * |
15 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
16 | + * Marco Trevisan (Treviño) <3v1n0@ubuntu.com> |
17 | */ |
18 | |
19 | #include "config.h" |
20 | |
21 | #include <Nux/Nux.h> |
22 | -#include <Nux/HLayout.h> |
23 | -#include <Nux/VLayout.h> |
24 | -#include <Nux/Button.h> |
25 | - |
26 | -#include <NuxGraphics/GLThread.h> |
27 | -#include <Nux/BaseWindow.h> |
28 | -#include <Nux/WindowCompositor.h> |
29 | - |
30 | + |
31 | +#include <UnityCore/GLibWrapper.h> |
32 | #include <UnityCore/Variant.h> |
33 | + |
34 | #include "WindowButtons.h" |
35 | |
36 | -#include "ubus-server.h" |
37 | -#include "UBusMessages.h" |
38 | - |
39 | #include "DashSettings.h" |
40 | #include "PanelStyle.h" |
41 | - |
42 | -#include <UnityCore/GLibWrapper.h> |
43 | +#include "UBusMessages.h" |
44 | +#include "WindowManager.h" |
45 | |
46 | namespace unity |
47 | { |
48 | |
49 | -class WindowButton : public nux::Button |
50 | +class WindowButton : public nux::Button, public debug::Introspectable |
51 | { |
52 | // A single window button |
53 | public: |
54 | WindowButton(panel::WindowButtonType type) |
55 | - : nux::Button("", NUX_TRACKER_LOCATION), |
56 | - _type(type), |
57 | - _overlay_is_open(false), |
58 | - _mouse_is_down(false), |
59 | - _place_shown_interest(0), |
60 | - _place_hidden_interest(0), |
61 | - _opacity(1.0f) |
62 | + : nux::Button("", NUX_TRACKER_LOCATION) |
63 | + , _type(type) |
64 | + , _focused(true) |
65 | + , _overlay_is_open(false) |
66 | + , _opacity(1.0f) |
67 | { |
68 | + panel::Style::Instance().changed.connect(sigc::mem_fun(this, &WindowButton::LoadImages)); |
69 | LoadImages(); |
70 | - UpdateDashUnmaximize(); |
71 | - panel::Style::Instance().changed.connect(sigc::mem_fun(this, &WindowButton::LoadImages)); |
72 | - dash::Settings::Instance().changed.connect(sigc::mem_fun(this, &WindowButton::UpdateDashUnmaximize)); |
73 | - |
74 | - UBusServer* ubus = ubus_server_get_default(); |
75 | - _place_shown_interest = ubus_server_register_interest(ubus, UBUS_OVERLAY_SHOWN, |
76 | - (UBusCallback)&WindowButton::OnOverlayShown, |
77 | - this); |
78 | - _place_hidden_interest = ubus_server_register_interest(ubus, UBUS_OVERLAY_HIDDEN, |
79 | - (UBusCallback)&WindowButton::OnOverlayHidden, |
80 | - this); |
81 | - |
82 | - /* FIXME HasMouseFocus() doesn't seem to work correctly, so we use this workaround */ |
83 | - mouse_down.connect([&_mouse_is_down](int, int, unsigned long, unsigned long) { |
84 | - _mouse_is_down = true; |
85 | - }); |
86 | - mouse_up.connect([&_mouse_is_down](int, int, unsigned long, unsigned long) { |
87 | - _mouse_is_down = false; |
88 | - }); |
89 | } |
90 | |
91 | - ~WindowButton() |
92 | + void SetVisualState(nux::ButtonVisualState new_state) |
93 | { |
94 | - UBusServer* ubus = ubus_server_get_default(); |
95 | - if (_place_shown_interest != 0) |
96 | - ubus_server_unregister_interest(ubus, _place_shown_interest); |
97 | - if (_place_hidden_interest != 0) |
98 | - ubus_server_unregister_interest(ubus, _place_hidden_interest); |
99 | + if (new_state != visual_state_) |
100 | + { |
101 | + visual_state_ = new_state; |
102 | + QueueDraw(); |
103 | + } |
104 | } |
105 | |
106 | void Draw(nux::GraphicsEngine& GfxContext, bool force_draw) |
107 | { |
108 | - nux::Geometry geo = GetGeometry(); |
109 | - nux::BaseTexture* tex = nullptr; |
110 | + nux::Geometry const& geo = GetGeometry(); |
111 | + nux::BaseTexture* tex; |
112 | nux::TexCoordXForm texxform; |
113 | |
114 | GfxContext.PushClippingRectangle(geo); |
115 | |
116 | if (_overlay_is_open) |
117 | { |
118 | - if (_type == panel::WindowButtonType::UNMAXIMIZE && !_overlay_can_maximize) |
119 | + if (!IsEnabled()) |
120 | { |
121 | tex = _disabled_dash_tex.GetPointer(); |
122 | } |
123 | else |
124 | { |
125 | - //FIXME should use HasMouseFocus() |
126 | - if (_mouse_is_down && IsMouseInside()) |
127 | - tex = _pressed_dash_tex.GetPointer(); |
128 | - else if (IsMouseInside()) |
129 | - tex = _prelight_dash_tex.GetPointer(); |
130 | - else |
131 | - tex = _normal_dash_tex.GetPointer(); |
132 | + switch (visual_state_) |
133 | + { |
134 | + case nux::VISUAL_STATE_PRESSED: |
135 | + tex = _pressed_dash_tex.GetPointer(); |
136 | + break; |
137 | + case nux::VISUAL_STATE_PRELIGHT: |
138 | + tex = _prelight_dash_tex.GetPointer(); |
139 | + break; |
140 | + default: |
141 | + tex = _normal_dash_tex.GetPointer(); |
142 | + } |
143 | + } |
144 | + } |
145 | + else if (!IsEnabled()) |
146 | + { |
147 | + tex = _disabled_tex.GetPointer(); |
148 | + } |
149 | + else if (!_focused) |
150 | + { |
151 | + switch (visual_state_) |
152 | + { |
153 | + case nux::VISUAL_STATE_PRESSED: |
154 | + tex = _unfocused_pressed_tex.GetPointer(); |
155 | + break; |
156 | + case nux::VISUAL_STATE_PRELIGHT: |
157 | + tex = _unfocused_prelight_tex.GetPointer(); |
158 | + break; |
159 | + default: |
160 | + tex = _unfocused_tex.GetPointer(); |
161 | } |
162 | } |
163 | else |
164 | { |
165 | - //FIXME should use HasMouseFocus() |
166 | - if (_mouse_is_down && IsMouseInside()) |
167 | - tex = _pressed_tex.GetPointer(); |
168 | - else if (IsMouseInside()) |
169 | - tex = _prelight_tex.GetPointer(); |
170 | - else |
171 | - tex = _normal_tex.GetPointer(); |
172 | + switch (visual_state_) |
173 | + { |
174 | + case nux::VISUAL_STATE_PRESSED: |
175 | + tex = _pressed_tex.GetPointer(); |
176 | + break; |
177 | + case nux::VISUAL_STATE_PRELIGHT: |
178 | + tex = _prelight_tex.GetPointer(); |
179 | + break; |
180 | + default: |
181 | + tex = _normal_tex.GetPointer(); |
182 | + } |
183 | } |
184 | |
185 | if (tex) |
186 | - GfxContext.QRP_1Tex(geo.x, |
187 | - geo.y, |
188 | - (float)geo.width, |
189 | - (float)geo.height, |
190 | - tex->GetDeviceTexture(), |
191 | - texxform, |
192 | + { |
193 | + GfxContext.QRP_1Tex(geo.x, geo.y, geo.width, geo.height, |
194 | + tex->GetDeviceTexture(), texxform, |
195 | nux::color::White * _opacity); |
196 | + } |
197 | |
198 | GfxContext.PopClippingRectangle(); |
199 | } |
200 | |
201 | + void UpdateSize() |
202 | + { |
203 | + int panel_height = panel::Style::Instance().panel_height; |
204 | + nux::BaseTexture* tex; |
205 | + tex = (_overlay_is_open) ? _normal_dash_tex.GetPointer() : _normal_tex.GetPointer(); |
206 | + int width = 0; |
207 | + int height = 0; |
208 | + |
209 | + if (tex) |
210 | + { |
211 | + width = std::min(panel_height, tex->GetWidth()); |
212 | + height = std::min(panel_height, tex->GetHeight()); |
213 | + } |
214 | + |
215 | + SetMinMaxSize(width, height); |
216 | + } |
217 | + |
218 | void LoadImages() |
219 | { |
220 | panel::Style& style = panel::Style::Instance(); |
221 | @@ -141,53 +155,16 @@ |
222 | _normal_tex.Adopt(style.GetWindowButton(_type, panel::WindowState::NORMAL)); |
223 | _prelight_tex.Adopt(style.GetWindowButton(_type, panel::WindowState::PRELIGHT)); |
224 | _pressed_tex.Adopt(style.GetWindowButton(_type, panel::WindowState::PRESSED)); |
225 | + _unfocused_tex.Adopt(style.GetWindowButton(_type, panel::WindowState::UNFOCUSED)); |
226 | + _disabled_tex.Adopt(style.GetWindowButton(_type, panel::WindowState::DISABLED)); |
227 | + _unfocused_prelight_tex.Adopt(style.GetWindowButton(_type, panel::WindowState::UNFOCUSED_PRELIGHT)); |
228 | + _unfocused_pressed_tex.Adopt(style.GetWindowButton(_type, panel::WindowState::UNFOCUSED_PRESSED)); |
229 | _normal_dash_tex.Adopt(GetDashWindowButton(_type, panel::WindowState::NORMAL)); |
230 | _prelight_dash_tex.Adopt(GetDashWindowButton(_type, panel::WindowState::PRELIGHT)); |
231 | _pressed_dash_tex.Adopt(GetDashWindowButton(_type, panel::WindowState::PRESSED)); |
232 | - |
233 | - if (_overlay_is_open) |
234 | - { |
235 | - if (_normal_dash_tex) |
236 | - SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight()); |
237 | - } |
238 | - else |
239 | - { |
240 | - if (_normal_tex) |
241 | - SetMinMaxSize(_normal_tex->GetWidth(), _normal_tex->GetHeight()); |
242 | - } |
243 | - |
244 | - QueueDraw(); |
245 | - } |
246 | - |
247 | - void UpdateDashUnmaximize() |
248 | - { |
249 | - // only update the unmaximize button |
250 | - if (_type != panel::WindowButtonType::UNMAXIMIZE) |
251 | - return; |
252 | - |
253 | - panel::WindowButtonType real_type = panel::WindowButtonType::UNMAXIMIZE; |
254 | - |
255 | - if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP) |
256 | - { |
257 | - real_type = panel::WindowButtonType::MAXIMIZE; |
258 | - } |
259 | - |
260 | - //!!FIXME!! - don't have disabled instances of the (un)maximize buttons |
261 | - // get (un)maximize buttons |
262 | - _normal_dash_tex.Adopt(GetDashWindowButton(real_type, panel::WindowState::NORMAL)); |
263 | - _prelight_dash_tex.Adopt(GetDashWindowButton(real_type, panel::WindowState::PRELIGHT)); |
264 | - _pressed_dash_tex.Adopt(GetDashWindowButton(real_type, panel::WindowState::PRESSED)); |
265 | - _disabled_dash_tex.Adopt(GetDashWindowButton(real_type, panel::WindowState::DISABLED)); |
266 | - |
267 | - // still check if the dash is really opened, |
268 | - // someone could change the form factor through dconf |
269 | - // when the dash is closed |
270 | - if (_overlay_is_open) |
271 | - { |
272 | - if (_normal_dash_tex) |
273 | - SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight()); |
274 | - } |
275 | - |
276 | + _disabled_dash_tex.Adopt(GetDashWindowButton(_type, panel::WindowState::DISABLED)); |
277 | + |
278 | + UpdateSize(); |
279 | QueueDraw(); |
280 | } |
281 | |
282 | @@ -196,62 +173,135 @@ |
283 | if (_opacity != opacity) |
284 | { |
285 | _opacity = opacity; |
286 | - NeedRedraw(); |
287 | + QueueDraw(); |
288 | } |
289 | } |
290 | |
291 | - double GetOpacity() |
292 | + double GetOpacity() const |
293 | { |
294 | return _opacity; |
295 | } |
296 | |
297 | + void SetFocusedState(bool focused) |
298 | + { |
299 | + if (_focused != focused) |
300 | + { |
301 | + _focused = focused; |
302 | + QueueDraw(); |
303 | + } |
304 | + } |
305 | + |
306 | + void SetOverlayOpen(bool open) |
307 | + { |
308 | + if (_overlay_is_open == open) |
309 | + return; |
310 | + |
311 | + _overlay_is_open = open; |
312 | + |
313 | + UpdateSize(); |
314 | + QueueDraw(); |
315 | + } |
316 | + |
317 | + bool IsOverlayOpen() |
318 | + { |
319 | + return _overlay_is_open; |
320 | + } |
321 | + |
322 | + panel::WindowButtonType GetType() const |
323 | + { |
324 | + return _type; |
325 | + } |
326 | + |
327 | + void ChangeType(panel::WindowButtonType new_type) |
328 | + { |
329 | + if (_type != new_type) |
330 | + { |
331 | + _type = new_type; |
332 | + LoadImages(); |
333 | + } |
334 | + } |
335 | + |
336 | + void SetEnabled(bool enabled) |
337 | + { |
338 | + if (enabled == IsEnabled()) |
339 | + return; |
340 | + |
341 | + SetEnableView(enabled); |
342 | + QueueDraw(); |
343 | + } |
344 | + |
345 | + bool IsEnabled() |
346 | + { |
347 | + return IsViewEnabled(); |
348 | + } |
349 | + |
350 | +protected: |
351 | + std::string GetName() const |
352 | + { |
353 | + return "Button"; |
354 | + } |
355 | + |
356 | + void AddProperties(GVariantBuilder* builder) |
357 | + { |
358 | + std::string type_name; |
359 | + std::string state_name; |
360 | + |
361 | + switch (_type) |
362 | + { |
363 | + case panel::WindowButtonType::CLOSE: |
364 | + type_name = "Close"; |
365 | + break; |
366 | + case panel::WindowButtonType::MINIMIZE: |
367 | + type_name = "Minimize"; |
368 | + break; |
369 | + case panel::WindowButtonType::MAXIMIZE: |
370 | + type_name = "Maximize"; |
371 | + break; |
372 | + case panel::WindowButtonType::UNMAXIMIZE: |
373 | + type_name = "Unmaximize"; |
374 | + break; |
375 | + } |
376 | + |
377 | + switch (visual_state_) |
378 | + { |
379 | + case nux::VISUAL_STATE_PRESSED: |
380 | + state_name = "pressed"; |
381 | + break; |
382 | + case nux::VISUAL_STATE_PRELIGHT: |
383 | + state_name = "prelight"; |
384 | + break; |
385 | + default: |
386 | + state_name = "normal"; |
387 | + } |
388 | + |
389 | + variant::BuilderWrapper(builder).add(GetGeometry()) |
390 | + .add("type", type_name) |
391 | + .add("visible", IsVisible()) |
392 | + .add("enabled", IsEnabled()) |
393 | + .add("visual_state", state_name) |
394 | + .add("opacity", _opacity) |
395 | + .add("focused", _focused) |
396 | + .add("overlay_mode", _overlay_is_open); |
397 | + } |
398 | + |
399 | + |
400 | private: |
401 | panel::WindowButtonType _type; |
402 | - typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr; |
403 | - BaseTexturePtr _normal_tex; |
404 | - BaseTexturePtr _prelight_tex; |
405 | - BaseTexturePtr _pressed_tex; |
406 | - BaseTexturePtr _normal_dash_tex; |
407 | - BaseTexturePtr _prelight_dash_tex; |
408 | - BaseTexturePtr _pressed_dash_tex; |
409 | - BaseTexturePtr _disabled_dash_tex; |
410 | - |
411 | + bool _focused; |
412 | bool _overlay_is_open; |
413 | - bool _overlay_can_maximize; |
414 | - bool _mouse_is_down; |
415 | - guint32 _place_shown_interest; |
416 | - guint32 _place_hidden_interest; |
417 | double _opacity; |
418 | |
419 | - static void OnOverlayShown(GVariant* data, void* val) |
420 | - { |
421 | - unity::glib::String overlay_identity; |
422 | - gboolean can_maximise = FALSE; |
423 | - gint32 overlay_monitor = 0; |
424 | - g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, |
425 | - &overlay_identity, &can_maximise, &overlay_monitor); |
426 | - |
427 | - WindowButton* self = (WindowButton*)val; |
428 | - |
429 | - self->_overlay_is_open = true; |
430 | - if (self->_normal_dash_tex) |
431 | - self->SetMinMaxSize(self->_normal_dash_tex->GetWidth(), self->_normal_dash_tex->GetHeight()); |
432 | - |
433 | - self->_overlay_can_maximize = (can_maximise) ? true : false; |
434 | - |
435 | - self->QueueDraw(); |
436 | - } |
437 | - |
438 | - static void OnOverlayHidden(GVariant* data, void* val) |
439 | - { |
440 | - WindowButton* self = (WindowButton*)val; |
441 | - |
442 | - self->_overlay_is_open = false; |
443 | - if (self->_normal_tex) |
444 | - self->SetMinMaxSize(self->_normal_tex->GetWidth(), self->_normal_tex->GetHeight()); |
445 | - |
446 | - self->QueueDraw(); |
447 | - } |
448 | + nux::ObjectPtr<nux::BaseTexture> _normal_tex; |
449 | + nux::ObjectPtr<nux::BaseTexture> _prelight_tex; |
450 | + nux::ObjectPtr<nux::BaseTexture> _pressed_tex; |
451 | + nux::ObjectPtr<nux::BaseTexture> _unfocused_tex; |
452 | + nux::ObjectPtr<nux::BaseTexture> _unfocused_prelight_tex; |
453 | + nux::ObjectPtr<nux::BaseTexture> _unfocused_pressed_tex; |
454 | + nux::ObjectPtr<nux::BaseTexture> _disabled_tex; |
455 | + nux::ObjectPtr<nux::BaseTexture> _normal_dash_tex; |
456 | + nux::ObjectPtr<nux::BaseTexture> _prelight_dash_tex; |
457 | + nux::ObjectPtr<nux::BaseTexture> _pressed_dash_tex; |
458 | + nux::ObjectPtr<nux::BaseTexture> _disabled_dash_tex; |
459 | |
460 | nux::BaseTexture* GetDashWindowButton(panel::WindowButtonType type, |
461 | panel::WindowState state) |
462 | @@ -282,7 +332,10 @@ |
463 | |
464 | WindowButtons::WindowButtons() |
465 | : HLayout("", NUX_TRACKER_LOCATION) |
466 | - , _opacity(1.0f) |
467 | + , monitor_(0) |
468 | + , opacity_(1.0f) |
469 | + , focused_(true) |
470 | + , window_xid_(0) |
471 | { |
472 | WindowButton* but; |
473 | |
474 | @@ -303,94 +356,408 @@ |
475 | |
476 | but = new WindowButton(panel::WindowButtonType::CLOSE); |
477 | AddView(but, 0, nux::eCenter, nux::eFix); |
478 | - but->state_change.connect(sigc::mem_fun(this, &WindowButtons::OnCloseClicked)); |
479 | + AddChild(but); |
480 | + but->click.connect(sigc::mem_fun(this, &WindowButtons::OnCloseClicked)); |
481 | but->mouse_enter.connect(lambda_enter); |
482 | but->mouse_leave.connect(lambda_leave); |
483 | but->mouse_move.connect(lambda_moved); |
484 | |
485 | but = new WindowButton(panel::WindowButtonType::MINIMIZE); |
486 | AddView(but, 0, nux::eCenter, nux::eFix); |
487 | - but->state_change.connect(sigc::mem_fun(this, &WindowButtons::OnMinimizeClicked)); |
488 | + AddChild(but); |
489 | + but->click.connect(sigc::mem_fun(this, &WindowButtons::OnMinimizeClicked)); |
490 | but->mouse_enter.connect(lambda_enter); |
491 | but->mouse_leave.connect(lambda_leave); |
492 | but->mouse_move.connect(lambda_moved); |
493 | |
494 | but = new WindowButton(panel::WindowButtonType::UNMAXIMIZE); |
495 | AddView(but, 0, nux::eCenter, nux::eFix); |
496 | - but->state_change.connect(sigc::mem_fun(this, &WindowButtons::OnRestoreClicked)); |
497 | - but->mouse_enter.connect(lambda_enter); |
498 | - but->mouse_leave.connect(lambda_leave); |
499 | - but->mouse_move.connect(lambda_moved); |
500 | + AddChild(but); |
501 | + but->click.connect(sigc::mem_fun(this, &WindowButtons::OnRestoreClicked)); |
502 | + but->mouse_enter.connect(lambda_enter); |
503 | + but->mouse_leave.connect(lambda_leave); |
504 | + but->mouse_move.connect(lambda_moved); |
505 | + |
506 | + but = new WindowButton(panel::WindowButtonType::MAXIMIZE); |
507 | + AddView(but, 0, nux::eCenter, nux::eFix); |
508 | + AddChild(but); |
509 | + but->click.connect(sigc::mem_fun(this, &WindowButtons::OnMaximizeClicked)); |
510 | + but->mouse_enter.connect(lambda_enter); |
511 | + but->mouse_leave.connect(lambda_leave); |
512 | + but->mouse_move.connect(lambda_moved); |
513 | + but->SetVisible(false); |
514 | |
515 | SetContentDistribution(nux::eStackLeft); |
516 | -} |
517 | - |
518 | - |
519 | -WindowButtons::~WindowButtons() |
520 | -{ |
521 | -} |
522 | - |
523 | -void |
524 | -WindowButtons::OnCloseClicked(nux::View* view) |
525 | -{ |
526 | + |
527 | + ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, sigc::mem_fun(this, &WindowButtons::OnOverlayShown)); |
528 | + ubus_manager_.RegisterInterest(UBUS_OVERLAY_HIDDEN, sigc::mem_fun(this, &WindowButtons::OnOverlayHidden)); |
529 | + dash::Settings::Instance().changed.connect(sigc::mem_fun(this, &WindowButtons::OnDashSettingsUpdated)); |
530 | +} |
531 | + |
532 | +nux::Area* WindowButtons::FindAreaUnderMouse(const nux::Point& mouse, nux::NuxEventType event_type) |
533 | +{ |
534 | + /* The first button should be clickable on the left space too, to |
535 | + * make Fitts happy. All also on their top side. See bug #839690 */ |
536 | + bool first_found = false; |
537 | + |
538 | + for (auto area : GetChildren()) |
539 | + { |
540 | + if (area->IsVisible() && area->GetInputEventSensitivity()) |
541 | + { |
542 | + nux::Geometry const& geo = area->GetAbsoluteGeometry(); |
543 | + |
544 | + if (!first_found) |
545 | + { |
546 | + first_found = true; |
547 | + |
548 | + if (mouse.x < geo.x && mouse.y < (geo.y + geo.height)) |
549 | + return area; |
550 | + } |
551 | + |
552 | + if (geo.IsPointInside(mouse.x, mouse.y)) |
553 | + return area; |
554 | + |
555 | + if (mouse.x >= geo.x && mouse.x <= (geo.x + geo.width) && mouse.y <= geo.y) |
556 | + return area; |
557 | + } |
558 | + } |
559 | + |
560 | + return nullptr; |
561 | +} |
562 | + |
563 | +void WindowButtons::OnCloseClicked(nux::Button *button) |
564 | +{ |
565 | + auto win_button = dynamic_cast<WindowButton*>(button); |
566 | + |
567 | + if (!win_button || !win_button->IsEnabled()) |
568 | + return; |
569 | + |
570 | + if (win_button->IsOverlayOpen()) |
571 | + { |
572 | + ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST); |
573 | + } |
574 | + else |
575 | + { |
576 | + WindowManager::Default()->Close(window_xid_); |
577 | + } |
578 | + |
579 | close_clicked.emit(); |
580 | } |
581 | |
582 | -void |
583 | -WindowButtons::OnMinimizeClicked(nux::View* view) |
584 | +void WindowButtons::OnMinimizeClicked(nux::Button *button) |
585 | { |
586 | + auto win_button = dynamic_cast<WindowButton*>(button); |
587 | + |
588 | + if (!win_button || !win_button->IsEnabled()) |
589 | + return; |
590 | + |
591 | + if (!win_button->IsOverlayOpen()) |
592 | + WindowManager::Default()->Minimize(window_xid_); |
593 | + |
594 | minimize_clicked.emit(); |
595 | } |
596 | |
597 | -void |
598 | -WindowButtons::OnRestoreClicked(nux::View* view) |
599 | +void WindowButtons::OnRestoreClicked(nux::Button *button) |
600 | { |
601 | + auto win_button = dynamic_cast<WindowButton*>(button); |
602 | + |
603 | + if (!win_button || !win_button->IsEnabled()) |
604 | + return; |
605 | + |
606 | + if (win_button->IsOverlayOpen()) |
607 | + { |
608 | + dash::Settings::Instance().SetFormFactor(dash::FormFactor::DESKTOP); |
609 | + } |
610 | + else |
611 | + { |
612 | + WindowManager* wm = WindowManager::Default(); |
613 | + Window to_restore = window_xid_; |
614 | + |
615 | + wm->Raise(to_restore); |
616 | + wm->Activate(to_restore); |
617 | + wm->Restore(to_restore); |
618 | + } |
619 | + |
620 | restore_clicked.emit(); |
621 | } |
622 | |
623 | -nux::Area* |
624 | -WindowButtons::FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type) |
625 | -{ |
626 | - return nux::HLayout::FindAreaUnderMouse(mouse_position, event_type); |
627 | -} |
628 | - |
629 | -void |
630 | -WindowButtons::SetOpacity(double opacity) |
631 | +void WindowButtons::OnMaximizeClicked(nux::Button *button) |
632 | +{ |
633 | + auto win_button = dynamic_cast<WindowButton*>(button); |
634 | + |
635 | + if (!win_button || !win_button->IsEnabled()) |
636 | + return; |
637 | + |
638 | + if (win_button->IsOverlayOpen()) |
639 | + { |
640 | + dash::Settings::Instance().SetFormFactor(dash::FormFactor::NETBOOK); |
641 | + } |
642 | + |
643 | + maximize_clicked.emit(); |
644 | +} |
645 | + |
646 | +void WindowButtons::OnOverlayShown(GVariant* data) |
647 | +{ |
648 | + WindowButton* maximize_button = nullptr; |
649 | + WindowButton* restore_button = nullptr; |
650 | + glib::String overlay_identity; |
651 | + gboolean can_maximise = FALSE; |
652 | + gint32 overlay_monitor = 0; |
653 | + g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, |
654 | + &overlay_identity, &can_maximise, &overlay_monitor); |
655 | + |
656 | + if (overlay_monitor != monitor_) |
657 | + { |
658 | + for (auto area : GetChildren()) |
659 | + { |
660 | + auto button = dynamic_cast<WindowButton*>(area); |
661 | + |
662 | + if (button) |
663 | + button->SetEnabled(false); |
664 | + } |
665 | + |
666 | + return; |
667 | + } |
668 | + |
669 | + active_overlay_ = overlay_identity.Str(); |
670 | + |
671 | + for (auto area : GetChildren()) |
672 | + { |
673 | + auto button = dynamic_cast<WindowButton*>(area); |
674 | + |
675 | + if (button) |
676 | + { |
677 | + if (button->GetType() == panel::WindowButtonType::UNMAXIMIZE) |
678 | + restore_button = button; |
679 | + |
680 | + if (button->GetType() == panel::WindowButtonType::MAXIMIZE) |
681 | + maximize_button = button; |
682 | + |
683 | + button->SetOverlayOpen(true); |
684 | + } |
685 | + } |
686 | + |
687 | + if (restore_button && maximize_button) |
688 | + { |
689 | + dash::Settings &dash_settings = dash::Settings::Instance(); |
690 | + bool maximizable = (dash_settings.GetFormFactor() == dash::FormFactor::DESKTOP); |
691 | + |
692 | + restore_button->SetEnabled(can_maximise); |
693 | + maximize_button->SetEnabled(can_maximise); |
694 | + |
695 | + if (maximizable != maximize_button->IsVisible()) |
696 | + { |
697 | + if (maximize_button->IsVisible()) |
698 | + restore_button->SetVisualState(maximize_button->GetVisualState()); |
699 | + else if (restore_button->IsVisible()) |
700 | + maximize_button->SetVisualState(restore_button->GetVisualState()); |
701 | + |
702 | + restore_button->SetVisible(!maximizable); |
703 | + maximize_button->SetVisible(maximizable); |
704 | + |
705 | + QueueDraw(); |
706 | + } |
707 | + } |
708 | +} |
709 | + |
710 | +void WindowButtons::OnOverlayHidden(GVariant* data) |
711 | +{ |
712 | + WindowButton* maximize_button = nullptr; |
713 | + WindowButton* restore_button = nullptr; |
714 | + |
715 | + glib::String overlay_identity; |
716 | + gboolean can_maximise = FALSE; |
717 | + gint32 overlay_monitor = 0; |
718 | + g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, |
719 | + &overlay_identity, &can_maximise, &overlay_monitor); |
720 | + |
721 | + if (overlay_monitor != monitor_) |
722 | + { |
723 | + for (auto area : GetChildren()) |
724 | + { |
725 | + auto button = dynamic_cast<WindowButton*>(area); |
726 | + |
727 | + if (button) |
728 | + button->SetEnabled(true); |
729 | + } |
730 | + } |
731 | + |
732 | + if (active_overlay_ != overlay_identity.Str()) |
733 | + return; |
734 | + |
735 | + active_overlay_ = ""; |
736 | + |
737 | + for (auto area : GetChildren()) |
738 | + { |
739 | + auto button = dynamic_cast<WindowButton*>(area); |
740 | + |
741 | + if (button) |
742 | + { |
743 | + if (button->GetType() == panel::WindowButtonType::UNMAXIMIZE) |
744 | + restore_button = button; |
745 | + |
746 | + if (button->GetType() == panel::WindowButtonType::MAXIMIZE) |
747 | + maximize_button = button; |
748 | + |
749 | + button->SetOverlayOpen(false); |
750 | + } |
751 | + } |
752 | + |
753 | + if (restore_button && maximize_button) |
754 | + { |
755 | + restore_button->SetEnabled(true); |
756 | + maximize_button->SetEnabled(true); |
757 | + |
758 | + if (!restore_button->IsVisible()) |
759 | + { |
760 | + restore_button->SetVisualState(maximize_button->GetVisualState()); |
761 | + |
762 | + restore_button->SetVisible(true); |
763 | + maximize_button->SetVisible(false); |
764 | + |
765 | + QueueDraw(); |
766 | + } |
767 | + } |
768 | +} |
769 | + |
770 | +void WindowButtons::OnDashSettingsUpdated() |
771 | +{ |
772 | + WindowButton* maximize_button = nullptr; |
773 | + WindowButton* restore_button = nullptr; |
774 | + |
775 | + for (auto area : GetChildren()) |
776 | + { |
777 | + auto button = dynamic_cast<WindowButton*>(area); |
778 | + |
779 | + if (button) |
780 | + { |
781 | + if (!button->IsOverlayOpen()) |
782 | + break; |
783 | + |
784 | + if (button->GetType() == panel::WindowButtonType::UNMAXIMIZE) |
785 | + restore_button = button; |
786 | + |
787 | + if (button->GetType() == panel::WindowButtonType::MAXIMIZE) |
788 | + maximize_button = button; |
789 | + |
790 | + if (restore_button && maximize_button) |
791 | + break; |
792 | + } |
793 | + } |
794 | + |
795 | + if (restore_button && restore_button->IsOverlayOpen() && maximize_button) |
796 | + { |
797 | + dash::Settings &dash_settings = dash::Settings::Instance(); |
798 | + bool maximizable = (dash_settings.GetFormFactor() == dash::FormFactor::DESKTOP); |
799 | + |
800 | + if (maximizable != maximize_button->IsVisible()) |
801 | + { |
802 | + if (maximize_button->IsVisible()) |
803 | + restore_button->SetVisualState(maximize_button->GetVisualState()); |
804 | + else if (restore_button->IsVisible()) |
805 | + maximize_button->SetVisualState(restore_button->GetVisualState()); |
806 | + |
807 | + restore_button->SetVisible(!maximizable); |
808 | + maximize_button->SetVisible(maximizable); |
809 | + |
810 | + QueueDraw(); |
811 | + } |
812 | + } |
813 | +} |
814 | + |
815 | +void WindowButtons::SetOpacity(double opacity) |
816 | { |
817 | opacity = CLAMP(opacity, 0.0f, 1.0f); |
818 | |
819 | for (auto area : GetChildren()) |
820 | { |
821 | - auto but = dynamic_cast<WindowButton*>(area); |
822 | - |
823 | - if (but) |
824 | - but->SetOpacity(opacity); |
825 | - } |
826 | - |
827 | - if (_opacity != opacity) |
828 | - { |
829 | - _opacity = opacity; |
830 | - NeedRedraw(); |
831 | - } |
832 | -} |
833 | - |
834 | -double |
835 | -WindowButtons::GetOpacity() |
836 | -{ |
837 | - return _opacity; |
838 | -} |
839 | - |
840 | -std::string |
841 | -WindowButtons::GetName() const |
842 | -{ |
843 | - return "window-buttons"; |
844 | -} |
845 | - |
846 | -void |
847 | -WindowButtons::AddProperties(GVariantBuilder* builder) |
848 | -{ |
849 | - unity::variant::BuilderWrapper(builder).add(GetGeometry()); |
850 | -} |
851 | - |
852 | - |
853 | -} // namespace unity |
854 | + auto button = dynamic_cast<WindowButton*>(area); |
855 | + |
856 | + if (button) |
857 | + button->SetOpacity(opacity); |
858 | + } |
859 | + |
860 | + if (opacity_ != opacity) |
861 | + { |
862 | + opacity_ = opacity; |
863 | + QueueDraw(); |
864 | + } |
865 | +} |
866 | + |
867 | +double WindowButtons::GetOpacity() |
868 | +{ |
869 | + return opacity_; |
870 | +} |
871 | + |
872 | +void WindowButtons::SetFocusedState(bool focused) |
873 | +{ |
874 | + for (auto area : GetChildren()) |
875 | + { |
876 | + auto button = dynamic_cast<WindowButton*>(area); |
877 | + |
878 | + if (button) |
879 | + button->SetFocusedState(focused); |
880 | + } |
881 | + |
882 | + if (focused_ != focused) |
883 | + { |
884 | + focused_ = focused; |
885 | + QueueDraw(); |
886 | + } |
887 | +} |
888 | + |
889 | +bool WindowButtons::GetFocusedState() |
890 | +{ |
891 | + return focused_; |
892 | +} |
893 | + |
894 | +void WindowButtons::SetControlledWindow(Window xid) |
895 | +{ |
896 | + if (xid != window_xid_) |
897 | + { |
898 | + window_xid_ = xid; |
899 | + |
900 | + for (auto area : GetChildren()) |
901 | + { |
902 | + auto button = dynamic_cast<WindowButton*>(area); |
903 | + |
904 | + if (button->GetType() == panel::WindowButtonType::MINIMIZE) |
905 | + { |
906 | + bool minimizable = WindowManager::Default()->IsWindowMinimizable(xid); |
907 | + button->SetEnabled(minimizable); |
908 | + break; |
909 | + } |
910 | + } |
911 | + } |
912 | +} |
913 | + |
914 | +Window WindowButtons::GetControlledWindow() |
915 | +{ |
916 | + return window_xid_; |
917 | +} |
918 | + |
919 | +void WindowButtons::SetMonitor(int monitor) |
920 | +{ |
921 | + monitor_ = monitor; |
922 | +} |
923 | + |
924 | +int WindowButtons::GetMonitor() |
925 | +{ |
926 | + return monitor_; |
927 | +} |
928 | + |
929 | +std::string WindowButtons::GetName() const |
930 | +{ |
931 | + return "WindowButtons"; |
932 | +} |
933 | + |
934 | +void WindowButtons::AddProperties(GVariantBuilder* builder) |
935 | +{ |
936 | + variant::BuilderWrapper(builder).add(GetGeometry()) |
937 | + .add("monitor", monitor_) |
938 | + .add("opacity", opacity_) |
939 | + .add("focused", focused_) |
940 | + .add("controlled_window", window_xid_); |
941 | +} |
942 | + |
943 | +} // unity namespace |
944 | |
945 | === modified file 'plugins/unityshell/src/WindowButtons.h' |
946 | --- plugins/unityshell/src/WindowButtons.h 2012-02-25 16:19:39 +0000 |
947 | +++ plugins/unityshell/src/WindowButtons.h 2012-04-04 20:17:24 +0000 |
948 | @@ -1,6 +1,6 @@ |
949 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
950 | /* |
951 | - * Copyright (C) 2010 Canonical Ltd |
952 | + * Copyright (C) 2010-2012 Canonical Ltd |
953 | * |
954 | * This program is free software: you can redistribute it and/or modify |
955 | * it under the terms of the GNU General Public License version 3 as |
956 | @@ -15,49 +15,70 @@ |
957 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
958 | * |
959 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
960 | + * Marco Trevisan (Treviño) <3v1n0@ubuntu.com> |
961 | */ |
962 | |
963 | #ifndef WINDOW_BUTTONS_H |
964 | #define WINDOW_BUTTONS_H |
965 | |
966 | #include <Nux/HLayout.h> |
967 | -#include <Nux/View.h> |
968 | +#include <Nux/Button.h> |
969 | |
970 | +#include "UBusWrapper.h" |
971 | #include "Introspectable.h" |
972 | |
973 | namespace unity |
974 | { |
975 | -class WindowButtons : public nux::HLayout, public unity::debug::Introspectable |
976 | +class WindowButtons : public nux::HLayout, public debug::Introspectable |
977 | { |
978 | // These are the [close][minimize][restore] buttons on the panel when there |
979 | // is a maximized window |
980 | |
981 | public: |
982 | WindowButtons(); |
983 | - ~WindowButtons(); |
984 | |
985 | void SetOpacity(double opacity); |
986 | double GetOpacity(); |
987 | |
988 | + void SetFocusedState(bool focused); |
989 | + bool GetFocusedState(); |
990 | + |
991 | + void SetControlledWindow(Window xid); |
992 | + Window GetControlledWindow(); |
993 | + |
994 | + void SetMonitor(int monitor); |
995 | + int GetMonitor(); |
996 | + |
997 | + virtual nux::Area* FindAreaUnderMouse(const nux::Point& mouse_pos, nux::NuxEventType event_type); |
998 | + |
999 | sigc::signal<void> close_clicked; |
1000 | sigc::signal<void> minimize_clicked; |
1001 | sigc::signal<void> restore_clicked; |
1002 | + sigc::signal<void> maximize_clicked; |
1003 | sigc::signal<void, int, int, int, int, unsigned long, unsigned long> mouse_move; |
1004 | sigc::signal<void, int, int, unsigned long, unsigned long> mouse_enter; |
1005 | sigc::signal<void, int, int, unsigned long, unsigned long> mouse_leave; |
1006 | |
1007 | - virtual nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type); |
1008 | - |
1009 | protected: |
1010 | std::string GetName() const; |
1011 | - void AddProperties(GVariantBuilder* builder); |
1012 | + void AddProperties(GVariantBuilder* builder); |
1013 | |
1014 | private: |
1015 | - void OnCloseClicked(nux::View *view); |
1016 | - void OnMinimizeClicked(nux::View *view); |
1017 | - void OnRestoreClicked(nux::View *view); |
1018 | - |
1019 | - double _opacity; |
1020 | + void OnCloseClicked(nux::Button *button); |
1021 | + void OnMinimizeClicked(nux::Button *button); |
1022 | + void OnRestoreClicked(nux::Button *button); |
1023 | + void OnMaximizeClicked(nux::Button *button); |
1024 | + void OnOverlayShown(GVariant* data); |
1025 | + void OnOverlayHidden(GVariant* data); |
1026 | + void OnDashSettingsUpdated(); |
1027 | + |
1028 | + int monitor_; |
1029 | + double opacity_; |
1030 | + bool focused_; |
1031 | + Window window_xid_; |
1032 | + std::string active_overlay_; |
1033 | + |
1034 | + UBusManager ubus_manager_; |
1035 | }; |
1036 | } |
1037 | #endif |
Looks OK, but I still recommend some real interactive testing :)