changeset 911:0010163f8e25 trunk

[svn] - aosd: added support to detect whether a composite manager is running (either standard with _NET_WM_CM_Sn or xcompmgr)
author giacomo
date Wed, 04 Apr 2007 07:48:53 -0700
parents 5aaf6c282617
children 5bd17596c7e9
files ChangeLog src/aosd/aosd.c src/aosd/aosd_cfg.c src/aosd/aosd_common.h src/aosd/aosd_osd.c src/aosd/aosd_osd.h src/aosd/aosd_ui.c src/aosd/ghosd.c src/aosd/ghosd.h
diffstat 9 files changed, 158 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Apr 02 13:54:59 2007 -0700
+++ b/ChangeLog	Wed Apr 04 07:48:53 2007 -0700
@@ -1,3 +1,10 @@
+2007-04-02 20:54:59 +0000  Giacomo Lozito <james@develia.org>
+  revision [1920]
+  rootvis: do not call cleanup routines if the plugin was not initted
+  trunk/src/rootvis/rootvis.c |   17 ++++++++++++-----
+  1 file changed, 12 insertions(+), 5 deletions(-)
+
+
 2007-04-02 17:35:45 +0000  Giacomo Lozito <james@develia.org>
   revision [1918]
   - aosd: added function to detect if a composite manager is active for a certain screen; this is not used for now, cause the _NET_WM_CM_Sn hint is pretty new; it will certainly prove useful at some time
--- a/src/aosd/aosd.c	Mon Apr 02 13:54:59 2007 -0700
+++ b/src/aosd/aosd.c	Wed Apr 04 07:48:53 2007 -0700
@@ -98,5 +98,6 @@
 aosd_about ( void )
 {
   aosd_ui_about();
+  aosd_osd_check_composite_mgr();
   return;
 }
--- a/src/aosd/aosd_cfg.c	Mon Apr 02 13:54:59 2007 -0700
+++ b/src/aosd/aosd_cfg.c	Wed Apr 04 07:48:53 2007 -0700
@@ -203,7 +203,7 @@
     aosd_color_t color = g_array_index( cfg->osd->decoration.colors , aosd_color_t , i );
     g_print("  color %i: %i,%i,%i (alpha %i)\n", i, color.red, color.green, color.blue, color.alpha);
   }
-  g_print("\TRIGGER\n");
+  g_print("\nTRIGGER\n");
   for ( i = 0 ; i < cfg->osd->trigger.active->len ; i++ )
     g_string_append_printf( string , "%i," , g_array_index( cfg->osd->trigger.active , gint , i ) );
   if ( string->len > 1 )
--- a/src/aosd/aosd_common.h	Mon Apr 02 13:54:59 2007 -0700
+++ b/src/aosd/aosd_common.h	Wed Apr 04 07:48:53 2007 -0700
@@ -30,6 +30,6 @@
 
 #include "../../config.h"
 
-#define AOSD_VERSION_PLUGIN "0.1beta4"
+#define AOSD_VERSION_PLUGIN "0.1beta5"
 
 #endif /* !_I_AOSD_COMMON_H */
--- a/src/aosd/aosd_osd.c	Mon Apr 02 13:54:59 2007 -0700
+++ b/src/aosd/aosd_osd.c	Wed Apr 04 07:48:53 2007 -0700
@@ -28,6 +28,7 @@
 #include <pango/pangocairo.h>
 #include <gdk/gdk.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/time.h>
 #include "ghosd.h"
 
@@ -447,7 +448,7 @@
 #ifdef HAVE_XCOMPOSITE
     {
       /* check if the composite module is actually loaded */
-      if ( aosd_osd_check_composite() )
+      if ( aosd_osd_check_composite_ext() )
         osd = ghosd_new_with_argbvisual(); /* ok */
       else
       {
@@ -480,8 +481,58 @@
 
 #ifdef HAVE_XCOMPOSITE
 int
-aosd_osd_check_composite ( void )
+aosd_osd_check_composite_ext ( void )
+{
+  return ghosd_check_composite_ext();
+}
+
+int
+aosd_osd_check_composite_mgr ( void )
 {
-  return ghosd_check_composite();
+  /* ghosd_check_composite_mgr() only checks for composite managers that
+     adhere to the Extended Window Manager hint specification ver.1.4 from
+     freedesktop ( where composite manager are identified with the hint
+     _NET_WM_CM_Sn ); unfortunately, non-standard comp.managers and older
+     ones (xcompmgr) do not use this hint; so let's also check if xcompmgr
+     is running before reporting a likely absence of running comp.managers */
+  int have_comp_mgr = ghosd_check_composite_mgr();
+  
+  if ( have_comp_mgr != 0 )
+  {
+    DEBUGMSG("running composite manager found\n");
+    return have_comp_mgr;
+  }
+  else
+  {
+    /* check if xcompmgr is running; assumes there's a working 'ps'
+       utility in the system; not the most elegant of the checking
+       systems, but this is more than enough for its purpose */
+    gchar *soutput = NULL, *serror = NULL;
+    gint exit_status;
+    
+    if ( g_spawn_command_line_sync( "ps -eo comm" ,
+           &soutput , &serror , &exit_status , NULL ) == TRUE )
+    {
+      if (( soutput != NULL ) && ( strstr( soutput , "\nxcompmgr\n" ) != NULL ))
+      {
+        DEBUGMSG("running xcompmgr found\n");
+        have_comp_mgr = 1;
+      }
+      else
+      {
+        DEBUGMSG("running xcompmgr not found\n");
+        have_comp_mgr = 0;
+      }
+    }
+    else
+    {
+      g_warning("command 'ps -eo comm' failed, unable to check if xcompgr is running\n");
+      have_comp_mgr = 0;
+    }
+    
+    g_free( soutput );
+    g_free( serror );
+    return have_comp_mgr;
+  }
 }
 #endif
--- a/src/aosd/aosd_osd.h	Mon Apr 02 13:54:59 2007 -0700
+++ b/src/aosd/aosd_osd.h	Wed Apr 04 07:48:53 2007 -0700
@@ -32,7 +32,8 @@
 void aosd_osd_cleanup ( void ); /* to be called when done with OSD usage */
 
 #ifdef HAVE_XCOMPOSITE
-int aosd_osd_check_composite ( void );
+int aosd_osd_check_composite_ext ( void );
+int aosd_osd_check_composite_mgr ( void );
 #endif
 
 #endif /* !_I_AOSD_OSD_H */
--- a/src/aosd/aosd_ui.c	Mon Apr 02 13:54:59 2007 -0700
+++ b/src/aosd/aosd_ui.c	Wed Apr 04 07:48:53 2007 -0700
@@ -785,6 +785,38 @@
 
 
 static void
+aosd_cb_configure_misc_transp_real_clicked ( GtkToggleButton * real_rbt , gpointer status_hbox )
+{
+  GtkWidget *img = g_object_get_data( G_OBJECT(status_hbox) , "img" );
+  GtkWidget *label = g_object_get_data( G_OBJECT(status_hbox) , "label" );
+  if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(real_rbt) ) )
+  {
+    if ( aosd_osd_check_composite_mgr() )
+    {
+      gtk_image_set_from_stock( GTK_IMAGE(img) , GTK_STOCK_YES , GTK_ICON_SIZE_MENU );
+      gtk_label_set_text( GTK_LABEL(label) , _("Composite manager detected") );
+      gtk_widget_set_sensitive( GTK_WIDGET(status_hbox) , TRUE );
+    }
+    else
+    {
+      gtk_image_set_from_stock( GTK_IMAGE(img) , GTK_STOCK_DIALOG_WARNING , GTK_ICON_SIZE_MENU );
+      gtk_label_set_text( GTK_LABEL(label) ,
+        _("Composite manager not detected;\nunless you know that you have one running, "
+          "please activate a composite manager otherwise the OSD won't work properly") );
+      gtk_widget_set_sensitive( GTK_WIDGET(status_hbox) , TRUE );
+    }
+  }
+  else
+  {
+    gtk_image_clear( GTK_IMAGE(img) );
+    gtk_label_set_text( GTK_LABEL(label) , _("Composite manager not required for fake transparency") );
+    gtk_widget_set_sensitive( GTK_WIDGET(status_hbox) , FALSE );
+  }
+  return;
+}
+
+
+static void
 aosd_cb_configure_misc_transp_commit ( GtkWidget * mis_transp_vbox , aosd_cfg_t * cfg )
 {
   GList *child_list = gtk_container_get_children( GTK_CONTAINER(mis_transp_vbox) );
@@ -807,6 +839,8 @@
   GtkWidget *mis_vbox;
   GtkWidget *mis_transp_frame, *mis_transp_vbox;
   GtkWidget *mis_transp_fake_rbt, *mis_transp_real_rbt;
+  GtkWidget *mis_transp_status_frame, *mis_transp_status_hbox;
+  GtkWidget *mis_transp_status_img, *mis_transp_status_label;
 
   mis_vbox = gtk_vbox_new( FALSE , 0 );
   gtk_container_set_border_width( GTK_CONTAINER(mis_vbox) , 6 );
@@ -825,10 +859,31 @@
                      GINT_TO_POINTER(AOSD_MISC_TRANSPARENCY_FAKE) );
   g_object_set_data( G_OBJECT(mis_transp_real_rbt) , "val" ,
                      GINT_TO_POINTER(AOSD_MISC_TRANSPARENCY_REAL) );
+  gtk_box_pack_start( GTK_BOX(mis_transp_vbox) , mis_transp_fake_rbt , TRUE , TRUE , 0 );
+  gtk_box_pack_start( GTK_BOX(mis_transp_vbox) , mis_transp_real_rbt , TRUE , TRUE , 0 );
+
+  mis_transp_status_hbox = gtk_hbox_new( FALSE , 4 );
+  mis_transp_status_frame = gtk_frame_new( NULL );
+  gtk_container_set_border_width( GTK_CONTAINER(mis_transp_status_hbox) , 3 );
+  gtk_container_add( GTK_CONTAINER(mis_transp_status_frame) , mis_transp_status_hbox );
+  gtk_box_pack_start( GTK_BOX(mis_transp_vbox) , mis_transp_status_frame , TRUE , TRUE , 0 );
+  
+  mis_transp_status_img = gtk_image_new();
+  gtk_misc_set_alignment( GTK_MISC(mis_transp_status_img) , 0.5 , 0 );
+  mis_transp_status_label = gtk_label_new( "" );
+  gtk_misc_set_alignment( GTK_MISC(mis_transp_status_label) , 0 , 0.5 );
+  gtk_label_set_line_wrap( GTK_LABEL(mis_transp_status_label) , TRUE );
+  gtk_box_pack_start( GTK_BOX(mis_transp_status_hbox) , mis_transp_status_img , FALSE , FALSE , 0 );
+  gtk_box_pack_start( GTK_BOX(mis_transp_status_hbox) , mis_transp_status_label , TRUE , TRUE , 0 );
+  g_object_set_data( G_OBJECT(mis_transp_status_hbox) , "img" , mis_transp_status_img );
+  g_object_set_data( G_OBJECT(mis_transp_status_hbox) , "label" , mis_transp_status_label );
+  
+  g_signal_connect( G_OBJECT(mis_transp_real_rbt) , "toggled" ,
+    G_CALLBACK(aosd_cb_configure_misc_transp_real_clicked) , mis_transp_status_hbox );
                      
 #ifdef HAVE_XCOMPOSITE
   /* check if the composite extension is loaded */
-  if ( aosd_osd_check_composite() )
+  if ( aosd_osd_check_composite_ext() )
   {
     if ( cfg->osd->misc.transparency_mode == AOSD_MISC_TRANSPARENCY_FAKE )
       gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(mis_transp_fake_rbt) , TRUE );
@@ -839,14 +894,20 @@
   {
     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(mis_transp_fake_rbt) , TRUE );
     gtk_widget_set_sensitive( GTK_WIDGET(mis_transp_real_rbt) , FALSE );
+    gtk_image_set_from_stock( GTK_IMAGE(mis_transp_status_img) ,
+    GTK_STOCK_DIALOG_ERROR , GTK_ICON_SIZE_MENU );
+    gtk_label_set_text( GTK_LABEL(mis_transp_status_label) , _("Composite extension not loaded") );
+    gtk_widget_set_sensitive( GTK_WIDGET(mis_transp_status_hbox) , FALSE );
   }
 #else
   gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(mis_transp_fake_rbt) , TRUE );
   gtk_widget_set_sensitive( GTK_WIDGET(mis_transp_real_rbt) , FALSE );
+  gtk_image_set_from_stock( GTK_IMAGE(mis_transp_status_img) ,
+    GTK_STOCK_DIALOG_ERROR , GTK_ICON_SIZE_MENU );
+  gtk_label_set_text( GTK_LABEL(mis_transp_status_label) , _("Composite extension not available") );
+  gtk_widget_set_sensitive( GTK_WIDGET(mis_transp_status_hbox) , FALSE );
 #endif
 
-  gtk_box_pack_start( GTK_BOX(mis_transp_vbox) , mis_transp_fake_rbt , TRUE , TRUE , 0 );
-  gtk_box_pack_start( GTK_BOX(mis_transp_vbox) , mis_transp_real_rbt , TRUE , TRUE , 0 );
   aosd_callback_list_add( cb_list , mis_transp_vbox , aosd_cb_configure_misc_transp_commit );
 
   return mis_vbox;
--- a/src/aosd/ghosd.c	Mon Apr 02 13:54:59 2007 -0700
+++ b/src/aosd/ghosd.c	Wed Apr 04 07:48:53 2007 -0700
@@ -435,10 +435,10 @@
 }
 
 int
-ghosd_check_composite(void)
+ghosd_check_composite_ext(void)
 {
   Display *dpy;
-  int have_composite = 0;
+  int have_composite_x = 0;
   int composite_event_base = 0, composite_error_base = 0;
   
   dpy = XOpenDisplay(NULL);
@@ -449,12 +449,33 @@
   
   if (!XCompositeQueryExtension(dpy,
         &composite_event_base, &composite_error_base))
-    have_composite = 0;
+    have_composite_x = 0;
   else
-    have_composite = 1;
+    have_composite_x = 1;
 
   XCloseDisplay(dpy);
-  return have_composite;
+  return have_composite_x;
+}
+
+int
+ghosd_check_composite_mgr(void)
+{
+  Display *dpy;
+  int have_composite_m = 0;
+  
+  dpy = XOpenDisplay(NULL);
+  if (dpy == NULL) {
+    fprintf(stderr, "Couldn't open display: (XXX FIXME)\n");
+    return 0;
+  }
+  
+  if (!composite_find_manager(dpy, DefaultScreen(dpy)))
+    have_composite_m = 0;
+  else
+    have_composite_m = 1;
+  
+  XCloseDisplay(dpy);
+  return have_composite_m;
 }
 #endif
 
--- a/src/aosd/ghosd.h	Mon Apr 02 13:54:59 2007 -0700
+++ b/src/aosd/ghosd.h	Wed Apr 04 07:48:53 2007 -0700
@@ -38,7 +38,8 @@
 void   ghosd_destroy(Ghosd* ghosd);
 #ifdef HAVE_XCOMPOSITE
 Ghosd *ghosd_new_with_argbvisual(void);
-int ghosd_check_composite(void);
+int ghosd_check_composite_ext(void);
+int ghosd_check_composite_mgr(void);
 #endif
 
 #define GHOSD_COORD_CENTER INT_MAX