1 #pragma once 2 3 #include <glibmm/refptr.h> 4 #include <gtkmm/drawingarea.h> 5 #include <gtkmm/window.h> 6 #include <wf-shell-app.hpp> 7 #include <wf-option-wrap.hpp> 8 #include <wayfire/util/duration.hpp> 9 10 class WayfireBackground; 11 12 class BackgroundImage 13 { 14 public: 15 double x, y; 16 Glib::RefPtr<Gdk::Pixbuf> pbuf; 17 }; 18 19 class BackgroundDrawingArea : public Gtk::DrawingArea 20 { 21 wf::animation::simple_animation_t fade{ 22 wf::create_option(1000), 23 wf::animation::smoothing::linear 24 }; 25 /* These two pixbufs are used for fading one background 26 * image to the next when changing backgrounds or when 27 * automatically cycling through a directory of images. 28 * pbuf is the current image to which we are fading and 29 * pbuf2 is the image from which we are fading. x and y 30 * are used as offsets when preserve aspect is set. */ 31 BackgroundImage to_image, from_image; 32 33 public: 34 BackgroundDrawingArea(); 35 void show_image(Glib::RefPtr<Gdk::Pixbuf> image, 36 double offset_x, double offset_y); 37 38 protected: 39 bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override; 40 }; 41 42 class WayfireBackground 43 { 44 WayfireShellApp *app; 45 WayfireOutput *output; 46 47 BackgroundDrawingArea drawing_area; 48 std::vector<std::string> images; 49 Gtk::Window window; 50 51 int scale; 52 double offset_x, offset_y; 53 bool inhibited = false; 54 uint current_background; 55 sigc::connection change_bg_conn; 56 57 WfOption<std::string> background_image{"background/image"}; 58 WfOption<int> background_cycle_timeout{"background/cycle_timeout"}; 59 WfOption<bool> background_randomize{"background/randomize"}; 60 WfOption<bool> background_preserve_aspect{"background/preserve_aspect"}; 61 62 Glib::RefPtr<Gdk::Pixbuf> create_from_file_safe(std::string path); 63 bool background_transition_frame(int timer); 64 bool change_background(int timer); 65 bool load_images_from_dir(std::string path); 66 bool load_next_background(Glib::RefPtr<Gdk::Pixbuf> &pbuf, std::string &path); 67 void reset_background(); 68 void set_background(); 69 void reset_cycle_timeout(); 70 71 void setup_window(); 72 73 public: 74 WayfireBackground(WayfireShellApp *app, WayfireOutput *output); 75 }; 76