I am just "rewriting" a program I did in C to C++. because I want to write a program in C++. so why not use on I already knows works. but in C++. pit falls. using c++ 11 .

Linux: not windows.
the situation is: the program takes image files and displays them on the background. I found some code to allow me to add it to the C program I wrote that allows me to not have to use a bash script to change the image at a given time. So I rewrote my program to do so in C. thus eliminating the need to use that BASH script. The program itself now does this.

then, I've never did C++, so why not use this one to do the same?

In my C program one issue I was having was opening the Display, then calling to close it. I'd run out of Displays that can be opened. as the call to close the Display has two setting ( if I remember correctly) right now as in flush the que or put it in a que to be flushed whenever it gets around to it.


to eliminate that issue of the system freezing up because it used up its allotted amount of open displays, I removed the call to have it opened and set to NULL each time a different image was being called to be set on the background.

the easiest way was to just add that line in main so it gets called only once and it worked. Now in C++ using that same methodology. I do not know if it is me or the command line directives, or the standard vers C++11 or C++14 or whatever the others ones are.

because I started out with a shell. as post in here and me dealing with a vector to get the list of file names I needed first then I moved on to getting it to set one image one the desktop using that list, got that, then I moved on to getting a timer setup so I can change images at a given time. got that.

when I was running that timer, in fiddling with it until I got it to work. I'd change images faster the C. but it worked, even after I figured out how to get it to stop wait then run again. (as I used a different method of timer)

nevertheless, now that i had all three of my basic needs met. a list of file names, the ability to load and set the image, then the means to change the image automatically at a give time by the users preference.

time to build off of that little bit of code needed to do that. Using the same method I used in C to eliminate the over run of Displays allowed. I am now getting a seg fault because when it gets to the function to do the rest my display is no longer valid. when it was with my little bit of code. strangely enough.
ug, my code:

I'm sure one does not want the entire program to run it ..
so I will post the main, and the function. keep in mind. it's still a work in progress,
Code:
#include <iostream>
#include <vector>
#include <algorithm>
#include </usr/include/Imlib2.h>
#include <pwd.h>
#include "options.h"
#include "img.h"
#include "files.h"
#include "timers.h"

int main(int argc, char **argv)
{
    img.display = XOpenDisplay(NULL);
    
//if display say so. it does then goes to the function to set 
//up the rest of it.

     if (img.display){
        std::cout<<"img.context main"<<std::endl;
    //    exit(1);
    }
    
    srand((unsigned)time(0));
    init_options(argc, argv);
    
    
    std::cout<< (int)img.mode<<std::endl;

   if ( (int)img.mode > 0 && img.time > 0){
    std::cout<<"size "<<opts.dfile.size()<<std::endl;
    sort_V();
    std::cout << "size 2 "<< opts.dfile.size()<<std::endl;
 //   if (opts.dfile.size() > 0)
       // setup_images();
      start_atimer(); <-- gets called in timer.
    }
    return 0;
}
timer, I guess I better put that in here to show code flow.
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
#include </usr/include/Imlib2.h>

#include <vector>

#include "files.h"
#include "img.h"
#include "timers.h"

#include "options.h"
 


void start_atimer() 
{ std::cout << "atimer "<< img.time <<std::endl;
 clock_t startTime = clock(); //Start timer
 double secondsPassed;
 double secondsToDelay = img.time;
 bool flag = true;
 while(flag)
  {
   secondsPassed = (clock() - startTime) / CLOCKS_PER_SEC;
   if(secondsPassed >= secondsToDelay)
    {
     std::cout << secondsPassed << " seconds have passed" << std::endl;
     setup_images(); <-- gets called here
     std::cout << secondsPassed << " call seconds have passed" << std::endl;
     secondsPassed  = 0;
     startTime = clock();
    }
  }
}
function
Code:
void setup_images()
{ 
 
    img.modifier = NULL;
    img.context = imlib_context_new();

// I added this call back in here and it runs like it should now
// but I bet a small duck that it will put me back
// in over flow of allowed displays open
// due to how they get closed

     img.display = XOpenDisplay(NULL);

   // this stops if from seg faulting 
// if not display exit, it exits, meaning no more display.

      if (!img.display){
        std::cout<<"img.display"<<std::endl;
        exit(1);
    }
    imlib_context_push(img.context);
    imlib_context_set_display(img.display);
  
    img.vis = DefaultVisual(img.display, 0);
    img.cm = DefaultColormap(img.display, 0);
    img.screenH = DisplayWidth(img.display, 0);
    img.screenW = DisplayHeight(img.display, 0);
    std::cout<<" in set  images"<<std::endl;
    img.depth = DefaultDepth(img.display, 0);
    std::cout<<" in set  images before create pix map"<<std::endl;
    img.pixmap = XCreatePixmap(img.display,    RootWindow(img.display, 0), img.screenW, img.screenH, img.depth);
    std::cout<<" in set  images before create pixmap"<<std::endl;
    imlib_context_set_display(img.display);
    imlib_context_set_visual(img.vis);
    imlib_context_set_colormap(img.cm);
    imlib_context_set_drawable(img.pixmap);
    imlib_context_set_color_range(imlib_create_color_range());
    std::cout<<" in set  images before create image"<<std::endl;
    img.buffer = imlib_create_image(img.screenW, img.screenH);
    std::cout<<" in set  images after create image"<<std::endl;
    imlib_context_set_image(img.buffer);
    //set_buffer();
    
    imlib_context_set_color(0, 0, 0, 255);
    imlib_image_fill_rectangle(0, 0, img.screenW, img.screenH);
    imlib_context_set_dither(1);
    imlib_context_set_blend(1);
    img.modifier = imlib_create_color_modifier();
    imlib_context_set_color_modifier(img.modifier);

    load_image();
}