~azzar1/unity/lp-552920

« back to all changes in this revision

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

  • Committer: Daniel van Vugt
  • Date: 2012-09-13 10:56:42 UTC
  • mfrom: (2684 unity)
  • mto: This revision was merged to the branch mainline in revision 2698.
  • Revision ID: daniel.van.vugt@canonical.com-20120913105642-9on2ald55h54j1zn
Merge latest lp:unity and fix conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
  , allowWindowPaint(false)
125
125
  , _key_nav_mode_requested(false)
126
126
  , _last_output(nullptr)
127
 
#ifndef USE_MODERN_COMPIZ_GL
128
 
  , _active_fbo (0)
129
 
#endif
130
127
  , grab_index_ (0)
131
128
  , painting_tray_ (false)
132
129
  , last_scroll_event_(0)
134
131
  , panel_texture_has_changed_(true)
135
132
  , paint_panel_(false)
136
133
  , scale_just_activated_(false)
137
 
  , scale_highlighted_window_(0)
138
134
  , minimize_speed_controller(new WindowMinimizeSpeedController())
139
135
{
140
136
  Timer timer;
250
246
     uScreen = this;
251
247
     _in_paint = false;
252
248
 
253
 
#ifndef USE_MODERN_COMPIZ_GL
254
 
    void *dlhand = dlopen ("libunityshell.so", RTLD_LAZY);
255
 
 
256
 
    if (dlhand)
257
 
    {
258
 
      dlerror ();
259
 
      glXGetProcAddressP = (ScreenEffectFramebufferObject::GLXGetProcAddressProc) dlsym (dlhand, "glXGetProcAddress");
260
 
      if (dlerror () != NULL)
261
 
        glXGetProcAddressP = NULL;
262
 
    }
263
 
 
264
 
     if (GL::fbo)
265
 
     {
266
 
       nux::Geometry geometry (0, 0, screen->width (), screen->height ());
267
 
       uScreen->_fbo = ScreenEffectFramebufferObject::Ptr (new ScreenEffectFramebufferObject (glXGetProcAddressP, geometry));
268
 
       uScreen->_fbo->onScreenSizeChanged (geometry);
269
 
     }
270
 
#endif
271
 
 
272
249
     optionSetShowHudInitiate(boost::bind(&UnityScreen::ShowHudInitiate, this, _1, _2, _3));
273
250
     optionSetShowHudTerminate(boost::bind(&UnityScreen::ShowHudTerminate, this, _1, _2, _3));
274
251
     optionSetBackgroundColorNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
381
358
       g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING,
382
359
                    &overlay_identity, &can_maximise, &overlay_monitor);
383
360
 
384
 
       dash_monitor_ = overlay_monitor;
 
361
       overlay_monitor_ = overlay_monitor;
385
362
 
386
363
       RaiseInputWindows();
387
364
     });
392
369
  }
393
370
 
394
371
  panel::Style::Instance().changed.connect(sigc::mem_fun(this, &UnityScreen::OnPanelStyleChanged));
395
 
  WindowManager::Default()->terminate_spread.connect([this] { scale_highlighted_window_ = 0; });
396
372
 
397
373
  minimize_speed_controller->DurationChanged.connect(
398
374
      sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged)
506
482
 
507
483
  glMatrixMode(GL_MODELVIEW);
508
484
  glPushMatrix();
509
 
 
510
 
#ifndef USE_MODERN_COMPIZ_GL
511
 
  /* This is needed to Fix a crash in glDrawArrays with the NVIDIA driver
512
 
   * see bugs #1031554 and #982626.
513
 
   * The NVIDIA driver looks to see if the legacy GL_VERTEX_ARRAY,
514
 
   * GL_TEXTURE_COORDINATES_ARRAY and other such client states are enabled
515
 
   * first before checking if a vertex buffer is bound and will prefer the
516
 
   * client buffers over the the vertex buffer object. */
517
 
  glDisableClientState(GL_VERTEX_ARRAY);
518
 
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
519
 
#endif
520
485
#endif
521
486
 
522
487
  glGetError();
525
490
void UnityScreen::nuxEpilogue()
526
491
{
527
492
#ifndef USE_GLES
528
 
#ifndef USE_MODERN_COMPIZ_GL
529
 
  (*GL::bindFramebuffer)(GL_FRAMEBUFFER_EXT, _active_fbo);
530
 
#endif
531
493
 
532
494
  glMatrixMode(GL_PROJECTION);
533
495
  glLoadIdentity();
549
511
 
550
512
  glPopAttrib();
551
513
 
552
 
#ifndef USE_MODERN_COMPIZ_GL
553
 
  /* Re-enable the client states that have been disabled in nuxPrologue, for
554
 
   * NVIDIA compatibility reasons */
555
 
  glEnableClientState(GL_VERTEX_ARRAY);
556
 
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
557
 
#endif
 
514
  glDepthRange(0, 1);
558
515
#else
559
 
#ifdef USE_GLES
560
516
  glDepthRangef(0, 1);
561
 
#else
562
 
  glDepthRange(0, 1);
563
 
#endif
564
 
  //glViewport(-1, -1, 2, 2);
565
517
  gScreen->resetRasterPos();
566
518
#endif
567
519
 
575
527
 
576
528
void UnityScreen::paintPanelShadow(const CompRegion &clip)
577
529
{
578
 
#ifndef USE_MODERN_COMPIZ_GL
579
 
  if (sources_.GetSource(local::RELAYOUT_TIMEOUT))
580
 
    return;
581
 
 
582
 
  if (PluginAdapter::Default()->IsExpoActive())
583
 
    return;
584
 
 
585
 
  CompOutput* output = _last_output;
586
 
  float vc[4];
587
 
  float h = 20.0f;
588
 
  float w = 1.0f;
589
 
  float panel_h = panel_style_.panel_height;
590
 
 
591
 
  float x1 = output->x();
592
 
  float y1 = output->y() + panel_h;
593
 
  float x2 = x1 + output->width();
594
 
  float y2 = y1 + h;
595
 
 
596
 
  glPushMatrix ();
597
 
  glLoadMatrixf (panel_shadow_matrix_.getMatrix ());
598
 
 
599
 
  vc[0] = x1;
600
 
  vc[1] = x2;
601
 
  vc[2] = y1;
602
 
  vc[3] = y2;
603
 
 
604
 
  // compiz doesn't use the same method of tracking monitors as our toolkit
605
 
  // we need to make sure we properly associate with the right monitor
606
 
  int current_monitor = -1;
607
 
  auto monitors = UScreen::GetDefault()->GetMonitors();
608
 
  int i = 0;
609
 
  for (auto monitor : monitors)
610
 
  {
611
 
    if (monitor.x == output->x() && monitor.y == output->y())
612
 
    {
613
 
      current_monitor = i;
614
 
      break;
615
 
    }
616
 
    i++;
617
 
  }
618
 
 
619
 
  if (!(launcher_controller_->IsOverlayOpen() && current_monitor == dash_monitor_)
620
 
      && panel_controller_->opacity() > 0.0f)
621
 
  {
622
 
    foreach(GLTexture * tex, _shadow_texture)
623
 
    {
624
 
      glEnable(GL_BLEND);
625
 
      glColor4f(1.0f, 1.0f, 1.0f, panel_controller_->opacity());
626
 
      glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
627
 
 
628
 
      GL::activeTexture(GL_TEXTURE0_ARB);
629
 
      tex->enable(GLTexture::Fast);
630
 
 
631
 
      glTexParameteri(tex->target(), GL_TEXTURE_WRAP_S, GL_REPEAT);
632
 
 
633
 
      glBegin(GL_QUADS);
634
 
      {
635
 
        glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), 0), COMP_TEX_COORD_Y(tex->matrix(), 0));
636
 
        glVertex2f(vc[0], vc[2]);
637
 
 
638
 
        glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), 0), COMP_TEX_COORD_Y(tex->matrix(), h));
639
 
        glVertex2f(vc[0], vc[3]);
640
 
 
641
 
        glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), w), COMP_TEX_COORD_Y(tex->matrix(), h));
642
 
        glVertex2f(vc[1], vc[3]);
643
 
 
644
 
        glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), w), COMP_TEX_COORD_Y(tex->matrix(), 0));
645
 
        glVertex2f(vc[1], vc[2]);
646
 
      }
647
 
      glEnd();
648
 
 
649
 
      tex->disable();
650
 
      glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
651
 
      glDisable(GL_BLEND);
652
 
    }
653
 
  }
654
 
  glPopMatrix();
655
 
#else
656
 
 
657
530
  if (sources_.GetSource(local::RELAYOUT_TIMEOUT))
658
531
    return;
659
532
 
706
579
    i++;
707
580
  }
708
581
 
709
 
  if (!(launcher_controller_->IsOverlayOpen() && current_monitor == dash_monitor_)
 
582
  if (!(launcher_controller_->IsOverlayOpen() && current_monitor == overlay_monitor_)
710
583
      && panel_controller_->opacity() > 0.0f)
711
584
  {
712
585
    foreach(GLTexture * tex, _shadow_texture)
758
631
    }
759
632
  }
760
633
  nuxEpilogue();
761
 
#endif
762
634
}
763
635
 
764
636
void
779
651
  panel_texture_has_changed_ = true;
780
652
}
781
653
 
782
 
#ifdef USE_MODERN_COMPIZ_GL
783
654
void UnityScreen::paintDisplay()
784
 
#else
785
 
void UnityScreen::paintDisplay(const CompRegion& region, const GLMatrix& transform, unsigned int mask)
786
 
#endif
787
655
{
788
656
  CompOutput *output = _last_output;
789
657
 
790
 
#ifndef USE_MODERN_COMPIZ_GL
791
 
  bool was_bound = _fbo->bound ();
792
 
 
793
 
  if (nux::GetGraphicsDisplay()->GetGraphicsEngine()->UsingGLSLCodePath())
794
 
  {
795
 
    if (was_bound && launcher_controller_->IsOverlayOpen() && paint_panel_)
796
 
    {
797
 
      if (panel_texture_has_changed_ || !panel_texture_.IsValid())
798
 
      {
799
 
        panel_texture_.Release();
800
 
 
801
 
        nux::NBitmapData* bitmap = panel::Style::Instance().GetBackground(screen->width (), screen->height(), 1.0f);
802
 
        nux::BaseTexture* texture2D = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
803
 
        if (bitmap && texture2D)
804
 
        {
805
 
          texture2D->Update(bitmap);
806
 
          panel_texture_ = texture2D->GetDeviceTexture();
807
 
          texture2D->UnReference();
808
 
          delete bitmap;
809
 
        }
810
 
        panel_texture_has_changed_ = false;
811
 
      }
812
 
 
813
 
      if (panel_texture_.IsValid())
814
 
      {
815
 
        nux::GetGraphicsDisplay()->GetGraphicsEngine()->ResetModelViewMatrixStack();
816
 
        nux::GetGraphicsDisplay()->GetGraphicsEngine()->Push2DTranslationModelViewMatrix(0.0f, 0.0f, 0.0f);
817
 
        nux::GetGraphicsDisplay()->GetGraphicsEngine()->ResetProjectionMatrix();
818
 
        nux::GetGraphicsDisplay()->GetGraphicsEngine()->SetOrthographicProjectionMatrix(screen->width (), screen->height());
819
 
 
820
 
        nux::TexCoordXForm texxform;
821
 
        int panel_height = panel_style_.panel_height;
822
 
        nux::GetGraphicsDisplay()->GetGraphicsEngine()->QRP_GLSL_1Tex(0, 0, screen->width (), panel_height, panel_texture_, texxform, nux::color::White);
823
 
      }
824
 
    }
825
 
  }
826
 
 
827
 
  _fbo->unbind ();
828
 
 
829
 
  /* Draw the bit of the relevant framebuffer for each output */
830
 
 
831
 
  if (was_bound)
832
 
  {
833
 
    GLMatrix sTransform;
834
 
    sTransform.toScreenSpace (&screen->fullscreenOutput (), -DEFAULT_Z_CAMERA);
835
 
    glPushMatrix ();
836
 
    glLoadMatrixf (sTransform.getMatrix ());
837
 
    _fbo->paint (nux::Geometry (output->x (), output->y (), output->width (), output->height ()));
838
 
    glPopMatrix ();
839
 
  }
840
 
 
841
 
  nux::ObjectPtr<nux::IOpenGLBaseTexture> device_texture =
842
 
      nux::GetGraphicsDisplay()->GetGpuDevice()->CreateTexture2DFromID(_fbo->texture(),
843
 
                                                                       screen->width (), screen->height(), 1, nux::BITFMT_R8G8B8A8);
844
 
#else
 
658
  DrawTopPanelBackground();
 
659
 
 
660
  auto gpu_device = nux::GetGraphicsDisplay()->GetGpuDevice();
 
661
 
845
662
  nux::ObjectPtr<nux::IOpenGLTexture2D> device_texture =
846
 
    nux::GetGraphicsDisplay()->GetGpuDevice()->CreateTexture2DFromID(gScreen->fbo ()->tex ()->name (),
847
 
      screen->width(), screen->height(), 1, nux::BITFMT_R8G8B8A8);
848
 
#endif
849
 
 
850
 
  nux::GetGraphicsDisplay()->GetGpuDevice()->backup_texture0_ = device_texture;
851
 
 
852
 
  nux::Geometry geo = nux::Geometry (0, 0, screen->width (), screen->height ());
853
 
  nux::Geometry oGeo = nux::Geometry (output->x (), output->y (), output->width (), output->height ());
 
663
    gpu_device->CreateTexture2DFromID(gScreen->fbo ()->tex ()->name (),
 
664
                                      screen->width(), screen->height(), 1, nux::BITFMT_R8G8B8A8);
 
665
 
 
666
  gpu_device->backup_texture0_ = device_texture;
 
667
 
 
668
  nux::Geometry geo(0, 0, screen->width (), screen->height ());
 
669
  nux::Geometry outputGeo(output->x (), output->y (), output->width (), output->height ());
854
670
  BackgroundEffectHelper::monitor_rect_ = geo;
855
671
 
856
 
#ifdef USE_MODERN_COMPIZ_GL
857
672
  GLint fboID;
858
673
  // Nux renders to the referenceFramebuffer when it's embedded.
859
674
  glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fboID);
860
 
  wt->GetWindowCompositor().SetReferenceFramebuffer(fboID, oGeo);
861
 
#endif
 
675
  wt->GetWindowCompositor().SetReferenceFramebuffer(fboID, outputGeo);
862
676
 
863
677
  nuxPrologue();
864
678
  _in_paint = true;
865
 
  wt->RenderInterfaceFromForeignCmd (&oGeo);
 
679
  wt->RenderInterfaceFromForeignCmd (&outputGeo);
866
680
  _in_paint = false;
867
681
  nuxEpilogue();
868
682
 
876
690
      {
877
691
        GLMatrix oTransform;
878
692
        UnityWindow  *uTrayWindow = UnityWindow::get (tray);
879
 
#ifndef USE_MODERN_COMPIZ_GL
880
 
        GLFragment::Attrib attrib (uTrayWindow->gWindow->lastPaintAttrib());
881
 
#else
882
693
        GLWindowPaintAttrib attrib (uTrayWindow->gWindow->lastPaintAttrib());
883
 
#endif
884
694
        unsigned int oldGlAddGeometryIndex = uTrayWindow->gWindow->glAddGeometryGetCurrentIndex ();
885
695
        unsigned int oldGlDrawIndex = uTrayWindow->gWindow->glDrawGetCurrentIndex ();
886
 
#ifndef USE_MODERN_COMPIZ_GL
887
 
        unsigned int oldGlDrawGeometryIndex = uTrayWindow->gWindow->glDrawGeometryGetCurrentIndex ();
888
 
#endif
889
696
 
890
 
#ifndef USE_MODERN_COMPIZ_GL
891
 
        attrib.setOpacity (OPAQUE);
892
 
        attrib.setBrightness (BRIGHT);
893
 
        attrib.setSaturation (COLOR);
894
 
#else
895
697
        attrib.opacity = OPAQUE;
896
698
        attrib.brightness = BRIGHT;
897
699
        attrib.saturation = COLOR;
898
 
#endif
899
700
 
900
701
        oTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
901
702
 
902
 
#ifndef USE_MODERN_COMPIZ_GL
903
 
        glPushMatrix ();
904
 
        glLoadMatrixf (oTransform.getMatrix ());
905
 
#endif
906
 
 
907
703
        painting_tray_ = true;
908
704
 
909
705
        /* force the use of the core functions */
910
706
        uTrayWindow->gWindow->glDrawSetCurrentIndex (MAXSHORT);
911
707
        uTrayWindow->gWindow->glAddGeometrySetCurrentIndex ( MAXSHORT);
912
 
#ifndef USE_MODERN_COMPIZ_GL
913
 
        uTrayWindow->gWindow->glDrawGeometrySetCurrentIndex (MAXSHORT);
914
 
#endif
915
708
        uTrayWindow->gWindow->glDraw (oTransform, attrib, infiniteRegion,
916
709
               PAINT_WINDOW_TRANSFORMED_MASK |
917
710
               PAINT_WINDOW_BLEND_MASK |
918
711
               PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK);
919
 
#ifndef USE_MODERN_COMPIZ_GL
920
 
        uTrayWindow->gWindow->glDrawGeometrySetCurrentIndex (oldGlDrawGeometryIndex);
921
 
#endif
922
712
        uTrayWindow->gWindow->glAddGeometrySetCurrentIndex (oldGlAddGeometryIndex);
923
713
        uTrayWindow->gWindow->glDrawSetCurrentIndex (oldGlDrawIndex);
924
714
        painting_tray_ = false;
925
 
 
926
 
#ifndef USE_MODERN_COMPIZ_GL
927
 
        glPopMatrix ();
928
 
#endif
929
715
      }
930
716
    }
931
717
  }
950
736
  didShellRepaint = true;
951
737
}
952
738
 
 
739
void UnityScreen::DrawTopPanelBackground()
 
740
{
 
741
  auto graphics_engine = nux::GetGraphicsDisplay()->GetGraphicsEngine();
 
742
 
 
743
  if (!graphics_engine->UsingGLSLCodePath() || !launcher_controller_->IsOverlayOpen() || !paint_panel_)
 
744
   return;
 
745
 
 
746
  if (TopPanelBackgroundTextureNeedsUpdate())
 
747
    UpdateTopPanelBackgroundTexture();
 
748
 
 
749
  if (panel_texture_.IsValid())
 
750
  {
 
751
    graphics_engine->ResetModelViewMatrixStack();
 
752
    graphics_engine->Push2DTranslationModelViewMatrix(0.0f, 0.0f, 0.0f);
 
753
    graphics_engine->ResetProjectionMatrix();
 
754
    graphics_engine->SetOrthographicProjectionMatrix(screen->width (), screen->height());
 
755
 
 
756
    nux::TexCoordXForm texxform;
 
757
    int panel_height = panel_style_.panel_height;
 
758
    graphics_engine->QRP_GLSL_1Tex(0, 0, screen->width (), panel_height, panel_texture_, texxform, nux::color::White);
 
759
  }
 
760
}
 
761
 
 
762
bool UnityScreen::TopPanelBackgroundTextureNeedsUpdate() const
 
763
{
 
764
  return panel_texture_has_changed_ || !panel_texture_.IsValid();
 
765
}
 
766
 
 
767
void UnityScreen::UpdateTopPanelBackgroundTexture()
 
768
{
 
769
  auto gpu_device = nux::GetGraphicsDisplay()->GetGpuDevice();
 
770
  auto &panel_style = panel::Style::Instance();
 
771
 
 
772
  panel_texture_.Release();
 
773
 
 
774
  std::unique_ptr<nux::NBitmapData> bitmap(panel_style.GetBackground(screen->width(), screen->height(), 1.0f));
 
775
  nux::ObjectPtr<nux::BaseTexture> texture2D(gpu_device->CreateSystemCapableTexture());
 
776
 
 
777
  if (bitmap && texture2D)
 
778
  {
 
779
    texture2D->Update(bitmap.get());
 
780
    panel_texture_ = texture2D->GetDeviceTexture();
 
781
  }
 
782
 
 
783
  panel_texture_has_changed_ = false;
 
784
}
 
785
 
953
786
bool UnityScreen::forcePaintOnTop ()
954
787
{
955
788
    return !allowWindowPaint ||
1362
1195
  _last_output = output;
1363
1196
  paint_panel_ = false;
1364
1197
 
1365
 
#ifndef USE_MODERN_COMPIZ_GL
1366
 
  /* bind the framebuffer here
1367
 
   * - it will be unbound and flushed
1368
 
   *   to the backbuffer when some
1369
 
   *   plugin requests to draw a
1370
 
   *   a transformed screen or when
1371
 
   *   we have finished this draw cycle.
1372
 
   *   once an fbo is bound any further
1373
 
   *   attempts to bind it will only increment
1374
 
   *   its bind reference so make sure that
1375
 
   *   you always unbind as much as you bind
1376
 
   *
1377
 
   * But NOTE: It is only safe to bind the FBO if !shellCouldBeHidden.
1378
 
   *           Otherwise it's possible painting won't occur and that would
1379
 
   *           confuse the state of the FBO.
1380
 
   */
1381
 
  if (doShellRepaint && !shellCouldBeHidden(*output))
1382
 
    _fbo->bind (nux::Geometry (output->x (), output->y (), output->width (), output->height ()));
1383
 
#endif
1384
 
 
1385
1198
  // CompRegion has no clear() method. So this is the fastest alternative.
1386
1199
  fullscreenRegion = CompRegion();
1387
1200
  nuxRegion = CompRegion();
1393
1206
    doShellRepaint = false;
1394
1207
 
1395
1208
  if (doShellRepaint)
1396
 
#ifdef USE_MODERN_COMPIZ_GL
1397
1209
    paintDisplay();
1398
 
#else
1399
 
    paintDisplay(region, transform, mask);
1400
 
#endif
1401
1210
 
1402
1211
  return ret;
1403
1212
}
1427
1236
  for (ShowdesktopHandlerWindowInterface *wi : ShowdesktopHandler::animating_windows)
1428
1237
    wi->HandleAnimations (ms);
1429
1238
 
1430
 
#ifndef USE_MODERN_COMPIZ_GL
1431
 
  compizDamageNux(cScreen->currentDamage());
1432
 
#endif
1433
 
 
1434
1239
  didShellRepaint = false;
1435
1240
  firstWindowAboveShell = NULL;
1436
1241
}
1557
1362
/* Grab changed nux regions and add damage rects for them */
1558
1363
void UnityScreen::nuxDamageCompiz()
1559
1364
{
1560
 
#ifdef USE_MODERN_COMPIZ_GL
1561
1365
  /*
1562
1366
   * If Nux is going to redraw anything then we have to tell Compiz to
1563
1367
   * redraw everything. This is because Nux has a bad habit (bug??) of drawing
1577
1381
    cScreen->damageScreen();
1578
1382
    cScreen->damageRegionSetEnabled(this, true);
1579
1383
  }
1580
 
 
1581
 
#else
1582
 
 
1583
 
  /*
1584
 
   * WARNING: Nux bug LP: #1014610 (unbounded DrawList growth) will cause
1585
 
   *          this code to be called far too often in some cases and
1586
 
   *          Unity will appear to freeze for a while. Please ensure you
1587
 
   *          have Nux 3.0+ with the fix for LP: #1014610.
1588
 
   */
1589
 
 
1590
 
  if (!launcher_controller_ || !dash_controller_)
1591
 
    return;
1592
 
 
1593
 
  CompRegion nux_damage;
1594
 
 
1595
 
  std::vector<nux::Geometry> const& dirty = wt->GetDrawList();
1596
 
 
1597
 
  for (auto const& geo : dirty)
1598
 
    nux_damage += CompRegion(geo.x, geo.y, geo.width, geo.height);
1599
 
 
1600
 
  if (launcher_controller_->IsOverlayOpen())
1601
 
  {
1602
 
    nux::BaseWindow* dash_window = dash_controller_->window();
1603
 
    nux::Geometry const& geo = dash_window->GetAbsoluteGeometry();
1604
 
    nux_damage += CompRegion(geo.x, geo.y, geo.width, geo.height);
1605
 
  }
1606
 
 
1607
 
  auto const& launchers = launcher_controller_->launchers();
1608
 
  for (auto const& launcher : launchers)
1609
 
  {
1610
 
    if (!launcher->Hidden())
1611
 
    {
1612
 
      nux::ObjectPtr<nux::View> tooltip = launcher->GetActiveTooltip();
1613
 
 
1614
 
      if (tooltip)
1615
 
      {
1616
 
        nux::Geometry const& g = tooltip->GetAbsoluteGeometry();
1617
 
        nux_damage += CompRegion(g.x, g.y, g.width, g.height);
1618
 
      }
1619
 
 
1620
 
      nux::ObjectPtr<LauncherDragWindow> const& dragged_icon = launcher->GetDraggedIcon();
1621
 
 
1622
 
      if (dragged_icon)
1623
 
      {
1624
 
        nux::Geometry const& g = dragged_icon->GetAbsoluteGeometry();
1625
 
        nux_damage += CompRegion(g.x, g.y, g.width, g.height);
1626
 
      }
1627
 
    }
1628
 
  }
1629
 
 
1630
 
  cScreen->damageRegionSetEnabled(this, false);
1631
 
  cScreen->damageRegion(nux_damage);
1632
 
  cScreen->damageRegionSetEnabled(this, true);
1633
 
#endif
1634
1384
}
1635
1385
 
1636
1386
/* handle X Events */
1637
1387
void UnityScreen::handleEvent(XEvent* event)
1638
1388
{
1639
1389
  bool skip_other_plugins = false;
 
1390
  auto wm = PluginAdapter::Default();
 
1391
 
1640
1392
  switch (event->type)
1641
1393
  {
1642
1394
    case FocusIn:
1643
1395
    case FocusOut:
1644
1396
      if (event->xfocus.mode == NotifyGrab)
1645
 
        PluginAdapter::Default()->OnScreenGrabbed();
 
1397
        wm->OnScreenGrabbed();
1646
1398
      else if (event->xfocus.mode == NotifyUngrab)
1647
 
        PluginAdapter::Default()->OnScreenUngrabbed();
1648
 
#ifndef USE_MODERN_COMPIZ_GL
1649
 
      cScreen->damageScreen();  // evil hack
1650
 
#endif
 
1399
        wm->OnScreenUngrabbed();
 
1400
 
1651
1401
      if (_key_nav_mode_requested)
1652
1402
      {
1653
1403
        // Close any overlay that is open.
1661
1411
      _key_nav_mode_requested = false;
1662
1412
      break;
1663
1413
    case MotionNotify:
1664
 
      if (scale_highlighted_window_ && PluginAdapter::Default()->IsScaleActive())
 
1414
      if (wm->IsScaleActive())
1665
1415
      {
1666
 
        if (CompWindow *w = screen->findWindow(scale_highlighted_window_))
 
1416
        ScaleScreen* ss = ScaleScreen::get(screen);
 
1417
        if (CompWindow *w = screen->findWindow(ss->getSelectedWindow()))
1667
1418
          skip_other_plugins = UnityWindow::get(w)->handleEvent(event);
1668
1419
      }
1669
1420
      break;
1673
1424
        launcher_controller_->KeyNavTerminate(false);
1674
1425
        EnableCancelAction(CancelActionTarget::LAUNCHER_SWITCHER, false);
1675
1426
      }
1676
 
      if (scale_highlighted_window_ && PluginAdapter::Default()->IsScaleActive())
 
1427
      if (wm->IsScaleActive())
1677
1428
      {
1678
 
        if (CompWindow *w = screen->findWindow(scale_highlighted_window_))
 
1429
        ScaleScreen* ss = ScaleScreen::get(screen);
 
1430
        if (CompWindow *w = screen->findWindow(ss->getSelectedWindow()))
1679
1431
          skip_other_plugins = UnityWindow::get(w)->handleEvent(event);
1680
1432
      }
1681
 
 
 
1433
      if (launcher_controller_->IsOverlayOpen())
 
1434
      {
 
1435
        int monitor_with_mouse = UScreen::GetDefault()->GetMonitorWithMouse();
 
1436
        if (overlay_monitor_ != monitor_with_mouse)
 
1437
        {
 
1438
          dash_controller_->HideDash(false);
 
1439
          hud_controller_->HideHud(false);
 
1440
        }
 
1441
      }
1682
1442
      break;
1683
1443
    case ButtonRelease:
1684
1444
      if (switcher_controller_ && switcher_controller_->Visible())
1698
1458
          }
1699
1459
        }
1700
1460
      }
1701
 
      else if (scale_highlighted_window_ && PluginAdapter::Default()->IsScaleActive())
 
1461
      else if (wm->IsScaleActive())
1702
1462
      {
1703
 
        if (CompWindow *w = screen->findWindow(scale_highlighted_window_))
1704
 
          UnityWindow::get(w)->handleEvent(event);
 
1463
        ScaleScreen* ss = ScaleScreen::get(screen);
 
1464
        if (CompWindow *w = screen->findWindow(ss->getSelectedWindow()))
 
1465
          skip_other_plugins = UnityWindow::get(w)->handleEvent(event);
1705
1466
      }
1706
1467
      break;
1707
1468
    case KeyPress:
2612
2373
      !uScreen->fullscreenRegion.contains(window->geometry())
2613
2374
     )
2614
2375
  {
2615
 
#ifdef USE_MODERN_COMPIZ_GL
2616
2376
    uScreen->paintDisplay();
2617
 
#else
2618
 
    uScreen->paintDisplay(region, matrix, mask);
2619
 
#endif
2620
2377
  }
2621
2378
 
2622
2379
  if (window->type() == CompWindowTypeDesktopMask)
2821
2578
    UnityScreen* us = UnityScreen::get(screen);
2822
2579
    CompWindow *lw;
2823
2580
 
2824
 
    if (us->launcher_controller_->IsOverlayOpen())
 
2581
    // can't rely on launcher->IsOverlayVisible on focus change (because ubus is async close on focus change.)
 
2582
    if (us && (us->dash_controller_->IsVisible() || us->hud_controller_->IsVisible()))
2825
2583
    {
2826
2584
      lw = screen->findWindow(us->launcher_controller_->LauncherWindowId(0));
2827
2585
      lw->moveInputFocusTo();
3133
2891
  if (!needsRelayout)
3134
2892
    return;
3135
2893
 
3136
 
#ifndef USE_MODERN_COMPIZ_GL
3137
 
  if (GL::fbo)
3138
 
  {
3139
 
    uScreen->_fbo = ScreenEffectFramebufferObject::Ptr (new ScreenEffectFramebufferObject (glXGetProcAddressP, geometry));
3140
 
    uScreen->_fbo->onScreenSizeChanged (geometry);
3141
 
  }
3142
 
#endif
3143
 
 
3144
2894
  UScreen *uscreen = UScreen::GetDefault();
3145
2895
  int primary_monitor = uscreen->GetPrimaryMonitor();
3146
2896
  auto geo = uscreen->GetMonitorGeometry(primary_monitor);
3870
3620
  if (!scale_win->hasSlot()) // animation not finished
3871
3621
    return;
3872
3622
 
3873
 
  UnityScreen* us = UnityScreen::get(screen);
3874
 
  const bool highlighted = (us->scale_highlighted_window_ == window->id());
 
3623
  ScaleScreen* ss = ScaleScreen::get(screen);
 
3624
  const bool highlighted = (ss->getSelectedWindow() == window->id());
3875
3625
 
3876
3626
  ScalePosition const& pos = scale_win->getCurrentPosition();
3877
3627
  auto const& border_rect = window->borderRect();
3924
3674
  }
3925
3675
}
3926
3676
 
3927
 
void UnityWindow::scaleSelectWindow()
3928
 
{
3929
 
  ScaleWindow::get(window)->scaleSelectWindow();
3930
 
 
3931
 
  UnityScreen* us = UnityScreen::get(screen);
3932
 
 
3933
 
  if (us->scale_highlighted_window_ != window->id())
3934
 
    us->scale_highlighted_window_ = window->id();
3935
 
}
3936
 
 
3937
3677
void UnityWindow::OnInitiateSpreed()
3938
3678
{
3939
3679
  auto const windows = screen->windows();