39
39
int PlacesController::_launcher_size = 66;
41
PlacesController::PlacesController ()
43
_fullscren_request (false),
41
PlacesController::PlacesController()
43
_fullscren_request(false),
46
46
_need_show = false;
48
for (unsigned int i = 0; i < G_N_ELEMENTS (_ubus_handles); i++)
48
for (unsigned int i = 0; i < G_N_ELEMENTS(_ubus_handles); i++)
49
49
_ubus_handles[i] = 0;
51
51
_last_activate_time.tv_sec = 0;
52
52
_last_activate_time.tv_nsec = 0;
53
53
// register interest with ubus so that we get activation messages
54
UBusServer *ubus = ubus_server_get_default ();
55
_ubus_handles[0] = ubus_server_register_interest (ubus,
56
UBUS_DASH_EXTERNAL_ACTIVATION,
57
(UBusCallback) &PlacesController::ExternalActivation,
59
_ubus_handles[1] = ubus_server_register_interest (ubus,
60
UBUS_PLACE_VIEW_CLOSE_REQUEST,
61
(UBusCallback) &PlacesController::CloseRequest,
64
_factory = PlaceFactory::GetDefault ();
66
_window_layout = new nux::HLayout ();
68
_window = new nux::BaseWindow ("Dash");
69
_window->SetBackgroundColor (nux::Color (0.0, 0.0, 0.0, 0.0));
70
_window->SinkReference ();
54
UBusServer* ubus = ubus_server_get_default();
55
_ubus_handles[0] = ubus_server_register_interest(ubus,
56
UBUS_DASH_EXTERNAL_ACTIVATION,
57
(UBusCallback) &PlacesController::ExternalActivation,
59
_ubus_handles[1] = ubus_server_register_interest(ubus,
60
UBUS_PLACE_VIEW_CLOSE_REQUEST,
61
(UBusCallback) &PlacesController::CloseRequest,
64
_factory = PlaceFactory::GetDefault();
66
_window_layout = new nux::HLayout();
68
_window = new nux::BaseWindow("Dash");
69
_window->SetBackgroundColor(nux::Color(0.0, 0.0, 0.0, 0.0));
70
_window->SinkReference();
71
71
_window->SetConfigureNotifyCallback(&PlacesController::WindowConfigureCallback, this);
72
72
_window->ShowWindow(false);
73
_window->SetOpacity (0.0f);
75
_window->OnMouseDownOutsideArea.connect (sigc::mem_fun (this, &PlacesController::RecvMouseDownOutsideOfView));
77
_view = new PlacesView (_factory);
78
_window_layout->AddView (_view, 1);
73
_window->SetOpacity(0.0f);
75
_window->OnMouseDownOutsideArea.connect(sigc::mem_fun(this, &PlacesController::RecvMouseDownOutsideOfView));
77
_view = new PlacesView(_factory);
78
_window_layout->AddView(_view, 1);
79
79
_window_layout->SetContentDistribution(nux::eStackLeft);
80
80
_window_layout->SetVerticalExternalMargin(0);
81
81
_window_layout->SetHorizontalExternalMargin(0);
83
_window->SetLayout (_window_layout);
83
_window->SetLayout(_window_layout);
84
84
// Set a InputArea to get the keyboard focus when window receives the enter focus event.
85
_window->SetFocused (true);
87
_window->OnMouseDown.connect (sigc::mem_fun (_view->GetSearchBar (), &PlacesSearchBar::RecvMouseDownFromWindow));
89
_view->entry_changed.connect (sigc::mem_fun (this, &PlacesController::OnActivePlaceEntryChanged));
90
_view->fullscreen_request.connect (sigc::mem_fun (this, &PlacesController::OnDashFullscreenRequest));
92
PlacesSettings::GetDefault ()->changed.connect (sigc::mem_fun (this, &PlacesController::OnSettingsChanged));
93
_view->SetFocused (true);
95
PluginAdapter::Default ()->compiz_screen_ungrabbed.connect (sigc::mem_fun (this, &PlacesController::OnCompizScreenUngrabbed));
97
Relayout (gdk_screen_get_default (), this);
98
g_signal_connect (gdk_screen_get_default (), "monitors-changed",
99
G_CALLBACK (PlacesController::Relayout), this);
100
g_signal_connect (gdk_screen_get_default (), "size-changed",
101
G_CALLBACK (PlacesController::Relayout), this);
85
_window->SetFocused(true);
87
_window->OnMouseDown.connect(sigc::mem_fun(_view->GetSearchBar(), &PlacesSearchBar::RecvMouseDownFromWindow));
89
_view->entry_changed.connect(sigc::mem_fun(this, &PlacesController::OnActivePlaceEntryChanged));
90
_view->fullscreen_request.connect(sigc::mem_fun(this, &PlacesController::OnDashFullscreenRequest));
92
PlacesSettings::GetDefault()->changed.connect(sigc::mem_fun(this, &PlacesController::OnSettingsChanged));
93
_view->SetFocused(true);
95
PluginAdapter::Default()->compiz_screen_ungrabbed.connect(sigc::mem_fun(this, &PlacesController::OnCompizScreenUngrabbed));
97
Relayout(gdk_screen_get_default(), this);
98
g_signal_connect(gdk_screen_get_default(), "monitors-changed",
99
G_CALLBACK(PlacesController::Relayout), this);
100
g_signal_connect(gdk_screen_get_default(), "size-changed",
101
G_CALLBACK(PlacesController::Relayout), this);
104
PlacesController::~PlacesController ()
104
PlacesController::~PlacesController()
106
106
if (_timeline_id)
107
g_source_remove (_timeline_id);
109
_window->UnReference ();
111
UBusServer* ubus = ubus_server_get_default ();
112
for (unsigned int i = 0; i < G_N_ELEMENTS (_ubus_handles); i++)
107
g_source_remove(_timeline_id);
109
_window->UnReference();
111
UBusServer* ubus = ubus_server_get_default();
112
for (unsigned int i = 0; i < G_N_ELEMENTS(_ubus_handles); i++)
114
114
if (_ubus_handles[i] != 0)
115
ubus_server_unregister_interest (ubus, _ubus_handles[i]);
115
ubus_server_unregister_interest(ubus, _ubus_handles[i]);
120
PlacesController::Relayout (GdkScreen *screen, PlacesController *self)
120
PlacesController::Relayout(GdkScreen* screen, PlacesController* self)
122
122
int width = 0, height = 0;
124
gdk_screen_get_monitor_geometry (screen,
125
gdk_screen_get_primary_monitor (screen),
126
&self->_monitor_rect);
128
self->GetWindowSize (&width, &height);
129
self->_window->SetGeometry (nux::Geometry (self->_monitor_rect.x + _launcher_size,
130
self->_monitor_rect.y + PANEL_HEIGHT,
124
gdk_screen_get_monitor_geometry(screen,
125
gdk_screen_get_primary_monitor(screen),
126
&self->_monitor_rect);
128
self->GetWindowSize(&width, &height);
129
self->_window->SetGeometry(nux::Geometry(self->_monitor_rect.x + _launcher_size,
130
self->_monitor_rect.y + PANEL_HEIGHT,
135
void PlacesController::OnCompizScreenUngrabbed ()
135
void PlacesController::OnCompizScreenUngrabbed()
141
void PlacesController::Show ()
141
void PlacesController::Show()
146
if (PluginAdapter::Default ()->IsExpoActive () || PluginAdapter::Default ()->IsScaleActive ())
146
if (PluginAdapter::Default()->IsExpoActive() || PluginAdapter::Default()->IsScaleActive())
149
if (PluginAdapter::Default ()->IsScreenGrabbed ())
149
if (PluginAdapter::Default()->IsScreenGrabbed())
151
151
_need_show = true;
155
155
_need_show = false;
157
_view->AboutToShow ();
158
_window->ShowWindow (true, false);
157
_view->AboutToShow();
158
_window->ShowWindow(true, false);
159
159
// Raise this window on top of all other BaseWindows
160
_window->PushToFront ();
161
_window->GrabPointer ();
162
_window->GrabKeyboard ();
163
_window->QueueDraw ();
164
_window->CaptureMouseDownAnyWhereElse (true);
166
StartShowHideTimeline ();
160
_window->PushToFront();
161
_window->GrabPointer();
162
_window->GrabKeyboard();
163
_window->QueueDraw();
164
_window->CaptureMouseDownAnyWhereElse(true);
166
StartShowHideTimeline();
170
ubus_server_send_message (ubus_server_get_default (), UBUS_PLACE_VIEW_SHOWN, NULL);
170
ubus_server_send_message(ubus_server_get_default(), UBUS_PLACE_VIEW_SHOWN, NULL);
172
172
nux::GetWindowCompositor().SetKeyFocusArea(_view->GetTextEntryView());
174
void PlacesController::Hide ()
174
void PlacesController::Hide()
179
_window->CaptureMouseDownAnyWhereElse (false);
180
_window->ForceStopFocus (1, 1);
181
_window->UnGrabPointer ();
182
_window->UnGrabKeyboard ();
179
_window->CaptureMouseDownAnyWhereElse(false);
180
_window->ForceStopFocus(1, 1);
181
_window->UnGrabPointer();
182
_window->UnGrabKeyboard();
183
183
_visible = false;
184
184
_fullscren_request = false;
186
StartShowHideTimeline ();
188
ubus_server_send_message (ubus_server_get_default (), UBUS_PLACE_VIEW_HIDDEN, NULL);
186
StartShowHideTimeline();
188
ubus_server_send_message(ubus_server_get_default(), UBUS_PLACE_VIEW_HIDDEN, NULL);
191
void PlacesController::ToggleShowHide ()
191
void PlacesController::ToggleShowHide()
194
ubus_server_send_message (ubus_server_get_default (), UBUS_DASH_VISIBLE, NULL);
194
ubus_server_send_message(ubus_server_get_default(), UBUS_DASH_VISIBLE, NULL);
196
_visible ? Hide () : Show ();
196
_visible ? Hide() : Show();
200
PlacesController::StartShowHideTimeline ()
200
PlacesController::StartShowHideTimeline()
202
202
if (_timeline_id)
203
g_source_remove (_timeline_id);
203
g_source_remove(_timeline_id);
205
_timeline_id = g_timeout_add (15, (GSourceFunc)PlacesController::OnViewShowHideFrame, this);
206
_last_opacity = _window->GetOpacity ();
207
_start_time = g_get_monotonic_time ();
205
_timeline_id = g_timeout_add(15, (GSourceFunc)PlacesController::OnViewShowHideFrame, this);
206
_last_opacity = _window->GetOpacity();
207
_start_time = g_get_monotonic_time();
211
PlacesController::OnViewShowHideFrame (PlacesController *self)
211
PlacesController::OnViewShowHideFrame(PlacesController* self)
213
213
#define _LENGTH_ 90000
216
216
float last_opacity;
218
diff = g_get_monotonic_time () - self->_start_time;
220
progress = diff/(float)_LENGTH_;
218
diff = g_get_monotonic_time() - self->_start_time;
220
progress = diff / (float)_LENGTH_;
222
222
last_opacity = self->_last_opacity;
224
224
if (self->_visible)
226
self->_window->SetOpacity (last_opacity + ((1.0f - last_opacity) * progress));
226
self->_window->SetOpacity(last_opacity + ((1.0f - last_opacity) * progress));
230
self->_window->SetOpacity (last_opacity - (last_opacity * progress));
230
self->_window->SetOpacity(last_opacity - (last_opacity * progress));
233
233
if (diff > _LENGTH_)
235
235
self->_timeline_id = 0;
237
237
// Make sure the state is right
238
self->_window->SetOpacity (self->_visible ? 1.0f : 0.0f);
238
self->_window->SetOpacity(self->_visible ? 1.0f : 0.0f);
239
239
if (!self->_visible)
241
self->_window->ShowWindow (false, false);
241
self->_window->ShowWindow(false, false);
242
242
//reset the active entry
243
self->_view->SetActiveEntry (NULL, 0, "");
243
self->_view->SetActiveEntry(NULL, 0, "");
253
PlacesController::GetWindowSize (int *out_width, int *out_height)
253
PlacesController::GetWindowSize(int* out_width, int* out_height)
255
PlacesSettings *settings = PlacesSettings::GetDefault ();
256
PlacesStyle *style = PlacesStyle::GetDefault ();
258
gint primary_monitor, width=0, height=0;
255
PlacesSettings* settings = PlacesSettings::GetDefault();
256
PlacesStyle* style = PlacesStyle::GetDefault();
258
gint primary_monitor, width = 0, height = 0;
259
259
GdkRectangle rect;
262
screen = gdk_screen_get_default ();
263
primary_monitor = gdk_screen_get_primary_monitor (screen);
264
gdk_screen_get_monitor_geometry (screen, primary_monitor, &rect);
266
tile_width = style->GetTileWidth ();
268
if (settings->GetFormFactor () == PlacesSettings::DESKTOP && !_fullscren_request)
262
screen = gdk_screen_get_default();
263
primary_monitor = gdk_screen_get_primary_monitor(screen);
264
gdk_screen_get_monitor_geometry(screen, primary_monitor, &rect);
266
tile_width = style->GetTileWidth();
268
if (settings->GetFormFactor() == PlacesSettings::DESKTOP && !_fullscren_request)
270
270
gint half = rect.width / 2;
272
272
while ((width + tile_width) <= half)
273
273
width += tile_width;
275
width = MAX (width, tile_width * 7);
276
height = MIN (rect.height, (style->GetTileHeight () * 5.5) + 12);
275
width = MAX(width, tile_width * 7);
276
height = MIN(rect.height, (style->GetTileHeight() * 5.5) + 12);
278
_view->SetSizeMode (PlacesView::SIZE_MODE_HOVER);
279
style->SetDefaultNColumns (6);
278
_view->SetSizeMode(PlacesView::SIZE_MODE_HOVER);
279
style->SetDefaultNColumns(6);
283
283
width = rect.width - _launcher_size;
284
284
height = rect.height - PANEL_HEIGHT;
286
_view->SetSizeMode (PlacesView::SIZE_MODE_FULLSCREEN);
287
style->SetDefaultNColumns (width / tile_width);
286
_view->SetSizeMode(PlacesView::SIZE_MODE_FULLSCREEN);
287
style->SetDefaultNColumns(width / tile_width);
290
290
*out_width = width;
294
294
/* Configure callback for the window */
296
PlacesController::WindowConfigureCallback(int WindowWidth, int WindowHeight, nux::Geometry& geo, void *user_data)
296
PlacesController::WindowConfigureCallback(int WindowWidth, int WindowHeight, nux::Geometry& geo, void* user_data)
298
PlacesController *self = static_cast<PlacesController *> (user_data);
298
PlacesController* self = static_cast<PlacesController*>(user_data);
299
299
int width = 0, height = 0;
301
self->GetWindowSize (&width, &height);
302
geo = nux::Geometry (self->_monitor_rect.x + self->_launcher_size,
303
self->_monitor_rect.y + PANEL_HEIGHT,
301
self->GetWindowSize(&width, &height);
302
geo = nux::Geometry(self->_monitor_rect.x + self->_launcher_size,
303
self->_monitor_rect.y + PANEL_HEIGHT,
309
PlacesController::OnDashFullscreenRequest ()
309
PlacesController::OnDashFullscreenRequest()
311
311
int width = 0, height = 0;
312
312
_fullscren_request = true;
313
GetWindowSize (&width, &height);
314
_window->SetGeometry (nux::Geometry (_monitor_rect.x + _launcher_size,
315
_monitor_rect.y + PANEL_HEIGHT,
313
GetWindowSize(&width, &height);
314
_window->SetGeometry(nux::Geometry(_monitor_rect.x + _launcher_size,
315
_monitor_rect.y + PANEL_HEIGHT,
320
bool PlacesController::IsActivationValid ()
320
bool PlacesController::IsActivationValid()
322
322
struct timespec event_time, delta;
323
323
clock_gettime(CLOCK_MONOTONIC, &event_time);
324
delta = time_diff (_last_activate_time, event_time);
324
delta = time_diff(_last_activate_time, event_time);
326
326
_last_activate_time.tv_sec = event_time.tv_sec;
327
327
_last_activate_time.tv_nsec = event_time.tv_nsec;
337
PlacesController::ExternalActivation (GVariant *data, void *val)
339
PlacesController *self = (PlacesController*)val;
341
if (self->IsActivationValid ())
342
self->ToggleShowHide ();
347
PlacesController::CloseRequest (GVariant *data, void *val)
349
PlacesController *self = (PlacesController*)val;
351
if (self->IsActivationValid ())
356
PlacesController::RecvMouseDownOutsideOfView (int x, int y, unsigned long button_flags, unsigned long key_flags)
358
if (IsActivationValid ())
363
PlacesController::OnActivePlaceEntryChanged (PlaceEntry *entry)
365
if (IsActivationValid ())
366
entry ? Show () : Hide ();
370
PlacesController::SetLauncherSize (int launcher_size)
372
_launcher_size = launcher_size;
337
PlacesController::ExternalActivation(GVariant* data, void* val)
339
PlacesController* self = (PlacesController*)val;
341
if (self->IsActivationValid())
342
self->ToggleShowHide();
347
PlacesController::CloseRequest(GVariant* data, void* val)
349
PlacesController* self = (PlacesController*)val;
351
if (self->IsActivationValid())
356
PlacesController::RecvMouseDownOutsideOfView(int x, int y, unsigned long button_flags, unsigned long key_flags)
358
if (IsActivationValid())
363
PlacesController::OnActivePlaceEntryChanged(PlaceEntry* entry)
365
if (IsActivationValid())
366
entry ? Show() : Hide();
370
PlacesController::SetLauncherSize(int launcher_size)
372
_launcher_size = launcher_size;
376
376
/* Introspection */
378
PlacesController::GetName ()
378
PlacesController::GetName()
380
380
return "PlacesController";
384
PlacesController::AddProperties (GVariantBuilder *builder)
384
PlacesController::AddProperties(GVariantBuilder* builder)
389
PlacesController::OnSettingsChanged (PlacesSettings *settings)
389
PlacesController::OnSettingsChanged(PlacesSettings* settings)
391
391
// We don't need to do anything just yet over here, it's a placeholder for when we do
394
394
// TODO: put that in some "util" toolbox
395
struct timespec PlacesController::time_diff (struct timespec start, struct timespec end)
395
struct timespec PlacesController::time_diff(struct timespec start, struct timespec end)
397
397
struct timespec temp;
398
if ((end.tv_nsec - start.tv_nsec) < 0) {
399
temp.tv_sec = end.tv_sec - start.tv_sec-1;
398
if ((end.tv_nsec - start.tv_nsec) < 0)
400
temp.tv_sec = end.tv_sec - start.tv_sec - 1;
400
401
temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
402
405
temp.tv_sec = end.tv_sec - start.tv_sec;
403
406
temp.tv_nsec = end.tv_nsec - start.tv_nsec;