-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdal.cpp
More file actions
89 lines (73 loc) · 2.51 KB
/
dal.cpp
File metadata and controls
89 lines (73 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
////////////////////////////////////////////////////////////////////////////////// //
// Desktop Animator for Linux //
// //
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <dirent.h>
#include <cstdlib>
#include <string.h>
#include <string>
#include <sstream>
#include <unistd.h>
#include <vector>
#include <fastformat/fastformat.hpp>
#include <fastformat/internal/initialiser.hpp>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;
int main(int argc, char* argv[]) {
if (argc < 4) {
cout << "Usage: daw [DIRECTORY OF IMAGES]\n [TIME BETWEEN FRAMES IN MICROSECONDS]\n [FILE EXTENSION OF IMAGES]\n\nNote: Must include a forward slash at end of specified directory name and a \".\" before file extension." << endl;
cin.get();
return -1;
}
DIR *direc = NULL;
const char *images = argv[1];
direc = opendir(images);
struct dirent *dirlist = NULL;
std::stringstream ss;
string framestr;
vector<string> frames(1), checkedframes(1), goodframes(1);
string currentframe;
const char *extension = argv[3];
const char *framecheck1, *framecheck2;
string framenumber;
pid_t process;
int useconds = atoi(argv[2]);
if (direc == NULL) {
return -1;
}
while ((dirlist = readdir(direc)) != NULL) {
ss.str(dirlist->d_name);
framestr = ss.str();
frames.push_back(framestr);
frames.reserve(1);
}
for (int i = 0; i < frames.size(); ++i) {
if (frames[i].find(extension) != std::string::npos) {
checkedframes.push_back(frames[i]);
checkedframes.reserve(1);
}
}
for (int j = 0; j < checkedframes.size(); ++j) {
framenumber = "";
fastformat::write(framenumber, "frame_", j, "_");
for (int k = 0; k < checkedframes.size(); ++k) {
if (checkedframes[k].find(framenumber) != std::string::npos) {
goodframes.push_back(checkedframes[k]);
goodframes.reserve(1);
}
}
}
for (int l = 0; l < goodframes.size(); ++l) {
currentframe = "";
fastformat::write(currentframe, "file://", argv[1], goodframes[l]);
if ((process = fork()) == 0) {
execl("/usr/bin/gsettings", "gsettings", "set", "org.gnome.desktop.background", "picture-uri", currentframe.c_str(), NULL);
}
usleep(useconds);
}
return 0;
}