diff --git a/plugins/thunar-wallpaper/README b/plugins/thunar-wallpaper/README new file mode 100644 index 0000000000000000000000000000000000000000..c84677a402b2b226bc572f01dd80f58a56713d81 --- /dev/null +++ b/plugins/thunar-wallpaper/README @@ -0,0 +1,8 @@ +Thunar Wallpaper Plugin (thunar-wallpaper) +=========================================== + +The Thunar Wallpaper plugin is an extension to Thunar. It pulls the xfconf +dependency required to set the correct settings on the Xfce4 desktop. + +To disable this plugin (and the xfconf dependency that comes with it), pass +--disable-wallpaper-plugin to ./configure. diff --git a/plugins/thunar-wallpaper/thunar-wallpaper-plugin.c b/plugins/thunar-wallpaper/thunar-wallpaper-plugin.c index bab5858b5d8c5ea244d57b6ab180ddddd3cf69cf..0509e2c80970f00113f90a63e7ff12c372e1a021 100644 --- a/plugins/thunar-wallpaper/thunar-wallpaper-plugin.c +++ b/plugins/thunar-wallpaper/thunar-wallpaper-plugin.c @@ -50,13 +50,16 @@ thunar_extension_initialize (ThunarxProviderPlugin *plugin) bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); #endif -#ifdef G_ENABLE_DEBUG +//#ifdef G_ENABLE_DEBUG g_message ("Initializing thunar-wallpaper-plugin extension"); -#endif +//#endif /* register the types provided by this plugin */ twp_provider_register_type (plugin); + g_module_make_resident (plugin); + xfconf_init(NULL); + /* setup the plugin provider type list */ type_list[0] = TWP_TYPE_PROVIDER; } @@ -69,6 +72,7 @@ thunar_extension_shutdown (void) #ifdef G_ENABLE_DEBUG g_message ("Shutting down thunar-wallpaper-plugin extension"); #endif + xfconf_shutdown(); } diff --git a/plugins/thunar-wallpaper/twp-provider.c b/plugins/thunar-wallpaper/twp-provider.c index a6028e350a5e27e8c6ca38ce9d11aa83b56a68be..5ddc69d137286c05ece7b47c4e9b7edcb7f8846d 100644 --- a/plugins/thunar-wallpaper/twp-provider.c +++ b/plugins/thunar-wallpaper/twp-provider.c @@ -38,6 +38,14 @@ #define XFDESKTOP_SELECTION_FMT "XFDESKTOP_SELECTION_%d" + +typedef enum { + DESKTOP_TYPE_NONE, + DESKTOP_TYPE_XFCE +} DesktopType; + +static DesktopType desktop_type; + static void twp_provider_class_init (TwpProviderClass *klass); static void twp_provider_menu_provider_init (ThunarxMenuProviderIface *iface); static void twp_provider_property_page_provider_init (ThunarxPropertyPageProviderIface *iface); @@ -56,7 +64,6 @@ static void twp_action_set_wallpaper (GtkAction *action, gpointer user_data); - struct _TwpProviderClass { GObjectClass __parent__; @@ -110,7 +117,6 @@ twp_provider_property_page_provider_init (ThunarxPropertyPageProviderIface *ifac static void twp_provider_init (TwpProvider *twp_provider) { - xfconf_init(NULL); //twp_gpg_backend_init(); } @@ -119,7 +125,6 @@ twp_provider_init (TwpProvider *twp_provider) static void twp_provider_finalize (GObject *object) { - xfconf_shutdown(); (*G_OBJECT_CLASS (twp_provider_parent_class)->finalize) (object); } @@ -129,6 +134,7 @@ twp_provider_get_file_actions (ThunarxMenuProvider *menu_provider, GtkWidget *window, GList *files) { + Atom xfce_selection_atom; ThunarVfsPathScheme scheme; ThunarVfsInfo *info; GtkWidget *action; @@ -138,28 +144,22 @@ twp_provider_get_file_actions (ThunarxMenuProvider *menu_provider, GdkScreen *gdk_screen = gdk_screen_get_default(); gint xscreen = gdk_screen_get_number(gdk_screen); - g_snprintf(selection_name, 100, XFDESKTOP_SELECTION_FMT, xscreen); + desktop_type = DESKTOP_TYPE_NONE; - Atom xfce_selection_atom = XInternAtom (gdk_display, selection_name, False); - if(!(XGetSelectionOwner(GDK_DISPLAY(), xfce_selection_atom))) + /* we can only set a single wallpaper */ + if (files->next == NULL) { - return NULL; - } + /* check if the file is a local file */ + info = thunarx_file_info_get_vfs_info (files->data); + scheme = thunar_vfs_path_get_scheme (info->path); + thunar_vfs_info_unref (info); - /* we can only set a single wallpaper */ - if (files->next == NULL) - { - /* check if the file is a local file */ - info = thunarx_file_info_get_vfs_info (files->data); - scheme = thunar_vfs_path_get_scheme (info->path); - thunar_vfs_info_unref (info); - - /* unable to handle non-local files */ - if (G_UNLIKELY (scheme != THUNAR_VFS_PATH_SCHEME_FILE)) - return NULL; - - if (!thunarx_file_info_is_directory (files->data)) - { + /* unable to handle non-local files */ + if (G_UNLIKELY (scheme != THUNAR_VFS_PATH_SCHEME_FILE)) + return NULL; + + if (!thunarx_file_info_is_directory (files->data)) + { if (thunarx_file_info_has_mime_type (files->data, "image/jpeg") ||thunarx_file_info_has_mime_type (files->data, "image/png") ||thunarx_file_info_has_mime_type (files->data, "image/svg+xml") @@ -173,8 +173,21 @@ twp_provider_get_file_actions (ThunarxMenuProvider *menu_provider, actions = g_list_append (actions, action); } - } - } + } + } + + g_snprintf(selection_name, 100, XFDESKTOP_SELECTION_FMT, xscreen); + xfce_selection_atom = XInternAtom (gdk_display, selection_name, False); + + if((XGetSelectionOwner(GDK_DISPLAY(), xfce_selection_atom))) + { + desktop_type = DESKTOP_TYPE_XFCE; + } + + if (desktop_type == DESKTOP_TYPE_NONE) + { + gtk_widget_set_sensitive (action, FALSE); + } return actions; } @@ -205,13 +218,19 @@ twp_action_set_wallpaper (GtkAction *action, gpointer user_data) gchar *file_uri; gchar *file_name; gchar *hostname = NULL; + XfconfChannel *xfdesktop_channel; - XfconfChannel *xfdesktop_channel = xfconf_channel_new("xfce4-desktop"); - - file_uri = thunarx_file_info_get_uri (file_info); - file_name = g_filename_from_uri (file_uri, &hostname, NULL); - if (hostname == NULL) + if (desktop_type != DESKTOP_TYPE_NONE) { + file_uri = thunarx_file_info_get_uri (file_info); + file_name = g_filename_from_uri (file_uri, &hostname, NULL); + if (hostname != NULL) + { + g_free (hostname); + g_free(file_uri); + g_free(file_name); + return; + } if (n_screens > 1) { screen = gdk_display_get_default_screen (display); @@ -220,33 +239,41 @@ twp_action_set_wallpaper (GtkAction *action, gpointer user_data) { screen = gdk_display_get_screen (display, 0); } - n_monitors = gdk_screen_get_n_monitors (screen); if (n_monitors > 1) { } - - image_path_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-path", screen_nr, monitor_nr); - image_show_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-show", screen_nr, monitor_nr); - image_style_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-style", screen_nr, monitor_nr); + g_free(file_uri); + g_free(file_name); + } - if(xfconf_channel_set_string(xfdesktop_channel, image_path_prop, file_name) == TRUE) - { - xfconf_channel_set_bool(xfdesktop_channel, image_show_prop, TRUE); - xfconf_channel_set_int(xfdesktop_channel, image_style_prop, 4); - } + switch (desktop_type) + { + case DESKTOP_TYPE_XFCE: + xfdesktop_channel = xfconf_channel_new("xfce4-desktop"); + image_path_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-path", screen_nr, monitor_nr); + image_show_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-show", screen_nr, monitor_nr); + image_style_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-style", screen_nr, monitor_nr); - g_free(image_path_prop); - g_free(image_show_prop); - g_free(image_style_prop); + if(xfconf_channel_set_string(xfdesktop_channel, image_path_prop, file_name) == TRUE) + { + xfconf_channel_set_bool(xfdesktop_channel, image_show_prop, TRUE); + xfconf_channel_set_int(xfdesktop_channel, image_style_prop, 4); + } + g_free(image_path_prop); + g_free(image_show_prop); + g_free(image_style_prop); + g_object_unref(xfdesktop_channel); + break; + + default: + return; + break; } - g_free(file_uri); - g_free(file_name); - g_object_unref(xfdesktop_channel); - + }