Merge lp:~3v1n0/unity/fix-maximimize-button-if-vert-horz into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 4166
Proposed branch: lp:~3v1n0/unity/fix-maximimize-button-if-vert-horz
Merge into: lp:unity
Diff against target: 237 lines (+70/-18)
6 files modified
decorations/DecoratedWindow.cpp (+29/-1)
decorations/DecoratedWindow.h (+1/-0)
decorations/DecorationsPriv.h (+3/-0)
decorations/DecorationsWindowButton.cpp (+34/-15)
decorations/DecorationsWindowButton.h (+2/-1)
plugins/unityshell/src/unityshell.cpp (+1/-1)
To merge this branch: bzr merge lp:~3v1n0/unity/fix-maximimize-button-if-vert-horz
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Andrea Azzarone (community) Approve
Review via email: mp+301768@code.launchpad.net

This proposal supersedes a proposal from 2016-08-01.

Commit message

DecoratedWindow: display unmaximize button if the window is vertically or horizontally maximized

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

Looks good thanks. Just a small problem with indent (see inline comments).

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Updated, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'decorations/DecoratedWindow.cpp'
2--- decorations/DecoratedWindow.cpp 2016-07-27 10:17:42 +0000
3+++ decorations/DecoratedWindow.cpp 2016-08-04 08:55:22 +0000
4@@ -148,6 +148,23 @@
5 bg_textures_.clear();
6 }
7
8+void Window::Impl::UpdateWindowState(unsigned old_state)
9+{
10+ Update();
11+
12+ if (state_change_button_)
13+ {
14+ if (win_->state() & (CompWindowStateMaximizedVertMask|CompWindowStateMaximizedHorzMask))
15+ {
16+ state_change_button_->type = WindowButtonType::UNMAXIMIZE;
17+ }
18+ else
19+ {
20+ state_change_button_->type = WindowButtonType::MAXIMIZE;
21+ }
22+ }
23+}
24+
25 void Window::Impl::UnsetExtents()
26 {
27 if (win_->hasUnmapReference())
28@@ -410,7 +427,13 @@
29 top_layout_->Append(std::make_shared<WindowButton>(win_, WindowButtonType::MINIMIZE));
30
31 if (win_->actions() & (CompWindowActionMaximizeHorzMask|CompWindowActionMaximizeVertMask))
32- top_layout_->Append(std::make_shared<WindowButton>(win_, WindowButtonType::MAXIMIZE));
33+ {
34+ auto type = (win_->state() & (CompWindowStateMaximizedVertMask|CompWindowStateMaximizedHorzMask)) ?
35+ WindowButtonType::UNMAXIMIZE : WindowButtonType::MAXIMIZE;
36+ auto state_change_button = std::make_shared<WindowButton>(win_, type);
37+ top_layout_->Append(state_change_button);
38+ state_change_button_ = state_change_button;
39+ }
40
41 auto title = std::make_shared<Title>();
42 title->text = last_title_.empty() ? WindowManager::Default().GetWindowName(win_->id()) : last_title_;
43@@ -993,6 +1016,11 @@
44 impl_->Update();
45 }
46
47+void Window::UpdateWindowState(unsigned old_state)
48+{
49+ impl_->UpdateWindowState(old_state);
50+}
51+
52 void Window::UpdateFrameRegion(CompRegion& r)
53 {
54 if (impl_->frame_region_.isEmpty())
55
56=== modified file 'decorations/DecoratedWindow.h'
57--- decorations/DecoratedWindow.h 2016-02-19 04:03:51 +0000
58+++ decorations/DecoratedWindow.h 2016-08-04 08:55:22 +0000
59@@ -53,6 +53,7 @@
60 void UpdateDecorationPositionDelayed();
61 void UpdateFrameRegion(CompRegion&);
62 void UpdateOutputExtents(compiz::window::extents::Extents&);
63+ void UpdateWindowState(unsigned old_state);
64 void Paint(GLMatrix const&, GLWindowPaintAttrib const&, CompRegion const&, unsigned mask);
65 void Draw(GLMatrix const&, GLWindowPaintAttrib const&, CompRegion const&, unsigned mask);
66
67
68=== modified file 'decorations/DecorationsPriv.h'
69--- decorations/DecorationsPriv.h 2016-07-26 11:33:50 +0000
70+++ decorations/DecorationsPriv.h 2016-08-04 08:55:22 +0000
71@@ -49,6 +49,7 @@
72 class MenuLayout;
73 class SlidingLayout;
74 class ForceQuitDialog;
75+class WindowButton;
76
77 namespace cu = compiz_utils;
78
79@@ -102,6 +103,7 @@
80 void SetupExtents();
81 void ComputeBorderExtent(CompWindowExtents &border);
82 void UpdateElements(cu::WindowFilter wf = cu::WindowFilter::NONE);
83+ void UpdateWindowState(unsigned old_state);
84 void UpdateClientDecorationsState();
85 void UpdateMonitor();
86 void UpdateFrame();
87@@ -164,6 +166,7 @@
88 std::shared_ptr<ForceQuitDialog> force_quit_;
89 InputMixer::Ptr input_mixer_;
90 Layout::Ptr top_layout_;
91+ uweak_ptr<WindowButton> state_change_button_;
92 uweak_ptr<MenuLayout> menus_;
93 uweak_ptr<Title> title_;
94 uweak_ptr<SlidingLayout> sliding_layout_;
95
96=== modified file 'decorations/DecorationsWindowButton.cpp'
97--- decorations/DecorationsWindowButton.cpp 2014-02-27 07:11:16 +0000
98+++ decorations/DecorationsWindowButton.cpp 2016-08-04 08:55:22 +0000
99@@ -29,8 +29,8 @@
100 namespace decoration
101 {
102
103-WindowButton::WindowButton(CompWindow* win, WindowButtonType type)
104- : type_(type)
105+WindowButton::WindowButton(CompWindow* win, WindowButtonType wbt)
106+ : type(wbt)
107 , pressed_(false)
108 , was_pressed_(false)
109 , win_(win)
110@@ -39,12 +39,13 @@
111 mouse_owner.changed.connect(cb);
112 focused.changed.connect(cb);
113 scale.changed.connect(cb);
114+ type.changed.connect(cb);
115 UpdateTexture();
116 }
117
118 void WindowButton::UpdateTexture()
119 {
120- SetTexture(DataPool::Get()->ButtonTexture(scale(), type_, GetCurrentState()));
121+ SetTexture(DataPool::Get()->ButtonTexture(scale(), type(), GetCurrentState()));
122 }
123
124 WidgetState WindowButton::GetCurrentState() const
125@@ -98,7 +99,7 @@
126 pressed_ = false;
127 UpdateTexture();
128
129- switch (type_)
130+ switch (type())
131 {
132 case WindowButtonType::CLOSE:
133 if (win_->actions() & CompWindowActionCloseMask)
134@@ -112,32 +113,50 @@
135 switch (button)
136 {
137 case Button1:
138- if ((win_->state() & CompWindowStateMaximizedVertMask) ||
139- (win_->state() & CompWindowStateMaximizedHorzMask))
140- win_->maximize(0);
141- else if (win_->actions() & (CompWindowActionMaximizeHorzMask|CompWindowActionMaximizeVertMask))
142+ if (win_->actions() & (CompWindowActionMaximizeHorzMask|CompWindowActionMaximizeVertMask))
143 win_->maximize(MAXIMIZE_STATE);
144 break;
145 case Button2:
146 if (win_->actions() & CompWindowActionMaximizeVertMask)
147 {
148 if (!(win_->state() & CompWindowStateMaximizedVertMask))
149- win_->maximize(CompWindowStateMaximizedVertMask);
150- else
151- win_->maximize(0);
152+ win_->maximize(win_->state() | CompWindowStateMaximizedVertMask);
153 }
154 break;
155 case Button3:
156 if (win_->actions() & CompWindowActionMaximizeHorzMask)
157 {
158 if (!(win_->state() & CompWindowStateMaximizedHorzMask))
159- win_->maximize(CompWindowStateMaximizedHorzMask);
160- else
161- win_->maximize(0);
162+ win_->maximize(win_->state() | CompWindowStateMaximizedHorzMask);
163 }
164 break;
165 }
166 break;
167+ case WindowButtonType::UNMAXIMIZE:
168+ switch (button)
169+ {
170+ case Button1:
171+ win_->maximize(0);
172+ break;
173+ case Button2:
174+ if (win_->actions() & CompWindowActionMaximizeVertMask)
175+ {
176+ if (!(win_->state() & CompWindowStateMaximizedVertMask))
177+ win_->maximize(win_->state() | CompWindowStateMaximizedVertMask);
178+ else
179+ win_->maximize(win_->state() & ~CompWindowStateMaximizedVertMask);
180+ }
181+ break;
182+ case Button3:
183+ if (win_->actions() & CompWindowActionMaximizeHorzMask)
184+ {
185+ if (!(win_->state() & CompWindowStateMaximizedHorzMask))
186+ win_->maximize(win_->state() | CompWindowStateMaximizedHorzMask);
187+ else
188+ win_->maximize(win_->state() & ~CompWindowStateMaximizedHorzMask);
189+ }
190+ break;
191+ }
192 default:
193 break;
194 }
195@@ -168,7 +187,7 @@
196
197 std::string WindowButton::GetName() const
198 {
199- switch (type_)
200+ switch (type())
201 {
202 case WindowButtonType::CLOSE:
203 return "CloseWindowButton";
204
205=== modified file 'decorations/DecorationsWindowButton.h'
206--- decorations/DecorationsWindowButton.h 2014-02-19 00:03:24 +0000
207+++ decorations/DecorationsWindowButton.h 2016-08-04 08:55:22 +0000
208@@ -33,6 +33,8 @@
209 public:
210 WindowButton(CompWindow*, WindowButtonType type);
211
212+ nux::Property<WindowButtonType> type;
213+
214 WidgetState GetCurrentState() const;
215
216 protected:
217@@ -46,7 +48,6 @@
218 private:
219 void UpdateTexture();
220
221- WindowButtonType type_;
222 bool pressed_;
223 bool was_pressed_;
224 CompWindow* win_;
225
226=== modified file 'plugins/unityshell/src/unityshell.cpp'
227--- plugins/unityshell/src/unityshell.cpp 2016-07-27 10:24:41 +0000
228+++ plugins/unityshell/src/unityshell.cpp 2016-08-04 08:55:22 +0000
229@@ -3421,7 +3421,7 @@
230 uScreen->fullscreen_windows_.remove(window);
231 }
232
233- deco_win_->Update();
234+ deco_win_->UpdateWindowState(lastState);
235 PluginAdapter::Default().NotifyStateChange(window, window->state(), lastState);
236 window->stateChangeNotify(lastState);
237 }