Merge lp:~renatofilho/unity/unity-lp876017-fixes into lp:unity
- unity-lp876017-fixes
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Timo Jyrinki |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2662 |
Proposed branch: | lp:~renatofilho/unity/unity-lp876017-fixes |
Merge into: | lp:unity |
Diff against target: |
981 lines (+425/-321) 7 files modified
plugins/unityshell/src/unityshell.cpp (+311/-295) plugins/unityshell/src/unityshell.h (+30/-26) unity-shared/PluginAdapter.h (+4/-0) unity-shared/PluginAdapterCompiz.cpp (+67/-0) unity-shared/PluginAdapterStandalone.cpp (+6/-0) unity-shared/WindowManager.cpp (+5/-0) unity-shared/WindowManager.h (+2/-0) |
To merge this branch: | bzr merge lp:~renatofilho/unity/unity-lp876017-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marco Trevisan (Treviño) | Approve | ||
jenkins | continuous-integration | Pending | |
Review via email: mp+122357@code.launchpad.net |
Commit message
UnityWindow: scale window code improved
* Fixed code style.
* Moved function "GetWindowName" from UnityWindow to WindowManager.
* Used glib::Object auto pointer instead of "c" pointer;
Description of the change
* Fixed code style.
* Moved function "GetWindowName" from UnityWindow to WindowManager.
* Used glib::Object auto pointer instead of "c" pointer;
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
> Another thing that should be fixed is the titlebar font, You're actually using
> a sans font, but you should instead use the system font; you can see again
> QuicklistMenuIt
Err... I didn't remember I wrote Style::
Michal Hruby (mhr3) wrote : | # |
> 23:29:10 <renato> this last point you notice about the string, I do not think
> this is a good solution since the string is created internally by
> "XGetWindowProp
>
> Yeah, but XFree is basically free, so I'd ust glib::String for that too.
>
Mixing memory allocation functions from multiple libraries isn't a good idea... Yes, right now both XFree and g_free might be just aliases for free(), but that doesn't mean that's always the case. Please keep the XFree.
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Mh, I see that the fade is using a linear gradient here, I think you should change it so that it only cuts the exceeding pixels with a small fade effect (as the top bar does).
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Ah, another thing... Is it just me or I see the top bar starting one px before the thumbnail x?
Michal Hruby (mhr3) wrote : | # |
> Ah, another thing... Is it just me or I see the top bar starting one px before
> the thumbnail x?
>
> http://
Seeing that too, not all the time though, perhaps a float conversion issue?
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
> Mh, I see that the fade is using a linear gradient here, I think you should
> change it so that it only cuts the exceeding pixels with a small fade effect
> (as the top bar does).
I'm using the same code used as "PanelMenuView:
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
> > Mh, I see that the fade is using a linear gradient here, I think you should
> > change it so that it only cuts the exceeding pixels with a small fade effect
> > (as the top bar does).
>
>
> I'm using the same code used as "PanelMenuView:
> are you talking about?
Ok I found the problem, fixed on rev. 2658
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
Hi guys I have fixed the problems, but I found a problem related with maximized windows which is not exactly related with this bug, but produce a bad window drawing. Take a look on this image: http://
How I can fix it?
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
> Hi guys I have fixed the problems, but I found a problem related with
> maximized windows which is not exactly related with this bug, but produce a
> bad window drawing. Take a look on this image: http://
>
> How I can fix it?
Mhm, I think you need make scale to produce smaller windows that consider the height of your decoration.
See if you can set that at scale level and then make unity to define its padding.
Loris Zinsou (nepenthes) wrote : | # |
I'm still running the Unity Staging PPA version of Unity, any idea why the maximized window decoration cannot be clicked to raise the window ? Un-maximised windows are not affected by this issue.
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
> I'm still running the Unity Staging PPA version of Unity, any idea why the
> maximized window decoration cannot be clicked to raise the window ? Un-
> maximised windows are not affected by this issue.
yes I have fixed this on rev: 2660, this happen because the maximized window does not have decorations.
Loris Zinsou (nepenthes) wrote : | # |
That's fine then !
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Looks good, further improvements coming into lp:~3v1n0/unity/spread-title-improved
Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
Preview Diff
1 | === modified file 'plugins/unityshell/src/unityshell.cpp' |
2 | --- plugins/unityshell/src/unityshell.cpp 2012-08-31 13:21:02 +0000 |
3 | +++ plugins/unityshell/src/unityshell.cpp 2012-09-04 17:21:20 +0000 |
4 | @@ -110,6 +110,8 @@ |
5 | class WindowCairoContext |
6 | { |
7 | public: |
8 | + typedef std::shared_ptr<WindowCairoContext> Ptr; |
9 | + |
10 | Pixmap pixmap_; |
11 | cairo_surface_t* surface_; |
12 | GLTexture::List texture_; |
13 | @@ -421,7 +423,10 @@ |
14 | } |
15 | |
16 | panel::Style::Instance().changed.connect(sigc::mem_fun(this, &UnityScreen::OnPanelStyleChanged)); |
17 | - |
18 | + |
19 | + WindowManager::Default()->initiate_spread.connect(sigc::mem_fun(this, &UnityScreen::OnInitiateSpreed)); |
20 | + WindowManager::Default()->terminate_spread.connect(sigc::mem_fun(this, &UnityScreen::OnTerminateSpreed)); |
21 | + |
22 | minimize_speed_controller->DurationChanged.connect( |
23 | sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged) |
24 | ); |
25 | @@ -438,6 +443,25 @@ |
26 | reset_glib_logging(); |
27 | } |
28 | |
29 | +void UnityScreen::OnInitiateSpreed() |
30 | +{ |
31 | + for (CompWindow *w : screen->windows()) |
32 | + { |
33 | + UnityWindow *uw = UnityWindow::get(w); |
34 | + uw->InitiateSpreed(); |
35 | + } |
36 | +} |
37 | + |
38 | +void UnityScreen::OnTerminateSpreed() |
39 | +{ |
40 | + for (CompWindow *w : screen->windows()) |
41 | + { |
42 | + UnityWindow *uw = UnityWindow::get(w); |
43 | + uw->TerminateSpreed(); |
44 | + } |
45 | +} |
46 | + |
47 | + |
48 | void UnityScreen::initAltTabNextWindow() |
49 | { |
50 | KeyboardUtil key_util(screen->dpy()); |
51 | @@ -1257,7 +1281,8 @@ |
52 | } |
53 | } |
54 | |
55 | -CompRect UnityWindow::closeButtonArea () |
56 | +CompRect |
57 | +UnityWindow::CloseButtonArea() |
58 | { |
59 | return close_button_area_; |
60 | } |
61 | @@ -1633,14 +1658,14 @@ |
62 | event->xbutton.button == Button1 && |
63 | highlighted_window_ != 0) |
64 | { |
65 | - CompWindow *w = screen->findWindow (highlighted_window_); |
66 | + CompWindow *w = screen->findWindow(highlighted_window_); |
67 | if (w) |
68 | { |
69 | - UnityWindow *uw = UnityWindow::get (w); |
70 | - CompPoint pointer (pointerX, pointerY); |
71 | - if (uw->closeButtonArea ().contains (pointer)) |
72 | + UnityWindow *uw = UnityWindow::get(w); |
73 | + CompPoint pointer(pointerX, pointerY); |
74 | + if (uw->CloseButtonArea().contains(pointer)) |
75 | { |
76 | - w->close (0); |
77 | + w->close(0); |
78 | skip_other_plugins = true; |
79 | } |
80 | } |
81 | @@ -3517,18 +3542,19 @@ |
82 | } |
83 | } |
84 | |
85 | -void UnityWindow::DrawTexture (GLTexture* icon, |
86 | - const GLWindowPaintAttrib& attrib, |
87 | - const GLMatrix& transform, |
88 | - unsigned int mask, |
89 | - float x, float y, |
90 | - int &maxWidth, int &maxHeight) |
91 | +void |
92 | +UnityWindow::DrawTexture(GLTexture* icon, |
93 | + const GLWindowPaintAttrib& attrib, |
94 | + const GLMatrix& transform, |
95 | + unsigned int mask, |
96 | + float x, float y, |
97 | + int &maxWidth, int &maxHeight) |
98 | { |
99 | if (icon) |
100 | { |
101 | int width, height; |
102 | - width = icon->width (); |
103 | - height = icon->height (); |
104 | + width = icon->width(); |
105 | + height = icon->height(); |
106 | |
107 | if (height > maxHeight) |
108 | maxHeight = height; |
109 | @@ -3536,271 +3562,343 @@ |
110 | if (width > maxWidth) |
111 | maxWidth = width; |
112 | |
113 | - CompRegion iconReg (0, 0, width, height); |
114 | - GLTexture::MatrixList ml (1); |
115 | + CompRegion iconReg(0, 0, width, height); |
116 | + GLTexture::MatrixList ml(1); |
117 | |
118 | - ml[0] = icon->matrix (); |
119 | - gWindow->vertexBuffer ()->begin (); |
120 | + ml[0] = icon->matrix(); |
121 | + gWindow->vertexBuffer()->begin(); |
122 | if (width && height) |
123 | - gWindow->glAddGeometry (ml, iconReg, iconReg); |
124 | - |
125 | - if (gWindow->vertexBuffer ()->end ()) |
126 | - { |
127 | - GLMatrix wTransform (transform); |
128 | - |
129 | - wTransform.translate (x, y, 0.0f); |
130 | - |
131 | - gWindow->glDrawTexture (icon, wTransform, attrib, mask); |
132 | - } |
133 | - } |
134 | -} |
135 | - |
136 | -WindowCairoContext* UnityWindow::CreateCairoContext (float width, float height) |
137 | -{ |
138 | - XRenderPictFormat *format; |
139 | - Screen *xScreen; |
140 | - WindowCairoContext *context = new WindowCairoContext(); |
141 | - |
142 | - xScreen = ScreenOfDisplay (screen->dpy (), screen->screenNum ()); |
143 | - |
144 | - format = XRenderFindStandardFormat (screen->dpy (), PictStandardARGB32); |
145 | - context->pixmap_ = XCreatePixmap (screen->dpy (), |
146 | - screen->root (), |
147 | - width, height, 32); |
148 | - |
149 | - context->texture_ = GLTexture::bindPixmapToTexture (context->pixmap_, |
150 | - width, height, |
151 | - 32); |
152 | - if (context->texture_.empty ()) |
153 | - { |
154 | - delete context; |
155 | - return 0; |
156 | - } |
157 | - |
158 | - context->surface_ = cairo_xlib_surface_create_with_xrender_format (screen->dpy (), |
159 | - context->pixmap_, |
160 | - xScreen, |
161 | - format, |
162 | - width, |
163 | - height); |
164 | - context->cr_ = cairo_create (context->surface_); |
165 | - |
166 | - // clear |
167 | - cairo_save (context->cr_); |
168 | - cairo_set_operator (context->cr_, CAIRO_OPERATOR_CLEAR); |
169 | - cairo_paint (context->cr_); |
170 | - cairo_restore (context->cr_); |
171 | - |
172 | - return context; |
173 | -} |
174 | - |
175 | -void UnityWindow::RenderText (WindowCairoContext *context, |
176 | - float x, float y, |
177 | - float maxWidth, float maxHeight) |
178 | -{ |
179 | - PangoFontDescription* font = pango_font_description_new (); |
180 | - pango_font_description_set_family (font, "sans"); |
181 | - pango_font_description_set_absolute_size (font, 12 * PANGO_SCALE); |
182 | - pango_font_description_set_style (font, PANGO_STYLE_NORMAL); |
183 | - pango_font_description_set_weight (font, PANGO_WEIGHT_BOLD); |
184 | - |
185 | - PangoLayout* layout = pango_cairo_create_layout (context->cr_); |
186 | - pango_layout_set_font_description (layout, font); |
187 | - pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); |
188 | - pango_layout_set_height (layout, maxHeight); |
189 | - |
190 | - pango_layout_set_auto_dir (layout, false); |
191 | - pango_layout_set_text (layout, |
192 | - GetWindowName (window->id ()).c_str (), |
193 | - -1); |
194 | + gWindow->glAddGeometry(ml, iconReg, iconReg); |
195 | + |
196 | + if (gWindow->vertexBuffer()->end()) |
197 | + { |
198 | + GLMatrix wTransform(transform); |
199 | + |
200 | + wTransform.translate(x, y, 0.0f); |
201 | + |
202 | + gWindow->glDrawTexture(icon, wTransform, attrib, mask); |
203 | + } |
204 | + } |
205 | +} |
206 | + |
207 | +std::shared_ptr<WindowCairoContext> |
208 | +UnityWindow::CreateCairoContext(float width, float height) |
209 | +{ |
210 | + XRenderPictFormat *format; |
211 | + Screen *xScreen; |
212 | + auto cContext = std::make_shared<WindowCairoContext>(); |
213 | + |
214 | + xScreen = ScreenOfDisplay(screen->dpy(), screen->screenNum()); |
215 | + |
216 | + format = XRenderFindStandardFormat(screen->dpy(), PictStandardARGB32); |
217 | + cContext->pixmap_ = XCreatePixmap(screen->dpy(), |
218 | + screen->root(), |
219 | + width, height, 32); |
220 | + |
221 | + cContext->texture_ = GLTexture::bindPixmapToTexture(cContext->pixmap_, |
222 | + width, height, |
223 | + 32); |
224 | + if (cContext->texture_.empty()) |
225 | + { |
226 | + return 0; |
227 | + } |
228 | + |
229 | + cContext->surface_ = cairo_xlib_surface_create_with_xrender_format(screen->dpy(), |
230 | + cContext->pixmap_, |
231 | + xScreen, |
232 | + format, |
233 | + width, |
234 | + height); |
235 | + cContext->cr_ = cairo_create(cContext->surface_); |
236 | + |
237 | + // clear |
238 | + cairo_save(cContext->cr_); |
239 | + cairo_set_operator(cContext->cr_, CAIRO_OPERATOR_CLEAR); |
240 | + cairo_paint(cContext->cr_); |
241 | + cairo_restore(cContext->cr_); |
242 | + |
243 | + return cContext; |
244 | +} |
245 | + |
246 | +void |
247 | +UnityWindow::RenderText(WindowCairoContext *context, |
248 | + float x, float y, |
249 | + float maxWidth, float maxHeight) |
250 | +{ |
251 | + panel::Style& style = panel::Style::Instance(); |
252 | + std::string fontDescription(style.GetFontDescription(panel::PanelItem::TITLE)); |
253 | + |
254 | + glib::Object<PangoLayout> layout(pango_cairo_create_layout(context->cr_)); |
255 | + std::shared_ptr<PangoFontDescription> font(pango_font_description_from_string(fontDescription.c_str()), |
256 | + pango_font_description_free); |
257 | + |
258 | + pango_layout_set_font_description(layout, font.get()); |
259 | + |
260 | + GdkScreen* gdkScreen = gdk_screen_get_default(); |
261 | + PangoContext* pCxt = pango_layout_get_context(layout); |
262 | + int dpi = style.GetTextDPI(); |
263 | + |
264 | + pango_cairo_context_set_font_options(pCxt, gdk_screen_get_font_options(gdkScreen)); |
265 | + pango_cairo_context_set_resolution(pCxt, dpi / static_cast<float>(PANGO_SCALE)); |
266 | + pango_layout_context_changed(layout); |
267 | + |
268 | + pango_layout_set_height(layout, maxHeight); |
269 | + pango_layout_set_width(layout, -1); //avoid wrap lines |
270 | + pango_layout_set_auto_dir(layout, false); |
271 | + pango_layout_set_text(layout, |
272 | + WindowManager::Default()->GetWindowName(window->id()).c_str(), |
273 | + -1); |
274 | |
275 | /* update the size of the pango layout */ |
276 | - pango_layout_set_width (layout, maxWidth * PANGO_SCALE); |
277 | - pango_cairo_update_layout (context->cr_, layout); |
278 | - |
279 | - cairo_set_operator (context->cr_, CAIRO_OPERATOR_OVER); |
280 | - |
281 | - cairo_set_source_rgba (context->cr_, |
282 | - 1.0, |
283 | - 1.0, |
284 | - 1.0, |
285 | - 1.0); |
286 | + pango_cairo_update_layout(context->cr_, layout); |
287 | + cairo_set_operator(context->cr_, CAIRO_OPERATOR_OVER); |
288 | + cairo_set_source_rgba(context->cr_, |
289 | + 1.0, |
290 | + 1.0, |
291 | + 1.0, |
292 | + 1.0); |
293 | |
294 | // alignment |
295 | - int lWidth, lHeight; |
296 | - pango_layout_get_pixel_size (layout, &lWidth, &lHeight); |
297 | - |
298 | - y = ((maxHeight - lHeight) / 2.0) + y; |
299 | - cairo_translate (context->cr_, x, y); |
300 | - pango_cairo_show_layout (context->cr_, layout); |
301 | + PangoRectangle lRect; |
302 | + int textWidth, textHeight; |
303 | + |
304 | + pango_layout_get_extents(layout, NULL, &lRect); |
305 | + textWidth = lRect.width / PANGO_SCALE; |
306 | + textHeight = lRect.height / PANGO_SCALE; |
307 | + |
308 | + y = ((maxHeight - textHeight) / 2.0) + y; |
309 | + cairo_translate(context->cr_, x, y); |
310 | + |
311 | + if (textWidth > maxWidth) |
312 | + { |
313 | + // apply a fade effect in the right corner |
314 | + const int outPixels = textWidth - maxWidth; |
315 | + const int fadingPixels = 35; |
316 | + const int fadingWidth = outPixels < fadingPixels ? outPixels : fadingPixels; |
317 | + |
318 | + cairo_push_group(context->cr_); |
319 | + pango_cairo_show_layout(context->cr_, layout); |
320 | + cairo_pop_group_to_source(context->cr_); |
321 | + |
322 | + std::shared_ptr<cairo_pattern_t> linpat(cairo_pattern_create_linear(maxWidth - fadingWidth, |
323 | + y, maxWidth, y), |
324 | + cairo_pattern_destroy); |
325 | + cairo_pattern_add_color_stop_rgba(linpat.get(), 0, 0, 0, 0, 1); |
326 | + cairo_pattern_add_color_stop_rgba(linpat.get(), 1, 0, 0, 0, 0); |
327 | + cairo_mask(context->cr_, linpat.get()); |
328 | + } |
329 | + else |
330 | + { |
331 | + pango_cairo_show_layout(context->cr_, layout); |
332 | + } |
333 | } |
334 | |
335 | -void UnityWindow::DrawWindowTitle (const GLWindowPaintAttrib& attrib, |
336 | - const GLMatrix& transform, |
337 | - unsigned int mask, |
338 | - float x, float y, float x2, float y2) |
339 | +void |
340 | +UnityWindow::DrawWindowDecoration(const GLWindowPaintAttrib& attrib, |
341 | + const GLMatrix& transform, |
342 | + unsigned int mask, |
343 | + bool highlighted, |
344 | + float x, float y, float x2, float y2) |
345 | { |
346 | const float width = x2 - x; |
347 | + const float height = y2 - y; |
348 | |
349 | // Paint a fake window decoration |
350 | - WindowCairoContext *context = CreateCairoContext (width, SCALE_WINDOW_TITLE_SIZE); |
351 | + WindowCairoContext::Ptr context(CreateCairoContext(width, height)); |
352 | |
353 | - cairo_save (context->cr_); |
354 | - cairo_push_group (context->cr_); |
355 | + cairo_save(context->cr_); |
356 | + cairo_push_group(context->cr_); |
357 | |
358 | // Round window decoration top border |
359 | - const double height = SCALE_WINDOW_TITLE_SIZE; |
360 | const double aspect = 1.0; |
361 | const double corner_radius = height / 10.0; |
362 | const double radius = corner_radius / aspect; |
363 | const double degrees = M_PI / 180.0; |
364 | |
365 | - cairo_new_sub_path (context->cr_); |
366 | - |
367 | - cairo_arc (context->cr_, radius, radius, radius, 180 * degrees, 270 * degrees); |
368 | - cairo_arc (context->cr_, width - radius, radius, radius, -90 * degrees, 0 * degrees); |
369 | - cairo_line_to (context->cr_, width, height); |
370 | - cairo_line_to (context->cr_, 0, height); |
371 | - |
372 | - cairo_close_path (context->cr_); |
373 | - cairo_clip (context->cr_); |
374 | + cairo_new_sub_path(context->cr_); |
375 | + |
376 | + cairo_arc(context->cr_, radius, radius, radius, 180 * degrees, 270 * degrees); |
377 | + cairo_arc(context->cr_, width - radius, radius, radius, -90 * degrees, 0 * degrees); |
378 | + cairo_line_to(context->cr_, width, height); |
379 | + cairo_line_to(context->cr_, 0, height); |
380 | + |
381 | + cairo_close_path(context->cr_); |
382 | + cairo_clip(context->cr_); |
383 | |
384 | // Draw window decoration abased on gtk style |
385 | - gtk_render_background (window_header_style_, context->cr_, 0, 0, width, SCALE_WINDOW_TITLE_SIZE); |
386 | - gtk_render_frame (window_header_style_, context->cr_, 0, 0, width, SCALE_WINDOW_TITLE_SIZE); |
387 | - |
388 | - cairo_pop_group_to_source (context->cr_); |
389 | - |
390 | - cairo_paint_with_alpha (context->cr_, 1.0); |
391 | - cairo_restore (context->cr_); |
392 | - |
393 | - // Draw windows title |
394 | - RenderText (context, |
395 | - CLOSE_ICON_SPACE * 2 + CLOSE_ICON_SIZE, |
396 | - 0.0, |
397 | - width, SCALE_WINDOW_TITLE_SIZE); |
398 | + gtk_render_background(window_header_style_, context->cr_, 0, 0, width, height); |
399 | + gtk_render_frame(window_header_style_, context->cr_, 0, 0, width, height); |
400 | + |
401 | + cairo_pop_group_to_source(context->cr_); |
402 | + |
403 | + cairo_paint_with_alpha(context->cr_, 1.0); |
404 | + cairo_restore(context->cr_); |
405 | + |
406 | + if (highlighted) |
407 | + { |
408 | + // Draw windows title |
409 | + const float xText = CLOSE_ICON_SPACE * 2 + CLOSE_ICON_SIZE; |
410 | + RenderText(context.get(), |
411 | + xText, 0.0, |
412 | + width - xText, height); |
413 | + } |
414 | |
415 | mask |= PAINT_WINDOW_BLEND_MASK; |
416 | int maxWidth, maxHeight; |
417 | foreach(GLTexture *icon, context->texture_) |
418 | { |
419 | - DrawTexture (icon, attrib, transform, mask, |
420 | - x, y, |
421 | - maxWidth , maxHeight); |
422 | + DrawTexture(icon, attrib, transform, mask, |
423 | + x, y, |
424 | + maxWidth , maxHeight); |
425 | } |
426 | - |
427 | - delete context; |
428 | } |
429 | |
430 | -void UnityWindow::scalePaintDecoration (const GLWindowPaintAttrib& attrib, |
431 | - const GLMatrix& transform, |
432 | - const CompRegion& region, |
433 | - unsigned int mask) |
434 | +void |
435 | +UnityWindow::PrepareHeaderStyle() |
436 | { |
437 | - ScaleWindow *sWindow = ScaleWindow::get (window); |
438 | - if (!sWindow) |
439 | - return; |
440 | - |
441 | - sWindow->scalePaintDecoration (attrib, transform, region, mask); |
442 | - |
443 | - if (!sWindow->hasSlot()) // animation not finished |
444 | - return; |
445 | - |
446 | if (!window_header_style_) |
447 | { |
448 | - GtkWidgetPath* widget_path = gtk_widget_path_new (); |
449 | - gint pos = gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); |
450 | - gtk_widget_path_iter_set_name (widget_path, pos, "UnityPanelWidget"); |
451 | + GtkWidgetPath* widget_path = gtk_widget_path_new(); |
452 | + gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_WINDOW); |
453 | + gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget"); |
454 | |
455 | - window_header_style_ = gtk_style_context_new (); |
456 | - gtk_style_context_set_path (window_header_style_, widget_path); |
457 | - gtk_style_context_add_class (window_header_style_, "gnome-panel-menu-bar"); |
458 | - gtk_style_context_add_class (window_header_style_, "unity-panel"); |
459 | + window_header_style_ = glib::Object<GtkStyleContext>(gtk_style_context_new()); |
460 | + gtk_style_context_set_path(window_header_style_, widget_path); |
461 | + gtk_style_context_add_class(window_header_style_, "gnome-panel-menu-bar"); |
462 | + gtk_style_context_add_class(window_header_style_, "unity-panel"); |
463 | |
464 | // get close button |
465 | panel::Style& style = panel::Style::Instance(); |
466 | |
467 | - std::vector<std::string> files = style.GetWindowButtonFileNames (panel::WindowButtonType::CLOSE, |
468 | - panel::WindowState::NORMAL); |
469 | + std::vector<std::string> files = style.GetWindowButtonFileNames(panel::WindowButtonType::CLOSE, |
470 | + panel::WindowState::NORMAL); |
471 | |
472 | - CompString pName ("unityshell"); |
473 | + CompString pName("unityshell"); |
474 | foreach (std::string file, files) |
475 | { |
476 | - CompString fileName (file.c_str ()); |
477 | - CompSize size (CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); |
478 | - close_icon_ = GLTexture::readImageToTexture (fileName, |
479 | - pName, |
480 | - size); |
481 | - if (close_icon_.size () != 0) |
482 | + CompString fileName(file.c_str ()); |
483 | + CompSize size(CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); |
484 | + close_icon_ = GLTexture::readImageToTexture(fileName, |
485 | + pName, |
486 | + size); |
487 | + if (close_icon_.size() != 0) |
488 | break; |
489 | } |
490 | |
491 | - if (close_icon_.size () == 0) |
492 | + if (close_icon_.size() == 0) |
493 | { |
494 | - CompString fileName (PKGDATADIR"/close_dash.png"); |
495 | - CompSize size (CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); |
496 | - close_icon_ = GLTexture::readImageToTexture (fileName, |
497 | - pName, |
498 | - size); |
499 | + CompString fileName(PKGDATADIR"/close_dash.png"); |
500 | + CompSize size(CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); |
501 | + close_icon_ = GLTexture::readImageToTexture(fileName, |
502 | + pName, |
503 | + size); |
504 | } |
505 | } |
506 | - |
507 | - // Make the windows header opaque to override the original |
508 | - GLWindowPaintAttrib sAttrib (attrib); |
509 | +} |
510 | + |
511 | +void |
512 | +UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, |
513 | + const GLMatrix& transform, |
514 | + const CompRegion& region, |
515 | + unsigned int mask) |
516 | +{ |
517 | + ScaleWindow *sWindow = ScaleWindow::get(window); |
518 | + if (!sWindow) |
519 | + return; |
520 | + |
521 | + sWindow->scalePaintDecoration(attrib, transform, region, mask); |
522 | + |
523 | + if (!sWindow->hasSlot()) // animation not finished |
524 | + return; |
525 | + |
526 | + UnityScreen* us = UnityScreen::get(screen); |
527 | + const guint32 xid = window->id(); |
528 | + const bool highlighted = (us->highlighted_window_ == xid); |
529 | + GLWindowPaintAttrib sAttrib(attrib); |
530 | sAttrib.opacity = OPAQUE; |
531 | |
532 | - ScalePosition pos = sWindow->getCurrentPosition (); |
533 | + PrepareHeaderStyle(); |
534 | + |
535 | + ScalePosition pos = sWindow->getCurrentPosition(); |
536 | int maxHeight, maxWidth; |
537 | - // Use "2" as margin to make sure to cover all originial decoration |
538 | - const float width = (window->width () + 4) * pos.scale; |
539 | - const float x = pos.x () + window->x () - (2 * pos.scale); |
540 | - const float y = pos.y () + window->y () - SCALE_WINDOW_TITLE_SIZE; |
541 | - const float iconX = x + CLOSE_ICON_SPACE; |
542 | - const float iconY = y + ((SCALE_WINDOW_TITLE_SIZE - CLOSE_ICON_SIZE) / 2.0); |
543 | - |
544 | - maxHeight = maxWidth = 0; |
545 | - |
546 | - DrawWindowTitle (sAttrib, |
547 | - transform, |
548 | - mask, |
549 | - x, y, |
550 | - x + width, y + SCALE_WINDOW_TITLE_SIZE); |
551 | - |
552 | - mask |= PAINT_WINDOW_BLEND_MASK; |
553 | - foreach(GLTexture *icon, close_icon_) |
554 | - { |
555 | - DrawTexture (icon, sAttrib, transform, mask, |
556 | - iconX, iconY, |
557 | - maxWidth , maxHeight); |
558 | - } |
559 | - |
560 | - close_button_area_ = CompRect (iconX, iconY, maxWidth, maxHeight); |
561 | + // Use "1" as margin to make sure to cover all originial decoration |
562 | + const float width = (window->width() * pos.scale) + 2; |
563 | + const float x = pos.x() + window->x() - 1; |
564 | + float y = pos.y() + window->y(); |
565 | + float decorationHeight = SCALE_WINDOW_TITLE_SIZE; |
566 | + |
567 | + // If window is decorated draw the decoration |
568 | + // otherwise draw a small bar over the window |
569 | + if (!highlighted) |
570 | + decorationHeight = SCALE_WINDOW_TITLE_SIZE * 0.30; |
571 | + |
572 | + DrawWindowDecoration(sAttrib, transform, mask, highlighted, |
573 | + x, y, |
574 | + x + width, y + decorationHeight); |
575 | + |
576 | + if (highlighted) |
577 | + { |
578 | + const float iconX = x + CLOSE_ICON_SPACE; |
579 | + const float iconY = y + ((decorationHeight - CLOSE_ICON_SIZE) / 2.0); |
580 | + maxHeight = maxWidth = 0; |
581 | + mask |= PAINT_WINDOW_BLEND_MASK; |
582 | + |
583 | + foreach(GLTexture *icon, close_icon_) |
584 | + { |
585 | + DrawTexture(icon, sAttrib, transform, mask, |
586 | + iconX, iconY, |
587 | + maxWidth , maxHeight); |
588 | + } |
589 | + |
590 | + close_button_area_ = CompRect(iconX, iconY, maxWidth, maxHeight); |
591 | + } |
592 | + else |
593 | + { |
594 | + close_button_area_ = CompRect(); |
595 | + } |
596 | } |
597 | |
598 | -void UnityWindow::scaleSelectWindow () |
599 | +void |
600 | +UnityWindow::scaleSelectWindow () |
601 | { |
602 | UnityScreen* us = UnityScreen::get(screen); |
603 | |
604 | if (us->highlighted_window_ != window->id ()) |
605 | { |
606 | - CompositeWindow *cWindow = CompositeWindow::get (window); |
607 | + CompositeWindow *cWindow = CompositeWindow::get(window); |
608 | if (cWindow) |
609 | - cWindow->addDamage (); |
610 | + cWindow->addDamage(); |
611 | |
612 | cWindow = 0; |
613 | - CompWindow *old_window = screen->findWindow (us->highlighted_window_); |
614 | + CompWindow *old_window = screen->findWindow(us->highlighted_window_); |
615 | if (old_window) |
616 | - cWindow = CompositeWindow::get (old_window); |
617 | + cWindow = CompositeWindow::get(old_window); |
618 | |
619 | if (cWindow) |
620 | - cWindow->addDamage (); |
621 | + cWindow->addDamage(); |
622 | |
623 | - us->highlighted_window_ = window->id (); |
624 | + us->highlighted_window_ = window->id(); |
625 | } |
626 | |
627 | - ScaleWindow *sWindow = ScaleWindow::get (window); |
628 | + ScaleWindow *sWindow = ScaleWindow::get(window); |
629 | if (sWindow) |
630 | - sWindow->scaleSelectWindow (); |
631 | + sWindow->scaleSelectWindow(); |
632 | +} |
633 | + |
634 | +void UnityWindow::InitiateSpreed() |
635 | +{ |
636 | + WindowManager *wm = WindowManager::Default(); |
637 | + const guint32 xid = window->id(); |
638 | + has_original_decoration_ = wm->IsWindowDecorated(xid) && |
639 | + !wm->IsWindowMaximized(xid); |
640 | + if (has_original_decoration_) |
641 | + wm->Undecorate(xid); |
642 | +} |
643 | + |
644 | +void UnityWindow::TerminateSpreed() |
645 | +{ |
646 | + if (has_original_decoration_) |
647 | + WindowManager::Default()->Decorate(window->id()); |
648 | } |
649 | |
650 | UnityWindow::~UnityWindow() |
651 | @@ -3821,9 +3919,6 @@ |
652 | window->minimize (); |
653 | } |
654 | |
655 | - if (window_header_style_) |
656 | - g_object_unref (window_header_style_); |
657 | - |
658 | ShowdesktopHandler::animating_windows.remove (static_cast <ShowdesktopHandlerWindowInterface *> (this)); |
659 | |
660 | if (mShowdesktopHandler) |
661 | @@ -3863,85 +3958,6 @@ |
662 | return true; |
663 | } |
664 | |
665 | -CompString UnityWindow::GetUtf8Property (Window id, |
666 | - Atom atom) |
667 | -{ |
668 | - Atom type; |
669 | - int result, format; |
670 | - unsigned long nItems, bytesAfter; |
671 | - char *val; |
672 | - CompString retval; |
673 | - Atom utf8StringAtom; |
674 | - |
675 | - utf8StringAtom = XInternAtom (screen->dpy (), "UTF8_STRING", 0); |
676 | - result = XGetWindowProperty (screen->dpy (), id, atom, 0L, 65536, False, |
677 | - utf8StringAtom, &type, &format, &nItems, |
678 | - &bytesAfter, (unsigned char **) &val); |
679 | - |
680 | - if (result != Success) |
681 | - return retval; |
682 | - |
683 | - if (type == utf8StringAtom && format == 8 && val && nItems > 0) |
684 | - { |
685 | - char valueString[nItems + 1]; |
686 | - strncpy (valueString, val, nItems); |
687 | - valueString[nItems] = 0; |
688 | - retval = valueString; |
689 | - } |
690 | - if (val) |
691 | - XFree (val); |
692 | - |
693 | - return retval; |
694 | -} |
695 | - |
696 | -CompString UnityWindow::GetTextProperty (Window id, |
697 | - Atom atom) |
698 | -{ |
699 | - XTextProperty text; |
700 | - CompString retval; |
701 | - |
702 | - text.nitems = 0; |
703 | - if (XGetTextProperty (screen->dpy (), id, &text, atom)) |
704 | - { |
705 | - if (text.value) |
706 | - { |
707 | - char valueString[text.nitems + 1]; |
708 | - |
709 | - strncpy (valueString, (char *) text.value, text.nitems); |
710 | - valueString[text.nitems] = 0; |
711 | - |
712 | - retval = valueString; |
713 | - |
714 | - XFree (text.value); |
715 | - } |
716 | - } |
717 | - |
718 | - return retval; |
719 | -} |
720 | - |
721 | - |
722 | -CompString UnityWindow::GetWindowName (Window id) |
723 | -{ |
724 | - CompString name; |
725 | - Atom visibleNameAtom; |
726 | - |
727 | - visibleNameAtom = XInternAtom (screen->dpy (), "_NET_WM_VISIBLE_NAME", 0); |
728 | - name = GetUtf8Property (id, visibleNameAtom); |
729 | - if (name.empty ()) |
730 | - { |
731 | - Atom wmNameAtom = XInternAtom (screen->dpy (), "_NET_WM_NAME", 0); |
732 | - name = GetUtf8Property (id, wmNameAtom); |
733 | - } |
734 | - |
735 | - |
736 | - if (name.empty ()) |
737 | - name = GetTextProperty (id, XA_WM_NAME); |
738 | - |
739 | - return name; |
740 | -} |
741 | - |
742 | - |
743 | - |
744 | namespace |
745 | { |
746 | |
747 | |
748 | === modified file 'plugins/unityshell/src/unityshell.h' |
749 | --- plugins/unityshell/src/unityshell.h 2012-08-31 13:21:02 +0000 |
750 | +++ plugins/unityshell/src/unityshell.h 2012-09-04 17:21:20 +0000 |
751 | @@ -249,7 +249,10 @@ |
752 | void OnPanelStyleChanged(); |
753 | |
754 | void InitGesturesSupport(); |
755 | - |
756 | + |
757 | + void OnInitiateSpreed(); |
758 | + void OnTerminateSpreed(); |
759 | + |
760 | nux::animation::TickSource tick_source_; |
761 | nux::animation::AnimationController animation_controller_; |
762 | |
763 | @@ -419,7 +422,7 @@ |
764 | |
765 | void handleEvent (XEvent *event); |
766 | |
767 | - CompRect closeButtonArea (); |
768 | + CompRect CloseButtonArea(); |
769 | |
770 | typedef compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow> |
771 | UnityMinimizedHandler; |
772 | @@ -430,11 +433,14 @@ |
773 | //! Emited when CompWindowNotifyBeforeDestroy is received |
774 | sigc::signal<void> being_destroyed; |
775 | |
776 | - void scaleSelectWindow (); |
777 | - void scalePaintDecoration (const GLWindowPaintAttrib &, |
778 | - const GLMatrix &, |
779 | - const CompRegion &, |
780 | - unsigned int); |
781 | + void scaleSelectWindow(); |
782 | + void scalePaintDecoration(const GLWindowPaintAttrib &, |
783 | + const GLMatrix &, |
784 | + const CompRegion &, |
785 | + unsigned int); |
786 | + |
787 | + void InitiateSpreed(); |
788 | + void TerminateSpreed(); |
789 | |
790 | private: |
791 | void DoEnableFocus (); |
792 | @@ -467,32 +473,30 @@ |
793 | |
794 | compiz::WindowInputRemoverLock::Ptr GetInputRemover (); |
795 | |
796 | - void DrawWindowTitle (const GLWindowPaintAttrib& attrib, |
797 | - const GLMatrix& transform, |
798 | - unsigned int mask, |
799 | - float x, float y, float x2, float y2); |
800 | - void DrawTexture (GLTexture *icon, |
801 | - const GLWindowPaintAttrib& attrib, |
802 | - const GLMatrix& transform, |
803 | - unsigned int mask, |
804 | - float x, float y, |
805 | - int &maxWidth, int &maxHeight); |
806 | - void RenderText (WindowCairoContext *context, |
807 | + void DrawWindowDecoration(const GLWindowPaintAttrib& attrib, |
808 | + const GLMatrix& transform, |
809 | + unsigned int mask, |
810 | + bool highlighted, |
811 | + float x, float y, float x2, float y2); |
812 | + void DrawTexture(GLTexture *icon, |
813 | + const GLWindowPaintAttrib& attrib, |
814 | + const GLMatrix& transform, |
815 | + unsigned int mask, |
816 | float x, float y, |
817 | - float maxWidth, float maxHeight); |
818 | - WindowCairoContext* CreateCairoContext (float width, float height); |
819 | - |
820 | - // based on compiz text plugin |
821 | - CompString GetWindowName (Window id); |
822 | - CompString GetUtf8Property (Window id, Atom atom); |
823 | - CompString GetTextProperty (Window id, Atom atom); |
824 | + int &maxWidth, int &maxHeight); |
825 | + void RenderText(WindowCairoContext *context, |
826 | + float x, float y, |
827 | + float maxWidth, float maxHeight); |
828 | + void PrepareHeaderStyle(); |
829 | + std::shared_ptr<WindowCairoContext> CreateCairoContext(float width, float height); |
830 | |
831 | compiz::WindowInputRemoverLock::Weak input_remover_; |
832 | glib::Source::UniquePtr focus_desktop_timeout_; |
833 | |
834 | GLTexture::List close_icon_; |
835 | CompRect close_button_area_; |
836 | - GtkStyleContext* window_header_style_; |
837 | + glib::Object<GtkStyleContext> window_header_style_; |
838 | + bool has_original_decoration_; |
839 | }; |
840 | |
841 | |
842 | |
843 | === modified file 'unity-shared/PluginAdapter.h' |
844 | --- unity-shared/PluginAdapter.h 2012-08-02 21:21:12 +0000 |
845 | +++ unity-shared/PluginAdapter.h 2012-09-04 17:21:20 +0000 |
846 | @@ -154,6 +154,7 @@ |
847 | nux::Geometry GetWindowSavedGeometry(guint32 xid) const; |
848 | nux::Geometry GetScreenGeometry() const; |
849 | nux::Geometry GetWorkAreaGeometry(guint32 xid = 0) const; |
850 | + std::string GetWindowName(guint32 xid) const; |
851 | |
852 | void CheckWindowIntersections(nux::Geometry const& region, bool &active, bool &any); |
853 | |
854 | @@ -177,6 +178,9 @@ |
855 | bool CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) const; |
856 | void SetMwmWindowHints(Window xid, MotifWmHints* new_hints); |
857 | |
858 | + std::string GetTextProperty(guint32 xid, Atom atom) const; |
859 | + std::string GetUtf8Property(guint32 xid, Atom atom) const; |
860 | + |
861 | CompScreen* m_Screen; |
862 | MultiActionList m_ExpoActionList; |
863 | MultiActionList m_ScaleActionList; |
864 | |
865 | === modified file 'unity-shared/PluginAdapterCompiz.cpp' |
866 | --- unity-shared/PluginAdapterCompiz.cpp 2012-08-17 05:58:15 +0000 |
867 | +++ unity-shared/PluginAdapterCompiz.cpp 2012-09-04 17:21:20 +0000 |
868 | @@ -1335,3 +1335,70 @@ |
869 | .add("viewport_switch_running", IsViewPortSwitchStarted()) |
870 | .add("showdesktop_active", _in_show_desktop); |
871 | } |
872 | + |
873 | +std::string |
874 | +PluginAdapter::GetWindowName(guint32 xid) const |
875 | +{ |
876 | + std::string name; |
877 | + Atom visibleNameAtom; |
878 | + |
879 | + visibleNameAtom = XInternAtom(m_Screen->dpy(), "_NET_WM_VISIBLE_NAME", 0); |
880 | + name = GetUtf8Property(xid, visibleNameAtom); |
881 | + if (name.empty()) |
882 | + { |
883 | + Atom wmNameAtom = XInternAtom(m_Screen->dpy(), "_NET_WM_NAME", 0); |
884 | + name = GetUtf8Property(xid, wmNameAtom); |
885 | + } |
886 | + |
887 | + if (name.empty()) |
888 | + name = GetTextProperty(xid, XA_WM_NAME); |
889 | + |
890 | + return name; |
891 | +} |
892 | + |
893 | +std::string |
894 | +PluginAdapter::GetUtf8Property(guint32 xid, Atom atom) const |
895 | +{ |
896 | + Atom type; |
897 | + int result, format; |
898 | + unsigned long nItems, bytesAfter; |
899 | + char *val; |
900 | + std::string retval; |
901 | + Atom utf8StringAtom; |
902 | + |
903 | + utf8StringAtom = XInternAtom(m_Screen->dpy(), "UTF8_STRING", 0); |
904 | + result = XGetWindowProperty(m_Screen->dpy(), xid, atom, 0L, 65536, False, |
905 | + utf8StringAtom, &type, &format, &nItems, |
906 | + &bytesAfter, reinterpret_cast<unsigned char **>(&val)); |
907 | + |
908 | + if (result != Success) |
909 | + return retval; |
910 | + |
911 | + if (type == utf8StringAtom && format == 8 && val && nItems > 0) |
912 | + { |
913 | + retval = std::string(val, nItems); |
914 | + } |
915 | + if (val) |
916 | + XFree(val); |
917 | + |
918 | + return retval; |
919 | +} |
920 | + |
921 | +std::string |
922 | +PluginAdapter::GetTextProperty(guint32 id, Atom atom) const |
923 | +{ |
924 | + XTextProperty text; |
925 | + std::string retval; |
926 | + |
927 | + text.nitems = 0; |
928 | + if (XGetTextProperty(m_Screen->dpy(), id, &text, atom)) |
929 | + { |
930 | + if (text.value) |
931 | + { |
932 | + retval = std::string(reinterpret_cast<char*>(text.value), text.nitems); |
933 | + XFree (text.value); |
934 | + } |
935 | + } |
936 | + |
937 | + return retval; |
938 | +} |
939 | |
940 | === modified file 'unity-shared/PluginAdapterStandalone.cpp' |
941 | --- unity-shared/PluginAdapterStandalone.cpp 2012-08-02 21:21:12 +0000 |
942 | +++ unity-shared/PluginAdapterStandalone.cpp 2012-09-04 17:21:20 +0000 |
943 | @@ -458,3 +458,9 @@ |
944 | .add("viewport_switch_running", IsViewPortSwitchStarted()) |
945 | .add("showdesktop_active", _in_show_desktop); |
946 | } |
947 | + |
948 | +std::string |
949 | +PluginAdapter::GetWindowName(guint32 xid) const |
950 | +{ |
951 | + return ""; |
952 | +} |
953 | |
954 | === modified file 'unity-shared/WindowManager.cpp' |
955 | --- unity-shared/WindowManager.cpp 2012-08-02 21:21:12 +0000 |
956 | +++ unity-shared/WindowManager.cpp 2012-09-04 17:21:20 +0000 |
957 | @@ -240,6 +240,11 @@ |
958 | void AddProperties(GVariantBuilder* builder) |
959 | { |
960 | } |
961 | + |
962 | + std::string GetWindowName(guint32 xid) const |
963 | + { |
964 | + return "unknown"; |
965 | + } |
966 | }; |
967 | |
968 | WindowManager* |
969 | |
970 | === modified file 'unity-shared/WindowManager.h' |
971 | --- unity-shared/WindowManager.h 2012-08-02 21:21:12 +0000 |
972 | +++ unity-shared/WindowManager.h 2012-09-04 17:21:20 +0000 |
973 | @@ -111,6 +111,8 @@ |
974 | virtual bool saveInputFocus() = 0; |
975 | virtual bool restoreInputFocus() = 0; |
976 | |
977 | + virtual std::string GetWindowName(guint32 xid) const = 0; |
978 | + |
979 | // Signals |
980 | sigc::signal<void, guint32> window_mapped; |
981 | sigc::signal<void, guint32> window_unmapped; |
Ok, nice... It's getting better!
Another thing that must be
23:29:10 <renato> this last point you notice about the string, I do not think this is a good solution since the string is created internally by "XGetWindowProp erty" and they recommend to free the memory with XFree
Yeah, but XFree is basically free, so I'd ust glib::String for that too.
Another thing that should be fixed is the titlebar font, You're actually using a sans font, but you should instead use the system font; you can see again QuicklistMenuIt em::DrawText how to get the proper font name and dpi values.
An extra nice plus would be to cut the long titles fading them out, there's some code that already does it in PanelMenuView: :DrawTitle, give that a test. ;)