~ubuntu-branches/ubuntu/trusty/compiz/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2013-08-22 06:58:07 UTC
  • mto: This revision was merged to the branch mainline in revision 3352.
  • Revision ID: package-import@ubuntu.com-20130822065807-17nlzez0d30y09so
Tags: upstream-0.9.10+13.10.20130822
Import upstream version 0.9.10+13.10.20130822

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Compiz Fusion Freewins plugin
 
3
 *
 
4
 * freewins.cpp
 
5
 *
 
6
 * Copyright (C) 2007  Rodolfo Granata <warlock.cc@gmail.com>
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU General Public License
 
10
 * as published by the Free Software Foundation; either version 2
 
11
 * of the License, or (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * Author(s):
 
19
 * Rodolfo Granata <warlock.cc@gmail.com>
 
20
 * Sam Spilsbury <smspillaz@gmail.com>
 
21
 *
 
22
 * Button binding support and Reset added by:
 
23
 * enigma_0Z <enigma.0ZA@gmail.com>
 
24
 *
 
25
 * Most of the input handling here is based on
 
26
 * the shelf plugin by
 
27
 *        : Kristian Lyngstøl <kristian@bohemians.org>
 
28
 *        : Danny Baumann <maniac@opencompositing.org>
 
29
 *
 
30
 * Description:
 
31
 *
 
32
 * This plugin allows you to freely transform the texture of a window,
 
33
 * whether that be rotation or scaling to make better use of screen space
 
34
 * or just as a toy.
 
35
 *
 
36
 * Todo:
 
37
 *  - Modifier key to rotate on the Z Axis
 
38
 *  - Fully implement an input redirection system by
 
39
 *    finding an inverse matrix, multiplying by it,
 
40
 *    translating to the actual window co-ords and
 
41
 *    XSendEvent() the co-ords to the actual window.
 
42
 *  - Code could be cleaner
 
43
 *  - Add timestep and speed options to animation
 
44
 *  - Add window hover-over info via paintOutput : i.e
 
45
 *    - Resize borders
 
46
 *    - 'Reset' Button
 
47
 *    - 'Scale' Button
 
48
 *    - 'Rotate' Button
 
49
 */
 
50
 
 
51
#include "freewins.h"
 
52
 
 
53
COMPIZ_PLUGIN_20090315 (freewins, FWPluginVTable);
 
54
 
 
55
/* Information on window resize */
 
56
void
 
57
FWWindow::resizeNotify (int dx,
 
58
                        int dy,
 
59
                        int dw,
 
60
                        int dh)
 
61
{
 
62
    calculateInputRect ();
 
63
 
 
64
    int x = WIN_REAL_X(window) + WIN_REAL_W(window)/2.0;
 
65
    int y = WIN_REAL_Y(window) + WIN_REAL_H(window)/2.0;
 
66
 
 
67
    mRadius = sqrt(pow((x - WIN_REAL_X (window)), 2) + pow((y - WIN_REAL_Y (window)), 2));
 
68
 
 
69
    window->resizeNotify (dx, dy, dw, dh);
 
70
}
 
71
 
 
72
void
 
73
FWWindow::moveNotify (int dx,
 
74
                      int dy,
 
75
                      bool immediate)
 
76
{
 
77
    FREEWINS_SCREEN (screen);
 
78
 
 
79
    /* Did we move and IPW and not the actual window? */
 
80
    CompWindow *useWindow = fws->getRealWindow (window);
 
81
 
 
82
    if (useWindow)
 
83
        useWindow->move (dx, dy, fws->optionGetImmediateMoves ());
 
84
    else if (window != fws->mGrabWindow)
 
85
        adjustIPW ();
 
86
 
 
87
    if (!useWindow)
 
88
        useWindow = window;
 
89
 
 
90
    int x = WIN_REAL_X (useWindow) + WIN_REAL_W (useWindow) /2.0;
 
91
    int y = WIN_REAL_Y (useWindow) + WIN_REAL_H (useWindow) /2.0;
 
92
 
 
93
 
 
94
    mRadius = sqrt (pow((x - WIN_REAL_X (useWindow)), 2) + pow ((y - WIN_REAL_Y (useWindow)), 2));
 
95
 
 
96
    useWindow->moveNotify (dx, dy, immediate);
 
97
}
 
98
 
 
99
void
 
100
FWScreen::reloadSnapKeys ()
 
101
{
 
102
    unsigned int imask = optionGetInvertModsMask ();
 
103
    mInvertMask = 0;
 
104
 
 
105
    if (imask & InvertModsShiftMask)
 
106
        mInvertMask |= ShiftMask;
 
107
    if (imask & InvertModsAltMask)
 
108
        mInvertMask |= CompAltMask;
 
109
    if (imask & InvertModsControlMask)
 
110
        mInvertMask |= ControlMask;
 
111
    if (imask & InvertModsMetaMask)
 
112
        mInvertMask |= CompMetaMask;
 
113
 
 
114
    unsigned int smask = optionGetSnapModsMask ();
 
115
    mSnapMask = 0;
 
116
    if (smask & SnapModsShiftMask)
 
117
        mSnapMask |= ShiftMask;
 
118
    if (smask & SnapModsAltMask)
 
119
        mSnapMask |= CompAltMask;
 
120
    if (smask & SnapModsControlMask)
 
121
        mSnapMask |= ControlMask;
 
122
    if (smask & SnapModsMetaMask)
 
123
        mSnapMask |= CompMetaMask;
 
124
}
 
125
 
 
126
void
 
127
FWScreen::optionChanged (CompOption *option,
 
128
                         FreewinsOptions::Options num)
 
129
{
 
130
    switch (num)
 
131
    {
 
132
        case FreewinsOptions::SnapMods:
 
133
        case FreewinsOptions::InvertMods:
 
134
            reloadSnapKeys ();
 
135
            break;
 
136
        default:
 
137
            break;
 
138
    }
 
139
}
 
140
 
 
141
/* ------ Plugin Initialisation ---------------------------------------*/
 
142
 
 
143
/* Window initialisation / cleaning */
 
144
 
 
145
FWWindow::FWWindow (CompWindow *w) :
 
146
    PluginClassHandler <FWWindow, CompWindow> (w),
 
147
    window (w),
 
148
    cWindow (CompositeWindow::get (w)),
 
149
    gWindow (GLWindow::get (w)),
 
150
    mIMidX (WIN_REAL_W (w) / 2.0),
 
151
    mIMidY (WIN_REAL_H (w) / 2.0),
 
152
    mOMidX (0.0f),
 
153
    mOMidY (0.0f),
 
154
    mAdjustX (0.0f),
 
155
    mAdjustY (0.0f),
 
156
    mOldWinX (0),
 
157
    mOldWinY (0),
 
158
    mWinH (0),
 
159
    mWinW (0),
 
160
    mDirection (UpDown),
 
161
    mCorner (CornerTopLeft),
 
162
    mInput (NULL),
 
163
    mOutputRect (w->outputRect ()),
 
164
    mInputRect (w->borderRect ()),
 
165
    mResetting (false),
 
166
    mIsAnimating (false),
 
167
    mCan2D (false),
 
168
    mCan3D (false),
 
169
    mTransformed (false),
 
170
    mGrab (grabNone)
 
171
{
 
172
    WindowInterface::setHandler (window);
 
173
    CompositeWindowInterface::setHandler (cWindow);
 
174
    GLWindowInterface::setHandler (gWindow);
 
175
 
 
176
    int x = WIN_REAL_X (w) + WIN_REAL_W (w) /2.0;
 
177
    int y = WIN_REAL_Y (w) + WIN_REAL_H (w) /2.0;
 
178
 
 
179
    mRadius = sqrt (pow ((x - WIN_REAL_X (w)), 2) + pow ((y - WIN_REAL_Y (w)), 2));
 
180
}
 
181
 
 
182
FWWindow::~FWWindow ()
 
183
{
 
184
    if (canShape ())
 
185
        handleWindowInputInfo ();
 
186
 
 
187
    FREEWINS_SCREEN (screen);
 
188
 
 
189
    if (fws->mGrabWindow == window)
 
190
        fws->mGrabWindow = NULL;
 
191
}
 
192
 
 
193
#define ROTATE_INC optionGetRotateIncrementAmount ()
 
194
#define NEG_ROTATE_INC optionGetRotateIncrementAmount () *-1
 
195
 
 
196
#define SCALE_INC optionGetScaleIncrementAmount ()
 
197
#define NEG_SCALE_INC optionGetScaleIncrementAmount () *-1
 
198
 
 
199
FWScreen::FWScreen (CompScreen *screen) :
 
200
    PluginClassHandler <FWScreen, CompScreen> (screen),
 
201
    cScreen (CompositeScreen::get (screen)),
 
202
    gScreen (GLScreen::get (screen)),
 
203
    mClick_root_x (0),
 
204
    mClick_root_y (0),
 
205
    mGrabWindow (NULL),
 
206
    mHoverWindow (NULL),
 
207
    mLastGrabWindow (NULL),
 
208
    mAxisHelp (false),
 
209
    mSnap (false),
 
210
    mInvert (false),
 
211
    mSnapMask (0),
 
212
    mInvertMask (0),
 
213
    mGrabIndex (0)
 
214
{
 
215
    ScreenInterface::setHandler (screen);
 
216
    CompositeScreenInterface::setHandler (cScreen);
 
217
    GLScreenInterface::setHandler (gScreen);
 
218
 
 
219
    /* TODO: warning about shape! */
 
220
 
 
221
    /* BCOP Action initiation */
 
222
    optionSetInitiateRotationButtonInitiate (boost::bind (&FWScreen::initiateFWRotate, this, _1, _2, _3));
 
223
    optionSetInitiateRotationButtonTerminate (boost::bind (&FWScreen::terminateFWRotate, this, _1, _2, _3));
 
224
    optionSetInitiateScaleButtonInitiate (boost::bind (&FWScreen::initiateFWScale, this, _1, _2, _3));
 
225
    optionSetInitiateScaleButtonTerminate (boost::bind (&FWScreen::terminateFWScale, this, _1, _2, _3));
 
226
    optionSetResetButtonInitiate (boost::bind (&FWScreen::resetFWTransform, this, _1, _2, _3));
 
227
    optionSetResetKeyInitiate (boost::bind (&FWScreen::resetFWTransform, this, _1, _2, _3));
 
228
    optionSetToggleAxisKeyInitiate (boost::bind (&FWScreen::toggleFWAxis, this, _1, _2, _3));
 
229
    
 
230
    // Rotate / Scale Up Down Left Right TODO: rebind these actions on option change
 
231
 
 
232
    optionSetScaleUpButtonInitiate (boost::bind (&FWScreen::scale, this, _1, _2, _3, SCALE_INC));
 
233
    optionSetScaleDownButtonInitiate (boost::bind (&FWScreen::scale, this, _1, _2, _3, NEG_SCALE_INC));
 
234
    optionSetScaleUpKeyInitiate (boost::bind (&FWScreen::scale, this, _1, _2, _3, SCALE_INC));
 
235
    optionSetScaleDownKeyInitiate (boost::bind (&FWScreen::scale, this, _1, _2, _3, NEG_SCALE_INC));
 
236
 
 
237
    optionSetRotateUpKeyInitiate (boost::bind (&FWScreen::rotate, this, _1, _2, _3, 0, ROTATE_INC, 0));
 
238
    optionSetRotateDownKeyInitiate (boost::bind (&FWScreen::rotate, this, _1, _2, _3, 0, NEG_ROTATE_INC, 0));
 
239
    optionSetRotateLeftKeyInitiate (boost::bind (&FWScreen::rotate, this, _1, _2, _3, ROTATE_INC, 0, 0));
 
240
    optionSetRotateRightKeyInitiate (boost::bind (&FWScreen::rotate, this, _1, _2, _3, NEG_ROTATE_INC, 0, 0));
 
241
    optionSetRotateCKeyInitiate (boost::bind (&FWScreen::rotate, this, _1, _2, _3, 0, 0, ROTATE_INC));
 
242
    optionSetRotateCcKeyInitiate (boost::bind (&FWScreen::rotate, this, _1, _2, _3, 0, 0, NEG_ROTATE_INC));
 
243
 
 
244
    optionSetRotateInitiate (boost::bind (&FWScreen::rotateAction, this, _1, _2, _3));
 
245
    optionSetIncrementRotateInitiate (boost::bind (&FWScreen::incrementRotateAction, this, _1, _2, _3));
 
246
    optionSetScaleInitiate (boost::bind (&FWScreen::scaleAction, this, _1, _2, _3));
 
247
 
 
248
    optionSetSnapModsNotify (boost::bind (&FWScreen::optionChanged, this, _1, _2));
 
249
    optionSetInvertModsNotify (boost::bind (&FWScreen::optionChanged, this, _1, _2));
 
250
 
 
251
    reloadSnapKeys ();
 
252
}
 
253
 
 
254
bool
 
255
FWPluginVTable::init ()
 
256
{
 
257
    if (!screen->XShape ())
 
258
    {
 
259
        compLogMessage ("shelf", CompLogLevelError,
 
260
                        "No Shape extension found. IPW Usage not enabled \n");
 
261
    }
 
262
 
 
263
    if (CompPlugin::checkPluginABI ("core", CORE_ABIVERSION)            &&
 
264
        CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI)  &&
 
265
        CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
 
266
        return true;
 
267
 
 
268
    return false;
 
269
}