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/.
30 #include <X11/Xutil.h>
31 #include <X11/Xatom.h>
32 #include <netinet/in.h>
36 #include "gdkwindow.h"
38 #include "gdkinputprivate.h"
39 #include "gdkdisplay-x11.h"
40 #include "gdkprivate-x11.h"
41 #include "gdkregion.h"
42 #include "gdkinternals.h"
44 #include "gdkwindow-x11.h"
52 #include <X11/extensions/shape.h>
55 const int _gdk_event_mask_table[21] =
59 PointerMotionHintMask,
76 SubstructureNotifyMask,
77 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
79 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
81 /* Forward declarations */
82 static void gdk_window_set_static_win_gravity (GdkWindow *window,
84 static gboolean gdk_window_have_shape_ext (GdkDisplay *display);
85 static gboolean gdk_window_icon_name_set (GdkWindow *window);
86 static void gdk_window_add_colormap_windows (GdkWindow *window);
87 static void set_wm_name (GdkDisplay *display,
91 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
92 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
94 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
97 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
98 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
99 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
100 static void gdk_window_impl_x11_finalize (GObject *object);
102 static gpointer parent_class = NULL;
104 #define WINDOW_IS_TOPLEVEL(window) \
105 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
106 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
109 gdk_window_impl_x11_get_type (void)
111 static GType object_type = 0;
115 static const GTypeInfo object_info =
117 sizeof (GdkWindowImplX11Class),
118 (GBaseInitFunc) NULL,
119 (GBaseFinalizeFunc) NULL,
120 (GClassInitFunc) gdk_window_impl_x11_class_init,
121 NULL, /* class_finalize */
122 NULL, /* class_data */
123 sizeof (GdkWindowImplX11),
125 (GInstanceInitFunc) gdk_window_impl_x11_init,
128 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
137 _gdk_window_impl_get_type (void)
139 return gdk_window_impl_x11_get_type ();
143 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
147 impl->toplevel_window_type = -1;
151 _gdk_x11_window_get_toplevel (GdkWindow *window)
153 GdkWindowObject *private;
154 GdkWindowImplX11 *impl;
156 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
158 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
161 private = (GdkWindowObject *)window;
162 impl = GDK_WINDOW_IMPL_X11 (private->impl);
165 impl->toplevel = g_new0 (GdkToplevelX11, 1);
167 return impl->toplevel;
171 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
173 GObjectClass *object_class = G_OBJECT_CLASS (klass);
174 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
176 parent_class = g_type_class_peek_parent (klass);
178 object_class->finalize = gdk_window_impl_x11_finalize;
180 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
181 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
182 drawable_class->get_size = gdk_window_impl_x11_get_size;
184 /* Visible and clip regions are the same */
185 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
186 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
190 gdk_window_impl_x11_finalize (GObject *object)
192 GdkWindowObject *wrapper;
193 GdkDrawableImplX11 *draw_impl;
194 GdkWindowImplX11 *window_impl;
196 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
198 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
199 window_impl = GDK_WINDOW_IMPL_X11 (object);
201 wrapper = (GdkWindowObject*) draw_impl->wrapper;
203 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
205 if (!GDK_WINDOW_DESTROYED (wrapper))
207 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
209 _gdk_xid_table_remove (display, draw_impl->xid);
210 if (window_impl->toplevel && window_impl->toplevel->focus_window)
211 _gdk_xid_table_remove (display, window_impl->toplevel->focus_window);
214 if (window_impl->toplevel)
215 g_free (window_impl->toplevel);
217 G_OBJECT_CLASS (parent_class)->finalize (object);
221 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
223 GdkDrawableImplX11 *drawable_impl;
224 GdkWindowImplX11 *window_impl;
226 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
228 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
229 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
231 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
232 drawable_impl->colormap == NULL)
234 XWindowAttributes window_attributes;
237 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
241 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
242 window_attributes.visual->visualid);
243 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
244 window_attributes.colormap);
247 return drawable_impl->colormap;
251 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
254 GdkWindowImplX11 *impl;
255 GdkDrawableImplX11 *draw_impl;
257 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
259 impl = GDK_WINDOW_IMPL_X11 (drawable);
260 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
262 if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper))
266 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
270 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
272 GDK_COLORMAP_XCOLORMAP (cmap));
274 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
276 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
282 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
286 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
289 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
291 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
295 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
297 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
298 GdkRectangle result_rect;
302 result_rect.width = impl->width;
303 result_rect.height = impl->height;
305 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
307 return gdk_region_rectangle (&result_rect);
311 _gdk_windowing_window_init (GdkScreen * screen)
313 GdkWindowObject *private;
314 GdkWindowImplX11 *impl;
315 GdkDrawableImplX11 *draw_impl;
316 GdkScreenX11 *screen_x11;
318 screen_x11 = GDK_SCREEN_X11 (screen);
320 g_assert (screen_x11->root_window == NULL);
322 gdk_screen_set_default_colormap (screen,
323 gdk_screen_get_system_colormap (screen));
325 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
326 private = (GdkWindowObject *)screen_x11->root_window;
327 impl = GDK_WINDOW_IMPL_X11 (private->impl);
328 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
330 draw_impl->screen = screen;
331 draw_impl->xid = screen_x11->xroot_window;
332 draw_impl->wrapper = GDK_DRAWABLE (private);
333 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
334 g_object_ref (draw_impl->colormap);
336 private->window_type = GDK_WINDOW_ROOT;
337 private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
339 impl->width = WidthOfScreen (screen_x11->xscreen);
340 impl->height = HeightOfScreen (screen_x11->xscreen);
342 _gdk_window_init_position (GDK_WINDOW (private));
344 _gdk_xid_table_insert (screen_x11->display,
345 &screen_x11->xroot_window,
346 screen_x11->root_window);
350 set_wm_protocols (GdkWindow *window)
352 GdkDisplay *display = gdk_drawable_get_display (window);
355 protocols[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
356 protocols[1] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
357 protocols[2] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
359 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, 3);
363 get_default_title (void)
367 title = g_get_application_name ();
369 title = g_get_prgname ();
375 check_leader_window_title (GdkDisplay *display)
377 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
379 if (display_x11->leader_window && !display_x11->leader_window_title_set)
381 set_wm_name (display,
382 display_x11->leader_window,
383 get_default_title ());
385 display_x11->leader_window_title_set = TRUE;
390 create_focus_window (Display *xdisplay,
393 Window focus_window = XCreateSimpleWindow (xdisplay, parent,
397 /* FIXME: probably better to actually track the requested event mask for the toplevel
399 XSelectInput (xdisplay, focus_window,
400 KeyPressMask | KeyReleaseMask | FocusChangeMask);
402 XMapWindow (xdisplay, focus_window);
408 setup_toplevel_window (GdkWindow *window, GdkWindow *parent)
410 GdkWindowObject *obj = (GdkWindowObject *)window;
411 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
412 GdkWindowImplX11 *impl = (GdkWindowImplX11 *)obj->impl;
413 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
414 XID xid = GDK_WINDOW_XID (window);
415 XID xparent = GDK_WINDOW_XID (parent);
416 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
417 XSizeHints size_hints;
420 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_DIALOG)
421 XSetTransientForHint (xdisplay, xid, xparent);
423 set_wm_protocols (window);
425 if (!obj->input_only)
427 /* The focus window is off the visible area, and serves to receive key
428 * press events so they don't get sent to child windows.
430 toplevel->focus_window = create_focus_window (xdisplay, xid);
431 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
434 check_leader_window_title (screen_x11->display);
436 /* FIXME: Is there any point in doing this? Do any WM's pay
437 * attention to PSize, and even if they do, is this the
440 size_hints.flags = PSize;
441 size_hints.width = impl->width;
442 size_hints.height = impl->height;
444 XSetWMNormalHints (xdisplay, xid, &size_hints);
446 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
447 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
450 XChangeProperty (xdisplay, xid,
451 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
456 XChangeProperty (xdisplay, xid,
457 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
458 XA_WINDOW, 32, PropModeReplace,
459 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
461 if (!obj->focus_on_map)
462 gdk_x11_window_set_user_time(window, 0);
463 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
464 gdk_x11_window_set_user_time(window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
469 * @parent: a #GdkWindow, or %NULL to create the window as a child of
470 * the default root window for the default display.
471 * @attributes: attributes of the new window
472 * @attributes_mask: mask indicating which fields in @attributes are valid
474 * Creates a new #GdkWindow using the attributes from
475 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
476 * more details. Note: to use this on displays other than the default
477 * display, @parent must be specified.
479 * Return value: the new #GdkWindow
482 gdk_window_new (GdkWindow *parent,
483 GdkWindowAttr *attributes,
484 gint attributes_mask)
487 GdkWindowObject *private;
488 GdkWindowImplX11 *impl;
489 GdkDrawableImplX11 *draw_impl;
490 GdkScreenX11 *screen_x11;
499 XSetWindowAttributes xattributes;
500 long xattributes_mask;
501 XClassHint *class_hint;
508 g_return_val_if_fail (attributes != NULL, NULL);
513 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
515 screen = gdk_screen_get_default ();
516 parent = gdk_screen_get_root_window (screen);
519 screen = gdk_drawable_get_screen (parent);
521 screen_x11 = GDK_SCREEN_X11 (screen);
523 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
525 if (GDK_WINDOW_DESTROYED (parent))
528 xparent = GDK_WINDOW_XID (parent);
530 window = g_object_new (GDK_TYPE_WINDOW, NULL);
531 private = (GdkWindowObject *)window;
532 impl = GDK_WINDOW_IMPL_X11 (private->impl);
533 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
534 draw_impl->wrapper = GDK_DRAWABLE (window);
536 draw_impl->screen = screen;
537 xdisplay = screen_x11->xdisplay;
539 /* Windows with a foreign parent are treated as if they are children
540 * of the root window, except for actual creation.
542 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
543 parent = gdk_screen_get_root_window (screen);
545 private->parent = (GdkWindowObject *)parent;
547 private->accept_focus = TRUE;
548 private->focus_on_map = TRUE;
550 xattributes_mask = 0;
552 if (attributes_mask & GDK_WA_X)
557 if (attributes_mask & GDK_WA_Y)
564 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
565 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
567 if (attributes->wclass == GDK_INPUT_ONLY)
569 /* Backwards compatiblity - we've always ignored
570 * attributes->window_type for input-only windows
573 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
574 private->window_type = GDK_WINDOW_TEMP;
576 private->window_type = GDK_WINDOW_CHILD;
579 private->window_type = attributes->window_type;
581 _gdk_window_init_position (GDK_WINDOW (private));
582 if (impl->position_info.big)
583 private->guffaw_gravity = TRUE;
585 if (attributes_mask & GDK_WA_VISUAL)
586 visual = attributes->visual;
588 visual = gdk_screen_get_system_visual (screen);
589 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
591 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
592 for (i = 0; i < _gdk_nenvent_masks; i++)
594 if (attributes->event_mask & (1 << (i + 1)))
595 xattributes.event_mask |= _gdk_event_mask_table[i];
597 private->event_mask = attributes->event_mask;
599 if (xattributes.event_mask)
600 xattributes_mask |= CWEventMask;
602 if (attributes_mask & GDK_WA_NOREDIR)
604 xattributes.override_redirect =
605 (attributes->override_redirect == FALSE)?False:True;
606 xattributes_mask |= CWOverrideRedirect;
609 xattributes.override_redirect = False;
611 if (private->parent && private->parent->guffaw_gravity)
613 xattributes.win_gravity = StaticGravity;
614 xattributes_mask |= CWWinGravity;
618 switch (private->window_type)
620 case GDK_WINDOW_TOPLEVEL:
621 case GDK_WINDOW_DIALOG:
622 case GDK_WINDOW_TEMP:
623 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
625 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
626 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
627 xparent = GDK_SCREEN_XROOTWIN (screen);
629 case GDK_WINDOW_CHILD:
632 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
636 if (attributes->wclass == GDK_INPUT_OUTPUT)
639 depth = visual->depth;
641 private->input_only = FALSE;
642 private->depth = depth;
644 if (attributes_mask & GDK_WA_COLORMAP)
646 draw_impl->colormap = attributes->colormap;
647 g_object_ref (attributes->colormap);
651 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
653 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
654 g_object_ref (draw_impl->colormap);
658 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
662 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
663 xattributes.background_pixel = private->bg_color.pixel;
665 private->bg_pixmap = NULL;
667 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
668 xattributes_mask |= CWBorderPixel | CWBackPixel;
670 if (private->guffaw_gravity)
671 xattributes.bit_gravity = StaticGravity;
673 xattributes.bit_gravity = NorthWestGravity;
675 xattributes_mask |= CWBitGravity;
677 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
678 xattributes_mask |= CWColormap;
680 if (private->window_type == GDK_WINDOW_TEMP)
682 xattributes.save_under = True;
683 xattributes.override_redirect = True;
684 xattributes.cursor = None;
685 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
693 private->input_only = TRUE;
694 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
695 g_object_ref (draw_impl->colormap);
698 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
699 impl->position_info.x, impl->position_info.y,
700 impl->position_info.width, impl->position_info.height,
701 0, depth, class, xvisual,
702 xattributes_mask, &xattributes);
704 g_object_ref (window);
705 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
707 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
708 (attributes->cursor) :
712 private->parent->children = g_list_prepend (private->parent->children, window);
714 switch (GDK_WINDOW_TYPE (private))
716 case GDK_WINDOW_DIALOG:
717 case GDK_WINDOW_TOPLEVEL:
718 case GDK_WINDOW_TEMP:
719 if (attributes_mask & GDK_WA_TITLE)
720 title = attributes->title;
722 title = get_default_title ();
724 gdk_window_set_title (window, title);
726 if (attributes_mask & GDK_WA_WMCLASS)
728 class_hint = XAllocClassHint ();
729 class_hint->res_name = attributes->wmclass_name;
730 class_hint->res_class = attributes->wmclass_class;
731 XSetClassHint (xdisplay, xid, class_hint);
735 setup_toplevel_window (window, parent);
738 case GDK_WINDOW_CHILD:
739 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
740 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
741 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
743 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
744 gdk_window_add_colormap_windows (window);
756 x_event_mask_to_gdk_event_mask (long mask)
758 GdkEventMask event_mask = 0;
761 for (i = 0; i < _gdk_nenvent_masks; i++)
763 if (mask & _gdk_event_mask_table[i])
764 event_mask |= 1 << (i + 1);
771 * gdk_window_foreign_new_for_display:
772 * @display: the #GdkDisplay where the window handle comes from.
773 * @anid: a native window handle.
775 * Wraps a native window in a #GdkWindow.
776 * This may fail if the window has been destroyed.
778 * For example in the X backend, a native window handle is an Xlib
781 * Return value: the newly-created #GdkWindow wrapper for the
782 * native window or %NULL if the window has been destroyed.
787 gdk_window_foreign_new_for_display (GdkDisplay *display,
788 GdkNativeWindow anid)
791 GdkWindowObject *private;
792 GdkWindowImplX11 *impl;
793 GdkDrawableImplX11 *draw_impl;
794 GdkDisplayX11 *display_x11;
795 XWindowAttributes attrs;
797 Window *children = NULL;
801 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
803 display_x11 = GDK_DISPLAY_X11 (display);
805 gdk_error_trap_push ();
806 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
807 if (gdk_error_trap_pop () || !result)
810 /* FIXME: This is pretty expensive. Maybe the caller should supply
812 gdk_error_trap_push ();
813 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
814 if (gdk_error_trap_pop () || !result)
820 window = g_object_new (GDK_TYPE_WINDOW, NULL);
821 private = (GdkWindowObject *)window;
822 impl = GDK_WINDOW_IMPL_X11 (private->impl);
823 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
824 draw_impl->wrapper = GDK_DRAWABLE (window);
825 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
827 private->parent = gdk_xid_table_lookup_for_display (display, parent);
829 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
830 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
832 private->parent->children = g_list_prepend (private->parent->children, window);
834 draw_impl->xid = anid;
836 private->x = attrs.x;
837 private->y = attrs.y;
838 impl->width = attrs.width;
839 impl->height = attrs.height;
840 private->window_type = GDK_WINDOW_FOREIGN;
841 private->destroyed = FALSE;
843 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
845 if (attrs.map_state == IsUnmapped)
846 private->state = GDK_WINDOW_STATE_WITHDRAWN;
850 private->depth = attrs.depth;
852 _gdk_window_init_position (GDK_WINDOW (private));
854 g_object_ref (window);
855 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
860 * gdk_window_lookup_for_display:
861 * @display: the #GdkDisplay corresponding to the window handle
862 * @anid: a native window handle.
864 * Looks up the #GdkWindow that wraps the given native window handle.
866 * For example in the X backend, a native window handle is an Xlib
869 * Return value: the #GdkWindow wrapper for the native window,
870 * or %NULL if there is none.
875 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
877 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
882 * @anid: a native window handle.
884 * Looks up the #GdkWindow that wraps the given native window handle.
886 * For example in the X backend, a native window handle is an Xlib
889 * Return value: the #GdkWindow wrapper for the native window,
890 * or %NULL if there is none.
893 gdk_window_lookup (GdkNativeWindow anid)
895 return (GdkWindow*) gdk_xid_table_lookup (anid);
899 gdk_toplevel_x11_free_contents (GdkToplevelX11 *toplevel)
901 if (toplevel->icon_window)
903 g_object_unref (toplevel->icon_window);
904 toplevel->icon_window = NULL;
906 if (toplevel->icon_pixmap)
908 g_object_unref (toplevel->icon_pixmap);
909 toplevel->icon_pixmap = NULL;
911 if (toplevel->icon_mask)
913 g_object_unref (toplevel->icon_mask);
914 toplevel->icon_mask = NULL;
916 if (toplevel->group_leader)
918 g_object_unref (toplevel->group_leader);
919 toplevel->group_leader = NULL;
924 _gdk_windowing_window_destroy (GdkWindow *window,
926 gboolean foreign_destroy)
928 GdkWindowObject *private = (GdkWindowObject *)window;
929 GdkToplevelX11 *toplevel;
930 GdkDrawableImplX11 *draw_impl;
932 g_return_if_fail (GDK_IS_WINDOW (window));
934 _gdk_selection_window_destroyed (window);
936 if (private->extension_events != 0)
937 _gdk_input_window_destroy (window);
939 toplevel = _gdk_x11_window_get_toplevel (window);
941 gdk_toplevel_x11_free_contents (toplevel);
943 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
945 if (draw_impl->xft_draw)
946 XftDrawDestroy (draw_impl->xft_draw);
948 if (!recursing && !foreign_destroy)
950 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
955 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
957 /* It's somebody else's window, but in our heirarchy,
958 * so reparent it to the root window, and then send
959 * it a delete event, as if we were a WM
961 XClientMessageEvent xevent;
963 gdk_error_trap_push ();
964 gdk_window_hide (window);
965 gdk_window_reparent (window, NULL, 0, 0);
967 xevent.type = ClientMessage;
968 xevent.window = GDK_WINDOW_XID (window);
969 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
972 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
974 xevent.data.l[1] = CurrentTime;
975 xevent.data.l[2] = 0;
976 xevent.data.l[3] = 0;
977 xevent.data.l[4] = 0;
979 XSendEvent (GDK_WINDOW_XDISPLAY (window),
980 GDK_WINDOW_XID (window),
981 False, 0, (XEvent *)&xevent);
982 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
983 gdk_error_trap_pop ();
986 /* This function is called when the XWindow is really gone.
989 gdk_window_destroy_notify (GdkWindow *window)
991 GdkWindowImplX11 *window_impl;
993 g_return_if_fail (window != NULL);
995 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
997 if (!GDK_WINDOW_DESTROYED (window))
999 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1000 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1002 _gdk_window_destroy (window, TRUE);
1005 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1006 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1007 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1009 _gdk_xgrab_check_destroy (window);
1011 g_object_unref (window);
1015 update_wm_hints (GdkWindow *window,
1018 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1019 GdkWindowObject *private = (GdkWindowObject *)window;
1020 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1024 private->state & GDK_WINDOW_STATE_WITHDRAWN)
1027 wm_hints.flags = StateHint | InputHint;
1028 wm_hints.input = private->accept_focus ? True : False;
1029 wm_hints.initial_state = NormalState;
1031 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
1033 wm_hints.flags |= StateHint;
1034 wm_hints.initial_state = IconicState;
1037 if (toplevel->icon_window && !GDK_WINDOW_DESTROYED (toplevel->icon_window))
1039 wm_hints.flags |= IconWindowHint;
1040 wm_hints.icon_window = GDK_WINDOW_XID (toplevel->icon_window);
1043 if (toplevel->icon_pixmap)
1045 wm_hints.flags |= IconPixmapHint;
1046 wm_hints.icon_pixmap = GDK_PIXMAP_XID (toplevel->icon_pixmap);
1049 if (toplevel->icon_mask)
1051 wm_hints.flags |= IconMaskHint;
1052 wm_hints.icon_mask = GDK_PIXMAP_XID (toplevel->icon_mask);
1055 wm_hints.flags |= WindowGroupHint;
1056 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1058 wm_hints.flags |= WindowGroupHint;
1059 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1062 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1064 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1065 GDK_WINDOW_XID (window),
1070 set_initial_hints (GdkWindow *window)
1072 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1073 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1074 Window xwindow = GDK_WINDOW_XID (window);
1075 GdkWindowObject *private;
1076 GdkToplevelX11 *toplevel;
1080 private = (GdkWindowObject*) window;
1081 toplevel = _gdk_x11_window_get_toplevel (window);
1086 update_wm_hints (window, TRUE);
1088 /* We set the spec hints regardless of whether the spec is supported,
1089 * since it can't hurt and it's kind of expensive to check whether
1095 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1097 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1098 "_NET_WM_STATE_MAXIMIZED_VERT");
1100 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1101 "_NET_WM_STATE_MAXIMIZED_HORZ");
1105 if (private->state & GDK_WINDOW_STATE_STICKY)
1107 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1108 "_NET_WM_STATE_STICKY");
1112 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1114 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1115 "_NET_WM_STATE_FULLSCREEN");
1119 if (private->modal_hint)
1121 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1122 "_NET_WM_STATE_MODAL");
1126 if (toplevel->skip_taskbar_hint)
1128 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1129 "_NET_WM_STATE_SKIP_TASKBAR");
1133 if (toplevel->skip_pager_hint)
1135 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1136 "_NET_WM_STATE_SKIP_PAGER");
1142 XChangeProperty (xdisplay,
1144 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1145 XA_ATOM, 32, PropModeReplace,
1146 (guchar*) atoms, i);
1150 XDeleteProperty (xdisplay,
1152 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1155 if (private->state & GDK_WINDOW_STATE_STICKY)
1157 atoms[0] = 0xFFFFFFFF;
1158 XChangeProperty (xdisplay,
1160 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1161 XA_CARDINAL, 32, PropModeReplace,
1162 (guchar*) atoms, 1);
1166 XDeleteProperty (xdisplay,
1168 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1171 toplevel->map_serial = NextRequest (xdisplay);
1175 show_window_internal (GdkWindow *window,
1178 GdkWindowObject *private;
1180 g_return_if_fail (GDK_IS_WINDOW (window));
1182 private = (GdkWindowObject*) window;
1183 if (!private->destroyed)
1185 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1186 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1187 Window xwindow = GDK_WINDOW_XID (window);
1190 XRaiseWindow (xdisplay, xwindow);
1192 if (!GDK_WINDOW_IS_MAPPED (window))
1194 set_initial_hints (window);
1196 gdk_synthesize_window_state (window,
1197 GDK_WINDOW_STATE_WITHDRAWN,
1201 g_assert (GDK_WINDOW_IS_MAPPED (window));
1203 if (impl->position_info.mapped)
1204 XMapWindow (xdisplay, xwindow);
1209 * gdk_window_show_unraised:
1210 * @window: a #GdkWindow
1212 * Shows a #GdkWindow onscreen, but does not modify its stacking
1213 * order. In contrast, gdk_window_show() will raise the window
1214 * to the top of the window stack.
1216 * On the X11 platform, in Xlib terms, this function calls
1217 * XMapWindow() (it also updates some internal GDK state, which means
1218 * that you can't really use XMapWindow() directly on a GDK window).
1222 gdk_window_show_unraised (GdkWindow *window)
1224 g_return_if_fail (GDK_IS_WINDOW (window));
1226 show_window_internal (window, FALSE);
1231 * @window: a #GdkWindow
1233 * Like gdk_window_show_unraised(), but also raises the window to the
1234 * top of the window stack (moves the window to the front of the
1237 * This function maps a window so it's visible onscreen. Its opposite
1238 * is gdk_window_hide().
1240 * When implementing a #GtkWidget, you should call this function on the widget's
1241 * #GdkWindow as part of the "map" method.
1245 gdk_window_show (GdkWindow *window)
1247 g_return_if_fail (GDK_IS_WINDOW (window));
1249 show_window_internal (window, TRUE);
1254 * @window: a #GdkWindow
1256 * For toplevel windows, withdraws them, so they will no longer be
1257 * known to the window manager; for all windows, unmaps them, so
1258 * they won't be displayed. Normally done automatically as
1259 * part of gtk_widget_hide().
1263 gdk_window_hide (GdkWindow *window)
1265 GdkWindowObject *private;
1267 g_return_if_fail (window != NULL);
1269 private = (GdkWindowObject*) window;
1271 /* We'll get the unmap notify eventually, and handle it then,
1272 * but checking here makes things more consistent if we are
1273 * just doing stuff ourself.
1275 _gdk_xgrab_check_unmap (window,
1276 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1278 /* You can't simply unmap toplevel windows. */
1279 switch (private->window_type)
1281 case GDK_WINDOW_TOPLEVEL:
1282 case GDK_WINDOW_DIALOG:
1283 case GDK_WINDOW_TEMP: /* ? */
1284 gdk_window_withdraw (window);
1288 case GDK_WINDOW_FOREIGN:
1289 case GDK_WINDOW_ROOT:
1290 case GDK_WINDOW_CHILD:
1294 if (!private->destroyed)
1296 if (GDK_WINDOW_IS_MAPPED (window))
1297 gdk_synthesize_window_state (window,
1299 GDK_WINDOW_STATE_WITHDRAWN);
1301 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1303 _gdk_window_clear_update_area (window);
1305 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1306 GDK_WINDOW_XID (window));
1311 * gdk_window_withdraw:
1312 * @window: a toplevel #GdkWindow
1314 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1315 * This function is not really useful as gdk_window_hide() automatically
1316 * withdraws toplevel windows before hiding them.
1320 gdk_window_withdraw (GdkWindow *window)
1322 GdkWindowObject *private;
1324 g_return_if_fail (window != NULL);
1326 private = (GdkWindowObject*) window;
1327 if (!private->destroyed)
1329 if (GDK_WINDOW_IS_MAPPED (window))
1330 gdk_synthesize_window_state (window,
1332 GDK_WINDOW_STATE_WITHDRAWN);
1334 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1336 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1337 GDK_WINDOW_XID (window), 0);
1343 * @window: a #GdkWindow
1344 * @x: X coordinate relative to window's parent
1345 * @y: Y coordinate relative to window's parent
1347 * Repositions a window relative to its parent window.
1348 * For toplevel windows, window managers may ignore or modify the move;
1349 * you should probably use gtk_window_move() on a #GtkWindow widget
1350 * anyway, instead of using GDK functions. For child windows,
1351 * the move will reliably succeed.
1353 * If you're also planning to resize the window, use gdk_window_move_resize()
1354 * to both move and resize simultaneously, for a nicer visual effect.
1357 gdk_window_move (GdkWindow *window,
1361 GdkWindowObject *private = (GdkWindowObject *)window;
1362 GdkWindowImplX11 *impl;
1364 g_return_if_fail (window != NULL);
1365 g_return_if_fail (GDK_IS_WINDOW (window));
1367 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1369 if (!GDK_WINDOW_DESTROYED (window))
1371 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1372 _gdk_window_move_resize_child (window, x, y,
1373 impl->width, impl->height);
1376 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1377 GDK_WINDOW_XID (window),
1384 * gdk_window_resize:
1385 * @window: a #GdkWindow
1386 * @width: new width of the window
1387 * @height: new height of the window
1389 * Resizes @window; for toplevel windows, asks the window manager to resize
1390 * the window. The window manager may not allow the resize. When using GTK+,
1391 * use gtk_window_resize() instead of this low-level GDK function.
1393 * Windows may not be resized below 1x1.
1395 * If you're also planning to move the window, use gdk_window_move_resize()
1396 * to both move and resize simultaneously, for a nicer visual effect.
1399 gdk_window_resize (GdkWindow *window,
1403 GdkWindowObject *private;
1405 g_return_if_fail (window != NULL);
1406 g_return_if_fail (GDK_IS_WINDOW (window));
1413 private = (GdkWindowObject*) window;
1415 if (!GDK_WINDOW_DESTROYED (window))
1417 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1418 _gdk_window_move_resize_child (window, private->x, private->y,
1422 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1424 if (width != impl->width || height != impl->height)
1425 private->resize_count += 1;
1427 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1428 GDK_WINDOW_XID (window),
1435 * gdk_window_move_resize:
1436 * @window: a #GdkWindow
1437 * @x: new X position relative to window's parent
1438 * @y: new Y position relative to window's parent
1440 * @height: new height
1442 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1443 * except that both operations are performed at once, avoiding strange
1444 * visual effects. (i.e. the user may be able to see the window first
1445 * move, then resize, if you don't use gdk_window_move_resize().)
1448 gdk_window_move_resize (GdkWindow *window,
1454 GdkWindowObject *private;
1456 g_return_if_fail (window != NULL);
1457 g_return_if_fail (GDK_IS_WINDOW (window));
1464 private = (GdkWindowObject*) window;
1466 if (!GDK_WINDOW_DESTROYED (window))
1468 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1469 _gdk_window_move_resize_child (window, x, y, width, height);
1472 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1474 if (width != impl->width || height != impl->height)
1475 private->resize_count += 1;
1477 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1478 GDK_WINDOW_XID (window),
1479 x, y, width, height);
1485 * gdk_window_reparent:
1486 * @window: a #GdkWindow
1487 * @new_parent: new parent to move @window into
1488 * @x: X location inside the new parent
1489 * @y: Y location inside the new parent
1491 * Reparents @window into the given @new_parent. The window being
1492 * reparented will be unmapped as a side effect.
1496 gdk_window_reparent (GdkWindow *window,
1497 GdkWindow *new_parent,
1501 GdkDisplay *display;
1502 GdkWindowObject *window_private;
1503 GdkWindowObject *parent_private;
1504 GdkWindowObject *old_parent_private;
1505 GdkWindowImplX11 *impl;
1506 gboolean was_toplevel;
1508 g_return_if_fail (window != NULL);
1509 g_return_if_fail (GDK_IS_WINDOW (window));
1510 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1511 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1513 if (GDK_WINDOW_DESTROYED (window) ||
1514 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1520 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1522 display = GDK_WINDOW_DISPLAY (window);
1524 window_private = (GdkWindowObject*) window;
1525 old_parent_private = (GdkWindowObject*)window_private->parent;
1526 parent_private = (GdkWindowObject*) new_parent;
1527 impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
1529 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1530 GDK_WINDOW_XID (window),
1531 GDK_WINDOW_XID (new_parent),
1534 window_private->x = x;
1535 window_private->y = y;
1537 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1540 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1541 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1543 window_private->parent = (GdkWindowObject *)new_parent;
1545 /* Switch the window type as appropriate */
1547 switch (GDK_WINDOW_TYPE (new_parent))
1549 case GDK_WINDOW_ROOT:
1550 case GDK_WINDOW_FOREIGN:
1551 was_toplevel = WINDOW_IS_TOPLEVEL (window);
1553 if (impl->toplevel_window_type != -1)
1554 GDK_WINDOW_TYPE (window) = impl->toplevel_window_type;
1555 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1556 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1558 if (WINDOW_IS_TOPLEVEL (window) && !was_toplevel)
1559 setup_toplevel_window (window, new_parent);
1561 case GDK_WINDOW_TOPLEVEL:
1562 case GDK_WINDOW_CHILD:
1563 case GDK_WINDOW_DIALOG:
1564 case GDK_WINDOW_TEMP:
1565 if (WINDOW_IS_TOPLEVEL (window))
1567 /* Save the original window type so we can restore it if the
1568 * window is reparented back to be a toplevel
1570 impl->toplevel_window_type = GDK_WINDOW_TYPE (window);
1571 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1574 if (impl->toplevel->focus_window)
1576 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1577 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1580 gdk_toplevel_x11_free_contents (impl->toplevel);
1581 g_free (impl->toplevel);
1582 impl->toplevel = NULL;
1587 if (old_parent_private)
1588 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1590 if ((old_parent_private &&
1591 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1592 (!old_parent_private && parent_private->guffaw_gravity))
1593 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1595 parent_private->children = g_list_prepend (parent_private->children, window);
1596 _gdk_window_init_position (GDK_WINDOW (window_private));
1600 _gdk_windowing_window_clear_area (GdkWindow *window,
1606 g_return_if_fail (window != NULL);
1607 g_return_if_fail (GDK_IS_WINDOW (window));
1609 if (!GDK_WINDOW_DESTROYED (window))
1610 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1611 x, y, width, height, False);
1615 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1621 g_return_if_fail (window != NULL);
1622 g_return_if_fail (GDK_IS_WINDOW (window));
1624 if (!GDK_WINDOW_DESTROYED (window))
1625 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1626 x, y, width, height, True);
1632 * @window: a #GdkWindow
1634 * Raises @window to the top of the Z-order (stacking order), so that
1635 * other windows with the same parent window appear below @window.
1636 * This is true whether or not the windows are visible.
1638 * If @window is a toplevel, the window manager may choose to deny the
1639 * request to move the window in the Z-order, gdk_window_raise() only
1640 * requests the restack, does not guarantee it.
1644 gdk_window_raise (GdkWindow *window)
1646 g_return_if_fail (window != NULL);
1647 g_return_if_fail (GDK_IS_WINDOW (window));
1649 if (!GDK_WINDOW_DESTROYED (window))
1650 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1655 * @window: a #GdkWindow
1657 * Lowers @window to the bottom of the Z-order (stacking order), so that
1658 * other windows with the same parent window appear above @window.
1659 * This is true whether or not the other windows are visible.
1661 * If @window is a toplevel, the window manager may choose to deny the
1662 * request to move the window in the Z-order, gdk_window_lower() only
1663 * requests the restack, does not guarantee it.
1665 * Note that gdk_window_show() raises the window again, so don't call this
1666 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1670 gdk_window_lower (GdkWindow *window)
1672 g_return_if_fail (window != NULL);
1673 g_return_if_fail (GDK_IS_WINDOW (window));
1675 if (!GDK_WINDOW_DESTROYED (window))
1676 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1681 * @window: a #GdkWindow
1682 * @timestamp: timestamp of the event triggering the window focus
1684 * Sets keyboard focus to @window. If @window is not onscreen this
1685 * will not work. In most cases, gtk_window_present() should be used on
1686 * a #GtkWindow, rather than calling this function.
1690 gdk_window_focus (GdkWindow *window,
1693 GdkDisplay *display;
1695 g_return_if_fail (GDK_IS_WINDOW (window));
1697 if (GDK_WINDOW_DESTROYED (window))
1700 display = GDK_WINDOW_DISPLAY (window);
1702 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1703 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1707 xev.xclient.type = ClientMessage;
1708 xev.xclient.serial = 0;
1709 xev.xclient.send_event = True;
1710 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1711 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1712 "_NET_ACTIVE_WINDOW");
1713 xev.xclient.format = 32;
1714 xev.xclient.data.l[0] = 0;
1715 xev.xclient.data.l[1] = 0;
1716 xev.xclient.data.l[2] = 0;
1717 xev.xclient.data.l[3] = 0;
1718 xev.xclient.data.l[4] = 0;
1720 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1721 SubstructureRedirectMask | SubstructureNotifyMask,
1726 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1728 /* There is no way of knowing reliably whether we are viewable;
1729 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1731 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1738 * gdk_window_set_hints:
1739 * @window: a #GdkWindow
1740 * @x: ignored field, does not matter
1741 * @y: ignored field, does not matter
1742 * @min_width: minimum width hint
1743 * @min_height: minimum height hint
1744 * @max_width: max width hint
1745 * @max_height: max height hint
1746 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1748 * This function is broken and useless and you should ignore it.
1749 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1750 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1751 * depending on what you're trying to do.
1753 * If using GDK directly, use gdk_window_set_geometry_hints().
1757 gdk_window_set_hints (GdkWindow *window,
1766 XSizeHints size_hints;
1768 g_return_if_fail (window != NULL);
1769 g_return_if_fail (GDK_IS_WINDOW (window));
1771 if (GDK_WINDOW_DESTROYED (window))
1774 size_hints.flags = 0;
1776 if (flags & GDK_HINT_POS)
1778 size_hints.flags |= PPosition;
1783 if (flags & GDK_HINT_MIN_SIZE)
1785 size_hints.flags |= PMinSize;
1786 size_hints.min_width = min_width;
1787 size_hints.min_height = min_height;
1790 if (flags & GDK_HINT_MAX_SIZE)
1792 size_hints.flags |= PMaxSize;
1793 size_hints.max_width = max_width;
1794 size_hints.max_height = max_height;
1797 /* FIXME: Would it be better to delete this property if
1798 * flags == 0? It would save space on the server
1800 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1801 GDK_WINDOW_XID (window),
1806 * gdk_window_set_type_hint:
1807 * @window: A toplevel #GdkWindow
1808 * @hint: A hint of the function this window will have
1810 * The application can use this call to provide a hint to the window
1811 * manager about the functionality of a window. The window manager
1812 * can use this information when determining the decoration and behaviour
1815 * The hint must be set before the window is mapped.
1818 gdk_window_set_type_hint (GdkWindow *window,
1819 GdkWindowTypeHint hint)
1821 GdkDisplay *display;
1824 g_return_if_fail (window != NULL);
1825 g_return_if_fail (GDK_IS_WINDOW (window));
1827 if (GDK_WINDOW_DESTROYED (window))
1830 display = gdk_drawable_get_display (window);
1834 case GDK_WINDOW_TYPE_HINT_DIALOG:
1835 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1837 case GDK_WINDOW_TYPE_HINT_MENU:
1838 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1840 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1841 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1843 case GDK_WINDOW_TYPE_HINT_UTILITY:
1844 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1846 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1847 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1849 case GDK_WINDOW_TYPE_HINT_DOCK:
1850 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1852 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1853 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1856 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1858 case GDK_WINDOW_TYPE_HINT_NORMAL:
1859 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1863 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1864 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1865 XA_ATOM, 32, PropModeReplace,
1866 (guchar *)&atom, 1);
1871 gdk_wmspec_change_state (gboolean add,
1876 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1879 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1880 #define _NET_WM_STATE_ADD 1 /* add/set property */
1881 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1883 xev.xclient.type = ClientMessage;
1884 xev.xclient.serial = 0;
1885 xev.xclient.send_event = True;
1886 xev.xclient.window = GDK_WINDOW_XID (window);
1887 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1888 xev.xclient.format = 32;
1889 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1890 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1891 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1892 xev.xclient.data.l[3] = 0;
1893 xev.xclient.data.l[4] = 0;
1895 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1896 SubstructureRedirectMask | SubstructureNotifyMask,
1901 * gdk_window_set_modal_hint:
1902 * @window: A toplevel #GdkWindow
1903 * @modal: TRUE if the window is modal, FALSE otherwise.
1905 * The application can use this hint to tell the window manager
1906 * that a certain window has modal behaviour. The window manager
1907 * can use this information to handle modal windows in a special
1910 * You should only use this on windows for which you have
1911 * previously called #gdk_window_set_transient_for()
1914 gdk_window_set_modal_hint (GdkWindow *window,
1917 GdkWindowObject *private;
1919 g_return_if_fail (window != NULL);
1920 g_return_if_fail (GDK_IS_WINDOW (window));
1922 if (GDK_WINDOW_DESTROYED (window))
1925 private = (GdkWindowObject*) window;
1927 private->modal_hint = modal;
1929 if (GDK_WINDOW_IS_MAPPED (window))
1930 gdk_wmspec_change_state (modal, window,
1931 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1936 * gdk_window_set_skip_taskbar_hint:
1937 * @window: a toplevel #GdkWindow
1938 * @skips_taskbar: %TRUE to skip the taskbar
1940 * Toggles whether a window should appear in a task list or window
1941 * list. If a window's semantic type as specified with
1942 * gdk_window_set_type_hint() already fully describes the window, this
1943 * function should NOT be called in addition, instead you should allow
1944 * the window to be treated according to standard policy for its
1950 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
1951 gboolean skips_taskbar)
1953 GdkToplevelX11 *toplevel;
1955 g_return_if_fail (window != NULL);
1956 g_return_if_fail (GDK_IS_WINDOW (window));
1957 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1959 if (GDK_WINDOW_DESTROYED (window))
1962 toplevel = _gdk_x11_window_get_toplevel (window);
1963 toplevel->skip_taskbar_hint = skips_taskbar;
1965 if (GDK_WINDOW_IS_MAPPED (window))
1966 gdk_wmspec_change_state (skips_taskbar, window,
1967 gdk_atom_intern ("_NET_WM_STATE_SKIP_TASKBAR", FALSE),
1972 * gdk_window_set_skip_pager_hint:
1973 * @window: a toplevel #GdkWindow
1974 * @skips_pager: %TRUE to skip the pager
1976 * Toggles whether a window should appear in a pager (workspace
1977 * switcher, or other desktop utility program that displays a small
1978 * thumbnail representation of the windows on the desktop). If a
1979 * window's semantic type as specified with gdk_window_set_type_hint()
1980 * already fully describes the window, this function should NOT be
1981 * called in addition, instead you should allow the window to be
1982 * treated according to standard policy for its semantic type.
1987 gdk_window_set_skip_pager_hint (GdkWindow *window,
1988 gboolean skips_pager)
1990 GdkToplevelX11 *toplevel;
1992 g_return_if_fail (window != NULL);
1993 g_return_if_fail (GDK_IS_WINDOW (window));
1994 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1996 if (GDK_WINDOW_DESTROYED (window))
1999 toplevel = _gdk_x11_window_get_toplevel (window);
2000 toplevel->skip_pager_hint = skips_pager;
2002 if (GDK_WINDOW_IS_MAPPED (window))
2003 gdk_wmspec_change_state (skips_pager, window,
2004 gdk_atom_intern ("_NET_WM_STATE_SKIP_PAGER", FALSE),
2009 * gdk_window_set_geometry_hints:
2010 * @window: a toplevel #GdkWindow
2011 * @geometry: geometry hints
2012 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
2014 * Sets the geometry hints for @window. Hints flagged in @geom_mask
2015 * are set, hints not flagged in @geom_mask are unset.
2016 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
2018 * This function provides hints to the windowing system about
2019 * acceptable sizes for a toplevel window. The purpose of
2020 * this is to constrain user resizing, but the windowing system
2021 * will typically (but is not required to) also constrain the
2022 * current size of the window to the provided values and
2023 * constrain programatic resizing via gdk_window_resize() or
2024 * gdk_window_move_resize().
2026 * Note that on X11, this effect has no effect on windows
2027 * of type GDK_WINDOW_TEMP or windows where override_redirect
2028 * has been turned on via gdk_window_set_override_redirect()
2029 * since these windows are not resizable by the user.
2031 * Since you can't count on the windowing system doing the
2032 * constraints for programmatic resizes, you should generally
2033 * call gdk_window_constrain_size() yourself to determine
2034 * appropriate sizes.
2038 gdk_window_set_geometry_hints (GdkWindow *window,
2039 GdkGeometry *geometry,
2040 GdkWindowHints geom_mask)
2042 XSizeHints size_hints;
2044 g_return_if_fail (window != NULL);
2045 g_return_if_fail (GDK_IS_WINDOW (window));
2047 if (GDK_WINDOW_DESTROYED (window))
2050 size_hints.flags = 0;
2052 if (geom_mask & GDK_HINT_POS)
2054 size_hints.flags |= PPosition;
2055 /* We need to initialize the following obsolete fields because KWM
2056 * apparently uses these fields if they are non-zero.
2063 if (geom_mask & GDK_HINT_USER_POS)
2065 size_hints.flags |= USPosition;
2068 if (geom_mask & GDK_HINT_USER_SIZE)
2070 size_hints.flags |= USSize;
2073 if (geom_mask & GDK_HINT_MIN_SIZE)
2075 size_hints.flags |= PMinSize;
2076 size_hints.min_width = geometry->min_width;
2077 size_hints.min_height = geometry->min_height;
2080 if (geom_mask & GDK_HINT_MAX_SIZE)
2082 size_hints.flags |= PMaxSize;
2083 size_hints.max_width = MAX (geometry->max_width, 1);
2084 size_hints.max_height = MAX (geometry->max_height, 1);
2087 if (geom_mask & GDK_HINT_BASE_SIZE)
2089 size_hints.flags |= PBaseSize;
2090 size_hints.base_width = geometry->base_width;
2091 size_hints.base_height = geometry->base_height;
2094 if (geom_mask & GDK_HINT_RESIZE_INC)
2096 size_hints.flags |= PResizeInc;
2097 size_hints.width_inc = geometry->width_inc;
2098 size_hints.height_inc = geometry->height_inc;
2101 if (geom_mask & GDK_HINT_ASPECT)
2103 size_hints.flags |= PAspect;
2104 if (geometry->min_aspect <= 1)
2106 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2107 size_hints.min_aspect.y = 65536;
2111 size_hints.min_aspect.x = 65536;
2112 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2114 if (geometry->max_aspect <= 1)
2116 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2117 size_hints.max_aspect.y = 65536;
2121 size_hints.max_aspect.x = 65536;
2122 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2126 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2128 size_hints.flags |= PWinGravity;
2129 size_hints.win_gravity = geometry->win_gravity;
2132 /* FIXME: Would it be better to delete this property if
2133 * geom_mask == 0? It would save space on the server
2135 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2136 GDK_WINDOW_XID (window),
2141 gdk_window_get_geometry_hints (GdkWindow *window,
2142 GdkGeometry *geometry,
2143 GdkWindowHints *geom_mask)
2145 XSizeHints size_hints;
2146 glong junk_size_mask = 0;
2148 g_return_if_fail (GDK_IS_WINDOW (window));
2149 g_return_if_fail (geometry != NULL);
2150 g_return_if_fail (geom_mask != NULL);
2154 if (GDK_WINDOW_DESTROYED (window))
2157 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2158 GDK_WINDOW_XID (window),
2163 if (size_hints.flags & PMinSize)
2165 *geom_mask |= GDK_HINT_MIN_SIZE;
2166 geometry->min_width = size_hints.min_width;
2167 geometry->min_height = size_hints.min_height;
2170 if (size_hints.flags & PMaxSize)
2172 *geom_mask |= GDK_HINT_MAX_SIZE;
2173 geometry->max_width = MAX (size_hints.max_width, 1);
2174 geometry->max_height = MAX (size_hints.max_height, 1);
2177 if (size_hints.flags & PResizeInc)
2179 *geom_mask |= GDK_HINT_RESIZE_INC;
2180 geometry->width_inc = size_hints.width_inc;
2181 geometry->height_inc = size_hints.height_inc;
2184 if (size_hints.flags & PAspect)
2186 *geom_mask |= GDK_HINT_ASPECT;
2188 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
2189 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
2192 if (size_hints.flags & PWinGravity)
2194 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2195 geometry->win_gravity = size_hints.win_gravity;
2200 utf8_is_latin1 (const gchar *str)
2202 const char *p = str;
2206 gunichar ch = g_utf8_get_char (p);
2211 p = g_utf8_next_char (p);
2217 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2218 * convertable to STRING, otherwise, set it as compound text
2221 set_text_property (GdkDisplay *display,
2224 const gchar *utf8_str)
2226 guchar *prop_text = NULL;
2230 gboolean is_compound_text;
2232 if (utf8_is_latin1 (utf8_str))
2234 prop_type = XA_STRING;
2235 prop_text = gdk_utf8_to_string_target (utf8_str);
2236 prop_length = prop_text ? strlen (prop_text) : 0;
2238 is_compound_text = FALSE;
2244 gdk_utf8_to_compound_text_for_display (display,
2245 utf8_str, &gdk_type, &prop_format,
2246 &prop_text, &prop_length);
2247 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2248 is_compound_text = TRUE;
2253 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2256 prop_type, prop_format,
2257 PropModeReplace, prop_text,
2260 if (is_compound_text)
2261 gdk_free_compound_text (prop_text);
2267 /* Set WM_NAME and _NET_WM_NAME
2270 set_wm_name (GdkDisplay *display,
2274 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2275 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2276 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2277 PropModeReplace, name, strlen (name));
2279 set_text_property (display, xwindow,
2280 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2285 * gdk_window_set_title:
2286 * @window: a toplevel #GdkWindow
2287 * @title: title of @window
2289 * Sets the title of a toplevel window, to be displayed in the titlebar.
2290 * If you haven't explicitly set the icon name for the window
2291 * (using gdk_window_set_icon_name()), the icon name will be set to
2292 * @title as well. @title must be in UTF-8 encoding (as with all
2293 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2296 gdk_window_set_title (GdkWindow *window,
2299 GdkDisplay *display;
2303 g_return_if_fail (window != NULL);
2304 g_return_if_fail (GDK_IS_WINDOW (window));
2305 g_return_if_fail (title != NULL);
2307 if (GDK_WINDOW_DESTROYED (window))
2310 display = gdk_drawable_get_display (window);
2311 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2312 xwindow = GDK_WINDOW_XID (window);
2314 set_wm_name (display, xwindow, title);
2316 if (!gdk_window_icon_name_set (window))
2318 XChangeProperty (xdisplay, xwindow,
2319 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2320 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2321 PropModeReplace, title, strlen (title));
2323 set_text_property (display, xwindow,
2324 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2330 * gdk_window_set_role:
2331 * @window: a toplevel #GdkWindow
2332 * @role: a string indicating its role
2334 * When using GTK+, typically you should use gtk_window_set_role() instead
2335 * of this low-level function.
2337 * The window manager and session manager use a window's role to
2338 * distinguish it from other kinds of window in the same application.
2339 * When an application is restarted after being saved in a previous
2340 * session, all windows with the same title and role are treated as
2341 * interchangeable. So if you have two windows with the same title
2342 * that should be distinguished for session management purposes, you
2343 * should set the role on those windows. It doesn't matter what string
2344 * you use for the role, as long as you have a different role for each
2345 * non-interchangeable kind of window.
2349 gdk_window_set_role (GdkWindow *window,
2352 GdkDisplay *display;
2354 g_return_if_fail (window != NULL);
2355 g_return_if_fail (GDK_IS_WINDOW (window));
2357 display = gdk_drawable_get_display (window);
2359 if (!GDK_WINDOW_DESTROYED (window))
2362 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2363 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2364 XA_STRING, 8, PropModeReplace, role, strlen (role));
2366 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2367 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2372 * gdk_window_set_transient_for:
2373 * @window: a toplevel #GdkWindow
2374 * @parent: another toplevel #GdkWindow
2376 * Indicates to the window manager that @window is a transient dialog
2377 * associated with the application window @parent. This allows the
2378 * window manager to do things like center @window on @parent and
2379 * keep @window above @parent.
2381 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2386 gdk_window_set_transient_for (GdkWindow *window,
2389 GdkWindowObject *private;
2390 GdkWindowObject *parent_private;
2392 g_return_if_fail (window != NULL);
2393 g_return_if_fail (GDK_IS_WINDOW (window));
2395 private = (GdkWindowObject*) window;
2396 parent_private = (GdkWindowObject*) parent;
2398 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2399 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2400 GDK_WINDOW_XID (window),
2401 GDK_WINDOW_XID (parent));
2405 * gdk_window_set_background:
2406 * @window: a #GdkWindow
2407 * @color: an allocated #GdkColor
2409 * Sets the background color of @window. (However, when using GTK+,
2410 * set the background of a widget with gtk_widget_modify_bg() - if
2411 * you're an application - or gtk_style_set_background() - if you're
2412 * implementing a custom widget.)
2414 * The @color must be allocated; gdk_rgb_find_color() is the best way
2415 * to allocate a color.
2417 * See also gdk_window_set_back_pixmap().
2421 gdk_window_set_background (GdkWindow *window,
2422 const GdkColor *color)
2424 GdkWindowObject *private = (GdkWindowObject *)window;
2426 g_return_if_fail (window != NULL);
2427 g_return_if_fail (GDK_IS_WINDOW (window));
2429 if (!GDK_WINDOW_DESTROYED (window))
2430 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2431 GDK_WINDOW_XID (window), color->pixel);
2433 private->bg_color = *color;
2435 if (private->bg_pixmap &&
2436 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2437 private->bg_pixmap != GDK_NO_BG)
2438 g_object_unref (private->bg_pixmap);
2440 private->bg_pixmap = NULL;
2444 * gdk_window_set_back_pixmap:
2445 * @window: a #GdkWindow
2446 * @pixmap: a #GdkPixmap, or %NULL
2447 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2449 * Sets the background pixmap of @window. May also be used to set a background of
2450 * "None" on @window, by setting a background pixmap of %NULL.
2451 * A background pixmap will be tiled, positioning the first tile at the origin of
2452 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2453 * origin of the parent window (useful to align tiles in a parent with tiles
2456 * A background pixmap of %NULL means that the window will have no
2457 * background. A window with no background will never have its
2458 * background filled by the windowing system, instead the window will
2459 * contain whatever pixels were already in the corresponding area of
2462 * The windowing system will normally fill a window with its background
2463 * when the window is obscured then exposed, and when you call
2464 * gdk_window_clear().
2468 gdk_window_set_back_pixmap (GdkWindow *window,
2470 gboolean parent_relative)
2472 GdkWindowObject *private = (GdkWindowObject *)window;
2475 g_return_if_fail (window != NULL);
2476 g_return_if_fail (GDK_IS_WINDOW (window));
2477 g_return_if_fail (pixmap == NULL || !parent_relative);
2478 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2480 if (private->bg_pixmap &&
2481 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2482 private->bg_pixmap != GDK_NO_BG)
2483 g_object_unref (private->bg_pixmap);
2485 if (parent_relative)
2487 xpixmap = ParentRelative;
2488 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2494 g_object_ref (pixmap);
2495 private->bg_pixmap = pixmap;
2496 xpixmap = GDK_PIXMAP_XID (pixmap);
2501 private->bg_pixmap = GDK_NO_BG;
2505 if (!GDK_WINDOW_DESTROYED (window))
2506 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2507 GDK_WINDOW_XID (window), xpixmap);
2511 * gdk_window_set_cursor:
2512 * @window: a #GdkWindow
2515 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2516 * gdk_cursor_new_from_pixmap() to create the cursor.
2517 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2518 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2519 * to gdk_window_set_cursor() means that @window will use the cursor of
2520 * its parent window. Most windows should use this default.
2524 gdk_window_set_cursor (GdkWindow *window,
2527 GdkCursorPrivate *cursor_private;
2530 g_return_if_fail (window != NULL);
2531 g_return_if_fail (GDK_IS_WINDOW (window));
2533 cursor_private = (GdkCursorPrivate*) cursor;
2538 xcursor = cursor_private->xcursor;
2540 if (!GDK_WINDOW_DESTROYED (window))
2541 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2542 GDK_WINDOW_XID (window),
2547 * gdk_window_get_geometry:
2548 * @window: a #GdkWindow
2549 * @x: return location for X coordinate of window (relative to its parent)
2550 * @y: return location for Y coordinate of window (relative to its parent)
2551 * @width: return location for width of window
2552 * @height: return location for height of window
2553 * @depth: return location for bit depth of window
2555 * Any of the return location arguments to this function may be %NULL,
2556 * if you aren't interested in getting the value of that field.
2558 * The X and Y coordinates returned are relative to the parent window
2559 * of @window, which for toplevels usually means relative to the
2560 * window decorations (titlebar, etc.) rather than relative to the
2561 * root window (screen-size background window).
2563 * On the X11 platform, the geometry is obtained from the X server,
2564 * so reflects the latest position of @window; this may be out-of-sync
2565 * with the position of @window delivered in the most-recently-processed
2566 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2567 * position from the most recent configure event.
2571 gdk_window_get_geometry (GdkWindow *window,
2583 guint tborder_width;
2586 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2590 GDK_NOTE (MULTIHEAD,
2591 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2592 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
2595 if (!GDK_WINDOW_DESTROYED (window))
2597 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2598 GDK_WINDOW_XID (window),
2599 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2615 * gdk_window_get_origin:
2616 * @window: a #GdkWindow
2617 * @x: return location for X coordinate
2618 * @y: return location for Y coordinate
2620 * Obtains the position of a window in root window coordinates.
2621 * (Compare with gdk_window_get_position() and
2622 * gdk_window_get_geometry() which return the position of a window
2623 * relative to its parent window.)
2625 * Return value: not meaningful, ignore
2628 gdk_window_get_origin (GdkWindow *window,
2637 g_return_val_if_fail (window != NULL, 0);
2639 if (!GDK_WINDOW_DESTROYED (window))
2641 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2642 GDK_WINDOW_XID (window),
2643 GDK_WINDOW_XROOTWIN (window),
2659 * gdk_window_get_deskrelative_origin:
2660 * @window: a toplevel #GdkWindow
2661 * @x: return location for X coordinate
2662 * @y: return location for Y coordinate
2664 * This gets the origin of a #GdkWindow relative to
2665 * an Enlightenment-window-manager desktop. As long as you don't
2666 * assume that the user's desktop/workspace covers the entire
2667 * root window (i.e. you don't assume that the desktop begins
2668 * at root window coordinate 0,0) this function is not necessary.
2669 * It's deprecated for that reason.
2671 * Return value: not meaningful
2674 gdk_window_get_deskrelative_origin (GdkWindow *window,
2678 gboolean return_val = FALSE;
2679 gint num_children, format_return;
2680 Window win, *child, parent, root;
2685 gulong number_return, bytes_after_return;
2686 guchar *data_return;
2688 g_return_val_if_fail (window != NULL, FALSE);
2689 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2691 if (!GDK_WINDOW_DESTROYED (window))
2693 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2694 "ENLIGHTENMENT_DESKTOP");
2695 win = GDK_WINDOW_XID (window);
2697 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2698 &child, (unsigned int *)&num_children))
2700 if ((child) && (num_children > 0))
2712 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2713 False, XA_CARDINAL, &type_return, &format_return,
2714 &number_return, &bytes_after_return, &data_return);
2716 if (type_return == XA_CARDINAL)
2718 XFree (data_return);
2723 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2724 GDK_WINDOW_XID (window),
2739 * gdk_window_get_root_origin:
2740 * @window: a toplevel #GdkWindow
2741 * @x: return location for X position of window frame
2742 * @y: return location for Y position of window frame
2744 * Obtains the top-left corner of the window manager frame in root
2745 * window coordinates.
2749 gdk_window_get_root_origin (GdkWindow *window,
2755 g_return_if_fail (GDK_IS_WINDOW (window));
2757 gdk_window_get_frame_extents (window, &rect);
2767 * gdk_window_get_frame_extents:
2768 * @window: a toplevel #GdkWindow
2769 * @rect: rectangle to fill with bounding box of the window frame
2771 * Obtains the bounding box of the window, including window manager
2772 * titlebar/borders if any. The frame position is given in root window
2773 * coordinates. To get the position of the window itself (rather than
2774 * the frame) in root window coordinates, use gdk_window_get_origin().
2778 gdk_window_get_frame_extents (GdkWindow *window,
2781 GdkWindowObject *private;
2786 unsigned int nchildren;
2788 g_return_if_fail (GDK_IS_WINDOW (window));
2789 g_return_if_fail (rect != NULL);
2791 private = (GdkWindowObject*) window;
2798 if (GDK_WINDOW_DESTROYED (window))
2801 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2802 private = (GdkWindowObject*) private->parent;
2804 /* Refine our fallback answer a bit using local information */
2805 rect->x = private->x;
2806 rect->y = private->y;
2807 gdk_drawable_get_size ((GdkDrawable *)private, &rect->width, &rect->height);
2809 if (GDK_WINDOW_DESTROYED (private))
2812 gdk_error_trap_push();
2814 xparent = GDK_WINDOW_XID (window);
2818 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2820 &children, &nchildren))
2826 while (xparent != root);
2828 if (xparent == root)
2830 unsigned int ww, wh, wb, wd;
2833 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2843 gdk_error_trap_pop ();
2847 _gdk_windowing_get_pointer (GdkDisplay *display,
2851 GdkModifierType *mask)
2853 GdkScreen *default_screen;
2861 if (display->closed)
2864 default_screen = gdk_display_get_default_screen (display);
2866 XQueryPointer (GDK_SCREEN_XDISPLAY (default_screen),
2867 GDK_SCREEN_XROOTWIN (default_screen),
2868 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
2872 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
2873 *screen = gdk_drawable_get_screen (gdk_root);
2882 _gdk_windowing_window_get_pointer (GdkDisplay *display,
2886 GdkModifierType *mask)
2888 GdkWindow *return_val;
2894 unsigned int xmask = 0;
2895 gint xoffset, yoffset;
2897 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2899 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2902 if (!GDK_WINDOW_DESTROYED (window) &&
2903 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2904 GDK_WINDOW_XID (window),
2905 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2908 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
2911 *x = winx + xoffset;
2912 *y = winy + yoffset;
2919 _gdk_windowing_window_at_pointer (GdkDisplay *display,
2928 Window xwindow_last = 0;
2930 int rootx = -1, rooty = -1;
2934 screen = gdk_display_get_default_screen (display);
2936 xwindow = GDK_SCREEN_XROOTWIN (screen);
2937 xdisplay = GDK_SCREEN_XDISPLAY (screen);
2939 /* This function really only works if the mouse pointer is held still
2940 * during its operation. If it moves from one leaf window to another
2941 * than we'll end up with inaccurate values for win_x, win_y
2944 gdk_x11_display_grab (display);
2945 XQueryPointer (xdisplay, xwindow,
2946 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
2948 if (root == xwindow)
2955 xwindow_last = xwindow;
2956 XQueryPointer (xdisplay, xwindow,
2957 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
2959 gdk_x11_display_ungrab (display);
2961 window = gdk_window_lookup_for_display (GDK_SCREEN_DISPLAY(screen),
2963 *win_x = window ? winx : -1;
2964 *win_y = window ? winy : -1;
2970 * gdk_window_get_events:
2971 * @window: a #GdkWindow
2973 * Gets the event mask for @window. See gdk_window_set_events().
2975 * Return value: event mask for @window
2978 gdk_window_get_events (GdkWindow *window)
2980 XWindowAttributes attrs;
2981 GdkEventMask event_mask;
2983 g_return_val_if_fail (window != NULL, 0);
2984 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2986 if (GDK_WINDOW_DESTROYED (window))
2990 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2991 GDK_WINDOW_XID (window),
2994 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2995 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
3002 * gdk_window_set_events:
3003 * @window: a #GdkWindow
3004 * @event_mask: event mask for @window
3006 * The event mask for a window determines which events will be reported
3007 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
3008 * means the window should report button press events. The event mask
3009 * is the bitwise OR of values from the #GdkEventMask enumeration.
3013 gdk_window_set_events (GdkWindow *window,
3014 GdkEventMask event_mask)
3019 g_return_if_fail (window != NULL);
3020 g_return_if_fail (GDK_IS_WINDOW (window));
3022 if (!GDK_WINDOW_DESTROYED (window))
3024 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
3025 xevent_mask = StructureNotifyMask | PropertyChangeMask;
3026 for (i = 0; i < _gdk_nenvent_masks; i++)
3028 if (event_mask & (1 << (i + 1)))
3029 xevent_mask |= _gdk_event_mask_table[i];
3032 XSelectInput (GDK_WINDOW_XDISPLAY (window),
3033 GDK_WINDOW_XID (window),
3039 gdk_window_add_colormap_windows (GdkWindow *window)
3041 GdkWindow *toplevel;
3042 Window *old_windows;
3043 Window *new_windows;
3046 g_return_if_fail (window != NULL);
3047 g_return_if_fail (GDK_IS_WINDOW (window));
3049 if (GDK_WINDOW_DESTROYED (window))
3051 toplevel = gdk_window_get_toplevel (window);
3054 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3055 GDK_WINDOW_XID (toplevel),
3056 &old_windows, &count))
3061 for (i = 0; i < count; i++)
3062 if (old_windows[i] == GDK_WINDOW_XID (window))
3064 XFree (old_windows);
3068 new_windows = g_new (Window, count + 1);
3070 for (i = 0; i < count; i++)
3071 new_windows[i] = old_windows[i];
3072 new_windows[count] = GDK_WINDOW_XID (window);
3074 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3075 GDK_WINDOW_XID (toplevel),
3076 new_windows, count + 1);
3078 g_free (new_windows);
3080 XFree (old_windows);
3084 gdk_window_have_shape_ext (GdkDisplay *display)
3086 #ifdef HAVE_SHAPE_EXT
3089 return XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display),
3096 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
3099 * This needs the X11 shape extension.
3100 * If not available, shaped windows will look
3101 * ugly, but programs still work. Stefan Wille
3104 * gdk_window_shape_combine_mask:
3105 * @window: a #GdkWindow
3107 * @x: X position of shape mask with respect to @window
3108 * @y: Y position of shape mask with respect to @window
3110 * Applies a shape mask to @window. Pixels in @window corresponding to
3111 * set bits in the @mask will be visible; pixels in @window
3112 * corresponding to unset bits in the @mask will be transparent. This
3113 * gives a non-rectangular window.
3115 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
3116 * parameters are not used.
3118 * On the X11 platform, this uses an X server extension which is
3119 * widely available on most common platforms, but not available on
3120 * very old X servers, and occasionally the implementation will be
3121 * buggy. On servers without the shape extension, this function
3124 * This function works on both toplevel and child windows.
3128 gdk_window_shape_combine_mask (GdkWindow *window,
3133 gint xoffset, yoffset;
3135 g_return_if_fail (window != NULL);
3136 g_return_if_fail (GDK_IS_WINDOW (window));
3138 #ifdef HAVE_SHAPE_EXT
3139 if (GDK_WINDOW_DESTROYED (window))
3142 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3144 if (xoffset != 0 || yoffset != 0)
3146 WARN_SHAPE_TOO_BIG ();
3150 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3154 pixmap = GDK_PIXMAP_XID (mask);
3163 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3164 GDK_WINDOW_XID (window),
3170 #endif /* HAVE_SHAPE_EXT */
3174 * gdk_window_shape_combine_region:
3175 * @window: a #GdkWindow
3176 * @shape_region: region of window to be non-transparent
3177 * @offset_x: X position of @shape_region in @window coordinates
3178 * @offset_y: Y position of @shape_region in @window coordinates
3180 * Makes pixels in @window outside @shape_region be transparent,
3181 * so that the window may be nonrectangular. See also
3182 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
3184 * If @shape_region is %NULL, the shape will be unset, so the whole
3185 * window will be opaque again. @offset_x and @offset_y are ignored
3186 * if @shape_region is %NULL.
3188 * On the X11 platform, this uses an X server extension which is
3189 * widely available on most common platforms, but not available on
3190 * very old X servers, and occasionally the implementation will be
3191 * buggy. On servers without the shape extension, this function
3194 * This function works on both toplevel and child windows.
3198 gdk_window_shape_combine_region (GdkWindow *window,
3199 GdkRegion *shape_region,
3203 gint xoffset, yoffset;
3205 g_return_if_fail (GDK_IS_WINDOW (window));
3207 #ifdef HAVE_SHAPE_EXT
3208 if (GDK_WINDOW_DESTROYED (window))
3211 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3213 if (xoffset != 0 || yoffset != 0)
3215 WARN_SHAPE_TOO_BIG ();
3219 if (shape_region == NULL)
3221 /* Use NULL mask to unset the shape */
3222 gdk_window_shape_combine_mask (window, NULL, 0, 0);
3226 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3229 XRectangle *xrects = NULL;
3231 _gdk_region_get_xrectangles (shape_region,
3235 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3236 GDK_WINDOW_XID (window),
3245 #endif /* HAVE_SHAPE_EXT */
3250 * gdk_window_set_override_redirect:
3251 * @window: a toplevel #GdkWindow
3252 * @override_redirect: %TRUE if window should be override redirect
3254 * An override redirect window is not under the control of the window manager.
3255 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3256 * be entirely under the control of the application. The window manager
3257 * can't see the override redirect window at all.
3259 * Override redirect should only be used for short-lived temporary
3260 * windows, such as popup menus. #GtkMenu uses an override redirect
3261 * window in its implementation, for example.
3265 gdk_window_set_override_redirect (GdkWindow *window,
3266 gboolean override_redirect)
3268 XSetWindowAttributes attr;
3270 g_return_if_fail (window != NULL);
3271 g_return_if_fail (GDK_IS_WINDOW (window));
3273 if (!GDK_WINDOW_DESTROYED (window))
3275 attr.override_redirect = (override_redirect == FALSE)?False:True;
3276 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3277 GDK_WINDOW_XID (window),
3284 * gdk_window_set_accept_focus:
3285 * @window: a toplevel #GdkWindow
3286 * @accept_focus: %TRUE if the window should receive input focus
3288 * Setting @accept_focus to %FALSE hints the desktop environment that the
3289 * window doesn't want to receive input focus.
3291 * On X, it is the responsibility of the window manager to interpret this
3292 * hint. ICCCM-compliant window manager usually respect it.
3297 gdk_window_set_accept_focus (GdkWindow *window,
3298 gboolean accept_focus)
3300 GdkWindowObject *private;
3301 g_return_if_fail (window != NULL);
3302 g_return_if_fail (GDK_IS_WINDOW (window));
3304 private = (GdkWindowObject *)window;
3306 accept_focus = accept_focus != FALSE;
3308 if (private->accept_focus != accept_focus)
3310 private->accept_focus = accept_focus;
3312 if (!GDK_WINDOW_DESTROYED (window))
3313 update_wm_hints (window, FALSE);
3318 * gdk_window_set_focus_on_map:
3319 * @window: a toplevel #GdkWindow
3320 * @focus_on_map: %TRUE if the window should receive input focus when mapped
3322 * Setting @focus_on_map to %FALSE hints the desktop environment that the
3323 * window doesn't want to receive input focus when it is mapped.
3324 * focus_on_map should be turned off for windows that aren't triggered
3325 * interactively (such as popups from network activity).
3327 * On X, it is the responsibility of the window manager to interpret
3328 * this hint. Window managers following the freedesktop.org window
3329 * manager extension specification should respect it.
3334 gdk_window_set_focus_on_map (GdkWindow *window,
3335 gboolean focus_on_map)
3337 GdkWindowObject *private;
3338 g_return_if_fail (window != NULL);
3339 g_return_if_fail (GDK_IS_WINDOW (window));
3341 private = (GdkWindowObject *)window;
3343 focus_on_map = focus_on_map != FALSE;
3345 if (private->focus_on_map != focus_on_map)
3347 private->focus_on_map = focus_on_map;
3349 if ((!GDK_WINDOW_DESTROYED (window)) && (!private->focus_on_map))
3350 gdk_x11_window_set_user_time (window, 0);
3355 * gdk_x11_window_set_user_time:
3356 * @window: A toplevel #GdkWindow
3357 * @timestamp: An XServer timestamp to which the property should be set
3359 * The application can use this call to update the _NET_WM_USER_TIME
3360 * property on a toplevel window. This property stores an Xserver
3361 * time which represents the time of the last user input event
3362 * received for this window. This property may be used by the window
3363 * manager to alter the focus, stacking, and/or placement behavior of
3364 * windows when they are mapped depending on whether the new window
3365 * was created by a user action or is a "pop-up" window activated by a
3366 * timer or some other event.
3368 * Note that this property is automatically updated by GDK, so this
3369 * function should only be used by applications which handle input
3370 * events bypassing GDK.
3375 gdk_x11_window_set_user_time (GdkWindow *window,
3378 GdkDisplay *display;
3379 GdkDisplayX11 *display_x11;
3381 g_return_if_fail (window != NULL);
3382 g_return_if_fail (GDK_IS_WINDOW (window));
3384 if (GDK_WINDOW_DESTROYED (window))
3387 display = gdk_drawable_get_display (window);
3388 display_x11 = GDK_DISPLAY_X11 (display);
3390 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3391 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3392 XA_CARDINAL, 32, PropModeReplace,
3393 (guchar *)×tamp, 1);
3395 if (timestamp != GDK_CURRENT_TIME)
3396 display_x11->user_time = timestamp;
3400 * gdk_window_set_icon_list:
3401 * @window: The #GdkWindow toplevel window to set the icon of.
3402 * @pixbufs: A list of pixbufs, of different sizes.
3404 * Sets a list of icons for the window. One of these will be used
3405 * to represent the window when it has been iconified. The icon is
3406 * usually shown in an icon box or some sort of task bar. Which icon
3407 * size is shown depends on the window manager. The window manager
3408 * can scale the icon but setting several size icons can give better
3409 * image quality since the window manager may only need to scale the
3410 * icon by a small amount or not at all.
3414 gdk_window_set_icon_list (GdkWindow *window,
3423 gint width, height, stride;
3426 GdkDisplay *display;
3428 g_return_if_fail (GDK_IS_WINDOW (window));
3430 if (GDK_WINDOW_DESTROYED (window))
3433 display = gdk_drawable_get_display (window);
3441 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3443 width = gdk_pixbuf_get_width (pixbuf);
3444 height = gdk_pixbuf_get_height (pixbuf);
3446 size += 2 + width * height;
3448 l = g_list_next (l);
3451 data = g_malloc (size * sizeof (gulong));
3459 width = gdk_pixbuf_get_width (pixbuf);
3460 height = gdk_pixbuf_get_height (pixbuf);
3461 stride = gdk_pixbuf_get_rowstride (pixbuf);
3462 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3467 pixels = gdk_pixbuf_get_pixels (pixbuf);
3469 for (y = 0; y < height; y++)
3471 for (x = 0; x < width; x++)
3475 r = pixels[y*stride + x*n_channels + 0];
3476 g = pixels[y*stride + x*n_channels + 1];
3477 b = pixels[y*stride + x*n_channels + 2];
3478 if (n_channels >= 4)
3479 a = pixels[y*stride + x*n_channels + 3];
3483 *p++ = a << 24 | r << 16 | g << 8 | b ;
3487 l = g_list_next (l);
3492 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3493 GDK_WINDOW_XID (window),
3494 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3497 (guchar*) data, size);
3501 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3502 GDK_WINDOW_XID (window),
3503 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3510 * gdk_window_set_icon:
3511 * @window: a toplevel #GdkWindow
3512 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
3513 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
3514 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
3516 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
3517 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
3518 * and gtk_window_set_icon(). If those don't meet your needs, look at
3519 * gdk_window_set_icon_list(). Only if all those are too high-level do you
3520 * want to fall back to gdk_window_set_icon().
3524 gdk_window_set_icon (GdkWindow *window,
3525 GdkWindow *icon_window,
3529 GdkToplevelX11 *toplevel;
3531 g_return_if_fail (window != NULL);
3532 g_return_if_fail (GDK_IS_WINDOW (window));
3533 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3535 if (GDK_WINDOW_DESTROYED (window))
3538 toplevel = _gdk_x11_window_get_toplevel (window);
3540 if (toplevel->icon_window != icon_window)
3542 if (toplevel->icon_window)
3543 g_object_unref (toplevel->icon_window);
3544 toplevel->icon_window = g_object_ref (icon_window);
3547 if (toplevel->icon_pixmap != pixmap)
3550 g_object_ref (pixmap);
3551 if (toplevel->icon_pixmap)
3552 g_object_unref (toplevel->icon_pixmap);
3553 toplevel->icon_pixmap = pixmap;
3556 if (toplevel->icon_mask != mask)
3559 g_object_ref (mask);
3560 if (toplevel->icon_mask)
3561 g_object_unref (toplevel->icon_mask);
3562 toplevel->icon_mask = mask;
3565 update_wm_hints (window, FALSE);
3569 gdk_window_icon_name_set (GdkWindow *window)
3571 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3572 g_quark_from_static_string ("gdk-icon-name-set")));
3576 * gdk_window_set_icon_name:
3577 * @window: a toplevel #GdkWindow
3578 * @name: name of window while iconified (minimized)
3580 * Windows may have a name used while minimized, distinct from the
3581 * name they display in their titlebar. Most of the time this is a bad
3582 * idea from a user interface standpoint. But you can set such a name
3583 * with this function, if you like.
3587 gdk_window_set_icon_name (GdkWindow *window,
3590 GdkDisplay *display;
3592 g_return_if_fail (window != NULL);
3593 g_return_if_fail (GDK_IS_WINDOW (window));
3595 if (GDK_WINDOW_DESTROYED (window))
3598 display = gdk_drawable_get_display (window);
3600 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3601 GUINT_TO_POINTER (TRUE));
3603 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3604 GDK_WINDOW_XID (window),
3605 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3606 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3607 PropModeReplace, name, strlen (name));
3609 set_text_property (display, GDK_WINDOW_XID (window),
3610 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3615 * gdk_window_iconify:
3616 * @window: a toplevel #GdkWindow
3618 * Asks to iconify (minimize) @window. The window manager may choose
3619 * to ignore the request, but normally will honor it. Using
3620 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3622 * This function only makes sense when @window is a toplevel window.
3626 gdk_window_iconify (GdkWindow *window)
3628 GdkWindowObject *private;
3630 g_return_if_fail (window != NULL);
3631 g_return_if_fail (GDK_IS_WINDOW (window));
3633 if (GDK_WINDOW_DESTROYED (window))
3636 private = (GdkWindowObject*) window;
3638 if (GDK_WINDOW_IS_MAPPED (window))
3640 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3641 GDK_WINDOW_XWINDOW (window),
3642 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3646 /* Flip our client side flag, the real work happens on map. */
3647 gdk_synthesize_window_state (window,
3649 GDK_WINDOW_STATE_ICONIFIED);
3654 * gdk_window_deiconify:
3655 * @window: a toplevel #GdkWindow
3657 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3658 * choose to ignore the request to deiconify. When using GTK+,
3659 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3660 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3661 * unminimizes it, and puts it on the current desktop.
3665 gdk_window_deiconify (GdkWindow *window)
3667 GdkWindowObject *private;
3669 g_return_if_fail (window != NULL);
3670 g_return_if_fail (GDK_IS_WINDOW (window));
3672 if (GDK_WINDOW_DESTROYED (window))
3675 private = (GdkWindowObject*) window;
3677 if (GDK_WINDOW_IS_MAPPED (window))
3679 gdk_window_show (window);
3683 /* Flip our client side flag, the real work happens on map. */
3684 gdk_synthesize_window_state (window,
3685 GDK_WINDOW_STATE_ICONIFIED,
3692 * @window: a toplevel #GdkWindow
3694 * "Pins" a window such that it's on all workspaces and does not scroll
3695 * with viewports, for window managers that have scrollable viewports.
3696 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3698 * On the X11 platform, this function depends on window manager
3699 * support, so may have no effect with many window managers. However,
3700 * GDK will do the best it can to convince the window manager to stick
3701 * the window. For window managers that don't support this operation,
3702 * there's nothing you can do to force it to happen.
3706 gdk_window_stick (GdkWindow *window)
3708 g_return_if_fail (GDK_IS_WINDOW (window));
3710 if (GDK_WINDOW_DESTROYED (window))
3713 if (GDK_WINDOW_IS_MAPPED (window))
3715 /* "stick" means stick to all desktops _and_ do not scroll with the
3716 * viewport. i.e. glue to the monitor glass in all cases.
3721 /* Request stick during viewport scroll */
3722 gdk_wmspec_change_state (TRUE, window,
3723 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3726 /* Request desktop 0xFFFFFFFF */
3727 xev.xclient.type = ClientMessage;
3728 xev.xclient.serial = 0;
3729 xev.xclient.send_event = True;
3730 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3731 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
3732 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3734 xev.xclient.format = 32;
3736 xev.xclient.data.l[0] = 0xFFFFFFFF;
3737 xev.xclient.data.l[1] = 0;
3738 xev.xclient.data.l[2] = 0;
3739 xev.xclient.data.l[3] = 0;
3740 xev.xclient.data.l[4] = 0;
3742 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3743 SubstructureRedirectMask | SubstructureNotifyMask,
3748 /* Flip our client side flag, the real work happens on map. */
3749 gdk_synthesize_window_state (window,
3751 GDK_WINDOW_STATE_STICKY);
3756 * gdk_window_unstick:
3757 * @window: a toplevel #GdkWindow
3759 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3760 * and gtk_window_unstick().
3764 gdk_window_unstick (GdkWindow *window)
3766 g_return_if_fail (GDK_IS_WINDOW (window));
3768 if (GDK_WINDOW_DESTROYED (window))
3771 if (GDK_WINDOW_IS_MAPPED (window))
3778 gulong *current_desktop;
3779 GdkDisplay *display = gdk_drawable_get_display (window);
3781 /* Request unstick from viewport */
3782 gdk_wmspec_change_state (FALSE, window,
3783 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3786 /* Get current desktop, then set it; this is a race, but not
3787 * one that matters much in practice.
3789 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
3790 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
3792 False, XA_CARDINAL, &type, &format, &nitems,
3793 &bytes_after, (guchar **)¤t_desktop);
3795 if (type == XA_CARDINAL)
3797 xev.xclient.type = ClientMessage;
3798 xev.xclient.serial = 0;
3799 xev.xclient.send_event = True;
3800 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3801 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
3802 xev.xclient.format = 32;
3804 xev.xclient.data.l[0] = *current_desktop;
3805 xev.xclient.data.l[1] = 0;
3806 xev.xclient.data.l[2] = 0;
3807 xev.xclient.data.l[3] = 0;
3808 xev.xclient.data.l[4] = 0;
3810 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3811 SubstructureRedirectMask | SubstructureNotifyMask,
3814 XFree (current_desktop);
3819 /* Flip our client side flag, the real work happens on map. */
3820 gdk_synthesize_window_state (window,
3821 GDK_WINDOW_STATE_STICKY,
3828 * gdk_window_maximize:
3829 * @window: a toplevel #GdkWindow
3831 * Maximizes the window. If the window was already maximized, then
3832 * this function does nothing.
3834 * On X11, asks the window manager to maximize @window, if the window
3835 * manager supports this operation. Not all window managers support
3836 * this, and some deliberately ignore it or don't have a concept of
3837 * "maximized"; so you can't rely on the maximization actually
3838 * happening. But it will happen with most standard window managers,
3839 * and GDK makes a best effort to get it to happen.
3841 * On Windows, reliably maximizes the window.
3845 gdk_window_maximize (GdkWindow *window)
3847 g_return_if_fail (GDK_IS_WINDOW (window));
3849 if (GDK_WINDOW_DESTROYED (window))
3852 if (GDK_WINDOW_IS_MAPPED (window))
3853 gdk_wmspec_change_state (TRUE, window,
3854 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3855 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3857 gdk_synthesize_window_state (window,
3859 GDK_WINDOW_STATE_MAXIMIZED);
3863 * gdk_window_unmaximize:
3864 * @window: a toplevel #GdkWindow
3866 * Unmaximizes the window. If the window wasn't maximized, then this
3867 * function does nothing.
3869 * On X11, asks the window manager to unmaximize @window, if the
3870 * window manager supports this operation. Not all window managers
3871 * support this, and some deliberately ignore it or don't have a
3872 * concept of "maximized"; so you can't rely on the unmaximization
3873 * actually happening. But it will happen with most standard window
3874 * managers, and GDK makes a best effort to get it to happen.
3876 * On Windows, reliably unmaximizes the window.
3880 gdk_window_unmaximize (GdkWindow *window)
3882 g_return_if_fail (GDK_IS_WINDOW (window));
3884 if (GDK_WINDOW_DESTROYED (window))
3887 if (GDK_WINDOW_IS_MAPPED (window))
3888 gdk_wmspec_change_state (FALSE, window,
3889 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3890 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3892 gdk_synthesize_window_state (window,
3893 GDK_WINDOW_STATE_MAXIMIZED,
3898 * gdk_window_fullscreen:
3899 * @window: a toplevel #GdkWindow
3901 * Moves the window into fullscreen mode. This means the
3902 * window covers the entire screen and is above any panels
3905 * If the window was already fullscreen, then this function does nothing.
3907 * On X11, asks the window manager to put @window in a fullscreen
3908 * state, if the window manager supports this operation. Not all
3909 * window managers support this, and some deliberately ignore it or
3910 * don't have a concept of "fullscreen"; so you can't rely on the
3911 * fullscreenification actually happening. But it will happen with
3912 * most standard window managers, and GDK makes a best effort to get
3918 gdk_window_fullscreen (GdkWindow *window)
3920 g_return_if_fail (GDK_IS_WINDOW (window));
3922 if (GDK_WINDOW_DESTROYED (window))
3925 if (GDK_WINDOW_IS_MAPPED (window))
3926 gdk_wmspec_change_state (TRUE, window,
3927 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3931 gdk_synthesize_window_state (window,
3933 GDK_WINDOW_STATE_FULLSCREEN);
3937 * gdk_window_unfullscreen:
3938 * @window: a toplevel #GdkWindow
3940 * Moves the window out of fullscreen mode. If the window was not
3941 * fullscreen, does nothing.
3943 * On X11, asks the window manager to move @window out of the fullscreen
3944 * state, if the window manager supports this operation. Not all
3945 * window managers support this, and some deliberately ignore it or
3946 * don't have a concept of "fullscreen"; so you can't rely on the
3947 * unfullscreenification actually happening. But it will happen with
3948 * most standard window managers, and GDK makes a best effort to get
3954 gdk_window_unfullscreen (GdkWindow *window)
3956 g_return_if_fail (GDK_IS_WINDOW (window));
3958 if (GDK_WINDOW_DESTROYED (window))
3961 if (GDK_WINDOW_IS_MAPPED (window))
3962 gdk_wmspec_change_state (FALSE, window,
3963 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3967 gdk_synthesize_window_state (window,
3968 GDK_WINDOW_STATE_FULLSCREEN,
3973 * gdk_window_set_keep_above:
3974 * @window: a toplevel #GdkWindow
3975 * @setting: whether to keep @window above other windows
3977 * Set if @window must be kept above other windows. If the
3978 * window was already above, then this function does nothing.
3980 * On X11, asks the window manager to keep @window above, if the window
3981 * manager supports this operation. Not all window managers support
3982 * this, and some deliberately ignore it or don't have a concept of
3983 * "keep above"; so you can't rely on the window being kept above.
3984 * But it will happen with most standard window managers,
3985 * and GDK makes a best effort to get it to happen.
3990 gdk_window_set_keep_above (GdkWindow *window, gboolean setting)
3992 g_return_if_fail (GDK_IS_WINDOW (window));
3994 if (GDK_WINDOW_DESTROYED (window))
3997 if (GDK_WINDOW_IS_MAPPED (window))
3998 gdk_wmspec_change_state (setting, window,
3999 gdk_atom_intern ("_NET_WM_STATE_ABOVE", setting),
4000 setting ? gdk_atom_intern ("_NET_WM_STATE_BELOW", FALSE)
4003 gdk_synthesize_window_state (window,
4004 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
4005 setting ? GDK_WINDOW_STATE_ABOVE : 0);
4009 * gdk_window_set_keep_below:
4010 * @window: a toplevel #GdkWindow
4011 * @setting: whether to keep @window below other windows
4013 * Set if @window must be kept below other windows. If the
4014 * window was already below, then this function does nothing.
4016 * On X11, asks the window manager to keep @window below, if the window
4017 * manager supports this operation. Not all window managers support
4018 * this, and some deliberately ignore it or don't have a concept of
4019 * "keep below"; so you can't rely on the window being kept below.
4020 * But it will happen with most standard window managers,
4021 * and GDK makes a best effort to get it to happen.
4026 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
4028 g_return_if_fail (GDK_IS_WINDOW (window));
4030 if (GDK_WINDOW_DESTROYED (window))
4033 if (GDK_WINDOW_IS_MAPPED (window))
4034 gdk_wmspec_change_state (setting, window,
4035 gdk_atom_intern ("_NET_WM_STATE_BELOW", setting),
4036 setting ? gdk_atom_intern ("_NET_WM_STATE_ABOVE", FALSE)
4039 gdk_synthesize_window_state (window,
4040 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
4041 setting ? GDK_WINDOW_STATE_BELOW : 0);
4045 * gdk_window_get_group:
4046 * @window: a toplevel #GdkWindow
4048 * Returns the group leader window for @window. See gdk_window_set_group().
4050 * Return value: the group leader window for @window
4055 gdk_window_get_group (GdkWindow *window)
4057 GdkToplevelX11 *toplevel;
4059 g_return_val_if_fail (window != NULL, NULL);
4060 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4061 g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL);
4063 if (GDK_WINDOW_DESTROYED (window))
4066 toplevel = _gdk_x11_window_get_toplevel (window);
4068 return toplevel->group_leader;
4072 * gdk_window_set_group:
4073 * @window: a toplevel #GdkWindow
4074 * @leader: group leader window, or %NULL to restore the default group leader window
4076 * Sets the group leader window for @window. By default,
4077 * GDK sets the group leader for all toplevel windows
4078 * to a global window implicitly created by GDK. With this function
4079 * you can override this default.
4081 * The group leader window allows the window manager to distinguish
4082 * all windows that belong to a single application. It may for example
4083 * allow users to minimize/unminimize all windows belonging to an
4084 * application at once. You should only set a non-default group window
4085 * if your application pretends to be multiple applications.
4088 gdk_window_set_group (GdkWindow *window,
4091 GdkToplevelX11 *toplevel;
4093 g_return_if_fail (window != NULL);
4094 g_return_if_fail (GDK_IS_WINDOW (window));
4095 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4096 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
4098 if (GDK_WINDOW_DESTROYED (window) || (leader != NULL && GDK_WINDOW_DESTROYED (leader)))
4101 toplevel = _gdk_x11_window_get_toplevel (window);
4104 leader = gdk_display_get_default_group (gdk_drawable_get_display (window));
4106 if (toplevel->group_leader != leader)
4108 if (toplevel->group_leader)
4109 g_object_unref (toplevel->group_leader);
4110 toplevel->group_leader = g_object_ref (leader);
4113 update_wm_hints (window, FALSE);
4116 static MotifWmHints *
4117 gdk_window_get_mwm_hints (GdkWindow *window)
4119 GdkDisplay *display;
4120 Atom hints_atom = None;
4121 MotifWmHints *hints;
4127 if (GDK_WINDOW_DESTROYED (window))
4130 display = gdk_drawable_get_display (window);
4132 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4134 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4135 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4136 False, AnyPropertyType, &type, &format, &nitems,
4137 &bytes_after, (guchar **)&hints);
4146 gdk_window_set_mwm_hints (GdkWindow *window,
4147 MotifWmHints *new_hints)
4149 GdkDisplay *display;
4150 Atom hints_atom = None;
4151 MotifWmHints *hints;
4157 if (GDK_WINDOW_DESTROYED (window))
4160 display = gdk_drawable_get_display (window);
4162 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4164 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4165 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4166 False, AnyPropertyType, &type, &format, &nitems,
4167 &bytes_after, (guchar **)&hints);
4173 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4175 hints->flags |= MWM_HINTS_FUNCTIONS;
4176 hints->functions = new_hints->functions;
4178 if (new_hints->flags & MWM_HINTS_DECORATIONS)
4180 hints->flags |= MWM_HINTS_DECORATIONS;
4181 hints->decorations = new_hints->decorations;
4185 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4186 hints_atom, hints_atom, 32, PropModeReplace,
4187 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
4189 if (hints != new_hints)
4194 * gdk_window_set_decorations:
4195 * @window: a toplevel #GdkWindow
4196 * @decorations: decoration hint mask
4198 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
4199 * This function sets the traditional Motif window manager hints that tell the
4200 * window manager which decorations you would like your window to have.
4201 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
4202 * using the GDK function directly.
4204 * The @decorations argument is the logical OR of the fields in
4205 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
4206 * mask, the other bits indicate which decorations should be turned off.
4207 * If #GDK_DECOR_ALL is not included, then the other bits indicate
4208 * which decorations should be turned on.
4210 * Most window managers honor a decorations hint of 0 to disable all decorations,
4211 * but very few honor all possible combinations of bits.
4215 gdk_window_set_decorations (GdkWindow *window,
4216 GdkWMDecoration decorations)
4220 g_return_if_fail (window != NULL);
4221 g_return_if_fail (GDK_IS_WINDOW (window));
4223 hints.flags = MWM_HINTS_DECORATIONS;
4224 hints.decorations = decorations;
4226 gdk_window_set_mwm_hints (window, &hints);
4230 * gdk_window_get_decorations:
4231 * @window: The toplevel #GdkWindow to get the decorations from
4232 * @decorations: The window decorations will be written here
4234 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
4235 * Returns: TRUE if the window has decorations set, FALSE otherwise.
4238 gdk_window_get_decorations(GdkWindow *window,
4239 GdkWMDecoration *decorations)
4241 MotifWmHints *hints;
4242 gboolean result = FALSE;
4244 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4246 hints = gdk_window_get_mwm_hints (window);
4250 if (hints->flags & MWM_HINTS_DECORATIONS)
4253 *decorations = hints->decorations;
4264 * gdk_window_set_functions:
4265 * @window: a toplevel #GdkWindow
4266 * @functions: bitmask of operations to allow on @window
4268 * This function isn't really good for much. It sets the traditional
4269 * Motif window manager hint for which operations the window manager
4270 * should allow on a toplevel window. However, few window managers do
4271 * anything reliable or interesting with this hint. Many ignore it
4274 * The @functions argument is the logical OR of values from the
4275 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
4276 * then the other bits indicate which functions to disable; if
4277 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
4282 gdk_window_set_functions (GdkWindow *window,
4283 GdkWMFunction functions)
4287 g_return_if_fail (window != NULL);
4288 g_return_if_fail (GDK_IS_WINDOW (window));
4290 hints.flags = MWM_HINTS_FUNCTIONS;
4291 hints.functions = functions;
4293 gdk_window_set_mwm_hints (window, &hints);
4296 #ifdef HAVE_SHAPE_EXT
4299 * propagate the shapes from all child windows of a GDK window to the parent
4300 * window. Shamelessly ripped from Enlightenment's code
4308 struct _gdk_span *next;
4312 gdk_add_to_span (struct _gdk_span **s,
4316 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
4323 /* scan the spans for this line */
4326 /* -- -> new span */
4327 /* == -> existing span */
4328 /* ## -> spans intersect */
4329 /* if we are in the middle of spanning the span into the line */
4332 /* case: ---- ==== */
4333 if (xx < ptr1->start - 1)
4335 /* ends before next span - extend to here */
4339 /* case: ----##=== */
4340 else if (xx <= ptr1->end)
4342 /* crosses into next span - delete next span and append */
4343 ss->end = ptr1->end;
4344 ss->next = ptr1->next;
4348 /* case: ---###--- */
4351 /* overlaps next span - delete and keep checking */
4352 ss->next = ptr1->next;
4357 /* otherwise havent started spanning it in yet */
4360 /* case: ---- ==== */
4361 if (xx < ptr1->start - 1)
4363 /* insert span here in list */
4364 noo = g_malloc (sizeof (struct _gdk_span));
4378 /* case: ----##=== */
4379 else if ((x < ptr1->start) && (xx <= ptr1->end))
4381 /* expand this span to the left point of the new one */
4385 /* case: ===###=== */
4386 else if ((x >= ptr1->start) && (xx <= ptr1->end))
4388 /* throw the span away */
4391 /* case: ---###--- */
4392 else if ((x < ptr1->start) && (xx > ptr1->end))
4399 /* case: ===##---- */
4400 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
4406 /* case: ==== ---- */
4407 /* case handled by next loop iteration - first case */
4412 /* it started in the middle but spans beyond your current list */
4418 /* it does not start inside a span or in the middle, so add it to the end */
4419 noo = g_malloc (sizeof (struct _gdk_span));
4427 noo->next = ptr2->next;
4440 gdk_add_rectangles (Display *disp,
4442 struct _gdk_span **spans,
4449 gint x1, y1, x2, y2;
4453 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
4456 /* go through all clip rects in this window's shape */
4457 for (k = 0; k < rn; k++)
4459 /* for each clip rect, add it to each line's spans */
4461 x2 = x + rl[k].x + (rl[k].width - 1);
4463 y2 = y + rl[k].y + (rl[k].height - 1);
4472 for (a = y1; a <= y2; a++)
4475 gdk_add_to_span (&spans[a], x1, x2);
4483 gdk_propagate_shapes (Display *disp,
4487 Window rt, par, *list = NULL;
4488 gint i, j, num = 0, num_rects = 0;
4492 XRectangle *rects = NULL;
4493 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
4494 XWindowAttributes xatt;
4496 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
4501 spans = g_malloc (sizeof (struct _gdk_span *) * h);
4503 for (i = 0; i < h; i++)
4505 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
4508 /* go through all child windows and create/insert spans */
4509 for (i = 0; i < num; i++)
4511 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
4512 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
4513 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
4516 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
4518 /* go through the spans list and build a list of rects */
4519 rects = g_malloc (sizeof (XRectangle) * 256);
4521 for (i = 0; i < baseh; i++)
4524 /* go through the line for all spans */
4527 rects[num_rects].x = ptr1->start;
4528 rects[num_rects].y = i;
4529 rects[num_rects].width = ptr1->end - ptr1->start + 1;
4530 rects[num_rects].height = 1;
4532 /* if there are more lines */
4534 /* while contigous rects (same start/end coords) exist */
4535 while ((contig) && (j < baseh))
4537 /* search next line for spans matching this one */
4543 /* if we have an exact span match set contig */
4544 if ((ptr2->start == ptr1->start) &&
4545 (ptr2->end == ptr1->end))
4548 /* remove the span - not needed */
4551 ptr3->next = ptr2->next;
4557 spans[j] = ptr2->next;
4563 /* gone past the span point no point looking */
4564 else if (ptr2->start < ptr1->start)
4572 /* if a contiguous span was found increase the rect h */
4575 rects[num_rects].height++;
4579 /* up the rect count */
4581 /* every 256 new rects increase the rect array */
4582 if ((num_rects % 256) == 0)
4583 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
4587 /* set the rects as the shape mask */
4590 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
4591 ShapeSet, YXSorted);
4596 /* free up all the spans we made */
4597 for (i = 0; i < baseh; i++)
4610 #endif /* HAVE_SHAPE_EXT */
4613 * gdk_window_set_child_shapes:
4614 * @window: a #GdkWindow
4616 * Sets the shape mask of @window to the union of shape masks
4617 * for all children of @window, ignoring the shape mask of @window
4618 * itself. Contrast with gdk_window_merge_child_shapes() which includes
4619 * the shape mask of @window in the masks to be merged.
4622 gdk_window_set_child_shapes (GdkWindow *window)
4624 g_return_if_fail (window != NULL);
4625 g_return_if_fail (GDK_IS_WINDOW (window));
4627 #ifdef HAVE_SHAPE_EXT
4628 if (!GDK_WINDOW_DESTROYED (window) &&
4629 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4630 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4631 GDK_WINDOW_XID (window), FALSE);
4636 * gdk_window_merge_child_shapes:
4637 * @window: a #GdkWindow
4639 * Merges the shape masks for any child windows into the
4640 * shape mask for @window. i.e. the union of all masks
4641 * for @window and its children will become the new mask
4642 * for @window. See gdk_window_shape_combine_mask().
4644 * This function is distinct from gdk_window_set_child_shapes()
4645 * because it includes @window's shape mask in the set of shapes to
4650 gdk_window_merge_child_shapes (GdkWindow *window)
4652 g_return_if_fail (window != NULL);
4653 g_return_if_fail (GDK_IS_WINDOW (window));
4655 #ifdef HAVE_SHAPE_EXT
4656 if (!GDK_WINDOW_DESTROYED (window) &&
4657 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4658 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4659 GDK_WINDOW_XID (window), TRUE);
4664 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
4666 XSetWindowAttributes xattributes;
4667 GdkWindowObject *private;
4668 guint xattributes_mask = 0;
4670 g_return_if_fail (window != NULL);
4672 private = GDK_WINDOW_OBJECT (window);
4673 if (private->input_only)
4676 xattributes.bit_gravity = StaticGravity;
4677 xattributes_mask |= CWBitGravity;
4678 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4679 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4680 GDK_WINDOW_XID (window),
4681 CWBitGravity, &xattributes);
4685 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
4687 XSetWindowAttributes xattributes;
4689 g_return_if_fail (window != NULL);
4691 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4693 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4694 GDK_WINDOW_XID (window),
4695 CWWinGravity, &xattributes);
4699 * gdk_window_set_static_gravities:
4700 * @window: a #GdkWindow
4701 * @use_static: %TRUE to turn on static gravity
4703 * Set the bit gravity of the given window to static, and flag it so
4704 * all children get static subwindow gravity. This is used if you are
4705 * implementing scary features that involve deep knowledge of the
4706 * windowing system. Don't worry about it unless you have to.
4708 * Return value: %TRUE if the server supports static gravity
4711 gdk_window_set_static_gravities (GdkWindow *window,
4712 gboolean use_static)
4714 GdkWindowObject *private = (GdkWindowObject *)window;
4717 g_return_val_if_fail (window != NULL, FALSE);
4718 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4720 if (!use_static == !private->guffaw_gravity)
4723 private->guffaw_gravity = use_static;
4725 if (!GDK_WINDOW_DESTROYED (window))
4727 gdk_window_set_static_bit_gravity (window, use_static);
4729 tmp_list = private->children;
4732 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4734 tmp_list = tmp_list->next;
4742 wmspec_moveresize (GdkWindow *window,
4748 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4752 /* Release passive grab */
4753 gdk_display_pointer_ungrab (display, timestamp);
4755 xev.xclient.type = ClientMessage;
4756 xev.xclient.serial = 0;
4757 xev.xclient.send_event = True;
4758 xev.xclient.window = GDK_WINDOW_XID (window);
4759 xev.xclient.message_type =
4760 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4761 xev.xclient.format = 32;
4762 xev.xclient.data.l[0] = root_x;
4763 xev.xclient.data.l[1] = root_y;
4764 xev.xclient.data.l[2] = direction;
4765 xev.xclient.data.l[3] = 0;
4766 xev.xclient.data.l[4] = 0;
4768 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4769 SubstructureRedirectMask | SubstructureNotifyMask,
4773 typedef struct _MoveResizeData MoveResizeData;
4775 struct _MoveResizeData
4777 GdkDisplay *display;
4779 GdkWindow *moveresize_window;
4780 GdkWindow *moveresize_emulation_window;
4782 GdkWindowEdge resize_edge;
4783 gint moveresize_button;
4786 gint moveresize_orig_x;
4787 gint moveresize_orig_y;
4788 gint moveresize_orig_width;
4789 gint moveresize_orig_height;
4790 GdkWindowHints moveresize_geom_mask;
4791 GdkGeometry moveresize_geometry;
4792 Time moveresize_process_time;
4793 XEvent *moveresize_pending_event;
4796 /* From the WM spec */
4797 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4798 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4799 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4800 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4801 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4802 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4803 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4804 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4805 #define _NET_WM_MOVERESIZE_MOVE 8
4808 wmspec_resize_drag (GdkWindow *window,
4817 /* Let the compiler turn a switch into a table, instead
4818 * of doing the table manually, this way is easier to verify.
4822 case GDK_WINDOW_EDGE_NORTH_WEST:
4823 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4826 case GDK_WINDOW_EDGE_NORTH:
4827 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4830 case GDK_WINDOW_EDGE_NORTH_EAST:
4831 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4834 case GDK_WINDOW_EDGE_WEST:
4835 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4838 case GDK_WINDOW_EDGE_EAST:
4839 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4842 case GDK_WINDOW_EDGE_SOUTH_WEST:
4843 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4846 case GDK_WINDOW_EDGE_SOUTH:
4847 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4850 case GDK_WINDOW_EDGE_SOUTH_EAST:
4851 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4855 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4861 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4864 static MoveResizeData *
4865 get_move_resize_data (GdkDisplay *display,
4868 MoveResizeData *mv_resize;
4869 static GQuark move_resize_quark = 0;
4871 if (!move_resize_quark)
4872 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4874 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4876 if (!mv_resize && create)
4878 mv_resize = g_new0 (MoveResizeData, 1);
4879 mv_resize->display = display;
4881 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4888 update_pos (MoveResizeData *mv_resize,
4894 dx = new_root_x - mv_resize->moveresize_x;
4895 dy = new_root_y - mv_resize->moveresize_y;
4897 if (mv_resize->is_resize)
4901 x = mv_resize->moveresize_orig_x;
4902 y = mv_resize->moveresize_orig_y;
4904 w = mv_resize->moveresize_orig_width;
4905 h = mv_resize->moveresize_orig_height;
4907 switch (mv_resize->resize_edge)
4909 case GDK_WINDOW_EDGE_NORTH_WEST:
4915 case GDK_WINDOW_EDGE_NORTH:
4919 case GDK_WINDOW_EDGE_NORTH_EAST:
4924 case GDK_WINDOW_EDGE_SOUTH_WEST:
4929 case GDK_WINDOW_EDGE_SOUTH_EAST:
4933 case GDK_WINDOW_EDGE_SOUTH:
4936 case GDK_WINDOW_EDGE_EAST:
4939 case GDK_WINDOW_EDGE_WEST:
4950 if (mv_resize->moveresize_geom_mask)
4952 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4953 mv_resize->moveresize_geom_mask,
4957 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4963 x = mv_resize->moveresize_orig_x + dx;
4964 y = mv_resize->moveresize_orig_y + dy;
4966 gdk_window_move (mv_resize->moveresize_window, x, y);
4971 finish_drag (MoveResizeData *mv_resize)
4973 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4974 mv_resize->moveresize_emulation_window = NULL;
4975 mv_resize->moveresize_window = NULL;
4977 if (mv_resize->moveresize_pending_event)
4979 g_free (mv_resize->moveresize_pending_event);
4980 mv_resize->moveresize_pending_event = NULL;
4985 lookahead_motion_predicate (Display *xdisplay,
4989 gboolean *seen_release = (gboolean *)arg;
4990 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4991 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4996 switch (event->xany.type)
4999 *seen_release = TRUE;
5002 mv_resize->moveresize_process_time = event->xmotion.time;
5012 moveresize_lookahead (MoveResizeData *mv_resize,
5016 gboolean seen_release = FALSE;
5018 if (mv_resize->moveresize_process_time)
5020 if (event->xmotion.time == mv_resize->moveresize_process_time)
5022 mv_resize->moveresize_process_time = 0;
5029 XCheckIfEvent (event->xany.display, &tmp_event,
5030 lookahead_motion_predicate, (XPointer) & seen_release);
5032 return mv_resize->moveresize_process_time == 0;
5036 _gdk_moveresize_handle_event (XEvent *event)
5038 guint button_mask = 0;
5039 GdkWindowObject *window_private;
5040 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
5041 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5043 if (!mv_resize || !mv_resize->moveresize_window)
5046 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
5048 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
5050 switch (event->xany.type)
5053 if (window_private->resize_count > 0)
5055 if (mv_resize->moveresize_pending_event)
5056 *mv_resize->moveresize_pending_event = *event;
5058 mv_resize->moveresize_pending_event =
5059 g_memdup (event, sizeof (XEvent));
5063 if (!moveresize_lookahead (mv_resize, event))
5066 update_pos (mv_resize,
5067 event->xmotion.x_root,
5068 event->xmotion.y_root);
5070 /* This should never be triggered in normal cases, but in the
5071 * case where the drag started without an implicit grab being
5072 * in effect, we could miss the release if it occurs before
5073 * we grab the pointer; this ensures that we will never
5074 * get a permanently stuck grab.
5076 if ((event->xmotion.state & button_mask) == 0)
5077 finish_drag (mv_resize);
5081 update_pos (mv_resize,
5082 event->xbutton.x_root,
5083 event->xbutton.y_root);
5085 if (event->xbutton.button == mv_resize->moveresize_button)
5086 finish_drag (mv_resize);
5093 _gdk_moveresize_configure_done (GdkDisplay *display,
5097 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5099 if (!mv_resize || window != mv_resize->moveresize_window)
5102 if (mv_resize->moveresize_pending_event)
5104 tmp_event = mv_resize->moveresize_pending_event;
5105 mv_resize->moveresize_pending_event = NULL;
5106 _gdk_moveresize_handle_event (tmp_event);
5114 create_moveresize_window (MoveResizeData *mv_resize,
5117 GdkWindowAttr attributes;
5118 gint attributes_mask;
5119 GdkGrabStatus status;
5121 g_assert (mv_resize->moveresize_emulation_window == NULL);
5123 attributes.x = -100;
5124 attributes.y = -100;
5125 attributes.width = 10;
5126 attributes.height = 10;
5127 attributes.window_type = GDK_WINDOW_TEMP;
5128 attributes.wclass = GDK_INPUT_ONLY;
5129 attributes.override_redirect = TRUE;
5130 attributes.event_mask = 0;
5132 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
5134 mv_resize->moveresize_emulation_window =
5135 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
5139 gdk_window_show (mv_resize->moveresize_emulation_window);
5141 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
5143 GDK_BUTTON_RELEASE_MASK |
5144 GDK_POINTER_MOTION_MASK,
5149 if (status != GDK_GRAB_SUCCESS)
5151 /* If this fails, some other client has grabbed the window
5154 gdk_window_destroy (mv_resize->moveresize_emulation_window);
5155 mv_resize->moveresize_emulation_window = NULL;
5158 mv_resize->moveresize_process_time = 0;
5162 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
5163 so that calling XMoveWindow with these coordinates will not move the
5165 Note that this depends on the WM to implement ICCCM-compliant reference
5169 calculate_unmoving_origin (MoveResizeData *mv_resize)
5174 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
5175 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
5177 gdk_window_get_origin (mv_resize->moveresize_window,
5178 &mv_resize->moveresize_orig_x,
5179 &mv_resize->moveresize_orig_y);
5183 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
5184 gdk_window_get_geometry (mv_resize->moveresize_window,
5185 NULL, NULL, &width, &height, NULL);
5187 switch (mv_resize->moveresize_geometry.win_gravity)
5189 case GDK_GRAVITY_NORTH_WEST:
5190 mv_resize->moveresize_orig_x = rect.x;
5191 mv_resize->moveresize_orig_y = rect.y;
5193 case GDK_GRAVITY_NORTH:
5194 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5195 mv_resize->moveresize_orig_y = rect.y;
5197 case GDK_GRAVITY_NORTH_EAST:
5198 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5199 mv_resize->moveresize_orig_y = rect.y;
5201 case GDK_GRAVITY_WEST:
5202 mv_resize->moveresize_orig_x = rect.x;
5203 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5205 case GDK_GRAVITY_CENTER:
5206 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5207 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5209 case GDK_GRAVITY_EAST:
5210 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5211 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5213 case GDK_GRAVITY_SOUTH_WEST:
5214 mv_resize->moveresize_orig_x = rect.x;
5215 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5217 case GDK_GRAVITY_SOUTH:
5218 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5219 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5221 case GDK_GRAVITY_SOUTH_EAST:
5222 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5223 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5226 mv_resize->moveresize_orig_x = rect.x;
5227 mv_resize->moveresize_orig_y = rect.y;
5234 emulate_resize_drag (GdkWindow *window,
5241 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5243 mv_resize->is_resize = TRUE;
5244 mv_resize->moveresize_button = button;
5245 mv_resize->resize_edge = edge;
5246 mv_resize->moveresize_x = root_x;
5247 mv_resize->moveresize_y = root_y;
5248 mv_resize->moveresize_window = g_object_ref (window);
5250 gdk_drawable_get_size (window,
5251 &mv_resize->moveresize_orig_width,
5252 &mv_resize->moveresize_orig_height);
5254 mv_resize->moveresize_geom_mask = 0;
5255 gdk_window_get_geometry_hints (window,
5256 &mv_resize->moveresize_geometry,
5257 &mv_resize->moveresize_geom_mask);
5259 calculate_unmoving_origin (mv_resize);
5261 create_moveresize_window (mv_resize, timestamp);
5265 emulate_move_drag (GdkWindow *window,
5271 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5273 mv_resize->is_resize = FALSE;
5274 mv_resize->moveresize_button = button;
5275 mv_resize->moveresize_x = root_x;
5276 mv_resize->moveresize_y = root_y;
5278 mv_resize->moveresize_window = g_object_ref (window);
5280 calculate_unmoving_origin (mv_resize);
5282 create_moveresize_window (mv_resize, timestamp);
5286 * gdk_window_begin_resize_drag:
5287 * @window: a toplevel #GdkWindow
5288 * @edge: the edge or corner from which the drag is started
5289 * @button: the button being used to drag
5290 * @root_x: root window X coordinate of mouse click that began the drag
5291 * @root_y: root window Y coordinate of mouse click that began the drag
5292 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
5294 * Begins a window resize operation (for a toplevel window).
5295 * You might use this function to implement a "window resize grip," for
5296 * example; in fact #GtkStatusbar uses it. The function works best
5297 * with window managers that support the Extended Window Manager Hints spec
5298 * (see http://www.freedesktop.org), but has a fallback implementation
5299 * for other window managers.
5303 gdk_window_begin_resize_drag (GdkWindow *window,
5310 g_return_if_fail (GDK_IS_WINDOW (window));
5312 if (GDK_WINDOW_DESTROYED (window))
5315 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5316 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
5317 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
5319 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
5323 * gdk_window_begin_move_drag:
5324 * @window: a toplevel #GdkWindow
5325 * @button: the button being used to drag
5326 * @root_x: root window X coordinate of mouse click that began the drag
5327 * @root_y: root window Y coordinate of mouse click that began the drag
5328 * @timestamp: timestamp of mouse click that began the drag
5330 * Begins a window move operation (for a toplevel window). You might
5331 * use this function to implement a "window move grip," for
5332 * example. The function works best with window managers that support
5333 * the Extended Window Manager Hints spec (see
5334 * http://www.freedesktop.org), but has a fallback implementation for
5335 * other window managers.
5339 gdk_window_begin_move_drag (GdkWindow *window,
5345 g_return_if_fail (GDK_IS_WINDOW (window));
5347 if (GDK_WINDOW_DESTROYED (window))
5350 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5351 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
5352 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
5355 emulate_move_drag (window, button, root_x, root_y, timestamp);