Back to index

unity  6.0.0
unity-mt-grab-handle-layout.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Canonical Ltd
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 3 as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
00017  */
00018 
00019 #include "unity-mt-grab-handle-layout.h"
00020 #include "unity-mt-grab-handle.h"
00021 
00022 unsigned int
00023 unity::MT::getLayoutForMask (unsigned int state,
00024                              unsigned int actions)
00025 {
00026   unsigned int allHandles = 0;
00027   for (unsigned int i = 0; i < NUM_HANDLES; i++)
00028   {
00029     allHandles |= (1 << i);
00030   }
00031 
00032   struct _skipInfo
00033   {
00034     /* All must match in order for skipping to apply */
00035     unsigned int state; /* Match if in state */
00036     unsigned int notstate; /* Match if not in state */
00037     unsigned int actions; /* Match if in actions */
00038     unsigned int notactions; /* Match if not in actions */
00039     unsigned int allowOnly;
00040   };
00041 
00042   const unsigned int numSkipInfo = 5;
00043   const struct _skipInfo skip[5] =
00044   {
00045     /* Vertically maximized, don't care
00046      * about left or right handles, or
00047      * the movement handle */
00048     {
00049       MaximizedVertMask,
00050       MaximizedHorzMask,
00051       0, static_cast<unsigned int>(~0),
00052       LeftHandle | RightHandle | MiddleHandle
00053     },
00054     /* Horizontally maximized, don't care
00055      * about top or bottom handles, or
00056      * the movement handle */
00057     {
00058       MaximizedHorzMask,
00059       MaximizedVertMask,
00060       0, static_cast<unsigned int>(~0),
00061       TopHandle | BottomHandle | MiddleHandle
00062     },
00063     /* Maximized, don't care about the movement
00064     * handle */
00065     {
00066       MaximizedVertMask | MaximizedHorzMask,
00067       0, 0, static_cast<unsigned int>(~0),
00068       MiddleHandle
00069     },
00070     /* Immovable, don't show move handle */
00071     {
00072       0,
00073       static_cast<unsigned int>(~0),
00074       static_cast<unsigned int>(~0), MoveMask,
00075       TopLeftHandle | TopHandle | TopRightHandle |
00076       LeftHandle | RightHandle |
00077       BottomLeftHandle | BottomHandle | BottomRightHandle
00078     },
00079     /* Not resizable, don't show resize handle */
00080     {
00081       0,
00082       static_cast<unsigned int>(~0),
00083       static_cast<unsigned int>(~0), ResizeMask,
00084       MiddleHandle
00085     },
00086   };
00087 
00088   /* Set the high bit if it was zero */
00089   if (!state)
00090     state |= 0x8000;
00091 
00092   /* Set the high bit if it was zero */
00093   if (!actions)
00094     actions |= 0x8000;
00095 
00096   for (unsigned int j = 0; j < numSkipInfo; j++)
00097   {
00098     const bool exactState = skip[j].state && skip[j].state != static_cast <unsigned int> (~0);
00099     const bool exactActions = skip[j].actions && skip[j].actions != static_cast <unsigned int> (~0);
00100 
00101     bool stateMatch = false;
00102     bool actionMatch = false;
00103 
00104     if (exactState)
00105       stateMatch = (skip[j].state & state) == skip[j].state;
00106     else
00107       stateMatch = skip[j].state & state;
00108 
00109     stateMatch &= !(state & skip[j].notstate);
00110 
00111     if (exactActions)
00112       actionMatch = (skip[j].actions & actions) == skip[j].actions;
00113     else
00114       actionMatch = skip[j].actions & actions;
00115 
00116     actionMatch &= !(actions & skip[j].notactions);
00117 
00118     if (stateMatch || actionMatch)
00119       allHandles &= skip[j].allowOnly;  
00120   }
00121 
00122   return allHandles;
00123 }