1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 window.c for the Openbox window manager
4 Copyright (c) 2003-2007 Dana Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
20 #include "menuframe.h"
24 #include "unmanaged.h"
25 #include "composite.h"
31 #include "obt/xqueue.h"
33 static GHashTable *window_map;
35 static guint window_hash(Window *w) { return *w; }
36 static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; }
38 void window_startup(gboolean reconfig)
42 window_map = g_hash_table_new((GHashFunc)window_hash,
43 (GEqualFunc)window_comp);
46 void window_shutdown(gboolean reconfig)
50 g_hash_table_destroy(window_map);
53 ObWindow* window_new_size(ObWindowClass type, gsize size)
57 g_assert(size >= sizeof(ObWindow));
58 self = g_slice_alloc0(size);
64 void window_set_abstract(ObWindow *self,
67 const ObStackingLayer *layer,
71 g_assert(!self->top && !self->redir && !self->layer && !self->depth &&
73 #ifdef USE_COMPOSITING
74 g_assert(self->area.width > 0 && self->area.height > 0);
83 /* set up any things in ObWindow that require use of the abstract pointers
87 #ifdef USE_COMPOSITING
88 if (window_redir(self)) {
93 XShapeQueryExtents(obt_display, window_redir(self), &s, &foo,
94 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
96 if (s) window_adjust_redir_shape(self);
101 if (window_redir(self))
102 composite_window_setup(self);
105 void window_set_top_area(ObWindow *self, const Rect *r, gint border)
107 g_assert(!self->top);
109 #ifdef USE_COMPOSITING
111 self->topborder = border;
112 RECT_SET(self->area, -border, -border,
113 self->toparea.width + border * 2,
114 self->toparea.height + border * 2);
118 void window_cleanup(ObWindow *self)
120 if (window_redir(self)) {
121 composite_window_cleanup(self);
122 /* when the window goes away, we will need to redraw */
127 void window_free(ObWindow *self)
129 /* The abstract pointers must not be used here, they are likely invalid
132 if (self->rects) XFree(self->rects);
133 g_slice_free1(self->bytes, self);
136 ObWindow* window_find(Window xwin)
138 return g_hash_table_lookup(window_map, &xwin);
141 void wfe(gpointer k, gpointer v, gpointer data)
143 ((ObWindowForeachFunc)data)(v);
146 void window_foreach(ObWindowForeachFunc func)
148 g_hash_table_foreach(window_map, wfe, func);
151 void window_add(Window *xwin, ObWindow *win)
153 g_assert(xwin != NULL);
154 g_assert(win != NULL);
155 g_hash_table_insert(window_map, xwin, win);
158 void window_remove(Window xwin)
160 g_assert(xwin != None);
161 g_hash_table_remove(window_map, &xwin);
164 void window_adjust_redir_shape(ObWindow *self)
166 #ifdef USE_COMPOSITING
171 self->rects = XShapeGetRectangles(obt_display, window_redir(self),
172 ShapeBounding, &self->n_rects, &ord);
177 ObInternalWindow* window_internal_new(Window window, const Rect *area,
178 gint border, gint depth)
180 ObInternalWindow *self;
182 self = window_new(OB_WINDOW_CLASS_INTERNAL, ObInternalWindow);
183 self->window = window;
184 self->layer = OB_STACKING_LAYER_INTERNAL;
186 window_set_top_area(INTERNAL_AS_WINDOW(self), area, border);
187 window_set_abstract(INTERNAL_AS_WINDOW(self),
188 &self->window, /* top-most window */
189 (depth ? &self->window : NULL), /* comp redir window */
190 &self->layer, /* stacking layer */
191 &self->depth, /* window depth */
196 void window_manage_all(void)
201 XWindowAttributes attrib;
203 if (!XQueryTree(obt_display, RootWindow(obt_display, ob_screen),
204 &w, &w, &children, &nchild)) {
205 ob_debug("XQueryTree failed in window_manage_all");
209 /* remove all icon windows from the list */
210 for (i = 0; i < nchild; i++) {
211 if (children[i] == None) continue;
212 wmhints = XGetWMHints(obt_display, children[i]);
214 if ((wmhints->flags & IconWindowHint) &&
215 (wmhints->icon_window != children[i]))
216 for (j = 0; j < nchild; j++)
217 if (children[j] == wmhints->icon_window) {
218 /* XXX watch the window though */
226 for (i = 0; i < nchild; ++i) {
227 if (children[i] == None) continue;
228 if (window_find(children[i])) continue; /* skip our own windows */
229 if (!XGetWindowAttributes(obt_display, children[i], &attrib)) continue;
230 if (attrib.map_state == IsUnmapped || attrib.override_redirect)
231 unmanaged_new(children[i]);
233 window_manage(children[i]);
236 if (children) XFree(children);
239 void window_manage(Window win)
241 gboolean is_dockapp = FALSE;
242 Window icon_win = None;
245 /* is the window a docking app */
247 if ((wmhints = XGetWMHints(obt_display, win))) {
248 if ((wmhints->flags & StateHint) &&
249 wmhints->initial_state == WithdrawnState)
251 if (wmhints->flags & IconWindowHint)
252 icon_win = wmhints->icon_window;
263 dock_manage(icon_win, win);
266 client_manage(win, NULL);
269 void window_unmanage_all(void)
272 client_unmanage_all();
273 unmanaged_destroy_all();