~george-edison55/stackfusion/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "stackfusion.h"

COMPIZ_PLUGIN_20090315 (stackfusion, StackFusionVTable);

StackFusionScreen::StackFusionScreen(CompScreen * screen)
    : PluginClassHandler <StackFusionScreen, CompScreen> (screen),
      m_c_screen(CompositeScreen::get(screen)),
      m_g_screen(GLScreen::get(screen)),
      m_active(false)
{
    CompositeScreenInterface::setHandler(m_c_screen, false);
    GLScreenInterface::setHandler(m_g_screen, false);

    // Setup the keybindings
    optionSetToggleKeyInitiate(boost::bind(&StackFusionScreen::toggle, this, _1, _2, _3));
}

StackFusionScreen::~StackFusionScreen()
{
    // If the display is active, disable it
    if(m_active)
        ToggleDisplay();
}

// Painting functions
void StackFusionScreen::preparePaint(int ms)
{
    m_ms = ms;
    m_c_screen->preparePaint(ms);
}

void StackFusionScreen::donePaint()
{
    m_c_screen->damageScreen();
    m_c_screen->donePaint();
}

void StackFusionScreen::ToggleDisplay()
{
    m_active = !m_active;

    m_c_screen->preparePaintSetEnabled(this, m_active);
    m_c_screen->donePaintSetEnabled(this, m_active);
    m_g_screen->glPaintOutputSetEnabled(this, m_active);
    
    m_bubble.FadeIn(2000);
}

bool StackFusionScreen::glPaintOutput (const GLScreenPaintAttrib & sAttrib,
                                       const GLMatrix            & transform,
                                       const CompRegion          & region,
                                       CompOutput                * output,
                                       unsigned int              mask)
{
    bool status = m_g_screen->glPaintOutput (sAttrib, transform, region, output, mask);

    // Draw a rectangle
    GLMatrix sTransform = transform;
    sTransform.toScreenSpace(output, -DEFAULT_Z_CAMERA);

    glPushMatrix();
    glLoadMatrixf(sTransform.getMatrix ());
    glTranslatef(100.0f, 100.0f, 0.0f);
    glScalef(25.0f, 25.0f, 1.0f);

    /*
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColor4f(0.5, 0.5, 0.5, 0.2f);
    glBegin(GL_QUADS);
    glVertex2f(-1.0f, 1.0f);
    glVertex2f( 1.0f, 1.0f);
    glVertex2f( 1.0f,-1.0f);
    glVertex2f(-1.0f,-1.0f);
    glEnd();
    glDisable(GL_BLEND);
    */
    
    glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    m_bubble.Render(m_ms);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glPopAttrib();

    glPopMatrix();

    return status;
}

bool StackFusionScreen::toggle(CompAction * action, CompAction::State state, CompOption::Vector options)
{
    ToggleDisplay();

    return true;
}

bool StackFusionVTable::init()
{
    if (!CompPlugin::checkPluginABI("core",      CORE_ABIVERSION) ||
        !CompPlugin::checkPluginABI("composite", COMPIZ_COMPOSITE_ABI) ||
        !CompPlugin::checkPluginABI("opengl",    COMPIZ_OPENGL_ABI))
            return false;

    return true;
}