~smspillaz/unity/untiy.less-paint-insanity

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/WindowButtons.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
      _normal_dash_tex(NULL),
55
55
      _prelight_dash_tex(NULL),
56
56
      _pressed_dash_tex(NULL),
57
 
      _dash_is_open(false),
 
57
      _overlay_is_open(false),
58
58
      _mouse_is_down(false),
59
59
      _place_shown_interest(0),
60
60
      _place_hidden_interest(0),
66
66
    dash::Settings::Instance().changed.connect(sigc::mem_fun(this, &WindowButton::UpdateDashUnmaximize));
67
67
 
68
68
    UBusServer* ubus = ubus_server_get_default();
69
 
    _place_shown_interest = ubus_server_register_interest(ubus, UBUS_PLACE_VIEW_SHOWN,
70
 
                                                          (UBusCallback)&WindowButton::OnPlaceViewShown,
 
69
    _place_shown_interest = ubus_server_register_interest(ubus, UBUS_OVERLAY_SHOWN,
 
70
                                                          (UBusCallback)&WindowButton::OnOverlayShown,
71
71
                                                          this);
72
 
    _place_hidden_interest = ubus_server_register_interest(ubus, UBUS_PLACE_VIEW_HIDDEN,
73
 
                                                           (UBusCallback)&WindowButton::OnPlaceViewHidden,
 
72
    _place_hidden_interest = ubus_server_register_interest(ubus, UBUS_OVERLAY_HIDDEN,
 
73
                                                           (UBusCallback)&WindowButton::OnOverlayHidden,
74
74
                                                           this);
75
75
 
76
76
    /* FIXME HasMouseFocus() doesn't seem to work correctly, so we use this workaround */
106
106
 
107
107
    GfxContext.PushClippingRectangle(geo);
108
108
 
109
 
    if (_dash_is_open)
 
109
    if (_overlay_is_open)
110
110
    {
111
 
      //FIXME should use HasMouseFocus()
112
 
      if (_mouse_is_down && IsMouseInside())
113
 
        tex = _pressed_dash_tex;
114
 
      else if (IsMouseInside())
115
 
        tex = _prelight_dash_tex;
 
111
      if (_type == panel::WindowButtonType::UNMAXIMIZE && !_overlay_can_maximize)
 
112
      {
 
113
        tex = _disabled_dash_tex;
 
114
      }
116
115
      else
117
 
        tex = _normal_dash_tex;
 
116
      {
 
117
        //FIXME should use HasMouseFocus()
 
118
        if (_mouse_is_down && IsMouseInside())
 
119
          tex = _pressed_dash_tex;
 
120
        else if (IsMouseInside())
 
121
          tex = _prelight_dash_tex;
 
122
        else
 
123
          tex = _normal_dash_tex;
 
124
      }
118
125
    }
119
126
    else
120
127
    {
163
170
    _prelight_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRELIGHT);
164
171
    _pressed_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRESSED);
165
172
 
166
 
    if (_dash_is_open)
 
173
    if (_overlay_is_open)
167
174
    {
168
175
      if (_normal_dash_tex)
169
176
        SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight());
183
190
    if (_type != panel::WindowButtonType::UNMAXIMIZE)
184
191
      return;
185
192
 
186
 
    if (_normal_dash_tex)
187
 
      _normal_dash_tex->UnReference();
188
 
    if (_prelight_dash_tex)
189
 
      _prelight_dash_tex->UnReference();
190
 
    if (_pressed_dash_tex)
191
 
      _pressed_dash_tex->UnReference();
 
193
    panel::WindowButtonType real_type = panel::WindowButtonType::UNMAXIMIZE;
192
194
 
193
195
    if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP)
194
196
    {
195
 
      // get maximize buttons
196
 
      _normal_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::NORMAL);
197
 
      _prelight_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::PRELIGHT);
198
 
      _pressed_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::PRESSED);
199
 
    }
200
 
    else
201
 
    {
202
 
      // get unmaximize buttons
203
 
      _normal_dash_tex = GetDashWindowButton(_type, panel::WindowState::NORMAL);
204
 
      _prelight_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRELIGHT);
205
 
      _pressed_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRESSED);
206
 
    }
 
197
      real_type = panel::WindowButtonType::MAXIMIZE;
 
198
    }
 
199
 
 
200
    if (_normal_dash_tex)
 
201
      _normal_dash_tex->UnReference();
 
202
    if (_prelight_dash_tex)
 
203
      _prelight_dash_tex->UnReference();
 
204
    if (_pressed_dash_tex)
 
205
      _pressed_dash_tex->UnReference();
 
206
 
 
207
    //!!FIXME!! - don't have disabled instances of the (un)maximize buttons
 
208
    // get (un)maximize buttons
 
209
    _normal_dash_tex = GetDashWindowButton(real_type, panel::WindowState::NORMAL);
 
210
    _prelight_dash_tex = GetDashWindowButton(real_type, panel::WindowState::PRELIGHT);
 
211
    _pressed_dash_tex = GetDashWindowButton(real_type, panel::WindowState::PRESSED);
 
212
    _disabled_dash_tex = GetDashWindowButton(real_type, panel::WindowState::DISABLED);
207
213
 
208
214
    // still check if the dash is really opened,
209
215
    // someone could change the form factor through dconf
210
216
    // when the dash is closed
211
 
    if (_dash_is_open)
 
217
    if (_overlay_is_open)
212
218
    {
213
219
      if (_normal_dash_tex)
214
220
        SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight());
233
239
 
234
240
private:
235
241
  panel::WindowButtonType _type;
 
242
  // FIXME - replace with objectptr varients
236
243
  nux::BaseTexture* _normal_tex;
237
244
  nux::BaseTexture* _prelight_tex;
238
245
  nux::BaseTexture* _pressed_tex;
239
246
  nux::BaseTexture* _normal_dash_tex;
240
247
  nux::BaseTexture* _prelight_dash_tex;
241
248
  nux::BaseTexture* _pressed_dash_tex;
242
 
  bool _dash_is_open;
 
249
  nux::BaseTexture* _disabled_dash_tex;
 
250
 
 
251
  bool _overlay_is_open;
 
252
  bool _overlay_can_maximize;
243
253
  bool _mouse_is_down;
244
254
  guint32 _place_shown_interest;
245
255
  guint32 _place_hidden_interest;
246
256
  double _opacity;
247
257
 
248
 
  static void OnPlaceViewShown(GVariant* data, void* val)
 
258
  static void OnOverlayShown(GVariant* data, void* val)
249
259
  {
 
260
    unity::glib::String overlay_identity;
 
261
    gboolean can_maximise = FALSE;
 
262
    gint32 overlay_monitor = 0;
 
263
    g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, 
 
264
                  &overlay_identity, &can_maximise, &overlay_monitor);
 
265
 
250
266
    WindowButton* self = (WindowButton*)val;
251
267
 
252
 
    self->_dash_is_open = true;
 
268
    self->_overlay_is_open = true;
253
269
    if (self->_normal_dash_tex)
254
270
      self->SetMinMaxSize(self->_normal_dash_tex->GetWidth(), self->_normal_dash_tex->GetHeight());
255
271
 
 
272
    self->_overlay_can_maximize = (can_maximise) ? true : false;
 
273
 
256
274
    self->QueueDraw();
257
275
  }
258
276
 
259
 
  static void OnPlaceViewHidden(GVariant* data, void* val)
 
277
  static void OnOverlayHidden(GVariant* data, void* val)
260
278
  {
261
279
    WindowButton* self = (WindowButton*)val;
262
280
 
263
 
    self->_dash_is_open = false;
 
281
    self->_overlay_is_open = false;
264
282
    if (self->_normal_tex)
265
283
      self->SetMinMaxSize(self->_normal_tex->GetWidth(), self->_normal_tex->GetHeight());
266
284
 
270
288
  nux::BaseTexture* GetDashWindowButton(panel::WindowButtonType type,
271
289
                                        panel::WindowState state)
272
290
  {
273
 
    const char* names[] = { "close_dash", "minimize_dash", "unmaximize_dash" };
274
 
    const char* states[] = { "", "_prelight", "_pressed" };
 
291
    nux::BaseTexture* texture = nullptr;
 
292
    const char* names[] = { "close_dash", "minimize_dash", "unmaximize_dash", "maximize_dash" };
 
293
    const char* states[] = { "", "_prelight", "_pressed", "_disabled" };
275
294
 
276
295
    std::ostringstream subpath;
277
296
    subpath << names[static_cast<int>(type)]
280
299
    glib::String filename(g_build_filename(PKGDATADIR, subpath.str().c_str(), NULL));
281
300
 
282
301
    glib::Error error;
283
 
    glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename.Value(), &error));
284
 
 
285
 
    // not handling broken texture or missing files
286
 
    return nux::CreateTexture2DFromPixbuf(pixbuf, true);
287
 
  }
288
 
 
289
 
  nux::BaseTexture* GetDashMaximizeWindowButton(panel::WindowState state)
290
 
  {
291
 
    const char* states[] = { "", "_prelight", "_pressed" };
292
 
 
293
 
    std::ostringstream subpath;
294
 
    subpath << "maximize_dash" << states[static_cast<int>(state)] << ".png";
295
 
 
296
 
    glib::String filename(g_build_filename(PKGDATADIR, subpath.str().c_str(), NULL));
297
 
 
298
 
    glib::Error error;
299
 
    glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename.Value(), &error));
300
 
 
301
 
    // not handling broken texture or missing files
302
 
    return nux::CreateTexture2DFromPixbuf(pixbuf, true);
 
302
    glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename, &error));
 
303
 
 
304
    if (pixbuf && !error)
 
305
      texture = nux::CreateTexture2DFromPixbuf(pixbuf, true);
 
306
 
 
307
    if (!texture)
 
308
      texture = panel::Style::Instance().GetFallbackWindowButton(type, state);
 
309
 
 
310
    return texture;
303
311
  }
304
312
};
305
313