~unity-team/compiz/plugins-main-trunk.fix_wrong_window_move_expo

« back to all changes in this revision

Viewing changes to snap/src/snap.h

  • Committer: David Barth
  • Date: 2011-03-29 16:36:40 UTC
  • Revision ID: david.barth@canonical.com-20110329163640-fpen5qsoo0lbjode
initial import from compiz-plugins-main_0.9.4git20110322.orig.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Compiz snap plugin
 
3
 * Author : Guillaume "iXce" Seguin
 
4
 * Email  : ixce@beryl-project.org
 
5
 *
 
6
 * Ported to compiz by : Patrick "marex" Niklaus
 
7
 * Email               : marex@beryl-project.org
 
8
 *
 
9
 * Ported to C++ by : Travis Watkins
 
10
 * Email            : amaranth@ubuntu.com
 
11
 *
 
12
 * Copyright (C) 2009 Guillaume Seguin
 
13
 *
 
14
 * This program is free software; you can redistribute it and/or
 
15
 * modify it under the terms of the GNU General Public License
 
16
 * as published by the Free Software Foundation; either version 2
 
17
 * of the License, or (at your option) any later version.
 
18
 *
 
19
 * This program is distributed in the hope that it will be useful,
 
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
 * GNU General Public License for more details.
 
23
 *
 
24
 * You should have received a copy of the GNU General Public License
 
25
 * along with this program; if not, write to the Free Software
 
26
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
27
 */
 
28
 
 
29
#include <vector>
 
30
 
 
31
#include <core/core.h>
 
32
#include <core/pluginclasshandler.h>
 
33
 
 
34
#include "snap_options.h"
 
35
 
 
36
/*
 
37
 * The window we should snap too if snapping to windows
 
38
 */
 
39
#define SNAP_WINDOW_TYPE (CompWindowTypeNormalMask  | \
 
40
                          CompWindowTypeToolbarMask | \
 
41
                          CompWindowTypeMenuMask    | \
 
42
                          CompWindowTypeUtilMask)
 
43
 
 
44
#define VerticalSnap    (1L << 0)
 
45
#define HorizontalSnap  (1L << 1)
 
46
 
 
47
#define MoveGrab                (1L << 0)
 
48
#define ResizeGrab              (1L << 1)
 
49
 
 
50
typedef enum
 
51
{
 
52
    LeftEdge = 0,
 
53
    RightEdge,
 
54
    TopEdge,
 
55
    BottomEdge
 
56
} EdgeType;
 
57
 
 
58
/* Custom Edge struct
 
59
 * Position, start, end meanings are specific to type :
 
60
 *  - LeftEdge/RightEdge : position : x, start/end : y1/y2
 
61
 *  - TopEdge/BottomEdge : position : y, start/end : x1/x2
 
62
 * id/passed are used during visibility detection when adding edges
 
63
 * snapped is straight forward
 
64
 */
 
65
typedef struct
 
66
{
 
67
    int position;
 
68
    int start;
 
69
    int end;
 
70
    EdgeType type;
 
71
    bool screenEdge;
 
72
 
 
73
    Window id;
 
74
    bool passed;
 
75
 
 
76
    bool snapped;
 
77
} Edge;
 
78
 
 
79
class SnapScreen :
 
80
    public ScreenInterface,
 
81
    public PluginClassHandler <SnapScreen, CompScreen>,
 
82
    public SnapOptions
 
83
{
 
84
    public:
 
85
        bool snapping;
 
86
 
 
87
        SnapScreen (CompScreen *s);
 
88
 
 
89
        void handleEvent (XEvent *event);
 
90
        bool enableSnapping (CompAction *action, CompAction::State state,
 
91
                             CompOption::Vector &options);
 
92
        bool disableSnapping (CompAction *action, CompAction::State state,
 
93
                              CompOption::Vector &options);
 
94
        void optionChanged (CompOption *opt, SnapOptions::Options num);
 
95
 
 
96
    private:
 
97
        // used to allow moving windows without snapping
 
98
        int avoidSnapMask;
 
99
};
 
100
 
 
101
class SnapWindow :
 
102
    public WindowInterface,
 
103
    public PluginClassHandler <SnapWindow, CompWindow>
 
104
{
 
105
    public:
 
106
        SnapWindow (CompWindow *window);
 
107
        ~SnapWindow ();
 
108
 
 
109
        void resizeNotify (int dx, int dy, int dwidth, int dheight);
 
110
        void moveNotify (int dx, int dy, bool immediate);
 
111
        void grabNotify (int x, int y, unsigned int state, unsigned int mask);
 
112
        void ungrabNotify ();
 
113
 
 
114
    private:
 
115
        CompWindow *window;
 
116
 
 
117
        // linked lists
 
118
        std::list<Edge> edges;
 
119
 
 
120
        // bitfield
 
121
        int snapDirection;
 
122
 
 
123
        // dx/dy/dw/dh when a window is resisting to user
 
124
        int m_dx;
 
125
        int m_dy;
 
126
        int m_dwidth;
 
127
        int m_dheight;
 
128
 
 
129
        // internals
 
130
        bool snapped;
 
131
        int grabbed;
 
132
 
 
133
        // internal, avoids infinite notify loops
 
134
        bool skipNotify;
 
135
 
 
136
 
 
137
        void move (int dx, int dy);
 
138
        void resize (int dx, int dy, int dwidth, int dheight);
 
139
 
 
140
        void addEdge (Window id, int position, int start, int end,
 
141
                      EdgeType type, bool screenEdge);
 
142
        void addRegionEdges (Edge *parent, CompRegion region);
 
143
        void updateWindowsEdges ();
 
144
        void updateScreenEdges ();
 
145
        void updateEdges ();
 
146
        void moveCheckNearestEdge (int position, int start, int end,
 
147
                                   bool before, EdgeType type,
 
148
                                   int snapDirection);
 
149
        void moveCheckEdges ();
 
150
        void resizeCheckNearestEdge (int position, int start, int end,
 
151
                                     bool before, EdgeType type,
 
152
                                     int snapDirection);
 
153
        void resizeCheckEdges (int dx, int dy, int dwidth, int dheight);
 
154
};
 
155
 
 
156
#define SNAP_SCREEN(s) \
 
157
    SnapScreen *ss = SnapScreen::get (s)
 
158
 
 
159
#define SNAP_WINDOW(w) \
 
160
    SnapWindow *sw = SnapWindow::get (w)
 
161
 
 
162
class SnapPluginVTable :
 
163
    public CompPlugin::VTableForScreenAndWindow <SnapScreen, SnapWindow>
 
164
{
 
165
    public:
 
166
        bool init ();
 
167
};
 
168