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 "gdkdisplay-x11.h"
38 #include "gdkprivate-x11.h"
39 #include "gdkregion.h"
40 #include "gdkinternals.h"
42 #include "gdkwindow-x11.h"
50 #include <X11/extensions/shape.h>
53 const int _gdk_event_mask_table[21] =
57 PointerMotionHintMask,
74 SubstructureNotifyMask,
75 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
77 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
79 /* Forward declarations */
80 static gboolean gdk_window_gravity_works (GdkWindow *window);
81 static void gdk_window_set_static_win_gravity (GdkWindow *window,
83 static gboolean gdk_window_have_shape_ext (GdkDisplay *display);
84 static gboolean gdk_window_icon_name_set (GdkWindow *window);
85 static void gdk_window_add_colormap_windows (GdkWindow *window);
86 static void set_wm_name (GdkDisplay *display,
90 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
91 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
93 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
96 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
97 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
98 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
99 static void gdk_window_impl_x11_finalize (GObject *object);
101 static gpointer parent_class = NULL;
104 gdk_window_impl_x11_get_type (void)
106 static GType object_type = 0;
110 static const GTypeInfo object_info =
112 sizeof (GdkWindowImplX11Class),
113 (GBaseInitFunc) NULL,
114 (GBaseFinalizeFunc) NULL,
115 (GClassInitFunc) gdk_window_impl_x11_class_init,
116 NULL, /* class_finalize */
117 NULL, /* class_data */
118 sizeof (GdkWindowImplX11),
120 (GInstanceInitFunc) gdk_window_impl_x11_init,
123 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
132 _gdk_window_impl_get_type (void)
134 return gdk_window_impl_x11_get_type ();
138 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
145 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
147 GObjectClass *object_class = G_OBJECT_CLASS (klass);
148 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
150 parent_class = g_type_class_peek_parent (klass);
152 object_class->finalize = gdk_window_impl_x11_finalize;
154 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
155 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
156 drawable_class->get_size = gdk_window_impl_x11_get_size;
158 /* Visible and clip regions are the same */
159 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
160 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
164 gdk_window_impl_x11_finalize (GObject *object)
166 GdkWindowObject *wrapper;
167 GdkDrawableImplX11 *draw_impl;
168 GdkWindowImplX11 *window_impl;
170 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
172 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
173 window_impl = GDK_WINDOW_IMPL_X11 (object);
175 wrapper = (GdkWindowObject*) draw_impl->wrapper;
177 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
179 if (!GDK_WINDOW_DESTROYED (wrapper))
181 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), draw_impl->xid);
182 if (window_impl->focus_window)
183 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), window_impl->focus_window);
186 G_OBJECT_CLASS (parent_class)->finalize (object);
190 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
192 GdkDrawableImplX11 *drawable_impl;
193 GdkWindowImplX11 *window_impl;
195 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
197 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
198 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
200 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
201 drawable_impl->colormap == NULL)
203 XWindowAttributes window_attributes;
206 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
210 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
211 window_attributes.visual->visualid);
212 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
213 window_attributes.colormap);
216 return drawable_impl->colormap;
220 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
223 GdkWindowImplX11 *impl;
224 GdkDrawableImplX11 *draw_impl;
226 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
228 impl = GDK_WINDOW_IMPL_X11 (drawable);
229 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
231 if (GDK_WINDOW_DESTROYED (draw_impl->wrapper))
235 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
239 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
241 GDK_COLORMAP_XCOLORMAP (cmap));
243 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
245 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
251 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
255 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
258 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
260 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
264 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
266 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
267 GdkRectangle result_rect;
271 result_rect.width = impl->width;
272 result_rect.height = impl->height;
274 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
276 return gdk_region_rectangle (&result_rect);
280 _gdk_windowing_window_init (GdkScreen * screen)
282 GdkWindowObject *private;
283 GdkWindowImplX11 *impl;
284 GdkDrawableImplX11 *draw_impl;
285 GdkScreenX11 *screen_x11;
286 XWindowAttributes xattributes;
289 unsigned int border_width;
293 screen_x11 = GDK_SCREEN_X11 (screen);
295 g_assert (screen_x11->root_window == NULL);
297 screen_x11->default_colormap = gdk_screen_get_system_colormap (screen);
299 XGetGeometry (screen_x11->xdisplay, screen_x11->xroot_window,
300 &screen_x11->xroot_window, &x, &y, &width, &height, &border_width, &depth);
301 XGetWindowAttributes (screen_x11->xdisplay, screen_x11->xroot_window, &xattributes);
303 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
304 private = (GdkWindowObject *)screen_x11->root_window;
305 impl = GDK_WINDOW_IMPL_X11 (private->impl);
306 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
308 draw_impl->screen = screen;
309 draw_impl->xid = screen_x11->xroot_window;
310 draw_impl->wrapper = GDK_DRAWABLE (private);
311 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
313 private->window_type = GDK_WINDOW_ROOT;
314 private->depth = depth;
317 impl->height = height;
319 _gdk_window_init_position (GDK_WINDOW (private));
321 _gdk_xid_table_insert (screen_x11->display,
322 &screen_x11->xroot_window,
323 screen_x11->root_window);
327 set_wm_protocols (GdkWindow *window)
329 GdkDisplay *display = gdk_drawable_get_display (window);
332 protocols[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
333 protocols[1] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
334 protocols[2] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
336 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, 3);
340 get_default_title (void)
344 title = g_get_application_name ();
346 title = g_get_prgname ();
352 check_leader_window_title (GdkDisplay *display)
354 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
356 if (!display_x11->leader_window_title_set)
358 set_wm_name (display,
359 display_x11->leader_window,
360 get_default_title ());
362 display_x11->leader_window_title_set = TRUE;
368 * @parent: a #GdkWindow, or %NULL to create the window as a child of
369 * the default root window for the default display.
370 * @attributes: attributes of the new window
371 * @attributes_mask: mask indicating which fields in @attributes are valid
373 * Creates a new #GdkWindow using the attributes from
374 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
375 * more details. Note: to use this on displays other than the default
376 * display, @parent must be specified.
378 * Return value: the new #GdkWindow
381 gdk_window_new (GdkWindow *parent,
382 GdkWindowAttr *attributes,
383 gint attributes_mask)
386 GdkWindowObject *private;
387 GdkWindowImplX11 *impl;
388 GdkDrawableImplX11 *draw_impl;
389 GdkScreenX11 *screen_x11;
398 XSetWindowAttributes xattributes;
399 long xattributes_mask;
400 XSizeHints size_hints;
402 XClassHint *class_hint;
410 g_return_val_if_fail (attributes != NULL, NULL);
415 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
417 screen = gdk_screen_get_default ();
418 parent = gdk_screen_get_root_window (screen);
421 screen = gdk_drawable_get_screen (parent);
423 screen_x11 = GDK_SCREEN_X11 (screen);
425 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
427 if (GDK_WINDOW_DESTROYED (parent))
430 xparent = GDK_WINDOW_XID (parent);
432 window = g_object_new (GDK_TYPE_WINDOW, NULL);
433 private = (GdkWindowObject *)window;
434 impl = GDK_WINDOW_IMPL_X11 (private->impl);
435 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
436 draw_impl->wrapper = GDK_DRAWABLE (window);
438 draw_impl->screen = screen;
439 xdisplay = screen_x11->xdisplay;
441 /* Windows with a foreign parent are treated as if they are children
442 * of the root window, except for actual creation.
444 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
445 parent = gdk_screen_get_root_window (screen);
447 private->parent = (GdkWindowObject *)parent;
449 xattributes_mask = 0;
451 if (attributes_mask & GDK_WA_X)
456 if (attributes_mask & GDK_WA_Y)
463 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
464 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
466 if (attributes->wclass == GDK_INPUT_ONLY)
468 /* Backwards compatiblity - we've always ignored
469 * attributes->window_type for input-only windows
472 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
473 private->window_type = GDK_WINDOW_TEMP;
475 private->window_type = GDK_WINDOW_CHILD;
478 private->window_type = attributes->window_type;
480 _gdk_window_init_position (GDK_WINDOW (private));
481 if (impl->position_info.big)
482 private->guffaw_gravity = TRUE;
484 if (attributes_mask & GDK_WA_VISUAL)
485 visual = attributes->visual;
487 visual = gdk_screen_get_system_visual (screen);
488 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
490 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
491 for (i = 0; i < _gdk_nenvent_masks; i++)
493 if (attributes->event_mask & (1 << (i + 1)))
494 xattributes.event_mask |= _gdk_event_mask_table[i];
496 private->event_mask = attributes->event_mask;
498 if (xattributes.event_mask)
499 xattributes_mask |= CWEventMask;
501 if (attributes_mask & GDK_WA_NOREDIR)
503 xattributes.override_redirect =
504 (attributes->override_redirect == FALSE)?False:True;
505 xattributes_mask |= CWOverrideRedirect;
508 xattributes.override_redirect = False;
510 if (private->parent && private->parent->guffaw_gravity)
512 xattributes.win_gravity = StaticGravity;
513 xattributes_mask |= CWWinGravity;
517 switch (private->window_type)
519 case GDK_WINDOW_TOPLEVEL:
520 case GDK_WINDOW_DIALOG:
521 case GDK_WINDOW_TEMP:
522 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
524 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
525 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
526 xparent = GDK_SCREEN_XROOTWIN (screen);
528 case GDK_WINDOW_CHILD:
531 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
535 if (attributes->wclass == GDK_INPUT_OUTPUT)
538 depth = visual->depth;
540 private->input_only = FALSE;
541 private->depth = depth;
543 if (attributes_mask & GDK_WA_COLORMAP)
545 draw_impl->colormap = attributes->colormap;
546 g_object_ref (attributes->colormap);
550 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
552 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
553 g_object_ref (draw_impl->colormap);
557 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
561 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
562 xattributes.background_pixel = private->bg_color.pixel;
564 private->bg_pixmap = NULL;
566 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
567 xattributes_mask |= CWBorderPixel | CWBackPixel;
569 if (private->guffaw_gravity)
570 xattributes.bit_gravity = StaticGravity;
572 xattributes.bit_gravity = NorthWestGravity;
574 xattributes_mask |= CWBitGravity;
576 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
577 xattributes_mask |= CWColormap;
579 if (private->window_type == GDK_WINDOW_TEMP)
581 xattributes.save_under = True;
582 xattributes.override_redirect = True;
583 xattributes.cursor = None;
584 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
592 private->input_only = TRUE;
593 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
594 g_object_ref (draw_impl->colormap);
597 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
598 impl->position_info.x, impl->position_info.y,
599 impl->position_info.width, impl->position_info.height,
600 0, depth, class, xvisual,
601 xattributes_mask, &xattributes);
603 g_object_ref (window);
604 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
606 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
607 (attributes->cursor) :
611 private->parent->children = g_list_prepend (private->parent->children, window);
613 switch (GDK_WINDOW_TYPE (private))
615 case GDK_WINDOW_DIALOG:
616 XSetTransientForHint (xdisplay, xid, xparent);
617 case GDK_WINDOW_TOPLEVEL:
618 case GDK_WINDOW_TEMP:
619 set_wm_protocols (window);
621 case GDK_WINDOW_CHILD:
622 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
623 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
624 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
626 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
627 gdk_window_add_colormap_windows (window);
636 if (class != InputOnly)
638 /* The focus window is off the visible area, and serves to receive key
639 * press events so they don't get sent to child windows.
641 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
643 xattributes.background_pixel,
644 xattributes.background_pixel);
645 /* FIXME: probably better to actually track the requested event mask for the toplevel
647 XSelectInput (xdisplay, impl->focus_window,
648 KeyPressMask | KeyReleaseMask | FocusChangeMask);
650 XMapWindow (xdisplay, impl->focus_window);
651 _gdk_xid_table_insert (screen_x11->display, &impl->focus_window, window);
654 size_hints.flags = PSize;
655 size_hints.width = impl->width;
656 size_hints.height = impl->height;
658 check_leader_window_title (screen_x11->display);
660 wm_hints.flags = StateHint | WindowGroupHint;
661 wm_hints.window_group = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
662 wm_hints.input = True;
663 wm_hints.initial_state = NormalState;
665 /* FIXME: Is there any point in doing this? Do any WM's pay
666 * attention to PSize, and even if they do, is this the
669 XSetWMNormalHints (xdisplay, xid, &size_hints);
671 XSetWMHints (xdisplay, xid, &wm_hints);
673 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
674 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
677 XChangeProperty (xdisplay, xid,
678 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
683 XChangeProperty (xdisplay, xid,
684 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
685 XA_WINDOW, 32, PropModeReplace,
686 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
688 if (attributes_mask & GDK_WA_TITLE)
689 title = attributes->title;
691 title = get_default_title ();
693 gdk_window_set_title (window, title);
695 if (attributes_mask & GDK_WA_WMCLASS)
697 class_hint = XAllocClassHint ();
698 class_hint->res_name = attributes->wmclass_name;
699 class_hint->res_class = attributes->wmclass_class;
700 XSetClassHint (xdisplay, xid, class_hint);
708 x_event_mask_to_gdk_event_mask (long mask)
710 GdkEventMask event_mask = 0;
713 for (i = 0; i < _gdk_nenvent_masks; i++)
715 if (mask & _gdk_event_mask_table[i])
716 event_mask |= 1 << (i + 1);
723 * gdk_window_foreign_new_for_display:
724 * @display: the #GdkDisplay where the window handle comes from.
725 * @anid: a native window handle.
727 * Wraps a native window in a #GdkWindow.
728 * This may fail if the window has been destroyed.
730 * For example in the X backend, a native window handle is an Xlib
733 * Return value: the newly-created #GdkWindow wrapper for the
734 * native window or %NULL if the window has been destroyed.
737 gdk_window_foreign_new_for_display (GdkDisplay *display,
738 GdkNativeWindow anid)
741 GdkWindowObject *private;
742 GdkWindowImplX11 *impl;
743 GdkDrawableImplX11 *draw_impl;
744 GdkDisplayX11 *display_x11;
745 XWindowAttributes attrs;
747 Window *children = NULL;
751 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
753 display_x11 = GDK_DISPLAY_X11 (display);
755 gdk_error_trap_push ();
756 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
757 if (gdk_error_trap_pop () || !result)
760 /* FIXME: This is pretty expensive. Maybe the caller should supply
762 gdk_error_trap_push ();
763 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
764 if (gdk_error_trap_pop () || !result)
770 window = g_object_new (GDK_TYPE_WINDOW, NULL);
771 private = (GdkWindowObject *)window;
772 impl = GDK_WINDOW_IMPL_X11 (private->impl);
773 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
774 draw_impl->wrapper = GDK_DRAWABLE (window);
775 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
777 private->parent = gdk_xid_table_lookup_for_display (display, parent);
779 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
780 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
782 private->parent->children = g_list_prepend (private->parent->children, window);
784 draw_impl->xid = anid;
786 private->x = attrs.x;
787 private->y = attrs.y;
788 impl->width = attrs.width;
789 impl->height = attrs.height;
790 private->window_type = GDK_WINDOW_FOREIGN;
791 private->destroyed = FALSE;
793 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
795 if (attrs.map_state == IsUnmapped)
796 private->state = GDK_WINDOW_STATE_WITHDRAWN;
800 private->depth = attrs.depth;
802 _gdk_window_init_position (GDK_WINDOW (private));
804 g_object_ref (window);
805 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
810 * gdk_window_lookup_for_display:
811 * @display: the #GdkDisplay corresponding to the window handle
812 * @anid: a native window handle.
814 * Looks up the #GdkWindow that wraps the given native window handle.
816 * For example in the X backend, a native window handle is an Xlib
819 * Return value: the #GdkWindow wrapper for the native window,
820 * or %NULL if there is none.
823 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
825 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
830 * @anid: a native window handle.
832 * Looks up the #GdkWindow that wraps the given native window handle.
834 * For example in the X backend, a native window handle is an Xlib
837 * Return value: the #GdkWindow wrapper for the native window,
838 * or %NULL if there is none.
841 gdk_window_lookup (GdkNativeWindow anid)
843 return (GdkWindow*) gdk_xid_table_lookup (anid);
847 _gdk_windowing_window_destroy (GdkWindow *window,
849 gboolean foreign_destroy)
851 GdkWindowObject *private = (GdkWindowObject *)window;
853 g_return_if_fail (GDK_IS_WINDOW (window));
855 _gdk_selection_window_destroyed (window);
857 if (private->extension_events != 0)
858 _gdk_input_window_destroy (window);
862 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
865 if (draw_impl->xft_draw)
866 XftDrawDestroy (draw_impl->xft_draw);
867 #else /* !HAVE_XFT2 */
868 if (draw_impl->picture)
869 XRenderFreePicture (GDK_DRAWABLE_XDISPLAY (window), draw_impl->picture);
870 #endif /* HAVE_XFT2 */
872 #endif /* HAVE_XFT */
874 if (private->window_type == GDK_WINDOW_FOREIGN)
876 if (!foreign_destroy && (private->parent != NULL))
878 /* It's somebody else's window, but in our heirarchy,
879 * so reparent it to the root window, and then send
880 * it a delete event, as if we were a WM
882 XClientMessageEvent xevent;
884 gdk_error_trap_push ();
885 gdk_window_hide (window);
886 gdk_window_reparent (window, NULL, 0, 0);
888 xevent.type = ClientMessage;
889 xevent.window = GDK_WINDOW_XID (window);
890 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
893 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
895 xevent.data.l[1] = CurrentTime;
897 XSendEvent (GDK_WINDOW_XDISPLAY (window),
898 GDK_WINDOW_XID (window),
899 False, 0, (XEvent *)&xevent);
900 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
901 gdk_error_trap_pop ();
904 else if (!recursing && !foreign_destroy)
906 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
910 /* This function is called when the XWindow is really gone.
913 gdk_window_destroy_notify (GdkWindow *window)
915 GdkWindowImplX11 *window_impl;
917 g_return_if_fail (window != NULL);
919 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
921 if (!GDK_WINDOW_DESTROYED (window))
923 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
924 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
926 _gdk_window_destroy (window, TRUE);
929 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
930 if (window_impl->focus_window)
931 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->focus_window);
933 _gdk_xgrab_check_destroy (window);
935 g_object_unref (window);
939 set_initial_hints (GdkWindow *window)
941 GdkWindowObject *private;
945 private = (GdkWindowObject*) window;
947 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
951 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
952 GDK_WINDOW_XID (window));
954 wm_hints = XAllocWMHints ();
956 wm_hints->flags |= StateHint;
957 wm_hints->initial_state = IconicState;
959 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
960 GDK_WINDOW_XID (window), wm_hints);
964 /* We set the spec hints regardless of whether the spec is supported,
965 * since it can't hurt and it's kind of expensive to check whether
971 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
973 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
974 "_NET_WM_STATE_MAXIMIZED_VERT");
976 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
977 "_NET_WM_STATE_MAXIMIZED_HORZ");
981 if (private->state & GDK_WINDOW_STATE_STICKY)
983 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
984 "_NET_WM_STATE_STICKY");
988 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
990 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
991 "_NET_WM_STATE_FULLSCREEN");
995 if (private->modal_hint)
997 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
998 "_NET_WM_STATE_MODAL");
1004 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1005 GDK_WINDOW_XID (window),
1006 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_STATE"),
1007 XA_ATOM, 32, PropModeReplace,
1008 (guchar*) atoms, i);
1011 if (private->state & GDK_WINDOW_STATE_STICKY)
1013 atoms[0] = 0xFFFFFFFF;
1014 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1015 GDK_WINDOW_XID (window),
1016 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_DESKTOP"),
1017 XA_CARDINAL, 32, PropModeReplace,
1018 (guchar*) atoms, 1);
1023 show_window_internal (GdkWindow *window,
1026 GdkWindowObject *private;
1028 g_return_if_fail (GDK_IS_WINDOW (window));
1030 private = (GdkWindowObject*) window;
1031 if (!private->destroyed)
1034 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
1035 GDK_WINDOW_XID (window));
1037 if (!GDK_WINDOW_IS_MAPPED (window))
1039 set_initial_hints (window);
1041 gdk_synthesize_window_state (window,
1042 GDK_WINDOW_STATE_WITHDRAWN,
1046 g_assert (GDK_WINDOW_IS_MAPPED (window));
1048 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
1049 XMapWindow (GDK_WINDOW_XDISPLAY (window),
1050 GDK_WINDOW_XID (window));
1055 * gdk_window_show_unraised:
1056 * @window: a #GdkWindow
1058 * Shows a #GdkWindow onscreen, but does not modify its stacking
1059 * order. In contrast, gdk_window_show() will raise the window
1060 * to the top of the window stack.
1062 * On the X11 platform, in Xlib terms, this function calls
1063 * XMapWindow() (it also updates some internal GDK state, which means
1064 * that you can't really use XMapWindow() directly on a GDK window).
1068 gdk_window_show_unraised (GdkWindow *window)
1070 g_return_if_fail (GDK_IS_WINDOW (window));
1072 show_window_internal (window, FALSE);
1077 * @window: a #GdkWindow
1079 * Like gdk_window_show_unraised(), but also raises the window to the
1080 * top of the window stack (moves the window to the front of the
1083 * This function maps a window so it's visible onscreen. Its opposite
1084 * is gdk_window_hide().
1086 * When implementing a #GtkWidget, you should call this function on the widget's
1087 * #GdkWindow as part of the "map" method.
1091 gdk_window_show (GdkWindow *window)
1093 g_return_if_fail (GDK_IS_WINDOW (window));
1095 show_window_internal (window, TRUE);
1100 * @window: a #GdkWindow
1102 * For toplevel windows, withdraws them, so they will no longer be
1103 * known to the window manager; for all windows, unmaps them, so
1104 * they won't be displayed. Normally done automatically as
1105 * part of gtk_widget_hide().
1109 gdk_window_hide (GdkWindow *window)
1111 GdkWindowObject *private;
1113 g_return_if_fail (window != NULL);
1115 private = (GdkWindowObject*) window;
1117 /* We'll get the unmap notify eventually, and handle it then,
1118 * but checking here makes things more consistent if we are
1119 * just doing stuff ourself.
1121 _gdk_xgrab_check_unmap (window,
1122 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1124 /* You can't simply unmap toplevel windows. */
1125 switch (private->window_type)
1127 case GDK_WINDOW_TOPLEVEL:
1128 case GDK_WINDOW_DIALOG:
1129 case GDK_WINDOW_TEMP: /* ? */
1130 gdk_window_withdraw (window);
1134 case GDK_WINDOW_FOREIGN:
1135 case GDK_WINDOW_ROOT:
1136 case GDK_WINDOW_CHILD:
1140 if (!private->destroyed)
1142 if (GDK_WINDOW_IS_MAPPED (window))
1143 gdk_synthesize_window_state (window,
1145 GDK_WINDOW_STATE_WITHDRAWN);
1147 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1149 _gdk_window_clear_update_area (window);
1151 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1152 GDK_WINDOW_XID (window));
1157 * gdk_window_withdraw:
1158 * @window: a toplevel #GdkWindow
1160 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1161 * This function is not really useful as gdk_window_hide() automatically
1162 * withdraws toplevel windows before hiding them.
1166 gdk_window_withdraw (GdkWindow *window)
1168 GdkWindowObject *private;
1170 g_return_if_fail (window != NULL);
1172 private = (GdkWindowObject*) window;
1173 if (!private->destroyed)
1175 if (GDK_WINDOW_IS_MAPPED (window))
1176 gdk_synthesize_window_state (window,
1178 GDK_WINDOW_STATE_WITHDRAWN);
1180 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1182 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1183 GDK_WINDOW_XID (window), 0);
1189 * @window: a #GdkWindow
1190 * @x: X coordinate relative to window's parent
1191 * @y: Y coordinate relative to window's parent
1193 * Repositions a window relative to its parent window.
1194 * For toplevel windows, window managers may ignore or modify the move;
1195 * you should probably use gtk_window_move() on a #GtkWindow widget
1196 * anyway, instead of using GDK functions. For child windows,
1197 * the move will reliably succeed.
1199 * If you're also planning to resize the window, use gdk_window_move_resize()
1200 * to both move and resize simultaneously, for a nicer visual effect.
1203 gdk_window_move (GdkWindow *window,
1207 GdkWindowObject *private = (GdkWindowObject *)window;
1208 GdkWindowImplX11 *impl;
1210 g_return_if_fail (window != NULL);
1211 g_return_if_fail (GDK_IS_WINDOW (window));
1213 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1215 if (!GDK_WINDOW_DESTROYED (window))
1217 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1218 _gdk_window_move_resize_child (window, x, y,
1219 impl->width, impl->height);
1222 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1223 GDK_WINDOW_XID (window),
1230 * gdk_window_resize:
1231 * @window: a #GdkWindow
1232 * @width: new width of the window
1233 * @height: new height of the window
1235 * Resizes @window; for toplevel windows, asks the window manager to resize
1236 * the window. The window manager may not allow the resize. When using GTK+,
1237 * use gtk_window_resize() instead of this low-level GDK function.
1239 * Windows may not be resized below 1x1.
1241 * If you're also planning to move the window, use gdk_window_move_resize()
1242 * to both move and resize simultaneously, for a nicer visual effect.
1245 gdk_window_resize (GdkWindow *window,
1249 GdkWindowObject *private;
1251 g_return_if_fail (window != NULL);
1252 g_return_if_fail (GDK_IS_WINDOW (window));
1259 private = (GdkWindowObject*) window;
1261 if (!GDK_WINDOW_DESTROYED (window))
1263 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1264 _gdk_window_move_resize_child (window, private->x, private->y,
1268 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1270 if (width != impl->width || height != impl->height)
1271 private->resize_count += 1;
1273 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1274 GDK_WINDOW_XID (window),
1281 * gdk_window_move_resize:
1282 * @window: a #GdkWindow
1283 * @x: new X position relative to window's parent
1284 * @y: new Y position relative to window's parent
1286 * @height: new height
1288 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1289 * except that both operations are performed at once, avoiding strange
1290 * visual effects. (i.e. the user may be able to see the window first
1291 * move, then resize, if you don't use gdk_window_move_resize().)
1294 gdk_window_move_resize (GdkWindow *window,
1300 GdkWindowObject *private;
1302 g_return_if_fail (window != NULL);
1303 g_return_if_fail (GDK_IS_WINDOW (window));
1310 private = (GdkWindowObject*) window;
1312 if (!GDK_WINDOW_DESTROYED (window))
1314 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1315 _gdk_window_move_resize_child (window, x, y, width, height);
1318 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1320 if (width != impl->width || height != impl->height)
1321 private->resize_count += 1;
1323 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1324 GDK_WINDOW_XID (window),
1325 x, y, width, height);
1331 * gdk_window_reparent:
1332 * @window: a #GdkWindow
1333 * @new_parent: new parent to move @window into
1334 * @x: X location inside the new parent
1335 * @y: Y location inside the new parent
1337 * Reparents @window into the given @new_parent. The window being
1338 * reparented will be unmapped as a side effect.
1342 gdk_window_reparent (GdkWindow *window,
1343 GdkWindow *new_parent,
1347 GdkDisplay *display;
1348 GdkWindowObject *window_private;
1349 GdkWindowObject *parent_private;
1350 GdkWindowObject *old_parent_private;
1352 g_return_if_fail (window != NULL);
1353 g_return_if_fail (GDK_IS_WINDOW (window));
1354 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1355 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1358 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1360 display = GDK_WINDOW_DISPLAY (window);
1362 window_private = (GdkWindowObject*) window;
1363 old_parent_private = (GdkWindowObject*)window_private->parent;
1364 parent_private = (GdkWindowObject*) new_parent;
1366 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1367 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1368 GDK_WINDOW_XID (window),
1369 GDK_WINDOW_XID (new_parent),
1372 window_private->x = x;
1373 window_private->y = y;
1375 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1378 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1379 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1381 window_private->parent = (GdkWindowObject *)new_parent;
1383 /* Switch the window type as appropriate */
1385 switch (GDK_WINDOW_TYPE (new_parent))
1387 case GDK_WINDOW_ROOT:
1388 case GDK_WINDOW_FOREIGN:
1389 /* Now a toplevel */
1390 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1391 set_wm_protocols (window);
1393 case GDK_WINDOW_TOPLEVEL:
1394 case GDK_WINDOW_CHILD:
1395 case GDK_WINDOW_DIALOG:
1396 case GDK_WINDOW_TEMP:
1397 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1398 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1400 /* If we were being sophisticated, we'd save the old window type
1401 * here, and restore it if we were reparented back to the
1402 * toplevel. However, the difference between different types
1403 * of toplevels only really matters on creation anyways.
1405 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1409 if (old_parent_private)
1410 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1412 if ((old_parent_private &&
1413 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1414 (!old_parent_private && parent_private->guffaw_gravity))
1415 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1417 parent_private->children = g_list_prepend (parent_private->children, window);
1418 _gdk_window_init_position (GDK_WINDOW (window_private));
1422 _gdk_windowing_window_clear_area (GdkWindow *window,
1428 g_return_if_fail (window != NULL);
1429 g_return_if_fail (GDK_IS_WINDOW (window));
1431 if (!GDK_WINDOW_DESTROYED (window))
1432 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1433 x, y, width, height, False);
1437 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1443 g_return_if_fail (window != NULL);
1444 g_return_if_fail (GDK_IS_WINDOW (window));
1446 if (!GDK_WINDOW_DESTROYED (window))
1447 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1448 x, y, width, height, True);
1454 * @window: a #GdkWindow
1456 * Raises @window to the top of the Z-order (stacking order), so that
1457 * other windows with the same parent window appear below @window.
1458 * This is true whether or not the windows are visible.
1460 * If @window is a toplevel, the window manager may choose to deny the
1461 * request to move the window in the Z-order, gdk_window_raise() only
1462 * requests the restack, does not guarantee it.
1466 gdk_window_raise (GdkWindow *window)
1468 g_return_if_fail (window != NULL);
1469 g_return_if_fail (GDK_IS_WINDOW (window));
1471 if (!GDK_WINDOW_DESTROYED (window))
1472 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1477 * @window: a #GdkWindow
1479 * Lowers @window to the bottom of the Z-order (stacking order), so that
1480 * other windows with the same parent window appear above @window.
1481 * This is true whether or not the other windows are visible.
1483 * If @window is a toplevel, the window manager may choose to deny the
1484 * request to move the window in the Z-order, gdk_window_lower() only
1485 * requests the restack, does not guarantee it.
1487 * Note that gdk_window_show() raises the window again, so don't call this
1488 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1492 gdk_window_lower (GdkWindow *window)
1494 g_return_if_fail (window != NULL);
1495 g_return_if_fail (GDK_IS_WINDOW (window));
1497 if (!GDK_WINDOW_DESTROYED (window))
1498 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1503 * @window: a #GdkWindow
1504 * @timestamp: timestamp of the event triggering the window focus
1506 * Sets keyboard focus to @window. If @window is not onscreen this
1507 * will not work. In most cases, gtk_window_present() should be used on
1508 * a #GtkWindow, rather than calling this function.
1512 gdk_window_focus (GdkWindow *window,
1515 g_return_if_fail (GDK_IS_WINDOW (window));
1517 if (GDK_WINDOW_DESTROYED (window))
1520 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1521 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1525 xev.xclient.type = ClientMessage;
1526 xev.xclient.serial = 0;
1527 xev.xclient.send_event = True;
1528 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1529 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1530 "_NET_ACTIVE_WINDOW");
1531 xev.xclient.format = 32;
1532 xev.xclient.data.l[0] = 0;
1534 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1535 SubstructureRedirectMask | SubstructureNotifyMask,
1540 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1542 /* There is no way of knowing reliably whether we are viewable so we need
1543 * to trap errors so we don't cause a BadMatch.
1545 gdk_error_trap_push ();
1546 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1547 GDK_WINDOW_XWINDOW (window),
1550 XSync (GDK_WINDOW_XDISPLAY (window), False);
1551 gdk_error_trap_pop ();
1556 * gdk_window_set_hints:
1557 * @window: a #GdkWindow
1558 * @x: ignored field, does not matter
1559 * @y: ignored field, does not matter
1560 * @min_width: minimum width hint
1561 * @min_height: minimum height hint
1562 * @max_width: max width hint
1563 * @max_height: max height hint
1564 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1566 * This function is broken and useless and you should ignore it.
1567 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1568 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1569 * depending on what you're trying to do.
1571 * If using GDK directly, use gdk_window_set_geometry_hints().
1575 gdk_window_set_hints (GdkWindow *window,
1584 XSizeHints size_hints;
1586 g_return_if_fail (window != NULL);
1587 g_return_if_fail (GDK_IS_WINDOW (window));
1589 if (GDK_WINDOW_DESTROYED (window))
1592 size_hints.flags = 0;
1594 if (flags & GDK_HINT_POS)
1596 size_hints.flags |= PPosition;
1601 if (flags & GDK_HINT_MIN_SIZE)
1603 size_hints.flags |= PMinSize;
1604 size_hints.min_width = min_width;
1605 size_hints.min_height = min_height;
1608 if (flags & GDK_HINT_MAX_SIZE)
1610 size_hints.flags |= PMaxSize;
1611 size_hints.max_width = max_width;
1612 size_hints.max_height = max_height;
1615 /* FIXME: Would it be better to delete this property if
1616 * flags == 0? It would save space on the server
1618 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1619 GDK_WINDOW_XID (window),
1624 * gdk_window_set_type_hint:
1625 * @window: A toplevel #GdkWindow
1626 * @hint: A hint of the function this window will have
1628 * The application can use this call to provide a hint to the window
1629 * manager about the functionality of a window. The window manager
1630 * can use this information when determining the decoration and behaviour
1633 * The hint must be set before the window is mapped.
1636 gdk_window_set_type_hint (GdkWindow *window,
1637 GdkWindowTypeHint hint)
1639 GdkDisplay *display;
1642 g_return_if_fail (window != NULL);
1643 g_return_if_fail (GDK_IS_WINDOW (window));
1645 if (GDK_WINDOW_DESTROYED (window))
1648 display = gdk_drawable_get_display (window);
1652 case GDK_WINDOW_TYPE_HINT_DIALOG:
1653 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1655 case GDK_WINDOW_TYPE_HINT_MENU:
1656 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1658 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1659 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1661 case GDK_WINDOW_TYPE_HINT_UTILITY:
1662 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1664 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1665 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASHSCREEN");
1667 case GDK_WINDOW_TYPE_HINT_DOCK:
1668 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1670 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1671 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1674 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1676 case GDK_WINDOW_TYPE_HINT_NORMAL:
1677 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1681 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1682 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1683 XA_ATOM, 32, PropModeReplace,
1684 (guchar *)&atom, 1);
1689 gdk_wmspec_change_state (gboolean add,
1694 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1697 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1698 #define _NET_WM_STATE_ADD 1 /* add/set property */
1699 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1701 xev.xclient.type = ClientMessage;
1702 xev.xclient.serial = 0;
1703 xev.xclient.send_event = True;
1704 xev.xclient.window = GDK_WINDOW_XID (window);
1705 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1706 xev.xclient.format = 32;
1707 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1708 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1709 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1711 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1712 SubstructureRedirectMask | SubstructureNotifyMask,
1717 * gdk_window_set_modal_hint:
1718 * @window: A toplevel #GdkWindow
1719 * @modal: TRUE if the window is modal, FALSE otherwise.
1721 * The application can use this hint to tell the window manager
1722 * that a certain window has modal behaviour. The window manager
1723 * can use this information to handle modal windows in a special
1726 * You should only use this on windows for which you have
1727 * previously called #gdk_window_set_transient_for()
1730 gdk_window_set_modal_hint (GdkWindow *window,
1733 GdkWindowObject *private;
1735 g_return_if_fail (window != NULL);
1736 g_return_if_fail (GDK_IS_WINDOW (window));
1738 if (GDK_WINDOW_DESTROYED (window))
1741 private = (GdkWindowObject*) window;
1743 private->modal_hint = modal;
1745 if (GDK_WINDOW_IS_MAPPED (window))
1746 gdk_wmspec_change_state (modal, window,
1747 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1752 * gdk_window_set_skip_taskbar_hint:
1753 * @window: a toplevel #GdkWindow
1754 * @skips_taskbar: %TRUE to skip the taskbar
1756 * Toggles whether a window should appear in a task list or window
1757 * list. If a window's semantic type as specified with
1758 * gdk_window_set_type_hint() already fully describes the window, this
1759 * function should NOT be called in addition, instead you should allow
1760 * the window to be treated according to standard policy for its
1764 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
1765 gboolean skips_taskbar)
1767 GdkWindowObject *private;
1768 GdkWindowImplX11 *impl;
1770 g_return_if_fail (window != NULL);
1771 g_return_if_fail (GDK_IS_WINDOW (window));
1773 if (GDK_WINDOW_DESTROYED (window))
1776 private = (GdkWindowObject*) window;
1777 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1779 impl->skip_taskbar_hint = skips_taskbar;
1781 if (GDK_WINDOW_IS_MAPPED (window))
1782 gdk_wmspec_change_state (skips_taskbar, window,
1783 gdk_atom_intern ("_NET_WM_STATE_SKIP_TASKBAR", FALSE),
1788 * gdk_window_set_skip_pager_hint:
1789 * @window: a toplevel #GdkWindow
1790 * @skips_pager: %TRUE to skip the pager
1792 * Toggles whether a window should appear in a pager (workspace
1793 * switcher, or other desktop utility program that displays a small
1794 * thumbnail representation of the windows on the desktop). If a
1795 * window's semantic type as specified with gdk_window_set_type_hint()
1796 * already fully describes the window, this function should NOT be
1797 * called in addition, instead you should allow the window to be
1798 * treated according to standard policy for its semantic type.
1801 gdk_window_set_skip_pager_hint (GdkWindow *window,
1802 gboolean skips_pager)
1804 GdkWindowObject *private;
1805 GdkWindowImplX11 *impl;
1807 g_return_if_fail (window != NULL);
1808 g_return_if_fail (GDK_IS_WINDOW (window));
1810 if (GDK_WINDOW_DESTROYED (window))
1813 private = (GdkWindowObject*) window;
1814 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1816 impl->skip_pager_hint = skips_pager;
1818 if (GDK_WINDOW_IS_MAPPED (window))
1819 gdk_wmspec_change_state (skips_pager, window,
1820 gdk_atom_intern ("_NET_WM_STATE_SKIP_PAGER", FALSE),
1825 * gdk_window_set_geometry_hints:
1826 * @window: a toplevel #GdkWindow
1827 * @geometry: geometry hints
1828 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1830 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1831 * are set, hints not flagged in @geom_mask are unset.
1832 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1834 * This function provides hints to the windowing system about
1835 * acceptable sizes for a toplevel window. The purpose of
1836 * this is to constrain user resizing, but the windowing system
1837 * will typically (but is not required to) also constrain the
1838 * current size of the window to the provided values and
1839 * constrain programatic resizing via gdk_window_resize() or
1840 * gdk_window_move_resize().
1842 * Note that on X11, this effect has no effect on windows
1843 * of type GDK_WINDOW_TEMP or windows where override_redirect
1844 * has been turned on via gdk_window_set_override_redirect()
1845 * since these windows are not resizable by the user.
1847 * Since you can't count on the windowing system doing the
1848 * constraints for programmatic resizes, you should generally
1849 * call gdk_window_constrain_size() yourself to determine
1850 * appropriate sizes.
1854 gdk_window_set_geometry_hints (GdkWindow *window,
1855 GdkGeometry *geometry,
1856 GdkWindowHints geom_mask)
1858 XSizeHints size_hints;
1860 g_return_if_fail (window != NULL);
1861 g_return_if_fail (GDK_IS_WINDOW (window));
1863 if (GDK_WINDOW_DESTROYED (window))
1866 size_hints.flags = 0;
1868 if (geom_mask & GDK_HINT_POS)
1870 size_hints.flags |= PPosition;
1871 /* We need to initialize the following obsolete fields because KWM
1872 * apparently uses these fields if they are non-zero.
1879 if (geom_mask & GDK_HINT_USER_POS)
1881 size_hints.flags |= USPosition;
1884 if (geom_mask & GDK_HINT_USER_SIZE)
1886 size_hints.flags |= USSize;
1889 if (geom_mask & GDK_HINT_MIN_SIZE)
1891 size_hints.flags |= PMinSize;
1892 size_hints.min_width = geometry->min_width;
1893 size_hints.min_height = geometry->min_height;
1896 if (geom_mask & GDK_HINT_MAX_SIZE)
1898 size_hints.flags |= PMaxSize;
1899 size_hints.max_width = MAX (geometry->max_width, 1);
1900 size_hints.max_height = MAX (geometry->max_height, 1);
1903 if (geom_mask & GDK_HINT_BASE_SIZE)
1905 size_hints.flags |= PBaseSize;
1906 size_hints.base_width = geometry->base_width;
1907 size_hints.base_height = geometry->base_height;
1910 if (geom_mask & GDK_HINT_RESIZE_INC)
1912 size_hints.flags |= PResizeInc;
1913 size_hints.width_inc = geometry->width_inc;
1914 size_hints.height_inc = geometry->height_inc;
1917 if (geom_mask & GDK_HINT_ASPECT)
1919 size_hints.flags |= PAspect;
1920 if (geometry->min_aspect <= 1)
1922 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1923 size_hints.min_aspect.y = 65536;
1927 size_hints.min_aspect.x = 65536;
1928 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1930 if (geometry->max_aspect <= 1)
1932 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1933 size_hints.max_aspect.y = 65536;
1937 size_hints.max_aspect.x = 65536;
1938 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1942 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1944 size_hints.flags |= PWinGravity;
1945 size_hints.win_gravity = geometry->win_gravity;
1948 /* FIXME: Would it be better to delete this property if
1949 * geom_mask == 0? It would save space on the server
1951 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1952 GDK_WINDOW_XID (window),
1957 gdk_window_get_geometry_hints (GdkWindow *window,
1958 GdkGeometry *geometry,
1959 GdkWindowHints *geom_mask)
1961 XSizeHints size_hints;
1962 glong junk_size_mask = 0;
1964 g_return_if_fail (GDK_IS_WINDOW (window));
1965 g_return_if_fail (geometry != NULL);
1966 g_return_if_fail (geom_mask != NULL);
1970 if (GDK_WINDOW_DESTROYED (window))
1973 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1974 GDK_WINDOW_XID (window),
1979 if (size_hints.flags & PMinSize)
1981 *geom_mask |= GDK_HINT_MIN_SIZE;
1982 geometry->min_width = size_hints.min_width;
1983 geometry->min_height = size_hints.min_height;
1986 if (size_hints.flags & PMaxSize)
1988 *geom_mask |= GDK_HINT_MAX_SIZE;
1989 geometry->max_width = MAX (size_hints.max_width, 1);
1990 geometry->max_height = MAX (size_hints.max_height, 1);
1993 if (size_hints.flags & PResizeInc)
1995 *geom_mask |= GDK_HINT_RESIZE_INC;
1996 geometry->width_inc = size_hints.width_inc;
1997 geometry->height_inc = size_hints.height_inc;
2000 if (size_hints.flags & PAspect)
2002 *geom_mask |= GDK_HINT_ASPECT;
2004 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
2005 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
2008 if (size_hints.flags & PWinGravity)
2010 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2011 geometry->win_gravity = size_hints.win_gravity;
2016 utf8_is_latin1 (const gchar *str)
2018 const char *p = str;
2022 gunichar ch = g_utf8_get_char (p);
2027 p = g_utf8_next_char (p);
2033 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2034 * convertable to STRING, otherwise, set it as compound text
2037 set_text_property (GdkDisplay *display,
2040 const gchar *utf8_str)
2042 guchar *prop_text = NULL;
2047 if (utf8_is_latin1 (utf8_str))
2049 prop_type = XA_STRING;
2050 prop_text = gdk_utf8_to_string_target (utf8_str);
2051 prop_length = prop_text ? strlen (prop_text) : 0;
2058 gdk_utf8_to_compound_text_for_display (display,
2059 utf8_str, &gdk_type, &prop_format,
2060 &prop_text, &prop_length);
2061 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2066 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2069 prop_type, prop_format,
2070 PropModeReplace, prop_text,
2077 /* Set WM_NAME and _NET_WM_NAME
2080 set_wm_name (GdkDisplay *display,
2084 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2085 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2086 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2087 PropModeReplace, name, strlen (name));
2089 set_text_property (display, xwindow,
2090 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2095 * gdk_window_set_title:
2096 * @window: a toplevel #GdkWindow
2097 * @title: title of @window
2099 * Sets the title of a toplevel window, to be displayed in the titlebar.
2100 * If you haven't explicitly set the icon name for the window
2101 * (using gdk_window_set_icon_name()), the icon name will be set to
2102 * @title as well. @title must be in UTF-8 encoding (as with all
2103 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2106 gdk_window_set_title (GdkWindow *window,
2109 GdkDisplay *display;
2113 g_return_if_fail (window != NULL);
2114 g_return_if_fail (GDK_IS_WINDOW (window));
2115 g_return_if_fail (title != NULL);
2117 if (GDK_WINDOW_DESTROYED (window))
2120 display = gdk_drawable_get_display (window);
2121 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2122 xwindow = GDK_WINDOW_XID (window);
2124 set_wm_name (display, xwindow, title);
2126 if (!gdk_window_icon_name_set (window))
2128 XChangeProperty (xdisplay, xwindow,
2129 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2130 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2131 PropModeReplace, title, strlen (title));
2133 set_text_property (display, xwindow,
2134 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2140 * gdk_window_set_role:
2141 * @window: a toplevel #GdkWindow
2142 * @role: a string indicating its role
2144 * When using GTK+, typically you should use gtk_window_set_role() instead
2145 * of this low-level function.
2147 * The window manager and session manager use a window's role to
2148 * distinguish it from other kinds of window in the same application.
2149 * When an application is restarted after being saved in a previous
2150 * session, all windows with the same title and role are treated as
2151 * interchangeable. So if you have two windows with the same title
2152 * that should be distinguished for session management purposes, you
2153 * should set the role on those windows. It doesn't matter what string
2154 * you use for the role, as long as you have a different role for each
2155 * non-interchangeable kind of window.
2159 gdk_window_set_role (GdkWindow *window,
2162 GdkDisplay *display;
2164 g_return_if_fail (window != NULL);
2165 g_return_if_fail (GDK_IS_WINDOW (window));
2167 display = gdk_drawable_get_display (window);
2169 if (!GDK_WINDOW_DESTROYED (window))
2172 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2173 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2174 XA_STRING, 8, PropModeReplace, role, strlen (role));
2176 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2177 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2182 * gdk_window_set_transient_for:
2183 * @window: a toplevel #GdkWindow
2184 * @parent: another toplevel #GdkWindow
2186 * Indicates to the window manager that @window is a transient dialog
2187 * associated with the application window @parent. This allows the
2188 * window manager to do things like center @window on @parent and
2189 * keep @window above @parent.
2191 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2196 gdk_window_set_transient_for (GdkWindow *window,
2199 GdkWindowObject *private;
2200 GdkWindowObject *parent_private;
2202 g_return_if_fail (window != NULL);
2203 g_return_if_fail (GDK_IS_WINDOW (window));
2205 private = (GdkWindowObject*) window;
2206 parent_private = (GdkWindowObject*) parent;
2208 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2209 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2210 GDK_WINDOW_XID (window),
2211 GDK_WINDOW_XID (parent));
2215 * gdk_window_set_background:
2216 * @window: a #GdkWindow
2217 * @color: an allocated #GdkColor
2219 * Sets the background color of @window. (However, when using GTK+,
2220 * set the background of a widget with gtk_widget_modify_bg() - if
2221 * you're an application - or gtk_style_set_background() - if you're
2222 * implementing a custom widget.)
2224 * The @color must be allocated; gdk_rgb_find_color() is the best way
2225 * to allocate a color.
2227 * See also gdk_window_set_back_pixmap().
2231 gdk_window_set_background (GdkWindow *window,
2234 GdkWindowObject *private = (GdkWindowObject *)window;
2236 g_return_if_fail (window != NULL);
2237 g_return_if_fail (GDK_IS_WINDOW (window));
2239 if (!GDK_WINDOW_DESTROYED (window))
2240 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2241 GDK_WINDOW_XID (window), color->pixel);
2243 private->bg_color = *color;
2245 if (private->bg_pixmap &&
2246 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2247 private->bg_pixmap != GDK_NO_BG)
2248 g_object_unref (private->bg_pixmap);
2250 private->bg_pixmap = NULL;
2254 * gdk_window_set_back_pixmap:
2255 * @window: a #GdkWindow
2256 * @pixmap: a #GdkPixmap, or %NULL
2257 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2259 * Sets the background pixmap of @window. May also be used to set a background of
2260 * "None" on @window, by setting a background pixmap of %NULL.
2261 * A background pixmap will be tiled, positioning the first tile at the origin of
2262 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2263 * origin of the parent window (useful to align tiles in a parent with tiles
2266 * A background pixmap of %NULL means that the window will have no
2267 * background. A window with no background will never have its
2268 * background filled by the windowing system, instead the window will
2269 * contain whatever pixels were already in the corresponding area of
2272 * The windowing system will normally fill a window with its background
2273 * when the window is obscured then exposed, and when you call
2274 * gdk_window_clear().
2278 gdk_window_set_back_pixmap (GdkWindow *window,
2280 gboolean parent_relative)
2282 GdkWindowObject *private = (GdkWindowObject *)window;
2285 g_return_if_fail (window != NULL);
2286 g_return_if_fail (GDK_IS_WINDOW (window));
2287 g_return_if_fail (pixmap == NULL || !parent_relative);
2288 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2290 if (private->bg_pixmap &&
2291 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2292 private->bg_pixmap != GDK_NO_BG)
2293 g_object_unref (private->bg_pixmap);
2295 if (parent_relative)
2297 xpixmap = ParentRelative;
2298 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2304 g_object_ref (pixmap);
2305 private->bg_pixmap = pixmap;
2306 xpixmap = GDK_PIXMAP_XID (pixmap);
2311 private->bg_pixmap = GDK_NO_BG;
2315 if (!GDK_WINDOW_DESTROYED (window))
2316 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2317 GDK_WINDOW_XID (window), xpixmap);
2321 * gdk_window_set_cursor:
2322 * @window: a #GdkWindow
2325 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2326 * gdk_cursor_new_from_pixmap() to create the cursor.
2327 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2328 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2329 * to gdk_window_set_cursor() means that @window will use the cursor of
2330 * its parent window. Most windows should use this default.
2334 gdk_window_set_cursor (GdkWindow *window,
2337 GdkCursorPrivate *cursor_private;
2340 g_return_if_fail (window != NULL);
2341 g_return_if_fail (GDK_IS_WINDOW (window));
2343 cursor_private = (GdkCursorPrivate*) cursor;
2348 xcursor = cursor_private->xcursor;
2350 if (!GDK_WINDOW_DESTROYED (window))
2351 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2352 GDK_WINDOW_XID (window),
2357 * gdk_window_get_geometry:
2358 * @window: a #GdkWindow
2359 * @x: return location for X coordinate of window (relative to its parent)
2360 * @y: return location for Y coordinate of window (relative to its parent)
2361 * @width: return location for width of window
2362 * @height: return location for height of window
2363 * @depth: return location for bit depth of window
2365 * Any of the return location arguments to this function may be %NULL,
2366 * if you aren't interested in getting the value of that field.
2368 * The X and Y coordinates returned are relative to the parent window
2369 * of @window, which for toplevels usually means relative to the
2370 * window decorations (titlebar, etc.) rather than relative to the
2371 * root window (screen-size background window).
2373 * On the X11 platform, the geometry is obtained from the X server,
2374 * so reflects the latest position of @window; this may be out-of-sync
2375 * with the position of @window delivered in the most-recently-processed
2376 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2377 * position from the most recent configure event.
2381 gdk_window_get_geometry (GdkWindow *window,
2393 guint tborder_width;
2396 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2400 GDK_NOTE (MULTIHEAD,
2401 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2402 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
2405 if (!GDK_WINDOW_DESTROYED (window))
2407 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2408 GDK_WINDOW_XID (window),
2409 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2425 * gdk_window_get_origin:
2426 * @window: a #GdkWindow
2427 * @x: return location for X coordinate
2428 * @y: return location for Y coordinate
2430 * Obtains the position of a window in root window coordinates.
2431 * (Compare with gdk_window_get_position() and
2432 * gdk_window_get_geometry() which return the position of a window
2433 * relative to its parent window.)
2435 * Return value: not meaningful, ignore
2438 gdk_window_get_origin (GdkWindow *window,
2447 g_return_val_if_fail (window != NULL, 0);
2449 if (!GDK_WINDOW_DESTROYED (window))
2451 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2452 GDK_WINDOW_XID (window),
2453 GDK_WINDOW_XROOTWIN (window),
2469 * gdk_window_get_deskrelative_origin:
2470 * @window: a toplevel #GdkWindow
2471 * @x: return location for X coordinate
2472 * @y: return location for Y coordinate
2474 * This gets the origin of a #GdkWindow relative to
2475 * an Enlightenment-window-manager desktop. As long as you don't
2476 * assume that the user's desktop/workspace covers the entire
2477 * root window (i.e. you don't assume that the desktop begins
2478 * at root window coordinate 0,0) this function is not necessary.
2479 * It's deprecated for that reason.
2481 * Return value: not meaningful
2484 gdk_window_get_deskrelative_origin (GdkWindow *window,
2488 gboolean return_val = FALSE;
2489 gint num_children, format_return;
2490 Window win, *child, parent, root;
2495 gulong number_return, bytes_after_return;
2496 guchar *data_return;
2498 g_return_val_if_fail (window != NULL, 0);
2499 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2501 if (!GDK_WINDOW_DESTROYED (window))
2503 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2504 "ENLIGHTENMENT_DESKTOP");
2505 win = GDK_WINDOW_XID (window);
2507 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2508 &child, (unsigned int *)&num_children))
2510 if ((child) && (num_children > 0))
2522 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2523 False, XA_CARDINAL, &type_return, &format_return,
2524 &number_return, &bytes_after_return, &data_return);
2526 if (type_return == XA_CARDINAL)
2528 XFree (data_return);
2533 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2534 GDK_WINDOW_XID (window),
2549 * gdk_window_get_root_origin:
2550 * @window: a toplevel #GdkWindow
2551 * @x: return location for X position of window frame
2552 * @y: return location for Y position of window frame
2554 * Obtains the top-left corner of the window manager frame in root
2555 * window coordinates.
2559 gdk_window_get_root_origin (GdkWindow *window,
2565 g_return_if_fail (GDK_IS_WINDOW (window));
2567 gdk_window_get_frame_extents (window, &rect);
2577 * gdk_window_get_frame_extents:
2578 * @window: a toplevel #GdkWindow
2579 * @rect: rectangle to fill with bounding box of the window frame
2581 * Obtains the bounding box of the window, including window manager
2582 * titlebar/borders if any. The frame position is given in root window
2583 * coordinates. To get the position of the window itself (rather than
2584 * the frame) in root window coordinates, use gdk_window_get_origin().
2588 gdk_window_get_frame_extents (GdkWindow *window,
2591 GdkWindowObject *private;
2596 unsigned int nchildren;
2598 g_return_if_fail (GDK_IS_WINDOW (window));
2599 g_return_if_fail (rect != NULL);
2601 private = (GdkWindowObject*) window;
2608 if (GDK_WINDOW_DESTROYED (window))
2611 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2612 private = (GdkWindowObject*) private->parent;
2613 if (GDK_WINDOW_DESTROYED (window))
2616 xparent = GDK_WINDOW_XID (window);
2620 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2622 &children, &nchildren))
2628 while (xparent != root);
2630 if (xparent == root)
2632 unsigned int ww, wh, wb, wd;
2635 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2646 _gdk_windowing_get_pointer (GdkDisplay *display,
2650 GdkModifierType *mask)
2652 GdkScreen *default_screen;
2660 if (display->closed)
2663 default_screen = gdk_display_get_default_screen (display);
2665 XQueryPointer (GDK_SCREEN_XDISPLAY (default_screen),
2666 GDK_SCREEN_XROOTWIN (default_screen),
2667 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
2671 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
2672 *screen = gdk_drawable_get_screen (gdk_root);
2681 _gdk_windowing_window_get_pointer (GdkDisplay *display,
2685 GdkModifierType *mask)
2687 GdkWindow *return_val;
2693 unsigned int xmask = 0;
2694 gint xoffset, yoffset;
2696 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2698 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2701 if (!GDK_WINDOW_DESTROYED (window) &&
2702 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2703 GDK_WINDOW_XID (window),
2704 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2707 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
2710 *x = winx + xoffset;
2711 *y = winy + yoffset;
2718 _gdk_windowing_window_at_pointer (GdkDisplay *display,
2727 Window xwindow_last = 0;
2729 int rootx = -1, rooty = -1;
2733 screen = gdk_display_get_default_screen (display);
2735 xwindow = GDK_SCREEN_XROOTWIN (screen);
2736 xdisplay = GDK_SCREEN_XDISPLAY (screen);
2738 /* This function really only works if the mouse pointer is held still
2739 * during its operation. If it moves from one leaf window to another
2740 * than we'll end up with inaccurate values for win_x, win_y
2743 XGrabServer (xdisplay);
2744 XQueryPointer (xdisplay, xwindow,
2745 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
2747 if (root == xwindow)
2754 xwindow_last = xwindow;
2755 XQueryPointer (xdisplay, xwindow,
2756 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
2758 XUngrabServer (xdisplay);
2760 window = gdk_window_lookup_for_display (GDK_SCREEN_DISPLAY(screen),
2762 *win_x = window ? winx : -1;
2763 *win_y = window ? winy : -1;
2769 * gdk_window_get_events:
2770 * @window: a #GdkWindow
2772 * Gets the event mask for @window. See gdk_window_set_events().
2774 * Return value: event mask for @window
2777 gdk_window_get_events (GdkWindow *window)
2779 XWindowAttributes attrs;
2780 GdkEventMask event_mask;
2782 g_return_val_if_fail (window != NULL, 0);
2783 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2785 if (GDK_WINDOW_DESTROYED (window))
2789 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2790 GDK_WINDOW_XID (window),
2793 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2794 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2801 * gdk_window_set_events:
2802 * @window: a #GdkWindow
2803 * @event_mask: event mask for @window
2805 * The event mask for a window determines which events will be reported
2806 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2807 * means the window should report button press events. The event mask
2808 * is the bitwise OR of values from the #GdkEventMask enumeration.
2812 gdk_window_set_events (GdkWindow *window,
2813 GdkEventMask event_mask)
2818 g_return_if_fail (window != NULL);
2819 g_return_if_fail (GDK_IS_WINDOW (window));
2821 if (!GDK_WINDOW_DESTROYED (window))
2823 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2824 xevent_mask = StructureNotifyMask | PropertyChangeMask;
2825 for (i = 0; i < _gdk_nenvent_masks; i++)
2827 if (event_mask & (1 << (i + 1)))
2828 xevent_mask |= _gdk_event_mask_table[i];
2831 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2832 GDK_WINDOW_XID (window),
2838 gdk_window_add_colormap_windows (GdkWindow *window)
2840 GdkWindow *toplevel;
2841 Window *old_windows;
2842 Window *new_windows;
2845 g_return_if_fail (window != NULL);
2846 g_return_if_fail (GDK_IS_WINDOW (window));
2848 if (GDK_WINDOW_DESTROYED (window))
2850 toplevel = gdk_window_get_toplevel (window);
2853 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2854 GDK_WINDOW_XID (toplevel),
2855 &old_windows, &count))
2860 for (i = 0; i < count; i++)
2861 if (old_windows[i] == GDK_WINDOW_XID (window))
2863 XFree (old_windows);
2867 new_windows = g_new (Window, count + 1);
2869 for (i = 0; i < count; i++)
2870 new_windows[i] = old_windows[i];
2871 new_windows[count] = GDK_WINDOW_XID (window);
2873 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2874 GDK_WINDOW_XID (toplevel),
2875 new_windows, count + 1);
2877 g_free (new_windows);
2879 XFree (old_windows);
2883 gdk_window_have_shape_ext (GdkDisplay *display)
2885 GdkDisplayX11 *display_x11;
2887 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2889 display_x11 = GDK_DISPLAY_X11 (display);
2891 if (display_x11->have_shape == GDK_UNKNOWN)
2894 if (XQueryExtension (display_x11->xdisplay, "SHAPE", &ignore, &ignore, &ignore))
2895 display_x11->have_shape = GDK_YES;
2897 display_x11->have_shape = GDK_NO;
2900 return (display_x11->have_shape == GDK_YES);
2903 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2906 * This needs the X11 shape extension.
2907 * If not available, shaped windows will look
2908 * ugly, but programs still work. Stefan Wille
2911 * gdk_window_shape_combine_mask:
2912 * @window: a #GdkWindow
2914 * @x: X position of shape mask with respect to @window
2915 * @y: Y position of shape mask with respect to @window
2917 * Applies a shape mask to @window. Pixels in @window corresponding to
2918 * set bits in the @mask will be visible; pixels in @window
2919 * corresponding to unset bits in the @mask will be transparent. This
2920 * gives a non-rectangular window.
2922 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
2923 * parameters are not used.
2925 * On the X11 platform, this uses an X server extension which is
2926 * widely available on most common platforms, but not available on
2927 * very old X servers, and occasionally the implementation will be
2928 * buggy. On servers without the shape extension, this function
2931 * This function works on both toplevel and child windows.
2935 gdk_window_shape_combine_mask (GdkWindow *window,
2940 gint xoffset, yoffset;
2942 g_return_if_fail (window != NULL);
2943 g_return_if_fail (GDK_IS_WINDOW (window));
2945 #ifdef HAVE_SHAPE_EXT
2946 if (GDK_WINDOW_DESTROYED (window))
2949 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2951 if (xoffset != 0 || yoffset != 0)
2953 WARN_SHAPE_TOO_BIG ();
2957 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2961 pixmap = GDK_PIXMAP_XID (mask);
2970 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2971 GDK_WINDOW_XID (window),
2977 #endif /* HAVE_SHAPE_EXT */
2981 * gdk_window_shape_combine_region:
2982 * @window: a #GdkWindow
2983 * @shape_region: region of window to be non-transparent
2984 * @offset_x: X position of @shape_region in @window coordinates
2985 * @offset_y: Y position of @shape_region in @window coordinates
2987 * Makes pixels in @window outside @shape_region be transparent,
2988 * so that the window may be nonrectangular. See also
2989 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
2991 * If @shape_region is %NULL, the shape will be unset, so the whole
2992 * window will be opaque again. @offset_x and @offset_y are ignored
2993 * if @shape_region is %NULL.
2995 * On the X11 platform, this uses an X server extension which is
2996 * widely available on most common platforms, but not available on
2997 * very old X servers, and occasionally the implementation will be
2998 * buggy. On servers without the shape extension, this function
3001 * This function works on both toplevel and child windows.
3005 gdk_window_shape_combine_region (GdkWindow *window,
3006 GdkRegion *shape_region,
3010 gint xoffset, yoffset;
3012 g_return_if_fail (GDK_IS_WINDOW (window));
3014 #ifdef HAVE_SHAPE_EXT
3015 if (GDK_WINDOW_DESTROYED (window))
3018 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3020 if (xoffset != 0 || yoffset != 0)
3022 WARN_SHAPE_TOO_BIG ();
3026 if (shape_region == NULL)
3028 /* Use NULL mask to unset the shape */
3029 gdk_window_shape_combine_mask (window, NULL, 0, 0);
3033 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3036 XRectangle *xrects = NULL;
3038 _gdk_region_get_xrectangles (shape_region,
3042 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3043 GDK_WINDOW_XID (window),
3052 #endif /* HAVE_SHAPE_EXT */
3057 * gdk_window_set_override_redirect:
3058 * @window: a toplevel #GdkWindow
3059 * @override_redirect: %TRUE if window should be override redirect
3061 * An override redirect window is not under the control of the window manager.
3062 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3063 * be entirely under the control of the application. The window manager
3064 * can't see the override redirect window at all.
3066 * Override redirect should only be used for short-lived temporary
3067 * windows, such as popup menus. #GtkMenu uses an override redirect
3068 * window in its implementation, for example.
3072 gdk_window_set_override_redirect (GdkWindow *window,
3073 gboolean override_redirect)
3075 XSetWindowAttributes attr;
3077 g_return_if_fail (window != NULL);
3078 g_return_if_fail (GDK_IS_WINDOW (window));
3080 if (!GDK_WINDOW_DESTROYED (window))
3082 attr.override_redirect = (override_redirect == FALSE)?False:True;
3083 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3084 GDK_WINDOW_XID (window),
3092 * gdk_window_set_icon_list:
3093 * @window: The #GdkWindow toplevel window to set the icon of.
3094 * @pixbufs: A list of pixbufs, of different sizes.
3096 * Sets a list of icons for the window. One of these will be used
3097 * to represent the window when it has been iconified. The icon is
3098 * usually shown in an icon box or some sort of task bar. Which icon
3099 * size is shown depends on the window manager. The window manager
3100 * can scale the icon but setting several size icons can give better
3101 * image quality since the window manager may only need to scale the
3102 * icon by a small amount or not at all.
3106 gdk_window_set_icon_list (GdkWindow *window,
3115 gint width, height, stride;
3118 GdkDisplay *display;
3120 g_return_if_fail (GDK_IS_WINDOW (window));
3122 if (GDK_WINDOW_DESTROYED (window))
3125 display = gdk_drawable_get_display (window);
3133 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3135 width = gdk_pixbuf_get_width (pixbuf);
3136 height = gdk_pixbuf_get_height (pixbuf);
3138 size += 2 + width * height;
3140 l = g_list_next (l);
3143 data = g_malloc (size * sizeof (gulong));
3151 width = gdk_pixbuf_get_width (pixbuf);
3152 height = gdk_pixbuf_get_height (pixbuf);
3153 stride = gdk_pixbuf_get_rowstride (pixbuf);
3154 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3159 pixels = gdk_pixbuf_get_pixels (pixbuf);
3161 for (y = 0; y < height; y++)
3163 for (x = 0; x < width; x++)
3167 r = pixels[y*stride + x*n_channels + 0];
3168 g = pixels[y*stride + x*n_channels + 1];
3169 b = pixels[y*stride + x*n_channels + 2];
3170 if (n_channels >= 4)
3171 a = pixels[y*stride + x*n_channels + 3];
3175 *p++ = a << 24 | r << 16 | g << 8 | b ;
3179 l = g_list_next (l);
3184 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3185 GDK_WINDOW_XID (window),
3186 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3189 (guchar*) data, size);
3193 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3194 GDK_WINDOW_XID (window),
3195 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3202 * gdk_window_set_icon:
3203 * @window: a toplevel #GdkWindow
3204 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
3205 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
3206 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
3208 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
3209 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
3210 * and gtk_window_set_icon(). If those don't meet your needs, look at
3211 * gdk_window_set_icon_list(). Only if all those are too high-level do you
3212 * want to fall back to gdk_window_set_icon().
3216 gdk_window_set_icon (GdkWindow *window,
3217 GdkWindow *icon_window,
3223 g_return_if_fail (window != NULL);
3224 g_return_if_fail (GDK_IS_WINDOW (window));
3226 if (GDK_WINDOW_DESTROYED (window))
3229 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3230 GDK_WINDOW_XID (window));
3232 wm_hints = XAllocWMHints ();
3234 if (icon_window != NULL)
3236 wm_hints->flags |= IconWindowHint;
3237 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
3242 wm_hints->flags |= IconPixmapHint;
3243 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
3248 wm_hints->flags |= IconMaskHint;
3249 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
3252 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3253 GDK_WINDOW_XID (window), wm_hints);
3258 gdk_window_icon_name_set (GdkWindow *window)
3260 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3261 g_quark_from_static_string ("gdk-icon-name-set")));
3265 * gdk_window_set_icon_name:
3266 * @window: a toplevel #GdkWindow
3267 * @name: name of window while iconified (minimized)
3269 * Windows may have a name used while minimized, distinct from the
3270 * name they display in their titlebar. Most of the time this is a bad
3271 * idea from a user interface standpoint. But you can set such a name
3272 * with this function, if you like.
3276 gdk_window_set_icon_name (GdkWindow *window,
3279 GdkDisplay *display;
3281 g_return_if_fail (window != NULL);
3282 g_return_if_fail (GDK_IS_WINDOW (window));
3284 if (GDK_WINDOW_DESTROYED (window))
3287 display = gdk_drawable_get_display (window);
3289 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3290 GUINT_TO_POINTER (TRUE));
3292 XChangeProperty (GDK_DISPLAY_XDISPLAY (window),
3293 GDK_WINDOW_XID (window),
3294 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3295 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3296 PropModeReplace, name, strlen (name));
3298 set_text_property (display, GDK_WINDOW_XID (window),
3299 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3304 * gdk_window_iconify:
3305 * @window: a toplevel #GdkWindow
3307 * Asks to iconify (minimize) @window. The window manager may choose
3308 * to ignore the request, but normally will honor it. Using
3309 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3311 * This function only makes sense when @window is a toplevel window.
3315 gdk_window_iconify (GdkWindow *window)
3317 GdkWindowObject *private;
3319 g_return_if_fail (window != NULL);
3320 g_return_if_fail (GDK_IS_WINDOW (window));
3322 if (GDK_WINDOW_DESTROYED (window))
3325 private = (GdkWindowObject*) window;
3327 if (GDK_WINDOW_IS_MAPPED (window))
3329 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3330 GDK_WINDOW_XWINDOW (window),
3331 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3335 /* Flip our client side flag, the real work happens on map. */
3336 gdk_synthesize_window_state (window,
3338 GDK_WINDOW_STATE_ICONIFIED);
3343 * gdk_window_deiconify:
3344 * @window: a toplevel #GdkWindow
3346 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3347 * choose to ignore the request to deiconify. When using GTK+,
3348 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3349 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3350 * unminimizes it, and puts it on the current desktop.
3354 gdk_window_deiconify (GdkWindow *window)
3356 GdkWindowObject *private;
3358 g_return_if_fail (window != NULL);
3359 g_return_if_fail (GDK_IS_WINDOW (window));
3361 if (GDK_WINDOW_DESTROYED (window))
3364 private = (GdkWindowObject*) window;
3366 if (GDK_WINDOW_IS_MAPPED (window))
3368 gdk_window_show (window);
3372 /* Flip our client side flag, the real work happens on map. */
3373 gdk_synthesize_window_state (window,
3374 GDK_WINDOW_STATE_ICONIFIED,
3381 * @window: a toplevel #GdkWindow
3383 * "Pins" a window such that it's on all workspaces and does not scroll
3384 * with viewports, for window managers that have scrollable viewports.
3385 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3387 * On the X11 platform, this function depends on window manager
3388 * support, so may have no effect with many window managers. However,
3389 * GDK will do the best it can to convince the window manager to stick
3390 * the window. For window managers that don't support this operation,
3391 * there's nothing you can do to force it to happen.
3395 gdk_window_stick (GdkWindow *window)
3397 g_return_if_fail (GDK_IS_WINDOW (window));
3399 if (GDK_WINDOW_DESTROYED (window))
3402 if (GDK_WINDOW_IS_MAPPED (window))
3404 /* "stick" means stick to all desktops _and_ do not scroll with the
3405 * viewport. i.e. glue to the monitor glass in all cases.
3410 /* Request stick during viewport scroll */
3411 gdk_wmspec_change_state (TRUE, window,
3412 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3415 /* Request desktop 0xFFFFFFFF */
3416 xev.xclient.type = ClientMessage;
3417 xev.xclient.serial = 0;
3418 xev.xclient.send_event = True;
3419 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3420 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
3421 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3423 xev.xclient.format = 32;
3425 xev.xclient.data.l[0] = 0xFFFFFFFF;
3427 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3428 SubstructureRedirectMask | SubstructureNotifyMask,
3433 /* Flip our client side flag, the real work happens on map. */
3434 gdk_synthesize_window_state (window,
3436 GDK_WINDOW_STATE_STICKY);
3441 * gdk_window_unstick:
3442 * @window: a toplevel #GdkWindow
3444 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3445 * and gtk_window_unstick().
3449 gdk_window_unstick (GdkWindow *window)
3451 g_return_if_fail (GDK_IS_WINDOW (window));
3453 if (GDK_WINDOW_DESTROYED (window))
3456 if (GDK_WINDOW_IS_MAPPED (window))
3463 gulong *current_desktop;
3464 GdkDisplay *display = gdk_drawable_get_display (window);
3466 /* Request unstick from viewport */
3467 gdk_wmspec_change_state (FALSE, window,
3468 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3471 /* Get current desktop, then set it; this is a race, but not
3472 * one that matters much in practice.
3474 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
3475 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
3477 False, XA_CARDINAL, &type, &format, &nitems,
3478 &bytes_after, (guchar **)¤t_desktop);
3480 if (type == XA_CARDINAL)
3482 xev.xclient.type = ClientMessage;
3483 xev.xclient.serial = 0;
3484 xev.xclient.send_event = True;
3485 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3486 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
3487 xev.xclient.format = 32;
3489 xev.xclient.data.l[0] = *current_desktop;
3491 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3492 SubstructureRedirectMask | SubstructureNotifyMask,
3495 XFree (current_desktop);
3500 /* Flip our client side flag, the real work happens on map. */
3501 gdk_synthesize_window_state (window,
3502 GDK_WINDOW_STATE_STICKY,
3509 * gdk_window_maximize:
3510 * @window: a toplevel #GdkWindow
3512 * Maximizes the window. If the window was already maximized, then
3513 * this function does nothing.
3515 * On X11, asks the window manager to maximize @window, if the window
3516 * manager supports this operation. Not all window managers support
3517 * this, and some deliberately ignore it or don't have a concept of
3518 * "maximized"; so you can't rely on the maximization actually
3519 * happening. But it will happen with most standard window managers,
3520 * and GDK makes a best effort to get it to happen.
3522 * On Windows, reliably maximizes the window.
3526 gdk_window_maximize (GdkWindow *window)
3528 g_return_if_fail (GDK_IS_WINDOW (window));
3530 if (GDK_WINDOW_DESTROYED (window))
3533 if (GDK_WINDOW_IS_MAPPED (window))
3534 gdk_wmspec_change_state (TRUE, window,
3535 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3536 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3538 gdk_synthesize_window_state (window,
3540 GDK_WINDOW_STATE_MAXIMIZED);
3544 * gdk_window_unmaximize:
3545 * @window: a toplevel #GdkWindow
3547 * Unmaximizes the window. If the window wasn't maximized, then this
3548 * function does nothing.
3550 * On X11, asks the window manager to unmaximize @window, if the
3551 * window manager supports this operation. Not all window managers
3552 * support this, and some deliberately ignore it or don't have a
3553 * concept of "maximized"; so you can't rely on the unmaximization
3554 * actually happening. But it will happen with most standard window
3555 * managers, and GDK makes a best effort to get it to happen.
3557 * On Windows, reliably unmaximizes the window.
3561 gdk_window_unmaximize (GdkWindow *window)
3563 g_return_if_fail (GDK_IS_WINDOW (window));
3565 if (GDK_WINDOW_DESTROYED (window))
3568 if (GDK_WINDOW_IS_MAPPED (window))
3569 gdk_wmspec_change_state (FALSE, window,
3570 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3571 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3573 gdk_synthesize_window_state (window,
3574 GDK_WINDOW_STATE_MAXIMIZED,
3579 * gdk_window_fullscreen:
3580 * @window: a toplevel #GdkWindow
3582 * Moves the window into fullscreen mode. This means the
3583 * window covers the entire screen and is above any panels
3586 * If the window was already fullscreen, then this function does nothing.
3588 * On X11, asks the window manager to put @window in a fullscreen
3589 * state, if the window manager supports this operation. Not all
3590 * window managers support this, and some deliberately ignore it or
3591 * don't have a concept of "fullscreen"; so you can't rely on the
3592 * fullscreenification actually happening. But it will happen with
3593 * most standard window managers, and GDK makes a best effort to get
3598 gdk_window_fullscreen (GdkWindow *window)
3600 g_return_if_fail (GDK_IS_WINDOW (window));
3602 if (GDK_WINDOW_DESTROYED (window))
3605 if (GDK_WINDOW_IS_MAPPED (window))
3606 gdk_wmspec_change_state (TRUE, window,
3607 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3611 gdk_synthesize_window_state (window,
3613 GDK_WINDOW_STATE_FULLSCREEN);
3617 * gdk_window_unfullscreen:
3618 * @window: a toplevel #GdkWindow
3620 * Moves the window out of fullscreen mode. If the window was not
3621 * fullscreen, does nothing.
3623 * On X11, asks the window manager to move @window out of the fullscreen
3624 * state, if the window manager supports this operation. Not all
3625 * window managers support this, and some deliberately ignore it or
3626 * don't have a concept of "fullscreen"; so you can't rely on the
3627 * unfullscreenification actually happening. But it will happen with
3628 * most standard window managers, and GDK makes a best effort to get
3633 gdk_window_unfullscreen (GdkWindow *window)
3635 g_return_if_fail (GDK_IS_WINDOW (window));
3637 if (GDK_WINDOW_DESTROYED (window))
3640 if (GDK_WINDOW_IS_MAPPED (window))
3641 gdk_wmspec_change_state (FALSE, window,
3642 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3646 gdk_synthesize_window_state (window,
3647 GDK_WINDOW_STATE_FULLSCREEN,
3653 * gdk_window_set_group:
3654 * @window: a toplevel #GdkWindow
3655 * @leader: group leader window
3657 * Sets the group leader window for @window. By default,
3658 * GDK sets the group leader for all toplevel windows
3659 * to a global window implicitly created by GDK. With this function
3660 * you can override this default.
3662 * The group leader window allows the window manager to distinguish
3663 * all windows that belong to a single application. It may for example
3664 * allow users to minimize/unminimize all windows belonging to an
3665 * application at once. You should only set a non-default group window
3666 * if your application pretends to be multiple applications.
3667 * The group leader window may not be changed after a window has been
3668 * mapped (with gdk_window_show() for example).
3672 gdk_window_set_group (GdkWindow *window,
3677 g_return_if_fail (window != NULL);
3678 g_return_if_fail (GDK_IS_WINDOW (window));
3679 g_return_if_fail (leader != NULL);
3680 g_return_if_fail (GDK_IS_WINDOW (leader));
3682 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3685 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3686 GDK_WINDOW_XID (window));
3688 wm_hints = XAllocWMHints ();
3690 wm_hints->flags |= WindowGroupHint;
3691 wm_hints->window_group = GDK_WINDOW_XID (leader);
3693 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3694 GDK_WINDOW_XID (window), wm_hints);
3698 static MotifWmHints *
3699 gdk_window_get_mwm_hints (GdkWindow *window)
3701 GdkDisplay *display;
3702 Atom hints_atom = None;
3703 MotifWmHints *hints;
3709 if (GDK_WINDOW_DESTROYED (window))
3712 display = gdk_drawable_get_display (window);
3714 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3716 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3717 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3718 False, AnyPropertyType, &type, &format, &nitems,
3719 &bytes_after, (guchar **)&hints);
3728 gdk_window_set_mwm_hints (GdkWindow *window,
3729 MotifWmHints *new_hints)
3731 GdkDisplay *display;
3732 Atom hints_atom = None;
3733 MotifWmHints *hints;
3739 if (GDK_WINDOW_DESTROYED (window))
3742 display = gdk_drawable_get_display (window);
3744 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3746 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3747 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3748 False, AnyPropertyType, &type, &format, &nitems,
3749 &bytes_after, (guchar **)&hints);
3755 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3757 hints->flags |= MWM_HINTS_FUNCTIONS;
3758 hints->functions = new_hints->functions;
3760 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3762 hints->flags |= MWM_HINTS_DECORATIONS;
3763 hints->decorations = new_hints->decorations;
3767 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3768 hints_atom, hints_atom, 32, PropModeReplace,
3769 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3771 if (hints != new_hints)
3776 * gdk_window_set_decorations:
3777 * @window: a toplevel #GdkWindow
3778 * @decorations: decoration hint mask
3780 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3781 * This function sets the traditional Motif window manager hints that tell the
3782 * window manager which decorations you would like your window to have.
3783 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3784 * using the GDK function directly.
3786 * The @decorations argument is the logical OR of the fields in
3787 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3788 * mask, the other bits indicate which decorations should be turned off.
3789 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3790 * which decorations should be turned on.
3792 * Most window managers honor a decorations hint of 0 to disable all decorations,
3793 * but very few honor all possible combinations of bits.
3797 gdk_window_set_decorations (GdkWindow *window,
3798 GdkWMDecoration decorations)
3802 g_return_if_fail (window != NULL);
3803 g_return_if_fail (GDK_IS_WINDOW (window));
3805 hints.flags = MWM_HINTS_DECORATIONS;
3806 hints.decorations = decorations;
3808 gdk_window_set_mwm_hints (window, &hints);
3812 * gdk_window_get_decorations:
3813 * @window: The toplevel #GdkWindow to get the decorations from
3814 * @decorations: The window decorations will be written here
3816 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3817 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3820 gdk_window_get_decorations(GdkWindow *window,
3821 GdkWMDecoration *decorations)
3823 MotifWmHints *hints;
3824 gboolean result = FALSE;
3826 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3828 hints = gdk_window_get_mwm_hints (window);
3832 if (hints->flags & MWM_HINTS_DECORATIONS)
3835 *decorations = hints->decorations;
3846 * gdk_window_set_functions:
3847 * @window: a toplevel #GdkWindow
3848 * @functions: bitmask of operations to allow on @window
3850 * This function isn't really good for much. It sets the traditional
3851 * Motif window manager hint for which operations the window manager
3852 * should allow on a toplevel window. However, few window managers do
3853 * anything reliable or interesting with this hint. Many ignore it
3856 * The @functions argument is the logical OR of values from the
3857 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3858 * then the other bits indicate which functions to disable; if
3859 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
3864 gdk_window_set_functions (GdkWindow *window,
3865 GdkWMFunction functions)
3869 g_return_if_fail (window != NULL);
3870 g_return_if_fail (GDK_IS_WINDOW (window));
3872 hints.flags = MWM_HINTS_FUNCTIONS;
3873 hints.functions = functions;
3875 gdk_window_set_mwm_hints (window, &hints);
3878 #ifdef HAVE_SHAPE_EXT
3881 * propagate the shapes from all child windows of a GDK window to the parent
3882 * window. Shamelessly ripped from Enlightenment's code
3890 struct _gdk_span *next;
3894 gdk_add_to_span (struct _gdk_span **s,
3898 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
3905 /* scan the spans for this line */
3908 /* -- -> new span */
3909 /* == -> existing span */
3910 /* ## -> spans intersect */
3911 /* if we are in the middle of spanning the span into the line */
3914 /* case: ---- ==== */
3915 if (xx < ptr1->start - 1)
3917 /* ends before next span - extend to here */
3921 /* case: ----##=== */
3922 else if (xx <= ptr1->end)
3924 /* crosses into next span - delete next span and append */
3925 ss->end = ptr1->end;
3926 ss->next = ptr1->next;
3930 /* case: ---###--- */
3933 /* overlaps next span - delete and keep checking */
3934 ss->next = ptr1->next;
3939 /* otherwise havent started spanning it in yet */
3942 /* case: ---- ==== */
3943 if (xx < ptr1->start - 1)
3945 /* insert span here in list */
3946 noo = g_malloc (sizeof (struct _gdk_span));
3960 /* case: ----##=== */
3961 else if ((x < ptr1->start) && (xx <= ptr1->end))
3963 /* expand this span to the left point of the new one */
3967 /* case: ===###=== */
3968 else if ((x >= ptr1->start) && (xx <= ptr1->end))
3970 /* throw the span away */
3973 /* case: ---###--- */
3974 else if ((x < ptr1->start) && (xx > ptr1->end))
3981 /* case: ===##---- */
3982 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
3988 /* case: ==== ---- */
3989 /* case handled by next loop iteration - first case */
3994 /* it started in the middle but spans beyond your current list */
4000 /* it does not start inside a span or in the middle, so add it to the end */
4001 noo = g_malloc (sizeof (struct _gdk_span));
4009 noo->next = ptr2->next;
4022 gdk_add_rectangles (Display *disp,
4024 struct _gdk_span **spans,
4031 gint x1, y1, x2, y2;
4035 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
4038 /* go through all clip rects in this window's shape */
4039 for (k = 0; k < rn; k++)
4041 /* for each clip rect, add it to each line's spans */
4043 x2 = x + rl[k].x + (rl[k].width - 1);
4045 y2 = y + rl[k].y + (rl[k].height - 1);
4054 for (a = y1; a <= y2; a++)
4057 gdk_add_to_span (&spans[a], x1, x2);
4065 gdk_propagate_shapes (Display *disp,
4069 Window rt, par, *list = NULL;
4070 gint i, j, num = 0, num_rects = 0;
4074 XRectangle *rects = NULL;
4075 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
4076 XWindowAttributes xatt;
4078 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
4083 spans = g_malloc (sizeof (struct _gdk_span *) * h);
4085 for (i = 0; i < h; i++)
4087 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
4090 /* go through all child windows and create/insert spans */
4091 for (i = 0; i < num; i++)
4093 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
4094 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
4095 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
4098 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
4100 /* go through the spans list and build a list of rects */
4101 rects = g_malloc (sizeof (XRectangle) * 256);
4103 for (i = 0; i < baseh; i++)
4106 /* go through the line for all spans */
4109 rects[num_rects].x = ptr1->start;
4110 rects[num_rects].y = i;
4111 rects[num_rects].width = ptr1->end - ptr1->start + 1;
4112 rects[num_rects].height = 1;
4114 /* if there are more lines */
4116 /* while contigous rects (same start/end coords) exist */
4117 while ((contig) && (j < baseh))
4119 /* search next line for spans matching this one */
4125 /* if we have an exact span match set contig */
4126 if ((ptr2->start == ptr1->start) &&
4127 (ptr2->end == ptr1->end))
4130 /* remove the span - not needed */
4133 ptr3->next = ptr2->next;
4139 spans[j] = ptr2->next;
4145 /* gone past the span point no point looking */
4146 else if (ptr2->start < ptr1->start)
4154 /* if a contiguous span was found increase the rect h */
4157 rects[num_rects].height++;
4161 /* up the rect count */
4163 /* every 256 new rects increase the rect array */
4164 if ((num_rects % 256) == 0)
4165 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
4169 /* set the rects as the shape mask */
4172 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
4173 ShapeSet, YXSorted);
4178 /* free up all the spans we made */
4179 for (i = 0; i < baseh; i++)
4192 #endif /* HAVE_SHAPE_EXT */
4195 * gdk_window_set_child_shapes:
4196 * @window: a #GdkWindow
4198 * Sets the shape mask of @window to the union of shape masks
4199 * for all children of @window, ignoring the shape mask of @window
4200 * itself. Contrast with gdk_window_merge_child_shapes() which includes
4201 * the shape mask of @window in the masks to be merged.
4204 gdk_window_set_child_shapes (GdkWindow *window)
4206 g_return_if_fail (window != NULL);
4207 g_return_if_fail (GDK_IS_WINDOW (window));
4209 #ifdef HAVE_SHAPE_EXT
4210 if (!GDK_WINDOW_DESTROYED (window) &&
4211 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4212 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4213 GDK_WINDOW_XID (window), FALSE);
4218 * gdk_window_merge_child_shapes:
4219 * @window: a #GdkWindow
4221 * Merges the shape masks for any child windows into the
4222 * shape mask for @window. i.e. the union of all masks
4223 * for @window and its children will become the new mask
4224 * for @window. See gdk_window_shape_combine_mask().
4226 * This function is distinct from gdk_window_set_child_shapes()
4227 * because it includes @window's shape mask in the set of shapes to
4232 gdk_window_merge_child_shapes (GdkWindow *window)
4234 g_return_if_fail (window != NULL);
4235 g_return_if_fail (GDK_IS_WINDOW (window));
4237 #ifdef HAVE_SHAPE_EXT
4238 if (!GDK_WINDOW_DESTROYED (window) &&
4239 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4240 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4241 GDK_WINDOW_XID (window), TRUE);
4245 /* Support for windows that can be guffaw-scrolled
4246 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
4250 gdk_window_gravity_works (GdkWindow *window)
4252 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (window));
4254 if (display_x11->gravity_works == GDK_UNKNOWN)
4261 /* This particular server apparently has a bug so that the test
4262 * works but the actual code crashes it
4264 if ((!strcmp (XServerVendor (display_x11->xdisplay),
4265 "Sun Microsystems, Inc.")) &&
4266 (VendorRelease (display_x11->xdisplay) == 3400))
4268 display_x11->gravity_works = GDK_NO;
4272 attr.window_type = GDK_WINDOW_TEMP;
4273 attr.wclass = GDK_INPUT_OUTPUT;
4278 attr.event_mask = 0;
4280 parent = gdk_window_new (gdk_screen_get_root_window (GDK_DRAWABLE_SCREEN (window)),
4281 &attr, GDK_WA_X | GDK_WA_Y);
4283 attr.window_type = GDK_WINDOW_CHILD;
4284 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
4286 gdk_window_set_static_win_gravity (child, TRUE);
4288 gdk_window_resize (parent, 100, 110);
4290 gdk_window_move (parent, 0, -10);
4291 gdk_window_move_resize (parent, 0, 0, 100, 100);
4293 gdk_window_resize (parent, 100, 110);
4294 gdk_window_move (parent, 0, -10);
4295 gdk_window_move_resize (parent, 0, 0, 100, 100);
4297 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
4299 gdk_window_destroy (parent);
4300 gdk_window_destroy (child);
4302 display_x11->gravity_works = ((y == -20) ? GDK_YES : GDK_NO);
4305 return (display_x11->gravity_works == GDK_YES);
4309 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
4311 XSetWindowAttributes xattributes;
4312 GdkWindowObject *private;
4313 guint xattributes_mask = 0;
4315 g_return_if_fail (window != NULL);
4317 private = GDK_WINDOW_OBJECT (window);
4318 if (private->input_only)
4321 xattributes.bit_gravity = StaticGravity;
4322 xattributes_mask |= CWBitGravity;
4323 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4324 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4325 GDK_WINDOW_XID (window),
4326 CWBitGravity, &xattributes);
4330 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
4332 XSetWindowAttributes xattributes;
4334 g_return_if_fail (window != NULL);
4336 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4338 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4339 GDK_WINDOW_XID (window),
4340 CWWinGravity, &xattributes);
4344 * gdk_window_set_static_gravities:
4345 * @window: a #GdkWindow
4346 * @use_static: %TRUE to turn on static gravity
4348 * Set the bit gravity of the given window to static, and flag it so
4349 * all children get static subwindow gravity. This is used if you are
4350 * implementing scary features that involve deep knowledge of the
4351 * windowing system. Don't worry about it unless you have to.
4353 * Return value: %TRUE if the server supports static gravity
4356 gdk_window_set_static_gravities (GdkWindow *window,
4357 gboolean use_static)
4359 GdkWindowObject *private = (GdkWindowObject *)window;
4362 g_return_val_if_fail (window != NULL, FALSE);
4363 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4365 if (!use_static == !private->guffaw_gravity)
4368 if (use_static && !gdk_window_gravity_works (window))
4371 private->guffaw_gravity = use_static;
4373 if (!GDK_WINDOW_DESTROYED (window))
4375 gdk_window_set_static_bit_gravity (window, use_static);
4377 tmp_list = private->children;
4380 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4382 tmp_list = tmp_list->next;
4390 wmspec_moveresize (GdkWindow *window,
4396 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4400 /* Release passive grab */
4401 gdk_display_pointer_ungrab (display, timestamp);
4403 xev.xclient.type = ClientMessage;
4404 xev.xclient.serial = 0;
4405 xev.xclient.send_event = True;
4406 xev.xclient.window = GDK_WINDOW_XID (window);
4407 xev.xclient.message_type =
4408 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4409 xev.xclient.format = 32;
4410 xev.xclient.data.l[0] = root_x;
4411 xev.xclient.data.l[1] = root_y;
4412 xev.xclient.data.l[2] = direction;
4413 xev.xclient.data.l[3] = 0;
4414 xev.xclient.data.l[4] = 0;
4416 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4417 SubstructureRedirectMask | SubstructureNotifyMask,
4421 typedef struct _MoveResizeData MoveResizeData;
4423 struct _MoveResizeData
4425 GdkDisplay *display;
4427 GdkWindow *moveresize_window;
4428 GdkWindow *moveresize_emulation_window;
4430 GdkWindowEdge resize_edge;
4431 gint moveresize_button;
4434 gint moveresize_orig_x;
4435 gint moveresize_orig_y;
4436 gint moveresize_orig_width;
4437 gint moveresize_orig_height;
4438 GdkWindowHints moveresize_geom_mask;
4439 GdkGeometry moveresize_geometry;
4440 Time moveresize_process_time;
4441 XEvent *moveresize_pending_event;
4444 /* From the WM spec */
4445 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4446 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4447 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4448 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4449 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4450 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4451 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4452 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4453 #define _NET_WM_MOVERESIZE_MOVE 8
4456 wmspec_resize_drag (GdkWindow *window,
4465 /* Let the compiler turn a switch into a table, instead
4466 * of doing the table manually, this way is easier to verify.
4470 case GDK_WINDOW_EDGE_NORTH_WEST:
4471 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4474 case GDK_WINDOW_EDGE_NORTH:
4475 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4478 case GDK_WINDOW_EDGE_NORTH_EAST:
4479 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4482 case GDK_WINDOW_EDGE_WEST:
4483 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4486 case GDK_WINDOW_EDGE_EAST:
4487 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4490 case GDK_WINDOW_EDGE_SOUTH_WEST:
4491 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4494 case GDK_WINDOW_EDGE_SOUTH:
4495 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4498 case GDK_WINDOW_EDGE_SOUTH_EAST:
4499 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4503 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4509 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4512 static MoveResizeData *
4513 get_move_resize_data (GdkDisplay *display,
4516 MoveResizeData *mv_resize;
4517 static GQuark move_resize_quark = 0;
4519 if (!move_resize_quark)
4520 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4522 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4524 if (!mv_resize && create)
4526 mv_resize = g_new0 (MoveResizeData, 1);
4527 mv_resize->display = display;
4529 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4536 update_pos (MoveResizeData *mv_resize,
4542 dx = new_root_x - mv_resize->moveresize_x;
4543 dy = new_root_y - mv_resize->moveresize_y;
4545 if (mv_resize->is_resize)
4549 w = mv_resize->moveresize_orig_width;
4550 h = mv_resize->moveresize_orig_height;
4552 switch (mv_resize->resize_edge)
4554 case GDK_WINDOW_EDGE_SOUTH_EAST:
4563 if (mv_resize->moveresize_geom_mask)
4565 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4566 mv_resize->moveresize_geom_mask,
4570 gdk_window_resize (mv_resize->moveresize_window, w, h);
4576 x = mv_resize->moveresize_orig_x + dx;
4577 y = mv_resize->moveresize_orig_y + dy;
4579 gdk_window_move (mv_resize->moveresize_window, x, y);
4584 finish_drag (MoveResizeData *mv_resize)
4586 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4587 mv_resize->moveresize_emulation_window = NULL;
4588 mv_resize->moveresize_window = NULL;
4590 if (mv_resize->moveresize_pending_event)
4592 g_free (mv_resize->moveresize_pending_event);
4593 mv_resize->moveresize_pending_event = NULL;
4598 lookahead_motion_predicate (Display *xdisplay,
4602 gboolean *seen_release = (gboolean *)arg;
4603 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4604 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4609 switch (event->xany.type)
4612 *seen_release = TRUE;
4615 mv_resize->moveresize_process_time = event->xmotion.time;
4625 moveresize_lookahead (MoveResizeData *mv_resize,
4629 gboolean seen_release = FALSE;
4631 if (mv_resize->moveresize_process_time)
4633 if (event->xmotion.time == mv_resize->moveresize_process_time)
4635 mv_resize->moveresize_process_time = 0;
4642 XCheckIfEvent (event->xany.display, &tmp_event,
4643 lookahead_motion_predicate, (XPointer) & seen_release);
4645 return mv_resize->moveresize_process_time == 0;
4649 _gdk_moveresize_handle_event (XEvent *event)
4651 guint button_mask = 0;
4652 GdkWindowObject *window_private;
4653 GdkDisplay *display= gdk_x11_lookup_xdisplay (event->xany.display);
4654 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4656 if (!mv_resize || !mv_resize->moveresize_window)
4659 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
4661 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4663 switch (event->xany.type)
4666 if (window_private->resize_count > 0)
4668 if (mv_resize->moveresize_pending_event)
4669 *mv_resize->moveresize_pending_event = *event;
4671 mv_resize->moveresize_pending_event =
4672 g_memdup (event, sizeof (XEvent));
4676 if (!moveresize_lookahead (mv_resize, event))
4679 update_pos (mv_resize,
4680 event->xmotion.x_root,
4681 event->xmotion.y_root);
4683 /* This should never be triggered in normal cases, but in the
4684 * case where the drag started without an implicit grab being
4685 * in effect, we could miss the release if it occurs before
4686 * we grab the pointer; this ensures that we will never
4687 * get a permanently stuck grab.
4689 if ((event->xmotion.state & button_mask) == 0)
4690 finish_drag (mv_resize);
4694 update_pos (mv_resize,
4695 event->xbutton.x_root,
4696 event->xbutton.y_root);
4698 if (event->xbutton.button == mv_resize->moveresize_button)
4699 finish_drag (mv_resize);
4706 _gdk_moveresize_configure_done (GdkDisplay *display,
4710 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4712 if (!mv_resize || window != mv_resize->moveresize_window)
4715 if (mv_resize->moveresize_pending_event)
4717 tmp_event = mv_resize->moveresize_pending_event;
4718 mv_resize->moveresize_pending_event = NULL;
4719 _gdk_moveresize_handle_event (tmp_event);
4727 create_moveresize_window (MoveResizeData *mv_resize,
4730 GdkWindowAttr attributes;
4731 gint attributes_mask;
4732 GdkGrabStatus status;
4734 g_assert (mv_resize->moveresize_emulation_window == NULL);
4736 attributes.x = -100;
4737 attributes.y = -100;
4738 attributes.width = 10;
4739 attributes.height = 10;
4740 attributes.window_type = GDK_WINDOW_TEMP;
4741 attributes.wclass = GDK_INPUT_ONLY;
4742 attributes.override_redirect = TRUE;
4743 attributes.event_mask = 0;
4745 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4747 mv_resize->moveresize_emulation_window =
4748 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
4752 gdk_window_show (mv_resize->moveresize_emulation_window);
4754 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
4756 GDK_BUTTON_RELEASE_MASK |
4757 GDK_POINTER_MOTION_MASK,
4762 if (status != GDK_GRAB_SUCCESS)
4764 /* If this fails, some other client has grabbed the window
4767 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4768 mv_resize->moveresize_emulation_window = NULL;
4771 mv_resize->moveresize_process_time = 0;
4775 emulate_resize_drag (GdkWindow *window,
4782 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4784 mv_resize->is_resize = TRUE;
4785 mv_resize->moveresize_button = button;
4786 mv_resize->resize_edge = edge;
4787 mv_resize->moveresize_x = root_x;
4788 mv_resize->moveresize_y = root_y;
4789 mv_resize->moveresize_window = g_object_ref (window);
4791 gdk_drawable_get_size (window,
4792 &mv_resize->moveresize_orig_width,
4793 &mv_resize->moveresize_orig_height);
4795 mv_resize->moveresize_geom_mask = 0;
4796 gdk_window_get_geometry_hints (window,
4797 &mv_resize->moveresize_geometry,
4798 &mv_resize->moveresize_geom_mask);
4800 create_moveresize_window (mv_resize, timestamp);
4804 emulate_move_drag (GdkWindow *window,
4810 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4812 mv_resize->is_resize = FALSE;
4813 mv_resize->moveresize_button = button;
4814 mv_resize->moveresize_x = root_x;
4815 mv_resize->moveresize_y = root_y;
4817 mv_resize->moveresize_window = g_object_ref (window);
4819 gdk_window_get_deskrelative_origin (mv_resize->moveresize_window,
4820 &mv_resize->moveresize_orig_x,
4821 &mv_resize->moveresize_orig_y);
4823 create_moveresize_window (mv_resize, timestamp);
4827 * gdk_window_begin_resize_drag:
4828 * @window: a toplevel #GdkWindow
4829 * @edge: the edge or corner from which the drag is started
4830 * @button: the button being used to drag
4831 * @root_x: root window X coordinate of mouse click that began the drag
4832 * @root_y: root window Y coordinate of mouse click that began the drag
4833 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
4835 * Begins a window resize operation (for a toplevel window).
4836 * You might use this function to implement a "window resize grip," for
4837 * example; in fact #GtkStatusbar uses it. The function works best
4838 * with window managers that support the Extended Window Manager Hints spec
4839 * (see http://www.freedesktop.org), but has a fallback implementation
4840 * for other window managers.
4844 gdk_window_begin_resize_drag (GdkWindow *window,
4851 g_return_if_fail (GDK_IS_WINDOW (window));
4853 if (GDK_WINDOW_DESTROYED (window))
4856 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4857 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4858 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4860 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4864 * gdk_window_begin_move_drag:
4865 * @window: a toplevel #GdkWindow
4866 * @button: the button being used to drag
4867 * @root_x: root window X coordinate of mouse click that began the drag
4868 * @root_y: root window Y coordinate of mouse click that began the drag
4869 * @timestamp: timestamp of mouse click that began the drag
4871 * Begins a window move operation (for a toplevel window). You might
4872 * use this function to implement a "window move grip," for
4873 * example. The function works best with window managers that support
4874 * the Extended Window Manager Hints spec (see
4875 * http://www.freedesktop.org), but has a fallback implementation for
4876 * other window managers.
4880 gdk_window_begin_move_drag (GdkWindow *window,
4886 g_return_if_fail (GDK_IS_WINDOW (window));
4888 if (GDK_WINDOW_DESTROYED (window))
4891 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4892 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4893 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
4896 emulate_move_drag (window, button, root_x, root_y, timestamp);