diff --git a/config/.config/polybar/config b/config/.config/polybar/config index 85e3384..d82191b 100644 --- a/config/.config/polybar/config +++ b/config/.config/polybar/config @@ -113,16 +113,16 @@ click-left = bash -c "playerctl next" [module/spotify-play] type = custom/script exec-if = pgrep -x spotify -exec = python -u /home/tuan/.scripts/spotify-play.py +exec = ~/.scripts/spotify-play.out tail = true -click-left = bash -c "if [ `cat /home/tuan/.scripts/playstate` = 0 ]; then echo '1'>/home/tuan/.scripts/playstate;else echo '0'>/home/tuan/.scripts/playstate;fi" +click-left = bash -c "if [ `cat /home/$USER/.scripts/playstate` = 0 ]; then echo '1'>/home/$USER/.scripts/playstate;else echo '0'>/home/$USER/.scripts/playstate;fi" [module/spotify-stop] type = custom/script exec-if = pgrep -x spotify exec = echo "" tail = true -click-left = bash -c "playerctl stop && echo '0'>/home/tuan/.scripts/playstate" +click-left = bash -c "playerctl stop && echo '0'>/home/$USER/.scripts/playstate" [module/i3] type = internal/i3 diff --git a/config/.scripts/spotify-play.cpp b/config/.scripts/spotify-play.cpp new file mode 100644 index 0000000..423853f --- /dev/null +++ b/config/.scripts/spotify-play.cpp @@ -0,0 +1,90 @@ +/* ______ _________ _______ _______ _ _______ _________ _______ _______ _______ + * ( __ \ \__ __/( ____ \( ____ \( \ ( ___ )\__ __/( )( ____ \( ____ ) + * | ( \ ) ) ( | ( \/| ( \/| ( | ( ) | ) ( | () () || ( \/| ( )| + * | | ) | | | | (_____ | | | | | (___) | | | | || || || (__ | (____)| + * | | | | | | (_____ )| | | | | ___ | | | | |(_)| || __) | __) + * | | ) | | | ) || | | | | ( ) | | | | | | || ( | (\ ( + * | (__/ )___) (___/\____) || (____/\| (____/\| ) ( |___) (___| ) ( || (____/\| ) \ \__ + * (______/ \_______/\_______)(_______/(_______/|/ \|\_______/|/ \|(_______/|/ \__/ + * + * + * THIS IS GARBAGE CODE AND I KNOW IT. + * I KNOW ABSOLUTLY NOTHING ABOUT C++ AND JUST FRANKENSTEINED + * A BUNCH OF CODE SAMPLES, USING MY PYTHON CODE AS A TEMPLATE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +int getdir(string dir, vector &files){ + DIR *dp; + struct dirent *dirp; + if((dp = opendir(dir.c_str())) == NULL){ + cout << "Error(" << errno << ") opening " << dir << endl; + return errno; + } + + while ((dirp = readdir(dp)) != NULL){ + files.push_back(string(dirp->d_name)); + } + closedir(dp); + return 0; +} + +string getfile(string file_path){ + ifstream inFile; + string file_content; + inFile.open(file_path); + if(!inFile){ + return ""; + } + inFile >> file_content; + return file_content; +} + +bool spotify_running(){ + string dir = string("/proc/"); + vector procs = vector(); + getdir(dir, procs); + string proc_name = string(""); + for (unsigned int i = 0; i < procs.size(); i++){ + proc_name = dir + procs[i] + "/cmdline"; + if(getfile(proc_name).find(string("/usr/bin/spotify")) != string::npos){ + return true; + } + } + return false; +} + +int main(){ + struct passwd *pw = getpwuid(getuid()); + const char *homedir = pw->pw_dir; + int state = -1; + int playstate = 0; + string playstate_file = ""; + playstate_file += homedir + string("/.scripts/playstate"); + while (spotify_running()){ + playstate = stoi(getfile(playstate_file)); + if(playstate != state){ + state = playstate; + if (state == 0){ + cout << "" << endl; + system("playerctl pause"); + } + else if (state == 1){ + cout << "" << endl; + system("playerctl play"); + } + } + usleep(100); + } +} diff --git a/config/.scripts/spotify-play.out b/config/.scripts/spotify-play.out new file mode 100755 index 0000000..641e867 Binary files /dev/null and b/config/.scripts/spotify-play.out differ diff --git a/config/.scripts/spotify-play.py b/config/.scripts/spotify-play.py index 92913bd..48ad62e 100755 --- a/config/.scripts/spotify-play.py +++ b/config/.scripts/spotify-play.py @@ -3,6 +3,7 @@ import subprocess import time import os + def find_proc(proc_name): this_proc = "pythonspotify-play.py" proc_path = '/proc' @@ -25,8 +26,9 @@ def spotify_running(): def main(): state = -1 + home = os.path.expanduser("~") while spotify_running(): - with open('~/.scripts/playstate', 'r') as f: + with open(home + '/.scripts/playstate', 'r') as f: try: file_state = int(f.readline().strip('\n')) except ValueError: diff --git a/emacs/.emacs.d/snippets/c++-mode/cerr b/emacs/.emacs.d/snippets/c++-mode/cerr new file mode 100644 index 0000000..921b3a0 --- /dev/null +++ b/emacs/.emacs.d/snippets/c++-mode/cerr @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: cerr +# key: err +# -- +cerr << $0; \ No newline at end of file diff --git a/emacs/.emacs.d/snippets/c++-mode/cin b/emacs/.emacs.d/snippets/c++-mode/cin new file mode 100644 index 0000000..401ccda --- /dev/null +++ b/emacs/.emacs.d/snippets/c++-mode/cin @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: cin +# key: cin +# -- +cin >> $0; \ No newline at end of file diff --git a/emacs/.emacs.d/snippets/c++-mode/cout b/emacs/.emacs.d/snippets/c++-mode/cout new file mode 100644 index 0000000..1c8e600 --- /dev/null +++ b/emacs/.emacs.d/snippets/c++-mode/cout @@ -0,0 +1,8 @@ +# -*- mode: snippet -*- +# contributor: York Zhao +# name: cout +# key: cout +# -- +`(progn (goto-char (point-min)) (unless (re-search-forward +"^using\\s-+namespace std;" nil 'no-errer) "std::")) +`cout << $0${1: << "${2:\n}"}; \ No newline at end of file diff --git a/emacs/.emacs.d/snippets/c++-mode/fori b/emacs/.emacs.d/snippets/c++-mode/fori new file mode 100644 index 0000000..7676a89 --- /dev/null +++ b/emacs/.emacs.d/snippets/c++-mode/fori @@ -0,0 +1,7 @@ +# -*- mode: snippet -*- +# name: fori +# key: fori +# -- +for (${1:auto }${2:it} = ${3:var}.begin(); $2 != $3.end(); ++$2) { + $0 +} \ No newline at end of file diff --git a/emacs/.emacs.d/snippets/c++-mode/io b/emacs/.emacs.d/snippets/c++-mode/io new file mode 100644 index 0000000..1355dac --- /dev/null +++ b/emacs/.emacs.d/snippets/c++-mode/io @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: io +# key: io +# -- +#include \ No newline at end of file