gboolean get_image(char *name){ char *image_name = malloc(strlen(current_dir) + strlen(name) + 2); strcpy(image_name, current_dir); strcat(image_name, name); return set_wallpaper(image_name, style); }
void Wallpaper::handle_disable() { if ( ! m_disable ) { set_wallpaper(); m_count = 0; } }
void Wallpaper::handle_jump_back( size_t distance ) { if ( ! m_disable ) { set_wallpaper(); m_count = 0; } }
void Wallpaper::handle_continue() { if ( ! m_disable ) { if ( 0 == ( ++m_count % m_frequence ) ) { set_wallpaper(); } } }
void Wallpaper::listen_thread_function() { while ( m_listening && !m_disable ) { IGlobalSignals::instance().wait_next_slide(); if ( m_listening && !m_disable ) { set_wallpaper(); } } }
void window_request(int pid, unsigned char *req) { /* window request */ if (req[1] == WMREQ_REGWIN) add_window(pid, (wm_reg_t *) req); else if (req[1] == WMREQ_REDRAW) redraw_window(pid, (wm_redraw_t *) req); else if (req[1] == WMREQ_CLOSEWIN) close_window(pid, (wm_closewin_t *) req); else if (req[1] == WMREQ_SET_WP) { set_wallpaper(((wm_set_wallpaper_t *) req)->index); update_screen(); } }
/* Main function */ int main(int argc, char **argv) { int rc = -1, local_brightness = -1; int exit_status = EXIT_SUCCESS; unsigned seed; char *annfile = NULL; char cfgpath[PATH_MAX]; char current_wallpaper[PATH_MAX] = "\0"; char dbfile[PATH_MAX]; char wallpaper_path[PATH_MAX] = "\0"; struct arguments arguments; struct fann *ann = NULL; GSettings *settings = NULL; sqlite3 *db = NULL; /* Default argument values */ arguments.brightness = -1; arguments.interactive = 0; arguments.latitude = -1; arguments.longitude = -1; arguments.recursion = 0; arguments.scan = 0; arguments.time = 0; arguments.verbose = 0; /* Parse arguments; every option seen by parse_opt will be reflected in arguments. */ argp_parse(&argp, argc, argv, 0, 0, &arguments); /* Define the wallpaper state */ struct wallpaper_state wallpaper = { arguments.args[0], current_wallpaper, wallpaper_path }; if ( !g_file_test(wallpaper.dir, G_FILE_TEST_IS_DIR) ) { fprintf(stderr, "Cannot access directory %s\n", wallpaper.dir); exit_status = EXIT_FAILURE; goto Return; } /* Set the user specific data storage folder. The folder is automatically created if it doesn't already exist. */ get_user_data_folder(cfgpath, sizeof cfgpath, "nextwall"); if (cfgpath[0] == 0) { fprintf(stderr, "Error: Unable to set the data storage folder.\n"); exit_status = EXIT_FAILURE; goto Return; } /* Set the database file path */ strcpy(dbfile, cfgpath); strcat(dbfile, "nextwall.db"); /* Find the location of the ANN file */ if (arguments.scan) { int i, ann_found; char *annfiles[3]; if (asprintf(&annfile, "%snextwall.net", cfgpath) == -1) { fprintf(stderr, "asprintf() failed: %s\n", strerror(errno)); exit_status = EXIT_FAILURE; goto Return; } annfiles[0] = annfile; annfiles[1] = "/usr/local/share/nextwall/nextwall.net"; annfiles[2] = "/usr/share/nextwall/nextwall.net"; for (i = 0; i < 3; i++) { if ( (ann_found = g_file_test(annfiles[i], G_FILE_TEST_IS_REGULAR)) ) { eprintf("Using ANN %s\n", annfiles[i]); /* Initialize the ANN */ ann = fann_create_from_file(annfiles[i]); break; } } if (!ann_found) { fprintf(stderr, "Error: Could not find ANN file nextwall.net\n"); exit_status = EXIT_FAILURE; goto Return; } } /* Create the database if it doesn't exist */ if ( !g_file_test(dbfile, G_FILE_TEST_IS_REGULAR) ) { eprintf("Creating database... "); if ( (rc = sqlite3_open(dbfile, &db)) == SQLITE_OK && \ create_database(db) == 0 ) { eprintf("Done\n"); } else { eprintf("Failed\n"); fprintf(stderr, "Error: Creating database failed.\n"); exit_status = EXIT_FAILURE; goto Return; } } /* Open database connection */ if ( rc != SQLITE_OK ) { if ( sqlite3_open(dbfile, &db) != SQLITE_OK ) { fprintf(stderr, "Error: Can't open database: %s\n", sqlite3_errmsg(db)); exit_status = EXIT_FAILURE; goto Return; } } /* Search directory for wallpapers */ if (arguments.scan) { int found; fprintf(stderr, "Scanning for new wallpapers..."); found = scan_dir(db, wallpaper.dir, ann, arguments.recursion); fann_destroy(ann); fprintf(stderr, " Done\n"); fprintf(stderr, "Found %d new wallpapers\n", found); goto Return; } /* Get local brightness */ if (arguments.time) { if (arguments.brightness == -1) local_brightness = get_local_brightness(arguments.latitude, arguments.longitude); else local_brightness = arguments.brightness; switch (local_brightness) { case 0: eprintf("Selecting wallpaper for night.\n"); break; case 1: eprintf("Selecting wallpapers for twilight.\n"); break; case 2: eprintf("Selecting wallpaper for day.\n"); break; default: fprintf(stderr, "Error: Could not determine the local " \ "brightness value.\n"); exit_status = EXIT_FAILURE; goto Return; } } /* Set the seed for the random number generator */ if ( read(open("/dev/urandom", O_RDONLY), &seed, sizeof seed) == -1 ) { exit_status = EXIT_FAILURE; goto Return; } srand(seed); /* Set the wallpaper path */ if ( (nextwall(db, wallpaper.dir, local_brightness, wallpaper.path)) == -1 ) { fprintf(stderr, "No wallpapers found for directory %s. Try the " \ "--scan option or remove the --time option.\n", wallpaper.dir); goto Return; } /* Create a GSettings object for the desktop background */ settings = g_settings_new("org.gnome.desktop.background"); if (arguments.interactive) { char* input, shell_prompt[100]; fprintf(stderr, "Nextwall %s\n" \ "License: GNU GPL version 3 or later " \ "<http://gnu.org/licenses/gpl.html>\n" \ "Type 'help' for more information.\n", PACKAGE_VERSION); // Configure readline to auto-complete paths when the tab key is hit. rl_bind_key('\t', rl_complete); // Set the prompt text. snprintf(shell_prompt, sizeof(shell_prompt), "nextwall> "); for(;;) { // Display prompt and read input. input = readline(shell_prompt); // Check for EOF. if (!input) { fprintf(stderr, "\n"); break; } // If the line has any text in it, save it on the history. if (input && *input) add_history(input); // Check if the directory still exists. if ( !g_file_test(wallpaper.dir, G_FILE_TEST_IS_DIR) ) { fprintf(stderr, "Cannot access directory %s\n", wallpaper.dir); exit_status = EXIT_FAILURE; goto Return; } if (strcmp(input, "d") == 0) { get_background_uri(settings, wallpaper.current); fprintf(stderr, "Move wallpaper %s to trash? (y/N) ", wallpaper.current); if ( (input = readline("")) && strcmp(input, "y") == 0 && \ remove_wallpaper(db, wallpaper.current) == 0 ) { fprintf(stderr, "Wallpaper removed\n"); if ( set_wallpaper(settings, db, local_brightness, &wallpaper) == -1) goto Return; } } else if (strcmp(input, "") == 0 || strcmp(input, "n") == 0) { if (set_wallpaper(settings, db, local_brightness, &wallpaper) == -1) goto Return; } else if (strcmp(input, "o") == 0) { get_background_uri(settings, wallpaper.current); open_image(wallpaper.current); } else if (strcmp(input, "help") == 0) { fprintf(stderr, "Nextwall is now running in interactive mode. The " \ "following commands are available:\n" \ "'d'\tDelete the current wallpaper\n" \ "'n'\tNext wallpaper (default)\n" \ "'o'\tOpen the current wallpaper\n" \ "'q'\tExit nextwall\n"); } else if (strcmp(input, "q") == 0) { goto Return; } else { fprintf(stderr, "Unknown command. Type 'help' to see the " \ "available commands.\n"); } // Free input. free(input); } } else { set_wallpaper(settings, db, local_brightness, &wallpaper); } goto Return; Return: if (annfile) free(annfile); if (settings) g_object_unref(settings); if (db) sqlite3_close(db); return exit_status; }
int re_rotate_wallpaper(char *wallpaper) { char *path2wallpaper, *wall_base, *wall_path; DIR *dirp; struct dirent *dp; int ret; int found = FALSE; /* Suppose someone is doing something nasty with `lastwallpaper' */ cleanpath(wallpaper); path2wallpaper = malloc(MAXPATHLEN); if (path2wallpaper == NULL) err(1, "out of memory"); wall_path = malloc(MAXPATHLEN); if (wall_path == NULL) err(1, "out of memory"); wall_base = malloc(MAXPATHLEN); if (wall_base == NULL) err(1, "out of memory"); /* dirname ruins wallpaper, so run basename first. */ ret = snprintf(wall_base, MAXPATHLEN, "%s", basename(wallpaper)); if (ret < 0 || ret >= MAXPATHLEN) errx(1, "arguments out of bounds for wallpaperpath"); ret = snprintf(wall_path, MAXPATHLEN, "%s", dirname(wallpaper)); if (ret < 0 || ret >= MAXPATHLEN) errx(1, "arguments out of bounds for wallpaperpath"); #ifdef DEBUG printf("path: %s ;name: %s\n", wall_path, wall_base); #endif /* Open the directory */ if ((dirp = opendir(wall_path)) == NULL) err(1, "%s: ", wall_path); /* First lets find the current wallpaper in this dir. */ while ((dp = readdir(dirp)) != NULL) { /* step over . and .. */ if (dp->d_name[0] == '.') { if (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' && dp->d_name[2] == '\0')) continue; } if (strcmp (wall_base, dp->d_name) == 0) { /* We found our wallpaper, lets step to the next one. * If it happened to be the last member of list, cycle * and read the first entry. */ found = TRUE; if ((dp = readdir(dirp)) == NULL) { rewinddir(dirp); dp = readdir(dirp); } } /* Now that we found our wallpaper the _next_ one with a valid * extension will be set. */ if (found == TRUE && checkextension(dp->d_name) == 0) { ret = snprintf(path2wallpaper, MAXPATHLEN, "%s/%s", wall_path, dp->d_name); if (ret < 0 || ret >= MAXPATHLEN) errx(1, "arguments out of bounds" " for wallpaperpath"); set_wallpaper('o', path2wallpaper); break; } #ifdef DEBUG printf("looking for:%s ;current: %s\n", wall_base, dp->d_name); #endif } closedir(dirp); free(path2wallpaper); free(wall_path); free(wall_base); if (found == TRUE) return(TRUE); else errx(1, "no wallpaper was found"); }