251
247
_in_paint = false;
253
#ifndef USE_MODERN_COMPIZ_GL
254
void *dlhand = dlopen ("libunityshell.so", RTLD_LAZY);
259
glXGetProcAddressP = (ScreenEffectFramebufferObject::GLXGetProcAddressProc) dlsym (dlhand, "glXGetProcAddress");
260
if (dlerror () != NULL)
261
glXGetProcAddressP = NULL;
266
nux::Geometry geometry (0, 0, screen->width (), screen->height ());
267
uScreen->_fbo = ScreenEffectFramebufferObject::Ptr (new ScreenEffectFramebufferObject (glXGetProcAddressP, geometry));
268
uScreen->_fbo->onScreenSizeChanged (geometry);
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));
576
528
void UnityScreen::paintPanelShadow(const CompRegion &clip)
578
#ifndef USE_MODERN_COMPIZ_GL
579
if (sources_.GetSource(local::RELAYOUT_TIMEOUT))
582
if (PluginAdapter::Default()->IsExpoActive())
585
CompOutput* output = _last_output;
589
float panel_h = panel_style_.panel_height;
591
float x1 = output->x();
592
float y1 = output->y() + panel_h;
593
float x2 = x1 + output->width();
597
glLoadMatrixf (panel_shadow_matrix_.getMatrix ());
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();
609
for (auto monitor : monitors)
611
if (monitor.x == output->x() && monitor.y == output->y())
619
if (!(launcher_controller_->IsOverlayOpen() && current_monitor == dash_monitor_)
620
&& panel_controller_->opacity() > 0.0f)
622
foreach(GLTexture * tex, _shadow_texture)
625
glColor4f(1.0f, 1.0f, 1.0f, panel_controller_->opacity());
626
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
628
GL::activeTexture(GL_TEXTURE0_ARB);
629
tex->enable(GLTexture::Fast);
631
glTexParameteri(tex->target(), GL_TEXTURE_WRAP_S, GL_REPEAT);
635
glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), 0), COMP_TEX_COORD_Y(tex->matrix(), 0));
636
glVertex2f(vc[0], vc[2]);
638
glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), 0), COMP_TEX_COORD_Y(tex->matrix(), h));
639
glVertex2f(vc[0], vc[3]);
641
glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), w), COMP_TEX_COORD_Y(tex->matrix(), h));
642
glVertex2f(vc[1], vc[3]);
644
glTexCoord2f(COMP_TEX_COORD_X(tex->matrix(), w), COMP_TEX_COORD_Y(tex->matrix(), 0));
645
glVertex2f(vc[1], vc[2]);
650
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
657
530
if (sources_.GetSource(local::RELAYOUT_TIMEOUT))
779
651
panel_texture_has_changed_ = true;
782
#ifdef USE_MODERN_COMPIZ_GL
783
654
void UnityScreen::paintDisplay()
785
void UnityScreen::paintDisplay(const CompRegion& region, const GLMatrix& transform, unsigned int mask)
788
656
CompOutput *output = _last_output;
790
#ifndef USE_MODERN_COMPIZ_GL
791
bool was_bound = _fbo->bound ();
793
if (nux::GetGraphicsDisplay()->GetGraphicsEngine()->UsingGLSLCodePath())
795
if (was_bound && launcher_controller_->IsOverlayOpen() && paint_panel_)
797
if (panel_texture_has_changed_ || !panel_texture_.IsValid())
799
panel_texture_.Release();
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)
805
texture2D->Update(bitmap);
806
panel_texture_ = texture2D->GetDeviceTexture();
807
texture2D->UnReference();
810
panel_texture_has_changed_ = false;
813
if (panel_texture_.IsValid())
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());
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);
829
/* Draw the bit of the relevant framebuffer for each output */
834
sTransform.toScreenSpace (&screen->fullscreenOutput (), -DEFAULT_Z_CAMERA);
836
glLoadMatrixf (sTransform.getMatrix ());
837
_fbo->paint (nux::Geometry (output->x (), output->y (), output->width (), output->height ()));
841
nux::ObjectPtr<nux::IOpenGLBaseTexture> device_texture =
842
nux::GetGraphicsDisplay()->GetGpuDevice()->CreateTexture2DFromID(_fbo->texture(),
843
screen->width (), screen->height(), 1, nux::BITFMT_R8G8B8A8);
658
DrawTopPanelBackground();
660
auto gpu_device = nux::GetGraphicsDisplay()->GetGpuDevice();
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);
850
nux::GetGraphicsDisplay()->GetGpuDevice()->backup_texture0_ = device_texture;
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);
666
gpu_device->backup_texture0_ = device_texture;
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;
856
#ifdef USE_MODERN_COMPIZ_GL
858
673
// Nux renders to the referenceFramebuffer when it's embedded.
859
674
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fboID);
860
wt->GetWindowCompositor().SetReferenceFramebuffer(fboID, oGeo);
675
wt->GetWindowCompositor().SetReferenceFramebuffer(fboID, outputGeo);
864
678
_in_paint = true;
865
wt->RenderInterfaceFromForeignCmd (&oGeo);
679
wt->RenderInterfaceFromForeignCmd (&outputGeo);
866
680
_in_paint = false;
877
691
GLMatrix oTransform;
878
692
UnityWindow *uTrayWindow = UnityWindow::get (tray);
879
#ifndef USE_MODERN_COMPIZ_GL
880
GLFragment::Attrib attrib (uTrayWindow->gWindow->lastPaintAttrib());
882
693
GLWindowPaintAttrib attrib (uTrayWindow->gWindow->lastPaintAttrib());
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 ();
890
#ifndef USE_MODERN_COMPIZ_GL
891
attrib.setOpacity (OPAQUE);
892
attrib.setBrightness (BRIGHT);
893
attrib.setSaturation (COLOR);
895
697
attrib.opacity = OPAQUE;
896
698
attrib.brightness = BRIGHT;
897
699
attrib.saturation = COLOR;
900
701
oTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
902
#ifndef USE_MODERN_COMPIZ_GL
904
glLoadMatrixf (oTransform.getMatrix ());
907
703
painting_tray_ = true;
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);
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);
922
712
uTrayWindow->gWindow->glAddGeometrySetCurrentIndex (oldGlAddGeometryIndex);
923
713
uTrayWindow->gWindow->glDrawSetCurrentIndex (oldGlDrawIndex);
924
714
painting_tray_ = false;
926
#ifndef USE_MODERN_COMPIZ_GL
950
736
didShellRepaint = true;
739
void UnityScreen::DrawTopPanelBackground()
741
auto graphics_engine = nux::GetGraphicsDisplay()->GetGraphicsEngine();
743
if (!graphics_engine->UsingGLSLCodePath() || !launcher_controller_->IsOverlayOpen() || !paint_panel_)
746
if (TopPanelBackgroundTextureNeedsUpdate())
747
UpdateTopPanelBackgroundTexture();
749
if (panel_texture_.IsValid())
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());
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);
762
bool UnityScreen::TopPanelBackgroundTextureNeedsUpdate() const
764
return panel_texture_has_changed_ || !panel_texture_.IsValid();
767
void UnityScreen::UpdateTopPanelBackgroundTexture()
769
auto gpu_device = nux::GetGraphicsDisplay()->GetGpuDevice();
770
auto &panel_style = panel::Style::Instance();
772
panel_texture_.Release();
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());
777
if (bitmap && texture2D)
779
texture2D->Update(bitmap.get());
780
panel_texture_ = texture2D->GetDeviceTexture();
783
panel_texture_has_changed_ = false;
953
786
bool UnityScreen::forcePaintOnTop ()
955
788
return !allowWindowPaint ||
1362
1195
_last_output = output;
1363
1196
paint_panel_ = false;
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
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.
1381
if (doShellRepaint && !shellCouldBeHidden(*output))
1382
_fbo->bind (nux::Geometry (output->x (), output->y (), output->width (), output->height ()));
1385
1198
// CompRegion has no clear() method. So this is the fastest alternative.
1386
1199
fullscreenRegion = CompRegion();
1387
1200
nuxRegion = CompRegion();
1577
1381
cScreen->damageScreen();
1578
1382
cScreen->damageRegionSetEnabled(this, true);
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.
1590
if (!launcher_controller_ || !dash_controller_)
1593
CompRegion nux_damage;
1595
std::vector<nux::Geometry> const& dirty = wt->GetDrawList();
1597
for (auto const& geo : dirty)
1598
nux_damage += CompRegion(geo.x, geo.y, geo.width, geo.height);
1600
if (launcher_controller_->IsOverlayOpen())
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);
1607
auto const& launchers = launcher_controller_->launchers();
1608
for (auto const& launcher : launchers)
1610
if (!launcher->Hidden())
1612
nux::ObjectPtr<nux::View> tooltip = launcher->GetActiveTooltip();
1616
nux::Geometry const& g = tooltip->GetAbsoluteGeometry();
1617
nux_damage += CompRegion(g.x, g.y, g.width, g.height);
1620
nux::ObjectPtr<LauncherDragWindow> const& dragged_icon = launcher->GetDraggedIcon();
1624
nux::Geometry const& g = dragged_icon->GetAbsoluteGeometry();
1625
nux_damage += CompRegion(g.x, g.y, g.width, g.height);
1630
cScreen->damageRegionSetEnabled(this, false);
1631
cScreen->damageRegion(nux_damage);
1632
cScreen->damageRegionSetEnabled(this, true);
1636
1386
/* handle X Events */
1637
1387
void UnityScreen::handleEvent(XEvent* event)
1639
1389
bool skip_other_plugins = false;
1390
auto wm = PluginAdapter::Default();
1640
1392
switch (event->type)
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
1399
wm->OnScreenUngrabbed();
1651
1401
if (_key_nav_mode_requested)
1653
1403
// Close any overlay that is open.
1673
1424
launcher_controller_->KeyNavTerminate(false);
1674
1425
EnableCancelAction(CancelActionTarget::LAUNCHER_SWITCHER, false);
1676
if (scale_highlighted_window_ && PluginAdapter::Default()->IsScaleActive())
1427
if (wm->IsScaleActive())
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);
1433
if (launcher_controller_->IsOverlayOpen())
1435
int monitor_with_mouse = UScreen::GetDefault()->GetMonitorWithMouse();
1436
if (overlay_monitor_ != monitor_with_mouse)
1438
dash_controller_->HideDash(false);
1439
hud_controller_->HideHud(false);
1683
1443
case ButtonRelease:
1684
1444
if (switcher_controller_ && switcher_controller_->Visible())