Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lidgnulinux/6518b7e1f5a10c87e7eecdfb9f7925a6 to your computer and use it in GitHub Desktop.
Save lidgnulinux/6518b7e1f5a10c87e7eecdfb9f7925a6 to your computer and use it in GitHub Desktop.
Patch to remove set as wallpaper option.
--- plugins/thunar-wallpaper/twp-provider.c 2025-05-30 15:44:12.534952614 +0700
+++ plugins/thunar-wallpaper/twp-provider.c.new 2025-05-30 16:00:50.899096470 +0700
@@ -145,17 +145,6 @@
/* get the mime type of the file */
mime_type = thunarx_file_info_get_mime_type (files->data);
- if (g_str_has_prefix (mime_type, "image/")
- && (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")
- || thunarx_file_info_has_mime_type (files->data, "image/svg+xml-compressed")))
- {
- item = thunarx_menu_item_new ("Twp::setwallpaper", _("Set as wallpaper"), NULL, "preferences-desktop-wallpaper");
- g_signal_connect (item, "activate", G_CALLBACK (twp_action_set_wallpaper), files->data);
-
- items = g_list_append (items, item);
- }
g_free (mime_type);
}
}
@@ -163,164 +152,6 @@
return items;
}
-static void
-twp_action_set_wallpaper (ThunarxMenuItem *item,
- gpointer user_data)
-{
- ThunarxFileInfo *file_info = user_data;
- GdkDisplay *display = gdk_display_get_default ();
- gint screen_nr = 0;
- gint n_monitors;
- gint monitor_nr = 0;
- gint workspace;
- GdkScreen *screen;
- GdkMonitor *monitor;
- gchar *image_path_prop;
- gchar *image_show_prop;
- gchar *image_style_prop;
- const char *monitor_name;
- gchar *file_uri;
- gchar *escaped_file_name;
- gchar *file_name = NULL;
- gchar *hostname = NULL;
- gchar *command;
- XfconfChannel *channel;
- gboolean is_single_workspace;
- gint current_image_style;
- const gchar *desktop_type = NULL;
-
- screen = gdk_display_get_default_screen (display);
-
- desktop_type = g_getenv ("XDG_CURRENT_DESKTOP");
- if (desktop_type == NULL)
- {
- g_warning ("Failed to set wallpaper: $XDG_CURRENT_DESKTOP is not defined");
- return;
- }
-
- 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;
- }
-
- workspace = twp_get_active_workspace_number (screen);
- n_monitors = gdk_display_get_n_monitors (display);
-
- if (n_monitors > 1 && main_window)
- {
- monitor = gdk_display_get_monitor_at_window (display, gtk_widget_get_window (main_window));
- }
- else
- {
- monitor = gdk_display_get_monitor (display, monitor_nr);
- }
-
- monitor_name = gdk_monitor_get_model (monitor);
- escaped_file_name = g_shell_quote (file_name);
-
- if (g_strcmp0 (desktop_type, "XFCE") == 0)
- {
- g_debug ("set on xfce");
-
- channel = xfconf_channel_get ("xfce4-desktop");
-
- /* This is the format for xfdesktop before 4.11 */
- 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);
-
- /* Set the wallpaper and ensure that it's set to show */
- xfconf_channel_set_string (channel, image_path_prop, file_name);
- xfconf_channel_set_bool (channel, image_show_prop, TRUE);
-
- /* If there isn't a wallpaper style set (-1), or it is set to 'None' (which is 0) then set one */
- current_image_style = xfconf_channel_get_int (channel, image_style_prop, -1);
- if (current_image_style <= 0)
- {
- /* Lets hope that 5 = 'Zoomed' works fine for the selected picture */
- xfconf_channel_set_int (channel, image_style_prop, 5);
- }
-
- g_free (image_path_prop);
- g_free (image_show_prop);
- g_free (image_style_prop);
-
-
- /* Xfdesktop 4.11+ has a concept of a single-workspace-mode where
- * the same workspace is used for everything but additionally allows
- * the user to use any current workspace as the single active
- * workspace, we'll need to check if it is enabled (which by default
- * it is) and use that. */
- is_single_workspace = xfconf_channel_get_bool (channel, "/backdrop/single-workspace-mode", TRUE);
- if (is_single_workspace)
- {
- workspace = xfconf_channel_get_int (channel, "/backdrop/single-workspace-number", 0);
- }
-
- /* This is the format for xfdesktop post 4.11. A workspace number is
- * added and the monitor is referred to name. We set both formats so
- * that it works as the user expects. */
- if (monitor_name)
- {
- image_path_prop = g_strdup_printf ("/backdrop/screen%d/monitor%s/workspace%d/last-image", screen_nr, monitor_name, workspace);
- image_style_prop = g_strdup_printf ("/backdrop/screen%d/monitor%s/workspace%d/image-style", screen_nr, monitor_name, workspace);
- }
- else
- {
- /* gdk_screen_get_monitor_plug_name can return NULL, in those
- * instances we fallback to monitor number but still include the
- * workspace number */
- image_path_prop = g_strdup_printf ("/backdrop/screen%d/monitor%d/workspace%d/last-image", screen_nr, monitor_nr, workspace);
- image_style_prop = g_strdup_printf ("/backdrop/screen%d/monitor%d/workspace%d/image-style", screen_nr, monitor_nr, workspace);
- }
-
- xfconf_channel_set_string (channel, image_path_prop, file_name);
-
- /* If there isn't a wallpaper style set (-1), or it is set to 'None' (which is 0) then set one */
- current_image_style = xfconf_channel_get_int (channel, image_style_prop, -1);
- if (current_image_style <= 0)
- {
- /* Lets hope that 5 = 'Zoomed' works fine for the selected picture */
- xfconf_channel_set_int (channel, image_style_prop, 5);
- }
-
- g_free (image_path_prop);
- g_free (image_style_prop);
- }
- else if (g_strcmp0 (desktop_type, "GNOME") == 0)
- {
- if (_has_gsettings)
- {
- g_debug ("set on gnome");
-
- command = g_strdup_printf ("gsettings set "
- "org.gnome.desktop.background picture-uri "
- "'%s'",
- file_uri);
- g_spawn_command_line_async (command, NULL);
- g_free (command);
- }
- else
- {
- g_warning ("Failed to set wallpaper: Missing executable 'gsettings'");
- }
- }
- else
- {
- g_warning (("Failed to set wallpaper: $XDG_CURRENT_DESKTOP Desktop type '%s' not supported by thunar wallpaper plugin."), desktop_type);
- }
-
- g_free (escaped_file_name);
- g_free (file_name);
- g_free (file_uri);
-}
-
/* Taken from xfce_spawn_get_active_workspace_number in xfce-spawn.c apart of
* the libxfce4ui library.
* https://git.xfce.org/xfce/libxfce4ui/tree/libxfce4ui/xfce-spawn.c#n193
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment