boxes.h

Go to the documentation of this file.
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 
00003 /* Simple box operations */
00004 
00005 /* 
00006  * Copyright (C) 2005, 2006 Elijah Newren
00007  * 
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00021  * 02111-1307, USA.
00022  */
00023 
00024 #ifndef META_BOXES_H
00025 #define META_BOXES_H
00026 
00027 #include <glib.h>
00028 #include "common.h"
00029 
00030 typedef struct _MetaRectangle MetaRectangle;
00031 struct _MetaRectangle
00032 {
00033   int x;
00034   int y;
00035   int width;
00036   int height;
00037 };
00038 
00039 typedef struct _MetaStrut MetaStrut;
00040 struct _MetaStrut
00041 {
00042   MetaRectangle rect;
00043   MetaDirection side;
00044 };
00045 
00046 #define BOX_LEFT(box)    ((box).x)                /* Leftmost pixel of rect */
00047 #define BOX_RIGHT(box)   ((box).x + (box).width)  /* One pixel past right   */
00048 #define BOX_TOP(box)     ((box).y)                /* Topmost pixel of rect  */
00049 #define BOX_BOTTOM(box)  ((box).y + (box).height) /* One pixel past bottom  */
00050 
00051 typedef enum
00052 {
00053   FIXED_DIRECTION_NONE = 0,
00054   FIXED_DIRECTION_X    = 1 << 0,
00055   FIXED_DIRECTION_Y    = 1 << 1,
00056 } FixedDirections;
00057 
00058 typedef enum
00059 {
00060   META_EDGE_WINDOW,
00061   META_EDGE_XINERAMA,
00062   META_EDGE_SCREEN
00063 } MetaEdgeType;
00064 
00065 typedef struct _MetaEdge MetaEdge;
00066 struct _MetaEdge
00067 {
00068   MetaRectangle rect;      /* width or height should be 1 */
00069   MetaDirection side_type; /* should only have 1 of the 4 directions set */
00070   MetaEdgeType  edge_type;
00071 };
00072 
00073 /* Output functions -- note that the output buffer had better be big enough:
00074  *   rect_to_string:   RECT_LENGTH
00075  *   region_to_string: (RECT_LENGTH+strlen(separator_string)) *
00076  *                     g_list_length (region)
00077  *   edge_to_string:   EDGE_LENGTH
00078  *   edge_list_to_...: (EDGE_LENGTH+strlen(separator_string)) * 
00079  *                     g_list_length (edge_list)
00080  */
00081 #define RECT_LENGTH 27
00082 #define EDGE_LENGTH 37
00083 char* meta_rectangle_to_string        (const MetaRectangle *rect,
00084                                        char                *output);
00085 char* meta_rectangle_region_to_string (GList               *region,
00086                                        const char          *separator_string,
00087                                        char                *output);
00088 char* meta_rectangle_edge_to_string   (const MetaEdge      *edge,
00089                                        char                *output);
00090 char* meta_rectangle_edge_list_to_string (
00091                                        GList               *edge_list,
00092                                        const char          *separator_string,
00093                                        char                *output);
00094 
00095 /* Function to make initializing a rect with a single line of code easy */
00096 MetaRectangle                 meta_rect (int x, int y, int width, int height);
00097 
00098 /* Basic comparison functions */
00099 int      meta_rectangle_area            (const MetaRectangle *rect);
00100 gboolean meta_rectangle_intersect       (const MetaRectangle *src1,
00101                                          const MetaRectangle *src2,
00102                                          MetaRectangle       *dest);
00103 gboolean meta_rectangle_equal           (const MetaRectangle *src1,
00104                                          const MetaRectangle *src2);
00105 
00106 /* overlap is similar to intersect but doesn't provide location of
00107  * intersection information.
00108  */
00109 gboolean meta_rectangle_overlap         (const MetaRectangle *rect1,
00110                                          const MetaRectangle *rect2);
00111 
00112 /* vert_overlap means ignore the horizontal location and ask if the
00113  * vertical parts overlap.  An alternate way to think of it is "Does there
00114  * exist a way to shift either rect horizontally so that the two rects
00115  * overlap?"  horiz_overlap is similar.
00116  */
00117 gboolean meta_rectangle_vert_overlap    (const MetaRectangle *rect1,
00118                                          const MetaRectangle *rect2);
00119 gboolean meta_rectangle_horiz_overlap   (const MetaRectangle *rect1,
00120                                          const MetaRectangle *rect2);
00121 
00122 /* could_fit_rect determines whether "outer_rect" is big enough to contain
00123  * inner_rect.  contains_rect checks whether it actually contains it.
00124  */
00125 gboolean meta_rectangle_could_fit_rect  (const MetaRectangle *outer_rect,
00126                                          const MetaRectangle *inner_rect);
00127 gboolean meta_rectangle_contains_rect   (const MetaRectangle *outer_rect,
00128                                          const MetaRectangle *inner_rect);
00129 
00130 /* Resize old_rect to the given new_width and new_height, but store the
00131  * result in rect.  NOTE THAT THIS IS RESIZE ONLY SO IT CANNOT BE USED FOR
00132  * A MOVERESIZE OPERATION (that simplies the routine a little bit as it
00133  * means there's no difference between NorthWestGravity and StaticGravity.
00134  * Also, I lied a little bit--technically, you could use it in a MoveResize
00135  * operation if you muck with old_rect just right).
00136  */
00137 void meta_rectangle_resize_with_gravity (const MetaRectangle *old_rect,
00138                                          MetaRectangle       *rect,
00139                                          int                  gravity,
00140                                          int                  new_width,
00141                                          int                  new_height);
00142 
00143 /* find a list of rectangles with the property that a window is contained
00144  * in the given region if and only if it is contained in one of the
00145  * rectangles in the list.
00146  *
00147  * In this case, the region is given by taking basic_rect, removing from
00148  * it the intersections with all the rectangles in the all_struts list,
00149  * then expanding all the rectangles in the resulting list by the given
00150  * amounts on each side.
00151  *
00152  * See boxes.c for more details.
00153  */
00154 GList*   meta_rectangle_get_minimal_spanning_set_for_region (
00155                                          const MetaRectangle *basic_rect,
00156                                          const GSList        *all_struts);
00157 
00158 /* Expand all rectangles in region by the given amount on each side */
00159 GList*   meta_rectangle_expand_region   (GList               *region,
00160                                          const int            left_expand,
00161                                          const int            right_expand,
00162                                          const int            top_expand,
00163                                          const int            bottom_expand);
00164 /* Same as for meta_rectangle_expand_region except that rectangles not at
00165  * least min_x or min_y in size are not expanded in that direction
00166  */
00167 GList*   meta_rectangle_expand_region_conditionally (
00168                                          GList                *region,
00169                                          const int            left_expand,
00170                                          const int            right_expand,
00171                                          const int            top_expand,
00172                                          const int            bottom_expand,
00173                                          const int            min_x,
00174                                          const int            min_y);
00175 
00176 /* Expand rect in direction to the size of expand_to, and then clip out any
00177  * overlapping struts oriented orthognal to the expansion direction.  (Think
00178  * horizontal or vertical maximization)
00179  */
00180 void     meta_rectangle_expand_to_avoiding_struts (
00181                                          MetaRectangle       *rect,
00182                                          const MetaRectangle *expand_to,
00183                                          const MetaDirection  direction,
00184                                          const GSList        *all_struts);
00185 
00186 /* Free the list created by
00187  *   meta_rectangle_get_minimal_spanning_set_for_region()
00188  * or
00189  *   meta_rectangle_find_onscreen_edges ()
00190  * or
00191  *   meta_rectangle_find_nonintersected_xinerama_edges()
00192  */
00193 void     meta_rectangle_free_list_and_elements (GList *filled_list);
00194 
00195 /* could_fit_in_region determines whether one of the spanning_rects is
00196  * big enough to contain rect.  contained_in_region checks whether one
00197  * actually contains it.
00198  */
00199 gboolean meta_rectangle_could_fit_in_region (
00200                                          const GList         *spanning_rects,
00201                                          const MetaRectangle *rect);
00202 gboolean meta_rectangle_contained_in_region (
00203                                          const GList         *spanning_rects,
00204                                          const MetaRectangle *rect);
00205 gboolean meta_rectangle_overlaps_with_region (
00206                                          const GList         *spanning_rects,
00207                                          const MetaRectangle *rect);
00208 
00209 /* Make the rectangle small enough to fit into one of the spanning_rects,
00210  * but make it no smaller than min_size.
00211  */
00212 void     meta_rectangle_clamp_to_fit_into_region (
00213                                          const GList         *spanning_rects,
00214                                          FixedDirections      fixed_directions,
00215                                          MetaRectangle       *rect,
00216                                          const MetaRectangle *min_size);
00217 
00218 /* Clip the rectangle so that it fits into one of the spanning_rects, assuming
00219  * it overlaps with at least one of them
00220  */
00221 void     meta_rectangle_clip_to_region  (const GList         *spanning_rects,
00222                                          FixedDirections      fixed_directions,
00223                                          MetaRectangle       *rect);
00224 
00225 /* Shove the rectangle into one of the spanning_rects, assuming it fits in
00226  * one of them.
00227  */
00228 void     meta_rectangle_shove_into_region(
00229                                          const GList         *spanning_rects,
00230                                          FixedDirections      fixed_directions,
00231                                          MetaRectangle       *rect);
00232 
00233 /* Finds the point on the line connecting (x1,y1) to (x2,y2) which is closest
00234  * to (px, py).  Useful for finding an optimal rectangle size when given a
00235  * range between two sizes that are all candidates.
00236  */
00237 void meta_rectangle_find_linepoint_closest_to_point (double x1,    double y1,
00238                                                      double x2,    double y2,
00239                                                      double px,    double py,
00240                                                      double *valx, double *valy);
00241 
00242 /***************************************************************************/
00243 /*                                                                         */
00244 /* Switching gears to code for edges instead of just rectangles            */
00245 /*                                                                         */
00246 /***************************************************************************/
00247 
00248 /* Return whether an edge overlaps or is adjacent to the rectangle in the
00249  * nonzero-width dimension of the edge.
00250  */
00251 gboolean meta_rectangle_edge_aligns (const MetaRectangle *rect, 
00252                                      const MetaEdge      *edge);
00253 
00254 /* Compare two edges, so that sorting functions can put a list of edges in
00255  * canonical order.
00256  */
00257 gint   meta_rectangle_edge_cmp (gconstpointer a, gconstpointer b);
00258 
00259 /* Compare two edges, so that sorting functions can put a list of edges in
00260  * order.  This function doesn't separate left edges first, then right edges,
00261  * etc., but rather compares only upon location.
00262  */
00263 gint   meta_rectangle_edge_cmp_ignore_type (gconstpointer a, gconstpointer b);
00264 
00265 /* Removes an parts of edges in the given list that intersect any box in the
00266  * given rectangle list.  Returns the result.
00267  */
00268 GList* meta_rectangle_remove_intersections_with_boxes_from_edges (
00269                                            GList *edges,
00270                                            const GSList *rectangles);
00271 
00272 /* Finds all the edges of an onscreen region, returning a GList* of
00273  * MetaEdgeRect's.
00274  */
00275 GList* meta_rectangle_find_onscreen_edges (const MetaRectangle *basic_rect,
00276                                            const GSList        *all_struts);
00277 
00278 /* Finds edges between adjacent xineramas which are not covered by the given
00279  * struts.
00280  */
00281 GList* meta_rectangle_find_nonintersected_xinerama_edges (
00282                                            const GList         *xinerama_rects,
00283                                            const GSList        *all_struts);
00284 
00285 #endif /* META_BOXES_H */

Generated on Sat Aug 23 22:04:18 2008 for metacity by  doxygen 1.5.5