1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
30 #include <netinet/in.h>
35 #include "gdkwindow.h"
36 #include "gdkinputprivate.h"
37 #include "gdkprivate-x11.h"
38 #include "gdkregion.h"
39 #include "gdkinternals.h"
41 #include "gdkwindow-x11.h"
49 #include <X11/extensions/shape.h>
52 const int _gdk_event_mask_table[21] =
56 PointerMotionHintMask,
73 SubstructureNotifyMask,
74 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
76 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
78 /* Forward declarations */
79 static gboolean gdk_window_gravity_works (void);
80 static void gdk_window_set_static_win_gravity (GdkWindow *window,
82 static gboolean gdk_window_have_shape_ext (void);
83 static gboolean gdk_window_icon_name_set (GdkWindow *window);
85 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
86 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
88 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
91 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
92 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
93 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
94 static void gdk_window_impl_x11_finalize (GObject *object);
96 static gpointer parent_class = NULL;
99 gdk_window_impl_x11_get_type (void)
101 static GType object_type = 0;
105 static const GTypeInfo object_info =
107 sizeof (GdkWindowImplX11Class),
108 (GBaseInitFunc) NULL,
109 (GBaseFinalizeFunc) NULL,
110 (GClassInitFunc) gdk_window_impl_x11_class_init,
111 NULL, /* class_finalize */
112 NULL, /* class_data */
113 sizeof (GdkWindowImplX11),
115 (GInstanceInitFunc) gdk_window_impl_x11_init,
118 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
127 _gdk_window_impl_get_type (void)
129 return gdk_window_impl_x11_get_type ();
133 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
140 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
142 GObjectClass *object_class = G_OBJECT_CLASS (klass);
143 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
145 parent_class = g_type_class_peek_parent (klass);
147 object_class->finalize = gdk_window_impl_x11_finalize;
149 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
150 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
151 drawable_class->get_size = gdk_window_impl_x11_get_size;
153 /* Visible and clip regions are the same */
154 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
155 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
159 gdk_window_impl_x11_finalize (GObject *object)
161 GdkWindowObject *wrapper;
162 GdkDrawableImplX11 *draw_impl;
163 GdkWindowImplX11 *window_impl;
165 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
167 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
168 window_impl = GDK_WINDOW_IMPL_X11 (object);
170 wrapper = (GdkWindowObject*) draw_impl->wrapper;
172 if (!GDK_WINDOW_DESTROYED (wrapper))
174 gdk_xid_table_remove (draw_impl->xid);
175 if (window_impl->focus_window)
176 gdk_xid_table_remove (window_impl->focus_window);
179 G_OBJECT_CLASS (parent_class)->finalize (object);
183 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
185 GdkDrawableImplX11 *drawable_impl;
186 GdkWindowImplX11 *window_impl;
188 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
190 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
191 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
193 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
194 drawable_impl->colormap == NULL)
196 XWindowAttributes window_attributes;
198 XGetWindowAttributes (drawable_impl->xdisplay,
201 drawable_impl->colormap =
202 gdk_colormap_lookup (window_attributes.colormap);
205 return drawable_impl->colormap;
209 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
212 GdkWindowImplX11 *impl;
213 GdkDrawableImplX11 *draw_impl;
215 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
217 impl = GDK_WINDOW_IMPL_X11 (drawable);
218 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
221 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
225 XSetWindowColormap (draw_impl->xdisplay,
227 GDK_COLORMAP_XCOLORMAP (cmap));
229 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
231 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
237 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
241 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
244 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
246 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
250 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
252 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
253 GdkRectangle result_rect;
257 result_rect.width = impl->width;
258 result_rect.height = impl->height;
260 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
262 return gdk_region_rectangle (&result_rect);
266 _gdk_windowing_window_init (void)
268 GdkWindowObject *private;
269 GdkWindowImplX11 *impl;
270 GdkDrawableImplX11 *draw_impl;
271 XWindowAttributes xattributes;
274 unsigned int border_width;
278 g_assert (_gdk_parent_root == NULL);
280 XGetGeometry (gdk_display, _gdk_root_window, &_gdk_root_window,
281 &x, &y, &width, &height, &border_width, &depth);
282 XGetWindowAttributes (gdk_display, _gdk_root_window, &xattributes);
284 _gdk_parent_root = g_object_new (GDK_TYPE_WINDOW, NULL);
285 private = (GdkWindowObject *)_gdk_parent_root;
286 impl = GDK_WINDOW_IMPL_X11 (private->impl);
287 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
289 draw_impl->xdisplay = gdk_display;
290 draw_impl->xid = _gdk_root_window;
291 draw_impl->wrapper = GDK_DRAWABLE (private);
293 private->window_type = GDK_WINDOW_ROOT;
294 private->depth = depth;
296 impl->height = height;
298 gdk_xid_table_insert (&_gdk_root_window, _gdk_parent_root);
301 static Atom wm_client_leader_atom = None;
305 * @parent: a #GdkWindow
306 * @attributes: attributes of the new window
307 * @attributes_mask: mask indicating which fields in @attributes are valid
309 * Creates a new #GdkWindow using the attributes from @attributes. See
310 * #GdkWindowAttr and #GdkWindowAttributesType for more details.
312 * Return value: the new #GdkWindow
315 gdk_window_new (GdkWindow *parent,
316 GdkWindowAttr *attributes,
317 gint attributes_mask)
320 GdkWindowObject *private;
321 GdkWindowImplX11 *impl;
322 GdkDrawableImplX11 *draw_impl;
330 XSetWindowAttributes xattributes;
331 long xattributes_mask;
332 XSizeHints size_hints;
334 XClassHint *class_hint;
342 g_return_val_if_fail (attributes != NULL, NULL);
345 parent = _gdk_parent_root;
347 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
349 if (GDK_WINDOW_DESTROYED (parent))
352 xparent = GDK_WINDOW_XID (parent);
354 window = g_object_new (GDK_TYPE_WINDOW, NULL);
355 private = (GdkWindowObject *)window;
356 impl = GDK_WINDOW_IMPL_X11 (private->impl);
357 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
358 draw_impl->wrapper = GDK_DRAWABLE (window);
360 xdisplay = draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (parent);
362 /* Windows with a foreign parent are treated as if they are children
363 * of the root window, except for actual creation.
365 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
366 parent = _gdk_parent_root;
368 private->parent = (GdkWindowObject *)parent;
370 xattributes_mask = 0;
372 if (attributes_mask & GDK_WA_X)
377 if (attributes_mask & GDK_WA_Y)
384 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
385 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
387 if (attributes->wclass == GDK_INPUT_ONLY)
389 /* Backwards compatiblity - we've always ignored
390 * attributes->window_type for input-only windows
393 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
394 private->window_type = GDK_WINDOW_TEMP;
396 private->window_type = GDK_WINDOW_CHILD;
399 private->window_type = attributes->window_type;
401 _gdk_window_init_position (GDK_WINDOW (private));
402 if (impl->position_info.big)
403 private->guffaw_gravity = TRUE;
405 if (attributes_mask & GDK_WA_VISUAL)
406 visual = attributes->visual;
408 visual = gdk_visual_get_system ();
409 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
411 xattributes.event_mask = StructureNotifyMask;
412 for (i = 0; i < _gdk_nenvent_masks; i++)
414 if (attributes->event_mask & (1 << (i + 1)))
415 xattributes.event_mask |= _gdk_event_mask_table[i];
417 private->event_mask = attributes->event_mask;
419 if (xattributes.event_mask)
420 xattributes_mask |= CWEventMask;
422 if (attributes_mask & GDK_WA_NOREDIR)
424 xattributes.override_redirect =
425 (attributes->override_redirect == FALSE)?False:True;
426 xattributes_mask |= CWOverrideRedirect;
429 xattributes.override_redirect = False;
431 if (private->parent && private->parent->guffaw_gravity)
433 xattributes.win_gravity = StaticGravity;
434 xattributes_mask |= CWWinGravity;
438 switch (private->window_type)
440 case GDK_WINDOW_TOPLEVEL:
441 case GDK_WINDOW_DIALOG:
442 case GDK_WINDOW_TEMP:
443 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
445 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
446 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
447 xparent = _gdk_root_window;
449 case GDK_WINDOW_CHILD:
452 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
456 if (attributes->wclass == GDK_INPUT_OUTPUT)
459 depth = visual->depth;
461 private->input_only = FALSE;
462 private->depth = depth;
464 if (attributes_mask & GDK_WA_COLORMAP)
466 draw_impl->colormap = attributes->colormap;
467 gdk_colormap_ref (attributes->colormap);
471 if ((((GdkVisualPrivate*)gdk_visual_get_system ())->xvisual) == xvisual)
473 draw_impl->colormap =
474 gdk_colormap_get_system ();
475 gdk_colormap_ref (draw_impl->colormap);
479 draw_impl->colormap =
480 gdk_colormap_new (visual, FALSE);
484 private->bg_color.pixel = BlackPixel (gdk_display, _gdk_screen);
485 xattributes.background_pixel = private->bg_color.pixel;
487 private->bg_pixmap = NULL;
489 xattributes.border_pixel = BlackPixel (gdk_display, _gdk_screen);
490 xattributes_mask |= CWBorderPixel | CWBackPixel;
492 if (private->guffaw_gravity)
493 xattributes.bit_gravity = StaticGravity;
495 xattributes.bit_gravity = NorthWestGravity;
497 xattributes_mask |= CWBitGravity;
499 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
500 xattributes_mask |= CWColormap;
502 if (private->window_type == GDK_WINDOW_TEMP)
504 xattributes.save_under = True;
505 xattributes.override_redirect = True;
506 xattributes.cursor = None;
507 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
515 private->input_only = TRUE;
516 draw_impl->colormap = gdk_colormap_get_system ();
517 gdk_colormap_ref (draw_impl->colormap);
520 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
521 impl->position_info.x, impl->position_info.y,
522 impl->position_info.width, impl->position_info.height,
523 0, depth, class, xvisual,
524 xattributes_mask, &xattributes);
526 gdk_drawable_ref (window);
527 gdk_xid_table_insert (&draw_impl->xid, window);
529 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
530 (attributes->cursor) :
534 private->parent->children = g_list_prepend (private->parent->children, window);
536 switch (GDK_WINDOW_TYPE (private))
538 case GDK_WINDOW_DIALOG:
539 XSetTransientForHint (xdisplay, xid, xparent);
540 case GDK_WINDOW_TOPLEVEL:
541 case GDK_WINDOW_TEMP:
542 XSetWMProtocols (xdisplay, xid,
543 _gdk_wm_window_protocols, 3);
545 case GDK_WINDOW_CHILD:
546 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
547 (draw_impl->colormap != gdk_colormap_get_system ()) &&
548 (draw_impl->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window))))
550 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
551 gdk_window_add_colormap_windows (window);
560 if (class != InputOnly)
562 /* The focus window is off the visible area, and serves to receive key
563 * press events so they don't get sent to child windows.
565 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
567 xattributes.background_pixel,
568 xattributes.background_pixel);
569 /* FIXME: probably better to actually track the requested event mask for the toplevel
571 XSelectInput (xdisplay, impl->focus_window,
572 KeyPressMask | KeyReleaseMask | FocusChangeMask);
574 XMapWindow (xdisplay, impl->focus_window);
575 gdk_xid_table_insert (&impl->focus_window, window);
578 size_hints.flags = PSize;
579 size_hints.width = impl->width;
580 size_hints.height = impl->height;
582 wm_hints.flags = StateHint | WindowGroupHint;
583 wm_hints.window_group = _gdk_leader_window;
584 wm_hints.input = True;
585 wm_hints.initial_state = NormalState;
587 /* FIXME: Is there any point in doing this? Do any WM's pay
588 * attention to PSize, and even if they do, is this the
591 XSetWMNormalHints (xdisplay, xid, &size_hints);
593 XSetWMHints (xdisplay, xid, &wm_hints);
595 if (!wm_client_leader_atom)
596 wm_client_leader_atom = gdk_x11_get_xatom_by_name ("WM_CLIENT_LEADER");
598 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
599 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
602 XChangeProperty (xdisplay, xid,
603 gdk_x11_get_xatom_by_name ("_NET_WM_PID"),
608 XChangeProperty (xdisplay, xid,
609 wm_client_leader_atom,
610 XA_WINDOW, 32, PropModeReplace,
611 (guchar*) &_gdk_leader_window, 1);
613 if (attributes_mask & GDK_WA_TITLE)
614 title = attributes->title;
616 title = g_get_prgname ();
618 gdk_window_set_title (window, title);
620 if (attributes_mask & GDK_WA_WMCLASS)
622 class_hint = XAllocClassHint ();
623 class_hint->res_name = attributes->wmclass_name;
624 class_hint->res_class = attributes->wmclass_class;
625 XSetClassHint (xdisplay, xid, class_hint);
633 * gdk_window_foreign_new:
634 * @anid: a native window handle.
636 * Wraps a native window in a #GdkWindow.
637 * This may fail if the window has been destroyed.
639 * For example in the X backend, a native window handle is an Xlib
642 * Return value: the newly-created #GdkWindow wrapper for the
643 * native window or %NULL if the window has been destroyed.
646 gdk_window_foreign_new (GdkNativeWindow anid)
649 GdkWindowObject *private;
650 GdkWindowImplX11 *impl;
651 GdkDrawableImplX11 *draw_impl;
652 XWindowAttributes attrs;
654 Window *children = NULL;
658 gdk_error_trap_push ();
659 result = XGetWindowAttributes (gdk_display, anid, &attrs);
660 if (gdk_error_trap_pop () || !result)
663 /* FIXME: This is pretty expensive. Maybe the caller should supply
665 gdk_error_trap_push ();
666 result = XQueryTree (gdk_display, anid, &root, &parent, &children, &nchildren);
667 if (gdk_error_trap_pop () || !result)
673 window = g_object_new (GDK_TYPE_WINDOW, NULL);
674 private = (GdkWindowObject *)window;
675 impl = GDK_WINDOW_IMPL_X11 (private->impl);
676 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
677 draw_impl->wrapper = GDK_DRAWABLE (window);
679 private->parent = gdk_xid_table_lookup (parent);
680 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
681 private->parent = (GdkWindowObject *)_gdk_parent_root;
683 private->parent->children = g_list_prepend (private->parent->children, window);
685 draw_impl->xid = anid;
686 draw_impl->xdisplay = gdk_display;
688 private->x = attrs.x;
689 private->y = attrs.y;
690 impl->width = attrs.width;
691 impl->height = attrs.height;
692 private->window_type = GDK_WINDOW_FOREIGN;
693 private->destroyed = FALSE;
695 if (attrs.map_state == IsUnmapped)
696 private->state = GDK_WINDOW_STATE_WITHDRAWN;
700 private->depth = attrs.depth;
702 _gdk_window_init_position (GDK_WINDOW (private));
704 gdk_drawable_ref (window);
705 gdk_xid_table_insert (&GDK_WINDOW_XID (window), window);
712 * @anid: a native window handle.
714 * Looks up the #GdkWindow that wraps the given native window handle.
716 * For example in the X backend, a native window handle is an Xlib
719 * Return value: the #GdkWindow wrapper for the native window,
720 * or %NULL if there is none.
723 gdk_window_lookup (GdkNativeWindow anid)
725 return (GdkWindow*) gdk_xid_table_lookup (anid);
729 _gdk_windowing_window_destroy (GdkWindow *window,
731 gboolean foreign_destroy)
733 GdkWindowObject *private = (GdkWindowObject *)window;
735 g_return_if_fail (GDK_IS_WINDOW (window));
737 _gdk_selection_window_destroyed (window);
739 if (private->extension_events != 0)
740 gdk_input_window_destroy (window);
744 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
746 if (draw_impl->picture)
747 XRenderFreePicture (draw_impl->xdisplay, draw_impl->picture);
749 #endif /* HAVE_XFT */
751 if (private->window_type == GDK_WINDOW_FOREIGN)
753 if (!foreign_destroy && (private->parent != NULL))
755 /* It's somebody else's window, but in our heirarchy,
756 * so reparent it to the root window, and then send
757 * it a delete event, as if we were a WM
759 XClientMessageEvent xevent;
761 gdk_error_trap_push ();
762 gdk_window_hide (window);
763 gdk_window_reparent (window, NULL, 0, 0);
765 xevent.type = ClientMessage;
766 xevent.window = GDK_WINDOW_XID (window);
767 xevent.message_type = gdk_x11_get_xatom_by_name ("WM_PROTOCOLS");
769 xevent.data.l[0] = gdk_x11_get_xatom_by_name ("WM_DELETE_WINDOW");
770 xevent.data.l[1] = CurrentTime;
772 XSendEvent (GDK_WINDOW_XDISPLAY (window),
773 GDK_WINDOW_XID (window),
774 False, 0, (XEvent *)&xevent);
776 gdk_error_trap_pop ();
779 else if (!recursing && !foreign_destroy)
780 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
783 /* This function is called when the XWindow is really gone.
786 gdk_window_destroy_notify (GdkWindow *window)
788 GdkWindowImplX11 *window_impl;
790 g_return_if_fail (window != NULL);
792 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
794 if (!GDK_WINDOW_DESTROYED (window))
796 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
797 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
799 _gdk_window_destroy (window, TRUE);
802 gdk_xid_table_remove (GDK_WINDOW_XID (window));
803 if (window_impl->focus_window)
804 gdk_xid_table_remove (window_impl->focus_window);
806 gdk_drawable_unref (window);
810 set_initial_hints (GdkWindow *window)
812 GdkWindowObject *private;
816 private = (GdkWindowObject*) window;
818 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
822 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
823 GDK_WINDOW_XID (window));
825 wm_hints = XAllocWMHints ();
827 wm_hints->flags |= StateHint;
828 wm_hints->initial_state = IconicState;
830 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
831 GDK_WINDOW_XID (window), wm_hints);
835 /* We set the spec hints regardless of whether the spec is supported,
836 * since it can't hurt and it's kind of expensive to check whether
842 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
844 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MAXIMIZED_VERT");
846 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MAXIMIZED_HORZ");
850 if (private->state & GDK_WINDOW_STATE_STICKY)
852 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_STICKY");
856 if (private->modal_hint)
858 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MODAL");
864 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
865 GDK_WINDOW_XID (window),
866 gdk_x11_get_xatom_by_name ("_NET_WM_STATE"),
867 XA_ATOM, 32, PropModeReplace,
871 if (private->state & GDK_WINDOW_STATE_STICKY)
873 atoms[0] = 0xFFFFFFFF;
874 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
875 GDK_WINDOW_XID (window),
876 gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP"),
877 XA_CARDINAL, 32, PropModeReplace,
883 show_window_internal (GdkWindow *window,
886 GdkWindowObject *private;
888 g_return_if_fail (GDK_IS_WINDOW (window));
890 private = (GdkWindowObject*) window;
891 if (!private->destroyed)
894 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
895 GDK_WINDOW_XID (window));
897 if (!GDK_WINDOW_IS_MAPPED (window))
899 set_initial_hints (window);
901 gdk_synthesize_window_state (window,
902 GDK_WINDOW_STATE_WITHDRAWN,
906 g_assert (GDK_WINDOW_IS_MAPPED (window));
908 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
909 XMapWindow (GDK_WINDOW_XDISPLAY (window),
910 GDK_WINDOW_XID (window));
915 * gdk_window_show_unraised:
916 * @window: a #GdkWindow
918 * Shows a #GdkWindow onscreen, but does not modify its stacking
919 * order. In contrast, gdk_window_show() will raise the window
920 * to the top of the window stack.
922 * On the X11 platform, in Xlib terms, this function calls
923 * XMapWindow() (it also updates some internal GDK state, which means
924 * that you can't really use XMapWindow() directly on a GDK window).
928 gdk_window_show_unraised (GdkWindow *window)
930 g_return_if_fail (GDK_IS_WINDOW (window));
932 show_window_internal (window, FALSE);
937 * @window: a #GdkWindow
939 * Like gdk_window_show_unraised(), but also raises the window to the
940 * top of the window stack (moves the window to the front of the
943 * This function maps a window so it's visible onscreen. Its opposite
944 * is gdk_window_hide().
946 * When implementing a #GtkWidget, you should call this function on the widget's
947 * #GdkWindow as part of the "map" method.
951 gdk_window_show (GdkWindow *window)
953 g_return_if_fail (GDK_IS_WINDOW (window));
955 show_window_internal (window, TRUE);
960 * @window: a #GdkWindow
962 * For toplevel windows, withdraws them, so they will no longer be
963 * known to the window manager; for all windows, unmaps them, so
964 * they won't be displayed. Normally done automatically as
965 * part of gtk_widget_hide().
969 gdk_window_hide (GdkWindow *window)
971 GdkWindowObject *private;
973 g_return_if_fail (window != NULL);
975 private = (GdkWindowObject*) window;
977 /* You can't simply unmap toplevel windows. */
978 switch (private->window_type)
980 case GDK_WINDOW_TOPLEVEL:
981 case GDK_WINDOW_DIALOG:
982 case GDK_WINDOW_TEMP: /* ? */
983 gdk_window_withdraw (window);
987 case GDK_WINDOW_FOREIGN:
988 case GDK_WINDOW_ROOT:
989 case GDK_WINDOW_CHILD:
993 if (!private->destroyed)
995 if (GDK_WINDOW_IS_MAPPED (window))
996 gdk_synthesize_window_state (window,
998 GDK_WINDOW_STATE_WITHDRAWN);
1000 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1002 _gdk_window_clear_update_area (window);
1004 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1005 GDK_WINDOW_XID (window));
1010 * gdk_window_withdraw:
1011 * @window: a toplevel #GdkWindow
1013 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1014 * Normally done automatically by gtk_widget_hide() called on a #GtkWindow.
1018 gdk_window_withdraw (GdkWindow *window)
1020 GdkWindowObject *private;
1022 g_return_if_fail (window != NULL);
1024 private = (GdkWindowObject*) window;
1025 if (!private->destroyed)
1027 if (GDK_WINDOW_IS_MAPPED (window))
1028 gdk_synthesize_window_state (window,
1030 GDK_WINDOW_STATE_WITHDRAWN);
1032 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1034 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1035 GDK_WINDOW_XID (window), 0);
1041 * @window: a #GdkWindow
1042 * @x: X coordinate relative to window's parent
1043 * @y: Y coordinate relative to window's parent
1045 * Repositions a window relative to its parent window.
1046 * For toplevel windows, window managers may ignore or modify the move;
1047 * you should probably use gtk_window_move() on a #GtkWindow widget
1048 * anyway, instead of using GDK functions. For child windows,
1049 * the move will reliably succeed.
1051 * If you're also planning to resize the window, use gdk_window_move_resize()
1052 * to both move and resize simultaneously, for a nicer visual effect.
1056 gdk_window_move (GdkWindow *window,
1060 GdkWindowObject *private = (GdkWindowObject *)window;
1061 GdkWindowImplX11 *impl;
1063 g_return_if_fail (window != NULL);
1064 g_return_if_fail (GDK_IS_WINDOW (window));
1066 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1068 if (!GDK_WINDOW_DESTROYED (window))
1070 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1071 _gdk_window_move_resize_child (window, x, y,
1072 impl->width, impl->height);
1075 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1076 GDK_WINDOW_XID (window),
1083 * gdk_window_resize:
1084 * @window: a #GdkWindow
1085 * @width: new width of the window
1086 * @height: new height of the window
1088 * Resizes @window; for toplevel windows, asks the window manager to resize
1089 * the window. The window manager may not allow the resize. When using GTK+,
1090 * use gtk_window_resize() instead of this low-level GDK function.
1092 * Windows may not be resized below 1x1.
1094 * If you're also planning to move the window, use gdk_window_move_resize()
1095 * to both move and resize simultaneously, for a nicer visual effect.
1099 gdk_window_resize (GdkWindow *window,
1103 GdkWindowObject *private;
1105 g_return_if_fail (window != NULL);
1106 g_return_if_fail (GDK_IS_WINDOW (window));
1113 private = (GdkWindowObject*) window;
1115 if (!GDK_WINDOW_DESTROYED (window))
1117 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1118 _gdk_window_move_resize_child (window, private->x, private->y,
1122 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1124 if (width != impl->width || height != impl->height)
1125 private->resize_count += 1;
1127 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1128 GDK_WINDOW_XID (window),
1135 * gdk_window_move_resize:
1136 * @window: a #GdkWindow
1137 * @x: new X position relative to window's parent
1138 * @y: new Y position relative to window's parent
1140 * @height: new height
1142 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1143 * except that both operations are performed at once, avoiding strange
1144 * visual effects. (i.e. the user may be able to see the window first
1145 * move, then resize, if youu don't use gdk_window_move_resize().)
1149 gdk_window_move_resize (GdkWindow *window,
1155 GdkWindowObject *private;
1157 g_return_if_fail (window != NULL);
1158 g_return_if_fail (GDK_IS_WINDOW (window));
1165 private = (GdkWindowObject*) window;
1167 if (!GDK_WINDOW_DESTROYED (window))
1169 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1170 _gdk_window_move_resize_child (window, x, y, width, height);
1173 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1175 if (width != impl->width || height != impl->height)
1176 private->resize_count += 1;
1178 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1179 GDK_WINDOW_XID (window),
1180 x, y, width, height);
1186 * gdk_window_reparent:
1187 * @window: a #GdkWindow
1188 * @new_parent: new parent to move @window into
1189 * @x: X location inside the new parent
1190 * @y: Y location inside the new parent
1192 * Reparents @window into the given @new_parent. The window being
1193 * reparented will be unmapped as a side effect.
1197 gdk_window_reparent (GdkWindow *window,
1198 GdkWindow *new_parent,
1202 GdkWindowObject *window_private;
1203 GdkWindowObject *parent_private;
1204 GdkWindowObject *old_parent_private;
1206 g_return_if_fail (window != NULL);
1207 g_return_if_fail (GDK_IS_WINDOW (window));
1208 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1209 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1212 new_parent = _gdk_parent_root;
1214 window_private = (GdkWindowObject*) window;
1215 old_parent_private = (GdkWindowObject*)window_private->parent;
1216 parent_private = (GdkWindowObject*) new_parent;
1218 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1219 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1220 GDK_WINDOW_XID (window),
1221 GDK_WINDOW_XID (new_parent),
1224 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1227 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1228 new_parent = _gdk_parent_root;
1230 window_private->parent = (GdkWindowObject *)new_parent;
1232 /* Switch the window type as appropriate */
1234 switch (GDK_WINDOW_TYPE (new_parent))
1236 case GDK_WINDOW_ROOT:
1237 case GDK_WINDOW_FOREIGN:
1238 /* Now a toplevel */
1239 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1241 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1242 XSetWMProtocols (GDK_WINDOW_XDISPLAY (window),
1243 GDK_WINDOW_XID (window),
1244 _gdk_wm_window_protocols, 3);
1246 case GDK_WINDOW_TOPLEVEL:
1247 case GDK_WINDOW_CHILD:
1248 case GDK_WINDOW_DIALOG:
1249 case GDK_WINDOW_TEMP:
1250 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1251 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1253 /* If we were being sophisticated, we'd save the old window type
1254 * here, and restore it if we were reparented back to the
1255 * toplevel. However, the difference between different types
1256 * of toplevels only really matters on creation anyways.
1258 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1262 if (old_parent_private)
1263 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1265 if ((old_parent_private &&
1266 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1267 (!old_parent_private && parent_private->guffaw_gravity))
1268 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1270 parent_private->children = g_list_prepend (parent_private->children, window);
1271 _gdk_window_init_position (GDK_WINDOW (window_private));
1275 _gdk_windowing_window_clear_area (GdkWindow *window,
1281 g_return_if_fail (window != NULL);
1282 g_return_if_fail (GDK_IS_WINDOW (window));
1284 if (!GDK_WINDOW_DESTROYED (window))
1285 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1286 x, y, width, height, False);
1290 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1296 g_return_if_fail (window != NULL);
1297 g_return_if_fail (GDK_IS_WINDOW (window));
1299 if (!GDK_WINDOW_DESTROYED (window))
1300 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1301 x, y, width, height, True);
1307 * @window: a #GdkWindow
1309 * Raises @window to the top of the Z-order (stacking order), so that
1310 * other windows with the same parent window appear below @window.
1311 * If @window is a toplevel, the window manager may choose to deny the
1312 * request to move the window in the Z-order, gdk_window_raise() only
1313 * requests the restack, does not guarantee it.
1317 gdk_window_raise (GdkWindow *window)
1319 g_return_if_fail (window != NULL);
1320 g_return_if_fail (GDK_IS_WINDOW (window));
1322 if (!GDK_WINDOW_DESTROYED (window))
1323 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1328 * @window: a #GdkWindow
1330 * Lowers @window to the bottom of the Z-order (stacking order), so that
1331 * other windows with the same parent window appear above @window.
1332 * If @window is a toplevel, the window manager may choose to deny the
1333 * request to move the window in the Z-order, gdk_window_lower() only
1334 * requests the restack, does not guarantee it.
1336 * Note that gdk_window_show() raises the window again, so don't call this
1337 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1341 gdk_window_lower (GdkWindow *window)
1343 g_return_if_fail (window != NULL);
1344 g_return_if_fail (GDK_IS_WINDOW (window));
1346 if (!GDK_WINDOW_DESTROYED (window))
1347 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1352 * @window: a #GdkWindow
1353 * @timestamp: timestamp of the event triggering the window focus
1355 * Sets keyboard focus to @window. If @window is not onscreen this
1356 * will not work. In most cases, gtk_window_present() should be used on
1357 * a #GtkWindow, rather than calling this function.
1361 gdk_window_focus (GdkWindow *window,
1364 g_return_if_fail (GDK_IS_WINDOW (window));
1366 if (GDK_WINDOW_DESTROYED (window))
1369 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1373 xev.xclient.type = ClientMessage;
1374 xev.xclient.serial = 0;
1375 xev.xclient.send_event = True;
1376 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1377 xev.xclient.display = gdk_display;
1378 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW");
1379 xev.xclient.format = 32;
1380 xev.xclient.data.l[0] = 0;
1382 XSendEvent (gdk_display, _gdk_root_window, False,
1383 SubstructureRedirectMask | SubstructureNotifyMask,
1388 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1390 /* There is no way of knowing reliably whether we are viewable so we need
1391 * to trap errors so we don't cause a BadMatch.
1393 gdk_error_trap_push ();
1394 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1395 GDK_WINDOW_XWINDOW (window),
1398 XSync (GDK_WINDOW_XDISPLAY (window), False);
1399 gdk_error_trap_pop ();
1404 * gdk_window_set_hints:
1405 * @window: a #GdkWindow
1406 * @x: ignored field, does not matter
1407 * @y: ignored field, does not matter
1408 * @min_width: minimum width hint
1409 * @min_height: minimum height hint
1410 * @max_width: max width hint
1411 * @max_height: max height hint
1412 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1414 * This function is broken and useless and you should ignore it.
1415 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1416 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1417 * depending on what you're trying to do.
1419 * If using GDK directly, use gdk_window_set_geometry_hints().
1423 gdk_window_set_hints (GdkWindow *window,
1432 XSizeHints size_hints;
1434 g_return_if_fail (window != NULL);
1435 g_return_if_fail (GDK_IS_WINDOW (window));
1437 if (GDK_WINDOW_DESTROYED (window))
1440 size_hints.flags = 0;
1442 if (flags & GDK_HINT_POS)
1444 size_hints.flags |= PPosition;
1449 if (flags & GDK_HINT_MIN_SIZE)
1451 size_hints.flags |= PMinSize;
1452 size_hints.min_width = min_width;
1453 size_hints.min_height = min_height;
1456 if (flags & GDK_HINT_MAX_SIZE)
1458 size_hints.flags |= PMaxSize;
1459 size_hints.max_width = max_width;
1460 size_hints.max_height = max_height;
1463 /* FIXME: Would it be better to delete this property if
1464 * flags == 0? It would save space on the server
1466 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1467 GDK_WINDOW_XID (window),
1472 * gdk_window_set_type_hint:
1473 * @window: A #GdkWindow
1474 * @hint: A hint of the function this window will have
1476 * The application can use this call to provide a hint to the window
1477 * manager about the functionality of a window. The window manager
1478 * can use this information when determining the decoration and behaviour
1481 * The hint must be set before the window is mapped.
1484 gdk_window_set_type_hint (GdkWindow *window,
1485 GdkWindowTypeHint hint)
1489 g_return_if_fail (window != NULL);
1490 g_return_if_fail (GDK_IS_WINDOW (window));
1492 if (GDK_WINDOW_DESTROYED (window))
1497 case GDK_WINDOW_TYPE_HINT_DIALOG:
1498 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_DIALOG");
1500 case GDK_WINDOW_TYPE_HINT_MENU:
1501 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_MENU");
1503 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1504 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_TOOLBAR");
1507 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1509 case GDK_WINDOW_TYPE_HINT_NORMAL:
1510 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_NORMAL");
1514 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1515 GDK_WINDOW_XID (window),
1516 gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE"),
1517 XA_ATOM, 32, PropModeReplace,
1518 (guchar *)&atom, 1);
1523 gdk_wmspec_change_state (gboolean add,
1530 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1531 #define _NET_WM_STATE_ADD 1 /* add/set property */
1532 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1534 xev.xclient.type = ClientMessage;
1535 xev.xclient.serial = 0;
1536 xev.xclient.send_event = True;
1537 xev.xclient.display = gdk_display;
1538 xev.xclient.window = GDK_WINDOW_XID (window);
1539 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_STATE");
1540 xev.xclient.format = 32;
1541 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1542 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom (state1);
1543 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom (state2);
1545 XSendEvent (gdk_display, _gdk_root_window, False,
1546 SubstructureRedirectMask | SubstructureNotifyMask,
1550 * gdk_window_set_modal_hint:
1551 * @window: A #GdkWindow
1552 * @modal: TRUE if the window is modal, FALSE otherwise.
1554 * The application can use this hint to tell the window manager
1555 * that a certain window has modal behaviour. The window manager
1556 * can use this information to handle modal windows in a special
1559 * You should only use this on windows for which you have
1560 * previously called #gdk_window_set_transient_for()
1563 gdk_window_set_modal_hint (GdkWindow *window,
1566 GdkWindowObject *private;
1568 g_return_if_fail (window != NULL);
1569 g_return_if_fail (GDK_IS_WINDOW (window));
1571 if (GDK_WINDOW_DESTROYED (window))
1574 private = (GdkWindowObject*) window;
1576 private->modal_hint = modal;
1578 if (GDK_WINDOW_IS_MAPPED (window))
1579 gdk_wmspec_change_state (modal, window,
1580 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1585 * gdk_window_set_geometry_hints:
1586 * @window: a #GdkWindow
1587 * @geometry: geometry hints
1588 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1590 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1591 * are set, hints not flagged in @geom_mask are unset.
1592 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1596 gdk_window_set_geometry_hints (GdkWindow *window,
1597 GdkGeometry *geometry,
1598 GdkWindowHints geom_mask)
1600 XSizeHints size_hints;
1602 g_return_if_fail (window != NULL);
1603 g_return_if_fail (GDK_IS_WINDOW (window));
1605 if (GDK_WINDOW_DESTROYED (window))
1608 size_hints.flags = 0;
1610 if (geom_mask & GDK_HINT_POS)
1612 size_hints.flags |= PPosition;
1613 /* We need to initialize the following obsolete fields because KWM
1614 * apparently uses these fields if they are non-zero.
1621 if (geom_mask & GDK_HINT_USER_POS)
1623 size_hints.flags |= USPosition;
1626 if (geom_mask & GDK_HINT_USER_SIZE)
1628 size_hints.flags |= USSize;
1631 if (geom_mask & GDK_HINT_MIN_SIZE)
1633 size_hints.flags |= PMinSize;
1634 size_hints.min_width = geometry->min_width;
1635 size_hints.min_height = geometry->min_height;
1638 if (geom_mask & GDK_HINT_MAX_SIZE)
1640 size_hints.flags |= PMaxSize;
1641 size_hints.max_width = MAX (geometry->max_width, 1);
1642 size_hints.max_height = MAX (geometry->max_height, 1);
1645 if (geom_mask & GDK_HINT_BASE_SIZE)
1647 size_hints.flags |= PBaseSize;
1648 size_hints.base_width = geometry->base_width;
1649 size_hints.base_height = geometry->base_height;
1652 if (geom_mask & GDK_HINT_RESIZE_INC)
1654 size_hints.flags |= PResizeInc;
1655 size_hints.width_inc = geometry->width_inc;
1656 size_hints.height_inc = geometry->height_inc;
1659 if (geom_mask & GDK_HINT_ASPECT)
1661 size_hints.flags |= PAspect;
1662 if (geometry->min_aspect <= 1)
1664 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1665 size_hints.min_aspect.y = 65536;
1669 size_hints.min_aspect.x = 65536;
1670 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1672 if (geometry->max_aspect <= 1)
1674 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1675 size_hints.max_aspect.y = 65536;
1679 size_hints.max_aspect.x = 65536;
1680 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1684 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1686 size_hints.flags |= PWinGravity;
1687 size_hints.win_gravity = geometry->win_gravity;
1690 /* FIXME: Would it be better to delete this property if
1691 * geom_mask == 0? It would save space on the server
1693 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1694 GDK_WINDOW_XID (window),
1699 gdk_window_get_geometry_hints (GdkWindow *window,
1700 GdkGeometry *geometry,
1701 GdkWindowHints *geom_mask)
1703 XSizeHints size_hints;
1704 glong junk_size_mask = 0;
1706 g_return_if_fail (GDK_IS_WINDOW (window));
1707 g_return_if_fail (geometry != NULL);
1708 g_return_if_fail (geom_mask != NULL);
1712 if (GDK_WINDOW_DESTROYED (window))
1715 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1716 GDK_WINDOW_XID (window),
1721 if (size_hints.flags & PMinSize)
1723 *geom_mask |= GDK_HINT_MIN_SIZE;
1724 geometry->min_width = size_hints.min_width;
1725 geometry->min_height = size_hints.min_height;
1728 if (size_hints.flags & PMaxSize)
1730 *geom_mask |= GDK_HINT_MAX_SIZE;
1731 geometry->max_width = MAX (size_hints.max_width, 1);
1732 geometry->max_height = MAX (size_hints.max_height, 1);
1735 if (size_hints.flags & PResizeInc)
1737 *geom_mask |= GDK_HINT_RESIZE_INC;
1738 geometry->width_inc = size_hints.width_inc;
1739 geometry->height_inc = size_hints.height_inc;
1742 if (size_hints.flags & PAspect)
1744 *geom_mask |= GDK_HINT_ASPECT;
1746 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
1747 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
1750 if (size_hints.flags & PWinGravity)
1752 *geom_mask |= GDK_HINT_WIN_GRAVITY;
1753 geometry->win_gravity = size_hints.win_gravity;
1758 utf8_is_latin1 (const gchar *str)
1760 const char *p = str;
1764 gunichar ch = g_utf8_get_char (p);
1769 p = g_utf8_next_char (p);
1775 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
1776 * convertable to STRING, otherwise, set it as compound text
1779 set_text_property (GdkWindow *window,
1781 const gchar *utf8_str)
1783 guchar *prop_text = NULL;
1788 if (utf8_is_latin1 (utf8_str))
1790 prop_type = XA_STRING;
1791 prop_text = gdk_utf8_to_string_target (utf8_str);
1792 prop_length = strlen (prop_text);
1799 gdk_utf8_to_compound_text (utf8_str, &gdk_type, &prop_format,
1800 &prop_text, &prop_length);
1801 prop_type = gdk_x11_atom_to_xatom (gdk_type);
1806 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1807 GDK_WINDOW_XID (window),
1809 prop_type, prop_format,
1810 PropModeReplace, prop_text,
1818 * gdk_window_set_title:
1819 * @window: a #GdkWindow
1820 * @title: title of @window
1822 * Sets the title of a toplevel window, to be displayed in the titlebar.
1823 * If you haven't explicitly set the icon name for the window
1824 * (using gdk_window_set_icon_name()), the icon name will be set to
1825 * @title as well. @title must be in UTF-8 encoding (as with all
1826 * user-readable strings in GDK/GTK+). @title may not be %NULL.
1830 gdk_window_set_title (GdkWindow *window,
1833 g_return_if_fail (window != NULL);
1834 g_return_if_fail (GDK_IS_WINDOW (window));
1835 g_return_if_fail (title != NULL);
1837 if (GDK_WINDOW_DESTROYED (window))
1840 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1841 GDK_WINDOW_XID (window),
1842 gdk_x11_get_xatom_by_name ("_NET_WM_NAME"),
1843 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
1844 PropModeReplace, title,
1847 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_NAME"), title);
1848 if (!gdk_window_icon_name_set (window))
1850 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1851 GDK_WINDOW_XID (window),
1852 gdk_x11_get_xatom_by_name ("_NET_WM_ICON_NAME"),
1853 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
1854 PropModeReplace, title,
1856 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_ICON_NAME"), title);
1861 * gdk_window_set_role:
1862 * @window: a #GdkWindow
1863 * @role: a string indicating its role
1865 * When using GTK+, typically you should use gtk_window_set_role() instead
1866 * of this low-level function.
1868 * The window manager and session manager use a window's role to
1869 * distinguish it from other kinds of window in the same application.
1870 * When an application is restarted after being saved in a previous
1871 * session, all windows with the same title and role are treated as
1872 * interchangeable. So if you have two windows with the same title
1873 * that should be distinguished for session management purposes, you
1874 * should set the role on those windows. It doesn't matter what string
1875 * you use for the role, as long as you have a different role for each
1876 * non-interchangeable kind of window.
1880 gdk_window_set_role (GdkWindow *window,
1883 g_return_if_fail (window != NULL);
1884 g_return_if_fail (GDK_IS_WINDOW (window));
1886 if (!GDK_WINDOW_DESTROYED (window))
1889 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1890 gdk_x11_get_xatom_by_name ("WM_WINDOW_ROLE"), XA_STRING,
1891 8, PropModeReplace, role, strlen (role));
1893 XDeleteProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1894 gdk_x11_get_xatom_by_name ("WM_WINDOW_ROLE"));
1899 * gdk_window_set_transient_for:
1900 * @window: a toplevel #GdkWindow
1901 * @parent: another toplevel #GdkWindow
1903 * Indicates to the window manager that @window is a transient dialog
1904 * associated with the application window @parent. This allows the
1905 * window manager to do things like center @window on @parent and
1906 * keep @window above @parent.
1908 * See gtk_window_set_transient_for() if you're using #GtkWindow or
1913 gdk_window_set_transient_for (GdkWindow *window,
1916 GdkWindowObject *private;
1917 GdkWindowObject *parent_private;
1919 g_return_if_fail (window != NULL);
1920 g_return_if_fail (GDK_IS_WINDOW (window));
1922 private = (GdkWindowObject*) window;
1923 parent_private = (GdkWindowObject*) parent;
1925 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
1926 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
1927 GDK_WINDOW_XID (window),
1928 GDK_WINDOW_XID (parent));
1932 * gdk_window_set_background:
1933 * @window: a #GdkWindow
1934 * @color: an allocated #GdkColor
1936 * Sets the background color of @window. (However, when using GTK+,
1937 * set the background of a widget with gtk_widget_modify_bg() - if
1938 * you're an application - or gtk_style_set_background() - if you're
1939 * implementing a custom widget.)
1941 * The @color must be allocated; gdk_rgb_find_color() is the best way
1942 * to allocate a color.
1944 * See also gdk_window_set_back_pixmap().
1948 gdk_window_set_background (GdkWindow *window,
1951 GdkWindowObject *private = (GdkWindowObject *)window;
1953 g_return_if_fail (window != NULL);
1954 g_return_if_fail (GDK_IS_WINDOW (window));
1956 if (!GDK_WINDOW_DESTROYED (window))
1957 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
1958 GDK_WINDOW_XID (window), color->pixel);
1960 private->bg_color = *color;
1962 if (private->bg_pixmap &&
1963 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1964 private->bg_pixmap != GDK_NO_BG)
1965 gdk_pixmap_unref (private->bg_pixmap);
1967 private->bg_pixmap = NULL;
1971 * gdk_window_set_back_pixmap:
1972 * @window: a #GdkWindow
1973 * @pixmap: a #GdkPixmap, or %NULL
1974 * @parent_relative: whether the tiling origin is at the origin of @window's parent
1976 * Sets the background pixmap of @window. May also be used to set a background of
1977 * "None" on @window, by setting a background pixmap of %NULL.
1978 * A background pixmap will be tiled, positioning the first tile at the origin of
1979 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
1980 * origin of the parent window (useful to align tiles in a parent with tiles
1983 * A background pixmap of %NULL means that the window will have no
1984 * background. A window with no background will never have its
1985 * background filled by the windowing system, instead the window will
1986 * contain whatever pixels were already in the corresponding area of
1989 * The windowing system will normally fill a window with its background
1990 * when the window is obscured then exposed, and when you call
1991 * gdk_window_clear().
1995 gdk_window_set_back_pixmap (GdkWindow *window,
1997 gboolean parent_relative)
1999 GdkWindowObject *private = (GdkWindowObject *)window;
2002 g_return_if_fail (window != NULL);
2003 g_return_if_fail (GDK_IS_WINDOW (window));
2004 g_return_if_fail (pixmap == NULL || !parent_relative);
2006 if (private->bg_pixmap &&
2007 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2008 private->bg_pixmap != GDK_NO_BG)
2009 gdk_pixmap_unref (private->bg_pixmap);
2011 if (parent_relative)
2013 xpixmap = ParentRelative;
2014 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2020 gdk_pixmap_ref (pixmap);
2021 private->bg_pixmap = pixmap;
2022 xpixmap = GDK_PIXMAP_XID (pixmap);
2027 private->bg_pixmap = GDK_NO_BG;
2031 if (!GDK_WINDOW_DESTROYED (window))
2032 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2033 GDK_WINDOW_XID (window), xpixmap);
2037 * gdk_window_set_cursor:
2038 * @window: a #GdkWindow
2041 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2042 * gdk_cursor_new_from_pixmap() to create the cursor.
2043 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2044 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2045 * to gdk_window_set_cursor() means that @window will use the cursor of
2046 * its parent window. Most windows should use this default.
2050 gdk_window_set_cursor (GdkWindow *window,
2053 GdkCursorPrivate *cursor_private;
2056 g_return_if_fail (window != NULL);
2057 g_return_if_fail (GDK_IS_WINDOW (window));
2059 cursor_private = (GdkCursorPrivate*) cursor;
2064 xcursor = cursor_private->xcursor;
2066 if (!GDK_WINDOW_DESTROYED (window))
2067 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2068 GDK_WINDOW_XID (window),
2073 * gdk_window_get_geometry:
2074 * @window: a #GdkWindow
2075 * @x: return location for X coordinate of window (relative to its parent)
2076 * @y: return location for Y coordinate of window (relative to its parent)
2077 * @width: return location for width of window
2078 * @height: return location for height of window
2079 * @depth: return location for bit depth of window
2081 * Any of the return location arguments to this function may be %NULL,
2082 * if you aren't interested in getting the value of that field.
2084 * The X and Y coordinates returned are relative to the parent window
2085 * of @window, which for toplevels usually means relative to the
2086 * window decorations (titlebar, etc.) rather than relative to the
2087 * root window (screen-size background window).
2089 * On the X11 platform, the geometry is obtained from the X server,
2090 * so reflects the latest position of @window; this may be out-of-sync
2091 * with the position of @window delivered in the most-recently-processed
2092 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2093 * position from the most recent configure event.
2097 gdk_window_get_geometry (GdkWindow *window,
2109 guint tborder_width;
2112 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2115 window = _gdk_parent_root;
2117 if (!GDK_WINDOW_DESTROYED (window))
2119 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2120 GDK_WINDOW_XID (window),
2121 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2137 * gdk_window_get_origin:
2138 * @window: a #GdkWindow
2139 * @x: return location for X coordinate
2140 * @y: return location for Y coordinate
2142 * Obtains the position of a window in root window coordinates.
2143 * (Compare with gdk_window_get_position() and
2144 * gdk_window_get_geometry() which return the position of a window
2145 * relative to its parent window.)
2147 * Return value: not meaningful, ignore
2150 gdk_window_get_origin (GdkWindow *window,
2159 g_return_val_if_fail (window != NULL, 0);
2161 if (!GDK_WINDOW_DESTROYED (window))
2163 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2164 GDK_WINDOW_XID (window),
2182 * gdk_window_get_deskrelative_origin:
2183 * @window: a #GdkWindow
2184 * @x: return location for X coordinate
2185 * @y: return location for Y coordinate
2187 * This gets the origin of a #GdkWindow relative to
2188 * an Enlightenment-window-manager desktop. As long as you don't
2189 * assume that the user's desktop/workspace covers the entire
2190 * root window (i.e. you don't assume that the desktop begins
2191 * at root window coordinate 0,0) this function is not necessary.
2192 * It's deprecated for that reason.
2194 * Return value: not meaningful
2197 gdk_window_get_deskrelative_origin (GdkWindow *window,
2201 gboolean return_val = FALSE;
2202 gint num_children, format_return;
2203 Window win, *child, parent, root;
2207 static Atom atom = 0;
2208 gulong number_return, bytes_after_return;
2209 guchar *data_return;
2211 g_return_val_if_fail (window != NULL, 0);
2212 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2214 if (!GDK_WINDOW_DESTROYED (window))
2217 atom = gdk_x11_get_xatom_by_name ("ENLIGHTENMENT_DESKTOP");
2218 win = GDK_WINDOW_XID (window);
2220 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2221 &child, (unsigned int *)&num_children))
2223 if ((child) && (num_children > 0))
2235 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2236 False, XA_CARDINAL, &type_return, &format_return,
2237 &number_return, &bytes_after_return, &data_return);
2238 if (type_return == XA_CARDINAL)
2240 XFree (data_return);
2245 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2246 GDK_WINDOW_XID (window),
2261 * gdk_window_get_root_origin:
2262 * @window: a #GdkWindow
2263 * @x: return location for X position of window frame
2264 * @y: return location for Y position of window frame
2266 * Obtains the top-left corner of the window manager frame in root
2267 * window coordinates.
2271 gdk_window_get_root_origin (GdkWindow *window,
2277 g_return_if_fail (GDK_IS_WINDOW (window));
2279 gdk_window_get_frame_extents (window, &rect);
2289 * gdk_window_get_frame_extents:
2290 * @window: a #GdkWindow
2291 * @rect: rectangle to fill with bounding box of the window frame
2293 * Obtains the bounding box of the window, including window manager
2294 * titlebar/borders if any. The frame position is given in root window
2295 * coordinates. To get the position of the window itself (rather than
2296 * the frame) in root window coordinates, use gdk_window_get_origin().
2300 gdk_window_get_frame_extents (GdkWindow *window,
2303 GdkWindowObject *private;
2308 unsigned int nchildren;
2310 g_return_if_fail (GDK_IS_WINDOW (window));
2311 g_return_if_fail (rect != NULL);
2313 private = (GdkWindowObject*) window;
2320 if (GDK_WINDOW_DESTROYED (window))
2323 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2324 private = (GdkWindowObject*) private->parent;
2325 if (GDK_WINDOW_DESTROYED (window))
2328 xparent = GDK_WINDOW_XID (window);
2332 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2334 &children, &nchildren))
2340 while (xparent != root);
2342 if (xparent == root)
2344 unsigned int ww, wh, wb, wd;
2347 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2358 _gdk_windowing_window_get_pointer (GdkWindow *window,
2361 GdkModifierType *mask)
2363 GdkWindow *return_val;
2369 unsigned int xmask = 0;
2370 gint xoffset, yoffset;
2372 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2375 window = _gdk_parent_root;
2377 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2380 if (!GDK_WINDOW_DESTROYED (window) &&
2381 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2382 GDK_WINDOW_XID (window),
2383 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2386 return_val = gdk_window_lookup (child);
2390 *x = winx + xoffset;
2392 *y = winy + yoffset;
2400 _gdk_windowing_window_at_pointer (GdkScreen *screen,
2407 Window xwindow_last = 0;
2409 int rootx = -1, rooty = -1;
2413 xwindow = GDK_ROOT_WINDOW ();
2414 xdisplay = GDK_DISPLAY ();
2416 gdk_x11_grab_server ();
2419 xwindow_last = xwindow;
2420 XQueryPointer (xdisplay, xwindow,
2426 gdk_x11_ungrab_server ();
2428 window = gdk_window_lookup (xwindow_last);
2431 *win_x = window ? winx : -1;
2433 *win_y = window ? winy : -1;
2439 * gdk_window_get_events:
2440 * @window: a #GdkWindow
2442 * Gets the event mask for @window. See gdk_window_set_events().
2444 * Return value: event mask for @window
2447 gdk_window_get_events (GdkWindow *window)
2449 XWindowAttributes attrs;
2450 GdkEventMask event_mask;
2453 g_return_val_if_fail (window != NULL, 0);
2454 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2456 if (GDK_WINDOW_DESTROYED (window))
2460 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2461 GDK_WINDOW_XID (window),
2465 for (i = 0; i < _gdk_nenvent_masks; i++)
2467 if (attrs.your_event_mask & _gdk_event_mask_table[i])
2468 event_mask |= 1 << (i + 1);
2471 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2478 * gdk_window_set_events:
2479 * @window: a #GdkWindow
2480 * @event_mask: event mask for @window
2482 * The event mask for a window determines which events will be reported
2483 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2484 * means the window should report button press events. The event mask
2485 * is the bitwise OR of values from the #GdkEventMask enumeration.
2489 gdk_window_set_events (GdkWindow *window,
2490 GdkEventMask event_mask)
2495 g_return_if_fail (window != NULL);
2496 g_return_if_fail (GDK_IS_WINDOW (window));
2498 if (!GDK_WINDOW_DESTROYED (window))
2500 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2501 xevent_mask = StructureNotifyMask;
2502 for (i = 0; i < _gdk_nenvent_masks; i++)
2504 if (event_mask & (1 << (i + 1)))
2505 xevent_mask |= _gdk_event_mask_table[i];
2508 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2509 GDK_WINDOW_XID (window),
2515 gdk_window_add_colormap_windows (GdkWindow *window)
2517 GdkWindow *toplevel;
2518 Window *old_windows;
2519 Window *new_windows;
2522 g_return_if_fail (window != NULL);
2523 g_return_if_fail (GDK_IS_WINDOW (window));
2525 toplevel = gdk_window_get_toplevel (window);
2526 if (GDK_WINDOW_DESTROYED (toplevel))
2530 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2531 GDK_WINDOW_XID (toplevel),
2532 &old_windows, &count))
2537 for (i = 0; i < count; i++)
2538 if (old_windows[i] == GDK_WINDOW_XID (window))
2540 XFree (old_windows);
2544 new_windows = g_new (Window, count + 1);
2546 for (i = 0; i < count; i++)
2547 new_windows[i] = old_windows[i];
2548 new_windows[count] = GDK_WINDOW_XID (window);
2550 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2551 GDK_WINDOW_XID (toplevel),
2552 new_windows, count + 1);
2554 g_free (new_windows);
2556 XFree (old_windows);
2560 gdk_window_have_shape_ext (void)
2562 enum { UNKNOWN, NO, YES };
2563 static gint have_shape = UNKNOWN;
2565 if (have_shape == UNKNOWN)
2568 if (XQueryExtension (gdk_display, "SHAPE", &ignore, &ignore, &ignore))
2574 return (have_shape == YES);
2577 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2580 * This needs the X11 shape extension.
2581 * If not available, shaped windows will look
2582 * ugly, but programs still work. Stefan Wille
2585 * gdk_window_shape_combine_mask:
2586 * @window: a #GdkWindow
2588 * @x: X position of shape mask with respect to @window
2589 * @y: Y position of shape mask with respect to @window
2591 * Applies a shape mask to @window. Pixels in @window corresponding to
2592 * set bits in the @mask will be visible; pixels in @window
2593 * corresponding to unset bits in the @mask will be transparent. This
2594 * gives a non-rectangular window.
2596 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
2597 * parameters are not used.
2599 * On the X11 platform, this uses an X server extension which is
2600 * widely available on most common platforms, but not available on
2601 * very old X servers, and occasionally the implementation will be
2602 * buggy. On servers without the shape extension, this function
2607 gdk_window_shape_combine_mask (GdkWindow *window,
2612 gint xoffset, yoffset;
2614 g_return_if_fail (window != NULL);
2615 g_return_if_fail (GDK_IS_WINDOW (window));
2617 #ifdef HAVE_SHAPE_EXT
2618 if (GDK_WINDOW_DESTROYED (window))
2621 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2623 if (xoffset != 0 || yoffset != 0)
2625 WARN_SHAPE_TOO_BIG ();
2629 if (gdk_window_have_shape_ext ())
2633 pixmap = GDK_PIXMAP_XID (mask);
2642 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2643 GDK_WINDOW_XID (window),
2649 #endif /* HAVE_SHAPE_EXT */
2653 * gdk_window_shape_combine_region:
2654 * @window: a #GdkWindow
2655 * @shape_region: region of window to be non-transparent
2656 * @offset_x: X position of @shape_region in @window coordinates
2657 * @offset_y: Y position of @shape_region in @window coordinates
2659 * Makes pixels in @window outside @shape_region be transparent,
2660 * so that the window may be nonrectangular. See also
2661 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
2663 * If @shape_region is %NULL, the shape will be unset, so the whole
2664 * window will be opaque again. @offset_x and @offset_y are ignored
2665 * if @shape_region is %NULL.
2667 * On the X11 platform, this uses an X server extension which is
2668 * widely available on most common platforms, but not available on
2669 * very old X servers, and occasionally the implementation will be
2670 * buggy. On servers without the shape extension, this function
2675 gdk_window_shape_combine_region (GdkWindow *window,
2676 GdkRegion *shape_region,
2680 gint xoffset, yoffset;
2682 g_return_if_fail (GDK_IS_WINDOW (window));
2684 #ifdef HAVE_SHAPE_EXT
2685 if (GDK_WINDOW_DESTROYED (window))
2688 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2690 if (xoffset != 0 || yoffset != 0)
2692 WARN_SHAPE_TOO_BIG ();
2696 if (shape_region == NULL)
2698 /* Use NULL mask to unset the shape */
2699 gdk_window_shape_combine_mask (window, NULL, 0, 0);
2703 if (gdk_window_have_shape_ext ())
2706 XRectangle *xrects = NULL;
2708 _gdk_region_get_xrectangles (shape_region,
2712 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2713 GDK_WINDOW_XID (window),
2722 #endif /* HAVE_SHAPE_EXT */
2727 * gdk_window_set_override_redirect:
2728 * @window: a #GdkWindow
2729 * @override_redirect: %TRUE if window should be override redirect
2731 * An override redirect window is not under the control of the window manager.
2732 * This means it won't have a titlebar, won't be minimizable, etc. - it will
2733 * be entirely under the control of the application. The window manager
2734 * can't see the override redirect window at all.
2736 * Override redirect should only be used for short-lived temporary
2737 * windows, such as popup menus. #GtkMenu uses an override redirect
2738 * window in its implementation, for example.
2742 gdk_window_set_override_redirect (GdkWindow *window,
2743 gboolean override_redirect)
2745 XSetWindowAttributes attr;
2747 g_return_if_fail (window != NULL);
2748 g_return_if_fail (GDK_IS_WINDOW (window));
2750 if (GDK_WINDOW_DESTROYED (window))
2752 attr.override_redirect = (override_redirect == FALSE)?False:True;
2753 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2754 GDK_WINDOW_XID (window),
2762 * gdk_window_set_icon_list:
2763 * @window: The #GdkWindow toplevel window to set the icon of.
2764 * @pixbufs: A list of pixbufs, of different sizes.
2766 * Sets a list of icons for the window. One of these will be used
2767 * to represent the window when it has been iconified. The icon is
2768 * usually shown in an icon box or some sort of task bar. Which icon
2769 * size is shown depends on the window manager. The window manager
2770 * can scale the icon but setting several size icons can give better
2771 * image quality since the window manager may only need to scale the
2772 * icon by a small amount or not at all.
2776 gdk_window_set_icon_list (GdkWindow *window,
2785 gint width, height, stride;
2789 g_return_if_fail (GDK_IS_WINDOW (window));
2791 if (GDK_WINDOW_DESTROYED (window))
2800 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
2802 width = gdk_pixbuf_get_width (pixbuf);
2803 height = gdk_pixbuf_get_height (pixbuf);
2805 size += 2 + width * height;
2807 l = g_list_next (l);
2810 data = g_malloc (size * sizeof (gulong));
2818 width = gdk_pixbuf_get_width (pixbuf);
2819 height = gdk_pixbuf_get_height (pixbuf);
2820 stride = gdk_pixbuf_get_rowstride (pixbuf);
2821 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
2826 pixels = gdk_pixbuf_get_pixels (pixbuf);
2828 for (y = 0; y < height; y++)
2830 for (x = 0; x < width; x++)
2834 r = pixels[y*stride + x*n_channels + 0];
2835 g = pixels[y*stride + x*n_channels + 1];
2836 b = pixels[y*stride + x*n_channels + 2];
2837 if (n_channels >= 4)
2838 a = pixels[y*stride + x*n_channels + 3];
2842 *p++ = a << 24 | r << 16 | g << 8 | b ;
2846 l = g_list_next (l);
2851 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2852 GDK_WINDOW_XID (window),
2853 gdk_x11_get_xatom_by_name ("_NET_WM_ICON"),
2856 (guchar*) data, size);
2860 XDeleteProperty (GDK_WINDOW_XDISPLAY (window),
2861 GDK_WINDOW_XID (window),
2862 gdk_x11_get_xatom_by_name ("_NET_WM_ICON"));
2869 * gdk_window_set_icon:
2870 * @window: a #GdkWindow
2871 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
2872 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
2873 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
2875 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
2876 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
2877 * and gtk_window_set_icon(). If those don't meet your needs, look at
2878 * gdk_window_set_icon_list(). Only if all those are too high-level do you
2879 * want to fall back to gdk_window_set_icon().
2883 gdk_window_set_icon (GdkWindow *window,
2884 GdkWindow *icon_window,
2890 g_return_if_fail (window != NULL);
2891 g_return_if_fail (GDK_IS_WINDOW (window));
2893 if (GDK_WINDOW_DESTROYED (window))
2896 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
2897 GDK_WINDOW_XID (window));
2899 wm_hints = XAllocWMHints ();
2901 if (icon_window != NULL)
2903 wm_hints->flags |= IconWindowHint;
2904 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
2909 wm_hints->flags |= IconPixmapHint;
2910 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
2915 wm_hints->flags |= IconMaskHint;
2916 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
2919 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
2920 GDK_WINDOW_XID (window), wm_hints);
2925 gdk_window_icon_name_set (GdkWindow *window)
2927 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
2928 g_quark_from_static_string ("gdk-icon-name-set")));
2932 * gdk_window_set_icon_name:
2933 * @window: a #GdkWindow
2934 * @name: name of window while iconified (minimized)
2936 * Windows may have a name used while minimized, distinct from the
2937 * name they display in their titlebar. Most of the time this is a bad
2938 * idea from a user interface standpoint. But you can set such a name
2939 * with this function, if you like.
2943 gdk_window_set_icon_name (GdkWindow *window,
2946 g_return_if_fail (window != NULL);
2947 g_return_if_fail (GDK_IS_WINDOW (window));
2949 if (GDK_WINDOW_DESTROYED (window))
2952 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
2953 GUINT_TO_POINTER (TRUE));
2955 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2956 GDK_WINDOW_XID (window),
2957 gdk_x11_get_xatom_by_name ("_NET_WM_ICON_NAME"),
2958 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
2959 PropModeReplace, name,
2961 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_ICON_NAME"), name);
2965 * gdk_window_iconify:
2966 * @window: a #GdkWindow
2968 * Asks to iconify (minimize) @window. The window manager may choose
2969 * to ignore the request, but normally will honor it. Using
2970 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
2974 gdk_window_iconify (GdkWindow *window)
2977 GdkWindowObject *private;
2979 g_return_if_fail (window != NULL);
2980 g_return_if_fail (GDK_IS_WINDOW (window));
2982 if (GDK_WINDOW_DESTROYED (window))
2985 display = GDK_WINDOW_XDISPLAY (window);
2987 private = (GdkWindowObject*) window;
2989 if (GDK_WINDOW_IS_MAPPED (window))
2991 XIconifyWindow (display, GDK_WINDOW_XWINDOW (window), DefaultScreen (display));
2996 /* Flip our client side flag, the real work happens on map. */
2997 gdk_synthesize_window_state (window,
2999 GDK_WINDOW_STATE_ICONIFIED);
3004 * gdk_window_deiconify:
3005 * @window: a #GdkWindow
3007 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3008 * choose to ignore the request to deiconify. When using GTK+,
3009 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3010 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3011 * unminimizes it, and puts it on the current desktop.
3015 gdk_window_deiconify (GdkWindow *window)
3018 GdkWindowObject *private;
3020 g_return_if_fail (window != NULL);
3021 g_return_if_fail (GDK_IS_WINDOW (window));
3023 if (GDK_WINDOW_DESTROYED (window))
3026 display = GDK_WINDOW_XDISPLAY (window);
3028 private = (GdkWindowObject*) window;
3030 if (GDK_WINDOW_IS_MAPPED (window))
3032 gdk_window_show (window);
3036 /* Flip our client side flag, the real work happens on map. */
3037 gdk_synthesize_window_state (window,
3038 GDK_WINDOW_STATE_ICONIFIED,
3045 * @window: a toplevel #GdkWindow
3047 * "Pins" a window such that it's on all workspaces and does not scroll
3048 * with viewports, for window managers that have scrollable viewports.
3049 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3051 * On the X11 platform, this function depends on window manager
3052 * support, so may have no effect with many window managers. However,
3053 * GDK will do the best it can to convince the window manager to stick
3054 * the window. For window managers that don't support this operation,
3055 * there's nothing you can do to force it to happen.
3059 gdk_window_stick (GdkWindow *window)
3061 g_return_if_fail (GDK_IS_WINDOW (window));
3063 if (GDK_WINDOW_DESTROYED (window))
3066 if (GDK_WINDOW_IS_MAPPED (window))
3068 /* "stick" means stick to all desktops _and_ do not scroll with the
3069 * viewport. i.e. glue to the monitor glass in all cases.
3074 /* Request stick during viewport scroll */
3075 gdk_wmspec_change_state (TRUE, window,
3076 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3079 /* Request desktop 0xFFFFFFFF */
3080 xev.xclient.type = ClientMessage;
3081 xev.xclient.serial = 0;
3082 xev.xclient.send_event = True;
3083 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3084 xev.xclient.display = gdk_display;
3085 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP");
3086 xev.xclient.format = 32;
3088 xev.xclient.data.l[0] = 0xFFFFFFFF;
3090 XSendEvent (gdk_display, _gdk_root_window, False,
3091 SubstructureRedirectMask | SubstructureNotifyMask,
3096 /* Flip our client side flag, the real work happens on map. */
3097 gdk_synthesize_window_state (window,
3099 GDK_WINDOW_STATE_STICKY);
3104 * gdk_window_unstick:
3105 * @window: a toplevel #GdkWindow
3107 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3108 * and gtk_window_unstick().
3112 gdk_window_unstick (GdkWindow *window)
3114 g_return_if_fail (GDK_IS_WINDOW (window));
3116 if (GDK_WINDOW_DESTROYED (window))
3119 if (GDK_WINDOW_IS_MAPPED (window))
3126 gulong *current_desktop;
3128 /* Request unstick from viewport */
3129 gdk_wmspec_change_state (FALSE, window,
3130 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3133 /* Get current desktop, then set it; this is a race, but not
3134 * one that matters much in practice.
3136 XGetWindowProperty (gdk_display, _gdk_root_window,
3137 gdk_x11_get_xatom_by_name ("_NET_CURRENT_DESKTOP"),
3139 False, XA_CARDINAL, &type, &format, &nitems,
3140 &bytes_after, (guchar **)¤t_desktop);
3142 if (type == XA_CARDINAL)
3144 xev.xclient.type = ClientMessage;
3145 xev.xclient.serial = 0;
3146 xev.xclient.send_event = True;
3147 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3148 xev.xclient.display = gdk_display;
3149 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP");
3150 xev.xclient.format = 32;
3152 xev.xclient.data.l[0] = *current_desktop;
3154 XSendEvent (gdk_display, _gdk_root_window, False,
3155 SubstructureRedirectMask | SubstructureNotifyMask,
3158 XFree (current_desktop);
3163 /* Flip our client side flag, the real work happens on map. */
3164 gdk_synthesize_window_state (window,
3165 GDK_WINDOW_STATE_STICKY,
3172 * gdk_window_maximize:
3173 * @window: a #GdkWindow
3175 * Asks the window manager to maximize @window, if the window manager supports
3176 * this operation. Not all window managers support this, and some deliberately
3177 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3178 * maximization actually happening. But it will happen with most standard
3179 * window managers, and GDK makes a best effort to get it to happen.
3181 * If the window was already maximized, then this function does nothing.
3185 gdk_window_maximize (GdkWindow *window)
3187 g_return_if_fail (GDK_IS_WINDOW (window));
3189 if (GDK_WINDOW_DESTROYED (window))
3192 if (GDK_WINDOW_IS_MAPPED (window))
3193 gdk_wmspec_change_state (TRUE, window,
3194 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3195 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3197 gdk_synthesize_window_state (window,
3199 GDK_WINDOW_STATE_MAXIMIZED);
3203 * gdk_window_unmaximize:
3204 * @window: a #GdkWindow
3206 * Asks the window manager to unmaximize @window, if the window manager supports
3207 * this operation. Not all window managers support this, and some deliberately
3208 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3209 * unmaximization actually happening. But it will happen with most standard
3210 * window managers, and GDK makes a best effort to get it to happen.
3212 * If the window wasn't maximized, then this function does nothing.
3216 gdk_window_unmaximize (GdkWindow *window)
3218 g_return_if_fail (GDK_IS_WINDOW (window));
3220 if (GDK_WINDOW_DESTROYED (window))
3223 if (GDK_WINDOW_IS_MAPPED (window))
3224 gdk_wmspec_change_state (FALSE, window,
3225 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3226 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3228 gdk_synthesize_window_state (window,
3229 GDK_WINDOW_STATE_MAXIMIZED,
3234 * gdk_window_set_group:
3235 * @window: a #GdkWindow
3236 * @leader: group leader window
3238 * Sets the group leader window for @window. By default,
3239 * GDK sets the group leader for all toplevel windows
3240 * to a global window implicitly created by GDK. With this function
3241 * you can override this default.
3243 * The group leader window allows the window manager to distinguish
3244 * all windows that belong to a single application. It may for example
3245 * allow users to minimize/unminimize all windows belonging to an
3246 * application at once. You should only set a non-default group window
3247 * if your application pretends to be multiple applications.
3248 * The group leader window may not be changed after a window has been
3249 * mapped (with gdk_window_show() for example).
3253 gdk_window_set_group (GdkWindow *window,
3258 g_return_if_fail (window != NULL);
3259 g_return_if_fail (GDK_IS_WINDOW (window));
3260 g_return_if_fail (leader != NULL);
3261 g_return_if_fail (GDK_IS_WINDOW (leader));
3263 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3266 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3267 GDK_WINDOW_XID (window));
3269 wm_hints = XAllocWMHints ();
3271 wm_hints->flags |= WindowGroupHint;
3272 wm_hints->window_group = GDK_WINDOW_XID (leader);
3274 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3275 GDK_WINDOW_XID (window), wm_hints);
3279 static MotifWmHints *
3280 gdk_window_get_mwm_hints (GdkWindow *window)
3282 static Atom hints_atom = None;
3283 MotifWmHints *hints;
3289 if (GDK_WINDOW_DESTROYED (window))
3293 hints_atom = XInternAtom (GDK_WINDOW_XDISPLAY (window),
3294 _XA_MOTIF_WM_HINTS, FALSE);
3296 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3297 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3298 False, AnyPropertyType, &type, &format, &nitems,
3299 &bytes_after, (guchar **)&hints);
3308 gdk_window_set_mwm_hints (GdkWindow *window,
3309 MotifWmHints *new_hints)
3311 static Atom hints_atom = None;
3312 MotifWmHints *hints;
3318 if (GDK_WINDOW_DESTROYED (window))
3322 hints_atom = XInternAtom (GDK_WINDOW_XDISPLAY (window),
3323 _XA_MOTIF_WM_HINTS, FALSE);
3325 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3326 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3327 False, AnyPropertyType, &type, &format, &nitems,
3328 &bytes_after, (guchar **)&hints);
3334 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3336 hints->flags |= MWM_HINTS_FUNCTIONS;
3337 hints->functions = new_hints->functions;
3339 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3341 hints->flags |= MWM_HINTS_DECORATIONS;
3342 hints->decorations = new_hints->decorations;
3346 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3347 hints_atom, hints_atom, 32, PropModeReplace,
3348 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3350 if (hints != new_hints)
3355 * gdk_window_set_decorations:
3356 * @window: a #GdkWindow
3357 * @decorations: decoration hint mask
3359 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3360 * This function sets the traditional Motif window manager hints that tell the
3361 * window manager which decorations you would like your window to have.
3362 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3363 * using the GDK function directly.
3365 * The @decorations argument is the logical OR of the fields in
3366 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3367 * mask, the other bits indicate which decorations should be turned off.
3368 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3369 * which decorations should be turned on.
3371 * Most window managers honor a decorations hint of 0 to disable all decorations,
3372 * but very few honor all possible combinations of bits.
3376 gdk_window_set_decorations (GdkWindow *window,
3377 GdkWMDecoration decorations)
3381 g_return_if_fail (window != NULL);
3382 g_return_if_fail (GDK_IS_WINDOW (window));
3384 hints.flags = MWM_HINTS_DECORATIONS;
3385 hints.decorations = decorations;
3387 gdk_window_set_mwm_hints (window, &hints);
3391 * gdk_window_get_decorations:
3392 * @window: The #GdkWindow to get the decorations from
3393 * @decorations: The window decorations will be written here
3395 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3396 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3399 gdk_window_get_decorations(GdkWindow *window,
3400 GdkWMDecoration *decorations)
3402 MotifWmHints *hints;
3403 gboolean result = FALSE;
3405 hints = gdk_window_get_mwm_hints (window);
3409 if (hints->flags & MWM_HINTS_DECORATIONS)
3411 *decorations = hints->decorations;
3422 * gdk_window_set_functions:
3423 * @window: a #GdkWindow
3424 * @functions: bitmask of operations to allow on @window
3426 * This function isn't really good for much. It sets the traditional
3427 * Motif window manager hint for which operations the window manager
3428 * should allow on a toplevel window. However, few window managers do
3429 * anything reliable or interesting with this hint. Many ignore it
3432 * The @functions argument is the logical OR of values from the
3433 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3434 * then the other bits indicate which functions to disable; if
3435 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
3440 gdk_window_set_functions (GdkWindow *window,
3441 GdkWMFunction functions)
3445 g_return_if_fail (window != NULL);
3446 g_return_if_fail (GDK_IS_WINDOW (window));
3448 hints.flags = MWM_HINTS_FUNCTIONS;
3449 hints.functions = functions;
3451 gdk_window_set_mwm_hints (window, &hints);
3454 #ifdef HAVE_SHAPE_EXT
3457 * propagate the shapes from all child windows of a GDK window to the parent
3458 * window. Shamelessly ripped from Enlightenment's code
3466 struct _gdk_span *next;
3470 gdk_add_to_span (struct _gdk_span **s,
3474 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
3481 /* scan the spans for this line */
3484 /* -- -> new span */
3485 /* == -> existing span */
3486 /* ## -> spans intersect */
3487 /* if we are in the middle of spanning the span into the line */
3490 /* case: ---- ==== */
3491 if (xx < ptr1->start - 1)
3493 /* ends before next span - extend to here */
3497 /* case: ----##=== */
3498 else if (xx <= ptr1->end)
3500 /* crosses into next span - delete next span and append */
3501 ss->end = ptr1->end;
3502 ss->next = ptr1->next;
3506 /* case: ---###--- */
3509 /* overlaps next span - delete and keep checking */
3510 ss->next = ptr1->next;
3515 /* otherwise havent started spanning it in yet */
3518 /* case: ---- ==== */
3519 if (xx < ptr1->start - 1)
3521 /* insert span here in list */
3522 noo = g_malloc (sizeof (struct _gdk_span));
3536 /* case: ----##=== */
3537 else if ((x < ptr1->start) && (xx <= ptr1->end))
3539 /* expand this span to the left point of the new one */
3543 /* case: ===###=== */
3544 else if ((x >= ptr1->start) && (xx <= ptr1->end))
3546 /* throw the span away */
3549 /* case: ---###--- */
3550 else if ((x < ptr1->start) && (xx > ptr1->end))
3557 /* case: ===##---- */
3558 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
3564 /* case: ==== ---- */
3565 /* case handled by next loop iteration - first case */
3570 /* it started in the middle but spans beyond your current list */
3576 /* it does not start inside a span or in the middle, so add it to the end */
3577 noo = g_malloc (sizeof (struct _gdk_span));
3585 noo->next = ptr2->next;
3598 gdk_add_rectangles (Display *disp,
3600 struct _gdk_span **spans,
3607 gint x1, y1, x2, y2;
3611 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
3614 /* go through all clip rects in this window's shape */
3615 for (k = 0; k < rn; k++)
3617 /* for each clip rect, add it to each line's spans */
3619 x2 = x + rl[k].x + (rl[k].width - 1);
3621 y2 = y + rl[k].y + (rl[k].height - 1);
3630 for (a = y1; a <= y2; a++)
3633 gdk_add_to_span (&spans[a], x1, x2);
3641 gdk_propagate_shapes (Display *disp,
3645 Window rt, par, *list = NULL;
3646 gint i, j, num = 0, num_rects = 0;
3650 XRectangle *rects = NULL;
3651 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
3652 XWindowAttributes xatt;
3654 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
3659 spans = g_malloc (sizeof (struct _gdk_span *) * h);
3661 for (i = 0; i < h; i++)
3663 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
3666 /* go through all child windows and create/insert spans */
3667 for (i = 0; i < num; i++)
3669 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
3670 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
3671 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
3674 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
3676 /* go through the spans list and build a list of rects */
3677 rects = g_malloc (sizeof (XRectangle) * 256);
3679 for (i = 0; i < baseh; i++)
3682 /* go through the line for all spans */
3685 rects[num_rects].x = ptr1->start;
3686 rects[num_rects].y = i;
3687 rects[num_rects].width = ptr1->end - ptr1->start + 1;
3688 rects[num_rects].height = 1;
3690 /* if there are more lines */
3692 /* while contigous rects (same start/end coords) exist */
3693 while ((contig) && (j < baseh))
3695 /* search next line for spans matching this one */
3701 /* if we have an exact span match set contig */
3702 if ((ptr2->start == ptr1->start) &&
3703 (ptr2->end == ptr1->end))
3706 /* remove the span - not needed */
3709 ptr3->next = ptr2->next;
3715 spans[j] = ptr2->next;
3721 /* gone past the span point no point looking */
3722 else if (ptr2->start < ptr1->start)
3730 /* if a contiguous span was found increase the rect h */
3733 rects[num_rects].height++;
3737 /* up the rect count */
3739 /* every 256 new rects increase the rect array */
3740 if ((num_rects % 256) == 0)
3741 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
3745 /* set the rects as the shape mask */
3748 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
3749 ShapeSet, YXSorted);
3754 /* free up all the spans we made */
3755 for (i = 0; i < baseh; i++)
3768 #endif /* HAVE_SHAPE_EXT */
3771 * gdk_window_set_child_shapes:
3772 * @window: a #GdkWindow
3774 * Sets the shape mask of @window to the union of shape masks
3775 * for all children of @window, ignoring the shape mask of @window
3776 * itself. Contrast with gdk_window_merge_child_shapes() which includes
3777 * the shape mask of @window in the masks to be merged.
3780 gdk_window_set_child_shapes (GdkWindow *window)
3782 g_return_if_fail (window != NULL);
3783 g_return_if_fail (GDK_IS_WINDOW (window));
3785 #ifdef HAVE_SHAPE_EXT
3786 if (!GDK_WINDOW_DESTROYED (window) &&
3787 gdk_window_have_shape_ext ())
3788 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3789 GDK_WINDOW_XID (window), FALSE);
3794 * gdk_window_merge_child_shapes:
3795 * @window: a #GdkWindow
3797 * Merges the shape masks for any child windows into the
3798 * shape mask for @window. i.e. the union of all masks
3799 * for @window and its children will become the new mask
3800 * for @window. See gdk_window_shape_combine_mask().
3802 * This function is distinct from gdk_window_set_child_shapes()
3803 * because it includes @window's shape mask in the set of shapes to
3808 gdk_window_merge_child_shapes (GdkWindow *window)
3810 g_return_if_fail (window != NULL);
3811 g_return_if_fail (GDK_IS_WINDOW (window));
3813 #ifdef HAVE_SHAPE_EXT
3814 if (!GDK_WINDOW_DESTROYED (window) &&
3815 gdk_window_have_shape_ext ())
3816 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3817 GDK_WINDOW_XID (window), TRUE);
3821 /* Support for windows that can be guffaw-scrolled
3822 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
3826 gdk_window_gravity_works (void)
3828 enum { UNKNOWN, NO, YES };
3829 static gint gravity_works = UNKNOWN;
3831 if (gravity_works == UNKNOWN)
3838 /* This particular server apparently has a bug so that the test
3839 * works but the actual code crashes it
3841 if ((!strcmp (XServerVendor (gdk_display), "Sun Microsystems, Inc.")) &&
3842 (VendorRelease (gdk_display) == 3400))
3848 attr.window_type = GDK_WINDOW_TEMP;
3849 attr.wclass = GDK_INPUT_OUTPUT;
3854 attr.event_mask = 0;
3856 parent = gdk_window_new (NULL, &attr, GDK_WA_X | GDK_WA_Y);
3858 attr.window_type = GDK_WINDOW_CHILD;
3859 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
3861 gdk_window_set_static_win_gravity (child, TRUE);
3863 gdk_window_resize (parent, 100, 110);
3864 gdk_window_move (parent, 0, -10);
3865 gdk_window_move_resize (parent, 0, 0, 100, 100);
3867 gdk_window_resize (parent, 100, 110);
3868 gdk_window_move (parent, 0, -10);
3869 gdk_window_move_resize (parent, 0, 0, 100, 100);
3871 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
3873 gdk_window_destroy (parent);
3874 gdk_window_destroy (child);
3876 gravity_works = ((y == -20) ? YES : NO);
3879 return (gravity_works == YES);
3883 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
3885 XSetWindowAttributes xattributes;
3886 guint xattributes_mask = 0;
3888 g_return_if_fail (window != NULL);
3890 xattributes.bit_gravity = StaticGravity;
3891 xattributes_mask |= CWBitGravity;
3892 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
3893 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3894 GDK_WINDOW_XID (window),
3895 CWBitGravity, &xattributes);
3899 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
3901 XSetWindowAttributes xattributes;
3903 g_return_if_fail (window != NULL);
3905 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
3907 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3908 GDK_WINDOW_XID (window),
3909 CWWinGravity, &xattributes);
3913 * gdk_window_set_static_gravities:
3914 * @window: a #GdkWindow
3915 * @use_static: %TRUE to turn on static gravity
3917 * Set the bit gravity of the given window to static, and flag it so
3918 * all children get static subwindow gravity. This is used if you are
3919 * implementing scary features that involve deep knowledge of the
3920 * windowing system. Don't worry about it unless you have to.
3922 * Return value: %TRUE if the server supports static gravity
3925 gdk_window_set_static_gravities (GdkWindow *window,
3926 gboolean use_static)
3928 GdkWindowObject *private = (GdkWindowObject *)window;
3931 g_return_val_if_fail (window != NULL, FALSE);
3932 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3934 if (!use_static == !private->guffaw_gravity)
3937 if (use_static && !gdk_window_gravity_works ())
3940 private->guffaw_gravity = use_static;
3942 if (!GDK_WINDOW_DESTROYED (window))
3944 gdk_window_set_static_bit_gravity (window, use_static);
3946 tmp_list = private->children;
3949 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
3951 tmp_list = tmp_list->next;
3958 /* internal function created for and used by gdk_window_xid_at_coords */
3960 gdk_window_xid_at (Window base,
3966 gboolean excl_child)
3969 Window *list = NULL;
3970 Window child = 0, parent_win = 0, root_win = 0;
3972 unsigned int ww, wh, wb, wd, num;
3975 xdisplay = GDK_DISPLAY ();
3976 if (!XGetGeometry (xdisplay, base, &root_win, &wx, &wy, &ww, &wh, &wb, &wd))
3983 (x < (int) (wx + ww)) &&
3984 (y < (int) (wy + wh))))
3987 if (!XQueryTree (xdisplay, base, &root_win, &parent_win, &list, &num))
3992 for (i = num - 1; ; i--)
3994 if ((!excl_child) || (!g_list_find (excludes, (gpointer *) list[i])))
3996 if ((child = gdk_window_xid_at (list[i], wx, wy, x, y, excludes, excl_child)) != 0)
4011 * The following fucntion by The Rasterman <raster@redhat.com>
4012 * This function returns the X Window ID in which the x y location is in
4013 * (x and y being relative to the root window), excluding any windows listed
4014 * in the GList excludes (this is a list of X Window ID's - gpointer being
4017 * This is primarily designed for internal gdk use - for DND for example
4018 * when using a shaped icon window as the drag object - you exclude the
4019 * X Window ID of the "icon" (perhaps more if excludes may be needed) and
4020 * You can get back an X Window ID as to what X Window ID is infact under
4021 * those X,Y co-ordinates.
4024 gdk_window_xid_at_coords (gint x,
4027 gboolean excl_child)
4031 Window *list = NULL;
4032 Window root, child = 0, parent_win = 0, root_win = 0;
4036 window = _gdk_parent_root;
4037 xdisplay = GDK_WINDOW_XDISPLAY (window);
4038 root = GDK_WINDOW_XID (window);
4039 num = g_list_length (excludes);
4041 gdk_x11_grab_server ();
4042 if (!XQueryTree (xdisplay, root, &root_win, &parent_win, &list, &num))
4044 gdk_x11_ungrab_server ();
4052 XWindowAttributes xwa;
4054 XGetWindowAttributes (xdisplay, list [i], &xwa);
4056 if (xwa.map_state != IsViewable)
4059 if (excl_child && g_list_find (excludes, (gpointer *) list[i]))
4062 if ((child = gdk_window_xid_at (list[i], 0, 0, x, y, excludes, excl_child)) == 0)
4067 if (!g_list_find (excludes, (gpointer *) child))
4070 gdk_x11_ungrab_server ();
4077 gdk_x11_ungrab_server ();
4083 gdk_x11_ungrab_server ();
4088 wmspec_moveresize (GdkWindow *window,
4096 /* Release passive grab */
4097 gdk_pointer_ungrab (timestamp);
4099 xev.xclient.type = ClientMessage;
4100 xev.xclient.serial = 0;
4101 xev.xclient.send_event = True;
4102 xev.xclient.display = gdk_display;
4103 xev.xclient.window = GDK_WINDOW_XID (window);
4104 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_MOVERESIZE");
4105 xev.xclient.format = 32;
4106 xev.xclient.data.l[0] = root_x;
4107 xev.xclient.data.l[1] = root_y;
4108 xev.xclient.data.l[2] = direction;
4109 xev.xclient.data.l[3] = 0;
4110 xev.xclient.data.l[4] = 0;
4112 XSendEvent (gdk_display, _gdk_root_window, False,
4113 SubstructureRedirectMask | SubstructureNotifyMask,
4117 /* From the WM spec */
4118 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4119 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4120 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4121 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4122 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4123 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4124 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4125 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4126 #define _NET_WM_MOVERESIZE_MOVE 8
4129 wmspec_resize_drag (GdkWindow *window,
4138 /* Let the compiler turn a switch into a table, instead
4139 * of doing the table manually, this way is easier to verify.
4143 case GDK_WINDOW_EDGE_NORTH_WEST:
4144 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4147 case GDK_WINDOW_EDGE_NORTH:
4148 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4151 case GDK_WINDOW_EDGE_NORTH_EAST:
4152 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4155 case GDK_WINDOW_EDGE_WEST:
4156 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4159 case GDK_WINDOW_EDGE_EAST:
4160 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4163 case GDK_WINDOW_EDGE_SOUTH_WEST:
4164 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4167 case GDK_WINDOW_EDGE_SOUTH:
4168 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4171 case GDK_WINDOW_EDGE_SOUTH_EAST:
4172 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4176 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4182 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4185 /* This is global for use in gdkevents-x11.c */
4186 GdkWindow *_gdk_moveresize_window;
4188 static GdkWindow *moveresize_emulation_window = NULL;
4189 static gboolean is_resize = FALSE;
4190 static GdkWindowEdge resize_edge;
4191 static gint moveresize_button;
4192 static gint moveresize_x;
4193 static gint moveresize_y;
4194 static gint moveresize_orig_x;
4195 static gint moveresize_orig_y;
4196 static gint moveresize_orig_width;
4197 static gint moveresize_orig_height;
4198 static GdkWindowHints moveresize_geom_mask = 0;
4199 static GdkGeometry moveresize_geometry;
4200 static Time moveresize_process_time;
4202 static XEvent *moveresize_pending_event;
4205 update_pos (gint new_root_x,
4210 dx = new_root_x - moveresize_x;
4211 dy = new_root_y - moveresize_y;
4217 w = moveresize_orig_width;
4218 h = moveresize_orig_height;
4220 switch (resize_edge)
4222 case GDK_WINDOW_EDGE_SOUTH_EAST:
4231 if (moveresize_geom_mask)
4233 gdk_window_constrain_size (&moveresize_geometry,
4234 moveresize_geom_mask,
4239 gdk_window_resize (_gdk_moveresize_window, w, h);
4245 x = moveresize_orig_x + dx;
4246 y = moveresize_orig_y + dy;
4248 gdk_window_move (_gdk_moveresize_window, x, y);
4255 gdk_window_destroy (moveresize_emulation_window);
4256 moveresize_emulation_window = NULL;
4257 _gdk_moveresize_window = NULL;
4259 if (moveresize_pending_event)
4261 g_free (moveresize_pending_event);
4262 moveresize_pending_event = NULL;
4267 lookahead_motion_predicate (Display *display,
4271 gboolean *seen_release = (gboolean *)arg;
4276 switch (event->xany.type)
4279 *seen_release = TRUE;
4282 moveresize_process_time = event->xmotion.time;
4292 moveresize_lookahead (XEvent *event)
4295 gboolean seen_release = FALSE;
4297 if (moveresize_process_time)
4299 if (event->xmotion.time == moveresize_process_time)
4301 moveresize_process_time = 0;
4308 XCheckIfEvent (gdk_display, &tmp_event,
4309 lookahead_motion_predicate, (XPointer)&seen_release);
4311 return moveresize_process_time == 0;
4315 _gdk_moveresize_handle_event (XEvent *event)
4317 guint button_mask = 0;
4318 GdkWindowObject *window_private = (GdkWindowObject *) _gdk_moveresize_window;
4320 button_mask = GDK_BUTTON1_MASK << (moveresize_button - 1);
4322 switch (event->xany.type)
4325 if (window_private->resize_count > 0)
4327 if (moveresize_pending_event)
4328 *moveresize_pending_event = *event;
4330 moveresize_pending_event = g_memdup (event, sizeof (XEvent));
4334 if (!moveresize_lookahead (event))
4337 update_pos (event->xmotion.x_root,
4338 event->xmotion.y_root);
4340 /* This should never be triggered in normal cases, but in the
4341 * case where the drag started without an implicit grab being
4342 * in effect, we could miss the release if it occurs before
4343 * we grab the pointer; this ensures that we will never
4344 * get a permanently stuck grab.
4346 if ((event->xmotion.state & button_mask) == 0)
4351 update_pos (event->xbutton.x_root,
4352 event->xbutton.y_root);
4354 if (event->xbutton.button == moveresize_button)
4361 _gdk_moveresize_configure_done (void)
4365 if (moveresize_pending_event)
4367 tmp_event = moveresize_pending_event;
4368 moveresize_pending_event = NULL;
4369 _gdk_moveresize_handle_event (tmp_event);
4375 create_moveresize_window (guint32 timestamp)
4377 GdkWindowAttr attributes;
4378 gint attributes_mask;
4379 GdkGrabStatus status;
4381 g_assert (moveresize_emulation_window == NULL);
4383 attributes.x = -100;
4384 attributes.y = -100;
4385 attributes.width = 10;
4386 attributes.height = 10;
4387 attributes.window_type = GDK_WINDOW_TEMP;
4388 attributes.wclass = GDK_INPUT_ONLY;
4389 attributes.override_redirect = TRUE;
4390 attributes.event_mask = 0;
4392 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4394 moveresize_emulation_window =
4395 gdk_window_new (NULL, &attributes, attributes_mask);
4397 gdk_window_show (moveresize_emulation_window);
4399 status = gdk_pointer_grab (moveresize_emulation_window,
4401 GDK_BUTTON_RELEASE_MASK |
4402 GDK_POINTER_MOTION_MASK,
4407 if (status != GDK_GRAB_SUCCESS)
4409 /* If this fails, some other client has grabbed the window
4412 gdk_window_destroy (moveresize_emulation_window);
4413 moveresize_emulation_window = NULL;
4416 moveresize_process_time = 0;
4420 emulate_resize_drag (GdkWindow *window,
4428 moveresize_button = button;
4430 moveresize_x = root_x;
4431 moveresize_y = root_y;
4432 _gdk_moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4434 gdk_window_get_size (window, &moveresize_orig_width, &moveresize_orig_height);
4436 moveresize_geom_mask = 0;
4437 gdk_window_get_geometry_hints (window,
4438 &moveresize_geometry,
4439 &moveresize_geom_mask);
4441 create_moveresize_window (timestamp);
4445 emulate_move_drag (GdkWindow *window,
4452 moveresize_button = button;
4453 moveresize_x = root_x;
4454 moveresize_y = root_y;
4455 _gdk_moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4457 gdk_window_get_deskrelative_origin (_gdk_moveresize_window,
4459 &moveresize_orig_y);
4461 create_moveresize_window (timestamp);
4465 * gdk_window_begin_resize_drag:
4466 * @window: a #GdkWindow
4467 * @edge: the edge or corner from which the drag is started
4468 * @button: the button being used to drag
4469 * @root_x: root window X coordinate of mouse click that began the drag
4470 * @root_y: root window Y coordinate of mouse click that began the drag
4471 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
4473 * Begins a window resize operation (for a toplevel window).
4474 * You might use this function to implement a "window resize grip," for
4475 * example; in fact #GtkStatusbar uses it. The function works best
4476 * with window managers that support the Extended Window Manager Hints spec
4477 * (see http://www.freedesktop.org), but has a fallback implementation
4478 * for other window managers.
4482 gdk_window_begin_resize_drag (GdkWindow *window,
4489 g_return_if_fail (GDK_IS_WINDOW (window));
4490 g_return_if_fail (moveresize_emulation_window == NULL);
4492 if (GDK_WINDOW_DESTROYED (window))
4495 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4496 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4498 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4502 * gdk_window_begin_move_drag:
4503 * @window: a #GdkWindow
4504 * @button: the button being used to drag
4505 * @root_x: root window X coordinate of mouse click that began the drag
4506 * @root_y: root window Y coordinate of mouse click that began the drag
4507 * @timestamp: timestamp of mouse click that began the drag
4509 * Begins a window move operation (for a toplevel window). You might
4510 * use this function to implement a "window move grip," for
4511 * example. The function works best with window managers that support
4512 * the Extended Window Manager Hints spec (see
4513 * http://www.freedesktop.org), but has a fallback implementation for
4514 * other window managers.
4518 gdk_window_begin_move_drag (GdkWindow *window,
4524 g_return_if_fail (GDK_IS_WINDOW (window));
4525 g_return_if_fail (moveresize_emulation_window == NULL);
4527 if (GDK_WINDOW_DESTROYED (window))
4530 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4531 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE,
4532 root_x, root_y, timestamp);
4534 emulate_move_drag (window, button, root_x, root_y, timestamp);