添加壁纸动态切换功能
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/* 壁纸列表,支持通配符和 shell 环境变量拼接,最后以 NULL 结尾 */
|
/* 壁纸列表,支持通配符和 shell 环境变量拼接,最后以 NULL 结尾 */
|
||||||
const char *wallpager_list[] = {NULL};
|
const char *wallpager_list[] = {NULL};
|
||||||
|
/* 壁纸切换间隔(单位:秒),0 表示不切换 */
|
||||||
|
const uint32_t wallpaper_interval = 0;
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
extern const char *wallpager_list[];
|
extern const char *wallpager_list[];
|
||||||
|
extern const uint32_t wallpaper_interval;
|
||||||
|
|||||||
24
src/main.c
24
src/main.c
@@ -1,5 +1,6 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glibconfig.h>
|
#include <glibconfig.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -15,6 +16,7 @@
|
|||||||
|
|
||||||
static void init_monitors(void);
|
static void init_monitors(void);
|
||||||
static void init_wallpaper(void);
|
static void init_wallpaper(void);
|
||||||
|
static gboolean update_wallpaper(gpointer user_data);
|
||||||
static void set_wallpaper_by_index(uint32_t index);
|
static void set_wallpaper_by_index(uint32_t index);
|
||||||
static wallpaper_config_t *parse_wallpaper_config(const char **wallpapers);
|
static wallpaper_config_t *parse_wallpaper_config(const char **wallpapers);
|
||||||
static void free_wallpaper_config(wallpaper_config_t *wallpaper_config);
|
static void free_wallpaper_config(wallpaper_config_t *wallpaper_config);
|
||||||
@@ -82,8 +84,28 @@ void init_monitors(void) {
|
|||||||
void init_wallpaper(void) {
|
void init_wallpaper(void) {
|
||||||
wallpaper_config = parse_wallpaper_config(wallpager_list);
|
wallpaper_config = parse_wallpaper_config(wallpager_list);
|
||||||
if (!wallpaper_config) return;
|
if (!wallpaper_config) return;
|
||||||
|
if (wallpaper_interval) {
|
||||||
|
g_timeout_add_seconds(wallpaper_interval, update_wallpaper,
|
||||||
|
wallpaper_config);
|
||||||
|
}
|
||||||
|
|
||||||
set_wallpaper_by_index(0);
|
update_wallpaper(wallpaper_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean update_wallpaper(gpointer user_data) {
|
||||||
|
wallpaper_config_t *wc = user_data;
|
||||||
|
if (!wc) return false;
|
||||||
|
|
||||||
|
static uint32_t index = 0;
|
||||||
|
set_wallpaper_by_index(index);
|
||||||
|
uint32_t monitor_count = 0;
|
||||||
|
for (monitor_t *m = monitors; m; m = m->next) monitor_count++;
|
||||||
|
if (monitor_count) {
|
||||||
|
index += monitor_count;
|
||||||
|
index %= wc->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_wallpaper_by_index(uint32_t index) {
|
void set_wallpaper_by_index(uint32_t index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user