~om26er/ubuntu/oneiric/unity/sru-778256

« back to all changes in this revision

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

Update formatting to match style (as close as possible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
int PlacesController::_launcher_size = 66;
40
40
 
41
 
PlacesController::PlacesController ()
42
 
: _visible (false),
43
 
  _fullscren_request (false),
44
 
  _timeline_id (0)
 
41
PlacesController::PlacesController()
 
42
  : _visible(false),
 
43
    _fullscren_request(false),
 
44
    _timeline_id(0)
45
45
{
46
46
  _need_show = false;
47
47
 
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;
50
50
 
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,
58
 
                                                    this);
59
 
  _ubus_handles[1] = ubus_server_register_interest (ubus,
60
 
                                                    UBUS_PLACE_VIEW_CLOSE_REQUEST,
61
 
                                                    (UBusCallback) &PlacesController::CloseRequest,
62
 
                                                    this);
63
 
 
64
 
  _factory = PlaceFactory::GetDefault ();
65
 
 
66
 
  _window_layout = new nux::HLayout ();
67
 
 
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,
 
58
                                                   this);
 
59
  _ubus_handles[1] = ubus_server_register_interest(ubus,
 
60
                                                   UBUS_PLACE_VIEW_CLOSE_REQUEST,
 
61
                                                   (UBusCallback) &PlacesController::CloseRequest,
 
62
                                                   this);
 
63
 
 
64
  _factory = PlaceFactory::GetDefault();
 
65
 
 
66
  _window_layout = new nux::HLayout();
 
67
 
 
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);
74
 
 
75
 
  _window->OnMouseDownOutsideArea.connect (sigc::mem_fun (this, &PlacesController::RecvMouseDownOutsideOfView));
76
 
 
77
 
  _view = new PlacesView (_factory);
78
 
  _window_layout->AddView (_view, 1);
 
73
  _window->SetOpacity(0.0f);
 
74
 
 
75
  _window->OnMouseDownOutsideArea.connect(sigc::mem_fun(this, &PlacesController::RecvMouseDownOutsideOfView));
 
76
 
 
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);
82
82
 
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);
86
 
 
87
 
  _window->OnMouseDown.connect (sigc::mem_fun (_view->GetSearchBar (), &PlacesSearchBar::RecvMouseDownFromWindow));
88
 
 
89
 
  _view->entry_changed.connect (sigc::mem_fun (this, &PlacesController::OnActivePlaceEntryChanged));
90
 
  _view->fullscreen_request.connect (sigc::mem_fun (this, &PlacesController::OnDashFullscreenRequest));
91
 
 
92
 
  PlacesSettings::GetDefault ()->changed.connect (sigc::mem_fun (this, &PlacesController::OnSettingsChanged));
93
 
  _view->SetFocused (true);
94
 
 
95
 
  PluginAdapter::Default ()->compiz_screen_ungrabbed.connect (sigc::mem_fun (this, &PlacesController::OnCompizScreenUngrabbed));
96
 
 
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);
 
86
 
 
87
  _window->OnMouseDown.connect(sigc::mem_fun(_view->GetSearchBar(), &PlacesSearchBar::RecvMouseDownFromWindow));
 
88
 
 
89
  _view->entry_changed.connect(sigc::mem_fun(this, &PlacesController::OnActivePlaceEntryChanged));
 
90
  _view->fullscreen_request.connect(sigc::mem_fun(this, &PlacesController::OnDashFullscreenRequest));
 
91
 
 
92
  PlacesSettings::GetDefault()->changed.connect(sigc::mem_fun(this, &PlacesController::OnSettingsChanged));
 
93
  _view->SetFocused(true);
 
94
 
 
95
  PluginAdapter::Default()->compiz_screen_ungrabbed.connect(sigc::mem_fun(this, &PlacesController::OnCompizScreenUngrabbed));
 
96
 
 
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);
102
102
}
103
103
 
104
 
PlacesController::~PlacesController ()
 
104
PlacesController::~PlacesController()
105
105
{
106
106
  if (_timeline_id)
107
 
    g_source_remove (_timeline_id);
108
 
 
109
 
  _window->UnReference ();
110
 
 
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);
 
108
 
 
109
  _window->UnReference();
 
110
 
 
111
  UBusServer* ubus = ubus_server_get_default();
 
112
  for (unsigned int i = 0; i < G_N_ELEMENTS(_ubus_handles); i++)
113
113
  {
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]);
116
116
  }
117
117
}
118
118
 
119
119
void
120
 
PlacesController::Relayout (GdkScreen *screen, PlacesController *self)
 
120
PlacesController::Relayout(GdkScreen* screen, PlacesController* self)
121
121
{
122
122
  int width = 0, height = 0;
123
 
 
124
 
  gdk_screen_get_monitor_geometry (screen,
125
 
                                   gdk_screen_get_primary_monitor (screen),
126
 
                                   &self->_monitor_rect);
127
 
 
128
 
  self->GetWindowSize (&width, &height);
129
 
  self->_window->SetGeometry (nux::Geometry (self->_monitor_rect.x + _launcher_size, 
130
 
                                             self->_monitor_rect.y + PANEL_HEIGHT,
131
 
                                             width,
132
 
                                             height));
 
123
 
 
124
  gdk_screen_get_monitor_geometry(screen,
 
125
                                  gdk_screen_get_primary_monitor(screen),
 
126
                                  &self->_monitor_rect);
 
127
 
 
128
  self->GetWindowSize(&width, &height);
 
129
  self->_window->SetGeometry(nux::Geometry(self->_monitor_rect.x + _launcher_size,
 
130
                                           self->_monitor_rect.y + PANEL_HEIGHT,
 
131
                                           width,
 
132
                                           height));
133
133
}
134
134
 
135
 
void PlacesController::OnCompizScreenUngrabbed ()
 
135
void PlacesController::OnCompizScreenUngrabbed()
136
136
{
137
137
  if (_need_show)
138
 
    Show ();
 
138
    Show();
139
139
}
140
140
 
141
 
void PlacesController::Show ()
 
141
void PlacesController::Show()
142
142
{
143
143
  if (_visible)
144
144
    return;
145
 
    
146
 
  if (PluginAdapter::Default ()->IsExpoActive () || PluginAdapter::Default ()->IsScaleActive ())
 
145
 
 
146
  if (PluginAdapter::Default()->IsExpoActive() || PluginAdapter::Default()->IsScaleActive())
147
147
    return;
148
 
  
149
 
  if (PluginAdapter::Default ()->IsScreenGrabbed ())
 
148
 
 
149
  if (PluginAdapter::Default()->IsScreenGrabbed())
150
150
  {
151
151
    _need_show = true;
152
152
    return;
153
153
  }
154
 
  
 
154
 
155
155
  _need_show = false;
156
 
    
157
 
  _view->AboutToShow ();
158
 
  _window->ShowWindow (true, false);
 
156
 
 
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);
165
 
  
166
 
  StartShowHideTimeline ();
 
160
  _window->PushToFront();
 
161
  _window->GrabPointer();
 
162
  _window->GrabKeyboard();
 
163
  _window->QueueDraw();
 
164
  _window->CaptureMouseDownAnyWhereElse(true);
 
165
 
 
166
  StartShowHideTimeline();
167
167
 
168
168
  _visible = true;
169
169
 
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);
171
171
 
172
172
  nux::GetWindowCompositor().SetKeyFocusArea(_view->GetTextEntryView());
173
173
}
174
 
void PlacesController::Hide ()
 
174
void PlacesController::Hide()
175
175
{
176
176
  if (!_visible)
177
177
    return;
178
178
 
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;
185
185
 
186
 
  StartShowHideTimeline ();
187
 
  
188
 
  ubus_server_send_message (ubus_server_get_default (),  UBUS_PLACE_VIEW_HIDDEN, NULL);
 
186
  StartShowHideTimeline();
 
187
 
 
188
  ubus_server_send_message(ubus_server_get_default(),  UBUS_PLACE_VIEW_HIDDEN, NULL);
189
189
}
190
190
 
191
 
void PlacesController::ToggleShowHide ()
 
191
void PlacesController::ToggleShowHide()
192
192
{
193
193
  if (!_visible)
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);
195
195
 
196
 
  _visible ? Hide () : Show ();
 
196
  _visible ? Hide() : Show();
197
197
}
198
198
 
199
199
void
200
 
PlacesController::StartShowHideTimeline ()
 
200
PlacesController::StartShowHideTimeline()
201
201
{
202
202
  if (_timeline_id)
203
 
    g_source_remove (_timeline_id);
 
203
    g_source_remove(_timeline_id);
204
204
 
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();
208
208
}
209
209
 
210
210
gboolean
211
 
PlacesController::OnViewShowHideFrame (PlacesController *self)
 
211
PlacesController::OnViewShowHideFrame(PlacesController* self)
212
212
{
213
213
#define _LENGTH_ 90000
214
214
  gint64 diff;
215
215
  float  progress;
216
216
  float  last_opacity;
217
217
 
218
 
  diff = g_get_monotonic_time () - self->_start_time;
219
 
 
220
 
  progress = diff/(float)_LENGTH_;
221
 
  
 
218
  diff = g_get_monotonic_time() - self->_start_time;
 
219
 
 
220
  progress = diff / (float)_LENGTH_;
 
221
 
222
222
  last_opacity = self->_last_opacity;
223
223
 
224
224
  if (self->_visible)
225
225
  {
226
 
    self->_window->SetOpacity (last_opacity + ((1.0f - last_opacity) * progress));
 
226
    self->_window->SetOpacity(last_opacity + ((1.0f - last_opacity) * progress));
227
227
  }
228
228
  else
229
229
  {
230
 
    self->_window->SetOpacity (last_opacity - (last_opacity * progress));
 
230
    self->_window->SetOpacity(last_opacity - (last_opacity * progress));
231
231
  }
232
 
 
 
232
 
233
233
  if (diff > _LENGTH_)
234
234
  {
235
235
    self->_timeline_id = 0;
236
236
 
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)
240
240
    {
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, "");
244
244
    }
245
 
    
 
245
 
246
246
    return FALSE;
247
247
  }
248
248
  return TRUE;
250
250
 
251
251
 
252
252
void
253
 
PlacesController::GetWindowSize (int *out_width, int *out_height)
 
253
PlacesController::GetWindowSize(int* out_width, int* out_height)
254
254
{
255
 
  PlacesSettings *settings = PlacesSettings::GetDefault ();
256
 
  PlacesStyle    *style = PlacesStyle::GetDefault ();
257
 
  GdkScreen      *screen;
258
 
  gint            primary_monitor, width=0, height=0;
 
255
  PlacesSettings* settings = PlacesSettings::GetDefault();
 
256
  PlacesStyle*    style = PlacesStyle::GetDefault();
 
257
  GdkScreen*      screen;
 
258
  gint            primary_monitor, width = 0, height = 0;
259
259
  GdkRectangle    rect;
260
260
  gint            tile_width;
261
261
 
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);
265
 
 
266
 
  tile_width = style->GetTileWidth ();
267
 
 
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);
 
265
 
 
266
  tile_width = style->GetTileWidth();
 
267
 
 
268
  if (settings->GetFormFactor() == PlacesSettings::DESKTOP && !_fullscren_request)
269
269
  {
270
270
    gint half = rect.width / 2;
271
271
 
272
272
    while ((width + tile_width) <= half)
273
273
      width += tile_width;
274
274
 
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);
277
277
 
278
 
    _view->SetSizeMode (PlacesView::SIZE_MODE_HOVER);
279
 
    style->SetDefaultNColumns (6);
 
278
    _view->SetSizeMode(PlacesView::SIZE_MODE_HOVER);
 
279
    style->SetDefaultNColumns(6);
280
280
  }
281
281
  else
282
282
  {
283
283
    width = rect.width - _launcher_size;
284
284
    height = rect.height - PANEL_HEIGHT;
285
285
 
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);
288
288
  }
289
289
 
290
290
  *out_width = width;
293
293
 
294
294
/* Configure callback for the window */
295
295
void
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)
297
297
{
298
 
  PlacesController *self = static_cast<PlacesController *> (user_data);
 
298
  PlacesController* self = static_cast<PlacesController*>(user_data);
299
299
  int width = 0, height = 0;
300
300
 
301
 
  self->GetWindowSize (&width, &height);
302
 
  geo = nux::Geometry (self->_monitor_rect.x + self->_launcher_size, 
303
 
                       self->_monitor_rect.y + PANEL_HEIGHT,
304
 
                       width,
305
 
                       height);
 
301
  self->GetWindowSize(&width, &height);
 
302
  geo = nux::Geometry(self->_monitor_rect.x + self->_launcher_size,
 
303
                      self->_monitor_rect.y + PANEL_HEIGHT,
 
304
                      width,
 
305
                      height);
306
306
}
307
307
 
308
308
void
309
 
PlacesController::OnDashFullscreenRequest ()
 
309
PlacesController::OnDashFullscreenRequest()
310
310
{
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,
316
 
                                       width,
317
 
                                       height));
 
313
  GetWindowSize(&width, &height);
 
314
  _window->SetGeometry(nux::Geometry(_monitor_rect.x + _launcher_size,
 
315
                                     _monitor_rect.y + PANEL_HEIGHT,
 
316
                                     width,
 
317
                                     height));
318
318
}
319
319
 
320
 
bool PlacesController::IsActivationValid ()
 
320
bool PlacesController::IsActivationValid()
321
321
{
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);
325
325
 
326
326
  _last_activate_time.tv_sec = event_time.tv_sec;
327
327
  _last_activate_time.tv_nsec = event_time.tv_nsec;
334
334
}
335
335
 
336
336
void
337
 
PlacesController::ExternalActivation (GVariant *data, void *val)
338
 
{
339
 
  PlacesController *self = (PlacesController*)val;
340
 
 
341
 
  if (self->IsActivationValid ())
342
 
    self->ToggleShowHide ();
343
 
 
344
 
}
345
 
 
346
 
void
347
 
PlacesController::CloseRequest (GVariant *data, void *val)
348
 
{
349
 
  PlacesController *self = (PlacesController*)val;
350
 
  
351
 
  if (self->IsActivationValid ())
352
 
    self->Hide ();
353
 
}
354
 
 
355
 
void
356
 
PlacesController::RecvMouseDownOutsideOfView  (int x, int y, unsigned long button_flags, unsigned long key_flags)
357
 
{
358
 
  if (IsActivationValid ())
359
 
    Hide ();
360
 
}
361
 
 
362
 
void
363
 
PlacesController::OnActivePlaceEntryChanged (PlaceEntry *entry)
364
 
{
365
 
  if (IsActivationValid ())
366
 
    entry ? Show () : Hide ();
367
 
}
368
 
 
369
 
void
370
 
PlacesController::SetLauncherSize (int launcher_size)
371
 
{
372
 
    _launcher_size = launcher_size;
 
337
PlacesController::ExternalActivation(GVariant* data, void* val)
 
338
{
 
339
  PlacesController* self = (PlacesController*)val;
 
340
 
 
341
  if (self->IsActivationValid())
 
342
    self->ToggleShowHide();
 
343
 
 
344
}
 
345
 
 
346
void
 
347
PlacesController::CloseRequest(GVariant* data, void* val)
 
348
{
 
349
  PlacesController* self = (PlacesController*)val;
 
350
 
 
351
  if (self->IsActivationValid())
 
352
    self->Hide();
 
353
}
 
354
 
 
355
void
 
356
PlacesController::RecvMouseDownOutsideOfView(int x, int y, unsigned long button_flags, unsigned long key_flags)
 
357
{
 
358
  if (IsActivationValid())
 
359
    Hide();
 
360
}
 
361
 
 
362
void
 
363
PlacesController::OnActivePlaceEntryChanged(PlaceEntry* entry)
 
364
{
 
365
  if (IsActivationValid())
 
366
    entry ? Show() : Hide();
 
367
}
 
368
 
 
369
void
 
370
PlacesController::SetLauncherSize(int launcher_size)
 
371
{
 
372
  _launcher_size = launcher_size;
373
373
}
374
374
 
375
375
 
376
376
/* Introspection */
377
 
const gchar *
378
 
PlacesController::GetName ()
 
377
const gchar*
 
378
PlacesController::GetName()
379
379
{
380
380
  return "PlacesController";
381
381
}
382
382
 
383
383
void
384
 
PlacesController::AddProperties (GVariantBuilder *builder)
 
384
PlacesController::AddProperties(GVariantBuilder* builder)
385
385
{
386
386
}
387
387
 
388
388
void
389
 
PlacesController::OnSettingsChanged (PlacesSettings *settings)
 
389
PlacesController::OnSettingsChanged(PlacesSettings* settings)
390
390
{
391
391
  // We don't need to do anything just yet over here, it's a placeholder for when we do
392
392
}
393
393
 
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)
396
396
{
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)
 
399
  {
 
400
    temp.tv_sec = end.tv_sec - start.tv_sec - 1;
400
401
    temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
401
 
  } else {
 
402
  }
 
403
  else
 
404
  {
402
405
    temp.tv_sec = end.tv_sec - start.tv_sec;
403
406
    temp.tv_nsec = end.tv_nsec - start.tv_nsec;
404
407
  }