Merge lp:~unity-team/unity/panel-fixes-2010-12-07 into lp:unity
- panel-fixes-2010-12-07
- Merge into trunk
Status: | Merged | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | Gord Allott | ||||||||||||||||||||
Approved revision: | no longer in the source branch. | ||||||||||||||||||||
Merged at revision: | 722 | ||||||||||||||||||||
Proposed branch: | lp:~unity-team/unity/panel-fixes-2010-12-07 | ||||||||||||||||||||
Merge into: | lp:unity | ||||||||||||||||||||
Diff against target: |
1845 lines (+1499/-47) 20 files modified
src/IndicatorObjectEntryProxy.h (+2/-1) src/IndicatorObjectEntryProxyRemote.cpp (+3/-2) src/IndicatorObjectFactory.h (+1/-0) src/IndicatorObjectFactoryRemote.cpp (+3/-1) src/PanelIndicatorObjectEntryView.cpp (+8/-4) src/PanelIndicatorObjectEntryView.h (+7/-0) src/PanelIndicatorObjectView.cpp (+7/-0) src/PanelIndicatorObjectView.h (+1/-1) src/PanelMenuView.cpp (+671/-0) src/PanelMenuView.h (+103/-0) src/PanelView.cpp (+48/-32) src/PanelView.h (+3/-0) src/PluginAdapter.cpp (+77/-4) src/PluginAdapter.h (+10/-1) src/WindowButtons.cpp (+254/-0) src/WindowButtons.h (+63/-0) src/WindowManager.cpp (+171/-0) src/WindowManager.h (+57/-0) src/unity.cpp (+2/-1) tests/CMakeLists.txt (+8/-0) |
||||||||||||||||||||
To merge this branch: | bzr merge lp:~unity-team/unity/panel-fixes-2010-12-07 | ||||||||||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity Team | Pending | ||
Review via email: mp+44015@code.launchpad.net |
Commit message
Description of the change
This implements the panel menubar as per spec.
The things to check for:
1. Unmaximised window + no mouse hover over panel = Application name
2. Unmaximised window + mouse hover over panel = Menus (and they work)
3. Unmaximised window + no mouse hover + Alt+F (or whatever) = Menus show
4. Maximised window + no mouse = no decorations + usable close/min/restore buttons + window *title*
5. Maximised window + mouse = no decs + usable close/min/restore buttons + menu
6. Maximised window + no mouse + Alt+F (i.e.) = no decs + usable buttons + menu
7. Maximised window + click on restore = restored decorations on floating window
Notes:
- Windows that were already undecorated should be unaffected by max/restore (i.e. restore shouldn't add decorations, chromium with non-system-borders enabled is a good test)
- Transmission goes weird when trying to restore decorations, need to investigate
- Interaction is weird with desktop, sometimes you get "Unknown"
Neil J. Patel (njpatel) wrote : | # |
Gord Allott (gordallott) wrote : | # |
noting: Nux: [Object:
Preview Diff
1 | === modified file 'src/IndicatorObjectEntryProxy.h' | |||
2 | --- src/IndicatorObjectEntryProxy.h 2010-11-11 15:07:58 +0000 | |||
3 | +++ src/IndicatorObjectEntryProxy.h 2010-12-17 10:43:24 +0000 | |||
4 | @@ -36,7 +36,8 @@ | |||
5 | 36 | virtual void ShowMenu (int x, int y, guint32 timestamp, guint32 button) = 0; | 36 | virtual void ShowMenu (int x, int y, guint32 timestamp, guint32 button) = 0; |
6 | 37 | 37 | ||
7 | 38 | // Signals | 38 | // Signals |
9 | 39 | sigc::signal<void> Updated; | 39 | sigc::signal<void> updated; |
10 | 40 | sigc::signal<void, bool> active_changed; | ||
11 | 40 | 41 | ||
12 | 41 | public: | 42 | public: |
13 | 42 | bool label_visible; | 43 | bool label_visible; |
14 | 43 | 44 | ||
15 | === modified file 'src/IndicatorObjectEntryProxyRemote.cpp' | |||
16 | --- src/IndicatorObjectEntryProxyRemote.cpp 2010-11-17 20:12:42 +0000 | |||
17 | +++ src/IndicatorObjectEntryProxyRemote.cpp 2010-12-17 10:43:24 +0000 | |||
18 | @@ -104,7 +104,8 @@ | |||
19 | 104 | 104 | ||
20 | 105 | _active = active; | 105 | _active = active; |
21 | 106 | 106 | ||
23 | 107 | Updated.emit (); | 107 | active_changed.emit (active); |
24 | 108 | updated.emit (); | ||
25 | 108 | } | 109 | } |
26 | 109 | 110 | ||
27 | 110 | bool | 111 | bool |
28 | @@ -141,7 +142,7 @@ | |||
29 | 141 | icon_sensitive = __image_sensitive; | 142 | icon_sensitive = __image_sensitive; |
30 | 142 | icon_visible = __image_visible; | 143 | icon_visible = __image_visible; |
31 | 143 | 144 | ||
33 | 144 | Updated.emit (); | 145 | updated.emit (); |
34 | 145 | } | 146 | } |
35 | 146 | 147 | ||
36 | 147 | const char * | 148 | const char * |
37 | 148 | 149 | ||
38 | === modified file 'src/IndicatorObjectFactory.h' | |||
39 | --- src/IndicatorObjectFactory.h 2010-12-07 13:55:04 +0000 | |||
40 | +++ src/IndicatorObjectFactory.h 2010-12-17 10:43:24 +0000 | |||
41 | @@ -45,6 +45,7 @@ | |||
42 | 45 | sigc::signal<void, IndicatorObjectProxy *> OnObjectRemoved; | 45 | sigc::signal<void, IndicatorObjectProxy *> OnObjectRemoved; |
43 | 46 | sigc::signal<void, int, int> OnMenuPointerMoved; | 46 | sigc::signal<void, int, int> OnMenuPointerMoved; |
44 | 47 | sigc::signal<void, const char *> OnEntryActivateRequest; | 47 | sigc::signal<void, const char *> OnEntryActivateRequest; |
45 | 48 | sigc::signal<void, const char *> OnEntryActivated; | ||
46 | 48 | 49 | ||
47 | 49 | protected: | 50 | protected: |
48 | 50 | std::vector<IndicatorObjectProxy *>_indicators; | 51 | std::vector<IndicatorObjectProxy *>_indicators; |
49 | 51 | 52 | ||
50 | === modified file 'src/IndicatorObjectFactoryRemote.cpp' | |||
51 | --- src/IndicatorObjectFactoryRemote.cpp 2010-12-13 19:53:58 +0000 | |||
52 | +++ src/IndicatorObjectFactoryRemote.cpp 2010-12-17 10:43:24 +0000 | |||
53 | @@ -239,7 +239,9 @@ | |||
54 | 239 | 239 | ||
55 | 240 | entry->SetActive (g_strcmp0 (entry_id, entry->GetId ()) == 0); | 240 | entry->SetActive (g_strcmp0 (entry_id, entry->GetId ()) == 0); |
56 | 241 | } | 241 | } |
58 | 242 | } | 242 | } |
59 | 243 | |||
60 | 244 | IndicatorObjectFactory::OnEntryActivated.emit (entry_id); | ||
61 | 243 | } | 245 | } |
62 | 244 | 246 | ||
63 | 245 | void | 247 | void |
64 | 246 | 248 | ||
65 | === modified file 'src/PanelIndicatorObjectEntryView.cpp' | |||
66 | --- src/PanelIndicatorObjectEntryView.cpp 2010-12-07 15:01:07 +0000 | |||
67 | +++ src/PanelIndicatorObjectEntryView.cpp 2010-12-17 10:43:24 +0000 | |||
68 | @@ -31,9 +31,6 @@ | |||
69 | 31 | #include <gtk/gtk.h> | 31 | #include <gtk/gtk.h> |
70 | 32 | #include <time.h> | 32 | #include <time.h> |
71 | 33 | 33 | ||
72 | 34 | #define PANEL_HEIGHT 24 | ||
73 | 35 | #define PADDING 6 | ||
74 | 36 | #define SPACING 3 | ||
75 | 37 | 34 | ||
76 | 38 | static void draw_menu_bg (cairo_t *cr, int width, int height); | 35 | static void draw_menu_bg (cairo_t *cr, int width, int height); |
77 | 39 | 36 | ||
78 | @@ -43,7 +40,8 @@ | |||
79 | 43 | _proxy (proxy), | 40 | _proxy (proxy), |
80 | 44 | _util_cg (CAIRO_FORMAT_ARGB32, 1, 1) | 41 | _util_cg (CAIRO_FORMAT_ARGB32, 1, 1) |
81 | 45 | { | 42 | { |
83 | 46 | _proxy->Updated.connect (sigc::mem_fun (this, &PanelIndicatorObjectEntryView::Refresh)); | 43 | _proxy->active_changed.connect (sigc::mem_fun (this, &PanelIndicatorObjectEntryView::OnActiveChanged)); |
84 | 44 | _proxy->updated.connect (sigc::mem_fun (this, &PanelIndicatorObjectEntryView::Refresh)); | ||
85 | 47 | 45 | ||
86 | 48 | InputArea::OnMouseDown.connect (sigc::mem_fun (this, &PanelIndicatorObjectEntryView::OnMouseDown)); | 46 | InputArea::OnMouseDown.connect (sigc::mem_fun (this, &PanelIndicatorObjectEntryView::OnMouseDown)); |
87 | 49 | 47 | ||
88 | @@ -55,6 +53,12 @@ | |||
89 | 55 | } | 53 | } |
90 | 56 | 54 | ||
91 | 57 | void | 55 | void |
92 | 56 | PanelIndicatorObjectEntryView::OnActiveChanged (bool is_active) | ||
93 | 57 | { | ||
94 | 58 | active_changed.emit (this, is_active); | ||
95 | 59 | } | ||
96 | 60 | |||
97 | 61 | void | ||
98 | 58 | PanelIndicatorObjectEntryView::OnMouseDown (int x, int y, long button_flags, long key_flags) | 62 | PanelIndicatorObjectEntryView::OnMouseDown (int x, int y, long button_flags, long key_flags) |
99 | 59 | { | 63 | { |
100 | 60 | if (_proxy->GetActive ()) | 64 | if (_proxy->GetActive ()) |
101 | 61 | 65 | ||
102 | === modified file 'src/PanelIndicatorObjectEntryView.h' | |||
103 | --- src/PanelIndicatorObjectEntryView.h 2010-12-07 13:55:04 +0000 | |||
104 | +++ src/PanelIndicatorObjectEntryView.h 2010-12-17 10:43:24 +0000 | |||
105 | @@ -28,6 +28,10 @@ | |||
106 | 28 | 28 | ||
107 | 29 | #include "Introspectable.h" | 29 | #include "Introspectable.h" |
108 | 30 | 30 | ||
109 | 31 | #define PANEL_HEIGHT 24 | ||
110 | 32 | #define PADDING 6 | ||
111 | 33 | #define SPACING 3 | ||
112 | 34 | |||
113 | 31 | class PanelIndicatorObjectEntryView : public nux::TextureArea, public Introspectable | 35 | class PanelIndicatorObjectEntryView : public nux::TextureArea, public Introspectable |
114 | 32 | { | 36 | { |
115 | 33 | public: | 37 | public: |
116 | @@ -37,10 +41,13 @@ | |||
117 | 37 | void Refresh (); | 41 | void Refresh (); |
118 | 38 | void OnMouseDown (int x, int y, long button_flags, long key_flags); | 42 | void OnMouseDown (int x, int y, long button_flags, long key_flags); |
119 | 39 | void Activate (); | 43 | void Activate (); |
120 | 44 | void OnActiveChanged (bool is_active); | ||
121 | 40 | 45 | ||
122 | 41 | const gchar * GetName (); | 46 | const gchar * GetName (); |
123 | 42 | void AddProperties (GVariantBuilder *builder); | 47 | void AddProperties (GVariantBuilder *builder); |
124 | 43 | 48 | ||
125 | 49 | sigc::signal<void, PanelIndicatorObjectEntryView *, bool> active_changed; | ||
126 | 50 | |||
127 | 44 | public: | 51 | public: |
128 | 45 | IndicatorObjectEntryProxy *_proxy; | 52 | IndicatorObjectEntryProxy *_proxy; |
129 | 46 | private: | 53 | private: |
130 | 47 | 54 | ||
131 | === modified file 'src/PanelIndicatorObjectView.cpp' | |||
132 | --- src/PanelIndicatorObjectView.cpp 2010-12-02 11:55:02 +0000 | |||
133 | +++ src/PanelIndicatorObjectView.cpp 2010-12-17 10:43:24 +0000 | |||
134 | @@ -30,6 +30,13 @@ | |||
135 | 30 | 30 | ||
136 | 31 | #include <glib.h> | 31 | #include <glib.h> |
137 | 32 | 32 | ||
138 | 33 | PanelIndicatorObjectView::PanelIndicatorObjectView () | ||
139 | 34 | : View (NUX_TRACKER_LOCATION), | ||
140 | 35 | _proxy (NULL), | ||
141 | 36 | _entries () | ||
142 | 37 | { | ||
143 | 38 | } | ||
144 | 39 | |||
145 | 33 | PanelIndicatorObjectView::PanelIndicatorObjectView (IndicatorObjectProxy *proxy) | 40 | PanelIndicatorObjectView::PanelIndicatorObjectView (IndicatorObjectProxy *proxy) |
146 | 34 | : View (NUX_TRACKER_LOCATION), | 41 | : View (NUX_TRACKER_LOCATION), |
147 | 35 | _proxy (proxy), | 42 | _proxy (proxy), |
148 | 36 | 43 | ||
149 | === modified file 'src/PanelIndicatorObjectView.h' | |||
150 | --- src/PanelIndicatorObjectView.h 2010-12-02 11:55:02 +0000 | |||
151 | +++ src/PanelIndicatorObjectView.h 2010-12-17 10:43:24 +0000 | |||
152 | @@ -29,6 +29,7 @@ | |||
153 | 29 | class PanelIndicatorObjectView : public nux::View, public Introspectable | 29 | class PanelIndicatorObjectView : public nux::View, public Introspectable |
154 | 30 | { | 30 | { |
155 | 31 | public: | 31 | public: |
156 | 32 | PanelIndicatorObjectView (); | ||
157 | 32 | PanelIndicatorObjectView (IndicatorObjectProxy *proxy); | 33 | PanelIndicatorObjectView (IndicatorObjectProxy *proxy); |
158 | 33 | ~PanelIndicatorObjectView (); | 34 | ~PanelIndicatorObjectView (); |
159 | 34 | 35 | ||
160 | @@ -47,7 +48,6 @@ | |||
161 | 47 | const gchar * GetChildsName (); | 48 | const gchar * GetChildsName (); |
162 | 48 | void AddProperties (GVariantBuilder *builder); | 49 | void AddProperties (GVariantBuilder *builder); |
163 | 49 | 50 | ||
164 | 50 | private: | ||
165 | 51 | IndicatorObjectProxy *_proxy; | 51 | IndicatorObjectProxy *_proxy; |
166 | 52 | std::vector<PanelIndicatorObjectEntryView *> _entries; | 52 | std::vector<PanelIndicatorObjectEntryView *> _entries; |
167 | 53 | }; | 53 | }; |
168 | 54 | 54 | ||
169 | === added file 'src/PanelMenuView.cpp' | |||
170 | --- src/PanelMenuView.cpp 1970-01-01 00:00:00 +0000 | |||
171 | +++ src/PanelMenuView.cpp 2010-12-17 10:43:24 +0000 | |||
172 | @@ -0,0 +1,671 @@ | |||
173 | 1 | /* | ||
174 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
175 | 3 | * | ||
176 | 4 | * This program is free software: you can redistribute it and/or modify | ||
177 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
178 | 6 | * published by the Free Software Foundation. | ||
179 | 7 | * | ||
180 | 8 | * This program is distributed in the hope that it will be useful, | ||
181 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
182 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
183 | 11 | * GNU General Public License for more details. | ||
184 | 12 | * | ||
185 | 13 | * You should have received a copy of the GNU General Public License | ||
186 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
187 | 15 | * | ||
188 | 16 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | ||
189 | 17 | */ | ||
190 | 18 | #include <glib.h> | ||
191 | 19 | #include <pango/pangocairo.h> | ||
192 | 20 | #include <gtk/gtk.h> | ||
193 | 21 | |||
194 | 22 | #include "Nux/Nux.h" | ||
195 | 23 | #include "Nux/HLayout.h" | ||
196 | 24 | #include "Nux/VLayout.h" | ||
197 | 25 | #include <Nux/TextureArea.h> | ||
198 | 26 | |||
199 | 27 | #include "NuxGraphics/GLThread.h" | ||
200 | 28 | #include "Nux/BaseWindow.h" | ||
201 | 29 | #include "Nux/WindowCompositor.h" | ||
202 | 30 | |||
203 | 31 | #include "PanelMenuView.h" | ||
204 | 32 | |||
205 | 33 | #include "WindowManager.h" | ||
206 | 34 | |||
207 | 35 | #include "IndicatorObjectEntryProxy.h" | ||
208 | 36 | |||
209 | 37 | #include <gio/gdesktopappinfo.h> | ||
210 | 38 | |||
211 | 39 | #define BUTTONS_WIDTH 72 | ||
212 | 40 | |||
213 | 41 | static void on_active_window_changed (BamfMatcher *matcher, | ||
214 | 42 | BamfView *old_view, | ||
215 | 43 | BamfView *new_view, | ||
216 | 44 | PanelMenuView *self); | ||
217 | 45 | |||
218 | 46 | |||
219 | 47 | PanelMenuView::PanelMenuView () | ||
220 | 48 | : _matcher (NULL), | ||
221 | 49 | _title_layer (NULL), | ||
222 | 50 | _util_cg (CAIRO_FORMAT_ARGB32, 1, 1), | ||
223 | 51 | _gradient_texture (NULL), | ||
224 | 52 | _title_tex (NULL), | ||
225 | 53 | _is_inside (false), | ||
226 | 54 | _is_maximized (false), | ||
227 | 55 | _last_active_view (NULL) | ||
228 | 56 | { | ||
229 | 57 | WindowManager *win_manager; | ||
230 | 58 | |||
231 | 59 | _matcher = bamf_matcher_get_default (); | ||
232 | 60 | g_signal_connect (_matcher, "active-window-changed", | ||
233 | 61 | G_CALLBACK (on_active_window_changed), this); | ||
234 | 62 | |||
235 | 63 | _menu_layout = new nux::HLayout ("", NUX_TRACKER_LOCATION); | ||
236 | 64 | |||
237 | 65 | /* This is for our parent and for PanelView to read indicator entries, we | ||
238 | 66 | * shouldn't touch this again | ||
239 | 67 | */ | ||
240 | 68 | _layout = _menu_layout; | ||
241 | 69 | |||
242 | 70 | _window_buttons = new WindowButtons (); | ||
243 | 71 | _window_buttons->NeedRedraw (); | ||
244 | 72 | _window_buttons->close_clicked.connect (sigc::mem_fun (this, &PanelMenuView::OnCloseClicked)); | ||
245 | 73 | _window_buttons->minimize_clicked.connect (sigc::mem_fun (this, &PanelMenuView::OnMinimizeClicked)); | ||
246 | 74 | _window_buttons->restore_clicked.connect (sigc::mem_fun (this, &PanelMenuView::OnRestoreClicked)); | ||
247 | 75 | _window_buttons->redraw_signal.connect (sigc::mem_fun (this, &PanelMenuView::OnWindowButtonsRedraw)); | ||
248 | 76 | |||
249 | 77 | win_manager = WindowManager::Default (); | ||
250 | 78 | win_manager->window_maximized.connect (sigc::mem_fun (this, &PanelMenuView::OnWindowMaximized)); | ||
251 | 79 | win_manager->window_restored.connect (sigc::mem_fun (this, &PanelMenuView::OnWindowRestored)); | ||
252 | 80 | win_manager->window_unmapped.connect (sigc::mem_fun (this, &PanelMenuView::OnWindowUnmapped)); | ||
253 | 81 | |||
254 | 82 | Refresh (); | ||
255 | 83 | } | ||
256 | 84 | |||
257 | 85 | PanelMenuView::~PanelMenuView () | ||
258 | 86 | { | ||
259 | 87 | if (_title_layer) | ||
260 | 88 | delete _title_layer; | ||
261 | 89 | if (_title_tex) | ||
262 | 90 | _title_tex->UnReference (); | ||
263 | 91 | |||
264 | 92 | _menu_layout->UnReference (); | ||
265 | 93 | _window_buttons->UnReference (); | ||
266 | 94 | } | ||
267 | 95 | |||
268 | 96 | void | ||
269 | 97 | PanelMenuView::FullRedraw () | ||
270 | 98 | { | ||
271 | 99 | _menu_layout->NeedRedraw (); | ||
272 | 100 | _window_buttons->NeedRedraw (); | ||
273 | 101 | NeedRedraw (); | ||
274 | 102 | } | ||
275 | 103 | |||
276 | 104 | void | ||
277 | 105 | PanelMenuView::SetProxy (IndicatorObjectProxy *proxy) | ||
278 | 106 | { | ||
279 | 107 | _proxy = proxy; | ||
280 | 108 | printf ("IndicatorAdded: %s\n", _proxy->GetName ().c_str ()); | ||
281 | 109 | |||
282 | 110 | _proxy->OnEntryAdded.connect (sigc::mem_fun (this, &PanelMenuView::OnEntryAdded)); | ||
283 | 111 | _proxy->OnEntryMoved.connect (sigc::mem_fun (this, &PanelMenuView::OnEntryMoved)); | ||
284 | 112 | _proxy->OnEntryRemoved.connect (sigc::mem_fun (this, &PanelMenuView::OnEntryRemoved)); | ||
285 | 113 | } | ||
286 | 114 | |||
287 | 115 | long | ||
288 | 116 | PanelMenuView::ProcessEvent (nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo) | ||
289 | 117 | { | ||
290 | 118 | long ret = TraverseInfo; | ||
291 | 119 | nux::Geometry geo = GetGeometry (); | ||
292 | 120 | |||
293 | 121 | if (geo.IsPointInside (ievent.e_x, ievent.e_y)) | ||
294 | 122 | { | ||
295 | 123 | if (_is_inside != true) | ||
296 | 124 | { | ||
297 | 125 | _is_inside = true; | ||
298 | 126 | FullRedraw (); | ||
299 | 127 | } | ||
300 | 128 | } | ||
301 | 129 | else | ||
302 | 130 | { | ||
303 | 131 | if (_is_inside != false) | ||
304 | 132 | { | ||
305 | 133 | _is_inside = false; | ||
306 | 134 | FullRedraw (); | ||
307 | 135 | } | ||
308 | 136 | } | ||
309 | 137 | |||
310 | 138 | if (_is_maximized) | ||
311 | 139 | ret = _window_buttons->ProcessEvent (ievent, ret, ProcessEventInfo); | ||
312 | 140 | ret = _menu_layout->ProcessEvent (ievent, ret, ProcessEventInfo); | ||
313 | 141 | |||
314 | 142 | return ret; | ||
315 | 143 | } | ||
316 | 144 | |||
317 | 145 | long PanelMenuView::PostLayoutManagement (long LayoutResult) | ||
318 | 146 | { | ||
319 | 147 | long res = View::PostLayoutManagement (LayoutResult); | ||
320 | 148 | int w = _window_buttons->GetContentWidth (); | ||
321 | 149 | |||
322 | 150 | nux::Geometry geo = GetGeometry (); | ||
323 | 151 | |||
324 | 152 | _window_buttons->SetGeometry (geo.x + PADDING, geo.y, w, geo.height); | ||
325 | 153 | _window_buttons->ComputeLayout2 (); | ||
326 | 154 | |||
327 | 155 | /* Explicitly set the size and position of the widgets */ | ||
328 | 156 | geo.x += PADDING + w + PADDING; | ||
329 | 157 | geo.width -= PADDING + w + PADDING; | ||
330 | 158 | |||
331 | 159 | _menu_layout->SetGeometry (geo.x, geo.y, geo.width, geo.height); | ||
332 | 160 | _menu_layout->ComputeLayout2(); | ||
333 | 161 | |||
334 | 162 | Refresh (); | ||
335 | 163 | |||
336 | 164 | return res; | ||
337 | 165 | } | ||
338 | 166 | |||
339 | 167 | void | ||
340 | 168 | PanelMenuView::Draw (nux::GraphicsEngine& GfxContext, bool force_draw) | ||
341 | 169 | { | ||
342 | 170 | nux::Geometry geo = GetGeometry (); | ||
343 | 171 | int button_width = PADDING + _window_buttons->GetContentWidth () + PADDING; | ||
344 | 172 | float factor = 4; | ||
345 | 173 | button_width /= factor; | ||
346 | 174 | |||
347 | 175 | GfxContext.PushClippingRectangle (geo); | ||
348 | 176 | |||
349 | 177 | /* "Clear" out the background */ | ||
350 | 178 | nux::ROPConfig rop; | ||
351 | 179 | rop.Blend = true; | ||
352 | 180 | rop.SrcBlend = GL_ONE; | ||
353 | 181 | rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; | ||
354 | 182 | |||
355 | 183 | nux::ColorLayer layer (nux::Color (0x00000000), true, rop); | ||
356 | 184 | gPainter.PushDrawLayer (GfxContext, GetGeometry (), &layer); | ||
357 | 185 | |||
358 | 186 | if (_is_maximized) | ||
359 | 187 | { | ||
360 | 188 | if (!_is_inside) | ||
361 | 189 | gPainter.PushDrawLayer (GfxContext, GetGeometry (), _title_layer); | ||
362 | 190 | } | ||
363 | 191 | else | ||
364 | 192 | { | ||
365 | 193 | if (_is_inside || _last_active_view) | ||
366 | 194 | { | ||
367 | 195 | if (_gradient_texture == NULL) | ||
368 | 196 | { | ||
369 | 197 | nux::NTextureData texture_data (nux::BITFMT_R8G8B8A8, geo.width, 1, 1); | ||
370 | 198 | nux::ImageSurface surface = texture_data.GetSurface (0); | ||
371 | 199 | nux::SURFACE_LOCKED_RECT lockrect; | ||
372 | 200 | BYTE *dest; | ||
373 | 201 | int num_row; | ||
374 | 202 | |||
375 | 203 | _gradient_texture = nux::GetThreadGLDeviceFactory ()->CreateSystemCapableDeviceTexture (texture_data.GetWidth (), texture_data.GetHeight (), 1, texture_data.GetFormat ()); | ||
376 | 204 | |||
377 | 205 | _gradient_texture->LockRect (0, &lockrect, 0); | ||
378 | 206 | |||
379 | 207 | dest = (BYTE *) lockrect.pBits; | ||
380 | 208 | num_row = surface.GetBlockHeight (); | ||
381 | 209 | |||
382 | 210 | for (int y = 0; y < num_row; y++) | ||
383 | 211 | { | ||
384 | 212 | for (int x = 0; x < geo.width; x++) | ||
385 | 213 | { | ||
386 | 214 | *(dest + y * lockrect.Pitch + 4*x + 0) = 223; //red | ||
387 | 215 | *(dest + y * lockrect.Pitch + 4*x + 1) = 219; //green | ||
388 | 216 | *(dest + y * lockrect.Pitch + 4*x + 2) = 210; //blue | ||
389 | 217 | |||
390 | 218 | if (x < button_width * (factor - 1)) | ||
391 | 219 | { | ||
392 | 220 | *(dest + y * lockrect.Pitch + 4*x + 3) = 0xff; | ||
393 | 221 | } | ||
394 | 222 | else if (x < button_width * factor) | ||
395 | 223 | { | ||
396 | 224 | *(dest + y * lockrect.Pitch + 4*x + 3) = 255 - 255 * (((float)x-(button_width * (factor -1)))/(float)(button_width)); | ||
397 | 225 | } | ||
398 | 226 | else | ||
399 | 227 | { | ||
400 | 228 | *(dest + y * lockrect.Pitch + 4*x + 3) = 0x00; | ||
401 | 229 | } | ||
402 | 230 | } | ||
403 | 231 | } | ||
404 | 232 | _gradient_texture->UnlockRect (0); | ||
405 | 233 | } | ||
406 | 234 | GfxContext.GetRenderStates ().SetBlend(true, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
407 | 235 | |||
408 | 236 | nux::TexCoordXForm texxform0; | ||
409 | 237 | nux::TexCoordXForm texxform1; | ||
410 | 238 | |||
411 | 239 | // Modulate the checkboard and the gradient texture | ||
412 | 240 | GfxContext.QRP_2TexMod(geo.x, geo.y, | ||
413 | 241 | geo.width, geo.height, | ||
414 | 242 | _gradient_texture, texxform0, | ||
415 | 243 | nux::Color::White, | ||
416 | 244 | _title_tex->GetDeviceTexture (), | ||
417 | 245 | texxform1, | ||
418 | 246 | nux::Color::White); | ||
419 | 247 | |||
420 | 248 | GfxContext.GetRenderStates ().SetBlend(false); | ||
421 | 249 | |||
422 | 250 | // The previous blend is too aggressive on the texture and therefore there | ||
423 | 251 | // is a slight loss of clarity. This fixes that | ||
424 | 252 | geo.width = button_width * (factor - 1); | ||
425 | 253 | gPainter.PushDrawLayer (GfxContext, geo, _title_layer); | ||
426 | 254 | geo = GetGeometry (); | ||
427 | 255 | } | ||
428 | 256 | else | ||
429 | 257 | { | ||
430 | 258 | gPainter.PushDrawLayer (GfxContext, | ||
431 | 259 | geo, | ||
432 | 260 | _title_layer); | ||
433 | 261 | } | ||
434 | 262 | } | ||
435 | 263 | |||
436 | 264 | gPainter.PopBackground (); | ||
437 | 265 | |||
438 | 266 | GfxContext.PopClippingRectangle(); | ||
439 | 267 | } | ||
440 | 268 | |||
441 | 269 | void | ||
442 | 270 | PanelMenuView::DrawContent (nux::GraphicsEngine &GfxContext, bool force_draw) | ||
443 | 271 | { | ||
444 | 272 | nux::Geometry geo = GetGeometry (); | ||
445 | 273 | |||
446 | 274 | GfxContext.PushClippingRectangle (geo); | ||
447 | 275 | |||
448 | 276 | if (_is_inside || _last_active_view) | ||
449 | 277 | { | ||
450 | 278 | _layout->ProcessDraw (GfxContext, force_draw); | ||
451 | 279 | } | ||
452 | 280 | |||
453 | 281 | if (_is_maximized) | ||
454 | 282 | { | ||
455 | 283 | _window_buttons->ProcessDraw (GfxContext, true); | ||
456 | 284 | } | ||
457 | 285 | |||
458 | 286 | GfxContext.PopClippingRectangle(); | ||
459 | 287 | } | ||
460 | 288 | |||
461 | 289 | gchar * | ||
462 | 290 | PanelMenuView::GetActiveViewName () | ||
463 | 291 | { | ||
464 | 292 | gchar *label = NULL; | ||
465 | 293 | |||
466 | 294 | if (_is_maximized) | ||
467 | 295 | { | ||
468 | 296 | BamfWindow *window = bamf_matcher_get_active_window (_matcher); | ||
469 | 297 | |||
470 | 298 | if (BAMF_IS_WINDOW (window)) | ||
471 | 299 | label = g_strdup (bamf_view_get_name (BAMF_VIEW (window))); | ||
472 | 300 | } | ||
473 | 301 | |||
474 | 302 | if (!label) | ||
475 | 303 | { | ||
476 | 304 | BamfApplication *app = bamf_matcher_get_active_application (_matcher); | ||
477 | 305 | if (BAMF_IS_APPLICATION (app)) | ||
478 | 306 | { | ||
479 | 307 | const gchar *filename; | ||
480 | 308 | |||
481 | 309 | filename = bamf_application_get_desktop_file (app); | ||
482 | 310 | |||
483 | 311 | if (filename && g_strcmp0 (filename, "") != 0) | ||
484 | 312 | { | ||
485 | 313 | GDesktopAppInfo *info; | ||
486 | 314 | |||
487 | 315 | info = g_desktop_app_info_new_from_filename (bamf_application_get_desktop_file (app)); | ||
488 | 316 | |||
489 | 317 | if (info) | ||
490 | 318 | { | ||
491 | 319 | label = g_strdup (g_app_info_get_display_name (G_APP_INFO (info))); | ||
492 | 320 | g_object_unref (info); | ||
493 | 321 | } | ||
494 | 322 | else | ||
495 | 323 | { | ||
496 | 324 | g_warning ("Unable to get GDesktopAppInfo for %s", | ||
497 | 325 | bamf_application_get_desktop_file (app)); | ||
498 | 326 | } | ||
499 | 327 | } | ||
500 | 328 | |||
501 | 329 | if (label == NULL) | ||
502 | 330 | { | ||
503 | 331 | BamfView *active_view; | ||
504 | 332 | |||
505 | 333 | active_view = (BamfView *)bamf_matcher_get_active_window (_matcher); | ||
506 | 334 | if (BAMF_IS_VIEW (active_view)) | ||
507 | 335 | label = g_strdup (bamf_view_get_name (active_view)); | ||
508 | 336 | else | ||
509 | 337 | label = g_strdup (""); | ||
510 | 338 | } | ||
511 | 339 | } | ||
512 | 340 | else | ||
513 | 341 | { | ||
514 | 342 | label = g_strdup (" "); | ||
515 | 343 | } | ||
516 | 344 | } | ||
517 | 345 | |||
518 | 346 | return label; | ||
519 | 347 | } | ||
520 | 348 | |||
521 | 349 | void | ||
522 | 350 | PanelMenuView::Refresh () | ||
523 | 351 | { | ||
524 | 352 | nux::Geometry geo = GetGeometry (); | ||
525 | 353 | char *label = GetActiveViewName (); | ||
526 | 354 | PangoLayout *layout = NULL; | ||
527 | 355 | PangoFontDescription *desc = NULL; | ||
528 | 356 | GtkSettings *settings = gtk_settings_get_default (); | ||
529 | 357 | cairo_t *cr; | ||
530 | 358 | char *font_description = NULL; | ||
531 | 359 | GdkScreen *screen = gdk_screen_get_default (); | ||
532 | 360 | int dpi = 0; | ||
533 | 361 | |||
534 | 362 | int x = 0; | ||
535 | 363 | int y = 0; | ||
536 | 364 | int width = geo.width; | ||
537 | 365 | int height = geo.height; | ||
538 | 366 | int text_width = 0; | ||
539 | 367 | int text_height = 0; | ||
540 | 368 | |||
541 | 369 | if (label) | ||
542 | 370 | { | ||
543 | 371 | PangoContext *cxt; | ||
544 | 372 | PangoRectangle log_rect; | ||
545 | 373 | |||
546 | 374 | cr = _util_cg.GetContext (); | ||
547 | 375 | |||
548 | 376 | g_object_get (settings, | ||
549 | 377 | "gtk-font-name", &font_description, | ||
550 | 378 | "gtk-xft-dpi", &dpi, | ||
551 | 379 | NULL); | ||
552 | 380 | desc = pango_font_description_from_string (font_description); | ||
553 | 381 | pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD); | ||
554 | 382 | |||
555 | 383 | layout = pango_cairo_create_layout (cr); | ||
556 | 384 | pango_layout_set_font_description (layout, desc); | ||
557 | 385 | pango_layout_set_text (layout, label, -1); | ||
558 | 386 | |||
559 | 387 | cxt = pango_layout_get_context (layout); | ||
560 | 388 | pango_cairo_context_set_font_options (cxt, gdk_screen_get_font_options (screen)); | ||
561 | 389 | pango_cairo_context_set_resolution (cxt, (float)dpi/(float)PANGO_SCALE); | ||
562 | 390 | pango_layout_context_changed (layout); | ||
563 | 391 | |||
564 | 392 | pango_layout_get_extents (layout, NULL, &log_rect); | ||
565 | 393 | text_width = log_rect.width / PANGO_SCALE; | ||
566 | 394 | text_height = log_rect.height / PANGO_SCALE; | ||
567 | 395 | |||
568 | 396 | pango_font_description_free (desc); | ||
569 | 397 | g_free (font_description); | ||
570 | 398 | cairo_destroy (cr); | ||
571 | 399 | } | ||
572 | 400 | |||
573 | 401 | nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height); | ||
574 | 402 | cr = cairo_graphics.GetContext(); | ||
575 | 403 | cairo_set_line_width (cr, 1); | ||
576 | 404 | |||
577 | 405 | x = PADDING; | ||
578 | 406 | y = 0; | ||
579 | 407 | |||
580 | 408 | if (_is_maximized) | ||
581 | 409 | x += _window_buttons->GetContentWidth () + PADDING + PADDING; | ||
582 | 410 | |||
583 | 411 | if (label) | ||
584 | 412 | { | ||
585 | 413 | pango_cairo_update_layout (cr, layout); | ||
586 | 414 | |||
587 | 415 | // Once for the homies that couldn't be here | ||
588 | 416 | cairo_set_source_rgb (cr, 50/255.0f, 50/255.0f, 45/255.0f); | ||
589 | 417 | cairo_move_to (cr, x, ((height - text_height)/2)-1); | ||
590 | 418 | pango_cairo_show_layout (cr, layout); | ||
591 | 419 | cairo_stroke (cr); | ||
592 | 420 | |||
593 | 421 | // Once again for the homies that could | ||
594 | 422 | cairo_set_source_rgba (cr, 223/255.0f, 219/255.0f, 210/255.0f, 1.0f); | ||
595 | 423 | cairo_move_to (cr, x, (height - text_height)/2); | ||
596 | 424 | pango_cairo_show_layout (cr, layout); | ||
597 | 425 | cairo_stroke (cr); | ||
598 | 426 | } | ||
599 | 427 | |||
600 | 428 | cairo_destroy (cr); | ||
601 | 429 | if (layout) | ||
602 | 430 | g_object_unref (layout); | ||
603 | 431 | |||
604 | 432 | nux::NBitmapData* bitmap = cairo_graphics.GetBitmap(); | ||
605 | 433 | |||
606 | 434 | // The Texture is created with a reference count of 1. | ||
607 | 435 | nux::BaseTexture* texture2D = nux::GetThreadGLDeviceFactory ()->CreateSystemCapableTexture (); | ||
608 | 436 | texture2D->Update(bitmap); | ||
609 | 437 | delete bitmap; | ||
610 | 438 | |||
611 | 439 | if (_title_layer) | ||
612 | 440 | delete _title_layer; | ||
613 | 441 | |||
614 | 442 | nux::TexCoordXForm texxform; | ||
615 | 443 | texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD); | ||
616 | 444 | texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); | ||
617 | 445 | |||
618 | 446 | nux::ROPConfig rop; | ||
619 | 447 | rop.Blend = true; | ||
620 | 448 | rop.SrcBlend = GL_ONE; | ||
621 | 449 | rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; | ||
622 | 450 | _title_layer = new nux::TextureLayer (texture2D->GetDeviceTexture(), | ||
623 | 451 | texxform, | ||
624 | 452 | nux::Color::White, | ||
625 | 453 | false, | ||
626 | 454 | rop); | ||
627 | 455 | |||
628 | 456 | |||
629 | 457 | if (_title_tex) | ||
630 | 458 | _title_tex->UnReference (); | ||
631 | 459 | |||
632 | 460 | _title_tex = texture2D; | ||
633 | 461 | |||
634 | 462 | g_free (label); | ||
635 | 463 | } | ||
636 | 464 | |||
637 | 465 | void | ||
638 | 466 | PanelMenuView::OnActiveChanged (PanelIndicatorObjectEntryView *view, | ||
639 | 467 | bool is_active) | ||
640 | 468 | { | ||
641 | 469 | if (is_active) | ||
642 | 470 | _last_active_view = view; | ||
643 | 471 | else | ||
644 | 472 | { | ||
645 | 473 | if (_last_active_view == view) | ||
646 | 474 | { | ||
647 | 475 | _last_active_view = NULL; | ||
648 | 476 | } | ||
649 | 477 | } | ||
650 | 478 | FullRedraw (); | ||
651 | 479 | } | ||
652 | 480 | |||
653 | 481 | void | ||
654 | 482 | PanelMenuView::OnEntryAdded (IndicatorObjectEntryProxy *proxy) | ||
655 | 483 | { | ||
656 | 484 | PanelIndicatorObjectEntryView *view = new PanelIndicatorObjectEntryView (proxy); | ||
657 | 485 | view->active_changed.connect (sigc::mem_fun (this, &PanelMenuView::OnActiveChanged)); | ||
658 | 486 | _menu_layout->AddView (view, 0, nux::eCenter, nux::eFull); | ||
659 | 487 | _menu_layout->SetContentDistribution (nux::eStackLeft); | ||
660 | 488 | |||
661 | 489 | _entries.push_back (view); | ||
662 | 490 | |||
663 | 491 | AddChild (view); | ||
664 | 492 | |||
665 | 493 | this->ComputeChildLayout (); | ||
666 | 494 | NeedRedraw (); | ||
667 | 495 | } | ||
668 | 496 | |||
669 | 497 | void | ||
670 | 498 | PanelMenuView::OnEntryMoved (IndicatorObjectEntryProxy *proxy) | ||
671 | 499 | { | ||
672 | 500 | printf ("ERROR: Moving IndicatorObjectEntry not supported\n"); | ||
673 | 501 | } | ||
674 | 502 | |||
675 | 503 | void | ||
676 | 504 | PanelMenuView::OnEntryRemoved(IndicatorObjectEntryProxy *proxy) | ||
677 | 505 | { | ||
678 | 506 | std::vector<PanelIndicatorObjectEntryView *>::iterator it; | ||
679 | 507 | |||
680 | 508 | for (it = _entries.begin(); it != _entries.end(); it++) | ||
681 | 509 | { | ||
682 | 510 | PanelIndicatorObjectEntryView *view = static_cast<PanelIndicatorObjectEntryView *> (*it); | ||
683 | 511 | if (view->_proxy == proxy) | ||
684 | 512 | { | ||
685 | 513 | RemoveChild (view); | ||
686 | 514 | _entries.erase (it); | ||
687 | 515 | _menu_layout->RemoveChildObject (view); | ||
688 | 516 | |||
689 | 517 | break; | ||
690 | 518 | } | ||
691 | 519 | } | ||
692 | 520 | |||
693 | 521 | this->ComputeChildLayout (); | ||
694 | 522 | NeedRedraw (); | ||
695 | 523 | } | ||
696 | 524 | |||
697 | 525 | void | ||
698 | 526 | PanelMenuView::AllMenusClosed () | ||
699 | 527 | { | ||
700 | 528 | _is_inside = false; | ||
701 | 529 | _last_active_view = false; | ||
702 | 530 | |||
703 | 531 | FullRedraw (); | ||
704 | 532 | } | ||
705 | 533 | |||
706 | 534 | void | ||
707 | 535 | PanelMenuView::OnActiveWindowChanged (BamfView *old_view, | ||
708 | 536 | BamfView *new_view) | ||
709 | 537 | { | ||
710 | 538 | _is_maximized = false; | ||
711 | 539 | |||
712 | 540 | if (BAMF_IS_WINDOW (new_view)) | ||
713 | 541 | { | ||
714 | 542 | BamfWindow *window = BAMF_WINDOW (new_view); | ||
715 | 543 | _is_maximized = WindowManager::Default ()->IsWindowMaximized (bamf_window_get_xid (window)); | ||
716 | 544 | } | ||
717 | 545 | |||
718 | 546 | Refresh (); | ||
719 | 547 | FullRedraw (); | ||
720 | 548 | } | ||
721 | 549 | |||
722 | 550 | void | ||
723 | 551 | PanelMenuView::OnWindowUnmapped (guint32 xid) | ||
724 | 552 | { | ||
725 | 553 | _decor_map.erase (xid); | ||
726 | 554 | } | ||
727 | 555 | |||
728 | 556 | void | ||
729 | 557 | PanelMenuView::OnWindowMaximized (guint xid) | ||
730 | 558 | { | ||
731 | 559 | BamfWindow *window; | ||
732 | 560 | |||
733 | 561 | window = bamf_matcher_get_active_window (_matcher); | ||
734 | 562 | if (BAMF_IS_WINDOW (window) && bamf_window_get_xid (window) == xid) | ||
735 | 563 | { | ||
736 | 564 | // We could probably just check if a key is available, but who wants to do that | ||
737 | 565 | if (_decor_map.find (xid) == _decor_map.end ()) | ||
738 | 566 | _decor_map[xid] = WindowManager::Default ()->IsWindowDecorated (xid); | ||
739 | 567 | |||
740 | 568 | if (_decor_map[xid]) | ||
741 | 569 | { | ||
742 | 570 | WindowManager::Default ()->Undecorate (xid); | ||
743 | 571 | } | ||
744 | 572 | |||
745 | 573 | _is_maximized = true; | ||
746 | 574 | |||
747 | 575 | Refresh (); | ||
748 | 576 | FullRedraw (); | ||
749 | 577 | } | ||
750 | 578 | } | ||
751 | 579 | |||
752 | 580 | void | ||
753 | 581 | PanelMenuView::OnWindowRestored (guint xid) | ||
754 | 582 | { | ||
755 | 583 | BamfWindow *window; | ||
756 | 584 | |||
757 | 585 | window = bamf_matcher_get_active_window (_matcher); | ||
758 | 586 | if (BAMF_IS_WINDOW (window) && bamf_window_get_xid (window) == xid) | ||
759 | 587 | { | ||
760 | 588 | _is_maximized = false; | ||
761 | 589 | |||
762 | 590 | if (_decor_map[xid]) | ||
763 | 591 | { | ||
764 | 592 | WindowManager::Default ()->Decorate (xid); | ||
765 | 593 | } | ||
766 | 594 | |||
767 | 595 | Refresh (); | ||
768 | 596 | FullRedraw (); | ||
769 | 597 | } | ||
770 | 598 | } | ||
771 | 599 | |||
772 | 600 | void | ||
773 | 601 | PanelMenuView::OnCloseClicked () | ||
774 | 602 | { | ||
775 | 603 | BamfWindow *window; | ||
776 | 604 | |||
777 | 605 | window = bamf_matcher_get_active_window (_matcher); | ||
778 | 606 | if (BAMF_IS_WINDOW (window)) | ||
779 | 607 | WindowManager::Default ()->Close (bamf_window_get_xid (window)); | ||
780 | 608 | } | ||
781 | 609 | |||
782 | 610 | void | ||
783 | 611 | PanelMenuView::OnMinimizeClicked () | ||
784 | 612 | { | ||
785 | 613 | BamfWindow *window; | ||
786 | 614 | |||
787 | 615 | window = bamf_matcher_get_active_window (_matcher); | ||
788 | 616 | if (BAMF_IS_WINDOW (window)) | ||
789 | 617 | WindowManager::Default ()->Minimize (bamf_window_get_xid (window)); | ||
790 | 618 | } | ||
791 | 619 | |||
792 | 620 | void | ||
793 | 621 | PanelMenuView::OnRestoreClicked () | ||
794 | 622 | { | ||
795 | 623 | BamfWindow *window; | ||
796 | 624 | |||
797 | 625 | window = bamf_matcher_get_active_window (_matcher); | ||
798 | 626 | if (BAMF_IS_WINDOW (window)) | ||
799 | 627 | WindowManager::Default ()->Restore (bamf_window_get_xid (window)); | ||
800 | 628 | } | ||
801 | 629 | |||
802 | 630 | void | ||
803 | 631 | PanelMenuView::OnWindowButtonsRedraw () | ||
804 | 632 | { | ||
805 | 633 | FullRedraw (); | ||
806 | 634 | } | ||
807 | 635 | |||
808 | 636 | // Introspectable | ||
809 | 637 | const gchar * | ||
810 | 638 | PanelMenuView::GetName () | ||
811 | 639 | { | ||
812 | 640 | return "MenuView"; | ||
813 | 641 | } | ||
814 | 642 | |||
815 | 643 | const gchar * | ||
816 | 644 | PanelMenuView::GetChildsName () | ||
817 | 645 | { | ||
818 | 646 | return "entries"; | ||
819 | 647 | } | ||
820 | 648 | |||
821 | 649 | void | ||
822 | 650 | PanelMenuView::AddProperties (GVariantBuilder *builder) | ||
823 | 651 | { | ||
824 | 652 | nux::Geometry geo = GetGeometry (); | ||
825 | 653 | |||
826 | 654 | /* Now some props from ourselves */ | ||
827 | 655 | g_variant_builder_add (builder, "{sv}", "x", g_variant_new_int32 (geo.x)); | ||
828 | 656 | g_variant_builder_add (builder, "{sv}", "y", g_variant_new_int32 (geo.y)); | ||
829 | 657 | g_variant_builder_add (builder, "{sv}", "width", g_variant_new_int32 (geo.width)); | ||
830 | 658 | g_variant_builder_add (builder, "{sv}", "height", g_variant_new_int32 (geo.height)); | ||
831 | 659 | } | ||
832 | 660 | |||
833 | 661 | /* | ||
834 | 662 | * C code for callbacks | ||
835 | 663 | */ | ||
836 | 664 | static void | ||
837 | 665 | on_active_window_changed (BamfMatcher *matcher, | ||
838 | 666 | BamfView *old_view, | ||
839 | 667 | BamfView *new_view, | ||
840 | 668 | PanelMenuView *self) | ||
841 | 669 | { | ||
842 | 670 | self->OnActiveWindowChanged (old_view, new_view); | ||
843 | 671 | } | ||
844 | 0 | 672 | ||
845 | === added file 'src/PanelMenuView.h' | |||
846 | --- src/PanelMenuView.h 1970-01-01 00:00:00 +0000 | |||
847 | +++ src/PanelMenuView.h 2010-12-17 10:43:24 +0000 | |||
848 | @@ -0,0 +1,103 @@ | |||
849 | 1 | /* | ||
850 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
851 | 3 | * | ||
852 | 4 | * This program is free software: you can redistribute it and/or modify | ||
853 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
854 | 6 | * published by the Free Software Foundation. | ||
855 | 7 | * | ||
856 | 8 | * This program is distributed in the hope that it will be useful, | ||
857 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
858 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
859 | 11 | * GNU General Public License for more details. | ||
860 | 12 | * | ||
861 | 13 | * You should have received a copy of the GNU General Public License | ||
862 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
863 | 15 | * | ||
864 | 16 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | ||
865 | 17 | */ | ||
866 | 18 | |||
867 | 19 | #ifndef PANEL_MENU_VIEW_H | ||
868 | 20 | #define PANEL_MENU_VIEW_H | ||
869 | 21 | |||
870 | 22 | #include <Nux/View.h> | ||
871 | 23 | #include <map> | ||
872 | 24 | |||
873 | 25 | #include "IndicatorObjectProxy.h" | ||
874 | 26 | #include "Introspectable.h" | ||
875 | 27 | #include "PanelIndicatorObjectView.h" | ||
876 | 28 | #include "StaticCairoText.h" | ||
877 | 29 | #include "WindowButtons.h" | ||
878 | 30 | |||
879 | 31 | #include <libbamf/libbamf.h> | ||
880 | 32 | |||
881 | 33 | class PanelMenuView : public PanelIndicatorObjectView | ||
882 | 34 | { | ||
883 | 35 | public: | ||
884 | 36 | // This contains all the menubar logic for the Panel. Mainly it contains | ||
885 | 37 | // the following states: | ||
886 | 38 | // 1. Unmaximized window + no mouse hover | ||
887 | 39 | // 2. Unmaximized window + mouse hover | ||
888 | 40 | // 3. Unmaximized window + active menu (Alt+F/arrow key nav) | ||
889 | 41 | // 4. Maximized window + no mouse hover | ||
890 | 42 | // 5. Maximized window + mouse hover | ||
891 | 43 | // 6. Maximized window + active menu | ||
892 | 44 | // | ||
893 | 45 | // It also deals with undecorating maximized windows (and redecorating them | ||
894 | 46 | // on unmaximize) | ||
895 | 47 | |||
896 | 48 | PanelMenuView (); | ||
897 | 49 | ~PanelMenuView (); | ||
898 | 50 | |||
899 | 51 | void FullRedraw (); | ||
900 | 52 | |||
901 | 53 | virtual long ProcessEvent (nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo); | ||
902 | 54 | virtual void Draw (nux::GraphicsEngine& GfxContext, bool force_draw); | ||
903 | 55 | virtual void DrawContent (nux::GraphicsEngine &GfxContext, bool force_draw); | ||
904 | 56 | virtual long PostLayoutManagement (long LayoutResult); | ||
905 | 57 | |||
906 | 58 | void SetProxy (IndicatorObjectProxy *proxy); | ||
907 | 59 | |||
908 | 60 | void OnEntryAdded (IndicatorObjectEntryProxy *proxy); | ||
909 | 61 | void OnEntryMoved (IndicatorObjectEntryProxy *proxy); | ||
910 | 62 | void OnEntryRemoved (IndicatorObjectEntryProxy *proxy); | ||
911 | 63 | void OnActiveChanged (PanelIndicatorObjectEntryView *view, bool is_active); | ||
912 | 64 | void OnActiveWindowChanged (BamfView *old_view, BamfView *new_view); | ||
913 | 65 | |||
914 | 66 | void OnWindowUnmapped (guint xid); | ||
915 | 67 | void OnWindowMaximized (guint32 xid); | ||
916 | 68 | void OnWindowRestored (guint32 xid); | ||
917 | 69 | |||
918 | 70 | void Refresh (); | ||
919 | 71 | void AllMenusClosed (); | ||
920 | 72 | |||
921 | 73 | void OnCloseClicked (); | ||
922 | 74 | void OnMinimizeClicked (); | ||
923 | 75 | void OnRestoreClicked (); | ||
924 | 76 | void OnWindowButtonsRedraw (); | ||
925 | 77 | |||
926 | 78 | protected: | ||
927 | 79 | const gchar * GetName (); | ||
928 | 80 | const gchar * GetChildsName (); | ||
929 | 81 | void AddProperties (GVariantBuilder *builder); | ||
930 | 82 | |||
931 | 83 | private: | ||
932 | 84 | gchar * GetActiveViewName (); | ||
933 | 85 | |||
934 | 86 | private: | ||
935 | 87 | BamfMatcher* _matcher; | ||
936 | 88 | |||
937 | 89 | nux::AbstractPaintLayer *_title_layer; | ||
938 | 90 | nux::HLayout *_menu_layout; | ||
939 | 91 | nux::CairoGraphics _util_cg; | ||
940 | 92 | nux::IntrusiveSP<nux::IOpenGLBaseTexture> _gradient_texture; | ||
941 | 93 | nux::BaseTexture *_title_tex; | ||
942 | 94 | |||
943 | 95 | bool _is_inside; | ||
944 | 96 | bool _is_maximized; | ||
945 | 97 | PanelIndicatorObjectEntryView *_last_active_view; | ||
946 | 98 | |||
947 | 99 | WindowButtons *_window_buttons; | ||
948 | 100 | |||
949 | 101 | std::map<guint32, bool> _decor_map; | ||
950 | 102 | }; | ||
951 | 103 | #endif | ||
952 | 0 | 104 | ||
953 | === modified file 'src/PanelView.cpp' | |||
954 | --- src/PanelView.cpp 2010-12-09 17:58:53 +0000 | |||
955 | +++ src/PanelView.cpp 2010-12-17 10:43:24 +0000 | |||
956 | @@ -46,13 +46,17 @@ | |||
957 | 46 | // Home button | 46 | // Home button |
958 | 47 | _home_button = new PanelHomeButton (); | 47 | _home_button = new PanelHomeButton (); |
959 | 48 | _layout->AddView (_home_button, 0, nux::eCenter, nux::eFull); | 48 | _layout->AddView (_home_button, 0, nux::eCenter, nux::eFull); |
960 | 49 | |||
961 | 50 | AddChild (_home_button); | 49 | AddChild (_home_button); |
962 | 51 | 50 | ||
963 | 51 | _menu_view = new PanelMenuView (); | ||
964 | 52 | _layout->AddView (_menu_view, 1, nux::eCenter, nux::eFull); | ||
965 | 53 | AddChild (_menu_view); | ||
966 | 54 | |||
967 | 52 | _remote = new IndicatorObjectFactoryRemote (); | 55 | _remote = new IndicatorObjectFactoryRemote (); |
968 | 53 | _remote->OnObjectAdded.connect (sigc::mem_fun (this, &PanelView::OnObjectAdded)); | 56 | _remote->OnObjectAdded.connect (sigc::mem_fun (this, &PanelView::OnObjectAdded)); |
969 | 54 | _remote->OnMenuPointerMoved.connect (sigc::mem_fun (this, &PanelView::OnMenuPointerMoved)); | 57 | _remote->OnMenuPointerMoved.connect (sigc::mem_fun (this, &PanelView::OnMenuPointerMoved)); |
970 | 55 | _remote->OnEntryActivateRequest.connect (sigc::mem_fun (this, &PanelView::OnEntryActivateRequest)); | 58 | _remote->OnEntryActivateRequest.connect (sigc::mem_fun (this, &PanelView::OnEntryActivateRequest)); |
971 | 59 | _remote->IndicatorObjectFactory::OnEntryActivated.connect (sigc::mem_fun (this, &PanelView::OnEntryActivated)); | ||
972 | 56 | } | 60 | } |
973 | 57 | 61 | ||
974 | 58 | PanelView::~PanelView () | 62 | PanelView::~PanelView () |
975 | @@ -204,7 +208,11 @@ | |||
976 | 204 | 208 | ||
977 | 205 | // Appmenu is treated differently as it needs to expand | 209 | // Appmenu is treated differently as it needs to expand |
978 | 206 | // We could do this in a more special way, but who has the time for special? | 210 | // We could do this in a more special way, but who has the time for special? |
980 | 207 | _layout->AddView (view, (g_strstr_len (proxy->GetName ().c_str (), -1, "appmenu") != NULL), nux::eCenter, nux::eFull); | 211 | if (g_strstr_len (proxy->GetName ().c_str (), -1, "appmenu") != NULL) |
981 | 212 | _menu_view->SetProxy (proxy); | ||
982 | 213 | else | ||
983 | 214 | _layout->AddView (view, 0, nux::eCenter, nux::eFull); | ||
984 | 215 | |||
985 | 208 | _layout->SetContentDistribution (nux::eStackLeft); | 216 | _layout->SetContentDistribution (nux::eStackLeft); |
986 | 209 | 217 | ||
987 | 210 | AddChild (view); | 218 | AddChild (view); |
988 | @@ -224,40 +232,40 @@ | |||
989 | 224 | 232 | ||
990 | 225 | if (x >= geo.x && x <= (geo.x + geo.width) | 233 | if (x >= geo.x && x <= (geo.x + geo.width) |
991 | 226 | && y >= geo.y && y <= (geo.y + geo.height)) | 234 | && y >= geo.y && y <= (geo.y + geo.height)) |
992 | 235 | { | ||
993 | 236 | std::list<Area *>::iterator it; | ||
994 | 237 | |||
995 | 238 | std::list<Area *> my_children = _layout->GetChildren (); | ||
996 | 239 | for (it = my_children.begin(); it != my_children.end(); it++) | ||
997 | 227 | { | 240 | { |
999 | 228 | std::list<Area *>::iterator it; | 241 | PanelIndicatorObjectView *view = static_cast<PanelIndicatorObjectView *> (*it); |
1000 | 242 | |||
1001 | 243 | if (view->_layout == NULL) | ||
1002 | 244 | continue; | ||
1003 | 229 | 245 | ||
1006 | 230 | std::list<Area *> my_children = _layout->GetChildren (); | 246 | geo = view->GetGeometry (); |
1007 | 231 | for (it = my_children.begin(); it != my_children.end(); it++) | 247 | if (x >= geo.x && x <= (geo.x + geo.width) |
1008 | 248 | && y >= geo.y && y <= (geo.y + geo.height)) | ||
1009 | 232 | { | 249 | { |
1018 | 233 | PanelIndicatorObjectView *view = static_cast<PanelIndicatorObjectView *> (*it); | 250 | std::list<Area *>::iterator it2; |
1019 | 234 | 251 | ||
1020 | 235 | if (view->_layout == NULL) | 252 | std::list<Area *> its_children = view->_layout->GetChildren (); |
1021 | 236 | continue; | 253 | for (it2 = its_children.begin(); it2 != its_children.end(); it2++) |
1022 | 237 | 254 | { | |
1023 | 238 | geo = view->GetGeometry (); | 255 | PanelIndicatorObjectEntryView *entry = static_cast<PanelIndicatorObjectEntryView *> (*it2); |
1024 | 239 | if (x >= geo.x && x <= (geo.x + geo.width) | 256 | |
1025 | 240 | && y >= geo.y && y <= (geo.y + geo.height)) | 257 | geo = entry->GetGeometry (); |
1026 | 258 | if (x >= geo.x && x <= (geo.x + geo.width) | ||
1027 | 259 | && y >= geo.y && y <= (geo.y + geo.height)) | ||
1028 | 241 | { | 260 | { |
1044 | 242 | std::list<Area *>::iterator it2; | 261 | entry->OnMouseDown (x, y, 0, 0); |
1030 | 243 | |||
1031 | 244 | std::list<Area *> its_children = view->_layout->GetChildren (); | ||
1032 | 245 | for (it2 = its_children.begin(); it2 != its_children.end(); it2++) | ||
1033 | 246 | { | ||
1034 | 247 | PanelIndicatorObjectEntryView *entry = static_cast<PanelIndicatorObjectEntryView *> (*it2); | ||
1035 | 248 | |||
1036 | 249 | geo = entry->GetGeometry (); | ||
1037 | 250 | if (x >= geo.x && x <= (geo.x + geo.width) | ||
1038 | 251 | && y >= geo.y && y <= (geo.y + geo.height)) | ||
1039 | 252 | { | ||
1040 | 253 | entry->OnMouseDown (x, y, 0, 0); | ||
1041 | 254 | break; | ||
1042 | 255 | } | ||
1043 | 256 | } | ||
1045 | 257 | break; | 262 | break; |
1046 | 258 | } | 263 | } |
1047 | 264 | } | ||
1048 | 265 | break; | ||
1049 | 259 | } | 266 | } |
1050 | 260 | } | 267 | } |
1051 | 268 | } | ||
1052 | 261 | } | 269 | } |
1053 | 262 | 270 | ||
1054 | 263 | void | 271 | void |
1055 | @@ -281,10 +289,18 @@ | |||
1056 | 281 | PanelIndicatorObjectEntryView *entry = static_cast<PanelIndicatorObjectEntryView *> (*it2); | 289 | PanelIndicatorObjectEntryView *entry = static_cast<PanelIndicatorObjectEntryView *> (*it2); |
1057 | 282 | 290 | ||
1058 | 283 | if (g_strcmp0 (entry->GetName (), entry_id) == 0) | 291 | if (g_strcmp0 (entry->GetName (), entry_id) == 0) |
1063 | 284 | { | 292 | { |
1064 | 285 | entry->Activate (); | 293 | g_debug ("%s: Activating: %s", G_STRFUNC, entry_id); |
1065 | 286 | break; | 294 | entry->Activate (); |
1066 | 287 | } | 295 | break; |
1067 | 296 | } | ||
1068 | 288 | } | 297 | } |
1069 | 289 | } | 298 | } |
1070 | 290 | } | 299 | } |
1071 | 300 | |||
1072 | 301 | void | ||
1073 | 302 | PanelView::OnEntryActivated (const char *entry_id) | ||
1074 | 303 | { | ||
1075 | 304 | if (g_strcmp0 (entry_id, "") == 0) | ||
1076 | 305 | _menu_view->AllMenusClosed (); | ||
1077 | 306 | } | ||
1078 | 291 | 307 | ||
1079 | === modified file 'src/PanelView.h' | |||
1080 | --- src/PanelView.h 2010-12-07 13:55:04 +0000 | |||
1081 | +++ src/PanelView.h 2010-12-17 10:43:24 +0000 | |||
1082 | @@ -24,6 +24,7 @@ | |||
1083 | 24 | #include <NuxGraphics/GraphicsEngine.h> | 24 | #include <NuxGraphics/GraphicsEngine.h> |
1084 | 25 | 25 | ||
1085 | 26 | #include "PanelHomeButton.h" | 26 | #include "PanelHomeButton.h" |
1086 | 27 | #include "PanelMenuView.h" | ||
1087 | 27 | #include "IndicatorObjectFactoryRemote.h" | 28 | #include "IndicatorObjectFactoryRemote.h" |
1088 | 28 | #include "Introspectable.h" | 29 | #include "Introspectable.h" |
1089 | 29 | 30 | ||
1090 | @@ -43,6 +44,7 @@ | |||
1091 | 43 | void OnObjectAdded (IndicatorObjectProxy *proxy); | 44 | void OnObjectAdded (IndicatorObjectProxy *proxy); |
1092 | 44 | void OnMenuPointerMoved (int x, int y); | 45 | void OnMenuPointerMoved (int x, int y); |
1093 | 45 | void OnEntryActivateRequest (const char *entry_id); | 46 | void OnEntryActivateRequest (const char *entry_id); |
1094 | 47 | void OnEntryActivated (const char *entry_id); | ||
1095 | 46 | 48 | ||
1096 | 47 | PanelHomeButton * HomeButton (); | 49 | PanelHomeButton * HomeButton (); |
1097 | 48 | 50 | ||
1098 | @@ -59,6 +61,7 @@ | |||
1099 | 59 | IndicatorObjectFactoryRemote *_remote; | 61 | IndicatorObjectFactoryRemote *_remote; |
1100 | 60 | 62 | ||
1101 | 61 | PanelHomeButton *_home_button; | 63 | PanelHomeButton *_home_button; |
1102 | 64 | PanelMenuView *_menu_view; | ||
1103 | 62 | nux::AbstractPaintLayer *_bg_layer; | 65 | nux::AbstractPaintLayer *_bg_layer; |
1104 | 63 | nux::HLayout *_layout; | 66 | nux::HLayout *_layout; |
1105 | 64 | 67 | ||
1106 | 65 | 68 | ||
1107 | === modified file 'src/PluginAdapter.cpp' | |||
1108 | --- src/PluginAdapter.cpp 2010-12-17 10:03:18 +0000 | |||
1109 | +++ src/PluginAdapter.cpp 2010-12-17 10:43:24 +0000 | |||
1110 | @@ -65,9 +65,15 @@ | |||
1111 | 65 | PluginAdapter::NotifyStateChange (CompWindow *window, unsigned int state, unsigned int last_state) | 65 | PluginAdapter::NotifyStateChange (CompWindow *window, unsigned int state, unsigned int last_state) |
1112 | 66 | { | 66 | { |
1113 | 67 | if (!(last_state & MAXIMIZE_STATE) && (state & MAXIMIZE_STATE)) | 67 | if (!(last_state & MAXIMIZE_STATE) && (state & MAXIMIZE_STATE)) |
1115 | 68 | window_maximized.emit (window); | 68 | { |
1116 | 69 | PluginAdapter::window_maximized.emit (window); | ||
1117 | 70 | WindowManager::window_maximized.emit (window->id ()); | ||
1118 | 71 | } | ||
1119 | 69 | else if ((last_state & MAXIMIZE_STATE) && !(state & MAXIMIZE_STATE)) | 72 | else if ((last_state & MAXIMIZE_STATE) && !(state & MAXIMIZE_STATE)) |
1121 | 70 | window_restored.emit (window); | 73 | { |
1122 | 74 | PluginAdapter::window_restored.emit (window); | ||
1123 | 75 | WindowManager::window_restored.emit (window->id ()); | ||
1124 | 76 | } | ||
1125 | 71 | } | 77 | } |
1126 | 72 | 78 | ||
1127 | 73 | void | 79 | void |
1128 | @@ -94,10 +100,12 @@ | |||
1129 | 94 | window_shown.emit (window); | 100 | window_shown.emit (window); |
1130 | 95 | break; | 101 | break; |
1131 | 96 | case CompWindowNotifyMap: | 102 | case CompWindowNotifyMap: |
1133 | 97 | window_mapped.emit (window); | 103 | PluginAdapter::window_mapped.emit (window); |
1134 | 104 | WindowManager::window_mapped.emit (window->id ()); | ||
1135 | 98 | break; | 105 | break; |
1136 | 99 | case CompWindowNotifyUnmap: | 106 | case CompWindowNotifyUnmap: |
1138 | 100 | window_unmapped.emit (window); | 107 | PluginAdapter::window_unmapped.emit (window); |
1139 | 108 | WindowManager::window_unmapped.emit (window->id ()); | ||
1140 | 101 | break; | 109 | break; |
1141 | 102 | default: | 110 | default: |
1142 | 103 | break; | 111 | break; |
1143 | @@ -216,3 +224,68 @@ | |||
1144 | 216 | 224 | ||
1145 | 217 | m_ExpoAction->initiate () (m_ExpoAction, 0, argument); | 225 | m_ExpoAction->initiate () (m_ExpoAction, 0, argument); |
1146 | 218 | } | 226 | } |
1147 | 227 | |||
1148 | 228 | // WindowManager implementation | ||
1149 | 229 | bool | ||
1150 | 230 | PluginAdapter::IsWindowMaximized (guint xid) | ||
1151 | 231 | { | ||
1152 | 232 | Window win = (Window)xid; | ||
1153 | 233 | CompWindow *window; | ||
1154 | 234 | |||
1155 | 235 | window = m_Screen->findWindow (win); | ||
1156 | 236 | if (window) | ||
1157 | 237 | { | ||
1158 | 238 | return window->state () & MAXIMIZE_STATE; | ||
1159 | 239 | } | ||
1160 | 240 | |||
1161 | 241 | return false; | ||
1162 | 242 | } | ||
1163 | 243 | |||
1164 | 244 | bool | ||
1165 | 245 | PluginAdapter::IsWindowDecorated (guint32 xid) | ||
1166 | 246 | { | ||
1167 | 247 | Window win = (Window)xid; | ||
1168 | 248 | CompWindow *window; | ||
1169 | 249 | |||
1170 | 250 | window = m_Screen->findWindow (win); | ||
1171 | 251 | if (window) | ||
1172 | 252 | { | ||
1173 | 253 | unsigned int decor = window->mwmDecor (); | ||
1174 | 254 | |||
1175 | 255 | return decor & (MwmDecorAll | MwmDecorTitle); | ||
1176 | 256 | } | ||
1177 | 257 | return true; | ||
1178 | 258 | } | ||
1179 | 259 | |||
1180 | 260 | void | ||
1181 | 261 | PluginAdapter::Restore (guint32 xid) | ||
1182 | 262 | { | ||
1183 | 263 | Window win = (Window)xid; | ||
1184 | 264 | CompWindow *window; | ||
1185 | 265 | |||
1186 | 266 | window = m_Screen->findWindow (win); | ||
1187 | 267 | if (window) | ||
1188 | 268 | window->maximize (0); | ||
1189 | 269 | } | ||
1190 | 270 | |||
1191 | 271 | void | ||
1192 | 272 | PluginAdapter::Minimize (guint32 xid) | ||
1193 | 273 | { | ||
1194 | 274 | Window win = (Window)xid; | ||
1195 | 275 | CompWindow *window; | ||
1196 | 276 | |||
1197 | 277 | window = m_Screen->findWindow (win); | ||
1198 | 278 | if (window) | ||
1199 | 279 | window->minimize (); | ||
1200 | 280 | } | ||
1201 | 281 | |||
1202 | 282 | void | ||
1203 | 283 | PluginAdapter::Close (guint32 xid) | ||
1204 | 284 | { | ||
1205 | 285 | Window win = (Window)xid; | ||
1206 | 286 | CompWindow *window; | ||
1207 | 287 | |||
1208 | 288 | window = m_Screen->findWindow (win); | ||
1209 | 289 | if (window) | ||
1210 | 290 | window->close (CurrentTime); | ||
1211 | 291 | } | ||
1212 | 219 | 292 | ||
1213 | === modified file 'src/PluginAdapter.h' | |||
1214 | --- src/PluginAdapter.h 2010-12-17 10:03:18 +0000 | |||
1215 | +++ src/PluginAdapter.h 2010-12-17 10:43:24 +0000 | |||
1216 | @@ -24,7 +24,9 @@ | |||
1217 | 24 | 24 | ||
1218 | 25 | #include <sigc++/sigc++.h> | 25 | #include <sigc++/sigc++.h> |
1219 | 26 | 26 | ||
1221 | 27 | class PluginAdapter : public sigc::trackable | 27 | #include "WindowManager.h" |
1222 | 28 | |||
1223 | 29 | class PluginAdapter : public sigc::trackable, public WindowManager | ||
1224 | 28 | { | 30 | { |
1225 | 29 | public: | 31 | public: |
1226 | 30 | static PluginAdapter * Default (); | 32 | static PluginAdapter * Default (); |
1227 | @@ -52,6 +54,13 @@ | |||
1228 | 52 | void NotifyResized (CompWindow *window, int x, int y, int w, int h); | 54 | void NotifyResized (CompWindow *window, int x, int y, int w, int h); |
1229 | 53 | void NotifyStateChange (CompWindow *window, unsigned int state, unsigned int last_state); | 55 | void NotifyStateChange (CompWindow *window, unsigned int state, unsigned int last_state); |
1230 | 54 | 56 | ||
1231 | 57 | // WindowManager implementation | ||
1232 | 58 | bool IsWindowMaximized (guint xid); | ||
1233 | 59 | bool IsWindowDecorated (guint xid); | ||
1234 | 60 | void Restore (guint32 xid); | ||
1235 | 61 | void Minimize (guint32 xid); | ||
1236 | 62 | void Close (guint32 xid); | ||
1237 | 63 | |||
1238 | 55 | sigc::signal<void, CompWindow *> window_maximized; | 64 | sigc::signal<void, CompWindow *> window_maximized; |
1239 | 56 | sigc::signal<void, CompWindow *> window_restored; | 65 | sigc::signal<void, CompWindow *> window_restored; |
1240 | 57 | sigc::signal<void, CompWindow *> window_minimized; | 66 | sigc::signal<void, CompWindow *> window_minimized; |
1241 | 58 | 67 | ||
1242 | === added file 'src/WindowButtons.cpp' | |||
1243 | --- src/WindowButtons.cpp 1970-01-01 00:00:00 +0000 | |||
1244 | +++ src/WindowButtons.cpp 2010-12-17 10:43:24 +0000 | |||
1245 | @@ -0,0 +1,254 @@ | |||
1246 | 1 | /* | ||
1247 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
1248 | 3 | * | ||
1249 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1250 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
1251 | 6 | * published by the Free Software Foundation. | ||
1252 | 7 | * | ||
1253 | 8 | * This program is distributed in the hope that it will be useful, | ||
1254 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1255 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1256 | 11 | * GNU General Public License for more details. | ||
1257 | 12 | * | ||
1258 | 13 | * You should have received a copy of the GNU General Public License | ||
1259 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1260 | 15 | * | ||
1261 | 16 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | ||
1262 | 17 | */ | ||
1263 | 18 | |||
1264 | 19 | #include "Nux/Nux.h" | ||
1265 | 20 | #include "Nux/HLayout.h" | ||
1266 | 21 | #include "Nux/VLayout.h" | ||
1267 | 22 | #include "Nux/Button.h" | ||
1268 | 23 | |||
1269 | 24 | #include "NuxGraphics/GLThread.h" | ||
1270 | 25 | #include "Nux/BaseWindow.h" | ||
1271 | 26 | #include "Nux/WindowCompositor.h" | ||
1272 | 27 | |||
1273 | 28 | #include "WindowButtons.h" | ||
1274 | 29 | |||
1275 | 30 | #include <glib.h> | ||
1276 | 31 | |||
1277 | 32 | |||
1278 | 33 | // FIXME: This will be all automatic in the future | ||
1279 | 34 | #define AMBIANCE "/usr/share/themes/Ambiance/metacity-1" | ||
1280 | 35 | |||
1281 | 36 | enum | ||
1282 | 37 | { | ||
1283 | 38 | BUTTON_CLOSE=0, | ||
1284 | 39 | BUTTON_MINIMISE, | ||
1285 | 40 | BUTTON_UNMAXIMISE | ||
1286 | 41 | }; | ||
1287 | 42 | |||
1288 | 43 | class WindowButton : public nux::Button | ||
1289 | 44 | { | ||
1290 | 45 | // A single window button | ||
1291 | 46 | public: | ||
1292 | 47 | WindowButton (int type) | ||
1293 | 48 | : nux::Button ("X", NUX_TRACKER_LOCATION), | ||
1294 | 49 | _normal_tex (NULL), | ||
1295 | 50 | _prelight_tex (NULL), | ||
1296 | 51 | _pressed_tex (NULL) | ||
1297 | 52 | { | ||
1298 | 53 | if (type == BUTTON_CLOSE) | ||
1299 | 54 | LoadImages ("close"); | ||
1300 | 55 | else if (type == BUTTON_MINIMISE) | ||
1301 | 56 | LoadImages ("minimize"); | ||
1302 | 57 | else | ||
1303 | 58 | LoadImages ("unmaximize"); | ||
1304 | 59 | } | ||
1305 | 60 | |||
1306 | 61 | ~WindowButton () | ||
1307 | 62 | { | ||
1308 | 63 | _normal_tex->UnReference (); | ||
1309 | 64 | _prelight_tex->UnReference (); | ||
1310 | 65 | _pressed_tex->UnReference (); | ||
1311 | 66 | } | ||
1312 | 67 | |||
1313 | 68 | void Draw (nux::GraphicsEngine &GfxContext, bool force_draw) | ||
1314 | 69 | { | ||
1315 | 70 | nux::Geometry geo = GetGeometry (); | ||
1316 | 71 | nux::BaseTexture *tex; | ||
1317 | 72 | nux::TexCoordXForm texxform; | ||
1318 | 73 | |||
1319 | 74 | GfxContext.PushClippingRectangle (geo); | ||
1320 | 75 | |||
1321 | 76 | if (HasMouseFocus ()) | ||
1322 | 77 | { | ||
1323 | 78 | tex = _pressed_tex; | ||
1324 | 79 | } | ||
1325 | 80 | else if (IsMouseInside ()) | ||
1326 | 81 | { | ||
1327 | 82 | tex = _prelight_tex; | ||
1328 | 83 | } | ||
1329 | 84 | else | ||
1330 | 85 | { | ||
1331 | 86 | tex = _normal_tex; | ||
1332 | 87 | } | ||
1333 | 88 | |||
1334 | 89 | GfxContext.GetRenderStates ().SetSeparateBlend (true, | ||
1335 | 90 | GL_SRC_ALPHA, | ||
1336 | 91 | GL_ONE_MINUS_SRC_ALPHA, | ||
1337 | 92 | GL_ONE_MINUS_DST_ALPHA, | ||
1338 | 93 | GL_ONE); | ||
1339 | 94 | GfxContext.GetRenderStates ().SetColorMask (true, true, true, true); | ||
1340 | 95 | if (tex) | ||
1341 | 96 | GfxContext.QRP_GLSL_1Tex (geo.x, | ||
1342 | 97 | geo.y, | ||
1343 | 98 | (float)geo.width, | ||
1344 | 99 | (float)geo.height, | ||
1345 | 100 | tex->GetDeviceTexture (), | ||
1346 | 101 | texxform, | ||
1347 | 102 | nux::Color::White); | ||
1348 | 103 | GfxContext.GetRenderStates ().SetSeparateBlend (false, | ||
1349 | 104 | GL_SRC_ALPHA, | ||
1350 | 105 | GL_ONE_MINUS_SRC_ALPHA, | ||
1351 | 106 | GL_ONE_MINUS_DST_ALPHA, | ||
1352 | 107 | GL_ONE); | ||
1353 | 108 | GfxContext.PopClippingRectangle(); | ||
1354 | 109 | } | ||
1355 | 110 | |||
1356 | 111 | void LoadImages (const char *name) | ||
1357 | 112 | { | ||
1358 | 113 | //FIXME: We need to somehow be theme aware. Or, at least support the themes | ||
1359 | 114 | // we know and have a good default fallback | ||
1360 | 115 | gchar *filename; | ||
1361 | 116 | GError *error = NULL; | ||
1362 | 117 | GdkPixbuf *_normal; | ||
1363 | 118 | GdkPixbuf *_prelight; | ||
1364 | 119 | GdkPixbuf *_pressed; | ||
1365 | 120 | |||
1366 | 121 | filename = g_strdup_printf ("%s/%s.png", AMBIANCE, name); | ||
1367 | 122 | _normal = gdk_pixbuf_new_from_file (filename, &error); | ||
1368 | 123 | if (error) | ||
1369 | 124 | { | ||
1370 | 125 | g_warning ("Unable to load window button %s: %s", filename, error->message); | ||
1371 | 126 | g_error_free (error); | ||
1372 | 127 | error = NULL; | ||
1373 | 128 | } | ||
1374 | 129 | else | ||
1375 | 130 | _normal_tex = nux::CreateTextureFromPixbuf (_normal); | ||
1376 | 131 | g_free (filename); | ||
1377 | 132 | g_object_unref (_normal); | ||
1378 | 133 | |||
1379 | 134 | filename = g_strdup_printf ("%s/%s_focused_prelight.png", AMBIANCE, name); | ||
1380 | 135 | _prelight = gdk_pixbuf_new_from_file (filename, &error); | ||
1381 | 136 | if (error) | ||
1382 | 137 | { | ||
1383 | 138 | g_warning ("Unable to load window button %s: %s", filename, error->message); | ||
1384 | 139 | g_error_free (error); | ||
1385 | 140 | error = NULL; | ||
1386 | 141 | } | ||
1387 | 142 | else | ||
1388 | 143 | _prelight_tex = nux::CreateTextureFromPixbuf (_prelight); | ||
1389 | 144 | g_free (filename); | ||
1390 | 145 | g_object_unref (_prelight); | ||
1391 | 146 | |||
1392 | 147 | filename = g_strdup_printf ("%s/%s_focused_pressed.png", AMBIANCE, name); | ||
1393 | 148 | _pressed = gdk_pixbuf_new_from_file (filename, &error); | ||
1394 | 149 | if (error) | ||
1395 | 150 | { | ||
1396 | 151 | g_warning ("Unable to load window button %s: %s", name, error->message); | ||
1397 | 152 | g_error_free (error); | ||
1398 | 153 | error = NULL; | ||
1399 | 154 | } | ||
1400 | 155 | else | ||
1401 | 156 | _pressed_tex = nux::CreateTextureFromPixbuf (_pressed); | ||
1402 | 157 | g_free (filename); | ||
1403 | 158 | g_object_unref (_pressed); | ||
1404 | 159 | |||
1405 | 160 | if (_normal_tex) | ||
1406 | 161 | SetMinimumSize (_normal_tex->GetWidth (), _normal_tex->GetHeight ()); | ||
1407 | 162 | } | ||
1408 | 163 | |||
1409 | 164 | private: | ||
1410 | 165 | nux::BaseTexture *_normal_tex; | ||
1411 | 166 | nux::BaseTexture *_prelight_tex; | ||
1412 | 167 | nux::BaseTexture *_pressed_tex; | ||
1413 | 168 | }; | ||
1414 | 169 | |||
1415 | 170 | |||
1416 | 171 | WindowButtons::WindowButtons () | ||
1417 | 172 | : HLayout ("", NUX_TRACKER_LOCATION) | ||
1418 | 173 | { | ||
1419 | 174 | WindowButton *but; | ||
1420 | 175 | |||
1421 | 176 | but = new WindowButton (BUTTON_CLOSE); | ||
1422 | 177 | AddView (but, 0, nux::eCenter, nux::eFix); | ||
1423 | 178 | but->sigClick.connect (sigc::mem_fun (this, &WindowButtons::OnCloseClicked)); | ||
1424 | 179 | but->OnMouseEnter.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseEnter)); | ||
1425 | 180 | but->OnMouseLeave.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseLeave)); | ||
1426 | 181 | |||
1427 | 182 | but = new WindowButton (BUTTON_MINIMISE); | ||
1428 | 183 | AddView (but, 0, nux::eCenter, nux::eFix); | ||
1429 | 184 | but->sigClick.connect (sigc::mem_fun (this, &WindowButtons::OnMinimizeClicked)); | ||
1430 | 185 | but->OnMouseEnter.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseEnter)); | ||
1431 | 186 | but->OnMouseLeave.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseLeave)); | ||
1432 | 187 | |||
1433 | 188 | but = new WindowButton (BUTTON_UNMAXIMISE); | ||
1434 | 189 | AddView (but, 0, nux::eCenter, nux::eFix); | ||
1435 | 190 | but->sigClick.connect (sigc::mem_fun (this, &WindowButtons::OnRestoreClicked)); | ||
1436 | 191 | but->OnMouseEnter.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseEnter)); | ||
1437 | 192 | but->OnMouseLeave.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseLeave)); | ||
1438 | 193 | |||
1439 | 194 | SetContentDistribution (nux::eStackLeft); | ||
1440 | 195 | } | ||
1441 | 196 | |||
1442 | 197 | |||
1443 | 198 | WindowButtons::~WindowButtons () | ||
1444 | 199 | { | ||
1445 | 200 | } | ||
1446 | 201 | |||
1447 | 202 | void | ||
1448 | 203 | WindowButtons::OnCloseClicked () | ||
1449 | 204 | { | ||
1450 | 205 | close_clicked.emit (); | ||
1451 | 206 | } | ||
1452 | 207 | |||
1453 | 208 | void | ||
1454 | 209 | WindowButtons::OnMinimizeClicked () | ||
1455 | 210 | { | ||
1456 | 211 | minimize_clicked.emit (); | ||
1457 | 212 | } | ||
1458 | 213 | |||
1459 | 214 | void | ||
1460 | 215 | WindowButtons::OnRestoreClicked () | ||
1461 | 216 | { | ||
1462 | 217 | restore_clicked.emit (); | ||
1463 | 218 | } | ||
1464 | 219 | |||
1465 | 220 | const gchar * | ||
1466 | 221 | WindowButtons::GetName () | ||
1467 | 222 | { | ||
1468 | 223 | return "window-buttons"; | ||
1469 | 224 | } | ||
1470 | 225 | |||
1471 | 226 | const gchar * | ||
1472 | 227 | WindowButtons::GetChildsName () | ||
1473 | 228 | { | ||
1474 | 229 | return ""; | ||
1475 | 230 | } | ||
1476 | 231 | |||
1477 | 232 | void | ||
1478 | 233 | WindowButtons::AddProperties (GVariantBuilder *builder) | ||
1479 | 234 | { | ||
1480 | 235 | nux::Geometry geo = GetGeometry (); | ||
1481 | 236 | |||
1482 | 237 | /* Now some props from ourselves */ | ||
1483 | 238 | g_variant_builder_add (builder, "{sv}", "x", g_variant_new_int32 (geo.x)); | ||
1484 | 239 | g_variant_builder_add (builder, "{sv}", "y", g_variant_new_int32 (geo.y)); | ||
1485 | 240 | g_variant_builder_add (builder, "{sv}", "width", g_variant_new_int32 (geo.width)); | ||
1486 | 241 | g_variant_builder_add (builder, "{sv}", "height", g_variant_new_int32 (geo.height)); | ||
1487 | 242 | } | ||
1488 | 243 | |||
1489 | 244 | void WindowButtons::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags) | ||
1490 | 245 | { | ||
1491 | 246 | redraw_signal.emit (); | ||
1492 | 247 | } | ||
1493 | 248 | |||
1494 | 249 | void WindowButtons::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags) | ||
1495 | 250 | { | ||
1496 | 251 | redraw_signal.emit (); | ||
1497 | 252 | } | ||
1498 | 253 | |||
1499 | 254 | |||
1500 | 0 | 255 | ||
1501 | === added file 'src/WindowButtons.h' | |||
1502 | --- src/WindowButtons.h 1970-01-01 00:00:00 +0000 | |||
1503 | +++ src/WindowButtons.h 2010-12-17 10:43:24 +0000 | |||
1504 | @@ -0,0 +1,63 @@ | |||
1505 | 1 | /* | ||
1506 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
1507 | 3 | * | ||
1508 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1509 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
1510 | 6 | * published by the Free Software Foundation. | ||
1511 | 7 | * | ||
1512 | 8 | * This program is distributed in the hope that it will be useful, | ||
1513 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1514 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1515 | 11 | * GNU General Public License for more details. | ||
1516 | 12 | * | ||
1517 | 13 | * You should have received a copy of the GNU General Public License | ||
1518 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1519 | 15 | * | ||
1520 | 16 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | ||
1521 | 17 | */ | ||
1522 | 18 | |||
1523 | 19 | #ifndef WINDOW_BUTTONS_H | ||
1524 | 20 | #define WINDOW_BUTTONS_H | ||
1525 | 21 | |||
1526 | 22 | #include <Nux/View.h> | ||
1527 | 23 | |||
1528 | 24 | #include "Introspectable.h" | ||
1529 | 25 | |||
1530 | 26 | class WindowButtons : public nux::HLayout, public Introspectable | ||
1531 | 27 | { | ||
1532 | 28 | // These are the [close][minimize][restore] buttons on the panel when there | ||
1533 | 29 | // is a maximized window | ||
1534 | 30 | |||
1535 | 31 | public: | ||
1536 | 32 | WindowButtons (); | ||
1537 | 33 | ~WindowButtons (); | ||
1538 | 34 | |||
1539 | 35 | sigc::signal<void> close_clicked; | ||
1540 | 36 | sigc::signal<void> minimize_clicked; | ||
1541 | 37 | sigc::signal<void> restore_clicked; | ||
1542 | 38 | sigc::signal<void> redraw_signal; | ||
1543 | 39 | |||
1544 | 40 | protected: | ||
1545 | 41 | const gchar * GetName (); | ||
1546 | 42 | const gchar * GetChildsName (); | ||
1547 | 43 | void AddProperties (GVariantBuilder *builder); | ||
1548 | 44 | |||
1549 | 45 | |||
1550 | 46 | // For testing the buttons | ||
1551 | 47 | void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags); | ||
1552 | 48 | void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags); | ||
1553 | 49 | void RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags); | ||
1554 | 50 | void RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags); | ||
1555 | 51 | void RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags); | ||
1556 | 52 | void RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); | ||
1557 | 53 | |||
1558 | 54 | private: | ||
1559 | 55 | void OnCloseClicked (); | ||
1560 | 56 | void OnMinimizeClicked (); | ||
1561 | 57 | void OnRestoreClicked (); | ||
1562 | 58 | |||
1563 | 59 | private: | ||
1564 | 60 | nux::HLayout *_layout; | ||
1565 | 61 | }; | ||
1566 | 62 | |||
1567 | 63 | #endif | ||
1568 | 0 | 64 | ||
1569 | === added file 'src/WindowManager.cpp' | |||
1570 | --- src/WindowManager.cpp 1970-01-01 00:00:00 +0000 | |||
1571 | +++ src/WindowManager.cpp 2010-12-17 10:43:24 +0000 | |||
1572 | @@ -0,0 +1,171 @@ | |||
1573 | 1 | /* | ||
1574 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
1575 | 3 | * | ||
1576 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1577 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
1578 | 6 | * published by the Free Software Foundation. | ||
1579 | 7 | * | ||
1580 | 8 | * This program is distributed in the hope that it will be useful, | ||
1581 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1582 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1583 | 11 | * GNU General Public License for more details. | ||
1584 | 12 | * | ||
1585 | 13 | * You should have received a copy of the GNU General Public License | ||
1586 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1587 | 15 | * | ||
1588 | 16 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | ||
1589 | 17 | */ | ||
1590 | 18 | |||
1591 | 19 | #include "WindowManager.h" | ||
1592 | 20 | |||
1593 | 21 | #include <gdk/gdkx.h> | ||
1594 | 22 | |||
1595 | 23 | typedef struct { | ||
1596 | 24 | unsigned long flags; | ||
1597 | 25 | unsigned long functions; | ||
1598 | 26 | unsigned long decorations; | ||
1599 | 27 | long input_mode; | ||
1600 | 28 | unsigned long status; | ||
1601 | 29 | } MotifWmHints, MwmHints; | ||
1602 | 30 | |||
1603 | 31 | #define MWM_HINTS_FUNCTIONS (1L << 0) | ||
1604 | 32 | #define MWM_HINTS_DECORATIONS (1L << 1) | ||
1605 | 33 | #define _XA_MOTIF_WM_HINTS "_MOTIF_WM_HINTS" | ||
1606 | 34 | |||
1607 | 35 | static void gdk_window_set_mwm_hints (Window xid, | ||
1608 | 36 | MotifWmHints *new_hints); | ||
1609 | 37 | |||
1610 | 38 | |||
1611 | 39 | static WindowManager *window_manager = NULL; | ||
1612 | 40 | |||
1613 | 41 | class WindowManagerDummy : public WindowManager | ||
1614 | 42 | { | ||
1615 | 43 | bool IsWindowMaximized (guint32 xid) | ||
1616 | 44 | { | ||
1617 | 45 | return false; | ||
1618 | 46 | } | ||
1619 | 47 | |||
1620 | 48 | bool IsWindowDecorated (guint32 xid) | ||
1621 | 49 | { | ||
1622 | 50 | return true; | ||
1623 | 51 | } | ||
1624 | 52 | |||
1625 | 53 | void Restore (guint32 xid) | ||
1626 | 54 | { | ||
1627 | 55 | g_debug ("%s", G_STRFUNC); | ||
1628 | 56 | } | ||
1629 | 57 | |||
1630 | 58 | void Minimize (guint32 xid) | ||
1631 | 59 | { | ||
1632 | 60 | g_debug ("%s", G_STRFUNC); | ||
1633 | 61 | } | ||
1634 | 62 | |||
1635 | 63 | void Close (guint32 xid) | ||
1636 | 64 | { | ||
1637 | 65 | g_debug ("%s", G_STRFUNC); | ||
1638 | 66 | } | ||
1639 | 67 | }; | ||
1640 | 68 | |||
1641 | 69 | WindowManager * | ||
1642 | 70 | WindowManager::Default () | ||
1643 | 71 | { | ||
1644 | 72 | if (!window_manager) | ||
1645 | 73 | window_manager = new WindowManagerDummy (); | ||
1646 | 74 | |||
1647 | 75 | return window_manager; | ||
1648 | 76 | } | ||
1649 | 77 | |||
1650 | 78 | void | ||
1651 | 79 | WindowManager::SetDefault (WindowManager *manager) | ||
1652 | 80 | { | ||
1653 | 81 | window_manager = manager; | ||
1654 | 82 | } | ||
1655 | 83 | |||
1656 | 84 | void | ||
1657 | 85 | WindowManager::Decorate (guint32 xid) | ||
1658 | 86 | { | ||
1659 | 87 | MotifWmHints hints = { 0 }; | ||
1660 | 88 | |||
1661 | 89 | hints.flags = MWM_HINTS_DECORATIONS; | ||
1662 | 90 | hints.decorations = GDK_DECOR_ALL; | ||
1663 | 91 | |||
1664 | 92 | gdk_window_set_mwm_hints (xid, &hints); | ||
1665 | 93 | } | ||
1666 | 94 | |||
1667 | 95 | void | ||
1668 | 96 | WindowManager::Undecorate (guint32 xid) | ||
1669 | 97 | { | ||
1670 | 98 | MotifWmHints hints = { 0 }; | ||
1671 | 99 | |||
1672 | 100 | hints.flags = MWM_HINTS_DECORATIONS; | ||
1673 | 101 | hints.decorations = 0; | ||
1674 | 102 | |||
1675 | 103 | gdk_window_set_mwm_hints (xid, &hints); | ||
1676 | 104 | } | ||
1677 | 105 | |||
1678 | 106 | /* | ||
1679 | 107 | * Copied over C code | ||
1680 | 108 | */ | ||
1681 | 109 | static void | ||
1682 | 110 | gdk_window_set_mwm_hints (Window xid, | ||
1683 | 111 | MotifWmHints *new_hints) | ||
1684 | 112 | { | ||
1685 | 113 | GdkDisplay *display = gdk_display_get_default(); | ||
1686 | 114 | Atom hints_atom = None; | ||
1687 | 115 | guchar *data = NULL; | ||
1688 | 116 | MotifWmHints *hints = NULL; | ||
1689 | 117 | Atom type = None; | ||
1690 | 118 | gint format; | ||
1691 | 119 | gulong nitems; | ||
1692 | 120 | gulong bytes_after; | ||
1693 | 121 | |||
1694 | 122 | g_return_if_fail (GDK_IS_DISPLAY (display)); | ||
1695 | 123 | |||
1696 | 124 | hints_atom = gdk_x11_get_xatom_by_name_for_display (display, | ||
1697 | 125 | _XA_MOTIF_WM_HINTS); | ||
1698 | 126 | |||
1699 | 127 | gdk_error_trap_push (); | ||
1700 | 128 | XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), | ||
1701 | 129 | xid, | ||
1702 | 130 | hints_atom, 0, sizeof (MotifWmHints)/sizeof (long), | ||
1703 | 131 | False, AnyPropertyType, &type, &format, &nitems, | ||
1704 | 132 | &bytes_after, &data); | ||
1705 | 133 | gdk_flush (); | ||
1706 | 134 | if (gdk_error_trap_pop ()) | ||
1707 | 135 | { | ||
1708 | 136 | g_debug ("ERROR: Cannot set decorations"); | ||
1709 | 137 | return; | ||
1710 | 138 | } | ||
1711 | 139 | |||
1712 | 140 | if (type != hints_atom || !data) | ||
1713 | 141 | hints = new_hints; | ||
1714 | 142 | else | ||
1715 | 143 | { | ||
1716 | 144 | hints = (MotifWmHints *)data; | ||
1717 | 145 | |||
1718 | 146 | if (new_hints->flags & MWM_HINTS_FUNCTIONS) | ||
1719 | 147 | { | ||
1720 | 148 | hints->flags |= MWM_HINTS_FUNCTIONS; | ||
1721 | 149 | hints->functions = new_hints->functions; | ||
1722 | 150 | } | ||
1723 | 151 | if (new_hints->flags & MWM_HINTS_DECORATIONS) | ||
1724 | 152 | { | ||
1725 | 153 | hints->flags |= MWM_HINTS_DECORATIONS; | ||
1726 | 154 | hints->decorations = new_hints->decorations; | ||
1727 | 155 | } | ||
1728 | 156 | } | ||
1729 | 157 | |||
1730 | 158 | gdk_error_trap_push (); | ||
1731 | 159 | XChangeProperty (GDK_DISPLAY_XDISPLAY (display), | ||
1732 | 160 | xid, | ||
1733 | 161 | hints_atom, hints_atom, 32, PropModeReplace, | ||
1734 | 162 | (guchar *)hints, sizeof (MotifWmHints)/sizeof (long)); | ||
1735 | 163 | gdk_flush (); | ||
1736 | 164 | if (gdk_error_trap_pop ()) | ||
1737 | 165 | { | ||
1738 | 166 | g_debug ("ERROR: Setting decorations"); | ||
1739 | 167 | } | ||
1740 | 168 | |||
1741 | 169 | if (data) | ||
1742 | 170 | XFree (data); | ||
1743 | 171 | } | ||
1744 | 0 | 172 | ||
1745 | === added file 'src/WindowManager.h' | |||
1746 | --- src/WindowManager.h 1970-01-01 00:00:00 +0000 | |||
1747 | +++ src/WindowManager.h 2010-12-17 10:43:24 +0000 | |||
1748 | @@ -0,0 +1,57 @@ | |||
1749 | 1 | /* | ||
1750 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
1751 | 3 | * | ||
1752 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1753 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
1754 | 6 | * published by the Free Software Foundation. | ||
1755 | 7 | * | ||
1756 | 8 | * This program is distributed in the hope that it will be useful, | ||
1757 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1758 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1759 | 11 | * GNU General Public License for more details. | ||
1760 | 12 | * | ||
1761 | 13 | * You should have received a copy of the GNU General Public License | ||
1762 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1763 | 15 | * | ||
1764 | 16 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | ||
1765 | 17 | */ | ||
1766 | 18 | |||
1767 | 19 | #ifndef WINDOW_MANAGER_H | ||
1768 | 20 | #define WINDOW_MANAGER_H | ||
1769 | 21 | |||
1770 | 22 | #include <glib.h> | ||
1771 | 23 | #include <sigc++/sigc++.h> | ||
1772 | 24 | |||
1773 | 25 | class WindowManager | ||
1774 | 26 | { | ||
1775 | 27 | // This is a glue interface that breaks the dependancy of Unity with Compiz | ||
1776 | 28 | // Basically it has a default implementation that does nothing useful, but | ||
1777 | 29 | // the idea is that unity.cpp uses SetDefault() early enough in it's | ||
1778 | 30 | // initialization so the things that require it get a usable implementation | ||
1779 | 31 | // | ||
1780 | 32 | // Currently only the Panel uses it but hopefully we'll get more of | ||
1781 | 33 | // PluginAdaptor features moved into here and also get the Launcher to use | ||
1782 | 34 | // it. | ||
1783 | 35 | |||
1784 | 36 | public: | ||
1785 | 37 | static WindowManager * Default (); | ||
1786 | 38 | static void SetDefault (WindowManager *manager); | ||
1787 | 39 | |||
1788 | 40 | virtual bool IsWindowMaximized (guint32 xid) = 0; | ||
1789 | 41 | virtual bool IsWindowDecorated (guint32 xid) = 0; | ||
1790 | 42 | |||
1791 | 43 | virtual void Restore (guint32 xid) = 0; | ||
1792 | 44 | virtual void Minimize (guint32 xid) = 0; | ||
1793 | 45 | virtual void Close (guint32 xid) = 0; | ||
1794 | 46 | |||
1795 | 47 | virtual void Decorate (guint32 xid); | ||
1796 | 48 | virtual void Undecorate (guint32 xid); | ||
1797 | 49 | |||
1798 | 50 | // Signals | ||
1799 | 51 | sigc::signal<void, guint32> window_mapped; | ||
1800 | 52 | sigc::signal<void, guint32> window_unmapped; | ||
1801 | 53 | sigc::signal<void, guint32> window_maximized; | ||
1802 | 54 | sigc::signal<void, guint32> window_restored; | ||
1803 | 55 | }; | ||
1804 | 56 | |||
1805 | 57 | #endif // WINDOW_MANAGER_H | ||
1806 | 0 | 58 | ||
1807 | === modified file 'src/unity.cpp' | |||
1808 | --- src/unity.cpp 2010-12-16 21:07:28 +0000 | |||
1809 | +++ src/unity.cpp 2010-12-17 10:43:24 +0000 | |||
1810 | @@ -395,6 +395,8 @@ | |||
1811 | 395 | GLScreenInterface::setHandler (gScreen); | 395 | GLScreenInterface::setHandler (gScreen); |
1812 | 396 | 396 | ||
1813 | 397 | PluginAdapter::Initialize (screen); | 397 | PluginAdapter::Initialize (screen); |
1814 | 398 | WindowManager::SetDefault (PluginAdapter::Default ()); | ||
1815 | 399 | |||
1816 | 398 | StartupNotifyService::Default ()->SetSnDisplay (screen->snDisplay (), screen->screenNum ()); | 400 | StartupNotifyService::Default ()->SetSnDisplay (screen->snDisplay (), screen->screenNum ()); |
1817 | 399 | 401 | ||
1818 | 400 | nux::NuxInitialize (0); | 402 | nux::NuxInitialize (0); |
1819 | @@ -410,7 +412,6 @@ | |||
1820 | 410 | 412 | ||
1821 | 411 | debugger = new IntrospectionDBusInterface (this); | 413 | debugger = new IntrospectionDBusInterface (this); |
1822 | 412 | 414 | ||
1823 | 413 | |||
1824 | 414 | optionSetLauncherAutohideNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2)); | 415 | optionSetLauncherAutohideNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2)); |
1825 | 415 | optionSetLauncherFloatNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2)); | 416 | optionSetLauncherFloatNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2)); |
1826 | 416 | 417 | ||
1827 | 417 | 418 | ||
1828 | === modified file 'tests/CMakeLists.txt' | |||
1829 | --- tests/CMakeLists.txt 2010-12-13 09:54:54 +0000 | |||
1830 | +++ tests/CMakeLists.txt 2010-12-17 10:43:24 +0000 | |||
1831 | @@ -82,6 +82,14 @@ | |||
1832 | 82 | ../src/Introspectable.h | 82 | ../src/Introspectable.h |
1833 | 83 | ../src/PanelHomeButton.cpp | 83 | ../src/PanelHomeButton.cpp |
1834 | 84 | ../src/PanelHomeButton.h | 84 | ../src/PanelHomeButton.h |
1835 | 85 | ../src/PanelMenuView.cpp | ||
1836 | 86 | ../src/PanelMenuView.h | ||
1837 | 87 | ../src/StaticCairoText.cpp | ||
1838 | 88 | ../src/StaticCairoText.h | ||
1839 | 89 | ../src/WindowButtons.cpp | ||
1840 | 90 | ../src/WindowButtons.h | ||
1841 | 91 | ../src/WindowManager.cpp | ||
1842 | 92 | ../src/WindowManager.h | ||
1843 | 85 | ../libunity/ubus-server.c | 93 | ../libunity/ubus-server.c |
1844 | 86 | ../libunity/ubus-server.h | 94 | ../libunity/ubus-server.h |
1845 | 87 | ) | 95 | ) |
Oh, some of the linked bugs are because of reusing the same branch, please ignore that.