2017-05-23 15:32:34 -04:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-04 19:08:18 -05:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-05-23 15:32:34 -04:00
|
|
|
#include "common.hpp"
|
|
|
|
#include "events/signal_fwd.hpp"
|
2017-08-31 12:26:38 -04:00
|
|
|
#include "events/signal_receiver.hpp"
|
2017-05-23 15:32:34 -04:00
|
|
|
#include "x11/extensions/fwd.hpp"
|
|
|
|
#include "x11/types.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
|
|
|
class logger;
|
|
|
|
|
|
|
|
namespace cairo {
|
|
|
|
class surface;
|
|
|
|
class xcb_surface;
|
2022-09-05 03:58:12 -04:00
|
|
|
} // namespace cairo
|
2017-05-23 15:32:34 -04:00
|
|
|
|
2019-01-04 19:08:18 -05:00
|
|
|
class bg_slice {
|
|
|
|
public:
|
|
|
|
~bg_slice();
|
|
|
|
// copying bg_slices is not allowed
|
|
|
|
bg_slice(const bg_slice&) = delete;
|
|
|
|
bg_slice& operator=(const bg_slice&) = delete;
|
|
|
|
|
2022-09-05 03:58:12 -04:00
|
|
|
cairo::surface* get_surface() const;
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
void copy(xcb_pixmap_t root_pixmap, int depth, xcb_rectangle_t geom, xcb_visualtype_t* visual);
|
2019-01-04 19:08:18 -05:00
|
|
|
|
|
|
|
private:
|
2022-09-05 03:58:12 -04:00
|
|
|
bg_slice(connection& conn, const logger& log, xcb_rectangle_t rect, xcb_window_t window);
|
2019-01-04 19:08:18 -05:00
|
|
|
|
|
|
|
connection& m_connection;
|
2022-09-05 03:58:12 -04:00
|
|
|
const logger& m_log;
|
2019-01-04 19:08:18 -05:00
|
|
|
|
2022-09-05 03:58:12 -04:00
|
|
|
/**
|
|
|
|
* Area covered by this slice
|
|
|
|
*
|
|
|
|
* Area is relative to given window
|
|
|
|
*/
|
2019-01-04 19:08:18 -05:00
|
|
|
xcb_rectangle_t m_rect{0, 0, 0U, 0U};
|
|
|
|
xcb_window_t m_window;
|
|
|
|
|
2022-09-05 03:58:12 -04:00
|
|
|
/**
|
|
|
|
* Cache for the root window background at this slice's position
|
|
|
|
*/
|
2019-01-04 19:08:18 -05:00
|
|
|
xcb_pixmap_t m_pixmap{XCB_NONE};
|
|
|
|
unique_ptr<cairo::xcb_surface> m_surface;
|
|
|
|
xcb_gcontext_t m_gcontext{XCB_NONE};
|
2022-09-05 03:58:12 -04:00
|
|
|
int m_depth{0};
|
2019-01-04 19:08:18 -05:00
|
|
|
|
2022-09-05 03:58:12 -04:00
|
|
|
void ensure_resources(int depth, xcb_visualtype_t* visual);
|
|
|
|
void allocate_resources(xcb_visualtype_t* visual);
|
2019-01-04 19:08:18 -05:00
|
|
|
void free_resources();
|
|
|
|
|
|
|
|
friend class background_manager;
|
|
|
|
};
|
|
|
|
|
2018-08-13 12:38:36 -04:00
|
|
|
/**
|
2022-02-20 15:40:48 -05:00
|
|
|
* @brief Class to keep track of the desktop background used to support pseudo-transparency
|
2018-08-13 12:38:36 -04:00
|
|
|
*
|
|
|
|
* For pseudo-transparency that bar needs access to the desktop background.
|
|
|
|
* We only need to store the slice of the background image which is covered by the bar window,
|
|
|
|
* so this class takes a rectangle that limits what part of the background is stored.
|
|
|
|
*/
|
2017-08-31 12:26:38 -04:00
|
|
|
class background_manager : public signal_receiver<SIGN_PRIORITY_SCREEN, signals::ui::update_geometry>,
|
2021-01-04 04:38:43 -05:00
|
|
|
public xpp::event::sink<evt::property_notify> {
|
2017-05-23 15:32:34 -04:00
|
|
|
public:
|
|
|
|
using make_type = background_manager&;
|
|
|
|
static make_type make();
|
|
|
|
|
2018-08-13 12:38:36 -04:00
|
|
|
/**
|
|
|
|
* Initializes a new background_manager that by default does not observe anything.
|
|
|
|
*
|
|
|
|
* To observe a slice of the background you need to call background_manager::activate.
|
|
|
|
*/
|
2017-05-23 15:32:34 -04:00
|
|
|
explicit background_manager(connection& conn, signal_emitter& sig, const logger& log);
|
|
|
|
~background_manager();
|
|
|
|
|
2018-08-13 12:38:36 -04:00
|
|
|
/**
|
|
|
|
* Starts observing a rectangular slice of the desktop background.
|
|
|
|
*
|
|
|
|
* After calling this function, you can obtain the current slice of the desktop background
|
2019-01-04 19:08:18 -05:00
|
|
|
* by calling get_surface on the returned bg_slice object.
|
|
|
|
* Whenever the background slice changes (for example, due to bar position changes or because
|
|
|
|
* the user changed the desktop background) the class emits a signals::ui::update_background event.
|
2018-08-13 12:38:36 -04:00
|
|
|
*
|
2019-01-04 19:08:18 -05:00
|
|
|
* You should only call this function once and then re-use the returned bg_slice because the bg_slice
|
|
|
|
* caches the background. If you don't need the background anymore, destroy the shared_ptr to free up
|
|
|
|
* resources.
|
2018-08-13 12:38:36 -04:00
|
|
|
*
|
2022-02-20 15:40:48 -05:00
|
|
|
* @param rect Slice of the background to observe (coordinates relative to window).
|
|
|
|
* @param window Coordinates are interpreted relative to this window
|
2018-08-13 12:38:36 -04:00
|
|
|
*/
|
2019-01-04 19:08:18 -05:00
|
|
|
std::shared_ptr<bg_slice> observe(xcb_rectangle_t rect, xcb_window_t window);
|
2017-05-23 15:32:34 -04:00
|
|
|
|
2021-01-04 04:38:43 -05:00
|
|
|
void handle(const evt::property_notify& evt) override;
|
|
|
|
bool on(const signals::ui::update_geometry&) override;
|
|
|
|
|
2017-05-23 15:32:34 -04:00
|
|
|
private:
|
2019-01-04 19:08:18 -05:00
|
|
|
void activate();
|
|
|
|
void deactivate();
|
|
|
|
|
2022-09-05 03:58:12 -04:00
|
|
|
void attach();
|
|
|
|
void detach();
|
|
|
|
/**
|
|
|
|
* True if we are currently attached as a listener for desktop background changes
|
|
|
|
*/
|
|
|
|
bool m_attached{false};
|
|
|
|
|
2018-08-13 12:38:36 -04:00
|
|
|
// references to standard components
|
2017-05-23 15:32:34 -04:00
|
|
|
connection& m_connection;
|
|
|
|
signal_emitter& m_sig;
|
|
|
|
const logger& m_log;
|
|
|
|
|
2022-09-05 03:58:12 -04:00
|
|
|
/**
|
|
|
|
* List of slices that need to be filled with the desktop background
|
|
|
|
*/
|
2019-01-04 19:08:18 -05:00
|
|
|
std::vector<std::weak_ptr<bg_slice>> m_slices;
|
2017-05-23 15:32:34 -04:00
|
|
|
|
2018-07-06 09:19:12 -04:00
|
|
|
void allocate_resources();
|
2017-05-23 15:32:34 -04:00
|
|
|
void free_resources();
|
2022-09-05 03:58:12 -04:00
|
|
|
void on_background_change();
|
|
|
|
|
|
|
|
void update_slice(bg_slice& slice);
|
|
|
|
|
|
|
|
bool has_pixmap() const;
|
|
|
|
void ensure_pixmap();
|
|
|
|
void load_pixmap();
|
|
|
|
void clear_pixmap();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The loaded root pixmap
|
|
|
|
*/
|
|
|
|
xcb_pixmap_t m_pixmap{XCB_NONE};
|
|
|
|
int m_pixmap_depth{0};
|
|
|
|
xcb_rectangle_t m_pixmap_geom{0, 0, 0, 0};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tracks whether we were able to load a pixmap.
|
|
|
|
*/
|
|
|
|
bool m_pixmap_load_failed{false};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Visual matching the root pixmap's depth.
|
|
|
|
*
|
|
|
|
* Only valid if m_pixmap is set
|
|
|
|
*/
|
|
|
|
xcb_visualtype_t* m_visual{nullptr};
|
2017-05-23 15:32:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|