summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <smspillaz@XPS-FEDORA.(none)>2009-07-28 21:44:08 +0800
committerSam Spilsbury <smspillaz@XPS-FEDORA.(none)>2009-07-28 21:44:08 +0800
commit1203709daaaba3a0da330d607e8e07a1ce878dd1 (patch)
tree54fa44d80fe62c54909381d4eae636a4582e7e72
parentc52bfb373c28635529ce147b50fce2f59b34c306 (diff)
downloadautoresize-1203709daaaba3a0da330d607e8e07a1ce878dd1.tar.gz
autoresize-1203709daaaba3a0da330d607e8e07a1ce878dd1.tar.bz2
Intial commit
-rw-r--r--CMakeLists.txt2
-rw-r--r--snap.xml.in98
-rw-r--r--src/snap.cpp831
-rw-r--r--src/snap.h168
4 files changed, 1 insertions, 1098 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fe951ba..fed9360 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,4 +2,4 @@ find_package (Compiz REQUIRED)
include (CompizPlugin)
-compiz_plugin (snap)
+compiz_plugin (autoresize)
diff --git a/snap.xml.in b/snap.xml.in
deleted file mode 100644
index 382740a..0000000
--- a/snap.xml.in
+++ /dev/null
@@ -1,98 +0,0 @@
-<?xml version="1.0"?>
-<compiz>
- <plugin name="snap" useBcop="true">
- <_short>Snapping Windows</_short>
- <_long>Enables windows edges resistance</_long>
- <category>Window Management</category>
- <feature>edgeresistance</feature>
- <deps>
- <relation type="after">
- <plugin>decoration</plugin>
- </relation>
- </deps>
- <options>
- <group>
- <_short>Bindings</_short>
- <option name="avoid_snap" type="list">
- <_short>Avoid Snap Modifier</_short>
- <_long>Use these bindings to avoid snapping.</_long>
- <type>int</type>
- <min>0</min>
- <max>3</max>
- <default>
- <value>0</value>
- </default>
- <desc>
- <value>0</value>
- <_name>Shift</_name>
- </desc>
- <desc>
- <value>1</value>
- <_name>Alt</_name>
- </desc>
- <desc>
- <value>2</value>
- <_name>Control</_name>
- </desc>
- <desc>
- <value>3</value>
- <_name>Meta</_name>
- </desc>
- </option>
- </group>
- <group>
- <_short>Behaviour</_short>
- <option name="snap_type" type="list">
- <_short>Snap Type</_short>
- <_long>Choose 'Resistance', 'Attraction' or 'Full Mode'.</_long>
- <type>int</type>
- <min>0</min>
- <max>1</max>
- <default>
- <value>0</value>
- </default>
- <desc>
- <value>0</value>
- <_name>Edge resistance</_name>
- </desc>
- <desc>
- <value>1</value>
- <_name>Edge attraction</_name>
- </desc>
- </option>
- <option name="edges_categories" type="list">
- <_short>Edges</_short>
- <_long>Snap to 'Screen Edges', 'Windows Edges' or 'Both'.</_long>
- <type>int</type>
- <min>0</min>
- <max>1</max>
- <default>
- <value>0</value>
- </default>
- <desc>
- <value>0</value>
- <_name>Screen edges</_name>
- </desc>
- <desc>
- <value>1</value>
- <_name>Window edges</_name>
- </desc>
- </option>
- <option name="resistance_distance" type="int">
- <_short>Edge Resistance Distance</_short>
- <_long>The distance until edge resistance takes place.</_long>
- <default>30</default>
- <min>1</min>
- <max>100</max>
- </option>
- <option name="attraction_distance" type="int">
- <_short>Edge Attraction Distance</_short>
- <_long>The distance until edge attraction takes place.</_long>
- <default>20</default>
- <min>1</min>
- <max>100</max>
- </option>
- </group>
- </options>
- </plugin>
-</compiz>
diff --git a/src/snap.cpp b/src/snap.cpp
deleted file mode 100644
index 83375b6..0000000
--- a/src/snap.cpp
+++ /dev/null
@@ -1,831 +0,0 @@
-/*
- * Compiz snap plugin
- * Author : Guillaume "iXce" Seguin
- * Email : ixce@beryl-project.org
- *
- * Ported to compiz by : Patrick "marex" Niklaus
- * Email : marex@beryl-project.org
- *
- * Ported to C++ by : Travis Watkins
- * Email : amaranth@ubuntu.com
- *
- * Copyright (C) 2009 Guillaume Seguin
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/*
- * TODO
- * - Apply Edge Resistance to resize
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "snap.h"
-
-
-COMPIZ_PLUGIN_20090315 (snap, SnapPluginVTable);
-
-// helper functions
-
-/*
- * Wrapper functions to avoid infinite notify loops
- */
-void
-SnapWindow::move (int dx, int dy)
-{
- skipNotify = true;
- window->move (dx, dy, true);
- screen->warpPointer (dx, dy);
- skipNotify = false;
-}
-
-void
-SnapWindow::resize (int dx, int dy, int dwidth, int dheight)
-{
- CompWindow::Geometry geometry = window->geometry ();
- skipNotify = true;
- window->resize (geometry.x () + dx, geometry.y () + dy,
- geometry.width () + dwidth, geometry.height () + dheight,
- geometry.border ());
- skipNotify = false;
-}
-
-void
-SnapWindow::addEdge (Window id,
- int position,
- int start,
- int end,
- EdgeType type,
- bool screenEdge)
-{
- Edge edge;
-
- edge.position = position;
- edge.start = start;
- edge.end = end;
- edge.type = type;
- edge.screenEdge = screenEdge;
- edge.snapped = false;
- edge.passed = false;
- edge.id = id;
-
- edges.push_back (edge);
-}
-
-/*
- * Add an edge for each rectangle of the region
- */
-void
-SnapWindow::addRegionEdges (Edge *parent, CompRegion region)
-{
- int position, start, end;
-
- foreach (const CompRect &r, region.rects ())
- {
- switch (parent->type)
- {
- case LeftEdge:
- case RightEdge:
- position = r.x1 ();
- start = r.y1 ();
- end = r.y2 ();
- break;
- case TopEdge:
- case BottomEdge:
- default:
- position = r.y1 ();
- start = r.x1 ();
- end = r.x2 ();
- }
-
- addEdge (parent->id, position, start, end,
- parent->type, parent->screenEdge);
- edges.back ().passed = parent->passed;
- }
-}
-
-/* Checks if a window is considered a snap window. If it's
- * not visible, returns false. If it's a panel and we're
- * snapping to screen edges, it's considered a snap-window.
- */
-
-#define UNLIKELY(x) __builtin_expect(!!(x),0)
-
-static inline bool
-isSnapWindow (CompWindow *w)
-{
- SNAP_SCREEN (screen);
-
- if (UNLIKELY(!w))
- return false;
- if (!w->isViewable ())
- return false;
- if ((w->type () & SNAP_WINDOW_TYPE) &&
- (ss->optionGetEdgesCategoriesMask () & EdgesCategoriesWindowEdgesMask))
- return true;
- if (w->struts () &&
- (ss->optionGetEdgesCategoriesMask () & EdgesCategoriesScreenEdgesMask))
- return true;
- return false;
-}
-
-// Edges update functions ------------------------------------------------------
-/*
- * Detect visible windows edges
- */
-void
-SnapWindow::updateWindowsEdges ()
-{
- CompRegion edgeRegion, resultRegion;
- CompRect input;
- bool remove = false;
-
- // First add all the windows
- foreach (CompWindow *w, screen->windows ())
- {
-
- // Just check that we're not trying to snap to current window,
- // that the window is not invisible and of a valid type
- if (w == window || !isSnapWindow (w))
- {
- continue;
- }
-
- input = w->inputRect ();
- addEdge (w->id (), input.top (), input.left (),
- input.right (), TopEdge, false);
- addEdge (w->id (), input.bottom (), input.left (),
- input.right (), BottomEdge, false);
- addEdge (w->id (), input.left (), input.top (),
- input.bottom (), LeftEdge, false);
- addEdge (w->id (), input.right (), input.top (),
- input.bottom (), RightEdge, false);
- }
-
- // Now strip invisible edges
- // Loop through all the windows stack, and through all the edges
- // If an edge has been passed, check if it's in the region window,
- // if the edge is fully under the window, drop it, or if it's only
- // partly covered, cut it/split it in one/two smaller visible edges
- foreach (CompWindow *w, screen->windows ())
- {
- if (w == window || !isSnapWindow (w))
- continue;
-
- // can't use foreach here because we need the iterator for erase()
- for (std::list<Edge>::iterator it = edges.begin (); it != edges.end (); )
- {
- Edge *e = &*it;
- CompRect rect;
-
- if (!e->passed)
- {
- if (e->id == w->id ())
- e->passed = true;
- it++;
- continue;
- }
-
- switch (e->type)
- {
- case LeftEdge:
- case RightEdge:
- rect.setGeometry (e->position,
- e->start,
- 1,
- e->end - e->start);
- break;
- case TopEdge:
- case BottomEdge:
- default:
- rect.setGeometry (e->start,
- e->position,
- e->end - e->start,
- 1);
- }
-
- // If the edge is in the window region, remove it,
- // if it's partly in the region, split it
- edgeRegion = CompRegion (rect);
- resultRegion = edgeRegion - w->region ();
- if (resultRegion.isEmpty ())
- {
- remove = true;
- }
- else if (edgeRegion != resultRegion)
- {
- addRegionEdges (e, resultRegion);
- remove = true;
- }
-
- if (remove)
- {
- it = edges.erase (it);
- remove = false;
- }
- else
- {
- it++;
- }
- }
- }
-}
-
-/*
- * Loop on outputDevs and add the extents as edges
- * Note that left side is a right edge, right side a left edge,
- * top side a bottom edge and bottom side a top edge,
- * since they will be snapped as the right/left/bottom/top edge of a window
- */
-void
-SnapWindow::updateScreenEdges ()
-{
- CompRegion edgeRegion, resultRegion;
- bool remove = false;
-
- foreach (CompOutput output, screen->outputDevs ())
- {
- const CompRect& area = output.workArea ();
- addEdge (0, area.top (), area.left (), area.right () - 1,
- BottomEdge, true);
- addEdge (0, area.bottom (), area.left (), area.right () - 1,
- TopEdge, true);
- addEdge (0, area.left (), area.top (), area.bottom () - 1,
- RightEdge, true);
- addEdge (0, area.right (), area.top (), area.bottom () - 1,
- LeftEdge, true);
- }
-
- // Drop screen edges parts that are under struts, basically apply the
- // same strategy than for windows edges visibility
- foreach (CompWindow *w, screen->windows ())
- {
- if (w == window || !w->struts ())
- continue;
-
- for (std::list<Edge>::iterator it = edges.begin (); it != edges.end ();)
- {
- Edge *e = &*it;
- CompRect rect;
-
- if (!e->screenEdge)
- {
- it++;
- continue;
- }
-
- switch (e->type)
- {
- case LeftEdge:
- case RightEdge:
- rect.setGeometry (e->position,
- e->start,
- 1,
- e->end - e->start);
- break;
- case TopEdge:
- case BottomEdge:
- default:
- rect.setGeometry (e->start,
- e->position,
- e->end - e->start,
- 1);
- }
-
- edgeRegion = CompRegion (rect);
- resultRegion = edgeRegion - w->region ();
- if (resultRegion.isEmpty ())
- {
- remove = true;
- }
- else if (edgeRegion != resultRegion)
- {
- addRegionEdges (e, resultRegion);
- remove = true;
- }
-
- if (remove)
- {
- it = edges.erase (it);
- remove = false;
- }
- else
- {
- it++;
- }
- }
- }
-}
-
-/*
- * Clean edges and fill it again with appropriate edges
- */
-void
-SnapWindow::updateEdges ()
-{
- SNAP_SCREEN (screen);
-
- edges.clear ();
- updateWindowsEdges ();
-
- if (ss->optionGetEdgesCategoriesMask () & EdgesCategoriesScreenEdgesMask)
- updateScreenEdges ();
-}
-
-// Edges checking functions (move) ---------------------------------------------
-
-/*
- * Find nearest edge in the direction set by "type",
- * w is the grabbed window, position/start/end are the window edges coordinates
- * before : if true the window has to be before the edge (top/left being origin)
- * snapDirection : just an helper, related to type
- */
-void
-SnapWindow::moveCheckNearestEdge (int position,
- int start,
- int end,
- bool before,
- EdgeType type,
- int snapDirection)
-{
- SNAP_SCREEN (screen);
-
- Edge *edge = &edges.front ();
- int dist, min = 65535;
-
- foreach (Edge &current, edges)
- {
- // Skip wrong type or outbound edges
- if (current.type != type || current.end < start || current.start > end)
- continue;
-
- // Compute distance
- dist = before ? position - current.position : current.position - position;
- // Update minimum distance if needed
- if (dist < min && dist >= 0)
- {
- min = dist;
- edge = &current;
- }
- // 0-dist edge, just break
- if (dist == 0)
- break;
- // Unsnap edges that aren't snapped anymore
- if (current.snapped && dist > ss->optionGetResistanceDistance ())
- current.snapped = false;
- }
- // We found a 0-dist edge, or we have a snapping candidate
- if (min == 0 || (min <= ss->optionGetAttractionDistance ()
- && ss->optionGetSnapTypeMask () & SnapTypeEdgeAttractionMask))
- {
- // Update snapping data
- if (ss->optionGetSnapTypeMask () & SnapTypeEdgeResistanceMask)
- {
- snapped = true;
- this->snapDirection |= snapDirection;
- }
- // Attract the window if needed, moving it of the correct dist
- if (min != 0 && !edge->snapped)
- {
- edge->snapped = true;
- switch (type)
- {
- case LeftEdge:
- move (min, 0);
- break;
- case RightEdge:
- move (-min, 0);
- break;
- case TopEdge:
- move (0, min);
- break;
- case BottomEdge:
- move (0, -min);
- break;
- default:
- break;
- }
- }
- }
-}
-
-/*
- * Call the previous function for each of the 4 sides of the window
- */
-void
-SnapWindow::moveCheckEdges ()
-{
- CompRect input (window->inputRect ());
- moveCheckNearestEdge (input.left (), input.top (), input.bottom (),
- true, RightEdge, HorizontalSnap);
- moveCheckNearestEdge (input.right (), input.top (), input.bottom (),
- false, LeftEdge, HorizontalSnap);
- moveCheckNearestEdge (input.top (), input.left (), input.right (),
- true, BottomEdge, VerticalSnap);
- moveCheckNearestEdge (input.bottom (), input.left (), input.right (),
- false, TopEdge, VerticalSnap);
-}
-
-// Edges checking functions (resize) -------------------------------------------
-
-/*
- * Similar function for Snap on Resize
- */
-void
-SnapWindow::resizeCheckNearestEdge (int position,
- int start,
- int end,
- bool before,
- EdgeType type,
- int snapDirection)
-{
- SNAP_SCREEN (screen);
-
- Edge *edge = &edges.front ();
- int dist, min = 65535;
-
- foreach (Edge &current, edges)
- {
- // Skip wrong type or outbound edges
- if (current.type != type || current.end < start || current.start > end)
- continue;
-
- // Compute distance
- dist = before ? position - current.position : current.position - position;
- // Update minimum distance if needed
- if (dist < min && dist >= 0)
- {
- min = dist;
- edge = &current;
- }
- // 0-dist edge, just break
- if (dist == 0)
- break;
- // Unsnap edges that aren't snapped anymore
- if (current.snapped && dist > ss->optionGetResistanceDistance ())
- current.snapped = false;
- }
- // We found a 0-dist edge, or we have a snapping candidate
- if (min == 0 || (min <= ss->optionGetAttractionDistance ()
- && ss->optionGetSnapTypeMask () & SnapTypeEdgeAttractionMask))
- {
- // Update snapping data
- if (ss->optionGetSnapTypeMask () & SnapTypeEdgeResistanceMask)
- {
- snapped = true;
- this->snapDirection |= snapDirection;
- }
- // FIXME : this needs resize-specific code.
- // Attract the window if needed, moving it of the correct dist
- if (min != 0 && !edge->snapped)
- {
- edge->snapped = true;
- switch (type)
- {
- case LeftEdge:
- resize (min, 0, 0, 0);
- break;
- case RightEdge:
- resize (-min, 0, 0, 0);
- break;
- case TopEdge:
- resize (0, min, 0, 0);
- break;
- case BottomEdge:
- resize (0, -min, 0, 0);
- break;
- default:
- break;
- }
- }
- }
-}
-
-/*
- * Call the previous function for each of the 4 sides of the window
- */
-void
-SnapWindow::resizeCheckEdges (int dx, int dy, int dwidth, int dheight)
-{
- CompRect input (window->inputRect ());
-
- resizeCheckNearestEdge (input.left (), input.top (), input.bottom (),
- true, RightEdge, HorizontalSnap);
- resizeCheckNearestEdge (input.right (), input.top (), input.bottom (),
- false, LeftEdge, HorizontalSnap);
- resizeCheckNearestEdge (input.top (), input.left (), input.right (),
- true, BottomEdge, VerticalSnap);
- resizeCheckNearestEdge (input.bottom (), input.left (), input.right (),
- false, TopEdge, VerticalSnap);
-}
-
-// Check if avoidSnap is matched, and enable/disable snap consequently
-void
-SnapScreen::handleEvent (XEvent *event)
-{
- if (event->type == screen->xkbEvent ())
- {
- XkbAnyEvent *xkbEvent = (XkbAnyEvent *) event;
-
- if (xkbEvent->xkb_type == XkbStateNotify)
- {
- XkbStateNotifyEvent *stateEvent = (XkbStateNotifyEvent *) event;
-
- unsigned int mods = 0xffffffff;
- if (avoidSnapMask)
- mods = avoidSnapMask;
-
- if ((stateEvent->mods & mods) == mods)
- snapping = false;
- else
- snapping = true;
- }
- }
-
- screen->handleEvent (event);
-}
-
-// Events notifications --------------------------------------------------------
-
-void
-SnapWindow::resizeNotify (int dx, int dy, int dwidth, int dheight)
-{
- SNAP_SCREEN (screen);
-
- window->resizeNotify (dx, dy, dwidth, dheight);
-
- // avoid-infinite-notify-loop mode/not grabbed
- if (skipNotify || !(grabbed & ResizeGrab))
- return;
-
- // we have to avoid snapping but there's still some buffered moving
- if (!ss->snapping && (m_dx || m_dy || m_dwidth || m_dheight))
- {
- resize (m_dx, m_dy, m_dwidth, m_dheight);
- m_dx = m_dy = m_dwidth = m_dheight = 0;
- return;
- }
-
- // avoiding snap, nothing buffered
- if (!ss->snapping)
- return;
-
- // apply edge resistance
- if (ss->optionGetSnapTypeMask () & SnapTypeEdgeResistanceMask)
- {
- // If there's horizontal snapping, add dx to current buffered
- // dx and resist (move by -dx) or release the window and move
- // by buffered dx - dx, same for dh
- if (snapped && snapDirection & HorizontalSnap)
- {
- m_dx += dx;
- if (m_dx < ss->optionGetResistanceDistance ()
- && m_dx > -ss->optionGetResistanceDistance ())
- {
- resize (-dx, 0, 0, 0);
- }
- else
- {
- resize (m_dx - dx, 0, 0, 0);
- m_dx = 0;
- if (!m_dwidth)
- snapDirection &= VerticalSnap;
- }
- m_dwidth += dwidth;
- if (m_dwidth < ss->optionGetResistanceDistance ()
- && m_dwidth > -ss->optionGetResistanceDistance ())
- {
- resize (0, 0, -dwidth, 0);
- }
- else
- {
- resize (0, 0, m_dwidth - dwidth, 0);
- m_dwidth = 0;
- if (!m_dx)
- snapDirection &= VerticalSnap;
- }
- }
-
- // Same for vertical snapping and dy/dh
- if (snapped && snapDirection & VerticalSnap)
- {
- m_dy += dy;
- if (m_dy < ss->optionGetResistanceDistance ()
- && m_dy > -ss->optionGetResistanceDistance ())
- {
- resize (0, -dy, 0, 0);
- }
- else
- {
- resize (0, m_dy - dy, 0, 0);
- m_dy = 0;
- if (!m_dheight)
- snapDirection &= HorizontalSnap;
- }
- m_dheight += dheight;
- if (m_dheight < ss->optionGetResistanceDistance ()
- && m_dheight > -ss->optionGetResistanceDistance ())
- {
- resize (0, 0, 0, -dheight);
- }
- else
- {
- resize (0, 0, 0, m_dheight - dheight);
- m_dheight = 0;
- if (!m_dy)
- snapDirection &= HorizontalSnap;
- }
- }
- // If we are no longer snapping in any direction, reset snapped
- if (snapped && !snapDirection)
- snapped = false;
- }
-
- // If we don't already snap vertically and horizontally,
- // check edges status
- if (snapDirection != (VerticalSnap | HorizontalSnap))
- resizeCheckEdges (dx, dy, dwidth, dheight);
-}
-
-void
-SnapWindow::moveNotify (int dx, int dy, bool immediate)
-{
- SNAP_SCREEN (screen);
-
- window->moveNotify (dx, dy, immediate);
-
- // avoid-infinite-notify-loop mode/not grabbed
- if (skipNotify || !(grabbed & MoveGrab))
- return;
-
- // we have to avoid snapping but there's still some buffered moving
- if (!ss->snapping && (m_dx || m_dy))
- {
- move (m_dx, m_dy);
- m_dx = m_dy = 0;
- return;
- }
-
- // avoiding snap, nothing buffered
- if (!ss->snapping)
- return;
-
- // apply edge resistance
- if (ss->optionGetSnapTypeMask () & SnapTypeEdgeResistanceMask)
- {
- // If there's horizontal snapping, add dx to current buffered
- // dx and resist (move by -dx) or release the window and move
- // by buffered dx - dx
- if (snapped && snapDirection & HorizontalSnap)
- {
- m_dx += dx;
- if (m_dx < ss->optionGetResistanceDistance ()
- && m_dx > -ss->optionGetResistanceDistance ())
- {
- move (-dx, 0);
- }
- else
- {
- move (m_dx - dx, 0);
- m_dx = 0;
- snapDirection &= VerticalSnap;
- }
- }
- // Same for vertical snapping and dy
- if (snapped && snapDirection & VerticalSnap)
- {
- m_dy += dy;
- if (m_dy < ss->optionGetResistanceDistance ()
- && m_dy > -ss->optionGetResistanceDistance ())
- {
- move (0, -dy);
- }
- else
- {
- move (0, m_dy - dy);
- m_dy = 0;
- snapDirection &= HorizontalSnap;
- }
- }
- // If we are no longer snapping in any direction, reset snapped
- if (snapped && !snapDirection)
- snapped = false;
- }
- // If we don't already snap vertically and horizontally,
- // check edges status
- if (snapDirection != (VerticalSnap | HorizontalSnap))
- moveCheckEdges ();
-}
-
-/*
- * Initiate snap, get edges
- */
-void
-SnapWindow::grabNotify (int x, int y, unsigned int state, unsigned int mask)
-{
- grabbed = (mask & CompWindowGrabResizeMask) ? ResizeGrab : MoveGrab;
- updateEdges ();
-
- window->grabNotify (x, y, state, mask);
-}
-
-/*
- * Clean edges data, reset dx/dy to avoid buggy moves
- * when snap will be triggered again.
- */
-void
-SnapWindow::ungrabNotify ()
-{
- edges.clear ();
-
- snapped = false;
- snapDirection = 0;
- grabbed = 0;
- m_dx = m_dy = m_dwidth = m_dheight = 0;
-
- window->ungrabNotify ();
-}
-
-// Internal stuff --------------------------------------------------------------
-
-void
-SnapScreen::optionChanged (CompOption *opt, SnapOptions::Options num)
-{
- switch (num)
- {
- case SnapOptions::AvoidSnap:
- {
- unsigned int mask = optionGetAvoidSnapMask ();
- avoidSnapMask = 0;
- if (mask & AvoidSnapShiftMask)
- avoidSnapMask |= ShiftMask;
- if (mask & AvoidSnapAltMask)
- avoidSnapMask |= CompAltMask;
- if (mask & AvoidSnapControlMask)
- avoidSnapMask |= ControlMask;
- if (mask & AvoidSnapMetaMask)
- avoidSnapMask |= CompMetaMask;
- }
-
- default:
- break;
- }
-}
-
-SnapScreen::SnapScreen (CompScreen *screen) :
- PluginClassHandler <SnapScreen, CompScreen> (screen),
- SnapOptions (),
- snapping (true),
- avoidSnapMask (0)
-{
- ScreenInterface::setHandler (screen);
-
-#define setNotify(func) \
- optionSet##func##Notify (boost::bind (&SnapScreen::optionChanged, this, _1, _2))
-
- setNotify (AvoidSnap);
-}
-
-SnapWindow::SnapWindow (CompWindow *window) :
- PluginClassHandler <SnapWindow, CompWindow> (window),
- window (window),
- snapDirection (0),
- m_dx (0),
- m_dy (0),
- m_dwidth (0),
- m_dheight (0),
- snapped (false),
- grabbed (0),
- skipNotify (false)
-{
- WindowInterface::setHandler (window);
-}
-
-SnapWindow::~SnapWindow ()
-{
-}
-
-bool
-SnapPluginVTable::init ()
-{
- if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
- return false;
-
- return true;
-}
-
diff --git a/src/snap.h b/src/snap.h
deleted file mode 100644
index cce3de7..0000000
--- a/src/snap.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Compiz snap plugin
- * Author : Guillaume "iXce" Seguin
- * Email : ixce@beryl-project.org
- *
- * Ported to compiz by : Patrick "marex" Niklaus
- * Email : marex@beryl-project.org
- *
- * Ported to C++ by : Travis Watkins
- * Email : amaranth@ubuntu.com
- *
- * Copyright (C) 2009 Guillaume Seguin
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include <vector>
-
-#include <core/core.h>
-#include <core/pluginclasshandler.h>
-
-#include "snap_options.h"
-
-/*
- * The window we should snap too if snapping to windows
- */
-#define SNAP_WINDOW_TYPE (CompWindowTypeNormalMask | \
- CompWindowTypeToolbarMask | \
- CompWindowTypeMenuMask | \
- CompWindowTypeUtilMask)
-
-#define VerticalSnap (1L << 0)
-#define HorizontalSnap (1L << 1)
-
-#define MoveGrab (1L << 0)
-#define ResizeGrab (1L << 1)
-
-typedef enum
-{
- LeftEdge = 0,
- RightEdge,
- TopEdge,
- BottomEdge
-} EdgeType;
-
-/* Custom Edge struct
- * Position, start, end meanings are specific to type :
- * - LeftEdge/RightEdge : position : x, start/end : y1/y2
- * - TopEdge/BottomEdge : position : y, start/end : x1/x2
- * id/passed are used during visibility detection when adding edges
- * snapped is straight forward
- */
-typedef struct
-{
- int position;
- int start;
- int end;
- EdgeType type;
- bool screenEdge;
-
- Window id;
- bool passed;
-
- bool snapped;
-} Edge;
-
-class SnapScreen :
- public ScreenInterface,
- public PluginClassHandler <SnapScreen, CompScreen>,
- public SnapOptions
-{
- public:
- bool snapping;
-
- SnapScreen (CompScreen *s);
-
- void handleEvent (XEvent *event);
- bool enableSnapping (CompAction *action, CompAction::State state,
- CompOption::Vector &options);
- bool disableSnapping (CompAction *action, CompAction::State state,
- CompOption::Vector &options);
- void optionChanged (CompOption *opt, SnapOptions::Options num);
-
- private:
- // used to allow moving windows without snapping
- int avoidSnapMask;
-};
-
-class SnapWindow :
- public WindowInterface,
- public PluginClassHandler <SnapWindow, CompWindow>
-{
- public:
- SnapWindow (CompWindow *window);
- ~SnapWindow ();
-
- void resizeNotify (int dx, int dy, int dwidth, int dheight);
- void moveNotify (int dx, int dy, bool immediate);
- void grabNotify (int x, int y, unsigned int state, unsigned int mask);
- void ungrabNotify ();
-
- private:
- CompWindow *window;
-
- // linked lists
- std::list<Edge> edges;
-
- // bitfield
- int snapDirection;
-
- // dx/dy/dw/dh when a window is resisting to user
- int m_dx;
- int m_dy;
- int m_dwidth;
- int m_dheight;
-
- // internals
- bool snapped;
- int grabbed;
-
- // internal, avoids infinite notify loops
- bool skipNotify;
-
-
- void move (int dx, int dy);
- void resize (int dx, int dy, int dwidth, int dheight);
-
- void addEdge (Window id, int position, int start, int end,
- EdgeType type, bool screenEdge);
- void addRegionEdges (Edge *parent, CompRegion region);
- void updateWindowsEdges ();
- void updateScreenEdges ();
- void updateEdges ();
- void moveCheckNearestEdge (int position, int start, int end,
- bool before, EdgeType type,
- int snapDirection);
- void moveCheckEdges ();
- void resizeCheckNearestEdge (int position, int start, int end,
- bool before, EdgeType type,
- int snapDirection);
- void resizeCheckEdges (int dx, int dy, int dwidth, int dheight);
-};
-
-#define SNAP_SCREEN(s) \
- SnapScreen *ss = SnapScreen::get (s)
-
-#define SNAP_WINDOW(w) \
- SnapWindow *sw = SnapWindow::get (w)
-
-class SnapPluginVTable :
- public CompPlugin::VTableForScreenAndWindow <SnapScreen, SnapWindow>
-{
- public:
- bool init ();
-};
-