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 <cairo-xlib.h>
40 #include <netinet/in.h>
46 #include "gdkwindow.h"
47 #include "gdkwindowimpl.h"
49 #include "gdkdisplay-x11.h"
50 #include "gdkprivate-x11.h"
51 #include "gdkinternals.h"
53 #include "gdkwindow-x11.h"
54 #include "gdkdeviceprivate.h"
55 #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);
111 static void gdk_window_x11_set_background (GdkWindow *window,
112 cairo_pattern_t *pattern);
114 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
115 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
117 static void gdk_window_impl_x11_finalize (GObject *object);
118 static void gdk_window_impl_iface_init (GdkWindowImplIface *iface);
120 #define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \
121 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
122 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
124 #define WINDOW_IS_TOPLEVEL(window) \
125 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
126 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
127 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
129 /* Return whether time1 is considered later than time2 as far as xserver
130 * time is concerned. Accounts for wraparound.
132 #define XSERVER_TIME_IS_LATER(time1, time2) \
133 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
134 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
137 G_DEFINE_TYPE_WITH_CODE (GdkWindowImplX11,
139 GDK_TYPE_DRAWABLE_IMPL_X11,
140 G_IMPLEMENT_INTERFACE (GDK_TYPE_WINDOW_IMPL,
141 gdk_window_impl_iface_init));
144 _gdk_window_impl_get_type (void)
146 return gdk_window_impl_x11_get_type ();
150 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
152 impl->toplevel_window_type = -1;
153 impl->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
154 (GDestroyNotify) gdk_cursor_unref);
158 _gdk_x11_window_get_toplevel (GdkWindow *window)
160 GdkWindowObject *private;
161 GdkWindowImplX11 *impl;
163 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
165 if (!WINDOW_IS_TOPLEVEL (window))
168 private = (GdkWindowObject *)window;
169 impl = GDK_WINDOW_IMPL_X11 (private->impl);
172 impl->toplevel = g_new0 (GdkToplevelX11, 1);
174 return impl->toplevel;
178 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
180 GObjectClass *object_class = G_OBJECT_CLASS (klass);
181 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
183 object_class->finalize = gdk_window_impl_x11_finalize;
185 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
186 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
190 gdk_window_impl_x11_finalize (GObject *object)
192 GdkWindowObject *wrapper;
193 GdkDrawableImplX11 *draw_impl;
194 GdkWindowImplX11 *window_impl;
196 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
198 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
199 window_impl = GDK_WINDOW_IMPL_X11 (object);
201 wrapper = (GdkWindowObject*) draw_impl->wrapper;
203 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
205 if (!GDK_WINDOW_DESTROYED (wrapper))
207 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
209 _gdk_xid_table_remove (display, draw_impl->xid);
210 if (window_impl->toplevel && window_impl->toplevel->focus_window)
211 _gdk_xid_table_remove (display, window_impl->toplevel->focus_window);
214 g_free (window_impl->toplevel);
216 if (window_impl->cursor)
217 gdk_cursor_unref (window_impl->cursor);
219 g_hash_table_destroy (window_impl->device_cursor);
221 G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
230 free_pixmap (gpointer datap)
232 FreePixmapData *data = datap;
234 if (!gdk_display_is_closed (data->display))
236 XFreePixmap (GDK_DISPLAY_XDISPLAY (data->display),
240 g_object_unref (data->display);
241 g_slice_free (FreePixmapData, data);
245 attach_free_pixmap_handler (cairo_surface_t *surface,
249 static const cairo_user_data_key_t key;
250 FreePixmapData *data;
252 data = g_slice_new (FreePixmapData);
253 data->display = g_object_ref (display);
254 data->pixmap = pixmap;
256 cairo_surface_set_user_data (surface, &key, data, free_pixmap);
259 /* Cairo does not guarantee we get an xlib surface if we call
260 * cairo_surface_create_similar(). In some cases however, we must use a
261 * pixmap or bitmap in the X11 API.
262 * These functions ensure an Xlib surface.
265 _gdk_x11_window_create_bitmap_surface (GdkWindow *window,
269 cairo_surface_t *surface;
272 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
273 GDK_WINDOW_XID (window),
275 surface = cairo_xlib_surface_create_for_bitmap (GDK_WINDOW_XDISPLAY (window),
277 GDK_SCREEN_XSCREEN (GDK_WINDOW_SCREEN (window)),
279 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
284 static cairo_surface_t *
285 gdk_x11_window_create_pixmap_surface (GdkWindow *window,
289 cairo_surface_t *surface;
292 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
293 GDK_WINDOW_XID (window),
295 DefaultDepthOfScreen (GDK_SCREEN_XSCREEN (GDK_WINDOW_SCREEN (window))));
296 surface = cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (window),
298 GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (window)),
300 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
306 tmp_unset_bg (GdkWindow *window)
308 GdkWindowImplX11 *impl;
309 GdkWindowObject *obj;
311 obj = (GdkWindowObject *) window;
312 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
316 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
317 GDK_DRAWABLE_XID (window), None);
321 tmp_reset_bg (GdkWindow *window)
323 GdkWindowImplX11 *impl;
324 GdkWindowObject *obj;
326 obj = (GdkWindowObject *) window;
327 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
331 gdk_window_x11_set_background (window, obj->background);
334 /* Unsetting and resetting window backgrounds.
336 * In many cases it is possible to avoid flicker by unsetting the
337 * background of windows. For example if the background of the
338 * parent window is unset when a window is unmapped, a brief flicker
339 * of background painting is avoided.
342 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
345 GdkWindowObject *private;
347 g_return_if_fail (GDK_IS_WINDOW (window));
349 private = (GdkWindowObject *)window;
351 if (private->input_only || private->destroyed ||
352 (private->window_type != GDK_WINDOW_ROOT &&
353 !GDK_WINDOW_IS_MAPPED (window)))
356 if (_gdk_window_has_impl (window) &&
357 GDK_WINDOW_IS_X11 (window) &&
358 private->window_type != GDK_WINDOW_ROOT &&
359 private->window_type != GDK_WINDOW_FOREIGN)
360 tmp_unset_bg (window);
366 for (l = private->children; l != NULL; l = l->next)
367 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
372 _gdk_x11_window_tmp_unset_parent_bg (GdkWindow *window)
374 GdkWindowObject *private;
375 private = (GdkWindowObject*) window;
377 if (GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT)
380 window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
381 _gdk_x11_window_tmp_unset_bg (window, FALSE);
385 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
388 GdkWindowObject *private;
390 g_return_if_fail (GDK_IS_WINDOW (window));
392 private = (GdkWindowObject *)window;
394 if (private->input_only || private->destroyed ||
395 (private->window_type != GDK_WINDOW_ROOT &&
396 !GDK_WINDOW_IS_MAPPED (window)))
400 if (_gdk_window_has_impl (window) &&
401 GDK_WINDOW_IS_X11 (window) &&
402 private->window_type != GDK_WINDOW_ROOT &&
403 private->window_type != GDK_WINDOW_FOREIGN)
404 tmp_reset_bg (window);
410 for (l = private->children; l != NULL; l = l->next)
411 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
416 _gdk_x11_window_tmp_reset_parent_bg (GdkWindow *window)
418 GdkWindowObject *private;
419 private = (GdkWindowObject*) window;
421 if (GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT)
424 window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
426 _gdk_x11_window_tmp_reset_bg (window, FALSE);
430 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
432 GdkDrawableImplX11 *drawable_impl;
434 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
436 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
438 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
439 drawable_impl->colormap == NULL)
441 XWindowAttributes window_attributes;
444 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
448 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
449 window_attributes.visual->visualid);
450 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
451 window_attributes.colormap);
454 return drawable_impl->colormap;
458 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
461 GdkDrawableImplX11 *draw_impl;
463 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
465 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
467 if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper))
471 GDK_DRAWABLE_CLASS (gdk_window_impl_x11_parent_class)->set_colormap (drawable, cmap);
475 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
477 GDK_COLORMAP_XCOLORMAP (cmap));
479 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
481 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
487 _gdk_windowing_window_init (GdkScreen * screen)
489 GdkWindowObject *private;
490 GdkDrawableImplX11 *draw_impl;
491 GdkScreenX11 *screen_x11;
493 screen_x11 = GDK_SCREEN_X11 (screen);
495 g_assert (screen_x11->root_window == NULL);
497 gdk_screen_set_default_colormap (screen,
498 gdk_screen_get_system_colormap (screen));
500 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
502 private = (GdkWindowObject *) screen_x11->root_window;
503 private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
504 private->impl_window = private;
506 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
508 draw_impl->screen = screen;
509 draw_impl->xid = screen_x11->xroot_window;
510 draw_impl->wrapper = GDK_DRAWABLE (private);
511 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
512 g_object_ref (draw_impl->colormap);
514 private->window_type = GDK_WINDOW_ROOT;
515 private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
521 private->width = WidthOfScreen (screen_x11->xscreen);
522 private->height = HeightOfScreen (screen_x11->xscreen);
523 private->viewable = TRUE;
525 /* see init_randr_support() in gdkscreen-x11.c */
526 private->event_mask = GDK_STRUCTURE_MASK;
528 _gdk_window_update_size (screen_x11->root_window);
530 _gdk_xid_table_insert (screen_x11->display,
531 &screen_x11->xroot_window,
532 screen_x11->root_window);
536 set_wm_protocols (GdkWindow *window)
538 GdkDisplay *display = gdk_drawable_get_display (window);
542 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
543 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
544 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
547 if (GDK_DISPLAY_X11 (display)->use_sync)
548 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
551 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
555 get_default_title (void)
559 title = g_get_application_name ();
561 title = g_get_prgname ();
569 check_leader_window_title (GdkDisplay *display)
571 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
573 if (display_x11->leader_window && !display_x11->leader_window_title_set)
575 set_wm_name (display,
576 display_x11->leader_window,
577 get_default_title ());
579 display_x11->leader_window_title_set = TRUE;
584 create_focus_window (GdkDisplay *display,
587 GdkDisplayX11 *display_x11;
588 GdkEventMask event_mask;
592 xdisplay = GDK_DISPLAY_XDISPLAY (display);
593 display_x11 = GDK_DISPLAY_X11 (display);
595 focus_window = XCreateSimpleWindow (xdisplay, parent,
599 /* FIXME: probably better to actually track the requested event mask for the toplevel
601 event_mask = (GDK_KEY_PRESS_MASK |
602 GDK_KEY_RELEASE_MASK |
603 GDK_FOCUS_CHANGE_MASK);
605 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
609 XMapWindow (xdisplay, focus_window);
615 ensure_sync_counter (GdkWindow *window)
618 if (!GDK_WINDOW_DESTROYED (window))
620 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
621 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
622 GdkWindowObject *private = (GdkWindowObject *)window;
623 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
625 if (toplevel && impl->use_synchronized_configure &&
626 toplevel->update_counter == None &&
627 GDK_DISPLAY_X11 (display)->use_sync)
629 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
633 XSyncIntToValue (&value, 0);
635 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
637 atom = gdk_x11_get_xatom_by_name_for_display (display,
638 "_NET_WM_SYNC_REQUEST_COUNTER");
640 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
643 (guchar *)&toplevel->update_counter, 1);
645 XSyncIntToValue (&toplevel->current_counter_value, 0);
652 setup_toplevel_window (GdkWindow *window,
655 GdkWindowObject *obj = (GdkWindowObject *)window;
656 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
657 GdkDisplay *display = gdk_drawable_get_display (window);
658 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
659 XID xid = GDK_WINDOW_XID (window);
660 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
661 XSizeHints size_hints;
663 Window leader_window;
665 set_wm_protocols (window);
667 if (!obj->input_only)
669 /* The focus window is off the visible area, and serves to receive key
670 * press events so they don't get sent to child windows.
672 toplevel->focus_window = create_focus_window (display, xid);
673 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
676 check_leader_window_title (screen_x11->display);
678 /* FIXME: Is there any point in doing this? Do any WM's pay
679 * attention to PSize, and even if they do, is this the
682 size_hints.flags = PSize;
683 size_hints.width = obj->width;
684 size_hints.height = obj->height;
686 XSetWMNormalHints (xdisplay, xid, &size_hints);
688 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
689 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
692 XChangeProperty (xdisplay, xid,
693 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
698 leader_window = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
701 XChangeProperty (xdisplay, xid,
702 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
703 XA_WINDOW, 32, PropModeReplace,
704 (guchar *) &leader_window, 1);
706 if (toplevel->focus_window != None)
707 XChangeProperty (xdisplay, xid,
708 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_USER_TIME_WINDOW"),
709 XA_WINDOW, 32, PropModeReplace,
710 (guchar *) &toplevel->focus_window, 1);
712 if (!obj->focus_on_map)
713 gdk_x11_window_set_user_time (window, 0);
714 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
715 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
717 ensure_sync_counter (window);
721 _gdk_window_impl_new (GdkWindow *window,
722 GdkWindow *real_parent,
725 GdkEventMask event_mask,
726 GdkWindowAttr *attributes,
727 gint attributes_mask)
729 GdkWindowObject *private;
730 GdkWindowImplX11 *impl;
731 GdkDrawableImplX11 *draw_impl;
732 GdkScreenX11 *screen_x11;
733 GdkDisplayX11 *display_x11;
740 XSetWindowAttributes xattributes;
741 long xattributes_mask;
742 XClassHint *class_hint;
747 private = (GdkWindowObject *) window;
749 screen_x11 = GDK_SCREEN_X11 (screen);
750 xparent = GDK_WINDOW_XID (real_parent);
751 display_x11 = GDK_DISPLAY_X11 (GDK_SCREEN_DISPLAY (screen));
753 impl = g_object_new (_gdk_window_impl_get_type (), NULL);
754 private->impl = (GdkDrawable *)impl;
755 draw_impl = GDK_DRAWABLE_IMPL_X11 (impl);
756 draw_impl->wrapper = GDK_DRAWABLE (window);
758 draw_impl->screen = screen;
759 xdisplay = screen_x11->xdisplay;
761 xattributes_mask = 0;
763 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
765 if (attributes_mask & GDK_WA_NOREDIR)
767 xattributes.override_redirect =
768 (attributes->override_redirect == FALSE)?False:True;
769 xattributes_mask |= CWOverrideRedirect;
772 xattributes.override_redirect = False;
774 impl->override_redirect = xattributes.override_redirect;
776 if (private->parent && private->parent->guffaw_gravity)
778 xattributes.win_gravity = StaticGravity;
779 xattributes_mask |= CWWinGravity;
783 switch (private->window_type)
785 case GDK_WINDOW_TOPLEVEL:
786 case GDK_WINDOW_TEMP:
787 if (GDK_WINDOW_TYPE (private->parent) != GDK_WINDOW_ROOT)
789 /* The common code warns for this case */
790 xparent = GDK_SCREEN_XROOTWIN (screen);
794 if (!private->input_only)
798 if (attributes_mask & GDK_WA_COLORMAP)
800 draw_impl->colormap = attributes->colormap;
801 g_object_ref (attributes->colormap);
805 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
807 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
808 g_object_ref (draw_impl->colormap);
812 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
816 xattributes.background_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
818 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
819 xattributes_mask |= CWBorderPixel | CWBackPixel;
821 if (private->guffaw_gravity)
822 xattributes.bit_gravity = StaticGravity;
824 xattributes.bit_gravity = NorthWestGravity;
826 xattributes_mask |= CWBitGravity;
828 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
829 xattributes_mask |= CWColormap;
831 if (private->window_type == GDK_WINDOW_TEMP)
833 xattributes.save_under = True;
834 xattributes.override_redirect = True;
835 xattributes.cursor = None;
836 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
838 impl->override_redirect = TRUE;
844 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
845 g_object_ref (draw_impl->colormap);
848 if (private->width > 65535 ||
849 private->height > 65535)
851 g_warning ("Native Windows wider or taller than 65535 pixels are not supported");
853 if (private->width > 65535)
854 private->width = 65535;
855 if (private->height > 65535)
856 private->height = 65535;
859 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
860 private->x + private->parent->abs_x,
861 private->y + private->parent->abs_y,
862 private->width, private->height,
863 0, private->depth, class, xvisual,
864 xattributes_mask, &xattributes);
866 g_object_ref (window);
867 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
869 switch (GDK_WINDOW_TYPE (private))
871 case GDK_WINDOW_TOPLEVEL:
872 case GDK_WINDOW_TEMP:
873 if (attributes_mask & GDK_WA_TITLE)
874 title = attributes->title;
876 title = get_default_title ();
878 gdk_window_set_title (window, title);
880 if (attributes_mask & GDK_WA_WMCLASS)
882 class_hint = XAllocClassHint ();
883 class_hint->res_name = attributes->wmclass_name;
884 class_hint->res_class = attributes->wmclass_class;
885 XSetClassHint (xdisplay, xid, class_hint);
889 setup_toplevel_window (window, (GdkWindow *)private->parent);
892 case GDK_WINDOW_CHILD:
893 if (!private->input_only &&
894 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
895 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
897 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
898 gdk_window_add_colormap_windows (window);
906 if (attributes_mask & GDK_WA_TYPE_HINT)
907 gdk_window_set_type_hint (window, attributes->type_hint);
909 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
910 GDK_WINDOW_XWINDOW (window), event_mask,
911 StructureNotifyMask | PropertyChangeMask);
915 x_event_mask_to_gdk_event_mask (long mask)
917 GdkEventMask event_mask = 0;
920 for (i = 0; i < _gdk_nenvent_masks; i++)
922 if (mask & _gdk_event_mask_table[i])
923 event_mask |= 1 << (i + 1);
930 * gdk_window_foreign_new_for_display:
931 * @display: the #GdkDisplay where the window handle comes from.
932 * @anid: a native window handle.
934 * Wraps a native window in a #GdkWindow.
935 * This may fail if the window has been destroyed. If the window
936 * was already known to GDK, a new reference to the existing
937 * #GdkWindow is returned.
939 * For example in the X backend, a native window handle is an Xlib
942 * Return value: a #GdkWindow wrapper for the native window or
943 * %NULL if the window has been destroyed. The wrapper will be
944 * newly created, if one doesn't exist already.
949 gdk_window_foreign_new_for_display (GdkDisplay *display,
950 GdkNativeWindow anid)
953 GdkWindowObject *private;
954 GdkWindowImplX11 *impl;
955 GdkDrawableImplX11 *draw_impl;
956 GdkDisplayX11 *display_x11;
957 XWindowAttributes attrs;
959 Window *children = NULL;
963 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
965 display_x11 = GDK_DISPLAY_X11 (display);
967 if ((window = gdk_xid_table_lookup_for_display (display, anid)) != NULL)
968 return g_object_ref (window);
970 gdk_error_trap_push ();
971 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
972 if (gdk_error_trap_pop () || !result)
975 /* FIXME: This is pretty expensive. Maybe the caller should supply
977 gdk_error_trap_push ();
978 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
979 if (gdk_error_trap_pop () || !result)
985 window = g_object_new (GDK_TYPE_WINDOW, NULL);
987 private = (GdkWindowObject *) window;
988 private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
989 private->impl_window = private;
991 impl = GDK_WINDOW_IMPL_X11 (private->impl);
992 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
993 draw_impl->wrapper = GDK_DRAWABLE (window);
994 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
996 private->parent = gdk_xid_table_lookup_for_display (display, parent);
998 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
999 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
1001 private->parent->children = g_list_prepend (private->parent->children, window);
1003 draw_impl->xid = anid;
1005 private->x = attrs.x;
1006 private->y = attrs.y;
1007 private->width = attrs.width;
1008 private->height = attrs.height;
1009 private->window_type = GDK_WINDOW_FOREIGN;
1010 private->destroyed = FALSE;
1012 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
1014 if (attrs.map_state == IsUnmapped)
1015 private->state = GDK_WINDOW_STATE_WITHDRAWN;
1018 private->viewable = TRUE;
1020 private->depth = attrs.depth;
1022 g_object_ref (window);
1023 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
1025 /* Update the clip region, etc */
1026 _gdk_window_update_size (window);
1032 * gdk_window_lookup_for_display:
1033 * @display: the #GdkDisplay corresponding to the window handle
1034 * @anid: a native window handle.
1036 * Looks up the #GdkWindow that wraps the given native window handle.
1038 * For example in the X backend, a native window handle is an Xlib
1041 * Return value: the #GdkWindow wrapper for the native window,
1042 * or %NULL if there is none.
1047 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
1049 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
1053 * gdk_window_lookup:
1054 * @anid: a native window handle.
1056 * Looks up the #GdkWindow that wraps the given native window handle.
1058 * For example in the X backend, a native window handle is an Xlib
1061 * Return value: the #GdkWindow wrapper for the native window,
1062 * or %NULL if there is none.
1065 gdk_window_lookup (GdkNativeWindow anid)
1067 return (GdkWindow*) gdk_xid_table_lookup (anid);
1071 gdk_toplevel_x11_free_contents (GdkDisplay *display,
1072 GdkToplevelX11 *toplevel)
1074 if (toplevel->icon_pixmap)
1076 cairo_surface_destroy (toplevel->icon_pixmap);
1077 toplevel->icon_pixmap = NULL;
1079 if (toplevel->icon_mask)
1081 cairo_surface_destroy (toplevel->icon_mask);
1082 toplevel->icon_mask = NULL;
1084 if (toplevel->group_leader)
1086 g_object_unref (toplevel->group_leader);
1087 toplevel->group_leader = NULL;
1090 if (toplevel->update_counter != None)
1092 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
1093 toplevel->update_counter);
1094 toplevel->update_counter = None;
1096 XSyncIntToValue (&toplevel->current_counter_value, 0);
1102 _gdk_x11_window_destroy (GdkWindow *window,
1104 gboolean foreign_destroy)
1106 GdkWindowObject *private = (GdkWindowObject *)window;
1107 GdkToplevelX11 *toplevel;
1109 g_return_if_fail (GDK_IS_WINDOW (window));
1111 _gdk_selection_window_destroyed (window);
1113 toplevel = _gdk_x11_window_get_toplevel (window);
1115 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1117 _gdk_x11_drawable_finish (private->impl);
1119 if (!recursing && !foreign_destroy)
1121 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1126 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
1128 /* It's somebody else's window, but in our hierarchy,
1129 * so reparent it to the root window, and then send
1130 * it a delete event, as if we were a WM
1132 XClientMessageEvent xclient;
1134 gdk_error_trap_push ();
1135 gdk_window_hide (window);
1136 gdk_window_reparent (window, NULL, 0, 0);
1138 memset (&xclient, 0, sizeof (xclient));
1139 xclient.type = ClientMessage;
1140 xclient.window = GDK_WINDOW_XID (window);
1141 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1143 xclient.format = 32;
1144 xclient.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1145 "WM_DELETE_WINDOW");
1146 xclient.data.l[1] = CurrentTime;
1147 xclient.data.l[2] = 0;
1148 xclient.data.l[3] = 0;
1149 xclient.data.l[4] = 0;
1151 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1152 GDK_WINDOW_XID (window),
1153 False, 0, (XEvent *)&xclient);
1154 gdk_error_trap_pop_ignored ();
1158 get_root (GdkWindow *window)
1160 GdkScreen *screen = gdk_drawable_get_screen (window);
1162 return gdk_screen_get_root_window (screen);
1165 /* This function is called when the XWindow is really gone.
1168 gdk_window_destroy_notify (GdkWindow *window)
1170 GdkWindowImplX11 *window_impl;
1172 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
1174 if (!GDK_WINDOW_DESTROYED (window))
1176 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1177 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1179 _gdk_window_destroy (window, TRUE);
1182 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1183 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1184 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1186 _gdk_xgrab_check_destroy (window);
1188 g_object_unref (window);
1192 update_wm_hints (GdkWindow *window,
1195 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1196 GdkWindowObject *private = (GdkWindowObject *)window;
1197 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1201 !toplevel->is_leader &&
1202 private->state & GDK_WINDOW_STATE_WITHDRAWN)
1205 wm_hints.flags = StateHint | InputHint;
1206 wm_hints.input = private->accept_focus ? True : False;
1207 wm_hints.initial_state = NormalState;
1209 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
1211 wm_hints.flags |= StateHint;
1212 wm_hints.initial_state = IconicState;
1215 if (toplevel->icon_pixmap)
1217 wm_hints.flags |= IconPixmapHint;
1218 wm_hints.icon_pixmap = cairo_xlib_surface_get_drawable (toplevel->icon_pixmap);
1221 if (toplevel->icon_mask)
1223 wm_hints.flags |= IconMaskHint;
1224 wm_hints.icon_mask = cairo_xlib_surface_get_drawable (toplevel->icon_mask);
1227 wm_hints.flags |= WindowGroupHint;
1228 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1230 wm_hints.flags |= WindowGroupHint;
1231 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1234 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1236 if (toplevel->urgency_hint)
1237 wm_hints.flags |= XUrgencyHint;
1239 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1240 GDK_WINDOW_XID (window),
1245 set_initial_hints (GdkWindow *window)
1247 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1248 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1249 Window xwindow = GDK_WINDOW_XID (window);
1250 GdkWindowObject *private;
1251 GdkToplevelX11 *toplevel;
1255 private = (GdkWindowObject*) window;
1256 toplevel = _gdk_x11_window_get_toplevel (window);
1261 update_wm_hints (window, TRUE);
1263 /* We set the spec hints regardless of whether the spec is supported,
1264 * since it can't hurt and it's kind of expensive to check whether
1270 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1272 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1273 "_NET_WM_STATE_MAXIMIZED_VERT");
1275 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1276 "_NET_WM_STATE_MAXIMIZED_HORZ");
1278 toplevel->have_maxhorz = toplevel->have_maxvert = TRUE;
1281 if (private->state & GDK_WINDOW_STATE_ABOVE)
1283 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1284 "_NET_WM_STATE_ABOVE");
1288 if (private->state & GDK_WINDOW_STATE_BELOW)
1290 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1291 "_NET_WM_STATE_BELOW");
1295 if (private->state & GDK_WINDOW_STATE_STICKY)
1297 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1298 "_NET_WM_STATE_STICKY");
1300 toplevel->have_sticky = TRUE;
1303 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1305 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1306 "_NET_WM_STATE_FULLSCREEN");
1308 toplevel->have_fullscreen = TRUE;
1311 if (private->modal_hint)
1313 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1314 "_NET_WM_STATE_MODAL");
1318 if (toplevel->skip_taskbar_hint)
1320 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1321 "_NET_WM_STATE_SKIP_TASKBAR");
1325 if (toplevel->skip_pager_hint)
1327 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1328 "_NET_WM_STATE_SKIP_PAGER");
1334 XChangeProperty (xdisplay,
1336 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1337 XA_ATOM, 32, PropModeReplace,
1338 (guchar*) atoms, i);
1342 XDeleteProperty (xdisplay,
1344 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1347 if (private->state & GDK_WINDOW_STATE_STICKY)
1349 atoms[0] = 0xFFFFFFFF;
1350 XChangeProperty (xdisplay,
1352 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1353 XA_CARDINAL, 32, PropModeReplace,
1354 (guchar*) atoms, 1);
1355 toplevel->on_all_desktops = TRUE;
1359 XDeleteProperty (xdisplay,
1361 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1364 toplevel->map_serial = NextRequest (xdisplay);
1368 gdk_window_x11_show (GdkWindow *window, gboolean already_mapped)
1370 GdkWindowObject *private = (GdkWindowObject*) window;
1371 GdkDisplay *display;
1372 GdkDisplayX11 *display_x11;
1373 GdkToplevelX11 *toplevel;
1374 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1375 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1376 Window xwindow = GDK_WINDOW_XID (window);
1379 if (!already_mapped)
1380 set_initial_hints (window);
1382 if (WINDOW_IS_TOPLEVEL (window))
1384 display = gdk_drawable_get_display (window);
1385 display_x11 = GDK_DISPLAY_X11 (display);
1386 toplevel = _gdk_x11_window_get_toplevel (window);
1388 if (toplevel->user_time != 0 &&
1389 display_x11->user_time != 0 &&
1390 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1391 gdk_x11_window_set_user_time (window, display_x11->user_time);
1394 unset_bg = !private->input_only &&
1395 (private->window_type == GDK_WINDOW_CHILD ||
1396 impl->override_redirect) &&
1397 gdk_window_is_viewable (window);
1400 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1402 XMapWindow (xdisplay, xwindow);
1405 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1409 pre_unmap (GdkWindow *window)
1411 GdkWindow *start_window = NULL;
1412 GdkWindowObject *private = (GdkWindowObject *)window;
1414 if (private->input_only)
1417 if (private->window_type == GDK_WINDOW_CHILD)
1418 start_window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
1419 else if (private->window_type == GDK_WINDOW_TEMP)
1420 start_window = get_root (window);
1423 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1427 post_unmap (GdkWindow *window)
1429 GdkWindow *start_window = NULL;
1430 GdkWindowObject *private = (GdkWindowObject *)window;
1432 if (private->input_only)
1435 if (private->window_type == GDK_WINDOW_CHILD)
1436 start_window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
1437 else if (private->window_type == GDK_WINDOW_TEMP)
1438 start_window = get_root (window);
1442 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1444 if (private->window_type == GDK_WINDOW_CHILD && private->parent)
1446 GdkRectangle invalid_rect;
1448 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1449 gdk_drawable_get_size (GDK_DRAWABLE (window),
1450 &invalid_rect.width, &invalid_rect.height);
1451 gdk_window_invalidate_rect ((GdkWindow *)private->parent,
1452 &invalid_rect, TRUE);
1458 gdk_window_x11_hide (GdkWindow *window)
1460 GdkWindowObject *private;
1462 private = (GdkWindowObject*) window;
1464 /* We'll get the unmap notify eventually, and handle it then,
1465 * but checking here makes things more consistent if we are
1466 * just doing stuff ourself.
1468 _gdk_xgrab_check_unmap (window,
1469 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1471 /* You can't simply unmap toplevel windows. */
1472 switch (private->window_type)
1474 case GDK_WINDOW_TOPLEVEL:
1475 case GDK_WINDOW_TEMP: /* ? */
1476 gdk_window_withdraw (window);
1479 case GDK_WINDOW_FOREIGN:
1480 case GDK_WINDOW_ROOT:
1481 case GDK_WINDOW_CHILD:
1485 _gdk_window_clear_update_area (window);
1488 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1489 GDK_WINDOW_XID (window));
1490 post_unmap (window);
1494 gdk_window_x11_withdraw (GdkWindow *window)
1496 GdkWindowObject *private;
1498 private = (GdkWindowObject*) window;
1499 if (!private->destroyed)
1501 if (GDK_WINDOW_IS_MAPPED (window))
1502 gdk_synthesize_window_state (window,
1504 GDK_WINDOW_STATE_WITHDRAWN);
1506 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1510 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1511 GDK_WINDOW_XID (window), 0);
1513 post_unmap (window);
1518 window_x11_move (GdkWindow *window,
1522 GdkWindowObject *private = (GdkWindowObject *) window;
1523 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1525 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1527 _gdk_window_move_resize_child (window,
1529 private->width, private->height);
1533 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1534 GDK_WINDOW_XID (window),
1537 if (impl->override_redirect)
1546 window_x11_resize (GdkWindow *window,
1550 GdkWindowObject *private = (GdkWindowObject *) window;
1558 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1560 _gdk_window_move_resize_child (window,
1561 private->x, private->y,
1566 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1568 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1569 GDK_WINDOW_XID (window),
1572 if (impl->override_redirect)
1574 private->width = width;
1575 private->height = height;
1576 _gdk_x11_drawable_update_size (private->impl);
1580 if (width != private->width || height != private->height)
1581 private->resize_count += 1;
1585 _gdk_x11_drawable_update_size (private->impl);
1589 window_x11_move_resize (GdkWindow *window,
1595 GdkWindowObject *private = (GdkWindowObject *) window;;
1603 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1605 _gdk_window_move_resize_child (window, x, y, width, height);
1606 _gdk_x11_drawable_update_size (private->impl);
1610 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1612 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1613 GDK_WINDOW_XID (window),
1614 x, y, width, height);
1616 if (impl->override_redirect)
1621 private->width = width;
1622 private->height = height;
1624 _gdk_x11_drawable_update_size (private->impl);
1628 if (width != private->width || height != private->height)
1629 private->resize_count += 1;
1635 gdk_window_x11_move_resize (GdkWindow *window,
1642 if (with_move && (width < 0 && height < 0))
1643 window_x11_move (window, x, y);
1647 window_x11_move_resize (window, x, y, width, height);
1649 window_x11_resize (window, width, height);
1654 gdk_window_x11_reparent (GdkWindow *window,
1655 GdkWindow *new_parent,
1659 GdkWindowObject *window_private;
1660 GdkWindowObject *parent_private;
1661 GdkWindowImplX11 *impl;
1663 window_private = (GdkWindowObject*) window;
1664 parent_private = (GdkWindowObject*) new_parent;
1665 impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
1667 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1668 _gdk_x11_window_tmp_unset_parent_bg (window);
1669 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1670 GDK_WINDOW_XID (window),
1671 GDK_WINDOW_XID (new_parent),
1672 parent_private->abs_x + x, parent_private->abs_y + y);
1673 _gdk_x11_window_tmp_reset_parent_bg (window);
1674 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1676 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1677 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1679 window_private->parent = parent_private;
1681 /* Switch the window type as appropriate */
1683 switch (GDK_WINDOW_TYPE (new_parent))
1685 case GDK_WINDOW_ROOT:
1686 case GDK_WINDOW_FOREIGN:
1687 /* Reparenting to toplevel */
1689 if (!WINDOW_IS_TOPLEVEL (window) &&
1690 GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1692 /* This is also done in common code at a later stage, but we
1693 need it in setup_toplevel, so do it here too */
1694 if (window_private->toplevel_window_type != -1)
1695 GDK_WINDOW_TYPE (window) = window_private->toplevel_window_type;
1696 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1697 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1699 /* Wasn't a toplevel, set up */
1700 setup_toplevel_window (window, new_parent);
1705 case GDK_WINDOW_TOPLEVEL:
1706 case GDK_WINDOW_CHILD:
1707 case GDK_WINDOW_TEMP:
1708 if (WINDOW_IS_TOPLEVEL (window) &&
1711 if (impl->toplevel->focus_window)
1713 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1714 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1717 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1719 g_free (impl->toplevel);
1720 impl->toplevel = NULL;
1728 gdk_window_x11_raise (GdkWindow *window)
1730 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1734 gdk_window_x11_restack_under (GdkWindow *window,
1735 GList *native_siblings /* in requested order, first is bottom-most */)
1741 n_windows = g_list_length (native_siblings) + 1;
1742 windows = g_new (Window, n_windows);
1744 windows[0] = GDK_WINDOW_XID (window);
1745 /* Reverse order, as input order is bottom-most first */
1747 for (l = native_siblings; l != NULL; l = l->next)
1748 windows[i--] = GDK_WINDOW_XID (l->data);
1750 XRestackWindows (GDK_WINDOW_XDISPLAY (window), windows, n_windows);
1756 gdk_window_x11_restack_toplevel (GdkWindow *window,
1760 XWindowChanges changes;
1762 changes.sibling = GDK_WINDOW_XID (sibling);
1763 changes.stack_mode = above ? Above : Below;
1764 XReconfigureWMWindow (GDK_WINDOW_XDISPLAY (window),
1765 GDK_WINDOW_XID (window),
1766 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)),
1767 CWStackMode | CWSibling, &changes);
1771 gdk_window_x11_lower (GdkWindow *window)
1773 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1777 * gdk_x11_window_move_to_current_desktop:
1778 * @window: a #GdkWindow
1780 * Moves the window to the correct workspace when running under a
1781 * window manager that supports multiple workspaces, as described
1782 * in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
1783 * Window Manager Hints</ulink>. Will not do anything if the
1784 * window is already on all workspaces.
1789 gdk_x11_window_move_to_current_desktop (GdkWindow *window)
1791 GdkToplevelX11 *toplevel;
1793 g_return_if_fail (GDK_IS_WINDOW (window));
1794 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1796 toplevel = _gdk_x11_window_get_toplevel (window);
1798 if (toplevel->on_all_desktops)
1801 move_to_current_desktop (window);
1805 move_to_current_desktop (GdkWindow *window)
1807 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1808 gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
1815 gulong *current_desktop;
1816 GdkDisplay *display;
1818 display = gdk_drawable_get_display (window);
1820 /* Get current desktop, then set it; this is a race, but not
1821 * one that matters much in practice.
1823 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
1824 GDK_WINDOW_XROOTWIN (window),
1825 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
1827 False, XA_CARDINAL, &type, &format, &nitems,
1828 &bytes_after, &data);
1830 if (type == XA_CARDINAL)
1832 XClientMessageEvent xclient;
1833 current_desktop = (gulong *)data;
1835 memset (&xclient, 0, sizeof (xclient));
1836 xclient.type = ClientMessage;
1838 xclient.send_event = True;
1839 xclient.window = GDK_WINDOW_XWINDOW (window);
1840 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
1841 xclient.format = 32;
1843 xclient.data.l[0] = *current_desktop;
1844 xclient.data.l[1] = 0;
1845 xclient.data.l[2] = 0;
1846 xclient.data.l[3] = 0;
1847 xclient.data.l[4] = 0;
1849 XSendEvent (GDK_DISPLAY_XDISPLAY (display),
1850 GDK_WINDOW_XROOTWIN (window),
1852 SubstructureRedirectMask | SubstructureNotifyMask,
1853 (XEvent *)&xclient);
1855 XFree (current_desktop);
1862 * @window: a #GdkWindow
1863 * @timestamp: timestamp of the event triggering the window focus
1865 * Sets keyboard focus to @window. In most cases, gtk_window_present()
1866 * should be used on a #GtkWindow, rather than calling this function.
1870 gdk_window_focus (GdkWindow *window,
1873 GdkDisplay *display;
1875 g_return_if_fail (GDK_IS_WINDOW (window));
1877 if (GDK_WINDOW_DESTROYED (window) ||
1878 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1881 display = GDK_WINDOW_DISPLAY (window);
1883 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1884 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
1886 XClientMessageEvent xclient;
1888 memset (&xclient, 0, sizeof (xclient));
1889 xclient.type = ClientMessage;
1890 xclient.window = GDK_WINDOW_XWINDOW (window);
1891 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1892 "_NET_ACTIVE_WINDOW");
1893 xclient.format = 32;
1894 xclient.data.l[0] = 1; /* requestor type; we're an app */
1895 xclient.data.l[1] = timestamp;
1896 xclient.data.l[2] = None; /* currently active window */
1897 xclient.data.l[3] = 0;
1898 xclient.data.l[4] = 0;
1900 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1901 SubstructureRedirectMask | SubstructureNotifyMask,
1902 (XEvent *)&xclient);
1906 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1908 /* There is no way of knowing reliably whether we are viewable;
1909 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1911 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1918 * gdk_window_set_type_hint:
1919 * @window: A toplevel #GdkWindow
1920 * @hint: A hint of the function this window will have
1922 * The application can use this call to provide a hint to the window
1923 * manager about the functionality of a window. The window manager
1924 * can use this information when determining the decoration and behaviour
1927 * The hint must be set before the window is mapped.
1930 gdk_window_set_type_hint (GdkWindow *window,
1931 GdkWindowTypeHint hint)
1933 GdkDisplay *display;
1936 if (GDK_WINDOW_DESTROYED (window) ||
1937 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1940 display = gdk_drawable_get_display (window);
1944 case GDK_WINDOW_TYPE_HINT_DIALOG:
1945 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1947 case GDK_WINDOW_TYPE_HINT_MENU:
1948 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1950 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1951 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1953 case GDK_WINDOW_TYPE_HINT_UTILITY:
1954 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1956 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1957 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1959 case GDK_WINDOW_TYPE_HINT_DOCK:
1960 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1962 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1963 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1965 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
1966 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
1968 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
1969 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
1971 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
1972 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
1974 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
1975 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
1977 case GDK_WINDOW_TYPE_HINT_COMBO:
1978 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
1980 case GDK_WINDOW_TYPE_HINT_DND:
1981 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
1984 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1986 case GDK_WINDOW_TYPE_HINT_NORMAL:
1987 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1991 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1992 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1993 XA_ATOM, 32, PropModeReplace,
1994 (guchar *)&atom, 1);
1998 * gdk_window_get_type_hint:
1999 * @window: A toplevel #GdkWindow
2001 * This function returns the type hint set for a window.
2003 * Return value: The type hint set for @window
2008 gdk_window_get_type_hint (GdkWindow *window)
2010 GdkDisplay *display;
2011 GdkWindowTypeHint type;
2014 gulong nitems_return;
2015 gulong bytes_after_return;
2016 guchar *data = NULL;
2018 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
2020 if (GDK_WINDOW_DESTROYED (window) ||
2021 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2022 return GDK_WINDOW_TYPE_HINT_NORMAL;
2024 type = GDK_WINDOW_TYPE_HINT_NORMAL;
2026 display = gdk_drawable_get_display (window);
2028 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2029 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
2030 0, G_MAXLONG, False, XA_ATOM, &type_return,
2031 &format_return, &nitems_return, &bytes_after_return,
2034 if ((type_return == XA_ATOM) && (format_return == 32) &&
2035 (data) && (nitems_return == 1))
2037 Atom atom = *(Atom*)data;
2039 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
2040 type = GDK_WINDOW_TYPE_HINT_DIALOG;
2041 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
2042 type = GDK_WINDOW_TYPE_HINT_MENU;
2043 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
2044 type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
2045 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
2046 type = GDK_WINDOW_TYPE_HINT_UTILITY;
2047 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
2048 type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
2049 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
2050 type = GDK_WINDOW_TYPE_HINT_DOCK;
2051 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
2052 type = GDK_WINDOW_TYPE_HINT_DESKTOP;
2053 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
2054 type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
2055 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
2056 type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
2057 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
2058 type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
2059 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
2060 type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
2061 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
2062 type = GDK_WINDOW_TYPE_HINT_COMBO;
2063 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
2064 type = GDK_WINDOW_TYPE_HINT_DND;
2067 if (type_return != None && data != NULL)
2075 gdk_wmspec_change_state (gboolean add,
2080 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
2081 XClientMessageEvent xclient;
2083 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
2084 #define _NET_WM_STATE_ADD 1 /* add/set property */
2085 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
2087 memset (&xclient, 0, sizeof (xclient));
2088 xclient.type = ClientMessage;
2089 xclient.window = GDK_WINDOW_XID (window);
2090 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
2091 xclient.format = 32;
2092 xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
2093 xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
2094 xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
2095 xclient.data.l[3] = 0;
2096 xclient.data.l[4] = 0;
2098 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
2099 SubstructureRedirectMask | SubstructureNotifyMask,
2100 (XEvent *)&xclient);
2104 * gdk_window_set_modal_hint:
2105 * @window: A toplevel #GdkWindow
2106 * @modal: %TRUE if the window is modal, %FALSE otherwise.
2108 * The application can use this hint to tell the window manager
2109 * that a certain window has modal behaviour. The window manager
2110 * can use this information to handle modal windows in a special
2113 * You should only use this on windows for which you have
2114 * previously called gdk_window_set_transient_for()
2117 gdk_window_set_modal_hint (GdkWindow *window,
2120 GdkWindowObject *private;
2122 if (GDK_WINDOW_DESTROYED (window) ||
2123 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2126 private = (GdkWindowObject*) window;
2128 private->modal_hint = modal;
2130 if (GDK_WINDOW_IS_MAPPED (window))
2131 gdk_wmspec_change_state (modal, window,
2132 gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
2137 * gdk_window_set_skip_taskbar_hint:
2138 * @window: a toplevel #GdkWindow
2139 * @skips_taskbar: %TRUE to skip the taskbar
2141 * Toggles whether a window should appear in a task list or window
2142 * list. If a window's semantic type as specified with
2143 * gdk_window_set_type_hint() already fully describes the window, this
2144 * function should <emphasis>not</emphasis> be called in addition,
2145 * instead you should allow the window to be treated according to
2146 * standard policy for its semantic type.
2151 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2152 gboolean skips_taskbar)
2154 GdkToplevelX11 *toplevel;
2156 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2158 if (GDK_WINDOW_DESTROYED (window) ||
2159 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2162 toplevel = _gdk_x11_window_get_toplevel (window);
2163 toplevel->skip_taskbar_hint = skips_taskbar;
2165 if (GDK_WINDOW_IS_MAPPED (window))
2166 gdk_wmspec_change_state (skips_taskbar, window,
2167 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
2172 * gdk_window_set_skip_pager_hint:
2173 * @window: a toplevel #GdkWindow
2174 * @skips_pager: %TRUE to skip the pager
2176 * Toggles whether a window should appear in a pager (workspace
2177 * switcher, or other desktop utility program that displays a small
2178 * thumbnail representation of the windows on the desktop). If a
2179 * window's semantic type as specified with gdk_window_set_type_hint()
2180 * already fully describes the window, this function should
2181 * <emphasis>not</emphasis> be called in addition, instead you should
2182 * allow the window to be treated according to standard policy for
2183 * its semantic type.
2188 gdk_window_set_skip_pager_hint (GdkWindow *window,
2189 gboolean skips_pager)
2191 GdkToplevelX11 *toplevel;
2193 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2195 if (GDK_WINDOW_DESTROYED (window) ||
2196 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2199 toplevel = _gdk_x11_window_get_toplevel (window);
2200 toplevel->skip_pager_hint = skips_pager;
2202 if (GDK_WINDOW_IS_MAPPED (window))
2203 gdk_wmspec_change_state (skips_pager, window,
2204 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
2209 * gdk_window_set_urgency_hint:
2210 * @window: a toplevel #GdkWindow
2211 * @urgent: %TRUE if the window is urgent
2213 * Toggles whether a window needs the user's
2219 gdk_window_set_urgency_hint (GdkWindow *window,
2222 GdkToplevelX11 *toplevel;
2224 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2226 if (GDK_WINDOW_DESTROYED (window) ||
2227 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2230 toplevel = _gdk_x11_window_get_toplevel (window);
2231 toplevel->urgency_hint = urgent;
2233 update_wm_hints (window, FALSE);
2237 * gdk_window_set_geometry_hints:
2238 * @window: a toplevel #GdkWindow
2239 * @geometry: geometry hints
2240 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
2242 * Sets the geometry hints for @window. Hints flagged in @geom_mask
2243 * are set, hints not flagged in @geom_mask are unset.
2244 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
2246 * This function provides hints to the windowing system about
2247 * acceptable sizes for a toplevel window. The purpose of
2248 * this is to constrain user resizing, but the windowing system
2249 * will typically (but is not required to) also constrain the
2250 * current size of the window to the provided values and
2251 * constrain programatic resizing via gdk_window_resize() or
2252 * gdk_window_move_resize().
2254 * Note that on X11, this effect has no effect on windows
2255 * of type %GDK_WINDOW_TEMP or windows where override redirect
2256 * has been turned on via gdk_window_set_override_redirect()
2257 * since these windows are not resizable by the user.
2259 * Since you can't count on the windowing system doing the
2260 * constraints for programmatic resizes, you should generally
2261 * call gdk_window_constrain_size() yourself to determine
2262 * appropriate sizes.
2266 gdk_window_set_geometry_hints (GdkWindow *window,
2267 const GdkGeometry *geometry,
2268 GdkWindowHints geom_mask)
2270 XSizeHints size_hints;
2272 if (GDK_WINDOW_DESTROYED (window) ||
2273 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2276 size_hints.flags = 0;
2278 if (geom_mask & GDK_HINT_POS)
2280 size_hints.flags |= PPosition;
2281 /* We need to initialize the following obsolete fields because KWM
2282 * apparently uses these fields if they are non-zero.
2289 if (geom_mask & GDK_HINT_USER_POS)
2291 size_hints.flags |= USPosition;
2294 if (geom_mask & GDK_HINT_USER_SIZE)
2296 size_hints.flags |= USSize;
2299 if (geom_mask & GDK_HINT_MIN_SIZE)
2301 size_hints.flags |= PMinSize;
2302 size_hints.min_width = geometry->min_width;
2303 size_hints.min_height = geometry->min_height;
2306 if (geom_mask & GDK_HINT_MAX_SIZE)
2308 size_hints.flags |= PMaxSize;
2309 size_hints.max_width = MAX (geometry->max_width, 1);
2310 size_hints.max_height = MAX (geometry->max_height, 1);
2313 if (geom_mask & GDK_HINT_BASE_SIZE)
2315 size_hints.flags |= PBaseSize;
2316 size_hints.base_width = geometry->base_width;
2317 size_hints.base_height = geometry->base_height;
2320 if (geom_mask & GDK_HINT_RESIZE_INC)
2322 size_hints.flags |= PResizeInc;
2323 size_hints.width_inc = geometry->width_inc;
2324 size_hints.height_inc = geometry->height_inc;
2327 if (geom_mask & GDK_HINT_ASPECT)
2329 size_hints.flags |= PAspect;
2330 if (geometry->min_aspect <= 1)
2332 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2333 size_hints.min_aspect.y = 65536;
2337 size_hints.min_aspect.x = 65536;
2338 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2340 if (geometry->max_aspect <= 1)
2342 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2343 size_hints.max_aspect.y = 65536;
2347 size_hints.max_aspect.x = 65536;
2348 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2352 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2354 size_hints.flags |= PWinGravity;
2355 size_hints.win_gravity = geometry->win_gravity;
2358 /* FIXME: Would it be better to delete this property if
2359 * geom_mask == 0? It would save space on the server
2361 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2362 GDK_WINDOW_XID (window),
2367 gdk_window_get_geometry_hints (GdkWindow *window,
2368 GdkGeometry *geometry,
2369 GdkWindowHints *geom_mask)
2371 XSizeHints *size_hints;
2372 glong junk_supplied_mask = 0;
2374 g_return_if_fail (GDK_IS_WINDOW (window));
2375 g_return_if_fail (geometry != NULL);
2376 g_return_if_fail (geom_mask != NULL);
2380 if (GDK_WINDOW_DESTROYED (window) ||
2381 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2384 size_hints = XAllocSizeHints ();
2388 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2389 GDK_WINDOW_XID (window),
2391 &junk_supplied_mask))
2392 size_hints->flags = 0;
2394 if (size_hints->flags & PMinSize)
2396 *geom_mask |= GDK_HINT_MIN_SIZE;
2397 geometry->min_width = size_hints->min_width;
2398 geometry->min_height = size_hints->min_height;
2401 if (size_hints->flags & PMaxSize)
2403 *geom_mask |= GDK_HINT_MAX_SIZE;
2404 geometry->max_width = MAX (size_hints->max_width, 1);
2405 geometry->max_height = MAX (size_hints->max_height, 1);
2408 if (size_hints->flags & PResizeInc)
2410 *geom_mask |= GDK_HINT_RESIZE_INC;
2411 geometry->width_inc = size_hints->width_inc;
2412 geometry->height_inc = size_hints->height_inc;
2415 if (size_hints->flags & PAspect)
2417 *geom_mask |= GDK_HINT_ASPECT;
2419 geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y;
2420 geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y;
2423 if (size_hints->flags & PWinGravity)
2425 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2426 geometry->win_gravity = size_hints->win_gravity;
2433 utf8_is_latin1 (const gchar *str)
2435 const char *p = str;
2439 gunichar ch = g_utf8_get_char (p);
2444 p = g_utf8_next_char (p);
2450 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2451 * convertable to STRING, otherwise, set it as compound text
2454 set_text_property (GdkDisplay *display,
2457 const gchar *utf8_str)
2459 gchar *prop_text = NULL;
2463 gboolean is_compound_text;
2465 if (utf8_is_latin1 (utf8_str))
2467 prop_type = XA_STRING;
2468 prop_text = gdk_utf8_to_string_target (utf8_str);
2469 prop_length = prop_text ? strlen (prop_text) : 0;
2471 is_compound_text = FALSE;
2477 gdk_utf8_to_compound_text_for_display (display,
2478 utf8_str, &gdk_type, &prop_format,
2479 (guchar **)&prop_text, &prop_length);
2480 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2481 is_compound_text = TRUE;
2486 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2489 prop_type, prop_format,
2490 PropModeReplace, (guchar *)prop_text,
2493 if (is_compound_text)
2494 gdk_free_compound_text ((guchar *)prop_text);
2500 /* Set WM_NAME and _NET_WM_NAME
2503 set_wm_name (GdkDisplay *display,
2507 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2508 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2509 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2510 PropModeReplace, (guchar *)name, strlen (name));
2512 set_text_property (display, xwindow,
2513 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2518 * gdk_window_set_title:
2519 * @window: a toplevel #GdkWindow
2520 * @title: title of @window
2522 * Sets the title of a toplevel window, to be displayed in the titlebar.
2523 * If you haven't explicitly set the icon name for the window
2524 * (using gdk_window_set_icon_name()), the icon name will be set to
2525 * @title as well. @title must be in UTF-8 encoding (as with all
2526 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2529 gdk_window_set_title (GdkWindow *window,
2532 GdkDisplay *display;
2536 g_return_if_fail (title != NULL);
2538 if (GDK_WINDOW_DESTROYED (window) ||
2539 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2542 display = gdk_drawable_get_display (window);
2543 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2544 xwindow = GDK_WINDOW_XID (window);
2546 set_wm_name (display, xwindow, title);
2548 if (!gdk_window_icon_name_set (window))
2550 XChangeProperty (xdisplay, xwindow,
2551 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2552 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2553 PropModeReplace, (guchar *)title, strlen (title));
2555 set_text_property (display, xwindow,
2556 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2562 * gdk_window_set_role:
2563 * @window: a toplevel #GdkWindow
2564 * @role: a string indicating its role
2566 * When using GTK+, typically you should use gtk_window_set_role() instead
2567 * of this low-level function.
2569 * The window manager and session manager use a window's role to
2570 * distinguish it from other kinds of window in the same application.
2571 * When an application is restarted after being saved in a previous
2572 * session, all windows with the same title and role are treated as
2573 * interchangeable. So if you have two windows with the same title
2574 * that should be distinguished for session management purposes, you
2575 * should set the role on those windows. It doesn't matter what string
2576 * you use for the role, as long as you have a different role for each
2577 * non-interchangeable kind of window.
2581 gdk_window_set_role (GdkWindow *window,
2584 GdkDisplay *display;
2586 display = gdk_drawable_get_display (window);
2588 if (GDK_WINDOW_DESTROYED (window) ||
2589 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2593 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2594 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2595 XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
2597 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2598 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2602 * gdk_window_set_startup_id:
2603 * @window: a toplevel #GdkWindow
2604 * @startup_id: a string with startup-notification identifier
2606 * When using GTK+, typically you should use gtk_window_set_startup_id()
2607 * instead of this low-level function.
2613 gdk_window_set_startup_id (GdkWindow *window,
2614 const gchar *startup_id)
2616 GdkDisplay *display;
2618 g_return_if_fail (GDK_IS_WINDOW (window));
2620 display = gdk_drawable_get_display (window);
2622 if (GDK_WINDOW_DESTROYED (window) ||
2623 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2627 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2628 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2629 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2630 PropModeReplace, (unsigned char *)startup_id, strlen (startup_id));
2632 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2633 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"));
2637 * gdk_window_set_transient_for:
2638 * @window: a toplevel #GdkWindow
2639 * @parent: another toplevel #GdkWindow
2641 * Indicates to the window manager that @window is a transient dialog
2642 * associated with the application window @parent. This allows the
2643 * window manager to do things like center @window on @parent and
2644 * keep @window above @parent.
2646 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2650 gdk_window_set_transient_for (GdkWindow *window,
2653 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) &&
2654 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2655 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2656 GDK_WINDOW_XID (window),
2657 GDK_WINDOW_XID (parent));
2661 gdk_window_x11_set_back_color (GdkWindow *window,
2664 GdkColor allocated = *color;
2666 if (!gdk_colormap_alloc_color (gdk_drawable_get_colormap (window),
2671 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2672 GDK_WINDOW_XID (window), allocated.pixel);
2674 gdk_colormap_free_colors (gdk_drawable_get_colormap (window), &allocated, 1);
2678 matrix_is_identity (cairo_matrix_t *matrix)
2680 return matrix->xx == 1.0 && matrix->yy == 1.0 &&
2681 matrix->yx == 0.0 && matrix->xy == 0.0 &&
2682 matrix->x0 == 0.0 && matrix->y0 == 0.0;
2686 gdk_window_x11_set_background (GdkWindow *window,
2687 cairo_pattern_t *pattern)
2689 GdkColor color = { 0, };
2691 cairo_surface_t *surface;
2692 cairo_matrix_t matrix;
2694 if (GDK_WINDOW_DESTROYED (window))
2697 if (pattern == NULL)
2699 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2700 GDK_WINDOW_XID (window), ParentRelative);
2704 switch (cairo_pattern_get_type (pattern))
2706 case CAIRO_PATTERN_TYPE_SOLID:
2707 cairo_pattern_get_rgba (pattern, &r, &g, &b, &a);
2708 color.red = r * 65535;
2709 color.green = g * 65535;
2710 color.blue = b * 65535;
2712 case CAIRO_PATTERN_TYPE_SURFACE:
2713 cairo_pattern_get_matrix (pattern, &matrix);
2714 if (cairo_pattern_get_surface (pattern, &surface) == CAIRO_STATUS_SUCCESS &&
2715 matrix_is_identity (&matrix) &&
2716 cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB &&
2717 cairo_xlib_surface_get_display (surface) == GDK_WINDOW_XDISPLAY (window))
2721 cairo_surface_get_device_offset (surface, &x, &y);
2722 /* XXX: This still bombs for non-pixmaps, but there's no way to
2723 * detect we're not a pixmap in Cairo... */
2724 if (x == 0.0 && y == 0.0)
2726 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2727 GDK_WINDOW_XID (window),
2728 cairo_xlib_surface_get_drawable (surface));
2733 case CAIRO_PATTERN_TYPE_LINEAR:
2734 case CAIRO_PATTERN_TYPE_RADIAL:
2736 /* fallback: just use black */
2740 gdk_window_x11_set_back_color (window, &color);
2744 gdk_window_x11_set_device_cursor (GdkWindow *window,
2748 GdkWindowObject *private;
2749 GdkWindowImplX11 *impl;
2751 g_return_if_fail (GDK_IS_WINDOW (window));
2752 g_return_if_fail (GDK_IS_DEVICE (device));
2754 private = (GdkWindowObject *) window;
2755 impl = GDK_WINDOW_IMPL_X11 (private->impl);
2758 g_hash_table_remove (impl->device_cursor, device);
2761 _gdk_x11_cursor_update_theme (cursor);
2762 g_hash_table_replace (impl->device_cursor,
2763 device, gdk_cursor_ref (cursor));
2766 if (!GDK_WINDOW_DESTROYED (window))
2767 GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor);
2771 _gdk_x11_window_get_cursor (GdkWindow *window)
2773 GdkWindowObject *private;
2774 GdkWindowImplX11 *impl;
2776 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2778 private = (GdkWindowObject *)window;
2779 impl = GDK_WINDOW_IMPL_X11 (private->impl);
2781 return impl->cursor;
2785 gdk_window_x11_get_geometry (GdkWindow *window,
2797 guint tborder_width;
2800 if (!GDK_WINDOW_DESTROYED (window))
2802 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2803 GDK_WINDOW_XID (window),
2804 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2820 gdk_window_x11_get_root_coords (GdkWindow *window,
2831 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2832 GDK_WINDOW_XID (window),
2833 GDK_WINDOW_XROOTWIN (window),
2846 * gdk_window_get_root_origin:
2847 * @window: a toplevel #GdkWindow
2848 * @x: return location for X position of window frame
2849 * @y: return location for Y position of window frame
2851 * Obtains the top-left corner of the window manager frame in root
2852 * window coordinates.
2856 gdk_window_get_root_origin (GdkWindow *window,
2862 gdk_window_get_frame_extents (window, &rect);
2872 * gdk_window_get_frame_extents:
2873 * @window: a toplevel #GdkWindow
2874 * @rect: rectangle to fill with bounding box of the window frame
2876 * Obtains the bounding box of the window, including window manager
2877 * titlebar/borders if any. The frame position is given in root window
2878 * coordinates. To get the position of the window itself (rather than
2879 * the frame) in root window coordinates, use gdk_window_get_origin().
2883 gdk_window_get_frame_extents (GdkWindow *window,
2886 GdkDisplay *display;
2887 GdkWindowObject *private;
2888 GdkWindowImplX11 *impl;
2899 gulong nitems_return;
2900 gulong bytes_after_return;
2903 guint ww, wh, wb, wd;
2905 gboolean got_frame_extents = FALSE;
2907 g_return_if_fail (rect != NULL);
2909 private = (GdkWindowObject*) window;
2916 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2917 private = (GdkWindowObject*) private->parent;
2919 /* Refine our fallback answer a bit using local information */
2920 rect->x = private->x;
2921 rect->y = private->y;
2922 gdk_drawable_get_size ((GdkDrawable *)private, &rect->width, &rect->height);
2924 impl = GDK_WINDOW_IMPL_X11 (private->impl);
2925 if (GDK_WINDOW_DESTROYED (private) || impl->override_redirect)
2931 gdk_error_trap_push();
2933 display = gdk_drawable_get_display (window);
2934 xwindow = GDK_WINDOW_XID (window);
2936 /* first try: use _NET_FRAME_EXTENTS */
2937 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2938 gdk_x11_get_xatom_by_name_for_display (display,
2939 "_NET_FRAME_EXTENTS"),
2940 0, G_MAXLONG, False, XA_CARDINAL, &type_return,
2941 &format_return, &nitems_return, &bytes_after_return,
2945 if ((type_return == XA_CARDINAL) && (format_return == 32) &&
2946 (nitems_return == 4) && (data))
2948 gulong *ldata = (gulong *) data;
2949 got_frame_extents = TRUE;
2951 /* try to get the real client window geometry */
2952 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2953 &root, &wx, &wy, &ww, &wh, &wb, &wd) &&
2954 XTranslateCoordinates (GDK_DISPLAY_XDISPLAY (display),
2955 xwindow, root, 0, 0, &wx, &wy, &child))
2963 /* _NET_FRAME_EXTENTS format is left, right, top, bottom */
2964 rect->x -= ldata[0];
2965 rect->y -= ldata[2];
2966 rect->width += ldata[0] + ldata[1];
2967 rect->height += ldata[2] + ldata[3];
2974 if (got_frame_extents)
2977 /* no frame extents property available, which means we either have a WM that
2978 is not EWMH compliant or is broken - try fallback and walk up the window
2979 tree to get our window's parent which hopefully is the window frame */
2981 /* use NETWM_VIRTUAL_ROOTS if available */
2982 root = GDK_WINDOW_XROOTWIN (window);
2984 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
2985 gdk_x11_get_xatom_by_name_for_display (display,
2986 "_NET_VIRTUAL_ROOTS"),
2987 0, G_MAXLONG, False, XA_WINDOW, &type_return,
2988 &format_return, &nitems_return, &bytes_after_return,
2992 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
2994 nvroots = nitems_return;
2995 vroots = (Window *)data;
2999 xparent = GDK_WINDOW_XID (window);
3005 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
3007 &children, &nchildren))
3013 /* check virtual roots */
3014 for (i = 0; i < nvroots; i++)
3016 if (xparent == vroots[i])
3023 while (xparent != root);
3025 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
3026 &root, &wx, &wy, &ww, &wh, &wb, &wd))
3038 gdk_error_trap_pop_ignored ();
3042 _gdk_windowing_get_device_state (GdkDisplay *display,
3047 GdkModifierType *mask)
3049 GdkScreen *default_screen;
3051 if (display->closed)
3054 default_screen = gdk_display_get_default_screen (display);
3057 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3061 GDK_DEVICE_GET_CLASS (device)->query_state (device,
3062 gdk_screen_get_root_window (default_screen),
3067 *screen = gdk_drawable_get_screen (root);
3071 XSetWindowAttributes attributes;
3073 Window xwindow, w, root, child;
3074 int rootx, rooty, winx, winy;
3077 /* FIXME: untrusted clients not multidevice-safe */
3079 xdisplay = GDK_SCREEN_XDISPLAY (default_screen);
3080 xwindow = GDK_SCREEN_XROOTWIN (default_screen);
3082 w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0,
3083 CopyFromParent, InputOnly, CopyFromParent,
3085 XQueryPointer (xdisplay, w,
3086 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3087 XDestroyWindow (xdisplay, w);
3091 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
3092 *screen = gdk_drawable_get_screen (gdk_root);
3102 gdk_window_x11_get_device_state (GdkWindow *window,
3106 GdkModifierType *mask)
3108 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
3109 gboolean return_val;
3111 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
3115 if (!GDK_WINDOW_DESTROYED (window))
3117 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3121 GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
3125 return_val = (child != NULL);
3130 int originx, originy;
3134 unsigned int xmask = 0;
3136 _gdk_windowing_get_device_state (gdk_drawable_get_display (window), device,
3137 &screen, &rootx, &rooty, &xmask);
3138 gdk_window_get_origin (window, &originx, &originy);
3139 winx = rootx - originx;
3140 winy = rooty - originy;
3152 * gdk_display_warp_pointer:
3153 * @display: a #GdkDisplay
3154 * @screen: the screen of @display to warp the pointer to
3155 * @x: the x coordinate of the destination
3156 * @y: the y coordinate of the destination
3158 * Warps the pointer of @display to the point @x,@y on
3159 * the screen @screen, unless the pointer is confined
3160 * to a window by a grab, in which case it will be moved
3161 * as far as allowed by the grab. Warping the pointer
3162 * creates events as if the user had moved the mouse
3163 * instantaneously to the destination.
3165 * Note that the pointer should normally be under the
3166 * control of the user. This function was added to cover
3167 * some rare use cases like keyboard navigation support
3168 * for the color picker in the #GtkColorSelectionDialog.
3172 * Deprecated: 3.0: Use gdk_display_warp_device() instead.
3175 gdk_display_warp_pointer (GdkDisplay *display,
3182 g_return_if_fail (GDK_IS_DISPLAY (display));
3183 g_return_if_fail (GDK_IS_SCREEN (screen));
3185 device = display->core_pointer;
3186 GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
3190 * gdk_display_warp_device:
3191 * @display: a #GdkDisplay.
3192 * @device: a #GdkDevice.
3193 * @screen: the screen of @display to warp @device to.
3194 * @x: the X coordinate of the destination.
3195 * @y: the Y coordinate of the destination.
3197 * Warps @device in @display to the point @x,@y on
3198 * the screen @screen, unless the device is confined
3199 * to a window by a grab, in which case it will be moved
3200 * as far as allowed by the grab. Warping the pointer
3201 * creates events as if the user had moved the mouse
3202 * instantaneously to the destination.
3204 * Note that the pointer should normally be under the
3205 * control of the user. This function was added to cover
3206 * some rare use cases like keyboard navigation support
3207 * for the color picker in the #GtkColorSelectionDialog.
3212 gdk_display_warp_device (GdkDisplay *display,
3218 g_return_if_fail (GDK_IS_DISPLAY (display));
3219 g_return_if_fail (GDK_IS_DEVICE (device));
3220 g_return_if_fail (GDK_IS_SCREEN (screen));
3221 g_return_if_fail (display == gdk_device_get_display (device));
3223 GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
3227 _gdk_windowing_window_at_device_position (GdkDisplay *display,
3231 GdkModifierType *mask,
3232 gboolean get_toplevel)
3237 screen = gdk_display_get_default_screen (display);
3239 /* This function really only works if the mouse pointer is held still
3240 * during its operation. If it moves from one leaf window to another
3241 * than we'll end up with inaccurate values for win_x, win_y
3244 gdk_x11_display_grab (display);
3245 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3246 window = GDK_DEVICE_GET_CLASS (device)->window_at_position (device, win_x, win_y, mask, get_toplevel);
3249 gint i, screens, width, height;
3250 GList *toplevels, *list;
3251 Window pointer_window, root, xwindow, child;
3252 Window xwindow_last = 0;
3254 int rootx = -1, rooty = -1;
3258 /* FIXME: untrusted clients case not multidevice-safe */
3260 xwindow = GDK_SCREEN_XROOTWIN (screen);
3261 xdisplay = GDK_SCREEN_XDISPLAY (screen);
3263 pointer_window = None;
3264 screens = gdk_display_get_n_screens (display);
3265 for (i = 0; i < screens; ++i) {
3266 screen = gdk_display_get_screen (display, i);
3267 toplevels = gdk_screen_get_toplevel_windows (screen);
3268 for (list = toplevels; list != NULL; list = g_list_next (list)) {
3269 window = GDK_WINDOW (list->data);
3270 xwindow = GDK_WINDOW_XWINDOW (window);
3271 gdk_error_trap_push ();
3272 XQueryPointer (xdisplay, xwindow,
3273 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3274 if (gdk_error_trap_pop ())
3278 pointer_window = child;
3281 gdk_window_get_geometry (window, NULL, NULL, &width, &height, NULL);
3282 if (winx >= 0 && winy >= 0 && winx < width && winy < height)
3284 /* A childless toplevel, or below another window? */
3285 XSetWindowAttributes attributes;
3288 w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0,
3289 CopyFromParent, InputOnly, CopyFromParent,
3291 XMapWindow (xdisplay, w);
3292 XQueryPointer (xdisplay, xwindow,
3293 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3294 XDestroyWindow (xdisplay, w);
3297 pointer_window = xwindow;
3302 g_list_free (toplevels);
3303 if (pointer_window != None)
3306 xwindow = pointer_window;
3310 xwindow_last = xwindow;
3311 gdk_error_trap_push ();
3312 XQueryPointer (xdisplay, xwindow,
3313 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3314 if (gdk_error_trap_pop ())
3316 if (get_toplevel && xwindow_last != root &&
3317 (window = gdk_window_lookup_for_display (display, xwindow_last)) != NULL &&
3318 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
3322 window = gdk_window_lookup_for_display (display, xwindow_last);
3324 *win_x = window ? winx : -1;
3325 *win_y = window ? winy : -1;
3330 gdk_x11_display_ungrab (display);
3336 gdk_window_x11_get_events (GdkWindow *window)
3338 XWindowAttributes attrs;
3339 GdkEventMask event_mask;
3340 GdkEventMask filtered;
3342 if (GDK_WINDOW_DESTROYED (window))
3346 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3347 GDK_WINDOW_XID (window),
3349 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
3350 /* if property change was filtered out before, keep it filtered out */
3351 filtered = GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK;
3352 GDK_WINDOW_OBJECT (window)->event_mask = event_mask & ((GDK_WINDOW_OBJECT (window)->event_mask & filtered) | ~filtered);
3358 gdk_window_x11_set_events (GdkWindow *window,
3359 GdkEventMask event_mask)
3361 long xevent_mask = 0;
3363 if (!GDK_WINDOW_DESTROYED (window))
3365 GdkDisplayX11 *display_x11;
3367 if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window))
3368 xevent_mask = StructureNotifyMask | PropertyChangeMask;
3370 display_x11 = GDK_DISPLAY_X11 (gdk_drawable_get_display (window));
3371 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
3372 GDK_WINDOW_XWINDOW (window), event_mask,
3378 gdk_window_add_colormap_windows (GdkWindow *window)
3380 GdkWindow *toplevel;
3381 Window *old_windows;
3382 Window *new_windows;
3385 g_return_if_fail (GDK_IS_WINDOW (window));
3387 if (GDK_WINDOW_DESTROYED (window))
3390 toplevel = gdk_window_get_toplevel (window);
3393 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3394 GDK_WINDOW_XID (toplevel),
3395 &old_windows, &count))
3400 for (i = 0; i < count; i++)
3401 if (old_windows[i] == GDK_WINDOW_XID (window))
3403 XFree (old_windows);
3407 new_windows = g_new (Window, count + 1);
3409 for (i = 0; i < count; i++)
3410 new_windows[i] = old_windows[i];
3411 new_windows[count] = GDK_WINDOW_XID (window);
3413 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3414 GDK_WINDOW_XID (toplevel),
3415 new_windows, count + 1);
3417 g_free (new_windows);
3419 XFree (old_windows);
3423 do_shape_combine_region (GdkWindow *window,
3424 const cairo_region_t *shape_region,
3429 if (GDK_WINDOW_DESTROYED (window))
3432 if (shape_region == NULL)
3434 /* Use NULL mask to unset the shape */
3435 if (shape == ShapeBounding
3436 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3437 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3439 if (shape == ShapeBounding)
3441 _gdk_x11_window_tmp_unset_parent_bg (window);
3442 _gdk_x11_window_tmp_unset_bg (window, TRUE);
3444 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3445 GDK_WINDOW_XID (window),
3450 if (shape == ShapeBounding)
3452 _gdk_x11_window_tmp_reset_parent_bg (window);
3453 _gdk_x11_window_tmp_reset_bg (window, TRUE);
3459 if (shape == ShapeBounding
3460 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3461 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3464 XRectangle *xrects = NULL;
3466 _gdk_region_get_xrectangles (shape_region,
3470 if (shape == ShapeBounding)
3472 _gdk_x11_window_tmp_unset_parent_bg (window);
3473 _gdk_x11_window_tmp_unset_bg (window, TRUE);
3475 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3476 GDK_WINDOW_XID (window),
3483 if (shape == ShapeBounding)
3485 _gdk_x11_window_tmp_reset_parent_bg (window);
3486 _gdk_x11_window_tmp_reset_bg (window, TRUE);
3494 gdk_window_x11_shape_combine_region (GdkWindow *window,
3495 const cairo_region_t *shape_region,
3499 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
3503 gdk_window_x11_input_shape_combine_region (GdkWindow *window,
3504 const cairo_region_t *shape_region,
3509 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
3515 * gdk_window_set_override_redirect:
3516 * @window: a toplevel #GdkWindow
3517 * @override_redirect: %TRUE if window should be override redirect
3519 * An override redirect window is not under the control of the window manager.
3520 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3521 * be entirely under the control of the application. The window manager
3522 * can't see the override redirect window at all.
3524 * Override redirect should only be used for short-lived temporary
3525 * windows, such as popup menus. #GtkMenu uses an override redirect
3526 * window in its implementation, for example.
3530 gdk_window_set_override_redirect (GdkWindow *window,
3531 gboolean override_redirect)
3533 XSetWindowAttributes attr;
3535 if (!GDK_WINDOW_DESTROYED (window) &&
3536 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3538 GdkWindowObject *private = (GdkWindowObject *)window;
3539 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
3541 attr.override_redirect = (override_redirect? True : False);
3542 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3543 GDK_WINDOW_XID (window),
3547 impl->override_redirect = attr.override_redirect;
3552 * gdk_window_set_accept_focus:
3553 * @window: a toplevel #GdkWindow
3554 * @accept_focus: %TRUE if the window should receive input focus
3556 * Setting @accept_focus to %FALSE hints the desktop environment that the
3557 * window doesn't want to receive input focus.
3559 * On X, it is the responsibility of the window manager to interpret this
3560 * hint. ICCCM-compliant window manager usually respect it.
3565 gdk_window_set_accept_focus (GdkWindow *window,
3566 gboolean accept_focus)
3568 GdkWindowObject *private;
3570 private = (GdkWindowObject *)window;
3572 accept_focus = accept_focus != FALSE;
3574 if (private->accept_focus != accept_focus)
3576 private->accept_focus = accept_focus;
3578 if (!GDK_WINDOW_DESTROYED (window) &&
3579 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3580 update_wm_hints (window, FALSE);
3585 * gdk_window_set_focus_on_map:
3586 * @window: a toplevel #GdkWindow
3587 * @focus_on_map: %TRUE if the window should receive input focus when mapped
3589 * Setting @focus_on_map to %FALSE hints the desktop environment that the
3590 * window doesn't want to receive input focus when it is mapped.
3591 * focus_on_map should be turned off for windows that aren't triggered
3592 * interactively (such as popups from network activity).
3594 * On X, it is the responsibility of the window manager to interpret
3595 * this hint. Window managers following the freedesktop.org window
3596 * manager extension specification should respect it.
3601 gdk_window_set_focus_on_map (GdkWindow *window,
3602 gboolean focus_on_map)
3604 GdkWindowObject *private;
3606 private = (GdkWindowObject *)window;
3608 focus_on_map = focus_on_map != FALSE;
3610 if (private->focus_on_map != focus_on_map)
3612 private->focus_on_map = focus_on_map;
3614 if ((!GDK_WINDOW_DESTROYED (window)) &&
3615 (!private->focus_on_map) &&
3616 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3617 gdk_x11_window_set_user_time (window, 0);
3622 * gdk_x11_window_set_user_time:
3623 * @window: A toplevel #GdkWindow
3624 * @timestamp: An XServer timestamp to which the property should be set
3626 * The application can use this call to update the _NET_WM_USER_TIME
3627 * property on a toplevel window. This property stores an Xserver
3628 * time which represents the time of the last user input event
3629 * received for this window. This property may be used by the window
3630 * manager to alter the focus, stacking, and/or placement behavior of
3631 * windows when they are mapped depending on whether the new window
3632 * was created by a user action or is a "pop-up" window activated by a
3633 * timer or some other event.
3635 * Note that this property is automatically updated by GDK, so this
3636 * function should only be used by applications which handle input
3637 * events bypassing GDK.
3642 gdk_x11_window_set_user_time (GdkWindow *window,
3645 GdkDisplay *display;
3646 GdkDisplayX11 *display_x11;
3647 GdkToplevelX11 *toplevel;
3648 glong timestamp_long = (glong)timestamp;
3651 if (GDK_WINDOW_DESTROYED (window) ||
3652 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3655 display = gdk_drawable_get_display (window);
3656 display_x11 = GDK_DISPLAY_X11 (display);
3657 toplevel = _gdk_x11_window_get_toplevel (window);
3661 g_warning ("gdk_window_set_user_time called on non-toplevel\n");
3665 if (toplevel->focus_window != None &&
3666 gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
3667 gdk_atom_intern_static_string ("_NET_WM_USER_TIME_WINDOW")))
3668 xid = toplevel->focus_window;
3670 xid = GDK_WINDOW_XID (window);
3672 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xid,
3673 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3674 XA_CARDINAL, 32, PropModeReplace,
3675 (guchar *)×tamp_long, 1);
3677 if (timestamp_long != GDK_CURRENT_TIME &&
3678 (display_x11->user_time == GDK_CURRENT_TIME ||
3679 XSERVER_TIME_IS_LATER (timestamp_long, display_x11->user_time)))
3680 display_x11->user_time = timestamp_long;
3683 toplevel->user_time = timestamp_long;
3686 #define GDK_SELECTION_MAX_SIZE(display) \
3688 XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
3689 ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
3690 : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
3693 gdk_window_update_icon (GdkWindow *window,
3696 GdkToplevelX11 *toplevel;
3697 GdkPixbuf *best_icon;
3701 toplevel = _gdk_x11_window_get_toplevel (window);
3703 if (toplevel->icon_pixmap != NULL)
3705 cairo_surface_destroy (toplevel->icon_pixmap);
3706 toplevel->icon_pixmap = NULL;
3709 if (toplevel->icon_mask != NULL)
3711 cairo_surface_destroy (toplevel->icon_mask);
3712 toplevel->icon_mask = NULL;
3715 #define IDEAL_SIZE 48
3717 best_size = G_MAXINT;
3719 for (tmp_list = icon_list; tmp_list; tmp_list = tmp_list->next)
3721 GdkPixbuf *pixbuf = tmp_list->data;
3724 /* average width and height - if someone passes in a rectangular
3725 * icon they deserve what they get.
3727 this = gdk_pixbuf_get_width (pixbuf) + gdk_pixbuf_get_height (pixbuf);
3730 if (best_icon == NULL)
3737 /* icon is better if it's 32 pixels or larger, and closer to
3738 * the ideal size than the current best.
3741 (ABS (best_size - IDEAL_SIZE) <
3742 ABS (this - IDEAL_SIZE)))
3752 int width = gdk_pixbuf_get_width (best_icon);
3753 int height = gdk_pixbuf_get_height (best_icon);
3756 toplevel->icon_pixmap = gdk_x11_window_create_pixmap_surface (window,
3760 cr = cairo_create (toplevel->icon_pixmap);
3761 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3762 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3763 if (gdk_pixbuf_get_has_alpha (best_icon))
3765 /* Saturate the image, so it has bilevel alpha */
3766 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
3768 cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);
3770 cairo_pop_group_to_source (cr);
3775 if (gdk_pixbuf_get_has_alpha (best_icon))
3777 toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window,
3781 cr = cairo_create (toplevel->icon_mask);
3782 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3783 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3789 update_wm_hints (window, FALSE);
3793 * gdk_window_set_icon_list:
3794 * @window: The #GdkWindow toplevel window to set the icon of.
3795 * @pixbufs: (transfer none) (element-type GdkPixbuf):
3796 * A list of pixbufs, of different sizes.
3798 * Sets a list of icons for the window. One of these will be used
3799 * to represent the window when it has been iconified. The icon is
3800 * usually shown in an icon box or some sort of task bar. Which icon
3801 * size is shown depends on the window manager. The window manager
3802 * can scale the icon but setting several size icons can give better
3803 * image quality since the window manager may only need to scale the
3804 * icon by a small amount or not at all.
3808 gdk_window_set_icon_list (GdkWindow *window,
3817 gint width, height, stride;
3820 GdkDisplay *display;
3823 if (GDK_WINDOW_DESTROYED (window) ||
3824 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3827 display = gdk_drawable_get_display (window);
3835 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3837 width = gdk_pixbuf_get_width (pixbuf);
3838 height = gdk_pixbuf_get_height (pixbuf);
3840 /* silently ignore overlarge icons */
3841 if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
3843 g_warning ("gdk_window_set_icon_list: icons too large");
3848 size += 2 + width * height;
3850 l = g_list_next (l);
3853 data = g_malloc (size * sizeof (gulong));
3861 width = gdk_pixbuf_get_width (pixbuf);
3862 height = gdk_pixbuf_get_height (pixbuf);
3863 stride = gdk_pixbuf_get_rowstride (pixbuf);
3864 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3869 pixels = gdk_pixbuf_get_pixels (pixbuf);
3871 for (y = 0; y < height; y++)
3873 for (x = 0; x < width; x++)
3877 r = pixels[y*stride + x*n_channels + 0];
3878 g = pixels[y*stride + x*n_channels + 1];
3879 b = pixels[y*stride + x*n_channels + 2];
3880 if (n_channels >= 4)
3881 a = pixels[y*stride + x*n_channels + 3];
3885 *p++ = a << 24 | r << 16 | g << 8 | b ;
3889 l = g_list_next (l);
3895 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3896 GDK_WINDOW_XID (window),
3897 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3900 (guchar*) data, size);
3904 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3905 GDK_WINDOW_XID (window),
3906 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3911 gdk_window_update_icon (window, pixbufs);
3915 gdk_window_icon_name_set (GdkWindow *window)
3917 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3918 g_quark_from_static_string ("gdk-icon-name-set")));
3922 * gdk_window_set_icon_name:
3923 * @window: a toplevel #GdkWindow
3924 * @name: name of window while iconified (minimized)
3926 * Windows may have a name used while minimized, distinct from the
3927 * name they display in their titlebar. Most of the time this is a bad
3928 * idea from a user interface standpoint. But you can set such a name
3929 * with this function, if you like.
3931 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
3932 * will not update the icon title.
3934 * Using %NULL for @name unsets the icon title; further calls to
3935 * gdk_window_set_title() will again update the icon title as well.
3938 gdk_window_set_icon_name (GdkWindow *window,
3941 GdkDisplay *display;
3943 if (GDK_WINDOW_DESTROYED (window) ||
3944 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3947 display = gdk_drawable_get_display (window);
3949 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3950 GUINT_TO_POINTER (name != NULL));
3954 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3955 GDK_WINDOW_XID (window),
3956 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3957 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3958 PropModeReplace, (guchar *)name, strlen (name));
3960 set_text_property (display, GDK_WINDOW_XID (window),
3961 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3966 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3967 GDK_WINDOW_XID (window),
3968 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"));
3969 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3970 GDK_WINDOW_XID (window),
3971 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"));
3976 * gdk_window_iconify:
3977 * @window: a toplevel #GdkWindow
3979 * Asks to iconify (minimize) @window. The window manager may choose
3980 * to ignore the request, but normally will honor it. Using
3981 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3983 * This function only makes sense when @window is a toplevel window.
3987 gdk_window_iconify (GdkWindow *window)
3989 if (GDK_WINDOW_DESTROYED (window) ||
3990 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3993 if (GDK_WINDOW_IS_MAPPED (window))
3995 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3996 GDK_WINDOW_XWINDOW (window),
3997 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
4001 /* Flip our client side flag, the real work happens on map. */
4002 gdk_synthesize_window_state (window,
4004 GDK_WINDOW_STATE_ICONIFIED);
4009 * gdk_window_deiconify:
4010 * @window: a toplevel #GdkWindow
4012 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
4013 * choose to ignore the request to deiconify. When using GTK+,
4014 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
4015 * you probably want to use gtk_window_present(), which raises the window, focuses it,
4016 * unminimizes it, and puts it on the current desktop.
4020 gdk_window_deiconify (GdkWindow *window)
4022 if (GDK_WINDOW_DESTROYED (window) ||
4023 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4026 if (GDK_WINDOW_IS_MAPPED (window))
4028 gdk_window_show (window);
4032 /* Flip our client side flag, the real work happens on map. */
4033 gdk_synthesize_window_state (window,
4034 GDK_WINDOW_STATE_ICONIFIED,
4041 * @window: a toplevel #GdkWindow
4043 * "Pins" a window such that it's on all workspaces and does not scroll
4044 * with viewports, for window managers that have scrollable viewports.
4045 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
4047 * On the X11 platform, this function depends on window manager
4048 * support, so may have no effect with many window managers. However,
4049 * GDK will do the best it can to convince the window manager to stick
4050 * the window. For window managers that don't support this operation,
4051 * there's nothing you can do to force it to happen.
4055 gdk_window_stick (GdkWindow *window)
4057 if (GDK_WINDOW_DESTROYED (window) ||
4058 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4061 if (GDK_WINDOW_IS_MAPPED (window))
4063 /* "stick" means stick to all desktops _and_ do not scroll with the
4064 * viewport. i.e. glue to the monitor glass in all cases.
4067 XClientMessageEvent xclient;
4069 /* Request stick during viewport scroll */
4070 gdk_wmspec_change_state (TRUE, window,
4071 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4074 /* Request desktop 0xFFFFFFFF */
4075 memset (&xclient, 0, sizeof (xclient));
4076 xclient.type = ClientMessage;
4077 xclient.window = GDK_WINDOW_XWINDOW (window);
4078 xclient.display = GDK_WINDOW_XDISPLAY (window);
4079 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
4081 xclient.format = 32;
4083 xclient.data.l[0] = 0xFFFFFFFF;
4084 xclient.data.l[1] = 0;
4085 xclient.data.l[2] = 0;
4086 xclient.data.l[3] = 0;
4087 xclient.data.l[4] = 0;
4089 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
4090 SubstructureRedirectMask | SubstructureNotifyMask,
4091 (XEvent *)&xclient);
4095 /* Flip our client side flag, the real work happens on map. */
4096 gdk_synthesize_window_state (window,
4098 GDK_WINDOW_STATE_STICKY);
4103 * gdk_window_unstick:
4104 * @window: a toplevel #GdkWindow
4106 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
4107 * and gtk_window_unstick().
4111 gdk_window_unstick (GdkWindow *window)
4113 if (GDK_WINDOW_DESTROYED (window) ||
4114 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4117 if (GDK_WINDOW_IS_MAPPED (window))
4119 /* Request unstick from viewport */
4120 gdk_wmspec_change_state (FALSE, window,
4121 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4124 move_to_current_desktop (window);
4128 /* Flip our client side flag, the real work happens on map. */
4129 gdk_synthesize_window_state (window,
4130 GDK_WINDOW_STATE_STICKY,
4137 * gdk_window_maximize:
4138 * @window: a toplevel #GdkWindow
4140 * Maximizes the window. If the window was already maximized, then
4141 * this function does nothing.
4143 * On X11, asks the window manager to maximize @window, if the window
4144 * manager supports this operation. Not all window managers support
4145 * this, and some deliberately ignore it or don't have a concept of
4146 * "maximized"; so you can't rely on the maximization actually
4147 * happening. But it will happen with most standard window managers,
4148 * and GDK makes a best effort to get it to happen.
4150 * On Windows, reliably maximizes the window.
4154 gdk_window_maximize (GdkWindow *window)
4156 if (GDK_WINDOW_DESTROYED (window) ||
4157 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4160 if (GDK_WINDOW_IS_MAPPED (window))
4161 gdk_wmspec_change_state (TRUE, window,
4162 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4163 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4165 gdk_synthesize_window_state (window,
4167 GDK_WINDOW_STATE_MAXIMIZED);
4171 * gdk_window_unmaximize:
4172 * @window: a toplevel #GdkWindow
4174 * Unmaximizes the window. If the window wasn't maximized, then this
4175 * function does nothing.
4177 * On X11, asks the window manager to unmaximize @window, if the
4178 * window manager supports this operation. Not all window managers
4179 * support this, and some deliberately ignore it or don't have a
4180 * concept of "maximized"; so you can't rely on the unmaximization
4181 * actually happening. But it will happen with most standard window
4182 * managers, and GDK makes a best effort to get it to happen.
4184 * On Windows, reliably unmaximizes the window.
4188 gdk_window_unmaximize (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_MAXIMIZED_VERT"),
4197 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4199 gdk_synthesize_window_state (window,
4200 GDK_WINDOW_STATE_MAXIMIZED,
4205 * gdk_window_fullscreen:
4206 * @window: a toplevel #GdkWindow
4208 * Moves the window into fullscreen mode. This means the
4209 * window covers the entire screen and is above any panels
4212 * If the window was already fullscreen, then this function does nothing.
4214 * On X11, asks the window manager to put @window in a fullscreen
4215 * state, if the window manager supports this operation. Not all
4216 * window managers support this, and some deliberately ignore it or
4217 * don't have a concept of "fullscreen"; so you can't rely on the
4218 * fullscreenification actually happening. But it will happen with
4219 * most standard window managers, and GDK makes a best effort to get
4225 gdk_window_fullscreen (GdkWindow *window)
4227 if (GDK_WINDOW_DESTROYED (window) ||
4228 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4231 if (GDK_WINDOW_IS_MAPPED (window))
4232 gdk_wmspec_change_state (TRUE, window,
4233 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4237 gdk_synthesize_window_state (window,
4239 GDK_WINDOW_STATE_FULLSCREEN);
4243 * gdk_window_unfullscreen:
4244 * @window: a toplevel #GdkWindow
4246 * Moves the window out of fullscreen mode. If the window was not
4247 * fullscreen, does nothing.
4249 * On X11, asks the window manager to move @window out of the fullscreen
4250 * state, if the window manager supports this operation. Not all
4251 * window managers support this, and some deliberately ignore it or
4252 * don't have a concept of "fullscreen"; so you can't rely on the
4253 * unfullscreenification actually happening. But it will happen with
4254 * most standard window managers, and GDK makes a best effort to get
4260 gdk_window_unfullscreen (GdkWindow *window)
4262 if (GDK_WINDOW_DESTROYED (window) ||
4263 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4266 if (GDK_WINDOW_IS_MAPPED (window))
4267 gdk_wmspec_change_state (FALSE, window,
4268 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4272 gdk_synthesize_window_state (window,
4273 GDK_WINDOW_STATE_FULLSCREEN,
4278 * gdk_window_set_keep_above:
4279 * @window: a toplevel #GdkWindow
4280 * @setting: whether to keep @window above other windows
4282 * Set if @window must be kept above other windows. If the
4283 * window was already above, then this function does nothing.
4285 * On X11, asks the window manager to keep @window above, if the window
4286 * manager supports this operation. Not all window managers support
4287 * this, and some deliberately ignore it or don't have a concept of
4288 * "keep above"; so you can't rely on the window being kept above.
4289 * But it will happen with most standard window managers,
4290 * and GDK makes a best effort to get it to happen.
4295 gdk_window_set_keep_above (GdkWindow *window,
4298 g_return_if_fail (GDK_IS_WINDOW (window));
4300 if (GDK_WINDOW_DESTROYED (window) ||
4301 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4304 if (GDK_WINDOW_IS_MAPPED (window))
4307 gdk_wmspec_change_state (FALSE, window,
4308 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4310 gdk_wmspec_change_state (setting, window,
4311 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4315 gdk_synthesize_window_state (window,
4316 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
4317 setting ? GDK_WINDOW_STATE_ABOVE : 0);
4321 * gdk_window_set_keep_below:
4322 * @window: a toplevel #GdkWindow
4323 * @setting: whether to keep @window below other windows
4325 * Set if @window must be kept below other windows. If the
4326 * window was already below, then this function does nothing.
4328 * On X11, asks the window manager to keep @window below, if the window
4329 * manager supports this operation. Not all window managers support
4330 * this, and some deliberately ignore it or don't have a concept of
4331 * "keep below"; so you can't rely on the window being kept below.
4332 * But it will happen with most standard window managers,
4333 * and GDK makes a best effort to get it to happen.
4338 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
4340 g_return_if_fail (GDK_IS_WINDOW (window));
4342 if (GDK_WINDOW_DESTROYED (window) ||
4343 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4346 if (GDK_WINDOW_IS_MAPPED (window))
4349 gdk_wmspec_change_state (FALSE, window,
4350 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4352 gdk_wmspec_change_state (setting, window,
4353 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4357 gdk_synthesize_window_state (window,
4358 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
4359 setting ? GDK_WINDOW_STATE_BELOW : 0);
4363 * gdk_window_get_group:
4364 * @window: a toplevel #GdkWindow
4366 * Returns the group leader window for @window. See gdk_window_set_group().
4368 * Return value: (transfer none): the group leader window for @window
4373 gdk_window_get_group (GdkWindow *window)
4375 GdkToplevelX11 *toplevel;
4377 if (GDK_WINDOW_DESTROYED (window) ||
4378 !WINDOW_IS_TOPLEVEL (window))
4381 toplevel = _gdk_x11_window_get_toplevel (window);
4383 return toplevel->group_leader;
4387 * gdk_window_set_group:
4388 * @window: a toplevel #GdkWindow
4389 * @leader: group leader window, or %NULL to restore the default group leader window
4391 * Sets the group leader window for @window. By default,
4392 * GDK sets the group leader for all toplevel windows
4393 * to a global window implicitly created by GDK. With this function
4394 * you can override this default.
4396 * The group leader window allows the window manager to distinguish
4397 * all windows that belong to a single application. It may for example
4398 * allow users to minimize/unminimize all windows belonging to an
4399 * application at once. You should only set a non-default group window
4400 * if your application pretends to be multiple applications.
4403 gdk_window_set_group (GdkWindow *window,
4406 GdkToplevelX11 *toplevel;
4408 g_return_if_fail (GDK_IS_WINDOW (window));
4409 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4410 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
4412 if (GDK_WINDOW_DESTROYED (window) ||
4413 (leader != NULL && GDK_WINDOW_DESTROYED (leader)) ||
4414 !WINDOW_IS_TOPLEVEL (window))
4417 toplevel = _gdk_x11_window_get_toplevel (window);
4420 leader = gdk_display_get_default_group (gdk_drawable_get_display (window));
4422 if (toplevel->group_leader != leader)
4424 if (toplevel->group_leader)
4425 g_object_unref (toplevel->group_leader);
4426 toplevel->group_leader = g_object_ref (leader);
4427 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
4430 update_wm_hints (window, FALSE);
4433 static MotifWmHints *
4434 gdk_window_get_mwm_hints (GdkWindow *window)
4436 GdkDisplay *display;
4437 Atom hints_atom = None;
4444 if (GDK_WINDOW_DESTROYED (window))
4447 display = gdk_drawable_get_display (window);
4449 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4451 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4452 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4453 False, AnyPropertyType, &type, &format, &nitems,
4454 &bytes_after, &data);
4459 return (MotifWmHints *)data;
4463 gdk_window_set_mwm_hints (GdkWindow *window,
4464 MotifWmHints *new_hints)
4466 GdkDisplay *display;
4467 Atom hints_atom = None;
4469 MotifWmHints *hints;
4475 if (GDK_WINDOW_DESTROYED (window))
4478 display = gdk_drawable_get_display (window);
4480 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4482 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4483 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4484 False, AnyPropertyType, &type, &format, &nitems,
4485 &bytes_after, &data);
4491 hints = (MotifWmHints *)data;
4493 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4495 hints->flags |= MWM_HINTS_FUNCTIONS;
4496 hints->functions = new_hints->functions;
4498 if (new_hints->flags & MWM_HINTS_DECORATIONS)
4500 hints->flags |= MWM_HINTS_DECORATIONS;
4501 hints->decorations = new_hints->decorations;
4505 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4506 hints_atom, hints_atom, 32, PropModeReplace,
4507 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
4509 if (hints != new_hints)
4514 * gdk_window_set_decorations:
4515 * @window: a toplevel #GdkWindow
4516 * @decorations: decoration hint mask
4518 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
4519 * This function sets the traditional Motif window manager hints that tell the
4520 * window manager which decorations you would like your window to have.
4521 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
4522 * using the GDK function directly.
4524 * The @decorations argument is the logical OR of the fields in
4525 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
4526 * mask, the other bits indicate which decorations should be turned off.
4527 * If #GDK_DECOR_ALL is not included, then the other bits indicate
4528 * which decorations should be turned on.
4530 * Most window managers honor a decorations hint of 0 to disable all decorations,
4531 * but very few honor all possible combinations of bits.
4535 gdk_window_set_decorations (GdkWindow *window,
4536 GdkWMDecoration decorations)
4540 if (GDK_WINDOW_DESTROYED (window) ||
4541 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4544 /* initialize to zero to avoid writing uninitialized data to socket */
4545 memset(&hints, 0, sizeof(hints));
4546 hints.flags = MWM_HINTS_DECORATIONS;
4547 hints.decorations = decorations;
4549 gdk_window_set_mwm_hints (window, &hints);
4553 * gdk_window_get_decorations:
4554 * @window: The toplevel #GdkWindow to get the decorations from
4555 * @decorations: The window decorations will be written here
4557 * Returns the decorations set on the GdkWindow with
4558 * gdk_window_set_decorations().
4560 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
4563 gdk_window_get_decorations(GdkWindow *window,
4564 GdkWMDecoration *decorations)
4566 MotifWmHints *hints;
4567 gboolean result = FALSE;
4569 if (GDK_WINDOW_DESTROYED (window) ||
4570 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4573 hints = gdk_window_get_mwm_hints (window);
4577 if (hints->flags & MWM_HINTS_DECORATIONS)
4580 *decorations = hints->decorations;
4591 * gdk_window_set_functions:
4592 * @window: a toplevel #GdkWindow
4593 * @functions: bitmask of operations to allow on @window
4595 * Sets hints about the window management functions to make available
4596 * via buttons on the window frame.
4598 * On the X backend, this function sets the traditional Motif window
4599 * manager hint for this purpose. However, few window managers do
4600 * anything reliable or interesting with this hint. Many ignore it
4603 * The @functions argument is the logical OR of values from the
4604 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
4605 * then the other bits indicate which functions to disable; if
4606 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
4611 gdk_window_set_functions (GdkWindow *window,
4612 GdkWMFunction functions)
4616 g_return_if_fail (GDK_IS_WINDOW (window));
4618 if (GDK_WINDOW_DESTROYED (window) ||
4619 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4622 /* initialize to zero to avoid writing uninitialized data to socket */
4623 memset(&hints, 0, sizeof(hints));
4624 hints.flags = MWM_HINTS_FUNCTIONS;
4625 hints.functions = functions;
4627 gdk_window_set_mwm_hints (window, &hints);
4631 _xwindow_get_shape (Display *xdisplay,
4635 cairo_region_t *shape;
4643 xrl = XShapeGetRectangles (xdisplay,
4645 shape_type, &rn, &ord);
4647 if (xrl == NULL || rn == 0)
4648 return cairo_region_create (); /* Empty */
4650 if (ord != YXBanded)
4652 /* This really shouldn't happen with any xserver, as they
4653 generally convert regions to YXBanded internally */
4654 g_warning ("non YXBanded shape masks not supported");
4659 rl = g_new (GdkRectangle, rn);
4660 for (i = 0; i < rn; i++)
4664 rl[i].width = xrl[i].width;
4665 rl[i].height = xrl[i].height;
4669 shape = cairo_region_create_rectangles (rl, rn);
4677 _gdk_windowing_window_get_shape (GdkWindow *window)
4679 if (!GDK_WINDOW_DESTROYED (window) &&
4680 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
4681 return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
4682 GDK_WINDOW_XID (window), ShapeBounding);
4688 _gdk_windowing_window_get_input_shape (GdkWindow *window)
4690 #if defined(ShapeInput)
4691 if (!GDK_WINDOW_DESTROYED (window) &&
4692 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
4693 return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
4694 GDK_WINDOW_XID (window),
4702 gdk_window_set_static_bit_gravity (GdkWindow *window,
4705 XSetWindowAttributes xattributes;
4706 GdkWindowObject *private;
4707 guint xattributes_mask = 0;
4709 g_return_if_fail (GDK_IS_WINDOW (window));
4711 private = GDK_WINDOW_OBJECT (window);
4712 if (private->input_only)
4715 xattributes.bit_gravity = StaticGravity;
4716 xattributes_mask |= CWBitGravity;
4717 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4718 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4719 GDK_WINDOW_XID (window),
4720 CWBitGravity, &xattributes);
4724 gdk_window_set_static_win_gravity (GdkWindow *window,
4727 XSetWindowAttributes xattributes;
4729 g_return_if_fail (GDK_IS_WINDOW (window));
4731 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4733 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4734 GDK_WINDOW_XID (window),
4735 CWWinGravity, &xattributes);
4739 gdk_window_x11_set_static_gravities (GdkWindow *window,
4740 gboolean use_static)
4742 GdkWindowObject *private = (GdkWindowObject *)window;
4745 if (!use_static == !private->guffaw_gravity)
4748 private->guffaw_gravity = use_static;
4750 if (!GDK_WINDOW_DESTROYED (window))
4752 gdk_window_set_static_bit_gravity (window, use_static);
4754 tmp_list = private->children;
4757 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4759 tmp_list = tmp_list->next;
4767 wmspec_moveresize (GdkWindow *window,
4773 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4775 XClientMessageEvent xclient;
4777 /* Release passive grab */
4778 gdk_display_pointer_ungrab (display, timestamp);
4780 memset (&xclient, 0, sizeof (xclient));
4781 xclient.type = ClientMessage;
4782 xclient.window = GDK_WINDOW_XID (window);
4783 xclient.message_type =
4784 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4785 xclient.format = 32;
4786 xclient.data.l[0] = root_x;
4787 xclient.data.l[1] = root_y;
4788 xclient.data.l[2] = direction;
4789 xclient.data.l[3] = 0;
4790 xclient.data.l[4] = 0;
4792 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4793 SubstructureRedirectMask | SubstructureNotifyMask,
4794 (XEvent *)&xclient);
4797 typedef struct _MoveResizeData MoveResizeData;
4799 struct _MoveResizeData
4801 GdkDisplay *display;
4803 GdkWindow *moveresize_window;
4804 GdkWindow *moveresize_emulation_window;
4806 GdkWindowEdge resize_edge;
4807 gint moveresize_button;
4810 gint moveresize_orig_x;
4811 gint moveresize_orig_y;
4812 gint moveresize_orig_width;
4813 gint moveresize_orig_height;
4814 GdkWindowHints moveresize_geom_mask;
4815 GdkGeometry moveresize_geometry;
4816 Time moveresize_process_time;
4817 XEvent *moveresize_pending_event;
4820 /* From the WM spec */
4821 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4822 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4823 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4824 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4825 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4826 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4827 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4828 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4829 #define _NET_WM_MOVERESIZE_MOVE 8
4832 wmspec_resize_drag (GdkWindow *window,
4841 /* Let the compiler turn a switch into a table, instead
4842 * of doing the table manually, this way is easier to verify.
4846 case GDK_WINDOW_EDGE_NORTH_WEST:
4847 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4850 case GDK_WINDOW_EDGE_NORTH:
4851 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4854 case GDK_WINDOW_EDGE_NORTH_EAST:
4855 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4858 case GDK_WINDOW_EDGE_WEST:
4859 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4862 case GDK_WINDOW_EDGE_EAST:
4863 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4866 case GDK_WINDOW_EDGE_SOUTH_WEST:
4867 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4870 case GDK_WINDOW_EDGE_SOUTH:
4871 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4874 case GDK_WINDOW_EDGE_SOUTH_EAST:
4875 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4879 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4884 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4887 static MoveResizeData *
4888 get_move_resize_data (GdkDisplay *display,
4891 MoveResizeData *mv_resize;
4892 static GQuark move_resize_quark = 0;
4894 if (!move_resize_quark)
4895 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4897 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4899 if (!mv_resize && create)
4901 mv_resize = g_new0 (MoveResizeData, 1);
4902 mv_resize->display = display;
4904 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4911 update_pos (MoveResizeData *mv_resize,
4917 dx = new_root_x - mv_resize->moveresize_x;
4918 dy = new_root_y - mv_resize->moveresize_y;
4920 if (mv_resize->is_resize)
4924 x = mv_resize->moveresize_orig_x;
4925 y = mv_resize->moveresize_orig_y;
4927 w = mv_resize->moveresize_orig_width;
4928 h = mv_resize->moveresize_orig_height;
4930 switch (mv_resize->resize_edge)
4932 case GDK_WINDOW_EDGE_NORTH_WEST:
4938 case GDK_WINDOW_EDGE_NORTH:
4942 case GDK_WINDOW_EDGE_NORTH_EAST:
4947 case GDK_WINDOW_EDGE_SOUTH_WEST:
4952 case GDK_WINDOW_EDGE_SOUTH_EAST:
4956 case GDK_WINDOW_EDGE_SOUTH:
4959 case GDK_WINDOW_EDGE_EAST:
4962 case GDK_WINDOW_EDGE_WEST:
4973 if (mv_resize->moveresize_geom_mask)
4975 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4976 mv_resize->moveresize_geom_mask,
4980 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4986 x = mv_resize->moveresize_orig_x + dx;
4987 y = mv_resize->moveresize_orig_y + dy;
4989 gdk_window_move (mv_resize->moveresize_window, x, y);
4994 finish_drag (MoveResizeData *mv_resize)
4996 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4997 mv_resize->moveresize_emulation_window = NULL;
4998 g_object_unref (mv_resize->moveresize_window);
4999 mv_resize->moveresize_window = NULL;
5001 if (mv_resize->moveresize_pending_event)
5003 g_free (mv_resize->moveresize_pending_event);
5004 mv_resize->moveresize_pending_event = NULL;
5009 lookahead_motion_predicate (Display *xdisplay,
5013 gboolean *seen_release = (gboolean *)arg;
5014 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
5015 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5020 switch (event->xany.type)
5023 *seen_release = TRUE;
5026 mv_resize->moveresize_process_time = event->xmotion.time;
5036 moveresize_lookahead (MoveResizeData *mv_resize,
5040 gboolean seen_release = FALSE;
5042 if (mv_resize->moveresize_process_time)
5044 if (event->xmotion.time == mv_resize->moveresize_process_time)
5046 mv_resize->moveresize_process_time = 0;
5053 XCheckIfEvent (event->xany.display, &tmp_event,
5054 lookahead_motion_predicate, (XPointer) & seen_release);
5056 return mv_resize->moveresize_process_time == 0;
5060 _gdk_moveresize_handle_event (XEvent *event)
5062 guint button_mask = 0;
5063 GdkWindowObject *window_private;
5064 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
5065 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5067 if (!mv_resize || !mv_resize->moveresize_window)
5070 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
5072 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
5074 switch (event->xany.type)
5077 if (window_private->resize_count > 0)
5079 if (mv_resize->moveresize_pending_event)
5080 *mv_resize->moveresize_pending_event = *event;
5082 mv_resize->moveresize_pending_event =
5083 g_memdup (event, sizeof (XEvent));
5087 if (!moveresize_lookahead (mv_resize, event))
5090 update_pos (mv_resize,
5091 event->xmotion.x_root,
5092 event->xmotion.y_root);
5094 /* This should never be triggered in normal cases, but in the
5095 * case where the drag started without an implicit grab being
5096 * in effect, we could miss the release if it occurs before
5097 * we grab the pointer; this ensures that we will never
5098 * get a permanently stuck grab.
5100 if ((event->xmotion.state & button_mask) == 0)
5101 finish_drag (mv_resize);
5105 update_pos (mv_resize,
5106 event->xbutton.x_root,
5107 event->xbutton.y_root);
5109 if (event->xbutton.button == mv_resize->moveresize_button)
5110 finish_drag (mv_resize);
5117 _gdk_moveresize_configure_done (GdkDisplay *display,
5121 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5123 if (!mv_resize || window != mv_resize->moveresize_window)
5126 if (mv_resize->moveresize_pending_event)
5128 tmp_event = mv_resize->moveresize_pending_event;
5129 mv_resize->moveresize_pending_event = NULL;
5130 _gdk_moveresize_handle_event (tmp_event);
5138 create_moveresize_window (MoveResizeData *mv_resize,
5141 GdkWindowAttr attributes;
5142 gint attributes_mask;
5143 GdkGrabStatus status;
5145 g_assert (mv_resize->moveresize_emulation_window == NULL);
5147 attributes.x = -100;
5148 attributes.y = -100;
5149 attributes.width = 10;
5150 attributes.height = 10;
5151 attributes.window_type = GDK_WINDOW_TEMP;
5152 attributes.wclass = GDK_INPUT_ONLY;
5153 attributes.override_redirect = TRUE;
5154 attributes.event_mask = 0;
5156 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
5158 mv_resize->moveresize_emulation_window =
5159 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
5163 gdk_window_show (mv_resize->moveresize_emulation_window);
5165 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
5167 GDK_BUTTON_RELEASE_MASK |
5168 GDK_POINTER_MOTION_MASK,
5173 if (status != GDK_GRAB_SUCCESS)
5175 /* If this fails, some other client has grabbed the window
5178 finish_drag (mv_resize);
5181 mv_resize->moveresize_process_time = 0;
5185 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
5186 so that calling XMoveWindow with these coordinates will not move the
5188 Note that this depends on the WM to implement ICCCM-compliant reference
5192 calculate_unmoving_origin (MoveResizeData *mv_resize)
5197 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
5198 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
5200 gdk_window_get_origin (mv_resize->moveresize_window,
5201 &mv_resize->moveresize_orig_x,
5202 &mv_resize->moveresize_orig_y);
5206 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
5207 gdk_window_get_geometry (mv_resize->moveresize_window,
5208 NULL, NULL, &width, &height, NULL);
5210 switch (mv_resize->moveresize_geometry.win_gravity)
5212 case GDK_GRAVITY_NORTH_WEST:
5213 mv_resize->moveresize_orig_x = rect.x;
5214 mv_resize->moveresize_orig_y = rect.y;
5216 case GDK_GRAVITY_NORTH:
5217 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5218 mv_resize->moveresize_orig_y = rect.y;
5220 case GDK_GRAVITY_NORTH_EAST:
5221 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5222 mv_resize->moveresize_orig_y = rect.y;
5224 case GDK_GRAVITY_WEST:
5225 mv_resize->moveresize_orig_x = rect.x;
5226 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5228 case GDK_GRAVITY_CENTER:
5229 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5230 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5232 case GDK_GRAVITY_EAST:
5233 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5234 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5236 case GDK_GRAVITY_SOUTH_WEST:
5237 mv_resize->moveresize_orig_x = rect.x;
5238 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5240 case GDK_GRAVITY_SOUTH:
5241 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5242 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5244 case GDK_GRAVITY_SOUTH_EAST:
5245 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5246 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5249 mv_resize->moveresize_orig_x = rect.x;
5250 mv_resize->moveresize_orig_y = rect.y;
5257 emulate_resize_drag (GdkWindow *window,
5264 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5266 mv_resize->is_resize = TRUE;
5267 mv_resize->moveresize_button = button;
5268 mv_resize->resize_edge = edge;
5269 mv_resize->moveresize_x = root_x;
5270 mv_resize->moveresize_y = root_y;
5271 mv_resize->moveresize_window = g_object_ref (window);
5273 gdk_drawable_get_size (window,
5274 &mv_resize->moveresize_orig_width,
5275 &mv_resize->moveresize_orig_height);
5277 mv_resize->moveresize_geom_mask = 0;
5278 gdk_window_get_geometry_hints (window,
5279 &mv_resize->moveresize_geometry,
5280 &mv_resize->moveresize_geom_mask);
5282 calculate_unmoving_origin (mv_resize);
5284 create_moveresize_window (mv_resize, timestamp);
5288 emulate_move_drag (GdkWindow *window,
5294 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5296 mv_resize->is_resize = FALSE;
5297 mv_resize->moveresize_button = button;
5298 mv_resize->moveresize_x = root_x;
5299 mv_resize->moveresize_y = root_y;
5301 mv_resize->moveresize_window = g_object_ref (window);
5303 calculate_unmoving_origin (mv_resize);
5305 create_moveresize_window (mv_resize, timestamp);
5309 * gdk_window_begin_resize_drag:
5310 * @window: a toplevel #GdkWindow
5311 * @edge: the edge or corner from which the drag is started
5312 * @button: the button being used to drag
5313 * @root_x: root window X coordinate of mouse click that began the drag
5314 * @root_y: root window Y coordinate of mouse click that began the drag
5315 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
5317 * Begins a window resize operation (for a toplevel window).
5318 * You might use this function to implement a "window resize grip," for
5319 * example; in fact #GtkStatusbar uses it. The function works best
5320 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
5321 * fallback implementation for other window managers.
5325 gdk_window_begin_resize_drag (GdkWindow *window,
5332 if (GDK_WINDOW_DESTROYED (window) ||
5333 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
5336 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5337 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
5338 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
5340 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
5344 * gdk_window_begin_move_drag:
5345 * @window: a toplevel #GdkWindow
5346 * @button: the button being used to drag
5347 * @root_x: root window X coordinate of mouse click that began the drag
5348 * @root_y: root window Y coordinate of mouse click that began the drag
5349 * @timestamp: timestamp of mouse click that began the drag
5351 * Begins a window move operation (for a toplevel window). You might
5352 * use this function to implement a "window move grip," for
5353 * example. The function works best with window managers that support
5354 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
5355 * Window Manager Hints</ulink>, but has a fallback implementation for
5356 * other window managers.
5360 gdk_window_begin_move_drag (GdkWindow *window,
5366 if (GDK_WINDOW_DESTROYED (window) ||
5367 !WINDOW_IS_TOPLEVEL (window))
5370 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5371 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
5372 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
5375 emulate_move_drag (window, button, root_x, root_y, timestamp);
5379 * gdk_window_enable_synchronized_configure:
5380 * @window: a toplevel #GdkWindow
5382 * Indicates that the application will cooperate with the window
5383 * system in synchronizing the window repaint with the window
5384 * manager during resizing operations. After an application calls
5385 * this function, it must call gdk_window_configure_finished() every
5386 * time it has finished all processing associated with a set of
5387 * Configure events. Toplevel GTK+ windows automatically use this
5390 * On X, calling this function makes @window participate in the
5391 * _NET_WM_SYNC_REQUEST window manager protocol.
5396 gdk_window_enable_synchronized_configure (GdkWindow *window)
5398 GdkWindowObject *private = (GdkWindowObject *)window;
5399 GdkWindowImplX11 *impl;
5401 if (!GDK_IS_WINDOW_IMPL_X11 (private->impl))
5404 impl = GDK_WINDOW_IMPL_X11 (private->impl);
5406 if (!impl->use_synchronized_configure)
5408 /* This basically means you want to do fancy X specific stuff, so
5409 ensure we have a native window */
5410 gdk_window_ensure_native (window);
5412 impl->use_synchronized_configure = TRUE;
5413 ensure_sync_counter (window);
5418 * gdk_window_configure_finished:
5419 * @window: a toplevel #GdkWindow
5421 * Signal to the window system that the application has finished
5422 * handling Configure events it has received. Window Managers can
5423 * use this to better synchronize the frame repaint with the
5424 * application. GTK+ applications will automatically call this
5425 * function when appropriate.
5427 * This function can only be called if gdk_window_enable_synchronized_configure()
5428 * was called previously.
5433 gdk_window_configure_finished (GdkWindow *window)
5435 GdkWindowImplX11 *impl;
5437 if (!WINDOW_IS_TOPLEVEL (window))
5440 impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
5441 if (!impl->use_synchronized_configure)
5445 if (!GDK_WINDOW_DESTROYED (window))
5447 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
5448 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
5450 if (toplevel && toplevel->update_counter != None &&
5451 GDK_DISPLAY_X11 (display)->use_sync &&
5452 !XSyncValueIsZero (toplevel->current_counter_value))
5454 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
5455 toplevel->update_counter,
5456 toplevel->current_counter_value);
5458 XSyncIntToValue (&toplevel->current_counter_value, 0);
5465 _gdk_windowing_window_beep (GdkWindow *window)
5467 GdkDisplay *display;
5469 g_return_if_fail (GDK_IS_WINDOW (window));
5471 display = GDK_WINDOW_DISPLAY (window);
5474 if (GDK_DISPLAY_X11 (display)->use_xkb)
5475 XkbBell (GDK_DISPLAY_XDISPLAY (display),
5476 GDK_WINDOW_XID (window),
5481 gdk_display_beep (display);
5485 * gdk_window_set_opacity:
5486 * @window: a top-level #GdkWindow
5489 * Request the windowing system to make @window partially transparent,
5490 * with opacity 0 being fully transparent and 1 fully opaque. (Values
5491 * of the opacity parameter are clamped to the [0,1] range.)
5493 * On X11, this works only on X screens with a compositing manager
5496 * For setting up per-pixel alpha, see gdk_screen_get_rgba_colormap().
5497 * For making non-toplevel windows translucent, see
5498 * gdk_window_set_composited().
5503 gdk_window_set_opacity (GdkWindow *window,
5506 GdkDisplay *display;
5509 g_return_if_fail (GDK_IS_WINDOW (window));
5511 if (GDK_WINDOW_DESTROYED (window) ||
5512 !WINDOW_IS_TOPLEVEL (window))
5515 display = gdk_drawable_get_display (window);
5519 else if (opacity > 1)
5522 cardinal = opacity * 0xffffffff;
5524 if (cardinal == 0xffffffff)
5525 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
5526 GDK_WINDOW_XID (window),
5527 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"));
5529 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
5530 GDK_WINDOW_XID (window),
5531 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"),
5534 (guchar *) &cardinal, 1);
5538 _gdk_windowing_window_set_composited (GdkWindow *window,
5539 gboolean composited)
5541 #if defined(HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES)
5542 GdkWindowObject *private = (GdkWindowObject *) window;
5543 GdkWindowImplX11 *impl;
5544 GdkDisplay *display;
5548 impl = GDK_WINDOW_IMPL_X11 (private->impl);
5550 display = gdk_screen_get_display (GDK_DRAWABLE_IMPL_X11 (impl)->screen);
5551 dpy = GDK_DISPLAY_XDISPLAY (display);
5552 xid = GDK_WINDOW_XWINDOW (private);
5556 XCompositeRedirectWindow (dpy, xid, CompositeRedirectManual);
5557 impl->damage = XDamageCreate (dpy, xid, XDamageReportBoundingBox);
5561 XCompositeUnredirectWindow (dpy, xid, CompositeRedirectManual);
5562 XDamageDestroy (dpy, impl->damage);
5563 impl->damage = None;
5569 _gdk_windowing_window_process_updates_recurse (GdkWindow *window,
5570 cairo_region_t *region)
5572 _gdk_window_process_updates_recurse (window, region);
5576 _gdk_windowing_before_process_all_updates (void)
5581 _gdk_windowing_after_process_all_updates (void)
5586 gdk_window_impl_iface_init (GdkWindowImplIface *iface)
5588 iface->show = gdk_window_x11_show;
5589 iface->hide = gdk_window_x11_hide;
5590 iface->withdraw = gdk_window_x11_withdraw;
5591 iface->set_events = gdk_window_x11_set_events;
5592 iface->get_events = gdk_window_x11_get_events;
5593 iface->raise = gdk_window_x11_raise;
5594 iface->lower = gdk_window_x11_lower;
5595 iface->restack_under = gdk_window_x11_restack_under;
5596 iface->restack_toplevel = gdk_window_x11_restack_toplevel;
5597 iface->move_resize = gdk_window_x11_move_resize;
5598 iface->set_background = gdk_window_x11_set_background;
5599 iface->reparent = gdk_window_x11_reparent;
5600 iface->set_device_cursor = gdk_window_x11_set_device_cursor;
5601 iface->get_geometry = gdk_window_x11_get_geometry;
5602 iface->get_root_coords = gdk_window_x11_get_root_coords;
5603 iface->get_device_state = gdk_window_x11_get_device_state;
5604 iface->shape_combine_region = gdk_window_x11_shape_combine_region;
5605 iface->input_shape_combine_region = gdk_window_x11_input_shape_combine_region;
5606 iface->set_static_gravities = gdk_window_x11_set_static_gravities;
5607 iface->queue_antiexpose = _gdk_x11_window_queue_antiexpose;
5608 iface->translate = _gdk_x11_window_translate;
5609 iface->destroy = _gdk_x11_window_destroy;
5613 timestamp_predicate (Display *display,
5617 Window xwindow = GPOINTER_TO_UINT (arg);
5618 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
5620 if (xevent->type == PropertyNotify &&
5621 xevent->xproperty.window == xwindow &&
5622 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
5623 "GDK_TIMESTAMP_PROP"))
5630 * gdk_x11_get_server_time:
5631 * @window: a #GdkWindow, used for communication with the server.
5632 * The window must have GDK_PROPERTY_CHANGE_MASK in its
5633 * events mask or a hang will result.
5635 * Routine to get the current X server time stamp.
5637 * Return value: the time stamp.
5640 gdk_x11_get_server_time (GdkWindow *window)
5646 Atom timestamp_prop_atom;
5648 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5649 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
5651 xdisplay = GDK_WINDOW_XDISPLAY (window);
5652 xwindow = GDK_WINDOW_XWINDOW (window);
5653 timestamp_prop_atom =
5654 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
5655 "GDK_TIMESTAMP_PROP");
5657 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
5658 timestamp_prop_atom,
5659 8, PropModeReplace, &c, 1);
5661 XIfEvent (xdisplay, &xevent,
5662 timestamp_predicate, GUINT_TO_POINTER(xwindow));
5664 return xevent.xproperty.time;