-Window
-gdk_window_xid_at_coords (gint x,
- gint y,
- GList *excludes,
- gboolean excl_child)
-{
- GdkWindow *window;
- GdkWindowPrivate *private;
- Display *disp;
- Window *list = NULL;
- Window root, child = 0, parent_win = 0, root_win = 0;
- unsigned int num;
- int i;
-
- window = (GdkWindow*) &gdk_root_parent;
- private = (GdkWindowPrivate*) window;
- disp = private->xdisplay;
- root = private->xwindow;
- num = g_list_length (excludes);
-
- XGrabServer (disp);
- if (!XQueryTree (disp, root, &root_win, &parent_win, &list, &num))
- {
- XUngrabServer(disp);
- return root;
- }
- if (list)
- {
- i = num - 1;
- do
- {
- XWindowAttributes xwa;
-
- XGetWindowAttributes (disp, list [i], &xwa);
-
- if (xwa.map_state != IsViewable)
- continue;
-
- if (excl_child && g_list_find (excludes, (gpointer *) list[i]))
- continue;
-
- if ((child = gdk_window_xid_at (list[i], 0, 0, x, y, excludes, excl_child)) == 0)
- continue;
-
- if (excludes)
- {
- if (!g_list_find (excludes, (gpointer *) child))
- {
- XFree (list);
- XUngrabServer (disp);
- return child;
- }
- }
- else
- {
- XFree (list);
- XUngrabServer (disp);
- return child;
- }
- } while (--i > 0);
- XFree (list);
- }
- XUngrabServer (disp);
- return root;
-}
-
-void
-gdk_window_init (void)
-{
- XWindowAttributes xattributes;
- unsigned int width;
- unsigned int height;
- unsigned int border_width;
- unsigned int depth;
- int x, y;
-
- XGetGeometry (gdk_display, gdk_root_window, &gdk_root_window,
- &x, &y, &width, &height, &border_width, &depth);
- XGetWindowAttributes (gdk_display, gdk_root_window, &xattributes);
-
- gdk_root_parent.xwindow = gdk_root_window;
- gdk_root_parent.xdisplay = gdk_display;
- gdk_root_parent.window_type = GDK_WINDOW_ROOT;
- gdk_root_parent.window.user_data = NULL;
- gdk_root_parent.width = width;
- gdk_root_parent.height = height;
- gdk_root_parent.children = NULL;
- gdk_root_parent.colormap = NULL;
- gdk_root_parent.ref_count = 1;
-
- gdk_xid_table_insert (&gdk_root_window, &gdk_root_parent);
-}
-
-GdkWindow*
-gdk_window_new (GdkWindow *parent,
- GdkWindowAttr *attributes,
- gint attributes_mask)
-{
- GdkWindow *window;
- GdkWindowPrivate *private;
- GdkWindowPrivate *parent_private;
- GdkVisual *visual;
- Display *parent_display;
- Window xparent;
- Visual *xvisual;
- XSetWindowAttributes xattributes;
- long xattributes_mask;
- XSizeHints size_hints;
- XWMHints wm_hints;
- XClassHint *class_hint;
- int x, y, depth;
- unsigned int class;
- char *title;
- int i;
-
- g_return_val_if_fail (attributes != NULL, NULL);
-
- if (!parent)
- parent = (GdkWindow*) &gdk_root_parent;
-
- parent_private = (GdkWindowPrivate*) parent;
- if (parent_private->destroyed)
- return NULL;
-
- xparent = parent_private->xwindow;
- parent_display = parent_private->xdisplay;
-
- private = g_new (GdkWindowPrivate, 1);
- window = (GdkWindow*) private;
-
- private->parent = parent;
-
- if (parent_private)
- parent_private->children = g_list_prepend (parent_private->children, window);
-
- private->xdisplay = parent_display;
- private->destroyed = FALSE;
- private->mapped = FALSE;
- private->resize_count = 0;
- private->ref_count = 1;
- xattributes_mask = 0;
-
- if (attributes_mask & GDK_WA_X)
- x = attributes->x;
- else
- x = 0;
-
- if (attributes_mask & GDK_WA_Y)
- y = attributes->y;
- else
- y = 0;
-
- private->x = x;
- private->y = y;
- private->width = (attributes->width > 1) ? (attributes->width) : (1);
- private->height = (attributes->height > 1) ? (attributes->height) : (1);
- private->window_type = attributes->window_type;
- private->extension_events = FALSE;
-
- private->filters = NULL;
- private->children = NULL;
-
- window->user_data = NULL;
-
- if (attributes_mask & GDK_WA_VISUAL)
- visual = attributes->visual;
- else
- visual = gdk_visual_get_system ();
- xvisual = ((GdkVisualPrivate*) visual)->xvisual;
-
- xattributes.event_mask = StructureNotifyMask;
- for (i = 0; i < gdk_nevent_masks; i++)
- {
- if (attributes->event_mask & (1 << (i + 1)))
- xattributes.event_mask |= gdk_event_mask_table[i];
- }
-
- if (xattributes.event_mask)
- xattributes_mask |= CWEventMask;
-
- if(attributes_mask & GDK_WA_NOREDIR) {
- xattributes.override_redirect =
- (attributes->override_redirect == FALSE)?False:True;
- xattributes_mask |= CWOverrideRedirect;
- } else
- xattributes.override_redirect = False;
-
- if (attributes->wclass == GDK_INPUT_OUTPUT)
- {
- class = InputOutput;
- depth = visual->depth;
-
- if (attributes_mask & GDK_WA_COLORMAP)
- private->colormap = attributes->colormap;
- else
- {
- if ((((GdkVisualPrivate*)gdk_visual_get_system())->xvisual) == xvisual)
- private->colormap = gdk_colormap_get_system ();
- else
- private->colormap = gdk_colormap_new (visual, False);
- }
-
- xattributes.background_pixel = BlackPixel (gdk_display, gdk_screen);
- xattributes.border_pixel = BlackPixel (gdk_display, gdk_screen);
- xattributes_mask |= CWBorderPixel | CWBackPixel;
-
- switch (private->window_type)
- {
- case GDK_WINDOW_TOPLEVEL:
- xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap;
- xattributes_mask |= CWColormap;
-
- xparent = gdk_root_window;
- break;
-
- case GDK_WINDOW_CHILD:
- xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap;
- xattributes_mask |= CWColormap;
- break;
-
- case GDK_WINDOW_DIALOG:
- xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap;
- xattributes_mask |= CWColormap;
-
- xparent = gdk_root_window;
- break;
-
- case GDK_WINDOW_TEMP:
- xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap;
- xattributes_mask |= CWColormap;
-
- xparent = gdk_root_window;
-
- xattributes.save_under = True;
- xattributes.override_redirect = True;
- xattributes.cursor = None;
- xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
- break;
- case GDK_WINDOW_ROOT:
- g_error ("cannot make windows of type GDK_WINDOW_ROOT");
- break;
- case GDK_WINDOW_PIXMAP:
- g_error ("cannot make windows of type GDK_WINDOW_PIXMAP (use gdk_pixmap_new)");
- break;
- }
- }
- else
- {
- depth = 0;
- class = InputOnly;
- private->colormap = NULL;
- }
-
- private->xwindow = XCreateWindow (private->xdisplay, xparent,
- x, y, private->width, private->height,
- 0, depth, class, xvisual,
- xattributes_mask, &xattributes);
- gdk_window_ref (window);
- gdk_xid_table_insert (&private->xwindow, window);
-
- if (private->colormap)
- gdk_colormap_ref (private->colormap);
-
- gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
- (attributes->cursor) :
- NULL));
-
- switch (private->window_type)
- {
- case GDK_WINDOW_DIALOG:
- XSetTransientForHint (private->xdisplay, private->xwindow, xparent);
- case GDK_WINDOW_TOPLEVEL:
- case GDK_WINDOW_TEMP:
- XSetWMProtocols (private->xdisplay, private->xwindow, gdk_wm_window_protocols, 2);
- break;
- case GDK_WINDOW_CHILD:
- if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
- (private->colormap != gdk_colormap_get_system ()) &&
- (private->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window))))
- {
- GDK_NOTE (MISC, g_message ("adding colormap window\n"));
- gdk_window_add_colormap_windows (window);
- }
-
- return window;
- default:
-
- return window;
- }
-
- size_hints.flags = PSize;
- size_hints.width = private->width;
- size_hints.height = private->height;
-
- wm_hints.flags = InputHint | StateHint | WindowGroupHint;
- wm_hints.window_group = gdk_leader_window;
- wm_hints.input = True;
- wm_hints.initial_state = NormalState;
-
- /* FIXME: Is there any point in doing this? Do any WM's pay
- * attention to PSize, and even if they do, is this the
- * correct value???
- */
- XSetWMNormalHints (private->xdisplay, private->xwindow, &size_hints);
-
- XSetWMHints (private->xdisplay, private->xwindow, &wm_hints);
-
- if (attributes_mask & GDK_WA_TITLE)
- title = attributes->title;
- else
- title = g_get_prgname ();
-
- XmbSetWMProperties (private->xdisplay, private->xwindow,
- title, title,
- NULL, 0,
- NULL, NULL, NULL);
-
- if (attributes_mask & GDK_WA_WMCLASS)
- {
- class_hint = XAllocClassHint ();
- class_hint->res_name = attributes->wmclass_name;
- class_hint->res_class = attributes->wmclass_class;
- XSetClassHint (private->xdisplay, private->xwindow, class_hint);
- XFree (class_hint);
- }
-
-
- return window;
-}
-
-GdkWindow *
-gdk_window_foreign_new (guint32 anid)
-{
- GdkWindow *window;
- GdkWindowPrivate *private;
- GdkWindowPrivate *parent_private;
- XWindowAttributes attrs;
- Window root, parent;
- Window *children = NULL;
- guint nchildren;
-
- if(!XGetWindowAttributes (gdk_display, anid, &attrs)) {
- g_warning("XGetWindowAttributes failed on window ID %d\n", anid);
- return NULL;
- }
-
- private = g_new (GdkWindowPrivate, 1);
- window = (GdkWindow*) private;
-
- /* FIXME: This is pretty expensive. Maybe the caller should supply
- * the parent */
- XQueryTree (gdk_display, anid, &root, &parent, &children, &nchildren);
-
- if (children)
- XFree (children);
- private->parent = gdk_xid_table_lookup (parent);
-
- parent_private = (GdkWindowPrivate *)private->parent;
-
- if (parent_private)
- parent_private->children = g_list_prepend (parent_private->children, window);
-
- private->xwindow = anid;
- private->xdisplay = gdk_display;
- private->x = attrs.x;
- private->y = attrs.y;
- private->width = attrs.width;
- private->height = attrs.height;
- private->resize_count = 0;
- private->ref_count = 1;
- private->window_type = GDK_WINDOW_FOREIGN;
- private->destroyed = FALSE;
- private->mapped = (attrs.map_state != IsUnmapped);
- private->extension_events = 0;
-
- private->colormap = NULL;
-
- private->filters = NULL;
- private->children = NULL;
-
- window->user_data = NULL;
-
- gdk_window_ref (window);
- gdk_xid_table_insert (&private->xwindow, window);
-
- return window;
-}
-
-/* Call this function when you want a window and all its children to
- disappear. When xdestroy is true, a request to destroy the XWindow
- is sent out. When it is false, it is assumed that the XWindow has
- been or will be destroyed by destroying some ancestor of this
- window. */
-
-static void
-gdk_window_internal_destroy (GdkWindow *window, gboolean xdestroy,
- gboolean our_destroy)
-{
- GdkWindowPrivate *private;
- GdkWindowPrivate *temp_private;
- GdkWindow *temp_window;
- GList *children;
- GList *tmp;
-
- g_return_if_fail (window != NULL);
-
- private = (GdkWindowPrivate*) window;
-
- switch (private->window_type)
- {
- case GDK_WINDOW_TOPLEVEL:
- case GDK_WINDOW_CHILD:
- case GDK_WINDOW_DIALOG:
- case GDK_WINDOW_TEMP:
- case GDK_WINDOW_FOREIGN:
- if (!private->destroyed)
- {
- if (private->parent)
- {
- GdkWindowPrivate *parent_private = (GdkWindowPrivate *)private->parent;
- if (parent_private->children)
- parent_private->children = g_list_remove (parent_private->children, window);
- }
-
- if (private->window_type != GDK_WINDOW_FOREIGN)
- {
- children = tmp = private->children;
- private->children = NULL;
-
- while (tmp)
- {
- temp_window = tmp->data;
- tmp = tmp->next;
-
- temp_private = (GdkWindowPrivate*) temp_window;
- if (temp_private)
- gdk_window_internal_destroy (temp_window, FALSE,
- our_destroy);
- }
-
- g_list_free (children);
- }
-
- if (private->extension_events != 0)
- gdk_input_window_destroy (window);
-
- if (private->filters)
- {
- tmp = private->filters;
-
- while (tmp)
- {
- g_free (tmp->data);
- tmp = tmp->next;
- }
-
- g_list_free (private->filters);
- private->filters = NULL;
- }
-
- if (private->window_type == GDK_WINDOW_FOREIGN)
- {
- if (our_destroy && (private->parent != NULL))
- {
- /* It's somebody elses window, but in our heirarchy,
- * so reparent it to the root window, and then send
- * it a delete event, as if we were a WM
- */
- XClientMessageEvent xevent;
-
- gdk_window_hide (window);
- gdk_window_reparent (window, NULL, 0, 0);
-
- xevent.type = ClientMessage;
- xevent.window = private->xwindow;
- xevent.message_type = gdk_wm_protocols;
- xevent.format = 32;
- xevent.data.l[0] = gdk_wm_delete_window;
- xevent.data.l[1] = CurrentTime;
-
- XSendEvent (private->xdisplay, private->xwindow,
- False, 0, (XEvent *)&xevent);
- }
- }
- else if (xdestroy)
- XDestroyWindow (private->xdisplay, private->xwindow);
-
- if (private->colormap)
- gdk_colormap_unref (private->colormap);
-
- private->destroyed = TRUE;
- }
- break;
-
- case GDK_WINDOW_ROOT:
- g_error ("attempted to destroy root window");
- break;
-
- case GDK_WINDOW_PIXMAP:
- g_error ("called gdk_window_destroy on a pixmap (use gdk_pixmap_unref)");
- break;
- }
-}
-
-/* Like internal_destroy, but also destroys the reference created by
- gdk_window_new. */
-
-void
-gdk_window_destroy (GdkWindow *window)
-{
- gdk_window_internal_destroy (window, TRUE, TRUE);
- gdk_window_unref (window);
-}
-
-/* This function is called when the XWindow is really gone. */
-
-void
-gdk_window_destroy_notify (GdkWindow *window)
-{
- GdkWindowPrivate *private;
-
- g_return_if_fail (window != NULL);
-
- private = (GdkWindowPrivate*) window;
-
- if (!private->destroyed)
- {
- if (private->window_type == GDK_WINDOW_FOREIGN)
- gdk_window_internal_destroy (window, FALSE, FALSE);
- else
- g_warning ("GdkWindow %#lx unexpectedly destroyed", private->xwindow);
- }
-
- gdk_xid_table_remove (private->xwindow);
- gdk_window_unref (window);
-}
-
-GdkWindow*
-gdk_window_ref (GdkWindow *window)
-{
- GdkWindowPrivate *private = (GdkWindowPrivate *)window;
- g_return_val_if_fail (window != NULL, NULL);
-
- private->ref_count += 1;
- return window;
-}
-
-void
-gdk_window_unref (GdkWindow *window)
-{
- GdkWindowPrivate *private = (GdkWindowPrivate *)window;
- g_return_if_fail (window != NULL);
-
- private->ref_count -= 1;
- if (private->ref_count == 0)
- {
- if (!private->destroyed)
- {
- if (private->window_type == GDK_WINDOW_FOREIGN)
- gdk_xid_table_remove (private->xwindow);
- else
- g_warning ("losing last reference to undestroyed window\n");
- }
- g_dataset_destroy (window);
- g_free (window);
- }
-}
-
-void
-gdk_window_show (GdkWindow *window)
-{
- GdkWindowPrivate *private;
-
- g_return_if_fail (window != NULL);
-
- private = (GdkWindowPrivate*) window;
- if (!private->destroyed)
- {
- private->mapped = TRUE;
- XRaiseWindow (private->xdisplay, private->xwindow);
- XMapWindow (private->xdisplay, private->xwindow);
- }
-}
-
-void
-gdk_window_hide (GdkWindow *window)
-{
- GdkWindowPrivate *private;
-
- g_return_if_fail (window != NULL);
-
- private = (GdkWindowPrivate*) window;
- if (!private->destroyed)
- {
- private->mapped = FALSE;
- XUnmapWindow (private->xdisplay, private->xwindow);
- }
-}
-
-void
-gdk_window_withdraw (GdkWindow *window)
-{
- GdkWindowPrivate *private;
-
- g_return_if_fail (window != NULL);
-
- private = (GdkWindowPrivate*) window;
- if (!private->destroyed)
- XWithdrawWindow (private->xdisplay, private->xwindow, 0);
-}
-
-void
-gdk_window_move (GdkWindow *window,
- gint x,
- gint y)
-{
- GdkWindowPrivate *private;
-
- g_return_if_fail (window != NULL);
-
- private = (GdkWindowPrivate*) window;
- if (!private->destroyed)
- {
- XMoveWindow (private->xdisplay, private->xwindow, x, y);
-
- if (private->window_type == GDK_WINDOW_CHILD)
- {
- private->x = x;
- private->y = y;
- }
- }
-}
-
-void
-gdk_window_resize (GdkWindow *window,
- gint width,
- gint height)
-{
- GdkWindowPrivate *private;
-
- g_return_if_fail (window != NULL);
-
- if (width < 1)
- width = 1;
- if (height < 1)
- height = 1;
-
- private = (GdkWindowPrivate*) window;
-
- if (!private->destroyed &&
- ((private->resize_count > 0) ||
- (private->width != (guint16) width) ||
- (private->height != (guint16) height)))
- {
- XResizeWindow (private->xdisplay, private->xwindow, width, height);
- private->resize_count += 1;
-
- if (private->window_type == GDK_WINDOW_CHILD)
- {
- private->width = width;
- private->height = height;
- }
- }
-}
-
-void
-gdk_window_move_resize (GdkWindow *window,
- gint x,
- gint y,
- gint width,
- gint height)
-{
- GdkWindowPrivate *private;
-
- g_return_if_fail (window != NULL);
-
- if (width < 1)
- width = 1;
- if (height < 1)
- height = 1;
-
- private = (GdkWindowPrivate*) window;
- if (!private->destroyed)
- {
- XMoveResizeWindow (private->xdisplay, private->xwindow, x, y, width, height);
-
- if (private->window_type == GDK_WINDOW_CHILD)
- {
- private->x = x;
- private->y = y;
- private->width = width;
- private->height = height;
- }
- }
-}
-
-void
-gdk_window_reparent (GdkWindow *window,
- GdkWindow *new_parent,
- gint x,
- gint y)
-{
- GdkWindowPrivate *window_private;
- GdkWindowPrivate *parent_private;
- GdkWindowPrivate *old_parent_private;
-
- g_return_if_fail (window != NULL);
-
- if (!new_parent)
- new_parent = (GdkWindow*) &gdk_root_parent;
-
- window_private = (GdkWindowPrivate*) window;
- old_parent_private = (GdkWindowPrivate*)window_private->parent;
- parent_private = (GdkWindowPrivate*) new_parent;
-
- if (!window_private->destroyed && !parent_private->destroyed)
- XReparentWindow (window_private->xdisplay,
- window_private->xwindow,
- parent_private->xwindow,
- x, y);
-
- window_private->parent = new_parent;
-
- if (old_parent_private)
- old_parent_private->children = g_list_remove (old_parent_private->children, window);
- parent_private->children = g_list_prepend (parent_private->children, window);
-
-}
-
-void
-gdk_window_clear (GdkWindow *window)
-{
- GdkWindowPrivate *private;
-
- g_return_if_fail (window != NULL);
-
- private = (GdkWindowPrivate*) window;
-
- if (!private->destroyed)
- XClearWindow (private->xdisplay, private->xwindow);
-}
-
-void
-gdk_window_clear_area (GdkWindow *window,
- gint x,
- gint y,
- gint width,
- gint height)
-{
- GdkWindowPrivate *private;
-
- g_return_if_fail (window != NULL);
-
- private = (GdkWindowPrivate*) window;
-
- if (!private->destroyed)
- XClearArea (private->xdisplay, private->xwindow,
- x, y, width, height, False);
-}
-
-void
-gdk_window_clear_area_e (GdkWindow *window,
- gint x,
- gint y,
- gint width,
- gint height)
-{
- GdkWindowPrivate *private;
-
- g_return_if_fail (window != NULL);
-
- private = (GdkWindowPrivate*) window;
-
- if (!private->destroyed)
- XClearArea (private->xdisplay, private->xwindow,
- x, y, width, height, True);
-}