Xfce Forum

Sub domains
 

You are not logged in.

#1 2025-05-15 14:35:54

archisman
Member
Registered: 2022-08-05
Posts: 3
LinuxFirefox 128.0

[Solved] How to get the path of current wallpaper with a command?

I am developing an app which features a "chameleonic" background color based on the wallpaper. For it, I get the path of the wallpaper, and get the appropriate color using imagemagick.

In GNOME, I can get the path of the wallpaper with `gsettings get org.gnome.desktop.background picture-uri`. Something similar is available for MATE Desktop and Cinnamon.

Is there any similar way (maybe, by looking at the appropriate conf file) I can get the path of the wallpaper in XFCE?

Last edited by archisman (2025-05-25 13:56:43)

Offline

#2 2025-05-15 18:33:26

mint4all
Member
From: off the map
Registered: 2018-08-21
Posts: 293
LinuxFirefox 138.0

Re: [Solved] How to get the path of current wallpaper with a command?

archisman wrote:

I am developing an app which features a "chameleonic" background color based on the wallpaper. For it, I get the path of the wallpaper, and get the appropriate color using imagemagick.

In GNOME, I can get the path of the wallpaper with `gsettings get org.gnome.desktop.background picture-uri`. Something similar is available for MATE Desktop and Cinnamon.

Is there any similar way (maybe, by looking at the appropriate conf file) I can get the path of the wallpaper in XFCE?

Greetings and welcome!

A while back, I had a similar need, and with ToZ's help, devised the following script run as a launcher's "command" string...

bash -c "backdrop=$(xfconf-query -c xfce4-desktop -p '/backdrop/screen0/monitoreDP-1/workspace0/last-image') && ristretto $backdrop "

I use it re-display with image viewer the current background image before it auto-cycles to the next image.

This might give you a starting point. Of course, you'll have to tweak you monitor's setup.
Cheers, m4a


Linux Mint 21.3 -- xfce 4.18 ... Apple iMAC -- Lenovo, Dell, HP Desktops and Laptops -- Family & Community Support

Offline

#3 2025-05-15 21:19:35

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,993
LinuxFirefox 138.0

Re: [Solved] How to get the path of current wallpaper with a command?

This might help to identify the currently valid display names, if you're looking for something programmatic.


Mark solved threads as [SOLVED] to make it easier for others to find solutions.
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#4 2025-05-16 09:02:52

Misko_2083
Member
Registered: 2015-10-13
Posts: 223
Website
LinuxFirefox 128.0

Re: [Solved] How to get the path of current wallpaper with a command?

mint4all wrote:
bash -c "backdrop=$(xfconf-query -c xfce4-desktop -p '/backdrop/screen0/monitoreDP-1/workspace0/last-image') && ristretto $backdrop "

This is not correct in case when you tick "Apply to all workspaces" on another workspace.
You can check /backdrop/single-workspace-mode and /backdrop/single-workspace-number to find out the right background.
This scipt will do (on X11, because it uses xrandr).

#!/bin/bash
# list_monitors_wallpapers.sh
# Ensure required tools are available
command -v xfconf-query >/dev/null 2>&1 || { echo "Error: xfconf-query is required"; exit 1; }
command -v xrandr >/dev/null 2>&1 || { echo "Error: xrandr is required"; exit 1; }

# Function to validate monitor name (exclude numeric names like "0", "1")
is_valid_monitor_name() {
    local name="$1"
    [[ -z "$name" ]] && return 1
    [[ "$name" =~ ^[0-9]+$ ]] && return 1
    return 0
}

# Get monitor information using xrandr
mapfile -t monitors < <(xrandr --current | grep -w connected | awk '{print $1, $2}')
monitor_count=${#monitors[@]}

# Get XFCE desktop channel properties
channel="xfce4-desktop"

# Check single workspace mode
single_workspace_mode=$(xfconf-query -c "$channel" -p "/backdrop/single-workspace-mode" 2>/dev/null || echo "false")
[[ "$single_workspace_mode" == "true" ]] && single_mode=1 || single_mode=0

# Get single workspace number (default to 0 if not set)
single_workspace_number=$(xfconf-query -c "$channel" -p "/backdrop/single-workspace-number" 2>/dev/null || echo "0")

# Get all backdrop properties
props=$(xfconf-query -c "$channel" -p "/backdrop/screen0" -l 2>/dev/null | grep "last-image")

# Initialize associative arrays
declare -A monitor_paths
if [[ $single_mode -eq 0 ]]; then
    declare -A workspace_paths
fi

# Parse properties
while IFS= read -r key; do
    if [[ "$key" == *"/last-image" ]]; then
        # Extract monitor name
        monitor_name=$(echo "$key" | grep -oP '(?<=/monitor)[^/]+')
        # Extract workspace name
        workspace_name=$(echo "$key" | grep -oP '(?<=workspace)[0-9]+')
        
        if [[ -n "$monitor_name" ]] && is_valid_monitor_name "$monitor_name"; then
            # Get wallpaper path
            value=$(xfconf-query -c "$channel" -p "$key" 2>/dev/null)
            if [[ -n "$value" ]]; then
                if [[ $single_mode -eq 1 ]]; then
                    # Single workspace mode: store only the wallpaper for single_workspace_number
                    if [[ "$workspace_name" == "$single_workspace_number" ]]; then
                        monitor_paths["$monitor_name"]="$value"
                    fi
                else
                    # Multi-workspace mode: store all workspaces
                    workspace_paths["$monitor_name:$workspace_name"]="$value"
                fi
            fi
        fi
    fi
done <<< "$props"

# Output monitor and wallpaper info
index=0
while IFS= read -r line; do
    monitor_name=$(echo "$line" | awk '{print $1}')
    is_primary=$(echo "$line" | grep -q "primary" && echo "Yes" || echo "No")
    
    if is_valid_monitor_name "$monitor_name"; then
        printf "Monitor %d: %s [Primary: %s]\n" "$index" "$monitor_name" "$is_primary"
        
        if [[ $single_mode -eq 1 ]]; then
            wallpaper="${monitor_paths[$monitor_name]:-<not set>}"
            printf "  Wallpaper: %s\n" "$wallpaper"
        else
            # Get all workspaces for this monitor and sort them numerically
            mapfile -t workspaces < <(
                for key in "${!workspace_paths[@]}"; do
                    if [[ "$key" == "$monitor_name:"* ]]; then
                        ws=$(echo "$key" | cut -d':' -f2)
                        echo "$ws"
                    fi
                done | sort -n
            )
            
            if [[ ${#workspaces[@]} -gt 0 ]]; then
                for ws in "${workspaces[@]}"; do
                    wallpaper="${workspace_paths[$monitor_name:$ws]:-<not set>}"
                    printf "  Workspace %s: %s\n" "$ws" "$wallpaper"
                done
            else
                printf "  No wallpapers set for this monitor\n"
            fi
        fi
        ((index++))
    fi
done < <(xrandr --current | grep -w connected)

exit 0

Now when you move desktop settings to another workspace,
pick some different wallpaper from that workspace and click "Apply to all workspaces" and this script will print the correct wallpaper.

@ToZ As for C, for 4.18 with a few libraries (gtk+-3.0 libxfconf-0 glib-2.0) this will do:

Hidden text

list_monitors_wallpapers_xfconf.c

// gcc -o list_monitors_wallpapers_xfconf list_monitors_wallpapers_xfconf.c `pkg-config --cflags --libs gtk+-3.0 libxfconf-0 glib-2.0`

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <xfconf/xfconf.h>

#define DEBUG_PRINT(fmt, ...) fprintf(stderr, "DEBUG: " fmt "\n", ##__VA_ARGS__)

// Helper to check string prefix
gboolean str_starts_with(const gchar *str, const gchar *prefix) {
    return g_str_has_prefix(str, prefix);
}

// Helper to validate monitor name (exclude numeric names like "0", "1")
gboolean is_valid_monitor_name(const gchar *name) {
    if (!name) return FALSE;
    for (const gchar *p = name; *p; p++) {
        if (!g_ascii_isdigit(*p)) return TRUE;
    }
    return FALSE;
}

int main(int argc, char **argv) {
    gtk_init(&argc, &argv);
    if (!xfconf_init(NULL)) {
        g_error("Failed to initialize Xfconf");
        return 1;
    }

    GdkDisplay *display = gdk_display_get_default();
    if (!display) {
        xfconf_shutdown();
        g_error("Failed to get GDK display");
        return 1;
    }

    int n_monitors = gdk_display_get_n_monitors(display);
    //DEBUG_PRINT("Number of monitors detected: %d", n_monitors);

    XfconfChannel *channel = xfconf_channel_get("xfce4-desktop");

    // Check single-workspace-mode
    gboolean single_workspace_mode = xfconf_channel_get_bool(channel, "/backdrop/single-workspace-mode", FALSE);
    //DEBUG_PRINT("Single workspace mode: %s", single_workspace_mode ? "true" : "false");

    // Get the single workspace number
    gint single_workspace_number = xfconf_channel_get_int(channel, "/backdrop/single-workspace-number", 0);
    gchar *single_workspace_str = g_strdup_printf("%d", single_workspace_number);
    //DEBUG_PRINT("Single workspace number: %s", single_workspace_str);

    GHashTable *props_table = xfconf_channel_get_properties(channel, "/backdrop/screen0");
    if (!props_table) {
        g_free(single_workspace_str);
        xfconf_shutdown();
        g_error("Failed to get XFCE wallpaper properties");
        return 1;
    }

    GList *props = g_hash_table_get_keys(props_table);

    // Store monitor wallpaper mappings
    // For single workspace: monitor_name -> wallpaper_path
    // For multi-workspace: monitor_name -> GHashTable(workspace -> wallpaper_path)
    GHashTable *monitor_paths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, 
        single_workspace_mode ? g_free : (GDestroyNotify)g_hash_table_destroy);

    for (GList *l = props; l != NULL; l = l->next) {
        const gchar *key = (const gchar *)l->data;

        if (strstr(key, "last-image")) {
            const gchar *monitor_prefix = "/monitor";
            const gchar *workspace_prefix = "workspace";
            gchar *monitor_name = NULL;
            gchar *workspace_name = NULL;

            // Extract monitor name
            const gchar *monitor_start = strstr(key, monitor_prefix);
            if (monitor_start) {
                monitor_start += strlen(monitor_prefix);
                const gchar *monitor_end = strchr(monitor_start, '/');
                if (monitor_end) {
                    monitor_name = g_strndup(monitor_start, monitor_end - monitor_start);
                } else {
                    monitor_name = g_strdup(monitor_start);
                }
            }

            // Extract workspace name
            const gchar *workspace_start = strstr(key, workspace_prefix);
            if (workspace_start) {
                workspace_start += strlen(workspace_prefix);
                const gchar *workspace_end = strstr(workspace_start, "/");
                if (workspace_end) {
                    workspace_name = g_strndup(workspace_start, workspace_end - workspace_start);
                } else {
                    workspace_name = g_strdup(workspace_start);
                }
            }

            if (monitor_name && is_valid_monitor_name(monitor_name)) {
                gchar *value = xfconf_channel_get_string(channel, key, NULL);
                if (value) {
                    if (single_workspace_mode) {
                        // Single workspace: store only the wallpaper for single_workspace_number
                        if (workspace_name && g_strcmp0(workspace_name, single_workspace_str) == 0) {
                            //DEBUG_PRINT("Single mode - Monitor: %s, wallpaper: %s", monitor_name, value);
                            g_hash_table_replace(monitor_paths, monitor_name, value);
                        } else {
                            g_free(monitor_name);
                            g_free(value);
                        }
                    } else {
                        // Multi-workspace: store all workspaces in a nested hash table
                        GHashTable *workspace_paths = g_hash_table_lookup(monitor_paths, monitor_name);
                        if (!workspace_paths) {
                            workspace_paths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
                            // Insert monitor_name into monitor_paths, hash table takes ownership
                            g_hash_table_insert(monitor_paths, monitor_name, workspace_paths);
                        } else {
                            // If workspace_paths exists, monitor_name is already owned by monitor_paths, so free it
                            g_free(monitor_name);
                        }
                        //DEBUG_PRINT("Multi mode - Monitor: %s, Workspace: %s, wallpaper: %s", 
                        //            monitor_name, workspace_name ? workspace_name : "unknown", value);
                        // Insert workspace_name and value, hash table takes ownership
                        g_hash_table_replace(workspace_paths, workspace_name ? workspace_name : g_strdup("unknown"), value);
                    }
                } else {
                    g_free(monitor_name);
                    g_free(workspace_name);
                }
            } else {
                g_free(monitor_name);
                g_free(workspace_name);
            }
        }
    }

    // Output info
    for (int i = 0; i < n_monitors; i++) {
        GdkMonitor *mon = gdk_display_get_monitor(display, i);
        const gchar *model = gdk_monitor_get_model(mon);
        gboolean is_primary = gdk_monitor_is_primary(mon);

        const gchar *monitor_key = model && is_valid_monitor_name(model) ? model : NULL;
        printf("Monitor %d: %s [Primary: %s]\n", i, model ? model : "unknown", is_primary ? "Yes" : "No");

        if (single_workspace_mode) {
            const gchar *wallpaper = monitor_key ? g_hash_table_lookup(monitor_paths, monitor_key) : NULL;
            printf("  Wallpaper: %s\n", wallpaper ? wallpaper : "<not set>");
        } else {
            GHashTable *workspace_paths = monitor_key ? g_hash_table_lookup(monitor_paths, monitor_key) : NULL;
            if (workspace_paths) {
                GList *workspace_keys = g_hash_table_get_keys(workspace_paths);
                // Sort workspace keys numerically
                workspace_keys = g_list_sort(workspace_keys, (GCompareFunc)g_strcmp0);
                for (GList *wk = workspace_keys; wk != NULL; wk = wk->next) {
                    const gchar *ws = wk->data;
                    const gchar *wallpaper = g_hash_table_lookup(workspace_paths, ws);
                    printf("  Workspace %s: %s\n", ws, wallpaper ? wallpaper : "<not set>");
                }
                g_list_free(workspace_keys);
            } else {
                printf("  No wallpapers set for this monitor\n");
            }
        }
    }

    // Cleanup
    g_free(single_workspace_str);
    xfconf_shutdown();
    g_list_free(props);
    g_hash_table_unref(props_table);
    g_hash_table_destroy(monitor_paths);

    return 0;
}

When compiled run

./list_monitors_wallpapers_xfconf

Last edited by Misko_2083 (2025-05-16 09:04:09)


Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

#5 2025-05-25 13:56:20

archisman
Member
Registered: 2022-08-05
Posts: 3
LinuxFirefox 138.0

Re: [Solved] How to get the path of current wallpaper with a command?

Misko_2083 wrote:
mint4all wrote:
bash -c "backdrop=$(xfconf-query -c xfce4-desktop -p '/backdrop/screen0/monitoreDP-1/workspace0/last-image') && ristretto $backdrop "

This is not correct in case when you tick "Apply to all workspaces" on another workspace.
You can check /backdrop/single-workspace-mode and /backdrop/single-workspace-number to find out the right background.
This scipt will do (on X11, because it uses xrandr).

#!/bin/bash
# list_monitors_wallpapers.sh
# Ensure required tools are available
command -v xfconf-query >/dev/null 2>&1 || { echo "Error: xfconf-query is required"; exit 1; }
command -v xrandr >/dev/null 2>&1 || { echo "Error: xrandr is required"; exit 1; }

# Function to validate monitor name (exclude numeric names like "0", "1")
is_valid_monitor_name() {
    local name="$1"
    [[ -z "$name" ]] && return 1
    [[ "$name" =~ ^[0-9]+$ ]] && return 1
    return 0
}

# Get monitor information using xrandr
mapfile -t monitors < <(xrandr --current | grep -w connected | awk '{print $1, $2}')
monitor_count=${#monitors[@]}

# Get XFCE desktop channel properties
channel="xfce4-desktop"

# Check single workspace mode
single_workspace_mode=$(xfconf-query -c "$channel" -p "/backdrop/single-workspace-mode" 2>/dev/null || echo "false")
[[ "$single_workspace_mode" == "true" ]] && single_mode=1 || single_mode=0

# Get single workspace number (default to 0 if not set)
single_workspace_number=$(xfconf-query -c "$channel" -p "/backdrop/single-workspace-number" 2>/dev/null || echo "0")

# Get all backdrop properties
props=$(xfconf-query -c "$channel" -p "/backdrop/screen0" -l 2>/dev/null | grep "last-image")

# Initialize associative arrays
declare -A monitor_paths
if [[ $single_mode -eq 0 ]]; then
    declare -A workspace_paths
fi

# Parse properties
while IFS= read -r key; do
    if [[ "$key" == *"/last-image" ]]; then
        # Extract monitor name
        monitor_name=$(echo "$key" | grep -oP '(?<=/monitor)[^/]+')
        # Extract workspace name
        workspace_name=$(echo "$key" | grep -oP '(?<=workspace)[0-9]+')
        
        if [[ -n "$monitor_name" ]] && is_valid_monitor_name "$monitor_name"; then
            # Get wallpaper path
            value=$(xfconf-query -c "$channel" -p "$key" 2>/dev/null)
            if [[ -n "$value" ]]; then
                if [[ $single_mode -eq 1 ]]; then
                    # Single workspace mode: store only the wallpaper for single_workspace_number
                    if [[ "$workspace_name" == "$single_workspace_number" ]]; then
                        monitor_paths["$monitor_name"]="$value"
                    fi
                else
                    # Multi-workspace mode: store all workspaces
                    workspace_paths["$monitor_name:$workspace_name"]="$value"
                fi
            fi
        fi
    fi
done <<< "$props"

# Output monitor and wallpaper info
index=0
while IFS= read -r line; do
    monitor_name=$(echo "$line" | awk '{print $1}')
    is_primary=$(echo "$line" | grep -q "primary" && echo "Yes" || echo "No")
    
    if is_valid_monitor_name "$monitor_name"; then
        printf "Monitor %d: %s [Primary: %s]\n" "$index" "$monitor_name" "$is_primary"
        
        if [[ $single_mode -eq 1 ]]; then
            wallpaper="${monitor_paths[$monitor_name]:-<not set>}"
            printf "  Wallpaper: %s\n" "$wallpaper"
        else
            # Get all workspaces for this monitor and sort them numerically
            mapfile -t workspaces < <(
                for key in "${!workspace_paths[@]}"; do
                    if [[ "$key" == "$monitor_name:"* ]]; then
                        ws=$(echo "$key" | cut -d':' -f2)
                        echo "$ws"
                    fi
                done | sort -n
            )
            
            if [[ ${#workspaces[@]} -gt 0 ]]; then
                for ws in "${workspaces[@]}"; do
                    wallpaper="${workspace_paths[$monitor_name:$ws]:-<not set>}"
                    printf "  Workspace %s: %s\n" "$ws" "$wallpaper"
                done
            else
                printf "  No wallpapers set for this monitor\n"
            fi
        fi
        ((index++))
    fi
done < <(xrandr --current | grep -w connected)

exit 0

Now when you move desktop settings to another workspace,
pick some different wallpaper from that workspace and click "Apply to all workspaces" and this script will print the correct wallpaper.

@ToZ As for C, for 4.18 with a few libraries (gtk+-3.0 libxfconf-0 glib-2.0) this will do:

Hidden text

list_monitors_wallpapers_xfconf.c

// gcc -o list_monitors_wallpapers_xfconf list_monitors_wallpapers_xfconf.c `pkg-config --cflags --libs gtk+-3.0 libxfconf-0 glib-2.0`

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <xfconf/xfconf.h>

#define DEBUG_PRINT(fmt, ...) fprintf(stderr, "DEBUG: " fmt "\n", ##__VA_ARGS__)

// Helper to check string prefix
gboolean str_starts_with(const gchar *str, const gchar *prefix) {
    return g_str_has_prefix(str, prefix);
}

// Helper to validate monitor name (exclude numeric names like "0", "1")
gboolean is_valid_monitor_name(const gchar *name) {
    if (!name) return FALSE;
    for (const gchar *p = name; *p; p++) {
        if (!g_ascii_isdigit(*p)) return TRUE;
    }
    return FALSE;
}

int main(int argc, char **argv) {
    gtk_init(&argc, &argv);
    if (!xfconf_init(NULL)) {
        g_error("Failed to initialize Xfconf");
        return 1;
    }

    GdkDisplay *display = gdk_display_get_default();
    if (!display) {
        xfconf_shutdown();
        g_error("Failed to get GDK display");
        return 1;
    }

    int n_monitors = gdk_display_get_n_monitors(display);
    //DEBUG_PRINT("Number of monitors detected: %d", n_monitors);

    XfconfChannel *channel = xfconf_channel_get("xfce4-desktop");

    // Check single-workspace-mode
    gboolean single_workspace_mode = xfconf_channel_get_bool(channel, "/backdrop/single-workspace-mode", FALSE);
    //DEBUG_PRINT("Single workspace mode: %s", single_workspace_mode ? "true" : "false");

    // Get the single workspace number
    gint single_workspace_number = xfconf_channel_get_int(channel, "/backdrop/single-workspace-number", 0);
    gchar *single_workspace_str = g_strdup_printf("%d", single_workspace_number);
    //DEBUG_PRINT("Single workspace number: %s", single_workspace_str);

    GHashTable *props_table = xfconf_channel_get_properties(channel, "/backdrop/screen0");
    if (!props_table) {
        g_free(single_workspace_str);
        xfconf_shutdown();
        g_error("Failed to get XFCE wallpaper properties");
        return 1;
    }

    GList *props = g_hash_table_get_keys(props_table);

    // Store monitor wallpaper mappings
    // For single workspace: monitor_name -> wallpaper_path
    // For multi-workspace: monitor_name -> GHashTable(workspace -> wallpaper_path)
    GHashTable *monitor_paths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, 
        single_workspace_mode ? g_free : (GDestroyNotify)g_hash_table_destroy);

    for (GList *l = props; l != NULL; l = l->next) {
        const gchar *key = (const gchar *)l->data;

        if (strstr(key, "last-image")) {
            const gchar *monitor_prefix = "/monitor";
            const gchar *workspace_prefix = "workspace";
            gchar *monitor_name = NULL;
            gchar *workspace_name = NULL;

            // Extract monitor name
            const gchar *monitor_start = strstr(key, monitor_prefix);
            if (monitor_start) {
                monitor_start += strlen(monitor_prefix);
                const gchar *monitor_end = strchr(monitor_start, '/');
                if (monitor_end) {
                    monitor_name = g_strndup(monitor_start, monitor_end - monitor_start);
                } else {
                    monitor_name = g_strdup(monitor_start);
                }
            }

            // Extract workspace name
            const gchar *workspace_start = strstr(key, workspace_prefix);
            if (workspace_start) {
                workspace_start += strlen(workspace_prefix);
                const gchar *workspace_end = strstr(workspace_start, "/");
                if (workspace_end) {
                    workspace_name = g_strndup(workspace_start, workspace_end - workspace_start);
                } else {
                    workspace_name = g_strdup(workspace_start);
                }
            }

            if (monitor_name && is_valid_monitor_name(monitor_name)) {
                gchar *value = xfconf_channel_get_string(channel, key, NULL);
                if (value) {
                    if (single_workspace_mode) {
                        // Single workspace: store only the wallpaper for single_workspace_number
                        if (workspace_name && g_strcmp0(workspace_name, single_workspace_str) == 0) {
                            //DEBUG_PRINT("Single mode - Monitor: %s, wallpaper: %s", monitor_name, value);
                            g_hash_table_replace(monitor_paths, monitor_name, value);
                        } else {
                            g_free(monitor_name);
                            g_free(value);
                        }
                    } else {
                        // Multi-workspace: store all workspaces in a nested hash table
                        GHashTable *workspace_paths = g_hash_table_lookup(monitor_paths, monitor_name);
                        if (!workspace_paths) {
                            workspace_paths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
                            // Insert monitor_name into monitor_paths, hash table takes ownership
                            g_hash_table_insert(monitor_paths, monitor_name, workspace_paths);
                        } else {
                            // If workspace_paths exists, monitor_name is already owned by monitor_paths, so free it
                            g_free(monitor_name);
                        }
                        //DEBUG_PRINT("Multi mode - Monitor: %s, Workspace: %s, wallpaper: %s", 
                        //            monitor_name, workspace_name ? workspace_name : "unknown", value);
                        // Insert workspace_name and value, hash table takes ownership
                        g_hash_table_replace(workspace_paths, workspace_name ? workspace_name : g_strdup("unknown"), value);
                    }
                } else {
                    g_free(monitor_name);
                    g_free(workspace_name);
                }
            } else {
                g_free(monitor_name);
                g_free(workspace_name);
            }
        }
    }

    // Output info
    for (int i = 0; i < n_monitors; i++) {
        GdkMonitor *mon = gdk_display_get_monitor(display, i);
        const gchar *model = gdk_monitor_get_model(mon);
        gboolean is_primary = gdk_monitor_is_primary(mon);

        const gchar *monitor_key = model && is_valid_monitor_name(model) ? model : NULL;
        printf("Monitor %d: %s [Primary: %s]\n", i, model ? model : "unknown", is_primary ? "Yes" : "No");

        if (single_workspace_mode) {
            const gchar *wallpaper = monitor_key ? g_hash_table_lookup(monitor_paths, monitor_key) : NULL;
            printf("  Wallpaper: %s\n", wallpaper ? wallpaper : "<not set>");
        } else {
            GHashTable *workspace_paths = monitor_key ? g_hash_table_lookup(monitor_paths, monitor_key) : NULL;
            if (workspace_paths) {
                GList *workspace_keys = g_hash_table_get_keys(workspace_paths);
                // Sort workspace keys numerically
                workspace_keys = g_list_sort(workspace_keys, (GCompareFunc)g_strcmp0);
                for (GList *wk = workspace_keys; wk != NULL; wk = wk->next) {
                    const gchar *ws = wk->data;
                    const gchar *wallpaper = g_hash_table_lookup(workspace_paths, ws);
                    printf("  Workspace %s: %s\n", ws, wallpaper ? wallpaper : "<not set>");
                }
                g_list_free(workspace_keys);
            } else {
                printf("  No wallpapers set for this monitor\n");
            }
        }
    }

    // Cleanup
    g_free(single_workspace_str);
    xfconf_shutdown();
    g_list_free(props);
    g_hash_table_unref(props_table);
    g_hash_table_destroy(monitor_paths);

    return 0;
}

When compiled run

./list_monitors_wallpapers_xfconf

The bash script worked. That you!

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.014 seconds, 7 queries executed - Memory usage: 664.92 KiB (Peak: 698.2 KiB) ]