1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball,
3 * Josh MacDonald, Ryan Lortie
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include <X11/Xutil.h>
32 #include <X11/Xatom.h>
35 #include <X11/XKBlib.h>
38 #include <netinet/in.h>
44 #include "gdkwindow.h"
45 #include "gdkwindowimpl.h"
47 #include "gdkdisplay-x11.h"
48 #include "gdkprivate-x11.h"
49 #include "gdkregion.h"
50 #include "gdkinternals.h"
52 #include "gdkwindow-x11.h"
53 #include "gdkdeviceprivate.h"
54 #include "gdkeventsource.h"
62 #include <X11/extensions/shape.h>
64 #ifdef HAVE_XCOMPOSITE
65 #include <X11/extensions/Xcomposite.h>
69 #include <X11/extensions/Xfixes.h>
73 #include <X11/extensions/Xdamage.h>
76 const int _gdk_event_mask_table[21] =
80 PointerMotionHintMask,
97 SubstructureNotifyMask,
98 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
100 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
102 /* Forward declarations */
103 static void gdk_window_set_static_win_gravity (GdkWindow *window,
105 static gboolean gdk_window_icon_name_set (GdkWindow *window);
106 static void gdk_window_add_colormap_windows (GdkWindow *window);
107 static void set_wm_name (GdkDisplay *display,
110 static void move_to_current_desktop (GdkWindow *window);
112 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
113 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
115 static void gdk_window_impl_x11_finalize (GObject *object);
116 static void gdk_window_impl_iface_init (GdkWindowImplIface *iface);
118 #define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \
119 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
120 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
122 #define WINDOW_IS_TOPLEVEL(window) \
123 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
124 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
125 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
127 /* Return whether time1 is considered later than time2 as far as xserver
128 * time is concerned. Accounts for wraparound.
130 #define XSERVER_TIME_IS_LATER(time1, time2) \
131 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
132 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
135 G_DEFINE_TYPE_WITH_CODE (GdkWindowImplX11,
137 GDK_TYPE_DRAWABLE_IMPL_X11,
138 G_IMPLEMENT_INTERFACE (GDK_TYPE_WINDOW_IMPL,
139 gdk_window_impl_iface_init));
142 _gdk_window_impl_get_type (void)
144 return gdk_window_impl_x11_get_type ();
148 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
150 impl->toplevel_window_type = -1;
151 impl->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
152 (GDestroyNotify) gdk_cursor_unref);
156 _gdk_x11_window_get_toplevel (GdkWindow *window)
158 GdkWindowObject *private;
159 GdkWindowImplX11 *impl;
161 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
163 if (!WINDOW_IS_TOPLEVEL (window))
166 private = (GdkWindowObject *)window;
167 impl = GDK_WINDOW_IMPL_X11 (private->impl);
170 impl->toplevel = g_new0 (GdkToplevelX11, 1);
172 return impl->toplevel;
176 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
178 GObjectClass *object_class = G_OBJECT_CLASS (klass);
179 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
181 object_class->finalize = gdk_window_impl_x11_finalize;
183 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
184 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
188 gdk_window_impl_x11_finalize (GObject *object)
190 GdkWindowObject *wrapper;
191 GdkDrawableImplX11 *draw_impl;
192 GdkWindowImplX11 *window_impl;
194 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
196 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
197 window_impl = GDK_WINDOW_IMPL_X11 (object);
199 wrapper = (GdkWindowObject*) draw_impl->wrapper;
201 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
203 if (!GDK_WINDOW_DESTROYED (wrapper))
205 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
207 _gdk_xid_table_remove (display, draw_impl->xid);
208 if (window_impl->toplevel && window_impl->toplevel->focus_window)
209 _gdk_xid_table_remove (display, window_impl->toplevel->focus_window);
212 g_free (window_impl->toplevel);
214 if (window_impl->cursor)
215 gdk_cursor_unref (window_impl->cursor);
217 g_hash_table_destroy (window_impl->device_cursor);
219 G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
223 tmp_unset_bg (GdkWindow *window)
225 GdkWindowImplX11 *impl;
226 GdkWindowObject *obj;
228 obj = (GdkWindowObject *) window;
229 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
233 if (obj->bg_pixmap != GDK_NO_BG)
234 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
235 GDK_DRAWABLE_XID (window), None);
239 tmp_reset_bg (GdkWindow *window)
241 GdkWindowImplX11 *impl;
242 GdkWindowObject *obj;
244 obj = (GdkWindowObject *) window;
245 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
249 if (obj->bg_pixmap == GDK_NO_BG)
256 if (obj->bg_pixmap == GDK_PARENT_RELATIVE_BG)
257 xpixmap = ParentRelative;
259 xpixmap = GDK_DRAWABLE_XID (obj->bg_pixmap);
261 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
262 GDK_DRAWABLE_XID (window), xpixmap);
266 XSetWindowBackground (GDK_DRAWABLE_XDISPLAY (window),
267 GDK_DRAWABLE_XID (window),
268 obj->bg_color.pixel);
272 /* Unsetting and resetting window backgrounds.
274 * In many cases it is possible to avoid flicker by unsetting the
275 * background of windows. For example if the background of the
276 * parent window is unset when a window is unmapped, a brief flicker
277 * of background painting is avoided.
280 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
283 GdkWindowObject *private;
285 g_return_if_fail (GDK_IS_WINDOW (window));
287 private = (GdkWindowObject *)window;
289 if (private->input_only || private->destroyed ||
290 (private->window_type != GDK_WINDOW_ROOT &&
291 !GDK_WINDOW_IS_MAPPED (window)))
294 if (_gdk_window_has_impl (window) &&
295 GDK_WINDOW_IS_X11 (window) &&
296 private->window_type != GDK_WINDOW_ROOT &&
297 private->window_type != GDK_WINDOW_FOREIGN)
298 tmp_unset_bg (window);
304 for (l = private->children; l != NULL; l = l->next)
305 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
310 _gdk_x11_window_tmp_unset_parent_bg (GdkWindow *window)
312 GdkWindowObject *private;
313 private = (GdkWindowObject*) window;
315 if (GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT)
318 window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
319 _gdk_x11_window_tmp_unset_bg (window, FALSE);
323 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
326 GdkWindowObject *private;
328 g_return_if_fail (GDK_IS_WINDOW (window));
330 private = (GdkWindowObject *)window;
332 if (private->input_only || private->destroyed ||
333 (private->window_type != GDK_WINDOW_ROOT &&
334 !GDK_WINDOW_IS_MAPPED (window)))
338 if (_gdk_window_has_impl (window) &&
339 GDK_WINDOW_IS_X11 (window) &&
340 private->window_type != GDK_WINDOW_ROOT &&
341 private->window_type != GDK_WINDOW_FOREIGN)
342 tmp_reset_bg (window);
348 for (l = private->children; l != NULL; l = l->next)
349 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
354 _gdk_x11_window_tmp_reset_parent_bg (GdkWindow *window)
356 GdkWindowObject *private;
357 private = (GdkWindowObject*) window;
359 if (GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT)
362 window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
364 _gdk_x11_window_tmp_reset_bg (window, FALSE);
368 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
370 GdkDrawableImplX11 *drawable_impl;
372 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
374 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
376 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
377 drawable_impl->colormap == NULL)
379 XWindowAttributes window_attributes;
382 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
386 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
387 window_attributes.visual->visualid);
388 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
389 window_attributes.colormap);
392 return drawable_impl->colormap;
396 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
399 GdkDrawableImplX11 *draw_impl;
401 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
403 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
405 if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper))
409 GDK_DRAWABLE_CLASS (gdk_window_impl_x11_parent_class)->set_colormap (drawable, cmap);
413 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
415 GDK_COLORMAP_XCOLORMAP (cmap));
417 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
419 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
425 _gdk_windowing_window_init (GdkScreen * screen)
427 GdkWindowObject *private;
428 GdkDrawableImplX11 *draw_impl;
429 GdkScreenX11 *screen_x11;
431 screen_x11 = GDK_SCREEN_X11 (screen);
433 g_assert (screen_x11->root_window == NULL);
435 gdk_screen_set_default_colormap (screen,
436 gdk_screen_get_system_colormap (screen));
438 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
440 private = (GdkWindowObject *) screen_x11->root_window;
441 private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
442 private->impl_window = private;
444 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
446 draw_impl->screen = screen;
447 draw_impl->xid = screen_x11->xroot_window;
448 draw_impl->wrapper = GDK_DRAWABLE (private);
449 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
450 g_object_ref (draw_impl->colormap);
452 private->window_type = GDK_WINDOW_ROOT;
453 private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
459 private->width = WidthOfScreen (screen_x11->xscreen);
460 private->height = HeightOfScreen (screen_x11->xscreen);
461 private->viewable = TRUE;
463 /* see init_randr_support() in gdkscreen-x11.c */
464 private->event_mask = GDK_STRUCTURE_MASK;
466 _gdk_window_update_size (screen_x11->root_window);
468 _gdk_xid_table_insert (screen_x11->display,
469 &screen_x11->xroot_window,
470 screen_x11->root_window);
474 set_wm_protocols (GdkWindow *window)
476 GdkDisplay *display = gdk_drawable_get_display (window);
480 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
481 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
482 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
485 if (GDK_DISPLAY_X11 (display)->use_sync)
486 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
489 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
493 get_default_title (void)
497 title = g_get_application_name ();
499 title = g_get_prgname ();
507 check_leader_window_title (GdkDisplay *display)
509 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
511 if (display_x11->leader_window && !display_x11->leader_window_title_set)
513 set_wm_name (display,
514 display_x11->leader_window,
515 get_default_title ());
517 display_x11->leader_window_title_set = TRUE;
522 create_focus_window (GdkDisplay *display,
525 GdkDisplayX11 *display_x11;
526 GdkEventMask event_mask;
530 xdisplay = GDK_DISPLAY_XDISPLAY (display);
531 display_x11 = GDK_DISPLAY_X11 (display);
533 focus_window = XCreateSimpleWindow (xdisplay, parent,
537 /* FIXME: probably better to actually track the requested event mask for the toplevel
539 event_mask = (GDK_KEY_PRESS_MASK |
540 GDK_KEY_RELEASE_MASK |
541 GDK_FOCUS_CHANGE_MASK);
543 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
547 XMapWindow (xdisplay, focus_window);
553 ensure_sync_counter (GdkWindow *window)
556 if (!GDK_WINDOW_DESTROYED (window))
558 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
559 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
560 GdkWindowObject *private = (GdkWindowObject *)window;
561 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
563 if (toplevel && impl->use_synchronized_configure &&
564 toplevel->update_counter == None &&
565 GDK_DISPLAY_X11 (display)->use_sync)
567 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
571 XSyncIntToValue (&value, 0);
573 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
575 atom = gdk_x11_get_xatom_by_name_for_display (display,
576 "_NET_WM_SYNC_REQUEST_COUNTER");
578 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
581 (guchar *)&toplevel->update_counter, 1);
583 XSyncIntToValue (&toplevel->current_counter_value, 0);
590 setup_toplevel_window (GdkWindow *window,
593 GdkWindowObject *obj = (GdkWindowObject *)window;
594 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
595 GdkDisplay *display = gdk_drawable_get_display (window);
596 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
597 XID xid = GDK_WINDOW_XID (window);
598 XID xparent = GDK_WINDOW_XID (parent);
599 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
600 XSizeHints size_hints;
602 Window leader_window;
604 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_DIALOG)
605 XSetTransientForHint (xdisplay, xid, xparent);
607 set_wm_protocols (window);
609 if (!obj->input_only)
611 /* The focus window is off the visible area, and serves to receive key
612 * press events so they don't get sent to child windows.
614 toplevel->focus_window = create_focus_window (display, xid);
615 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
618 check_leader_window_title (screen_x11->display);
620 /* FIXME: Is there any point in doing this? Do any WM's pay
621 * attention to PSize, and even if they do, is this the
624 size_hints.flags = PSize;
625 size_hints.width = obj->width;
626 size_hints.height = obj->height;
628 XSetWMNormalHints (xdisplay, xid, &size_hints);
630 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
631 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
634 XChangeProperty (xdisplay, xid,
635 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
640 leader_window = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
643 XChangeProperty (xdisplay, xid,
644 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
645 XA_WINDOW, 32, PropModeReplace,
646 (guchar *) &leader_window, 1);
648 if (toplevel->focus_window != None)
649 XChangeProperty (xdisplay, xid,
650 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_USER_TIME_WINDOW"),
651 XA_WINDOW, 32, PropModeReplace,
652 (guchar *) &toplevel->focus_window, 1);
654 if (!obj->focus_on_map)
655 gdk_x11_window_set_user_time (window, 0);
656 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
657 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
659 ensure_sync_counter (window);
663 _gdk_window_impl_new (GdkWindow *window,
664 GdkWindow *real_parent,
667 GdkEventMask event_mask,
668 GdkWindowAttr *attributes,
669 gint attributes_mask)
671 GdkWindowObject *private;
672 GdkWindowImplX11 *impl;
673 GdkDrawableImplX11 *draw_impl;
674 GdkScreenX11 *screen_x11;
675 GdkDisplayX11 *display_x11;
682 XSetWindowAttributes xattributes;
683 long xattributes_mask;
684 XClassHint *class_hint;
689 private = (GdkWindowObject *) window;
691 screen_x11 = GDK_SCREEN_X11 (screen);
692 xparent = GDK_WINDOW_XID (real_parent);
693 display_x11 = GDK_DISPLAY_X11 (GDK_SCREEN_DISPLAY (screen));
695 impl = g_object_new (_gdk_window_impl_get_type (), NULL);
696 private->impl = (GdkDrawable *)impl;
697 draw_impl = GDK_DRAWABLE_IMPL_X11 (impl);
698 draw_impl->wrapper = GDK_DRAWABLE (window);
700 draw_impl->screen = screen;
701 xdisplay = screen_x11->xdisplay;
703 xattributes_mask = 0;
705 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
707 if (attributes_mask & GDK_WA_NOREDIR)
709 xattributes.override_redirect =
710 (attributes->override_redirect == FALSE)?False:True;
711 xattributes_mask |= CWOverrideRedirect;
714 xattributes.override_redirect = False;
716 impl->override_redirect = xattributes.override_redirect;
718 if (private->parent && private->parent->guffaw_gravity)
720 xattributes.win_gravity = StaticGravity;
721 xattributes_mask |= CWWinGravity;
725 switch (private->window_type)
727 case GDK_WINDOW_TOPLEVEL:
728 case GDK_WINDOW_DIALOG:
729 case GDK_WINDOW_TEMP:
730 if (GDK_WINDOW_TYPE (private->parent) != GDK_WINDOW_ROOT)
732 /* The common code warns for this case */
733 xparent = GDK_SCREEN_XROOTWIN (screen);
737 if (!private->input_only)
741 if (attributes_mask & GDK_WA_COLORMAP)
743 draw_impl->colormap = attributes->colormap;
744 g_object_ref (attributes->colormap);
748 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
750 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
751 g_object_ref (draw_impl->colormap);
755 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
759 xattributes.background_pixel = private->bg_color.pixel;
761 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
762 xattributes_mask |= CWBorderPixel | CWBackPixel;
764 if (private->guffaw_gravity)
765 xattributes.bit_gravity = StaticGravity;
767 xattributes.bit_gravity = NorthWestGravity;
769 xattributes_mask |= CWBitGravity;
771 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
772 xattributes_mask |= CWColormap;
774 if (private->window_type == GDK_WINDOW_TEMP)
776 xattributes.save_under = True;
777 xattributes.override_redirect = True;
778 xattributes.cursor = None;
779 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
781 impl->override_redirect = TRUE;
787 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
788 g_object_ref (draw_impl->colormap);
791 if (private->width > 65535 ||
792 private->height > 65535)
794 g_warning ("Native Windows wider or taller than 65535 pixels are not supported");
796 if (private->width > 65535)
797 private->width = 65535;
798 if (private->height > 65535)
799 private->height = 65535;
802 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
803 private->x + private->parent->abs_x,
804 private->y + private->parent->abs_y,
805 private->width, private->height,
806 0, private->depth, class, xvisual,
807 xattributes_mask, &xattributes);
809 g_object_ref (window);
810 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
812 switch (GDK_WINDOW_TYPE (private))
814 case GDK_WINDOW_DIALOG:
815 case GDK_WINDOW_TOPLEVEL:
816 case GDK_WINDOW_TEMP:
817 if (attributes_mask & GDK_WA_TITLE)
818 title = attributes->title;
820 title = get_default_title ();
822 gdk_window_set_title (window, title);
824 if (attributes_mask & GDK_WA_WMCLASS)
826 class_hint = XAllocClassHint ();
827 class_hint->res_name = attributes->wmclass_name;
828 class_hint->res_class = attributes->wmclass_class;
829 XSetClassHint (xdisplay, xid, class_hint);
833 setup_toplevel_window (window, (GdkWindow *)private->parent);
836 case GDK_WINDOW_CHILD:
837 if (!private->input_only &&
838 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
839 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
841 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
842 gdk_window_add_colormap_windows (window);
850 if (attributes_mask & GDK_WA_TYPE_HINT)
851 gdk_window_set_type_hint (window, attributes->type_hint);
853 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
854 GDK_WINDOW_XWINDOW (window), event_mask,
855 StructureNotifyMask | PropertyChangeMask);
859 x_event_mask_to_gdk_event_mask (long mask)
861 GdkEventMask event_mask = 0;
864 for (i = 0; i < _gdk_nenvent_masks; i++)
866 if (mask & _gdk_event_mask_table[i])
867 event_mask |= 1 << (i + 1);
874 * gdk_window_foreign_new_for_display:
875 * @display: the #GdkDisplay where the window handle comes from.
876 * @anid: a native window handle.
878 * Wraps a native window in a #GdkWindow.
879 * This may fail if the window has been destroyed. If the window
880 * was already known to GDK, a new reference to the existing
881 * #GdkWindow is returned.
883 * For example in the X backend, a native window handle is an Xlib
886 * Return value: a #GdkWindow wrapper for the native window or
887 * %NULL if the window has been destroyed. The wrapper will be
888 * newly created, if one doesn't exist already.
893 gdk_window_foreign_new_for_display (GdkDisplay *display,
894 GdkNativeWindow anid)
897 GdkWindowObject *private;
898 GdkWindowImplX11 *impl;
899 GdkDrawableImplX11 *draw_impl;
900 GdkDisplayX11 *display_x11;
901 XWindowAttributes attrs;
903 Window *children = NULL;
907 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
909 display_x11 = GDK_DISPLAY_X11 (display);
911 if ((window = gdk_xid_table_lookup_for_display (display, anid)) != NULL)
912 return g_object_ref (window);
914 gdk_error_trap_push ();
915 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
916 if (gdk_error_trap_pop () || !result)
919 /* FIXME: This is pretty expensive. Maybe the caller should supply
921 gdk_error_trap_push ();
922 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
923 if (gdk_error_trap_pop () || !result)
929 window = g_object_new (GDK_TYPE_WINDOW, NULL);
931 private = (GdkWindowObject *) window;
932 private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
933 private->impl_window = private;
935 impl = GDK_WINDOW_IMPL_X11 (private->impl);
936 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
937 draw_impl->wrapper = GDK_DRAWABLE (window);
938 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
940 private->parent = gdk_xid_table_lookup_for_display (display, parent);
942 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
943 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
945 private->parent->children = g_list_prepend (private->parent->children, window);
947 draw_impl->xid = anid;
949 private->x = attrs.x;
950 private->y = attrs.y;
951 private->width = attrs.width;
952 private->height = attrs.height;
953 private->window_type = GDK_WINDOW_FOREIGN;
954 private->destroyed = FALSE;
956 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
958 if (attrs.map_state == IsUnmapped)
959 private->state = GDK_WINDOW_STATE_WITHDRAWN;
962 private->viewable = TRUE;
964 private->depth = attrs.depth;
966 g_object_ref (window);
967 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
969 /* Update the clip region, etc */
970 _gdk_window_update_size (window);
976 * gdk_window_lookup_for_display:
977 * @display: the #GdkDisplay corresponding to the window handle
978 * @anid: a native window handle.
980 * Looks up the #GdkWindow that wraps the given native window handle.
982 * For example in the X backend, a native window handle is an Xlib
985 * Return value: the #GdkWindow wrapper for the native window,
986 * or %NULL if there is none.
991 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
993 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
998 * @anid: a native window handle.
1000 * Looks up the #GdkWindow that wraps the given native window handle.
1002 * For example in the X backend, a native window handle is an Xlib
1005 * Return value: the #GdkWindow wrapper for the native window,
1006 * or %NULL if there is none.
1009 gdk_window_lookup (GdkNativeWindow anid)
1011 return (GdkWindow*) gdk_xid_table_lookup (anid);
1015 gdk_toplevel_x11_free_contents (GdkDisplay *display,
1016 GdkToplevelX11 *toplevel)
1018 if (toplevel->icon_window)
1020 g_object_unref (toplevel->icon_window);
1021 toplevel->icon_window = NULL;
1023 if (toplevel->icon_pixmap)
1025 g_object_unref (toplevel->icon_pixmap);
1026 toplevel->icon_pixmap = NULL;
1028 if (toplevel->icon_mask)
1030 g_object_unref (toplevel->icon_mask);
1031 toplevel->icon_mask = NULL;
1033 if (toplevel->group_leader)
1035 g_object_unref (toplevel->group_leader);
1036 toplevel->group_leader = NULL;
1039 if (toplevel->update_counter != None)
1041 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
1042 toplevel->update_counter);
1043 toplevel->update_counter = None;
1045 XSyncIntToValue (&toplevel->current_counter_value, 0);
1051 _gdk_x11_window_destroy (GdkWindow *window,
1053 gboolean foreign_destroy)
1055 GdkWindowObject *private = (GdkWindowObject *)window;
1056 GdkToplevelX11 *toplevel;
1058 g_return_if_fail (GDK_IS_WINDOW (window));
1060 _gdk_selection_window_destroyed (window);
1062 toplevel = _gdk_x11_window_get_toplevel (window);
1064 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1066 _gdk_x11_drawable_finish (private->impl);
1068 if (!recursing && !foreign_destroy)
1070 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1075 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
1077 /* It's somebody else's window, but in our hierarchy,
1078 * so reparent it to the root window, and then send
1079 * it a delete event, as if we were a WM
1081 XClientMessageEvent xclient;
1083 gdk_error_trap_push ();
1084 gdk_window_hide (window);
1085 gdk_window_reparent (window, NULL, 0, 0);
1087 memset (&xclient, 0, sizeof (xclient));
1088 xclient.type = ClientMessage;
1089 xclient.window = GDK_WINDOW_XID (window);
1090 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1092 xclient.format = 32;
1093 xclient.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1094 "WM_DELETE_WINDOW");
1095 xclient.data.l[1] = CurrentTime;
1096 xclient.data.l[2] = 0;
1097 xclient.data.l[3] = 0;
1098 xclient.data.l[4] = 0;
1100 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1101 GDK_WINDOW_XID (window),
1102 False, 0, (XEvent *)&xclient);
1103 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
1104 gdk_error_trap_pop ();
1108 get_root (GdkWindow *window)
1110 GdkScreen *screen = gdk_drawable_get_screen (window);
1112 return gdk_screen_get_root_window (screen);
1115 /* This function is called when the XWindow is really gone.
1118 gdk_window_destroy_notify (GdkWindow *window)
1120 GdkWindowImplX11 *window_impl;
1122 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
1124 if (!GDK_WINDOW_DESTROYED (window))
1126 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1127 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1129 _gdk_window_destroy (window, TRUE);
1132 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1133 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1134 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1136 _gdk_xgrab_check_destroy (window);
1138 g_object_unref (window);
1142 update_wm_hints (GdkWindow *window,
1145 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1146 GdkWindowObject *private = (GdkWindowObject *)window;
1147 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1151 !toplevel->is_leader &&
1152 private->state & GDK_WINDOW_STATE_WITHDRAWN)
1155 wm_hints.flags = StateHint | InputHint;
1156 wm_hints.input = private->accept_focus ? True : False;
1157 wm_hints.initial_state = NormalState;
1159 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
1161 wm_hints.flags |= StateHint;
1162 wm_hints.initial_state = IconicState;
1165 if (toplevel->icon_window && !GDK_WINDOW_DESTROYED (toplevel->icon_window))
1167 wm_hints.flags |= IconWindowHint;
1168 wm_hints.icon_window = GDK_WINDOW_XID (toplevel->icon_window);
1171 if (toplevel->icon_pixmap)
1173 wm_hints.flags |= IconPixmapHint;
1174 wm_hints.icon_pixmap = GDK_PIXMAP_XID (toplevel->icon_pixmap);
1177 if (toplevel->icon_mask)
1179 wm_hints.flags |= IconMaskHint;
1180 wm_hints.icon_mask = GDK_PIXMAP_XID (toplevel->icon_mask);
1183 wm_hints.flags |= WindowGroupHint;
1184 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1186 wm_hints.flags |= WindowGroupHint;
1187 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1190 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1192 if (toplevel->urgency_hint)
1193 wm_hints.flags |= XUrgencyHint;
1195 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1196 GDK_WINDOW_XID (window),
1201 set_initial_hints (GdkWindow *window)
1203 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1204 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1205 Window xwindow = GDK_WINDOW_XID (window);
1206 GdkWindowObject *private;
1207 GdkToplevelX11 *toplevel;
1211 private = (GdkWindowObject*) window;
1212 toplevel = _gdk_x11_window_get_toplevel (window);
1217 update_wm_hints (window, TRUE);
1219 /* We set the spec hints regardless of whether the spec is supported,
1220 * since it can't hurt and it's kind of expensive to check whether
1226 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1228 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1229 "_NET_WM_STATE_MAXIMIZED_VERT");
1231 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1232 "_NET_WM_STATE_MAXIMIZED_HORZ");
1234 toplevel->have_maxhorz = toplevel->have_maxvert = TRUE;
1237 if (private->state & GDK_WINDOW_STATE_ABOVE)
1239 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1240 "_NET_WM_STATE_ABOVE");
1244 if (private->state & GDK_WINDOW_STATE_BELOW)
1246 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1247 "_NET_WM_STATE_BELOW");
1251 if (private->state & GDK_WINDOW_STATE_STICKY)
1253 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1254 "_NET_WM_STATE_STICKY");
1256 toplevel->have_sticky = TRUE;
1259 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1261 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1262 "_NET_WM_STATE_FULLSCREEN");
1264 toplevel->have_fullscreen = TRUE;
1267 if (private->modal_hint)
1269 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1270 "_NET_WM_STATE_MODAL");
1274 if (toplevel->skip_taskbar_hint)
1276 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1277 "_NET_WM_STATE_SKIP_TASKBAR");
1281 if (toplevel->skip_pager_hint)
1283 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1284 "_NET_WM_STATE_SKIP_PAGER");
1290 XChangeProperty (xdisplay,
1292 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1293 XA_ATOM, 32, PropModeReplace,
1294 (guchar*) atoms, i);
1298 XDeleteProperty (xdisplay,
1300 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1303 if (private->state & GDK_WINDOW_STATE_STICKY)
1305 atoms[0] = 0xFFFFFFFF;
1306 XChangeProperty (xdisplay,
1308 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1309 XA_CARDINAL, 32, PropModeReplace,
1310 (guchar*) atoms, 1);
1311 toplevel->on_all_desktops = TRUE;
1315 XDeleteProperty (xdisplay,
1317 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1320 toplevel->map_serial = NextRequest (xdisplay);
1324 gdk_window_x11_show (GdkWindow *window, gboolean already_mapped)
1326 GdkWindowObject *private = (GdkWindowObject*) window;
1327 GdkDisplay *display;
1328 GdkDisplayX11 *display_x11;
1329 GdkToplevelX11 *toplevel;
1330 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1331 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1332 Window xwindow = GDK_WINDOW_XID (window);
1335 if (!already_mapped)
1336 set_initial_hints (window);
1338 if (WINDOW_IS_TOPLEVEL (window))
1340 display = gdk_drawable_get_display (window);
1341 display_x11 = GDK_DISPLAY_X11 (display);
1342 toplevel = _gdk_x11_window_get_toplevel (window);
1344 if (toplevel->user_time != 0 &&
1345 display_x11->user_time != 0 &&
1346 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1347 gdk_x11_window_set_user_time (window, display_x11->user_time);
1350 unset_bg = !private->input_only &&
1351 (private->window_type == GDK_WINDOW_CHILD ||
1352 impl->override_redirect) &&
1353 gdk_window_is_viewable (window);
1356 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1358 XMapWindow (xdisplay, xwindow);
1361 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1365 pre_unmap (GdkWindow *window)
1367 GdkWindow *start_window = NULL;
1368 GdkWindowObject *private = (GdkWindowObject *)window;
1370 if (private->input_only)
1373 if (private->window_type == GDK_WINDOW_CHILD)
1374 start_window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
1375 else if (private->window_type == GDK_WINDOW_TEMP)
1376 start_window = get_root (window);
1379 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1383 post_unmap (GdkWindow *window)
1385 GdkWindow *start_window = NULL;
1386 GdkWindowObject *private = (GdkWindowObject *)window;
1388 if (private->input_only)
1391 if (private->window_type == GDK_WINDOW_CHILD)
1392 start_window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
1393 else if (private->window_type == GDK_WINDOW_TEMP)
1394 start_window = get_root (window);
1398 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1400 if (private->window_type == GDK_WINDOW_CHILD && private->parent)
1402 GdkRectangle invalid_rect;
1404 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1405 gdk_drawable_get_size (GDK_DRAWABLE (window),
1406 &invalid_rect.width, &invalid_rect.height);
1407 gdk_window_invalidate_rect ((GdkWindow *)private->parent,
1408 &invalid_rect, TRUE);
1414 gdk_window_x11_hide (GdkWindow *window)
1416 GdkWindowObject *private;
1418 private = (GdkWindowObject*) window;
1420 /* We'll get the unmap notify eventually, and handle it then,
1421 * but checking here makes things more consistent if we are
1422 * just doing stuff ourself.
1424 _gdk_xgrab_check_unmap (window,
1425 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1427 /* You can't simply unmap toplevel windows. */
1428 switch (private->window_type)
1430 case GDK_WINDOW_TOPLEVEL:
1431 case GDK_WINDOW_DIALOG:
1432 case GDK_WINDOW_TEMP: /* ? */
1433 gdk_window_withdraw (window);
1436 case GDK_WINDOW_FOREIGN:
1437 case GDK_WINDOW_ROOT:
1438 case GDK_WINDOW_CHILD:
1442 _gdk_window_clear_update_area (window);
1445 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1446 GDK_WINDOW_XID (window));
1447 post_unmap (window);
1451 gdk_window_x11_withdraw (GdkWindow *window)
1453 GdkWindowObject *private;
1455 private = (GdkWindowObject*) window;
1456 if (!private->destroyed)
1458 if (GDK_WINDOW_IS_MAPPED (window))
1459 gdk_synthesize_window_state (window,
1461 GDK_WINDOW_STATE_WITHDRAWN);
1463 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1467 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1468 GDK_WINDOW_XID (window), 0);
1470 post_unmap (window);
1475 window_x11_move (GdkWindow *window,
1479 GdkWindowObject *private = (GdkWindowObject *) window;
1480 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1482 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1484 _gdk_window_move_resize_child (window,
1486 private->width, private->height);
1490 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1491 GDK_WINDOW_XID (window),
1494 if (impl->override_redirect)
1503 window_x11_resize (GdkWindow *window,
1507 GdkWindowObject *private = (GdkWindowObject *) window;
1515 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1517 _gdk_window_move_resize_child (window,
1518 private->x, private->y,
1523 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1525 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1526 GDK_WINDOW_XID (window),
1529 if (impl->override_redirect)
1531 private->width = width;
1532 private->height = height;
1533 _gdk_x11_drawable_update_size (private->impl);
1537 if (width != private->width || height != private->height)
1538 private->resize_count += 1;
1542 _gdk_x11_drawable_update_size (private->impl);
1546 window_x11_move_resize (GdkWindow *window,
1552 GdkWindowObject *private = (GdkWindowObject *) window;;
1560 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1562 _gdk_window_move_resize_child (window, x, y, width, height);
1563 _gdk_x11_drawable_update_size (private->impl);
1567 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1569 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1570 GDK_WINDOW_XID (window),
1571 x, y, width, height);
1573 if (impl->override_redirect)
1578 private->width = width;
1579 private->height = height;
1581 _gdk_x11_drawable_update_size (private->impl);
1585 if (width != private->width || height != private->height)
1586 private->resize_count += 1;
1592 gdk_window_x11_move_resize (GdkWindow *window,
1599 if (with_move && (width < 0 && height < 0))
1600 window_x11_move (window, x, y);
1604 window_x11_move_resize (window, x, y, width, height);
1606 window_x11_resize (window, width, height);
1611 gdk_window_x11_reparent (GdkWindow *window,
1612 GdkWindow *new_parent,
1616 GdkWindowObject *window_private;
1617 GdkWindowObject *parent_private;
1618 GdkWindowImplX11 *impl;
1620 window_private = (GdkWindowObject*) window;
1621 parent_private = (GdkWindowObject*) new_parent;
1622 impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
1624 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1625 _gdk_x11_window_tmp_unset_parent_bg (window);
1626 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1627 GDK_WINDOW_XID (window),
1628 GDK_WINDOW_XID (new_parent),
1629 parent_private->abs_x + x, parent_private->abs_y + y);
1630 _gdk_x11_window_tmp_reset_parent_bg (window);
1631 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1633 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1634 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1636 window_private->parent = parent_private;
1638 /* Switch the window type as appropriate */
1640 switch (GDK_WINDOW_TYPE (new_parent))
1642 case GDK_WINDOW_ROOT:
1643 case GDK_WINDOW_FOREIGN:
1644 /* Reparenting to toplevel */
1646 if (!WINDOW_IS_TOPLEVEL (window) &&
1647 GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1649 /* This is also done in common code at a later stage, but we
1650 need it in setup_toplevel, so do it here too */
1651 if (window_private->toplevel_window_type != -1)
1652 GDK_WINDOW_TYPE (window) = window_private->toplevel_window_type;
1653 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1654 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1656 /* Wasn't a toplevel, set up */
1657 setup_toplevel_window (window, new_parent);
1662 case GDK_WINDOW_TOPLEVEL:
1663 case GDK_WINDOW_CHILD:
1664 case GDK_WINDOW_DIALOG:
1665 case GDK_WINDOW_TEMP:
1666 if (WINDOW_IS_TOPLEVEL (window) &&
1669 if (impl->toplevel->focus_window)
1671 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1672 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1675 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1677 g_free (impl->toplevel);
1678 impl->toplevel = NULL;
1686 gdk_window_x11_clear_region (GdkWindow *window,
1688 gboolean send_expose)
1690 cairo_rectangle_int_t rect;
1693 n_rects = cairo_region_num_rectangles (region);
1695 for (i = 0; i < n_rects; i++)
1697 cairo_region_get_rectangle (region, i, &rect);
1698 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1700 rect.width, rect.height,
1706 gdk_window_x11_raise (GdkWindow *window)
1708 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1712 gdk_window_x11_restack_under (GdkWindow *window,
1713 GList *native_siblings /* in requested order, first is bottom-most */)
1719 n_windows = g_list_length (native_siblings) + 1;
1720 windows = g_new (Window, n_windows);
1722 windows[0] = GDK_WINDOW_XID (window);
1723 /* Reverse order, as input order is bottom-most first */
1725 for (l = native_siblings; l != NULL; l = l->next)
1726 windows[i--] = GDK_WINDOW_XID (l->data);
1728 XRestackWindows (GDK_WINDOW_XDISPLAY (window), windows, n_windows);
1734 gdk_window_x11_restack_toplevel (GdkWindow *window,
1738 XWindowChanges changes;
1740 changes.sibling = GDK_WINDOW_XID (sibling);
1741 changes.stack_mode = above ? Above : Below;
1742 XReconfigureWMWindow (GDK_WINDOW_XDISPLAY (window),
1743 GDK_WINDOW_XID (window),
1744 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)),
1745 CWStackMode | CWSibling, &changes);
1749 gdk_window_x11_lower (GdkWindow *window)
1751 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1755 * gdk_x11_window_move_to_current_desktop:
1756 * @window: a #GdkWindow
1758 * Moves the window to the correct workspace when running under a
1759 * window manager that supports multiple workspaces, as described
1760 * in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
1761 * Window Manager Hints</ulink>. Will not do anything if the
1762 * window is already on all workspaces.
1767 gdk_x11_window_move_to_current_desktop (GdkWindow *window)
1769 GdkToplevelX11 *toplevel;
1771 g_return_if_fail (GDK_IS_WINDOW (window));
1772 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1774 toplevel = _gdk_x11_window_get_toplevel (window);
1776 if (toplevel->on_all_desktops)
1779 move_to_current_desktop (window);
1783 move_to_current_desktop (GdkWindow *window)
1785 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1786 gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
1793 gulong *current_desktop;
1794 GdkDisplay *display;
1796 display = gdk_drawable_get_display (window);
1798 /* Get current desktop, then set it; this is a race, but not
1799 * one that matters much in practice.
1801 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
1802 GDK_WINDOW_XROOTWIN (window),
1803 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
1805 False, XA_CARDINAL, &type, &format, &nitems,
1806 &bytes_after, &data);
1808 if (type == XA_CARDINAL)
1810 XClientMessageEvent xclient;
1811 current_desktop = (gulong *)data;
1813 memset (&xclient, 0, sizeof (xclient));
1814 xclient.type = ClientMessage;
1816 xclient.send_event = True;
1817 xclient.window = GDK_WINDOW_XWINDOW (window);
1818 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
1819 xclient.format = 32;
1821 xclient.data.l[0] = *current_desktop;
1822 xclient.data.l[1] = 0;
1823 xclient.data.l[2] = 0;
1824 xclient.data.l[3] = 0;
1825 xclient.data.l[4] = 0;
1827 XSendEvent (GDK_DISPLAY_XDISPLAY (display),
1828 GDK_WINDOW_XROOTWIN (window),
1830 SubstructureRedirectMask | SubstructureNotifyMask,
1831 (XEvent *)&xclient);
1833 XFree (current_desktop);
1840 * @window: a #GdkWindow
1841 * @timestamp: timestamp of the event triggering the window focus
1843 * Sets keyboard focus to @window. In most cases, gtk_window_present()
1844 * should be used on a #GtkWindow, rather than calling this function.
1848 gdk_window_focus (GdkWindow *window,
1851 GdkDisplay *display;
1853 g_return_if_fail (GDK_IS_WINDOW (window));
1855 if (GDK_WINDOW_DESTROYED (window) ||
1856 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1859 display = GDK_WINDOW_DISPLAY (window);
1861 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1862 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
1864 XClientMessageEvent xclient;
1866 memset (&xclient, 0, sizeof (xclient));
1867 xclient.type = ClientMessage;
1868 xclient.window = GDK_WINDOW_XWINDOW (window);
1869 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1870 "_NET_ACTIVE_WINDOW");
1871 xclient.format = 32;
1872 xclient.data.l[0] = 1; /* requestor type; we're an app */
1873 xclient.data.l[1] = timestamp;
1874 xclient.data.l[2] = None; /* currently active window */
1875 xclient.data.l[3] = 0;
1876 xclient.data.l[4] = 0;
1878 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1879 SubstructureRedirectMask | SubstructureNotifyMask,
1880 (XEvent *)&xclient);
1884 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1886 /* There is no way of knowing reliably whether we are viewable;
1887 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1889 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1896 * gdk_window_set_type_hint:
1897 * @window: A toplevel #GdkWindow
1898 * @hint: A hint of the function this window will have
1900 * The application can use this call to provide a hint to the window
1901 * manager about the functionality of a window. The window manager
1902 * can use this information when determining the decoration and behaviour
1905 * The hint must be set before the window is mapped.
1908 gdk_window_set_type_hint (GdkWindow *window,
1909 GdkWindowTypeHint hint)
1911 GdkDisplay *display;
1914 if (GDK_WINDOW_DESTROYED (window) ||
1915 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1918 display = gdk_drawable_get_display (window);
1922 case GDK_WINDOW_TYPE_HINT_DIALOG:
1923 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1925 case GDK_WINDOW_TYPE_HINT_MENU:
1926 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1928 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1929 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1931 case GDK_WINDOW_TYPE_HINT_UTILITY:
1932 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1934 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1935 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1937 case GDK_WINDOW_TYPE_HINT_DOCK:
1938 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1940 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1941 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1943 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
1944 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
1946 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
1947 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
1949 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
1950 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
1952 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
1953 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
1955 case GDK_WINDOW_TYPE_HINT_COMBO:
1956 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
1958 case GDK_WINDOW_TYPE_HINT_DND:
1959 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
1962 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1964 case GDK_WINDOW_TYPE_HINT_NORMAL:
1965 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1969 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1970 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1971 XA_ATOM, 32, PropModeReplace,
1972 (guchar *)&atom, 1);
1976 * gdk_window_get_type_hint:
1977 * @window: A toplevel #GdkWindow
1979 * This function returns the type hint set for a window.
1981 * Return value: The type hint set for @window
1986 gdk_window_get_type_hint (GdkWindow *window)
1988 GdkDisplay *display;
1989 GdkWindowTypeHint type;
1992 gulong nitems_return;
1993 gulong bytes_after_return;
1994 guchar *data = NULL;
1996 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
1998 if (GDK_WINDOW_DESTROYED (window) ||
1999 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2000 return GDK_WINDOW_TYPE_HINT_NORMAL;
2002 type = GDK_WINDOW_TYPE_HINT_NORMAL;
2004 display = gdk_drawable_get_display (window);
2006 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2007 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
2008 0, G_MAXLONG, False, XA_ATOM, &type_return,
2009 &format_return, &nitems_return, &bytes_after_return,
2012 if ((type_return == XA_ATOM) && (format_return == 32) &&
2013 (data) && (nitems_return == 1))
2015 Atom atom = *(Atom*)data;
2017 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
2018 type = GDK_WINDOW_TYPE_HINT_DIALOG;
2019 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
2020 type = GDK_WINDOW_TYPE_HINT_MENU;
2021 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
2022 type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
2023 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
2024 type = GDK_WINDOW_TYPE_HINT_UTILITY;
2025 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
2026 type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
2027 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
2028 type = GDK_WINDOW_TYPE_HINT_DOCK;
2029 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
2030 type = GDK_WINDOW_TYPE_HINT_DESKTOP;
2031 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
2032 type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
2033 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
2034 type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
2035 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
2036 type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
2037 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
2038 type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
2039 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
2040 type = GDK_WINDOW_TYPE_HINT_COMBO;
2041 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
2042 type = GDK_WINDOW_TYPE_HINT_DND;
2045 if (type_return != None && data != NULL)
2053 gdk_wmspec_change_state (gboolean add,
2058 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
2059 XClientMessageEvent xclient;
2061 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
2062 #define _NET_WM_STATE_ADD 1 /* add/set property */
2063 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
2065 memset (&xclient, 0, sizeof (xclient));
2066 xclient.type = ClientMessage;
2067 xclient.window = GDK_WINDOW_XID (window);
2068 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
2069 xclient.format = 32;
2070 xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
2071 xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
2072 xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
2073 xclient.data.l[3] = 0;
2074 xclient.data.l[4] = 0;
2076 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
2077 SubstructureRedirectMask | SubstructureNotifyMask,
2078 (XEvent *)&xclient);
2082 * gdk_window_set_modal_hint:
2083 * @window: A toplevel #GdkWindow
2084 * @modal: %TRUE if the window is modal, %FALSE otherwise.
2086 * The application can use this hint to tell the window manager
2087 * that a certain window has modal behaviour. The window manager
2088 * can use this information to handle modal windows in a special
2091 * You should only use this on windows for which you have
2092 * previously called gdk_window_set_transient_for()
2095 gdk_window_set_modal_hint (GdkWindow *window,
2098 GdkWindowObject *private;
2100 if (GDK_WINDOW_DESTROYED (window) ||
2101 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2104 private = (GdkWindowObject*) window;
2106 private->modal_hint = modal;
2108 if (GDK_WINDOW_IS_MAPPED (window))
2109 gdk_wmspec_change_state (modal, window,
2110 gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
2115 * gdk_window_set_skip_taskbar_hint:
2116 * @window: a toplevel #GdkWindow
2117 * @skips_taskbar: %TRUE to skip the taskbar
2119 * Toggles whether a window should appear in a task list or window
2120 * list. If a window's semantic type as specified with
2121 * gdk_window_set_type_hint() already fully describes the window, this
2122 * function should <emphasis>not</emphasis> be called in addition,
2123 * instead you should allow the window to be treated according to
2124 * standard policy for its semantic type.
2129 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2130 gboolean skips_taskbar)
2132 GdkToplevelX11 *toplevel;
2134 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2136 if (GDK_WINDOW_DESTROYED (window) ||
2137 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2140 toplevel = _gdk_x11_window_get_toplevel (window);
2141 toplevel->skip_taskbar_hint = skips_taskbar;
2143 if (GDK_WINDOW_IS_MAPPED (window))
2144 gdk_wmspec_change_state (skips_taskbar, window,
2145 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
2150 * gdk_window_set_skip_pager_hint:
2151 * @window: a toplevel #GdkWindow
2152 * @skips_pager: %TRUE to skip the pager
2154 * Toggles whether a window should appear in a pager (workspace
2155 * switcher, or other desktop utility program that displays a small
2156 * thumbnail representation of the windows on the desktop). If a
2157 * window's semantic type as specified with gdk_window_set_type_hint()
2158 * already fully describes the window, this function should
2159 * <emphasis>not</emphasis> be called in addition, instead you should
2160 * allow the window to be treated according to standard policy for
2161 * its semantic type.
2166 gdk_window_set_skip_pager_hint (GdkWindow *window,
2167 gboolean skips_pager)
2169 GdkToplevelX11 *toplevel;
2171 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2173 if (GDK_WINDOW_DESTROYED (window) ||
2174 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2177 toplevel = _gdk_x11_window_get_toplevel (window);
2178 toplevel->skip_pager_hint = skips_pager;
2180 if (GDK_WINDOW_IS_MAPPED (window))
2181 gdk_wmspec_change_state (skips_pager, window,
2182 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
2187 * gdk_window_set_urgency_hint:
2188 * @window: a toplevel #GdkWindow
2189 * @urgent: %TRUE if the window is urgent
2191 * Toggles whether a window needs the user's
2197 gdk_window_set_urgency_hint (GdkWindow *window,
2200 GdkToplevelX11 *toplevel;
2202 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2204 if (GDK_WINDOW_DESTROYED (window) ||
2205 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2208 toplevel = _gdk_x11_window_get_toplevel (window);
2209 toplevel->urgency_hint = urgent;
2211 update_wm_hints (window, FALSE);
2215 * gdk_window_set_geometry_hints:
2216 * @window: a toplevel #GdkWindow
2217 * @geometry: geometry hints
2218 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
2220 * Sets the geometry hints for @window. Hints flagged in @geom_mask
2221 * are set, hints not flagged in @geom_mask are unset.
2222 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
2224 * This function provides hints to the windowing system about
2225 * acceptable sizes for a toplevel window. The purpose of
2226 * this is to constrain user resizing, but the windowing system
2227 * will typically (but is not required to) also constrain the
2228 * current size of the window to the provided values and
2229 * constrain programatic resizing via gdk_window_resize() or
2230 * gdk_window_move_resize().
2232 * Note that on X11, this effect has no effect on windows
2233 * of type %GDK_WINDOW_TEMP or windows where override redirect
2234 * has been turned on via gdk_window_set_override_redirect()
2235 * since these windows are not resizable by the user.
2237 * Since you can't count on the windowing system doing the
2238 * constraints for programmatic resizes, you should generally
2239 * call gdk_window_constrain_size() yourself to determine
2240 * appropriate sizes.
2244 gdk_window_set_geometry_hints (GdkWindow *window,
2245 const GdkGeometry *geometry,
2246 GdkWindowHints geom_mask)
2248 XSizeHints size_hints;
2250 if (GDK_WINDOW_DESTROYED (window) ||
2251 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2254 size_hints.flags = 0;
2256 if (geom_mask & GDK_HINT_POS)
2258 size_hints.flags |= PPosition;
2259 /* We need to initialize the following obsolete fields because KWM
2260 * apparently uses these fields if they are non-zero.
2267 if (geom_mask & GDK_HINT_USER_POS)
2269 size_hints.flags |= USPosition;
2272 if (geom_mask & GDK_HINT_USER_SIZE)
2274 size_hints.flags |= USSize;
2277 if (geom_mask & GDK_HINT_MIN_SIZE)
2279 size_hints.flags |= PMinSize;
2280 size_hints.min_width = geometry->min_width;
2281 size_hints.min_height = geometry->min_height;
2284 if (geom_mask & GDK_HINT_MAX_SIZE)
2286 size_hints.flags |= PMaxSize;
2287 size_hints.max_width = MAX (geometry->max_width, 1);
2288 size_hints.max_height = MAX (geometry->max_height, 1);
2291 if (geom_mask & GDK_HINT_BASE_SIZE)
2293 size_hints.flags |= PBaseSize;
2294 size_hints.base_width = geometry->base_width;
2295 size_hints.base_height = geometry->base_height;
2298 if (geom_mask & GDK_HINT_RESIZE_INC)
2300 size_hints.flags |= PResizeInc;
2301 size_hints.width_inc = geometry->width_inc;
2302 size_hints.height_inc = geometry->height_inc;
2305 if (geom_mask & GDK_HINT_ASPECT)
2307 size_hints.flags |= PAspect;
2308 if (geometry->min_aspect <= 1)
2310 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2311 size_hints.min_aspect.y = 65536;
2315 size_hints.min_aspect.x = 65536;
2316 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2318 if (geometry->max_aspect <= 1)
2320 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2321 size_hints.max_aspect.y = 65536;
2325 size_hints.max_aspect.x = 65536;
2326 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2330 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2332 size_hints.flags |= PWinGravity;
2333 size_hints.win_gravity = geometry->win_gravity;
2336 /* FIXME: Would it be better to delete this property if
2337 * geom_mask == 0? It would save space on the server
2339 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2340 GDK_WINDOW_XID (window),
2345 gdk_window_get_geometry_hints (GdkWindow *window,
2346 GdkGeometry *geometry,
2347 GdkWindowHints *geom_mask)
2349 XSizeHints *size_hints;
2350 glong junk_supplied_mask = 0;
2352 g_return_if_fail (GDK_IS_WINDOW (window));
2353 g_return_if_fail (geometry != NULL);
2354 g_return_if_fail (geom_mask != NULL);
2358 if (GDK_WINDOW_DESTROYED (window) ||
2359 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2362 size_hints = XAllocSizeHints ();
2366 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2367 GDK_WINDOW_XID (window),
2369 &junk_supplied_mask))
2370 size_hints->flags = 0;
2372 if (size_hints->flags & PMinSize)
2374 *geom_mask |= GDK_HINT_MIN_SIZE;
2375 geometry->min_width = size_hints->min_width;
2376 geometry->min_height = size_hints->min_height;
2379 if (size_hints->flags & PMaxSize)
2381 *geom_mask |= GDK_HINT_MAX_SIZE;
2382 geometry->max_width = MAX (size_hints->max_width, 1);
2383 geometry->max_height = MAX (size_hints->max_height, 1);
2386 if (size_hints->flags & PResizeInc)
2388 *geom_mask |= GDK_HINT_RESIZE_INC;
2389 geometry->width_inc = size_hints->width_inc;
2390 geometry->height_inc = size_hints->height_inc;
2393 if (size_hints->flags & PAspect)
2395 *geom_mask |= GDK_HINT_ASPECT;
2397 geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y;
2398 geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y;
2401 if (size_hints->flags & PWinGravity)
2403 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2404 geometry->win_gravity = size_hints->win_gravity;
2411 utf8_is_latin1 (const gchar *str)
2413 const char *p = str;
2417 gunichar ch = g_utf8_get_char (p);
2422 p = g_utf8_next_char (p);
2428 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2429 * convertable to STRING, otherwise, set it as compound text
2432 set_text_property (GdkDisplay *display,
2435 const gchar *utf8_str)
2437 gchar *prop_text = NULL;
2441 gboolean is_compound_text;
2443 if (utf8_is_latin1 (utf8_str))
2445 prop_type = XA_STRING;
2446 prop_text = gdk_utf8_to_string_target (utf8_str);
2447 prop_length = prop_text ? strlen (prop_text) : 0;
2449 is_compound_text = FALSE;
2455 gdk_utf8_to_compound_text_for_display (display,
2456 utf8_str, &gdk_type, &prop_format,
2457 (guchar **)&prop_text, &prop_length);
2458 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2459 is_compound_text = TRUE;
2464 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2467 prop_type, prop_format,
2468 PropModeReplace, (guchar *)prop_text,
2471 if (is_compound_text)
2472 gdk_free_compound_text ((guchar *)prop_text);
2478 /* Set WM_NAME and _NET_WM_NAME
2481 set_wm_name (GdkDisplay *display,
2485 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2486 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2487 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2488 PropModeReplace, (guchar *)name, strlen (name));
2490 set_text_property (display, xwindow,
2491 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2496 * gdk_window_set_title:
2497 * @window: a toplevel #GdkWindow
2498 * @title: title of @window
2500 * Sets the title of a toplevel window, to be displayed in the titlebar.
2501 * If you haven't explicitly set the icon name for the window
2502 * (using gdk_window_set_icon_name()), the icon name will be set to
2503 * @title as well. @title must be in UTF-8 encoding (as with all
2504 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2507 gdk_window_set_title (GdkWindow *window,
2510 GdkDisplay *display;
2514 g_return_if_fail (title != NULL);
2516 if (GDK_WINDOW_DESTROYED (window) ||
2517 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2520 display = gdk_drawable_get_display (window);
2521 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2522 xwindow = GDK_WINDOW_XID (window);
2524 set_wm_name (display, xwindow, title);
2526 if (!gdk_window_icon_name_set (window))
2528 XChangeProperty (xdisplay, xwindow,
2529 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2530 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2531 PropModeReplace, (guchar *)title, strlen (title));
2533 set_text_property (display, xwindow,
2534 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2540 * gdk_window_set_role:
2541 * @window: a toplevel #GdkWindow
2542 * @role: a string indicating its role
2544 * When using GTK+, typically you should use gtk_window_set_role() instead
2545 * of this low-level function.
2547 * The window manager and session manager use a window's role to
2548 * distinguish it from other kinds of window in the same application.
2549 * When an application is restarted after being saved in a previous
2550 * session, all windows with the same title and role are treated as
2551 * interchangeable. So if you have two windows with the same title
2552 * that should be distinguished for session management purposes, you
2553 * should set the role on those windows. It doesn't matter what string
2554 * you use for the role, as long as you have a different role for each
2555 * non-interchangeable kind of window.
2559 gdk_window_set_role (GdkWindow *window,
2562 GdkDisplay *display;
2564 display = gdk_drawable_get_display (window);
2566 if (GDK_WINDOW_DESTROYED (window) ||
2567 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2571 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2572 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2573 XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
2575 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2576 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2580 * gdk_window_set_startup_id:
2581 * @window: a toplevel #GdkWindow
2582 * @startup_id: a string with startup-notification identifier
2584 * When using GTK+, typically you should use gtk_window_set_startup_id()
2585 * instead of this low-level function.
2591 gdk_window_set_startup_id (GdkWindow *window,
2592 const gchar *startup_id)
2594 GdkDisplay *display;
2596 g_return_if_fail (GDK_IS_WINDOW (window));
2598 display = gdk_drawable_get_display (window);
2600 if (GDK_WINDOW_DESTROYED (window) ||
2601 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2605 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2606 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2607 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2608 PropModeReplace, (unsigned char *)startup_id, strlen (startup_id));
2610 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2611 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"));
2615 * gdk_window_set_transient_for:
2616 * @window: a toplevel #GdkWindow
2617 * @parent: another toplevel #GdkWindow
2619 * Indicates to the window manager that @window is a transient dialog
2620 * associated with the application window @parent. This allows the
2621 * window manager to do things like center @window on @parent and
2622 * keep @window above @parent.
2624 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2628 gdk_window_set_transient_for (GdkWindow *window,
2631 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) &&
2632 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2633 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2634 GDK_WINDOW_XID (window),
2635 GDK_WINDOW_XID (parent));
2639 gdk_window_x11_set_background (GdkWindow *window,
2640 const GdkColor *color)
2642 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2643 GDK_WINDOW_XID (window), color->pixel);
2647 gdk_window_x11_set_back_pixmap (GdkWindow *window,
2652 if (pixmap == GDK_PARENT_RELATIVE_BG)
2653 xpixmap = ParentRelative;
2654 else if (pixmap == GDK_NO_BG)
2657 xpixmap = GDK_PIXMAP_XID (pixmap);
2659 if (!GDK_WINDOW_DESTROYED (window))
2660 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2661 GDK_WINDOW_XID (window), xpixmap);
2665 gdk_window_x11_set_device_cursor (GdkWindow *window,
2669 GdkWindowObject *private;
2670 GdkWindowImplX11 *impl;
2672 g_return_if_fail (GDK_IS_WINDOW (window));
2673 g_return_if_fail (GDK_IS_DEVICE (device));
2675 private = (GdkWindowObject *) window;
2676 impl = GDK_WINDOW_IMPL_X11 (private->impl);
2679 g_hash_table_remove (impl->device_cursor, device);
2682 _gdk_x11_cursor_update_theme (cursor);
2683 g_hash_table_replace (impl->device_cursor,
2684 device, gdk_cursor_ref (cursor));
2687 if (!GDK_WINDOW_DESTROYED (window))
2688 GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor);
2692 _gdk_x11_window_get_cursor (GdkWindow *window)
2694 GdkWindowObject *private;
2695 GdkWindowImplX11 *impl;
2697 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2699 private = (GdkWindowObject *)window;
2700 impl = GDK_WINDOW_IMPL_X11 (private->impl);
2702 return impl->cursor;
2706 gdk_window_x11_get_geometry (GdkWindow *window,
2718 guint tborder_width;
2721 if (!GDK_WINDOW_DESTROYED (window))
2723 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2724 GDK_WINDOW_XID (window),
2725 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2741 gdk_window_x11_get_root_coords (GdkWindow *window,
2752 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2753 GDK_WINDOW_XID (window),
2754 GDK_WINDOW_XROOTWIN (window),
2767 gdk_window_x11_get_deskrelative_origin (GdkWindow *window,
2771 gboolean return_val = FALSE;
2772 gint num_children, format_return;
2773 Window win, *child, parent, root;
2776 gulong number_return, bytes_after_return;
2777 guchar *data_return;
2779 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2780 "ENLIGHTENMENT_DESKTOP");
2781 win = GDK_WINDOW_XID (window);
2783 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2784 &child, (unsigned int *)&num_children))
2786 if ((child) && (num_children > 0))
2798 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2799 False, XA_CARDINAL, &type_return, &format_return,
2800 &number_return, &bytes_after_return, &data_return);
2802 if (type_return == XA_CARDINAL)
2804 XFree (data_return);
2809 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2810 GDK_WINDOW_XID (window),
2819 * gdk_window_get_root_origin:
2820 * @window: a toplevel #GdkWindow
2821 * @x: return location for X position of window frame
2822 * @y: return location for Y position of window frame
2824 * Obtains the top-left corner of the window manager frame in root
2825 * window coordinates.
2829 gdk_window_get_root_origin (GdkWindow *window,
2835 gdk_window_get_frame_extents (window, &rect);
2845 * gdk_window_get_frame_extents:
2846 * @window: a toplevel #GdkWindow
2847 * @rect: rectangle to fill with bounding box of the window frame
2849 * Obtains the bounding box of the window, including window manager
2850 * titlebar/borders if any. The frame position is given in root window
2851 * coordinates. To get the position of the window itself (rather than
2852 * the frame) in root window coordinates, use gdk_window_get_origin().
2856 gdk_window_get_frame_extents (GdkWindow *window,
2859 GdkDisplay *display;
2860 GdkWindowObject *private;
2861 GdkWindowImplX11 *impl;
2872 gulong nitems_return;
2873 gulong bytes_after_return;
2876 guint ww, wh, wb, wd;
2878 gboolean got_frame_extents = FALSE;
2880 g_return_if_fail (rect != NULL);
2882 private = (GdkWindowObject*) window;
2889 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2890 private = (GdkWindowObject*) private->parent;
2892 /* Refine our fallback answer a bit using local information */
2893 rect->x = private->x;
2894 rect->y = private->y;
2895 gdk_drawable_get_size ((GdkDrawable *)private, &rect->width, &rect->height);
2897 impl = GDK_WINDOW_IMPL_X11 (private->impl);
2898 if (GDK_WINDOW_DESTROYED (private) || impl->override_redirect)
2904 gdk_error_trap_push();
2906 display = gdk_drawable_get_display (window);
2907 xwindow = GDK_WINDOW_XID (window);
2909 /* first try: use _NET_FRAME_EXTENTS */
2910 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2911 gdk_x11_get_xatom_by_name_for_display (display,
2912 "_NET_FRAME_EXTENTS"),
2913 0, G_MAXLONG, False, XA_CARDINAL, &type_return,
2914 &format_return, &nitems_return, &bytes_after_return,
2918 if ((type_return == XA_CARDINAL) && (format_return == 32) &&
2919 (nitems_return == 4) && (data))
2921 gulong *ldata = (gulong *) data;
2922 got_frame_extents = TRUE;
2924 /* try to get the real client window geometry */
2925 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2926 &root, &wx, &wy, &ww, &wh, &wb, &wd) &&
2927 XTranslateCoordinates (GDK_DISPLAY_XDISPLAY (display),
2928 xwindow, root, 0, 0, &wx, &wy, &child))
2936 /* _NET_FRAME_EXTENTS format is left, right, top, bottom */
2937 rect->x -= ldata[0];
2938 rect->y -= ldata[2];
2939 rect->width += ldata[0] + ldata[1];
2940 rect->height += ldata[2] + ldata[3];
2947 if (got_frame_extents)
2950 /* no frame extents property available, which means we either have a WM that
2951 is not EWMH compliant or is broken - try fallback and walk up the window
2952 tree to get our window's parent which hopefully is the window frame */
2954 /* use NETWM_VIRTUAL_ROOTS if available */
2955 root = GDK_WINDOW_XROOTWIN (window);
2957 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
2958 gdk_x11_get_xatom_by_name_for_display (display,
2959 "_NET_VIRTUAL_ROOTS"),
2960 0, G_MAXLONG, False, XA_WINDOW, &type_return,
2961 &format_return, &nitems_return, &bytes_after_return,
2965 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
2967 nvroots = nitems_return;
2968 vroots = (Window *)data;
2972 xparent = GDK_WINDOW_XID (window);
2978 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
2980 &children, &nchildren))
2986 /* check virtual roots */
2987 for (i = 0; i < nvroots; i++)
2989 if (xparent == vroots[i])
2996 while (xparent != root);
2998 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2999 &root, &wx, &wy, &ww, &wh, &wb, &wd))
3011 gdk_error_trap_pop ();
3015 _gdk_windowing_get_device_state (GdkDisplay *display,
3020 GdkModifierType *mask)
3022 GdkScreen *default_screen;
3024 if (display->closed)
3027 default_screen = gdk_display_get_default_screen (display);
3030 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3034 GDK_DEVICE_GET_CLASS (device)->query_state (device,
3035 gdk_screen_get_root_window (default_screen),
3040 *screen = gdk_drawable_get_screen (root);
3044 XSetWindowAttributes attributes;
3046 Window xwindow, w, root, child;
3047 int rootx, rooty, winx, winy;
3050 /* FIXME: untrusted clients not multidevice-safe */
3052 xdisplay = GDK_SCREEN_XDISPLAY (default_screen);
3053 xwindow = GDK_SCREEN_XROOTWIN (default_screen);
3055 w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0,
3056 CopyFromParent, InputOnly, CopyFromParent,
3058 XQueryPointer (xdisplay, w,
3059 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3060 XDestroyWindow (xdisplay, w);
3064 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
3065 *screen = gdk_drawable_get_screen (gdk_root);
3075 gdk_window_x11_get_device_state (GdkWindow *window,
3079 GdkModifierType *mask)
3081 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
3082 gboolean return_val;
3084 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
3088 if (!GDK_WINDOW_DESTROYED (window))
3090 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3094 GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
3098 return_val = (child != NULL);
3103 int originx, originy;
3107 unsigned int xmask = 0;
3109 _gdk_windowing_get_device_state (gdk_drawable_get_display (window), device,
3110 &screen, &rootx, &rooty, &xmask);
3111 gdk_window_get_origin (window, &originx, &originy);
3112 winx = rootx - originx;
3113 winy = rooty - originy;
3125 * gdk_display_warp_pointer:
3126 * @display: a #GdkDisplay
3127 * @screen: the screen of @display to warp the pointer to
3128 * @x: the x coordinate of the destination
3129 * @y: the y coordinate of the destination
3131 * Warps the pointer of @display to the point @x,@y on
3132 * the screen @screen, unless the pointer is confined
3133 * to a window by a grab, in which case it will be moved
3134 * as far as allowed by the grab. Warping the pointer
3135 * creates events as if the user had moved the mouse
3136 * instantaneously to the destination.
3138 * Note that the pointer should normally be under the
3139 * control of the user. This function was added to cover
3140 * some rare use cases like keyboard navigation support
3141 * for the color picker in the #GtkColorSelectionDialog.
3145 * Deprecated: 3.0: Use gdk_display_warp_device() instead.
3148 gdk_display_warp_pointer (GdkDisplay *display,
3155 g_return_if_fail (GDK_IS_DISPLAY (display));
3156 g_return_if_fail (GDK_IS_SCREEN (screen));
3158 device = display->core_pointer;
3159 GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
3163 * gdk_display_warp_device:
3164 * @display: a #GdkDisplay.
3165 * @device: a #GdkDevice.
3166 * @screen: the screen of @display to warp @device to.
3167 * @x: the X coordinate of the destination.
3168 * @y: the Y coordinate of the destination.
3170 * Warps @device in @display to the point @x,@y on
3171 * the screen @screen, unless the device is confined
3172 * to a window by a grab, in which case it will be moved
3173 * as far as allowed by the grab. Warping the pointer
3174 * creates events as if the user had moved the mouse
3175 * instantaneously to the destination.
3177 * Note that the pointer should normally be under the
3178 * control of the user. This function was added to cover
3179 * some rare use cases like keyboard navigation support
3180 * for the color picker in the #GtkColorSelectionDialog.
3185 gdk_display_warp_device (GdkDisplay *display,
3191 g_return_if_fail (GDK_IS_DISPLAY (display));
3192 g_return_if_fail (GDK_IS_DEVICE (device));
3193 g_return_if_fail (GDK_IS_SCREEN (screen));
3194 g_return_if_fail (display == gdk_device_get_display (device));
3196 GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
3200 _gdk_windowing_window_at_device_position (GdkDisplay *display,
3204 GdkModifierType *mask,
3205 gboolean get_toplevel)
3210 screen = gdk_display_get_default_screen (display);
3212 /* This function really only works if the mouse pointer is held still
3213 * during its operation. If it moves from one leaf window to another
3214 * than we'll end up with inaccurate values for win_x, win_y
3217 gdk_x11_display_grab (display);
3218 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3219 window = GDK_DEVICE_GET_CLASS (device)->window_at_position (device, win_x, win_y, mask, get_toplevel);
3222 gint i, screens, width, height;
3223 GList *toplevels, *list;
3224 Window pointer_window, root, xwindow, child;
3225 Window xwindow_last = 0;
3227 int rootx = -1, rooty = -1;
3231 /* FIXME: untrusted clients case not multidevice-safe */
3233 xwindow = GDK_SCREEN_XROOTWIN (screen);
3234 xdisplay = GDK_SCREEN_XDISPLAY (screen);
3236 pointer_window = None;
3237 screens = gdk_display_get_n_screens (display);
3238 for (i = 0; i < screens; ++i) {
3239 screen = gdk_display_get_screen (display, i);
3240 toplevels = gdk_screen_get_toplevel_windows (screen);
3241 for (list = toplevels; list != NULL; list = g_list_next (list)) {
3242 window = GDK_WINDOW (list->data);
3243 xwindow = GDK_WINDOW_XWINDOW (window);
3244 gdk_error_trap_push ();
3245 XQueryPointer (xdisplay, xwindow,
3246 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3248 if (gdk_error_trap_pop ())
3252 pointer_window = child;
3255 gdk_window_get_geometry (window, NULL, NULL, &width, &height, NULL);
3256 if (winx >= 0 && winy >= 0 && winx < width && winy < height)
3258 /* A childless toplevel, or below another window? */
3259 XSetWindowAttributes attributes;
3262 w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0,
3263 CopyFromParent, InputOnly, CopyFromParent,
3265 XMapWindow (xdisplay, w);
3266 XQueryPointer (xdisplay, xwindow,
3267 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3268 XDestroyWindow (xdisplay, w);
3271 pointer_window = xwindow;
3276 g_list_free (toplevels);
3277 if (pointer_window != None)
3280 xwindow = pointer_window;
3284 xwindow_last = xwindow;
3285 gdk_error_trap_push ();
3286 XQueryPointer (xdisplay, xwindow,
3287 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3289 if (gdk_error_trap_pop ())
3291 if (get_toplevel && xwindow_last != root &&
3292 (window = gdk_window_lookup_for_display (display, xwindow_last)) != NULL &&
3293 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
3297 window = gdk_window_lookup_for_display (display, xwindow_last);
3299 *win_x = window ? winx : -1;
3300 *win_y = window ? winy : -1;
3305 gdk_x11_display_ungrab (display);
3311 gdk_window_x11_get_events (GdkWindow *window)
3313 XWindowAttributes attrs;
3314 GdkEventMask event_mask;
3315 GdkEventMask filtered;
3317 if (GDK_WINDOW_DESTROYED (window))
3321 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3322 GDK_WINDOW_XID (window),
3324 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
3325 /* if property change was filtered out before, keep it filtered out */
3326 filtered = GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK;
3327 GDK_WINDOW_OBJECT (window)->event_mask = event_mask & ((GDK_WINDOW_OBJECT (window)->event_mask & filtered) | ~filtered);
3333 gdk_window_x11_set_events (GdkWindow *window,
3334 GdkEventMask event_mask)
3336 long xevent_mask = 0;
3338 if (!GDK_WINDOW_DESTROYED (window))
3340 GdkDisplayX11 *display_x11;
3342 if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window))
3343 xevent_mask = StructureNotifyMask | PropertyChangeMask;
3345 display_x11 = GDK_DISPLAY_X11 (gdk_drawable_get_display (window));
3346 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
3347 GDK_WINDOW_XWINDOW (window), event_mask,
3353 gdk_window_add_colormap_windows (GdkWindow *window)
3355 GdkWindow *toplevel;
3356 Window *old_windows;
3357 Window *new_windows;
3360 g_return_if_fail (GDK_IS_WINDOW (window));
3362 if (GDK_WINDOW_DESTROYED (window))
3365 toplevel = gdk_window_get_toplevel (window);
3368 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3369 GDK_WINDOW_XID (toplevel),
3370 &old_windows, &count))
3375 for (i = 0; i < count; i++)
3376 if (old_windows[i] == GDK_WINDOW_XID (window))
3378 XFree (old_windows);
3382 new_windows = g_new (Window, count + 1);
3384 for (i = 0; i < count; i++)
3385 new_windows[i] = old_windows[i];
3386 new_windows[count] = GDK_WINDOW_XID (window);
3388 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3389 GDK_WINDOW_XID (toplevel),
3390 new_windows, count + 1);
3392 g_free (new_windows);
3394 XFree (old_windows);
3398 do_shape_combine_region (GdkWindow *window,
3399 const GdkRegion *shape_region,
3404 if (GDK_WINDOW_DESTROYED (window))
3407 if (shape_region == NULL)
3409 /* Use NULL mask to unset the shape */
3410 if (shape == ShapeBounding
3411 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3412 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3414 if (shape == ShapeBounding)
3416 _gdk_x11_window_tmp_unset_parent_bg (window);
3417 _gdk_x11_window_tmp_unset_bg (window, TRUE);
3419 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3420 GDK_WINDOW_XID (window),
3425 if (shape == ShapeBounding)
3427 _gdk_x11_window_tmp_reset_parent_bg (window);
3428 _gdk_x11_window_tmp_reset_bg (window, TRUE);
3434 if (shape == ShapeBounding
3435 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3436 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3439 XRectangle *xrects = NULL;
3441 _gdk_region_get_xrectangles (shape_region,
3445 if (shape == ShapeBounding)
3447 _gdk_x11_window_tmp_unset_parent_bg (window);
3448 _gdk_x11_window_tmp_unset_bg (window, TRUE);
3450 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3451 GDK_WINDOW_XID (window),
3458 if (shape == ShapeBounding)
3460 _gdk_x11_window_tmp_reset_parent_bg (window);
3461 _gdk_x11_window_tmp_reset_bg (window, TRUE);
3469 gdk_window_x11_shape_combine_region (GdkWindow *window,
3470 const GdkRegion *shape_region,
3474 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
3478 gdk_window_x11_input_shape_combine_region (GdkWindow *window,
3479 const GdkRegion *shape_region,
3484 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
3490 * gdk_window_set_override_redirect:
3491 * @window: a toplevel #GdkWindow
3492 * @override_redirect: %TRUE if window should be override redirect
3494 * An override redirect window is not under the control of the window manager.
3495 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3496 * be entirely under the control of the application. The window manager
3497 * can't see the override redirect window at all.
3499 * Override redirect should only be used for short-lived temporary
3500 * windows, such as popup menus. #GtkMenu uses an override redirect
3501 * window in its implementation, for example.
3505 gdk_window_set_override_redirect (GdkWindow *window,
3506 gboolean override_redirect)
3508 XSetWindowAttributes attr;
3510 if (!GDK_WINDOW_DESTROYED (window) &&
3511 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3513 GdkWindowObject *private = (GdkWindowObject *)window;
3514 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
3516 attr.override_redirect = (override_redirect? True : False);
3517 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3518 GDK_WINDOW_XID (window),
3522 impl->override_redirect = attr.override_redirect;
3527 * gdk_window_set_accept_focus:
3528 * @window: a toplevel #GdkWindow
3529 * @accept_focus: %TRUE if the window should receive input focus
3531 * Setting @accept_focus to %FALSE hints the desktop environment that the
3532 * window doesn't want to receive input focus.
3534 * On X, it is the responsibility of the window manager to interpret this
3535 * hint. ICCCM-compliant window manager usually respect it.
3540 gdk_window_set_accept_focus (GdkWindow *window,
3541 gboolean accept_focus)
3543 GdkWindowObject *private;
3545 private = (GdkWindowObject *)window;
3547 accept_focus = accept_focus != FALSE;
3549 if (private->accept_focus != accept_focus)
3551 private->accept_focus = accept_focus;
3553 if (!GDK_WINDOW_DESTROYED (window) &&
3554 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3555 update_wm_hints (window, FALSE);
3560 * gdk_window_set_focus_on_map:
3561 * @window: a toplevel #GdkWindow
3562 * @focus_on_map: %TRUE if the window should receive input focus when mapped
3564 * Setting @focus_on_map to %FALSE hints the desktop environment that the
3565 * window doesn't want to receive input focus when it is mapped.
3566 * focus_on_map should be turned off for windows that aren't triggered
3567 * interactively (such as popups from network activity).
3569 * On X, it is the responsibility of the window manager to interpret
3570 * this hint. Window managers following the freedesktop.org window
3571 * manager extension specification should respect it.
3576 gdk_window_set_focus_on_map (GdkWindow *window,
3577 gboolean focus_on_map)
3579 GdkWindowObject *private;
3581 private = (GdkWindowObject *)window;
3583 focus_on_map = focus_on_map != FALSE;
3585 if (private->focus_on_map != focus_on_map)
3587 private->focus_on_map = focus_on_map;
3589 if ((!GDK_WINDOW_DESTROYED (window)) &&
3590 (!private->focus_on_map) &&
3591 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3592 gdk_x11_window_set_user_time (window, 0);
3597 * gdk_x11_window_set_user_time:
3598 * @window: A toplevel #GdkWindow
3599 * @timestamp: An XServer timestamp to which the property should be set
3601 * The application can use this call to update the _NET_WM_USER_TIME
3602 * property on a toplevel window. This property stores an Xserver
3603 * time which represents the time of the last user input event
3604 * received for this window. This property may be used by the window
3605 * manager to alter the focus, stacking, and/or placement behavior of
3606 * windows when they are mapped depending on whether the new window
3607 * was created by a user action or is a "pop-up" window activated by a
3608 * timer or some other event.
3610 * Note that this property is automatically updated by GDK, so this
3611 * function should only be used by applications which handle input
3612 * events bypassing GDK.
3617 gdk_x11_window_set_user_time (GdkWindow *window,
3620 GdkDisplay *display;
3621 GdkDisplayX11 *display_x11;
3622 GdkToplevelX11 *toplevel;
3623 glong timestamp_long = (glong)timestamp;
3626 if (GDK_WINDOW_DESTROYED (window) ||
3627 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3630 display = gdk_drawable_get_display (window);
3631 display_x11 = GDK_DISPLAY_X11 (display);
3632 toplevel = _gdk_x11_window_get_toplevel (window);
3636 g_warning ("gdk_window_set_user_time called on non-toplevel\n");
3640 if (toplevel->focus_window != None &&
3641 gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
3642 gdk_atom_intern_static_string ("_NET_WM_USER_TIME_WINDOW")))
3643 xid = toplevel->focus_window;
3645 xid = GDK_WINDOW_XID (window);
3647 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xid,
3648 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3649 XA_CARDINAL, 32, PropModeReplace,
3650 (guchar *)×tamp_long, 1);
3652 if (timestamp_long != GDK_CURRENT_TIME &&
3653 (display_x11->user_time == GDK_CURRENT_TIME ||
3654 XSERVER_TIME_IS_LATER (timestamp_long, display_x11->user_time)))
3655 display_x11->user_time = timestamp_long;
3658 toplevel->user_time = timestamp_long;
3661 #define GDK_SELECTION_MAX_SIZE(display) \
3663 XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
3664 ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
3665 : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
3668 * gdk_window_set_icon_list:
3669 * @window: The #GdkWindow toplevel window to set the icon of.
3670 * @pixbufs: A list of pixbufs, of different sizes.
3672 * Sets a list of icons for the window. One of these will be used
3673 * to represent the window when it has been iconified. The icon is
3674 * usually shown in an icon box or some sort of task bar. Which icon
3675 * size is shown depends on the window manager. The window manager
3676 * can scale the icon but setting several size icons can give better
3677 * image quality since the window manager may only need to scale the
3678 * icon by a small amount or not at all.
3682 gdk_window_set_icon_list (GdkWindow *window,
3691 gint width, height, stride;
3694 GdkDisplay *display;
3697 if (GDK_WINDOW_DESTROYED (window) ||
3698 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3701 display = gdk_drawable_get_display (window);
3709 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3711 width = gdk_pixbuf_get_width (pixbuf);
3712 height = gdk_pixbuf_get_height (pixbuf);
3714 /* silently ignore overlarge icons */
3715 if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
3717 g_warning ("gdk_window_set_icon_list: icons too large");
3722 size += 2 + width * height;
3724 l = g_list_next (l);
3727 data = g_malloc (size * sizeof (gulong));
3735 width = gdk_pixbuf_get_width (pixbuf);
3736 height = gdk_pixbuf_get_height (pixbuf);
3737 stride = gdk_pixbuf_get_rowstride (pixbuf);
3738 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3743 pixels = gdk_pixbuf_get_pixels (pixbuf);
3745 for (y = 0; y < height; y++)
3747 for (x = 0; x < width; x++)
3751 r = pixels[y*stride + x*n_channels + 0];
3752 g = pixels[y*stride + x*n_channels + 1];
3753 b = pixels[y*stride + x*n_channels + 2];
3754 if (n_channels >= 4)
3755 a = pixels[y*stride + x*n_channels + 3];
3759 *p++ = a << 24 | r << 16 | g << 8 | b ;
3763 l = g_list_next (l);
3769 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3770 GDK_WINDOW_XID (window),
3771 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3774 (guchar*) data, size);
3778 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3779 GDK_WINDOW_XID (window),
3780 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3787 * gdk_window_set_icon:
3788 * @window: a toplevel #GdkWindow
3789 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
3790 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
3791 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
3793 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
3794 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
3795 * and gtk_window_set_icon(). If those don't meet your needs, look at
3796 * gdk_window_set_icon_list(). Only if all those are too high-level do you
3797 * want to fall back to gdk_window_set_icon().
3801 gdk_window_set_icon (GdkWindow *window,
3802 GdkWindow *icon_window,
3806 GdkToplevelX11 *toplevel;
3808 if (GDK_WINDOW_DESTROYED (window) ||
3809 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3812 toplevel = _gdk_x11_window_get_toplevel (window);
3814 if (toplevel->icon_window != icon_window)
3816 if (toplevel->icon_window)
3817 g_object_unref (toplevel->icon_window);
3818 toplevel->icon_window = g_object_ref (icon_window);
3821 if (toplevel->icon_pixmap != pixmap)
3824 g_object_ref (pixmap);
3825 if (toplevel->icon_pixmap)
3826 g_object_unref (toplevel->icon_pixmap);
3827 toplevel->icon_pixmap = pixmap;
3830 if (toplevel->icon_mask != mask)
3833 g_object_ref (mask);
3834 if (toplevel->icon_mask)
3835 g_object_unref (toplevel->icon_mask);
3836 toplevel->icon_mask = mask;
3839 update_wm_hints (window, FALSE);
3843 gdk_window_icon_name_set (GdkWindow *window)
3845 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3846 g_quark_from_static_string ("gdk-icon-name-set")));
3850 * gdk_window_set_icon_name:
3851 * @window: a toplevel #GdkWindow
3852 * @name: name of window while iconified (minimized)
3854 * Windows may have a name used while minimized, distinct from the
3855 * name they display in their titlebar. Most of the time this is a bad
3856 * idea from a user interface standpoint. But you can set such a name
3857 * with this function, if you like.
3859 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
3860 * will not update the icon title.
3862 * Using %NULL for @name unsets the icon title; further calls to
3863 * gdk_window_set_title() will again update the icon title as well.
3866 gdk_window_set_icon_name (GdkWindow *window,
3869 GdkDisplay *display;
3871 if (GDK_WINDOW_DESTROYED (window) ||
3872 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3875 display = gdk_drawable_get_display (window);
3877 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3878 GUINT_TO_POINTER (name != NULL));
3882 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3883 GDK_WINDOW_XID (window),
3884 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3885 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3886 PropModeReplace, (guchar *)name, strlen (name));
3888 set_text_property (display, GDK_WINDOW_XID (window),
3889 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3894 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3895 GDK_WINDOW_XID (window),
3896 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"));
3897 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3898 GDK_WINDOW_XID (window),
3899 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"));
3904 * gdk_window_iconify:
3905 * @window: a toplevel #GdkWindow
3907 * Asks to iconify (minimize) @window. The window manager may choose
3908 * to ignore the request, but normally will honor it. Using
3909 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3911 * This function only makes sense when @window is a toplevel window.
3915 gdk_window_iconify (GdkWindow *window)
3917 if (GDK_WINDOW_DESTROYED (window) ||
3918 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3921 if (GDK_WINDOW_IS_MAPPED (window))
3923 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3924 GDK_WINDOW_XWINDOW (window),
3925 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3929 /* Flip our client side flag, the real work happens on map. */
3930 gdk_synthesize_window_state (window,
3932 GDK_WINDOW_STATE_ICONIFIED);
3937 * gdk_window_deiconify:
3938 * @window: a toplevel #GdkWindow
3940 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3941 * choose to ignore the request to deiconify. When using GTK+,
3942 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3943 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3944 * unminimizes it, and puts it on the current desktop.
3948 gdk_window_deiconify (GdkWindow *window)
3950 if (GDK_WINDOW_DESTROYED (window) ||
3951 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3954 if (GDK_WINDOW_IS_MAPPED (window))
3956 gdk_window_show (window);
3960 /* Flip our client side flag, the real work happens on map. */
3961 gdk_synthesize_window_state (window,
3962 GDK_WINDOW_STATE_ICONIFIED,
3969 * @window: a toplevel #GdkWindow
3971 * "Pins" a window such that it's on all workspaces and does not scroll
3972 * with viewports, for window managers that have scrollable viewports.
3973 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3975 * On the X11 platform, this function depends on window manager
3976 * support, so may have no effect with many window managers. However,
3977 * GDK will do the best it can to convince the window manager to stick
3978 * the window. For window managers that don't support this operation,
3979 * there's nothing you can do to force it to happen.
3983 gdk_window_stick (GdkWindow *window)
3985 if (GDK_WINDOW_DESTROYED (window) ||
3986 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3989 if (GDK_WINDOW_IS_MAPPED (window))
3991 /* "stick" means stick to all desktops _and_ do not scroll with the
3992 * viewport. i.e. glue to the monitor glass in all cases.
3995 XClientMessageEvent xclient;
3997 /* Request stick during viewport scroll */
3998 gdk_wmspec_change_state (TRUE, window,
3999 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4002 /* Request desktop 0xFFFFFFFF */
4003 memset (&xclient, 0, sizeof (xclient));
4004 xclient.type = ClientMessage;
4005 xclient.window = GDK_WINDOW_XWINDOW (window);
4006 xclient.display = GDK_WINDOW_XDISPLAY (window);
4007 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
4009 xclient.format = 32;
4011 xclient.data.l[0] = 0xFFFFFFFF;
4012 xclient.data.l[1] = 0;
4013 xclient.data.l[2] = 0;
4014 xclient.data.l[3] = 0;
4015 xclient.data.l[4] = 0;
4017 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
4018 SubstructureRedirectMask | SubstructureNotifyMask,
4019 (XEvent *)&xclient);
4023 /* Flip our client side flag, the real work happens on map. */
4024 gdk_synthesize_window_state (window,
4026 GDK_WINDOW_STATE_STICKY);
4031 * gdk_window_unstick:
4032 * @window: a toplevel #GdkWindow
4034 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
4035 * and gtk_window_unstick().
4039 gdk_window_unstick (GdkWindow *window)
4041 if (GDK_WINDOW_DESTROYED (window) ||
4042 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4045 if (GDK_WINDOW_IS_MAPPED (window))
4047 /* Request unstick from viewport */
4048 gdk_wmspec_change_state (FALSE, window,
4049 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4052 move_to_current_desktop (window);
4056 /* Flip our client side flag, the real work happens on map. */
4057 gdk_synthesize_window_state (window,
4058 GDK_WINDOW_STATE_STICKY,
4065 * gdk_window_maximize:
4066 * @window: a toplevel #GdkWindow
4068 * Maximizes the window. If the window was already maximized, then
4069 * this function does nothing.
4071 * On X11, asks the window manager to maximize @window, if the window
4072 * manager supports this operation. Not all window managers support
4073 * this, and some deliberately ignore it or don't have a concept of
4074 * "maximized"; so you can't rely on the maximization actually
4075 * happening. But it will happen with most standard window managers,
4076 * and GDK makes a best effort to get it to happen.
4078 * On Windows, reliably maximizes the window.
4082 gdk_window_maximize (GdkWindow *window)
4084 if (GDK_WINDOW_DESTROYED (window) ||
4085 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4088 if (GDK_WINDOW_IS_MAPPED (window))
4089 gdk_wmspec_change_state (TRUE, window,
4090 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4091 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4093 gdk_synthesize_window_state (window,
4095 GDK_WINDOW_STATE_MAXIMIZED);
4099 * gdk_window_unmaximize:
4100 * @window: a toplevel #GdkWindow
4102 * Unmaximizes the window. If the window wasn't maximized, then this
4103 * function does nothing.
4105 * On X11, asks the window manager to unmaximize @window, if the
4106 * window manager supports this operation. Not all window managers
4107 * support this, and some deliberately ignore it or don't have a
4108 * concept of "maximized"; so you can't rely on the unmaximization
4109 * actually happening. But it will happen with most standard window
4110 * managers, and GDK makes a best effort to get it to happen.
4112 * On Windows, reliably unmaximizes the window.
4116 gdk_window_unmaximize (GdkWindow *window)
4118 if (GDK_WINDOW_DESTROYED (window) ||
4119 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4122 if (GDK_WINDOW_IS_MAPPED (window))
4123 gdk_wmspec_change_state (FALSE, window,
4124 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4125 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4127 gdk_synthesize_window_state (window,
4128 GDK_WINDOW_STATE_MAXIMIZED,
4133 * gdk_window_fullscreen:
4134 * @window: a toplevel #GdkWindow
4136 * Moves the window into fullscreen mode. This means the
4137 * window covers the entire screen and is above any panels
4140 * If the window was already fullscreen, then this function does nothing.
4142 * On X11, asks the window manager to put @window in a fullscreen
4143 * state, if the window manager supports this operation. Not all
4144 * window managers support this, and some deliberately ignore it or
4145 * don't have a concept of "fullscreen"; so you can't rely on the
4146 * fullscreenification actually happening. But it will happen with
4147 * most standard window managers, and GDK makes a best effort to get
4153 gdk_window_fullscreen (GdkWindow *window)
4155 if (GDK_WINDOW_DESTROYED (window) ||
4156 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4159 if (GDK_WINDOW_IS_MAPPED (window))
4160 gdk_wmspec_change_state (TRUE, window,
4161 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4165 gdk_synthesize_window_state (window,
4167 GDK_WINDOW_STATE_FULLSCREEN);
4171 * gdk_window_unfullscreen:
4172 * @window: a toplevel #GdkWindow
4174 * Moves the window out of fullscreen mode. If the window was not
4175 * fullscreen, does nothing.
4177 * On X11, asks the window manager to move @window out of the fullscreen
4178 * state, if the window manager supports this operation. Not all
4179 * window managers support this, and some deliberately ignore it or
4180 * don't have a concept of "fullscreen"; so you can't rely on the
4181 * unfullscreenification actually happening. But it will happen with
4182 * most standard window managers, and GDK makes a best effort to get
4188 gdk_window_unfullscreen (GdkWindow *window)
4190 if (GDK_WINDOW_DESTROYED (window) ||
4191 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4194 if (GDK_WINDOW_IS_MAPPED (window))
4195 gdk_wmspec_change_state (FALSE, window,
4196 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4200 gdk_synthesize_window_state (window,
4201 GDK_WINDOW_STATE_FULLSCREEN,
4206 * gdk_window_set_keep_above:
4207 * @window: a toplevel #GdkWindow
4208 * @setting: whether to keep @window above other windows
4210 * Set if @window must be kept above other windows. If the
4211 * window was already above, then this function does nothing.
4213 * On X11, asks the window manager to keep @window above, if the window
4214 * manager supports this operation. Not all window managers support
4215 * this, and some deliberately ignore it or don't have a concept of
4216 * "keep above"; so you can't rely on the window being kept above.
4217 * But it will happen with most standard window managers,
4218 * and GDK makes a best effort to get it to happen.
4223 gdk_window_set_keep_above (GdkWindow *window,
4226 g_return_if_fail (GDK_IS_WINDOW (window));
4228 if (GDK_WINDOW_DESTROYED (window) ||
4229 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4232 if (GDK_WINDOW_IS_MAPPED (window))
4235 gdk_wmspec_change_state (FALSE, window,
4236 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4238 gdk_wmspec_change_state (setting, window,
4239 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4243 gdk_synthesize_window_state (window,
4244 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
4245 setting ? GDK_WINDOW_STATE_ABOVE : 0);
4249 * gdk_window_set_keep_below:
4250 * @window: a toplevel #GdkWindow
4251 * @setting: whether to keep @window below other windows
4253 * Set if @window must be kept below other windows. If the
4254 * window was already below, then this function does nothing.
4256 * On X11, asks the window manager to keep @window below, if the window
4257 * manager supports this operation. Not all window managers support
4258 * this, and some deliberately ignore it or don't have a concept of
4259 * "keep below"; so you can't rely on the window being kept below.
4260 * But it will happen with most standard window managers,
4261 * and GDK makes a best effort to get it to happen.
4266 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
4268 g_return_if_fail (GDK_IS_WINDOW (window));
4270 if (GDK_WINDOW_DESTROYED (window) ||
4271 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4274 if (GDK_WINDOW_IS_MAPPED (window))
4277 gdk_wmspec_change_state (FALSE, window,
4278 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4280 gdk_wmspec_change_state (setting, window,
4281 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4285 gdk_synthesize_window_state (window,
4286 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
4287 setting ? GDK_WINDOW_STATE_BELOW : 0);
4291 * gdk_window_get_group:
4292 * @window: a toplevel #GdkWindow
4294 * Returns the group leader window for @window. See gdk_window_set_group().
4296 * Return value: the group leader window for @window
4301 gdk_window_get_group (GdkWindow *window)
4303 GdkToplevelX11 *toplevel;
4305 if (GDK_WINDOW_DESTROYED (window) ||
4306 !WINDOW_IS_TOPLEVEL (window))
4309 toplevel = _gdk_x11_window_get_toplevel (window);
4311 return toplevel->group_leader;
4315 * gdk_window_set_group:
4316 * @window: a toplevel #GdkWindow
4317 * @leader: group leader window, or %NULL to restore the default group leader window
4319 * Sets the group leader window for @window. By default,
4320 * GDK sets the group leader for all toplevel windows
4321 * to a global window implicitly created by GDK. With this function
4322 * you can override this default.
4324 * The group leader window allows the window manager to distinguish
4325 * all windows that belong to a single application. It may for example
4326 * allow users to minimize/unminimize all windows belonging to an
4327 * application at once. You should only set a non-default group window
4328 * if your application pretends to be multiple applications.
4331 gdk_window_set_group (GdkWindow *window,
4334 GdkToplevelX11 *toplevel;
4336 g_return_if_fail (GDK_IS_WINDOW (window));
4337 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4338 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
4340 if (GDK_WINDOW_DESTROYED (window) ||
4341 (leader != NULL && GDK_WINDOW_DESTROYED (leader)) ||
4342 !WINDOW_IS_TOPLEVEL (window))
4345 toplevel = _gdk_x11_window_get_toplevel (window);
4348 leader = gdk_display_get_default_group (gdk_drawable_get_display (window));
4350 if (toplevel->group_leader != leader)
4352 if (toplevel->group_leader)
4353 g_object_unref (toplevel->group_leader);
4354 toplevel->group_leader = g_object_ref (leader);
4355 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
4358 update_wm_hints (window, FALSE);
4361 static MotifWmHints *
4362 gdk_window_get_mwm_hints (GdkWindow *window)
4364 GdkDisplay *display;
4365 Atom hints_atom = None;
4372 if (GDK_WINDOW_DESTROYED (window))
4375 display = gdk_drawable_get_display (window);
4377 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4379 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4380 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4381 False, AnyPropertyType, &type, &format, &nitems,
4382 &bytes_after, &data);
4387 return (MotifWmHints *)data;
4391 gdk_window_set_mwm_hints (GdkWindow *window,
4392 MotifWmHints *new_hints)
4394 GdkDisplay *display;
4395 Atom hints_atom = None;
4397 MotifWmHints *hints;
4403 if (GDK_WINDOW_DESTROYED (window))
4406 display = gdk_drawable_get_display (window);
4408 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4410 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4411 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4412 False, AnyPropertyType, &type, &format, &nitems,
4413 &bytes_after, &data);
4419 hints = (MotifWmHints *)data;
4421 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4423 hints->flags |= MWM_HINTS_FUNCTIONS;
4424 hints->functions = new_hints->functions;
4426 if (new_hints->flags & MWM_HINTS_DECORATIONS)
4428 hints->flags |= MWM_HINTS_DECORATIONS;
4429 hints->decorations = new_hints->decorations;
4433 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4434 hints_atom, hints_atom, 32, PropModeReplace,
4435 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
4437 if (hints != new_hints)
4442 * gdk_window_set_decorations:
4443 * @window: a toplevel #GdkWindow
4444 * @decorations: decoration hint mask
4446 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
4447 * This function sets the traditional Motif window manager hints that tell the
4448 * window manager which decorations you would like your window to have.
4449 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
4450 * using the GDK function directly.
4452 * The @decorations argument is the logical OR of the fields in
4453 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
4454 * mask, the other bits indicate which decorations should be turned off.
4455 * If #GDK_DECOR_ALL is not included, then the other bits indicate
4456 * which decorations should be turned on.
4458 * Most window managers honor a decorations hint of 0 to disable all decorations,
4459 * but very few honor all possible combinations of bits.
4463 gdk_window_set_decorations (GdkWindow *window,
4464 GdkWMDecoration decorations)
4468 if (GDK_WINDOW_DESTROYED (window) ||
4469 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4472 /* initialize to zero to avoid writing uninitialized data to socket */
4473 memset(&hints, 0, sizeof(hints));
4474 hints.flags = MWM_HINTS_DECORATIONS;
4475 hints.decorations = decorations;
4477 gdk_window_set_mwm_hints (window, &hints);
4481 * gdk_window_get_decorations:
4482 * @window: The toplevel #GdkWindow to get the decorations from
4483 * @decorations: The window decorations will be written here
4485 * Returns the decorations set on the GdkWindow with
4486 * gdk_window_set_decorations().
4488 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
4491 gdk_window_get_decorations(GdkWindow *window,
4492 GdkWMDecoration *decorations)
4494 MotifWmHints *hints;
4495 gboolean result = FALSE;
4497 if (GDK_WINDOW_DESTROYED (window) ||
4498 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4501 hints = gdk_window_get_mwm_hints (window);
4505 if (hints->flags & MWM_HINTS_DECORATIONS)
4508 *decorations = hints->decorations;
4519 * gdk_window_set_functions:
4520 * @window: a toplevel #GdkWindow
4521 * @functions: bitmask of operations to allow on @window
4523 * Sets hints about the window management functions to make available
4524 * via buttons on the window frame.
4526 * On the X backend, this function sets the traditional Motif window
4527 * manager hint for this purpose. However, few window managers do
4528 * anything reliable or interesting with this hint. Many ignore it
4531 * The @functions argument is the logical OR of values from the
4532 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
4533 * then the other bits indicate which functions to disable; if
4534 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
4539 gdk_window_set_functions (GdkWindow *window,
4540 GdkWMFunction functions)
4544 g_return_if_fail (GDK_IS_WINDOW (window));
4546 if (GDK_WINDOW_DESTROYED (window) ||
4547 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4550 /* initialize to zero to avoid writing uninitialized data to socket */
4551 memset(&hints, 0, sizeof(hints));
4552 hints.flags = MWM_HINTS_FUNCTIONS;
4553 hints.functions = functions;
4555 gdk_window_set_mwm_hints (window, &hints);
4559 _xwindow_get_shape (Display *xdisplay,
4571 xrl = XShapeGetRectangles (xdisplay,
4573 shape_type, &rn, &ord);
4575 if (xrl == NULL || rn == 0)
4576 return cairo_region_create (); /* Empty */
4578 if (ord != YXBanded)
4580 /* This really shouldn't happen with any xserver, as they
4581 generally convert regions to YXBanded internally */
4582 g_warning ("non YXBanded shape masks not supported");
4587 rl = g_new (GdkRectangle, rn);
4588 for (i = 0; i < rn; i++)
4592 rl[i].width = xrl[i].width;
4593 rl[i].height = xrl[i].height;
4597 shape = cairo_region_create_rectangles (rl, rn);
4605 _gdk_windowing_get_shape_for_mask (GdkBitmap *mask)
4607 GdkDisplay *display;
4611 display = gdk_drawable_get_display (GDK_DRAWABLE (mask));
4613 window = XCreateSimpleWindow (GDK_DISPLAY_XDISPLAY (display),
4614 GDK_SCREEN_XROOTWIN (gdk_drawable_get_screen (mask)),
4617 XShapeCombineMask (GDK_DISPLAY_XDISPLAY (display),
4621 GDK_PIXMAP_XID (mask),
4624 region = _xwindow_get_shape (GDK_DISPLAY_XDISPLAY (display),
4625 window, ShapeBounding);
4627 XDestroyWindow (GDK_DISPLAY_XDISPLAY (display), window);
4633 _gdk_windowing_window_get_shape (GdkWindow *window)
4635 if (!GDK_WINDOW_DESTROYED (window) &&
4636 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
4637 return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
4638 GDK_WINDOW_XID (window), ShapeBounding);
4644 _gdk_windowing_window_get_input_shape (GdkWindow *window)
4646 #if defined(ShapeInput)
4647 if (!GDK_WINDOW_DESTROYED (window) &&
4648 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
4649 return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
4650 GDK_WINDOW_XID (window),
4658 gdk_window_set_static_bit_gravity (GdkWindow *window,
4661 XSetWindowAttributes xattributes;
4662 GdkWindowObject *private;
4663 guint xattributes_mask = 0;
4665 g_return_if_fail (GDK_IS_WINDOW (window));
4667 private = GDK_WINDOW_OBJECT (window);
4668 if (private->input_only)
4671 xattributes.bit_gravity = StaticGravity;
4672 xattributes_mask |= CWBitGravity;
4673 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4674 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4675 GDK_WINDOW_XID (window),
4676 CWBitGravity, &xattributes);
4680 gdk_window_set_static_win_gravity (GdkWindow *window,
4683 XSetWindowAttributes xattributes;
4685 g_return_if_fail (GDK_IS_WINDOW (window));
4687 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4689 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4690 GDK_WINDOW_XID (window),
4691 CWWinGravity, &xattributes);
4695 gdk_window_x11_set_static_gravities (GdkWindow *window,
4696 gboolean use_static)
4698 GdkWindowObject *private = (GdkWindowObject *)window;
4701 if (!use_static == !private->guffaw_gravity)
4704 private->guffaw_gravity = use_static;
4706 if (!GDK_WINDOW_DESTROYED (window))
4708 gdk_window_set_static_bit_gravity (window, use_static);
4710 tmp_list = private->children;
4713 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4715 tmp_list = tmp_list->next;
4723 wmspec_moveresize (GdkWindow *window,
4729 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4731 XClientMessageEvent xclient;
4733 /* Release passive grab */
4734 gdk_display_pointer_ungrab (display, timestamp);
4736 memset (&xclient, 0, sizeof (xclient));
4737 xclient.type = ClientMessage;
4738 xclient.window = GDK_WINDOW_XID (window);
4739 xclient.message_type =
4740 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4741 xclient.format = 32;
4742 xclient.data.l[0] = root_x;
4743 xclient.data.l[1] = root_y;
4744 xclient.data.l[2] = direction;
4745 xclient.data.l[3] = 0;
4746 xclient.data.l[4] = 0;
4748 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4749 SubstructureRedirectMask | SubstructureNotifyMask,
4750 (XEvent *)&xclient);
4753 typedef struct _MoveResizeData MoveResizeData;
4755 struct _MoveResizeData
4757 GdkDisplay *display;
4759 GdkWindow *moveresize_window;
4760 GdkWindow *moveresize_emulation_window;
4762 GdkWindowEdge resize_edge;
4763 gint moveresize_button;
4766 gint moveresize_orig_x;
4767 gint moveresize_orig_y;
4768 gint moveresize_orig_width;
4769 gint moveresize_orig_height;
4770 GdkWindowHints moveresize_geom_mask;
4771 GdkGeometry moveresize_geometry;
4772 Time moveresize_process_time;
4773 XEvent *moveresize_pending_event;
4776 /* From the WM spec */
4777 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4778 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4779 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4780 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4781 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4782 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4783 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4784 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4785 #define _NET_WM_MOVERESIZE_MOVE 8
4788 wmspec_resize_drag (GdkWindow *window,
4797 /* Let the compiler turn a switch into a table, instead
4798 * of doing the table manually, this way is easier to verify.
4802 case GDK_WINDOW_EDGE_NORTH_WEST:
4803 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4806 case GDK_WINDOW_EDGE_NORTH:
4807 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4810 case GDK_WINDOW_EDGE_NORTH_EAST:
4811 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4814 case GDK_WINDOW_EDGE_WEST:
4815 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4818 case GDK_WINDOW_EDGE_EAST:
4819 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4822 case GDK_WINDOW_EDGE_SOUTH_WEST:
4823 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4826 case GDK_WINDOW_EDGE_SOUTH:
4827 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4830 case GDK_WINDOW_EDGE_SOUTH_EAST:
4831 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4835 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4840 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4843 static MoveResizeData *
4844 get_move_resize_data (GdkDisplay *display,
4847 MoveResizeData *mv_resize;
4848 static GQuark move_resize_quark = 0;
4850 if (!move_resize_quark)
4851 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4853 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4855 if (!mv_resize && create)
4857 mv_resize = g_new0 (MoveResizeData, 1);
4858 mv_resize->display = display;
4860 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4867 update_pos (MoveResizeData *mv_resize,
4873 dx = new_root_x - mv_resize->moveresize_x;
4874 dy = new_root_y - mv_resize->moveresize_y;
4876 if (mv_resize->is_resize)
4880 x = mv_resize->moveresize_orig_x;
4881 y = mv_resize->moveresize_orig_y;
4883 w = mv_resize->moveresize_orig_width;
4884 h = mv_resize->moveresize_orig_height;
4886 switch (mv_resize->resize_edge)
4888 case GDK_WINDOW_EDGE_NORTH_WEST:
4894 case GDK_WINDOW_EDGE_NORTH:
4898 case GDK_WINDOW_EDGE_NORTH_EAST:
4903 case GDK_WINDOW_EDGE_SOUTH_WEST:
4908 case GDK_WINDOW_EDGE_SOUTH_EAST:
4912 case GDK_WINDOW_EDGE_SOUTH:
4915 case GDK_WINDOW_EDGE_EAST:
4918 case GDK_WINDOW_EDGE_WEST:
4929 if (mv_resize->moveresize_geom_mask)
4931 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4932 mv_resize->moveresize_geom_mask,
4936 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4942 x = mv_resize->moveresize_orig_x + dx;
4943 y = mv_resize->moveresize_orig_y + dy;
4945 gdk_window_move (mv_resize->moveresize_window, x, y);
4950 finish_drag (MoveResizeData *mv_resize)
4952 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4953 mv_resize->moveresize_emulation_window = NULL;
4954 g_object_unref (mv_resize->moveresize_window);
4955 mv_resize->moveresize_window = NULL;
4957 if (mv_resize->moveresize_pending_event)
4959 g_free (mv_resize->moveresize_pending_event);
4960 mv_resize->moveresize_pending_event = NULL;
4965 lookahead_motion_predicate (Display *xdisplay,
4969 gboolean *seen_release = (gboolean *)arg;
4970 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4971 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4976 switch (event->xany.type)
4979 *seen_release = TRUE;
4982 mv_resize->moveresize_process_time = event->xmotion.time;
4992 moveresize_lookahead (MoveResizeData *mv_resize,
4996 gboolean seen_release = FALSE;
4998 if (mv_resize->moveresize_process_time)
5000 if (event->xmotion.time == mv_resize->moveresize_process_time)
5002 mv_resize->moveresize_process_time = 0;
5009 XCheckIfEvent (event->xany.display, &tmp_event,
5010 lookahead_motion_predicate, (XPointer) & seen_release);
5012 return mv_resize->moveresize_process_time == 0;
5016 _gdk_moveresize_handle_event (XEvent *event)
5018 guint button_mask = 0;
5019 GdkWindowObject *window_private;
5020 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
5021 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5023 if (!mv_resize || !mv_resize->moveresize_window)
5026 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
5028 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
5030 switch (event->xany.type)
5033 if (window_private->resize_count > 0)
5035 if (mv_resize->moveresize_pending_event)
5036 *mv_resize->moveresize_pending_event = *event;
5038 mv_resize->moveresize_pending_event =
5039 g_memdup (event, sizeof (XEvent));
5043 if (!moveresize_lookahead (mv_resize, event))
5046 update_pos (mv_resize,
5047 event->xmotion.x_root,
5048 event->xmotion.y_root);
5050 /* This should never be triggered in normal cases, but in the
5051 * case where the drag started without an implicit grab being
5052 * in effect, we could miss the release if it occurs before
5053 * we grab the pointer; this ensures that we will never
5054 * get a permanently stuck grab.
5056 if ((event->xmotion.state & button_mask) == 0)
5057 finish_drag (mv_resize);
5061 update_pos (mv_resize,
5062 event->xbutton.x_root,
5063 event->xbutton.y_root);
5065 if (event->xbutton.button == mv_resize->moveresize_button)
5066 finish_drag (mv_resize);
5073 _gdk_moveresize_configure_done (GdkDisplay *display,
5077 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5079 if (!mv_resize || window != mv_resize->moveresize_window)
5082 if (mv_resize->moveresize_pending_event)
5084 tmp_event = mv_resize->moveresize_pending_event;
5085 mv_resize->moveresize_pending_event = NULL;
5086 _gdk_moveresize_handle_event (tmp_event);
5094 create_moveresize_window (MoveResizeData *mv_resize,
5097 GdkWindowAttr attributes;
5098 gint attributes_mask;
5099 GdkGrabStatus status;
5101 g_assert (mv_resize->moveresize_emulation_window == NULL);
5103 attributes.x = -100;
5104 attributes.y = -100;
5105 attributes.width = 10;
5106 attributes.height = 10;
5107 attributes.window_type = GDK_WINDOW_TEMP;
5108 attributes.wclass = GDK_INPUT_ONLY;
5109 attributes.override_redirect = TRUE;
5110 attributes.event_mask = 0;
5112 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
5114 mv_resize->moveresize_emulation_window =
5115 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
5119 gdk_window_show (mv_resize->moveresize_emulation_window);
5121 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
5123 GDK_BUTTON_RELEASE_MASK |
5124 GDK_POINTER_MOTION_MASK,
5129 if (status != GDK_GRAB_SUCCESS)
5131 /* If this fails, some other client has grabbed the window
5134 finish_drag (mv_resize);
5137 mv_resize->moveresize_process_time = 0;
5141 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
5142 so that calling XMoveWindow with these coordinates will not move the
5144 Note that this depends on the WM to implement ICCCM-compliant reference
5148 calculate_unmoving_origin (MoveResizeData *mv_resize)
5153 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
5154 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
5156 gdk_window_get_origin (mv_resize->moveresize_window,
5157 &mv_resize->moveresize_orig_x,
5158 &mv_resize->moveresize_orig_y);
5162 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
5163 gdk_window_get_geometry (mv_resize->moveresize_window,
5164 NULL, NULL, &width, &height, NULL);
5166 switch (mv_resize->moveresize_geometry.win_gravity)
5168 case GDK_GRAVITY_NORTH_WEST:
5169 mv_resize->moveresize_orig_x = rect.x;
5170 mv_resize->moveresize_orig_y = rect.y;
5172 case GDK_GRAVITY_NORTH:
5173 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5174 mv_resize->moveresize_orig_y = rect.y;
5176 case GDK_GRAVITY_NORTH_EAST:
5177 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5178 mv_resize->moveresize_orig_y = rect.y;
5180 case GDK_GRAVITY_WEST:
5181 mv_resize->moveresize_orig_x = rect.x;
5182 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5184 case GDK_GRAVITY_CENTER:
5185 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5186 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5188 case GDK_GRAVITY_EAST:
5189 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5190 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5192 case GDK_GRAVITY_SOUTH_WEST:
5193 mv_resize->moveresize_orig_x = rect.x;
5194 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5196 case GDK_GRAVITY_SOUTH:
5197 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5198 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5200 case GDK_GRAVITY_SOUTH_EAST:
5201 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5202 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5205 mv_resize->moveresize_orig_x = rect.x;
5206 mv_resize->moveresize_orig_y = rect.y;
5213 emulate_resize_drag (GdkWindow *window,
5220 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5222 mv_resize->is_resize = TRUE;
5223 mv_resize->moveresize_button = button;
5224 mv_resize->resize_edge = edge;
5225 mv_resize->moveresize_x = root_x;
5226 mv_resize->moveresize_y = root_y;
5227 mv_resize->moveresize_window = g_object_ref (window);
5229 gdk_drawable_get_size (window,
5230 &mv_resize->moveresize_orig_width,
5231 &mv_resize->moveresize_orig_height);
5233 mv_resize->moveresize_geom_mask = 0;
5234 gdk_window_get_geometry_hints (window,
5235 &mv_resize->moveresize_geometry,
5236 &mv_resize->moveresize_geom_mask);
5238 calculate_unmoving_origin (mv_resize);
5240 create_moveresize_window (mv_resize, timestamp);
5244 emulate_move_drag (GdkWindow *window,
5250 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5252 mv_resize->is_resize = FALSE;
5253 mv_resize->moveresize_button = button;
5254 mv_resize->moveresize_x = root_x;
5255 mv_resize->moveresize_y = root_y;
5257 mv_resize->moveresize_window = g_object_ref (window);
5259 calculate_unmoving_origin (mv_resize);
5261 create_moveresize_window (mv_resize, timestamp);
5265 * gdk_window_begin_resize_drag:
5266 * @window: a toplevel #GdkWindow
5267 * @edge: the edge or corner from which the drag is started
5268 * @button: the button being used to drag
5269 * @root_x: root window X coordinate of mouse click that began the drag
5270 * @root_y: root window Y coordinate of mouse click that began the drag
5271 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
5273 * Begins a window resize operation (for a toplevel window).
5274 * You might use this function to implement a "window resize grip," for
5275 * example; in fact #GtkStatusbar uses it. The function works best
5276 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
5277 * fallback implementation for other window managers.
5281 gdk_window_begin_resize_drag (GdkWindow *window,
5288 if (GDK_WINDOW_DESTROYED (window) ||
5289 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
5292 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5293 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
5294 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
5296 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
5300 * gdk_window_begin_move_drag:
5301 * @window: a toplevel #GdkWindow
5302 * @button: the button being used to drag
5303 * @root_x: root window X coordinate of mouse click that began the drag
5304 * @root_y: root window Y coordinate of mouse click that began the drag
5305 * @timestamp: timestamp of mouse click that began the drag
5307 * Begins a window move operation (for a toplevel window). You might
5308 * use this function to implement a "window move grip," for
5309 * example. The function works best with window managers that support
5310 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
5311 * Window Manager Hints</ulink>, but has a fallback implementation for
5312 * other window managers.
5316 gdk_window_begin_move_drag (GdkWindow *window,
5322 if (GDK_WINDOW_DESTROYED (window) ||
5323 !WINDOW_IS_TOPLEVEL (window))
5326 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5327 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
5328 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
5331 emulate_move_drag (window, button, root_x, root_y, timestamp);
5335 * gdk_window_enable_synchronized_configure:
5336 * @window: a toplevel #GdkWindow
5338 * Indicates that the application will cooperate with the window
5339 * system in synchronizing the window repaint with the window
5340 * manager during resizing operations. After an application calls
5341 * this function, it must call gdk_window_configure_finished() every
5342 * time it has finished all processing associated with a set of
5343 * Configure events. Toplevel GTK+ windows automatically use this
5346 * On X, calling this function makes @window participate in the
5347 * _NET_WM_SYNC_REQUEST window manager protocol.
5352 gdk_window_enable_synchronized_configure (GdkWindow *window)
5354 GdkWindowObject *private = (GdkWindowObject *)window;
5355 GdkWindowImplX11 *impl;
5357 if (!GDK_IS_WINDOW_IMPL_X11 (private->impl))
5360 impl = GDK_WINDOW_IMPL_X11 (private->impl);
5362 if (!impl->use_synchronized_configure)
5364 /* This basically means you want to do fancy X specific stuff, so
5365 ensure we have a native window */
5366 gdk_window_ensure_native (window);
5368 impl->use_synchronized_configure = TRUE;
5369 ensure_sync_counter (window);
5374 * gdk_window_configure_finished:
5375 * @window: a toplevel #GdkWindow
5377 * Signal to the window system that the application has finished
5378 * handling Configure events it has received. Window Managers can
5379 * use this to better synchronize the frame repaint with the
5380 * application. GTK+ applications will automatically call this
5381 * function when appropriate.
5383 * This function can only be called if gdk_window_enable_synchronized_configure()
5384 * was called previously.
5389 gdk_window_configure_finished (GdkWindow *window)
5391 GdkWindowImplX11 *impl;
5393 if (!WINDOW_IS_TOPLEVEL (window))
5396 impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
5397 if (!impl->use_synchronized_configure)
5401 if (!GDK_WINDOW_DESTROYED (window))
5403 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
5404 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
5406 if (toplevel && toplevel->update_counter != None &&
5407 GDK_DISPLAY_X11 (display)->use_sync &&
5408 !XSyncValueIsZero (toplevel->current_counter_value))
5410 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
5411 toplevel->update_counter,
5412 toplevel->current_counter_value);
5414 XSyncIntToValue (&toplevel->current_counter_value, 0);
5421 _gdk_windowing_window_beep (GdkWindow *window)
5423 GdkDisplay *display;
5425 g_return_if_fail (GDK_IS_WINDOW (window));
5427 display = GDK_WINDOW_DISPLAY (window);
5430 if (GDK_DISPLAY_X11 (display)->use_xkb)
5431 XkbBell (GDK_DISPLAY_XDISPLAY (display),
5432 GDK_WINDOW_XID (window),
5437 gdk_display_beep (display);
5441 * gdk_window_set_opacity:
5442 * @window: a top-level #GdkWindow
5445 * Request the windowing system to make @window partially transparent,
5446 * with opacity 0 being fully transparent and 1 fully opaque. (Values
5447 * of the opacity parameter are clamped to the [0,1] range.)
5449 * On X11, this works only on X screens with a compositing manager
5452 * For setting up per-pixel alpha, see gdk_screen_get_rgba_colormap().
5453 * For making non-toplevel windows translucent, see
5454 * gdk_window_set_composited().
5459 gdk_window_set_opacity (GdkWindow *window,
5462 GdkDisplay *display;
5465 g_return_if_fail (GDK_IS_WINDOW (window));
5467 if (GDK_WINDOW_DESTROYED (window) ||
5468 !WINDOW_IS_TOPLEVEL (window))
5471 display = gdk_drawable_get_display (window);
5475 else if (opacity > 1)
5478 cardinal = opacity * 0xffffffff;
5480 if (cardinal == 0xffffffff)
5481 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
5482 GDK_WINDOW_XID (window),
5483 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"));
5485 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
5486 GDK_WINDOW_XID (window),
5487 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"),
5490 (guchar *) &cardinal, 1);
5494 _gdk_windowing_window_set_composited (GdkWindow *window,
5495 gboolean composited)
5497 #if defined(HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES)
5498 GdkWindowObject *private = (GdkWindowObject *) window;
5499 GdkWindowImplX11 *impl;
5500 GdkDisplay *display;
5504 impl = GDK_WINDOW_IMPL_X11 (private->impl);
5506 display = gdk_screen_get_display (GDK_DRAWABLE_IMPL_X11 (impl)->screen);
5507 dpy = GDK_DISPLAY_XDISPLAY (display);
5508 xid = GDK_WINDOW_XWINDOW (private);
5512 XCompositeRedirectWindow (dpy, xid, CompositeRedirectManual);
5513 impl->damage = XDamageCreate (dpy, xid, XDamageReportBoundingBox);
5517 XCompositeUnredirectWindow (dpy, xid, CompositeRedirectManual);
5518 XDamageDestroy (dpy, impl->damage);
5519 impl->damage = None;
5525 _gdk_windowing_window_process_updates_recurse (GdkWindow *window,
5528 _gdk_window_process_updates_recurse (window, region);
5532 _gdk_windowing_before_process_all_updates (void)
5537 _gdk_windowing_after_process_all_updates (void)
5542 gdk_window_impl_iface_init (GdkWindowImplIface *iface)
5544 iface->show = gdk_window_x11_show;
5545 iface->hide = gdk_window_x11_hide;
5546 iface->withdraw = gdk_window_x11_withdraw;
5547 iface->set_events = gdk_window_x11_set_events;
5548 iface->get_events = gdk_window_x11_get_events;
5549 iface->raise = gdk_window_x11_raise;
5550 iface->lower = gdk_window_x11_lower;
5551 iface->restack_under = gdk_window_x11_restack_under;
5552 iface->restack_toplevel = gdk_window_x11_restack_toplevel;
5553 iface->move_resize = gdk_window_x11_move_resize;
5554 iface->set_background = gdk_window_x11_set_background;
5555 iface->set_back_pixmap = gdk_window_x11_set_back_pixmap;
5556 iface->reparent = gdk_window_x11_reparent;
5557 iface->clear_region = gdk_window_x11_clear_region;
5558 iface->set_device_cursor = gdk_window_x11_set_device_cursor;
5559 iface->get_geometry = gdk_window_x11_get_geometry;
5560 iface->get_root_coords = gdk_window_x11_get_root_coords;
5561 iface->get_device_state = gdk_window_x11_get_device_state;
5562 iface->get_deskrelative_origin = gdk_window_x11_get_deskrelative_origin;
5563 iface->shape_combine_region = gdk_window_x11_shape_combine_region;
5564 iface->input_shape_combine_region = gdk_window_x11_input_shape_combine_region;
5565 iface->set_static_gravities = gdk_window_x11_set_static_gravities;
5566 iface->queue_antiexpose = _gdk_x11_window_queue_antiexpose;
5567 iface->queue_translation = _gdk_x11_window_queue_translation;
5568 iface->destroy = _gdk_x11_window_destroy;
5569 iface->supports_native_bg = TRUE;
5573 timestamp_predicate (Display *display,
5577 Window xwindow = GPOINTER_TO_UINT (arg);
5578 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
5580 if (xevent->type == PropertyNotify &&
5581 xevent->xproperty.window == xwindow &&
5582 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
5583 "GDK_TIMESTAMP_PROP"))
5590 * gdk_x11_get_server_time:
5591 * @window: a #GdkWindow, used for communication with the server.
5592 * The window must have GDK_PROPERTY_CHANGE_MASK in its
5593 * events mask or a hang will result.
5595 * Routine to get the current X server time stamp.
5597 * Return value: the time stamp.
5600 gdk_x11_get_server_time (GdkWindow *window)
5606 Atom timestamp_prop_atom;
5608 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5609 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
5611 xdisplay = GDK_WINDOW_XDISPLAY (window);
5612 xwindow = GDK_WINDOW_XWINDOW (window);
5613 timestamp_prop_atom =
5614 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
5615 "GDK_TIMESTAMP_PROP");
5617 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
5618 timestamp_prop_atom,
5619 8, PropModeReplace, &c, 1);
5621 XIfEvent (xdisplay, &xevent,
5622 timestamp_predicate, GUINT_TO_POINTER(xwindow));
5624 return xevent.xproperty.time;
5627 #define __GDK_WINDOW_X11_C__
5628 #include "gdkaliasdef.c"