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);
112 static void gdk_window_impl_iface_init (GdkWindowImplIface *iface);
114 #define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \
115 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
116 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
118 #define WINDOW_IS_TOPLEVEL(window) \
119 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
120 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
121 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
123 /* Return whether time1 is considered later than time2 as far as xserver
124 * time is concerned. Accounts for wraparound.
126 #define XSERVER_TIME_IS_LATER(time1, time2) \
127 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
128 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
131 G_DEFINE_TYPE_WITH_CODE (GdkWindowImplX11,
133 GDK_TYPE_DRAWABLE_IMPL_X11,
134 G_IMPLEMENT_INTERFACE (GDK_TYPE_WINDOW_IMPL,
135 gdk_window_impl_iface_init));
138 _gdk_window_impl_get_type (void)
140 return gdk_window_impl_x11_get_type ();
144 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
146 impl->toplevel_window_type = -1;
147 impl->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
148 (GDestroyNotify) gdk_cursor_unref);
152 _gdk_x11_window_get_toplevel (GdkWindow *window)
154 GdkWindowObject *private;
155 GdkWindowImplX11 *impl;
157 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
159 if (!WINDOW_IS_TOPLEVEL (window))
162 private = (GdkWindowObject *)window;
163 impl = GDK_WINDOW_IMPL_X11 (private->impl);
166 impl->toplevel = g_new0 (GdkToplevelX11, 1);
168 return impl->toplevel;
172 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
174 GObjectClass *object_class = G_OBJECT_CLASS (klass);
176 object_class->finalize = gdk_window_impl_x11_finalize;
180 gdk_window_impl_x11_finalize (GObject *object)
182 GdkWindowObject *wrapper;
183 GdkDrawableImplX11 *draw_impl;
184 GdkWindowImplX11 *window_impl;
186 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
188 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
189 window_impl = GDK_WINDOW_IMPL_X11 (object);
191 wrapper = (GdkWindowObject*) draw_impl->wrapper;
193 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
195 if (!GDK_WINDOW_DESTROYED (wrapper))
197 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
199 _gdk_xid_table_remove (display, draw_impl->xid);
200 if (window_impl->toplevel && window_impl->toplevel->focus_window)
201 _gdk_xid_table_remove (display, window_impl->toplevel->focus_window);
204 g_free (window_impl->toplevel);
206 if (window_impl->cursor)
207 gdk_cursor_unref (window_impl->cursor);
209 g_hash_table_destroy (window_impl->device_cursor);
211 G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
220 free_pixmap (gpointer datap)
222 FreePixmapData *data = datap;
224 if (!gdk_display_is_closed (data->display))
226 XFreePixmap (GDK_DISPLAY_XDISPLAY (data->display),
230 g_object_unref (data->display);
231 g_slice_free (FreePixmapData, data);
235 attach_free_pixmap_handler (cairo_surface_t *surface,
239 static const cairo_user_data_key_t key;
240 FreePixmapData *data;
242 data = g_slice_new (FreePixmapData);
243 data->display = g_object_ref (display);
244 data->pixmap = pixmap;
246 cairo_surface_set_user_data (surface, &key, data, free_pixmap);
249 /* Cairo does not guarantee we get an xlib surface if we call
250 * cairo_surface_create_similar(). In some cases however, we must use a
251 * pixmap or bitmap in the X11 API.
252 * These functions ensure an Xlib surface.
255 _gdk_x11_window_create_bitmap_surface (GdkWindow *window,
259 cairo_surface_t *surface;
262 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
263 GDK_WINDOW_XID (window),
265 surface = cairo_xlib_surface_create_for_bitmap (GDK_WINDOW_XDISPLAY (window),
267 GDK_SCREEN_XSCREEN (GDK_WINDOW_SCREEN (window)),
269 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
274 /* Create a surface backed with a pixmap without alpha on the same screen as window */
275 static cairo_surface_t *
276 gdk_x11_window_create_pixmap_surface (GdkWindow *window,
280 GdkScreen *screen = gdk_window_get_screen (window);
281 GdkVisual *visual = gdk_screen_get_system_visual (screen);
282 cairo_surface_t *surface;
285 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
286 GDK_WINDOW_XID (window),
288 gdk_visual_get_depth (visual));
289 surface = cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (window),
291 GDK_VISUAL_XVISUAL (visual),
293 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
299 tmp_unset_bg (GdkWindow *window)
301 GdkWindowImplX11 *impl;
302 GdkWindowObject *obj;
304 obj = (GdkWindowObject *) window;
305 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
309 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
310 GDK_DRAWABLE_XID (window), None);
314 tmp_reset_bg (GdkWindow *window)
316 GdkWindowImplX11 *impl;
317 GdkWindowObject *obj;
319 obj = (GdkWindowObject *) window;
320 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
324 gdk_window_x11_set_background (window, obj->background);
327 /* Unsetting and resetting window backgrounds.
329 * In many cases it is possible to avoid flicker by unsetting the
330 * background of windows. For example if the background of the
331 * parent window is unset when a window is unmapped, a brief flicker
332 * of background painting is avoided.
335 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
338 GdkWindowObject *private;
340 g_return_if_fail (GDK_IS_WINDOW (window));
342 private = (GdkWindowObject *)window;
344 if (private->input_only || private->destroyed ||
345 (private->window_type != GDK_WINDOW_ROOT &&
346 !GDK_WINDOW_IS_MAPPED (window)))
349 if (_gdk_window_has_impl (window) &&
350 GDK_WINDOW_IS_X11 (window) &&
351 private->window_type != GDK_WINDOW_ROOT &&
352 private->window_type != GDK_WINDOW_FOREIGN)
353 tmp_unset_bg (window);
359 for (l = private->children; l != NULL; l = l->next)
360 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
365 _gdk_x11_window_tmp_unset_parent_bg (GdkWindow *window)
367 GdkWindowObject *private;
368 private = (GdkWindowObject*) window;
370 if (GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT)
373 window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
374 _gdk_x11_window_tmp_unset_bg (window, FALSE);
378 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
381 GdkWindowObject *private;
383 g_return_if_fail (GDK_IS_WINDOW (window));
385 private = (GdkWindowObject *)window;
387 if (private->input_only || private->destroyed ||
388 (private->window_type != GDK_WINDOW_ROOT &&
389 !GDK_WINDOW_IS_MAPPED (window)))
393 if (_gdk_window_has_impl (window) &&
394 GDK_WINDOW_IS_X11 (window) &&
395 private->window_type != GDK_WINDOW_ROOT &&
396 private->window_type != GDK_WINDOW_FOREIGN)
397 tmp_reset_bg (window);
403 for (l = private->children; l != NULL; l = l->next)
404 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
409 _gdk_x11_window_tmp_reset_parent_bg (GdkWindow *window)
411 GdkWindowObject *private;
412 private = (GdkWindowObject*) window;
414 if (GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT)
417 window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
419 _gdk_x11_window_tmp_reset_bg (window, FALSE);
423 _gdk_windowing_window_init (GdkScreen * screen)
425 GdkWindowObject *private;
426 GdkDrawableImplX11 *draw_impl;
427 GdkScreenX11 *screen_x11;
429 screen_x11 = GDK_SCREEN_X11 (screen);
431 g_assert (screen_x11->root_window == NULL);
433 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
435 private = (GdkWindowObject *) screen_x11->root_window;
436 private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
437 private->impl_window = private;
438 private->visual = gdk_screen_get_system_visual (screen);
440 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
442 draw_impl->screen = screen;
443 draw_impl->xid = screen_x11->xroot_window;
444 draw_impl->wrapper = GDK_DRAWABLE (private);
446 private->window_type = GDK_WINDOW_ROOT;
447 private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
453 private->width = WidthOfScreen (screen_x11->xscreen);
454 private->height = HeightOfScreen (screen_x11->xscreen);
455 private->viewable = TRUE;
457 /* see init_randr_support() in gdkscreen-x11.c */
458 private->event_mask = GDK_STRUCTURE_MASK;
460 _gdk_window_update_size (screen_x11->root_window);
462 _gdk_xid_table_insert (screen_x11->display,
463 &screen_x11->xroot_window,
464 screen_x11->root_window);
468 set_wm_protocols (GdkWindow *window)
470 GdkDisplay *display = gdk_window_get_display (window);
474 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
475 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
476 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
479 if (GDK_DISPLAY_X11 (display)->use_sync)
480 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
483 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
487 get_default_title (void)
491 title = g_get_application_name ();
493 title = g_get_prgname ();
501 check_leader_window_title (GdkDisplay *display)
503 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
505 if (display_x11->leader_window && !display_x11->leader_window_title_set)
507 set_wm_name (display,
508 display_x11->leader_window,
509 get_default_title ());
511 display_x11->leader_window_title_set = TRUE;
516 create_focus_window (GdkDisplay *display,
519 GdkDisplayX11 *display_x11;
520 GdkEventMask event_mask;
524 xdisplay = GDK_DISPLAY_XDISPLAY (display);
525 display_x11 = GDK_DISPLAY_X11 (display);
527 focus_window = XCreateSimpleWindow (xdisplay, parent,
531 /* FIXME: probably better to actually track the requested event mask for the toplevel
533 event_mask = (GDK_KEY_PRESS_MASK |
534 GDK_KEY_RELEASE_MASK |
535 GDK_FOCUS_CHANGE_MASK);
537 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
541 XMapWindow (xdisplay, focus_window);
547 ensure_sync_counter (GdkWindow *window)
550 if (!GDK_WINDOW_DESTROYED (window))
552 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
553 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
554 GdkWindowObject *private = (GdkWindowObject *)window;
555 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
557 if (toplevel && impl->use_synchronized_configure &&
558 toplevel->update_counter == None &&
559 GDK_DISPLAY_X11 (display)->use_sync)
561 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
565 XSyncIntToValue (&value, 0);
567 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
569 atom = gdk_x11_get_xatom_by_name_for_display (display,
570 "_NET_WM_SYNC_REQUEST_COUNTER");
572 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
575 (guchar *)&toplevel->update_counter, 1);
577 XSyncIntToValue (&toplevel->current_counter_value, 0);
584 setup_toplevel_window (GdkWindow *window,
587 GdkWindowObject *obj = (GdkWindowObject *)window;
588 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
589 GdkDisplay *display = gdk_window_get_display (window);
590 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
591 XID xid = GDK_WINDOW_XID (window);
592 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
593 XSizeHints size_hints;
595 Window leader_window;
597 set_wm_protocols (window);
599 if (!obj->input_only)
601 /* The focus window is off the visible area, and serves to receive key
602 * press events so they don't get sent to child windows.
604 toplevel->focus_window = create_focus_window (display, xid);
605 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
608 check_leader_window_title (screen_x11->display);
610 /* FIXME: Is there any point in doing this? Do any WM's pay
611 * attention to PSize, and even if they do, is this the
614 size_hints.flags = PSize;
615 size_hints.width = obj->width;
616 size_hints.height = obj->height;
618 XSetWMNormalHints (xdisplay, xid, &size_hints);
620 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
621 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
624 XChangeProperty (xdisplay, xid,
625 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
630 leader_window = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
633 XChangeProperty (xdisplay, xid,
634 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
635 XA_WINDOW, 32, PropModeReplace,
636 (guchar *) &leader_window, 1);
638 if (toplevel->focus_window != None)
639 XChangeProperty (xdisplay, xid,
640 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_USER_TIME_WINDOW"),
641 XA_WINDOW, 32, PropModeReplace,
642 (guchar *) &toplevel->focus_window, 1);
644 if (!obj->focus_on_map)
645 gdk_x11_window_set_user_time (window, 0);
646 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
647 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
649 ensure_sync_counter (window);
653 _gdk_window_impl_new (GdkWindow *window,
654 GdkWindow *real_parent,
656 GdkEventMask event_mask,
657 GdkWindowAttr *attributes,
658 gint attributes_mask)
660 GdkWindowObject *private;
661 GdkWindowImplX11 *impl;
662 GdkDrawableImplX11 *draw_impl;
663 GdkScreenX11 *screen_x11;
664 GdkDisplayX11 *display_x11;
671 XSetWindowAttributes xattributes;
672 long xattributes_mask;
673 XClassHint *class_hint;
678 private = (GdkWindowObject *) window;
680 screen_x11 = GDK_SCREEN_X11 (screen);
681 xparent = GDK_WINDOW_XID (real_parent);
682 display_x11 = GDK_DISPLAY_X11 (GDK_SCREEN_DISPLAY (screen));
684 impl = g_object_new (_gdk_window_impl_get_type (), NULL);
685 private->impl = (GdkDrawable *)impl;
686 draw_impl = GDK_DRAWABLE_IMPL_X11 (impl);
687 draw_impl->wrapper = GDK_DRAWABLE (window);
689 draw_impl->screen = screen;
690 xdisplay = screen_x11->xdisplay;
692 xattributes_mask = 0;
694 xvisual = gdk_x11_visual_get_xvisual (private->visual);
696 if (attributes_mask & GDK_WA_NOREDIR)
698 xattributes.override_redirect =
699 (attributes->override_redirect == FALSE)?False:True;
700 xattributes_mask |= CWOverrideRedirect;
703 xattributes.override_redirect = False;
705 impl->override_redirect = xattributes.override_redirect;
707 if (private->parent && private->parent->guffaw_gravity)
709 xattributes.win_gravity = StaticGravity;
710 xattributes_mask |= CWWinGravity;
714 switch (private->window_type)
716 case GDK_WINDOW_TOPLEVEL:
717 case GDK_WINDOW_TEMP:
718 if (GDK_WINDOW_TYPE (private->parent) != GDK_WINDOW_ROOT)
720 /* The common code warns for this case */
721 xparent = GDK_SCREEN_XROOTWIN (screen);
725 if (!private->input_only)
729 xattributes.background_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
731 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
732 xattributes_mask |= CWBorderPixel | CWBackPixel;
734 if (private->guffaw_gravity)
735 xattributes.bit_gravity = StaticGravity;
737 xattributes.bit_gravity = NorthWestGravity;
739 xattributes_mask |= CWBitGravity;
741 xattributes.colormap = _gdk_visual_get_x11_colormap (private->visual);
742 xattributes_mask |= CWColormap;
744 if (private->window_type == GDK_WINDOW_TEMP)
746 xattributes.save_under = True;
747 xattributes.override_redirect = True;
748 xattributes.cursor = None;
749 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
751 impl->override_redirect = TRUE;
759 if (private->width > 65535 ||
760 private->height > 65535)
762 g_warning ("Native Windows wider or taller than 65535 pixels are not supported");
764 if (private->width > 65535)
765 private->width = 65535;
766 if (private->height > 65535)
767 private->height = 65535;
770 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
771 private->x + private->parent->abs_x,
772 private->y + private->parent->abs_y,
773 private->width, private->height,
774 0, private->depth, class, xvisual,
775 xattributes_mask, &xattributes);
777 g_object_ref (window);
778 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
780 switch (GDK_WINDOW_TYPE (private))
782 case GDK_WINDOW_TOPLEVEL:
783 case GDK_WINDOW_TEMP:
784 if (attributes_mask & GDK_WA_TITLE)
785 title = attributes->title;
787 title = get_default_title ();
789 gdk_window_set_title (window, title);
791 if (attributes_mask & GDK_WA_WMCLASS)
793 class_hint = XAllocClassHint ();
794 class_hint->res_name = attributes->wmclass_name;
795 class_hint->res_class = attributes->wmclass_class;
796 XSetClassHint (xdisplay, xid, class_hint);
800 setup_toplevel_window (window, (GdkWindow *)private->parent);
803 case GDK_WINDOW_CHILD:
808 if (attributes_mask & GDK_WA_TYPE_HINT)
809 gdk_window_set_type_hint (window, attributes->type_hint);
811 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
812 GDK_WINDOW_XWINDOW (window), event_mask,
813 StructureNotifyMask | PropertyChangeMask);
817 x_event_mask_to_gdk_event_mask (long mask)
819 GdkEventMask event_mask = 0;
822 for (i = 0; i < _gdk_nenvent_masks; i++)
824 if (mask & _gdk_event_mask_table[i])
825 event_mask |= 1 << (i + 1);
832 * gdk_window_foreign_new_for_display:
833 * @display: the #GdkDisplay where the window handle comes from.
834 * @anid: a native window handle.
836 * Wraps a native window in a #GdkWindow.
837 * This may fail if the window has been destroyed. If the window
838 * was already known to GDK, a new reference to the existing
839 * #GdkWindow is returned.
841 * For example in the X backend, a native window handle is an Xlib
844 * Return value: (transfer full): a #GdkWindow wrapper for the native
845 * window, or %NULL if the window has been destroyed. The wrapper
846 * will be newly created, if one doesn't exist already.
851 gdk_window_foreign_new_for_display (GdkDisplay *display,
852 GdkNativeWindow anid)
856 GdkWindowObject *private;
857 GdkWindowImplX11 *impl;
858 GdkDrawableImplX11 *draw_impl;
859 GdkDisplayX11 *display_x11;
860 XWindowAttributes attrs;
862 Window *children = NULL;
866 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
868 display_x11 = GDK_DISPLAY_X11 (display);
870 if ((window = gdk_xid_table_lookup_for_display (display, anid)) != NULL)
871 return g_object_ref (window);
873 gdk_error_trap_push ();
874 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
875 if (gdk_error_trap_pop () || !result)
878 /* FIXME: This is pretty expensive. Maybe the caller should supply
880 gdk_error_trap_push ();
881 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
882 if (gdk_error_trap_pop () || !result)
888 screen = _gdk_x11_display_screen_for_xrootwin (display, root);
890 window = g_object_new (GDK_TYPE_WINDOW, NULL);
892 private = (GdkWindowObject *) window;
893 private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
894 private->impl_window = private;
895 private->visual = gdk_x11_screen_lookup_visual (screen,
896 XVisualIDFromVisual (attrs.visual));
898 impl = GDK_WINDOW_IMPL_X11 (private->impl);
899 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
900 draw_impl->wrapper = GDK_DRAWABLE (window);
901 draw_impl->screen = screen;
903 private->parent = gdk_xid_table_lookup_for_display (display, parent);
905 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
906 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
908 private->parent->children = g_list_prepend (private->parent->children, window);
910 draw_impl->xid = anid;
912 private->x = attrs.x;
913 private->y = attrs.y;
914 private->width = attrs.width;
915 private->height = attrs.height;
916 private->window_type = GDK_WINDOW_FOREIGN;
917 private->destroyed = FALSE;
919 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
921 if (attrs.map_state == IsUnmapped)
922 private->state = GDK_WINDOW_STATE_WITHDRAWN;
925 private->viewable = TRUE;
927 private->depth = attrs.depth;
929 g_object_ref (window);
930 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
932 /* Update the clip region, etc */
933 _gdk_window_update_size (window);
939 * gdk_window_lookup_for_display:
940 * @display: the #GdkDisplay corresponding to the window handle
941 * @anid: a native window handle.
943 * Looks up the #GdkWindow that wraps the given native window handle.
945 * For example in the X backend, a native window handle is an Xlib
948 * Return value: (transfer none): the #GdkWindow wrapper for the native
949 * window, or %NULL if there is none.
954 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
956 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
961 * @anid: a native window handle.
963 * Looks up the #GdkWindow that wraps the given native window handle.
965 * For example in the X backend, a native window handle is an Xlib
968 * Return value: (transfer none): the #GdkWindow wrapper for the native
969 * window, or %NULL if there is none.
972 gdk_window_lookup (GdkNativeWindow anid)
974 return (GdkWindow*) gdk_xid_table_lookup (anid);
978 gdk_toplevel_x11_free_contents (GdkDisplay *display,
979 GdkToplevelX11 *toplevel)
981 if (toplevel->icon_pixmap)
983 cairo_surface_destroy (toplevel->icon_pixmap);
984 toplevel->icon_pixmap = NULL;
986 if (toplevel->icon_mask)
988 cairo_surface_destroy (toplevel->icon_mask);
989 toplevel->icon_mask = NULL;
991 if (toplevel->group_leader)
993 g_object_unref (toplevel->group_leader);
994 toplevel->group_leader = NULL;
997 if (toplevel->update_counter != None)
999 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
1000 toplevel->update_counter);
1001 toplevel->update_counter = None;
1003 XSyncIntToValue (&toplevel->current_counter_value, 0);
1009 _gdk_x11_window_destroy (GdkWindow *window,
1011 gboolean foreign_destroy)
1013 GdkWindowObject *private = (GdkWindowObject *)window;
1014 GdkToplevelX11 *toplevel;
1016 g_return_if_fail (GDK_IS_WINDOW (window));
1018 _gdk_selection_window_destroyed (window);
1020 toplevel = _gdk_x11_window_get_toplevel (window);
1022 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1024 _gdk_x11_drawable_finish (private->impl);
1026 if (!recursing && !foreign_destroy)
1028 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1032 static cairo_surface_t *
1033 gdk_window_x11_resize_cairo_surface (GdkWindow *window,
1034 cairo_surface_t *surface,
1038 cairo_xlib_surface_set_size (surface, width, height);
1044 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
1046 /* It's somebody else's window, but in our hierarchy,
1047 * so reparent it to the root window, and then send
1048 * it a delete event, as if we were a WM
1050 XClientMessageEvent xclient;
1052 gdk_error_trap_push ();
1053 gdk_window_hide (window);
1054 gdk_window_reparent (window, NULL, 0, 0);
1056 memset (&xclient, 0, sizeof (xclient));
1057 xclient.type = ClientMessage;
1058 xclient.window = GDK_WINDOW_XID (window);
1059 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1061 xclient.format = 32;
1062 xclient.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1063 "WM_DELETE_WINDOW");
1064 xclient.data.l[1] = CurrentTime;
1065 xclient.data.l[2] = 0;
1066 xclient.data.l[3] = 0;
1067 xclient.data.l[4] = 0;
1069 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1070 GDK_WINDOW_XID (window),
1071 False, 0, (XEvent *)&xclient);
1072 gdk_error_trap_pop_ignored ();
1076 get_root (GdkWindow *window)
1078 GdkScreen *screen = gdk_window_get_screen (window);
1080 return gdk_screen_get_root_window (screen);
1083 /* This function is called when the XWindow is really gone.
1086 gdk_window_destroy_notify (GdkWindow *window)
1088 GdkWindowImplX11 *window_impl;
1090 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
1092 if (!GDK_WINDOW_DESTROYED (window))
1094 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1095 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1097 _gdk_window_destroy (window, TRUE);
1100 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1101 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1102 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1104 _gdk_xgrab_check_destroy (window);
1106 g_object_unref (window);
1110 update_wm_hints (GdkWindow *window,
1113 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1114 GdkWindowObject *private = (GdkWindowObject *)window;
1115 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1119 !toplevel->is_leader &&
1120 private->state & GDK_WINDOW_STATE_WITHDRAWN)
1123 wm_hints.flags = StateHint | InputHint;
1124 wm_hints.input = private->accept_focus ? True : False;
1125 wm_hints.initial_state = NormalState;
1127 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
1129 wm_hints.flags |= StateHint;
1130 wm_hints.initial_state = IconicState;
1133 if (toplevel->icon_pixmap)
1135 wm_hints.flags |= IconPixmapHint;
1136 wm_hints.icon_pixmap = cairo_xlib_surface_get_drawable (toplevel->icon_pixmap);
1139 if (toplevel->icon_mask)
1141 wm_hints.flags |= IconMaskHint;
1142 wm_hints.icon_mask = cairo_xlib_surface_get_drawable (toplevel->icon_mask);
1145 wm_hints.flags |= WindowGroupHint;
1146 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1148 wm_hints.flags |= WindowGroupHint;
1149 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1152 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1154 if (toplevel->urgency_hint)
1155 wm_hints.flags |= XUrgencyHint;
1157 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1158 GDK_WINDOW_XID (window),
1163 set_initial_hints (GdkWindow *window)
1165 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1166 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1167 Window xwindow = GDK_WINDOW_XID (window);
1168 GdkWindowObject *private;
1169 GdkToplevelX11 *toplevel;
1173 private = (GdkWindowObject*) window;
1174 toplevel = _gdk_x11_window_get_toplevel (window);
1179 update_wm_hints (window, TRUE);
1181 /* We set the spec hints regardless of whether the spec is supported,
1182 * since it can't hurt and it's kind of expensive to check whether
1188 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1190 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1191 "_NET_WM_STATE_MAXIMIZED_VERT");
1193 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1194 "_NET_WM_STATE_MAXIMIZED_HORZ");
1196 toplevel->have_maxhorz = toplevel->have_maxvert = TRUE;
1199 if (private->state & GDK_WINDOW_STATE_ABOVE)
1201 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1202 "_NET_WM_STATE_ABOVE");
1206 if (private->state & GDK_WINDOW_STATE_BELOW)
1208 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1209 "_NET_WM_STATE_BELOW");
1213 if (private->state & GDK_WINDOW_STATE_STICKY)
1215 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1216 "_NET_WM_STATE_STICKY");
1218 toplevel->have_sticky = TRUE;
1221 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1223 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1224 "_NET_WM_STATE_FULLSCREEN");
1226 toplevel->have_fullscreen = TRUE;
1229 if (private->modal_hint)
1231 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1232 "_NET_WM_STATE_MODAL");
1236 if (toplevel->skip_taskbar_hint)
1238 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1239 "_NET_WM_STATE_SKIP_TASKBAR");
1243 if (toplevel->skip_pager_hint)
1245 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1246 "_NET_WM_STATE_SKIP_PAGER");
1252 XChangeProperty (xdisplay,
1254 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1255 XA_ATOM, 32, PropModeReplace,
1256 (guchar*) atoms, i);
1260 XDeleteProperty (xdisplay,
1262 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1265 if (private->state & GDK_WINDOW_STATE_STICKY)
1267 atoms[0] = 0xFFFFFFFF;
1268 XChangeProperty (xdisplay,
1270 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1271 XA_CARDINAL, 32, PropModeReplace,
1272 (guchar*) atoms, 1);
1273 toplevel->on_all_desktops = TRUE;
1277 XDeleteProperty (xdisplay,
1279 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1282 toplevel->map_serial = NextRequest (xdisplay);
1286 gdk_window_x11_show (GdkWindow *window, gboolean already_mapped)
1288 GdkWindowObject *private = (GdkWindowObject*) window;
1289 GdkDisplay *display;
1290 GdkDisplayX11 *display_x11;
1291 GdkToplevelX11 *toplevel;
1292 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1293 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1294 Window xwindow = GDK_WINDOW_XID (window);
1297 if (!already_mapped)
1298 set_initial_hints (window);
1300 if (WINDOW_IS_TOPLEVEL (window))
1302 display = gdk_window_get_display (window);
1303 display_x11 = GDK_DISPLAY_X11 (display);
1304 toplevel = _gdk_x11_window_get_toplevel (window);
1306 if (toplevel->user_time != 0 &&
1307 display_x11->user_time != 0 &&
1308 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1309 gdk_x11_window_set_user_time (window, display_x11->user_time);
1312 unset_bg = !private->input_only &&
1313 (private->window_type == GDK_WINDOW_CHILD ||
1314 impl->override_redirect) &&
1315 gdk_window_is_viewable (window);
1318 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1320 XMapWindow (xdisplay, xwindow);
1323 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1327 pre_unmap (GdkWindow *window)
1329 GdkWindow *start_window = NULL;
1330 GdkWindowObject *private = (GdkWindowObject *)window;
1332 if (private->input_only)
1335 if (private->window_type == GDK_WINDOW_CHILD)
1336 start_window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
1337 else if (private->window_type == GDK_WINDOW_TEMP)
1338 start_window = get_root (window);
1341 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1345 post_unmap (GdkWindow *window)
1347 GdkWindow *start_window = NULL;
1348 GdkWindowObject *private = (GdkWindowObject *)window;
1350 if (private->input_only)
1353 if (private->window_type == GDK_WINDOW_CHILD)
1354 start_window = _gdk_window_get_impl_window ((GdkWindow *)private->parent);
1355 else if (private->window_type == GDK_WINDOW_TEMP)
1356 start_window = get_root (window);
1360 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1362 if (private->window_type == GDK_WINDOW_CHILD && private->parent)
1364 GdkRectangle invalid_rect;
1366 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1367 invalid_rect.width = gdk_window_get_width (window);
1368 invalid_rect.height = gdk_window_get_height (window);
1369 gdk_window_invalidate_rect ((GdkWindow *)private->parent,
1370 &invalid_rect, TRUE);
1376 gdk_window_x11_hide (GdkWindow *window)
1378 GdkWindowObject *private;
1380 private = (GdkWindowObject*) window;
1382 /* We'll get the unmap notify eventually, and handle it then,
1383 * but checking here makes things more consistent if we are
1384 * just doing stuff ourself.
1386 _gdk_xgrab_check_unmap (window,
1387 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1389 /* You can't simply unmap toplevel windows. */
1390 switch (private->window_type)
1392 case GDK_WINDOW_TOPLEVEL:
1393 case GDK_WINDOW_TEMP: /* ? */
1394 gdk_window_withdraw (window);
1397 case GDK_WINDOW_FOREIGN:
1398 case GDK_WINDOW_ROOT:
1399 case GDK_WINDOW_CHILD:
1403 _gdk_window_clear_update_area (window);
1406 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1407 GDK_WINDOW_XID (window));
1408 post_unmap (window);
1412 gdk_window_x11_withdraw (GdkWindow *window)
1414 GdkWindowObject *private;
1416 private = (GdkWindowObject*) window;
1417 if (!private->destroyed)
1419 if (GDK_WINDOW_IS_MAPPED (window))
1420 gdk_synthesize_window_state (window,
1422 GDK_WINDOW_STATE_WITHDRAWN);
1424 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1428 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1429 GDK_WINDOW_XID (window), 0);
1431 post_unmap (window);
1436 window_x11_move (GdkWindow *window,
1440 GdkWindowObject *private = (GdkWindowObject *) window;
1441 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1443 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1445 _gdk_window_move_resize_child (window,
1447 private->width, private->height);
1451 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1452 GDK_WINDOW_XID (window),
1455 if (impl->override_redirect)
1464 window_x11_resize (GdkWindow *window,
1468 GdkWindowObject *private = (GdkWindowObject *) window;
1476 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1478 _gdk_window_move_resize_child (window,
1479 private->x, private->y,
1484 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1486 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1487 GDK_WINDOW_XID (window),
1490 if (impl->override_redirect)
1492 private->width = width;
1493 private->height = height;
1494 _gdk_x11_drawable_update_size (private->impl);
1498 if (width != private->width || height != private->height)
1499 private->resize_count += 1;
1503 _gdk_x11_drawable_update_size (private->impl);
1507 window_x11_move_resize (GdkWindow *window,
1513 GdkWindowObject *private = (GdkWindowObject *) window;;
1521 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1523 _gdk_window_move_resize_child (window, x, y, width, height);
1524 _gdk_x11_drawable_update_size (private->impl);
1528 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1530 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1531 GDK_WINDOW_XID (window),
1532 x, y, width, height);
1534 if (impl->override_redirect)
1539 private->width = width;
1540 private->height = height;
1542 _gdk_x11_drawable_update_size (private->impl);
1546 if (width != private->width || height != private->height)
1547 private->resize_count += 1;
1553 gdk_window_x11_move_resize (GdkWindow *window,
1560 if (with_move && (width < 0 && height < 0))
1561 window_x11_move (window, x, y);
1565 window_x11_move_resize (window, x, y, width, height);
1567 window_x11_resize (window, width, height);
1572 gdk_window_x11_reparent (GdkWindow *window,
1573 GdkWindow *new_parent,
1577 GdkWindowObject *window_private;
1578 GdkWindowObject *parent_private;
1579 GdkWindowImplX11 *impl;
1581 window_private = (GdkWindowObject*) window;
1582 parent_private = (GdkWindowObject*) new_parent;
1583 impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
1585 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1586 _gdk_x11_window_tmp_unset_parent_bg (window);
1587 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1588 GDK_WINDOW_XID (window),
1589 GDK_WINDOW_XID (new_parent),
1590 parent_private->abs_x + x, parent_private->abs_y + y);
1591 _gdk_x11_window_tmp_reset_parent_bg (window);
1592 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1594 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1595 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1597 window_private->parent = parent_private;
1599 /* Switch the window type as appropriate */
1601 switch (GDK_WINDOW_TYPE (new_parent))
1603 case GDK_WINDOW_ROOT:
1604 case GDK_WINDOW_FOREIGN:
1605 /* Reparenting to toplevel */
1607 if (!WINDOW_IS_TOPLEVEL (window) &&
1608 GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1610 /* This is also done in common code at a later stage, but we
1611 need it in setup_toplevel, so do it here too */
1612 if (window_private->toplevel_window_type != -1)
1613 GDK_WINDOW_TYPE (window) = window_private->toplevel_window_type;
1614 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1615 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1617 /* Wasn't a toplevel, set up */
1618 setup_toplevel_window (window, new_parent);
1623 case GDK_WINDOW_TOPLEVEL:
1624 case GDK_WINDOW_CHILD:
1625 case GDK_WINDOW_TEMP:
1626 if (WINDOW_IS_TOPLEVEL (window) &&
1629 if (impl->toplevel->focus_window)
1631 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1632 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1635 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1637 g_free (impl->toplevel);
1638 impl->toplevel = NULL;
1646 gdk_window_x11_raise (GdkWindow *window)
1648 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1652 gdk_window_x11_restack_under (GdkWindow *window,
1653 GList *native_siblings /* in requested order, first is bottom-most */)
1659 n_windows = g_list_length (native_siblings) + 1;
1660 windows = g_new (Window, n_windows);
1662 windows[0] = GDK_WINDOW_XID (window);
1663 /* Reverse order, as input order is bottom-most first */
1665 for (l = native_siblings; l != NULL; l = l->next)
1666 windows[i--] = GDK_WINDOW_XID (l->data);
1668 XRestackWindows (GDK_WINDOW_XDISPLAY (window), windows, n_windows);
1674 gdk_window_x11_restack_toplevel (GdkWindow *window,
1678 XWindowChanges changes;
1680 changes.sibling = GDK_WINDOW_XID (sibling);
1681 changes.stack_mode = above ? Above : Below;
1682 XReconfigureWMWindow (GDK_WINDOW_XDISPLAY (window),
1683 GDK_WINDOW_XID (window),
1684 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)),
1685 CWStackMode | CWSibling, &changes);
1689 gdk_window_x11_lower (GdkWindow *window)
1691 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1695 * gdk_x11_window_move_to_current_desktop:
1696 * @window: a #GdkWindow
1698 * Moves the window to the correct workspace when running under a
1699 * window manager that supports multiple workspaces, as described
1700 * in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
1701 * Window Manager Hints</ulink>. Will not do anything if the
1702 * window is already on all workspaces.
1707 gdk_x11_window_move_to_current_desktop (GdkWindow *window)
1709 GdkToplevelX11 *toplevel;
1711 g_return_if_fail (GDK_IS_WINDOW (window));
1712 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1714 toplevel = _gdk_x11_window_get_toplevel (window);
1716 if (toplevel->on_all_desktops)
1719 move_to_current_desktop (window);
1723 move_to_current_desktop (GdkWindow *window)
1725 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1726 gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
1733 gulong *current_desktop;
1734 GdkDisplay *display;
1736 display = gdk_window_get_display (window);
1738 /* Get current desktop, then set it; this is a race, but not
1739 * one that matters much in practice.
1741 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
1742 GDK_WINDOW_XROOTWIN (window),
1743 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
1745 False, XA_CARDINAL, &type, &format, &nitems,
1746 &bytes_after, &data);
1748 if (type == XA_CARDINAL)
1750 XClientMessageEvent xclient;
1751 current_desktop = (gulong *)data;
1753 memset (&xclient, 0, sizeof (xclient));
1754 xclient.type = ClientMessage;
1756 xclient.send_event = True;
1757 xclient.window = GDK_WINDOW_XWINDOW (window);
1758 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
1759 xclient.format = 32;
1761 xclient.data.l[0] = *current_desktop;
1762 xclient.data.l[1] = 0;
1763 xclient.data.l[2] = 0;
1764 xclient.data.l[3] = 0;
1765 xclient.data.l[4] = 0;
1767 XSendEvent (GDK_DISPLAY_XDISPLAY (display),
1768 GDK_WINDOW_XROOTWIN (window),
1770 SubstructureRedirectMask | SubstructureNotifyMask,
1771 (XEvent *)&xclient);
1773 XFree (current_desktop);
1780 * @window: a #GdkWindow
1781 * @timestamp: timestamp of the event triggering the window focus
1783 * Sets keyboard focus to @window. In most cases, gtk_window_present()
1784 * should be used on a #GtkWindow, rather than calling this function.
1788 gdk_window_focus (GdkWindow *window,
1791 GdkDisplay *display;
1793 g_return_if_fail (GDK_IS_WINDOW (window));
1795 if (GDK_WINDOW_DESTROYED (window) ||
1796 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1799 display = GDK_WINDOW_DISPLAY (window);
1801 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1802 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
1804 XClientMessageEvent xclient;
1806 memset (&xclient, 0, sizeof (xclient));
1807 xclient.type = ClientMessage;
1808 xclient.window = GDK_WINDOW_XWINDOW (window);
1809 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1810 "_NET_ACTIVE_WINDOW");
1811 xclient.format = 32;
1812 xclient.data.l[0] = 1; /* requestor type; we're an app */
1813 xclient.data.l[1] = timestamp;
1814 xclient.data.l[2] = None; /* currently active window */
1815 xclient.data.l[3] = 0;
1816 xclient.data.l[4] = 0;
1818 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1819 SubstructureRedirectMask | SubstructureNotifyMask,
1820 (XEvent *)&xclient);
1824 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1826 /* There is no way of knowing reliably whether we are viewable;
1827 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1829 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1836 * gdk_window_set_type_hint:
1837 * @window: A toplevel #GdkWindow
1838 * @hint: A hint of the function this window will have
1840 * The application can use this call to provide a hint to the window
1841 * manager about the functionality of a window. The window manager
1842 * can use this information when determining the decoration and behaviour
1845 * The hint must be set before the window is mapped.
1848 gdk_window_set_type_hint (GdkWindow *window,
1849 GdkWindowTypeHint hint)
1851 GdkDisplay *display;
1854 if (GDK_WINDOW_DESTROYED (window) ||
1855 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1858 display = gdk_window_get_display (window);
1862 case GDK_WINDOW_TYPE_HINT_DIALOG:
1863 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1865 case GDK_WINDOW_TYPE_HINT_MENU:
1866 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1868 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1869 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1871 case GDK_WINDOW_TYPE_HINT_UTILITY:
1872 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1874 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1875 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1877 case GDK_WINDOW_TYPE_HINT_DOCK:
1878 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1880 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1881 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1883 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
1884 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
1886 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
1887 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
1889 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
1890 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
1892 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
1893 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
1895 case GDK_WINDOW_TYPE_HINT_COMBO:
1896 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
1898 case GDK_WINDOW_TYPE_HINT_DND:
1899 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
1902 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1904 case GDK_WINDOW_TYPE_HINT_NORMAL:
1905 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1909 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1910 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1911 XA_ATOM, 32, PropModeReplace,
1912 (guchar *)&atom, 1);
1916 * gdk_window_get_type_hint:
1917 * @window: A toplevel #GdkWindow
1919 * This function returns the type hint set for a window.
1921 * Return value: The type hint set for @window
1926 gdk_window_get_type_hint (GdkWindow *window)
1928 GdkDisplay *display;
1929 GdkWindowTypeHint type;
1932 gulong nitems_return;
1933 gulong bytes_after_return;
1934 guchar *data = NULL;
1936 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
1938 if (GDK_WINDOW_DESTROYED (window) ||
1939 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1940 return GDK_WINDOW_TYPE_HINT_NORMAL;
1942 type = GDK_WINDOW_TYPE_HINT_NORMAL;
1944 display = gdk_window_get_display (window);
1946 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1947 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1948 0, G_MAXLONG, False, XA_ATOM, &type_return,
1949 &format_return, &nitems_return, &bytes_after_return,
1952 if ((type_return == XA_ATOM) && (format_return == 32) &&
1953 (data) && (nitems_return == 1))
1955 Atom atom = *(Atom*)data;
1957 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
1958 type = GDK_WINDOW_TYPE_HINT_DIALOG;
1959 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
1960 type = GDK_WINDOW_TYPE_HINT_MENU;
1961 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
1962 type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
1963 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
1964 type = GDK_WINDOW_TYPE_HINT_UTILITY;
1965 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
1966 type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
1967 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
1968 type = GDK_WINDOW_TYPE_HINT_DOCK;
1969 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
1970 type = GDK_WINDOW_TYPE_HINT_DESKTOP;
1971 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
1972 type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
1973 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
1974 type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
1975 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
1976 type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
1977 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
1978 type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
1979 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
1980 type = GDK_WINDOW_TYPE_HINT_COMBO;
1981 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
1982 type = GDK_WINDOW_TYPE_HINT_DND;
1985 if (type_return != None && data != NULL)
1993 gdk_wmspec_change_state (gboolean add,
1998 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1999 XClientMessageEvent xclient;
2001 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
2002 #define _NET_WM_STATE_ADD 1 /* add/set property */
2003 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
2005 memset (&xclient, 0, sizeof (xclient));
2006 xclient.type = ClientMessage;
2007 xclient.window = GDK_WINDOW_XID (window);
2008 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
2009 xclient.format = 32;
2010 xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
2011 xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
2012 xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
2013 xclient.data.l[3] = 0;
2014 xclient.data.l[4] = 0;
2016 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
2017 SubstructureRedirectMask | SubstructureNotifyMask,
2018 (XEvent *)&xclient);
2022 * gdk_window_set_modal_hint:
2023 * @window: A toplevel #GdkWindow
2024 * @modal: %TRUE if the window is modal, %FALSE otherwise.
2026 * The application can use this hint to tell the window manager
2027 * that a certain window has modal behaviour. The window manager
2028 * can use this information to handle modal windows in a special
2031 * You should only use this on windows for which you have
2032 * previously called gdk_window_set_transient_for()
2035 gdk_window_set_modal_hint (GdkWindow *window,
2038 GdkWindowObject *private;
2040 if (GDK_WINDOW_DESTROYED (window) ||
2041 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2044 private = (GdkWindowObject*) window;
2046 private->modal_hint = modal;
2048 if (GDK_WINDOW_IS_MAPPED (window))
2049 gdk_wmspec_change_state (modal, window,
2050 gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
2055 * gdk_window_set_skip_taskbar_hint:
2056 * @window: a toplevel #GdkWindow
2057 * @skips_taskbar: %TRUE to skip the taskbar
2059 * Toggles whether a window should appear in a task list or window
2060 * list. If a window's semantic type as specified with
2061 * gdk_window_set_type_hint() already fully describes the window, this
2062 * function should <emphasis>not</emphasis> be called in addition,
2063 * instead you should allow the window to be treated according to
2064 * standard policy for its semantic type.
2069 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2070 gboolean skips_taskbar)
2072 GdkToplevelX11 *toplevel;
2074 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2076 if (GDK_WINDOW_DESTROYED (window) ||
2077 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2080 toplevel = _gdk_x11_window_get_toplevel (window);
2081 toplevel->skip_taskbar_hint = skips_taskbar;
2083 if (GDK_WINDOW_IS_MAPPED (window))
2084 gdk_wmspec_change_state (skips_taskbar, window,
2085 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
2090 * gdk_window_set_skip_pager_hint:
2091 * @window: a toplevel #GdkWindow
2092 * @skips_pager: %TRUE to skip the pager
2094 * Toggles whether a window should appear in a pager (workspace
2095 * switcher, or other desktop utility program that displays a small
2096 * thumbnail representation of the windows on the desktop). If a
2097 * window's semantic type as specified with gdk_window_set_type_hint()
2098 * already fully describes the window, this function should
2099 * <emphasis>not</emphasis> be called in addition, instead you should
2100 * allow the window to be treated according to standard policy for
2101 * its semantic type.
2106 gdk_window_set_skip_pager_hint (GdkWindow *window,
2107 gboolean skips_pager)
2109 GdkToplevelX11 *toplevel;
2111 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2113 if (GDK_WINDOW_DESTROYED (window) ||
2114 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2117 toplevel = _gdk_x11_window_get_toplevel (window);
2118 toplevel->skip_pager_hint = skips_pager;
2120 if (GDK_WINDOW_IS_MAPPED (window))
2121 gdk_wmspec_change_state (skips_pager, window,
2122 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
2127 * gdk_window_set_urgency_hint:
2128 * @window: a toplevel #GdkWindow
2129 * @urgent: %TRUE if the window is urgent
2131 * Toggles whether a window needs the user's
2137 gdk_window_set_urgency_hint (GdkWindow *window,
2140 GdkToplevelX11 *toplevel;
2142 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2144 if (GDK_WINDOW_DESTROYED (window) ||
2145 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2148 toplevel = _gdk_x11_window_get_toplevel (window);
2149 toplevel->urgency_hint = urgent;
2151 update_wm_hints (window, FALSE);
2155 * gdk_window_set_geometry_hints:
2156 * @window: a toplevel #GdkWindow
2157 * @geometry: geometry hints
2158 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
2160 * Sets the geometry hints for @window. Hints flagged in @geom_mask
2161 * are set, hints not flagged in @geom_mask are unset.
2162 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
2164 * This function provides hints to the windowing system about
2165 * acceptable sizes for a toplevel window. The purpose of
2166 * this is to constrain user resizing, but the windowing system
2167 * will typically (but is not required to) also constrain the
2168 * current size of the window to the provided values and
2169 * constrain programatic resizing via gdk_window_resize() or
2170 * gdk_window_move_resize().
2172 * Note that on X11, this effect has no effect on windows
2173 * of type %GDK_WINDOW_TEMP or windows where override redirect
2174 * has been turned on via gdk_window_set_override_redirect()
2175 * since these windows are not resizable by the user.
2177 * Since you can't count on the windowing system doing the
2178 * constraints for programmatic resizes, you should generally
2179 * call gdk_window_constrain_size() yourself to determine
2180 * appropriate sizes.
2184 gdk_window_set_geometry_hints (GdkWindow *window,
2185 const GdkGeometry *geometry,
2186 GdkWindowHints geom_mask)
2188 XSizeHints size_hints;
2190 if (GDK_WINDOW_DESTROYED (window) ||
2191 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2194 size_hints.flags = 0;
2196 if (geom_mask & GDK_HINT_POS)
2198 size_hints.flags |= PPosition;
2199 /* We need to initialize the following obsolete fields because KWM
2200 * apparently uses these fields if they are non-zero.
2207 if (geom_mask & GDK_HINT_USER_POS)
2209 size_hints.flags |= USPosition;
2212 if (geom_mask & GDK_HINT_USER_SIZE)
2214 size_hints.flags |= USSize;
2217 if (geom_mask & GDK_HINT_MIN_SIZE)
2219 size_hints.flags |= PMinSize;
2220 size_hints.min_width = geometry->min_width;
2221 size_hints.min_height = geometry->min_height;
2224 if (geom_mask & GDK_HINT_MAX_SIZE)
2226 size_hints.flags |= PMaxSize;
2227 size_hints.max_width = MAX (geometry->max_width, 1);
2228 size_hints.max_height = MAX (geometry->max_height, 1);
2231 if (geom_mask & GDK_HINT_BASE_SIZE)
2233 size_hints.flags |= PBaseSize;
2234 size_hints.base_width = geometry->base_width;
2235 size_hints.base_height = geometry->base_height;
2238 if (geom_mask & GDK_HINT_RESIZE_INC)
2240 size_hints.flags |= PResizeInc;
2241 size_hints.width_inc = geometry->width_inc;
2242 size_hints.height_inc = geometry->height_inc;
2245 if (geom_mask & GDK_HINT_ASPECT)
2247 size_hints.flags |= PAspect;
2248 if (geometry->min_aspect <= 1)
2250 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2251 size_hints.min_aspect.y = 65536;
2255 size_hints.min_aspect.x = 65536;
2256 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2258 if (geometry->max_aspect <= 1)
2260 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2261 size_hints.max_aspect.y = 65536;
2265 size_hints.max_aspect.x = 65536;
2266 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2270 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2272 size_hints.flags |= PWinGravity;
2273 size_hints.win_gravity = geometry->win_gravity;
2276 /* FIXME: Would it be better to delete this property if
2277 * geom_mask == 0? It would save space on the server
2279 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2280 GDK_WINDOW_XID (window),
2285 gdk_window_get_geometry_hints (GdkWindow *window,
2286 GdkGeometry *geometry,
2287 GdkWindowHints *geom_mask)
2289 XSizeHints *size_hints;
2290 glong junk_supplied_mask = 0;
2292 g_return_if_fail (GDK_IS_WINDOW (window));
2293 g_return_if_fail (geometry != NULL);
2294 g_return_if_fail (geom_mask != NULL);
2298 if (GDK_WINDOW_DESTROYED (window) ||
2299 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2302 size_hints = XAllocSizeHints ();
2306 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2307 GDK_WINDOW_XID (window),
2309 &junk_supplied_mask))
2310 size_hints->flags = 0;
2312 if (size_hints->flags & PMinSize)
2314 *geom_mask |= GDK_HINT_MIN_SIZE;
2315 geometry->min_width = size_hints->min_width;
2316 geometry->min_height = size_hints->min_height;
2319 if (size_hints->flags & PMaxSize)
2321 *geom_mask |= GDK_HINT_MAX_SIZE;
2322 geometry->max_width = MAX (size_hints->max_width, 1);
2323 geometry->max_height = MAX (size_hints->max_height, 1);
2326 if (size_hints->flags & PResizeInc)
2328 *geom_mask |= GDK_HINT_RESIZE_INC;
2329 geometry->width_inc = size_hints->width_inc;
2330 geometry->height_inc = size_hints->height_inc;
2333 if (size_hints->flags & PAspect)
2335 *geom_mask |= GDK_HINT_ASPECT;
2337 geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y;
2338 geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y;
2341 if (size_hints->flags & PWinGravity)
2343 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2344 geometry->win_gravity = size_hints->win_gravity;
2351 utf8_is_latin1 (const gchar *str)
2353 const char *p = str;
2357 gunichar ch = g_utf8_get_char (p);
2362 p = g_utf8_next_char (p);
2368 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2369 * convertable to STRING, otherwise, set it as compound text
2372 set_text_property (GdkDisplay *display,
2375 const gchar *utf8_str)
2377 gchar *prop_text = NULL;
2381 gboolean is_compound_text;
2383 if (utf8_is_latin1 (utf8_str))
2385 prop_type = XA_STRING;
2386 prop_text = gdk_utf8_to_string_target (utf8_str);
2387 prop_length = prop_text ? strlen (prop_text) : 0;
2389 is_compound_text = FALSE;
2395 gdk_utf8_to_compound_text_for_display (display,
2396 utf8_str, &gdk_type, &prop_format,
2397 (guchar **)&prop_text, &prop_length);
2398 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2399 is_compound_text = TRUE;
2404 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2407 prop_type, prop_format,
2408 PropModeReplace, (guchar *)prop_text,
2411 if (is_compound_text)
2412 gdk_free_compound_text ((guchar *)prop_text);
2418 /* Set WM_NAME and _NET_WM_NAME
2421 set_wm_name (GdkDisplay *display,
2425 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2426 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2427 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2428 PropModeReplace, (guchar *)name, strlen (name));
2430 set_text_property (display, xwindow,
2431 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2436 * gdk_window_set_title:
2437 * @window: a toplevel #GdkWindow
2438 * @title: title of @window
2440 * Sets the title of a toplevel window, to be displayed in the titlebar.
2441 * If you haven't explicitly set the icon name for the window
2442 * (using gdk_window_set_icon_name()), the icon name will be set to
2443 * @title as well. @title must be in UTF-8 encoding (as with all
2444 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2447 gdk_window_set_title (GdkWindow *window,
2450 GdkDisplay *display;
2454 g_return_if_fail (title != NULL);
2456 if (GDK_WINDOW_DESTROYED (window) ||
2457 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2460 display = gdk_window_get_display (window);
2461 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2462 xwindow = GDK_WINDOW_XID (window);
2464 set_wm_name (display, xwindow, title);
2466 if (!gdk_window_icon_name_set (window))
2468 XChangeProperty (xdisplay, xwindow,
2469 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2470 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2471 PropModeReplace, (guchar *)title, strlen (title));
2473 set_text_property (display, xwindow,
2474 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2480 * gdk_window_set_role:
2481 * @window: a toplevel #GdkWindow
2482 * @role: a string indicating its role
2484 * When using GTK+, typically you should use gtk_window_set_role() instead
2485 * of this low-level function.
2487 * The window manager and session manager use a window's role to
2488 * distinguish it from other kinds of window in the same application.
2489 * When an application is restarted after being saved in a previous
2490 * session, all windows with the same title and role are treated as
2491 * interchangeable. So if you have two windows with the same title
2492 * that should be distinguished for session management purposes, you
2493 * should set the role on those windows. It doesn't matter what string
2494 * you use for the role, as long as you have a different role for each
2495 * non-interchangeable kind of window.
2499 gdk_window_set_role (GdkWindow *window,
2502 GdkDisplay *display;
2504 display = gdk_window_get_display (window);
2506 if (GDK_WINDOW_DESTROYED (window) ||
2507 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2511 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2512 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2513 XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
2515 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2516 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2520 * gdk_window_set_startup_id:
2521 * @window: a toplevel #GdkWindow
2522 * @startup_id: a string with startup-notification identifier
2524 * When using GTK+, typically you should use gtk_window_set_startup_id()
2525 * instead of this low-level function.
2531 gdk_window_set_startup_id (GdkWindow *window,
2532 const gchar *startup_id)
2534 GdkDisplay *display;
2536 g_return_if_fail (GDK_IS_WINDOW (window));
2538 display = gdk_window_get_display (window);
2540 if (GDK_WINDOW_DESTROYED (window) ||
2541 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2545 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2546 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2547 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2548 PropModeReplace, (unsigned char *)startup_id, strlen (startup_id));
2550 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2551 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"));
2555 * gdk_window_set_transient_for:
2556 * @window: a toplevel #GdkWindow
2557 * @parent: another toplevel #GdkWindow
2559 * Indicates to the window manager that @window is a transient dialog
2560 * associated with the application window @parent. This allows the
2561 * window manager to do things like center @window on @parent and
2562 * keep @window above @parent.
2564 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2568 gdk_window_set_transient_for (GdkWindow *window,
2571 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) &&
2572 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2573 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2574 GDK_WINDOW_XID (window),
2575 GDK_WINDOW_XID (parent));
2579 gdk_window_x11_set_back_color (GdkWindow *window,
2585 GdkVisual *visual = gdk_window_get_visual (window);
2587 /* I suppose we could handle these, but that'd require fiddling with
2588 * xrender formats... */
2592 switch (visual->type)
2594 case GDK_VISUAL_DIRECT_COLOR:
2595 case GDK_VISUAL_TRUE_COLOR:
2597 /* If bits not used for color are used for something other than padding,
2598 * it's likely alpha, so we set them to 1s.
2600 guint padding, pixel;
2602 /* Shifting by >= width-of-type isn't defined in C */
2603 if (visual->depth >= 32)
2606 padding = ((~(guint32)0)) << visual->depth;
2608 pixel = ~ (visual->red_mask | visual->green_mask | visual->blue_mask | padding);
2610 pixel += (((int) (red * ((1 << visual->red_prec ) - 1))) << visual->red_shift ) +
2611 (((int) (green * ((1 << visual->green_prec) - 1))) << visual->green_shift) +
2612 (((int) (blue * ((1 << visual->blue_prec ) - 1))) << visual->blue_shift );
2614 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2615 GDK_WINDOW_XID (window), pixel);
2619 /* These require fiddling with the colormap, and as they're essentially unused
2620 * we're just gonna skip them for now.
2622 case GDK_VISUAL_PSEUDO_COLOR:
2623 case GDK_VISUAL_GRAYSCALE:
2624 case GDK_VISUAL_STATIC_GRAY:
2625 case GDK_VISUAL_STATIC_COLOR:
2634 matrix_is_identity (cairo_matrix_t *matrix)
2636 return matrix->xx == 1.0 && matrix->yy == 1.0 &&
2637 matrix->yx == 0.0 && matrix->xy == 0.0 &&
2638 matrix->x0 == 0.0 && matrix->y0 == 0.0;
2642 gdk_window_x11_set_background (GdkWindow *window,
2643 cairo_pattern_t *pattern)
2646 cairo_surface_t *surface;
2647 cairo_matrix_t matrix;
2649 if (GDK_WINDOW_DESTROYED (window))
2652 if (pattern == NULL)
2656 /* X throws BadMatch if the parent has a different visual when
2657 * using ParentRelative */
2658 parent = gdk_window_get_parent (window);
2659 if (parent && gdk_window_get_visual (parent) == gdk_window_get_visual (window))
2660 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2661 GDK_WINDOW_XID (window), ParentRelative);
2663 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2664 GDK_WINDOW_XID (window), None);
2668 switch (cairo_pattern_get_type (pattern))
2670 case CAIRO_PATTERN_TYPE_SOLID:
2671 cairo_pattern_get_rgba (pattern, &r, &g, &b, &a);
2672 if (gdk_window_x11_set_back_color (window, r, g, b, a))
2675 case CAIRO_PATTERN_TYPE_SURFACE:
2676 cairo_pattern_get_matrix (pattern, &matrix);
2677 if (cairo_pattern_get_surface (pattern, &surface) == CAIRO_STATUS_SUCCESS &&
2678 matrix_is_identity (&matrix) &&
2679 cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB &&
2680 cairo_xlib_surface_get_visual (surface) == GDK_VISUAL_XVISUAL (gdk_window_get_visual ((window))) &&
2681 cairo_xlib_surface_get_display (surface) == GDK_WINDOW_XDISPLAY (window))
2685 cairo_surface_get_device_offset (surface, &x, &y);
2686 /* XXX: This still bombs for non-pixmaps, but there's no way to
2687 * detect we're not a pixmap in Cairo... */
2688 if (x == 0.0 && y == 0.0)
2690 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2691 GDK_WINDOW_XID (window),
2692 cairo_xlib_surface_get_drawable (surface));
2697 case CAIRO_PATTERN_TYPE_LINEAR:
2698 case CAIRO_PATTERN_TYPE_RADIAL:
2700 /* fallback: just use black */
2704 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2705 GDK_WINDOW_XID (window), None);
2709 gdk_window_x11_set_device_cursor (GdkWindow *window,
2713 GdkWindowObject *private;
2714 GdkWindowImplX11 *impl;
2716 g_return_if_fail (GDK_IS_WINDOW (window));
2717 g_return_if_fail (GDK_IS_DEVICE (device));
2719 private = (GdkWindowObject *) window;
2720 impl = GDK_WINDOW_IMPL_X11 (private->impl);
2723 g_hash_table_remove (impl->device_cursor, device);
2726 _gdk_x11_cursor_update_theme (cursor);
2727 g_hash_table_replace (impl->device_cursor,
2728 device, gdk_cursor_ref (cursor));
2731 if (!GDK_WINDOW_DESTROYED (window))
2732 GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor);
2736 _gdk_x11_window_get_cursor (GdkWindow *window)
2738 GdkWindowObject *private;
2739 GdkWindowImplX11 *impl;
2741 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2743 private = (GdkWindowObject *)window;
2744 impl = GDK_WINDOW_IMPL_X11 (private->impl);
2746 return impl->cursor;
2750 gdk_window_x11_get_geometry (GdkWindow *window,
2762 guint tborder_width;
2765 if (!GDK_WINDOW_DESTROYED (window))
2767 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2768 GDK_WINDOW_XID (window),
2769 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2785 gdk_window_x11_get_root_coords (GdkWindow *window,
2796 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2797 GDK_WINDOW_XID (window),
2798 GDK_WINDOW_XROOTWIN (window),
2811 * gdk_window_get_root_origin:
2812 * @window: a toplevel #GdkWindow
2813 * @x: return location for X position of window frame
2814 * @y: return location for Y position of window frame
2816 * Obtains the top-left corner of the window manager frame in root
2817 * window coordinates.
2821 gdk_window_get_root_origin (GdkWindow *window,
2827 gdk_window_get_frame_extents (window, &rect);
2837 * gdk_window_get_frame_extents:
2838 * @window: a toplevel #GdkWindow
2839 * @rect: rectangle to fill with bounding box of the window frame
2841 * Obtains the bounding box of the window, including window manager
2842 * titlebar/borders if any. The frame position is given in root window
2843 * coordinates. To get the position of the window itself (rather than
2844 * the frame) in root window coordinates, use gdk_window_get_origin().
2848 gdk_window_get_frame_extents (GdkWindow *window,
2851 GdkDisplay *display;
2852 GdkWindowObject *private;
2853 GdkWindowImplX11 *impl;
2864 gulong nitems_return;
2865 gulong bytes_after_return;
2868 guint ww, wh, wb, wd;
2870 gboolean got_frame_extents = FALSE;
2872 g_return_if_fail (rect != NULL);
2874 private = (GdkWindowObject*) window;
2881 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2882 private = (GdkWindowObject*) private->parent;
2884 /* Refine our fallback answer a bit using local information */
2885 rect->x = private->x;
2886 rect->y = private->y;
2887 rect->width = private->width;
2888 rect->height = private->height;
2890 impl = GDK_WINDOW_IMPL_X11 (private->impl);
2891 if (GDK_WINDOW_DESTROYED (private) || impl->override_redirect)
2897 gdk_error_trap_push();
2899 display = gdk_window_get_display (window);
2900 xwindow = GDK_WINDOW_XID (window);
2902 /* first try: use _NET_FRAME_EXTENTS */
2903 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2904 gdk_x11_get_xatom_by_name_for_display (display,
2905 "_NET_FRAME_EXTENTS"),
2906 0, G_MAXLONG, False, XA_CARDINAL, &type_return,
2907 &format_return, &nitems_return, &bytes_after_return,
2911 if ((type_return == XA_CARDINAL) && (format_return == 32) &&
2912 (nitems_return == 4) && (data))
2914 gulong *ldata = (gulong *) data;
2915 got_frame_extents = TRUE;
2917 /* try to get the real client window geometry */
2918 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2919 &root, &wx, &wy, &ww, &wh, &wb, &wd) &&
2920 XTranslateCoordinates (GDK_DISPLAY_XDISPLAY (display),
2921 xwindow, root, 0, 0, &wx, &wy, &child))
2929 /* _NET_FRAME_EXTENTS format is left, right, top, bottom */
2930 rect->x -= ldata[0];
2931 rect->y -= ldata[2];
2932 rect->width += ldata[0] + ldata[1];
2933 rect->height += ldata[2] + ldata[3];
2940 if (got_frame_extents)
2943 /* no frame extents property available, which means we either have a WM that
2944 is not EWMH compliant or is broken - try fallback and walk up the window
2945 tree to get our window's parent which hopefully is the window frame */
2947 /* use NETWM_VIRTUAL_ROOTS if available */
2948 root = GDK_WINDOW_XROOTWIN (window);
2950 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
2951 gdk_x11_get_xatom_by_name_for_display (display,
2952 "_NET_VIRTUAL_ROOTS"),
2953 0, G_MAXLONG, False, XA_WINDOW, &type_return,
2954 &format_return, &nitems_return, &bytes_after_return,
2958 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
2960 nvroots = nitems_return;
2961 vroots = (Window *)data;
2965 xparent = GDK_WINDOW_XID (window);
2971 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
2973 &children, &nchildren))
2979 /* check virtual roots */
2980 for (i = 0; i < nvroots; i++)
2982 if (xparent == vroots[i])
2989 while (xparent != root);
2991 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2992 &root, &wx, &wy, &ww, &wh, &wb, &wd))
3004 gdk_error_trap_pop_ignored ();
3008 _gdk_windowing_get_device_state (GdkDisplay *display,
3013 GdkModifierType *mask)
3015 GdkScreen *default_screen;
3017 if (display->closed)
3020 default_screen = gdk_display_get_default_screen (display);
3023 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3027 GDK_DEVICE_GET_CLASS (device)->query_state (device,
3028 gdk_screen_get_root_window (default_screen),
3033 *screen = gdk_window_get_screen (root);
3037 XSetWindowAttributes attributes;
3039 Window xwindow, w, root, child;
3040 int rootx, rooty, winx, winy;
3043 /* FIXME: untrusted clients not multidevice-safe */
3045 xdisplay = GDK_SCREEN_XDISPLAY (default_screen);
3046 xwindow = GDK_SCREEN_XROOTWIN (default_screen);
3048 w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0,
3049 CopyFromParent, InputOnly, CopyFromParent,
3051 XQueryPointer (xdisplay, w,
3052 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3053 XDestroyWindow (xdisplay, w);
3057 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
3058 *screen = gdk_window_get_screen (gdk_root);
3068 gdk_window_x11_get_device_state (GdkWindow *window,
3072 GdkModifierType *mask)
3074 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
3075 gboolean return_val;
3077 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
3081 if (!GDK_WINDOW_DESTROYED (window))
3083 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3087 GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
3091 return_val = (child != NULL);
3096 int originx, originy;
3100 unsigned int xmask = 0;
3102 _gdk_windowing_get_device_state (gdk_window_get_display (window), device,
3103 &screen, &rootx, &rooty, &xmask);
3104 gdk_window_get_origin (window, &originx, &originy);
3105 winx = rootx - originx;
3106 winy = rooty - originy;
3118 * gdk_display_warp_pointer:
3119 * @display: a #GdkDisplay
3120 * @screen: the screen of @display to warp the pointer to
3121 * @x: the x coordinate of the destination
3122 * @y: the y coordinate of the destination
3124 * Warps the pointer of @display to the point @x,@y on
3125 * the screen @screen, unless the pointer is confined
3126 * to a window by a grab, in which case it will be moved
3127 * as far as allowed by the grab. Warping the pointer
3128 * creates events as if the user had moved the mouse
3129 * instantaneously to the destination.
3131 * Note that the pointer should normally be under the
3132 * control of the user. This function was added to cover
3133 * some rare use cases like keyboard navigation support
3134 * for the color picker in the #GtkColorSelectionDialog.
3138 * Deprecated: 3.0: Use gdk_display_warp_device() instead.
3141 gdk_display_warp_pointer (GdkDisplay *display,
3148 g_return_if_fail (GDK_IS_DISPLAY (display));
3149 g_return_if_fail (GDK_IS_SCREEN (screen));
3151 device = display->core_pointer;
3152 GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
3156 * gdk_display_warp_device:
3157 * @display: a #GdkDisplay.
3158 * @device: a #GdkDevice.
3159 * @screen: the screen of @display to warp @device to.
3160 * @x: the X coordinate of the destination.
3161 * @y: the Y coordinate of the destination.
3163 * Warps @device in @display to the point @x,@y on
3164 * the screen @screen, unless the device is confined
3165 * to a window by a grab, in which case it will be moved
3166 * as far as allowed by the grab. Warping the pointer
3167 * creates events as if the user had moved the mouse
3168 * instantaneously to the destination.
3170 * Note that the pointer should normally be under the
3171 * control of the user. This function was added to cover
3172 * some rare use cases like keyboard navigation support
3173 * for the color picker in the #GtkColorSelectionDialog.
3178 gdk_display_warp_device (GdkDisplay *display,
3184 g_return_if_fail (GDK_IS_DISPLAY (display));
3185 g_return_if_fail (GDK_IS_DEVICE (device));
3186 g_return_if_fail (GDK_IS_SCREEN (screen));
3187 g_return_if_fail (display == gdk_device_get_display (device));
3189 GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
3193 _gdk_windowing_window_at_device_position (GdkDisplay *display,
3197 GdkModifierType *mask,
3198 gboolean get_toplevel)
3203 screen = gdk_display_get_default_screen (display);
3205 /* This function really only works if the mouse pointer is held still
3206 * during its operation. If it moves from one leaf window to another
3207 * than we'll end up with inaccurate values for win_x, win_y
3210 gdk_x11_display_grab (display);
3211 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3212 window = GDK_DEVICE_GET_CLASS (device)->window_at_position (device, win_x, win_y, mask, get_toplevel);
3215 gint i, screens, width, height;
3216 GList *toplevels, *list;
3217 Window pointer_window, root, xwindow, child;
3218 Window xwindow_last = 0;
3220 int rootx = -1, rooty = -1;
3224 /* FIXME: untrusted clients case not multidevice-safe */
3226 xwindow = GDK_SCREEN_XROOTWIN (screen);
3227 xdisplay = GDK_SCREEN_XDISPLAY (screen);
3229 pointer_window = None;
3230 screens = gdk_display_get_n_screens (display);
3231 for (i = 0; i < screens; ++i) {
3232 screen = gdk_display_get_screen (display, i);
3233 toplevels = gdk_screen_get_toplevel_windows (screen);
3234 for (list = toplevels; list != NULL; list = g_list_next (list)) {
3235 window = GDK_WINDOW (list->data);
3236 xwindow = GDK_WINDOW_XWINDOW (window);
3237 gdk_error_trap_push ();
3238 XQueryPointer (xdisplay, xwindow,
3239 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3240 if (gdk_error_trap_pop ())
3244 pointer_window = child;
3247 gdk_window_get_geometry (window, NULL, NULL, &width, &height, NULL);
3248 if (winx >= 0 && winy >= 0 && winx < width && winy < height)
3250 /* A childless toplevel, or below another window? */
3251 XSetWindowAttributes attributes;
3254 w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0,
3255 CopyFromParent, InputOnly, CopyFromParent,
3257 XMapWindow (xdisplay, w);
3258 XQueryPointer (xdisplay, xwindow,
3259 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3260 XDestroyWindow (xdisplay, w);
3263 pointer_window = xwindow;
3268 g_list_free (toplevels);
3269 if (pointer_window != None)
3272 xwindow = pointer_window;
3276 xwindow_last = xwindow;
3277 gdk_error_trap_push ();
3278 XQueryPointer (xdisplay, xwindow,
3279 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3280 if (gdk_error_trap_pop ())
3282 if (get_toplevel && xwindow_last != root &&
3283 (window = gdk_window_lookup_for_display (display, xwindow_last)) != NULL &&
3284 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
3288 window = gdk_window_lookup_for_display (display, xwindow_last);
3290 *win_x = window ? winx : -1;
3291 *win_y = window ? winy : -1;
3296 gdk_x11_display_ungrab (display);
3302 gdk_window_x11_get_events (GdkWindow *window)
3304 XWindowAttributes attrs;
3305 GdkEventMask event_mask;
3306 GdkEventMask filtered;
3308 if (GDK_WINDOW_DESTROYED (window))
3312 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3313 GDK_WINDOW_XID (window),
3315 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
3316 /* if property change was filtered out before, keep it filtered out */
3317 filtered = GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK;
3318 GDK_WINDOW_OBJECT (window)->event_mask = event_mask & ((GDK_WINDOW_OBJECT (window)->event_mask & filtered) | ~filtered);
3324 gdk_window_x11_set_events (GdkWindow *window,
3325 GdkEventMask event_mask)
3327 long xevent_mask = 0;
3329 if (!GDK_WINDOW_DESTROYED (window))
3331 GdkDisplayX11 *display_x11;
3333 if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window))
3334 xevent_mask = StructureNotifyMask | PropertyChangeMask;
3336 display_x11 = GDK_DISPLAY_X11 (gdk_window_get_display (window));
3337 gdk_event_source_select_events ((GdkEventSource *) display_x11->event_source,
3338 GDK_WINDOW_XWINDOW (window), event_mask,
3344 do_shape_combine_region (GdkWindow *window,
3345 const cairo_region_t *shape_region,
3350 if (GDK_WINDOW_DESTROYED (window))
3353 if (shape_region == NULL)
3355 /* Use NULL mask to unset the shape */
3356 if (shape == ShapeBounding
3357 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3358 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3360 if (shape == ShapeBounding)
3362 _gdk_x11_window_tmp_unset_parent_bg (window);
3363 _gdk_x11_window_tmp_unset_bg (window, TRUE);
3365 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3366 GDK_WINDOW_XID (window),
3371 if (shape == ShapeBounding)
3373 _gdk_x11_window_tmp_reset_parent_bg (window);
3374 _gdk_x11_window_tmp_reset_bg (window, TRUE);
3380 if (shape == ShapeBounding
3381 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3382 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3385 XRectangle *xrects = NULL;
3387 _gdk_region_get_xrectangles (shape_region,
3391 if (shape == ShapeBounding)
3393 _gdk_x11_window_tmp_unset_parent_bg (window);
3394 _gdk_x11_window_tmp_unset_bg (window, TRUE);
3396 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3397 GDK_WINDOW_XID (window),
3404 if (shape == ShapeBounding)
3406 _gdk_x11_window_tmp_reset_parent_bg (window);
3407 _gdk_x11_window_tmp_reset_bg (window, TRUE);
3415 gdk_window_x11_shape_combine_region (GdkWindow *window,
3416 const cairo_region_t *shape_region,
3420 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
3424 gdk_window_x11_input_shape_combine_region (GdkWindow *window,
3425 const cairo_region_t *shape_region,
3430 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
3436 * gdk_window_set_override_redirect:
3437 * @window: a toplevel #GdkWindow
3438 * @override_redirect: %TRUE if window should be override redirect
3440 * An override redirect window is not under the control of the window manager.
3441 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3442 * be entirely under the control of the application. The window manager
3443 * can't see the override redirect window at all.
3445 * Override redirect should only be used for short-lived temporary
3446 * windows, such as popup menus. #GtkMenu uses an override redirect
3447 * window in its implementation, for example.
3451 gdk_window_set_override_redirect (GdkWindow *window,
3452 gboolean override_redirect)
3454 XSetWindowAttributes attr;
3456 if (!GDK_WINDOW_DESTROYED (window) &&
3457 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3459 GdkWindowObject *private = (GdkWindowObject *)window;
3460 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
3462 attr.override_redirect = (override_redirect? True : False);
3463 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3464 GDK_WINDOW_XID (window),
3468 impl->override_redirect = attr.override_redirect;
3473 * gdk_window_set_accept_focus:
3474 * @window: a toplevel #GdkWindow
3475 * @accept_focus: %TRUE if the window should receive input focus
3477 * Setting @accept_focus to %FALSE hints the desktop environment that the
3478 * window doesn't want to receive input focus.
3480 * On X, it is the responsibility of the window manager to interpret this
3481 * hint. ICCCM-compliant window manager usually respect it.
3486 gdk_window_set_accept_focus (GdkWindow *window,
3487 gboolean accept_focus)
3489 GdkWindowObject *private;
3491 private = (GdkWindowObject *)window;
3493 accept_focus = accept_focus != FALSE;
3495 if (private->accept_focus != accept_focus)
3497 private->accept_focus = accept_focus;
3499 if (!GDK_WINDOW_DESTROYED (window) &&
3500 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3501 update_wm_hints (window, FALSE);
3506 * gdk_window_set_focus_on_map:
3507 * @window: a toplevel #GdkWindow
3508 * @focus_on_map: %TRUE if the window should receive input focus when mapped
3510 * Setting @focus_on_map to %FALSE hints the desktop environment that the
3511 * window doesn't want to receive input focus when it is mapped.
3512 * focus_on_map should be turned off for windows that aren't triggered
3513 * interactively (such as popups from network activity).
3515 * On X, it is the responsibility of the window manager to interpret
3516 * this hint. Window managers following the freedesktop.org window
3517 * manager extension specification should respect it.
3522 gdk_window_set_focus_on_map (GdkWindow *window,
3523 gboolean focus_on_map)
3525 GdkWindowObject *private;
3527 private = (GdkWindowObject *)window;
3529 focus_on_map = focus_on_map != FALSE;
3531 if (private->focus_on_map != focus_on_map)
3533 private->focus_on_map = focus_on_map;
3535 if ((!GDK_WINDOW_DESTROYED (window)) &&
3536 (!private->focus_on_map) &&
3537 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3538 gdk_x11_window_set_user_time (window, 0);
3543 * gdk_x11_window_set_user_time:
3544 * @window: A toplevel #GdkWindow
3545 * @timestamp: An XServer timestamp to which the property should be set
3547 * The application can use this call to update the _NET_WM_USER_TIME
3548 * property on a toplevel window. This property stores an Xserver
3549 * time which represents the time of the last user input event
3550 * received for this window. This property may be used by the window
3551 * manager to alter the focus, stacking, and/or placement behavior of
3552 * windows when they are mapped depending on whether the new window
3553 * was created by a user action or is a "pop-up" window activated by a
3554 * timer or some other event.
3556 * Note that this property is automatically updated by GDK, so this
3557 * function should only be used by applications which handle input
3558 * events bypassing GDK.
3563 gdk_x11_window_set_user_time (GdkWindow *window,
3566 GdkDisplay *display;
3567 GdkDisplayX11 *display_x11;
3568 GdkToplevelX11 *toplevel;
3569 glong timestamp_long = (glong)timestamp;
3572 if (GDK_WINDOW_DESTROYED (window) ||
3573 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3576 display = gdk_window_get_display (window);
3577 display_x11 = GDK_DISPLAY_X11 (display);
3578 toplevel = _gdk_x11_window_get_toplevel (window);
3582 g_warning ("gdk_window_set_user_time called on non-toplevel\n");
3586 if (toplevel->focus_window != None &&
3587 gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
3588 gdk_atom_intern_static_string ("_NET_WM_USER_TIME_WINDOW")))
3589 xid = toplevel->focus_window;
3591 xid = GDK_WINDOW_XID (window);
3593 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xid,
3594 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3595 XA_CARDINAL, 32, PropModeReplace,
3596 (guchar *)×tamp_long, 1);
3598 if (timestamp_long != GDK_CURRENT_TIME &&
3599 (display_x11->user_time == GDK_CURRENT_TIME ||
3600 XSERVER_TIME_IS_LATER (timestamp_long, display_x11->user_time)))
3601 display_x11->user_time = timestamp_long;
3604 toplevel->user_time = timestamp_long;
3607 #define GDK_SELECTION_MAX_SIZE(display) \
3609 XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
3610 ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
3611 : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
3614 gdk_window_update_icon (GdkWindow *window,
3617 GdkToplevelX11 *toplevel;
3618 GdkPixbuf *best_icon;
3622 toplevel = _gdk_x11_window_get_toplevel (window);
3624 if (toplevel->icon_pixmap != NULL)
3626 cairo_surface_destroy (toplevel->icon_pixmap);
3627 toplevel->icon_pixmap = NULL;
3630 if (toplevel->icon_mask != NULL)
3632 cairo_surface_destroy (toplevel->icon_mask);
3633 toplevel->icon_mask = NULL;
3636 #define IDEAL_SIZE 48
3638 best_size = G_MAXINT;
3640 for (tmp_list = icon_list; tmp_list; tmp_list = tmp_list->next)
3642 GdkPixbuf *pixbuf = tmp_list->data;
3645 /* average width and height - if someone passes in a rectangular
3646 * icon they deserve what they get.
3648 this = gdk_pixbuf_get_width (pixbuf) + gdk_pixbuf_get_height (pixbuf);
3651 if (best_icon == NULL)
3658 /* icon is better if it's 32 pixels or larger, and closer to
3659 * the ideal size than the current best.
3662 (ABS (best_size - IDEAL_SIZE) <
3663 ABS (this - IDEAL_SIZE)))
3673 int width = gdk_pixbuf_get_width (best_icon);
3674 int height = gdk_pixbuf_get_height (best_icon);
3677 toplevel->icon_pixmap = gdk_x11_window_create_pixmap_surface (window,
3681 cr = cairo_create (toplevel->icon_pixmap);
3682 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3683 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3684 if (gdk_pixbuf_get_has_alpha (best_icon))
3686 /* Saturate the image, so it has bilevel alpha */
3687 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
3689 cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);
3691 cairo_pop_group_to_source (cr);
3696 if (gdk_pixbuf_get_has_alpha (best_icon))
3698 toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window,
3702 cr = cairo_create (toplevel->icon_mask);
3703 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3704 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3710 update_wm_hints (window, FALSE);
3714 * gdk_window_set_icon_list:
3715 * @window: The #GdkWindow toplevel window to set the icon of.
3716 * @pixbufs: (transfer none) (element-type GdkPixbuf):
3717 * A list of pixbufs, of different sizes.
3719 * Sets a list of icons for the window. One of these will be used
3720 * to represent the window when it has been iconified. The icon is
3721 * usually shown in an icon box or some sort of task bar. Which icon
3722 * size is shown depends on the window manager. The window manager
3723 * can scale the icon but setting several size icons can give better
3724 * image quality since the window manager may only need to scale the
3725 * icon by a small amount or not at all.
3729 gdk_window_set_icon_list (GdkWindow *window,
3738 gint width, height, stride;
3741 GdkDisplay *display;
3744 if (GDK_WINDOW_DESTROYED (window) ||
3745 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3748 display = gdk_window_get_display (window);
3756 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3758 width = gdk_pixbuf_get_width (pixbuf);
3759 height = gdk_pixbuf_get_height (pixbuf);
3761 /* silently ignore overlarge icons */
3762 if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
3764 g_warning ("gdk_window_set_icon_list: icons too large");
3769 size += 2 + width * height;
3771 l = g_list_next (l);
3774 data = g_malloc (size * sizeof (gulong));
3782 width = gdk_pixbuf_get_width (pixbuf);
3783 height = gdk_pixbuf_get_height (pixbuf);
3784 stride = gdk_pixbuf_get_rowstride (pixbuf);
3785 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3790 pixels = gdk_pixbuf_get_pixels (pixbuf);
3792 for (y = 0; y < height; y++)
3794 for (x = 0; x < width; x++)
3798 r = pixels[y*stride + x*n_channels + 0];
3799 g = pixels[y*stride + x*n_channels + 1];
3800 b = pixels[y*stride + x*n_channels + 2];
3801 if (n_channels >= 4)
3802 a = pixels[y*stride + x*n_channels + 3];
3806 *p++ = a << 24 | r << 16 | g << 8 | b ;
3810 l = g_list_next (l);
3816 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3817 GDK_WINDOW_XID (window),
3818 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3821 (guchar*) data, size);
3825 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3826 GDK_WINDOW_XID (window),
3827 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3832 gdk_window_update_icon (window, pixbufs);
3836 gdk_window_icon_name_set (GdkWindow *window)
3838 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3839 g_quark_from_static_string ("gdk-icon-name-set")));
3843 * gdk_window_set_icon_name:
3844 * @window: a toplevel #GdkWindow
3845 * @name: name of window while iconified (minimized)
3847 * Windows may have a name used while minimized, distinct from the
3848 * name they display in their titlebar. Most of the time this is a bad
3849 * idea from a user interface standpoint. But you can set such a name
3850 * with this function, if you like.
3852 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
3853 * will not update the icon title.
3855 * Using %NULL for @name unsets the icon title; further calls to
3856 * gdk_window_set_title() will again update the icon title as well.
3859 gdk_window_set_icon_name (GdkWindow *window,
3862 GdkDisplay *display;
3864 if (GDK_WINDOW_DESTROYED (window) ||
3865 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3868 display = gdk_window_get_display (window);
3870 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3871 GUINT_TO_POINTER (name != NULL));
3875 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3876 GDK_WINDOW_XID (window),
3877 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3878 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3879 PropModeReplace, (guchar *)name, strlen (name));
3881 set_text_property (display, GDK_WINDOW_XID (window),
3882 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3887 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3888 GDK_WINDOW_XID (window),
3889 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"));
3890 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3891 GDK_WINDOW_XID (window),
3892 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"));
3897 * gdk_window_iconify:
3898 * @window: a toplevel #GdkWindow
3900 * Asks to iconify (minimize) @window. The window manager may choose
3901 * to ignore the request, but normally will honor it. Using
3902 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3904 * This function only makes sense when @window is a toplevel window.
3908 gdk_window_iconify (GdkWindow *window)
3910 if (GDK_WINDOW_DESTROYED (window) ||
3911 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3914 if (GDK_WINDOW_IS_MAPPED (window))
3916 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3917 GDK_WINDOW_XWINDOW (window),
3918 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3922 /* Flip our client side flag, the real work happens on map. */
3923 gdk_synthesize_window_state (window,
3925 GDK_WINDOW_STATE_ICONIFIED);
3930 * gdk_window_deiconify:
3931 * @window: a toplevel #GdkWindow
3933 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3934 * choose to ignore the request to deiconify. When using GTK+,
3935 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3936 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3937 * unminimizes it, and puts it on the current desktop.
3941 gdk_window_deiconify (GdkWindow *window)
3943 if (GDK_WINDOW_DESTROYED (window) ||
3944 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3947 if (GDK_WINDOW_IS_MAPPED (window))
3949 gdk_window_show (window);
3953 /* Flip our client side flag, the real work happens on map. */
3954 gdk_synthesize_window_state (window,
3955 GDK_WINDOW_STATE_ICONIFIED,
3962 * @window: a toplevel #GdkWindow
3964 * "Pins" a window such that it's on all workspaces and does not scroll
3965 * with viewports, for window managers that have scrollable viewports.
3966 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3968 * On the X11 platform, this function depends on window manager
3969 * support, so may have no effect with many window managers. However,
3970 * GDK will do the best it can to convince the window manager to stick
3971 * the window. For window managers that don't support this operation,
3972 * there's nothing you can do to force it to happen.
3976 gdk_window_stick (GdkWindow *window)
3978 if (GDK_WINDOW_DESTROYED (window) ||
3979 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3982 if (GDK_WINDOW_IS_MAPPED (window))
3984 /* "stick" means stick to all desktops _and_ do not scroll with the
3985 * viewport. i.e. glue to the monitor glass in all cases.
3988 XClientMessageEvent xclient;
3990 /* Request stick during viewport scroll */
3991 gdk_wmspec_change_state (TRUE, window,
3992 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
3995 /* Request desktop 0xFFFFFFFF */
3996 memset (&xclient, 0, sizeof (xclient));
3997 xclient.type = ClientMessage;
3998 xclient.window = GDK_WINDOW_XWINDOW (window);
3999 xclient.display = GDK_WINDOW_XDISPLAY (window);
4000 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
4002 xclient.format = 32;
4004 xclient.data.l[0] = 0xFFFFFFFF;
4005 xclient.data.l[1] = 0;
4006 xclient.data.l[2] = 0;
4007 xclient.data.l[3] = 0;
4008 xclient.data.l[4] = 0;
4010 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
4011 SubstructureRedirectMask | SubstructureNotifyMask,
4012 (XEvent *)&xclient);
4016 /* Flip our client side flag, the real work happens on map. */
4017 gdk_synthesize_window_state (window,
4019 GDK_WINDOW_STATE_STICKY);
4024 * gdk_window_unstick:
4025 * @window: a toplevel #GdkWindow
4027 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
4028 * and gtk_window_unstick().
4032 gdk_window_unstick (GdkWindow *window)
4034 if (GDK_WINDOW_DESTROYED (window) ||
4035 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4038 if (GDK_WINDOW_IS_MAPPED (window))
4040 /* Request unstick from viewport */
4041 gdk_wmspec_change_state (FALSE, window,
4042 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4045 move_to_current_desktop (window);
4049 /* Flip our client side flag, the real work happens on map. */
4050 gdk_synthesize_window_state (window,
4051 GDK_WINDOW_STATE_STICKY,
4058 * gdk_window_maximize:
4059 * @window: a toplevel #GdkWindow
4061 * Maximizes the window. If the window was already maximized, then
4062 * this function does nothing.
4064 * On X11, asks the window manager to maximize @window, if the window
4065 * manager supports this operation. Not all window managers support
4066 * this, and some deliberately ignore it or don't have a concept of
4067 * "maximized"; so you can't rely on the maximization actually
4068 * happening. But it will happen with most standard window managers,
4069 * and GDK makes a best effort to get it to happen.
4071 * On Windows, reliably maximizes the window.
4075 gdk_window_maximize (GdkWindow *window)
4077 if (GDK_WINDOW_DESTROYED (window) ||
4078 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4081 if (GDK_WINDOW_IS_MAPPED (window))
4082 gdk_wmspec_change_state (TRUE, window,
4083 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4084 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4086 gdk_synthesize_window_state (window,
4088 GDK_WINDOW_STATE_MAXIMIZED);
4092 * gdk_window_unmaximize:
4093 * @window: a toplevel #GdkWindow
4095 * Unmaximizes the window. If the window wasn't maximized, then this
4096 * function does nothing.
4098 * On X11, asks the window manager to unmaximize @window, if the
4099 * window manager supports this operation. Not all window managers
4100 * support this, and some deliberately ignore it or don't have a
4101 * concept of "maximized"; so you can't rely on the unmaximization
4102 * actually happening. But it will happen with most standard window
4103 * managers, and GDK makes a best effort to get it to happen.
4105 * On Windows, reliably unmaximizes the window.
4109 gdk_window_unmaximize (GdkWindow *window)
4111 if (GDK_WINDOW_DESTROYED (window) ||
4112 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4115 if (GDK_WINDOW_IS_MAPPED (window))
4116 gdk_wmspec_change_state (FALSE, window,
4117 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4118 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4120 gdk_synthesize_window_state (window,
4121 GDK_WINDOW_STATE_MAXIMIZED,
4126 * gdk_window_fullscreen:
4127 * @window: a toplevel #GdkWindow
4129 * Moves the window into fullscreen mode. This means the
4130 * window covers the entire screen and is above any panels
4133 * If the window was already fullscreen, then this function does nothing.
4135 * On X11, asks the window manager to put @window in a fullscreen
4136 * state, if the window manager supports this operation. Not all
4137 * window managers support this, and some deliberately ignore it or
4138 * don't have a concept of "fullscreen"; so you can't rely on the
4139 * fullscreenification actually happening. But it will happen with
4140 * most standard window managers, and GDK makes a best effort to get
4146 gdk_window_fullscreen (GdkWindow *window)
4148 if (GDK_WINDOW_DESTROYED (window) ||
4149 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4152 if (GDK_WINDOW_IS_MAPPED (window))
4153 gdk_wmspec_change_state (TRUE, window,
4154 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4158 gdk_synthesize_window_state (window,
4160 GDK_WINDOW_STATE_FULLSCREEN);
4164 * gdk_window_unfullscreen:
4165 * @window: a toplevel #GdkWindow
4167 * Moves the window out of fullscreen mode. If the window was not
4168 * fullscreen, does nothing.
4170 * On X11, asks the window manager to move @window out of the fullscreen
4171 * state, if the window manager supports this operation. Not all
4172 * window managers support this, and some deliberately ignore it or
4173 * don't have a concept of "fullscreen"; so you can't rely on the
4174 * unfullscreenification actually happening. But it will happen with
4175 * most standard window managers, and GDK makes a best effort to get
4181 gdk_window_unfullscreen (GdkWindow *window)
4183 if (GDK_WINDOW_DESTROYED (window) ||
4184 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4187 if (GDK_WINDOW_IS_MAPPED (window))
4188 gdk_wmspec_change_state (FALSE, window,
4189 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4193 gdk_synthesize_window_state (window,
4194 GDK_WINDOW_STATE_FULLSCREEN,
4199 * gdk_window_set_keep_above:
4200 * @window: a toplevel #GdkWindow
4201 * @setting: whether to keep @window above other windows
4203 * Set if @window must be kept above other windows. If the
4204 * window was already above, then this function does nothing.
4206 * On X11, asks the window manager to keep @window above, if the window
4207 * manager supports this operation. Not all window managers support
4208 * this, and some deliberately ignore it or don't have a concept of
4209 * "keep above"; so you can't rely on the window being kept above.
4210 * But it will happen with most standard window managers,
4211 * and GDK makes a best effort to get it to happen.
4216 gdk_window_set_keep_above (GdkWindow *window,
4219 g_return_if_fail (GDK_IS_WINDOW (window));
4221 if (GDK_WINDOW_DESTROYED (window) ||
4222 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4225 if (GDK_WINDOW_IS_MAPPED (window))
4228 gdk_wmspec_change_state (FALSE, window,
4229 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4231 gdk_wmspec_change_state (setting, window,
4232 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4236 gdk_synthesize_window_state (window,
4237 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
4238 setting ? GDK_WINDOW_STATE_ABOVE : 0);
4242 * gdk_window_set_keep_below:
4243 * @window: a toplevel #GdkWindow
4244 * @setting: whether to keep @window below other windows
4246 * Set if @window must be kept below other windows. If the
4247 * window was already below, then this function does nothing.
4249 * On X11, asks the window manager to keep @window below, if the window
4250 * manager supports this operation. Not all window managers support
4251 * this, and some deliberately ignore it or don't have a concept of
4252 * "keep below"; so you can't rely on the window being kept below.
4253 * But it will happen with most standard window managers,
4254 * and GDK makes a best effort to get it to happen.
4259 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
4261 g_return_if_fail (GDK_IS_WINDOW (window));
4263 if (GDK_WINDOW_DESTROYED (window) ||
4264 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4267 if (GDK_WINDOW_IS_MAPPED (window))
4270 gdk_wmspec_change_state (FALSE, window,
4271 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4273 gdk_wmspec_change_state (setting, window,
4274 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4278 gdk_synthesize_window_state (window,
4279 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
4280 setting ? GDK_WINDOW_STATE_BELOW : 0);
4284 * gdk_window_get_group:
4285 * @window: a toplevel #GdkWindow
4287 * Returns the group leader window for @window. See gdk_window_set_group().
4289 * Return value: (transfer none): the group leader window for @window
4294 gdk_window_get_group (GdkWindow *window)
4296 GdkToplevelX11 *toplevel;
4298 if (GDK_WINDOW_DESTROYED (window) ||
4299 !WINDOW_IS_TOPLEVEL (window))
4302 toplevel = _gdk_x11_window_get_toplevel (window);
4304 return toplevel->group_leader;
4308 * gdk_window_set_group:
4309 * @window: a toplevel #GdkWindow
4310 * @leader: group leader window, or %NULL to restore the default group leader window
4312 * Sets the group leader window for @window. By default,
4313 * GDK sets the group leader for all toplevel windows
4314 * to a global window implicitly created by GDK. With this function
4315 * you can override this default.
4317 * The group leader window allows the window manager to distinguish
4318 * all windows that belong to a single application. It may for example
4319 * allow users to minimize/unminimize all windows belonging to an
4320 * application at once. You should only set a non-default group window
4321 * if your application pretends to be multiple applications.
4324 gdk_window_set_group (GdkWindow *window,
4327 GdkToplevelX11 *toplevel;
4329 g_return_if_fail (GDK_IS_WINDOW (window));
4330 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4331 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
4333 if (GDK_WINDOW_DESTROYED (window) ||
4334 (leader != NULL && GDK_WINDOW_DESTROYED (leader)) ||
4335 !WINDOW_IS_TOPLEVEL (window))
4338 toplevel = _gdk_x11_window_get_toplevel (window);
4341 leader = gdk_display_get_default_group (gdk_window_get_display (window));
4343 if (toplevel->group_leader != leader)
4345 if (toplevel->group_leader)
4346 g_object_unref (toplevel->group_leader);
4347 toplevel->group_leader = g_object_ref (leader);
4348 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
4351 update_wm_hints (window, FALSE);
4354 static MotifWmHints *
4355 gdk_window_get_mwm_hints (GdkWindow *window)
4357 GdkDisplay *display;
4358 Atom hints_atom = None;
4365 if (GDK_WINDOW_DESTROYED (window))
4368 display = gdk_window_get_display (window);
4370 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4372 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4373 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4374 False, AnyPropertyType, &type, &format, &nitems,
4375 &bytes_after, &data);
4380 return (MotifWmHints *)data;
4384 gdk_window_set_mwm_hints (GdkWindow *window,
4385 MotifWmHints *new_hints)
4387 GdkDisplay *display;
4388 Atom hints_atom = None;
4390 MotifWmHints *hints;
4396 if (GDK_WINDOW_DESTROYED (window))
4399 display = gdk_window_get_display (window);
4401 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4403 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4404 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4405 False, AnyPropertyType, &type, &format, &nitems,
4406 &bytes_after, &data);
4412 hints = (MotifWmHints *)data;
4414 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4416 hints->flags |= MWM_HINTS_FUNCTIONS;
4417 hints->functions = new_hints->functions;
4419 if (new_hints->flags & MWM_HINTS_DECORATIONS)
4421 hints->flags |= MWM_HINTS_DECORATIONS;
4422 hints->decorations = new_hints->decorations;
4426 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4427 hints_atom, hints_atom, 32, PropModeReplace,
4428 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
4430 if (hints != new_hints)
4435 * gdk_window_set_decorations:
4436 * @window: a toplevel #GdkWindow
4437 * @decorations: decoration hint mask
4439 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
4440 * This function sets the traditional Motif window manager hints that tell the
4441 * window manager which decorations you would like your window to have.
4442 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
4443 * using the GDK function directly.
4445 * The @decorations argument is the logical OR of the fields in
4446 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
4447 * mask, the other bits indicate which decorations should be turned off.
4448 * If #GDK_DECOR_ALL is not included, then the other bits indicate
4449 * which decorations should be turned on.
4451 * Most window managers honor a decorations hint of 0 to disable all decorations,
4452 * but very few honor all possible combinations of bits.
4456 gdk_window_set_decorations (GdkWindow *window,
4457 GdkWMDecoration decorations)
4461 if (GDK_WINDOW_DESTROYED (window) ||
4462 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4465 /* initialize to zero to avoid writing uninitialized data to socket */
4466 memset(&hints, 0, sizeof(hints));
4467 hints.flags = MWM_HINTS_DECORATIONS;
4468 hints.decorations = decorations;
4470 gdk_window_set_mwm_hints (window, &hints);
4474 * gdk_window_get_decorations:
4475 * @window: The toplevel #GdkWindow to get the decorations from
4476 * @decorations: The window decorations will be written here
4478 * Returns the decorations set on the GdkWindow with
4479 * gdk_window_set_decorations().
4481 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
4484 gdk_window_get_decorations(GdkWindow *window,
4485 GdkWMDecoration *decorations)
4487 MotifWmHints *hints;
4488 gboolean result = FALSE;
4490 if (GDK_WINDOW_DESTROYED (window) ||
4491 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4494 hints = gdk_window_get_mwm_hints (window);
4498 if (hints->flags & MWM_HINTS_DECORATIONS)
4501 *decorations = hints->decorations;
4512 * gdk_window_set_functions:
4513 * @window: a toplevel #GdkWindow
4514 * @functions: bitmask of operations to allow on @window
4516 * Sets hints about the window management functions to make available
4517 * via buttons on the window frame.
4519 * On the X backend, this function sets the traditional Motif window
4520 * manager hint for this purpose. However, few window managers do
4521 * anything reliable or interesting with this hint. Many ignore it
4524 * The @functions argument is the logical OR of values from the
4525 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
4526 * then the other bits indicate which functions to disable; if
4527 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
4532 gdk_window_set_functions (GdkWindow *window,
4533 GdkWMFunction functions)
4537 g_return_if_fail (GDK_IS_WINDOW (window));
4539 if (GDK_WINDOW_DESTROYED (window) ||
4540 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4543 /* initialize to zero to avoid writing uninitialized data to socket */
4544 memset(&hints, 0, sizeof(hints));
4545 hints.flags = MWM_HINTS_FUNCTIONS;
4546 hints.functions = functions;
4548 gdk_window_set_mwm_hints (window, &hints);
4552 _xwindow_get_shape (Display *xdisplay,
4556 cairo_region_t *shape;
4564 xrl = XShapeGetRectangles (xdisplay,
4566 shape_type, &rn, &ord);
4568 if (xrl == NULL || rn == 0)
4569 return cairo_region_create (); /* Empty */
4571 if (ord != YXBanded)
4573 /* This really shouldn't happen with any xserver, as they
4574 generally convert regions to YXBanded internally */
4575 g_warning ("non YXBanded shape masks not supported");
4580 rl = g_new (GdkRectangle, rn);
4581 for (i = 0; i < rn; i++)
4585 rl[i].width = xrl[i].width;
4586 rl[i].height = xrl[i].height;
4590 shape = cairo_region_create_rectangles (rl, rn);
4598 _gdk_windowing_window_get_shape (GdkWindow *window)
4600 if (!GDK_WINDOW_DESTROYED (window) &&
4601 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
4602 return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
4603 GDK_WINDOW_XID (window), ShapeBounding);
4609 _gdk_windowing_window_get_input_shape (GdkWindow *window)
4611 #if defined(ShapeInput)
4612 if (!GDK_WINDOW_DESTROYED (window) &&
4613 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
4614 return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
4615 GDK_WINDOW_XID (window),
4623 gdk_window_set_static_bit_gravity (GdkWindow *window,
4626 XSetWindowAttributes xattributes;
4627 GdkWindowObject *private;
4628 guint xattributes_mask = 0;
4630 g_return_if_fail (GDK_IS_WINDOW (window));
4632 private = GDK_WINDOW_OBJECT (window);
4633 if (private->input_only)
4636 xattributes.bit_gravity = StaticGravity;
4637 xattributes_mask |= CWBitGravity;
4638 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4639 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4640 GDK_WINDOW_XID (window),
4641 CWBitGravity, &xattributes);
4645 gdk_window_set_static_win_gravity (GdkWindow *window,
4648 XSetWindowAttributes xattributes;
4650 g_return_if_fail (GDK_IS_WINDOW (window));
4652 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4654 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4655 GDK_WINDOW_XID (window),
4656 CWWinGravity, &xattributes);
4660 gdk_window_x11_set_static_gravities (GdkWindow *window,
4661 gboolean use_static)
4663 GdkWindowObject *private = (GdkWindowObject *)window;
4666 if (!use_static == !private->guffaw_gravity)
4669 private->guffaw_gravity = use_static;
4671 if (!GDK_WINDOW_DESTROYED (window))
4673 gdk_window_set_static_bit_gravity (window, use_static);
4675 tmp_list = private->children;
4678 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4680 tmp_list = tmp_list->next;
4688 wmspec_moveresize (GdkWindow *window,
4694 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4696 XClientMessageEvent xclient;
4698 /* Release passive grab */
4699 gdk_display_pointer_ungrab (display, timestamp);
4701 memset (&xclient, 0, sizeof (xclient));
4702 xclient.type = ClientMessage;
4703 xclient.window = GDK_WINDOW_XID (window);
4704 xclient.message_type =
4705 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4706 xclient.format = 32;
4707 xclient.data.l[0] = root_x;
4708 xclient.data.l[1] = root_y;
4709 xclient.data.l[2] = direction;
4710 xclient.data.l[3] = 0;
4711 xclient.data.l[4] = 0;
4713 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4714 SubstructureRedirectMask | SubstructureNotifyMask,
4715 (XEvent *)&xclient);
4718 typedef struct _MoveResizeData MoveResizeData;
4720 struct _MoveResizeData
4722 GdkDisplay *display;
4724 GdkWindow *moveresize_window;
4725 GdkWindow *moveresize_emulation_window;
4727 GdkWindowEdge resize_edge;
4728 gint moveresize_button;
4731 gint moveresize_orig_x;
4732 gint moveresize_orig_y;
4733 gint moveresize_orig_width;
4734 gint moveresize_orig_height;
4735 GdkWindowHints moveresize_geom_mask;
4736 GdkGeometry moveresize_geometry;
4737 Time moveresize_process_time;
4738 XEvent *moveresize_pending_event;
4741 /* From the WM spec */
4742 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4743 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4744 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4745 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4746 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4747 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4748 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4749 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4750 #define _NET_WM_MOVERESIZE_MOVE 8
4753 wmspec_resize_drag (GdkWindow *window,
4762 /* Let the compiler turn a switch into a table, instead
4763 * of doing the table manually, this way is easier to verify.
4767 case GDK_WINDOW_EDGE_NORTH_WEST:
4768 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4771 case GDK_WINDOW_EDGE_NORTH:
4772 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4775 case GDK_WINDOW_EDGE_NORTH_EAST:
4776 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4779 case GDK_WINDOW_EDGE_WEST:
4780 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4783 case GDK_WINDOW_EDGE_EAST:
4784 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4787 case GDK_WINDOW_EDGE_SOUTH_WEST:
4788 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4791 case GDK_WINDOW_EDGE_SOUTH:
4792 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4795 case GDK_WINDOW_EDGE_SOUTH_EAST:
4796 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4800 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4805 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4808 static MoveResizeData *
4809 get_move_resize_data (GdkDisplay *display,
4812 MoveResizeData *mv_resize;
4813 static GQuark move_resize_quark = 0;
4815 if (!move_resize_quark)
4816 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4818 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4820 if (!mv_resize && create)
4822 mv_resize = g_new0 (MoveResizeData, 1);
4823 mv_resize->display = display;
4825 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4832 update_pos (MoveResizeData *mv_resize,
4838 dx = new_root_x - mv_resize->moveresize_x;
4839 dy = new_root_y - mv_resize->moveresize_y;
4841 if (mv_resize->is_resize)
4845 x = mv_resize->moveresize_orig_x;
4846 y = mv_resize->moveresize_orig_y;
4848 w = mv_resize->moveresize_orig_width;
4849 h = mv_resize->moveresize_orig_height;
4851 switch (mv_resize->resize_edge)
4853 case GDK_WINDOW_EDGE_NORTH_WEST:
4859 case GDK_WINDOW_EDGE_NORTH:
4863 case GDK_WINDOW_EDGE_NORTH_EAST:
4868 case GDK_WINDOW_EDGE_SOUTH_WEST:
4873 case GDK_WINDOW_EDGE_SOUTH_EAST:
4877 case GDK_WINDOW_EDGE_SOUTH:
4880 case GDK_WINDOW_EDGE_EAST:
4883 case GDK_WINDOW_EDGE_WEST:
4894 if (mv_resize->moveresize_geom_mask)
4896 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4897 mv_resize->moveresize_geom_mask,
4901 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4907 x = mv_resize->moveresize_orig_x + dx;
4908 y = mv_resize->moveresize_orig_y + dy;
4910 gdk_window_move (mv_resize->moveresize_window, x, y);
4915 finish_drag (MoveResizeData *mv_resize)
4917 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4918 mv_resize->moveresize_emulation_window = NULL;
4919 g_object_unref (mv_resize->moveresize_window);
4920 mv_resize->moveresize_window = NULL;
4922 if (mv_resize->moveresize_pending_event)
4924 g_free (mv_resize->moveresize_pending_event);
4925 mv_resize->moveresize_pending_event = NULL;
4930 lookahead_motion_predicate (Display *xdisplay,
4934 gboolean *seen_release = (gboolean *)arg;
4935 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4936 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4941 switch (event->xany.type)
4944 *seen_release = TRUE;
4947 mv_resize->moveresize_process_time = event->xmotion.time;
4957 moveresize_lookahead (MoveResizeData *mv_resize,
4961 gboolean seen_release = FALSE;
4963 if (mv_resize->moveresize_process_time)
4965 if (event->xmotion.time == mv_resize->moveresize_process_time)
4967 mv_resize->moveresize_process_time = 0;
4974 XCheckIfEvent (event->xany.display, &tmp_event,
4975 lookahead_motion_predicate, (XPointer) & seen_release);
4977 return mv_resize->moveresize_process_time == 0;
4981 _gdk_moveresize_handle_event (XEvent *event)
4983 guint button_mask = 0;
4984 GdkWindowObject *window_private;
4985 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
4986 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4988 if (!mv_resize || !mv_resize->moveresize_window)
4991 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
4993 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4995 switch (event->xany.type)
4998 if (window_private->resize_count > 0)
5000 if (mv_resize->moveresize_pending_event)
5001 *mv_resize->moveresize_pending_event = *event;
5003 mv_resize->moveresize_pending_event =
5004 g_memdup (event, sizeof (XEvent));
5008 if (!moveresize_lookahead (mv_resize, event))
5011 update_pos (mv_resize,
5012 event->xmotion.x_root,
5013 event->xmotion.y_root);
5015 /* This should never be triggered in normal cases, but in the
5016 * case where the drag started without an implicit grab being
5017 * in effect, we could miss the release if it occurs before
5018 * we grab the pointer; this ensures that we will never
5019 * get a permanently stuck grab.
5021 if ((event->xmotion.state & button_mask) == 0)
5022 finish_drag (mv_resize);
5026 update_pos (mv_resize,
5027 event->xbutton.x_root,
5028 event->xbutton.y_root);
5030 if (event->xbutton.button == mv_resize->moveresize_button)
5031 finish_drag (mv_resize);
5038 _gdk_moveresize_configure_done (GdkDisplay *display,
5042 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5044 if (!mv_resize || window != mv_resize->moveresize_window)
5047 if (mv_resize->moveresize_pending_event)
5049 tmp_event = mv_resize->moveresize_pending_event;
5050 mv_resize->moveresize_pending_event = NULL;
5051 _gdk_moveresize_handle_event (tmp_event);
5059 create_moveresize_window (MoveResizeData *mv_resize,
5062 GdkWindowAttr attributes;
5063 gint attributes_mask;
5064 GdkGrabStatus status;
5066 g_assert (mv_resize->moveresize_emulation_window == NULL);
5068 attributes.x = -100;
5069 attributes.y = -100;
5070 attributes.width = 10;
5071 attributes.height = 10;
5072 attributes.window_type = GDK_WINDOW_TEMP;
5073 attributes.wclass = GDK_INPUT_ONLY;
5074 attributes.override_redirect = TRUE;
5075 attributes.event_mask = 0;
5077 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
5079 mv_resize->moveresize_emulation_window =
5080 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
5084 gdk_window_show (mv_resize->moveresize_emulation_window);
5086 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
5088 GDK_BUTTON_RELEASE_MASK |
5089 GDK_POINTER_MOTION_MASK,
5094 if (status != GDK_GRAB_SUCCESS)
5096 /* If this fails, some other client has grabbed the window
5099 finish_drag (mv_resize);
5102 mv_resize->moveresize_process_time = 0;
5106 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
5107 so that calling XMoveWindow with these coordinates will not move the
5109 Note that this depends on the WM to implement ICCCM-compliant reference
5113 calculate_unmoving_origin (MoveResizeData *mv_resize)
5118 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
5119 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
5121 gdk_window_get_origin (mv_resize->moveresize_window,
5122 &mv_resize->moveresize_orig_x,
5123 &mv_resize->moveresize_orig_y);
5127 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
5128 gdk_window_get_geometry (mv_resize->moveresize_window,
5129 NULL, NULL, &width, &height, NULL);
5131 switch (mv_resize->moveresize_geometry.win_gravity)
5133 case GDK_GRAVITY_NORTH_WEST:
5134 mv_resize->moveresize_orig_x = rect.x;
5135 mv_resize->moveresize_orig_y = rect.y;
5137 case GDK_GRAVITY_NORTH:
5138 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5139 mv_resize->moveresize_orig_y = rect.y;
5141 case GDK_GRAVITY_NORTH_EAST:
5142 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5143 mv_resize->moveresize_orig_y = rect.y;
5145 case GDK_GRAVITY_WEST:
5146 mv_resize->moveresize_orig_x = rect.x;
5147 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5149 case GDK_GRAVITY_CENTER:
5150 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5151 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5153 case GDK_GRAVITY_EAST:
5154 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5155 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5157 case GDK_GRAVITY_SOUTH_WEST:
5158 mv_resize->moveresize_orig_x = rect.x;
5159 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5161 case GDK_GRAVITY_SOUTH:
5162 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5163 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5165 case GDK_GRAVITY_SOUTH_EAST:
5166 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5167 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5170 mv_resize->moveresize_orig_x = rect.x;
5171 mv_resize->moveresize_orig_y = rect.y;
5178 emulate_resize_drag (GdkWindow *window,
5185 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5187 mv_resize->is_resize = TRUE;
5188 mv_resize->moveresize_button = button;
5189 mv_resize->resize_edge = edge;
5190 mv_resize->moveresize_x = root_x;
5191 mv_resize->moveresize_y = root_y;
5192 mv_resize->moveresize_window = g_object_ref (window);
5194 mv_resize->moveresize_orig_width = gdk_window_get_width (window);
5195 mv_resize->moveresize_orig_height = gdk_window_get_height (window);
5197 mv_resize->moveresize_geom_mask = 0;
5198 gdk_window_get_geometry_hints (window,
5199 &mv_resize->moveresize_geometry,
5200 &mv_resize->moveresize_geom_mask);
5202 calculate_unmoving_origin (mv_resize);
5204 create_moveresize_window (mv_resize, timestamp);
5208 emulate_move_drag (GdkWindow *window,
5214 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5216 mv_resize->is_resize = FALSE;
5217 mv_resize->moveresize_button = button;
5218 mv_resize->moveresize_x = root_x;
5219 mv_resize->moveresize_y = root_y;
5221 mv_resize->moveresize_window = g_object_ref (window);
5223 calculate_unmoving_origin (mv_resize);
5225 create_moveresize_window (mv_resize, timestamp);
5229 * gdk_window_begin_resize_drag:
5230 * @window: a toplevel #GdkWindow
5231 * @edge: the edge or corner from which the drag is started
5232 * @button: the button being used to drag
5233 * @root_x: root window X coordinate of mouse click that began the drag
5234 * @root_y: root window Y coordinate of mouse click that began the drag
5235 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
5237 * Begins a window resize operation (for a toplevel window).
5238 * You might use this function to implement a "window resize grip," for
5239 * example; in fact #GtkStatusbar uses it. The function works best
5240 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
5241 * fallback implementation for other window managers.
5245 gdk_window_begin_resize_drag (GdkWindow *window,
5252 if (GDK_WINDOW_DESTROYED (window) ||
5253 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
5256 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5257 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
5258 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
5260 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
5264 * gdk_window_begin_move_drag:
5265 * @window: a toplevel #GdkWindow
5266 * @button: the button being used to drag
5267 * @root_x: root window X coordinate of mouse click that began the drag
5268 * @root_y: root window Y coordinate of mouse click that began the drag
5269 * @timestamp: timestamp of mouse click that began the drag
5271 * Begins a window move operation (for a toplevel window). You might
5272 * use this function to implement a "window move grip," for
5273 * example. The function works best with window managers that support
5274 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
5275 * Window Manager Hints</ulink>, but has a fallback implementation for
5276 * other window managers.
5280 gdk_window_begin_move_drag (GdkWindow *window,
5286 if (GDK_WINDOW_DESTROYED (window) ||
5287 !WINDOW_IS_TOPLEVEL (window))
5290 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5291 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
5292 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
5295 emulate_move_drag (window, button, root_x, root_y, timestamp);
5299 * gdk_window_enable_synchronized_configure:
5300 * @window: a toplevel #GdkWindow
5302 * Indicates that the application will cooperate with the window
5303 * system in synchronizing the window repaint with the window
5304 * manager during resizing operations. After an application calls
5305 * this function, it must call gdk_window_configure_finished() every
5306 * time it has finished all processing associated with a set of
5307 * Configure events. Toplevel GTK+ windows automatically use this
5310 * On X, calling this function makes @window participate in the
5311 * _NET_WM_SYNC_REQUEST window manager protocol.
5316 gdk_window_enable_synchronized_configure (GdkWindow *window)
5318 GdkWindowObject *private = (GdkWindowObject *)window;
5319 GdkWindowImplX11 *impl;
5321 if (!GDK_IS_WINDOW_IMPL_X11 (private->impl))
5324 impl = GDK_WINDOW_IMPL_X11 (private->impl);
5326 if (!impl->use_synchronized_configure)
5328 /* This basically means you want to do fancy X specific stuff, so
5329 ensure we have a native window */
5330 gdk_window_ensure_native (window);
5332 impl->use_synchronized_configure = TRUE;
5333 ensure_sync_counter (window);
5338 * gdk_window_configure_finished:
5339 * @window: a toplevel #GdkWindow
5341 * Signal to the window system that the application has finished
5342 * handling Configure events it has received. Window Managers can
5343 * use this to better synchronize the frame repaint with the
5344 * application. GTK+ applications will automatically call this
5345 * function when appropriate.
5347 * This function can only be called if gdk_window_enable_synchronized_configure()
5348 * was called previously.
5353 gdk_window_configure_finished (GdkWindow *window)
5355 GdkWindowImplX11 *impl;
5357 if (!WINDOW_IS_TOPLEVEL (window))
5360 impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
5361 if (!impl->use_synchronized_configure)
5365 if (!GDK_WINDOW_DESTROYED (window))
5367 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
5368 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
5370 if (toplevel && toplevel->update_counter != None &&
5371 GDK_DISPLAY_X11 (display)->use_sync &&
5372 !XSyncValueIsZero (toplevel->current_counter_value))
5374 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
5375 toplevel->update_counter,
5376 toplevel->current_counter_value);
5378 XSyncIntToValue (&toplevel->current_counter_value, 0);
5385 _gdk_windowing_window_beep (GdkWindow *window)
5387 GdkDisplay *display;
5389 g_return_if_fail (GDK_IS_WINDOW (window));
5391 display = GDK_WINDOW_DISPLAY (window);
5394 if (GDK_DISPLAY_X11 (display)->use_xkb)
5395 XkbBell (GDK_DISPLAY_XDISPLAY (display),
5396 GDK_WINDOW_XID (window),
5401 gdk_display_beep (display);
5405 * gdk_window_set_opacity:
5406 * @window: a top-level #GdkWindow
5409 * Request the windowing system to make @window partially transparent,
5410 * with opacity 0 being fully transparent and 1 fully opaque. (Values
5411 * of the opacity parameter are clamped to the [0,1] range.)
5413 * On X11, this works only on X screens with a compositing manager
5416 * For setting up per-pixel alpha, see gdk_screen_get_rgba_visual().
5417 * For making non-toplevel windows translucent, see
5418 * gdk_window_set_composited().
5423 gdk_window_set_opacity (GdkWindow *window,
5426 GdkDisplay *display;
5429 g_return_if_fail (GDK_IS_WINDOW (window));
5431 if (GDK_WINDOW_DESTROYED (window) ||
5432 !WINDOW_IS_TOPLEVEL (window))
5435 display = gdk_window_get_display (window);
5439 else if (opacity > 1)
5442 cardinal = opacity * 0xffffffff;
5444 if (cardinal == 0xffffffff)
5445 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
5446 GDK_WINDOW_XID (window),
5447 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"));
5449 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
5450 GDK_WINDOW_XID (window),
5451 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"),
5454 (guchar *) &cardinal, 1);
5458 _gdk_windowing_window_set_composited (GdkWindow *window,
5459 gboolean composited)
5461 #if defined(HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES)
5462 GdkWindowObject *private = (GdkWindowObject *) window;
5463 GdkWindowImplX11 *impl;
5464 GdkDisplay *display;
5468 impl = GDK_WINDOW_IMPL_X11 (private->impl);
5470 display = gdk_screen_get_display (GDK_DRAWABLE_IMPL_X11 (impl)->screen);
5471 dpy = GDK_DISPLAY_XDISPLAY (display);
5472 xid = GDK_WINDOW_XWINDOW (private);
5476 XCompositeRedirectWindow (dpy, xid, CompositeRedirectManual);
5477 impl->damage = XDamageCreate (dpy, xid, XDamageReportBoundingBox);
5481 XCompositeUnredirectWindow (dpy, xid, CompositeRedirectManual);
5482 XDamageDestroy (dpy, impl->damage);
5483 impl->damage = None;
5489 _gdk_windowing_window_process_updates_recurse (GdkWindow *window,
5490 cairo_region_t *region)
5492 _gdk_window_process_updates_recurse (window, region);
5496 _gdk_windowing_before_process_all_updates (void)
5501 _gdk_windowing_after_process_all_updates (void)
5506 gdk_window_impl_iface_init (GdkWindowImplIface *iface)
5508 iface->show = gdk_window_x11_show;
5509 iface->hide = gdk_window_x11_hide;
5510 iface->withdraw = gdk_window_x11_withdraw;
5511 iface->set_events = gdk_window_x11_set_events;
5512 iface->get_events = gdk_window_x11_get_events;
5513 iface->raise = gdk_window_x11_raise;
5514 iface->lower = gdk_window_x11_lower;
5515 iface->restack_under = gdk_window_x11_restack_under;
5516 iface->restack_toplevel = gdk_window_x11_restack_toplevel;
5517 iface->move_resize = gdk_window_x11_move_resize;
5518 iface->set_background = gdk_window_x11_set_background;
5519 iface->reparent = gdk_window_x11_reparent;
5520 iface->set_device_cursor = gdk_window_x11_set_device_cursor;
5521 iface->get_geometry = gdk_window_x11_get_geometry;
5522 iface->get_root_coords = gdk_window_x11_get_root_coords;
5523 iface->get_device_state = gdk_window_x11_get_device_state;
5524 iface->shape_combine_region = gdk_window_x11_shape_combine_region;
5525 iface->input_shape_combine_region = gdk_window_x11_input_shape_combine_region;
5526 iface->set_static_gravities = gdk_window_x11_set_static_gravities;
5527 iface->queue_antiexpose = _gdk_x11_window_queue_antiexpose;
5528 iface->translate = _gdk_x11_window_translate;
5529 iface->destroy = _gdk_x11_window_destroy;
5530 iface->resize_cairo_surface = gdk_window_x11_resize_cairo_surface;
5534 timestamp_predicate (Display *display,
5538 Window xwindow = GPOINTER_TO_UINT (arg);
5539 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
5541 if (xevent->type == PropertyNotify &&
5542 xevent->xproperty.window == xwindow &&
5543 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
5544 "GDK_TIMESTAMP_PROP"))
5551 * gdk_x11_get_server_time:
5552 * @window: a #GdkWindow, used for communication with the server.
5553 * The window must have GDK_PROPERTY_CHANGE_MASK in its
5554 * events mask or a hang will result.
5556 * Routine to get the current X server time stamp.
5558 * Return value: the time stamp.
5561 gdk_x11_get_server_time (GdkWindow *window)
5567 Atom timestamp_prop_atom;
5569 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5570 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
5572 xdisplay = GDK_WINDOW_XDISPLAY (window);
5573 xwindow = GDK_WINDOW_XWINDOW (window);
5574 timestamp_prop_atom =
5575 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
5576 "GDK_TIMESTAMP_PROP");
5578 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
5579 timestamp_prop_atom,
5580 8, PropModeReplace, &c, 1);
5582 XIfEvent (xdisplay, &xevent,
5583 timestamp_predicate, GUINT_TO_POINTER(xwindow));
5585 return xevent.xproperty.time;