From b72dc0cbd2722d7a9b40773c32380b7742b86428 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Fri, 1 Aug 2014 10:03:27 +0300 Subject: [PATCH] Add a --next option to force wallpaper changes (Bug 10754) Several users have external scripts telling xfdesktop when to change the wallpaper. This patch adds a --next option so that users can advance the wallpaper on the current workspace when they want with those scripts, rather than being limited to only the time based events that are built into xfdesktop. --- src/xfce-backdrop.c | 14 ++++++++++++++ src/xfce-backdrop.h | 3 ++- src/xfce-desktop.c | 15 +++++++++++++-- src/xfce-desktop.h | 2 +- src/xfdesktop-application.c | 42 +++++++++++++++++++++++++++++++++++++++++- xfdesktop.1 | 12 +++++++----- 6 files changed, 78 insertions(+), 10 deletions(-) diff --git a/src/xfce-backdrop.c b/src/xfce-backdrop.c index 5408031..600b82e 100644 --- a/src/xfce-backdrop.c +++ b/src/xfce-backdrop.c @@ -1358,6 +1358,20 @@ xfce_backdrop_get_random_order(XfceBackdrop *backdrop) return backdrop->priv->random_backdrop_order; } +void +xfce_backdrop_force_cycle(XfceBackdrop *backdrop) +{ + g_return_if_fail(XFCE_IS_BACKDROP(backdrop)); + + TRACE("entering"); + + /* force it to update */ + xfce_backdrop_cycle_backdrop(backdrop); + + /* Update the timer, if running */ + xfce_backdrop_timer(backdrop); +} + /* Generates the background that will either be displayed or will have the * image drawn on top of */ static GdkPixbuf * diff --git a/src/xfce-backdrop.h b/src/xfce-backdrop.h index 8edda4b..8a5138f 100644 --- a/src/xfce-backdrop.h +++ b/src/xfce-backdrop.h @@ -143,12 +143,13 @@ void xfce_backdrop_set_random_order (XfceBackdrop *backdrop, gboolean random_order); gboolean xfce_backdrop_get_random_order (XfceBackdrop *backdrop); +void xfce_backdrop_force_cycle (XfceBackdrop *backdrop); + GdkPixbuf *xfce_backdrop_get_pixbuf (XfceBackdrop *backdrop); void xfce_backdrop_generate_async (XfceBackdrop *backdrop); - G_END_DECLS #endif diff --git a/src/xfce-desktop.c b/src/xfce-desktop.c index dafc315..9c576ce 100644 --- a/src/xfce-desktop.c +++ b/src/xfce-desktop.c @@ -1668,8 +1668,9 @@ xfce_desktop_popup_secondary_root_menu(XfceDesktop *desktop, xfce_desktop_do_menu_popup(desktop, button, activate_time, signals[SIG_POPULATE_SECONDARY_ROOT_MENU]); } + void -xfce_desktop_refresh(XfceDesktop *desktop) +xfce_desktop_refresh(XfceDesktop *desktop, gboolean advance_wallpaper) { gint i, current_workspace; @@ -1692,9 +1693,19 @@ xfce_desktop_refresh(XfceDesktop *desktop) backdrop = xfce_workspace_get_backdrop(desktop->priv->workspaces[current_workspace], i); - backdrop_changed_cb(backdrop, desktop); + if(advance_wallpaper) { + /* We need to trigger a new wallpaper event */ + xfce_backdrop_force_cycle(backdrop); + } else { + /* Fake a changed event so we redraw the wallpaper */ + backdrop_changed_cb(backdrop, desktop); + } } + /* If we're only advancing the wallpaper we can exit here */ + if(advance_wallpaper) + return; + #ifdef ENABLE_DESKTOP_ICONS /* reload icon view */ if(desktop->priv->icon_view) { diff --git a/src/xfce-desktop.h b/src/xfce-desktop.h index 04c089a..638aa03 100644 --- a/src/xfce-desktop.h +++ b/src/xfce-desktop.h @@ -108,7 +108,7 @@ void xfce_desktop_popup_secondary_root_menu(XfceDesktop *desktop, guint button, guint activate_time); -void xfce_desktop_refresh(XfceDesktop *desktop); +void xfce_desktop_refresh(XfceDesktop *desktop, gboolean advance_wallpaper); void xfce_desktop_arrange_icons(XfceDesktop *desktop); diff --git a/src/xfdesktop-application.c b/src/xfdesktop-application.c index c14d6d3..4152f84 100644 --- a/src/xfdesktop-application.c +++ b/src/xfdesktop-application.c @@ -73,6 +73,10 @@ static void cb_xfdesktop_application_reload(GAction *action, GVariant *parameter, gpointer data); +static void cb_xfdesktop_application_next(GAction *action, + GVariant *parameter, + gpointer data); + static void xfdesktop_handle_quit_signals(gint sig, gpointer user_data); static void cb_xfdesktop_application_quit(GAction *action, GVariant *parameter, @@ -186,6 +190,12 @@ xfdesktop_application_init(XfdesktopApplication *app) xfdesktop_application_add_action(app, G_ACTION(action)); g_object_unref(action); + /* next action */ + action = g_simple_action_new("next", NULL); + g_signal_connect(action, "activate", G_CALLBACK(cb_xfdesktop_application_next), app); + xfdesktop_application_add_action(app, G_ACTION(action)); + g_object_unref(action); + /* quit action */ action = g_simple_action_new("quit", NULL); g_signal_connect(action, "activate", G_CALLBACK(cb_xfdesktop_application_quit), app); @@ -367,7 +377,7 @@ reload_idle_cb(gpointer data) /* reload all the desktops */ for(i = 0; i < app->nscreens; ++i) { if(app->desktops[i]) - xfce_desktop_refresh(XFCE_DESKTOP(app->desktops[i])); + xfce_desktop_refresh(XFCE_DESKTOP(app->desktops[i]), FALSE); } menu_reload(); @@ -395,6 +405,31 @@ cb_xfdesktop_application_reload(GAction *action, } static void +cb_xfdesktop_application_next(GAction *action, + GVariant *parameter, + gpointer data) +{ + XfdesktopApplication *app; + gint i; + + TRACE("entering"); + + g_return_if_fail(XFDESKTOP_IS_APPLICATION(data)); + + app = XFDESKTOP_APPLICATION(data); + + /* If xfdesktop never started there's nothing to do here */ + if(!app->desktops) + return; + + /* reload all the desktops forcing the wallpaper to advance */ + for(i = 0; i < app->nscreens; ++i) { + if(app->desktops[i]) + xfce_desktop_refresh(XFCE_DESKTOP(app->desktops[i]), TRUE); + } +} + +static void xfdesktop_handle_quit_signals(gint sig, gpointer user_data) { @@ -789,6 +824,7 @@ xfdesktop_application_local_command_line(GApplication *g_application, GError *error = NULL; gboolean opt_version = FALSE; gboolean opt_reload = FALSE; + gboolean opt_next = FALSE; gboolean opt_menu = FALSE; gboolean opt_windowlist = FALSE; gboolean opt_arrange = FALSE; @@ -799,6 +835,7 @@ xfdesktop_application_local_command_line(GApplication *g_application, const GOptionEntry main_entries[] = { { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &opt_version, N_("Display version information"), NULL }, { "reload", 'R', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &opt_reload, N_("Reload all settings"), NULL }, + { "next", 'N', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &opt_next, N_("Advance to the next wallpaper on the current workspace"), NULL }, { "menu", 'M', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &opt_menu, N_("Pop up the menu (at the current mouse position)"), NULL }, { "windowlist", 'W', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &opt_windowlist, N_("Pop up the window list (at the current mouse position)"), NULL }, #ifdef ENABLE_FILE_ICONS @@ -876,6 +913,9 @@ xfdesktop_application_local_command_line(GApplication *g_application, } else if(opt_reload) { g_action_group_activate_action(G_ACTION_GROUP(g_application), "reload", NULL); option_set = TRUE; + } else if(opt_next) { + g_action_group_activate_action(G_ACTION_GROUP(g_application), "next", NULL); + option_set = TRUE; } else if(opt_menu) { g_action_group_activate_action(G_ACTION_GROUP(g_application), "menu", g_variant_new_boolean(TRUE)); diff --git a/xfdesktop.1 b/xfdesktop.1 index 652b06b..8ea2980 100644 --- a/xfdesktop.1 +++ b/xfdesktop.1 @@ -1,4 +1,4 @@ -.TH XFDESKTOP 1 "July 2014" +.TH XFDESKTOP 1 "August 2014" .SH NAME xfdesktop \- The Xfce 4 Desktop Environment's desktop manager @@ -40,7 +40,11 @@ Display version information .TP .B \-R, --reload Causes an already-running instance of \fBxfdesktop\fP to reload all its -settings, including loading a new random backdrop if using a backdrop list. +settings and redraws the desktop background. +.TP +.B \-N, --next +Causes an already-running instance of \fBxfdesktop\fP to advance to the +next wallpaper on the current workspace. .TP .B \-M, --menu Causes an already-running instance of \fBxfdesktop\fP to pop up the @@ -109,6 +113,4 @@ Jasper Huijsmans , Benedikt Meurer , Brian Tarricone , and Eric Koegel . -This manual page was originally written by Brian Tarricone -.br -. +This manual page was originally written by Brian Tarricone . -- 2.0.2