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>
37 #include "gdkwindow.h"
39 #include "gdkinputprivate.h"
40 #include "gdkdisplay-x11.h"
41 #include "gdkprivate-x11.h"
42 #include "gdkregion.h"
43 #include "gdkinternals.h"
45 #include "gdkwindow-x11.h"
54 #include <X11/extensions/shape.h>
57 const int _gdk_event_mask_table[21] =
61 PointerMotionHintMask,
78 SubstructureNotifyMask,
79 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
81 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
83 /* Forward declarations */
84 static void gdk_window_set_static_win_gravity (GdkWindow *window,
86 static gboolean gdk_window_icon_name_set (GdkWindow *window);
87 static void gdk_window_add_colormap_windows (GdkWindow *window);
88 static void set_wm_name (GdkDisplay *display,
91 static void move_to_current_desktop (GdkWindow *window);
93 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
94 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
96 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
99 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
100 static void gdk_window_impl_x11_finalize (GObject *object);
102 #define WINDOW_IS_TOPLEVEL(window) \
103 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
104 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
106 /* Return whether time1 is considered later than time2 as far as xserver
107 * time is concerned. Accounts for wraparound.
109 #define XSERVER_TIME_IS_LATER(time1, time2) \
110 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
111 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
114 G_DEFINE_TYPE (GdkWindowImplX11, gdk_window_impl_x11, GDK_TYPE_DRAWABLE_IMPL_X11)
117 _gdk_window_impl_get_type (void)
119 return gdk_window_impl_x11_get_type ();
123 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
127 impl->toplevel_window_type = -1;
131 _gdk_x11_window_get_toplevel (GdkWindow *window)
133 GdkWindowObject *private;
134 GdkWindowImplX11 *impl;
136 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
138 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
141 private = (GdkWindowObject *)window;
142 impl = GDK_WINDOW_IMPL_X11 (private->impl);
145 impl->toplevel = g_new0 (GdkToplevelX11, 1);
147 return impl->toplevel;
151 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
153 GObjectClass *object_class = G_OBJECT_CLASS (klass);
154 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
156 object_class->finalize = gdk_window_impl_x11_finalize;
158 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
159 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
160 drawable_class->get_size = gdk_window_impl_x11_get_size;
162 /* Visible and clip regions are the same */
163 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
164 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
168 gdk_window_impl_x11_finalize (GObject *object)
170 GdkWindowObject *wrapper;
171 GdkDrawableImplX11 *draw_impl;
172 GdkWindowImplX11 *window_impl;
174 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
176 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
177 window_impl = GDK_WINDOW_IMPL_X11 (object);
179 wrapper = (GdkWindowObject*) draw_impl->wrapper;
181 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
183 if (!GDK_WINDOW_DESTROYED (wrapper))
185 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
187 _gdk_xid_table_remove (display, draw_impl->xid);
188 if (window_impl->toplevel && window_impl->toplevel->focus_window)
189 _gdk_xid_table_remove (display, window_impl->toplevel->focus_window);
192 if (window_impl->toplevel)
193 g_free (window_impl->toplevel);
195 if (window_impl->cursor)
196 gdk_cursor_unref (window_impl->cursor);
198 G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
202 tmp_unset_bg (GdkWindow *window)
204 GdkWindowImplX11 *impl;
205 GdkWindowObject *obj;
207 obj = (GdkWindowObject *) window;
208 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
210 /* For windows without EXPOSURE_MASK, we can't do this
211 * unsetting because such windows depend on the drawing
212 * that the X server is going to do
214 if (!(obj->event_mask & GDK_EXPOSURE_MASK))
217 impl->position_info.no_bg = TRUE;
219 if (obj->bg_pixmap != GDK_NO_BG)
220 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
221 GDK_DRAWABLE_XID (window), None);
225 tmp_reset_bg (GdkWindow *window)
227 GdkWindowImplX11 *impl;
228 GdkWindowObject *obj;
230 obj = (GdkWindowObject *) window;
231 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
233 if (!(obj->event_mask & GDK_EXPOSURE_MASK))
236 impl->position_info.no_bg = FALSE;
238 if (obj->bg_pixmap == GDK_NO_BG)
245 if (obj->bg_pixmap == GDK_PARENT_RELATIVE_BG)
246 xpixmap = ParentRelative;
248 xpixmap = GDK_DRAWABLE_XID (obj->bg_pixmap);
250 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
251 GDK_DRAWABLE_XID (window), xpixmap);
255 XSetWindowBackground (GDK_DRAWABLE_XDISPLAY (window),
256 GDK_DRAWABLE_XID (window),
257 obj->bg_color.pixel);
261 /* Unsetting and resetting window backgrounds.
263 * In many cases it is possible to avoid flicker by unsetting the
264 * background of windows. For example if the background of the
265 * parent window is unset when a window is unmapped, a brief flicker
266 * of background painting is avoided.
269 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
272 GdkWindowObject *private;
274 g_return_if_fail (GDK_IS_WINDOW (window));
276 private = (GdkWindowObject *)window;
278 if (private->input_only || private->destroyed ||
279 (private->window_type != GDK_WINDOW_ROOT &&
280 !GDK_WINDOW_IS_MAPPED (window)))
285 if (private->window_type != GDK_WINDOW_ROOT &&
286 private->window_type != GDK_WINDOW_FOREIGN)
288 tmp_unset_bg (window);
295 for (l = private->children; l != NULL; l = l->next)
296 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
301 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
304 GdkWindowObject *private;
306 g_return_if_fail (GDK_IS_WINDOW (window));
308 private = (GdkWindowObject *)window;
310 if (private->input_only || private->destroyed ||
311 (private->window_type != GDK_WINDOW_ROOT &&
312 !GDK_WINDOW_IS_MAPPED (window)))
317 if (private->window_type != GDK_WINDOW_ROOT &&
318 private->window_type != GDK_WINDOW_FOREIGN)
320 tmp_reset_bg (window);
327 for (l = private->children; l != NULL; l = l->next)
328 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
333 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
335 GdkDrawableImplX11 *drawable_impl;
337 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
339 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
341 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
342 drawable_impl->colormap == NULL)
344 XWindowAttributes window_attributes;
347 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
351 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
352 window_attributes.visual->visualid);
353 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
354 window_attributes.colormap);
357 return drawable_impl->colormap;
361 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
364 GdkDrawableImplX11 *draw_impl;
366 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
368 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
370 if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper))
374 GDK_DRAWABLE_CLASS (gdk_window_impl_x11_parent_class)->set_colormap (drawable, cmap);
378 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
380 GDK_COLORMAP_XCOLORMAP (cmap));
382 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
384 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
390 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
394 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
397 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
399 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
403 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
405 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
406 GdkRectangle result_rect;
410 result_rect.width = impl->width;
411 result_rect.height = impl->height;
413 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
415 return gdk_region_rectangle (&result_rect);
419 _gdk_windowing_window_init (GdkScreen * screen)
421 GdkWindowObject *private;
422 GdkWindowImplX11 *impl;
423 GdkDrawableImplX11 *draw_impl;
424 GdkScreenX11 *screen_x11;
426 screen_x11 = GDK_SCREEN_X11 (screen);
428 g_assert (screen_x11->root_window == NULL);
430 gdk_screen_set_default_colormap (screen,
431 gdk_screen_get_system_colormap (screen));
433 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
434 private = (GdkWindowObject *)screen_x11->root_window;
435 impl = GDK_WINDOW_IMPL_X11 (private->impl);
436 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
438 draw_impl->screen = screen;
439 draw_impl->xid = screen_x11->xroot_window;
440 draw_impl->wrapper = GDK_DRAWABLE (private);
441 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
442 g_object_ref (draw_impl->colormap);
444 private->window_type = GDK_WINDOW_ROOT;
445 private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
447 impl->width = WidthOfScreen (screen_x11->xscreen);
448 impl->height = HeightOfScreen (screen_x11->xscreen);
450 _gdk_window_init_position (GDK_WINDOW (private));
452 _gdk_xid_table_insert (screen_x11->display,
453 &screen_x11->xroot_window,
454 screen_x11->root_window);
458 set_wm_protocols (GdkWindow *window)
460 GdkDisplay *display = gdk_drawable_get_display (window);
464 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
465 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
466 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
469 if (GDK_DISPLAY_X11 (display)->use_sync)
470 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
473 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
477 get_default_title (void)
481 title = g_get_application_name ();
483 title = g_get_prgname ();
489 check_leader_window_title (GdkDisplay *display)
491 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
493 if (display_x11->leader_window && !display_x11->leader_window_title_set)
495 set_wm_name (display,
496 display_x11->leader_window,
497 get_default_title ());
499 display_x11->leader_window_title_set = TRUE;
504 create_focus_window (Display *xdisplay,
507 Window focus_window = XCreateSimpleWindow (xdisplay, parent,
511 /* FIXME: probably better to actually track the requested event mask for the toplevel
513 XSelectInput (xdisplay, focus_window,
514 KeyPressMask | KeyReleaseMask | FocusChangeMask);
516 XMapWindow (xdisplay, focus_window);
522 ensure_sync_counter (GdkWindow *window)
525 if (!GDK_WINDOW_DESTROYED (window))
527 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
528 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
529 GdkWindowObject *private = (GdkWindowObject *)window;
530 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
532 if (toplevel && impl->use_synchronized_configure &&
533 toplevel->update_counter == None &&
534 GDK_DISPLAY_X11 (display)->use_sync)
536 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
540 XSyncIntToValue (&value, 0);
542 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
544 atom = gdk_x11_get_xatom_by_name_for_display (display,
545 "_NET_WM_SYNC_REQUEST_COUNTER");
547 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
550 (guchar *)&toplevel->update_counter, 1);
552 XSyncIntToValue (&toplevel->current_counter_value, 0);
559 setup_toplevel_window (GdkWindow *window,
562 GdkWindowObject *obj = (GdkWindowObject *)window;
563 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
564 GdkWindowImplX11 *impl = (GdkWindowImplX11 *)obj->impl;
565 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
566 XID xid = GDK_WINDOW_XID (window);
567 XID xparent = GDK_WINDOW_XID (parent);
568 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
569 XSizeHints size_hints;
572 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_DIALOG)
573 XSetTransientForHint (xdisplay, xid, xparent);
575 set_wm_protocols (window);
577 if (!obj->input_only)
579 /* The focus window is off the visible area, and serves to receive key
580 * press events so they don't get sent to child windows.
582 toplevel->focus_window = create_focus_window (xdisplay, xid);
583 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
586 check_leader_window_title (screen_x11->display);
588 /* FIXME: Is there any point in doing this? Do any WM's pay
589 * attention to PSize, and even if they do, is this the
592 size_hints.flags = PSize;
593 size_hints.width = impl->width;
594 size_hints.height = impl->height;
596 XSetWMNormalHints (xdisplay, xid, &size_hints);
598 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
599 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
602 XChangeProperty (xdisplay, xid,
603 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
608 XChangeProperty (xdisplay, xid,
609 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
610 XA_WINDOW, 32, PropModeReplace,
611 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
613 if (!obj->focus_on_map)
614 gdk_x11_window_set_user_time (window, 0);
615 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
616 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
618 ensure_sync_counter (window);
623 * @parent: a #GdkWindow, or %NULL to create the window as a child of
624 * the default root window for the default display.
625 * @attributes: attributes of the new window
626 * @attributes_mask: mask indicating which fields in @attributes are valid
628 * Creates a new #GdkWindow using the attributes from
629 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
630 * more details. Note: to use this on displays other than the default
631 * display, @parent must be specified.
633 * Return value: the new #GdkWindow
636 gdk_window_new (GdkWindow *parent,
637 GdkWindowAttr *attributes,
638 gint attributes_mask)
641 GdkWindowObject *private;
642 GdkWindowImplX11 *impl;
643 GdkDrawableImplX11 *draw_impl;
644 GdkScreenX11 *screen_x11;
653 XSetWindowAttributes xattributes;
654 long xattributes_mask;
655 XClassHint *class_hint;
662 g_return_val_if_fail (attributes != NULL, NULL);
667 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
669 screen = gdk_screen_get_default ();
670 parent = gdk_screen_get_root_window (screen);
673 screen = gdk_drawable_get_screen (parent);
675 screen_x11 = GDK_SCREEN_X11 (screen);
677 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
679 if (GDK_WINDOW_DESTROYED (parent))
682 xparent = GDK_WINDOW_XID (parent);
684 window = g_object_new (GDK_TYPE_WINDOW, NULL);
685 private = (GdkWindowObject *)window;
686 impl = GDK_WINDOW_IMPL_X11 (private->impl);
687 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
688 draw_impl->wrapper = GDK_DRAWABLE (window);
690 draw_impl->screen = screen;
691 xdisplay = screen_x11->xdisplay;
693 /* Windows with a foreign parent are treated as if they are children
694 * of the root window, except for actual creation.
696 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
697 parent = gdk_screen_get_root_window (screen);
699 private->parent = (GdkWindowObject *)parent;
701 private->accept_focus = TRUE;
702 private->focus_on_map = TRUE;
704 xattributes_mask = 0;
706 if (attributes_mask & GDK_WA_X)
711 if (attributes_mask & GDK_WA_Y)
718 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
719 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
721 if (attributes->wclass == GDK_INPUT_ONLY)
723 /* Backwards compatiblity - we've always ignored
724 * attributes->window_type for input-only windows
727 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
728 private->window_type = GDK_WINDOW_TEMP;
730 private->window_type = GDK_WINDOW_CHILD;
733 private->window_type = attributes->window_type;
735 /* Work around a bug where Xorg refuses to map toplevel InputOnly windows
736 * from an untrusted client: http://bugs.freedesktop.org/show_bug.cgi?id=6988
738 if (attributes->wclass == GDK_INPUT_ONLY &&
739 GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT &&
740 !G_LIKELY (GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (parent))->trusted_client))
742 g_warning ("Coercing GDK_INPUT_ONLY toplevel window to GDK_INPUT_OUTPUT to work around bug in Xorg server");
743 attributes->wclass = GDK_INPUT_OUTPUT;
746 _gdk_window_init_position (GDK_WINDOW (private));
747 if (impl->position_info.big)
748 private->guffaw_gravity = TRUE;
750 if (attributes_mask & GDK_WA_VISUAL)
751 visual = attributes->visual;
753 visual = gdk_screen_get_system_visual (screen);
754 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
756 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
757 for (i = 0; i < _gdk_nenvent_masks; i++)
759 if (attributes->event_mask & (1 << (i + 1)))
760 xattributes.event_mask |= _gdk_event_mask_table[i];
762 private->event_mask = attributes->event_mask;
764 if (xattributes.event_mask)
765 xattributes_mask |= CWEventMask;
767 if (attributes_mask & GDK_WA_NOREDIR)
769 xattributes.override_redirect =
770 (attributes->override_redirect == FALSE)?False:True;
771 xattributes_mask |= CWOverrideRedirect;
774 xattributes.override_redirect = False;
776 impl->override_redirect = xattributes.override_redirect;
778 if (private->parent && private->parent->guffaw_gravity)
780 xattributes.win_gravity = StaticGravity;
781 xattributes_mask |= CWWinGravity;
785 switch (private->window_type)
787 case GDK_WINDOW_TOPLEVEL:
788 case GDK_WINDOW_DIALOG:
789 case GDK_WINDOW_TEMP:
790 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
792 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
793 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
794 xparent = GDK_SCREEN_XROOTWIN (screen);
796 case GDK_WINDOW_CHILD:
799 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
803 if (attributes->wclass == GDK_INPUT_OUTPUT)
806 depth = visual->depth;
808 private->input_only = FALSE;
809 private->depth = depth;
811 if (attributes_mask & GDK_WA_COLORMAP)
813 draw_impl->colormap = attributes->colormap;
814 g_object_ref (attributes->colormap);
818 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
820 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
821 g_object_ref (draw_impl->colormap);
825 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
829 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
830 private->bg_color.red = private->bg_color.green = private->bg_color.blue = 0;
831 xattributes.background_pixel = private->bg_color.pixel;
833 private->bg_pixmap = NULL;
835 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
836 xattributes_mask |= CWBorderPixel | CWBackPixel;
838 if (private->guffaw_gravity)
839 xattributes.bit_gravity = StaticGravity;
841 xattributes.bit_gravity = NorthWestGravity;
843 xattributes_mask |= CWBitGravity;
845 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
846 xattributes_mask |= CWColormap;
848 if (private->window_type == GDK_WINDOW_TEMP)
850 xattributes.save_under = True;
851 xattributes.override_redirect = True;
852 xattributes.cursor = None;
853 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
855 impl->override_redirect = TRUE;
863 private->input_only = TRUE;
864 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
865 g_object_ref (draw_impl->colormap);
868 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
869 impl->position_info.x, impl->position_info.y,
870 impl->position_info.width, impl->position_info.height,
871 0, depth, class, xvisual,
872 xattributes_mask, &xattributes);
874 g_object_ref (window);
875 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
877 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
878 (attributes->cursor) :
882 private->parent->children = g_list_prepend (private->parent->children, window);
884 switch (GDK_WINDOW_TYPE (private))
886 case GDK_WINDOW_DIALOG:
887 case GDK_WINDOW_TOPLEVEL:
888 case GDK_WINDOW_TEMP:
889 if (attributes_mask & GDK_WA_TITLE)
890 title = attributes->title;
892 title = get_default_title ();
894 gdk_window_set_title (window, title);
896 if (attributes_mask & GDK_WA_WMCLASS)
898 class_hint = XAllocClassHint ();
899 class_hint->res_name = attributes->wmclass_name;
900 class_hint->res_class = attributes->wmclass_class;
901 XSetClassHint (xdisplay, xid, class_hint);
905 setup_toplevel_window (window, parent);
908 case GDK_WINDOW_CHILD:
909 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
910 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
911 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
913 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
914 gdk_window_add_colormap_windows (window);
926 x_event_mask_to_gdk_event_mask (long mask)
928 GdkEventMask event_mask = 0;
931 for (i = 0; i < _gdk_nenvent_masks; i++)
933 if (mask & _gdk_event_mask_table[i])
934 event_mask |= 1 << (i + 1);
941 * gdk_window_foreign_new_for_display:
942 * @display: the #GdkDisplay where the window handle comes from.
943 * @anid: a native window handle.
945 * Wraps a native window in a #GdkWindow.
946 * This may fail if the window has been destroyed. If the window
947 * was already known to GDK, a new reference to the existing
948 * #GdkWindow is returned.
950 * For example in the X backend, a native window handle is an Xlib
953 * Return value: a #GdkWindow wrapper for the native window or
954 * %NULL if the window has been destroyed. The wrapper will be
955 * newly created, if one doesn't exist already.
960 gdk_window_foreign_new_for_display (GdkDisplay *display,
961 GdkNativeWindow anid)
964 GdkWindowObject *private;
965 GdkWindowImplX11 *impl;
966 GdkDrawableImplX11 *draw_impl;
967 GdkDisplayX11 *display_x11;
968 XWindowAttributes attrs;
970 Window *children = NULL;
974 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
976 display_x11 = GDK_DISPLAY_X11 (display);
978 if ((window = gdk_xid_table_lookup_for_display (display, anid)) != NULL)
979 return g_object_ref (window);
981 gdk_error_trap_push ();
982 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
983 if (gdk_error_trap_pop () || !result)
986 /* FIXME: This is pretty expensive. Maybe the caller should supply
988 gdk_error_trap_push ();
989 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
990 if (gdk_error_trap_pop () || !result)
996 window = g_object_new (GDK_TYPE_WINDOW, NULL);
997 private = (GdkWindowObject *)window;
998 impl = GDK_WINDOW_IMPL_X11 (private->impl);
999 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
1000 draw_impl->wrapper = GDK_DRAWABLE (window);
1001 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
1003 private->parent = gdk_xid_table_lookup_for_display (display, parent);
1005 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
1006 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
1008 private->parent->children = g_list_prepend (private->parent->children, window);
1010 draw_impl->xid = anid;
1012 private->x = attrs.x;
1013 private->y = attrs.y;
1014 impl->width = attrs.width;
1015 impl->height = attrs.height;
1016 private->window_type = GDK_WINDOW_FOREIGN;
1017 private->destroyed = FALSE;
1019 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
1021 if (attrs.map_state == IsUnmapped)
1022 private->state = GDK_WINDOW_STATE_WITHDRAWN;
1026 private->depth = attrs.depth;
1028 _gdk_window_init_position (GDK_WINDOW (private));
1030 g_object_ref (window);
1031 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
1036 * gdk_window_lookup_for_display:
1037 * @display: the #GdkDisplay corresponding to the window handle
1038 * @anid: a native window handle.
1040 * Looks up the #GdkWindow that wraps the given native window handle.
1042 * For example in the X backend, a native window handle is an Xlib
1045 * Return value: the #GdkWindow wrapper for the native window,
1046 * or %NULL if there is none.
1051 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
1053 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
1057 * gdk_window_lookup:
1058 * @anid: a native window handle.
1060 * Looks up the #GdkWindow that wraps the given native window handle.
1062 * For example in the X backend, a native window handle is an Xlib
1065 * Return value: the #GdkWindow wrapper for the native window,
1066 * or %NULL if there is none.
1069 gdk_window_lookup (GdkNativeWindow anid)
1071 return (GdkWindow*) gdk_xid_table_lookup (anid);
1075 gdk_toplevel_x11_free_contents (GdkDisplay *display,
1076 GdkToplevelX11 *toplevel)
1078 if (toplevel->icon_window)
1080 g_object_unref (toplevel->icon_window);
1081 toplevel->icon_window = NULL;
1083 if (toplevel->icon_pixmap)
1085 g_object_unref (toplevel->icon_pixmap);
1086 toplevel->icon_pixmap = NULL;
1088 if (toplevel->icon_mask)
1090 g_object_unref (toplevel->icon_mask);
1091 toplevel->icon_mask = NULL;
1093 if (toplevel->group_leader)
1095 g_object_unref (toplevel->group_leader);
1096 toplevel->group_leader = NULL;
1099 if (toplevel->update_counter != None)
1101 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
1102 toplevel->update_counter);
1103 toplevel->update_counter = None;
1105 XSyncIntToValue (&toplevel->current_counter_value, 0);
1111 _gdk_windowing_window_destroy (GdkWindow *window,
1113 gboolean foreign_destroy)
1115 GdkWindowObject *private = (GdkWindowObject *)window;
1116 GdkToplevelX11 *toplevel;
1118 g_return_if_fail (GDK_IS_WINDOW (window));
1120 _gdk_selection_window_destroyed (window);
1122 if (private->extension_events != 0)
1123 _gdk_input_window_destroy (window);
1125 toplevel = _gdk_x11_window_get_toplevel (window);
1127 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1129 _gdk_x11_drawable_finish (private->impl);
1131 if (!recursing && !foreign_destroy)
1133 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1138 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
1140 /* It's somebody else's window, but in our heirarchy,
1141 * so reparent it to the root window, and then send
1142 * it a delete event, as if we were a WM
1144 XClientMessageEvent xevent;
1146 gdk_error_trap_push ();
1147 gdk_window_hide (window);
1148 gdk_window_reparent (window, NULL, 0, 0);
1150 xevent.type = ClientMessage;
1151 xevent.window = GDK_WINDOW_XID (window);
1152 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1155 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1156 "WM_DELETE_WINDOW");
1157 xevent.data.l[1] = CurrentTime;
1158 xevent.data.l[2] = 0;
1159 xevent.data.l[3] = 0;
1160 xevent.data.l[4] = 0;
1162 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1163 GDK_WINDOW_XID (window),
1164 False, 0, (XEvent *)&xevent);
1165 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
1166 gdk_error_trap_pop ();
1170 get_root (GdkWindow *window)
1172 GdkScreen *screen = gdk_drawable_get_screen (window);
1174 return gdk_screen_get_root_window (screen);
1177 /* This function is called when the XWindow is really gone.
1180 gdk_window_destroy_notify (GdkWindow *window)
1182 GdkWindowImplX11 *window_impl;
1184 g_return_if_fail (GDK_IS_WINDOW (window));
1186 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
1188 if (!GDK_WINDOW_DESTROYED (window))
1190 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1191 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1193 _gdk_window_destroy (window, TRUE);
1196 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1197 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1198 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1200 _gdk_xgrab_check_destroy (window);
1202 g_object_unref (window);
1206 update_wm_hints (GdkWindow *window,
1209 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1210 GdkWindowObject *private = (GdkWindowObject *)window;
1211 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1215 !toplevel->is_leader &&
1216 private->state & GDK_WINDOW_STATE_WITHDRAWN)
1219 wm_hints.flags = StateHint | InputHint;
1220 wm_hints.input = private->accept_focus ? True : False;
1221 wm_hints.initial_state = NormalState;
1223 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
1225 wm_hints.flags |= StateHint;
1226 wm_hints.initial_state = IconicState;
1229 if (toplevel->icon_window && !GDK_WINDOW_DESTROYED (toplevel->icon_window))
1231 wm_hints.flags |= IconWindowHint;
1232 wm_hints.icon_window = GDK_WINDOW_XID (toplevel->icon_window);
1235 if (toplevel->icon_pixmap)
1237 wm_hints.flags |= IconPixmapHint;
1238 wm_hints.icon_pixmap = GDK_PIXMAP_XID (toplevel->icon_pixmap);
1241 if (toplevel->icon_mask)
1243 wm_hints.flags |= IconMaskHint;
1244 wm_hints.icon_mask = GDK_PIXMAP_XID (toplevel->icon_mask);
1247 wm_hints.flags |= WindowGroupHint;
1248 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1250 wm_hints.flags |= WindowGroupHint;
1251 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1254 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1256 if (toplevel->urgency_hint)
1257 wm_hints.flags |= XUrgencyHint;
1259 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1260 GDK_WINDOW_XID (window),
1265 set_initial_hints (GdkWindow *window)
1267 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1268 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1269 Window xwindow = GDK_WINDOW_XID (window);
1270 GdkWindowObject *private;
1271 GdkToplevelX11 *toplevel;
1275 private = (GdkWindowObject*) window;
1276 toplevel = _gdk_x11_window_get_toplevel (window);
1281 update_wm_hints (window, TRUE);
1283 /* We set the spec hints regardless of whether the spec is supported,
1284 * since it can't hurt and it's kind of expensive to check whether
1290 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1292 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1293 "_NET_WM_STATE_MAXIMIZED_VERT");
1295 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1296 "_NET_WM_STATE_MAXIMIZED_HORZ");
1300 if (private->state & GDK_WINDOW_STATE_ABOVE)
1302 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1303 "_NET_WM_STATE_ABOVE");
1307 if (private->state & GDK_WINDOW_STATE_BELOW)
1309 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1310 "_NET_WM_STATE_BELOW");
1314 if (private->state & GDK_WINDOW_STATE_STICKY)
1316 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1317 "_NET_WM_STATE_STICKY");
1321 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1323 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1324 "_NET_WM_STATE_FULLSCREEN");
1328 if (private->modal_hint)
1330 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1331 "_NET_WM_STATE_MODAL");
1335 if (toplevel->skip_taskbar_hint)
1337 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1338 "_NET_WM_STATE_SKIP_TASKBAR");
1342 if (toplevel->skip_pager_hint)
1344 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1345 "_NET_WM_STATE_SKIP_PAGER");
1351 XChangeProperty (xdisplay,
1353 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1354 XA_ATOM, 32, PropModeReplace,
1355 (guchar*) atoms, i);
1359 XDeleteProperty (xdisplay,
1361 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1364 if (private->state & GDK_WINDOW_STATE_STICKY)
1366 atoms[0] = 0xFFFFFFFF;
1367 XChangeProperty (xdisplay,
1369 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1370 XA_CARDINAL, 32, PropModeReplace,
1371 (guchar*) atoms, 1);
1375 XDeleteProperty (xdisplay,
1377 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1380 toplevel->map_serial = NextRequest (xdisplay);
1384 show_window_internal (GdkWindow *window,
1387 GdkWindowObject *private;
1388 GdkDisplay *display;
1389 GdkDisplayX11 *display_x11;
1390 GdkToplevelX11 *toplevel;
1392 g_return_if_fail (GDK_IS_WINDOW (window));
1394 private = (GdkWindowObject*) window;
1395 if (!private->destroyed)
1397 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1398 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1399 Window xwindow = GDK_WINDOW_XID (window);
1402 XRaiseWindow (xdisplay, xwindow);
1404 if (!GDK_WINDOW_IS_MAPPED (window))
1406 set_initial_hints (window);
1408 gdk_synthesize_window_state (window,
1409 GDK_WINDOW_STATE_WITHDRAWN,
1413 g_assert (GDK_WINDOW_IS_MAPPED (window));
1415 if (WINDOW_IS_TOPLEVEL (window))
1417 display = gdk_drawable_get_display (window);
1418 display_x11 = GDK_DISPLAY_X11 (display);
1419 toplevel = _gdk_x11_window_get_toplevel (window);
1421 if (toplevel->user_time != 0 &&
1422 display_x11->user_time != 0 &&
1423 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1424 gdk_x11_window_set_user_time (window, display_x11->user_time);
1427 if (impl->position_info.mapped)
1429 gboolean unset_bg = !private->input_only &&
1430 (private->window_type == GDK_WINDOW_CHILD ||
1431 impl->override_redirect) &&
1432 gdk_window_is_viewable (window);
1435 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1437 XMapWindow (xdisplay, xwindow);
1441 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1442 gdk_window_invalidate_rect (window, NULL, TRUE);
1449 * gdk_window_show_unraised:
1450 * @window: a #GdkWindow
1452 * Shows a #GdkWindow onscreen, but does not modify its stacking
1453 * order. In contrast, gdk_window_show() will raise the window
1454 * to the top of the window stack.
1456 * On the X11 platform, in Xlib terms, this function calls
1457 * XMapWindow() (it also updates some internal GDK state, which means
1458 * that you can't really use XMapWindow() directly on a GDK window).
1462 gdk_window_show_unraised (GdkWindow *window)
1464 g_return_if_fail (GDK_IS_WINDOW (window));
1466 show_window_internal (window, FALSE);
1471 * @window: a #GdkWindow
1473 * Like gdk_window_show_unraised(), but also raises the window to the
1474 * top of the window stack (moves the window to the front of the
1477 * This function maps a window so it's visible onscreen. Its opposite
1478 * is gdk_window_hide().
1480 * When implementing a #GtkWidget, you should call this function on the widget's
1481 * #GdkWindow as part of the "map" method.
1485 gdk_window_show (GdkWindow *window)
1487 g_return_if_fail (GDK_IS_WINDOW (window));
1489 show_window_internal (window, TRUE);
1493 pre_unmap (GdkWindow *window)
1495 GdkWindow *start_window = NULL;
1496 GdkWindowObject *private = (GdkWindowObject *)window;
1498 if (private->input_only)
1501 if (private->window_type == GDK_WINDOW_CHILD)
1502 start_window = (GdkWindow *)private->parent;
1503 else if (private->window_type == GDK_WINDOW_TEMP)
1504 start_window = get_root (window);
1507 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1511 post_unmap (GdkWindow *window)
1513 GdkWindow *start_window = NULL;
1514 GdkWindowObject *private = (GdkWindowObject *)window;
1516 if (private->input_only)
1519 if (private->window_type == GDK_WINDOW_CHILD)
1520 start_window = (GdkWindow *)private->parent;
1521 else if (private->window_type == GDK_WINDOW_TEMP)
1522 start_window = get_root (window);
1526 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1528 if (private->window_type == GDK_WINDOW_CHILD && private->parent)
1530 GdkRectangle invalid_rect;
1532 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1533 gdk_drawable_get_size (GDK_DRAWABLE (window),
1534 &invalid_rect.width, &invalid_rect.height);
1535 gdk_window_invalidate_rect ((GdkWindow *)private->parent,
1536 &invalid_rect, TRUE);
1543 * @window: a #GdkWindow
1545 * For toplevel windows, withdraws them, so they will no longer be
1546 * known to the window manager; for all windows, unmaps them, so
1547 * they won't be displayed. Normally done automatically as
1548 * part of gtk_widget_hide().
1552 gdk_window_hide (GdkWindow *window)
1554 GdkWindowObject *private;
1556 g_return_if_fail (GDK_IS_WINDOW (window));
1558 private = (GdkWindowObject*) window;
1560 /* We'll get the unmap notify eventually, and handle it then,
1561 * but checking here makes things more consistent if we are
1562 * just doing stuff ourself.
1564 _gdk_xgrab_check_unmap (window,
1565 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1567 /* You can't simply unmap toplevel windows. */
1568 switch (private->window_type)
1570 case GDK_WINDOW_TOPLEVEL:
1571 case GDK_WINDOW_DIALOG:
1572 case GDK_WINDOW_TEMP: /* ? */
1573 gdk_window_withdraw (window);
1577 case GDK_WINDOW_FOREIGN:
1578 case GDK_WINDOW_ROOT:
1579 case GDK_WINDOW_CHILD:
1583 if (!private->destroyed)
1585 if (GDK_WINDOW_IS_MAPPED (window))
1586 gdk_synthesize_window_state (window,
1588 GDK_WINDOW_STATE_WITHDRAWN);
1590 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1592 _gdk_window_clear_update_area (window);
1596 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1597 GDK_WINDOW_XID (window));
1599 post_unmap (window);
1604 * gdk_window_withdraw:
1605 * @window: a toplevel #GdkWindow
1607 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1608 * This function is not really useful as gdk_window_hide() automatically
1609 * withdraws toplevel windows before hiding them.
1613 gdk_window_withdraw (GdkWindow *window)
1615 GdkWindowObject *private;
1617 g_return_if_fail (GDK_IS_WINDOW (window));
1619 private = (GdkWindowObject*) window;
1620 if (!private->destroyed)
1622 if (GDK_WINDOW_IS_MAPPED (window))
1623 gdk_synthesize_window_state (window,
1625 GDK_WINDOW_STATE_WITHDRAWN);
1627 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1631 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1632 GDK_WINDOW_XID (window), 0);
1634 post_unmap (window);
1640 * @window: a #GdkWindow
1641 * @x: X coordinate relative to window's parent
1642 * @y: Y coordinate relative to window's parent
1644 * Repositions a window relative to its parent window.
1645 * For toplevel windows, window managers may ignore or modify the move;
1646 * you should probably use gtk_window_move() on a #GtkWindow widget
1647 * anyway, instead of using GDK functions. For child windows,
1648 * the move will reliably succeed.
1650 * If you're also planning to resize the window, use gdk_window_move_resize()
1651 * to both move and resize simultaneously, for a nicer visual effect.
1654 gdk_window_move (GdkWindow *window,
1658 GdkWindowObject *private = (GdkWindowObject *)window;
1659 GdkWindowImplX11 *impl;
1661 g_return_if_fail (GDK_IS_WINDOW (window));
1663 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1665 if (!GDK_WINDOW_DESTROYED (window))
1667 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1669 _gdk_window_move_resize_child (window, x, y,
1670 impl->width, impl->height);
1674 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1675 GDK_WINDOW_XID (window),
1678 if (impl->override_redirect)
1688 * gdk_window_resize:
1689 * @window: a #GdkWindow
1690 * @width: new width of the window
1691 * @height: new height of the window
1693 * Resizes @window; for toplevel windows, asks the window manager to resize
1694 * the window. The window manager may not allow the resize. When using GTK+,
1695 * use gtk_window_resize() instead of this low-level GDK function.
1697 * Windows may not be resized below 1x1.
1699 * If you're also planning to move the window, use gdk_window_move_resize()
1700 * to both move and resize simultaneously, for a nicer visual effect.
1703 gdk_window_resize (GdkWindow *window,
1707 GdkWindowObject *private;
1709 g_return_if_fail (GDK_IS_WINDOW (window));
1716 private = (GdkWindowObject*) window;
1718 if (!GDK_WINDOW_DESTROYED (window))
1720 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1722 _gdk_window_move_resize_child (window, private->x, private->y,
1724 _gdk_x11_drawable_update_size (private->impl);
1728 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1730 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1731 GDK_WINDOW_XID (window),
1734 if (impl->override_redirect)
1736 impl->width = width;
1737 impl->height = height;
1738 _gdk_x11_drawable_update_size (private->impl);
1742 if (width != impl->width || height != impl->height)
1743 private->resize_count += 1;
1747 _gdk_x11_drawable_update_size (private->impl);
1752 * gdk_window_move_resize:
1753 * @window: a #GdkWindow
1754 * @x: new X position relative to window's parent
1755 * @y: new Y position relative to window's parent
1757 * @height: new height
1759 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1760 * except that both operations are performed at once, avoiding strange
1761 * visual effects. (i.e. the user may be able to see the window first
1762 * move, then resize, if you don't use gdk_window_move_resize().)
1765 gdk_window_move_resize (GdkWindow *window,
1771 GdkWindowObject *private;
1773 g_return_if_fail (GDK_IS_WINDOW (window));
1780 private = (GdkWindowObject*) window;
1782 if (!GDK_WINDOW_DESTROYED (window))
1784 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1786 _gdk_window_move_resize_child (window, x, y, width, height);
1787 _gdk_x11_drawable_update_size (private->impl);
1791 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1793 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1794 GDK_WINDOW_XID (window),
1795 x, y, width, height);
1796 if (impl->override_redirect)
1800 impl->width = width;
1801 impl->height = height;
1803 _gdk_x11_drawable_update_size (private->impl);
1807 if (width != impl->width || height != impl->height)
1808 private->resize_count += 1;
1815 * gdk_window_reparent:
1816 * @window: a #GdkWindow
1817 * @new_parent: new parent to move @window into
1818 * @x: X location inside the new parent
1819 * @y: Y location inside the new parent
1821 * Reparents @window into the given @new_parent. The window being
1822 * reparented will be unmapped as a side effect.
1826 gdk_window_reparent (GdkWindow *window,
1827 GdkWindow *new_parent,
1831 GdkWindowObject *window_private;
1832 GdkWindowObject *parent_private;
1833 GdkWindowObject *old_parent_private;
1834 GdkWindowImplX11 *impl;
1835 gboolean was_toplevel;
1837 g_return_if_fail (GDK_IS_WINDOW (window));
1838 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1839 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1841 if (GDK_WINDOW_DESTROYED (window) ||
1842 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1848 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1850 window_private = (GdkWindowObject*) window;
1851 old_parent_private = (GdkWindowObject*)window_private->parent;
1852 parent_private = (GdkWindowObject*) new_parent;
1853 impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
1855 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1856 GDK_WINDOW_XID (window),
1857 GDK_WINDOW_XID (new_parent),
1860 window_private->x = x;
1861 window_private->y = y;
1863 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1866 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1867 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1869 window_private->parent = (GdkWindowObject *)new_parent;
1871 /* Switch the window type as appropriate */
1873 switch (GDK_WINDOW_TYPE (new_parent))
1875 case GDK_WINDOW_ROOT:
1876 case GDK_WINDOW_FOREIGN:
1877 was_toplevel = WINDOW_IS_TOPLEVEL (window);
1879 if (impl->toplevel_window_type != -1)
1880 GDK_WINDOW_TYPE (window) = impl->toplevel_window_type;
1881 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1882 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1884 if (WINDOW_IS_TOPLEVEL (window) && !was_toplevel)
1885 setup_toplevel_window (window, new_parent);
1887 case GDK_WINDOW_TOPLEVEL:
1888 case GDK_WINDOW_CHILD:
1889 case GDK_WINDOW_DIALOG:
1890 case GDK_WINDOW_TEMP:
1891 if (WINDOW_IS_TOPLEVEL (window))
1893 /* Save the original window type so we can restore it if the
1894 * window is reparented back to be a toplevel
1896 impl->toplevel_window_type = GDK_WINDOW_TYPE (window);
1897 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1900 if (impl->toplevel->focus_window)
1902 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1903 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1906 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1908 g_free (impl->toplevel);
1909 impl->toplevel = NULL;
1914 if (old_parent_private)
1915 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1917 if ((old_parent_private &&
1918 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1919 (!old_parent_private && parent_private->guffaw_gravity))
1920 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1922 parent_private->children = g_list_prepend (parent_private->children, window);
1923 _gdk_window_init_position (GDK_WINDOW (window_private));
1927 _gdk_windowing_window_clear_area (GdkWindow *window,
1933 g_return_if_fail (GDK_IS_WINDOW (window));
1935 if (!GDK_WINDOW_DESTROYED (window))
1936 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1937 x, y, width, height, False);
1941 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1947 g_return_if_fail (GDK_IS_WINDOW (window));
1949 if (!GDK_WINDOW_DESTROYED (window))
1950 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1951 x, y, width, height, True);
1957 * @window: a #GdkWindow
1959 * Raises @window to the top of the Z-order (stacking order), so that
1960 * other windows with the same parent window appear below @window.
1961 * This is true whether or not the windows are visible.
1963 * If @window is a toplevel, the window manager may choose to deny the
1964 * request to move the window in the Z-order, gdk_window_raise() only
1965 * requests the restack, does not guarantee it.
1969 gdk_window_raise (GdkWindow *window)
1971 g_return_if_fail (GDK_IS_WINDOW (window));
1973 if (!GDK_WINDOW_DESTROYED (window))
1974 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1979 * @window: a #GdkWindow
1981 * Lowers @window to the bottom of the Z-order (stacking order), so that
1982 * other windows with the same parent window appear above @window.
1983 * This is true whether or not the other windows are visible.
1985 * If @window is a toplevel, the window manager may choose to deny the
1986 * request to move the window in the Z-order, gdk_window_lower() only
1987 * requests the restack, does not guarantee it.
1989 * Note that gdk_window_show() raises the window again, so don't call this
1990 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1994 gdk_window_lower (GdkWindow *window)
1996 g_return_if_fail (GDK_IS_WINDOW (window));
1998 if (!GDK_WINDOW_DESTROYED (window))
1999 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
2003 * gdk_x11_window_move_to_current_desktop:
2004 * @window: a #GdkWindow
2006 * Moves the window to the correct workspace when running under a
2007 * window manager that supports multiple workspaces, as described
2008 * in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
2009 * Window Manager Hints</ulink>. Will not do anything if the
2010 * window is already on all workspaces.
2015 gdk_x11_window_move_to_current_desktop (GdkWindow *window)
2017 GdkToplevelX11 *toplevel;
2018 toplevel = _gdk_x11_window_get_toplevel (window);
2020 if (toplevel->on_all_desktops)
2023 move_to_current_desktop (window);
2027 move_to_current_desktop (GdkWindow *window)
2029 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
2030 gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
2038 gulong *current_desktop;
2039 GdkDisplay *display;
2041 display = gdk_drawable_get_display (window);
2043 /* Get current desktop, then set it; this is a race, but not
2044 * one that matters much in practice.
2046 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
2047 GDK_WINDOW_XROOTWIN (window),
2048 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
2050 False, XA_CARDINAL, &type, &format, &nitems,
2051 &bytes_after, &data);
2053 if (type == XA_CARDINAL)
2055 current_desktop = (gulong *)data;
2057 xev.xclient.type = ClientMessage;
2058 xev.xclient.serial = 0;
2059 xev.xclient.send_event = True;
2060 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
2061 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
2062 xev.xclient.format = 32;
2064 xev.xclient.data.l[0] = *current_desktop;
2065 xev.xclient.data.l[1] = 0;
2066 xev.xclient.data.l[2] = 0;
2067 xev.xclient.data.l[3] = 0;
2068 xev.xclient.data.l[4] = 0;
2070 XSendEvent (GDK_DISPLAY_XDISPLAY (display),
2071 GDK_WINDOW_XROOTWIN (window),
2073 SubstructureRedirectMask | SubstructureNotifyMask,
2076 XFree (current_desktop);
2083 * @window: a #GdkWindow
2084 * @timestamp: timestamp of the event triggering the window focus
2086 * Sets keyboard focus to @window. In most cases, gtk_window_present()
2087 * should be used on a #GtkWindow, rather than calling this function.
2091 gdk_window_focus (GdkWindow *window,
2094 GdkDisplay *display;
2096 g_return_if_fail (GDK_IS_WINDOW (window));
2098 if (GDK_WINDOW_DESTROYED (window))
2101 display = GDK_WINDOW_DISPLAY (window);
2103 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
2104 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
2108 xev.xclient.type = ClientMessage;
2109 xev.xclient.serial = 0;
2110 xev.xclient.send_event = True;
2111 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
2112 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
2113 "_NET_ACTIVE_WINDOW");
2114 xev.xclient.format = 32;
2115 xev.xclient.data.l[0] = 1; /* requestor type; we're an app */
2116 xev.xclient.data.l[1] = timestamp;
2117 xev.xclient.data.l[2] = None; /* currently active window */
2118 xev.xclient.data.l[3] = 0;
2119 xev.xclient.data.l[4] = 0;
2121 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
2122 SubstructureRedirectMask | SubstructureNotifyMask,
2127 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
2129 /* There is no way of knowing reliably whether we are viewable;
2130 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
2132 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
2139 * gdk_window_set_hints:
2140 * @window: a #GdkWindow
2141 * @x: ignored field, does not matter
2142 * @y: ignored field, does not matter
2143 * @min_width: minimum width hint
2144 * @min_height: minimum height hint
2145 * @max_width: max width hint
2146 * @max_height: max height hint
2147 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
2149 * This function is broken and useless and you should ignore it.
2150 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
2151 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
2152 * depending on what you're trying to do.
2154 * If using GDK directly, use gdk_window_set_geometry_hints().
2158 gdk_window_set_hints (GdkWindow *window,
2167 XSizeHints size_hints;
2169 g_return_if_fail (GDK_IS_WINDOW (window));
2171 if (GDK_WINDOW_DESTROYED (window))
2174 size_hints.flags = 0;
2176 if (flags & GDK_HINT_POS)
2178 size_hints.flags |= PPosition;
2183 if (flags & GDK_HINT_MIN_SIZE)
2185 size_hints.flags |= PMinSize;
2186 size_hints.min_width = min_width;
2187 size_hints.min_height = min_height;
2190 if (flags & GDK_HINT_MAX_SIZE)
2192 size_hints.flags |= PMaxSize;
2193 size_hints.max_width = max_width;
2194 size_hints.max_height = max_height;
2197 /* FIXME: Would it be better to delete this property if
2198 * flags == 0? It would save space on the server
2200 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2201 GDK_WINDOW_XID (window),
2206 * gdk_window_set_type_hint:
2207 * @window: A toplevel #GdkWindow
2208 * @hint: A hint of the function this window will have
2210 * The application can use this call to provide a hint to the window
2211 * manager about the functionality of a window. The window manager
2212 * can use this information when determining the decoration and behaviour
2215 * The hint must be set before the window is mapped.
2218 gdk_window_set_type_hint (GdkWindow *window,
2219 GdkWindowTypeHint hint)
2221 GdkDisplay *display;
2224 g_return_if_fail (GDK_IS_WINDOW (window));
2226 if (GDK_WINDOW_DESTROYED (window))
2229 display = gdk_drawable_get_display (window);
2233 case GDK_WINDOW_TYPE_HINT_DIALOG:
2234 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
2236 case GDK_WINDOW_TYPE_HINT_MENU:
2237 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
2239 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
2240 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
2242 case GDK_WINDOW_TYPE_HINT_UTILITY:
2243 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
2245 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
2246 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
2248 case GDK_WINDOW_TYPE_HINT_DOCK:
2249 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
2251 case GDK_WINDOW_TYPE_HINT_DESKTOP:
2252 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
2254 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
2255 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
2257 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
2258 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
2260 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
2261 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
2263 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
2264 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
2266 case GDK_WINDOW_TYPE_HINT_COMBO:
2267 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
2269 case GDK_WINDOW_TYPE_HINT_DND:
2270 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
2273 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
2275 case GDK_WINDOW_TYPE_HINT_NORMAL:
2276 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
2280 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2281 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
2282 XA_ATOM, 32, PropModeReplace,
2283 (guchar *)&atom, 1);
2287 * gdk_window_get_type_hint:
2288 * @window: A toplevel #GdkWindow
2290 * This function returns the type hint set for a window.
2292 * Return value: The type hint set for @window
2297 gdk_window_get_type_hint (GdkWindow *window)
2299 GdkDisplay *display;
2300 GdkWindowTypeHint type;
2303 gulong nitems_return;
2304 gulong bytes_after_return;
2305 guchar *data = NULL;
2307 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
2309 if (GDK_WINDOW_DESTROYED (window))
2310 return GDK_WINDOW_TYPE_HINT_NORMAL;
2312 type = GDK_WINDOW_TYPE_HINT_NORMAL;
2314 display = gdk_drawable_get_display (window);
2316 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2317 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
2318 0, G_MAXLONG, False, XA_ATOM, &type_return,
2319 &format_return, &nitems_return, &bytes_after_return,
2322 if ((type_return == XA_ATOM) && (format_return == 32) &&
2323 (data) && (nitems_return == 1))
2325 Atom atom = *(Atom*)data;
2327 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
2328 type = GDK_WINDOW_TYPE_HINT_DIALOG;
2329 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
2330 type = GDK_WINDOW_TYPE_HINT_MENU;
2331 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
2332 type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
2333 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
2334 type = GDK_WINDOW_TYPE_HINT_UTILITY;
2335 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
2336 type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
2337 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
2338 type = GDK_WINDOW_TYPE_HINT_DOCK;
2339 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
2340 type = GDK_WINDOW_TYPE_HINT_DESKTOP;
2341 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
2342 type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
2343 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
2344 type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
2345 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
2346 type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
2347 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
2348 type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
2349 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
2350 type = GDK_WINDOW_TYPE_HINT_COMBO;
2351 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
2352 type = GDK_WINDOW_TYPE_HINT_DND;
2355 if (type_return != None && data != NULL)
2363 gdk_wmspec_change_state (gboolean add,
2368 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
2371 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
2372 #define _NET_WM_STATE_ADD 1 /* add/set property */
2373 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
2375 xev.xclient.type = ClientMessage;
2376 xev.xclient.serial = 0;
2377 xev.xclient.send_event = True;
2378 xev.xclient.window = GDK_WINDOW_XID (window);
2379 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
2380 xev.xclient.format = 32;
2381 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
2382 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
2383 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
2384 xev.xclient.data.l[3] = 0;
2385 xev.xclient.data.l[4] = 0;
2387 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
2388 SubstructureRedirectMask | SubstructureNotifyMask,
2393 * gdk_window_set_modal_hint:
2394 * @window: A toplevel #GdkWindow
2395 * @modal: %TRUE if the window is modal, %FALSE otherwise.
2397 * The application can use this hint to tell the window manager
2398 * that a certain window has modal behaviour. The window manager
2399 * can use this information to handle modal windows in a special
2402 * You should only use this on windows for which you have
2403 * previously called gdk_window_set_transient_for()
2406 gdk_window_set_modal_hint (GdkWindow *window,
2409 GdkWindowObject *private;
2411 g_return_if_fail (GDK_IS_WINDOW (window));
2413 if (GDK_WINDOW_DESTROYED (window))
2416 private = (GdkWindowObject*) window;
2418 private->modal_hint = modal;
2420 if (GDK_WINDOW_IS_MAPPED (window))
2421 gdk_wmspec_change_state (modal, window,
2422 gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
2427 * gdk_window_set_skip_taskbar_hint:
2428 * @window: a toplevel #GdkWindow
2429 * @skips_taskbar: %TRUE to skip the taskbar
2431 * Toggles whether a window should appear in a task list or window
2432 * list. If a window's semantic type as specified with
2433 * gdk_window_set_type_hint() already fully describes the window, this
2434 * function should <emphasis>not</emphasis> be called in addition,
2435 * instead you should allow the window to be treated according to
2436 * standard policy for its semantic type.
2441 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2442 gboolean skips_taskbar)
2444 GdkToplevelX11 *toplevel;
2446 g_return_if_fail (GDK_IS_WINDOW (window));
2447 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2449 if (GDK_WINDOW_DESTROYED (window))
2452 toplevel = _gdk_x11_window_get_toplevel (window);
2453 toplevel->skip_taskbar_hint = skips_taskbar;
2455 if (GDK_WINDOW_IS_MAPPED (window))
2456 gdk_wmspec_change_state (skips_taskbar, window,
2457 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
2462 * gdk_window_set_skip_pager_hint:
2463 * @window: a toplevel #GdkWindow
2464 * @skips_pager: %TRUE to skip the pager
2466 * Toggles whether a window should appear in a pager (workspace
2467 * switcher, or other desktop utility program that displays a small
2468 * thumbnail representation of the windows on the desktop). If a
2469 * window's semantic type as specified with gdk_window_set_type_hint()
2470 * already fully describes the window, this function should
2471 * <emphasis>not</emphasis> be called in addition, instead you should
2472 * allow the window to be treated according to standard policy for
2473 * its semantic type.
2478 gdk_window_set_skip_pager_hint (GdkWindow *window,
2479 gboolean skips_pager)
2481 GdkToplevelX11 *toplevel;
2483 g_return_if_fail (GDK_IS_WINDOW (window));
2484 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2486 if (GDK_WINDOW_DESTROYED (window))
2489 toplevel = _gdk_x11_window_get_toplevel (window);
2490 toplevel->skip_pager_hint = skips_pager;
2492 if (GDK_WINDOW_IS_MAPPED (window))
2493 gdk_wmspec_change_state (skips_pager, window,
2494 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
2499 * gdk_window_set_urgency_hint:
2500 * @window: a toplevel #GdkWindow
2501 * @urgent: %TRUE if the window is urgent
2503 * Toggles whether a window needs the user's
2509 gdk_window_set_urgency_hint (GdkWindow *window,
2512 GdkToplevelX11 *toplevel;
2514 g_return_if_fail (GDK_IS_WINDOW (window));
2515 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2517 if (GDK_WINDOW_DESTROYED (window))
2520 toplevel = _gdk_x11_window_get_toplevel (window);
2521 toplevel->urgency_hint = urgent;
2523 update_wm_hints (window, FALSE);
2527 * gdk_window_set_geometry_hints:
2528 * @window: a toplevel #GdkWindow
2529 * @geometry: geometry hints
2530 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
2532 * Sets the geometry hints for @window. Hints flagged in @geom_mask
2533 * are set, hints not flagged in @geom_mask are unset.
2534 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
2536 * This function provides hints to the windowing system about
2537 * acceptable sizes for a toplevel window. The purpose of
2538 * this is to constrain user resizing, but the windowing system
2539 * will typically (but is not required to) also constrain the
2540 * current size of the window to the provided values and
2541 * constrain programatic resizing via gdk_window_resize() or
2542 * gdk_window_move_resize().
2544 * Note that on X11, this effect has no effect on windows
2545 * of type %GDK_WINDOW_TEMP or windows where override redirect
2546 * has been turned on via gdk_window_set_override_redirect()
2547 * since these windows are not resizable by the user.
2549 * Since you can't count on the windowing system doing the
2550 * constraints for programmatic resizes, you should generally
2551 * call gdk_window_constrain_size() yourself to determine
2552 * appropriate sizes.
2556 gdk_window_set_geometry_hints (GdkWindow *window,
2557 GdkGeometry *geometry,
2558 GdkWindowHints geom_mask)
2560 XSizeHints size_hints;
2562 g_return_if_fail (GDK_IS_WINDOW (window));
2564 if (GDK_WINDOW_DESTROYED (window))
2567 size_hints.flags = 0;
2569 if (geom_mask & GDK_HINT_POS)
2571 size_hints.flags |= PPosition;
2572 /* We need to initialize the following obsolete fields because KWM
2573 * apparently uses these fields if they are non-zero.
2580 if (geom_mask & GDK_HINT_USER_POS)
2582 size_hints.flags |= USPosition;
2585 if (geom_mask & GDK_HINT_USER_SIZE)
2587 size_hints.flags |= USSize;
2590 if (geom_mask & GDK_HINT_MIN_SIZE)
2592 size_hints.flags |= PMinSize;
2593 size_hints.min_width = geometry->min_width;
2594 size_hints.min_height = geometry->min_height;
2597 if (geom_mask & GDK_HINT_MAX_SIZE)
2599 size_hints.flags |= PMaxSize;
2600 size_hints.max_width = MAX (geometry->max_width, 1);
2601 size_hints.max_height = MAX (geometry->max_height, 1);
2604 if (geom_mask & GDK_HINT_BASE_SIZE)
2606 size_hints.flags |= PBaseSize;
2607 size_hints.base_width = geometry->base_width;
2608 size_hints.base_height = geometry->base_height;
2611 if (geom_mask & GDK_HINT_RESIZE_INC)
2613 size_hints.flags |= PResizeInc;
2614 size_hints.width_inc = geometry->width_inc;
2615 size_hints.height_inc = geometry->height_inc;
2618 if (geom_mask & GDK_HINT_ASPECT)
2620 size_hints.flags |= PAspect;
2621 if (geometry->min_aspect <= 1)
2623 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2624 size_hints.min_aspect.y = 65536;
2628 size_hints.min_aspect.x = 65536;
2629 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2631 if (geometry->max_aspect <= 1)
2633 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2634 size_hints.max_aspect.y = 65536;
2638 size_hints.max_aspect.x = 65536;
2639 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2643 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2645 size_hints.flags |= PWinGravity;
2646 size_hints.win_gravity = geometry->win_gravity;
2649 /* FIXME: Would it be better to delete this property if
2650 * geom_mask == 0? It would save space on the server
2652 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2653 GDK_WINDOW_XID (window),
2658 gdk_window_get_geometry_hints (GdkWindow *window,
2659 GdkGeometry *geometry,
2660 GdkWindowHints *geom_mask)
2662 XSizeHints size_hints;
2663 glong junk_size_mask = 0;
2665 g_return_if_fail (GDK_IS_WINDOW (window));
2666 g_return_if_fail (geometry != NULL);
2667 g_return_if_fail (geom_mask != NULL);
2671 if (GDK_WINDOW_DESTROYED (window))
2674 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2675 GDK_WINDOW_XID (window),
2680 if (size_hints.flags & PMinSize)
2682 *geom_mask |= GDK_HINT_MIN_SIZE;
2683 geometry->min_width = size_hints.min_width;
2684 geometry->min_height = size_hints.min_height;
2687 if (size_hints.flags & PMaxSize)
2689 *geom_mask |= GDK_HINT_MAX_SIZE;
2690 geometry->max_width = MAX (size_hints.max_width, 1);
2691 geometry->max_height = MAX (size_hints.max_height, 1);
2694 if (size_hints.flags & PResizeInc)
2696 *geom_mask |= GDK_HINT_RESIZE_INC;
2697 geometry->width_inc = size_hints.width_inc;
2698 geometry->height_inc = size_hints.height_inc;
2701 if (size_hints.flags & PAspect)
2703 *geom_mask |= GDK_HINT_ASPECT;
2705 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
2706 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
2709 if (size_hints.flags & PWinGravity)
2711 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2712 geometry->win_gravity = size_hints.win_gravity;
2717 utf8_is_latin1 (const gchar *str)
2719 const char *p = str;
2723 gunichar ch = g_utf8_get_char (p);
2728 p = g_utf8_next_char (p);
2734 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2735 * convertable to STRING, otherwise, set it as compound text
2738 set_text_property (GdkDisplay *display,
2741 const gchar *utf8_str)
2743 gchar *prop_text = NULL;
2747 gboolean is_compound_text;
2749 if (utf8_is_latin1 (utf8_str))
2751 prop_type = XA_STRING;
2752 prop_text = gdk_utf8_to_string_target (utf8_str);
2753 prop_length = prop_text ? strlen (prop_text) : 0;
2755 is_compound_text = FALSE;
2761 gdk_utf8_to_compound_text_for_display (display,
2762 utf8_str, &gdk_type, &prop_format,
2763 (guchar **)&prop_text, &prop_length);
2764 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2765 is_compound_text = TRUE;
2770 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2773 prop_type, prop_format,
2774 PropModeReplace, (guchar *)prop_text,
2777 if (is_compound_text)
2778 gdk_free_compound_text ((guchar *)prop_text);
2784 /* Set WM_NAME and _NET_WM_NAME
2787 set_wm_name (GdkDisplay *display,
2791 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2792 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2793 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2794 PropModeReplace, (guchar *)name, strlen (name));
2796 set_text_property (display, xwindow,
2797 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2802 * gdk_window_set_title:
2803 * @window: a toplevel #GdkWindow
2804 * @title: title of @window
2806 * Sets the title of a toplevel window, to be displayed in the titlebar.
2807 * If you haven't explicitly set the icon name for the window
2808 * (using gdk_window_set_icon_name()), the icon name will be set to
2809 * @title as well. @title must be in UTF-8 encoding (as with all
2810 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2813 gdk_window_set_title (GdkWindow *window,
2816 GdkDisplay *display;
2820 g_return_if_fail (GDK_IS_WINDOW (window));
2821 g_return_if_fail (title != NULL);
2823 if (GDK_WINDOW_DESTROYED (window))
2826 display = gdk_drawable_get_display (window);
2827 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2828 xwindow = GDK_WINDOW_XID (window);
2830 set_wm_name (display, xwindow, title);
2832 if (!gdk_window_icon_name_set (window))
2834 XChangeProperty (xdisplay, xwindow,
2835 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2836 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2837 PropModeReplace, (guchar *)title, strlen (title));
2839 set_text_property (display, xwindow,
2840 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2846 * gdk_window_set_role:
2847 * @window: a toplevel #GdkWindow
2848 * @role: a string indicating its role
2850 * When using GTK+, typically you should use gtk_window_set_role() instead
2851 * of this low-level function.
2853 * The window manager and session manager use a window's role to
2854 * distinguish it from other kinds of window in the same application.
2855 * When an application is restarted after being saved in a previous
2856 * session, all windows with the same title and role are treated as
2857 * interchangeable. So if you have two windows with the same title
2858 * that should be distinguished for session management purposes, you
2859 * should set the role on those windows. It doesn't matter what string
2860 * you use for the role, as long as you have a different role for each
2861 * non-interchangeable kind of window.
2865 gdk_window_set_role (GdkWindow *window,
2868 GdkDisplay *display;
2870 g_return_if_fail (GDK_IS_WINDOW (window));
2872 display = gdk_drawable_get_display (window);
2874 if (!GDK_WINDOW_DESTROYED (window))
2877 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2878 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2879 XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
2881 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2882 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2887 * gdk_window_set_transient_for:
2888 * @window: a toplevel #GdkWindow
2889 * @parent: another toplevel #GdkWindow
2891 * Indicates to the window manager that @window is a transient dialog
2892 * associated with the application window @parent. This allows the
2893 * window manager to do things like center @window on @parent and
2894 * keep @window above @parent.
2896 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2901 gdk_window_set_transient_for (GdkWindow *window,
2904 g_return_if_fail (GDK_IS_WINDOW (window));
2906 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2907 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2908 GDK_WINDOW_XID (window),
2909 GDK_WINDOW_XID (parent));
2913 * gdk_window_set_background:
2914 * @window: a #GdkWindow
2915 * @color: an allocated #GdkColor
2917 * Sets the background color of @window. (However, when using GTK+,
2918 * set the background of a widget with gtk_widget_modify_bg() - if
2919 * you're an application - or gtk_style_set_background() - if you're
2920 * implementing a custom widget.)
2922 * The @color must be allocated; gdk_rgb_find_color() is the best way
2923 * to allocate a color.
2925 * See also gdk_window_set_back_pixmap().
2929 gdk_window_set_background (GdkWindow *window,
2930 const GdkColor *color)
2932 GdkWindowObject *private = (GdkWindowObject *)window;
2933 GdkColormap *colormap = gdk_drawable_get_colormap (window);
2935 g_return_if_fail (GDK_IS_WINDOW (window));
2937 if (!GDK_WINDOW_DESTROYED (window))
2938 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2939 GDK_WINDOW_XID (window), color->pixel);
2941 private->bg_color = *color;
2942 gdk_colormap_query_color (colormap, private->bg_color.pixel, &private->bg_color);
2944 if (private->bg_pixmap &&
2945 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2946 private->bg_pixmap != GDK_NO_BG)
2947 g_object_unref (private->bg_pixmap);
2949 private->bg_pixmap = NULL;
2953 * gdk_window_set_back_pixmap:
2954 * @window: a #GdkWindow
2955 * @pixmap: a #GdkPixmap, or %NULL
2956 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2958 * Sets the background pixmap of @window. May also be used to set a background of
2959 * "None" on @window, by setting a background pixmap of %NULL.
2960 * A background pixmap will be tiled, positioning the first tile at the origin of
2961 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2962 * origin of the parent window (useful to align tiles in a parent with tiles
2965 * A background pixmap of %NULL means that the window will have no
2966 * background. A window with no background will never have its
2967 * background filled by the windowing system, instead the window will
2968 * contain whatever pixels were already in the corresponding area of
2971 * The windowing system will normally fill a window with its background
2972 * when the window is obscured then exposed, and when you call
2973 * gdk_window_clear().
2977 gdk_window_set_back_pixmap (GdkWindow *window,
2979 gboolean parent_relative)
2981 GdkWindowObject *private = (GdkWindowObject *)window;
2984 g_return_if_fail (GDK_IS_WINDOW (window));
2985 g_return_if_fail (pixmap == NULL || !parent_relative);
2986 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2988 if (pixmap && !gdk_drawable_get_colormap (pixmap))
2990 g_warning ("gdk_window_set_back_pixmap(): pixmap must have a colormap");
2994 if (private->bg_pixmap &&
2995 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2996 private->bg_pixmap != GDK_NO_BG)
2997 g_object_unref (private->bg_pixmap);
2999 if (parent_relative)
3001 xpixmap = ParentRelative;
3002 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
3008 g_object_ref (pixmap);
3009 private->bg_pixmap = pixmap;
3010 xpixmap = GDK_PIXMAP_XID (pixmap);
3015 private->bg_pixmap = GDK_NO_BG;
3019 if (!GDK_WINDOW_DESTROYED (window))
3020 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
3021 GDK_WINDOW_XID (window), xpixmap);
3025 * gdk_window_set_cursor:
3026 * @window: a #GdkWindow
3029 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
3030 * gdk_cursor_new_from_pixmap() to create the cursor.
3031 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
3032 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
3033 * to gdk_window_set_cursor() means that @window will use the cursor of
3034 * its parent window. Most windows should use this default.
3038 gdk_window_set_cursor (GdkWindow *window,
3041 GdkWindowObject *private;
3042 GdkWindowImplX11 *impl;
3043 GdkCursorPrivate *cursor_private;
3046 g_return_if_fail (GDK_IS_WINDOW (window));
3048 private = (GdkWindowObject *)window;
3049 impl = GDK_WINDOW_IMPL_X11 (private->impl);
3050 cursor_private = (GdkCursorPrivate*) cursor;
3054 gdk_cursor_unref (impl->cursor);
3055 impl->cursor = NULL;
3062 _gdk_x11_cursor_update_theme (cursor);
3063 xcursor = cursor_private->xcursor;
3066 if (!GDK_WINDOW_DESTROYED (window))
3068 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
3069 GDK_WINDOW_XID (window),
3073 impl->cursor = gdk_cursor_ref (cursor);
3078 _gdk_x11_window_get_cursor (GdkWindow *window)
3080 GdkWindowObject *private;
3081 GdkWindowImplX11 *impl;
3083 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3085 private = (GdkWindowObject *)window;
3086 impl = GDK_WINDOW_IMPL_X11 (private->impl);
3088 return impl->cursor;
3092 * gdk_window_get_geometry:
3093 * @window: a #GdkWindow
3094 * @x: return location for X coordinate of window (relative to its parent)
3095 * @y: return location for Y coordinate of window (relative to its parent)
3096 * @width: return location for width of window
3097 * @height: return location for height of window
3098 * @depth: return location for bit depth of window
3100 * Any of the return location arguments to this function may be %NULL,
3101 * if you aren't interested in getting the value of that field.
3103 * The X and Y coordinates returned are relative to the parent window
3104 * of @window, which for toplevels usually means relative to the
3105 * window decorations (titlebar, etc.) rather than relative to the
3106 * root window (screen-size background window).
3108 * On the X11 platform, the geometry is obtained from the X server,
3109 * so reflects the latest position of @window; this may be out-of-sync
3110 * with the position of @window delivered in the most-recently-processed
3111 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
3112 * position from the most recent configure event.
3115 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
3116 * to call gdk_window_get_position() and gdk_drawable_get_size() instead,
3117 * because it avoids the roundtrip to the X server and because
3118 * gdk_drawable_get_size() supports the full 32-bit coordinate space,
3119 * whereas gdk_window_get_geometry() is restricted to the 16-bit
3120 * coordinates of X11.
3124 gdk_window_get_geometry (GdkWindow *window,
3136 guint tborder_width;
3139 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
3143 GDK_NOTE (MULTIHEAD,
3144 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
3145 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
3148 if (!GDK_WINDOW_DESTROYED (window))
3150 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
3151 GDK_WINDOW_XID (window),
3152 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
3168 * gdk_window_get_origin:
3169 * @window: a #GdkWindow
3170 * @x: return location for X coordinate
3171 * @y: return location for Y coordinate
3173 * Obtains the position of a window in root window coordinates.
3174 * (Compare with gdk_window_get_position() and
3175 * gdk_window_get_geometry() which return the position of a window
3176 * relative to its parent window.)
3178 * Return value: not meaningful, ignore
3181 gdk_window_get_origin (GdkWindow *window,
3190 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
3192 if (!GDK_WINDOW_DESTROYED (window))
3194 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
3195 GDK_WINDOW_XID (window),
3196 GDK_WINDOW_XROOTWIN (window),
3212 * gdk_window_get_deskrelative_origin:
3213 * @window: a toplevel #GdkWindow
3214 * @x: return location for X coordinate
3215 * @y: return location for Y coordinate
3217 * This gets the origin of a #GdkWindow relative to
3218 * an Enlightenment-window-manager desktop. As long as you don't
3219 * assume that the user's desktop/workspace covers the entire
3220 * root window (i.e. you don't assume that the desktop begins
3221 * at root window coordinate 0,0) this function is not necessary.
3222 * It's deprecated for that reason.
3224 * Return value: not meaningful
3227 gdk_window_get_deskrelative_origin (GdkWindow *window,
3231 gboolean return_val = FALSE;
3232 gint num_children, format_return;
3233 Window win, *child, parent, root;
3238 gulong number_return, bytes_after_return;
3239 guchar *data_return;
3241 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3243 if (!GDK_WINDOW_DESTROYED (window))
3245 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3246 "ENLIGHTENMENT_DESKTOP");
3247 win = GDK_WINDOW_XID (window);
3249 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
3250 &child, (unsigned int *)&num_children))
3252 if ((child) && (num_children > 0))
3264 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
3265 False, XA_CARDINAL, &type_return, &format_return,
3266 &number_return, &bytes_after_return, &data_return);
3268 if (type_return == XA_CARDINAL)
3270 XFree (data_return);
3275 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
3276 GDK_WINDOW_XID (window),
3291 * gdk_window_get_root_origin:
3292 * @window: a toplevel #GdkWindow
3293 * @x: return location for X position of window frame
3294 * @y: return location for Y position of window frame
3296 * Obtains the top-left corner of the window manager frame in root
3297 * window coordinates.
3301 gdk_window_get_root_origin (GdkWindow *window,
3307 g_return_if_fail (GDK_IS_WINDOW (window));
3309 gdk_window_get_frame_extents (window, &rect);
3319 * gdk_window_get_frame_extents:
3320 * @window: a toplevel #GdkWindow
3321 * @rect: rectangle to fill with bounding box of the window frame
3323 * Obtains the bounding box of the window, including window manager
3324 * titlebar/borders if any. The frame position is given in root window
3325 * coordinates. To get the position of the window itself (rather than
3326 * the frame) in root window coordinates, use gdk_window_get_origin().
3330 gdk_window_get_frame_extents (GdkWindow *window,
3333 GdkDisplay *display;
3334 GdkWindowObject *private;
3344 gulong nitems_return;
3345 gulong bytes_after_return;
3348 guint ww, wh, wb, wd;
3351 g_return_if_fail (GDK_IS_WINDOW (window));
3352 g_return_if_fail (rect != NULL);
3354 private = (GdkWindowObject*) window;
3361 if (GDK_WINDOW_DESTROYED (window))
3364 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
3365 private = (GdkWindowObject*) private->parent;
3367 /* Refine our fallback answer a bit using local information */
3368 rect->x = private->x;
3369 rect->y = private->y;
3370 gdk_drawable_get_size ((GdkDrawable *)private, &rect->width, &rect->height);
3372 if (GDK_WINDOW_DESTROYED (private))
3375 gdk_error_trap_push();
3377 /* use NETWM_VIRTUAL_ROOTS if available */
3378 display = gdk_drawable_get_display (window);
3379 root = GDK_WINDOW_XROOTWIN (window);
3384 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
3385 gdk_x11_get_xatom_by_name_for_display (display,
3386 "_NET_VIRTUAL_ROOTS"),
3387 0, G_MAXLONG, False, XA_WINDOW, &type_return,
3388 &format_return, &nitems_return, &bytes_after_return,
3392 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
3394 nvroots = nitems_return;
3395 vroots = (Window *)data;
3399 xparent = GDK_WINDOW_XID (window);
3405 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
3407 &children, &nchildren))
3413 /* check virtual roots */
3414 for (i = 0; i < nvroots; i++)
3416 if (xparent == vroots[i])
3423 while (xparent != root);
3425 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
3426 &root, &wx, &wy, &ww, &wh, &wb, &wd))
3438 gdk_error_trap_pop ();
3442 _gdk_windowing_get_pointer (GdkDisplay *display,
3446 GdkModifierType *mask)
3448 GdkScreen *default_screen;
3458 if (display->closed)
3461 default_screen = gdk_display_get_default_screen (display);
3463 xdisplay = GDK_SCREEN_XDISPLAY (default_screen);
3464 xwindow = GDK_SCREEN_XROOTWIN (default_screen);
3466 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3468 XQueryPointer (xdisplay, xwindow,
3469 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3473 XSetWindowAttributes attributes;
3476 w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0,
3477 CopyFromParent, InputOnly, CopyFromParent,
3479 XQueryPointer (xdisplay, w,
3480 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3481 XDestroyWindow (xdisplay, w);
3486 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
3487 *screen = gdk_drawable_get_screen (gdk_root);
3496 _gdk_windowing_window_get_pointer (GdkDisplay *display,
3500 GdkModifierType *mask)
3502 GdkWindow *return_val;
3508 unsigned int xmask = 0;
3509 gint xoffset, yoffset;
3511 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
3513 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3516 if (!GDK_WINDOW_DESTROYED (window))
3518 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3520 if (XQueryPointer (GDK_WINDOW_XDISPLAY (window),
3521 GDK_WINDOW_XID (window),
3522 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
3525 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
3531 int originx, originy;
3532 _gdk_windowing_get_pointer (gdk_drawable_get_display (window), &screen,
3533 &rootx, &rooty, &xmask);
3534 gdk_window_get_origin (window, &originx, &originy);
3535 winx = rootx - originx;
3536 winy = rooty - originy;
3540 *x = winx + xoffset;
3541 *y = winy + yoffset;
3548 * gdk_display_warp_pointer:
3549 * @display: a #GdkDisplay
3550 * @screen: the screen of @display to warp the pointer to
3551 * @x: the x coordinate of the destination
3552 * @y: the y coordinate of the destination
3554 * Warps the pointer of @display to the point @x,@y on
3555 * the screen @screen, unless the pointer is confined
3556 * to a window by a grab, in which case it will be moved
3557 * as far as allowed by the grab. Warping the pointer
3558 * creates events as if the user had moved the mouse
3559 * instantaneously to the destination.
3561 * Note that the pointer should normally be under the
3562 * control of the user. This function was added to cover
3563 * some rare use cases like keyboard navigation support
3564 * for the color picker in the #GtkColorSelectionDialog.
3569 gdk_display_warp_pointer (GdkDisplay *display,
3577 xdisplay = GDK_DISPLAY_XDISPLAY (display);
3578 dest = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen));
3580 XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0, x, y);
3584 _gdk_windowing_window_at_pointer (GdkDisplay *display,
3593 Window xwindow_last = 0;
3595 int rootx = -1, rooty = -1;
3599 screen = gdk_display_get_default_screen (display);
3601 xwindow = GDK_SCREEN_XROOTWIN (screen);
3602 xdisplay = GDK_SCREEN_XDISPLAY (screen);
3604 /* This function really only works if the mouse pointer is held still
3605 * during its operation. If it moves from one leaf window to another
3606 * than we'll end up with inaccurate values for win_x, win_y
3609 gdk_x11_display_grab (display);
3610 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3612 XQueryPointer (xdisplay, xwindow,
3613 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3614 if (root == xwindow)
3621 xwindow_last = xwindow;
3622 XQueryPointer (xdisplay, xwindow,
3623 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3628 gint i, screens, width, height;
3629 GList *toplevels, *list;
3630 Window pointer_window;
3632 pointer_window = None;
3633 screens = gdk_display_get_n_screens (display);
3634 for (i = 0; i < screens; ++i) {
3635 screen = gdk_display_get_screen (display, i);
3636 toplevels = gdk_screen_get_toplevel_windows (screen);
3637 for (list = toplevels; list != NULL; list = g_list_next (list)) {
3638 window = GDK_WINDOW (list->data);
3639 xwindow = GDK_WINDOW_XWINDOW (window);
3640 gdk_error_trap_push ();
3641 XQueryPointer (xdisplay, xwindow,
3642 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3644 if (gdk_error_trap_pop ())
3648 pointer_window = child;
3651 gdk_window_get_geometry (window, NULL, NULL, &width, &height, NULL);
3652 if (winx >= 0 && winy >= 0 && winx < width && winy < height)
3654 /* A childless toplevel, or below another window? */
3655 XSetWindowAttributes attributes;
3658 w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0,
3659 CopyFromParent, InputOnly, CopyFromParent,
3661 XMapWindow (xdisplay, w);
3662 XQueryPointer (xdisplay, xwindow,
3663 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3664 XDestroyWindow (xdisplay, w);
3667 pointer_window = xwindow;
3672 g_list_free (toplevels);
3673 if (pointer_window != None)
3676 xwindow = pointer_window;
3680 xwindow_last = xwindow;
3681 gdk_error_trap_push ();
3682 XQueryPointer (xdisplay, xwindow,
3683 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3685 if (gdk_error_trap_pop ())
3690 gdk_x11_display_ungrab (display);
3692 window = gdk_window_lookup_for_display (display, xwindow_last);
3693 *win_x = window ? winx : -1;
3694 *win_y = window ? winy : -1;
3700 * gdk_window_get_events:
3701 * @window: a #GdkWindow
3703 * Gets the event mask for @window. See gdk_window_set_events().
3705 * Return value: event mask for @window
3708 gdk_window_get_events (GdkWindow *window)
3710 XWindowAttributes attrs;
3711 GdkEventMask event_mask;
3713 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
3715 if (GDK_WINDOW_DESTROYED (window))
3719 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3720 GDK_WINDOW_XID (window),
3723 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
3724 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
3731 * gdk_window_set_events:
3732 * @window: a #GdkWindow
3733 * @event_mask: event mask for @window
3735 * The event mask for a window determines which events will be reported
3736 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
3737 * means the window should report button press events. The event mask
3738 * is the bitwise OR of values from the #GdkEventMask enumeration.
3742 gdk_window_set_events (GdkWindow *window,
3743 GdkEventMask event_mask)
3748 g_return_if_fail (GDK_IS_WINDOW (window));
3750 if (!GDK_WINDOW_DESTROYED (window))
3752 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
3753 xevent_mask = StructureNotifyMask | PropertyChangeMask;
3754 for (i = 0; i < _gdk_nenvent_masks; i++)
3756 if (event_mask & (1 << (i + 1)))
3757 xevent_mask |= _gdk_event_mask_table[i];
3760 XSelectInput (GDK_WINDOW_XDISPLAY (window),
3761 GDK_WINDOW_XID (window),
3767 gdk_window_add_colormap_windows (GdkWindow *window)
3769 GdkWindow *toplevel;
3770 Window *old_windows;
3771 Window *new_windows;
3774 g_return_if_fail (GDK_IS_WINDOW (window));
3776 if (GDK_WINDOW_DESTROYED (window))
3778 toplevel = gdk_window_get_toplevel (window);
3781 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3782 GDK_WINDOW_XID (toplevel),
3783 &old_windows, &count))
3788 for (i = 0; i < count; i++)
3789 if (old_windows[i] == GDK_WINDOW_XID (window))
3791 XFree (old_windows);
3795 new_windows = g_new (Window, count + 1);
3797 for (i = 0; i < count; i++)
3798 new_windows[i] = old_windows[i];
3799 new_windows[count] = GDK_WINDOW_XID (window);
3801 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3802 GDK_WINDOW_XID (toplevel),
3803 new_windows, count + 1);
3805 g_free (new_windows);
3807 XFree (old_windows);
3810 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
3813 * This needs the X11 shape extension.
3814 * If not available, shaped windows will look
3815 * ugly, but programs still work. Stefan Wille
3818 do_shape_combine_mask (GdkWindow *window,
3824 GdkWindowObject *private = (GdkWindowObject *)window;
3826 gint xoffset, yoffset;
3828 g_return_if_fail (GDK_IS_WINDOW (window));
3830 #ifdef HAVE_SHAPE_EXT
3831 if (GDK_WINDOW_DESTROYED (window))
3834 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3836 if (xoffset != 0 || yoffset != 0)
3838 WARN_SHAPE_TOO_BIG ();
3842 if (shape == ShapeBounding
3843 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3844 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3848 pixmap = GDK_PIXMAP_XID (mask);
3850 private->shaped = (shape == ShapeBounding);
3858 private->shaped = FALSE;
3861 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3862 GDK_WINDOW_XID (window),
3868 #endif /* HAVE_SHAPE_EXT */
3872 * gdk_window_shape_combine_mask:
3873 * @window: a #GdkWindow
3875 * @x: X position of shape mask with respect to @window
3876 * @y: Y position of shape mask with respect to @window
3878 * Applies a shape mask to @window. Pixels in @window corresponding to
3879 * set bits in the @mask will be visible; pixels in @window
3880 * corresponding to unset bits in the @mask will be transparent. This
3881 * gives a non-rectangular window.
3883 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
3884 * parameters are not used.
3886 * On the X11 platform, this uses an X server extension which is
3887 * widely available on most common platforms, but not available on
3888 * very old X servers, and occasionally the implementation will be
3889 * buggy. On servers without the shape extension, this function
3892 * This function works on both toplevel and child windows.
3896 gdk_window_shape_combine_mask (GdkWindow *window,
3901 do_shape_combine_mask (window, mask, x, y, ShapeBounding);
3905 * gdk_window_input_shape_combine_mask:
3906 * @window: a #GdkWindow
3908 * @x: X position of shape mask with respect to @window
3909 * @y: Y position of shape mask with respect to @window
3911 * Like gdk_window_shape_combine_mask(), but the shape applies
3912 * only to event handling. Mouse events which happen while
3913 * the pointer position corresponds to an unset bit in the
3914 * mask will be passed on the window below @window.
3916 * An input shape is typically used with RGBA windows.
3917 * The alpha channel of the window defines which pixels are
3918 * invisible and allows for nicely antialiased borders,
3919 * and the input shape controls where the window is
3922 * On the X11 platform, this requires version 1.1 of the
3928 gdk_window_input_shape_combine_mask (GdkWindow *window,
3934 do_shape_combine_mask (window, mask, x, y, ShapeInput);
3940 do_shape_combine_region (GdkWindow *window,
3941 GdkRegion *shape_region,
3946 GdkWindowObject *private = (GdkWindowObject *)window;
3947 gint xoffset, yoffset;
3949 g_return_if_fail (GDK_IS_WINDOW (window));
3951 #ifdef HAVE_SHAPE_EXT
3952 if (GDK_WINDOW_DESTROYED (window))
3955 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3957 if (xoffset != 0 || yoffset != 0)
3959 WARN_SHAPE_TOO_BIG ();
3963 if (shape_region == NULL)
3965 /* Use NULL mask to unset the shape */
3966 gdk_window_shape_combine_mask (window, NULL, 0, 0);
3970 if (shape == ShapeBounding
3971 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3972 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3975 XRectangle *xrects = NULL;
3977 private->shaped = shape == ShapeBounding;
3979 _gdk_region_get_xrectangles (shape_region,
3983 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3984 GDK_WINDOW_XID (window),
3993 #endif /* HAVE_SHAPE_EXT */
3997 * gdk_window_shape_combine_region:
3998 * @window: a #GdkWindow
3999 * @shape_region: region of window to be non-transparent
4000 * @offset_x: X position of @shape_region in @window coordinates
4001 * @offset_y: Y position of @shape_region in @window coordinates
4003 * Makes pixels in @window outside @shape_region be transparent,
4004 * so that the window may be nonrectangular. See also
4005 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
4007 * If @shape_region is %NULL, the shape will be unset, so the whole
4008 * window will be opaque again. @offset_x and @offset_y are ignored
4009 * if @shape_region is %NULL.
4011 * On the X11 platform, this uses an X server extension which is
4012 * widely available on most common platforms, but not available on
4013 * very old X servers, and occasionally the implementation will be
4014 * buggy. On servers without the shape extension, this function
4017 * This function works on both toplevel and child windows.
4021 gdk_window_shape_combine_region (GdkWindow *window,
4022 GdkRegion *shape_region,
4026 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
4030 * gdk_window_input_shape_combine_region:
4031 * @window: a #GdkWindow
4032 * @shape_region: region of window to be non-transparent
4033 * @offset_x: X position of @shape_region in @window coordinates
4034 * @offset_y: Y position of @shape_region in @window coordinates
4036 * Like gdk_window_shape_combine_region(), but the shape applies
4037 * only to event handling. Mouse events which happen while
4038 * the pointer position corresponds to an unset bit in the
4039 * mask will be passed on the window below @window.
4041 * An input shape is typically used with RGBA windows.
4042 * The alpha channel of the window defines which pixels are
4043 * invisible and allows for nicely antialiased borders,
4044 * and the input shape controls where the window is
4047 * On the X11 platform, this requires version 1.1 of the
4053 gdk_window_input_shape_combine_region (GdkWindow *window,
4054 GdkRegion *shape_region,
4059 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
4065 * gdk_window_set_override_redirect:
4066 * @window: a toplevel #GdkWindow
4067 * @override_redirect: %TRUE if window should be override redirect
4069 * An override redirect window is not under the control of the window manager.
4070 * This means it won't have a titlebar, won't be minimizable, etc. - it will
4071 * be entirely under the control of the application. The window manager
4072 * can't see the override redirect window at all.
4074 * Override redirect should only be used for short-lived temporary
4075 * windows, such as popup menus. #GtkMenu uses an override redirect
4076 * window in its implementation, for example.
4080 gdk_window_set_override_redirect (GdkWindow *window,
4081 gboolean override_redirect)
4083 XSetWindowAttributes attr;
4085 g_return_if_fail (GDK_IS_WINDOW (window));
4087 if (!GDK_WINDOW_DESTROYED (window))
4089 GdkWindowObject *private = (GdkWindowObject *)window;
4090 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
4092 attr.override_redirect = (override_redirect? True : False);
4093 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4094 GDK_WINDOW_XID (window),
4098 impl->override_redirect = attr.override_redirect;
4103 * gdk_window_set_accept_focus:
4104 * @window: a toplevel #GdkWindow
4105 * @accept_focus: %TRUE if the window should receive input focus
4107 * Setting @accept_focus to %FALSE hints the desktop environment that the
4108 * window doesn't want to receive input focus.
4110 * On X, it is the responsibility of the window manager to interpret this
4111 * hint. ICCCM-compliant window manager usually respect it.
4116 gdk_window_set_accept_focus (GdkWindow *window,
4117 gboolean accept_focus)
4119 GdkWindowObject *private;
4121 g_return_if_fail (GDK_IS_WINDOW (window));
4123 private = (GdkWindowObject *)window;
4125 accept_focus = accept_focus != FALSE;
4127 if (private->accept_focus != accept_focus)
4129 private->accept_focus = accept_focus;
4131 if (!GDK_WINDOW_DESTROYED (window))
4132 update_wm_hints (window, FALSE);
4137 * gdk_window_set_focus_on_map:
4138 * @window: a toplevel #GdkWindow
4139 * @focus_on_map: %TRUE if the window should receive input focus when mapped
4141 * Setting @focus_on_map to %FALSE hints the desktop environment that the
4142 * window doesn't want to receive input focus when it is mapped.
4143 * focus_on_map should be turned off for windows that aren't triggered
4144 * interactively (such as popups from network activity).
4146 * On X, it is the responsibility of the window manager to interpret
4147 * this hint. Window managers following the freedesktop.org window
4148 * manager extension specification should respect it.
4153 gdk_window_set_focus_on_map (GdkWindow *window,
4154 gboolean focus_on_map)
4156 GdkWindowObject *private;
4158 g_return_if_fail (GDK_IS_WINDOW (window));
4160 private = (GdkWindowObject *)window;
4162 focus_on_map = focus_on_map != FALSE;
4164 if (private->focus_on_map != focus_on_map)
4166 private->focus_on_map = focus_on_map;
4168 if ((!GDK_WINDOW_DESTROYED (window)) && (!private->focus_on_map))
4169 gdk_x11_window_set_user_time (window, 0);
4174 * gdk_x11_window_set_user_time:
4175 * @window: A toplevel #GdkWindow
4176 * @timestamp: An XServer timestamp to which the property should be set
4178 * The application can use this call to update the _NET_WM_USER_TIME
4179 * property on a toplevel window. This property stores an Xserver
4180 * time which represents the time of the last user input event
4181 * received for this window. This property may be used by the window
4182 * manager to alter the focus, stacking, and/or placement behavior of
4183 * windows when they are mapped depending on whether the new window
4184 * was created by a user action or is a "pop-up" window activated by a
4185 * timer or some other event.
4187 * Note that this property is automatically updated by GDK, so this
4188 * function should only be used by applications which handle input
4189 * events bypassing GDK.
4194 gdk_x11_window_set_user_time (GdkWindow *window,
4197 GdkDisplay *display;
4198 GdkDisplayX11 *display_x11;
4199 GdkToplevelX11 *toplevel;
4200 glong timestamp_long = (glong)timestamp;
4202 g_return_if_fail (GDK_IS_WINDOW (window));
4204 if (GDK_WINDOW_DESTROYED (window))
4207 display = gdk_drawable_get_display (window);
4208 display_x11 = GDK_DISPLAY_X11 (display);
4209 toplevel = _gdk_x11_window_get_toplevel (window);
4211 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4212 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
4213 XA_CARDINAL, 32, PropModeReplace,
4214 (guchar *)×tamp_long, 1);
4216 if (timestamp_long != GDK_CURRENT_TIME)
4217 display_x11->user_time = timestamp_long;
4219 toplevel->user_time = timestamp_long;
4222 #define GDK_SELECTION_MAX_SIZE(display) \
4224 XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
4225 ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
4226 : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
4229 * gdk_window_set_icon_list:
4230 * @window: The #GdkWindow toplevel window to set the icon of.
4231 * @pixbufs: A list of pixbufs, of different sizes.
4233 * Sets a list of icons for the window. One of these will be used
4234 * to represent the window when it has been iconified. The icon is
4235 * usually shown in an icon box or some sort of task bar. Which icon
4236 * size is shown depends on the window manager. The window manager
4237 * can scale the icon but setting several size icons can give better
4238 * image quality since the window manager may only need to scale the
4239 * icon by a small amount or not at all.
4243 gdk_window_set_icon_list (GdkWindow *window,
4252 gint width, height, stride;
4255 GdkDisplay *display;
4258 g_return_if_fail (GDK_IS_WINDOW (window));
4260 if (GDK_WINDOW_DESTROYED (window))
4263 display = gdk_drawable_get_display (window);
4271 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
4273 width = gdk_pixbuf_get_width (pixbuf);
4274 height = gdk_pixbuf_get_height (pixbuf);
4276 /* silently ignore overlarge icons */
4277 if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
4279 g_warning ("gdk_window_set_icon_list: icons too large");
4284 size += 2 + width * height;
4286 l = g_list_next (l);
4289 data = g_malloc (size * sizeof (gulong));
4297 width = gdk_pixbuf_get_width (pixbuf);
4298 height = gdk_pixbuf_get_height (pixbuf);
4299 stride = gdk_pixbuf_get_rowstride (pixbuf);
4300 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
4305 pixels = gdk_pixbuf_get_pixels (pixbuf);
4307 for (y = 0; y < height; y++)
4309 for (x = 0; x < width; x++)
4313 r = pixels[y*stride + x*n_channels + 0];
4314 g = pixels[y*stride + x*n_channels + 1];
4315 b = pixels[y*stride + x*n_channels + 2];
4316 if (n_channels >= 4)
4317 a = pixels[y*stride + x*n_channels + 3];
4321 *p++ = a << 24 | r << 16 | g << 8 | b ;
4325 l = g_list_next (l);
4331 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
4332 GDK_WINDOW_XID (window),
4333 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
4336 (guchar*) data, size);
4340 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
4341 GDK_WINDOW_XID (window),
4342 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
4349 * gdk_window_set_icon:
4350 * @window: a toplevel #GdkWindow
4351 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
4352 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
4353 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
4355 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
4356 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
4357 * and gtk_window_set_icon(). If those don't meet your needs, look at
4358 * gdk_window_set_icon_list(). Only if all those are too high-level do you
4359 * want to fall back to gdk_window_set_icon().
4363 gdk_window_set_icon (GdkWindow *window,
4364 GdkWindow *icon_window,
4368 GdkToplevelX11 *toplevel;
4370 g_return_if_fail (GDK_IS_WINDOW (window));
4371 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4373 if (GDK_WINDOW_DESTROYED (window))
4376 toplevel = _gdk_x11_window_get_toplevel (window);
4378 if (toplevel->icon_window != icon_window)
4380 if (toplevel->icon_window)
4381 g_object_unref (toplevel->icon_window);
4382 toplevel->icon_window = g_object_ref (icon_window);
4385 if (toplevel->icon_pixmap != pixmap)
4388 g_object_ref (pixmap);
4389 if (toplevel->icon_pixmap)
4390 g_object_unref (toplevel->icon_pixmap);
4391 toplevel->icon_pixmap = pixmap;
4394 if (toplevel->icon_mask != mask)
4397 g_object_ref (mask);
4398 if (toplevel->icon_mask)
4399 g_object_unref (toplevel->icon_mask);
4400 toplevel->icon_mask = mask;
4403 update_wm_hints (window, FALSE);
4407 gdk_window_icon_name_set (GdkWindow *window)
4409 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
4410 g_quark_from_static_string ("gdk-icon-name-set")));
4414 * gdk_window_set_icon_name:
4415 * @window: a toplevel #GdkWindow
4416 * @name: name of window while iconified (minimized)
4418 * Windows may have a name used while minimized, distinct from the
4419 * name they display in their titlebar. Most of the time this is a bad
4420 * idea from a user interface standpoint. But you can set such a name
4421 * with this function, if you like.
4425 gdk_window_set_icon_name (GdkWindow *window,
4428 GdkDisplay *display;
4430 g_return_if_fail (GDK_IS_WINDOW (window));
4432 if (GDK_WINDOW_DESTROYED (window))
4435 display = gdk_drawable_get_display (window);
4437 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
4438 GUINT_TO_POINTER (TRUE));
4440 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
4441 GDK_WINDOW_XID (window),
4442 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
4443 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
4444 PropModeReplace, (guchar *)name, strlen (name));
4446 set_text_property (display, GDK_WINDOW_XID (window),
4447 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
4452 * gdk_window_iconify:
4453 * @window: a toplevel #GdkWindow
4455 * Asks to iconify (minimize) @window. The window manager may choose
4456 * to ignore the request, but normally will honor it. Using
4457 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
4459 * This function only makes sense when @window is a toplevel window.
4463 gdk_window_iconify (GdkWindow *window)
4465 g_return_if_fail (GDK_IS_WINDOW (window));
4467 if (GDK_WINDOW_DESTROYED (window))
4470 if (GDK_WINDOW_IS_MAPPED (window))
4472 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
4473 GDK_WINDOW_XWINDOW (window),
4474 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
4478 /* Flip our client side flag, the real work happens on map. */
4479 gdk_synthesize_window_state (window,
4481 GDK_WINDOW_STATE_ICONIFIED);
4486 * gdk_window_deiconify:
4487 * @window: a toplevel #GdkWindow
4489 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
4490 * choose to ignore the request to deiconify. When using GTK+,
4491 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
4492 * you probably want to use gtk_window_present(), which raises the window, focuses it,
4493 * unminimizes it, and puts it on the current desktop.
4497 gdk_window_deiconify (GdkWindow *window)
4499 g_return_if_fail (GDK_IS_WINDOW (window));
4501 if (GDK_WINDOW_DESTROYED (window))
4504 if (GDK_WINDOW_IS_MAPPED (window))
4506 gdk_window_show (window);
4510 /* Flip our client side flag, the real work happens on map. */
4511 gdk_synthesize_window_state (window,
4512 GDK_WINDOW_STATE_ICONIFIED,
4519 * @window: a toplevel #GdkWindow
4521 * "Pins" a window such that it's on all workspaces and does not scroll
4522 * with viewports, for window managers that have scrollable viewports.
4523 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
4525 * On the X11 platform, this function depends on window manager
4526 * support, so may have no effect with many window managers. However,
4527 * GDK will do the best it can to convince the window manager to stick
4528 * the window. For window managers that don't support this operation,
4529 * there's nothing you can do to force it to happen.
4533 gdk_window_stick (GdkWindow *window)
4535 g_return_if_fail (GDK_IS_WINDOW (window));
4537 if (GDK_WINDOW_DESTROYED (window))
4540 if (GDK_WINDOW_IS_MAPPED (window))
4542 /* "stick" means stick to all desktops _and_ do not scroll with the
4543 * viewport. i.e. glue to the monitor glass in all cases.
4548 /* Request stick during viewport scroll */
4549 gdk_wmspec_change_state (TRUE, window,
4550 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4553 /* Request desktop 0xFFFFFFFF */
4554 xev.xclient.type = ClientMessage;
4555 xev.xclient.serial = 0;
4556 xev.xclient.send_event = True;
4557 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
4558 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
4559 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
4561 xev.xclient.format = 32;
4563 xev.xclient.data.l[0] = 0xFFFFFFFF;
4564 xev.xclient.data.l[1] = 0;
4565 xev.xclient.data.l[2] = 0;
4566 xev.xclient.data.l[3] = 0;
4567 xev.xclient.data.l[4] = 0;
4569 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
4570 SubstructureRedirectMask | SubstructureNotifyMask,
4575 /* Flip our client side flag, the real work happens on map. */
4576 gdk_synthesize_window_state (window,
4578 GDK_WINDOW_STATE_STICKY);
4583 * gdk_window_unstick:
4584 * @window: a toplevel #GdkWindow
4586 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
4587 * and gtk_window_unstick().
4591 gdk_window_unstick (GdkWindow *window)
4593 g_return_if_fail (GDK_IS_WINDOW (window));
4595 if (GDK_WINDOW_DESTROYED (window))
4598 if (GDK_WINDOW_IS_MAPPED (window))
4600 /* Request unstick from viewport */
4601 gdk_wmspec_change_state (FALSE, window,
4602 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4605 move_to_current_desktop (window);
4609 /* Flip our client side flag, the real work happens on map. */
4610 gdk_synthesize_window_state (window,
4611 GDK_WINDOW_STATE_STICKY,
4618 * gdk_window_maximize:
4619 * @window: a toplevel #GdkWindow
4621 * Maximizes the window. If the window was already maximized, then
4622 * this function does nothing.
4624 * On X11, asks the window manager to maximize @window, if the window
4625 * manager supports this operation. Not all window managers support
4626 * this, and some deliberately ignore it or don't have a concept of
4627 * "maximized"; so you can't rely on the maximization actually
4628 * happening. But it will happen with most standard window managers,
4629 * and GDK makes a best effort to get it to happen.
4631 * On Windows, reliably maximizes the window.
4635 gdk_window_maximize (GdkWindow *window)
4637 g_return_if_fail (GDK_IS_WINDOW (window));
4639 if (GDK_WINDOW_DESTROYED (window))
4642 if (GDK_WINDOW_IS_MAPPED (window))
4643 gdk_wmspec_change_state (TRUE, window,
4644 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4645 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4647 gdk_synthesize_window_state (window,
4649 GDK_WINDOW_STATE_MAXIMIZED);
4653 * gdk_window_unmaximize:
4654 * @window: a toplevel #GdkWindow
4656 * Unmaximizes the window. If the window wasn't maximized, then this
4657 * function does nothing.
4659 * On X11, asks the window manager to unmaximize @window, if the
4660 * window manager supports this operation. Not all window managers
4661 * support this, and some deliberately ignore it or don't have a
4662 * concept of "maximized"; so you can't rely on the unmaximization
4663 * actually happening. But it will happen with most standard window
4664 * managers, and GDK makes a best effort to get it to happen.
4666 * On Windows, reliably unmaximizes the window.
4670 gdk_window_unmaximize (GdkWindow *window)
4672 g_return_if_fail (GDK_IS_WINDOW (window));
4674 if (GDK_WINDOW_DESTROYED (window))
4677 if (GDK_WINDOW_IS_MAPPED (window))
4678 gdk_wmspec_change_state (FALSE, window,
4679 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4680 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4682 gdk_synthesize_window_state (window,
4683 GDK_WINDOW_STATE_MAXIMIZED,
4688 * gdk_window_fullscreen:
4689 * @window: a toplevel #GdkWindow
4691 * Moves the window into fullscreen mode. This means the
4692 * window covers the entire screen and is above any panels
4695 * If the window was already fullscreen, then this function does nothing.
4697 * On X11, asks the window manager to put @window in a fullscreen
4698 * state, if the window manager supports this operation. Not all
4699 * window managers support this, and some deliberately ignore it or
4700 * don't have a concept of "fullscreen"; so you can't rely on the
4701 * fullscreenification actually happening. But it will happen with
4702 * most standard window managers, and GDK makes a best effort to get
4708 gdk_window_fullscreen (GdkWindow *window)
4710 g_return_if_fail (GDK_IS_WINDOW (window));
4712 if (GDK_WINDOW_DESTROYED (window))
4715 if (GDK_WINDOW_IS_MAPPED (window))
4716 gdk_wmspec_change_state (TRUE, window,
4717 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4721 gdk_synthesize_window_state (window,
4723 GDK_WINDOW_STATE_FULLSCREEN);
4727 * gdk_window_unfullscreen:
4728 * @window: a toplevel #GdkWindow
4730 * Moves the window out of fullscreen mode. If the window was not
4731 * fullscreen, does nothing.
4733 * On X11, asks the window manager to move @window out of the fullscreen
4734 * state, if the window manager supports this operation. Not all
4735 * window managers support this, and some deliberately ignore it or
4736 * don't have a concept of "fullscreen"; so you can't rely on the
4737 * unfullscreenification actually happening. But it will happen with
4738 * most standard window managers, and GDK makes a best effort to get
4744 gdk_window_unfullscreen (GdkWindow *window)
4746 g_return_if_fail (GDK_IS_WINDOW (window));
4748 if (GDK_WINDOW_DESTROYED (window))
4751 if (GDK_WINDOW_IS_MAPPED (window))
4752 gdk_wmspec_change_state (FALSE, window,
4753 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4757 gdk_synthesize_window_state (window,
4758 GDK_WINDOW_STATE_FULLSCREEN,
4763 * gdk_window_set_keep_above:
4764 * @window: a toplevel #GdkWindow
4765 * @setting: whether to keep @window above other windows
4767 * Set if @window must be kept above other windows. If the
4768 * window was already above, then this function does nothing.
4770 * On X11, asks the window manager to keep @window above, if the window
4771 * manager supports this operation. Not all window managers support
4772 * this, and some deliberately ignore it or don't have a concept of
4773 * "keep above"; so you can't rely on the window being kept above.
4774 * But it will happen with most standard window managers,
4775 * and GDK makes a best effort to get it to happen.
4780 gdk_window_set_keep_above (GdkWindow *window, gboolean setting)
4782 g_return_if_fail (GDK_IS_WINDOW (window));
4784 if (GDK_WINDOW_DESTROYED (window))
4787 if (GDK_WINDOW_IS_MAPPED (window))
4790 gdk_wmspec_change_state (FALSE, window,
4791 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4793 gdk_wmspec_change_state (setting, window,
4794 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4798 gdk_synthesize_window_state (window,
4799 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
4800 setting ? GDK_WINDOW_STATE_ABOVE : 0);
4804 * gdk_window_set_keep_below:
4805 * @window: a toplevel #GdkWindow
4806 * @setting: whether to keep @window below other windows
4808 * Set if @window must be kept below other windows. If the
4809 * window was already below, then this function does nothing.
4811 * On X11, asks the window manager to keep @window below, if the window
4812 * manager supports this operation. Not all window managers support
4813 * this, and some deliberately ignore it or don't have a concept of
4814 * "keep below"; so you can't rely on the window being kept below.
4815 * But it will happen with most standard window managers,
4816 * and GDK makes a best effort to get it to happen.
4821 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
4823 g_return_if_fail (GDK_IS_WINDOW (window));
4825 if (GDK_WINDOW_DESTROYED (window))
4828 if (GDK_WINDOW_IS_MAPPED (window))
4831 gdk_wmspec_change_state (FALSE, window,
4832 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4834 gdk_wmspec_change_state (setting, window,
4835 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4839 gdk_synthesize_window_state (window,
4840 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
4841 setting ? GDK_WINDOW_STATE_BELOW : 0);
4845 * gdk_window_get_group:
4846 * @window: a toplevel #GdkWindow
4848 * Returns the group leader window for @window. See gdk_window_set_group().
4850 * Return value: the group leader window for @window
4855 gdk_window_get_group (GdkWindow *window)
4857 GdkToplevelX11 *toplevel;
4859 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4860 g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL);
4862 if (GDK_WINDOW_DESTROYED (window))
4865 toplevel = _gdk_x11_window_get_toplevel (window);
4867 return toplevel->group_leader;
4871 * gdk_window_set_group:
4872 * @window: a toplevel #GdkWindow
4873 * @leader: group leader window, or %NULL to restore the default group leader window
4875 * Sets the group leader window for @window. By default,
4876 * GDK sets the group leader for all toplevel windows
4877 * to a global window implicitly created by GDK. With this function
4878 * you can override this default.
4880 * The group leader window allows the window manager to distinguish
4881 * all windows that belong to a single application. It may for example
4882 * allow users to minimize/unminimize all windows belonging to an
4883 * application at once. You should only set a non-default group window
4884 * if your application pretends to be multiple applications.
4887 gdk_window_set_group (GdkWindow *window,
4890 GdkToplevelX11 *toplevel;
4892 g_return_if_fail (GDK_IS_WINDOW (window));
4893 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4894 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
4896 if (GDK_WINDOW_DESTROYED (window) || (leader != NULL && GDK_WINDOW_DESTROYED (leader)))
4899 toplevel = _gdk_x11_window_get_toplevel (window);
4902 leader = gdk_display_get_default_group (gdk_drawable_get_display (window));
4904 if (toplevel->group_leader != leader)
4906 if (toplevel->group_leader)
4907 g_object_unref (toplevel->group_leader);
4908 toplevel->group_leader = g_object_ref (leader);
4909 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
4912 update_wm_hints (window, FALSE);
4915 static MotifWmHints *
4916 gdk_window_get_mwm_hints (GdkWindow *window)
4918 GdkDisplay *display;
4919 Atom hints_atom = None;
4926 if (GDK_WINDOW_DESTROYED (window))
4929 display = gdk_drawable_get_display (window);
4931 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4933 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4934 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4935 False, AnyPropertyType, &type, &format, &nitems,
4936 &bytes_after, &data);
4941 return (MotifWmHints *)data;
4945 gdk_window_set_mwm_hints (GdkWindow *window,
4946 MotifWmHints *new_hints)
4948 GdkDisplay *display;
4949 Atom hints_atom = None;
4951 MotifWmHints *hints;
4957 if (GDK_WINDOW_DESTROYED (window))
4960 display = gdk_drawable_get_display (window);
4962 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4964 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4965 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4966 False, AnyPropertyType, &type, &format, &nitems,
4967 &bytes_after, &data);
4973 hints = (MotifWmHints *)data;
4975 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4977 hints->flags |= MWM_HINTS_FUNCTIONS;
4978 hints->functions = new_hints->functions;
4980 if (new_hints->flags & MWM_HINTS_DECORATIONS)
4982 hints->flags |= MWM_HINTS_DECORATIONS;
4983 hints->decorations = new_hints->decorations;
4987 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4988 hints_atom, hints_atom, 32, PropModeReplace,
4989 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
4991 if (hints != new_hints)
4996 * gdk_window_set_decorations:
4997 * @window: a toplevel #GdkWindow
4998 * @decorations: decoration hint mask
5000 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
5001 * This function sets the traditional Motif window manager hints that tell the
5002 * window manager which decorations you would like your window to have.
5003 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
5004 * using the GDK function directly.
5006 * The @decorations argument is the logical OR of the fields in
5007 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
5008 * mask, the other bits indicate which decorations should be turned off.
5009 * If #GDK_DECOR_ALL is not included, then the other bits indicate
5010 * which decorations should be turned on.
5012 * Most window managers honor a decorations hint of 0 to disable all decorations,
5013 * but very few honor all possible combinations of bits.
5017 gdk_window_set_decorations (GdkWindow *window,
5018 GdkWMDecoration decorations)
5022 g_return_if_fail (GDK_IS_WINDOW (window));
5024 /* initialize to zero to avoid writing uninitialized data to socket */
5025 memset(&hints, 0, sizeof(hints));
5026 hints.flags = MWM_HINTS_DECORATIONS;
5027 hints.decorations = decorations;
5029 gdk_window_set_mwm_hints (window, &hints);
5033 * gdk_window_get_decorations:
5034 * @window: The toplevel #GdkWindow to get the decorations from
5035 * @decorations: The window decorations will be written here
5037 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
5038 * Returns: TRUE if the window has decorations set, FALSE otherwise.
5041 gdk_window_get_decorations(GdkWindow *window,
5042 GdkWMDecoration *decorations)
5044 MotifWmHints *hints;
5045 gboolean result = FALSE;
5047 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5049 hints = gdk_window_get_mwm_hints (window);
5053 if (hints->flags & MWM_HINTS_DECORATIONS)
5056 *decorations = hints->decorations;
5067 * gdk_window_set_functions:
5068 * @window: a toplevel #GdkWindow
5069 * @functions: bitmask of operations to allow on @window
5071 * Sets hints about the window management functions to make available
5072 * via buttons on the window frame.
5074 * On the X backend, this function sets the traditional Motif window
5075 * manager hint for this purpose. However, few window managers do
5076 * anything reliable or interesting with this hint. Many ignore it
5079 * The @functions argument is the logical OR of values from the
5080 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
5081 * then the other bits indicate which functions to disable; if
5082 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
5087 gdk_window_set_functions (GdkWindow *window,
5088 GdkWMFunction functions)
5092 g_return_if_fail (GDK_IS_WINDOW (window));
5094 /* initialize to zero to avoid writing uninitialized data to socket */
5095 memset(&hints, 0, sizeof(hints));
5096 hints.flags = MWM_HINTS_FUNCTIONS;
5097 hints.functions = functions;
5099 gdk_window_set_mwm_hints (window, &hints);
5102 #ifdef HAVE_SHAPE_EXT
5105 * propagate the shapes from all child windows of a GDK window to the parent
5106 * window. Shamelessly ripped from Enlightenment's code
5114 struct _gdk_span *next;
5118 gdk_add_to_span (struct _gdk_span **s,
5122 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
5129 /* scan the spans for this line */
5132 /* -- -> new span */
5133 /* == -> existing span */
5134 /* ## -> spans intersect */
5135 /* if we are in the middle of spanning the span into the line */
5138 /* case: ---- ==== */
5139 if (xx < ptr1->start - 1)
5141 /* ends before next span - extend to here */
5145 /* case: ----##=== */
5146 else if (xx <= ptr1->end)
5148 /* crosses into next span - delete next span and append */
5149 ss->end = ptr1->end;
5150 ss->next = ptr1->next;
5154 /* case: ---###--- */
5157 /* overlaps next span - delete and keep checking */
5158 ss->next = ptr1->next;
5163 /* otherwise havent started spanning it in yet */
5166 /* case: ---- ==== */
5167 if (xx < ptr1->start - 1)
5169 /* insert span here in list */
5170 noo = g_malloc (sizeof (struct _gdk_span));
5184 /* case: ----##=== */
5185 else if ((x < ptr1->start) && (xx <= ptr1->end))
5187 /* expand this span to the left point of the new one */
5191 /* case: ===###=== */
5192 else if ((x >= ptr1->start) && (xx <= ptr1->end))
5194 /* throw the span away */
5197 /* case: ---###--- */
5198 else if ((x < ptr1->start) && (xx > ptr1->end))
5205 /* case: ===##---- */
5206 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
5212 /* case: ==== ---- */
5213 /* case handled by next loop iteration - first case */
5218 /* it started in the middle but spans beyond your current list */
5224 /* it does not start inside a span or in the middle, so add it to the end */
5225 noo = g_malloc (sizeof (struct _gdk_span));
5233 noo->next = ptr2->next;
5246 gdk_add_rectangles (Display *disp,
5248 struct _gdk_span **spans,
5255 gint x1, y1, x2, y2;
5259 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
5262 /* go through all clip rects in this window's shape */
5263 for (k = 0; k < rn; k++)
5265 /* for each clip rect, add it to each line's spans */
5267 x2 = x + rl[k].x + (rl[k].width - 1);
5269 y2 = y + rl[k].y + (rl[k].height - 1);
5278 for (a = y1; a <= y2; a++)
5281 gdk_add_to_span (&spans[a], x1, x2);
5289 gdk_propagate_shapes (Display *disp,
5294 Window rt, par, *list = NULL;
5295 gint i, j, num = 0, num_rects = 0;
5299 XRectangle *rects = NULL;
5300 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
5301 XWindowAttributes xatt;
5303 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
5308 spans = g_malloc (sizeof (struct _gdk_span *) * h);
5310 for (i = 0; i < h; i++)
5312 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
5315 /* go through all child windows and create/insert spans */
5316 for (i = 0; i < num; i++)
5318 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
5319 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
5320 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
5323 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
5325 /* go through the spans list and build a list of rects */
5326 rects = g_malloc (sizeof (XRectangle) * 256);
5328 for (i = 0; i < baseh; i++)
5331 /* go through the line for all spans */
5334 rects[num_rects].x = ptr1->start;
5335 rects[num_rects].y = i;
5336 rects[num_rects].width = ptr1->end - ptr1->start + 1;
5337 rects[num_rects].height = 1;
5339 /* if there are more lines */
5341 /* while contigous rects (same start/end coords) exist */
5342 while ((contig) && (j < baseh))
5344 /* search next line for spans matching this one */
5350 /* if we have an exact span match set contig */
5351 if ((ptr2->start == ptr1->start) &&
5352 (ptr2->end == ptr1->end))
5355 /* remove the span - not needed */
5358 ptr3->next = ptr2->next;
5364 spans[j] = ptr2->next;
5370 /* gone past the span point no point looking */
5371 else if (ptr2->start < ptr1->start)
5379 /* if a contiguous span was found increase the rect h */
5382 rects[num_rects].height++;
5386 /* up the rect count */
5388 /* every 256 new rects increase the rect array */
5389 if ((num_rects % 256) == 0)
5390 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
5394 /* set the rects as the shape mask */
5397 XShapeCombineRectangles (disp, win, shape, 0, 0, rects, num_rects,
5398 ShapeSet, YXSorted);
5403 /* free up all the spans we made */
5404 for (i = 0; i < baseh; i++)
5417 #endif /* HAVE_SHAPE_EXT */
5420 * gdk_window_set_child_shapes:
5421 * @window: a #GdkWindow
5423 * Sets the shape mask of @window to the union of shape masks
5424 * for all children of @window, ignoring the shape mask of @window
5425 * itself. Contrast with gdk_window_merge_child_shapes() which includes
5426 * the shape mask of @window in the masks to be merged.
5429 gdk_window_set_child_shapes (GdkWindow *window)
5431 g_return_if_fail (GDK_IS_WINDOW (window));
5434 #ifdef HAVE_SHAPE_EXT
5435 if (!GDK_WINDOW_DESTROYED (window) &&
5436 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
5437 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
5438 GDK_WINDOW_XID (window), FALSE, ShapeBounding);
5443 * gdk_window_merge_child_shapes:
5444 * @window: a #GdkWindow
5446 * Merges the shape masks for any child windows into the
5447 * shape mask for @window. i.e. the union of all masks
5448 * for @window and its children will become the new mask
5449 * for @window. See gdk_window_shape_combine_mask().
5451 * This function is distinct from gdk_window_set_child_shapes()
5452 * because it includes @window's shape mask in the set of shapes to
5456 gdk_window_merge_child_shapes (GdkWindow *window)
5458 g_return_if_fail (GDK_IS_WINDOW (window));
5460 #ifdef HAVE_SHAPE_EXT
5461 if (!GDK_WINDOW_DESTROYED (window) &&
5462 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
5463 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
5464 GDK_WINDOW_XID (window), TRUE, ShapeBounding);
5469 * gdk_window_set_child_input_shapes:
5470 * @window: a #GdkWindow
5472 * Sets the input shape mask of @window to the union of input shape masks
5473 * for all children of @window, ignoring the input shape mask of @window
5474 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
5475 * the input shape mask of @window in the masks to be merged.
5480 gdk_window_set_child_input_shapes (GdkWindow *window)
5482 g_return_if_fail (GDK_IS_WINDOW (window));
5484 #ifdef HAVE_SHAPE_EXT
5486 if (!GDK_WINDOW_DESTROYED (window) &&
5487 gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
5488 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
5489 GDK_WINDOW_XID (window), FALSE, ShapeInput);
5495 * gdk_window_merge_child_input_shapes:
5496 * @window: a #GdkWindow
5498 * Merges the input shape masks for any child windows into the
5499 * input shape mask for @window. i.e. the union of all input masks
5500 * for @window and its children will become the new input mask
5501 * for @window. See gdk_window_input_shape_combine_mask().
5503 * This function is distinct from gdk_window_set_child_input_shapes()
5504 * because it includes @window's input shape mask in the set of
5505 * shapes to be merged.
5510 gdk_window_merge_child_input_shapes (GdkWindow *window)
5512 g_return_if_fail (GDK_IS_WINDOW (window));
5514 #ifdef HAVE_SHAPE_EXT
5516 if (!GDK_WINDOW_DESTROYED (window) &&
5517 gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
5518 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
5519 GDK_WINDOW_XID (window), TRUE, ShapeInput);
5526 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
5528 XSetWindowAttributes xattributes;
5529 GdkWindowObject *private;
5530 guint xattributes_mask = 0;
5532 g_return_if_fail (GDK_IS_WINDOW (window));
5534 private = GDK_WINDOW_OBJECT (window);
5535 if (private->input_only)
5538 xattributes.bit_gravity = StaticGravity;
5539 xattributes_mask |= CWBitGravity;
5540 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
5541 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
5542 GDK_WINDOW_XID (window),
5543 CWBitGravity, &xattributes);
5547 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
5549 XSetWindowAttributes xattributes;
5551 g_return_if_fail (GDK_IS_WINDOW (window));
5553 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
5555 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
5556 GDK_WINDOW_XID (window),
5557 CWWinGravity, &xattributes);
5561 * gdk_window_set_static_gravities:
5562 * @window: a #GdkWindow
5563 * @use_static: %TRUE to turn on static gravity
5565 * Set the bit gravity of the given window to static, and flag it so
5566 * all children get static subwindow gravity. This is used if you are
5567 * implementing scary features that involve deep knowledge of the
5568 * windowing system. Don't worry about it unless you have to.
5570 * Return value: %TRUE if the server supports static gravity
5573 gdk_window_set_static_gravities (GdkWindow *window,
5574 gboolean use_static)
5576 GdkWindowObject *private = (GdkWindowObject *)window;
5579 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5581 if (!use_static == !private->guffaw_gravity)
5584 private->guffaw_gravity = use_static;
5586 if (!GDK_WINDOW_DESTROYED (window))
5588 gdk_window_set_static_bit_gravity (window, use_static);
5590 tmp_list = private->children;
5593 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
5595 tmp_list = tmp_list->next;
5603 wmspec_moveresize (GdkWindow *window,
5609 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
5613 /* Release passive grab */
5614 gdk_display_pointer_ungrab (display, timestamp);
5616 xev.xclient.type = ClientMessage;
5617 xev.xclient.serial = 0;
5618 xev.xclient.send_event = True;
5619 xev.xclient.window = GDK_WINDOW_XID (window);
5620 xev.xclient.message_type =
5621 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
5622 xev.xclient.format = 32;
5623 xev.xclient.data.l[0] = root_x;
5624 xev.xclient.data.l[1] = root_y;
5625 xev.xclient.data.l[2] = direction;
5626 xev.xclient.data.l[3] = 0;
5627 xev.xclient.data.l[4] = 0;
5629 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
5630 SubstructureRedirectMask | SubstructureNotifyMask,
5634 typedef struct _MoveResizeData MoveResizeData;
5636 struct _MoveResizeData
5638 GdkDisplay *display;
5640 GdkWindow *moveresize_window;
5641 GdkWindow *moveresize_emulation_window;
5643 GdkWindowEdge resize_edge;
5644 gint moveresize_button;
5647 gint moveresize_orig_x;
5648 gint moveresize_orig_y;
5649 gint moveresize_orig_width;
5650 gint moveresize_orig_height;
5651 GdkWindowHints moveresize_geom_mask;
5652 GdkGeometry moveresize_geometry;
5653 Time moveresize_process_time;
5654 XEvent *moveresize_pending_event;
5657 /* From the WM spec */
5658 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
5659 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
5660 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
5661 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
5662 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
5663 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
5664 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
5665 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
5666 #define _NET_WM_MOVERESIZE_MOVE 8
5669 wmspec_resize_drag (GdkWindow *window,
5678 /* Let the compiler turn a switch into a table, instead
5679 * of doing the table manually, this way is easier to verify.
5683 case GDK_WINDOW_EDGE_NORTH_WEST:
5684 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
5687 case GDK_WINDOW_EDGE_NORTH:
5688 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
5691 case GDK_WINDOW_EDGE_NORTH_EAST:
5692 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
5695 case GDK_WINDOW_EDGE_WEST:
5696 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
5699 case GDK_WINDOW_EDGE_EAST:
5700 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
5703 case GDK_WINDOW_EDGE_SOUTH_WEST:
5704 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
5707 case GDK_WINDOW_EDGE_SOUTH:
5708 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
5711 case GDK_WINDOW_EDGE_SOUTH_EAST:
5712 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
5716 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
5722 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
5725 static MoveResizeData *
5726 get_move_resize_data (GdkDisplay *display,
5729 MoveResizeData *mv_resize;
5730 static GQuark move_resize_quark = 0;
5732 if (!move_resize_quark)
5733 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
5735 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
5737 if (!mv_resize && create)
5739 mv_resize = g_new0 (MoveResizeData, 1);
5740 mv_resize->display = display;
5742 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
5749 update_pos (MoveResizeData *mv_resize,
5755 dx = new_root_x - mv_resize->moveresize_x;
5756 dy = new_root_y - mv_resize->moveresize_y;
5758 if (mv_resize->is_resize)
5762 x = mv_resize->moveresize_orig_x;
5763 y = mv_resize->moveresize_orig_y;
5765 w = mv_resize->moveresize_orig_width;
5766 h = mv_resize->moveresize_orig_height;
5768 switch (mv_resize->resize_edge)
5770 case GDK_WINDOW_EDGE_NORTH_WEST:
5776 case GDK_WINDOW_EDGE_NORTH:
5780 case GDK_WINDOW_EDGE_NORTH_EAST:
5785 case GDK_WINDOW_EDGE_SOUTH_WEST:
5790 case GDK_WINDOW_EDGE_SOUTH_EAST:
5794 case GDK_WINDOW_EDGE_SOUTH:
5797 case GDK_WINDOW_EDGE_EAST:
5800 case GDK_WINDOW_EDGE_WEST:
5811 if (mv_resize->moveresize_geom_mask)
5813 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
5814 mv_resize->moveresize_geom_mask,
5818 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
5824 x = mv_resize->moveresize_orig_x + dx;
5825 y = mv_resize->moveresize_orig_y + dy;
5827 gdk_window_move (mv_resize->moveresize_window, x, y);
5832 finish_drag (MoveResizeData *mv_resize)
5834 gdk_window_destroy (mv_resize->moveresize_emulation_window);
5835 mv_resize->moveresize_emulation_window = NULL;
5836 g_object_unref (mv_resize->moveresize_window);
5837 mv_resize->moveresize_window = NULL;
5839 if (mv_resize->moveresize_pending_event)
5841 g_free (mv_resize->moveresize_pending_event);
5842 mv_resize->moveresize_pending_event = NULL;
5847 lookahead_motion_predicate (Display *xdisplay,
5851 gboolean *seen_release = (gboolean *)arg;
5852 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
5853 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5858 switch (event->xany.type)
5861 *seen_release = TRUE;
5864 mv_resize->moveresize_process_time = event->xmotion.time;
5874 moveresize_lookahead (MoveResizeData *mv_resize,
5878 gboolean seen_release = FALSE;
5880 if (mv_resize->moveresize_process_time)
5882 if (event->xmotion.time == mv_resize->moveresize_process_time)
5884 mv_resize->moveresize_process_time = 0;
5891 XCheckIfEvent (event->xany.display, &tmp_event,
5892 lookahead_motion_predicate, (XPointer) & seen_release);
5894 return mv_resize->moveresize_process_time == 0;
5898 _gdk_moveresize_handle_event (XEvent *event)
5900 guint button_mask = 0;
5901 GdkWindowObject *window_private;
5902 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
5903 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5905 if (!mv_resize || !mv_resize->moveresize_window)
5908 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
5910 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
5912 switch (event->xany.type)
5915 if (window_private->resize_count > 0)
5917 if (mv_resize->moveresize_pending_event)
5918 *mv_resize->moveresize_pending_event = *event;
5920 mv_resize->moveresize_pending_event =
5921 g_memdup (event, sizeof (XEvent));
5925 if (!moveresize_lookahead (mv_resize, event))
5928 update_pos (mv_resize,
5929 event->xmotion.x_root,
5930 event->xmotion.y_root);
5932 /* This should never be triggered in normal cases, but in the
5933 * case where the drag started without an implicit grab being
5934 * in effect, we could miss the release if it occurs before
5935 * we grab the pointer; this ensures that we will never
5936 * get a permanently stuck grab.
5938 if ((event->xmotion.state & button_mask) == 0)
5939 finish_drag (mv_resize);
5943 update_pos (mv_resize,
5944 event->xbutton.x_root,
5945 event->xbutton.y_root);
5947 if (event->xbutton.button == mv_resize->moveresize_button)
5948 finish_drag (mv_resize);
5955 _gdk_moveresize_configure_done (GdkDisplay *display,
5959 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5961 if (!mv_resize || window != mv_resize->moveresize_window)
5964 if (mv_resize->moveresize_pending_event)
5966 tmp_event = mv_resize->moveresize_pending_event;
5967 mv_resize->moveresize_pending_event = NULL;
5968 _gdk_moveresize_handle_event (tmp_event);
5976 create_moveresize_window (MoveResizeData *mv_resize,
5979 GdkWindowAttr attributes;
5980 gint attributes_mask;
5981 GdkGrabStatus status;
5983 g_assert (mv_resize->moveresize_emulation_window == NULL);
5985 attributes.x = -100;
5986 attributes.y = -100;
5987 attributes.width = 10;
5988 attributes.height = 10;
5989 attributes.window_type = GDK_WINDOW_TEMP;
5990 attributes.wclass = GDK_INPUT_ONLY;
5991 attributes.override_redirect = TRUE;
5992 attributes.event_mask = 0;
5994 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
5996 mv_resize->moveresize_emulation_window =
5997 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
6001 gdk_window_show (mv_resize->moveresize_emulation_window);
6003 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
6005 GDK_BUTTON_RELEASE_MASK |
6006 GDK_POINTER_MOTION_MASK,
6011 if (status != GDK_GRAB_SUCCESS)
6013 /* If this fails, some other client has grabbed the window
6016 finish_drag (mv_resize);
6019 mv_resize->moveresize_process_time = 0;
6023 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
6024 so that calling XMoveWindow with these coordinates will not move the
6026 Note that this depends on the WM to implement ICCCM-compliant reference
6030 calculate_unmoving_origin (MoveResizeData *mv_resize)
6035 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
6036 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
6038 gdk_window_get_origin (mv_resize->moveresize_window,
6039 &mv_resize->moveresize_orig_x,
6040 &mv_resize->moveresize_orig_y);
6044 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
6045 gdk_window_get_geometry (mv_resize->moveresize_window,
6046 NULL, NULL, &width, &height, NULL);
6048 switch (mv_resize->moveresize_geometry.win_gravity)
6050 case GDK_GRAVITY_NORTH_WEST:
6051 mv_resize->moveresize_orig_x = rect.x;
6052 mv_resize->moveresize_orig_y = rect.y;
6054 case GDK_GRAVITY_NORTH:
6055 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
6056 mv_resize->moveresize_orig_y = rect.y;
6058 case GDK_GRAVITY_NORTH_EAST:
6059 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
6060 mv_resize->moveresize_orig_y = rect.y;
6062 case GDK_GRAVITY_WEST:
6063 mv_resize->moveresize_orig_x = rect.x;
6064 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
6066 case GDK_GRAVITY_CENTER:
6067 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
6068 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
6070 case GDK_GRAVITY_EAST:
6071 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
6072 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
6074 case GDK_GRAVITY_SOUTH_WEST:
6075 mv_resize->moveresize_orig_x = rect.x;
6076 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
6078 case GDK_GRAVITY_SOUTH:
6079 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
6080 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
6082 case GDK_GRAVITY_SOUTH_EAST:
6083 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
6084 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
6087 mv_resize->moveresize_orig_x = rect.x;
6088 mv_resize->moveresize_orig_y = rect.y;
6095 emulate_resize_drag (GdkWindow *window,
6102 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
6104 mv_resize->is_resize = TRUE;
6105 mv_resize->moveresize_button = button;
6106 mv_resize->resize_edge = edge;
6107 mv_resize->moveresize_x = root_x;
6108 mv_resize->moveresize_y = root_y;
6109 mv_resize->moveresize_window = g_object_ref (window);
6111 gdk_drawable_get_size (window,
6112 &mv_resize->moveresize_orig_width,
6113 &mv_resize->moveresize_orig_height);
6115 mv_resize->moveresize_geom_mask = 0;
6116 gdk_window_get_geometry_hints (window,
6117 &mv_resize->moveresize_geometry,
6118 &mv_resize->moveresize_geom_mask);
6120 calculate_unmoving_origin (mv_resize);
6122 create_moveresize_window (mv_resize, timestamp);
6126 emulate_move_drag (GdkWindow *window,
6132 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
6134 mv_resize->is_resize = FALSE;
6135 mv_resize->moveresize_button = button;
6136 mv_resize->moveresize_x = root_x;
6137 mv_resize->moveresize_y = root_y;
6139 mv_resize->moveresize_window = g_object_ref (window);
6141 calculate_unmoving_origin (mv_resize);
6143 create_moveresize_window (mv_resize, timestamp);
6147 * gdk_window_begin_resize_drag:
6148 * @window: a toplevel #GdkWindow
6149 * @edge: the edge or corner from which the drag is started
6150 * @button: the button being used to drag
6151 * @root_x: root window X coordinate of mouse click that began the drag
6152 * @root_y: root window Y coordinate of mouse click that began the drag
6153 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
6155 * Begins a window resize operation (for a toplevel window).
6156 * You might use this function to implement a "window resize grip," for
6157 * example; in fact #GtkStatusbar uses it. The function works best
6158 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
6159 * fallback implementation for other window managers.
6163 gdk_window_begin_resize_drag (GdkWindow *window,
6170 g_return_if_fail (GDK_IS_WINDOW (window));
6172 if (GDK_WINDOW_DESTROYED (window))
6175 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
6176 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
6177 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
6179 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
6183 * gdk_window_begin_move_drag:
6184 * @window: a toplevel #GdkWindow
6185 * @button: the button being used to drag
6186 * @root_x: root window X coordinate of mouse click that began the drag
6187 * @root_y: root window Y coordinate of mouse click that began the drag
6188 * @timestamp: timestamp of mouse click that began the drag
6190 * Begins a window move operation (for a toplevel window). You might
6191 * use this function to implement a "window move grip," for
6192 * example. The function works best with window managers that support
6193 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
6194 * Window Manager Hints</ulink>, but has a fallback implementation for
6195 * other window managers.
6199 gdk_window_begin_move_drag (GdkWindow *window,
6205 g_return_if_fail (GDK_IS_WINDOW (window));
6207 if (GDK_WINDOW_DESTROYED (window))
6210 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
6211 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
6212 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
6215 emulate_move_drag (window, button, root_x, root_y, timestamp);
6219 * gdk_window_enable_synchronized_configure:
6220 * @window: a toplevel #GdkWindow
6222 * Indicates that the application will cooperate with the window
6223 * system in synchronizing the window repaint with the window
6224 * manager during resizing operations. After an application calls
6225 * this function, it must call gdk_window_configure_finished() every
6226 * time it has finished all processing associated with a set of
6227 * Configure events. Toplevel GTK+ windows automatically use this
6230 * On X, calling this function makes @window participate in the
6231 * _NET_WM_SYNC_REQUEST window manager protocol.
6236 gdk_window_enable_synchronized_configure (GdkWindow *window)
6238 GdkWindowObject *private = (GdkWindowObject *)window;
6239 GdkWindowImplX11 *impl;
6241 g_return_if_fail (GDK_IS_WINDOW (window));
6243 impl = GDK_WINDOW_IMPL_X11 (private->impl);
6245 if (!impl->use_synchronized_configure)
6247 impl->use_synchronized_configure = TRUE;
6248 ensure_sync_counter (window);
6253 * gdk_window_configure_finished:
6254 * @window: a toplevel #GdkWindow
6256 * Signal to the window system that the application has finished
6257 * handling Configure events it has received. Window Managers can
6258 * use this to better synchronize the frame repaint with the
6259 * application. GTK+ applications will automatically call this
6260 * function when appropriate.
6262 * This function can only be called if gdk_window_enable_synchronized_configure()
6263 * was called previously.
6268 gdk_window_configure_finished (GdkWindow *window)
6270 GdkWindowImplX11 *impl;
6272 g_return_if_fail (GDK_IS_WINDOW (window));
6274 impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
6275 if (!impl->use_synchronized_configure)
6279 if (!GDK_WINDOW_DESTROYED (window))
6281 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
6282 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
6284 if (toplevel && toplevel->update_counter != None &&
6285 GDK_DISPLAY_X11 (display)->use_sync &&
6286 !XSyncValueIsZero (toplevel->current_counter_value))
6288 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
6289 toplevel->update_counter,
6290 toplevel->current_counter_value);
6292 XSyncIntToValue (&toplevel->current_counter_value, 0);
6298 #define __GDK_WINDOW_X11_C__
6299 #include "gdkaliasdef.c"