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 (GdkDrawable *drawable,
195 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
198 visual = gdk_window_get_visual (impl->wrapper);
199 return cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (impl->wrapper),
200 GDK_WINDOW_IMPL_X11 (impl)->xid,
201 GDK_VISUAL_XVISUAL (visual),
205 static cairo_surface_t *
206 gdk_x11_ref_cairo_surface (GdkDrawable *drawable)
208 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
210 if (GDK_IS_WINDOW_IMPL_X11 (drawable) &&
211 GDK_WINDOW_DESTROYED (impl->wrapper))
214 if (!impl->cairo_surface)
216 impl->cairo_surface = gdk_x11_create_cairo_surface (drawable,
217 gdk_window_get_width (impl->wrapper),
218 gdk_window_get_height (impl->wrapper));
220 if (impl->cairo_surface)
221 cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
222 drawable, gdk_x11_cairo_surface_destroy);
225 cairo_surface_reference (impl->cairo_surface);
227 return impl->cairo_surface;
231 gdk_window_impl_x11_finalize (GObject *object)
234 GdkWindowImplX11 *impl;
236 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
238 impl = GDK_WINDOW_IMPL_X11 (object);
240 wrapper = impl->wrapper;
242 _gdk_xgrab_check_destroy (wrapper);
244 if (!GDK_WINDOW_DESTROYED (wrapper))
246 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
248 _gdk_xid_table_remove (display, impl->xid);
249 if (impl->toplevel && impl->toplevel->focus_window)
250 _gdk_xid_table_remove (display, impl->toplevel->focus_window);
253 g_free (impl->toplevel);
256 gdk_cursor_unref (impl->cursor);
258 g_hash_table_destroy (impl->device_cursor);
260 G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
269 free_pixmap (gpointer datap)
271 FreePixmapData *data = datap;
273 if (!gdk_display_is_closed (data->display))
275 XFreePixmap (GDK_DISPLAY_XDISPLAY (data->display),
279 g_object_unref (data->display);
280 g_slice_free (FreePixmapData, data);
284 attach_free_pixmap_handler (cairo_surface_t *surface,
288 static const cairo_user_data_key_t key;
289 FreePixmapData *data;
291 data = g_slice_new (FreePixmapData);
292 data->display = g_object_ref (display);
293 data->pixmap = pixmap;
295 cairo_surface_set_user_data (surface, &key, data, free_pixmap);
298 /* Cairo does not guarantee we get an xlib surface if we call
299 * cairo_surface_create_similar(). In some cases however, we must use a
300 * pixmap or bitmap in the X11 API.
301 * These functions ensure an Xlib surface.
304 _gdk_x11_window_create_bitmap_surface (GdkWindow *window,
308 cairo_surface_t *surface;
311 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
312 GDK_WINDOW_XID (window),
314 surface = cairo_xlib_surface_create_for_bitmap (GDK_WINDOW_XDISPLAY (window),
316 GDK_SCREEN_XSCREEN (GDK_WINDOW_SCREEN (window)),
318 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
323 /* Create a surface backed with a pixmap without alpha on the same screen as window */
324 static cairo_surface_t *
325 gdk_x11_window_create_pixmap_surface (GdkWindow *window,
329 GdkScreen *screen = gdk_window_get_screen (window);
330 GdkVisual *visual = gdk_screen_get_system_visual (screen);
331 cairo_surface_t *surface;
334 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
335 GDK_WINDOW_XID (window),
337 gdk_visual_get_depth (visual));
338 surface = cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (window),
340 GDK_VISUAL_XVISUAL (visual),
342 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
348 tmp_unset_bg (GdkWindow *window)
350 GdkWindowImplX11 *impl;
352 impl = GDK_WINDOW_IMPL_X11 (window->impl);
356 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
357 GDK_WINDOW_XID (window), None);
361 tmp_reset_bg (GdkWindow *window)
363 GdkWindowImplX11 *impl;
365 impl = GDK_WINDOW_IMPL_X11 (window->impl);
369 gdk_window_x11_set_background (window, window->background);
372 /* Unsetting and resetting window backgrounds.
374 * In many cases it is possible to avoid flicker by unsetting the
375 * background of windows. For example if the background of the
376 * parent window is unset when a window is unmapped, a brief flicker
377 * of background painting is avoided.
380 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
383 g_return_if_fail (GDK_IS_WINDOW (window));
385 if (window->input_only || window->destroyed ||
386 (window->window_type != GDK_WINDOW_ROOT &&
387 !GDK_WINDOW_IS_MAPPED (window)))
390 if (_gdk_window_has_impl (window) &&
391 GDK_WINDOW_IS_X11 (window) &&
392 window->window_type != GDK_WINDOW_ROOT &&
393 window->window_type != GDK_WINDOW_FOREIGN)
394 tmp_unset_bg (window);
400 for (l = window->children; l != NULL; l = l->next)
401 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
406 _gdk_x11_window_tmp_unset_parent_bg (GdkWindow *window)
408 if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
411 window = _gdk_window_get_impl_window (window->parent);
412 _gdk_x11_window_tmp_unset_bg (window, FALSE);
416 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
419 g_return_if_fail (GDK_IS_WINDOW (window));
421 if (window->input_only || window->destroyed ||
422 (window->window_type != GDK_WINDOW_ROOT &&
423 !GDK_WINDOW_IS_MAPPED (window)))
427 if (_gdk_window_has_impl (window) &&
428 GDK_WINDOW_IS_X11 (window) &&
429 window->window_type != GDK_WINDOW_ROOT &&
430 window->window_type != GDK_WINDOW_FOREIGN)
431 tmp_reset_bg (window);
437 for (l = window->children; l != NULL; l = l->next)
438 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
443 _gdk_x11_window_tmp_reset_parent_bg (GdkWindow *window)
445 if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
448 window = _gdk_window_get_impl_window (window->parent);
450 _gdk_x11_window_tmp_reset_bg (window, FALSE);
454 _gdk_windowing_window_init (GdkScreen * screen)
457 GdkWindowImplX11 *impl;
458 GdkScreenX11 *screen_x11;
460 screen_x11 = GDK_SCREEN_X11 (screen);
462 g_assert (screen_x11->root_window == NULL);
464 window = screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
466 window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
467 window->impl_window = window;
468 window->visual = gdk_screen_get_system_visual (screen);
470 impl = GDK_WINDOW_IMPL_X11 (window->impl);
472 impl->xid = screen_x11->xroot_window;
473 impl->wrapper = window;
475 window->window_type = GDK_WINDOW_ROOT;
476 window->depth = DefaultDepthOfScreen (screen_x11->xscreen);
482 window->width = WidthOfScreen (screen_x11->xscreen);
483 window->height = HeightOfScreen (screen_x11->xscreen);
484 window->viewable = TRUE;
486 /* see init_randr_support() in gdkscreen-x11.c */
487 window->event_mask = GDK_STRUCTURE_MASK;
489 _gdk_window_update_size (screen_x11->root_window);
491 _gdk_xid_table_insert (screen_x11->display,
492 &screen_x11->xroot_window,
493 screen_x11->root_window);
497 set_wm_protocols (GdkWindow *window)
499 GdkDisplay *display = gdk_window_get_display (window);
503 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
504 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
505 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
508 if (GDK_DISPLAY_X11 (display)->use_sync)
509 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
512 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
516 get_default_title (void)
520 title = g_get_application_name ();
522 title = g_get_prgname ();
530 check_leader_window_title (GdkDisplay *display)
532 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
534 if (display_x11->leader_window && !display_x11->leader_window_title_set)
536 set_wm_name (display,
537 display_x11->leader_window,
538 get_default_title ());
540 display_x11->leader_window_title_set = TRUE;
545 create_focus_window (GdkDisplay *display,
548 GdkDisplayX11 *display_x11;
549 GdkEventMask event_mask;
553 xdisplay = GDK_DISPLAY_XDISPLAY (display);
554 display_x11 = GDK_DISPLAY_X11 (display);
556 focus_window = XCreateSimpleWindow (xdisplay, parent,
560 /* FIXME: probably better to actually track the requested event mask for the toplevel
562 event_mask = (GDK_KEY_PRESS_MASK |
563 GDK_KEY_RELEASE_MASK |
564 GDK_FOCUS_CHANGE_MASK);
566 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
570 XMapWindow (xdisplay, focus_window);
576 ensure_sync_counter (GdkWindow *window)
579 if (!GDK_WINDOW_DESTROYED (window))
581 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
582 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
583 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
585 if (toplevel && impl->use_synchronized_configure &&
586 toplevel->update_counter == None &&
587 GDK_DISPLAY_X11 (display)->use_sync)
589 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
593 XSyncIntToValue (&value, 0);
595 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
597 atom = gdk_x11_get_xatom_by_name_for_display (display,
598 "_NET_WM_SYNC_REQUEST_COUNTER");
600 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
603 (guchar *)&toplevel->update_counter, 1);
605 XSyncIntToValue (&toplevel->current_counter_value, 0);
612 setup_toplevel_window (GdkWindow *window,
615 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
616 GdkDisplay *display = gdk_window_get_display (window);
617 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
618 XID xid = GDK_WINDOW_XID (window);
619 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
620 XSizeHints size_hints;
622 Window leader_window;
624 set_wm_protocols (window);
626 if (!window->input_only)
628 /* The focus window is off the visible area, and serves to receive key
629 * press events so they don't get sent to child windows.
631 toplevel->focus_window = create_focus_window (display, xid);
632 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
635 check_leader_window_title (screen_x11->display);
637 /* FIXME: Is there any point in doing this? Do any WM's pay
638 * attention to PSize, and even if they do, is this the
641 size_hints.flags = PSize;
642 size_hints.width = window->width;
643 size_hints.height = window->height;
645 XSetWMNormalHints (xdisplay, xid, &size_hints);
647 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
648 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
651 XChangeProperty (xdisplay, xid,
652 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
657 leader_window = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
660 XChangeProperty (xdisplay, xid,
661 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
662 XA_WINDOW, 32, PropModeReplace,
663 (guchar *) &leader_window, 1);
665 if (toplevel->focus_window != None)
666 XChangeProperty (xdisplay, xid,
667 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_USER_TIME_WINDOW"),
668 XA_WINDOW, 32, PropModeReplace,
669 (guchar *) &toplevel->focus_window, 1);
671 if (!window->focus_on_map)
672 gdk_x11_window_set_user_time (window, 0);
673 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
674 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
676 ensure_sync_counter (window);
680 _gdk_window_impl_new (GdkWindow *window,
681 GdkWindow *real_parent,
683 GdkEventMask event_mask,
684 GdkWindowAttr *attributes,
685 gint attributes_mask)
687 GdkWindowImplX11 *impl;
688 GdkScreenX11 *screen_x11;
689 GdkDisplayX11 *display_x11;
695 XSetWindowAttributes xattributes;
696 long xattributes_mask;
697 XClassHint *class_hint;
702 screen_x11 = GDK_SCREEN_X11 (screen);
703 xparent = GDK_WINDOW_XID (real_parent);
704 display_x11 = GDK_DISPLAY_X11 (GDK_SCREEN_DISPLAY (screen));
706 impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
707 window->impl = (GdkDrawable *)impl;
708 impl->wrapper = GDK_WINDOW (window);
710 xdisplay = screen_x11->xdisplay;
712 xattributes_mask = 0;
714 xvisual = gdk_x11_visual_get_xvisual (window->visual);
716 if (attributes_mask & GDK_WA_NOREDIR)
718 xattributes.override_redirect =
719 (attributes->override_redirect == FALSE)?False:True;
720 xattributes_mask |= CWOverrideRedirect;
723 xattributes.override_redirect = False;
725 impl->override_redirect = xattributes.override_redirect;
727 if (window->parent && window->parent->guffaw_gravity)
729 xattributes.win_gravity = StaticGravity;
730 xattributes_mask |= CWWinGravity;
734 switch (window->window_type)
736 case GDK_WINDOW_TOPLEVEL:
737 case GDK_WINDOW_TEMP:
738 if (GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT)
740 /* The common code warns for this case */
741 xparent = GDK_SCREEN_XROOTWIN (screen);
745 if (!window->input_only)
749 xattributes.background_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
751 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
752 xattributes_mask |= CWBorderPixel | CWBackPixel;
754 if (window->guffaw_gravity)
755 xattributes.bit_gravity = StaticGravity;
757 xattributes.bit_gravity = NorthWestGravity;
759 xattributes_mask |= CWBitGravity;
761 xattributes.colormap = _gdk_visual_get_x11_colormap (window->visual);
762 xattributes_mask |= CWColormap;
764 if (window->window_type == GDK_WINDOW_TEMP)
766 xattributes.save_under = True;
767 xattributes.override_redirect = True;
768 xattributes.cursor = None;
769 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
771 impl->override_redirect = TRUE;
779 if (window->width > 65535 ||
780 window->height > 65535)
782 g_warning ("Native Windows wider or taller than 65535 pixels are not supported");
784 if (window->width > 65535)
785 window->width = 65535;
786 if (window->height > 65535)
787 window->height = 65535;
790 impl->xid = XCreateWindow (xdisplay, xparent,
791 window->x + window->parent->abs_x,
792 window->y + window->parent->abs_y,
793 window->width, window->height,
794 0, window->depth, class, xvisual,
795 xattributes_mask, &xattributes);
797 g_object_ref (window);
798 _gdk_xid_table_insert (screen_x11->display, &impl->xid, window);
800 switch (GDK_WINDOW_TYPE (window))
802 case GDK_WINDOW_TOPLEVEL:
803 case GDK_WINDOW_TEMP:
804 if (attributes_mask & GDK_WA_TITLE)
805 title = attributes->title;
807 title = get_default_title ();
809 gdk_window_set_title (window, title);
811 if (attributes_mask & GDK_WA_WMCLASS)
813 class_hint = XAllocClassHint ();
814 class_hint->res_name = attributes->wmclass_name;
815 class_hint->res_class = attributes->wmclass_class;
816 XSetClassHint (xdisplay, impl->xid, class_hint);
820 setup_toplevel_window (window, window->parent);
823 case GDK_WINDOW_CHILD:
828 if (attributes_mask & GDK_WA_TYPE_HINT)
829 gdk_window_set_type_hint (window, attributes->type_hint);
831 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
832 GDK_WINDOW_XID (window), event_mask,
833 StructureNotifyMask | PropertyChangeMask);
837 x_event_mask_to_gdk_event_mask (long mask)
839 GdkEventMask event_mask = 0;
842 for (i = 0; i < _gdk_nenvent_masks; i++)
844 if (mask & _gdk_event_mask_table[i])
845 event_mask |= 1 << (i + 1);
852 * gdk_window_foreign_new_for_display:
853 * @display: the #GdkDisplay where the window handle comes from.
854 * @anid: a native window handle.
856 * Wraps a native window in a #GdkWindow.
857 * This may fail if the window has been destroyed. If the window
858 * was already known to GDK, a new reference to the existing
859 * #GdkWindow is returned.
861 * For example in the X backend, a native window handle is an Xlib
864 * Return value: (transfer full): a #GdkWindow wrapper for the native
865 * window, or %NULL if the window has been destroyed. The wrapper
866 * will be newly created, if one doesn't exist already.
871 gdk_window_foreign_new_for_display (GdkDisplay *display,
872 GdkNativeWindow anid)
876 GdkWindowImplX11 *impl;
877 GdkDisplayX11 *display_x11;
878 XWindowAttributes attrs;
880 Window *children = NULL;
884 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
886 display_x11 = GDK_DISPLAY_X11 (display);
888 if ((window = gdk_xid_table_lookup_for_display (display, anid)) != NULL)
889 return g_object_ref (window);
891 gdk_error_trap_push ();
892 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
893 if (gdk_error_trap_pop () || !result)
896 /* FIXME: This is pretty expensive. Maybe the caller should supply
898 gdk_error_trap_push ();
899 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
900 if (gdk_error_trap_pop () || !result)
906 screen = _gdk_x11_display_screen_for_xrootwin (display, root);
908 window = g_object_new (GDK_TYPE_WINDOW, NULL);
910 window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
911 window->impl_window = window;
912 window->visual = gdk_x11_screen_lookup_visual (screen,
913 XVisualIDFromVisual (attrs.visual));
915 impl = GDK_WINDOW_IMPL_X11 (window->impl);
916 impl->wrapper = window;
918 window->parent = gdk_xid_table_lookup_for_display (display, parent);
920 if (!window->parent || GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_FOREIGN)
921 window->parent = gdk_screen_get_root_window (screen);
923 window->parent->children = g_list_prepend (window->parent->children, window);
929 window->width = attrs.width;
930 window->height = attrs.height;
931 window->window_type = GDK_WINDOW_FOREIGN;
932 window->destroyed = FALSE;
934 window->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
936 if (attrs.map_state == IsUnmapped)
937 window->state = GDK_WINDOW_STATE_WITHDRAWN;
940 window->viewable = TRUE;
942 window->depth = attrs.depth;
944 g_object_ref (window);
945 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
947 /* Update the clip region, etc */
948 _gdk_window_update_size (window);
954 * gdk_window_lookup_for_display:
955 * @display: the #GdkDisplay corresponding to the window handle
956 * @anid: a native window handle.
958 * Looks up the #GdkWindow that wraps the given native window handle.
960 * For example in the X backend, a native window handle is an Xlib
963 * Return value: (transfer none): the #GdkWindow wrapper for the native
964 * window, or %NULL if there is none.
969 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
971 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
976 * @anid: a native window handle.
978 * Looks up the #GdkWindow that wraps the given native window handle.
980 * For example in the X backend, a native window handle is an Xlib
983 * Return value: (transfer none): the #GdkWindow wrapper for the native
984 * window, or %NULL if there is none.
987 gdk_window_lookup (GdkNativeWindow anid)
989 return (GdkWindow*) gdk_xid_table_lookup (anid);
993 gdk_toplevel_x11_free_contents (GdkDisplay *display,
994 GdkToplevelX11 *toplevel)
996 if (toplevel->icon_pixmap)
998 cairo_surface_destroy (toplevel->icon_pixmap);
999 toplevel->icon_pixmap = NULL;
1001 if (toplevel->icon_mask)
1003 cairo_surface_destroy (toplevel->icon_mask);
1004 toplevel->icon_mask = NULL;
1006 if (toplevel->group_leader)
1008 g_object_unref (toplevel->group_leader);
1009 toplevel->group_leader = NULL;
1012 if (toplevel->update_counter != None)
1014 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
1015 toplevel->update_counter);
1016 toplevel->update_counter = None;
1018 XSyncIntToValue (&toplevel->current_counter_value, 0);
1024 _gdk_x11_window_destroy (GdkWindow *window,
1026 gboolean foreign_destroy)
1028 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1029 GdkToplevelX11 *toplevel;
1031 g_return_if_fail (GDK_IS_WINDOW (window));
1033 _gdk_selection_window_destroyed (window);
1035 toplevel = _gdk_x11_window_get_toplevel (window);
1037 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1039 if (impl->cairo_surface)
1041 cairo_surface_finish (impl->cairo_surface);
1042 cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
1046 if (!recursing && !foreign_destroy)
1048 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1052 static cairo_surface_t *
1053 gdk_window_x11_resize_cairo_surface (GdkDrawable *window,
1054 cairo_surface_t *surface,
1058 cairo_xlib_surface_set_size (surface, width, height);
1064 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
1066 /* It's somebody else's window, but in our hierarchy,
1067 * so reparent it to the root window, and then send
1068 * it a delete event, as if we were a WM
1070 XClientMessageEvent xclient;
1072 gdk_error_trap_push ();
1073 gdk_window_hide (window);
1074 gdk_window_reparent (window, NULL, 0, 0);
1076 memset (&xclient, 0, sizeof (xclient));
1077 xclient.type = ClientMessage;
1078 xclient.window = GDK_WINDOW_XID (window);
1079 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1081 xclient.format = 32;
1082 xclient.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1083 "WM_DELETE_WINDOW");
1084 xclient.data.l[1] = CurrentTime;
1085 xclient.data.l[2] = 0;
1086 xclient.data.l[3] = 0;
1087 xclient.data.l[4] = 0;
1089 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1090 GDK_WINDOW_XID (window),
1091 False, 0, (XEvent *)&xclient);
1092 gdk_error_trap_pop_ignored ();
1096 get_root (GdkWindow *window)
1098 GdkScreen *screen = gdk_window_get_screen (window);
1100 return gdk_screen_get_root_window (screen);
1103 /* This function is called when the XWindow is really gone.
1106 gdk_window_destroy_notify (GdkWindow *window)
1108 GdkWindowImplX11 *window_impl;
1110 window_impl = GDK_WINDOW_IMPL_X11 ((window)->impl);
1112 if (!GDK_WINDOW_DESTROYED (window))
1114 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1115 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1117 _gdk_window_destroy (window, TRUE);
1120 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1121 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1122 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1124 _gdk_xgrab_check_destroy (window);
1126 g_object_unref (window);
1130 update_wm_hints (GdkWindow *window,
1133 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1134 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1138 !toplevel->is_leader &&
1139 window->state & GDK_WINDOW_STATE_WITHDRAWN)
1142 wm_hints.flags = StateHint | InputHint;
1143 wm_hints.input = window->accept_focus ? True : False;
1144 wm_hints.initial_state = NormalState;
1146 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
1148 wm_hints.flags |= StateHint;
1149 wm_hints.initial_state = IconicState;
1152 if (toplevel->icon_pixmap)
1154 wm_hints.flags |= IconPixmapHint;
1155 wm_hints.icon_pixmap = cairo_xlib_surface_get_drawable (toplevel->icon_pixmap);
1158 if (toplevel->icon_mask)
1160 wm_hints.flags |= IconMaskHint;
1161 wm_hints.icon_mask = cairo_xlib_surface_get_drawable (toplevel->icon_mask);
1164 wm_hints.flags |= WindowGroupHint;
1165 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1167 wm_hints.flags |= WindowGroupHint;
1168 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1171 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1173 if (toplevel->urgency_hint)
1174 wm_hints.flags |= XUrgencyHint;
1176 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1177 GDK_WINDOW_XID (window),
1182 set_initial_hints (GdkWindow *window)
1184 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1185 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1186 Window xwindow = GDK_WINDOW_XID (window);
1187 GdkToplevelX11 *toplevel;
1191 toplevel = _gdk_x11_window_get_toplevel (window);
1196 update_wm_hints (window, TRUE);
1198 /* We set the spec hints regardless of whether the spec is supported,
1199 * since it can't hurt and it's kind of expensive to check whether
1205 if (window->state & GDK_WINDOW_STATE_MAXIMIZED)
1207 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1208 "_NET_WM_STATE_MAXIMIZED_VERT");
1210 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1211 "_NET_WM_STATE_MAXIMIZED_HORZ");
1213 toplevel->have_maxhorz = toplevel->have_maxvert = TRUE;
1216 if (window->state & GDK_WINDOW_STATE_ABOVE)
1218 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1219 "_NET_WM_STATE_ABOVE");
1223 if (window->state & GDK_WINDOW_STATE_BELOW)
1225 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1226 "_NET_WM_STATE_BELOW");
1230 if (window->state & GDK_WINDOW_STATE_STICKY)
1232 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1233 "_NET_WM_STATE_STICKY");
1235 toplevel->have_sticky = TRUE;
1238 if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
1240 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1241 "_NET_WM_STATE_FULLSCREEN");
1243 toplevel->have_fullscreen = TRUE;
1246 if (window->modal_hint)
1248 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1249 "_NET_WM_STATE_MODAL");
1253 if (toplevel->skip_taskbar_hint)
1255 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1256 "_NET_WM_STATE_SKIP_TASKBAR");
1260 if (toplevel->skip_pager_hint)
1262 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1263 "_NET_WM_STATE_SKIP_PAGER");
1269 XChangeProperty (xdisplay,
1271 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1272 XA_ATOM, 32, PropModeReplace,
1273 (guchar*) atoms, i);
1277 XDeleteProperty (xdisplay,
1279 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1282 if (window->state & GDK_WINDOW_STATE_STICKY)
1284 atoms[0] = 0xFFFFFFFF;
1285 XChangeProperty (xdisplay,
1287 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1288 XA_CARDINAL, 32, PropModeReplace,
1289 (guchar*) atoms, 1);
1290 toplevel->on_all_desktops = TRUE;
1294 XDeleteProperty (xdisplay,
1296 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1299 toplevel->map_serial = NextRequest (xdisplay);
1303 gdk_window_x11_show (GdkWindow *window, gboolean already_mapped)
1305 GdkDisplay *display;
1306 GdkDisplayX11 *display_x11;
1307 GdkToplevelX11 *toplevel;
1308 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1309 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1310 Window xwindow = GDK_WINDOW_XID (window);
1313 if (!already_mapped)
1314 set_initial_hints (window);
1316 if (WINDOW_IS_TOPLEVEL (window))
1318 display = gdk_window_get_display (window);
1319 display_x11 = GDK_DISPLAY_X11 (display);
1320 toplevel = _gdk_x11_window_get_toplevel (window);
1322 if (toplevel->user_time != 0 &&
1323 display_x11->user_time != 0 &&
1324 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1325 gdk_x11_window_set_user_time (window, display_x11->user_time);
1328 unset_bg = !window->input_only &&
1329 (window->window_type == GDK_WINDOW_CHILD ||
1330 impl->override_redirect) &&
1331 gdk_window_is_viewable (window);
1334 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1336 XMapWindow (xdisplay, xwindow);
1339 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1343 pre_unmap (GdkWindow *window)
1345 GdkWindow *start_window = NULL;
1347 if (window->input_only)
1350 if (window->window_type == GDK_WINDOW_CHILD)
1351 start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
1352 else if (window->window_type == GDK_WINDOW_TEMP)
1353 start_window = get_root (window);
1356 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1360 post_unmap (GdkWindow *window)
1362 GdkWindow *start_window = NULL;
1364 if (window->input_only)
1367 if (window->window_type == GDK_WINDOW_CHILD)
1368 start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
1369 else if (window->window_type == GDK_WINDOW_TEMP)
1370 start_window = get_root (window);
1374 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1376 if (window->window_type == GDK_WINDOW_CHILD && window->parent)
1378 GdkRectangle invalid_rect;
1380 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1381 invalid_rect.width = gdk_window_get_width (window);
1382 invalid_rect.height = gdk_window_get_height (window);
1383 gdk_window_invalidate_rect ((GdkWindow *)window->parent,
1384 &invalid_rect, TRUE);
1390 gdk_window_x11_hide (GdkWindow *window)
1392 /* We'll get the unmap notify eventually, and handle it then,
1393 * but checking here makes things more consistent if we are
1394 * just doing stuff ourself.
1396 _gdk_xgrab_check_unmap (window,
1397 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1399 /* You can't simply unmap toplevel windows. */
1400 switch (window->window_type)
1402 case GDK_WINDOW_TOPLEVEL:
1403 case GDK_WINDOW_TEMP: /* ? */
1404 gdk_window_withdraw (window);
1407 case GDK_WINDOW_FOREIGN:
1408 case GDK_WINDOW_ROOT:
1409 case GDK_WINDOW_CHILD:
1413 _gdk_window_clear_update_area (window);
1416 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1417 GDK_WINDOW_XID (window));
1418 post_unmap (window);
1422 gdk_window_x11_withdraw (GdkWindow *window)
1424 if (!window->destroyed)
1426 if (GDK_WINDOW_IS_MAPPED (window))
1427 gdk_synthesize_window_state (window,
1429 GDK_WINDOW_STATE_WITHDRAWN);
1431 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1435 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1436 GDK_WINDOW_XID (window), 0);
1438 post_unmap (window);
1443 window_x11_move (GdkWindow *window,
1447 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1449 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1451 _gdk_window_move_resize_child (window,
1453 window->width, window->height);
1457 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1458 GDK_WINDOW_XID (window),
1461 if (impl->override_redirect)
1470 window_x11_resize (GdkWindow *window,
1480 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1482 _gdk_window_move_resize_child (window,
1483 window->x, window->y,
1488 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1490 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1491 GDK_WINDOW_XID (window),
1494 if (impl->override_redirect)
1496 window->width = width;
1497 window->height = height;
1498 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1502 if (width != window->width || height != window->height)
1503 window->resize_count += 1;
1507 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1511 window_x11_move_resize (GdkWindow *window,
1523 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1525 _gdk_window_move_resize_child (window, x, y, width, height);
1526 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1530 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1532 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1533 GDK_WINDOW_XID (window),
1534 x, y, width, height);
1536 if (impl->override_redirect)
1541 window->width = width;
1542 window->height = height;
1544 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1548 if (width != window->width || height != window->height)
1549 window->resize_count += 1;
1555 gdk_window_x11_move_resize (GdkWindow *window,
1562 if (with_move && (width < 0 && height < 0))
1563 window_x11_move (window, x, y);
1567 window_x11_move_resize (window, x, y, width, height);
1569 window_x11_resize (window, width, height);
1574 gdk_window_x11_reparent (GdkWindow *window,
1575 GdkWindow *new_parent,
1579 GdkWindowImplX11 *impl;
1581 impl = GDK_WINDOW_IMPL_X11 (window->impl);
1583 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1584 _gdk_x11_window_tmp_unset_parent_bg (window);
1585 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1586 GDK_WINDOW_XID (window),
1587 GDK_WINDOW_XID (new_parent),
1588 new_parent->abs_x + x, new_parent->abs_y + y);
1589 _gdk_x11_window_tmp_reset_parent_bg (window);
1590 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1592 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1593 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1595 window->parent = new_parent;
1597 /* Switch the window type as appropriate */
1599 switch (GDK_WINDOW_TYPE (new_parent))
1601 case GDK_WINDOW_ROOT:
1602 case GDK_WINDOW_FOREIGN:
1603 /* Reparenting to toplevel */
1605 if (!WINDOW_IS_TOPLEVEL (window) &&
1606 GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1608 /* This is also done in common code at a later stage, but we
1609 need it in setup_toplevel, so do it here too */
1610 if (window->toplevel_window_type != -1)
1611 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1612 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1613 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1615 /* Wasn't a toplevel, set up */
1616 setup_toplevel_window (window, new_parent);
1621 case GDK_WINDOW_TOPLEVEL:
1622 case GDK_WINDOW_CHILD:
1623 case GDK_WINDOW_TEMP:
1624 if (WINDOW_IS_TOPLEVEL (window) &&
1627 if (impl->toplevel->focus_window)
1629 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1630 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1633 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1635 g_free (impl->toplevel);
1636 impl->toplevel = NULL;
1644 gdk_window_x11_raise (GdkWindow *window)
1646 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1650 gdk_window_x11_restack_under (GdkWindow *window,
1651 GList *native_siblings /* in requested order, first is bottom-most */)
1657 n_windows = g_list_length (native_siblings) + 1;
1658 windows = g_new (Window, n_windows);
1660 windows[0] = GDK_WINDOW_XID (window);
1661 /* Reverse order, as input order is bottom-most first */
1663 for (l = native_siblings; l != NULL; l = l->next)
1664 windows[i--] = GDK_WINDOW_XID (l->data);
1666 XRestackWindows (GDK_WINDOW_XDISPLAY (window), windows, n_windows);
1672 gdk_window_x11_restack_toplevel (GdkWindow *window,
1676 XWindowChanges changes;
1678 changes.sibling = GDK_WINDOW_XID (sibling);
1679 changes.stack_mode = above ? Above : Below;
1680 XReconfigureWMWindow (GDK_WINDOW_XDISPLAY (window),
1681 GDK_WINDOW_XID (window),
1682 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)),
1683 CWStackMode | CWSibling, &changes);
1687 gdk_window_x11_lower (GdkWindow *window)
1689 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1693 * gdk_x11_window_move_to_current_desktop:
1694 * @window: a #GdkWindow
1696 * Moves the window to the correct workspace when running under a
1697 * window manager that supports multiple workspaces, as described
1698 * in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
1699 * Window Manager Hints</ulink>. Will not do anything if the
1700 * window is already on all workspaces.
1705 gdk_x11_window_move_to_current_desktop (GdkWindow *window)
1707 GdkToplevelX11 *toplevel;
1709 g_return_if_fail (GDK_IS_WINDOW (window));
1710 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1712 toplevel = _gdk_x11_window_get_toplevel (window);
1714 if (toplevel->on_all_desktops)
1717 move_to_current_desktop (window);
1721 move_to_current_desktop (GdkWindow *window)
1723 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1724 gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
1731 gulong *current_desktop;
1732 GdkDisplay *display;
1734 display = gdk_window_get_display (window);
1736 /* Get current desktop, then set it; this is a race, but not
1737 * one that matters much in practice.
1739 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
1740 GDK_WINDOW_XROOTWIN (window),
1741 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
1743 False, XA_CARDINAL, &type, &format, &nitems,
1744 &bytes_after, &data);
1746 if (type == XA_CARDINAL)
1748 XClientMessageEvent xclient;
1749 current_desktop = (gulong *)data;
1751 memset (&xclient, 0, sizeof (xclient));
1752 xclient.type = ClientMessage;
1754 xclient.send_event = True;
1755 xclient.window = GDK_WINDOW_XID (window);
1756 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
1757 xclient.format = 32;
1759 xclient.data.l[0] = *current_desktop;
1760 xclient.data.l[1] = 0;
1761 xclient.data.l[2] = 0;
1762 xclient.data.l[3] = 0;
1763 xclient.data.l[4] = 0;
1765 XSendEvent (GDK_DISPLAY_XDISPLAY (display),
1766 GDK_WINDOW_XROOTWIN (window),
1768 SubstructureRedirectMask | SubstructureNotifyMask,
1769 (XEvent *)&xclient);
1771 XFree (current_desktop);
1778 * @window: a #GdkWindow
1779 * @timestamp: timestamp of the event triggering the window focus
1781 * Sets keyboard focus to @window. In most cases, gtk_window_present()
1782 * should be used on a #GtkWindow, rather than calling this function.
1786 gdk_window_focus (GdkWindow *window,
1789 GdkDisplay *display;
1791 g_return_if_fail (GDK_IS_WINDOW (window));
1793 if (GDK_WINDOW_DESTROYED (window) ||
1794 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1797 display = GDK_WINDOW_DISPLAY (window);
1799 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1800 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
1802 XClientMessageEvent xclient;
1804 memset (&xclient, 0, sizeof (xclient));
1805 xclient.type = ClientMessage;
1806 xclient.window = GDK_WINDOW_XID (window);
1807 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1808 "_NET_ACTIVE_WINDOW");
1809 xclient.format = 32;
1810 xclient.data.l[0] = 1; /* requestor type; we're an app */
1811 xclient.data.l[1] = timestamp;
1812 xclient.data.l[2] = None; /* currently active window */
1813 xclient.data.l[3] = 0;
1814 xclient.data.l[4] = 0;
1816 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1817 SubstructureRedirectMask | SubstructureNotifyMask,
1818 (XEvent *)&xclient);
1822 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1824 /* There is no way of knowing reliably whether we are viewable;
1825 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1827 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1834 * gdk_window_set_type_hint:
1835 * @window: A toplevel #GdkWindow
1836 * @hint: A hint of the function this window will have
1838 * The application can use this call to provide a hint to the window
1839 * manager about the functionality of a window. The window manager
1840 * can use this information when determining the decoration and behaviour
1843 * The hint must be set before the window is mapped.
1846 gdk_window_set_type_hint (GdkWindow *window,
1847 GdkWindowTypeHint hint)
1849 GdkDisplay *display;
1852 if (GDK_WINDOW_DESTROYED (window) ||
1853 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1856 display = gdk_window_get_display (window);
1860 case GDK_WINDOW_TYPE_HINT_DIALOG:
1861 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1863 case GDK_WINDOW_TYPE_HINT_MENU:
1864 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1866 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1867 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1869 case GDK_WINDOW_TYPE_HINT_UTILITY:
1870 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1872 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1873 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1875 case GDK_WINDOW_TYPE_HINT_DOCK:
1876 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1878 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1879 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1881 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
1882 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
1884 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
1885 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
1887 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
1888 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
1890 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
1891 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
1893 case GDK_WINDOW_TYPE_HINT_COMBO:
1894 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
1896 case GDK_WINDOW_TYPE_HINT_DND:
1897 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
1900 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1902 case GDK_WINDOW_TYPE_HINT_NORMAL:
1903 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1907 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1908 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1909 XA_ATOM, 32, PropModeReplace,
1910 (guchar *)&atom, 1);
1914 * gdk_window_get_type_hint:
1915 * @window: A toplevel #GdkWindow
1917 * This function returns the type hint set for a window.
1919 * Return value: The type hint set for @window
1924 gdk_window_get_type_hint (GdkWindow *window)
1926 GdkDisplay *display;
1927 GdkWindowTypeHint type;
1930 gulong nitems_return;
1931 gulong bytes_after_return;
1932 guchar *data = NULL;
1934 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
1936 if (GDK_WINDOW_DESTROYED (window) ||
1937 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1938 return GDK_WINDOW_TYPE_HINT_NORMAL;
1940 type = GDK_WINDOW_TYPE_HINT_NORMAL;
1942 display = gdk_window_get_display (window);
1944 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1945 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1946 0, G_MAXLONG, False, XA_ATOM, &type_return,
1947 &format_return, &nitems_return, &bytes_after_return,
1950 if ((type_return == XA_ATOM) && (format_return == 32) &&
1951 (data) && (nitems_return == 1))
1953 Atom atom = *(Atom*)data;
1955 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
1956 type = GDK_WINDOW_TYPE_HINT_DIALOG;
1957 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
1958 type = GDK_WINDOW_TYPE_HINT_MENU;
1959 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
1960 type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
1961 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
1962 type = GDK_WINDOW_TYPE_HINT_UTILITY;
1963 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
1964 type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
1965 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
1966 type = GDK_WINDOW_TYPE_HINT_DOCK;
1967 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
1968 type = GDK_WINDOW_TYPE_HINT_DESKTOP;
1969 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
1970 type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
1971 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
1972 type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
1973 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
1974 type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
1975 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
1976 type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
1977 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
1978 type = GDK_WINDOW_TYPE_HINT_COMBO;
1979 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
1980 type = GDK_WINDOW_TYPE_HINT_DND;
1983 if (type_return != None && data != NULL)
1991 gdk_wmspec_change_state (gboolean add,
1996 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1997 XClientMessageEvent xclient;
1999 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
2000 #define _NET_WM_STATE_ADD 1 /* add/set property */
2001 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
2003 memset (&xclient, 0, sizeof (xclient));
2004 xclient.type = ClientMessage;
2005 xclient.window = GDK_WINDOW_XID (window);
2006 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
2007 xclient.format = 32;
2008 xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
2009 xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
2010 xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
2011 xclient.data.l[3] = 0;
2012 xclient.data.l[4] = 0;
2014 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
2015 SubstructureRedirectMask | SubstructureNotifyMask,
2016 (XEvent *)&xclient);
2020 * gdk_window_set_modal_hint:
2021 * @window: A toplevel #GdkWindow
2022 * @modal: %TRUE if the window is modal, %FALSE otherwise.
2024 * The application can use this hint to tell the window manager
2025 * that a certain window has modal behaviour. The window manager
2026 * can use this information to handle modal windows in a special
2029 * You should only use this on windows for which you have
2030 * previously called gdk_window_set_transient_for()
2033 gdk_window_set_modal_hint (GdkWindow *window,
2036 if (GDK_WINDOW_DESTROYED (window) ||
2037 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2040 window->modal_hint = modal;
2042 if (GDK_WINDOW_IS_MAPPED (window))
2043 gdk_wmspec_change_state (modal, window,
2044 gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
2049 * gdk_window_set_skip_taskbar_hint:
2050 * @window: a toplevel #GdkWindow
2051 * @skips_taskbar: %TRUE to skip the taskbar
2053 * Toggles whether a window should appear in a task list or window
2054 * list. If a window's semantic type as specified with
2055 * gdk_window_set_type_hint() already fully describes the window, this
2056 * function should <emphasis>not</emphasis> be called in addition,
2057 * instead you should allow the window to be treated according to
2058 * standard policy for its semantic type.
2063 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2064 gboolean skips_taskbar)
2066 GdkToplevelX11 *toplevel;
2068 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2070 if (GDK_WINDOW_DESTROYED (window) ||
2071 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2074 toplevel = _gdk_x11_window_get_toplevel (window);
2075 toplevel->skip_taskbar_hint = skips_taskbar;
2077 if (GDK_WINDOW_IS_MAPPED (window))
2078 gdk_wmspec_change_state (skips_taskbar, window,
2079 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
2084 * gdk_window_set_skip_pager_hint:
2085 * @window: a toplevel #GdkWindow
2086 * @skips_pager: %TRUE to skip the pager
2088 * Toggles whether a window should appear in a pager (workspace
2089 * switcher, or other desktop utility program that displays a small
2090 * thumbnail representation of the windows on the desktop). If a
2091 * window's semantic type as specified with gdk_window_set_type_hint()
2092 * already fully describes the window, this function should
2093 * <emphasis>not</emphasis> be called in addition, instead you should
2094 * allow the window to be treated according to standard policy for
2095 * its semantic type.
2100 gdk_window_set_skip_pager_hint (GdkWindow *window,
2101 gboolean skips_pager)
2103 GdkToplevelX11 *toplevel;
2105 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2107 if (GDK_WINDOW_DESTROYED (window) ||
2108 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2111 toplevel = _gdk_x11_window_get_toplevel (window);
2112 toplevel->skip_pager_hint = skips_pager;
2114 if (GDK_WINDOW_IS_MAPPED (window))
2115 gdk_wmspec_change_state (skips_pager, window,
2116 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
2121 * gdk_window_set_urgency_hint:
2122 * @window: a toplevel #GdkWindow
2123 * @urgent: %TRUE if the window is urgent
2125 * Toggles whether a window needs the user's
2131 gdk_window_set_urgency_hint (GdkWindow *window,
2134 GdkToplevelX11 *toplevel;
2136 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2138 if (GDK_WINDOW_DESTROYED (window) ||
2139 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2142 toplevel = _gdk_x11_window_get_toplevel (window);
2143 toplevel->urgency_hint = urgent;
2145 update_wm_hints (window, FALSE);
2149 * gdk_window_set_geometry_hints:
2150 * @window: a toplevel #GdkWindow
2151 * @geometry: geometry hints
2152 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
2154 * Sets the geometry hints for @window. Hints flagged in @geom_mask
2155 * are set, hints not flagged in @geom_mask are unset.
2156 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
2158 * This function provides hints to the windowing system about
2159 * acceptable sizes for a toplevel window. The purpose of
2160 * this is to constrain user resizing, but the windowing system
2161 * will typically (but is not required to) also constrain the
2162 * current size of the window to the provided values and
2163 * constrain programatic resizing via gdk_window_resize() or
2164 * gdk_window_move_resize().
2166 * Note that on X11, this effect has no effect on windows
2167 * of type %GDK_WINDOW_TEMP or windows where override redirect
2168 * has been turned on via gdk_window_set_override_redirect()
2169 * since these windows are not resizable by the user.
2171 * Since you can't count on the windowing system doing the
2172 * constraints for programmatic resizes, you should generally
2173 * call gdk_window_constrain_size() yourself to determine
2174 * appropriate sizes.
2178 gdk_window_set_geometry_hints (GdkWindow *window,
2179 const GdkGeometry *geometry,
2180 GdkWindowHints geom_mask)
2182 XSizeHints size_hints;
2184 if (GDK_WINDOW_DESTROYED (window) ||
2185 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2188 size_hints.flags = 0;
2190 if (geom_mask & GDK_HINT_POS)
2192 size_hints.flags |= PPosition;
2193 /* We need to initialize the following obsolete fields because KWM
2194 * apparently uses these fields if they are non-zero.
2201 if (geom_mask & GDK_HINT_USER_POS)
2203 size_hints.flags |= USPosition;
2206 if (geom_mask & GDK_HINT_USER_SIZE)
2208 size_hints.flags |= USSize;
2211 if (geom_mask & GDK_HINT_MIN_SIZE)
2213 size_hints.flags |= PMinSize;
2214 size_hints.min_width = geometry->min_width;
2215 size_hints.min_height = geometry->min_height;
2218 if (geom_mask & GDK_HINT_MAX_SIZE)
2220 size_hints.flags |= PMaxSize;
2221 size_hints.max_width = MAX (geometry->max_width, 1);
2222 size_hints.max_height = MAX (geometry->max_height, 1);
2225 if (geom_mask & GDK_HINT_BASE_SIZE)
2227 size_hints.flags |= PBaseSize;
2228 size_hints.base_width = geometry->base_width;
2229 size_hints.base_height = geometry->base_height;
2232 if (geom_mask & GDK_HINT_RESIZE_INC)
2234 size_hints.flags |= PResizeInc;
2235 size_hints.width_inc = geometry->width_inc;
2236 size_hints.height_inc = geometry->height_inc;
2239 if (geom_mask & GDK_HINT_ASPECT)
2241 size_hints.flags |= PAspect;
2242 if (geometry->min_aspect <= 1)
2244 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2245 size_hints.min_aspect.y = 65536;
2249 size_hints.min_aspect.x = 65536;
2250 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2252 if (geometry->max_aspect <= 1)
2254 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2255 size_hints.max_aspect.y = 65536;
2259 size_hints.max_aspect.x = 65536;
2260 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2264 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2266 size_hints.flags |= PWinGravity;
2267 size_hints.win_gravity = geometry->win_gravity;
2270 /* FIXME: Would it be better to delete this property if
2271 * geom_mask == 0? It would save space on the server
2273 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2274 GDK_WINDOW_XID (window),
2279 gdk_window_get_geometry_hints (GdkWindow *window,
2280 GdkGeometry *geometry,
2281 GdkWindowHints *geom_mask)
2283 XSizeHints *size_hints;
2284 glong junk_supplied_mask = 0;
2286 g_return_if_fail (GDK_IS_WINDOW (window));
2287 g_return_if_fail (geometry != NULL);
2288 g_return_if_fail (geom_mask != NULL);
2292 if (GDK_WINDOW_DESTROYED (window) ||
2293 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2296 size_hints = XAllocSizeHints ();
2300 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2301 GDK_WINDOW_XID (window),
2303 &junk_supplied_mask))
2304 size_hints->flags = 0;
2306 if (size_hints->flags & PMinSize)
2308 *geom_mask |= GDK_HINT_MIN_SIZE;
2309 geometry->min_width = size_hints->min_width;
2310 geometry->min_height = size_hints->min_height;
2313 if (size_hints->flags & PMaxSize)
2315 *geom_mask |= GDK_HINT_MAX_SIZE;
2316 geometry->max_width = MAX (size_hints->max_width, 1);
2317 geometry->max_height = MAX (size_hints->max_height, 1);
2320 if (size_hints->flags & PResizeInc)
2322 *geom_mask |= GDK_HINT_RESIZE_INC;
2323 geometry->width_inc = size_hints->width_inc;
2324 geometry->height_inc = size_hints->height_inc;
2327 if (size_hints->flags & PAspect)
2329 *geom_mask |= GDK_HINT_ASPECT;
2331 geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y;
2332 geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y;
2335 if (size_hints->flags & PWinGravity)
2337 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2338 geometry->win_gravity = size_hints->win_gravity;
2345 utf8_is_latin1 (const gchar *str)
2347 const char *p = str;
2351 gunichar ch = g_utf8_get_char (p);
2356 p = g_utf8_next_char (p);
2362 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2363 * convertable to STRING, otherwise, set it as compound text
2366 set_text_property (GdkDisplay *display,
2369 const gchar *utf8_str)
2371 gchar *prop_text = NULL;
2375 gboolean is_compound_text;
2377 if (utf8_is_latin1 (utf8_str))
2379 prop_type = XA_STRING;
2380 prop_text = gdk_utf8_to_string_target (utf8_str);
2381 prop_length = prop_text ? strlen (prop_text) : 0;
2383 is_compound_text = FALSE;
2389 gdk_utf8_to_compound_text_for_display (display,
2390 utf8_str, &gdk_type, &prop_format,
2391 (guchar **)&prop_text, &prop_length);
2392 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2393 is_compound_text = TRUE;
2398 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2401 prop_type, prop_format,
2402 PropModeReplace, (guchar *)prop_text,
2405 if (is_compound_text)
2406 gdk_free_compound_text ((guchar *)prop_text);
2412 /* Set WM_NAME and _NET_WM_NAME
2415 set_wm_name (GdkDisplay *display,
2419 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2420 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2421 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2422 PropModeReplace, (guchar *)name, strlen (name));
2424 set_text_property (display, xwindow,
2425 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2430 * gdk_window_set_title:
2431 * @window: a toplevel #GdkWindow
2432 * @title: title of @window
2434 * Sets the title of a toplevel window, to be displayed in the titlebar.
2435 * If you haven't explicitly set the icon name for the window
2436 * (using gdk_window_set_icon_name()), the icon name will be set to
2437 * @title as well. @title must be in UTF-8 encoding (as with all
2438 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2441 gdk_window_set_title (GdkWindow *window,
2444 GdkDisplay *display;
2448 g_return_if_fail (title != NULL);
2450 if (GDK_WINDOW_DESTROYED (window) ||
2451 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2454 display = gdk_window_get_display (window);
2455 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2456 xwindow = GDK_WINDOW_XID (window);
2458 set_wm_name (display, xwindow, title);
2460 if (!gdk_window_icon_name_set (window))
2462 XChangeProperty (xdisplay, xwindow,
2463 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2464 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2465 PropModeReplace, (guchar *)title, strlen (title));
2467 set_text_property (display, xwindow,
2468 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2474 * gdk_window_set_role:
2475 * @window: a toplevel #GdkWindow
2476 * @role: a string indicating its role
2478 * When using GTK+, typically you should use gtk_window_set_role() instead
2479 * of this low-level function.
2481 * The window manager and session manager use a window's role to
2482 * distinguish it from other kinds of window in the same application.
2483 * When an application is restarted after being saved in a previous
2484 * session, all windows with the same title and role are treated as
2485 * interchangeable. So if you have two windows with the same title
2486 * that should be distinguished for session management purposes, you
2487 * should set the role on those windows. It doesn't matter what string
2488 * you use for the role, as long as you have a different role for each
2489 * non-interchangeable kind of window.
2493 gdk_window_set_role (GdkWindow *window,
2496 GdkDisplay *display;
2498 display = gdk_window_get_display (window);
2500 if (GDK_WINDOW_DESTROYED (window) ||
2501 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2505 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2506 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2507 XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
2509 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2510 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2514 * gdk_window_set_startup_id:
2515 * @window: a toplevel #GdkWindow
2516 * @startup_id: a string with startup-notification identifier
2518 * When using GTK+, typically you should use gtk_window_set_startup_id()
2519 * instead of this low-level function.
2525 gdk_window_set_startup_id (GdkWindow *window,
2526 const gchar *startup_id)
2528 GdkDisplay *display;
2530 g_return_if_fail (GDK_IS_WINDOW (window));
2532 display = gdk_window_get_display (window);
2534 if (GDK_WINDOW_DESTROYED (window) ||
2535 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2539 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2540 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2541 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2542 PropModeReplace, (unsigned char *)startup_id, strlen (startup_id));
2544 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2545 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"));
2549 * gdk_window_set_transient_for:
2550 * @window: a toplevel #GdkWindow
2551 * @parent: another toplevel #GdkWindow
2553 * Indicates to the window manager that @window is a transient dialog
2554 * associated with the application window @parent. This allows the
2555 * window manager to do things like center @window on @parent and
2556 * keep @window above @parent.
2558 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2562 gdk_window_set_transient_for (GdkWindow *window,
2565 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) &&
2566 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2567 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2568 GDK_WINDOW_XID (window),
2569 GDK_WINDOW_XID (parent));
2573 gdk_window_x11_set_back_color (GdkWindow *window,
2579 GdkVisual *visual = gdk_window_get_visual (window);
2581 /* I suppose we could handle these, but that'd require fiddling with
2582 * xrender formats... */
2586 switch (visual->type)
2588 case GDK_VISUAL_DIRECT_COLOR:
2589 case GDK_VISUAL_TRUE_COLOR:
2591 /* If bits not used for color are used for something other than padding,
2592 * it's likely alpha, so we set them to 1s.
2594 guint padding, pixel;
2596 /* Shifting by >= width-of-type isn't defined in C */
2597 if (visual->depth >= 32)
2600 padding = ((~(guint32)0)) << visual->depth;
2602 pixel = ~ (visual->red_mask | visual->green_mask | visual->blue_mask | padding);
2604 pixel += (((int) (red * ((1 << visual->red_prec ) - 1))) << visual->red_shift ) +
2605 (((int) (green * ((1 << visual->green_prec) - 1))) << visual->green_shift) +
2606 (((int) (blue * ((1 << visual->blue_prec ) - 1))) << visual->blue_shift );
2608 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2609 GDK_WINDOW_XID (window), pixel);
2613 /* These require fiddling with the colormap, and as they're essentially unused
2614 * we're just gonna skip them for now.
2616 case GDK_VISUAL_PSEUDO_COLOR:
2617 case GDK_VISUAL_GRAYSCALE:
2618 case GDK_VISUAL_STATIC_GRAY:
2619 case GDK_VISUAL_STATIC_COLOR:
2628 matrix_is_identity (cairo_matrix_t *matrix)
2630 return matrix->xx == 1.0 && matrix->yy == 1.0 &&
2631 matrix->yx == 0.0 && matrix->xy == 0.0 &&
2632 matrix->x0 == 0.0 && matrix->y0 == 0.0;
2636 gdk_window_x11_set_background (GdkWindow *window,
2637 cairo_pattern_t *pattern)
2640 cairo_surface_t *surface;
2641 cairo_matrix_t matrix;
2643 if (GDK_WINDOW_DESTROYED (window))
2646 if (pattern == NULL)
2650 /* X throws BadMatch if the parent has a different visual when
2651 * using ParentRelative */
2652 parent = gdk_window_get_parent (window);
2653 if (parent && gdk_window_get_visual (parent) == gdk_window_get_visual (window))
2654 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2655 GDK_WINDOW_XID (window), ParentRelative);
2657 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2658 GDK_WINDOW_XID (window), None);
2662 switch (cairo_pattern_get_type (pattern))
2664 case CAIRO_PATTERN_TYPE_SOLID:
2665 cairo_pattern_get_rgba (pattern, &r, &g, &b, &a);
2666 if (gdk_window_x11_set_back_color (window, r, g, b, a))
2669 case CAIRO_PATTERN_TYPE_SURFACE:
2670 cairo_pattern_get_matrix (pattern, &matrix);
2671 if (cairo_pattern_get_surface (pattern, &surface) == CAIRO_STATUS_SUCCESS &&
2672 matrix_is_identity (&matrix) &&
2673 cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB &&
2674 cairo_xlib_surface_get_visual (surface) == GDK_VISUAL_XVISUAL (gdk_window_get_visual ((window))) &&
2675 cairo_xlib_surface_get_display (surface) == GDK_WINDOW_XDISPLAY (window))
2679 cairo_surface_get_device_offset (surface, &x, &y);
2680 /* XXX: This still bombs for non-pixmaps, but there's no way to
2681 * detect we're not a pixmap in Cairo... */
2682 if (x == 0.0 && y == 0.0)
2684 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2685 GDK_WINDOW_XID (window),
2686 cairo_xlib_surface_get_drawable (surface));
2691 case CAIRO_PATTERN_TYPE_LINEAR:
2692 case CAIRO_PATTERN_TYPE_RADIAL:
2694 /* fallback: just use black */
2698 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2699 GDK_WINDOW_XID (window), None);
2703 gdk_window_x11_set_device_cursor (GdkWindow *window,
2707 GdkWindowImplX11 *impl;
2709 g_return_if_fail (GDK_IS_WINDOW (window));
2710 g_return_if_fail (GDK_IS_DEVICE (device));
2712 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2715 g_hash_table_remove (impl->device_cursor, device);
2718 _gdk_x11_cursor_update_theme (cursor);
2719 g_hash_table_replace (impl->device_cursor,
2720 device, gdk_cursor_ref (cursor));
2723 if (!GDK_WINDOW_DESTROYED (window))
2724 GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor);
2728 _gdk_x11_window_get_cursor (GdkWindow *window)
2730 GdkWindowImplX11 *impl;
2732 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2734 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2736 return impl->cursor;
2740 gdk_window_x11_get_geometry (GdkWindow *window,
2752 guint tborder_width;
2755 if (!GDK_WINDOW_DESTROYED (window))
2757 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2758 GDK_WINDOW_XID (window),
2759 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2775 gdk_window_x11_get_root_coords (GdkWindow *window,
2786 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2787 GDK_WINDOW_XID (window),
2788 GDK_WINDOW_XROOTWIN (window),
2801 * gdk_window_get_root_origin:
2802 * @window: a toplevel #GdkWindow
2803 * @x: return location for X position of window frame
2804 * @y: return location for Y position of window frame
2806 * Obtains the top-left corner of the window manager frame in root
2807 * window coordinates.
2811 gdk_window_get_root_origin (GdkWindow *window,
2817 gdk_window_get_frame_extents (window, &rect);
2827 * gdk_window_get_frame_extents:
2828 * @window: a toplevel #GdkWindow
2829 * @rect: rectangle to fill with bounding box of the window frame
2831 * Obtains the bounding box of the window, including window manager
2832 * titlebar/borders if any. The frame position is given in root window
2833 * coordinates. To get the position of the window itself (rather than
2834 * the frame) in root window coordinates, use gdk_window_get_origin().
2838 gdk_window_get_frame_extents (GdkWindow *window,
2841 GdkDisplay *display;
2842 GdkWindowImplX11 *impl;
2853 gulong nitems_return;
2854 gulong bytes_after_return;
2857 guint ww, wh, wb, wd;
2859 gboolean got_frame_extents = FALSE;
2861 g_return_if_fail (rect != NULL);
2868 while (window->parent && (window->parent)->parent)
2869 window = window->parent;
2871 /* Refine our fallback answer a bit using local information */
2872 rect->x = window->x;
2873 rect->y = window->y;
2874 rect->width = window->width;
2875 rect->height = window->height;
2877 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2878 if (GDK_WINDOW_DESTROYED (window) || impl->override_redirect)
2884 gdk_error_trap_push();
2886 display = gdk_window_get_display (window);
2887 xwindow = GDK_WINDOW_XID (window);
2889 /* first try: use _NET_FRAME_EXTENTS */
2890 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2891 gdk_x11_get_xatom_by_name_for_display (display,
2892 "_NET_FRAME_EXTENTS"),
2893 0, G_MAXLONG, False, XA_CARDINAL, &type_return,
2894 &format_return, &nitems_return, &bytes_after_return,
2898 if ((type_return == XA_CARDINAL) && (format_return == 32) &&
2899 (nitems_return == 4) && (data))
2901 gulong *ldata = (gulong *) data;
2902 got_frame_extents = TRUE;
2904 /* try to get the real client window geometry */
2905 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2906 &root, &wx, &wy, &ww, &wh, &wb, &wd) &&
2907 XTranslateCoordinates (GDK_DISPLAY_XDISPLAY (display),
2908 xwindow, root, 0, 0, &wx, &wy, &child))
2916 /* _NET_FRAME_EXTENTS format is left, right, top, bottom */
2917 rect->x -= ldata[0];
2918 rect->y -= ldata[2];
2919 rect->width += ldata[0] + ldata[1];
2920 rect->height += ldata[2] + ldata[3];
2927 if (got_frame_extents)
2930 /* no frame extents property available, which means we either have a WM that
2931 is not EWMH compliant or is broken - try fallback and walk up the window
2932 tree to get our window's parent which hopefully is the window frame */
2934 /* use NETWM_VIRTUAL_ROOTS if available */
2935 root = GDK_WINDOW_XROOTWIN (window);
2937 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
2938 gdk_x11_get_xatom_by_name_for_display (display,
2939 "_NET_VIRTUAL_ROOTS"),
2940 0, G_MAXLONG, False, XA_WINDOW, &type_return,
2941 &format_return, &nitems_return, &bytes_after_return,
2945 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
2947 nvroots = nitems_return;
2948 vroots = (Window *)data;
2952 xparent = GDK_WINDOW_XID (window);
2958 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
2960 &children, &nchildren))
2966 /* check virtual roots */
2967 for (i = 0; i < nvroots; i++)
2969 if (xparent == vroots[i])
2976 while (xparent != root);
2978 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2979 &root, &wx, &wy, &ww, &wh, &wb, &wd))
2991 gdk_error_trap_pop_ignored ();
2995 _gdk_windowing_get_device_state (GdkDisplay *display,
3000 GdkModifierType *mask)
3002 GdkScreen *default_screen;
3004 if (display->closed)
3007 default_screen = gdk_display_get_default_screen (display);
3010 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3014 GDK_DEVICE_GET_CLASS (device)->query_state (device,
3015 gdk_screen_get_root_window (default_screen),
3020 *screen = gdk_window_get_screen (root);
3024 XSetWindowAttributes attributes;
3026 Window xwindow, w, root, child;
3027 int rootx, rooty, winx, winy;
3030 /* FIXME: untrusted clients not multidevice-safe */
3032 xdisplay = GDK_SCREEN_XDISPLAY (default_screen);
3033 xwindow = GDK_SCREEN_XROOTWIN (default_screen);
3035 w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0,
3036 CopyFromParent, InputOnly, CopyFromParent,
3038 XQueryPointer (xdisplay, w,
3039 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3040 XDestroyWindow (xdisplay, w);
3044 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
3045 *screen = gdk_window_get_screen (gdk_root);
3055 gdk_window_x11_get_device_state (GdkWindow *window,
3059 GdkModifierType *mask)
3061 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
3062 gboolean return_val;
3064 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
3068 if (!GDK_WINDOW_DESTROYED (window))
3070 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3074 GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
3078 return_val = (child != NULL);
3083 int originx, originy;
3087 unsigned int xmask = 0;
3089 _gdk_windowing_get_device_state (gdk_window_get_display (window), device,
3090 &screen, &rootx, &rooty, &xmask);
3091 gdk_window_get_origin (window, &originx, &originy);
3092 winx = rootx - originx;
3093 winy = rooty - originy;
3105 * gdk_display_warp_pointer:
3106 * @display: a #GdkDisplay
3107 * @screen: the screen of @display to warp the pointer to
3108 * @x: the x coordinate of the destination
3109 * @y: the y coordinate of the destination
3111 * Warps the pointer of @display to the point @x,@y on
3112 * the screen @screen, unless the pointer is confined
3113 * to a window by a grab, in which case it will be moved
3114 * as far as allowed by the grab. Warping the pointer
3115 * creates events as if the user had moved the mouse
3116 * instantaneously to the destination.
3118 * Note that the pointer should normally be under the
3119 * control of the user. This function was added to cover
3120 * some rare use cases like keyboard navigation support
3121 * for the color picker in the #GtkColorSelectionDialog.
3125 * Deprecated: 3.0: Use gdk_display_warp_device() instead.
3128 gdk_display_warp_pointer (GdkDisplay *display,
3135 g_return_if_fail (GDK_IS_DISPLAY (display));
3136 g_return_if_fail (GDK_IS_SCREEN (screen));
3138 device = display->core_pointer;
3139 GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
3143 * gdk_display_warp_device:
3144 * @display: a #GdkDisplay.
3145 * @device: a #GdkDevice.
3146 * @screen: the screen of @display to warp @device to.
3147 * @x: the X coordinate of the destination.
3148 * @y: the Y coordinate of the destination.
3150 * Warps @device in @display to the point @x,@y on
3151 * the screen @screen, unless the device is confined
3152 * to a window by a grab, in which case it will be moved
3153 * as far as allowed by the grab. Warping the pointer
3154 * creates events as if the user had moved the mouse
3155 * instantaneously to the destination.
3157 * Note that the pointer should normally be under the
3158 * control of the user. This function was added to cover
3159 * some rare use cases like keyboard navigation support
3160 * for the color picker in the #GtkColorSelectionDialog.
3165 gdk_display_warp_device (GdkDisplay *display,
3171 g_return_if_fail (GDK_IS_DISPLAY (display));
3172 g_return_if_fail (GDK_IS_DEVICE (device));
3173 g_return_if_fail (GDK_IS_SCREEN (screen));
3174 g_return_if_fail (display == gdk_device_get_display (device));
3176 GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
3180 _gdk_windowing_window_at_device_position (GdkDisplay *display,
3184 GdkModifierType *mask,
3185 gboolean get_toplevel)
3190 screen = gdk_display_get_default_screen (display);
3192 /* This function really only works if the mouse pointer is held still
3193 * during its operation. If it moves from one leaf window to another
3194 * than we'll end up with inaccurate values for win_x, win_y
3197 gdk_x11_display_grab (display);
3198 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3199 window = GDK_DEVICE_GET_CLASS (device)->window_at_position (device, win_x, win_y, mask, get_toplevel);
3202 gint i, screens, width, height;
3203 GList *toplevels, *list;
3204 Window pointer_window, root, xwindow, child;
3205 Window xwindow_last = 0;
3207 int rootx = -1, rooty = -1;
3211 /* FIXME: untrusted clients case not multidevice-safe */
3213 xwindow = GDK_SCREEN_XROOTWIN (screen);
3214 xdisplay = GDK_SCREEN_XDISPLAY (screen);
3216 pointer_window = None;
3217 screens = gdk_display_get_n_screens (display);
3218 for (i = 0; i < screens; ++i) {
3219 screen = gdk_display_get_screen (display, i);
3220 toplevels = gdk_screen_get_toplevel_windows (screen);
3221 for (list = toplevels; list != NULL; list = g_list_next (list)) {
3222 window = GDK_WINDOW (list->data);
3223 xwindow = GDK_WINDOW_XID (window);
3224 gdk_error_trap_push ();
3225 XQueryPointer (xdisplay, xwindow,
3226 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3227 if (gdk_error_trap_pop ())
3231 pointer_window = child;
3234 gdk_window_get_geometry (window, NULL, NULL, &width, &height, NULL);
3235 if (winx >= 0 && winy >= 0 && winx < width && winy < height)
3237 /* A childless toplevel, or below another window? */
3238 XSetWindowAttributes attributes;
3241 w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0,
3242 CopyFromParent, InputOnly, CopyFromParent,
3244 XMapWindow (xdisplay, w);
3245 XQueryPointer (xdisplay, xwindow,
3246 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3247 XDestroyWindow (xdisplay, w);
3250 pointer_window = xwindow;
3255 g_list_free (toplevels);
3256 if (pointer_window != None)
3259 xwindow = pointer_window;
3263 xwindow_last = xwindow;
3264 gdk_error_trap_push ();
3265 XQueryPointer (xdisplay, xwindow,
3266 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3267 if (gdk_error_trap_pop ())
3269 if (get_toplevel && xwindow_last != root &&
3270 (window = gdk_window_lookup_for_display (display, xwindow_last)) != NULL &&
3271 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
3275 window = gdk_window_lookup_for_display (display, xwindow_last);
3277 *win_x = window ? winx : -1;
3278 *win_y = window ? winy : -1;
3283 gdk_x11_display_ungrab (display);
3289 gdk_window_x11_get_events (GdkWindow *window)
3291 XWindowAttributes attrs;
3292 GdkEventMask event_mask;
3293 GdkEventMask filtered;
3295 if (GDK_WINDOW_DESTROYED (window))
3299 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3300 GDK_WINDOW_XID (window),
3302 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
3303 /* if property change was filtered out before, keep it filtered out */
3304 filtered = GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK;
3305 window->event_mask = event_mask & ((window->event_mask & filtered) | ~filtered);
3311 gdk_window_x11_set_events (GdkWindow *window,
3312 GdkEventMask event_mask)
3314 long xevent_mask = 0;
3316 if (!GDK_WINDOW_DESTROYED (window))
3318 GdkDisplayX11 *display_x11;
3320 if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window))
3321 xevent_mask = StructureNotifyMask | PropertyChangeMask;
3323 display_x11 = GDK_DISPLAY_X11 (gdk_window_get_display (window));
3324 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
3325 GDK_WINDOW_XID (window), event_mask,
3331 do_shape_combine_region (GdkWindow *window,
3332 const cairo_region_t *shape_region,
3337 if (GDK_WINDOW_DESTROYED (window))
3340 if (shape_region == NULL)
3342 /* Use NULL mask to unset the shape */
3343 if (shape == ShapeBounding
3344 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3345 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3347 if (shape == ShapeBounding)
3349 _gdk_x11_window_tmp_unset_parent_bg (window);
3350 _gdk_x11_window_tmp_unset_bg (window, TRUE);
3352 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3353 GDK_WINDOW_XID (window),
3358 if (shape == ShapeBounding)
3360 _gdk_x11_window_tmp_reset_parent_bg (window);
3361 _gdk_x11_window_tmp_reset_bg (window, TRUE);
3367 if (shape == ShapeBounding
3368 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3369 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3372 XRectangle *xrects = NULL;
3374 _gdk_region_get_xrectangles (shape_region,
3378 if (shape == ShapeBounding)
3380 _gdk_x11_window_tmp_unset_parent_bg (window);
3381 _gdk_x11_window_tmp_unset_bg (window, TRUE);
3383 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3384 GDK_WINDOW_XID (window),
3391 if (shape == ShapeBounding)
3393 _gdk_x11_window_tmp_reset_parent_bg (window);
3394 _gdk_x11_window_tmp_reset_bg (window, TRUE);
3402 gdk_window_x11_shape_combine_region (GdkWindow *window,
3403 const cairo_region_t *shape_region,
3407 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
3411 gdk_window_x11_input_shape_combine_region (GdkWindow *window,
3412 const cairo_region_t *shape_region,
3417 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
3423 * gdk_window_set_override_redirect:
3424 * @window: a toplevel #GdkWindow
3425 * @override_redirect: %TRUE if window should be override redirect
3427 * An override redirect window is not under the control of the window manager.
3428 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3429 * be entirely under the control of the application. The window manager
3430 * can't see the override redirect window at all.
3432 * Override redirect should only be used for short-lived temporary
3433 * windows, such as popup menus. #GtkMenu uses an override redirect
3434 * window in its implementation, for example.
3438 gdk_window_set_override_redirect (GdkWindow *window,
3439 gboolean override_redirect)
3441 XSetWindowAttributes attr;
3443 if (!GDK_WINDOW_DESTROYED (window) &&
3444 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3446 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
3448 attr.override_redirect = (override_redirect? True : False);
3449 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3450 GDK_WINDOW_XID (window),
3454 impl->override_redirect = attr.override_redirect;
3459 * gdk_window_set_accept_focus:
3460 * @window: a toplevel #GdkWindow
3461 * @accept_focus: %TRUE if the window should receive input focus
3463 * Setting @accept_focus to %FALSE hints the desktop environment that the
3464 * window doesn't want to receive input focus.
3466 * On X, it is the responsibility of the window manager to interpret this
3467 * hint. ICCCM-compliant window manager usually respect it.
3472 gdk_window_set_accept_focus (GdkWindow *window,
3473 gboolean accept_focus)
3475 accept_focus = accept_focus != FALSE;
3477 if (window->accept_focus != accept_focus)
3479 window->accept_focus = accept_focus;
3481 if (!GDK_WINDOW_DESTROYED (window) &&
3482 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3483 update_wm_hints (window, FALSE);
3488 * gdk_window_set_focus_on_map:
3489 * @window: a toplevel #GdkWindow
3490 * @focus_on_map: %TRUE if the window should receive input focus when mapped
3492 * Setting @focus_on_map to %FALSE hints the desktop environment that the
3493 * window doesn't want to receive input focus when it is mapped.
3494 * focus_on_map should be turned off for windows that aren't triggered
3495 * interactively (such as popups from network activity).
3497 * On X, it is the responsibility of the window manager to interpret
3498 * this hint. Window managers following the freedesktop.org window
3499 * manager extension specification should respect it.
3504 gdk_window_set_focus_on_map (GdkWindow *window,
3505 gboolean focus_on_map)
3507 focus_on_map = focus_on_map != FALSE;
3509 if (window->focus_on_map != focus_on_map)
3511 window->focus_on_map = focus_on_map;
3513 if ((!GDK_WINDOW_DESTROYED (window)) &&
3514 (!window->focus_on_map) &&
3515 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3516 gdk_x11_window_set_user_time (window, 0);
3521 * gdk_x11_window_set_user_time:
3522 * @window: A toplevel #GdkWindow
3523 * @timestamp: An XServer timestamp to which the property should be set
3525 * The application can use this call to update the _NET_WM_USER_TIME
3526 * property on a toplevel window. This property stores an Xserver
3527 * time which represents the time of the last user input event
3528 * received for this window. This property may be used by the window
3529 * manager to alter the focus, stacking, and/or placement behavior of
3530 * windows when they are mapped depending on whether the new window
3531 * was created by a user action or is a "pop-up" window activated by a
3532 * timer or some other event.
3534 * Note that this property is automatically updated by GDK, so this
3535 * function should only be used by applications which handle input
3536 * events bypassing GDK.
3541 gdk_x11_window_set_user_time (GdkWindow *window,
3544 GdkDisplay *display;
3545 GdkDisplayX11 *display_x11;
3546 GdkToplevelX11 *toplevel;
3547 glong timestamp_long = (glong)timestamp;
3550 if (GDK_WINDOW_DESTROYED (window) ||
3551 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3554 display = gdk_window_get_display (window);
3555 display_x11 = GDK_DISPLAY_X11 (display);
3556 toplevel = _gdk_x11_window_get_toplevel (window);
3560 g_warning ("gdk_window_set_user_time called on non-toplevel\n");
3564 if (toplevel->focus_window != None &&
3565 gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
3566 gdk_atom_intern_static_string ("_NET_WM_USER_TIME_WINDOW")))
3567 xid = toplevel->focus_window;
3569 xid = GDK_WINDOW_XID (window);
3571 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xid,
3572 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3573 XA_CARDINAL, 32, PropModeReplace,
3574 (guchar *)×tamp_long, 1);
3576 if (timestamp_long != GDK_CURRENT_TIME &&
3577 (display_x11->user_time == GDK_CURRENT_TIME ||
3578 XSERVER_TIME_IS_LATER (timestamp_long, display_x11->user_time)))
3579 display_x11->user_time = timestamp_long;
3582 toplevel->user_time = timestamp_long;
3585 #define GDK_SELECTION_MAX_SIZE(display) \
3587 XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
3588 ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
3589 : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
3592 gdk_window_update_icon (GdkWindow *window,
3595 GdkToplevelX11 *toplevel;
3596 GdkPixbuf *best_icon;
3600 toplevel = _gdk_x11_window_get_toplevel (window);
3602 if (toplevel->icon_pixmap != NULL)
3604 cairo_surface_destroy (toplevel->icon_pixmap);
3605 toplevel->icon_pixmap = NULL;
3608 if (toplevel->icon_mask != NULL)
3610 cairo_surface_destroy (toplevel->icon_mask);
3611 toplevel->icon_mask = NULL;
3614 #define IDEAL_SIZE 48
3616 best_size = G_MAXINT;
3618 for (tmp_list = icon_list; tmp_list; tmp_list = tmp_list->next)
3620 GdkPixbuf *pixbuf = tmp_list->data;
3623 /* average width and height - if someone passes in a rectangular
3624 * icon they deserve what they get.
3626 this = gdk_pixbuf_get_width (pixbuf) + gdk_pixbuf_get_height (pixbuf);
3629 if (best_icon == NULL)
3636 /* icon is better if it's 32 pixels or larger, and closer to
3637 * the ideal size than the current best.
3640 (ABS (best_size - IDEAL_SIZE) <
3641 ABS (this - IDEAL_SIZE)))
3651 int width = gdk_pixbuf_get_width (best_icon);
3652 int height = gdk_pixbuf_get_height (best_icon);
3655 toplevel->icon_pixmap = gdk_x11_window_create_pixmap_surface (window,
3659 cr = cairo_create (toplevel->icon_pixmap);
3660 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3661 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3662 if (gdk_pixbuf_get_has_alpha (best_icon))
3664 /* Saturate the image, so it has bilevel alpha */
3665 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
3667 cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);
3669 cairo_pop_group_to_source (cr);
3674 if (gdk_pixbuf_get_has_alpha (best_icon))
3676 toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window,
3680 cr = cairo_create (toplevel->icon_mask);
3681 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3682 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3688 update_wm_hints (window, FALSE);
3692 * gdk_window_set_icon_list:
3693 * @window: The #GdkWindow toplevel window to set the icon of.
3694 * @pixbufs: (transfer none) (element-type GdkPixbuf):
3695 * A list of pixbufs, of different sizes.
3697 * Sets a list of icons for the window. One of these will be used
3698 * to represent the window when it has been iconified. The icon is
3699 * usually shown in an icon box or some sort of task bar. Which icon
3700 * size is shown depends on the window manager. The window manager
3701 * can scale the icon but setting several size icons can give better
3702 * image quality since the window manager may only need to scale the
3703 * icon by a small amount or not at all.
3707 gdk_window_set_icon_list (GdkWindow *window,
3716 gint width, height, stride;
3719 GdkDisplay *display;
3722 if (GDK_WINDOW_DESTROYED (window) ||
3723 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3726 display = gdk_window_get_display (window);
3734 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3736 width = gdk_pixbuf_get_width (pixbuf);
3737 height = gdk_pixbuf_get_height (pixbuf);
3739 /* silently ignore overlarge icons */
3740 if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
3742 g_warning ("gdk_window_set_icon_list: icons too large");
3747 size += 2 + width * height;
3749 l = g_list_next (l);
3752 data = g_malloc (size * sizeof (gulong));
3760 width = gdk_pixbuf_get_width (pixbuf);
3761 height = gdk_pixbuf_get_height (pixbuf);
3762 stride = gdk_pixbuf_get_rowstride (pixbuf);
3763 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3768 pixels = gdk_pixbuf_get_pixels (pixbuf);
3770 for (y = 0; y < height; y++)
3772 for (x = 0; x < width; x++)
3776 r = pixels[y*stride + x*n_channels + 0];
3777 g = pixels[y*stride + x*n_channels + 1];
3778 b = pixels[y*stride + x*n_channels + 2];
3779 if (n_channels >= 4)
3780 a = pixels[y*stride + x*n_channels + 3];
3784 *p++ = a << 24 | r << 16 | g << 8 | b ;
3788 l = g_list_next (l);
3794 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3795 GDK_WINDOW_XID (window),
3796 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3799 (guchar*) data, size);
3803 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3804 GDK_WINDOW_XID (window),
3805 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3810 gdk_window_update_icon (window, pixbufs);
3814 gdk_window_icon_name_set (GdkWindow *window)
3816 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3817 g_quark_from_static_string ("gdk-icon-name-set")));
3821 * gdk_window_set_icon_name:
3822 * @window: a toplevel #GdkWindow
3823 * @name: name of window while iconified (minimized)
3825 * Windows may have a name used while minimized, distinct from the
3826 * name they display in their titlebar. Most of the time this is a bad
3827 * idea from a user interface standpoint. But you can set such a name
3828 * with this function, if you like.
3830 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
3831 * will not update the icon title.
3833 * Using %NULL for @name unsets the icon title; further calls to
3834 * gdk_window_set_title() will again update the icon title as well.
3837 gdk_window_set_icon_name (GdkWindow *window,
3840 GdkDisplay *display;
3842 if (GDK_WINDOW_DESTROYED (window) ||
3843 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3846 display = gdk_window_get_display (window);
3848 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3849 GUINT_TO_POINTER (name != NULL));
3853 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3854 GDK_WINDOW_XID (window),
3855 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3856 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3857 PropModeReplace, (guchar *)name, strlen (name));
3859 set_text_property (display, GDK_WINDOW_XID (window),
3860 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3865 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3866 GDK_WINDOW_XID (window),
3867 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"));
3868 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3869 GDK_WINDOW_XID (window),
3870 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"));
3875 * gdk_window_iconify:
3876 * @window: a toplevel #GdkWindow
3878 * Asks to iconify (minimize) @window. The window manager may choose
3879 * to ignore the request, but normally will honor it. Using
3880 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3882 * This function only makes sense when @window is a toplevel window.
3886 gdk_window_iconify (GdkWindow *window)
3888 if (GDK_WINDOW_DESTROYED (window) ||
3889 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3892 if (GDK_WINDOW_IS_MAPPED (window))
3894 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3895 GDK_WINDOW_XID (window),
3896 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3900 /* Flip our client side flag, the real work happens on map. */
3901 gdk_synthesize_window_state (window,
3903 GDK_WINDOW_STATE_ICONIFIED);
3908 * gdk_window_deiconify:
3909 * @window: a toplevel #GdkWindow
3911 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3912 * choose to ignore the request to deiconify. When using GTK+,
3913 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3914 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3915 * unminimizes it, and puts it on the current desktop.
3919 gdk_window_deiconify (GdkWindow *window)
3921 if (GDK_WINDOW_DESTROYED (window) ||
3922 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3925 if (GDK_WINDOW_IS_MAPPED (window))
3927 gdk_window_show (window);
3931 /* Flip our client side flag, the real work happens on map. */
3932 gdk_synthesize_window_state (window,
3933 GDK_WINDOW_STATE_ICONIFIED,
3940 * @window: a toplevel #GdkWindow
3942 * "Pins" a window such that it's on all workspaces and does not scroll
3943 * with viewports, for window managers that have scrollable viewports.
3944 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3946 * On the X11 platform, this function depends on window manager
3947 * support, so may have no effect with many window managers. However,
3948 * GDK will do the best it can to convince the window manager to stick
3949 * the window. For window managers that don't support this operation,
3950 * there's nothing you can do to force it to happen.
3954 gdk_window_stick (GdkWindow *window)
3956 if (GDK_WINDOW_DESTROYED (window) ||
3957 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3960 if (GDK_WINDOW_IS_MAPPED (window))
3962 /* "stick" means stick to all desktops _and_ do not scroll with the
3963 * viewport. i.e. glue to the monitor glass in all cases.
3966 XClientMessageEvent xclient;
3968 /* Request stick during viewport scroll */
3969 gdk_wmspec_change_state (TRUE, window,
3970 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
3973 /* Request desktop 0xFFFFFFFF */
3974 memset (&xclient, 0, sizeof (xclient));
3975 xclient.type = ClientMessage;
3976 xclient.window = GDK_WINDOW_XID (window);
3977 xclient.display = GDK_WINDOW_XDISPLAY (window);
3978 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3980 xclient.format = 32;
3982 xclient.data.l[0] = 0xFFFFFFFF;
3983 xclient.data.l[1] = 0;
3984 xclient.data.l[2] = 0;
3985 xclient.data.l[3] = 0;
3986 xclient.data.l[4] = 0;
3988 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3989 SubstructureRedirectMask | SubstructureNotifyMask,
3990 (XEvent *)&xclient);
3994 /* Flip our client side flag, the real work happens on map. */
3995 gdk_synthesize_window_state (window,
3997 GDK_WINDOW_STATE_STICKY);
4002 * gdk_window_unstick:
4003 * @window: a toplevel #GdkWindow
4005 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
4006 * and gtk_window_unstick().
4010 gdk_window_unstick (GdkWindow *window)
4012 if (GDK_WINDOW_DESTROYED (window) ||
4013 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4016 if (GDK_WINDOW_IS_MAPPED (window))
4018 /* Request unstick from viewport */
4019 gdk_wmspec_change_state (FALSE, window,
4020 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4023 move_to_current_desktop (window);
4027 /* Flip our client side flag, the real work happens on map. */
4028 gdk_synthesize_window_state (window,
4029 GDK_WINDOW_STATE_STICKY,
4036 * gdk_window_maximize:
4037 * @window: a toplevel #GdkWindow
4039 * Maximizes the window. If the window was already maximized, then
4040 * this function does nothing.
4042 * On X11, asks the window manager to maximize @window, if the window
4043 * manager supports this operation. Not all window managers support
4044 * this, and some deliberately ignore it or don't have a concept of
4045 * "maximized"; so you can't rely on the maximization actually
4046 * happening. But it will happen with most standard window managers,
4047 * and GDK makes a best effort to get it to happen.
4049 * On Windows, reliably maximizes the window.
4053 gdk_window_maximize (GdkWindow *window)
4055 if (GDK_WINDOW_DESTROYED (window) ||
4056 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4059 if (GDK_WINDOW_IS_MAPPED (window))
4060 gdk_wmspec_change_state (TRUE, window,
4061 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4062 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4064 gdk_synthesize_window_state (window,
4066 GDK_WINDOW_STATE_MAXIMIZED);
4070 * gdk_window_unmaximize:
4071 * @window: a toplevel #GdkWindow
4073 * Unmaximizes the window. If the window wasn't maximized, then this
4074 * function does nothing.
4076 * On X11, asks the window manager to unmaximize @window, if the
4077 * window manager supports this operation. Not all window managers
4078 * support this, and some deliberately ignore it or don't have a
4079 * concept of "maximized"; so you can't rely on the unmaximization
4080 * actually happening. But it will happen with most standard window
4081 * managers, and GDK makes a best effort to get it to happen.
4083 * On Windows, reliably unmaximizes the window.
4087 gdk_window_unmaximize (GdkWindow *window)
4089 if (GDK_WINDOW_DESTROYED (window) ||
4090 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4093 if (GDK_WINDOW_IS_MAPPED (window))
4094 gdk_wmspec_change_state (FALSE, window,
4095 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4096 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4098 gdk_synthesize_window_state (window,
4099 GDK_WINDOW_STATE_MAXIMIZED,
4104 * gdk_window_fullscreen:
4105 * @window: a toplevel #GdkWindow
4107 * Moves the window into fullscreen mode. This means the
4108 * window covers the entire screen and is above any panels
4111 * If the window was already fullscreen, then this function does nothing.
4113 * On X11, asks the window manager to put @window in a fullscreen
4114 * state, if the window manager supports this operation. Not all
4115 * window managers support this, and some deliberately ignore it or
4116 * don't have a concept of "fullscreen"; so you can't rely on the
4117 * fullscreenification actually happening. But it will happen with
4118 * most standard window managers, and GDK makes a best effort to get
4124 gdk_window_fullscreen (GdkWindow *window)
4126 if (GDK_WINDOW_DESTROYED (window) ||
4127 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4130 if (GDK_WINDOW_IS_MAPPED (window))
4131 gdk_wmspec_change_state (TRUE, window,
4132 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4136 gdk_synthesize_window_state (window,
4138 GDK_WINDOW_STATE_FULLSCREEN);
4142 * gdk_window_unfullscreen:
4143 * @window: a toplevel #GdkWindow
4145 * Moves the window out of fullscreen mode. If the window was not
4146 * fullscreen, does nothing.
4148 * On X11, asks the window manager to move @window out of the fullscreen
4149 * state, if the window manager supports this operation. Not all
4150 * window managers support this, and some deliberately ignore it or
4151 * don't have a concept of "fullscreen"; so you can't rely on the
4152 * unfullscreenification actually happening. But it will happen with
4153 * most standard window managers, and GDK makes a best effort to get
4159 gdk_window_unfullscreen (GdkWindow *window)
4161 if (GDK_WINDOW_DESTROYED (window) ||
4162 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4165 if (GDK_WINDOW_IS_MAPPED (window))
4166 gdk_wmspec_change_state (FALSE, window,
4167 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4171 gdk_synthesize_window_state (window,
4172 GDK_WINDOW_STATE_FULLSCREEN,
4177 * gdk_window_set_keep_above:
4178 * @window: a toplevel #GdkWindow
4179 * @setting: whether to keep @window above other windows
4181 * Set if @window must be kept above other windows. If the
4182 * window was already above, then this function does nothing.
4184 * On X11, asks the window manager to keep @window above, if the window
4185 * manager supports this operation. Not all window managers support
4186 * this, and some deliberately ignore it or don't have a concept of
4187 * "keep above"; so you can't rely on the window being kept above.
4188 * But it will happen with most standard window managers,
4189 * and GDK makes a best effort to get it to happen.
4194 gdk_window_set_keep_above (GdkWindow *window,
4197 g_return_if_fail (GDK_IS_WINDOW (window));
4199 if (GDK_WINDOW_DESTROYED (window) ||
4200 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4203 if (GDK_WINDOW_IS_MAPPED (window))
4206 gdk_wmspec_change_state (FALSE, window,
4207 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4209 gdk_wmspec_change_state (setting, window,
4210 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4214 gdk_synthesize_window_state (window,
4215 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
4216 setting ? GDK_WINDOW_STATE_ABOVE : 0);
4220 * gdk_window_set_keep_below:
4221 * @window: a toplevel #GdkWindow
4222 * @setting: whether to keep @window below other windows
4224 * Set if @window must be kept below other windows. If the
4225 * window was already below, then this function does nothing.
4227 * On X11, asks the window manager to keep @window below, if the window
4228 * manager supports this operation. Not all window managers support
4229 * this, and some deliberately ignore it or don't have a concept of
4230 * "keep below"; so you can't rely on the window being kept below.
4231 * But it will happen with most standard window managers,
4232 * and GDK makes a best effort to get it to happen.
4237 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
4239 g_return_if_fail (GDK_IS_WINDOW (window));
4241 if (GDK_WINDOW_DESTROYED (window) ||
4242 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4245 if (GDK_WINDOW_IS_MAPPED (window))
4248 gdk_wmspec_change_state (FALSE, window,
4249 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4251 gdk_wmspec_change_state (setting, window,
4252 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4256 gdk_synthesize_window_state (window,
4257 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
4258 setting ? GDK_WINDOW_STATE_BELOW : 0);
4262 * gdk_window_get_group:
4263 * @window: a toplevel #GdkWindow
4265 * Returns the group leader window for @window. See gdk_window_set_group().
4267 * Return value: (transfer none): the group leader window for @window
4272 gdk_window_get_group (GdkWindow *window)
4274 GdkToplevelX11 *toplevel;
4276 if (GDK_WINDOW_DESTROYED (window) ||
4277 !WINDOW_IS_TOPLEVEL (window))
4280 toplevel = _gdk_x11_window_get_toplevel (window);
4282 return toplevel->group_leader;
4286 * gdk_window_set_group:
4287 * @window: a toplevel #GdkWindow
4288 * @leader: group leader window, or %NULL to restore the default group leader window
4290 * Sets the group leader window for @window. By default,
4291 * GDK sets the group leader for all toplevel windows
4292 * to a global window implicitly created by GDK. With this function
4293 * you can override this default.
4295 * The group leader window allows the window manager to distinguish
4296 * all windows that belong to a single application. It may for example
4297 * allow users to minimize/unminimize all windows belonging to an
4298 * application at once. You should only set a non-default group window
4299 * if your application pretends to be multiple applications.
4302 gdk_window_set_group (GdkWindow *window,
4305 GdkToplevelX11 *toplevel;
4307 g_return_if_fail (GDK_IS_WINDOW (window));
4308 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4309 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
4311 if (GDK_WINDOW_DESTROYED (window) ||
4312 (leader != NULL && GDK_WINDOW_DESTROYED (leader)) ||
4313 !WINDOW_IS_TOPLEVEL (window))
4316 toplevel = _gdk_x11_window_get_toplevel (window);
4319 leader = gdk_display_get_default_group (gdk_window_get_display (window));
4321 if (toplevel->group_leader != leader)
4323 if (toplevel->group_leader)
4324 g_object_unref (toplevel->group_leader);
4325 toplevel->group_leader = g_object_ref (leader);
4326 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
4329 update_wm_hints (window, FALSE);
4332 static MotifWmHints *
4333 gdk_window_get_mwm_hints (GdkWindow *window)
4335 GdkDisplay *display;
4336 Atom hints_atom = None;
4343 if (GDK_WINDOW_DESTROYED (window))
4346 display = gdk_window_get_display (window);
4348 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4350 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4351 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4352 False, AnyPropertyType, &type, &format, &nitems,
4353 &bytes_after, &data);
4358 return (MotifWmHints *)data;
4362 gdk_window_set_mwm_hints (GdkWindow *window,
4363 MotifWmHints *new_hints)
4365 GdkDisplay *display;
4366 Atom hints_atom = None;
4368 MotifWmHints *hints;
4374 if (GDK_WINDOW_DESTROYED (window))
4377 display = gdk_window_get_display (window);
4379 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4381 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4382 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4383 False, AnyPropertyType, &type, &format, &nitems,
4384 &bytes_after, &data);
4390 hints = (MotifWmHints *)data;
4392 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4394 hints->flags |= MWM_HINTS_FUNCTIONS;
4395 hints->functions = new_hints->functions;
4397 if (new_hints->flags & MWM_HINTS_DECORATIONS)
4399 hints->flags |= MWM_HINTS_DECORATIONS;
4400 hints->decorations = new_hints->decorations;
4404 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4405 hints_atom, hints_atom, 32, PropModeReplace,
4406 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
4408 if (hints != new_hints)
4413 * gdk_window_set_decorations:
4414 * @window: a toplevel #GdkWindow
4415 * @decorations: decoration hint mask
4417 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
4418 * This function sets the traditional Motif window manager hints that tell the
4419 * window manager which decorations you would like your window to have.
4420 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
4421 * using the GDK function directly.
4423 * The @decorations argument is the logical OR of the fields in
4424 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
4425 * mask, the other bits indicate which decorations should be turned off.
4426 * If #GDK_DECOR_ALL is not included, then the other bits indicate
4427 * which decorations should be turned on.
4429 * Most window managers honor a decorations hint of 0 to disable all decorations,
4430 * but very few honor all possible combinations of bits.
4434 gdk_window_set_decorations (GdkWindow *window,
4435 GdkWMDecoration decorations)
4439 if (GDK_WINDOW_DESTROYED (window) ||
4440 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4443 /* initialize to zero to avoid writing uninitialized data to socket */
4444 memset(&hints, 0, sizeof(hints));
4445 hints.flags = MWM_HINTS_DECORATIONS;
4446 hints.decorations = decorations;
4448 gdk_window_set_mwm_hints (window, &hints);
4452 * gdk_window_get_decorations:
4453 * @window: The toplevel #GdkWindow to get the decorations from
4454 * @decorations: The window decorations will be written here
4456 * Returns the decorations set on the GdkWindow with
4457 * gdk_window_set_decorations().
4459 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
4462 gdk_window_get_decorations(GdkWindow *window,
4463 GdkWMDecoration *decorations)
4465 MotifWmHints *hints;
4466 gboolean result = FALSE;
4468 if (GDK_WINDOW_DESTROYED (window) ||
4469 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4472 hints = gdk_window_get_mwm_hints (window);
4476 if (hints->flags & MWM_HINTS_DECORATIONS)
4479 *decorations = hints->decorations;
4490 * gdk_window_set_functions:
4491 * @window: a toplevel #GdkWindow
4492 * @functions: bitmask of operations to allow on @window
4494 * Sets hints about the window management functions to make available
4495 * via buttons on the window frame.
4497 * On the X backend, this function sets the traditional Motif window
4498 * manager hint for this purpose. However, few window managers do
4499 * anything reliable or interesting with this hint. Many ignore it
4502 * The @functions argument is the logical OR of values from the
4503 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
4504 * then the other bits indicate which functions to disable; if
4505 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
4510 gdk_window_set_functions (GdkWindow *window,
4511 GdkWMFunction functions)
4515 g_return_if_fail (GDK_IS_WINDOW (window));
4517 if (GDK_WINDOW_DESTROYED (window) ||
4518 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4521 /* initialize to zero to avoid writing uninitialized data to socket */
4522 memset(&hints, 0, sizeof(hints));
4523 hints.flags = MWM_HINTS_FUNCTIONS;
4524 hints.functions = functions;
4526 gdk_window_set_mwm_hints (window, &hints);
4530 _xwindow_get_shape (Display *xdisplay,
4534 cairo_region_t *shape;
4542 xrl = XShapeGetRectangles (xdisplay,
4544 shape_type, &rn, &ord);
4546 if (xrl == NULL || rn == 0)
4547 return cairo_region_create (); /* Empty */
4549 if (ord != YXBanded)
4551 /* This really shouldn't happen with any xserver, as they
4552 generally convert regions to YXBanded internally */
4553 g_warning ("non YXBanded shape masks not supported");
4558 rl = g_new (GdkRectangle, rn);
4559 for (i = 0; i < rn; i++)
4563 rl[i].width = xrl[i].width;
4564 rl[i].height = xrl[i].height;
4568 shape = cairo_region_create_rectangles (rl, rn);
4576 _gdk_windowing_window_get_shape (GdkWindow *window)
4578 if (!GDK_WINDOW_DESTROYED (window) &&
4579 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
4580 return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
4581 GDK_WINDOW_XID (window), ShapeBounding);
4587 _gdk_windowing_window_get_input_shape (GdkWindow *window)
4589 #if defined(ShapeInput)
4590 if (!GDK_WINDOW_DESTROYED (window) &&
4591 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
4592 return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
4593 GDK_WINDOW_XID (window),
4601 gdk_window_set_static_bit_gravity (GdkWindow *window,
4604 XSetWindowAttributes xattributes;
4605 guint xattributes_mask = 0;
4607 g_return_if_fail (GDK_IS_WINDOW (window));
4609 if (window->input_only)
4612 xattributes.bit_gravity = StaticGravity;
4613 xattributes_mask |= CWBitGravity;
4614 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4615 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4616 GDK_WINDOW_XID (window),
4617 CWBitGravity, &xattributes);
4621 gdk_window_set_static_win_gravity (GdkWindow *window,
4624 XSetWindowAttributes xattributes;
4626 g_return_if_fail (GDK_IS_WINDOW (window));
4628 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4630 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4631 GDK_WINDOW_XID (window),
4632 CWWinGravity, &xattributes);
4636 gdk_window_x11_set_static_gravities (GdkWindow *window,
4637 gboolean use_static)
4641 if (!use_static == !window->guffaw_gravity)
4644 window->guffaw_gravity = use_static;
4646 if (!GDK_WINDOW_DESTROYED (window))
4648 gdk_window_set_static_bit_gravity (window, use_static);
4650 tmp_list = window->children;
4653 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4655 tmp_list = tmp_list->next;
4663 wmspec_moveresize (GdkWindow *window,
4669 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4671 XClientMessageEvent xclient;
4673 /* Release passive grab */
4674 gdk_display_pointer_ungrab (display, timestamp);
4676 memset (&xclient, 0, sizeof (xclient));
4677 xclient.type = ClientMessage;
4678 xclient.window = GDK_WINDOW_XID (window);
4679 xclient.message_type =
4680 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4681 xclient.format = 32;
4682 xclient.data.l[0] = root_x;
4683 xclient.data.l[1] = root_y;
4684 xclient.data.l[2] = direction;
4685 xclient.data.l[3] = 0;
4686 xclient.data.l[4] = 0;
4688 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4689 SubstructureRedirectMask | SubstructureNotifyMask,
4690 (XEvent *)&xclient);
4693 typedef struct _MoveResizeData MoveResizeData;
4695 struct _MoveResizeData
4697 GdkDisplay *display;
4699 GdkWindow *moveresize_window;
4700 GdkWindow *moveresize_emulation_window;
4702 GdkWindowEdge resize_edge;
4703 gint moveresize_button;
4706 gint moveresize_orig_x;
4707 gint moveresize_orig_y;
4708 gint moveresize_orig_width;
4709 gint moveresize_orig_height;
4710 GdkWindowHints moveresize_geom_mask;
4711 GdkGeometry moveresize_geometry;
4712 Time moveresize_process_time;
4713 XEvent *moveresize_pending_event;
4716 /* From the WM spec */
4717 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4718 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4719 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4720 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4721 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4722 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4723 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4724 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4725 #define _NET_WM_MOVERESIZE_MOVE 8
4728 wmspec_resize_drag (GdkWindow *window,
4737 /* Let the compiler turn a switch into a table, instead
4738 * of doing the table manually, this way is easier to verify.
4742 case GDK_WINDOW_EDGE_NORTH_WEST:
4743 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4746 case GDK_WINDOW_EDGE_NORTH:
4747 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4750 case GDK_WINDOW_EDGE_NORTH_EAST:
4751 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4754 case GDK_WINDOW_EDGE_WEST:
4755 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4758 case GDK_WINDOW_EDGE_EAST:
4759 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4762 case GDK_WINDOW_EDGE_SOUTH_WEST:
4763 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4766 case GDK_WINDOW_EDGE_SOUTH:
4767 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4770 case GDK_WINDOW_EDGE_SOUTH_EAST:
4771 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4775 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4780 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4783 static MoveResizeData *
4784 get_move_resize_data (GdkDisplay *display,
4787 MoveResizeData *mv_resize;
4788 static GQuark move_resize_quark = 0;
4790 if (!move_resize_quark)
4791 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4793 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4795 if (!mv_resize && create)
4797 mv_resize = g_new0 (MoveResizeData, 1);
4798 mv_resize->display = display;
4800 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4807 update_pos (MoveResizeData *mv_resize,
4813 dx = new_root_x - mv_resize->moveresize_x;
4814 dy = new_root_y - mv_resize->moveresize_y;
4816 if (mv_resize->is_resize)
4820 x = mv_resize->moveresize_orig_x;
4821 y = mv_resize->moveresize_orig_y;
4823 w = mv_resize->moveresize_orig_width;
4824 h = mv_resize->moveresize_orig_height;
4826 switch (mv_resize->resize_edge)
4828 case GDK_WINDOW_EDGE_NORTH_WEST:
4834 case GDK_WINDOW_EDGE_NORTH:
4838 case GDK_WINDOW_EDGE_NORTH_EAST:
4843 case GDK_WINDOW_EDGE_SOUTH_WEST:
4848 case GDK_WINDOW_EDGE_SOUTH_EAST:
4852 case GDK_WINDOW_EDGE_SOUTH:
4855 case GDK_WINDOW_EDGE_EAST:
4858 case GDK_WINDOW_EDGE_WEST:
4869 if (mv_resize->moveresize_geom_mask)
4871 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4872 mv_resize->moveresize_geom_mask,
4876 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4882 x = mv_resize->moveresize_orig_x + dx;
4883 y = mv_resize->moveresize_orig_y + dy;
4885 gdk_window_move (mv_resize->moveresize_window, x, y);
4890 finish_drag (MoveResizeData *mv_resize)
4892 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4893 mv_resize->moveresize_emulation_window = NULL;
4894 g_object_unref (mv_resize->moveresize_window);
4895 mv_resize->moveresize_window = NULL;
4897 if (mv_resize->moveresize_pending_event)
4899 g_free (mv_resize->moveresize_pending_event);
4900 mv_resize->moveresize_pending_event = NULL;
4905 lookahead_motion_predicate (Display *xdisplay,
4909 gboolean *seen_release = (gboolean *)arg;
4910 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4911 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4916 switch (event->xany.type)
4919 *seen_release = TRUE;
4922 mv_resize->moveresize_process_time = event->xmotion.time;
4932 moveresize_lookahead (MoveResizeData *mv_resize,
4936 gboolean seen_release = FALSE;
4938 if (mv_resize->moveresize_process_time)
4940 if (event->xmotion.time == mv_resize->moveresize_process_time)
4942 mv_resize->moveresize_process_time = 0;
4949 XCheckIfEvent (event->xany.display, &tmp_event,
4950 lookahead_motion_predicate, (XPointer) & seen_release);
4952 return mv_resize->moveresize_process_time == 0;
4956 _gdk_moveresize_handle_event (XEvent *event)
4958 guint button_mask = 0;
4959 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
4960 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4962 if (!mv_resize || !mv_resize->moveresize_window)
4965 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4967 switch (event->xany.type)
4970 if (mv_resize->moveresize_window->resize_count > 0)
4972 if (mv_resize->moveresize_pending_event)
4973 *mv_resize->moveresize_pending_event = *event;
4975 mv_resize->moveresize_pending_event =
4976 g_memdup (event, sizeof (XEvent));
4980 if (!moveresize_lookahead (mv_resize, event))
4983 update_pos (mv_resize,
4984 event->xmotion.x_root,
4985 event->xmotion.y_root);
4987 /* This should never be triggered in normal cases, but in the
4988 * case where the drag started without an implicit grab being
4989 * in effect, we could miss the release if it occurs before
4990 * we grab the pointer; this ensures that we will never
4991 * get a permanently stuck grab.
4993 if ((event->xmotion.state & button_mask) == 0)
4994 finish_drag (mv_resize);
4998 update_pos (mv_resize,
4999 event->xbutton.x_root,
5000 event->xbutton.y_root);
5002 if (event->xbutton.button == mv_resize->moveresize_button)
5003 finish_drag (mv_resize);
5010 _gdk_moveresize_configure_done (GdkDisplay *display,
5014 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5016 if (!mv_resize || window != mv_resize->moveresize_window)
5019 if (mv_resize->moveresize_pending_event)
5021 tmp_event = mv_resize->moveresize_pending_event;
5022 mv_resize->moveresize_pending_event = NULL;
5023 _gdk_moveresize_handle_event (tmp_event);
5031 create_moveresize_window (MoveResizeData *mv_resize,
5034 GdkWindowAttr attributes;
5035 gint attributes_mask;
5036 GdkGrabStatus status;
5038 g_assert (mv_resize->moveresize_emulation_window == NULL);
5040 attributes.x = -100;
5041 attributes.y = -100;
5042 attributes.width = 10;
5043 attributes.height = 10;
5044 attributes.window_type = GDK_WINDOW_TEMP;
5045 attributes.wclass = GDK_INPUT_ONLY;
5046 attributes.override_redirect = TRUE;
5047 attributes.event_mask = 0;
5049 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
5051 mv_resize->moveresize_emulation_window =
5052 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
5056 gdk_window_show (mv_resize->moveresize_emulation_window);
5058 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
5060 GDK_BUTTON_RELEASE_MASK |
5061 GDK_POINTER_MOTION_MASK,
5066 if (status != GDK_GRAB_SUCCESS)
5068 /* If this fails, some other client has grabbed the window
5071 finish_drag (mv_resize);
5074 mv_resize->moveresize_process_time = 0;
5078 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
5079 so that calling XMoveWindow with these coordinates will not move the
5081 Note that this depends on the WM to implement ICCCM-compliant reference
5085 calculate_unmoving_origin (MoveResizeData *mv_resize)
5090 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
5091 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
5093 gdk_window_get_origin (mv_resize->moveresize_window,
5094 &mv_resize->moveresize_orig_x,
5095 &mv_resize->moveresize_orig_y);
5099 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
5100 gdk_window_get_geometry (mv_resize->moveresize_window,
5101 NULL, NULL, &width, &height, NULL);
5103 switch (mv_resize->moveresize_geometry.win_gravity)
5105 case GDK_GRAVITY_NORTH_WEST:
5106 mv_resize->moveresize_orig_x = rect.x;
5107 mv_resize->moveresize_orig_y = rect.y;
5109 case GDK_GRAVITY_NORTH:
5110 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5111 mv_resize->moveresize_orig_y = rect.y;
5113 case GDK_GRAVITY_NORTH_EAST:
5114 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5115 mv_resize->moveresize_orig_y = rect.y;
5117 case GDK_GRAVITY_WEST:
5118 mv_resize->moveresize_orig_x = rect.x;
5119 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5121 case GDK_GRAVITY_CENTER:
5122 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5123 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5125 case GDK_GRAVITY_EAST:
5126 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5127 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5129 case GDK_GRAVITY_SOUTH_WEST:
5130 mv_resize->moveresize_orig_x = rect.x;
5131 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5133 case GDK_GRAVITY_SOUTH:
5134 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5135 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5137 case GDK_GRAVITY_SOUTH_EAST:
5138 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5139 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5142 mv_resize->moveresize_orig_x = rect.x;
5143 mv_resize->moveresize_orig_y = rect.y;
5150 emulate_resize_drag (GdkWindow *window,
5157 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5159 mv_resize->is_resize = TRUE;
5160 mv_resize->moveresize_button = button;
5161 mv_resize->resize_edge = edge;
5162 mv_resize->moveresize_x = root_x;
5163 mv_resize->moveresize_y = root_y;
5164 mv_resize->moveresize_window = g_object_ref (window);
5166 mv_resize->moveresize_orig_width = gdk_window_get_width (window);
5167 mv_resize->moveresize_orig_height = gdk_window_get_height (window);
5169 mv_resize->moveresize_geom_mask = 0;
5170 gdk_window_get_geometry_hints (window,
5171 &mv_resize->moveresize_geometry,
5172 &mv_resize->moveresize_geom_mask);
5174 calculate_unmoving_origin (mv_resize);
5176 create_moveresize_window (mv_resize, timestamp);
5180 emulate_move_drag (GdkWindow *window,
5186 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5188 mv_resize->is_resize = FALSE;
5189 mv_resize->moveresize_button = button;
5190 mv_resize->moveresize_x = root_x;
5191 mv_resize->moveresize_y = root_y;
5193 mv_resize->moveresize_window = g_object_ref (window);
5195 calculate_unmoving_origin (mv_resize);
5197 create_moveresize_window (mv_resize, timestamp);
5201 * gdk_window_begin_resize_drag:
5202 * @window: a toplevel #GdkWindow
5203 * @edge: the edge or corner from which the drag is started
5204 * @button: the button being used to drag
5205 * @root_x: root window X coordinate of mouse click that began the drag
5206 * @root_y: root window Y coordinate of mouse click that began the drag
5207 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
5209 * Begins a window resize operation (for a toplevel window).
5210 * You might use this function to implement a "window resize grip," for
5211 * example; in fact #GtkStatusbar uses it. The function works best
5212 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
5213 * fallback implementation for other window managers.
5217 gdk_window_begin_resize_drag (GdkWindow *window,
5224 if (GDK_WINDOW_DESTROYED (window) ||
5225 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
5228 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5229 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
5230 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
5232 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
5236 * gdk_window_begin_move_drag:
5237 * @window: a toplevel #GdkWindow
5238 * @button: the button being used to drag
5239 * @root_x: root window X coordinate of mouse click that began the drag
5240 * @root_y: root window Y coordinate of mouse click that began the drag
5241 * @timestamp: timestamp of mouse click that began the drag
5243 * Begins a window move operation (for a toplevel window). You might
5244 * use this function to implement a "window move grip," for
5245 * example. The function works best with window managers that support
5246 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
5247 * Window Manager Hints</ulink>, but has a fallback implementation for
5248 * other window managers.
5252 gdk_window_begin_move_drag (GdkWindow *window,
5258 if (GDK_WINDOW_DESTROYED (window) ||
5259 !WINDOW_IS_TOPLEVEL (window))
5262 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5263 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
5264 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
5267 emulate_move_drag (window, button, root_x, root_y, timestamp);
5271 * gdk_window_enable_synchronized_configure:
5272 * @window: a toplevel #GdkWindow
5274 * Indicates that the application will cooperate with the window
5275 * system in synchronizing the window repaint with the window
5276 * manager during resizing operations. After an application calls
5277 * this function, it must call gdk_window_configure_finished() every
5278 * time it has finished all processing associated with a set of
5279 * Configure events. Toplevel GTK+ windows automatically use this
5282 * On X, calling this function makes @window participate in the
5283 * _NET_WM_SYNC_REQUEST window manager protocol.
5288 gdk_window_enable_synchronized_configure (GdkWindow *window)
5290 GdkWindowImplX11 *impl;
5292 if (!GDK_IS_WINDOW_IMPL_X11 (window->impl))
5295 impl = GDK_WINDOW_IMPL_X11 (window->impl);
5297 if (!impl->use_synchronized_configure)
5299 /* This basically means you want to do fancy X specific stuff, so
5300 ensure we have a native window */
5301 gdk_window_ensure_native (window);
5303 impl->use_synchronized_configure = TRUE;
5304 ensure_sync_counter (window);
5309 * gdk_window_configure_finished:
5310 * @window: a toplevel #GdkWindow
5312 * Signal to the window system that the application has finished
5313 * handling Configure events it has received. Window Managers can
5314 * use this to better synchronize the frame repaint with the
5315 * application. GTK+ applications will automatically call this
5316 * function when appropriate.
5318 * This function can only be called if gdk_window_enable_synchronized_configure()
5319 * was called previously.
5324 gdk_window_configure_finished (GdkWindow *window)
5326 GdkWindowImplX11 *impl;
5328 if (!WINDOW_IS_TOPLEVEL (window))
5331 impl = GDK_WINDOW_IMPL_X11 (window->impl);
5332 if (!impl->use_synchronized_configure)
5336 if (!GDK_WINDOW_DESTROYED (window))
5338 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
5339 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
5341 if (toplevel && toplevel->update_counter != None &&
5342 GDK_DISPLAY_X11 (display)->use_sync &&
5343 !XSyncValueIsZero (toplevel->current_counter_value))
5345 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
5346 toplevel->update_counter,
5347 toplevel->current_counter_value);
5349 XSyncIntToValue (&toplevel->current_counter_value, 0);
5356 _gdk_windowing_window_beep (GdkWindow *window)
5358 GdkDisplay *display;
5360 g_return_if_fail (GDK_IS_WINDOW (window));
5362 display = GDK_WINDOW_DISPLAY (window);
5365 if (GDK_DISPLAY_X11 (display)->use_xkb)
5366 XkbBell (GDK_DISPLAY_XDISPLAY (display),
5367 GDK_WINDOW_XID (window),
5372 gdk_display_beep (display);
5376 * gdk_window_set_opacity:
5377 * @window: a top-level #GdkWindow
5380 * Request the windowing system to make @window partially transparent,
5381 * with opacity 0 being fully transparent and 1 fully opaque. (Values
5382 * of the opacity parameter are clamped to the [0,1] range.)
5384 * On X11, this works only on X screens with a compositing manager
5387 * For setting up per-pixel alpha, see gdk_screen_get_rgba_visual().
5388 * For making non-toplevel windows translucent, see
5389 * gdk_window_set_composited().
5394 gdk_window_set_opacity (GdkWindow *window,
5397 GdkDisplay *display;
5400 g_return_if_fail (GDK_IS_WINDOW (window));
5402 if (GDK_WINDOW_DESTROYED (window) ||
5403 !WINDOW_IS_TOPLEVEL (window))
5406 display = gdk_window_get_display (window);
5410 else if (opacity > 1)
5413 cardinal = opacity * 0xffffffff;
5415 if (cardinal == 0xffffffff)
5416 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
5417 GDK_WINDOW_XID (window),
5418 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"));
5420 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
5421 GDK_WINDOW_XID (window),
5422 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"),
5425 (guchar *) &cardinal, 1);
5429 _gdk_windowing_window_set_composited (GdkWindow *window,
5430 gboolean composited)
5432 #if defined(HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES)
5433 GdkWindowImplX11 *impl;
5434 GdkDisplay *display;
5438 impl = GDK_WINDOW_IMPL_X11 (window->impl);
5440 display = gdk_window_get_display (window);
5441 dpy = GDK_DISPLAY_XDISPLAY (display);
5442 xid = GDK_WINDOW_XID (window);
5446 XCompositeRedirectWindow (dpy, xid, CompositeRedirectManual);
5447 impl->damage = XDamageCreate (dpy, xid, XDamageReportBoundingBox);
5451 XCompositeUnredirectWindow (dpy, xid, CompositeRedirectManual);
5452 XDamageDestroy (dpy, impl->damage);
5453 impl->damage = None;
5459 _gdk_windowing_window_process_updates_recurse (GdkWindow *window,
5460 cairo_region_t *region)
5462 _gdk_window_process_updates_recurse (window, region);
5466 _gdk_windowing_before_process_all_updates (void)
5471 _gdk_windowing_after_process_all_updates (void)
5476 timestamp_predicate (Display *display,
5480 Window xwindow = GPOINTER_TO_UINT (arg);
5481 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
5483 if (xevent->type == PropertyNotify &&
5484 xevent->xproperty.window == xwindow &&
5485 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
5486 "GDK_TIMESTAMP_PROP"))
5493 * gdk_x11_get_server_time:
5494 * @window: a #GdkWindow, used for communication with the server.
5495 * The window must have GDK_PROPERTY_CHANGE_MASK in its
5496 * events mask or a hang will result.
5498 * Routine to get the current X server time stamp.
5500 * Return value: the time stamp.
5503 gdk_x11_get_server_time (GdkWindow *window)
5509 Atom timestamp_prop_atom;
5511 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5512 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
5514 xdisplay = GDK_WINDOW_XDISPLAY (window);
5515 xwindow = GDK_WINDOW_XID (window);
5516 timestamp_prop_atom =
5517 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
5518 "GDK_TIMESTAMP_PROP");
5520 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
5521 timestamp_prop_atom,
5522 8, PropModeReplace, &c, 1);
5524 XIfEvent (xdisplay, &xevent,
5525 timestamp_predicate, GUINT_TO_POINTER(xwindow));
5527 return xevent.xproperty.time;
5531 * gdk_x11_window_get_xid:
5532 * @window: a native #GdkWindow.
5534 * Returns the X resource (window) belonging to a #GdkWindow.
5536 * Return value: the ID of @drawable's X resource.
5539 gdk_x11_window_get_xid (GdkWindow *window)
5543 /* Try to ensure the window has a native window */
5544 if (!_gdk_window_has_impl (window))
5546 gdk_window_ensure_native (window);
5548 /* We sync here to ensure the window is created in the Xserver when
5549 * this function returns. This is required because the returned XID
5550 * for this window must be valid immediately, even with another
5551 * connection to the Xserver */
5552 gdk_display_sync (gdk_window_get_display (window));
5555 if (!GDK_WINDOW_IS_X11 (window))
5557 g_warning (G_STRLOC " drawable is not a native X11 window");
5561 impl = window->impl;
5563 return ((GdkWindowImplX11 *)impl)->xid;
5567 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
5569 GObjectClass *object_class = G_OBJECT_CLASS (klass);
5570 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
5571 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass);
5573 object_class->finalize = gdk_window_impl_x11_finalize;
5575 drawable_class->ref_cairo_surface = gdk_x11_ref_cairo_surface;
5577 impl_class->show = gdk_window_x11_show;
5578 impl_class->hide = gdk_window_x11_hide;
5579 impl_class->withdraw = gdk_window_x11_withdraw;
5580 impl_class->set_events = gdk_window_x11_set_events;
5581 impl_class->get_events = gdk_window_x11_get_events;
5582 impl_class->raise = gdk_window_x11_raise;
5583 impl_class->lower = gdk_window_x11_lower;
5584 impl_class->restack_under = gdk_window_x11_restack_under;
5585 impl_class->restack_toplevel = gdk_window_x11_restack_toplevel;
5586 impl_class->move_resize = gdk_window_x11_move_resize;
5587 impl_class->set_background = gdk_window_x11_set_background;
5588 impl_class->reparent = gdk_window_x11_reparent;
5589 impl_class->set_device_cursor = gdk_window_x11_set_device_cursor;
5590 impl_class->get_geometry = gdk_window_x11_get_geometry;
5591 impl_class->get_root_coords = gdk_window_x11_get_root_coords;
5592 impl_class->get_device_state = gdk_window_x11_get_device_state;
5593 impl_class->shape_combine_region = gdk_window_x11_shape_combine_region;
5594 impl_class->input_shape_combine_region = gdk_window_x11_input_shape_combine_region;
5595 impl_class->set_static_gravities = gdk_window_x11_set_static_gravities;
5596 impl_class->queue_antiexpose = _gdk_x11_window_queue_antiexpose;
5597 impl_class->translate = _gdk_x11_window_translate;
5598 impl_class->destroy = _gdk_x11_window_destroy;
5599 impl_class->resize_cairo_surface = gdk_window_x11_resize_cairo_surface;