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/.
30 #include "gdkwindow-x11.h"
33 #include "gdkwindow.h"
34 #include "gdkwindowimpl.h"
36 #include "gdkdisplay-x11.h"
37 #include "gdkprivate-x11.h"
38 #include "gdkinternals.h"
39 #include "gdkdeviceprivate.h"
40 #include "gdkeventsource.h"
45 #include <netinet/in.h>
48 #include <cairo-xlib.h>
53 #include <X11/Xutil.h>
54 #include <X11/Xatom.h>
56 #include <X11/extensions/shape.h>
59 #include <X11/XKBlib.h>
62 #ifdef HAVE_XCOMPOSITE
63 #include <X11/extensions/Xcomposite.h>
67 #include <X11/extensions/Xfixes.h>
71 #include <X11/extensions/Xdamage.h>
74 const int _gdk_event_mask_table[21] =
78 PointerMotionHintMask,
95 SubstructureNotifyMask,
96 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
98 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
100 /* Forward declarations */
101 static void gdk_window_set_static_win_gravity (GdkWindow *window,
103 static gboolean gdk_window_icon_name_set (GdkWindow *window);
104 static void set_wm_name (GdkDisplay *display,
107 static void move_to_current_desktop (GdkWindow *window);
108 static void gdk_window_x11_set_background (GdkWindow *window,
109 cairo_pattern_t *pattern);
111 static void gdk_window_impl_x11_finalize (GObject *object);
113 #define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \
114 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
115 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
117 #define WINDOW_IS_TOPLEVEL(window) \
118 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
119 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
120 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
122 /* Return whether time1 is considered later than time2 as far as xserver
123 * time is concerned. Accounts for wraparound.
125 #define XSERVER_TIME_IS_LATER(time1, time2) \
126 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
127 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
130 G_DEFINE_TYPE (GdkWindowImplX11, gdk_window_impl_x11, GDK_TYPE_WINDOW_IMPL)
133 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
135 impl->toplevel_window_type = -1;
136 impl->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
137 (GDestroyNotify) gdk_cursor_unref);
141 _gdk_x11_window_get_toplevel (GdkWindow *window)
143 GdkWindowImplX11 *impl;
145 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
147 if (!WINDOW_IS_TOPLEVEL (window))
150 impl = GDK_WINDOW_IMPL_X11 (window->impl);
153 impl->toplevel = g_new0 (GdkToplevelX11, 1);
155 return impl->toplevel;
158 static const cairo_user_data_key_t gdk_x11_cairo_key;
161 * _gdk_x11_window_update_size:
162 * @impl: a #GdkWindowImplX11.
164 * Updates the state of the window (in particular the drawable's
165 * cairo surface) when its size has changed.
168 _gdk_x11_window_update_size (GdkWindowImplX11 *impl)
170 if (impl->cairo_surface)
172 cairo_xlib_surface_set_size (impl->cairo_surface,
173 gdk_window_get_width (impl->wrapper),
174 gdk_window_get_height (impl->wrapper));
178 /*****************************************************
179 * X11 specific implementations of generic functions *
180 *****************************************************/
183 gdk_x11_cairo_surface_destroy (void *data)
185 GdkWindowImplX11 *impl = data;
187 impl->cairo_surface = NULL;
190 static cairo_surface_t *
191 gdk_x11_create_cairo_surface (GdkWindowImplX11 *impl,
197 visual = gdk_window_get_visual (impl->wrapper);
198 return cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (impl->wrapper),
199 GDK_WINDOW_IMPL_X11 (impl)->xid,
200 GDK_VISUAL_XVISUAL (visual),
204 static cairo_surface_t *
205 gdk_x11_ref_cairo_surface (GdkWindow *window)
207 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
209 if (GDK_WINDOW_DESTROYED (window))
212 if (!impl->cairo_surface)
214 impl->cairo_surface = gdk_x11_create_cairo_surface (impl,
215 gdk_window_get_width (window),
216 gdk_window_get_height (window));
218 if (impl->cairo_surface)
219 cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
220 impl, gdk_x11_cairo_surface_destroy);
223 cairo_surface_reference (impl->cairo_surface);
225 return impl->cairo_surface;
229 gdk_window_impl_x11_finalize (GObject *object)
232 GdkWindowImplX11 *impl;
234 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
236 impl = GDK_WINDOW_IMPL_X11 (object);
238 wrapper = impl->wrapper;
240 _gdk_xgrab_check_destroy (wrapper);
242 if (!GDK_WINDOW_DESTROYED (wrapper))
244 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
246 _gdk_xid_table_remove (display, impl->xid);
247 if (impl->toplevel && impl->toplevel->focus_window)
248 _gdk_xid_table_remove (display, impl->toplevel->focus_window);
251 g_free (impl->toplevel);
254 gdk_cursor_unref (impl->cursor);
256 g_hash_table_destroy (impl->device_cursor);
258 G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
267 free_pixmap (gpointer datap)
269 FreePixmapData *data = datap;
271 if (!gdk_display_is_closed (data->display))
273 XFreePixmap (GDK_DISPLAY_XDISPLAY (data->display),
277 g_object_unref (data->display);
278 g_slice_free (FreePixmapData, data);
282 attach_free_pixmap_handler (cairo_surface_t *surface,
286 static const cairo_user_data_key_t key;
287 FreePixmapData *data;
289 data = g_slice_new (FreePixmapData);
290 data->display = g_object_ref (display);
291 data->pixmap = pixmap;
293 cairo_surface_set_user_data (surface, &key, data, free_pixmap);
296 /* Cairo does not guarantee we get an xlib surface if we call
297 * cairo_surface_create_similar(). In some cases however, we must use a
298 * pixmap or bitmap in the X11 API.
299 * These functions ensure an Xlib surface.
302 _gdk_x11_window_create_bitmap_surface (GdkWindow *window,
306 cairo_surface_t *surface;
309 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
310 GDK_WINDOW_XID (window),
312 surface = cairo_xlib_surface_create_for_bitmap (GDK_WINDOW_XDISPLAY (window),
314 GDK_SCREEN_XSCREEN (GDK_WINDOW_SCREEN (window)),
316 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
321 /* Create a surface backed with a pixmap without alpha on the same screen as window */
322 static cairo_surface_t *
323 gdk_x11_window_create_pixmap_surface (GdkWindow *window,
327 GdkScreen *screen = gdk_window_get_screen (window);
328 GdkVisual *visual = gdk_screen_get_system_visual (screen);
329 cairo_surface_t *surface;
332 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
333 GDK_WINDOW_XID (window),
335 gdk_visual_get_depth (visual));
336 surface = cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (window),
338 GDK_VISUAL_XVISUAL (visual),
340 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
346 tmp_unset_bg (GdkWindow *window)
348 GdkWindowImplX11 *impl;
350 impl = GDK_WINDOW_IMPL_X11 (window->impl);
354 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
355 GDK_WINDOW_XID (window), None);
359 tmp_reset_bg (GdkWindow *window)
361 GdkWindowImplX11 *impl;
363 impl = GDK_WINDOW_IMPL_X11 (window->impl);
367 gdk_window_x11_set_background (window, window->background);
370 /* Unsetting and resetting window backgrounds.
372 * In many cases it is possible to avoid flicker by unsetting the
373 * background of windows. For example if the background of the
374 * parent window is unset when a window is unmapped, a brief flicker
375 * of background painting is avoided.
378 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
381 g_return_if_fail (GDK_IS_WINDOW (window));
383 if (window->input_only || window->destroyed ||
384 (window->window_type != GDK_WINDOW_ROOT &&
385 !GDK_WINDOW_IS_MAPPED (window)))
388 if (_gdk_window_has_impl (window) &&
389 GDK_WINDOW_IS_X11 (window) &&
390 window->window_type != GDK_WINDOW_ROOT &&
391 window->window_type != GDK_WINDOW_FOREIGN)
392 tmp_unset_bg (window);
398 for (l = window->children; l != NULL; l = l->next)
399 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
404 _gdk_x11_window_tmp_unset_parent_bg (GdkWindow *window)
406 if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
409 window = _gdk_window_get_impl_window (window->parent);
410 _gdk_x11_window_tmp_unset_bg (window, FALSE);
414 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
417 g_return_if_fail (GDK_IS_WINDOW (window));
419 if (window->input_only || window->destroyed ||
420 (window->window_type != GDK_WINDOW_ROOT &&
421 !GDK_WINDOW_IS_MAPPED (window)))
425 if (_gdk_window_has_impl (window) &&
426 GDK_WINDOW_IS_X11 (window) &&
427 window->window_type != GDK_WINDOW_ROOT &&
428 window->window_type != GDK_WINDOW_FOREIGN)
429 tmp_reset_bg (window);
435 for (l = window->children; l != NULL; l = l->next)
436 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
441 _gdk_x11_window_tmp_reset_parent_bg (GdkWindow *window)
443 if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
446 window = _gdk_window_get_impl_window (window->parent);
448 _gdk_x11_window_tmp_reset_bg (window, FALSE);
452 _gdk_windowing_window_init (GdkScreen * screen)
455 GdkWindowImplX11 *impl;
456 GdkScreenX11 *screen_x11;
458 screen_x11 = GDK_SCREEN_X11 (screen);
460 g_assert (screen_x11->root_window == NULL);
462 window = screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
464 window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
465 window->impl_window = window;
466 window->visual = gdk_screen_get_system_visual (screen);
468 impl = GDK_WINDOW_IMPL_X11 (window->impl);
470 impl->xid = screen_x11->xroot_window;
471 impl->wrapper = window;
473 window->window_type = GDK_WINDOW_ROOT;
474 window->depth = DefaultDepthOfScreen (screen_x11->xscreen);
480 window->width = WidthOfScreen (screen_x11->xscreen);
481 window->height = HeightOfScreen (screen_x11->xscreen);
482 window->viewable = TRUE;
484 /* see init_randr_support() in gdkscreen-x11.c */
485 window->event_mask = GDK_STRUCTURE_MASK;
487 _gdk_window_update_size (screen_x11->root_window);
489 _gdk_xid_table_insert (screen_x11->display,
490 &screen_x11->xroot_window,
491 screen_x11->root_window);
495 set_wm_protocols (GdkWindow *window)
497 GdkDisplay *display = gdk_window_get_display (window);
501 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
502 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
503 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
506 if (GDK_DISPLAY_X11 (display)->use_sync)
507 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
510 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
514 get_default_title (void)
518 title = g_get_application_name ();
520 title = g_get_prgname ();
528 check_leader_window_title (GdkDisplay *display)
530 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
532 if (display_x11->leader_window && !display_x11->leader_window_title_set)
534 set_wm_name (display,
535 display_x11->leader_window,
536 get_default_title ());
538 display_x11->leader_window_title_set = TRUE;
543 create_focus_window (GdkDisplay *display,
546 GdkDisplayX11 *display_x11;
547 GdkEventMask event_mask;
551 xdisplay = GDK_DISPLAY_XDISPLAY (display);
552 display_x11 = GDK_DISPLAY_X11 (display);
554 focus_window = XCreateSimpleWindow (xdisplay, parent,
558 /* FIXME: probably better to actually track the requested event mask for the toplevel
560 event_mask = (GDK_KEY_PRESS_MASK |
561 GDK_KEY_RELEASE_MASK |
562 GDK_FOCUS_CHANGE_MASK);
564 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
568 XMapWindow (xdisplay, focus_window);
574 ensure_sync_counter (GdkWindow *window)
577 if (!GDK_WINDOW_DESTROYED (window))
579 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
580 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
581 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
583 if (toplevel && impl->use_synchronized_configure &&
584 toplevel->update_counter == None &&
585 GDK_DISPLAY_X11 (display)->use_sync)
587 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
591 XSyncIntToValue (&value, 0);
593 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
595 atom = gdk_x11_get_xatom_by_name_for_display (display,
596 "_NET_WM_SYNC_REQUEST_COUNTER");
598 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
601 (guchar *)&toplevel->update_counter, 1);
603 XSyncIntToValue (&toplevel->current_counter_value, 0);
610 setup_toplevel_window (GdkWindow *window,
613 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
614 GdkDisplay *display = gdk_window_get_display (window);
615 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
616 XID xid = GDK_WINDOW_XID (window);
617 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
618 XSizeHints size_hints;
620 Window leader_window;
622 set_wm_protocols (window);
624 if (!window->input_only)
626 /* The focus window is off the visible area, and serves to receive key
627 * press events so they don't get sent to child windows.
629 toplevel->focus_window = create_focus_window (display, xid);
630 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
633 check_leader_window_title (screen_x11->display);
635 /* FIXME: Is there any point in doing this? Do any WM's pay
636 * attention to PSize, and even if they do, is this the
639 size_hints.flags = PSize;
640 size_hints.width = window->width;
641 size_hints.height = window->height;
643 XSetWMNormalHints (xdisplay, xid, &size_hints);
645 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
646 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
649 XChangeProperty (xdisplay, xid,
650 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
655 leader_window = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
658 XChangeProperty (xdisplay, xid,
659 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
660 XA_WINDOW, 32, PropModeReplace,
661 (guchar *) &leader_window, 1);
663 if (toplevel->focus_window != None)
664 XChangeProperty (xdisplay, xid,
665 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_USER_TIME_WINDOW"),
666 XA_WINDOW, 32, PropModeReplace,
667 (guchar *) &toplevel->focus_window, 1);
669 if (!window->focus_on_map)
670 gdk_x11_window_set_user_time (window, 0);
671 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
672 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
674 ensure_sync_counter (window);
678 _gdk_window_impl_new (GdkWindow *window,
679 GdkWindow *real_parent,
681 GdkEventMask event_mask,
682 GdkWindowAttr *attributes,
683 gint attributes_mask)
685 GdkWindowImplX11 *impl;
686 GdkScreenX11 *screen_x11;
687 GdkDisplayX11 *display_x11;
693 XSetWindowAttributes xattributes;
694 long xattributes_mask;
695 XClassHint *class_hint;
700 screen_x11 = GDK_SCREEN_X11 (screen);
701 xparent = GDK_WINDOW_XID (real_parent);
702 display_x11 = GDK_DISPLAY_X11 (GDK_SCREEN_DISPLAY (screen));
704 impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
705 window->impl = GDK_WINDOW_IMPL (impl);
706 impl->wrapper = GDK_WINDOW (window);
708 xdisplay = screen_x11->xdisplay;
710 xattributes_mask = 0;
712 xvisual = gdk_x11_visual_get_xvisual (window->visual);
714 if (attributes_mask & GDK_WA_NOREDIR)
716 xattributes.override_redirect =
717 (attributes->override_redirect == FALSE)?False:True;
718 xattributes_mask |= CWOverrideRedirect;
721 xattributes.override_redirect = False;
723 impl->override_redirect = xattributes.override_redirect;
725 if (window->parent && window->parent->guffaw_gravity)
727 xattributes.win_gravity = StaticGravity;
728 xattributes_mask |= CWWinGravity;
732 switch (window->window_type)
734 case GDK_WINDOW_TOPLEVEL:
735 case GDK_WINDOW_TEMP:
736 if (GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT)
738 /* The common code warns for this case */
739 xparent = GDK_SCREEN_XROOTWIN (screen);
743 if (!window->input_only)
747 xattributes.background_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
749 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
750 xattributes_mask |= CWBorderPixel | CWBackPixel;
752 if (window->guffaw_gravity)
753 xattributes.bit_gravity = StaticGravity;
755 xattributes.bit_gravity = NorthWestGravity;
757 xattributes_mask |= CWBitGravity;
759 xattributes.colormap = _gdk_visual_get_x11_colormap (window->visual);
760 xattributes_mask |= CWColormap;
762 if (window->window_type == GDK_WINDOW_TEMP)
764 xattributes.save_under = True;
765 xattributes.override_redirect = True;
766 xattributes.cursor = None;
767 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
769 impl->override_redirect = TRUE;
777 if (window->width > 65535 ||
778 window->height > 65535)
780 g_warning ("Native Windows wider or taller than 65535 pixels are not supported");
782 if (window->width > 65535)
783 window->width = 65535;
784 if (window->height > 65535)
785 window->height = 65535;
788 impl->xid = XCreateWindow (xdisplay, xparent,
789 window->x + window->parent->abs_x,
790 window->y + window->parent->abs_y,
791 window->width, window->height,
792 0, window->depth, class, xvisual,
793 xattributes_mask, &xattributes);
795 g_object_ref (window);
796 _gdk_xid_table_insert (screen_x11->display, &impl->xid, window);
798 switch (GDK_WINDOW_TYPE (window))
800 case GDK_WINDOW_TOPLEVEL:
801 case GDK_WINDOW_TEMP:
802 if (attributes_mask & GDK_WA_TITLE)
803 title = attributes->title;
805 title = get_default_title ();
807 gdk_window_set_title (window, title);
809 if (attributes_mask & GDK_WA_WMCLASS)
811 class_hint = XAllocClassHint ();
812 class_hint->res_name = attributes->wmclass_name;
813 class_hint->res_class = attributes->wmclass_class;
814 XSetClassHint (xdisplay, impl->xid, class_hint);
818 setup_toplevel_window (window, window->parent);
821 case GDK_WINDOW_CHILD:
826 if (attributes_mask & GDK_WA_TYPE_HINT)
827 gdk_window_set_type_hint (window, attributes->type_hint);
829 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
830 GDK_WINDOW_XID (window), event_mask,
831 StructureNotifyMask | PropertyChangeMask);
835 x_event_mask_to_gdk_event_mask (long mask)
837 GdkEventMask event_mask = 0;
840 for (i = 0; i < _gdk_nenvent_masks; i++)
842 if (mask & _gdk_event_mask_table[i])
843 event_mask |= 1 << (i + 1);
850 * gdk_window_foreign_new_for_display:
851 * @display: the #GdkDisplay where the window handle comes from.
852 * @anid: a native window handle.
854 * Wraps a native window in a #GdkWindow.
855 * This may fail if the window has been destroyed. If the window
856 * was already known to GDK, a new reference to the existing
857 * #GdkWindow is returned.
859 * For example in the X backend, a native window handle is an Xlib
862 * Return value: (transfer full): a #GdkWindow wrapper for the native
863 * window, or %NULL if the window has been destroyed. The wrapper
864 * will be newly created, if one doesn't exist already.
869 gdk_window_foreign_new_for_display (GdkDisplay *display,
870 GdkNativeWindow anid)
874 GdkWindowImplX11 *impl;
875 GdkDisplayX11 *display_x11;
876 XWindowAttributes attrs;
878 Window *children = NULL;
882 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
884 display_x11 = GDK_DISPLAY_X11 (display);
886 if ((window = gdk_xid_table_lookup_for_display (display, anid)) != NULL)
887 return g_object_ref (window);
889 gdk_error_trap_push ();
890 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
891 if (gdk_error_trap_pop () || !result)
894 /* FIXME: This is pretty expensive. Maybe the caller should supply
896 gdk_error_trap_push ();
897 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
898 if (gdk_error_trap_pop () || !result)
904 screen = _gdk_x11_display_screen_for_xrootwin (display, root);
906 window = g_object_new (GDK_TYPE_WINDOW, NULL);
908 window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
909 window->impl_window = window;
910 window->visual = gdk_x11_screen_lookup_visual (screen,
911 XVisualIDFromVisual (attrs.visual));
913 impl = GDK_WINDOW_IMPL_X11 (window->impl);
914 impl->wrapper = window;
916 window->parent = gdk_xid_table_lookup_for_display (display, parent);
918 if (!window->parent || GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_FOREIGN)
919 window->parent = gdk_screen_get_root_window (screen);
921 window->parent->children = g_list_prepend (window->parent->children, window);
927 window->width = attrs.width;
928 window->height = attrs.height;
929 window->window_type = GDK_WINDOW_FOREIGN;
930 window->destroyed = FALSE;
932 window->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
934 if (attrs.map_state == IsUnmapped)
935 window->state = GDK_WINDOW_STATE_WITHDRAWN;
938 window->viewable = TRUE;
940 window->depth = attrs.depth;
942 g_object_ref (window);
943 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
945 /* Update the clip region, etc */
946 _gdk_window_update_size (window);
952 * gdk_window_lookup_for_display:
953 * @display: the #GdkDisplay corresponding to the window handle
954 * @anid: a native window handle.
956 * Looks up the #GdkWindow that wraps the given native window handle.
958 * For example in the X backend, a native window handle is an Xlib
961 * Return value: (transfer none): the #GdkWindow wrapper for the native
962 * window, or %NULL if there is none.
967 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
969 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
974 * @anid: a native window handle.
976 * Looks up the #GdkWindow that wraps the given native window handle.
978 * For example in the X backend, a native window handle is an Xlib
981 * Return value: (transfer none): the #GdkWindow wrapper for the native
982 * window, or %NULL if there is none.
985 gdk_window_lookup (GdkNativeWindow anid)
987 return (GdkWindow*) gdk_xid_table_lookup (anid);
991 gdk_toplevel_x11_free_contents (GdkDisplay *display,
992 GdkToplevelX11 *toplevel)
994 if (toplevel->icon_pixmap)
996 cairo_surface_destroy (toplevel->icon_pixmap);
997 toplevel->icon_pixmap = NULL;
999 if (toplevel->icon_mask)
1001 cairo_surface_destroy (toplevel->icon_mask);
1002 toplevel->icon_mask = NULL;
1004 if (toplevel->group_leader)
1006 g_object_unref (toplevel->group_leader);
1007 toplevel->group_leader = NULL;
1010 if (toplevel->update_counter != None)
1012 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
1013 toplevel->update_counter);
1014 toplevel->update_counter = None;
1016 XSyncIntToValue (&toplevel->current_counter_value, 0);
1022 _gdk_x11_window_destroy (GdkWindow *window,
1024 gboolean foreign_destroy)
1026 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1027 GdkToplevelX11 *toplevel;
1029 g_return_if_fail (GDK_IS_WINDOW (window));
1031 _gdk_selection_window_destroyed (window);
1033 toplevel = _gdk_x11_window_get_toplevel (window);
1035 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1037 if (impl->cairo_surface)
1039 cairo_surface_finish (impl->cairo_surface);
1040 cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
1044 if (!recursing && !foreign_destroy)
1046 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1050 static cairo_surface_t *
1051 gdk_window_x11_resize_cairo_surface (GdkWindow *window,
1052 cairo_surface_t *surface,
1056 cairo_xlib_surface_set_size (surface, width, height);
1062 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
1064 /* It's somebody else's window, but in our hierarchy,
1065 * so reparent it to the root window, and then send
1066 * it a delete event, as if we were a WM
1068 XClientMessageEvent xclient;
1070 gdk_error_trap_push ();
1071 gdk_window_hide (window);
1072 gdk_window_reparent (window, NULL, 0, 0);
1074 memset (&xclient, 0, sizeof (xclient));
1075 xclient.type = ClientMessage;
1076 xclient.window = GDK_WINDOW_XID (window);
1077 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1079 xclient.format = 32;
1080 xclient.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1081 "WM_DELETE_WINDOW");
1082 xclient.data.l[1] = CurrentTime;
1083 xclient.data.l[2] = 0;
1084 xclient.data.l[3] = 0;
1085 xclient.data.l[4] = 0;
1087 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1088 GDK_WINDOW_XID (window),
1089 False, 0, (XEvent *)&xclient);
1090 gdk_error_trap_pop_ignored ();
1094 get_root (GdkWindow *window)
1096 GdkScreen *screen = gdk_window_get_screen (window);
1098 return gdk_screen_get_root_window (screen);
1101 /* This function is called when the XWindow is really gone.
1104 gdk_window_destroy_notify (GdkWindow *window)
1106 GdkWindowImplX11 *window_impl;
1108 window_impl = GDK_WINDOW_IMPL_X11 ((window)->impl);
1110 if (!GDK_WINDOW_DESTROYED (window))
1112 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1113 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1115 _gdk_window_destroy (window, TRUE);
1118 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1119 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1120 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1122 _gdk_xgrab_check_destroy (window);
1124 g_object_unref (window);
1128 update_wm_hints (GdkWindow *window,
1131 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1132 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1136 !toplevel->is_leader &&
1137 window->state & GDK_WINDOW_STATE_WITHDRAWN)
1140 wm_hints.flags = StateHint | InputHint;
1141 wm_hints.input = window->accept_focus ? True : False;
1142 wm_hints.initial_state = NormalState;
1144 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
1146 wm_hints.flags |= StateHint;
1147 wm_hints.initial_state = IconicState;
1150 if (toplevel->icon_pixmap)
1152 wm_hints.flags |= IconPixmapHint;
1153 wm_hints.icon_pixmap = cairo_xlib_surface_get_drawable (toplevel->icon_pixmap);
1156 if (toplevel->icon_mask)
1158 wm_hints.flags |= IconMaskHint;
1159 wm_hints.icon_mask = cairo_xlib_surface_get_drawable (toplevel->icon_mask);
1162 wm_hints.flags |= WindowGroupHint;
1163 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1165 wm_hints.flags |= WindowGroupHint;
1166 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1169 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1171 if (toplevel->urgency_hint)
1172 wm_hints.flags |= XUrgencyHint;
1174 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1175 GDK_WINDOW_XID (window),
1180 set_initial_hints (GdkWindow *window)
1182 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1183 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1184 Window xwindow = GDK_WINDOW_XID (window);
1185 GdkToplevelX11 *toplevel;
1189 toplevel = _gdk_x11_window_get_toplevel (window);
1194 update_wm_hints (window, TRUE);
1196 /* We set the spec hints regardless of whether the spec is supported,
1197 * since it can't hurt and it's kind of expensive to check whether
1203 if (window->state & GDK_WINDOW_STATE_MAXIMIZED)
1205 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1206 "_NET_WM_STATE_MAXIMIZED_VERT");
1208 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1209 "_NET_WM_STATE_MAXIMIZED_HORZ");
1211 toplevel->have_maxhorz = toplevel->have_maxvert = TRUE;
1214 if (window->state & GDK_WINDOW_STATE_ABOVE)
1216 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1217 "_NET_WM_STATE_ABOVE");
1221 if (window->state & GDK_WINDOW_STATE_BELOW)
1223 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1224 "_NET_WM_STATE_BELOW");
1228 if (window->state & GDK_WINDOW_STATE_STICKY)
1230 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1231 "_NET_WM_STATE_STICKY");
1233 toplevel->have_sticky = TRUE;
1236 if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
1238 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1239 "_NET_WM_STATE_FULLSCREEN");
1241 toplevel->have_fullscreen = TRUE;
1244 if (window->modal_hint)
1246 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1247 "_NET_WM_STATE_MODAL");
1251 if (toplevel->skip_taskbar_hint)
1253 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1254 "_NET_WM_STATE_SKIP_TASKBAR");
1258 if (toplevel->skip_pager_hint)
1260 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1261 "_NET_WM_STATE_SKIP_PAGER");
1267 XChangeProperty (xdisplay,
1269 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1270 XA_ATOM, 32, PropModeReplace,
1271 (guchar*) atoms, i);
1275 XDeleteProperty (xdisplay,
1277 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1280 if (window->state & GDK_WINDOW_STATE_STICKY)
1282 atoms[0] = 0xFFFFFFFF;
1283 XChangeProperty (xdisplay,
1285 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1286 XA_CARDINAL, 32, PropModeReplace,
1287 (guchar*) atoms, 1);
1288 toplevel->on_all_desktops = TRUE;
1292 XDeleteProperty (xdisplay,
1294 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1297 toplevel->map_serial = NextRequest (xdisplay);
1301 gdk_window_x11_show (GdkWindow *window, gboolean already_mapped)
1303 GdkDisplay *display;
1304 GdkDisplayX11 *display_x11;
1305 GdkToplevelX11 *toplevel;
1306 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1307 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1308 Window xwindow = GDK_WINDOW_XID (window);
1311 if (!already_mapped)
1312 set_initial_hints (window);
1314 if (WINDOW_IS_TOPLEVEL (window))
1316 display = gdk_window_get_display (window);
1317 display_x11 = GDK_DISPLAY_X11 (display);
1318 toplevel = _gdk_x11_window_get_toplevel (window);
1320 if (toplevel->user_time != 0 &&
1321 display_x11->user_time != 0 &&
1322 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1323 gdk_x11_window_set_user_time (window, display_x11->user_time);
1326 unset_bg = !window->input_only &&
1327 (window->window_type == GDK_WINDOW_CHILD ||
1328 impl->override_redirect) &&
1329 gdk_window_is_viewable (window);
1332 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1334 XMapWindow (xdisplay, xwindow);
1337 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1341 pre_unmap (GdkWindow *window)
1343 GdkWindow *start_window = NULL;
1345 if (window->input_only)
1348 if (window->window_type == GDK_WINDOW_CHILD)
1349 start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
1350 else if (window->window_type == GDK_WINDOW_TEMP)
1351 start_window = get_root (window);
1354 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1358 post_unmap (GdkWindow *window)
1360 GdkWindow *start_window = NULL;
1362 if (window->input_only)
1365 if (window->window_type == GDK_WINDOW_CHILD)
1366 start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
1367 else if (window->window_type == GDK_WINDOW_TEMP)
1368 start_window = get_root (window);
1372 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1374 if (window->window_type == GDK_WINDOW_CHILD && window->parent)
1376 GdkRectangle invalid_rect;
1378 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1379 invalid_rect.width = gdk_window_get_width (window);
1380 invalid_rect.height = gdk_window_get_height (window);
1381 gdk_window_invalidate_rect ((GdkWindow *)window->parent,
1382 &invalid_rect, TRUE);
1388 gdk_window_x11_hide (GdkWindow *window)
1390 /* We'll get the unmap notify eventually, and handle it then,
1391 * but checking here makes things more consistent if we are
1392 * just doing stuff ourself.
1394 _gdk_xgrab_check_unmap (window,
1395 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1397 /* You can't simply unmap toplevel windows. */
1398 switch (window->window_type)
1400 case GDK_WINDOW_TOPLEVEL:
1401 case GDK_WINDOW_TEMP: /* ? */
1402 gdk_window_withdraw (window);
1405 case GDK_WINDOW_FOREIGN:
1406 case GDK_WINDOW_ROOT:
1407 case GDK_WINDOW_CHILD:
1411 _gdk_window_clear_update_area (window);
1414 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1415 GDK_WINDOW_XID (window));
1416 post_unmap (window);
1420 gdk_window_x11_withdraw (GdkWindow *window)
1422 if (!window->destroyed)
1424 if (GDK_WINDOW_IS_MAPPED (window))
1425 gdk_synthesize_window_state (window,
1427 GDK_WINDOW_STATE_WITHDRAWN);
1429 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1433 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1434 GDK_WINDOW_XID (window), 0);
1436 post_unmap (window);
1441 window_x11_move (GdkWindow *window,
1445 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1447 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1449 _gdk_window_move_resize_child (window,
1451 window->width, window->height);
1455 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1456 GDK_WINDOW_XID (window),
1459 if (impl->override_redirect)
1468 window_x11_resize (GdkWindow *window,
1478 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1480 _gdk_window_move_resize_child (window,
1481 window->x, window->y,
1486 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1488 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1489 GDK_WINDOW_XID (window),
1492 if (impl->override_redirect)
1494 window->width = width;
1495 window->height = height;
1496 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1500 if (width != window->width || height != window->height)
1501 window->resize_count += 1;
1505 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1509 window_x11_move_resize (GdkWindow *window,
1521 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1523 _gdk_window_move_resize_child (window, x, y, width, height);
1524 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1528 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1530 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1531 GDK_WINDOW_XID (window),
1532 x, y, width, height);
1534 if (impl->override_redirect)
1539 window->width = width;
1540 window->height = height;
1542 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1546 if (width != window->width || height != window->height)
1547 window->resize_count += 1;
1553 gdk_window_x11_move_resize (GdkWindow *window,
1560 if (with_move && (width < 0 && height < 0))
1561 window_x11_move (window, x, y);
1565 window_x11_move_resize (window, x, y, width, height);
1567 window_x11_resize (window, width, height);
1572 gdk_window_x11_reparent (GdkWindow *window,
1573 GdkWindow *new_parent,
1577 GdkWindowImplX11 *impl;
1579 impl = GDK_WINDOW_IMPL_X11 (window->impl);
1581 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1582 _gdk_x11_window_tmp_unset_parent_bg (window);
1583 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1584 GDK_WINDOW_XID (window),
1585 GDK_WINDOW_XID (new_parent),
1586 new_parent->abs_x + x, new_parent->abs_y + y);
1587 _gdk_x11_window_tmp_reset_parent_bg (window);
1588 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1590 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1591 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1593 window->parent = new_parent;
1595 /* Switch the window type as appropriate */
1597 switch (GDK_WINDOW_TYPE (new_parent))
1599 case GDK_WINDOW_ROOT:
1600 case GDK_WINDOW_FOREIGN:
1601 /* Reparenting to toplevel */
1603 if (!WINDOW_IS_TOPLEVEL (window) &&
1604 GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1606 /* This is also done in common code at a later stage, but we
1607 need it in setup_toplevel, so do it here too */
1608 if (window->toplevel_window_type != -1)
1609 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1610 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1611 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1613 /* Wasn't a toplevel, set up */
1614 setup_toplevel_window (window, new_parent);
1619 case GDK_WINDOW_TOPLEVEL:
1620 case GDK_WINDOW_CHILD:
1621 case GDK_WINDOW_TEMP:
1622 if (WINDOW_IS_TOPLEVEL (window) &&
1625 if (impl->toplevel->focus_window)
1627 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1628 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1631 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1633 g_free (impl->toplevel);
1634 impl->toplevel = NULL;
1642 gdk_window_x11_raise (GdkWindow *window)
1644 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1648 gdk_window_x11_restack_under (GdkWindow *window,
1649 GList *native_siblings /* in requested order, first is bottom-most */)
1655 n_windows = g_list_length (native_siblings) + 1;
1656 windows = g_new (Window, n_windows);
1658 windows[0] = GDK_WINDOW_XID (window);
1659 /* Reverse order, as input order is bottom-most first */
1661 for (l = native_siblings; l != NULL; l = l->next)
1662 windows[i--] = GDK_WINDOW_XID (l->data);
1664 XRestackWindows (GDK_WINDOW_XDISPLAY (window), windows, n_windows);
1670 gdk_window_x11_restack_toplevel (GdkWindow *window,
1674 XWindowChanges changes;
1676 changes.sibling = GDK_WINDOW_XID (sibling);
1677 changes.stack_mode = above ? Above : Below;
1678 XReconfigureWMWindow (GDK_WINDOW_XDISPLAY (window),
1679 GDK_WINDOW_XID (window),
1680 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)),
1681 CWStackMode | CWSibling, &changes);
1685 gdk_window_x11_lower (GdkWindow *window)
1687 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1691 * gdk_x11_window_move_to_current_desktop:
1692 * @window: a #GdkWindow
1694 * Moves the window to the correct workspace when running under a
1695 * window manager that supports multiple workspaces, as described
1696 * in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
1697 * Window Manager Hints</ulink>. Will not do anything if the
1698 * window is already on all workspaces.
1703 gdk_x11_window_move_to_current_desktop (GdkWindow *window)
1705 GdkToplevelX11 *toplevel;
1707 g_return_if_fail (GDK_IS_WINDOW (window));
1708 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1710 toplevel = _gdk_x11_window_get_toplevel (window);
1712 if (toplevel->on_all_desktops)
1715 move_to_current_desktop (window);
1719 move_to_current_desktop (GdkWindow *window)
1721 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1722 gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
1729 gulong *current_desktop;
1730 GdkDisplay *display;
1732 display = gdk_window_get_display (window);
1734 /* Get current desktop, then set it; this is a race, but not
1735 * one that matters much in practice.
1737 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
1738 GDK_WINDOW_XROOTWIN (window),
1739 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
1741 False, XA_CARDINAL, &type, &format, &nitems,
1742 &bytes_after, &data);
1744 if (type == XA_CARDINAL)
1746 XClientMessageEvent xclient;
1747 current_desktop = (gulong *)data;
1749 memset (&xclient, 0, sizeof (xclient));
1750 xclient.type = ClientMessage;
1752 xclient.send_event = True;
1753 xclient.window = GDK_WINDOW_XID (window);
1754 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
1755 xclient.format = 32;
1757 xclient.data.l[0] = *current_desktop;
1758 xclient.data.l[1] = 0;
1759 xclient.data.l[2] = 0;
1760 xclient.data.l[3] = 0;
1761 xclient.data.l[4] = 0;
1763 XSendEvent (GDK_DISPLAY_XDISPLAY (display),
1764 GDK_WINDOW_XROOTWIN (window),
1766 SubstructureRedirectMask | SubstructureNotifyMask,
1767 (XEvent *)&xclient);
1769 XFree (current_desktop);
1776 * @window: a #GdkWindow
1777 * @timestamp: timestamp of the event triggering the window focus
1779 * Sets keyboard focus to @window. In most cases, gtk_window_present()
1780 * should be used on a #GtkWindow, rather than calling this function.
1784 gdk_window_focus (GdkWindow *window,
1787 GdkDisplay *display;
1789 g_return_if_fail (GDK_IS_WINDOW (window));
1791 if (GDK_WINDOW_DESTROYED (window) ||
1792 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1795 display = GDK_WINDOW_DISPLAY (window);
1797 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1798 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
1800 XClientMessageEvent xclient;
1802 memset (&xclient, 0, sizeof (xclient));
1803 xclient.type = ClientMessage;
1804 xclient.window = GDK_WINDOW_XID (window);
1805 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1806 "_NET_ACTIVE_WINDOW");
1807 xclient.format = 32;
1808 xclient.data.l[0] = 1; /* requestor type; we're an app */
1809 xclient.data.l[1] = timestamp;
1810 xclient.data.l[2] = None; /* currently active window */
1811 xclient.data.l[3] = 0;
1812 xclient.data.l[4] = 0;
1814 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1815 SubstructureRedirectMask | SubstructureNotifyMask,
1816 (XEvent *)&xclient);
1820 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1822 /* There is no way of knowing reliably whether we are viewable;
1823 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1825 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1832 * gdk_window_set_type_hint:
1833 * @window: A toplevel #GdkWindow
1834 * @hint: A hint of the function this window will have
1836 * The application can use this call to provide a hint to the window
1837 * manager about the functionality of a window. The window manager
1838 * can use this information when determining the decoration and behaviour
1841 * The hint must be set before the window is mapped.
1844 gdk_window_set_type_hint (GdkWindow *window,
1845 GdkWindowTypeHint hint)
1847 GdkDisplay *display;
1850 if (GDK_WINDOW_DESTROYED (window) ||
1851 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1854 display = gdk_window_get_display (window);
1858 case GDK_WINDOW_TYPE_HINT_DIALOG:
1859 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1861 case GDK_WINDOW_TYPE_HINT_MENU:
1862 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1864 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1865 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1867 case GDK_WINDOW_TYPE_HINT_UTILITY:
1868 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1870 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1871 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1873 case GDK_WINDOW_TYPE_HINT_DOCK:
1874 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1876 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1877 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1879 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
1880 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
1882 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
1883 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
1885 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
1886 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
1888 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
1889 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
1891 case GDK_WINDOW_TYPE_HINT_COMBO:
1892 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
1894 case GDK_WINDOW_TYPE_HINT_DND:
1895 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
1898 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1900 case GDK_WINDOW_TYPE_HINT_NORMAL:
1901 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1905 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1906 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1907 XA_ATOM, 32, PropModeReplace,
1908 (guchar *)&atom, 1);
1912 * gdk_window_get_type_hint:
1913 * @window: A toplevel #GdkWindow
1915 * This function returns the type hint set for a window.
1917 * Return value: The type hint set for @window
1922 gdk_window_get_type_hint (GdkWindow *window)
1924 GdkDisplay *display;
1925 GdkWindowTypeHint type;
1928 gulong nitems_return;
1929 gulong bytes_after_return;
1930 guchar *data = NULL;
1932 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
1934 if (GDK_WINDOW_DESTROYED (window) ||
1935 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1936 return GDK_WINDOW_TYPE_HINT_NORMAL;
1938 type = GDK_WINDOW_TYPE_HINT_NORMAL;
1940 display = gdk_window_get_display (window);
1942 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1943 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1944 0, G_MAXLONG, False, XA_ATOM, &type_return,
1945 &format_return, &nitems_return, &bytes_after_return,
1948 if ((type_return == XA_ATOM) && (format_return == 32) &&
1949 (data) && (nitems_return == 1))
1951 Atom atom = *(Atom*)data;
1953 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
1954 type = GDK_WINDOW_TYPE_HINT_DIALOG;
1955 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
1956 type = GDK_WINDOW_TYPE_HINT_MENU;
1957 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
1958 type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
1959 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
1960 type = GDK_WINDOW_TYPE_HINT_UTILITY;
1961 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
1962 type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
1963 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
1964 type = GDK_WINDOW_TYPE_HINT_DOCK;
1965 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
1966 type = GDK_WINDOW_TYPE_HINT_DESKTOP;
1967 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
1968 type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
1969 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
1970 type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
1971 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
1972 type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
1973 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
1974 type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
1975 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
1976 type = GDK_WINDOW_TYPE_HINT_COMBO;
1977 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
1978 type = GDK_WINDOW_TYPE_HINT_DND;
1981 if (type_return != None && data != NULL)
1989 gdk_wmspec_change_state (gboolean add,
1994 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1995 XClientMessageEvent xclient;
1997 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1998 #define _NET_WM_STATE_ADD 1 /* add/set property */
1999 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
2001 memset (&xclient, 0, sizeof (xclient));
2002 xclient.type = ClientMessage;
2003 xclient.window = GDK_WINDOW_XID (window);
2004 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
2005 xclient.format = 32;
2006 xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
2007 xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
2008 xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
2009 xclient.data.l[3] = 0;
2010 xclient.data.l[4] = 0;
2012 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
2013 SubstructureRedirectMask | SubstructureNotifyMask,
2014 (XEvent *)&xclient);
2018 * gdk_window_set_modal_hint:
2019 * @window: A toplevel #GdkWindow
2020 * @modal: %TRUE if the window is modal, %FALSE otherwise.
2022 * The application can use this hint to tell the window manager
2023 * that a certain window has modal behaviour. The window manager
2024 * can use this information to handle modal windows in a special
2027 * You should only use this on windows for which you have
2028 * previously called gdk_window_set_transient_for()
2031 gdk_window_set_modal_hint (GdkWindow *window,
2034 if (GDK_WINDOW_DESTROYED (window) ||
2035 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2038 window->modal_hint = modal;
2040 if (GDK_WINDOW_IS_MAPPED (window))
2041 gdk_wmspec_change_state (modal, window,
2042 gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
2047 * gdk_window_set_skip_taskbar_hint:
2048 * @window: a toplevel #GdkWindow
2049 * @skips_taskbar: %TRUE to skip the taskbar
2051 * Toggles whether a window should appear in a task list or window
2052 * list. If a window's semantic type as specified with
2053 * gdk_window_set_type_hint() already fully describes the window, this
2054 * function should <emphasis>not</emphasis> be called in addition,
2055 * instead you should allow the window to be treated according to
2056 * standard policy for its semantic type.
2061 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2062 gboolean skips_taskbar)
2064 GdkToplevelX11 *toplevel;
2066 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2068 if (GDK_WINDOW_DESTROYED (window) ||
2069 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2072 toplevel = _gdk_x11_window_get_toplevel (window);
2073 toplevel->skip_taskbar_hint = skips_taskbar;
2075 if (GDK_WINDOW_IS_MAPPED (window))
2076 gdk_wmspec_change_state (skips_taskbar, window,
2077 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
2082 * gdk_window_set_skip_pager_hint:
2083 * @window: a toplevel #GdkWindow
2084 * @skips_pager: %TRUE to skip the pager
2086 * Toggles whether a window should appear in a pager (workspace
2087 * switcher, or other desktop utility program that displays a small
2088 * thumbnail representation of the windows on the desktop). If a
2089 * window's semantic type as specified with gdk_window_set_type_hint()
2090 * already fully describes the window, this function should
2091 * <emphasis>not</emphasis> be called in addition, instead you should
2092 * allow the window to be treated according to standard policy for
2093 * its semantic type.
2098 gdk_window_set_skip_pager_hint (GdkWindow *window,
2099 gboolean skips_pager)
2101 GdkToplevelX11 *toplevel;
2103 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2105 if (GDK_WINDOW_DESTROYED (window) ||
2106 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2109 toplevel = _gdk_x11_window_get_toplevel (window);
2110 toplevel->skip_pager_hint = skips_pager;
2112 if (GDK_WINDOW_IS_MAPPED (window))
2113 gdk_wmspec_change_state (skips_pager, window,
2114 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
2119 * gdk_window_set_urgency_hint:
2120 * @window: a toplevel #GdkWindow
2121 * @urgent: %TRUE if the window is urgent
2123 * Toggles whether a window needs the user's
2129 gdk_window_set_urgency_hint (GdkWindow *window,
2132 GdkToplevelX11 *toplevel;
2134 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2136 if (GDK_WINDOW_DESTROYED (window) ||
2137 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2140 toplevel = _gdk_x11_window_get_toplevel (window);
2141 toplevel->urgency_hint = urgent;
2143 update_wm_hints (window, FALSE);
2147 * gdk_window_set_geometry_hints:
2148 * @window: a toplevel #GdkWindow
2149 * @geometry: geometry hints
2150 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
2152 * Sets the geometry hints for @window. Hints flagged in @geom_mask
2153 * are set, hints not flagged in @geom_mask are unset.
2154 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
2156 * This function provides hints to the windowing system about
2157 * acceptable sizes for a toplevel window. The purpose of
2158 * this is to constrain user resizing, but the windowing system
2159 * will typically (but is not required to) also constrain the
2160 * current size of the window to the provided values and
2161 * constrain programatic resizing via gdk_window_resize() or
2162 * gdk_window_move_resize().
2164 * Note that on X11, this effect has no effect on windows
2165 * of type %GDK_WINDOW_TEMP or windows where override redirect
2166 * has been turned on via gdk_window_set_override_redirect()
2167 * since these windows are not resizable by the user.
2169 * Since you can't count on the windowing system doing the
2170 * constraints for programmatic resizes, you should generally
2171 * call gdk_window_constrain_size() yourself to determine
2172 * appropriate sizes.
2176 gdk_window_set_geometry_hints (GdkWindow *window,
2177 const GdkGeometry *geometry,
2178 GdkWindowHints geom_mask)
2180 XSizeHints size_hints;
2182 if (GDK_WINDOW_DESTROYED (window) ||
2183 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2186 size_hints.flags = 0;
2188 if (geom_mask & GDK_HINT_POS)
2190 size_hints.flags |= PPosition;
2191 /* We need to initialize the following obsolete fields because KWM
2192 * apparently uses these fields if they are non-zero.
2199 if (geom_mask & GDK_HINT_USER_POS)
2201 size_hints.flags |= USPosition;
2204 if (geom_mask & GDK_HINT_USER_SIZE)
2206 size_hints.flags |= USSize;
2209 if (geom_mask & GDK_HINT_MIN_SIZE)
2211 size_hints.flags |= PMinSize;
2212 size_hints.min_width = geometry->min_width;
2213 size_hints.min_height = geometry->min_height;
2216 if (geom_mask & GDK_HINT_MAX_SIZE)
2218 size_hints.flags |= PMaxSize;
2219 size_hints.max_width = MAX (geometry->max_width, 1);
2220 size_hints.max_height = MAX (geometry->max_height, 1);
2223 if (geom_mask & GDK_HINT_BASE_SIZE)
2225 size_hints.flags |= PBaseSize;
2226 size_hints.base_width = geometry->base_width;
2227 size_hints.base_height = geometry->base_height;
2230 if (geom_mask & GDK_HINT_RESIZE_INC)
2232 size_hints.flags |= PResizeInc;
2233 size_hints.width_inc = geometry->width_inc;
2234 size_hints.height_inc = geometry->height_inc;
2237 if (geom_mask & GDK_HINT_ASPECT)
2239 size_hints.flags |= PAspect;
2240 if (geometry->min_aspect <= 1)
2242 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2243 size_hints.min_aspect.y = 65536;
2247 size_hints.min_aspect.x = 65536;
2248 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2250 if (geometry->max_aspect <= 1)
2252 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2253 size_hints.max_aspect.y = 65536;
2257 size_hints.max_aspect.x = 65536;
2258 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2262 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2264 size_hints.flags |= PWinGravity;
2265 size_hints.win_gravity = geometry->win_gravity;
2268 /* FIXME: Would it be better to delete this property if
2269 * geom_mask == 0? It would save space on the server
2271 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2272 GDK_WINDOW_XID (window),
2277 gdk_window_get_geometry_hints (GdkWindow *window,
2278 GdkGeometry *geometry,
2279 GdkWindowHints *geom_mask)
2281 XSizeHints *size_hints;
2282 glong junk_supplied_mask = 0;
2284 g_return_if_fail (GDK_IS_WINDOW (window));
2285 g_return_if_fail (geometry != NULL);
2286 g_return_if_fail (geom_mask != NULL);
2290 if (GDK_WINDOW_DESTROYED (window) ||
2291 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2294 size_hints = XAllocSizeHints ();
2298 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2299 GDK_WINDOW_XID (window),
2301 &junk_supplied_mask))
2302 size_hints->flags = 0;
2304 if (size_hints->flags & PMinSize)
2306 *geom_mask |= GDK_HINT_MIN_SIZE;
2307 geometry->min_width = size_hints->min_width;
2308 geometry->min_height = size_hints->min_height;
2311 if (size_hints->flags & PMaxSize)
2313 *geom_mask |= GDK_HINT_MAX_SIZE;
2314 geometry->max_width = MAX (size_hints->max_width, 1);
2315 geometry->max_height = MAX (size_hints->max_height, 1);
2318 if (size_hints->flags & PResizeInc)
2320 *geom_mask |= GDK_HINT_RESIZE_INC;
2321 geometry->width_inc = size_hints->width_inc;
2322 geometry->height_inc = size_hints->height_inc;
2325 if (size_hints->flags & PAspect)
2327 *geom_mask |= GDK_HINT_ASPECT;
2329 geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y;
2330 geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y;
2333 if (size_hints->flags & PWinGravity)
2335 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2336 geometry->win_gravity = size_hints->win_gravity;
2343 utf8_is_latin1 (const gchar *str)
2345 const char *p = str;
2349 gunichar ch = g_utf8_get_char (p);
2354 p = g_utf8_next_char (p);
2360 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2361 * convertable to STRING, otherwise, set it as compound text
2364 set_text_property (GdkDisplay *display,
2367 const gchar *utf8_str)
2369 gchar *prop_text = NULL;
2373 gboolean is_compound_text;
2375 if (utf8_is_latin1 (utf8_str))
2377 prop_type = XA_STRING;
2378 prop_text = gdk_utf8_to_string_target (utf8_str);
2379 prop_length = prop_text ? strlen (prop_text) : 0;
2381 is_compound_text = FALSE;
2387 gdk_utf8_to_compound_text_for_display (display,
2388 utf8_str, &gdk_type, &prop_format,
2389 (guchar **)&prop_text, &prop_length);
2390 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2391 is_compound_text = TRUE;
2396 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2399 prop_type, prop_format,
2400 PropModeReplace, (guchar *)prop_text,
2403 if (is_compound_text)
2404 gdk_free_compound_text ((guchar *)prop_text);
2410 /* Set WM_NAME and _NET_WM_NAME
2413 set_wm_name (GdkDisplay *display,
2417 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2418 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2419 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2420 PropModeReplace, (guchar *)name, strlen (name));
2422 set_text_property (display, xwindow,
2423 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2428 * gdk_window_set_title:
2429 * @window: a toplevel #GdkWindow
2430 * @title: title of @window
2432 * Sets the title of a toplevel window, to be displayed in the titlebar.
2433 * If you haven't explicitly set the icon name for the window
2434 * (using gdk_window_set_icon_name()), the icon name will be set to
2435 * @title as well. @title must be in UTF-8 encoding (as with all
2436 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2439 gdk_window_set_title (GdkWindow *window,
2442 GdkDisplay *display;
2446 g_return_if_fail (title != NULL);
2448 if (GDK_WINDOW_DESTROYED (window) ||
2449 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2452 display = gdk_window_get_display (window);
2453 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2454 xwindow = GDK_WINDOW_XID (window);
2456 set_wm_name (display, xwindow, title);
2458 if (!gdk_window_icon_name_set (window))
2460 XChangeProperty (xdisplay, xwindow,
2461 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2462 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2463 PropModeReplace, (guchar *)title, strlen (title));
2465 set_text_property (display, xwindow,
2466 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2472 * gdk_window_set_role:
2473 * @window: a toplevel #GdkWindow
2474 * @role: a string indicating its role
2476 * When using GTK+, typically you should use gtk_window_set_role() instead
2477 * of this low-level function.
2479 * The window manager and session manager use a window's role to
2480 * distinguish it from other kinds of window in the same application.
2481 * When an application is restarted after being saved in a previous
2482 * session, all windows with the same title and role are treated as
2483 * interchangeable. So if you have two windows with the same title
2484 * that should be distinguished for session management purposes, you
2485 * should set the role on those windows. It doesn't matter what string
2486 * you use for the role, as long as you have a different role for each
2487 * non-interchangeable kind of window.
2491 gdk_window_set_role (GdkWindow *window,
2494 GdkDisplay *display;
2496 display = gdk_window_get_display (window);
2498 if (GDK_WINDOW_DESTROYED (window) ||
2499 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2503 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2504 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2505 XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
2507 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2508 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2512 * gdk_window_set_startup_id:
2513 * @window: a toplevel #GdkWindow
2514 * @startup_id: a string with startup-notification identifier
2516 * When using GTK+, typically you should use gtk_window_set_startup_id()
2517 * instead of this low-level function.
2523 gdk_window_set_startup_id (GdkWindow *window,
2524 const gchar *startup_id)
2526 GdkDisplay *display;
2528 g_return_if_fail (GDK_IS_WINDOW (window));
2530 display = gdk_window_get_display (window);
2532 if (GDK_WINDOW_DESTROYED (window) ||
2533 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2537 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2538 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2539 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2540 PropModeReplace, (unsigned char *)startup_id, strlen (startup_id));
2542 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2543 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"));
2547 * gdk_window_set_transient_for:
2548 * @window: a toplevel #GdkWindow
2549 * @parent: another toplevel #GdkWindow
2551 * Indicates to the window manager that @window is a transient dialog
2552 * associated with the application window @parent. This allows the
2553 * window manager to do things like center @window on @parent and
2554 * keep @window above @parent.
2556 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2560 gdk_window_set_transient_for (GdkWindow *window,
2563 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) &&
2564 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2565 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2566 GDK_WINDOW_XID (window),
2567 GDK_WINDOW_XID (parent));
2571 gdk_window_x11_set_back_color (GdkWindow *window,
2577 GdkVisual *visual = gdk_window_get_visual (window);
2579 /* I suppose we could handle these, but that'd require fiddling with
2580 * xrender formats... */
2584 switch (visual->type)
2586 case GDK_VISUAL_DIRECT_COLOR:
2587 case GDK_VISUAL_TRUE_COLOR:
2589 /* If bits not used for color are used for something other than padding,
2590 * it's likely alpha, so we set them to 1s.
2592 guint padding, pixel;
2594 /* Shifting by >= width-of-type isn't defined in C */
2595 if (visual->depth >= 32)
2598 padding = ((~(guint32)0)) << visual->depth;
2600 pixel = ~ (visual->red_mask | visual->green_mask | visual->blue_mask | padding);
2602 pixel += (((int) (red * ((1 << visual->red_prec ) - 1))) << visual->red_shift ) +
2603 (((int) (green * ((1 << visual->green_prec) - 1))) << visual->green_shift) +
2604 (((int) (blue * ((1 << visual->blue_prec ) - 1))) << visual->blue_shift );
2606 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2607 GDK_WINDOW_XID (window), pixel);
2611 /* These require fiddling with the colormap, and as they're essentially unused
2612 * we're just gonna skip them for now.
2614 case GDK_VISUAL_PSEUDO_COLOR:
2615 case GDK_VISUAL_GRAYSCALE:
2616 case GDK_VISUAL_STATIC_GRAY:
2617 case GDK_VISUAL_STATIC_COLOR:
2626 matrix_is_identity (cairo_matrix_t *matrix)
2628 return matrix->xx == 1.0 && matrix->yy == 1.0 &&
2629 matrix->yx == 0.0 && matrix->xy == 0.0 &&
2630 matrix->x0 == 0.0 && matrix->y0 == 0.0;
2634 gdk_window_x11_set_background (GdkWindow *window,
2635 cairo_pattern_t *pattern)
2638 cairo_surface_t *surface;
2639 cairo_matrix_t matrix;
2641 if (GDK_WINDOW_DESTROYED (window))
2644 if (pattern == NULL)
2648 /* X throws BadMatch if the parent has a different visual when
2649 * using ParentRelative */
2650 parent = gdk_window_get_parent (window);
2651 if (parent && gdk_window_get_visual (parent) == gdk_window_get_visual (window))
2652 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2653 GDK_WINDOW_XID (window), ParentRelative);
2655 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2656 GDK_WINDOW_XID (window), None);
2660 switch (cairo_pattern_get_type (pattern))
2662 case CAIRO_PATTERN_TYPE_SOLID:
2663 cairo_pattern_get_rgba (pattern, &r, &g, &b, &a);
2664 if (gdk_window_x11_set_back_color (window, r, g, b, a))
2667 case CAIRO_PATTERN_TYPE_SURFACE:
2668 cairo_pattern_get_matrix (pattern, &matrix);
2669 if (cairo_pattern_get_surface (pattern, &surface) == CAIRO_STATUS_SUCCESS &&
2670 matrix_is_identity (&matrix) &&
2671 cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB &&
2672 cairo_xlib_surface_get_visual (surface) == GDK_VISUAL_XVISUAL (gdk_window_get_visual ((window))) &&
2673 cairo_xlib_surface_get_display (surface) == GDK_WINDOW_XDISPLAY (window))
2677 cairo_surface_get_device_offset (surface, &x, &y);
2678 /* XXX: This still bombs for non-pixmaps, but there's no way to
2679 * detect we're not a pixmap in Cairo... */
2680 if (x == 0.0 && y == 0.0)
2682 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2683 GDK_WINDOW_XID (window),
2684 cairo_xlib_surface_get_drawable (surface));
2689 case CAIRO_PATTERN_TYPE_LINEAR:
2690 case CAIRO_PATTERN_TYPE_RADIAL:
2692 /* fallback: just use black */
2696 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2697 GDK_WINDOW_XID (window), None);
2701 gdk_window_x11_set_device_cursor (GdkWindow *window,
2705 GdkWindowImplX11 *impl;
2707 g_return_if_fail (GDK_IS_WINDOW (window));
2708 g_return_if_fail (GDK_IS_DEVICE (device));
2710 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2713 g_hash_table_remove (impl->device_cursor, device);
2716 _gdk_x11_cursor_update_theme (cursor);
2717 g_hash_table_replace (impl->device_cursor,
2718 device, gdk_cursor_ref (cursor));
2721 if (!GDK_WINDOW_DESTROYED (window))
2722 GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor);
2726 _gdk_x11_window_get_cursor (GdkWindow *window)
2728 GdkWindowImplX11 *impl;
2730 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2732 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2734 return impl->cursor;
2738 gdk_window_x11_get_geometry (GdkWindow *window,
2750 guint tborder_width;
2753 if (!GDK_WINDOW_DESTROYED (window))
2755 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2756 GDK_WINDOW_XID (window),
2757 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2773 gdk_window_x11_get_root_coords (GdkWindow *window,
2784 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2785 GDK_WINDOW_XID (window),
2786 GDK_WINDOW_XROOTWIN (window),
2799 * gdk_window_get_root_origin:
2800 * @window: a toplevel #GdkWindow
2801 * @x: return location for X position of window frame
2802 * @y: return location for Y position of window frame
2804 * Obtains the top-left corner of the window manager frame in root
2805 * window coordinates.
2809 gdk_window_get_root_origin (GdkWindow *window,
2815 gdk_window_get_frame_extents (window, &rect);
2825 * gdk_window_get_frame_extents:
2826 * @window: a toplevel #GdkWindow
2827 * @rect: rectangle to fill with bounding box of the window frame
2829 * Obtains the bounding box of the window, including window manager
2830 * titlebar/borders if any. The frame position is given in root window
2831 * coordinates. To get the position of the window itself (rather than
2832 * the frame) in root window coordinates, use gdk_window_get_origin().
2836 gdk_window_get_frame_extents (GdkWindow *window,
2839 GdkDisplay *display;
2840 GdkWindowImplX11 *impl;
2851 gulong nitems_return;
2852 gulong bytes_after_return;
2855 guint ww, wh, wb, wd;
2857 gboolean got_frame_extents = FALSE;
2859 g_return_if_fail (rect != NULL);
2866 while (window->parent && (window->parent)->parent)
2867 window = window->parent;
2869 /* Refine our fallback answer a bit using local information */
2870 rect->x = window->x;
2871 rect->y = window->y;
2872 rect->width = window->width;
2873 rect->height = window->height;
2875 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2876 if (GDK_WINDOW_DESTROYED (window) || impl->override_redirect)
2882 gdk_error_trap_push();
2884 display = gdk_window_get_display (window);
2885 xwindow = GDK_WINDOW_XID (window);
2887 /* first try: use _NET_FRAME_EXTENTS */
2888 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2889 gdk_x11_get_xatom_by_name_for_display (display,
2890 "_NET_FRAME_EXTENTS"),
2891 0, G_MAXLONG, False, XA_CARDINAL, &type_return,
2892 &format_return, &nitems_return, &bytes_after_return,
2896 if ((type_return == XA_CARDINAL) && (format_return == 32) &&
2897 (nitems_return == 4) && (data))
2899 gulong *ldata = (gulong *) data;
2900 got_frame_extents = TRUE;
2902 /* try to get the real client window geometry */
2903 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2904 &root, &wx, &wy, &ww, &wh, &wb, &wd) &&
2905 XTranslateCoordinates (GDK_DISPLAY_XDISPLAY (display),
2906 xwindow, root, 0, 0, &wx, &wy, &child))
2914 /* _NET_FRAME_EXTENTS format is left, right, top, bottom */
2915 rect->x -= ldata[0];
2916 rect->y -= ldata[2];
2917 rect->width += ldata[0] + ldata[1];
2918 rect->height += ldata[2] + ldata[3];
2925 if (got_frame_extents)
2928 /* no frame extents property available, which means we either have a WM that
2929 is not EWMH compliant or is broken - try fallback and walk up the window
2930 tree to get our window's parent which hopefully is the window frame */
2932 /* use NETWM_VIRTUAL_ROOTS if available */
2933 root = GDK_WINDOW_XROOTWIN (window);
2935 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
2936 gdk_x11_get_xatom_by_name_for_display (display,
2937 "_NET_VIRTUAL_ROOTS"),
2938 0, G_MAXLONG, False, XA_WINDOW, &type_return,
2939 &format_return, &nitems_return, &bytes_after_return,
2943 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
2945 nvroots = nitems_return;
2946 vroots = (Window *)data;
2950 xparent = GDK_WINDOW_XID (window);
2956 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
2958 &children, &nchildren))
2964 /* check virtual roots */
2965 for (i = 0; i < nvroots; i++)
2967 if (xparent == vroots[i])
2974 while (xparent != root);
2976 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2977 &root, &wx, &wy, &ww, &wh, &wb, &wd))
2989 gdk_error_trap_pop_ignored ();
2993 _gdk_windowing_get_device_state (GdkDisplay *display,
2998 GdkModifierType *mask)
3000 GdkScreen *default_screen;
3002 if (display->closed)
3005 default_screen = gdk_display_get_default_screen (display);
3008 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3012 GDK_DEVICE_GET_CLASS (device)->query_state (device,
3013 gdk_screen_get_root_window (default_screen),
3018 *screen = gdk_window_get_screen (root);
3022 XSetWindowAttributes attributes;
3024 Window xwindow, w, root, child;
3025 int rootx, rooty, winx, winy;
3028 /* FIXME: untrusted clients not multidevice-safe */
3030 xdisplay = GDK_SCREEN_XDISPLAY (default_screen);
3031 xwindow = GDK_SCREEN_XROOTWIN (default_screen);
3033 w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0,
3034 CopyFromParent, InputOnly, CopyFromParent,
3036 XQueryPointer (xdisplay, w,
3037 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3038 XDestroyWindow (xdisplay, w);
3042 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
3043 *screen = gdk_window_get_screen (gdk_root);
3053 gdk_window_x11_get_device_state (GdkWindow *window,
3057 GdkModifierType *mask)
3059 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
3060 gboolean return_val;
3062 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
3066 if (!GDK_WINDOW_DESTROYED (window))
3068 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3072 GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
3076 return_val = (child != NULL);
3081 int originx, originy;
3085 unsigned int xmask = 0;
3087 _gdk_windowing_get_device_state (gdk_window_get_display (window), device,
3088 &screen, &rootx, &rooty, &xmask);
3089 gdk_window_get_origin (window, &originx, &originy);
3090 winx = rootx - originx;
3091 winy = rooty - originy;
3103 * gdk_display_warp_pointer:
3104 * @display: a #GdkDisplay
3105 * @screen: the screen of @display to warp the pointer to
3106 * @x: the x coordinate of the destination
3107 * @y: the y coordinate of the destination
3109 * Warps the pointer of @display to the point @x,@y on
3110 * the screen @screen, unless the pointer is confined
3111 * to a window by a grab, in which case it will be moved
3112 * as far as allowed by the grab. Warping the pointer
3113 * creates events as if the user had moved the mouse
3114 * instantaneously to the destination.
3116 * Note that the pointer should normally be under the
3117 * control of the user. This function was added to cover
3118 * some rare use cases like keyboard navigation support
3119 * for the color picker in the #GtkColorSelectionDialog.
3123 * Deprecated: 3.0: Use gdk_display_warp_device() instead.
3126 gdk_display_warp_pointer (GdkDisplay *display,
3133 g_return_if_fail (GDK_IS_DISPLAY (display));
3134 g_return_if_fail (GDK_IS_SCREEN (screen));
3136 device = display->core_pointer;
3137 GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
3141 * gdk_display_warp_device:
3142 * @display: a #GdkDisplay.
3143 * @device: a #GdkDevice.
3144 * @screen: the screen of @display to warp @device to.
3145 * @x: the X coordinate of the destination.
3146 * @y: the Y coordinate of the destination.
3148 * Warps @device in @display to the point @x,@y on
3149 * the screen @screen, unless the device is confined
3150 * to a window by a grab, in which case it will be moved
3151 * as far as allowed by the grab. Warping the pointer
3152 * creates events as if the user had moved the mouse
3153 * instantaneously to the destination.
3155 * Note that the pointer should normally be under the
3156 * control of the user. This function was added to cover
3157 * some rare use cases like keyboard navigation support
3158 * for the color picker in the #GtkColorSelectionDialog.
3163 gdk_display_warp_device (GdkDisplay *display,
3169 g_return_if_fail (GDK_IS_DISPLAY (display));
3170 g_return_if_fail (GDK_IS_DEVICE (device));
3171 g_return_if_fail (GDK_IS_SCREEN (screen));
3172 g_return_if_fail (display == gdk_device_get_display (device));
3174 GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
3178 _gdk_windowing_window_at_device_position (GdkDisplay *display,
3182 GdkModifierType *mask,
3183 gboolean get_toplevel)
3188 screen = gdk_display_get_default_screen (display);
3190 /* This function really only works if the mouse pointer is held still
3191 * during its operation. If it moves from one leaf window to another
3192 * than we'll end up with inaccurate values for win_x, win_y
3195 gdk_x11_display_grab (display);
3196 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3197 window = GDK_DEVICE_GET_CLASS (device)->window_at_position (device, win_x, win_y, mask, get_toplevel);
3200 gint i, screens, width, height;
3201 GList *toplevels, *list;
3202 Window pointer_window, root, xwindow, child;
3203 Window xwindow_last = 0;
3205 int rootx = -1, rooty = -1;
3209 /* FIXME: untrusted clients case not multidevice-safe */
3211 xwindow = GDK_SCREEN_XROOTWIN (screen);
3212 xdisplay = GDK_SCREEN_XDISPLAY (screen);
3214 pointer_window = None;
3215 screens = gdk_display_get_n_screens (display);
3216 for (i = 0; i < screens; ++i) {
3217 screen = gdk_display_get_screen (display, i);
3218 toplevels = gdk_screen_get_toplevel_windows (screen);
3219 for (list = toplevels; list != NULL; list = g_list_next (list)) {
3220 window = GDK_WINDOW (list->data);
3221 xwindow = GDK_WINDOW_XID (window);
3222 gdk_error_trap_push ();
3223 XQueryPointer (xdisplay, xwindow,
3224 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3225 if (gdk_error_trap_pop ())
3229 pointer_window = child;
3232 gdk_window_get_geometry (window, NULL, NULL, &width, &height, NULL);
3233 if (winx >= 0 && winy >= 0 && winx < width && winy < height)
3235 /* A childless toplevel, or below another window? */
3236 XSetWindowAttributes attributes;
3239 w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0,
3240 CopyFromParent, InputOnly, CopyFromParent,
3242 XMapWindow (xdisplay, w);
3243 XQueryPointer (xdisplay, xwindow,
3244 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3245 XDestroyWindow (xdisplay, w);
3248 pointer_window = xwindow;
3253 g_list_free (toplevels);
3254 if (pointer_window != None)
3257 xwindow = pointer_window;
3261 xwindow_last = xwindow;
3262 gdk_error_trap_push ();
3263 XQueryPointer (xdisplay, xwindow,
3264 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3265 if (gdk_error_trap_pop ())
3267 if (get_toplevel && xwindow_last != root &&
3268 (window = gdk_window_lookup_for_display (display, xwindow_last)) != NULL &&
3269 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
3273 window = gdk_window_lookup_for_display (display, xwindow_last);
3275 *win_x = window ? winx : -1;
3276 *win_y = window ? winy : -1;
3281 gdk_x11_display_ungrab (display);
3287 gdk_window_x11_get_events (GdkWindow *window)
3289 XWindowAttributes attrs;
3290 GdkEventMask event_mask;
3291 GdkEventMask filtered;
3293 if (GDK_WINDOW_DESTROYED (window))
3297 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3298 GDK_WINDOW_XID (window),
3300 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
3301 /* if property change was filtered out before, keep it filtered out */
3302 filtered = GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK;
3303 window->event_mask = event_mask & ((window->event_mask & filtered) | ~filtered);
3309 gdk_window_x11_set_events (GdkWindow *window,
3310 GdkEventMask event_mask)
3312 long xevent_mask = 0;
3314 if (!GDK_WINDOW_DESTROYED (window))
3316 GdkDisplayX11 *display_x11;
3318 if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window))
3319 xevent_mask = StructureNotifyMask | PropertyChangeMask;
3321 display_x11 = GDK_DISPLAY_X11 (gdk_window_get_display (window));
3322 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
3323 GDK_WINDOW_XID (window), event_mask,
3329 do_shape_combine_region (GdkWindow *window,
3330 const cairo_region_t *shape_region,
3335 if (GDK_WINDOW_DESTROYED (window))
3338 if (shape_region == NULL)
3340 /* Use NULL mask to unset the shape */
3341 if (shape == ShapeBounding
3342 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3343 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3345 if (shape == ShapeBounding)
3347 _gdk_x11_window_tmp_unset_parent_bg (window);
3348 _gdk_x11_window_tmp_unset_bg (window, TRUE);
3350 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3351 GDK_WINDOW_XID (window),
3356 if (shape == ShapeBounding)
3358 _gdk_x11_window_tmp_reset_parent_bg (window);
3359 _gdk_x11_window_tmp_reset_bg (window, TRUE);
3365 if (shape == ShapeBounding
3366 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3367 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3370 XRectangle *xrects = NULL;
3372 _gdk_region_get_xrectangles (shape_region,
3376 if (shape == ShapeBounding)
3378 _gdk_x11_window_tmp_unset_parent_bg (window);
3379 _gdk_x11_window_tmp_unset_bg (window, TRUE);
3381 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3382 GDK_WINDOW_XID (window),
3389 if (shape == ShapeBounding)
3391 _gdk_x11_window_tmp_reset_parent_bg (window);
3392 _gdk_x11_window_tmp_reset_bg (window, TRUE);
3400 gdk_window_x11_shape_combine_region (GdkWindow *window,
3401 const cairo_region_t *shape_region,
3405 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
3409 gdk_window_x11_input_shape_combine_region (GdkWindow *window,
3410 const cairo_region_t *shape_region,
3415 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
3421 * gdk_window_set_override_redirect:
3422 * @window: a toplevel #GdkWindow
3423 * @override_redirect: %TRUE if window should be override redirect
3425 * An override redirect window is not under the control of the window manager.
3426 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3427 * be entirely under the control of the application. The window manager
3428 * can't see the override redirect window at all.
3430 * Override redirect should only be used for short-lived temporary
3431 * windows, such as popup menus. #GtkMenu uses an override redirect
3432 * window in its implementation, for example.
3436 gdk_window_set_override_redirect (GdkWindow *window,
3437 gboolean override_redirect)
3439 XSetWindowAttributes attr;
3441 if (!GDK_WINDOW_DESTROYED (window) &&
3442 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3444 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
3446 attr.override_redirect = (override_redirect? True : False);
3447 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3448 GDK_WINDOW_XID (window),
3452 impl->override_redirect = attr.override_redirect;
3457 * gdk_window_set_accept_focus:
3458 * @window: a toplevel #GdkWindow
3459 * @accept_focus: %TRUE if the window should receive input focus
3461 * Setting @accept_focus to %FALSE hints the desktop environment that the
3462 * window doesn't want to receive input focus.
3464 * On X, it is the responsibility of the window manager to interpret this
3465 * hint. ICCCM-compliant window manager usually respect it.
3470 gdk_window_set_accept_focus (GdkWindow *window,
3471 gboolean accept_focus)
3473 accept_focus = accept_focus != FALSE;
3475 if (window->accept_focus != accept_focus)
3477 window->accept_focus = accept_focus;
3479 if (!GDK_WINDOW_DESTROYED (window) &&
3480 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3481 update_wm_hints (window, FALSE);
3486 * gdk_window_set_focus_on_map:
3487 * @window: a toplevel #GdkWindow
3488 * @focus_on_map: %TRUE if the window should receive input focus when mapped
3490 * Setting @focus_on_map to %FALSE hints the desktop environment that the
3491 * window doesn't want to receive input focus when it is mapped.
3492 * focus_on_map should be turned off for windows that aren't triggered
3493 * interactively (such as popups from network activity).
3495 * On X, it is the responsibility of the window manager to interpret
3496 * this hint. Window managers following the freedesktop.org window
3497 * manager extension specification should respect it.
3502 gdk_window_set_focus_on_map (GdkWindow *window,
3503 gboolean focus_on_map)
3505 focus_on_map = focus_on_map != FALSE;
3507 if (window->focus_on_map != focus_on_map)
3509 window->focus_on_map = focus_on_map;
3511 if ((!GDK_WINDOW_DESTROYED (window)) &&
3512 (!window->focus_on_map) &&
3513 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3514 gdk_x11_window_set_user_time (window, 0);
3519 * gdk_x11_window_set_user_time:
3520 * @window: A toplevel #GdkWindow
3521 * @timestamp: An XServer timestamp to which the property should be set
3523 * The application can use this call to update the _NET_WM_USER_TIME
3524 * property on a toplevel window. This property stores an Xserver
3525 * time which represents the time of the last user input event
3526 * received for this window. This property may be used by the window
3527 * manager to alter the focus, stacking, and/or placement behavior of
3528 * windows when they are mapped depending on whether the new window
3529 * was created by a user action or is a "pop-up" window activated by a
3530 * timer or some other event.
3532 * Note that this property is automatically updated by GDK, so this
3533 * function should only be used by applications which handle input
3534 * events bypassing GDK.
3539 gdk_x11_window_set_user_time (GdkWindow *window,
3542 GdkDisplay *display;
3543 GdkDisplayX11 *display_x11;
3544 GdkToplevelX11 *toplevel;
3545 glong timestamp_long = (glong)timestamp;
3548 if (GDK_WINDOW_DESTROYED (window) ||
3549 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3552 display = gdk_window_get_display (window);
3553 display_x11 = GDK_DISPLAY_X11 (display);
3554 toplevel = _gdk_x11_window_get_toplevel (window);
3558 g_warning ("gdk_window_set_user_time called on non-toplevel\n");
3562 if (toplevel->focus_window != None &&
3563 gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
3564 gdk_atom_intern_static_string ("_NET_WM_USER_TIME_WINDOW")))
3565 xid = toplevel->focus_window;
3567 xid = GDK_WINDOW_XID (window);
3569 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xid,
3570 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3571 XA_CARDINAL, 32, PropModeReplace,
3572 (guchar *)×tamp_long, 1);
3574 if (timestamp_long != GDK_CURRENT_TIME &&
3575 (display_x11->user_time == GDK_CURRENT_TIME ||
3576 XSERVER_TIME_IS_LATER (timestamp_long, display_x11->user_time)))
3577 display_x11->user_time = timestamp_long;
3580 toplevel->user_time = timestamp_long;
3583 #define GDK_SELECTION_MAX_SIZE(display) \
3585 XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
3586 ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
3587 : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
3590 gdk_window_update_icon (GdkWindow *window,
3593 GdkToplevelX11 *toplevel;
3594 GdkPixbuf *best_icon;
3598 toplevel = _gdk_x11_window_get_toplevel (window);
3600 if (toplevel->icon_pixmap != NULL)
3602 cairo_surface_destroy (toplevel->icon_pixmap);
3603 toplevel->icon_pixmap = NULL;
3606 if (toplevel->icon_mask != NULL)
3608 cairo_surface_destroy (toplevel->icon_mask);
3609 toplevel->icon_mask = NULL;
3612 #define IDEAL_SIZE 48
3614 best_size = G_MAXINT;
3616 for (tmp_list = icon_list; tmp_list; tmp_list = tmp_list->next)
3618 GdkPixbuf *pixbuf = tmp_list->data;
3621 /* average width and height - if someone passes in a rectangular
3622 * icon they deserve what they get.
3624 this = gdk_pixbuf_get_width (pixbuf) + gdk_pixbuf_get_height (pixbuf);
3627 if (best_icon == NULL)
3634 /* icon is better if it's 32 pixels or larger, and closer to
3635 * the ideal size than the current best.
3638 (ABS (best_size - IDEAL_SIZE) <
3639 ABS (this - IDEAL_SIZE)))
3649 int width = gdk_pixbuf_get_width (best_icon);
3650 int height = gdk_pixbuf_get_height (best_icon);
3653 toplevel->icon_pixmap = gdk_x11_window_create_pixmap_surface (window,
3657 cr = cairo_create (toplevel->icon_pixmap);
3658 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3659 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3660 if (gdk_pixbuf_get_has_alpha (best_icon))
3662 /* Saturate the image, so it has bilevel alpha */
3663 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
3665 cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);
3667 cairo_pop_group_to_source (cr);
3672 if (gdk_pixbuf_get_has_alpha (best_icon))
3674 toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window,
3678 cr = cairo_create (toplevel->icon_mask);
3679 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3680 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3686 update_wm_hints (window, FALSE);
3690 * gdk_window_set_icon_list:
3691 * @window: The #GdkWindow toplevel window to set the icon of.
3692 * @pixbufs: (transfer none) (element-type GdkPixbuf):
3693 * A list of pixbufs, of different sizes.
3695 * Sets a list of icons for the window. One of these will be used
3696 * to represent the window when it has been iconified. The icon is
3697 * usually shown in an icon box or some sort of task bar. Which icon
3698 * size is shown depends on the window manager. The window manager
3699 * can scale the icon but setting several size icons can give better
3700 * image quality since the window manager may only need to scale the
3701 * icon by a small amount or not at all.
3705 gdk_window_set_icon_list (GdkWindow *window,
3714 gint width, height, stride;
3717 GdkDisplay *display;
3720 if (GDK_WINDOW_DESTROYED (window) ||
3721 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3724 display = gdk_window_get_display (window);
3732 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3734 width = gdk_pixbuf_get_width (pixbuf);
3735 height = gdk_pixbuf_get_height (pixbuf);
3737 /* silently ignore overlarge icons */
3738 if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
3740 g_warning ("gdk_window_set_icon_list: icons too large");
3745 size += 2 + width * height;
3747 l = g_list_next (l);
3750 data = g_malloc (size * sizeof (gulong));
3758 width = gdk_pixbuf_get_width (pixbuf);
3759 height = gdk_pixbuf_get_height (pixbuf);
3760 stride = gdk_pixbuf_get_rowstride (pixbuf);
3761 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3766 pixels = gdk_pixbuf_get_pixels (pixbuf);
3768 for (y = 0; y < height; y++)
3770 for (x = 0; x < width; x++)
3774 r = pixels[y*stride + x*n_channels + 0];
3775 g = pixels[y*stride + x*n_channels + 1];
3776 b = pixels[y*stride + x*n_channels + 2];
3777 if (n_channels >= 4)
3778 a = pixels[y*stride + x*n_channels + 3];
3782 *p++ = a << 24 | r << 16 | g << 8 | b ;
3786 l = g_list_next (l);
3792 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3793 GDK_WINDOW_XID (window),
3794 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3797 (guchar*) data, size);
3801 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3802 GDK_WINDOW_XID (window),
3803 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3808 gdk_window_update_icon (window, pixbufs);
3812 gdk_window_icon_name_set (GdkWindow *window)
3814 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3815 g_quark_from_static_string ("gdk-icon-name-set")));
3819 * gdk_window_set_icon_name:
3820 * @window: a toplevel #GdkWindow
3821 * @name: name of window while iconified (minimized)
3823 * Windows may have a name used while minimized, distinct from the
3824 * name they display in their titlebar. Most of the time this is a bad
3825 * idea from a user interface standpoint. But you can set such a name
3826 * with this function, if you like.
3828 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
3829 * will not update the icon title.
3831 * Using %NULL for @name unsets the icon title; further calls to
3832 * gdk_window_set_title() will again update the icon title as well.
3835 gdk_window_set_icon_name (GdkWindow *window,
3838 GdkDisplay *display;
3840 if (GDK_WINDOW_DESTROYED (window) ||
3841 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3844 display = gdk_window_get_display (window);
3846 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3847 GUINT_TO_POINTER (name != NULL));
3851 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3852 GDK_WINDOW_XID (window),
3853 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3854 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3855 PropModeReplace, (guchar *)name, strlen (name));
3857 set_text_property (display, GDK_WINDOW_XID (window),
3858 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3863 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3864 GDK_WINDOW_XID (window),
3865 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"));
3866 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3867 GDK_WINDOW_XID (window),
3868 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"));
3873 * gdk_window_iconify:
3874 * @window: a toplevel #GdkWindow
3876 * Asks to iconify (minimize) @window. The window manager may choose
3877 * to ignore the request, but normally will honor it. Using
3878 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3880 * This function only makes sense when @window is a toplevel window.
3884 gdk_window_iconify (GdkWindow *window)
3886 if (GDK_WINDOW_DESTROYED (window) ||
3887 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3890 if (GDK_WINDOW_IS_MAPPED (window))
3892 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3893 GDK_WINDOW_XID (window),
3894 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3898 /* Flip our client side flag, the real work happens on map. */
3899 gdk_synthesize_window_state (window,
3901 GDK_WINDOW_STATE_ICONIFIED);
3906 * gdk_window_deiconify:
3907 * @window: a toplevel #GdkWindow
3909 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3910 * choose to ignore the request to deiconify. When using GTK+,
3911 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3912 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3913 * unminimizes it, and puts it on the current desktop.
3917 gdk_window_deiconify (GdkWindow *window)
3919 if (GDK_WINDOW_DESTROYED (window) ||
3920 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3923 if (GDK_WINDOW_IS_MAPPED (window))
3925 gdk_window_show (window);
3929 /* Flip our client side flag, the real work happens on map. */
3930 gdk_synthesize_window_state (window,
3931 GDK_WINDOW_STATE_ICONIFIED,
3938 * @window: a toplevel #GdkWindow
3940 * "Pins" a window such that it's on all workspaces and does not scroll
3941 * with viewports, for window managers that have scrollable viewports.
3942 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3944 * On the X11 platform, this function depends on window manager
3945 * support, so may have no effect with many window managers. However,
3946 * GDK will do the best it can to convince the window manager to stick
3947 * the window. For window managers that don't support this operation,
3948 * there's nothing you can do to force it to happen.
3952 gdk_window_stick (GdkWindow *window)
3954 if (GDK_WINDOW_DESTROYED (window) ||
3955 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3958 if (GDK_WINDOW_IS_MAPPED (window))
3960 /* "stick" means stick to all desktops _and_ do not scroll with the
3961 * viewport. i.e. glue to the monitor glass in all cases.
3964 XClientMessageEvent xclient;
3966 /* Request stick during viewport scroll */
3967 gdk_wmspec_change_state (TRUE, window,
3968 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
3971 /* Request desktop 0xFFFFFFFF */
3972 memset (&xclient, 0, sizeof (xclient));
3973 xclient.type = ClientMessage;
3974 xclient.window = GDK_WINDOW_XID (window);
3975 xclient.display = GDK_WINDOW_XDISPLAY (window);
3976 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3978 xclient.format = 32;
3980 xclient.data.l[0] = 0xFFFFFFFF;
3981 xclient.data.l[1] = 0;
3982 xclient.data.l[2] = 0;
3983 xclient.data.l[3] = 0;
3984 xclient.data.l[4] = 0;
3986 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3987 SubstructureRedirectMask | SubstructureNotifyMask,
3988 (XEvent *)&xclient);
3992 /* Flip our client side flag, the real work happens on map. */
3993 gdk_synthesize_window_state (window,
3995 GDK_WINDOW_STATE_STICKY);
4000 * gdk_window_unstick:
4001 * @window: a toplevel #GdkWindow
4003 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
4004 * and gtk_window_unstick().
4008 gdk_window_unstick (GdkWindow *window)
4010 if (GDK_WINDOW_DESTROYED (window) ||
4011 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4014 if (GDK_WINDOW_IS_MAPPED (window))
4016 /* Request unstick from viewport */
4017 gdk_wmspec_change_state (FALSE, window,
4018 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4021 move_to_current_desktop (window);
4025 /* Flip our client side flag, the real work happens on map. */
4026 gdk_synthesize_window_state (window,
4027 GDK_WINDOW_STATE_STICKY,
4034 * gdk_window_maximize:
4035 * @window: a toplevel #GdkWindow
4037 * Maximizes the window. If the window was already maximized, then
4038 * this function does nothing.
4040 * On X11, asks the window manager to maximize @window, if the window
4041 * manager supports this operation. Not all window managers support
4042 * this, and some deliberately ignore it or don't have a concept of
4043 * "maximized"; so you can't rely on the maximization actually
4044 * happening. But it will happen with most standard window managers,
4045 * and GDK makes a best effort to get it to happen.
4047 * On Windows, reliably maximizes the window.
4051 gdk_window_maximize (GdkWindow *window)
4053 if (GDK_WINDOW_DESTROYED (window) ||
4054 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4057 if (GDK_WINDOW_IS_MAPPED (window))
4058 gdk_wmspec_change_state (TRUE, window,
4059 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4060 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4062 gdk_synthesize_window_state (window,
4064 GDK_WINDOW_STATE_MAXIMIZED);
4068 * gdk_window_unmaximize:
4069 * @window: a toplevel #GdkWindow
4071 * Unmaximizes the window. If the window wasn't maximized, then this
4072 * function does nothing.
4074 * On X11, asks the window manager to unmaximize @window, if the
4075 * window manager supports this operation. Not all window managers
4076 * support this, and some deliberately ignore it or don't have a
4077 * concept of "maximized"; so you can't rely on the unmaximization
4078 * actually happening. But it will happen with most standard window
4079 * managers, and GDK makes a best effort to get it to happen.
4081 * On Windows, reliably unmaximizes the window.
4085 gdk_window_unmaximize (GdkWindow *window)
4087 if (GDK_WINDOW_DESTROYED (window) ||
4088 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4091 if (GDK_WINDOW_IS_MAPPED (window))
4092 gdk_wmspec_change_state (FALSE, window,
4093 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4094 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4096 gdk_synthesize_window_state (window,
4097 GDK_WINDOW_STATE_MAXIMIZED,
4102 * gdk_window_fullscreen:
4103 * @window: a toplevel #GdkWindow
4105 * Moves the window into fullscreen mode. This means the
4106 * window covers the entire screen and is above any panels
4109 * If the window was already fullscreen, then this function does nothing.
4111 * On X11, asks the window manager to put @window in a fullscreen
4112 * state, if the window manager supports this operation. Not all
4113 * window managers support this, and some deliberately ignore it or
4114 * don't have a concept of "fullscreen"; so you can't rely on the
4115 * fullscreenification actually happening. But it will happen with
4116 * most standard window managers, and GDK makes a best effort to get
4122 gdk_window_fullscreen (GdkWindow *window)
4124 if (GDK_WINDOW_DESTROYED (window) ||
4125 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4128 if (GDK_WINDOW_IS_MAPPED (window))
4129 gdk_wmspec_change_state (TRUE, window,
4130 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4134 gdk_synthesize_window_state (window,
4136 GDK_WINDOW_STATE_FULLSCREEN);
4140 * gdk_window_unfullscreen:
4141 * @window: a toplevel #GdkWindow
4143 * Moves the window out of fullscreen mode. If the window was not
4144 * fullscreen, does nothing.
4146 * On X11, asks the window manager to move @window out of the fullscreen
4147 * state, if the window manager supports this operation. Not all
4148 * window managers support this, and some deliberately ignore it or
4149 * don't have a concept of "fullscreen"; so you can't rely on the
4150 * unfullscreenification actually happening. But it will happen with
4151 * most standard window managers, and GDK makes a best effort to get
4157 gdk_window_unfullscreen (GdkWindow *window)
4159 if (GDK_WINDOW_DESTROYED (window) ||
4160 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4163 if (GDK_WINDOW_IS_MAPPED (window))
4164 gdk_wmspec_change_state (FALSE, window,
4165 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4169 gdk_synthesize_window_state (window,
4170 GDK_WINDOW_STATE_FULLSCREEN,
4175 * gdk_window_set_keep_above:
4176 * @window: a toplevel #GdkWindow
4177 * @setting: whether to keep @window above other windows
4179 * Set if @window must be kept above other windows. If the
4180 * window was already above, then this function does nothing.
4182 * On X11, asks the window manager to keep @window above, if the window
4183 * manager supports this operation. Not all window managers support
4184 * this, and some deliberately ignore it or don't have a concept of
4185 * "keep above"; so you can't rely on the window being kept above.
4186 * But it will happen with most standard window managers,
4187 * and GDK makes a best effort to get it to happen.
4192 gdk_window_set_keep_above (GdkWindow *window,
4195 g_return_if_fail (GDK_IS_WINDOW (window));
4197 if (GDK_WINDOW_DESTROYED (window) ||
4198 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4201 if (GDK_WINDOW_IS_MAPPED (window))
4204 gdk_wmspec_change_state (FALSE, window,
4205 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4207 gdk_wmspec_change_state (setting, window,
4208 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4212 gdk_synthesize_window_state (window,
4213 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
4214 setting ? GDK_WINDOW_STATE_ABOVE : 0);
4218 * gdk_window_set_keep_below:
4219 * @window: a toplevel #GdkWindow
4220 * @setting: whether to keep @window below other windows
4222 * Set if @window must be kept below other windows. If the
4223 * window was already below, then this function does nothing.
4225 * On X11, asks the window manager to keep @window below, if the window
4226 * manager supports this operation. Not all window managers support
4227 * this, and some deliberately ignore it or don't have a concept of
4228 * "keep below"; so you can't rely on the window being kept below.
4229 * But it will happen with most standard window managers,
4230 * and GDK makes a best effort to get it to happen.
4235 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
4237 g_return_if_fail (GDK_IS_WINDOW (window));
4239 if (GDK_WINDOW_DESTROYED (window) ||
4240 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4243 if (GDK_WINDOW_IS_MAPPED (window))
4246 gdk_wmspec_change_state (FALSE, window,
4247 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4249 gdk_wmspec_change_state (setting, window,
4250 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4254 gdk_synthesize_window_state (window,
4255 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
4256 setting ? GDK_WINDOW_STATE_BELOW : 0);
4260 * gdk_window_get_group:
4261 * @window: a toplevel #GdkWindow
4263 * Returns the group leader window for @window. See gdk_window_set_group().
4265 * Return value: (transfer none): the group leader window for @window
4270 gdk_window_get_group (GdkWindow *window)
4272 GdkToplevelX11 *toplevel;
4274 if (GDK_WINDOW_DESTROYED (window) ||
4275 !WINDOW_IS_TOPLEVEL (window))
4278 toplevel = _gdk_x11_window_get_toplevel (window);
4280 return toplevel->group_leader;
4284 * gdk_window_set_group:
4285 * @window: a toplevel #GdkWindow
4286 * @leader: group leader window, or %NULL to restore the default group leader window
4288 * Sets the group leader window for @window. By default,
4289 * GDK sets the group leader for all toplevel windows
4290 * to a global window implicitly created by GDK. With this function
4291 * you can override this default.
4293 * The group leader window allows the window manager to distinguish
4294 * all windows that belong to a single application. It may for example
4295 * allow users to minimize/unminimize all windows belonging to an
4296 * application at once. You should only set a non-default group window
4297 * if your application pretends to be multiple applications.
4300 gdk_window_set_group (GdkWindow *window,
4303 GdkToplevelX11 *toplevel;
4305 g_return_if_fail (GDK_IS_WINDOW (window));
4306 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4307 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
4309 if (GDK_WINDOW_DESTROYED (window) ||
4310 (leader != NULL && GDK_WINDOW_DESTROYED (leader)) ||
4311 !WINDOW_IS_TOPLEVEL (window))
4314 toplevel = _gdk_x11_window_get_toplevel (window);
4317 leader = gdk_display_get_default_group (gdk_window_get_display (window));
4319 if (toplevel->group_leader != leader)
4321 if (toplevel->group_leader)
4322 g_object_unref (toplevel->group_leader);
4323 toplevel->group_leader = g_object_ref (leader);
4324 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
4327 update_wm_hints (window, FALSE);
4330 static MotifWmHints *
4331 gdk_window_get_mwm_hints (GdkWindow *window)
4333 GdkDisplay *display;
4334 Atom hints_atom = None;
4341 if (GDK_WINDOW_DESTROYED (window))
4344 display = gdk_window_get_display (window);
4346 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4348 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4349 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4350 False, AnyPropertyType, &type, &format, &nitems,
4351 &bytes_after, &data);
4356 return (MotifWmHints *)data;
4360 gdk_window_set_mwm_hints (GdkWindow *window,
4361 MotifWmHints *new_hints)
4363 GdkDisplay *display;
4364 Atom hints_atom = None;
4366 MotifWmHints *hints;
4372 if (GDK_WINDOW_DESTROYED (window))
4375 display = gdk_window_get_display (window);
4377 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4379 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4380 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4381 False, AnyPropertyType, &type, &format, &nitems,
4382 &bytes_after, &data);
4388 hints = (MotifWmHints *)data;
4390 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4392 hints->flags |= MWM_HINTS_FUNCTIONS;
4393 hints->functions = new_hints->functions;
4395 if (new_hints->flags & MWM_HINTS_DECORATIONS)
4397 hints->flags |= MWM_HINTS_DECORATIONS;
4398 hints->decorations = new_hints->decorations;
4402 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4403 hints_atom, hints_atom, 32, PropModeReplace,
4404 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
4406 if (hints != new_hints)
4411 * gdk_window_set_decorations:
4412 * @window: a toplevel #GdkWindow
4413 * @decorations: decoration hint mask
4415 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
4416 * This function sets the traditional Motif window manager hints that tell the
4417 * window manager which decorations you would like your window to have.
4418 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
4419 * using the GDK function directly.
4421 * The @decorations argument is the logical OR of the fields in
4422 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
4423 * mask, the other bits indicate which decorations should be turned off.
4424 * If #GDK_DECOR_ALL is not included, then the other bits indicate
4425 * which decorations should be turned on.
4427 * Most window managers honor a decorations hint of 0 to disable all decorations,
4428 * but very few honor all possible combinations of bits.
4432 gdk_window_set_decorations (GdkWindow *window,
4433 GdkWMDecoration decorations)
4437 if (GDK_WINDOW_DESTROYED (window) ||
4438 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4441 /* initialize to zero to avoid writing uninitialized data to socket */
4442 memset(&hints, 0, sizeof(hints));
4443 hints.flags = MWM_HINTS_DECORATIONS;
4444 hints.decorations = decorations;
4446 gdk_window_set_mwm_hints (window, &hints);
4450 * gdk_window_get_decorations:
4451 * @window: The toplevel #GdkWindow to get the decorations from
4452 * @decorations: The window decorations will be written here
4454 * Returns the decorations set on the GdkWindow with
4455 * gdk_window_set_decorations().
4457 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
4460 gdk_window_get_decorations(GdkWindow *window,
4461 GdkWMDecoration *decorations)
4463 MotifWmHints *hints;
4464 gboolean result = FALSE;
4466 if (GDK_WINDOW_DESTROYED (window) ||
4467 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4470 hints = gdk_window_get_mwm_hints (window);
4474 if (hints->flags & MWM_HINTS_DECORATIONS)
4477 *decorations = hints->decorations;
4488 * gdk_window_set_functions:
4489 * @window: a toplevel #GdkWindow
4490 * @functions: bitmask of operations to allow on @window
4492 * Sets hints about the window management functions to make available
4493 * via buttons on the window frame.
4495 * On the X backend, this function sets the traditional Motif window
4496 * manager hint for this purpose. However, few window managers do
4497 * anything reliable or interesting with this hint. Many ignore it
4500 * The @functions argument is the logical OR of values from the
4501 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
4502 * then the other bits indicate which functions to disable; if
4503 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
4508 gdk_window_set_functions (GdkWindow *window,
4509 GdkWMFunction functions)
4513 g_return_if_fail (GDK_IS_WINDOW (window));
4515 if (GDK_WINDOW_DESTROYED (window) ||
4516 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4519 /* initialize to zero to avoid writing uninitialized data to socket */
4520 memset(&hints, 0, sizeof(hints));
4521 hints.flags = MWM_HINTS_FUNCTIONS;
4522 hints.functions = functions;
4524 gdk_window_set_mwm_hints (window, &hints);
4528 _xwindow_get_shape (Display *xdisplay,
4532 cairo_region_t *shape;
4540 xrl = XShapeGetRectangles (xdisplay,
4542 shape_type, &rn, &ord);
4544 if (xrl == NULL || rn == 0)
4545 return cairo_region_create (); /* Empty */
4547 if (ord != YXBanded)
4549 /* This really shouldn't happen with any xserver, as they
4550 generally convert regions to YXBanded internally */
4551 g_warning ("non YXBanded shape masks not supported");
4556 rl = g_new (GdkRectangle, rn);
4557 for (i = 0; i < rn; i++)
4561 rl[i].width = xrl[i].width;
4562 rl[i].height = xrl[i].height;
4566 shape = cairo_region_create_rectangles (rl, rn);
4573 static cairo_region_t *
4574 gdk_x11_window_get_shape (GdkWindow *window)
4576 if (!GDK_WINDOW_DESTROYED (window) &&
4577 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
4578 return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
4579 GDK_WINDOW_XID (window), ShapeBounding);
4584 static cairo_region_t *
4585 gdk_x11_window_get_input_shape (GdkWindow *window)
4587 #if defined(ShapeInput)
4588 if (!GDK_WINDOW_DESTROYED (window) &&
4589 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
4590 return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
4591 GDK_WINDOW_XID (window),
4599 gdk_window_set_static_bit_gravity (GdkWindow *window,
4602 XSetWindowAttributes xattributes;
4603 guint xattributes_mask = 0;
4605 g_return_if_fail (GDK_IS_WINDOW (window));
4607 if (window->input_only)
4610 xattributes.bit_gravity = StaticGravity;
4611 xattributes_mask |= CWBitGravity;
4612 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4613 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4614 GDK_WINDOW_XID (window),
4615 CWBitGravity, &xattributes);
4619 gdk_window_set_static_win_gravity (GdkWindow *window,
4622 XSetWindowAttributes xattributes;
4624 g_return_if_fail (GDK_IS_WINDOW (window));
4626 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4628 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4629 GDK_WINDOW_XID (window),
4630 CWWinGravity, &xattributes);
4634 gdk_window_x11_set_static_gravities (GdkWindow *window,
4635 gboolean use_static)
4639 if (!use_static == !window->guffaw_gravity)
4642 window->guffaw_gravity = use_static;
4644 if (!GDK_WINDOW_DESTROYED (window))
4646 gdk_window_set_static_bit_gravity (window, use_static);
4648 tmp_list = window->children;
4651 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4653 tmp_list = tmp_list->next;
4661 wmspec_moveresize (GdkWindow *window,
4667 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4669 XClientMessageEvent xclient;
4671 /* Release passive grab */
4672 gdk_display_pointer_ungrab (display, timestamp);
4674 memset (&xclient, 0, sizeof (xclient));
4675 xclient.type = ClientMessage;
4676 xclient.window = GDK_WINDOW_XID (window);
4677 xclient.message_type =
4678 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4679 xclient.format = 32;
4680 xclient.data.l[0] = root_x;
4681 xclient.data.l[1] = root_y;
4682 xclient.data.l[2] = direction;
4683 xclient.data.l[3] = 0;
4684 xclient.data.l[4] = 0;
4686 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4687 SubstructureRedirectMask | SubstructureNotifyMask,
4688 (XEvent *)&xclient);
4691 typedef struct _MoveResizeData MoveResizeData;
4693 struct _MoveResizeData
4695 GdkDisplay *display;
4697 GdkWindow *moveresize_window;
4698 GdkWindow *moveresize_emulation_window;
4700 GdkWindowEdge resize_edge;
4701 gint moveresize_button;
4704 gint moveresize_orig_x;
4705 gint moveresize_orig_y;
4706 gint moveresize_orig_width;
4707 gint moveresize_orig_height;
4708 GdkWindowHints moveresize_geom_mask;
4709 GdkGeometry moveresize_geometry;
4710 Time moveresize_process_time;
4711 XEvent *moveresize_pending_event;
4714 /* From the WM spec */
4715 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4716 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4717 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4718 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4719 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4720 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4721 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4722 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4723 #define _NET_WM_MOVERESIZE_MOVE 8
4726 wmspec_resize_drag (GdkWindow *window,
4735 /* Let the compiler turn a switch into a table, instead
4736 * of doing the table manually, this way is easier to verify.
4740 case GDK_WINDOW_EDGE_NORTH_WEST:
4741 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4744 case GDK_WINDOW_EDGE_NORTH:
4745 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4748 case GDK_WINDOW_EDGE_NORTH_EAST:
4749 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4752 case GDK_WINDOW_EDGE_WEST:
4753 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4756 case GDK_WINDOW_EDGE_EAST:
4757 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4760 case GDK_WINDOW_EDGE_SOUTH_WEST:
4761 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4764 case GDK_WINDOW_EDGE_SOUTH:
4765 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4768 case GDK_WINDOW_EDGE_SOUTH_EAST:
4769 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4773 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4778 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4781 static MoveResizeData *
4782 get_move_resize_data (GdkDisplay *display,
4785 MoveResizeData *mv_resize;
4786 static GQuark move_resize_quark = 0;
4788 if (!move_resize_quark)
4789 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4791 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4793 if (!mv_resize && create)
4795 mv_resize = g_new0 (MoveResizeData, 1);
4796 mv_resize->display = display;
4798 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4805 update_pos (MoveResizeData *mv_resize,
4811 dx = new_root_x - mv_resize->moveresize_x;
4812 dy = new_root_y - mv_resize->moveresize_y;
4814 if (mv_resize->is_resize)
4818 x = mv_resize->moveresize_orig_x;
4819 y = mv_resize->moveresize_orig_y;
4821 w = mv_resize->moveresize_orig_width;
4822 h = mv_resize->moveresize_orig_height;
4824 switch (mv_resize->resize_edge)
4826 case GDK_WINDOW_EDGE_NORTH_WEST:
4832 case GDK_WINDOW_EDGE_NORTH:
4836 case GDK_WINDOW_EDGE_NORTH_EAST:
4841 case GDK_WINDOW_EDGE_SOUTH_WEST:
4846 case GDK_WINDOW_EDGE_SOUTH_EAST:
4850 case GDK_WINDOW_EDGE_SOUTH:
4853 case GDK_WINDOW_EDGE_EAST:
4856 case GDK_WINDOW_EDGE_WEST:
4867 if (mv_resize->moveresize_geom_mask)
4869 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4870 mv_resize->moveresize_geom_mask,
4874 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4880 x = mv_resize->moveresize_orig_x + dx;
4881 y = mv_resize->moveresize_orig_y + dy;
4883 gdk_window_move (mv_resize->moveresize_window, x, y);
4888 finish_drag (MoveResizeData *mv_resize)
4890 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4891 mv_resize->moveresize_emulation_window = NULL;
4892 g_object_unref (mv_resize->moveresize_window);
4893 mv_resize->moveresize_window = NULL;
4895 if (mv_resize->moveresize_pending_event)
4897 g_free (mv_resize->moveresize_pending_event);
4898 mv_resize->moveresize_pending_event = NULL;
4903 lookahead_motion_predicate (Display *xdisplay,
4907 gboolean *seen_release = (gboolean *)arg;
4908 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4909 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4914 switch (event->xany.type)
4917 *seen_release = TRUE;
4920 mv_resize->moveresize_process_time = event->xmotion.time;
4930 moveresize_lookahead (MoveResizeData *mv_resize,
4934 gboolean seen_release = FALSE;
4936 if (mv_resize->moveresize_process_time)
4938 if (event->xmotion.time == mv_resize->moveresize_process_time)
4940 mv_resize->moveresize_process_time = 0;
4947 XCheckIfEvent (event->xany.display, &tmp_event,
4948 lookahead_motion_predicate, (XPointer) & seen_release);
4950 return mv_resize->moveresize_process_time == 0;
4954 _gdk_moveresize_handle_event (XEvent *event)
4956 guint button_mask = 0;
4957 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
4958 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4960 if (!mv_resize || !mv_resize->moveresize_window)
4963 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4965 switch (event->xany.type)
4968 if (mv_resize->moveresize_window->resize_count > 0)
4970 if (mv_resize->moveresize_pending_event)
4971 *mv_resize->moveresize_pending_event = *event;
4973 mv_resize->moveresize_pending_event =
4974 g_memdup (event, sizeof (XEvent));
4978 if (!moveresize_lookahead (mv_resize, event))
4981 update_pos (mv_resize,
4982 event->xmotion.x_root,
4983 event->xmotion.y_root);
4985 /* This should never be triggered in normal cases, but in the
4986 * case where the drag started without an implicit grab being
4987 * in effect, we could miss the release if it occurs before
4988 * we grab the pointer; this ensures that we will never
4989 * get a permanently stuck grab.
4991 if ((event->xmotion.state & button_mask) == 0)
4992 finish_drag (mv_resize);
4996 update_pos (mv_resize,
4997 event->xbutton.x_root,
4998 event->xbutton.y_root);
5000 if (event->xbutton.button == mv_resize->moveresize_button)
5001 finish_drag (mv_resize);
5008 _gdk_moveresize_configure_done (GdkDisplay *display,
5012 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5014 if (!mv_resize || window != mv_resize->moveresize_window)
5017 if (mv_resize->moveresize_pending_event)
5019 tmp_event = mv_resize->moveresize_pending_event;
5020 mv_resize->moveresize_pending_event = NULL;
5021 _gdk_moveresize_handle_event (tmp_event);
5029 create_moveresize_window (MoveResizeData *mv_resize,
5032 GdkWindowAttr attributes;
5033 gint attributes_mask;
5034 GdkGrabStatus status;
5036 g_assert (mv_resize->moveresize_emulation_window == NULL);
5038 attributes.x = -100;
5039 attributes.y = -100;
5040 attributes.width = 10;
5041 attributes.height = 10;
5042 attributes.window_type = GDK_WINDOW_TEMP;
5043 attributes.wclass = GDK_INPUT_ONLY;
5044 attributes.override_redirect = TRUE;
5045 attributes.event_mask = 0;
5047 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
5049 mv_resize->moveresize_emulation_window =
5050 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
5054 gdk_window_show (mv_resize->moveresize_emulation_window);
5056 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
5058 GDK_BUTTON_RELEASE_MASK |
5059 GDK_POINTER_MOTION_MASK,
5064 if (status != GDK_GRAB_SUCCESS)
5066 /* If this fails, some other client has grabbed the window
5069 finish_drag (mv_resize);
5072 mv_resize->moveresize_process_time = 0;
5076 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
5077 so that calling XMoveWindow with these coordinates will not move the
5079 Note that this depends on the WM to implement ICCCM-compliant reference
5083 calculate_unmoving_origin (MoveResizeData *mv_resize)
5088 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
5089 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
5091 gdk_window_get_origin (mv_resize->moveresize_window,
5092 &mv_resize->moveresize_orig_x,
5093 &mv_resize->moveresize_orig_y);
5097 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
5098 gdk_window_get_geometry (mv_resize->moveresize_window,
5099 NULL, NULL, &width, &height, NULL);
5101 switch (mv_resize->moveresize_geometry.win_gravity)
5103 case GDK_GRAVITY_NORTH_WEST:
5104 mv_resize->moveresize_orig_x = rect.x;
5105 mv_resize->moveresize_orig_y = rect.y;
5107 case GDK_GRAVITY_NORTH:
5108 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5109 mv_resize->moveresize_orig_y = rect.y;
5111 case GDK_GRAVITY_NORTH_EAST:
5112 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5113 mv_resize->moveresize_orig_y = rect.y;
5115 case GDK_GRAVITY_WEST:
5116 mv_resize->moveresize_orig_x = rect.x;
5117 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5119 case GDK_GRAVITY_CENTER:
5120 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5121 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5123 case GDK_GRAVITY_EAST:
5124 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5125 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5127 case GDK_GRAVITY_SOUTH_WEST:
5128 mv_resize->moveresize_orig_x = rect.x;
5129 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5131 case GDK_GRAVITY_SOUTH:
5132 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5133 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5135 case GDK_GRAVITY_SOUTH_EAST:
5136 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5137 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5140 mv_resize->moveresize_orig_x = rect.x;
5141 mv_resize->moveresize_orig_y = rect.y;
5148 emulate_resize_drag (GdkWindow *window,
5155 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5157 mv_resize->is_resize = TRUE;
5158 mv_resize->moveresize_button = button;
5159 mv_resize->resize_edge = edge;
5160 mv_resize->moveresize_x = root_x;
5161 mv_resize->moveresize_y = root_y;
5162 mv_resize->moveresize_window = g_object_ref (window);
5164 mv_resize->moveresize_orig_width = gdk_window_get_width (window);
5165 mv_resize->moveresize_orig_height = gdk_window_get_height (window);
5167 mv_resize->moveresize_geom_mask = 0;
5168 gdk_window_get_geometry_hints (window,
5169 &mv_resize->moveresize_geometry,
5170 &mv_resize->moveresize_geom_mask);
5172 calculate_unmoving_origin (mv_resize);
5174 create_moveresize_window (mv_resize, timestamp);
5178 emulate_move_drag (GdkWindow *window,
5184 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5186 mv_resize->is_resize = FALSE;
5187 mv_resize->moveresize_button = button;
5188 mv_resize->moveresize_x = root_x;
5189 mv_resize->moveresize_y = root_y;
5191 mv_resize->moveresize_window = g_object_ref (window);
5193 calculate_unmoving_origin (mv_resize);
5195 create_moveresize_window (mv_resize, timestamp);
5199 * gdk_window_begin_resize_drag:
5200 * @window: a toplevel #GdkWindow
5201 * @edge: the edge or corner from which the drag is started
5202 * @button: the button being used to drag
5203 * @root_x: root window X coordinate of mouse click that began the drag
5204 * @root_y: root window Y coordinate of mouse click that began the drag
5205 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
5207 * Begins a window resize operation (for a toplevel window).
5208 * You might use this function to implement a "window resize grip," for
5209 * example; in fact #GtkStatusbar uses it. The function works best
5210 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
5211 * fallback implementation for other window managers.
5215 gdk_window_begin_resize_drag (GdkWindow *window,
5222 if (GDK_WINDOW_DESTROYED (window) ||
5223 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
5226 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5227 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
5228 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
5230 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
5234 * gdk_window_begin_move_drag:
5235 * @window: a toplevel #GdkWindow
5236 * @button: the button being used to drag
5237 * @root_x: root window X coordinate of mouse click that began the drag
5238 * @root_y: root window Y coordinate of mouse click that began the drag
5239 * @timestamp: timestamp of mouse click that began the drag
5241 * Begins a window move operation (for a toplevel window). You might
5242 * use this function to implement a "window move grip," for
5243 * example. The function works best with window managers that support
5244 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
5245 * Window Manager Hints</ulink>, but has a fallback implementation for
5246 * other window managers.
5250 gdk_window_begin_move_drag (GdkWindow *window,
5256 if (GDK_WINDOW_DESTROYED (window) ||
5257 !WINDOW_IS_TOPLEVEL (window))
5260 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5261 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
5262 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
5265 emulate_move_drag (window, button, root_x, root_y, timestamp);
5269 * gdk_window_enable_synchronized_configure:
5270 * @window: a toplevel #GdkWindow
5272 * Indicates that the application will cooperate with the window
5273 * system in synchronizing the window repaint with the window
5274 * manager during resizing operations. After an application calls
5275 * this function, it must call gdk_window_configure_finished() every
5276 * time it has finished all processing associated with a set of
5277 * Configure events. Toplevel GTK+ windows automatically use this
5280 * On X, calling this function makes @window participate in the
5281 * _NET_WM_SYNC_REQUEST window manager protocol.
5286 gdk_window_enable_synchronized_configure (GdkWindow *window)
5288 GdkWindowImplX11 *impl;
5290 if (!GDK_IS_WINDOW_IMPL_X11 (window->impl))
5293 impl = GDK_WINDOW_IMPL_X11 (window->impl);
5295 if (!impl->use_synchronized_configure)
5297 /* This basically means you want to do fancy X specific stuff, so
5298 ensure we have a native window */
5299 gdk_window_ensure_native (window);
5301 impl->use_synchronized_configure = TRUE;
5302 ensure_sync_counter (window);
5307 * gdk_window_configure_finished:
5308 * @window: a toplevel #GdkWindow
5310 * Signal to the window system that the application has finished
5311 * handling Configure events it has received. Window Managers can
5312 * use this to better synchronize the frame repaint with the
5313 * application. GTK+ applications will automatically call this
5314 * function when appropriate.
5316 * This function can only be called if gdk_window_enable_synchronized_configure()
5317 * was called previously.
5322 gdk_window_configure_finished (GdkWindow *window)
5324 GdkWindowImplX11 *impl;
5326 if (!WINDOW_IS_TOPLEVEL (window))
5329 impl = GDK_WINDOW_IMPL_X11 (window->impl);
5330 if (!impl->use_synchronized_configure)
5334 if (!GDK_WINDOW_DESTROYED (window))
5336 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
5337 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
5339 if (toplevel && toplevel->update_counter != None &&
5340 GDK_DISPLAY_X11 (display)->use_sync &&
5341 !XSyncValueIsZero (toplevel->current_counter_value))
5343 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
5344 toplevel->update_counter,
5345 toplevel->current_counter_value);
5347 XSyncIntToValue (&toplevel->current_counter_value, 0);
5354 _gdk_windowing_window_beep (GdkWindow *window)
5356 GdkDisplay *display;
5358 g_return_if_fail (GDK_IS_WINDOW (window));
5360 display = GDK_WINDOW_DISPLAY (window);
5363 if (GDK_DISPLAY_X11 (display)->use_xkb)
5364 XkbBell (GDK_DISPLAY_XDISPLAY (display),
5365 GDK_WINDOW_XID (window),
5370 gdk_display_beep (display);
5374 * gdk_window_set_opacity:
5375 * @window: a top-level #GdkWindow
5378 * Request the windowing system to make @window partially transparent,
5379 * with opacity 0 being fully transparent and 1 fully opaque. (Values
5380 * of the opacity parameter are clamped to the [0,1] range.)
5382 * On X11, this works only on X screens with a compositing manager
5385 * For setting up per-pixel alpha, see gdk_screen_get_rgba_visual().
5386 * For making non-toplevel windows translucent, see
5387 * gdk_window_set_composited().
5392 gdk_window_set_opacity (GdkWindow *window,
5395 GdkDisplay *display;
5398 g_return_if_fail (GDK_IS_WINDOW (window));
5400 if (GDK_WINDOW_DESTROYED (window) ||
5401 !WINDOW_IS_TOPLEVEL (window))
5404 display = gdk_window_get_display (window);
5408 else if (opacity > 1)
5411 cardinal = opacity * 0xffffffff;
5413 if (cardinal == 0xffffffff)
5414 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
5415 GDK_WINDOW_XID (window),
5416 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"));
5418 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
5419 GDK_WINDOW_XID (window),
5420 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"),
5423 (guchar *) &cardinal, 1);
5427 _gdk_windowing_window_set_composited (GdkWindow *window,
5428 gboolean composited)
5430 #if defined(HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES)
5431 GdkWindowImplX11 *impl;
5432 GdkDisplay *display;
5436 impl = GDK_WINDOW_IMPL_X11 (window->impl);
5438 display = gdk_window_get_display (window);
5439 dpy = GDK_DISPLAY_XDISPLAY (display);
5440 xid = GDK_WINDOW_XID (window);
5444 XCompositeRedirectWindow (dpy, xid, CompositeRedirectManual);
5445 impl->damage = XDamageCreate (dpy, xid, XDamageReportBoundingBox);
5449 XCompositeUnredirectWindow (dpy, xid, CompositeRedirectManual);
5450 XDamageDestroy (dpy, impl->damage);
5451 impl->damage = None;
5457 _gdk_windowing_window_process_updates_recurse (GdkWindow *window,
5458 cairo_region_t *region)
5460 _gdk_window_process_updates_recurse (window, region);
5464 _gdk_windowing_before_process_all_updates (void)
5469 _gdk_windowing_after_process_all_updates (void)
5474 timestamp_predicate (Display *display,
5478 Window xwindow = GPOINTER_TO_UINT (arg);
5479 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
5481 if (xevent->type == PropertyNotify &&
5482 xevent->xproperty.window == xwindow &&
5483 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
5484 "GDK_TIMESTAMP_PROP"))
5491 * gdk_x11_get_server_time:
5492 * @window: a #GdkWindow, used for communication with the server.
5493 * The window must have GDK_PROPERTY_CHANGE_MASK in its
5494 * events mask or a hang will result.
5496 * Routine to get the current X server time stamp.
5498 * Return value: the time stamp.
5501 gdk_x11_get_server_time (GdkWindow *window)
5507 Atom timestamp_prop_atom;
5509 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5510 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
5512 xdisplay = GDK_WINDOW_XDISPLAY (window);
5513 xwindow = GDK_WINDOW_XID (window);
5514 timestamp_prop_atom =
5515 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
5516 "GDK_TIMESTAMP_PROP");
5518 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
5519 timestamp_prop_atom,
5520 8, PropModeReplace, &c, 1);
5522 XIfEvent (xdisplay, &xevent,
5523 timestamp_predicate, GUINT_TO_POINTER(xwindow));
5525 return xevent.xproperty.time;
5529 * gdk_x11_window_get_xid:
5530 * @window: a native #GdkWindow.
5532 * Returns the X resource (window) belonging to a #GdkWindow.
5534 * Return value: the ID of @drawable's X resource.
5537 gdk_x11_window_get_xid (GdkWindow *window)
5539 /* Try to ensure the window has a native window */
5540 if (!_gdk_window_has_impl (window))
5542 gdk_window_ensure_native (window);
5544 /* We sync here to ensure the window is created in the Xserver when
5545 * this function returns. This is required because the returned XID
5546 * for this window must be valid immediately, even with another
5547 * connection to the Xserver */
5548 gdk_display_sync (gdk_window_get_display (window));
5551 if (!GDK_WINDOW_IS_X11 (window))
5553 g_warning (G_STRLOC " drawable is not a native X11 window");
5557 return GDK_WINDOW_IMPL_X11 (window->impl)->xid;
5561 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
5563 GObjectClass *object_class = G_OBJECT_CLASS (klass);
5564 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass);
5566 object_class->finalize = gdk_window_impl_x11_finalize;
5568 impl_class->ref_cairo_surface = gdk_x11_ref_cairo_surface;
5569 impl_class->show = gdk_window_x11_show;
5570 impl_class->hide = gdk_window_x11_hide;
5571 impl_class->withdraw = gdk_window_x11_withdraw;
5572 impl_class->set_events = gdk_window_x11_set_events;
5573 impl_class->get_events = gdk_window_x11_get_events;
5574 impl_class->raise = gdk_window_x11_raise;
5575 impl_class->lower = gdk_window_x11_lower;
5576 impl_class->restack_under = gdk_window_x11_restack_under;
5577 impl_class->restack_toplevel = gdk_window_x11_restack_toplevel;
5578 impl_class->move_resize = gdk_window_x11_move_resize;
5579 impl_class->set_background = gdk_window_x11_set_background;
5580 impl_class->reparent = gdk_window_x11_reparent;
5581 impl_class->set_device_cursor = gdk_window_x11_set_device_cursor;
5582 impl_class->get_geometry = gdk_window_x11_get_geometry;
5583 impl_class->get_root_coords = gdk_window_x11_get_root_coords;
5584 impl_class->get_device_state = gdk_window_x11_get_device_state;
5585 impl_class->shape_combine_region = gdk_window_x11_shape_combine_region;
5586 impl_class->input_shape_combine_region = gdk_window_x11_input_shape_combine_region;
5587 impl_class->set_static_gravities = gdk_window_x11_set_static_gravities;
5588 impl_class->queue_antiexpose = _gdk_x11_window_queue_antiexpose;
5589 impl_class->translate = _gdk_x11_window_translate;
5590 impl_class->destroy = _gdk_x11_window_destroy;
5591 impl_class->resize_cairo_surface = gdk_window_x11_resize_cairo_surface;
5592 impl_class->get_shape = gdk_x11_window_get_shape;
5593 impl_class->get_input_shape = gdk_x11_window_get_input_shape;