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"
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 Window window_top(ObWindow *self)
56 case OB_WINDOW_CLASS_MENUFRAME:
57 return WINDOW_AS_MENUFRAME(self)->window;
58 case OB_WINDOW_CLASS_DOCK:
59 return WINDOW_AS_DOCK(self)->frame;
60 case OB_WINDOW_CLASS_CLIENT:
61 return WINDOW_AS_CLIENT(self)->frame->window;
62 case OB_WINDOW_CLASS_INTERNAL:
63 return WINDOW_AS_INTERNAL(self)->window;
64 case OB_WINDOW_CLASS_PROMPT:
65 return WINDOW_AS_PROMPT(self)->super.window;
66 case OB_WINDOW_CLASS_EDGE:
67 return WINDOW_AS_EDGE(self)->win;
69 g_assert_not_reached();
73 ObStackingLayer window_layer(ObWindow *self)
76 case OB_WINDOW_CLASS_DOCK:
77 return config_dock_layer;
78 case OB_WINDOW_CLASS_CLIENT:
79 return ((ObClient*)self)->layer;
80 case OB_WINDOW_CLASS_EDGE:
81 case OB_WINDOW_CLASS_MENUFRAME:
82 case OB_WINDOW_CLASS_INTERNAL:
83 return OB_STACKING_LAYER_INTERNAL;
84 case OB_WINDOW_CLASS_PROMPT:
85 /* not used directly for stacking, prompts are managed as clients */
86 g_assert_not_reached();
89 g_assert_not_reached();
93 ObWindow* window_find(Window xwin)
95 return g_hash_table_lookup(window_map, &xwin);
98 void window_add(Window *xwin, ObWindow *win)
100 g_assert(xwin != NULL);
101 g_assert(win != NULL);
102 g_hash_table_insert(window_map, xwin, win);
105 void window_remove(Window xwin)
107 g_assert(xwin != None);
108 g_hash_table_remove(window_map, &xwin);
111 void window_manage_all(void)
116 XWindowAttributes attrib;
118 if (!XQueryTree(obt_display, RootWindow(obt_display, ob_screen),
119 &w, &w, &children, &nchild)) {
120 ob_debug("XQueryTree failed in window_manage_all");
124 /* remove all icon windows from the list */
125 for (i = 0; i < nchild; i++) {
126 if (children[i] == None) continue;
127 wmhints = XGetWMHints(obt_display, children[i]);
129 if ((wmhints->flags & IconWindowHint) &&
130 (wmhints->icon_window != children[i]))
131 for (j = 0; j < nchild; j++)
132 if (children[j] == wmhints->icon_window) {
133 /* XXX watch the window though */
141 for (i = 0; i < nchild; ++i) {
142 if (children[i] == None) continue;
143 if (window_find(children[i])) continue; /* skip our own windows */
144 if (XGetWindowAttributes(obt_display, children[i], &attrib)) {
145 if (attrib.map_state == IsUnmapped)
148 window_manage(children[i]);
152 if (children) XFree(children);
155 static gboolean check_unmap(XEvent *e, gpointer data)
157 const Window win = *(Window*)data;
158 return ((e->type == DestroyNotify && e->xdestroywindow.window == win) ||
159 (e->type == UnmapNotify && e->xunmap.window == win));
162 void window_manage(Window win)
164 XWindowAttributes attrib;
165 gboolean no_manage = FALSE;
166 gboolean is_dockapp = FALSE;
167 Window icon_win = None;
171 /* check if it has already been unmapped by the time we started
172 mapping. the grab does a sync so we don't have to here */
173 if (xqueue_exists_local(check_unmap, &win)) {
174 ob_debug("Trying to manage unmapped window. Aborting that.");
177 else if (!XGetWindowAttributes(obt_display, win, &attrib))
182 /* is the window a docking app */
184 if ((wmhints = XGetWMHints(obt_display, win))) {
185 if ((wmhints->flags & StateHint) &&
186 wmhints->initial_state == WithdrawnState)
188 if (wmhints->flags & IconWindowHint)
189 icon_win = wmhints->icon_window;
194 /* This is a new method to declare that a window is a dockapp, being
195 implemented by Windowmaker, to alleviate pain in writing GTK+
197 http://thread.gmane.org/gmane.comp.window-managers.openbox/4881
201 if (OBT_PROP_GETSS_TYPE(win, WM_CLASS, STRING_NO_CC, &ss))
203 if (ss[0] && ss[1] && strcmp(ss[1], "DockApp") == 0)
211 if (attrib.override_redirect) {
212 ob_debug("not managing override redirect window 0x%x", win);
215 else if (is_dockapp) {
218 dock_manage(icon_win, win);
221 client_manage(win, NULL);
225 ob_debug("FAILED to manage window 0x%x", win);
229 void window_unmanage_all(void)
232 client_unmanage_all();