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

« back to all changes in this revision

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

  • Committer: Didier Roche
  • Date: 2011-07-21 16:17:59 UTC
  • mfrom: (55.813.3 upstream)
  • Revision ID: didier.roche@canonical.com-20110721161759-osmh94x428t2bf2b
* New upstream release.
* debian/control:
  - build-dep on libnotify-dev
  - bump libnux-1.0-dev dep for ABI break

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include <glib/gi18n-lib.h>
41
41
#include <gtk/gtk.h>
42
42
#include <gdk/gdk.h>
 
43
#include <libnotify/notify.h>
43
44
 
44
45
#include <core/atoms.h>
45
46
 
54
55
   the accessible root object, this include would not be required */
55
56
#include "unity-util-accessible.h"
56
57
 
 
58
using namespace unity::switcher;
 
59
 
57
60
/* Set up vtable symbols */
58
 
COMPIZ_PLUGIN_20090315 (unityshell, UnityPluginVTable);
 
61
COMPIZ_PLUGIN_20090315(unityshell, UnityPluginVTable);
59
62
 
60
63
using ::unity::logger::Timer;
61
64
 
62
 
namespace {
 
65
namespace
 
66
{
63
67
 
64
68
nux::logging::Logger logger("unity.shell");
65
69
 
66
70
UnityScreen* uScreen = 0;
67
71
 
68
72
void configure_logging();
69
 
void capture_g_log_calls(const gchar *log_domain,
 
73
void capture_g_log_calls(const gchar* log_domain,
70
74
                         GLogLevelFlags log_level,
71
 
                         const gchar *message,
 
75
                         const gchar* message,
72
76
                         gpointer user_data);
73
77
gboolean is_extension_supported(const gchar* extensions, const gchar* extension);
74
78
gfloat get_opengl_version_f32(const gchar* version_string);
75
79
 
76
80
}
77
81
 
78
 
UnityScreen::UnityScreen(CompScreen *screen)
79
 
 : PluginClassHandler <UnityScreen, CompScreen> (screen)
80
 
 , screen(screen)
81
 
 , cScreen(CompositeScreen::get(screen))
82
 
 , gScreen(GLScreen::get(screen))
83
 
 , relayoutSourceId(0)
84
 
 , _edge_trigger_handle(0)
85
 
 , doShellRepaint(false)
 
82
UnityScreen::UnityScreen(CompScreen* screen)
 
83
  : PluginClassHandler <UnityScreen, CompScreen> (screen)
 
84
  , screen(screen)
 
85
  , cScreen(CompositeScreen::get(screen))
 
86
  , gScreen(GLScreen::get(screen))
 
87
  , relayoutSourceId(0)
 
88
  , _edge_trigger_handle(0)
 
89
  , doShellRepaint(false)
 
90
  , switcher_desktop_icon(0)
86
91
{
87
92
  Timer timer;
88
93
  configure_logging();
89
94
  LOG_DEBUG(logger) << __PRETTY_FUNCTION__;
90
95
  _key_nav_mode_requested = false;
91
 
  int (*old_handler) (Display *, XErrorEvent *);
92
 
  old_handler = XSetErrorHandler (NULL);
93
 
 
94
 
  g_thread_init (NULL);
95
 
  dbus_g_thread_init ();
96
 
 
97
 
  unity_a11y_preset_environment ();
98
 
 
99
 
  XSetErrorHandler (old_handler);
 
96
  int (*old_handler)(Display*, XErrorEvent*);
 
97
  old_handler = XSetErrorHandler(NULL);
 
98
  damaged = false;
 
99
 
 
100
  notify_init("unityshell");
 
101
 
 
102
  g_thread_init(NULL);
 
103
  dbus_g_thread_init();
 
104
 
 
105
  unity_a11y_preset_environment();
 
106
 
 
107
  XSetErrorHandler(old_handler);
100
108
 
101
109
  /* Wrap compiz interfaces */
102
 
  ScreenInterface::setHandler (screen);
103
 
  CompositeScreenInterface::setHandler (cScreen);
104
 
  GLScreenInterface::setHandler (gScreen);
105
 
 
106
 
  PluginAdapter::Initialize (screen);
107
 
  WindowManager::SetDefault (PluginAdapter::Default ());
108
 
 
109
 
  StartupNotifyService::Default ()->SetSnDisplay (screen->snDisplay (), screen->screenNum ());
 
110
  ScreenInterface::setHandler(screen);
 
111
  CompositeScreenInterface::setHandler(cScreen);
 
112
  GLScreenInterface::setHandler(gScreen);
 
113
 
 
114
  PluginAdapter::Initialize(screen);
 
115
  WindowManager::SetDefault(PluginAdapter::Default());
 
116
 
 
117
  StartupNotifyService::Default()->SetSnDisplay(screen->snDisplay(), screen->screenNum());
110
118
 
111
119
  nux::NuxInitialize(0);
112
 
  wt = nux::CreateFromForeignWindow (cScreen->output (),
113
 
                                     glXGetCurrentContext (),
114
 
                                     &UnityScreen::initUnity,
115
 
                                     this);
116
 
 
117
 
  wt->RedrawRequested.connect (sigc::mem_fun (this, &UnityScreen::onRedrawRequested));
118
 
 
119
 
  unity_a11y_init (wt);
 
120
  wt = nux::CreateFromForeignWindow(cScreen->output(),
 
121
                                    glXGetCurrentContext(),
 
122
                                    &UnityScreen::initUnity,
 
123
                                    this);
 
124
 
 
125
  wt->RedrawRequested.connect(sigc::mem_fun(this, &UnityScreen::onRedrawRequested));
 
126
 
 
127
  unity_a11y_init(wt);
120
128
 
121
129
  newFocusedWindow  = NULL;
122
130
  lastFocusedWindow = NULL;
123
131
 
124
132
  /* i18n init */
125
 
  bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
126
 
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
133
  bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
 
134
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
127
135
 
128
 
  wt->Run (NULL);
 
136
  wt->Run(NULL);
129
137
  uScreen = this;
130
138
 
131
 
  debugger = new DebugDBusInterface (this);
 
139
  debugger = new DebugDBusInterface(this);
132
140
 
133
 
  optionSetLauncherHideModeNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
134
 
  optionSetBacklightModeNotify    (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
135
 
  optionSetLaunchAnimationNotify  (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
136
 
  optionSetUrgentAnimationNotify  (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
137
 
  optionSetPanelOpacityNotify     (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
138
 
  optionSetIconSizeNotify         (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
139
 
  optionSetAutohideAnimationNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
140
 
  optionSetDashBlurExperimentalNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
141
 
  optionSetShowLauncherInitiate   (boost::bind (&UnityScreen::showLauncherKeyInitiate, this, _1, _2, _3));
142
 
  optionSetShowLauncherTerminate  (boost::bind (&UnityScreen::showLauncherKeyTerminate, this, _1, _2, _3));
143
 
  optionSetKeyboardFocusInitiate  (boost::bind (&UnityScreen::setKeyboardFocusKeyInitiate, this, _1, _2, _3));
 
141
  optionSetLauncherHideModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
 
142
  optionSetBacklightModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
 
143
  optionSetLaunchAnimationNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
 
144
  optionSetUrgentAnimationNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
 
145
  optionSetPanelOpacityNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
 
146
  optionSetIconSizeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
 
147
  optionSetAutohideAnimationNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
 
148
  optionSetDashBlurExperimentalNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
 
149
  optionSetShowLauncherInitiate(boost::bind(&UnityScreen::showLauncherKeyInitiate, this, _1, _2, _3));
 
150
  optionSetShowLauncherTerminate(boost::bind(&UnityScreen::showLauncherKeyTerminate, this, _1, _2, _3));
 
151
  optionSetKeyboardFocusInitiate(boost::bind(&UnityScreen::setKeyboardFocusKeyInitiate, this, _1, _2, _3));
144
152
  //optionSetKeyboardFocusTerminate (boost::bind (&UnityScreen::setKeyboardFocusKeyTerminate, this, _1, _2, _3));
145
 
  optionSetExecuteCommandInitiate  (boost::bind (&UnityScreen::executeCommand, this, _1, _2, _3));
146
 
  optionSetPanelFirstMenuInitiate (boost::bind (&UnityScreen::showPanelFirstMenuKeyInitiate, this, _1, _2, _3));
147
 
  optionSetPanelFirstMenuTerminate(boost::bind (&UnityScreen::showPanelFirstMenuKeyTerminate, this, _1, _2, _3));
148
 
  optionSetLauncherRevealEdgeInitiate (boost::bind (&UnityScreen::launcherRevealEdgeInitiate, this, _1, _2, _3));
149
 
  optionSetAutomaximizeValueNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
 
153
  optionSetExecuteCommandInitiate(boost::bind(&UnityScreen::executeCommand, this, _1, _2, _3));
 
154
  optionSetAltTabForwardInitiate(boost::bind(&UnityScreen::altTabForwardInitiate, this, _1, _2, _3));
 
155
  optionSetAltTabForwardTerminate(boost::bind(&UnityScreen::altTabForwardTerminate, this, _1, _2, _3));
 
156
  optionSetAltTabPrevInitiate(boost::bind(&UnityScreen::altTabPrevInitiate, this, _1, _2, _3));
 
157
  optionSetAltTabPrevTerminate(boost::bind(&UnityScreen::altTabPrevTerminate, this, _1, _2, _3));
 
158
  optionSetPanelFirstMenuInitiate(boost::bind(&UnityScreen::showPanelFirstMenuKeyInitiate, this, _1, _2, _3));
 
159
  optionSetPanelFirstMenuTerminate(boost::bind(&UnityScreen::showPanelFirstMenuKeyTerminate, this, _1, _2, _3));
 
160
  optionSetLauncherRevealEdgeInitiate(boost::bind(&UnityScreen::launcherRevealEdgeInitiate, this, _1, _2, _3));
 
161
  optionSetAutomaximizeValueNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
150
162
 
151
 
  for (unsigned int i = 0; i < G_N_ELEMENTS (_ubus_handles); i++)
 
163
  for (unsigned int i = 0; i < G_N_ELEMENTS(_ubus_handles); i++)
152
164
    _ubus_handles[i] = 0;
153
165
 
154
 
  UBusServer* ubus = ubus_server_get_default ();
155
 
  _ubus_handles[0] = ubus_server_register_interest (ubus,
156
 
                                                    UBUS_LAUNCHER_START_KEY_NAV,
157
 
                                                    (UBusCallback)&UnityScreen::OnLauncherStartKeyNav,
158
 
                                                    this);
159
 
 
160
 
  _ubus_handles[1] = ubus_server_register_interest (ubus,
161
 
                                                    UBUS_LAUNCHER_END_KEY_NAV,
162
 
                                                    (UBusCallback)&UnityScreen::OnLauncherEndKeyNav,
163
 
                                                    this);
164
 
 
165
 
  _ubus_handles[2] = ubus_server_register_interest (ubus,
166
 
                                                    UBUS_QUICKLIST_END_KEY_NAV,
167
 
                                                    (UBusCallback)&UnityScreen::OnQuicklistEndKeyNav,
168
 
                                                    this);
169
 
 
170
 
  g_timeout_add (0, &UnityScreen::initPluginActions, this);
171
 
 
172
 
  GeisAdapter::Default (screen)->Run ();
173
 
  gestureEngine = new GestureEngine (screen);
174
 
 
175
 
  CompString name (PKGDATADIR"/panel-shadow.png");
176
 
  CompString pname ("unityshell");
177
 
  CompSize size (1, 20);
178
 
  _shadow_texture = GLTexture::readImageToTexture (name, pname, size);
 
166
  UBusServer* ubus = ubus_server_get_default();
 
167
  _ubus_handles[0] = ubus_server_register_interest(ubus,
 
168
                                                   UBUS_LAUNCHER_START_KEY_NAV,
 
169
                                                   (UBusCallback)&UnityScreen::OnLauncherStartKeyNav,
 
170
                                                   this);
 
171
 
 
172
  _ubus_handles[1] = ubus_server_register_interest(ubus,
 
173
                                                   UBUS_LAUNCHER_END_KEY_NAV,
 
174
                                                   (UBusCallback)&UnityScreen::OnLauncherEndKeyNav,
 
175
                                                   this);
 
176
 
 
177
  _ubus_handles[2] = ubus_server_register_interest(ubus,
 
178
                                                   UBUS_QUICKLIST_END_KEY_NAV,
 
179
                                                   (UBusCallback)&UnityScreen::OnQuicklistEndKeyNav,
 
180
                                                   this);
 
181
 
 
182
  g_timeout_add(0, &UnityScreen::initPluginActions, this);
 
183
 
 
184
  GeisAdapter::Default(screen)->Run();
 
185
  gestureEngine = new GestureEngine(screen);
 
186
 
 
187
  CompString name(PKGDATADIR"/panel-shadow.png");
 
188
  CompString pname("unityshell");
 
189
  CompSize size(1, 20);
 
190
  _shadow_texture = GLTexture::readImageToTexture(name, pname, size);
179
191
 
180
192
  LOG_INFO(logger) << "UnityScreen constructed: " << timer.ElapsedSeconds() << "s";
181
193
}
183
195
UnityScreen::~UnityScreen()
184
196
{
185
197
  delete placesController;
186
 
  panelController->UnReference ();
 
198
  panelController->UnReference();
187
199
  delete controller;
188
 
  launcher->UnReference ();
189
 
  launcherWindow->UnReference ();
190
 
 
191
 
  unity_a11y_finalize ();
192
 
 
193
 
  UBusServer* ubus = ubus_server_get_default ();
194
 
  for (unsigned int i = 0; i < G_N_ELEMENTS (_ubus_handles); i++)
 
200
  launcher->UnReference();
 
201
  launcherWindow->UnReference();
 
202
 
 
203
  notify_uninit();
 
204
 
 
205
  unity_a11y_finalize();
 
206
 
 
207
  UBusServer* ubus = ubus_server_get_default();
 
208
  for (unsigned int i = 0; i < G_N_ELEMENTS(_ubus_handles); i++)
195
209
  {
196
210
    if (_ubus_handles[i] != 0)
197
 
      ubus_server_unregister_interest (ubus, _ubus_handles[i]);
 
211
      ubus_server_unregister_interest(ubus, _ubus_handles[i]);
198
212
  }
199
213
 
200
214
  if (relayoutSourceId != 0)
201
 
    g_source_remove (relayoutSourceId);
 
215
    g_source_remove(relayoutSourceId);
202
216
 
203
217
  delete wt;
204
218
}
227
241
 
228
242
void UnityScreen::nuxEpilogue()
229
243
{
230
 
  (*GL::bindFramebuffer) (GL_FRAMEBUFFER_EXT, 0);
231
 
 
232
 
  glMatrixMode (GL_PROJECTION);
233
 
  glLoadIdentity ();
234
 
  glMatrixMode (GL_MODELVIEW);
235
 
  glLoadIdentity ();
236
 
  glDepthRange (0, 1);
237
 
  glViewport (-1, -1, 2, 2);
238
 
  glRasterPos2f (0, 0);
239
 
 
240
 
  gScreen->resetRasterPos ();
241
 
 
242
 
  glMatrixMode (GL_PROJECTION);
243
 
  glPopMatrix ();
244
 
  glMatrixMode (GL_MODELVIEW);
245
 
  glPopMatrix ();
246
 
 
247
 
  glDrawBuffer (GL_BACK);
248
 
  glReadBuffer (GL_BACK);
249
 
 
250
 
  glPopAttrib ();
 
244
  (*GL::bindFramebuffer)(GL_FRAMEBUFFER_EXT, 0);
 
245
 
 
246
  glMatrixMode(GL_PROJECTION);
 
247
  glLoadIdentity();
 
248
  glMatrixMode(GL_MODELVIEW);
 
249
  glLoadIdentity();
 
250
  glDepthRange(0, 1);
 
251
  glViewport(-1, -1, 2, 2);
 
252
  glRasterPos2f(0, 0);
 
253
 
 
254
  gScreen->resetRasterPos();
 
255
 
 
256
  glMatrixMode(GL_PROJECTION);
 
257
  glPopMatrix();
 
258
  glMatrixMode(GL_MODELVIEW);
 
259
  glPopMatrix();
 
260
 
 
261
  glDrawBuffer(GL_BACK);
 
262
  glReadBuffer(GL_BACK);
 
263
 
 
264
  glPopAttrib();
251
265
}
252
266
 
253
267
void UnityScreen::OnLauncherHiddenChanged()
254
268
{
255
 
  if (launcher->Hidden ())
256
 
    screen->addAction (&optionGetLauncherRevealEdge ());
 
269
  if (launcher->Hidden())
 
270
    screen->addAction(&optionGetLauncherRevealEdge());
257
271
  else
258
 
    screen->removeAction (&optionGetLauncherRevealEdge ());
 
272
    screen->removeAction(&optionGetLauncherRevealEdge());
259
273
}
260
274
 
261
 
void UnityScreen::paintPanelShadow(const GLMatrix &matrix)
 
275
void UnityScreen::paintPanelShadow(const GLMatrix& matrix)
262
276
{
263
277
  if (relayoutSourceId > 0)
264
278
    return;
265
279
 
266
 
  if (PluginAdapter::Default ()->IsExpoActive ())
 
280
  if (PluginAdapter::Default()->IsExpoActive())
267
281
    return;
268
282
 
269
 
  nuxPrologue ();
 
283
  nuxPrologue();
270
284
 
271
 
  CompOutput *output = _last_output;
 
285
  CompOutput* output = _last_output;
272
286
  float vc[4];
273
287
  float h = 20.0f;
274
288
  float w = 1.0f;
275
289
  float panel_h = 24.0f;
276
290
 
277
 
  float x1 = output->x ();
 
291
  float x1 = output->x();
278
292
  float y1 = panel_h;
279
 
  float x2 = x1 + output->width ();
 
293
  float x2 = x1 + output->width();
280
294
  float y2 = y1 + h;
281
295
 
282
296
  vc[0] = x1;
284
298
  vc[2] = y1;
285
299
  vc[3] = y2;
286
300
 
287
 
  foreach (GLTexture *tex, _shadow_texture)
 
301
  foreach(GLTexture * tex, _shadow_texture)
288
302
  {
289
 
    glEnable (GL_BLEND);
290
 
    glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
291
 
 
292
 
    GL::activeTexture (GL_TEXTURE0_ARB);
293
 
    tex->enable (GLTexture::Fast);
294
 
 
295
 
    glTexParameteri (tex->target (), GL_TEXTURE_WRAP_S, GL_REPEAT);
296
 
 
297
 
    glBegin (GL_QUADS);
 
303
    glEnable(GL_BLEND);
 
304
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 
305
 
 
306
    GL::activeTexture(GL_TEXTURE0_ARB);
 
307
    tex->enable(GLTexture::Fast);
 
308
 
 
309
    glTexParameteri(tex->target(), GL_TEXTURE_WRAP_S, GL_REPEAT);
 
310
 
 
311
    glBegin(GL_QUADS);
298
312
    {
299
 
      glTexCoord2f(COMP_TEX_COORD_X (tex->matrix (), 0), COMP_TEX_COORD_Y (tex->matrix (), 0));
 
313
      glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), 0), COMP_TEX_COORD_Y(tex->matrix(), 0));
300
314
      glVertex2f(vc[0], vc[2]);
301
315
 
302
 
      glTexCoord2f(COMP_TEX_COORD_X (tex->matrix (), 0), COMP_TEX_COORD_Y (tex->matrix (), h));
 
316
      glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), 0), COMP_TEX_COORD_Y(tex->matrix(), h));
303
317
      glVertex2f(vc[0], vc[3]);
304
318
 
305
 
      glTexCoord2f(COMP_TEX_COORD_X (tex->matrix (), w), COMP_TEX_COORD_Y (tex->matrix (), h));
 
319
      glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), w), COMP_TEX_COORD_Y(tex->matrix(), h));
306
320
      glVertex2f(vc[1], vc[3]);
307
321
 
308
 
      glTexCoord2f(COMP_TEX_COORD_X (tex->matrix (), w), COMP_TEX_COORD_Y (tex->matrix (), 0));
 
322
      glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), w), COMP_TEX_COORD_Y(tex->matrix(), 0));
309
323
      glVertex2f(vc[1], vc[2]);
310
324
    }
311
 
    glEnd ();
 
325
    glEnd();
312
326
 
313
 
    tex->disable ();
314
 
    glDisable (GL_BLEND);
 
327
    tex->disable();
 
328
    glDisable(GL_BLEND);
315
329
  }
316
 
  nuxEpilogue ();
 
330
  nuxEpilogue();
317
331
}
318
332
 
319
 
void UnityScreen::paintDisplay(const CompRegion &region)
 
333
void UnityScreen::paintDisplay(const CompRegion& region)
320
334
{
321
 
  nuxPrologue ();
322
 
  CompOutput *output = _last_output;
323
 
  nux::Geometry geo = nux::Geometry (output->x (), output->y (), output->width (), output->height ());
 
335
  nuxPrologue();
 
336
  CompOutput* output = _last_output;
 
337
  nux::Geometry geo = nux::Geometry(output->x(), output->y(), output->width(), output->height());
324
338
 
325
 
  wt->RenderInterfaceFromForeignCmd (&geo);
326
 
  nuxEpilogue ();
 
339
  wt->RenderInterfaceFromForeignCmd(&geo);
 
340
  nuxEpilogue();
327
341
 
328
342
  doShellRepaint = false;
 
343
  damaged = false;
329
344
}
330
345
 
331
346
/* called whenever we need to repaint parts of the screen */
342
357
  _last_output = output;
343
358
 
344
359
  /* glPaintOutput is part of the opengl plugin, so we need the GLScreen base class. */
345
 
  ret = gScreen->glPaintOutput (attrib, transform, region, output, mask);
 
360
  ret = gScreen->glPaintOutput(attrib, transform, region, output, mask);
346
361
 
347
362
  if (doShellRepaint)
348
 
    paintDisplay (region);
 
363
    paintDisplay(region);
349
364
 
350
365
  return ret;
351
366
}
360
375
                                           unsigned int mask)
361
376
{
362
377
  allowWindowPaint = false;
363
 
  gScreen->glPaintOutput (attrib, transform, region, output, mask);
 
378
  gScreen->glPaintOutput(attrib, transform, region, output, mask);
 
379
}
 
380
 
 
381
void UnityScreen::preparePaint(int ms)
 
382
{
 
383
  cScreen->preparePaint(ms);
 
384
 
 
385
  if (damaged)
 
386
  {
 
387
    damaged = false;
 
388
    damageNuxRegions();
 
389
  }
 
390
 
364
391
}
365
392
 
366
393
/* Grab changed nux regions and add damage rects for them */
367
394
void UnityScreen::damageNuxRegions()
368
395
{
 
396
  if (damaged)
 
397
    return;
 
398
 
369
399
  std::vector<nux::Geometry> dirty = wt->GetDrawList();
 
400
  damaged = true;
370
401
 
371
402
  for (std::vector<nux::Geometry>::iterator it = dirty.begin(), end = dirty.end();
372
403
       it != end; ++it)
373
404
  {
374
405
    nux::Geometry const& geo = *it;
375
 
    cScreen->damageRegion (CompRegion (geo.x, geo.y, geo.width, geo.height));
 
406
    cScreen->damageRegion(CompRegion(geo.x, geo.y, geo.width, geo.height));
376
407
  }
377
408
 
378
409
  nux::Geometry geo = wt->GetWindowCompositor().GetTooltipMainWindowGeometry();
382
413
 
383
414
  lastTooltipArea = geo;
384
415
 
385
 
  wt->ClearDrawList ();
 
416
  wt->ClearDrawList();
386
417
}
387
418
 
388
419
/* handle X Events */
389
 
void UnityScreen::handleEvent(XEvent *event)
 
420
void UnityScreen::handleEvent(XEvent* event)
390
421
{
391
422
  bool skip_other_plugins = false;
392
423
 
395
426
    case FocusIn:
396
427
    case FocusOut:
397
428
      if (event->xfocus.mode == NotifyGrab)
398
 
        PluginAdapter::Default ()->OnScreenGrabbed ();
 
429
        PluginAdapter::Default()->OnScreenGrabbed();
399
430
      else if (event->xfocus.mode == NotifyUngrab)
400
 
        PluginAdapter::Default ()->OnScreenUngrabbed ();
401
 
        cScreen->damageScreen (); // evil hack
402
 
        if (_key_nav_mode_requested)
403
 
          launcher->startKeyNavMode ();
404
 
        _key_nav_mode_requested = false;
 
431
        PluginAdapter::Default()->OnScreenUngrabbed();
 
432
      cScreen->damageScreen();  // evil hack
 
433
      if (_key_nav_mode_requested)
 
434
        launcher->startKeyNavMode();
 
435
      _key_nav_mode_requested = false;
405
436
      break;
406
437
    case KeyPress:
407
438
      KeySym key_sym;
408
439
      char key_string[2];
409
440
      int result;
410
 
      if ((result = XLookupString (&(event->xkey), key_string, 2, &key_sym, 0)) > 0) {
 
441
      if ((result = XLookupString(&(event->xkey), key_string, 2, &key_sym, 0)) > 0)
 
442
      {
411
443
        key_string[result] = 0;
412
 
        skip_other_plugins = launcher->CheckSuperShortcutPressed (key_sym, event->xkey.keycode, event->xkey.state, key_string);
 
444
        skip_other_plugins = launcher->CheckSuperShortcutPressed(key_sym, event->xkey.keycode, event->xkey.state, key_string);
413
445
      }
414
446
      break;
415
447
  }
416
448
 
417
449
  // avoid further propagation (key conflict for instance)
418
450
  if (!skip_other_plugins)
419
 
    screen->handleEvent (event);
 
451
    screen->handleEvent(event);
420
452
 
421
 
  if (!skip_other_plugins && screen->otherGrabExist ("deco", "move", "switcher", "resize", NULL))
 
453
  if (!skip_other_plugins && screen->otherGrabExist("deco", "move", "switcher", "resize", NULL))
422
454
  {
423
 
    wt->ProcessForeignEvent (event, NULL);
 
455
    wt->ProcessForeignEvent(event, NULL);
424
456
  }
425
457
}
426
458
 
433
465
   *  the ws switch as we can get false positives
434
466
   *  (like switching to an empty viewport while grabbing a fullscreen window)
435
467
   */
436
 
  if (strcmp (event, "start_viewport_switch") == 0)
437
 
    launcher->EnableCheckWindowOverLauncher (false);
438
 
  else if (strcmp (event, "end_viewport_switch") == 0)
 
468
  if (strcmp(event, "start_viewport_switch") == 0)
 
469
    launcher->EnableCheckWindowOverLauncher(false);
 
470
  else if (strcmp(event, "end_viewport_switch") == 0)
439
471
  {
440
472
    // compute again the list of all window on the new viewport
441
473
    // to decide if we should or not hide the launcher
442
 
    launcher->EnableCheckWindowOverLauncher (true);
443
 
    launcher->CheckWindowOverLauncher ();
 
474
    launcher->EnableCheckWindowOverLauncher(true);
 
475
    launcher->CheckWindowOverLauncher();
444
476
  }
445
 
  screen->handleCompizEvent (plugin, event, option);
 
477
  screen->handleCompizEvent(plugin, event, option);
446
478
}
447
479
 
448
480
bool UnityScreen::showLauncherKeyInitiate(CompAction* action,
451
483
{
452
484
  // to receive the Terminate event
453
485
  if (state & CompAction::StateInitKey)
454
 
    action->setState (action->state () | CompAction::StateTermKey);
 
486
    action->setState(action->state() | CompAction::StateTermKey);
455
487
 
456
 
  launcher->StartKeyShowLauncher ();
 
488
  launcher->StartKeyShowLauncher();
457
489
  return false;
458
490
}
459
491
 
461
493
                                           CompAction::State state,
462
494
                                           CompOption::Vector& options)
463
495
{
464
 
  launcher->EndKeyShowLauncher ();
 
496
  launcher->EndKeyShowLauncher();
465
497
  return false;
466
498
}
467
499
 
471
503
{
472
504
  // to receive the Terminate event
473
505
  if (state & CompAction::StateInitKey)
474
 
    action->setState (action->state () | CompAction::StateTermKey);
 
506
    action->setState(action->state() | CompAction::StateTermKey);
475
507
 
476
 
  panelController->StartFirstMenuShow ();
 
508
  panelController->StartFirstMenuShow();
477
509
  return false;
478
510
}
479
511
 
481
513
                                                 CompAction::State state,
482
514
                                                 CompOption::Vector& options)
483
515
{
484
 
  panelController->EndFirstMenuShow ();
 
516
  panelController->EndFirstMenuShow();
485
517
  return false;
486
518
}
487
519
 
489
521
{
490
522
  UnityScreen* self = reinterpret_cast<UnityScreen*>(data);
491
523
 
492
 
  Window root_r, child_r;
493
 
  int root_x_r, root_y_r, win_x_r, win_y_r;
494
 
  unsigned int mask;
495
 
  XQueryPointer(self->screen->dpy(), self->screen->root(),
496
 
                &root_r, &child_r, &root_x_r, &root_y_r,
497
 
                &win_x_r, &win_y_r, &mask);
498
 
 
499
 
  if (root_x_r == 0)
500
 
    self->launcher->EdgeRevealTriggered ();
 
524
  if (pointerX == 0)
 
525
    self->launcher->EdgeRevealTriggered();
501
526
 
502
527
  self->_edge_trigger_handle = 0;
503
528
  return false;
507
532
                                             CompAction::State state,
508
533
                                             CompOption::Vector& options)
509
534
{
510
 
  if (screen->grabbed ())
 
535
  if (screen->grabbed())
511
536
    return false;
512
537
 
513
538
  if (_edge_trigger_handle)
514
 
    g_source_remove (_edge_trigger_handle);
 
539
    g_source_remove(_edge_trigger_handle);
515
540
 
516
 
  _edge_trigger_handle = g_timeout_add (500, &UnityScreen::OnEdgeTriggerTimeout, this);
 
541
  _edge_trigger_handle = g_timeout_add(500, &UnityScreen::OnEdgeTriggerTimeout, this);
517
542
  return false;
518
543
}
519
544
 
520
545
void UnityScreen::SendExecuteCommand()
521
546
{
522
 
  ubus_server_send_message (ubus_server_get_default (),
523
 
                            UBUS_PLACE_ENTRY_ACTIVATE_REQUEST,
524
 
                            g_variant_new ("(sus)",
525
 
                                           "/com/canonical/unity/applicationsplace/runner",
526
 
                                           0,
527
 
                                           ""));
 
547
  ubus_server_send_message(ubus_server_get_default(),
 
548
                           UBUS_PLACE_ENTRY_ACTIVATE_REQUEST,
 
549
                           g_variant_new("(sus)",
 
550
                                         "/com/canonical/unity/applicationsplace/runner",
 
551
                                         0,
 
552
                                         ""));
528
553
}
529
554
 
530
555
bool UnityScreen::executeCommand(CompAction* action,
531
556
                                 CompAction::State state,
532
557
                                 CompOption::Vector& options)
533
558
{
534
 
  SendExecuteCommand ();
 
559
  SendExecuteCommand();
535
560
  return false;
536
561
}
537
562
 
540
565
  // set input-focus on launcher-window and start key-nav mode
541
566
  if (newFocusedWindow != NULL)
542
567
  {
543
 
    newFocusedWindow->moveInputFocusTo ();
544
 
    launcher->startKeyNavMode ();
 
568
    newFocusedWindow->moveInputFocusTo();
 
569
    launcher->startKeyNavMode();
545
570
  }
546
571
}
547
572
 
548
573
void UnityScreen::startLauncherKeyNav()
549
574
{
550
575
  // get CompWindow* of launcher-window
551
 
  newFocusedWindow = screen->findWindow (launcherWindow->GetInputWindowId ());
 
576
  newFocusedWindow = screen->findWindow(launcherWindow->GetInputWindowId());
552
577
 
553
578
  // check if currently focused window isn't the launcher-window
554
 
  if (newFocusedWindow != screen->findWindow (screen->activeWindow ()))
555
 
    lastFocusedWindow = screen->findWindow (screen->activeWindow ());
 
579
  if (newFocusedWindow != screen->findWindow(screen->activeWindow()))
 
580
    lastFocusedWindow = screen->findWindow(screen->activeWindow());
556
581
 
557
582
  // set input-focus on launcher-window and start key-nav mode
558
583
  if (newFocusedWindow != NULL)
561
586
    // input focus coming from the XinputWindow will be processed by the
562
587
    // launcher BaseWindow only. Then the Launcher BaseWindow will decide
563
588
    // which View will get the input focus.
564
 
    launcherWindow->PushToFront ();
565
 
    newFocusedWindow->moveInputFocusTo ();
 
589
    launcherWindow->PushToFront();
 
590
    newFocusedWindow->moveInputFocusTo();
566
591
  }
567
592
}
568
593
 
574
599
  return false;
575
600
}
576
601
 
 
602
bool UnityScreen::altTabForwardInitiate(CompAction* action,
 
603
                                        CompAction::State state,
 
604
                                        CompOption::Vector& options)
 
605
{
 
606
  if (switcherController->Visible())
 
607
  {
 
608
    switcherController->MoveNext();
 
609
  }
 
610
  else
 
611
  {
 
612
    std::vector<AbstractLauncherIcon*> results;
 
613
 
 
614
    if (!switcher_desktop_icon)
 
615
    {
 
616
      switcher_desktop_icon = new DesktopLauncherIcon(launcher);
 
617
      switcher_desktop_icon->SinkReference();
 
618
    }
 
619
 
 
620
    results.push_back(switcher_desktop_icon);
 
621
 
 
622
    LauncherModel::iterator it;
 
623
    for (it = launcher->GetModel()->begin(); it != launcher->GetModel()->end(); it++)
 
624
      if ((*it)->ShowInSwitcher())
 
625
        results.push_back(*it);
 
626
 
 
627
    // maybe check launcher position/hide state?
 
628
    switcherController->SetWorkspace(nux::Geometry(_primary_monitor.x + 100,
 
629
                                                   _primary_monitor.y + 100,
 
630
                                                   _primary_monitor.width - 200,
 
631
                                                   _primary_monitor.height - 200));
 
632
    switcherController->Show(SwitcherController::ALL, SwitcherController::FOCUS_ORDER, false, results);
 
633
  }
 
634
 
 
635
  action->setState(action->state() | CompAction::StateTermKey);
 
636
  return false;
 
637
}
 
638
 
 
639
bool UnityScreen::altTabForwardTerminate(CompAction* action,
 
640
                                         CompAction::State state,
 
641
                                         CompOption::Vector& options)
 
642
{
 
643
  action->setState(action->state() & (unsigned)~(CompAction::StateTermKey));
 
644
  switcherController->Hide();
 
645
  return false;
 
646
}
 
647
 
 
648
bool UnityScreen::altTabPrevInitiate(CompAction* action,
 
649
                                     CompAction::State state,
 
650
                                     CompOption::Vector& options)
 
651
{
 
652
  if (switcherController->Visible())
 
653
    switcherController->MovePrev();
 
654
 
 
655
  action->setState(action->state() | CompAction::StateTermKey);
 
656
  return false;
 
657
}
 
658
 
 
659
bool UnityScreen::altTabPrevTerminate(CompAction* action,
 
660
                                      CompAction::State state,
 
661
                                      CompOption::Vector& options)
 
662
{
 
663
  action->setState(action->state() & (unsigned)~(CompAction::StateTermKey));
 
664
  return false;
 
665
}
 
666
 
577
667
void UnityScreen::OnLauncherStartKeyNav(GVariant* data, void* value)
578
668
{
579
669
  UnityScreen* self = reinterpret_cast<UnityScreen*>(value);
580
 
  self->startLauncherKeyNav ();
 
670
  self->startLauncherKeyNav();
581
671
}
582
672
 
583
673
void UnityScreen::OnLauncherEndKeyNav(GVariant* data, void* value)
610
700
 
611
701
  if (p)
612
702
  {
613
 
    MultiActionList expoActions (0);
 
703
    MultiActionList expoActions(0);
614
704
 
615
 
    foreach (CompOption& option, p->vTable->getOptions())
 
705
    foreach(CompOption & option, p->vTable->getOptions())
616
706
    {
617
707
      if (option.name() == "expo_key" ||
618
708
          option.name() == "expo_button" ||
624
714
      }
625
715
    }
626
716
 
627
 
    PluginAdapter::Default ()->SetExpoAction(expoActions);
 
717
    PluginAdapter::Default()->SetExpoAction(expoActions);
628
718
  }
629
719
 
630
 
  p = CompPlugin::find ("scale");
 
720
  p = CompPlugin::find("scale");
631
721
 
632
722
  if (p)
633
723
  {
634
 
    MultiActionList scaleActions (0);
 
724
    MultiActionList scaleActions(0);
635
725
 
636
 
    foreach (CompOption& option, p->vTable->getOptions ())
 
726
    foreach(CompOption & option, p->vTable->getOptions())
637
727
    {
638
 
      if (option.name () == "initiate_all_key" ||
639
 
          option.name () == "initiate_all_edge" ||
640
 
          option.name () == "initiate_key" ||
641
 
          option.name () == "initiate_button" ||
642
 
          option.name () == "initiate_edge" ||
643
 
          option.name () == "initiate_group_key" ||
644
 
          option.name () == "initiate_group_button" ||
645
 
          option.name () == "initiate_group_edge" ||
646
 
          option.name () == "initiate_output_key" ||
647
 
          option.name () == "initiate_output_button" ||
648
 
          option.name () == "initiate_output_edge")
 
728
      if (option.name() == "initiate_all_key" ||
 
729
          option.name() == "initiate_all_edge" ||
 
730
          option.name() == "initiate_key" ||
 
731
          option.name() == "initiate_button" ||
 
732
          option.name() == "initiate_edge" ||
 
733
          option.name() == "initiate_group_key" ||
 
734
          option.name() == "initiate_group_button" ||
 
735
          option.name() == "initiate_group_edge" ||
 
736
          option.name() == "initiate_output_key" ||
 
737
          option.name() == "initiate_output_button" ||
 
738
          option.name() == "initiate_output_edge")
649
739
      {
650
 
        CompAction* action = &option.value ().action ();
651
 
        scaleActions.AddNewAction (action, false);
 
740
        CompAction* action = &option.value().action();
 
741
        scaleActions.AddNewAction(action, false);
652
742
      }
653
 
      else if (option.name () == "initiate_all_button")
 
743
      else if (option.name() == "initiate_all_button")
654
744
      {
655
 
        CompAction* action = &option.value ().action ();
656
 
        scaleActions.AddNewAction (action, true);
 
745
        CompAction* action = &option.value().action();
 
746
        scaleActions.AddNewAction(action, true);
657
747
      }
658
748
    }
659
749
 
660
 
    PluginAdapter::Default ()->SetScaleAction (scaleActions);
 
750
    PluginAdapter::Default()->SetScaleAction(scaleActions);
661
751
  }
662
752
 
663
 
  p = CompPlugin::find ("unitymtgrabhandles");
 
753
  p = CompPlugin::find("unitymtgrabhandles");
664
754
 
665
755
  if (p)
666
756
  {
667
 
    foreach (CompOption &option, p->vTable->getOptions ())
 
757
    foreach(CompOption & option, p->vTable->getOptions())
668
758
    {
669
 
      if (option.name () == "show_handles_key")
670
 
        PluginAdapter::Default ()->SetShowHandlesAction (&option.value ().action ());
671
 
      else if (option.name () == "hide_handles_key")
672
 
        PluginAdapter::Default ()->SetHideHandlesAction (&option.value ().action ());
673
 
      else if (option.name () == "toggle_handles_key")
674
 
        PluginAdapter::Default ()->SetToggleHandlesAction (&option.value ().action ());
 
759
      if (option.name() == "show_handles_key")
 
760
        PluginAdapter::Default()->SetShowHandlesAction(&option.value().action());
 
761
      else if (option.name() == "hide_handles_key")
 
762
        PluginAdapter::Default()->SetHideHandlesAction(&option.value().action());
 
763
      else if (option.name() == "toggle_handles_key")
 
764
        PluginAdapter::Default()->SetToggleHandlesAction(&option.value().action());
675
765
    }
676
766
  }
677
767
 
703
793
{
704
794
  CompWindowList& pl = _withRemovedNuxWindows = cScreen->getWindowPaintList();
705
795
  CompWindowList::iterator it = pl.end();
706
 
  const std::list<Window>& xwns = nux::XInputWindow::NativeHandleList();
707
 
 
708
 
  while (it != pl.begin())
 
796
  CompWindowList::iterator begin = pl.begin();
 
797
  std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();
 
798
 
 
799
  unsigned int size = xwns.size();
 
800
 
 
801
  while (it != begin)
709
802
  {
710
803
    --it;
711
804
 
712
 
    if (std::find(xwns.begin(), xwns.end(), (*it)->id()) != xwns.end())
 
805
    auto id = (*it)->id();
 
806
    for (unsigned int i = 0; i < size; ++i)
713
807
    {
714
 
      it = pl.erase(it);
 
808
      if (xwns[i] == id)
 
809
      {
 
810
        it = pl.erase(it);
 
811
        break;
 
812
      }
715
813
    }
716
814
  }
717
815
 
732
830
{
733
831
  if (uScreen->doShellRepaint && uScreen->allowWindowPaint)
734
832
  {
735
 
    const std::list<Window>& xwns = nux::XInputWindow::NativeHandleList();
 
833
    std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();
 
834
    unsigned int size = xwns.size();
736
835
 
737
836
    for (CompWindow* w = window; w && uScreen->doShellRepaint; w = w->prev)
738
837
    {
739
 
      if (std::find(xwns.begin(), xwns.end(), w->id()) != xwns.end())
 
838
      auto id = w->id();
 
839
      for (unsigned int i = 0; i < size; ++i)
740
840
      {
741
 
        uScreen->paintDisplay(region);
 
841
        if (xwns[i] == id)
 
842
        {
 
843
          uScreen->paintDisplay(region);
 
844
          break;
 
845
        }
742
846
      }
743
847
    }
744
848
  }
747
851
 
748
852
  if (window->type() == CompWindowTypeDesktopMask)
749
853
  {
750
 
    uScreen->paintPanelShadow (matrix);
 
854
    uScreen->paintPanelShadow(matrix);
751
855
  }
752
856
 
753
857
  return ret;
756
860
/* Called whenever a window is mapped, unmapped, minimized etc */
757
861
void UnityWindow::windowNotify(CompWindowNotify n)
758
862
{
759
 
  PluginAdapter::Default ()->Notify (window, n);
760
 
  window->windowNotify (n);
 
863
  PluginAdapter::Default()->Notify(window, n);
 
864
  window->windowNotify(n);
761
865
}
762
866
 
763
867
void UnityWindow::stateChangeNotify(unsigned int lastState)
764
868
{
765
 
  PluginAdapter::Default ()->NotifyStateChange (window, window->state (), lastState);
766
 
  window->stateChangeNotify (lastState);
 
869
  PluginAdapter::Default()->NotifyStateChange(window, window->state(), lastState);
 
870
  window->stateChangeNotify(lastState);
767
871
}
768
872
 
769
873
void UnityWindow::moveNotify(int x, int y, bool immediate)
770
874
{
771
 
  PluginAdapter::Default ()->NotifyMoved (window, x, y);
772
 
  window->moveNotify (x, y, immediate);
 
875
  PluginAdapter::Default()->NotifyMoved(window, x, y);
 
876
  window->moveNotify(x, y, immediate);
773
877
}
774
878
 
775
879
void UnityWindow::resizeNotify(int x, int y, int w, int h)
776
880
{
777
 
  PluginAdapter::Default ()->NotifyResized (window, x, y, w, h);
778
 
  window->resizeNotify (x, y, w, h);
 
881
  PluginAdapter::Default()->NotifyResized(window, x, y, w, h);
 
882
  window->resizeNotify(x, y, w, h);
779
883
}
780
884
 
781
885
CompPoint UnityWindow::tryNotIntersectLauncher(CompPoint& pos)
784
888
  nux::Geometry geo = us->launcher->GetAbsoluteGeometry();
785
889
  CompRect launcherGeo(geo.x, geo.y, geo.width, geo.height);
786
890
 
787
 
  if (launcherGeo.contains (pos))
 
891
  if (launcherGeo.contains(pos))
788
892
  {
789
893
    if (screen->workArea().contains(CompRect(launcherGeo.right() + 1, pos.y(), window->width(), window->height())))
790
894
      pos.setX(launcherGeo.right() + 1);
796
900
bool UnityWindow::place(CompPoint& pos)
797
901
{
798
902
  UnityScreen* us = UnityScreen::get(screen);
799
 
  Launcher::LauncherHideMode hideMode = us->launcher->GetHideMode ();
 
903
  Launcher::LauncherHideMode hideMode = us->launcher->GetHideMode();
800
904
 
801
 
  bool result = window->place (pos);
 
905
  bool result = window->place(pos);
802
906
 
803
907
  switch (hideMode)
804
908
  {
805
909
    case Launcher::LAUNCHER_HIDE_DODGE_WINDOWS:
806
910
    case Launcher::LAUNCHER_HIDE_DODGE_ACTIVE_WINDOW:
807
 
      pos = tryNotIntersectLauncher (pos);
 
911
      pos = tryNotIntersectLauncher(pos);
808
912
      break;
809
913
 
810
914
    default:
836
940
 
837
941
void UnityScreen::onRedrawRequested()
838
942
{
839
 
  damageNuxRegions ();
 
943
  damageNuxRegions();
840
944
}
841
945
 
842
946
/* Handle option changes and plug that into nux windows */
845
949
  switch (num)
846
950
  {
847
951
    case UnityshellOptions::LauncherHideMode:
848
 
      launcher->SetHideMode ((Launcher::LauncherHideMode) optionGetLauncherHideMode ());
 
952
      launcher->SetHideMode((Launcher::LauncherHideMode) optionGetLauncherHideMode());
849
953
      break;
850
954
    case UnityshellOptions::BacklightMode:
851
 
      launcher->SetBacklightMode ((Launcher::BacklightMode) optionGetBacklightMode ());
 
955
      launcher->SetBacklightMode((Launcher::BacklightMode) optionGetBacklightMode());
852
956
      break;
853
957
    case UnityshellOptions::LaunchAnimation:
854
 
      launcher->SetLaunchAnimation ((Launcher::LaunchAnimation) optionGetLaunchAnimation ());
 
958
      launcher->SetLaunchAnimation((Launcher::LaunchAnimation) optionGetLaunchAnimation());
855
959
      break;
856
960
    case UnityshellOptions::UrgentAnimation:
857
 
      launcher->SetUrgentAnimation ((Launcher::UrgentAnimation) optionGetUrgentAnimation ());
 
961
      launcher->SetUrgentAnimation((Launcher::UrgentAnimation) optionGetUrgentAnimation());
858
962
      break;
859
963
    case UnityshellOptions::PanelOpacity:
860
 
      panelController->SetOpacity (optionGetPanelOpacity ());
 
964
      panelController->SetOpacity(optionGetPanelOpacity());
861
965
      break;
862
966
    case UnityshellOptions::IconSize:
863
 
      panelController->SetBFBSize (optionGetIconSize()+18);
864
 
      launcher->SetIconSize (optionGetIconSize()+6, optionGetIconSize());
865
 
      PlacesController::SetLauncherSize (optionGetIconSize()+18);
 
967
      panelController->SetBFBSize(optionGetIconSize() + 18);
 
968
      launcher->SetIconSize(optionGetIconSize() + 6, optionGetIconSize());
 
969
      PlacesController::SetLauncherSize(optionGetIconSize() + 18);
866
970
 
867
971
      break;
868
972
    case UnityshellOptions::AutohideAnimation:
869
 
      launcher->SetAutoHideAnimation ((Launcher::AutoHideAnimation) optionGetAutohideAnimation ());
 
973
      launcher->SetAutoHideAnimation((Launcher::AutoHideAnimation) optionGetAutohideAnimation());
870
974
      break;
871
975
 
872
976
    case UnityshellOptions::DashBlurExperimental:
873
 
      PlacesSettings::GetDefault ()->SetDashBlurType ((PlacesSettings::DashBlurType)optionGetDashBlurExperimental ());
 
977
      PlacesSettings::GetDefault()->SetDashBlurType((PlacesSettings::DashBlurType)optionGetDashBlurExperimental());
874
978
      break;
875
979
    case UnityshellOptions::AutomaximizeValue:
876
 
      PluginAdapter::Default ()->SetCoverageAreaBeforeAutomaximize (optionGetAutomaximizeValue () / 100.0f);
 
980
      PluginAdapter::Default()->SetCoverageAreaBeforeAutomaximize(optionGetAutomaximizeValue() / 100.0f);
877
981
      break;
878
982
    default:
879
983
      break;
888
992
void UnityScreen::ScheduleRelayout(guint timeout)
889
993
{
890
994
  if (relayoutSourceId == 0)
891
 
    relayoutSourceId = g_timeout_add (timeout, &UnityScreen::RelayoutTimeout, this);
 
995
    relayoutSourceId = g_timeout_add(timeout, &UnityScreen::RelayoutTimeout, this);
892
996
}
893
997
 
894
998
void UnityScreen::Relayout()
895
999
{
896
 
  GdkScreen *scr;
 
1000
  GdkScreen* scr;
897
1001
  GdkRectangle rect;
898
1002
  nux::Geometry lCurGeom;
899
1003
  gint primary_monitor;
902
1006
  if (!needsRelayout)
903
1007
    return;
904
1008
 
905
 
  scr = gdk_screen_get_default ();
906
 
  primary_monitor = gdk_screen_get_primary_monitor (scr);
907
 
  gdk_screen_get_monitor_geometry (scr, primary_monitor, &rect);
 
1009
  scr = gdk_screen_get_default();
 
1010
  primary_monitor = gdk_screen_get_primary_monitor(scr);
 
1011
  gdk_screen_get_monitor_geometry(scr, primary_monitor, &rect);
908
1012
  _primary_monitor = rect;
909
1013
 
910
 
  wt->SetWindowSize (rect.width, rect.height);
 
1014
  wt->SetWindowSize(rect.width, rect.height);
911
1015
 
912
1016
  lCurGeom = launcherWindow->GetGeometry();
913
1017
  launcher->SetMaximumHeight(rect.height - panel_height);
914
1018
 
915
 
  g_debug ("Setting to primary screen rect: x=%d y=%d w=%d h=%d",
916
 
           rect.x,
917
 
           rect.y,
918
 
           rect.width,
919
 
           rect.height);
 
1019
  g_debug("Setting to primary screen rect: x=%d y=%d w=%d h=%d",
 
1020
          rect.x,
 
1021
          rect.y,
 
1022
          rect.width,
 
1023
          rect.height);
920
1024
 
921
1025
  launcherWindow->SetGeometry(nux::Geometry(rect.x,
922
 
                                        rect.y + panel_height,
923
 
                                        lCurGeom.width,
924
 
                                        rect.height - panel_height));
 
1026
                                            rect.y + panel_height,
 
1027
                                            lCurGeom.width,
 
1028
                                            rect.height - panel_height));
925
1029
  launcher->SetGeometry(nux::Geometry(rect.x,
926
 
                                        rect.y + panel_height,
927
 
                                        lCurGeom.width,
928
 
                                        rect.height - panel_height));
 
1030
                                      rect.y + panel_height,
 
1031
                                      lCurGeom.width,
 
1032
                                      rect.height - panel_height));
929
1033
  needsRelayout = false;
930
1034
}
931
1035
 
932
1036
gboolean UnityScreen::RelayoutTimeout(gpointer data)
933
1037
{
934
 
  UnityScreen *uScr = reinterpret_cast<UnityScreen*>(data);
 
1038
  UnityScreen* uScr = reinterpret_cast<UnityScreen*>(data);
935
1039
 
936
 
  uScr->NeedsRelayout ();
 
1040
  uScr->NeedsRelayout();
937
1041
  uScr->Relayout();
938
1042
  uScr->relayoutSourceId = 0;
939
1043
 
940
 
  uScr->cScreen->damageScreen ();
 
1044
  uScr->cScreen->damageScreen();
941
1045
 
942
1046
  return FALSE;
943
1047
}
950
1054
  bool status = screen->setOptionForPlugin(plugin, name, v);
951
1055
  if (status)
952
1056
  {
953
 
    if (strcmp (plugin, "core") == 0 && strcmp (name, "hsize") == 0)
 
1057
    if (strcmp(plugin, "core") == 0 && strcmp(name, "hsize") == 0)
954
1058
    {
955
 
      controller->UpdateNumWorkspaces(screen->vpSize ().width () * screen->vpSize ().height ());
 
1059
      controller->UpdateNumWorkspaces(screen->vpSize().width() * screen->vpSize().height());
956
1060
    }
957
1061
  }
958
1062
  return status;
960
1064
 
961
1065
void UnityScreen::outputChangeNotify()
962
1066
{
963
 
  ScheduleRelayout (500);
 
1067
  ScheduleRelayout(500);
964
1068
}
965
1069
 
966
1070
/* Start up the launcher */
967
1071
void UnityScreen::initLauncher(nux::NThread* thread, void* InitData)
968
1072
{
969
1073
  Timer timer;
970
 
  UnityScreen *self = reinterpret_cast<UnityScreen*>(InitData);
 
1074
  UnityScreen* self = reinterpret_cast<UnityScreen*>(InitData);
971
1075
 
972
1076
  self->launcherWindow = new nux::BaseWindow(TEXT("LauncherWindow"));
973
 
  self->launcherWindow->SinkReference ();
 
1077
  self->launcherWindow->SinkReference();
974
1078
 
975
1079
  self->launcher = new Launcher(self->launcherWindow, self->screen);
976
 
  self->launcher->SinkReference ();
977
 
  self->launcher->hidden_changed.connect (sigc::mem_fun (self, &UnityScreen::OnLauncherHiddenChanged));
 
1080
  self->launcher->SinkReference();
 
1081
  self->launcher->hidden_changed.connect(sigc::mem_fun(self, &UnityScreen::OnLauncherHiddenChanged));
978
1082
 
979
 
  self->AddChild (self->launcher);
 
1083
  self->AddChild(self->launcher);
980
1084
 
981
1085
  nux::HLayout* layout = new nux::HLayout();
982
1086
  layout->AddView(self->launcher, 1);
984
1088
  layout->SetVerticalExternalMargin(0);
985
1089
  layout->SetHorizontalExternalMargin(0);
986
1090
 
987
 
  self->controller = new LauncherController (self->launcher, self->screen);
 
1091
  self->controller = new LauncherController(self->launcher, self->screen);
988
1092
 
989
1093
  self->launcherWindow->SetConfigureNotifyCallback(&UnityScreen::launcherWindowConfigureCallback, self);
990
1094
  self->launcherWindow->SetLayout(layout);
992
1096
  self->launcherWindow->ShowWindow(true);
993
1097
  self->launcherWindow->EnableInputWindow(true, "launcher", false, false);
994
1098
  self->launcherWindow->InputWindowEnableStruts(true);
995
 
  self->launcherWindow->SetEnterFocusInputArea (self->launcher);
 
1099
  self->launcherWindow->SetEnterFocusInputArea(self->launcher);
996
1100
 
 
1101
  self->switcherController = new SwitcherController();
997
1102
  /* FIXME: this should not be manual, should be managed with a
998
1103
     show/hide callback like in GAIL*/
999
 
  if (unity_a11y_initialized () == TRUE)
1000
 
    unity_util_accessible_add_window (self->launcherWindow);
 
1104
  if (unity_a11y_initialized() == TRUE)
 
1105
    unity_util_accessible_add_window(self->launcherWindow);
1001
1106
 
1002
 
  self->launcher->SetIconSize (54, 48);
1003
 
  self->launcher->SetBacklightMode (Launcher::BACKLIGHT_ALWAYS_ON);
 
1107
  self->launcher->SetIconSize(54, 48);
 
1108
  self->launcher->SetBacklightMode(Launcher::BACKLIGHT_ALWAYS_ON);
1004
1109
 
1005
1110
  LOG_INFO(logger) << "initLauncher-Launcher " << timer.ElapsedSeconds() << "s";
1006
1111
 
1007
1112
  /* Setup panel */
1008
1113
  timer.Reset();
1009
 
  self->panelController = new PanelController ();
1010
 
  self->AddChild (self->panelController);
 
1114
  self->panelController = new PanelController();
 
1115
  self->AddChild(self->panelController);
1011
1116
  LOG_INFO(logger) << "initLauncher-Panel " << timer.ElapsedSeconds() << "s";
1012
1117
 
1013
1118
  /* Setup Places */
1014
 
  self->placesController = new PlacesController ();
 
1119
  self->placesController = new PlacesController();
1015
1120
 
1016
1121
  /* FIXME: this should not be manual, should be managed with a
1017
1122
     show/hide callback like in GAIL*/
1018
 
  if (unity_a11y_initialized () == TRUE)
1019
 
    {
1020
 
      AtkObject *atk_obj = NULL;
1021
 
 
1022
 
      atk_obj = unity_util_accessible_add_window (self->placesController->GetWindow ());
1023
 
 
1024
 
      atk_object_set_name (atk_obj, _("Places"));
1025
 
    }
1026
 
 
1027
 
  self->launcher->SetHideMode (Launcher::LAUNCHER_HIDE_DODGE_WINDOWS);
1028
 
  self->launcher->SetLaunchAnimation (Launcher::LAUNCH_ANIMATION_PULSE);
1029
 
  self->launcher->SetUrgentAnimation (Launcher::URGENT_ANIMATION_WIGGLE);
1030
 
  self->ScheduleRelayout (0);
1031
 
 
1032
 
  self->OnLauncherHiddenChanged ();
 
1123
  if (unity_a11y_initialized() == TRUE)
 
1124
  {
 
1125
    AtkObject* atk_obj = NULL;
 
1126
 
 
1127
    atk_obj = unity_util_accessible_add_window(self->placesController->GetWindow());
 
1128
 
 
1129
    atk_object_set_name(atk_obj, _("Places"));
 
1130
  }
 
1131
 
 
1132
  self->launcher->SetHideMode(Launcher::LAUNCHER_HIDE_DODGE_WINDOWS);
 
1133
  self->launcher->SetLaunchAnimation(Launcher::LAUNCH_ANIMATION_PULSE);
 
1134
  self->launcher->SetUrgentAnimation(Launcher::URGENT_ANIMATION_WIGGLE);
 
1135
  self->ScheduleRelayout(0);
 
1136
 
 
1137
  self->OnLauncherHiddenChanged();
1033
1138
}
1034
1139
 
1035
1140
/* Window init */
1036
1141
UnityWindow::UnityWindow(CompWindow* window)
1037
 
 : PluginClassHandler<UnityWindow, CompWindow>(window)
1038
 
 , window(window)
1039
 
 , gWindow(GLWindow::get(window))
 
1142
  : PluginClassHandler<UnityWindow, CompWindow>(window)
 
1143
  , window(window)
 
1144
  , gWindow(GLWindow::get(window))
1040
1145
{
1041
 
  WindowInterface::setHandler (window);
1042
 
  GLWindowInterface::setHandler (gWindow);
 
1146
  WindowInterface::setHandler(window);
 
1147
  GLWindowInterface::setHandler(gWindow);
1043
1148
}
1044
1149
 
1045
1150
UnityWindow::~UnityWindow()
1046
1151
{
1047
 
  UnityScreen *us = UnityScreen::get (screen);
1048
 
  if (us->newFocusedWindow && (UnityWindow::get (us->newFocusedWindow) == this))
 
1152
  UnityScreen* us = UnityScreen::get(screen);
 
1153
  if (us->newFocusedWindow && (UnityWindow::get(us->newFocusedWindow) == this))
1049
1154
    us->newFocusedWindow = NULL;
1050
 
  if (us->lastFocusedWindow && (UnityWindow::get (us->lastFocusedWindow) == this))
 
1155
  if (us->lastFocusedWindow && (UnityWindow::get(us->lastFocusedWindow) == this))
1051
1156
    us->lastFocusedWindow = NULL;
1052
1157
}
1053
1158
 
1057
1162
  gfloat version;
1058
1163
  gchar* extensions;
1059
1164
 
1060
 
  if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
1061
 
    return false;
1062
 
  if (!CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI))
1063
 
    return false;
1064
 
  if (!CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
 
1165
  if (!CompPlugin::checkPluginABI("core", CORE_ABIVERSION))
 
1166
    return false;
 
1167
  if (!CompPlugin::checkPluginABI("composite", COMPIZ_COMPOSITE_ABI))
 
1168
    return false;
 
1169
  if (!CompPlugin::checkPluginABI("opengl", COMPIZ_OPENGL_ABI))
1065
1170
    return false;
1066
1171
 
1067
1172
  /* Ensure OpenGL version is 1.4+. */
1068
 
  version = get_opengl_version_f32 ((const gchar*) glGetString (GL_VERSION));
 
1173
  version = get_opengl_version_f32((const gchar*) glGetString(GL_VERSION));
1069
1174
  if (version < 1.4f)
1070
1175
  {
1071
 
    compLogMessage ("unityshell", CompLogLevelError,
1072
 
                    "OpenGL 1.4+ not supported\n");
 
1176
    compLogMessage("unityshell", CompLogLevelError,
 
1177
                   "OpenGL 1.4+ not supported\n");
1073
1178
    return false;
1074
1179
  }
1075
1180
 
1076
1181
  /* Ensure OpenGL extensions required by the Unity plugin are available. */
1077
 
  extensions = (gchar*) glGetString (GL_EXTENSIONS);
1078
 
  if (!is_extension_supported (extensions, "GL_ARB_vertex_program"))
1079
 
  {
1080
 
    compLogMessage ("unityshell", CompLogLevelError,
1081
 
                    "GL_ARB_vertex_program not supported\n");
1082
 
    return false;
1083
 
  }
1084
 
  if (!is_extension_supported (extensions, "GL_ARB_fragment_program"))
1085
 
  {
1086
 
    compLogMessage ("unityshell", CompLogLevelError,
1087
 
                    "GL_ARB_fragment_program not supported\n");
1088
 
    return false;
1089
 
  }
1090
 
  if (!is_extension_supported (extensions, "GL_ARB_vertex_buffer_object"))
1091
 
  {
1092
 
    compLogMessage ("unityshell", CompLogLevelError,
1093
 
                    "GL_ARB_vertex_buffer_object not supported\n");
1094
 
    return false;
1095
 
  }
1096
 
  if (!is_extension_supported (extensions, "GL_ARB_framebuffer_object"))
1097
 
  {
1098
 
    if (!is_extension_supported (extensions, "GL_EXT_framebuffer_object"))
 
1182
  extensions = (gchar*) glGetString(GL_EXTENSIONS);
 
1183
  if (!is_extension_supported(extensions, "GL_ARB_vertex_program"))
 
1184
  {
 
1185
    compLogMessage("unityshell", CompLogLevelError,
 
1186
                   "GL_ARB_vertex_program not supported\n");
 
1187
    return false;
 
1188
  }
 
1189
  if (!is_extension_supported(extensions, "GL_ARB_fragment_program"))
 
1190
  {
 
1191
    compLogMessage("unityshell", CompLogLevelError,
 
1192
                   "GL_ARB_fragment_program not supported\n");
 
1193
    return false;
 
1194
  }
 
1195
  if (!is_extension_supported(extensions, "GL_ARB_vertex_buffer_object"))
 
1196
  {
 
1197
    compLogMessage("unityshell", CompLogLevelError,
 
1198
                   "GL_ARB_vertex_buffer_object not supported\n");
 
1199
    return false;
 
1200
  }
 
1201
  if (!is_extension_supported(extensions, "GL_ARB_framebuffer_object"))
 
1202
  {
 
1203
    if (!is_extension_supported(extensions, "GL_EXT_framebuffer_object"))
1099
1204
    {
1100
 
      compLogMessage ("unityshell", CompLogLevelError,
1101
 
                      "GL_ARB_framebuffer_object or GL_EXT_framebuffer_object "
1102
 
                      "not supported\n");
 
1205
      compLogMessage("unityshell", CompLogLevelError,
 
1206
                     "GL_ARB_framebuffer_object or GL_EXT_framebuffer_object "
 
1207
                     "not supported\n");
1103
1208
      return false;
1104
1209
    }
1105
1210
  }
1106
 
  if (!is_extension_supported (extensions, "GL_ARB_texture_non_power_of_two"))
 
1211
  if (!is_extension_supported(extensions, "GL_ARB_texture_non_power_of_two"))
1107
1212
  {
1108
 
    if (!is_extension_supported (extensions, "GL_ARB_texture_rectangle"))
 
1213
    if (!is_extension_supported(extensions, "GL_ARB_texture_rectangle"))
1109
1214
    {
1110
 
      compLogMessage ("unityshell", CompLogLevelError,
1111
 
                      "GL_ARB_texture_non_power_of_two or "
1112
 
                      "GL_ARB_texture_rectangle not supported\n");
 
1215
      compLogMessage("unityshell", CompLogLevelError,
 
1216
                     "GL_ARB_texture_non_power_of_two or "
 
1217
                     "GL_ARB_texture_rectangle not supported\n");
1113
1218
      return false;
1114
1219
    }
1115
1220
  }
1118
1223
}
1119
1224
 
1120
1225
 
1121
 
namespace {
 
1226
namespace
 
1227
{
1122
1228
 
1123
1229
void configure_logging()
1124
1230
{
1136
1242
{
1137
1243
  if (extensions != NULL && extension != NULL)
1138
1244
  {
1139
 
    const gsize len = strlen (extension);
 
1245
    const gsize len = strlen(extension);
1140
1246
    gchar* p = (gchar*) extensions;
1141
 
    gchar* end = p + strlen (p);
 
1247
    gchar* end = p + strlen(p);
1142
1248
 
1143
1249
    while (p < end)
1144
1250
    {
1145
 
      const gsize size = strcspn (p, " ");
1146
 
      if (len == size && strncmp (extension, p, size) == 0)
 
1251
      const gsize size = strcspn(p, " ");
 
1252
      if (len == size && strncmp(extension, p, size) == 0)
1147
1253
        return TRUE;
1148
1254
      p += size + 1;
1149
1255
    }
1158
1264
  gfloat version = 0.0f;
1159
1265
  gint32 i;
1160
1266
 
1161
 
  for (i = 0; isdigit (version_string[i]); i++)
 
1267
  for (i = 0; isdigit(version_string[i]); i++)
1162
1268
    version = version * 10.0f + (version_string[i] - 48);
1163
1269
 
1164
 
  if (version_string[i++] == '.')
 
1270
  if ((version_string[i] == '.' || version_string[i] == ',') &&
 
1271
      isdigit(version_string[i + 1]))
1165
1272
  {
1166
 
    version = version * 10.0f + (version_string[i] - 48);
 
1273
    version = version * 10.0f + (version_string[i + 1] - 48);
1167
1274
    return (version + 0.1f) * 0.1f;
1168
1275
  }
1169
1276
  else
1186
1293
  return nux::logging::DEBUG;
1187
1294
}
1188
1295
 
1189
 
void capture_g_log_calls(const gchar *log_domain,
 
1296
void capture_g_log_calls(const gchar* log_domain,
1190
1297
                         GLogLevelFlags log_level,
1191
 
                         const gchar *message,
 
1298
                         const gchar* message,
1192
1299
                         gpointer user_data)
1193
1300
{
1194
1301
  // Since we aren't entirely sure if log_domain contains anything, lets have
1195
1302
  // a glib prefix.
1196
1303
  std::string module("glib");
1197
 
  if (log_domain) {
 
1304
  if (log_domain)
 
1305
  {
1198
1306
    module += std::string(".") + log_domain;
1199
1307
  }
1200
1308
  nux::logging::Logger logger(module);
1202
1310
  if (logger.GetEffectiveLogLevel() >= level)
1203
1311
  {
1204
1312
    nux::logging::LogStream(level, logger.module(), "<unknown>", 0).stream()
1205
 
      << message;
 
1313
        << message;
1206
1314
  }
1207
1315
}
1208
1316