[Swfdec-commits] 2 commits - src/plugin.c src/plugin_x11.c src/plugin_x11.h src/swfmoz_config.c src/swfmoz_config.h src/swfmoz_player.c src/swfmoz_player.h

Pekka Lampila medar at kemper.freedesktop.org
Sat Aug 16 10:28:03 PDT 2008


 src/plugin.c        |    3 +-
 src/plugin_x11.c    |   14 +++++-----
 src/plugin_x11.h    |    3 +-
 src/swfmoz_config.c |   53 ++++++++++++++++++++++++++++++---------
 src/swfmoz_config.h |   23 +++++++++++------
 src/swfmoz_player.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++-----
 src/swfmoz_player.h |    4 ++-
 7 files changed, 133 insertions(+), 36 deletions(-)

New commits:
commit 071dc432d829732f1452c52ab342d50d3a43837d
Author: Riccardo Magliocchetti <riccardo.magliocchetti at gmail.com>
Date:   Sat Aug 16 20:24:31 2008 +0300

    Implement different autoplay policies, add GUI for changing between them
    
    The three possible configuration are: always autoplay, never autoplay and check
    last choice for the same host.
    
    The idea implemented is to have the global autoplay key be not overridden by
    the per host configuration. If the global autoplay key is not present the
    behaviour of the actual implementation is preserved, and its default is still
    to do not play automatically.

diff --git a/src/swfmoz_config.c b/src/swfmoz_config.c
index 649b656..10685e3 100644
--- a/src/swfmoz_config.c
+++ b/src/swfmoz_config.c
@@ -35,20 +35,10 @@ swfmoz_config_save_file (SwfmozConfig *config)
   gchar *data;
   gsize data_size;
   GError *error = NULL;
-  gboolean has_global;
 
   gchar *keyfile_name = g_build_filename (g_get_user_config_dir (),
 					  SWFMOZ_CONFIG_FILE, NULL);
 
-  has_global = g_key_file_has_key (config->keyfile, "global", "autoplay",
-				   &error);
-  if (error) {
-    g_error_free (error);
-    error = NULL;
-  } else if (!has_global) {
-    g_key_file_set_boolean (config->keyfile, "global", "autoplay", FALSE);
-  }
-
   data = g_key_file_to_data (config->keyfile, &data_size, &error);
   if (error) {
     goto fail;
@@ -94,7 +84,21 @@ swfmoz_config_read_file (void)
   return keyfile;
 }
 
-static gboolean
+gboolean
+swfmoz_config_has_global_key (SwfmozConfig *config)
+{
+  GError *error = NULL;
+  gboolean ret;
+
+  ret = g_key_file_has_key (config->keyfile, "global", "autoplay",
+				 &error);
+  if (error)
+    g_error_free (error);
+
+  return ret;
+}
+
+gboolean
 swfmoz_config_read_autoplay (SwfmozConfig *config, const char *host,
 			     gboolean autoplay)
 {
@@ -120,11 +124,13 @@ swfmoz_config_should_autoplay (SwfmozConfig *config, const SwfdecURL *url)
 
   g_return_val_if_fail (SWFMOZ_IS_CONFIG (config), FALSE);
 
+  if (swfmoz_config_has_global_key (config))
+    return swfmoz_config_read_autoplay (config, "global", autoplay);
+
   host = swfdec_url_get_host (url);
   if (host == NULL)
     host = swfdec_url_get_protocol (url);
 
-  autoplay = swfmoz_config_read_autoplay (config, "global", autoplay);
   autoplay = swfmoz_config_read_autoplay (config, host, autoplay);
 
   return autoplay;
@@ -148,6 +154,29 @@ swfmoz_config_set_autoplay (SwfmozConfig *config, const SwfdecURL *url,
   swfmoz_config_save_file (config);
 }
 
+void
+swfmoz_config_set_global_autoplay (SwfmozConfig *config, gboolean autoplay)
+{
+  g_return_if_fail (SWFMOZ_IS_CONFIG (config));
+
+  g_key_file_set_boolean (config->keyfile, "global", "autoplay", autoplay);
+
+  swfmoz_config_save_file (config);
+}
+
+void
+swfmoz_config_remove_global_autoplay (SwfmozConfig *config)
+{
+  GError *error = NULL;
+  g_return_if_fail (SWFMOZ_IS_CONFIG (config));
+
+  g_key_file_remove_key (config->keyfile, "global", "autoplay", &error);
+  if (error)
+    g_error_free (error);
+
+  swfmoz_config_save_file (config);
+}
+
 static void
 swfmoz_config_dispose (GObject *object)
 {
diff --git a/src/swfmoz_config.h b/src/swfmoz_config.h
index b14c786..5a02f29 100644
--- a/src/swfmoz_config.h
+++ b/src/swfmoz_config.h
@@ -46,14 +46,21 @@ struct _SwfmozConfigClass
  GObjectClass 	parent;
 };
 
-GType		swfmoz_config_get_type   	(void);
-
-SwfmozConfig *	swfmoz_config_new		(void);
-gboolean 	swfmoz_config_should_autoplay 	(SwfmozConfig *config,
-						 const SwfdecURL *url);
-void		swfmoz_config_set_autoplay 	(SwfmozConfig *config,
-						 const SwfdecURL *url,
-						 gboolean autoplay);
+GType		swfmoz_config_get_type			(void);
+
+SwfmozConfig *	swfmoz_config_new			(void);
+gboolean	swfmoz_config_read_autoplay		(SwfmozConfig *config,
+							 const char *host,
+							 gboolean autoplay);
+gboolean 	swfmoz_config_should_autoplay 		(SwfmozConfig *config,
+							 const SwfdecURL *url);
+void		swfmoz_config_set_autoplay 		(SwfmozConfig *config,
+							 const SwfdecURL *url,
+							 gboolean autoplay);
+gboolean	swfmoz_config_has_global_key		(SwfmozConfig *config);
+void		swfmoz_config_set_global_autoplay	(SwfmozConfig *config,
+							 gboolean autoplay);
+void		swfmoz_config_remove_global_autoplay	(SwfmozConfig *config);
 
 G_END_DECLS
 #endif
diff --git a/src/swfmoz_player.c b/src/swfmoz_player.c
index 05f7fca..b1685af 100644
--- a/src/swfmoz_player.c
+++ b/src/swfmoz_player.c
@@ -65,6 +65,31 @@ swfmoz_player_menu_notify_audio (SwfdecGtkPlayer *player, GParamSpec *pspec,
 }
 
 static void
+swfmoz_player_menu_autoplay_always_toggled (GtkCheckMenuItem *item,
+    SwfmozPlayer* player)
+{
+  gboolean item_active = gtk_check_menu_item_get_active (item);
+  swfmoz_config_set_global_autoplay (player->config, item_active);
+}
+
+static void
+swfmoz_player_menu_autoplay_remember_last_toggled (GtkCheckMenuItem *item,
+    SwfmozPlayer* player)
+{
+  gboolean item_active = gtk_check_menu_item_get_active (item);
+  if (item_active && swfmoz_config_has_global_key (player->config))
+    swfmoz_config_remove_global_autoplay (player->config);
+}
+
+static void
+swfmoz_player_menu_autoplay_never_toggled (GtkCheckMenuItem *item,
+    SwfmozPlayer* player)
+{
+  gboolean item_active = gtk_check_menu_item_get_active (item);
+  swfmoz_config_set_global_autoplay (player->config, !item_active);
+}
+
+static void
 swfmoz_player_menu_about (GtkMenuItem *item, SwfmozPlayer *player)
 {
   static const char *authors[] = {
@@ -95,31 +120,62 @@ static void
 swfmoz_player_popup_menu (SwfmozPlayer *player)
 {
   if (player->menu == NULL) {
-    GtkWidget *item;
+    GtkWidget *item, *submenu;
 
     player->menu = GTK_MENU (gtk_menu_new ());
     g_object_ref_sink (player->menu);
     
     item = gtk_check_menu_item_new_with_mnemonic ("Playing");
-    g_signal_connect (item, "toggled", 
+    g_signal_connect (item, "toggled",
 	G_CALLBACK (swfmoz_player_menu_playing_toggled), player);
     g_signal_connect (player, "notify::playing",
 	G_CALLBACK (swfmoz_player_menu_notify_playing), item);
-    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), 
+    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
 	swfdec_gtk_player_get_playing (SWFDEC_GTK_PLAYER (player)));
     gtk_widget_show (item);
     gtk_menu_shell_append (GTK_MENU_SHELL (player->menu), item);
 
     item = gtk_check_menu_item_new_with_mnemonic ("Enable Audio");
-    g_signal_connect (item, "toggled", 
+    g_signal_connect (item, "toggled",
 	G_CALLBACK (swfmoz_player_menu_audio_toggled), player);
     g_signal_connect (player, "notify::audio-enabled",
 	G_CALLBACK (swfmoz_player_menu_notify_audio), item);
-    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), 
+    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
 	swfdec_gtk_player_get_audio_enabled (SWFDEC_GTK_PLAYER (player)));
     gtk_widget_show (item);
     gtk_menu_shell_append (GTK_MENU_SHELL (player->menu), item);
 
+    submenu = gtk_menu_new();
+    item = gtk_radio_menu_item_new_with_mnemonic (NULL, "Always");
+    g_signal_connect (item, "toggled",
+        G_CALLBACK (swfmoz_player_menu_autoplay_always_toggled), player);
+    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
+	swfmoz_config_read_autoplay (player->config, "global", FALSE));
+    gtk_widget_show (item);
+    gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
+
+    item = gtk_radio_menu_item_new_with_mnemonic_from_widget (GTK_RADIO_MENU_ITEM (item),
+        "Remember last choice");
+    g_signal_connect (item, "toggled",
+	G_CALLBACK (swfmoz_player_menu_autoplay_remember_last_toggled), player);
+    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
+        !swfmoz_config_has_global_key (player->config));
+    gtk_widget_show (item);
+    gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
+
+    item = gtk_radio_menu_item_new_with_mnemonic_from_widget (GTK_RADIO_MENU_ITEM (item), "Never");
+    g_signal_connect (item, "toggled",
+        G_CALLBACK (swfmoz_player_menu_autoplay_never_toggled), player);
+    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
+	!swfmoz_config_read_autoplay (player->config, "global", TRUE));
+    gtk_widget_show (item);
+    gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
+
+    item = gtk_menu_item_new_with_label ("Autoplay");
+    gtk_widget_show (item);
+    gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
+    gtk_menu_shell_append (GTK_MENU_SHELL (player->menu), item);
+
     item = gtk_separator_menu_item_new ();
     gtk_widget_show (item);
     gtk_menu_shell_append (GTK_MENU_SHELL (player->menu), item);
commit 373931a2f30088951659d3fb011ef9e6a09e9a36
Author: Karl Tomlinson <bugs.freedesktop at karlt.net>
Date:   Sat Aug 16 20:03:23 2008 +0300

    draw to the visual from the NPWindow
    
    Currently the swfdec plugin draws with the visual from the browser toplevel
    window which is not necessarily appropriate for the Drawable of windowless
    plugins.  This can result in "BadMatch (invalid parameter attributes)" when the
    depths differ or colour confusion if the depths are the same but color masks
    differ.
    
    Once this Mozilla bug is fixed, its test case can serve as a test case for this
    bug:
    
    https://bugzilla.mozilla.org/show_bug.cgi?id=445250
    
    Even without non-unit opacity, it's possible there may be some
    Xserver/application configurations where the visual on the toplevel window
    differs from that used within Mozilla, which is gdk_rgb_get_colormap(), or
    other browser.
    
    Fixes bug #16717

diff --git a/src/plugin.c b/src/plugin.c
index 598ef24..677ddf8 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -396,7 +396,8 @@ plugin_set_window (NPP instance, NPWindow *window)
 
   if (window) {
     plugin_x11_setup_windowed (instance->pdata, (Window) window->window, 
-	window->x, window->y, window->width, window->height);
+	window->x, window->y, window->width, window->height,
+	((NPSetWindowCallbackStruct *)window->ws_info)->visual);
   } else {
     plugin_x11_teardown (instance->pdata);
   }
diff --git a/src/plugin_x11.c b/src/plugin_x11.c
index 22775e1..2f6b3f5 100644
--- a/src/plugin_x11.c
+++ b/src/plugin_x11.c
@@ -51,7 +51,7 @@ plugin_x11_handle_event (SwfmozPlayer *mozplay, XEvent *event)
 	GdkRectangle rect = { expose->x, expose->y, expose->width, expose->height };
 	GdkRegion *region = gdk_region_rectangle (&rect);
 	cairo_surface_t *surface = cairo_xlib_surface_create (expose->display, 
-	    expose->drawable, GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (mozplay->target)),
+	    expose->drawable, mozplay->target_visual,
 	    expose->x + expose->width, expose->y + expose->height);
 	cairo_t *cr = cairo_create (surface);
 	swfmoz_player_render (mozplay, cr, region);
@@ -129,7 +129,7 @@ plugin_x11_handle_event (SwfmozPlayer *mozplay, XEvent *event)
 	XConfigureEvent *conf = (XConfigureEvent *) event;
 
 	if (!mozplay->windowless)
-	  swfmoz_player_set_target (mozplay, mozplay->target, 0, 0, conf->width, conf->height);
+	  swfmoz_player_set_target (mozplay, mozplay->target, 0, 0, conf->width, conf->height, mozplay->target_visual);
 	break;
       }
     default:
@@ -147,7 +147,7 @@ plugin_x11_filter_event (GdkXEvent *gdkxevent, GdkEvent *unused, gpointer player
 
 void
 plugin_x11_setup_windowed (SwfmozPlayer *player, Window xwindow, 
-    int x, int y, int width, int height)
+    int x, int y, int width, int height, Visual *visual)
 {
   if (player->windowless) {
     if (player->target == NULL) {
@@ -157,9 +157,9 @@ plugin_x11_setup_windowed (SwfmozPlayer *player, Window xwindow,
 	g_printerr ("cannot set window given for setup (id %lu)\n", xwindow);
 	return;
       }
-      swfmoz_player_set_target (player, window, x, y, width, height);
+      swfmoz_player_set_target (player, window, x, y, width, height, visual);
     } else {
-      swfmoz_player_set_target (player, player->target, x, y, width, height);
+      swfmoz_player_set_target (player, player->target, x, y, width, height, visual);
     }
   } else {
     if (player->target == NULL) {
@@ -186,7 +186,7 @@ plugin_x11_setup_windowed (SwfmozPlayer *player, Window xwindow,
       window = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
       gdk_window_add_filter (window, plugin_x11_filter_event, player);
       gdk_window_show (window);
-      swfmoz_player_set_target (player, window, 0, 0, width, height);
+      swfmoz_player_set_target (player, window, 0, 0, width, height, visual);
     } else {
       gdk_window_move_resize (player->target, 0, 0, width, height);
     }
@@ -199,5 +199,5 @@ plugin_x11_teardown (SwfmozPlayer *player)
   if (player->target) {
     gdk_window_remove_filter (player->target, plugin_x11_filter_event, player);
   }
-  swfmoz_player_set_target (player, NULL, 0, 0, 0, 0);
+  swfmoz_player_set_target (player, NULL, 0, 0, 0, 0, NULL);
 }
diff --git a/src/plugin_x11.h b/src/plugin_x11.h
index b07c677..dfd39e0 100644
--- a/src/plugin_x11.h
+++ b/src/plugin_x11.h
@@ -32,7 +32,8 @@ void	plugin_x11_setup_windowed	(SwfmozPlayer *	      player,
 					 int		      x,
 					 int		      y,
 					 int		      width,
-					 int		      height);
+					 int		      height,
+					 Visual *	      visual);
 void	plugin_x11_teardown		(SwfmozPlayer *	      player);
 void	plugin_x11_handle_event		(SwfmozPlayer *	      player,
 					 XEvent *	      event);
diff --git a/src/swfmoz_player.c b/src/swfmoz_player.c
index 03746c4..05f7fca 100644
--- a/src/swfmoz_player.c
+++ b/src/swfmoz_player.c
@@ -654,7 +654,7 @@ swfmoz_player_add_loader (SwfmozPlayer *player, SwfmozLoader *loader)
 
 void
 swfmoz_player_set_target (SwfmozPlayer *player, GdkWindow *target, 
-    int x, int y, int width, int height)
+    int x, int y, int width, int height, Visual *visual)
 {
   g_return_if_fail (SWFMOZ_IS_PLAYER (player));
   g_return_if_fail (target == NULL || GDK_IS_WINDOW (target));
@@ -689,6 +689,7 @@ swfmoz_player_set_target (SwfmozPlayer *player, GdkWindow *target,
   player->target_rect.y = y;
   player->target_rect.width = width;
   player->target_rect.height = height;
+  player->target_visual = visual;
   swfdec_player_set_size (SWFDEC_PLAYER (player), width, height);
 }
 
diff --git a/src/swfmoz_player.h b/src/swfmoz_player.h
index bd747a9..c838d7d 100644
--- a/src/swfmoz_player.h
+++ b/src/swfmoz_player.h
@@ -57,6 +57,7 @@ struct _SwfmozPlayer {
   gboolean		opaque;			/* TRUE if the player should not allow translucency */
   GdkWindow *		target;			/* what we draw to */
   GdkRectangle		target_rect;		/* area in target that this plugin occupies */
+  Visual *		target_visual;		/* visual for drawing */
 
   GSource *		repaint_source;		/* set when repaint is necessary */
   GdkRegion *		repaint;		/* area to repaint or NULL if none */
@@ -89,7 +90,8 @@ void		swfmoz_player_set_target	(SwfmozPlayer *		player,
 						 int			x,
 						 int			y,
 						 int			width,
-						 int			height);
+						 int			height,
+						 Visual *		visual);
 void		swfmoz_player_set_allow_popups	(SwfmozPlayer *		player,
 						 gboolean		allow);
 void		swfmoz_player_render		(SwfmozPlayer *		player,


More information about the Swfdec-commits mailing list