]> icculus.org git repositories - dana/openbox.git/blob - openbox/frame.h
unredirect on a window with bad timing can cause a BadValue error
[dana/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_NUM_CONTEXTS
58 } ObFrameContext;
59
60 #define FRAME_CONTEXT(co, cl) ((cl && cl->type != OB_CLIENT_TYPE_DESKTOP) ? \
61                                co == OB_FRAME_CONTEXT_FRAME : FALSE)
62 #define CLIENT_CONTEXT(co, cl) ((cl && cl->type == OB_CLIENT_TYPE_DESKTOP) ? \
63                                 co == OB_FRAME_CONTEXT_DESKTOP : \
64                                 co == OB_FRAME_CONTEXT_CLIENT)
65
66 /*! The decorations the client window wants to be displayed on it */
67 typedef enum {
68     OB_FRAME_DECOR_TITLEBAR    = 1 << 0, /*!< Display a titlebar */
69     OB_FRAME_DECOR_HANDLE      = 1 << 1, /*!< Display a handle (bottom) */
70     OB_FRAME_DECOR_GRIPS       = 1 << 2, /*!< Display grips in the handle */
71     OB_FRAME_DECOR_BORDER      = 1 << 3, /*!< Display a border */
72     OB_FRAME_DECOR_ICON        = 1 << 4, /*!< Display the window's icon */
73     OB_FRAME_DECOR_ICONIFY     = 1 << 5, /*!< Display an iconify button */
74     OB_FRAME_DECOR_MAXIMIZE    = 1 << 6, /*!< Display a maximize button */
75     /*! Display a button to toggle the window's placement on
76       all desktops */
77     OB_FRAME_DECOR_ALLDESKTOPS = 1 << 7,
78     OB_FRAME_DECOR_SHADE       = 1 << 8, /*!< Display a shade button */
79     OB_FRAME_DECOR_CLOSE       = 1 << 9  /*!< Display a close button */
80 } ObFrameDecorations;
81
82 struct _ObFrame
83 {
84     struct _ObClient *client;
85
86     Window    window;
87     gint      depth;
88
89     /* These are used to prevent flashing when the client window unmaps? */
90     Window    backback;
91     Window    backfront;
92
93     Strut     size;
94     Strut     oldsize; /* the size of the frame last told to the client */
95     Rect      area;
96     gboolean  visible;
97
98     guint     functions;
99     guint     decorations;
100
101     Colormap  colormap;
102
103     /* the leftmost and rightmost elements in the titlebar */
104     ObFrameContext leftmost;
105     ObFrameContext rightmost;
106
107     /* the client menu placement code puts the menu under the titlebar but
108        on top of its bottom border right now,
109        so it needs to know the border width. */
110     gint bwidth;
111     /* the amount of space between the client and the bottom decor (handle) */
112     gint cbwidth_b;
113
114     /* if the frame is showing a maximized/shaded state or not,
115        so the client/frame knows if it needs to be adjusted or not */
116     gboolean max_horz;
117     gboolean max_vert;
118     gboolean shaded;
119
120     gboolean  max_press;
121     gboolean  close_press;
122     gboolean  desk_press;
123     gboolean  shade_press;
124     gboolean  iconify_press;
125     gboolean  max_hover;
126     gboolean  close_hover;
127     gboolean  desk_hover;
128     gboolean  shade_hover;
129     gboolean  iconify_hover;
130
131     gboolean  focused;
132     gboolean  need_render;
133
134     gboolean  flashing;
135     gboolean  flash_on;
136     GTimeVal  flash_end;
137     guint     flash_timer;
138
139     /*! Is the frame currently in an animation for iconify or restore.
140       0 means that it is not animating. > 0 means it is animating an iconify.
141       < 0 means it is animating a restore.
142     */
143     gint iconify_animation_going;
144     guint iconify_animation_timer;
145     GTimeVal  iconify_animation_end;
146 };
147
148 ObFrame *frame_new(struct _ObClient *c);
149 void frame_free(ObFrame *self);
150
151 void frame_show(ObFrame *self);
152 void frame_hide(ObFrame *self);
153 void frame_adjust_theme(ObFrame *self);
154 #ifdef SHAPE
155 void frame_adjust_shape_kind(ObFrame *self, int kind);
156 #endif
157 void frame_adjust_shape(ObFrame *self);
158 void frame_adjust_area(ObFrame *self, gboolean moved,
159                        gboolean resized, gboolean fake);
160 void frame_adjust_client_area(ObFrame *self);
161 void frame_adjust_state(ObFrame *self);
162 void frame_adjust_focus(ObFrame *self, gboolean hilite);
163 void frame_adjust_title(ObFrame *self);
164 void frame_adjust_icon(ObFrame *self);
165 void frame_grab_client(ObFrame *self);
166 void frame_release_client(ObFrame *self);
167
168 ObFrameContext frame_context_from_string(const gchar *name);
169
170 /*! Parses a ObFrameContext from a string of space-separated context names.
171   @names The list of context names, the first of which is removed from the
172          string.
173   @cx The ObFrameContext is returned here.  If an invalid name is found, this
174       is set to OB_FRAME_CONTEXT_NONE.
175   @return TRUE if there was something to read in @names, FALSE if it was an
176           empty input.
177 */
178 gboolean frame_next_context_from_string(gchar *names, ObFrameContext *cx);
179
180 ObFrameContext frame_context(struct _ObClient *self, Window win,
181                              gint x, gint y);
182
183 /*! Applies gravity to the client's position to find where the frame should
184   be positioned.
185   @return The proper coordinates for the frame, based on the client.
186 */
187 void frame_client_gravity(ObFrame *self, gint *x, gint *y);
188
189 /*! Reversly applies gravity to the frame's position to find where the client
190   should be positioned.
191     @return The proper coordinates for the client, based on the frame.
192 */
193 void frame_frame_gravity(ObFrame *self, gint *x, gint *y);
194
195 /*! Convert a rectangle in client coordinates/sizes to what it would be
196   for the frame, given its current decorations sizes */
197 void frame_rect_to_frame(ObFrame *self, Rect *r);
198
199 /*! Convert a rectangle in frame coordinates/sizes to what it would be for the
200   client, given its current decorations sizes */
201 void frame_rect_to_client(ObFrame *self, Rect *r);
202
203 void frame_flash_start(ObFrame *self);
204 void frame_flash_stop(ObFrame *self);
205
206 /*! Start an animation for iconifying or restoring a frame. The callback
207   will be called when the animation finishes. But if another animation is
208   started in the meantime, the callback will never get called. */
209 void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying);
210 void frame_end_iconify_animation(ObFrame *self);
211
212 #define frame_iconify_animating(f) (f->iconify_animation_going != 0)
213
214 #endif