~ubuntu-branches/ubuntu/lucid/compiz-fusion-plugins-extra/lucid

« back to all changes in this revision

Viewing changes to src/scalefilter/scalefilter.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2007-12-05 22:48:25 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20071205224825-yhfs0zm2evj7ca3x
Tags: 0.6.99+git20071127-0ubuntu1
new git HEAD snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <X11/Xlib.h>
37
37
#include <X11/keysymdef.h>
38
38
 
39
 
#include <compiz.h>
40
 
#include <scale.h>
41
 
#include <text.h>
 
39
#include <compiz-core.h>
 
40
#include <compiz-scale.h>
 
41
#include <compiz-text.h>
42
42
 
43
43
#include "scalefilter_options.h"
44
44
 
73
73
    XIM xim;
74
74
    XIC xic;
75
75
 
 
76
    Bool textAvailable;
 
77
 
76
78
    HandleEventProc       handleEvent;
77
79
    HandleCompizEventProc handleCompizEvent;
78
80
} ScaleFilterDisplay;
88
90
} ScaleFilterScreen;
89
91
 
90
92
#define GET_FILTER_DISPLAY(d)                                     \
91
 
    ((ScaleFilterDisplay *) (d)->privates[displayPrivateIndex].ptr)
 
93
    ((ScaleFilterDisplay *) (d)->base.privates[displayPrivateIndex].ptr)
92
94
 
93
95
#define FILTER_DISPLAY(d)                         \
94
96
    ScaleFilterDisplay *fd = GET_FILTER_DISPLAY (d)
95
97
 
96
98
#define GET_FILTER_SCREEN(s, fd)                                              \
97
 
    ((ScaleFilterScreen *) (s)->privates[(fd)->screenPrivateIndex].ptr)
 
99
    ((ScaleFilterScreen *) (s)->base.privates[(fd)->screenPrivateIndex].ptr)
98
100
 
99
 
#define FILTER_SCREEN(s)                                                               \
100
 
    ScaleFilterScreen *fs = GET_FILTER_SCREEN (s, GET_FILTER_DISPLAY (s->display))
 
101
#define FILTER_SCREEN(s)                                    \
 
102
    ScaleFilterScreen *fs = GET_FILTER_SCREEN (s,           \
 
103
                            GET_FILTER_DISPLAY (s->display))
101
104
 
102
105
static void
103
106
scalefilterFreeFilterText (CompScreen *s)
129
132
    char           buffer[2 * MAX_FILTER_STRING_LEN];
130
133
 
131
134
    FILTER_SCREEN (s);
 
135
    FILTER_DISPLAY (s->display);
132
136
 
133
137
    if (!fs->filterInfo)
134
138
        return;
160
164
    if (fs->filterInfo->filterStringLength == 0)
161
165
        return;
162
166
 
163
 
    tA.maxwidth = x2 - x1 - (2 * scalefilterGetBorderSize (s));
164
 
    tA.maxheight = y2 - y1 - (2 * scalefilterGetBorderSize (s));
 
167
    if (!fd->textAvailable)
 
168
        return;
 
169
 
 
170
    tA.maxWidth = x2 - x1 - (2 * scalefilterGetBorderSize (s));
 
171
    tA.maxHeight = y2 - y1 - (2 * scalefilterGetBorderSize (s));
165
172
    tA.screen = s;
166
173
    tA.size = scalefilterGetFontSize (s);
167
174
    tA.color[0] = scalefilterGetFontColorRed (s);
220
227
{
221
228
    FILTER_SCREEN (s);
222
229
 
223
 
    GLboolean wasBlend;
224
 
    GLint     oldBlendSrc, oldBlendDst;
225
 
    int       ox1, ox2, oy1, oy2;
 
230
    GLboolean  wasBlend;
 
231
    GLint      oldBlendSrc, oldBlendDst;
 
232
    int        k;
 
233
    int        ox1, ox2, oy1, oy2;
 
234
    float      width, height, border;
 
235
    float      x, y;
 
236
    CompMatrix *m;
226
237
 
227
 
    float width = fs->filterInfo->textWidth;
228
 
    float height = fs->filterInfo->textHeight;
229
 
    float border = scalefilterGetBorderSize (s);
 
238
    width = fs->filterInfo->textWidth;
 
239
    height = fs->filterInfo->textHeight;
 
240
    border = scalefilterGetBorderSize (s);
230
241
 
231
242
    ox1 = output->region.extents.x1;
232
243
    ox2 = output->region.extents.x2;
233
244
    oy1 = output->region.extents.y1;
234
245
    oy2 = output->region.extents.y2;
235
 
    float x = ox1 + ((ox2 - ox1) / 2) - (width / 2);
236
 
    float y = oy1 + ((oy2 - oy1) / 2) + (height / 2);
237
246
 
238
 
    x = floor (x);
239
 
    y = floor (y);
 
247
    x = floor (ox1 + ((ox2 - ox1) / 2) - (width / 2));
 
248
    y = floor (oy1 + ((oy2 - oy1) / 2) + (height / 2));
240
249
 
241
250
    wasBlend = glIsEnabled (GL_BLEND);
242
251
    glGetIntegerv (GL_BLEND_SRC, &oldBlendSrc);
265
274
#define CORNER(a,b) \
266
275
    for (k = a; k < b; k++) \
267
276
    {\
268
 
        float rad = k* (3.14159 / 180.0f);\
 
277
        float rad = k * (3.14159 / 180.0f);\
269
278
        glVertex2f (0.0f, 0.0f);\
270
279
        glVertex2f (cos (rad) * border, sin (rad) * border);\
271
280
        glVertex2f (cos ((k - 1) * (3.14159 / 180.0f)) * border, \
273
282
    }
274
283
 
275
284
    /* Rounded corners */
276
 
    int k;
277
 
 
278
285
    glTranslatef (border, border, 0.0f);
279
286
    glBegin (GL_TRIANGLES);
280
287
    CORNER (180, 270) glEnd();
304
311
 
305
312
    enableTexture (s, &fs->filterInfo->textTexture, COMP_TEXTURE_FILTER_GOOD);
306
313
 
307
 
    CompMatrix *m = &fs->filterInfo->textTexture.matrix;
 
314
    m = &fs->filterInfo->textTexture.matrix;
308
315
 
309
316
    glBegin (GL_QUADS);
310
317
 
311
 
    glTexCoord2f (COMP_TEX_COORD_X(m, 0),COMP_TEX_COORD_Y(m ,0));
 
318
    glTexCoord2f (COMP_TEX_COORD_X (m, 0), COMP_TEX_COORD_Y (m ,0));
312
319
    glVertex2f (x, y - height);
313
 
    glTexCoord2f (COMP_TEX_COORD_X(m, 0),COMP_TEX_COORD_Y(m, height));
 
320
    glTexCoord2f (COMP_TEX_COORD_X (m, 0), COMP_TEX_COORD_Y (m, height));
314
321
    glVertex2f (x, y);
315
 
    glTexCoord2f (COMP_TEX_COORD_X(m, width),COMP_TEX_COORD_Y(m, height));
 
322
    glTexCoord2f (COMP_TEX_COORD_X (m, width), COMP_TEX_COORD_Y (m, height));
316
323
    glVertex2f (x + width, y);
317
 
    glTexCoord2f (COMP_TEX_COORD_X(m, width),COMP_TEX_COORD_Y(m, 0));
 
324
    glTexCoord2f (COMP_TEX_COORD_X (m, width), COMP_TEX_COORD_Y (m, 0));
318
325
    glVertex2f (x + width, y - height);
319
326
 
320
327
    glEnd ();
384
391
static void
385
392
scalefilterInitFilterInfo (CompScreen *s)
386
393
{
 
394
    ScaleFilterInfo *info;
 
395
 
387
396
    FILTER_SCREEN (s);
388
397
    SCALE_SCREEN (s);
389
398
 
390
 
    ScaleFilterInfo *info = fs->filterInfo;
391
 
 
 
399
    info = fs->filterInfo;
392
400
    memset (info->filterString, 0, sizeof (info->filterString));
393
401
    info->filterStringLength = 0;
394
402
 
556
564
    /* set the event type invalid if we
557
565
       don't want other plugins see it */
558
566
    if (dropKeyEvent)
559
 
        event->type = LASTEvent+1;
 
567
        event->type = LASTEvent + 1;
560
568
 
561
569
    if (needRelayout)
562
570
    {
603
611
 
604
612
static void
605
613
scalefilterHandleCompizEvent (CompDisplay *d,
606
 
                              char        *pluginName,
607
 
                              char        *eventName,
 
614
                              const char  *pluginName,
 
615
                              const char  *eventName,
608
616
                              CompOption  *option,
609
617
                              int         nOption)
610
618
{
632
640
                matchInit (&fs->scaleMatch);
633
641
                matchCopy (&fs->scaleMatch, ss->currentMatch);
634
642
                matchUpdate (d, &fs->scaleMatch);
635
 
                fs->matchApplied = FALSE;
636
643
            }
637
 
 
638
 
            if (!activated)
 
644
            else if (fs->filterInfo)
639
645
            {
640
 
                if (fs->filterInfo)
641
 
                {
642
 
                    ss->currentMatch = fs->filterInfo->origMatch;
643
 
                    scalefilterFiniFilterInfo (s, TRUE);
644
 
                }
645
 
                fs->matchApplied = FALSE;
 
646
                ss->currentMatch = fs->filterInfo->origMatch;
 
647
                scalefilterFiniFilterInfo (s, TRUE);
646
648
            }
 
649
 
 
650
            fs->matchApplied = FALSE;
647
651
        }
648
652
    }
649
653
}
738
742
 
739
743
static Bool
740
744
scalefilterInitDisplay (CompPlugin  *p,
741
 
                        CompDisplay *d)
 
745
                        CompDisplay *d)
742
746
{
743
747
    ScaleFilterDisplay *fd;
744
 
    CompPlugin         *scale = findActivePlugin ("scale");
745
 
    CompOption         *option;
746
 
    int                nOption;
747
 
 
748
 
    if (!scale || !scale->vTable->getDisplayOptions)
749
 
        return FALSE;
750
 
 
751
 
    option = (*scale->vTable->getDisplayOptions) (scale, d, &nOption);
752
 
 
753
 
    if (getIntOptionNamed (option, nOption, "abi", 0) != SCALE_ABIVERSION)
754
 
    {
755
 
        compLogMessage (d, "scalefilter", CompLogLevelError,
756
 
                        "scale ABI version mismatch");
757
 
        return FALSE;
758
 
    }
759
 
 
760
 
    scaleDisplayPrivateIndex = getIntOptionNamed (option, nOption, "index", -1);
761
 
    if (scaleDisplayPrivateIndex < 0)
 
748
 
 
749
    if (!checkPluginABI ("core", CORE_ABIVERSION))
 
750
        return FALSE;
 
751
 
 
752
    if (!checkPluginABI ("scale", SCALE_ABIVERSION))
 
753
        return FALSE;
 
754
 
 
755
    if (!getPluginDisplayIndex (d, "scale", &scaleDisplayPrivateIndex))
762
756
        return FALSE;
763
757
 
764
758
    fd = malloc (sizeof (ScaleFilterDisplay));
785
779
    if (fd->xic)
786
780
        setlocale (LC_CTYPE, "");
787
781
 
 
782
    fd->textAvailable = checkPluginABI ("text", TEXT_ABIVERSION);
 
783
    if (!fd->textAvailable)
 
784
        compLogMessage (d, "scalefilter", CompLogLevelWarn,
 
785
                        "No compatible text plugin found.");
 
786
 
788
787
    WRAP (fd, d, handleEvent, scalefilterHandleEvent);
789
788
    WRAP (fd, d, handleCompizEvent, scalefilterHandleCompizEvent);
790
789
 
791
 
    d->privates[displayPrivateIndex].ptr = fd;
 
790
    d->base.privates[displayPrivateIndex].ptr = fd;
792
791
 
793
792
    return TRUE;
794
793
}
814
813
 
815
814
static Bool
816
815
scalefilterInitScreen (CompPlugin *p,
817
 
                       CompScreen *s)
 
816
                       CompScreen *s)
818
817
{
819
818
    ScaleFilterScreen *fs;
820
819
 
838
837
    scalefilterSetFontColorNotify (s, scalefilterScreenOptionChanged);
839
838
    scalefilterSetBackColorNotify (s, scalefilterScreenOptionChanged);
840
839
 
841
 
    s->privates[fd->screenPrivateIndex].ptr = fs;
 
840
    s->base.privates[fd->screenPrivateIndex].ptr = fs;
842
841
 
843
842
    return TRUE;
844
843
}
845
844
 
846
845
static void
847
846
scalefilterFiniScreen (CompPlugin *p,
848
 
                       CompScreen *s)
 
847
                       CompScreen *s)
849
848
{
850
849
    FILTER_SCREEN (s);
851
850
    SCALE_SCREEN (s);
862
861
    free (fs);
863
862
}
864
863
 
 
864
static CompBool
 
865
scalefilterInitObject (CompPlugin *p,
 
866
                       CompObject *o)
 
867
{
 
868
    static InitPluginObjectProc dispTab[] = {
 
869
        (InitPluginObjectProc) 0, /* InitCore */
 
870
        (InitPluginObjectProc) scalefilterInitDisplay,
 
871
        (InitPluginObjectProc) scalefilterInitScreen
 
872
    };
 
873
 
 
874
    RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o));
 
875
}
 
876
 
 
877
static void
 
878
scalefilterFiniObject (CompPlugin *p,
 
879
                       CompObject *o)
 
880
{
 
881
    static FiniPluginObjectProc dispTab[] = {
 
882
        (FiniPluginObjectProc) 0, /* FiniCore */
 
883
        (FiniPluginObjectProc) scalefilterFiniDisplay,
 
884
        (FiniPluginObjectProc) scalefilterFiniScreen
 
885
    };
 
886
 
 
887
    DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o));
 
888
}
 
889
 
865
890
static Bool
866
891
scalefilterInit (CompPlugin *p)
867
892
{
878
903
    freeDisplayPrivateIndex (displayPrivateIndex);
879
904
}
880
905
 
881
 
static int
882
 
scalefilterGetVersion (CompPlugin *plugin,
883
 
                       int       version)
884
 
{
885
 
    return ABIVERSION;
886
 
}
887
 
 
888
906
CompPluginVTable scalefilterVTable = {
889
907
    "scalefilter",
890
 
    scalefilterGetVersion,
891
908
    0,
892
909
    scalefilterInit,
893
910
    scalefilterFini,
894
 
    scalefilterInitDisplay,
895
 
    scalefilterFiniDisplay,
896
 
    scalefilterInitScreen,
897
 
    scalefilterFiniScreen,
898
 
    0,
899
 
    0,
900
 
    0,
901
 
    0,
 
911
    scalefilterInitObject,
 
912
    scalefilterFiniObject,
902
913
    0,
903
914
    0
904
915
};