]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/frame.h
Merge branch 'work' into wip/mikabox
[mikachu/openbox.git] / openbox / frame.h
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    frame.h for the Openbox window manager
4    Copyright (c) 2006        Mikael Magnusson
5    Copyright (c) 2003-2007   Dana Jansens
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #ifndef __frame_h
21 #define __frame_h
22
23 #include "geom.h"
24 #include "obrender/render.h"
25
26 typedef struct _ObFrame ObFrame;
27
28 struct _ObClient;
29
30 typedef void (*ObFrameIconifyAnimateFunc)(gpointer data);
31
32 typedef enum {
33     OB_FRAME_CONTEXT_NONE,
34     OB_FRAME_CONTEXT_DESKTOP,
35     OB_FRAME_CONTEXT_ROOT,
36     OB_FRAME_CONTEXT_CLIENT,
37     OB_FRAME_CONTEXT_TITLEBAR,
38     OB_FRAME_CONTEXT_FRAME,
39     OB_FRAME_CONTEXT_BLCORNER,
40     OB_FRAME_CONTEXT_BRCORNER,
41     OB_FRAME_CONTEXT_TLCORNER,
42     OB_FRAME_CONTEXT_TRCORNER,
43     OB_FRAME_CONTEXT_TOP,
44     OB_FRAME_CONTEXT_BOTTOM,
45     OB_FRAME_CONTEXT_LEFT,
46     OB_FRAME_CONTEXT_RIGHT,
47     OB_FRAME_CONTEXT_MAXIMIZE,
48     OB_FRAME_CONTEXT_ALLDESKTOPS,
49     OB_FRAME_CONTEXT_SHADE,
50     OB_FRAME_CONTEXT_ICONIFY,
51     OB_FRAME_CONTEXT_ICON,
52     OB_FRAME_CONTEXT_CLOSE,
53     /*! This is a special context, which occurs while dragging a window in
54       a move/resize */
55     OB_FRAME_CONTEXT_MOVE_RESIZE,
56     OB_FRAME_CONTEXT_DOCK,
57     OB_FRAME_CONTEXT_EDGE_TOP,
58     OB_FRAME_CONTEXT_EDGE_TOPRIGHT,
59     OB_FRAME_CONTEXT_EDGE_RIGHT,
60     OB_FRAME_CONTEXT_EDGE_BOTTOMRIGHT,
61     OB_FRAME_CONTEXT_EDGE_BOTTOM,
62     OB_FRAME_CONTEXT_EDGE_BOTTOMLEFT,
63     OB_FRAME_CONTEXT_EDGE_LEFT,
64     OB_FRAME_CONTEXT_EDGE_TOPLEFT,
65     OB_FRAME_NUM_CONTEXTS
66 } ObFrameContext;
67
68 #define FRAME_CONTEXT(co, cl) ((cl && cl->type != OB_CLIENT_TYPE_DESKTOP) ? \
69                                co == OB_FRAME_CONTEXT_FRAME : FALSE)
70 #define CLIENT_CONTEXT(co, cl) ((cl && cl->type == OB_CLIENT_TYPE_DESKTOP) ? \
71                                 co == OB_FRAME_CONTEXT_DESKTOP : \
72                                 co == OB_FRAME_CONTEXT_CLIENT)
73
74 /*! The decorations the client window wants to be displayed on it */
75 typedef enum {
76     OB_FRAME_DECOR_TITLEBAR    = 1 << 0, /*!< Display a titlebar */
77     OB_FRAME_DECOR_HANDLE      = 1 << 1, /*!< Display a handle (bottom) */
78     OB_FRAME_DECOR_GRIPS       = 1 << 2, /*!< Display grips in the handle */
79     OB_FRAME_DECOR_BORDER      = 1 << 3, /*!< Display a border */
80     OB_FRAME_DECOR_ICON        = 1 << 4, /*!< Display the window's icon */
81     OB_FRAME_DECOR_ICONIFY     = 1 << 5, /*!< Display an iconify button */
82     OB_FRAME_DECOR_MAXIMIZE    = 1 << 6, /*!< Display a maximize button */
83     /*! Display a button to toggle the window's placement on
84       all desktops */
85     OB_FRAME_DECOR_ALLDESKTOPS = 1 << 7,
86     OB_FRAME_DECOR_SHADE       = 1 << 8, /*!< Display a shade button */
87     OB_FRAME_DECOR_CLOSE       = 1 << 9  /*!< Display a close button */
88 } ObFrameDecorations;
89
90 struct _ObFrame
91 {
92     struct _ObClient *client;
93
94     Window    window;
95
96     Strut     size;    /* the size of the frame */
97     Strut     oldsize; /* the size of the frame last told to the client */
98     Rect      area;
99     gboolean  visible;
100
101     guint     functions;
102     guint     decorations;
103
104     Window    title;
105     Window    label;
106     Window    max;
107     Window    close;
108     Window    desk;
109     Window    shade;
110     Window    icon;
111     Window    iconify;
112     Window    handle;
113     Window    lgrip;
114     Window    rgrip;
115
116     /* These are borders of the frame and its elements */
117     Window    titleleft;
118     Window    titletop;
119     Window    titletopleft;
120     Window    titletopright;
121     Window    titleright;
122     Window    titlebottom;
123     Window    left;
124     Window    right;
125     Window    handleleft;
126     Window    handletop;
127     Window    handleright;
128     Window    handlebottom;
129     Window    lgriptop;
130     Window    lgripleft;
131     Window    lgripbottom;
132     Window    rgriptop;
133     Window    rgripright;
134     Window    rgripbottom;
135     Window    innerleft;    /*!< For drawing the inner client border */
136     Window    innertop;     /*!< For drawing the inner client border */
137     Window    innerright;   /*!< For drawing the inner client border */
138     Window    innerbottom;  /*!< For drawing the inner client border */
139     Window    innerblb;
140     Window    innerbll;
141     Window    innerbrb;
142     Window    innerbrr;
143     Window    backback;     /*!< A colored window shown while resizing */
144     Window    backfront;    /*!< An undrawn-in window, to prevent flashing on
145                                  unmap */
146
147     /* These are resize handles inside the titlebar */
148     Window    topresize;
149     Window    tltresize;
150     Window    tllresize;
151     Window    trtresize;
152     Window    trrresize;
153
154     Colormap  colormap;
155
156     gint      icon_on;    /* if the window icon button is on */
157     gint      label_on;   /* if the window title is on */
158     gint      iconify_on; /* if the window iconify button is on */
159     gint      desk_on;    /* if the window all-desktops button is on */
160     gint      shade_on;   /* if the window shade button is on */
161     gint      max_on;     /* if the window maximize button is on */
162     gint      close_on;   /* if the window close button is on */
163
164     gint      width;         /* width of the titlebar and handle */
165     gint      label_width;   /* width of the label in the titlebar */
166     gint      icon_x;        /* x-position of the window icon button */
167     gint      label_x;       /* x-position of the window title */
168     gint      iconify_x;     /* x-position of the window iconify button */
169     gint      desk_x;        /* x-position of the window all-desktops button */
170     gint      shade_x;       /* x-position of the window shade button */
171     gint      max_x;         /* x-position of the window maximize button */
172     gint      close_x;       /* x-position of the window close button */
173     gint      bwidth;        /* border width */
174     gint      cbwidth_l;     /* client border width */
175     gint      cbwidth_t;     /* client border width */
176     gint      cbwidth_r;     /* client border width */
177     gint      cbwidth_b;     /* client border width */
178     gboolean  max_horz;      /* when maxed some decorations are hidden */
179     gboolean  max_vert;      /* when maxed some decorations are hidden */
180     gboolean  shaded;        /* decorations adjust when shaded */
181
182     /* the leftmost and rightmost elements in the titlebar */
183     ObFrameContext leftmost;
184     ObFrameContext rightmost;
185
186     gboolean  max_press;
187     gboolean  close_press;
188     gboolean  desk_press;
189     gboolean  shade_press;
190     gboolean  iconify_press;
191     gboolean  max_hover;
192     gboolean  close_hover;
193     gboolean  desk_hover;
194     gboolean  shade_hover;
195     gboolean  iconify_hover;
196
197     gboolean  focused;
198     gboolean  need_render;
199
200     gboolean  flashing;
201     gboolean  flash_on;
202     GTimeVal  flash_end;
203     guint     flash_timer;
204
205     /*! Is the frame currently in an animation for iconify or restore.
206       0 means that it is not animating. > 0 means it is animating an iconify.
207       < 0 means it is animating a restore.
208     */
209     gint iconify_animation_going;
210     guint iconify_animation_timer;
211     GTimeVal  iconify_animation_end;
212 };
213
214 ObFrame *frame_new(struct _ObClient *c);
215 void frame_free(ObFrame *self);
216
217 void frame_show(ObFrame *self);
218 void frame_hide(ObFrame *self);
219 void frame_adjust_theme(ObFrame *self);
220 #ifdef SHAPE
221 void frame_adjust_shape_kind(ObFrame *self, int kind);
222 #endif
223 void frame_adjust_shape(ObFrame *self);
224 void frame_adjust_area(ObFrame *self, gboolean moved,
225                        gboolean resized, gboolean fake);
226 void frame_adjust_client_area(ObFrame *self);
227 void frame_adjust_state(ObFrame *self);
228 void frame_adjust_focus(ObFrame *self, gboolean hilite);
229 void frame_adjust_title(ObFrame *self);
230 void frame_adjust_icon(ObFrame *self);
231 void frame_grab_client(ObFrame *self);
232 void frame_release_client(ObFrame *self);
233
234 ObFrameContext frame_context_from_string(const gchar *name);
235
236 /*! Parses a ObFrameContext from a string of space-separated context names.
237   @names The list of context names, the first of which is removed from the
238          string.
239   @cx The ObFrameContext is returned here.  If an invalid name is found, this
240       is set to OB_FRAME_CONTEXT_NONE.
241   @return TRUE if there was something to read in @names, FALSE if it was an
242           empty input.
243 */
244 gboolean frame_next_context_from_string(gchar *names, ObFrameContext *cx);
245
246 ObFrameContext frame_context(struct _ObClient *self, Window win,
247                              gint x, gint y);
248
249 /*! Applies gravity to the client's position to find where the frame should
250   be positioned.
251   @return The proper coordinates for the frame, based on the client.
252 */
253 void frame_client_gravity(ObFrame *self, gint *x, gint *y);
254
255 /*! Reversly applies gravity to the frame's position to find where the client
256   should be positioned.
257     @return The proper coordinates for the client, based on the frame.
258 */
259 void frame_frame_gravity(ObFrame *self, gint *x, gint *y);
260
261 /*! Convert a rectangle in client coordinates/sizes to what it would be
262   for the frame, given its current decorations sizes */
263 void frame_rect_to_frame(ObFrame *self, Rect *r);
264
265 /*! Convert a rectangle in frame coordinates/sizes to what it would be for the
266   client, given its current decorations sizes */
267 void frame_rect_to_client(ObFrame *self, Rect *r);
268
269 void frame_flash_start(ObFrame *self);
270 void frame_flash_stop(ObFrame *self);
271
272 /*! Start an animation for iconifying or restoring a frame. The callback
273   will be called when the animation finishes. But if another animation is
274   started in the meantime, the callback will never get called. */
275 void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying);
276 void frame_end_iconify_animation(gpointer data);
277
278 #define frame_iconify_animating(f) (f->iconify_animation_going != 0)
279
280 #endif