I am making program that can change wallpapers in Gnome desktop when you switch workspace and for periodic time. Assume that you have 3 workspace and for each workspace ( or virtual desktop ) you have each list. So for workspace number one, you have 4 hot chicks themed wallpapers ( Britney.png, Madonna,jpg, etc ). Workspace number two, you have 3 Super Hero themed wallpapers ( Superman.jpg, Spiderman2.png, etc ). Workspace 3, you have 2 Cartoon wallpapers.
Assume for 00:00 time, you are in workspace ( ws ) 2, you got Spiderman2.png wallpaper. If you change to ws 1, you will get Britney.png wallpaper, if you change to ws3, you will get Donald.png. But you don't change the ws. you just wait one minute. 01:00. Now you wallpaper change in your current ws( that is number 2 ) to Superman.jpg. If you change to ws 1, you will get Madonna.png wallpaper not Britney anymore, if you change to ws3, you will get MickeyMouse.png not Donald anymore.
What is the best way to randomize this list? Threads? So for this case, I am making three threads. Thread 1 randomize 4 wallpapers. Thread 2 randomize 3 wallpapers. Thread 3 randomize 2 wallpapers. Or just forking the child process?
That is question number one.
This is the rough daemon source code:
This daemon take up too much CPU usage. How do I press it down beside use nice function? How do I improve my algorithm for this daemon? To make it short, my daemon checking all the time what workspace is it. I don't surprise if the daemon has checked what workspace it is for more than ten times under one seconds. The problem is that to get clue what workspace it is, I have to forking another process to find out. Then I read the stdout from the program. By that way, only I can know what workspace it is.Code:string wallpaper; int workspace, dump; const int forever = 1; while( forever ) { //check if the workspace change workspace = whatWorkspaceIsIt(); //if still the same if( previous_workspace == workspace ) { //check if has passed 60 seconds dump = getCurrentTime() - previousTime; if( dump >= 60 ) { //here we ask the information from thread or child process that randomize wallpaper = getCurrentWallpaper( workspace ); changeTheWallpaper( wallpaper ); previousTime = getCurrentTime(); } } else { previousTime = getCurrentTime(); wallpaper = getCurrentWallpaper( workspace ); changeTheWallpaper( wallpaper ); } previous_workspace = workspace; }
Ideally it would be better if I can hacked the workspace swithcer source code. So the wallpaper changer is included in workspace switcher. So if you change the workspace , it will automatically change the wallpaper. But it is in C. And I am still newbie...... And it is not easy to read somebody sourcecode.