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"
29 #include "obt/xqueue.h"
31 static GHashTable *window_map;
33 static guint window_hash(Window *w) { return *w; }
34 static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; }
36 void window_startup(gboolean reconfig)
40 window_map = g_hash_table_new((GHashFunc)window_hash,
41 (GEqualFunc)window_comp);
44 void window_shutdown(gboolean reconfig)
48 g_hash_table_destroy(window_map);
51 Window window_top(ObWindow *self)
54 case OB_WINDOW_CLASS_MENUFRAME:
55 return WINDOW_AS_MENUFRAME(self)->window;
56 case OB_WINDOW_CLASS_DOCK:
57 return WINDOW_AS_DOCK(self)->frame;
58 case OB_WINDOW_CLASS_CLIENT:
59 return WINDOW_AS_CLIENT(self)->frame->window;
60 case OB_WINDOW_CLASS_INTERNAL:
61 return WINDOW_AS_INTERNAL(self)->window;
62 case OB_WINDOW_CLASS_PROMPT:
63 return WINDOW_AS_PROMPT(self)->super.window;
65 g_assert_not_reached();
69 ObStackingLayer window_layer(ObWindow *self)
72 case OB_WINDOW_CLASS_DOCK:
73 return config_dock_layer;
74 case OB_WINDOW_CLASS_CLIENT:
75 return ((ObClient*)self)->layer;
76 case OB_WINDOW_CLASS_MENUFRAME:
77 case OB_WINDOW_CLASS_INTERNAL:
78 return OB_STACKING_LAYER_INTERNAL;
79 case OB_WINDOW_CLASS_PROMPT:
80 /* not used directly for stacking, prompts are managed as clients */
81 g_assert_not_reached();
84 g_assert_not_reached();
88 ObWindow* window_find(Window xwin)
90 return g_hash_table_lookup(window_map, &xwin);
93 void window_add(Window *xwin, ObWindow *win)
95 g_assert(xwin != NULL);
96 g_assert(win != NULL);
97 g_hash_table_insert(window_map, xwin, win);
100 void window_remove(Window xwin)
102 g_assert(xwin != None);
103 g_hash_table_remove(window_map, &xwin);
106 void window_manage_all(void)
111 XWindowAttributes attrib;
113 if (!XQueryTree(obt_display, RootWindow(obt_display, ob_screen),
114 &w, &w, &children, &nchild)) {
115 ob_debug("XQueryTree failed in window_manage_all");
119 /* remove all icon windows from the list */
120 for (i = 0; i < nchild; i++) {
121 if (children[i] == None) continue;
122 wmhints = XGetWMHints(obt_display, children[i]);
124 if ((wmhints->flags & IconWindowHint) &&
125 (wmhints->icon_window != children[i]))
126 for (j = 0; j < nchild; j++)
127 if (children[j] == wmhints->icon_window) {
128 /* XXX watch the window though */
136 for (i = 0; i < nchild; ++i) {
137 if (children[i] == None) continue;
138 if (window_find(children[i])) continue; /* skip our own windows */
139 if (XGetWindowAttributes(obt_display, children[i], &attrib)) {
140 if (attrib.map_state == IsUnmapped)
143 window_manage(children[i]);
147 if (children) XFree(children);
150 static gboolean check_unmap(XEvent *e, gpointer data)
152 const Window win = *(Window*)data;
153 return ((e->type == DestroyNotify && e->xdestroywindow.window == win) ||
154 (e->type == UnmapNotify && e->xunmap.window == win));
157 void window_manage(Window win)
159 XWindowAttributes attrib;
160 gboolean no_manage = FALSE;
161 gboolean is_dockapp = FALSE;
162 Window icon_win = None;
166 /* check if it has already been unmapped by the time we started
167 mapping. the grab does a sync so we don't have to here */
168 if (xqueue_exists_local(check_unmap, &win)) {
169 ob_debug("Trying to manage unmapped window. Aborting that.");
172 else if (!XGetWindowAttributes(obt_display, win, &attrib))
177 /* is the window a docking app */
179 if ((wmhints = XGetWMHints(obt_display, win))) {
180 if ((wmhints->flags & StateHint) &&
181 wmhints->initial_state == WithdrawnState)
183 if (wmhints->flags & IconWindowHint)
184 icon_win = wmhints->icon_window;
192 if (attrib.override_redirect) {
193 ob_debug("not managing override redirect window 0x%x", win);
196 else if (is_dockapp) {
199 dock_manage(icon_win, win);
202 client_manage(win, NULL);
206 ob_debug("FAILED to manage window 0x%x", win);
210 void window_unmanage_all(void)
213 client_unmanage_all();