Re: Implementation of new EWMH spec



Soeren Sandmann <sandmann daimi au dk> writes:

> 
> The attached patch implements all the properties dealing with
> compositing managers that were recently added to the EWHM spec.
> 
And here is the patch.

Soren

? birnan
? emfle
? gtkcm
? gtklabel.ac
? net-wm-all-apr1
? net-wm-all-apr12.patch
? net-wm-all-apr13.patch
? net-wm-all-apr17.patch
? net-wm-all.patch
? net-wm-cm-extensions.patch
? net-wm-cm-selection.patch
? properties
? demos/big-background.jpg
? gtk/144270.patch
? gtk/birnan
? gtk/blah
? gtk/gtkwindow.ah
? gtk/initial-sort-type.patch
? tests/testdiff
Index: gdk/gdkscreen.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkscreen.c,v
retrieving revision 1.26
diff -u -p -u -r1.26 gdkscreen.c
--- gdk/gdkscreen.c	4 Apr 2006 14:02:01 -0000	1.26
+++ gdk/gdkscreen.c	17 Apr 2006 17:12:56 -0000
@@ -50,6 +50,7 @@ enum
 enum
 {
   SIZE_CHANGED,
+  COMPOSITED_CHANGED,
   LAST_SIGNAL
 };
 
@@ -104,6 +105,25 @@ gdk_screen_class_init (GdkScreenClass *k
                   g_cclosure_marshal_VOID__VOID,
                   G_TYPE_NONE,
                   0);
+
+  /**
+   * GdkScreen::composited-changed:
+   * @screen: the object on which the signal is emitted
+   *
+   * The ::composited_changed signal is emitted when the composited
+   * status of the screen changes
+   *
+   * Since: 2.10
+   */
+  signals[COMPOSITED_CHANGED] =
+    g_signal_new (g_intern_static_string ("composited_changed"),
+		  G_OBJECT_CLASS_TYPE (klass),
+		  G_SIGNAL_RUN_LAST,
+		  G_STRUCT_OFFSET (GdkScreenClass, composited_changed),
+		  NULL, NULL,
+		  g_cclosure_marshal_VOID__VOID,
+		  G_TYPE_NONE,
+		  0);
 }
 
 static void
Index: gdk/gdkscreen.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkscreen.h,v
retrieving revision 1.18
diff -u -p -u -r1.18 gdkscreen.h
--- gdk/gdkscreen.h	8 Mar 2006 17:02:32 -0000	1.18
+++ gdk/gdkscreen.h	17 Apr 2006 17:12:56 -0000
@@ -57,6 +57,8 @@ struct _GdkScreenClass
   GObjectClass parent_class;
 
   void (*size_changed) (GdkScreen *screen);
+  void (*composited_changed) (GdkScreen *screen,
+			      gboolean   composited);
 };
 
 GType        gdk_screen_get_type              (void) G_GNUC_CONST;
@@ -69,7 +71,7 @@ GdkColormap *gdk_screen_get_rgb_colormap
 GdkVisual *  gdk_screen_get_rgb_visual        (GdkScreen   *screen);
 GdkColormap *gdk_screen_get_rgba_colormap     (GdkScreen   *screen);
 GdkVisual *  gdk_screen_get_rgba_visual       (GdkScreen   *screen);
-
+gboolean     gdk_screen_is_composited	      (GdkScreen   *screen);
 
 GdkWindow *  gdk_screen_get_root_window       (GdkScreen   *screen);
 GdkDisplay * gdk_screen_get_display           (GdkScreen   *screen);
Index: gdk/gdkwindow.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkwindow.h,v
retrieving revision 1.58
diff -u -p -u -r1.58 gdkwindow.h
--- gdk/gdkwindow.h	20 Feb 2006 01:36:48 -0000	1.58
+++ gdk/gdkwindow.h	17 Apr 2006 17:12:56 -0000
@@ -127,14 +127,19 @@ typedef enum
 {
   GDK_WINDOW_TYPE_HINT_NORMAL,
   GDK_WINDOW_TYPE_HINT_DIALOG,
-  GDK_WINDOW_TYPE_HINT_MENU,
+  GDK_WINDOW_TYPE_HINT_MENU,		/* Torn off menu */
   GDK_WINDOW_TYPE_HINT_TOOLBAR,
   GDK_WINDOW_TYPE_HINT_SPLASHSCREEN,
   GDK_WINDOW_TYPE_HINT_UTILITY,
   GDK_WINDOW_TYPE_HINT_DOCK,
-  GDK_WINDOW_TYPE_HINT_DESKTOP
+  GDK_WINDOW_TYPE_HINT_DESKTOP,
+  GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU,	/* A drop down menu (from a menubar) */
+  GDK_WINDOW_TYPE_HINT_POPUP_MENU,	/* A popup menu (from right-click) */
+  GDK_WINDOW_TYPE_HINT_TOOLTIP,
+  GDK_WINDOW_TYPE_HINT_NOTIFICATION,
+  GDK_WINDOW_TYPE_HINT_COMBO,
+  GDK_WINDOW_TYPE_HINT_DND
 } GdkWindowTypeHint;
-
 
 /* The next two enumeration values current match the
  * Motif constants. If this is changed, the implementation
Index: gdk/quartz/gdkscreen-quartz.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/quartz/gdkscreen-quartz.c,v
retrieving revision 1.3
diff -u -p -u -r1.3 gdkscreen-quartz.c
--- gdk/quartz/gdkscreen-quartz.c	8 Mar 2006 17:02:33 -0000	1.3
+++ gdk/quartz/gdkscreen-quartz.c	17 Apr 2006 17:12:56 -0000
@@ -255,3 +255,11 @@ gdk_screen_get_window_stack (GdkScreen *
 
   return NULL;
 }
+
+gboolean
+gdk_screen_is_composited (GdkScreen *screen)
+{
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
+
+  return TRUE;
+}
Index: gdk/win32/gdkscreen-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkscreen-win32.c,v
retrieving revision 1.16
diff -u -p -u -r1.16 gdkscreen-win32.c
--- gdk/win32/gdkscreen-win32.c	8 Mar 2006 17:02:33 -0000	1.16
+++ gdk/win32/gdkscreen-win32.c	17 Apr 2006 17:12:56 -0000
@@ -133,3 +133,11 @@ gdk_screen_get_window_stack (GdkScreen *
 
   return NULL;
 }
+
+gboolean
+gdk_screen_is_composited (GdkScreen *screen)
+{
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
+
+  return FALSE;
+}
Index: gdk/x11/gdkdisplay-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkdisplay-x11.c,v
retrieving revision 1.69
diff -u -p -u -r1.69 gdkdisplay-x11.c
--- gdk/x11/gdkdisplay-x11.c	4 Apr 2006 14:02:02 -0000	1.69
+++ gdk/x11/gdkdisplay-x11.c	17 Apr 2006 17:12:56 -0000
@@ -77,6 +77,22 @@ static const char *const precache_atoms[
   "WM_LOCALE_NAME",
   "WM_PROTOCOLS",
   "WM_TAKE_FOCUS",
+  "_NET_WM_CM_S0",
+  "_NET_WM_CM_S1",
+  "_NET_WM_CM_S2",
+  "_NET_WM_CM_S3",
+  "_NET_WM_CM_S4",
+  "_NET_WM_CM_S5",
+  "_NET_WM_CM_S6",
+  "_NET_WM_CM_S7",
+  "_NET_WM_CM_S8",
+  "_NET_WM_CM_S9",
+  "_NET_WM_CM_S10",
+  "_NET_WM_CM_S11",
+  "_NET_WM_CM_S12",
+  "_NET_WM_CM_S13",
+  "_NET_WM_CM_S14",
+  "_NET_WM_CM_S15",
   "_NET_WM_DESKTOP",
   "_NET_WM_ICON",
   "_NET_WM_ICON_NAME",
@@ -311,6 +327,9 @@ gdk_display_open (const gchar *display_n
   _gdk_input_init (display);
   _gdk_dnd_init (display);
 
+  for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
+    _gdk_x11_screen_request_cm_notification (display_x11->screens[i]);
+
   g_signal_emit_by_name (gdk_display_manager_get(),
 			 "display_opened", display);
 
@@ -1102,8 +1121,9 @@ gdk_display_supports_selection_notificat
  *
  * Since: 2.6
  **/
-gboolean gdk_display_request_selection_notification  (GdkDisplay *display,
-						      GdkAtom     selection)
+gboolean
+gdk_display_request_selection_notification  (GdkDisplay *display,
+					     GdkAtom     selection)
 
 {
 #ifdef HAVE_XFIXES
Index: gdk/x11/gdkevents-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkevents-x11.c,v
retrieving revision 1.168
diff -u -p -u -r1.168 gdkevents-x11.c
--- gdk/x11/gdkevents-x11.c	27 Feb 2006 13:56:29 -0000	1.168
+++ gdk/x11/gdkevents-x11.c	17 Apr 2006 17:12:56 -0000
@@ -2077,6 +2077,9 @@ gdk_event_translate (GdkDisplay *display
       if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
 	{
 	  XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
+
+	  _gdk_x11_screen_process_owner_change (screen, xevent);
+	  
 	  event->owner_change.type = GDK_OWNER_CHANGE;
 	  event->owner_change.window = window;
 	  event->owner_change.owner = selection_notify->owner;
@@ -2086,7 +2089,7 @@ gdk_event_translate (GdkDisplay *display
 					       selection_notify->selection);
 	  event->owner_change.time = selection_notify->timestamp;
 	  event->owner_change.selection_time = selection_notify->selection_timestamp;
-
+	  
 	  return_val = TRUE;
 	}
       else
Index: gdk/x11/gdkscreen-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkscreen-x11.c,v
retrieving revision 1.46
diff -u -p -u -r1.46 gdkscreen-x11.c
--- gdk/x11/gdkscreen-x11.c	4 Apr 2006 14:02:03 -0000	1.46
+++ gdk/x11/gdkscreen-x11.c	17 Apr 2006 17:12:56 -0000
@@ -47,6 +47,10 @@
 #include <X11/extensions/Xrandr.h>
 #endif
 
+#ifdef HAVE_XFIXES
+#include <X11/extensions/Xfixes.h>
+#endif
+
 static void         gdk_screen_x11_dispose     (GObject		  *object);
 static void         gdk_screen_x11_finalize    (GObject		  *object);
 static void	    init_xinerama_support      (GdkScreen	  *screen);
@@ -460,6 +464,27 @@ gdk_x11_screen_get_screen_number (GdkScr
   return GDK_SCREEN_X11 (screen)->screen_num;
 }
 
+static gboolean
+check_is_composited (GdkDisplay *display,
+		     GdkScreenX11 *screen_x11)
+{
+  Atom xselection = gdk_x11_atom_to_xatom_for_display (display, screen_x11->cm_selection_atom);
+  Window xwindow;
+  
+  xwindow = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display), xselection);
+
+  return xwindow != None;
+}
+
+static GdkAtom
+make_cm_atom (int screen_number)
+{
+  gchar *name = g_strdup_printf ("_NET_WM_CM_S%d", screen_number);
+  GdkAtom atom = gdk_atom_intern (name, FALSE);
+  g_free (name);
+  return atom;
+}
+
 GdkScreen *
 _gdk_x11_screen_new (GdkDisplay *display,
 		     gint	 screen_number) 
@@ -479,16 +504,52 @@ _gdk_x11_screen_new (GdkDisplay *display
   screen_x11->wmspec_check_window = None;
   /* we want this to be always non-null */
   screen_x11->window_manager_name = g_strdup ("unknown");
+  screen_x11->cm_selection_atom = make_cm_atom (screen_number);
+  screen_x11->is_composited = check_is_composited (display, screen_x11);
   
   init_xinerama_support (screen);
   init_randr_support (screen);
   
   _gdk_visual_init (screen);
   _gdk_windowing_window_init (screen);
-
+  
   return screen;
 }
 
+void
+_gdk_x11_screen_request_cm_notification (GdkScreenX11 *screen_x11)
+{
+  gdk_display_request_selection_notification (screen_x11->display, screen_x11->cm_selection_atom);
+}
+
+/**
+ * gdk_screen_is_composited:
+ * @screen: a #GdkScreen
+ * 
+ * Returns whether windows with an RGBA visual can reasonably
+ * be expected to have their alpha channel drawn correctly on
+ * the screen.
+ *
+ * On X11 this function returns whether a compositing manager is
+ * compositing @screen.
+ * 
+ * Return value: Whether windows with RGBA visuals can reasonably be
+ * expected to have their alpha channels drawn correctly on the screen.
+ * 
+ * Since: 2.10
+ **/
+gboolean
+gdk_screen_is_composited (GdkScreen *screen)
+{
+  GdkScreenX11 *screen_x11;
+
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
+
+  screen_x11 = GDK_SCREEN_X11 (screen);
+
+  return screen_x11->is_composited;
+}
+
 #ifdef HAVE_XINERAMA
 static gboolean
 check_solaris_xinerama (GdkScreen *screen)
@@ -703,6 +764,28 @@ void
 _gdk_x11_screen_window_manager_changed (GdkScreen *screen)
 {
   g_signal_emit (screen, signals[WINDOW_MANAGER_CHANGED], 0);
+}
+
+void
+_gdk_x11_screen_process_owner_change (GdkScreen *screen,
+				      XEvent *event)
+{
+  XFixesSelectionNotifyEvent *selection_event = (XFixesSelectionNotifyEvent *)event;
+  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
+  Atom xcm_selection_atom = gdk_x11_atom_to_xatom_for_display (screen_x11->display,
+							       screen_x11->cm_selection_atom);
+
+  if (selection_event->selection == xcm_selection_atom)
+    {
+      gboolean composited = selection_event->owner != None;
+
+      if (composited != screen_x11->is_composited)
+	{
+	  screen_x11->is_composited = composited;
+
+	  g_signal_emit_by_name (screen, "composited_changed");
+	}
+    }
 }
 
 /**
Index: gdk/x11/gdkscreen-x11.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkscreen-x11.h,v
retrieving revision 1.13
diff -u -p -u -r1.13 gdkscreen-x11.h
--- gdk/x11/gdkscreen-x11.h	21 Jul 2005 13:59:22 -0000	1.13
+++ gdk/x11/gdkscreen-x11.h	17 Apr 2006 17:12:56 -0000
@@ -103,6 +103,9 @@ struct _GdkScreenX11
   gint xft_hintstyle;
   gint xft_rgba;
   gint xft_dpi;
+
+  GdkAtom cm_selection_atom;
+  gboolean is_composited;
 };
   
 struct _GdkScreenX11Class
@@ -119,6 +122,8 @@ GdkScreen * _gdk_x11_screen_new      (Gd
 void _gdk_x11_screen_window_manager_changed (GdkScreen *screen);
 void _gdk_x11_screen_size_changed           (GdkScreen *screen,
 					     XEvent    *event);
+void _gdk_x11_screen_process_owner_change (GdkScreen *screen,
+					   XEvent    *event);
 
 G_END_DECLS
 
Index: gdk/x11/gdkwindow-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkwindow-x11.c,v
retrieving revision 1.258
diff -u -p -u -r1.258 gdkwindow-x11.c
--- gdk/x11/gdkwindow-x11.c	16 Apr 2006 05:05:49 -0000	1.258
+++ gdk/x11/gdkwindow-x11.c	17 Apr 2006 17:12:56 -0000
@@ -2226,6 +2226,24 @@ gdk_window_set_type_hint (GdkWindow     
     case GDK_WINDOW_TYPE_HINT_DESKTOP:
       atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
       break;
+    case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
+      atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
+      break;
+    case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
+      atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
+      break;
+    case GDK_WINDOW_TYPE_HINT_TOOLTIP:
+      atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
+      break;
+    case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
+      atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
+      break;
+    case GDK_WINDOW_TYPE_HINT_COMBO:
+      atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
+      break;
+    case GDK_WINDOW_TYPE_HINT_DND:
+      atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
+      break;
     default:
       g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
       /* Fall thru */
@@ -2295,6 +2313,18 @@ gdk_window_get_type_hint (GdkWindow *win
             type = GDK_WINDOW_TYPE_HINT_DOCK;
           else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
             type = GDK_WINDOW_TYPE_HINT_DESKTOP;
+	  else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
+	    type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
+	  else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
+	    type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
+	  else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
+	    type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
+	  else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
+	    type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
+	  else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
+	    type = GDK_WINDOW_TYPE_HINT_COMBO;
+	  else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
+	    type = GDK_WINDOW_TYPE_HINT_DND;
         }
 
       if (type_return != None && data != NULL)
Index: gtk/gtkcombo.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcombo.c,v
retrieving revision 1.95
diff -u -p -u -r1.95 gtkcombo.c
--- gtk/gtkcombo.c	10 Jan 2006 04:32:44 -0000	1.95
+++ gtk/gtkcombo.c	17 Apr 2006 17:12:56 -0000
@@ -564,6 +564,7 @@ gtk_combo_popup_list (GtkCombo *combo)
     {
       gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)), 
                                    GTK_WINDOW (combo->popwin));
+      gtk_window_set_transient_for (combo->popwin, GTK_WINDOW (toplevel));
     }
 
   gtk_widget_set_size_request (combo->popwin, width, height);
@@ -941,6 +942,7 @@ gtk_combo_init (GtkCombo * combo)
 		    G_CALLBACK (gtk_combo_popup_button_leave), combo);
 
   combo->popwin = gtk_window_new (GTK_WINDOW_POPUP);
+  gtk_window_set_type_hint (GTK_WINDOW (combo->popwin), GDK_WINDOW_TYPE_HINT_COMBO);
   g_object_ref (combo->popwin);
   gtk_window_set_resizable (GTK_WINDOW (combo->popwin), FALSE);
 
Index: gtk/gtkcombobox.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcombobox.c,v
retrieving revision 1.173
diff -u -p -u -r1.173 gtkcombobox.c
--- gtk/gtkcombobox.c	21 Mar 2006 00:12:48 -0000	1.173
+++ gtk/gtkcombobox.c	17 Apr 2006 17:12:56 -0000
@@ -1220,6 +1220,9 @@ gtk_combo_box_set_popup_widget (GtkCombo
 	  
           combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
 
+	  gtk_window_set_type_hint (GTK_WINDOW (combo_box->priv->popup_window),
+				    GDK_WINDOW_TYPE_HINT_COMBO);
+
 	  g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"show",
 			    G_CALLBACK (gtk_combo_box_child_show),
 			    combo_box);
Index: gtk/gtkdnd.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkdnd.c,v
retrieving revision 1.151
diff -u -p -u -r1.151 gtkdnd.c
--- gtk/gtkdnd.c	17 Apr 2006 13:43:23 -0000	1.151
+++ gtk/gtkdnd.c	17 Apr 2006 17:12:56 -0000
@@ -2938,6 +2938,7 @@ set_icon_stock_pixbuf (GdkDragContext   
   /* Push a NULL colormap to guard against gtk_widget_push_colormap() */
   gtk_widget_push_colormap (NULL);
   window = gtk_window_new (GTK_WINDOW_POPUP);
+  gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DND);
   gtk_window_set_screen (GTK_WINDOW (window), screen);
   set_can_change_screen (window, TRUE);
   gtk_widget_pop_colormap ();
@@ -3083,6 +3084,7 @@ gtk_drag_set_icon_pixmap (GdkDragContext
   gtk_widget_push_colormap (colormap);
 
   window = gtk_window_new (GTK_WINDOW_POPUP);
+  gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DND);
   gtk_window_set_screen (GTK_WINDOW (window), screen);
   set_can_change_screen (window, FALSE);
   gtk_widget_set_events (window, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
Index: gtk/gtkmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenu.c,v
retrieving revision 1.214
diff -u -p -u -r1.214 gtkmenu.c
--- gtk/gtkmenu.c	27 Mar 2006 17:00:01 -0000	1.214
+++ gtk/gtkmenu.c	17 Apr 2006 17:12:57 -0000
@@ -1036,6 +1036,33 @@ attach_widget_screen_changed (GtkWidget 
     }
 }
 
+static void
+attach_widget_hierarchy_changed (GtkWidget *attach_widget,
+				 GtkWidget *previous_toplevel,
+				 gpointer data)
+{
+  GtkMenu *menu = GTK_MENU (data);
+  GtkWidget *new_toplevel = gtk_widget_get_toplevel (attach_widget);
+
+  if (g_object_get_data (G_OBJECT (menu), "gtk-menu-explicit-screen"))
+    {
+      /* If there is an explicit screen set, then don't set WM_TRANSIENT_FOR.
+       * Because, what would happen if the attach widget moved to a different
+       * screen on a different display? The menu wouldn't move along with it,
+       * so we just make it the responsibility of whoever set the screen to
+       * also set WM_TRANSIENT_FOR.
+       */
+      return;
+    }
+  
+  if (menu->toplevel && !g_object_get_data (G_OBJECT (menu), "gtk-menu-explicit-screen") &&
+      (!new_toplevel || GTK_IS_WINDOW (new_toplevel)))
+    {
+      gtk_window_set_transient_for (GTK_WINDOW (menu->toplevel),
+				    GTK_WINDOW (new_toplevel));
+    }
+}
+
 void
 gtk_menu_attach_to_widget (GtkMenu	       *menu,
 			   GtkWidget	       *attach_widget,
@@ -1067,6 +1094,10 @@ gtk_menu_attach_to_widget (GtkMenu	     
 		    G_CALLBACK (attach_widget_screen_changed), menu);
   attach_widget_screen_changed (attach_widget, NULL, menu);
   
+  g_signal_connect (attach_widget, "hierarchy_changed",
+		    G_CALLBACK (attach_widget_hierarchy_changed), menu);
+  attach_widget_hierarchy_changed (attach_widget, NULL, menu);
+  
   data->detacher = detacher;
   g_object_set_data (G_OBJECT (menu), I_(attach_data_key), data);
   list = g_object_steal_data (G_OBJECT (attach_widget), ATTACHED_MENUS);
@@ -1121,6 +1152,10 @@ gtk_menu_detach (GtkMenu *menu)
   g_signal_handlers_disconnect_by_func (data->attach_widget,
 					(gpointer) attach_widget_screen_changed,
 					menu);
+  g_signal_handlers_disconnect_by_func (data->attach_widget,
+					(gpointer) attach_widget_hierarchy_changed,
+					menu);
+  attach_widget_hierarchy_changed (data->attach_widget, NULL, menu);
 
   if (data->detacher)
     data->detacher (data->attach_widget, menu);
@@ -3765,6 +3800,9 @@ gtk_menu_position (GtkMenu *menu)
   private->monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
 
   private->initially_pushed_in = FALSE;
+
+  /* Set the type hint here to allow custom position functions to set a different hint */
+  gtk_window_set_type_hint (GTK_WINDOW (menu->toplevel), GDK_WINDOW_TYPE_HINT_POPUP_MENU);
   
   if (menu->position_func)
     {
Index: gtk/gtkmenuitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenuitem.c,v
retrieving revision 1.128
diff -u -p -u -r1.128 gtkmenuitem.c
--- gtk/gtkmenuitem.c	3 Mar 2006 12:38:42 -0000	1.128
+++ gtk/gtkmenuitem.c	17 Apr 2006 17:12:57 -0000
@@ -1122,7 +1122,7 @@ gtk_menu_item_position_menu (GtkMenu  *m
 {
   GtkMenuItem *menu_item;
   GtkWidget *widget;
-  GtkWidget *parent_menu_item;
+  GtkMenuItem *parent_menu_item;
   GdkScreen *screen;
   gint twidth, theight;
   gint tx, ty;
@@ -1168,6 +1168,7 @@ gtk_menu_item_position_menu (GtkMenu  *m
   switch (menu_item->submenu_placement)
     {
     case GTK_TOP_BOTTOM:
+      menu_item->from_menubar = TRUE;
       if (direction == GTK_TEXT_DIR_LTR)
 	menu_item->submenu_direction = GTK_DIRECTION_RIGHT;
       else 
@@ -1175,7 +1176,6 @@ gtk_menu_item_position_menu (GtkMenu  *m
 	  menu_item->submenu_direction = GTK_DIRECTION_LEFT;
 	  tx += widget->allocation.width - twidth;
 	}
-
       if ((ty + widget->allocation.height + theight) <= monitor.y + monitor.height)
 	ty += widget->allocation.height;
       else if ((ty - theight) >= monitor.y)
@@ -1188,16 +1188,24 @@ gtk_menu_item_position_menu (GtkMenu  *m
 
     case GTK_LEFT_RIGHT:
       if (GTK_IS_MENU (widget->parent))
-	parent_menu_item = GTK_MENU (widget->parent)->parent_menu_item;
+	parent_menu_item = GTK_MENU_ITEM (GTK_MENU (widget->parent)->parent_menu_item);
       else
 	parent_menu_item = NULL;
       parent_xthickness = widget->parent->style->xthickness;
-      if (parent_menu_item && !GTK_MENU (widget->parent)->torn_off)
-	menu_item->submenu_direction = GTK_MENU_ITEM (parent_menu_item)->submenu_direction;
-      else if (direction == GTK_TEXT_DIR_LTR)
-	menu_item->submenu_direction = GTK_DIRECTION_RIGHT;
+      if (parent_menu_item)
+	{
+	  if (!GTK_MENU (widget->parent)->torn_off)
+	    menu_item->submenu_direction = parent_menu_item->submenu_direction;
+	  menu_item->from_menubar = parent_menu_item->from_menubar;
+	}
       else
-	menu_item->submenu_direction = GTK_DIRECTION_LEFT;
+	{
+	  if (direction == GTK_TEXT_DIR_LTR)
+	    menu_item->submenu_direction = GTK_DIRECTION_RIGHT;
+	  else
+	    menu_item->submenu_direction = GTK_DIRECTION_LEFT;
+	  menu_item->from_menubar = FALSE;
+	}
 
       switch (menu_item->submenu_direction)
 	{
@@ -1236,6 +1244,8 @@ gtk_menu_item_position_menu (GtkMenu  *m
   *y = ty;
 
   gtk_menu_set_monitor (menu, monitor_num);
+  gtk_window_set_type_hint (GTK_WINDOW (menu->toplevel), menu_item->from_menubar?
+			    GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU : GDK_WINDOW_TYPE_HINT_POPUP_MENU);
 }
 
 /**
Index: gtk/gtkmenuitem.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenuitem.h,v
retrieving revision 1.29
diff -u -p -u -r1.29 gtkmenuitem.h
--- gtk/gtkmenuitem.h	20 Mar 2005 07:01:22 -0000	1.29
+++ gtk/gtkmenuitem.h	17 Apr 2006 17:12:57 -0000
@@ -61,6 +61,7 @@ struct _GtkMenuItem
   guint submenu_direction : 1;
   guint right_justify: 1;
   guint timer_from_keypress : 1;
+  guint from_menubar : 1;
   guint timer;
 };
 
Index: gtk/gtktooltips.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktooltips.c,v
retrieving revision 1.72
diff -u -p -u -r1.72 gtktooltips.c
--- gtk/gtktooltips.c	2 Mar 2006 14:24:54 -0000	1.72
+++ gtk/gtktooltips.c	17 Apr 2006 17:12:57 -0000
@@ -249,6 +249,7 @@ gtk_tooltips_force_window (GtkTooltips *
   if (!tooltips->tip_window)
     {
       tooltips->tip_window = gtk_window_new (GTK_WINDOW_POPUP);
+      gtk_window_set_type_hint (GTK_WINDOW (tooltips->tip_window), GDK_WINDOW_TYPE_HINT_TOOLTIP);
       gtk_tooltips_update_screen (tooltips, TRUE);
       gtk_widget_set_app_paintable (tooltips->tip_window, TRUE);
       gtk_window_set_resizable (GTK_WINDOW (tooltips->tip_window), FALSE);
@@ -405,6 +406,7 @@ gtk_tooltips_draw_tips (GtkTooltips *too
   GdkScreen *pointer_screen;
   gint monitor_num, px, py;
   GdkRectangle monitor;
+  GtkWindow *toplevel;
 
   if (!tooltips->tip_window)
     gtk_tooltips_force_window (tooltips);
@@ -466,6 +468,10 @@ gtk_tooltips_draw_tips (GtkTooltips *too
   else
     y = y + widget->allocation.height + 4;
 
+  toplevel = gtk_widget_get_toplevel (widget);
+  if (toplevel && GTK_IS_WINDOW (toplevel))
+    gtk_window_set_transient_for (tooltips->tip_window, toplevel);
+  
   gtk_window_move (GTK_WINDOW (tooltips->tip_window), x, y);
   gtk_widget_show (tooltips->tip_window);
 }
Index: gtk/gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.429
diff -u -p -u -r1.429 gtkwidget.c
--- gtk/gtkwidget.c	6 Apr 2006 03:12:04 -0000	1.429
+++ gtk/gtkwidget.c	17 Apr 2006 17:12:57 -0000
@@ -121,6 +121,7 @@ enum {
   SCREEN_CHANGED,
   CAN_ACTIVATE_ACCEL,
   GRAB_BROKEN,
+  COMPOSITED_CHANGED,
   LAST_SIGNAL
 };
 
@@ -787,6 +788,14 @@ gtk_widget_class_init (GtkWidgetClass *k
 		  _gtk_marshal_BOOLEAN__BOXED,
 		  G_TYPE_BOOLEAN, 1,
 		  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  widget_signals[COMPOSITED_CHANGED] =
+    g_signal_new (I_("composited_changed"),
+		  G_TYPE_FROM_CLASS (gobject_class),
+		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+		  G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
+		  NULL, NULL,
+		  _gtk_marshal_VOID__VOID,
+		  G_TYPE_NONE, 0);
 
 /**
  * GtkWidget::delete-event:
@@ -5155,6 +5164,49 @@ gtk_widget_propagate_screen_changed_recu
 			  client_data);
   
   g_object_unref (widget);
+}
+
+/**
+ * gtk_widget_is_composited:
+ * @widget: 
+ * 
+ * Whether @widget can rely on having its alpha channel
+ * drawn correctly. On X11 this function returns whether a
+ * compositing manager is running for @widget's screen
+ * 
+ * Return value: #TRUE if the widget can rely on its alpha
+ * channel being drawn correctly.
+ * 
+ * Since: 2.10
+ **/
+gboolean
+gtk_widget_is_composited (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+  
+  GdkScreen *screen = gtk_widget_get_screen (widget);
+  
+  return gdk_screen_is_composited (screen);
+}
+
+static void
+propagate_composited_changed (GtkWidget *widget,
+			      gpointer dummy)
+{
+  if (GTK_IS_CONTAINER (widget))
+    {
+      gtk_container_forall (GTK_CONTAINER (widget),
+			    propagate_composited_changed,
+			    NULL);
+    }
+  
+  g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
+}
+
+void
+_gtk_widget_propagate_composited_changed (GtkWidget *widget)
+{
+  propagate_composited_changed (widget, NULL);
 }
 
 /**
Index: gtk/gtkwidget.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.h,v
retrieving revision 1.158
diff -u -p -u -r1.158 gtkwidget.h
--- gtk/gtkwidget.h	20 Feb 2006 01:36:50 -0000	1.158
+++ gtk/gtkwidget.h	17 Apr 2006 17:12:57 -0000
@@ -407,8 +407,9 @@ struct _GtkWidgetClass
   gboolean (*grab_broken_event) (GtkWidget	     *widget,
                                  GdkEventGrabBroken  *event);
 
+  void         (* composited_changed) (GtkWidget *widget);
+	
   /* Padding for future expansion */
-  void (*_gtk_reserved3) (void);
   void (*_gtk_reserved4) (void);
   void (*_gtk_reserved5) (void);
   void (*_gtk_reserved6) (void);
@@ -738,6 +739,9 @@ GtkTextDirection gtk_widget_get_directio
 void             gtk_widget_set_default_direction (GtkTextDirection  dir);
 GtkTextDirection gtk_widget_get_default_direction (void);
 
+/* Compositing manager functionality */
+gboolean gtk_widget_is_composited (GtkWidget *widget);
+
 /* Counterpart to gdk_window_shape_combine_mask.
  */
 void	     gtk_widget_shape_combine_mask (GtkWidget *widget,
@@ -788,6 +792,7 @@ void              _gtk_widget_propagate_
 							   GtkWidget    *previous_toplevel);
 void              _gtk_widget_propagate_screen_changed    (GtkWidget    *widget,
 							   GdkScreen    *previous_screen);
+void		  _gtk_widget_propagate_composited_changed (GtkWidget    *widget);
 
 GdkColormap* _gtk_widget_peek_colormap (void);
 
Index: gtk/gtkwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.c,v
retrieving revision 1.317
diff -u -p -u -r1.317 gtkwindow.c
--- gtk/gtkwindow.c	13 Mar 2006 03:32:11 -0000	1.317
+++ gtk/gtkwindow.c	17 Apr 2006 17:12:57 -0000
@@ -172,6 +172,9 @@ struct _GtkWindowPrivate
   guint accept_focus : 1;
   guint focus_on_map : 1;
   guint deletable : 1;
+
+  guint reset_type_hint : 1;
+  GdkWindowTypeHint type_hint;
 };
 
 static void gtk_window_class_init         (GtkWindowClass    *klass);
@@ -279,6 +282,8 @@ static void     gtk_window_unrealize_ico
 static void        gtk_window_notify_keys_changed (GtkWindow   *window);
 static GtkKeyHash *gtk_window_get_key_hash        (GtkWindow   *window);
 static void        gtk_window_free_key_hash       (GtkWindow   *window);
+static void	   gtk_window_on_composited_changed (GdkScreen *screen,
+						     GtkWindow *window);
 
 static GSList      *toplevel_list = NULL;
 static GtkBinClass *parent_class = NULL;
@@ -815,6 +820,7 @@ gtk_window_init (GtkWindow *window)
   priv->accept_focus = TRUE;
   priv->focus_on_map = TRUE;
   priv->deletable = TRUE;
+  priv->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
 
   colormap = _gtk_widget_peek_colormap ();
   if (colormap)
@@ -826,6 +832,8 @@ gtk_window_init (GtkWindow *window)
 
   gtk_decorated_window_init (window);
 
+  g_signal_connect (window->screen, "composited_changed",
+		    G_CALLBACK (gtk_window_on_composited_changed), window);
 }
 
 static void
@@ -937,9 +945,11 @@ gtk_window_get_property (GObject      *o
 			 GParamSpec   *pspec)
 {
   GtkWindow  *window;
+  GtkWindowPrivate *priv;
 
   window = GTK_WINDOW (object);
-
+  priv = GTK_WINDOW_GET_PRIVATE (window);
+  
   switch (prop_id)
     {
       GtkWindowGeometryInfo *info;
@@ -1000,8 +1010,7 @@ gtk_window_get_property (GObject      *o
       g_value_set_boolean (value, window->has_toplevel_focus);
       break;
     case PROP_TYPE_HINT:
-      g_value_set_enum (value,
-                        window->type_hint);
+      g_value_set_enum (value, priv->type_hint);
       break;
     case PROP_SKIP_TASKBAR_HINT:
       g_value_set_boolean (value,
@@ -1980,9 +1989,20 @@ void
 gtk_window_set_type_hint (GtkWindow           *window, 
 			  GdkWindowTypeHint    hint)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
   g_return_if_fail (!GTK_WIDGET_VISIBLE (window));
-  window->type_hint = hint;
+
+  priv = GTK_WINDOW_GET_PRIVATE (window);
+
+  if (hint < GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU)
+    window->type_hint = hint;
+  else
+    window->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
+
+  priv->reset_type_hint = TRUE;
+  priv->type_hint = hint;
 }
 
 /**
@@ -1996,9 +2016,13 @@ gtk_window_set_type_hint (GtkWindow     
 GdkWindowTypeHint
 gtk_window_get_type_hint (GtkWindow *window)
 {
+  GtkWindowPrivate *priv;
+  
   g_return_val_if_fail (GTK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
 
-  return window->type_hint;
+  priv = GTK_WINDOW_GET_PRIVATE (window);
+  
+  return priv->type_hint;
 }
 
 /**
@@ -3956,6 +3980,12 @@ gtk_window_finalize (GObject *object)
       window->keys_changed_handler = 0;
     }
 
+  if (window->screen)
+    {
+      g_signal_handlers_disconnect_by_func (window->screen,
+					    gtk_window_on_composited_changed, window);
+    }
+      
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -4101,6 +4131,17 @@ gtk_window_map (GtkWidget *widget)
   window->need_default_size = FALSE;
   window->need_default_position = FALSE;
   
+  if (priv->reset_type_hint)
+    {
+      /* We should only reset the type hint when the application
+       * used gtk_window_set_type_hint() to change the hint.
+       * Some applications use X directly to change the properties;
+       * in that case, we shouldn't overwrite what they did.
+       */
+      gdk_window_set_type_hint (widget->window, priv->type_hint);
+      priv->reset_type_hint = FALSE;
+    }
+
   gdk_window_show (widget->window);
 
   if (window->frame)
@@ -4312,8 +4353,8 @@ gtk_window_realize (GtkWidget *widget)
   if (!priv->deletable)
     gdk_window_set_functions (widget->window, GDK_FUNC_ALL | GDK_FUNC_CLOSE);
 
-  gdk_window_set_type_hint (widget->window, window->type_hint);
-
+  gdk_window_set_type_hint (widget->window, priv->type_hint);
+ 
   if (gtk_window_get_skip_pager_hint (window))
     gdk_window_set_skip_pager_hint (widget->window, TRUE);
 
@@ -6866,11 +6907,28 @@ gtk_window_set_screen (GtkWindow *window
   window->screen = screen;
   gtk_widget_reset_rc_styles (widget);
   if (screen != previous_screen)
-    _gtk_widget_propagate_screen_changed (widget, previous_screen);
+    {
+      g_signal_handlers_disconnect_by_func (previous_screen,
+					    gtk_window_on_composited_changed, window);
+      g_signal_connect (screen, "composited_changed", 
+			gtk_window_on_composited_changed, window);
+      
+      _gtk_widget_propagate_screen_changed (widget, previous_screen);
+      _gtk_widget_propagate_composited_changed (widget);
+    }
   g_object_notify (G_OBJECT (window), "screen");
 
   if (was_mapped)
     gtk_widget_map (widget);
+}
+
+static void
+gtk_window_on_composited_changed (GdkScreen *screen,
+				  GtkWindow *window)
+{
+  gtk_widget_queue_draw (GTK_WIDGET (window));
+  
+  _gtk_widget_propagate_composited_changed (GTK_WIDGET (window));
 }
 
 static GdkScreen *
Index: gtk/gtkwindow.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.h,v
retrieving revision 1.84
diff -u -p -u -r1.84 gtkwindow.h
--- gtk/gtkwindow.h	10 Jan 2006 04:32:27 -0000	1.84
+++ gtk/gtkwindow.h	17 Apr 2006 17:12:57 -0000
@@ -94,7 +94,9 @@ struct _GtkWindow
   guint maximize_initially : 1;
   guint decorated : 1;
   
-  guint type_hint : 3; /* GdkWindowTypeHint */ 
+  guint type_hint : 3; /* GdkWindowTypeHint if the hint is one of the original eight. If not, then
+			* it contains GDK_WINDOW_TYPE_HINT_NORMAL
+			*/
   guint gravity : 5; /* GdkGravity */
 
   guint is_active : 1;
Index: tests/testgtk.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/testgtk.c,v
retrieving revision 1.357
diff -u -p -u -r1.357 testgtk.c
--- tests/testgtk.c	11 Jan 2006 04:18:19 -0000	1.357
+++ tests/testgtk.c	17 Apr 2006 17:12:58 -0000
@@ -170,7 +170,8 @@ on_alpha_window_expose (GtkWidget      *
 					 widget->allocation.height / 2,
 					 radius * 1.33);
 
-  if (gdk_screen_get_rgba_colormap (gtk_widget_get_screen (widget)))
+  if (gdk_screen_get_rgba_colormap (gtk_widget_get_screen (widget)) &&
+      gtk_widget_is_composited (widget))
     cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
   else
     cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* opaque white */
@@ -354,6 +355,18 @@ on_alpha_screen_changed (GtkWidget *widg
   gtk_widget_set_colormap (widget, colormap);
 }
 
+static void
+on_composited_changed (GtkWidget *window,
+		      GtkLabel *label)
+{
+  gboolean is_composited = gtk_widget_is_composited (window);
+
+  if (is_composited)
+    gtk_label_set_text (label, "Composited");
+  else
+    gtk_label_set_text (label, "Not composited");
+}
+
 void
 create_alpha_window (GtkWidget *widget)
 {
@@ -379,22 +392,26 @@ create_alpha_window (GtkWidget *widget)
 			  TRUE, TRUE, 0);
 
       label = gtk_label_new (NULL);
-      
       gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
-      gtk_box_pack_start (GTK_BOX (vbox), build_alpha_widgets (), TRUE, TRUE, 0);
-      gtk_box_pack_start (GTK_BOX (vbox), build_alpha_drawing (), TRUE, TRUE, 0);
-
       on_alpha_screen_changed (window, NULL, label);
       g_signal_connect (window, "screen-changed",
 			G_CALLBACK (on_alpha_screen_changed), label);
       
+      label = gtk_label_new (NULL);
+      gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
+      on_composited_changed (window, GTK_LABEL (label));
+      g_signal_connect (window, "composited_changed", G_CALLBACK (on_composited_changed), label);
+      
+      gtk_box_pack_start (GTK_BOX (vbox), build_alpha_widgets (), TRUE, TRUE, 0);
+      gtk_box_pack_start (GTK_BOX (vbox), build_alpha_drawing (), TRUE, TRUE, 0);
+
       g_signal_connect (window, "destroy",
 			G_CALLBACK (gtk_widget_destroyed),
 			&window);
       
       g_signal_connect (window, "response",
                         G_CALLBACK (gtk_widget_destroy),
-                        NULL);
+                        NULL); 
     }
 
   if (!GTK_WIDGET_VISIBLE (window))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]