66
66
dash::Settings::Instance().changed.connect(sigc::mem_fun(this, &WindowButton::UpdateDashUnmaximize));
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,
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,
76
76
/* FIXME HasMouseFocus() doesn't seem to work correctly, so we use this workaround */
107
107
GfxContext.PushClippingRectangle(geo);
109
if (_overlay_is_open)
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)
113
tex = _disabled_dash_tex;
117
tex = _normal_dash_tex;
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;
123
tex = _normal_dash_tex;
163
170
_prelight_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRELIGHT);
164
171
_pressed_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRESSED);
173
if (_overlay_is_open)
168
175
if (_normal_dash_tex)
169
176
SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight());
183
190
if (_type != panel::WindowButtonType::UNMAXIMIZE)
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;
193
195
if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP)
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);
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);
197
real_type = panel::WindowButtonType::MAXIMIZE;
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();
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);
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
217
if (_overlay_is_open)
213
219
if (_normal_dash_tex)
214
220
SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight());
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;
249
nux::BaseTexture* _disabled_dash_tex;
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;
248
static void OnPlaceViewShown(GVariant* data, void* val)
258
static void OnOverlayShown(GVariant* data, void* val)
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);
250
266
WindowButton* self = (WindowButton*)val;
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());
272
self->_overlay_can_maximize = (can_maximise) ? true : false;
256
274
self->QueueDraw();
259
static void OnPlaceViewHidden(GVariant* data, void* val)
277
static void OnOverlayHidden(GVariant* data, void* val)
261
279
WindowButton* self = (WindowButton*)val;
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());
270
288
nux::BaseTexture* GetDashWindowButton(panel::WindowButtonType type,
271
289
panel::WindowState state)
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" };
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));
282
301
glib::Error error;
283
glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename.Value(), &error));
285
// not handling broken texture or missing files
286
return nux::CreateTexture2DFromPixbuf(pixbuf, true);
289
nux::BaseTexture* GetDashMaximizeWindowButton(panel::WindowState state)
291
const char* states[] = { "", "_prelight", "_pressed" };
293
std::ostringstream subpath;
294
subpath << "maximize_dash" << states[static_cast<int>(state)] << ".png";
296
glib::String filename(g_build_filename(PKGDATADIR, subpath.str().c_str(), NULL));
299
glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename.Value(), &error));
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));
304
if (pixbuf && !error)
305
texture = nux::CreateTexture2DFromPixbuf(pixbuf, true);
308
texture = panel::Style::Instance().GetFallbackWindowButton(type, state);