2016-11-02 15:22:45 -04:00
|
|
|
#pragma once
|
|
|
|
|
2016-11-25 07:55:15 -05:00
|
|
|
#include <chrono>
|
2019-01-04 19:08:18 -05:00
|
|
|
#include <memory>
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2017-05-23 15:32:34 -04:00
|
|
|
#include "cairo/context.hpp"
|
|
|
|
#include "cairo/surface.hpp"
|
2016-11-02 15:22:45 -04:00
|
|
|
#include "common.hpp"
|
|
|
|
#include "components/logger.hpp"
|
|
|
|
#include "components/types.hpp"
|
2016-12-05 14:41:00 -05:00
|
|
|
#include "events/signal_fwd.hpp"
|
2017-01-24 02:49:27 -05:00
|
|
|
#include "events/signal_receiver.hpp"
|
2016-11-20 17:04:31 -05:00
|
|
|
#include "utils/concurrency.hpp"
|
2016-12-05 14:41:00 -05:00
|
|
|
#include "x11/atoms.hpp"
|
|
|
|
#include "x11/connection.hpp"
|
|
|
|
#include "x11/tray_client.hpp"
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
#define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
|
|
|
|
#define _NET_SYSTEM_TRAY_ORIENTATION_VERT 1
|
|
|
|
|
|
|
|
#define SYSTEM_TRAY_REQUEST_DOCK 0
|
|
|
|
#define SYSTEM_TRAY_BEGIN_MESSAGE 1
|
|
|
|
#define SYSTEM_TRAY_CANCEL_MESSAGE 2
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
#define TRAY_WM_NAME "Polybar tray window"
|
|
|
|
#define TRAY_WM_CLASS "tray\0Polybar"
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2017-01-01 15:28:28 -05:00
|
|
|
#define TRAY_PLACEHOLDER "<placeholder-systray>"
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-25 07:55:15 -05:00
|
|
|
namespace chrono = std::chrono;
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
2016-11-12 06:56:39 -05:00
|
|
|
// fwd declarations
|
|
|
|
class connection;
|
|
|
|
struct xembed_data;
|
2017-05-23 15:32:34 -04:00
|
|
|
class background_manager;
|
2019-01-04 19:08:18 -05:00
|
|
|
class bg_slice;
|
2016-11-12 06:56:39 -05:00
|
|
|
|
|
|
|
struct tray_settings {
|
|
|
|
tray_settings() = default;
|
|
|
|
tray_settings& operator=(const tray_settings& o) = default;
|
|
|
|
|
|
|
|
alignment align{alignment::NONE};
|
2017-01-19 05:11:28 -05:00
|
|
|
bool running{false};
|
2018-08-08 08:33:48 -04:00
|
|
|
int rel_x{0};
|
|
|
|
int rel_y{0};
|
2017-01-19 05:11:28 -05:00
|
|
|
int orig_x{0};
|
|
|
|
int orig_y{0};
|
|
|
|
int configured_x{0};
|
|
|
|
int configured_y{0};
|
2017-01-25 17:33:26 -05:00
|
|
|
unsigned int configured_w{0U};
|
|
|
|
unsigned int configured_h{0U};
|
|
|
|
unsigned int configured_slots{0U};
|
|
|
|
unsigned int width{0U};
|
|
|
|
unsigned int width_max{0U};
|
|
|
|
unsigned int height{0U};
|
|
|
|
unsigned int height_fill{0U};
|
|
|
|
unsigned int spacing{0U};
|
|
|
|
unsigned int sibling{0U};
|
|
|
|
unsigned int background{0U};
|
2016-11-12 06:56:39 -05:00
|
|
|
bool transparent{false};
|
2016-12-03 17:01:21 -05:00
|
|
|
bool detached{false};
|
2016-11-12 06:56:39 -05:00
|
|
|
};
|
|
|
|
|
2017-01-25 17:33:26 -05:00
|
|
|
class tray_manager
|
|
|
|
: public xpp::event::sink<evt::expose, evt::visibility_notify, evt::client_message, evt::configure_request,
|
|
|
|
evt::resize_request, evt::selection_clear, evt::property_notify, evt::reparent_notify, evt::destroy_notify,
|
|
|
|
evt::map_notify, evt::unmap_notify>,
|
2017-05-23 15:32:34 -04:00
|
|
|
public signal_receiver<SIGN_PRIORITY_TRAY, signals::ui::visibility_change, signals::ui::dim_window, signals::ui::update_background> {
|
2016-11-02 15:22:45 -04:00
|
|
|
public:
|
2016-12-09 03:40:46 -05:00
|
|
|
using make_type = unique_ptr<tray_manager>;
|
|
|
|
static make_type make();
|
2016-12-09 03:02:47 -05:00
|
|
|
|
2017-05-23 15:32:34 -04:00
|
|
|
explicit tray_manager(connection& conn, signal_emitter& emitter, const logger& logger, background_manager& back);
|
2016-11-12 06:56:39 -05:00
|
|
|
|
|
|
|
~tray_manager();
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-12 06:56:39 -05:00
|
|
|
const tray_settings settings() const;
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
void setup(const bar_settings& bar_opts);
|
2016-11-02 15:22:45 -04:00
|
|
|
void activate();
|
2016-11-25 07:55:15 -05:00
|
|
|
void activate_delayed(chrono::duration<double, std::milli> delay = 1s);
|
2016-11-24 22:10:26 -05:00
|
|
|
void deactivate(bool clear_selection = true);
|
2016-11-02 15:22:45 -04:00
|
|
|
void reconfigure();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void reconfigure_window();
|
|
|
|
void reconfigure_clients();
|
2016-11-04 13:50:33 -04:00
|
|
|
void reconfigure_bg(bool realloc = false);
|
|
|
|
void refresh_window();
|
2016-12-04 21:49:57 -05:00
|
|
|
void redraw_window(bool realloc_bg = false);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
void query_atom();
|
|
|
|
void create_window();
|
2016-11-12 06:56:39 -05:00
|
|
|
void create_bg(bool realloc = false);
|
|
|
|
void restack_window();
|
2016-12-05 14:41:00 -05:00
|
|
|
void set_wm_hints();
|
|
|
|
void set_tray_colors();
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
void acquire_selection();
|
|
|
|
void notify_clients();
|
2016-12-14 05:34:09 -05:00
|
|
|
void notify_clients_delayed();
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
void track_selection_owner(xcb_window_t owner);
|
|
|
|
void process_docking_request(xcb_window_t win);
|
|
|
|
|
2018-08-08 08:33:48 -04:00
|
|
|
int calculate_x(unsigned width, bool abspos = true) const;
|
|
|
|
int calculate_y(bool abspos = true) const;
|
2019-01-04 19:08:18 -05:00
|
|
|
unsigned short int calculate_w() const;
|
|
|
|
unsigned short int calculate_h() const;
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2017-01-19 05:11:28 -05:00
|
|
|
int calculate_client_x(const xcb_window_t& win);
|
|
|
|
int calculate_client_y();
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
bool is_embedded(const xcb_window_t& win) const;
|
2016-11-12 06:56:39 -05:00
|
|
|
shared_ptr<tray_client> find_client(const xcb_window_t& win) const;
|
|
|
|
void remove_client(shared_ptr<tray_client>& client, bool reconfigure = true);
|
2016-12-14 21:30:41 -05:00
|
|
|
void remove_client(xcb_window_t win, bool reconfigure = true);
|
2017-01-25 17:33:26 -05:00
|
|
|
unsigned int mapped_clients() const;
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
void handle(const evt::expose& evt);
|
|
|
|
void handle(const evt::visibility_notify& evt);
|
|
|
|
void handle(const evt::client_message& evt);
|
|
|
|
void handle(const evt::configure_request& evt);
|
|
|
|
void handle(const evt::resize_request& evt);
|
|
|
|
void handle(const evt::selection_clear& evt);
|
|
|
|
void handle(const evt::property_notify& evt);
|
|
|
|
void handle(const evt::reparent_notify& evt);
|
|
|
|
void handle(const evt::destroy_notify& evt);
|
|
|
|
void handle(const evt::map_notify& evt);
|
|
|
|
void handle(const evt::unmap_notify& evt);
|
|
|
|
|
2017-01-25 17:33:26 -05:00
|
|
|
bool on(const signals::ui::visibility_change& evt);
|
|
|
|
bool on(const signals::ui::dim_window& evt);
|
2017-05-23 15:32:34 -04:00
|
|
|
bool on(const signals::ui::update_background& evt);
|
2016-12-05 14:41:00 -05:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
private:
|
|
|
|
connection& m_connection;
|
2016-12-05 14:41:00 -05:00
|
|
|
signal_emitter& m_sig;
|
2016-11-02 15:22:45 -04:00
|
|
|
const logger& m_log;
|
2019-01-04 19:08:18 -05:00
|
|
|
background_manager& m_background_manager;
|
|
|
|
std::shared_ptr<bg_slice> m_bg_slice;
|
2016-11-12 06:56:39 -05:00
|
|
|
vector<shared_ptr<tray_client>> m_clients;
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-15 03:29:14 -05:00
|
|
|
tray_settings m_opts{};
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-04 13:50:33 -04:00
|
|
|
xcb_gcontext_t m_gc{0};
|
|
|
|
xcb_pixmap_t m_pixmap{0};
|
2017-05-23 15:32:34 -04:00
|
|
|
unique_ptr<cairo::surface> m_surface;
|
|
|
|
unique_ptr<cairo::context> m_context;
|
2017-01-24 02:49:27 -05:00
|
|
|
|
2017-01-25 17:33:26 -05:00
|
|
|
unsigned int m_prevwidth{0U};
|
|
|
|
unsigned int m_prevheight{0U};
|
2016-11-04 13:50:33 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
xcb_atom_t m_atom{0};
|
|
|
|
xcb_window_t m_tray{0};
|
|
|
|
xcb_window_t m_othermanager{0};
|
|
|
|
|
2016-12-22 23:18:58 -05:00
|
|
|
atomic<bool> m_activated{false};
|
|
|
|
atomic<bool> m_mapped{false};
|
|
|
|
atomic<bool> m_hidden{false};
|
|
|
|
atomic<bool> m_acquired_selection{false};
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-25 07:55:15 -05:00
|
|
|
thread m_delaythread;
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-22 23:18:58 -05:00
|
|
|
mutex m_mtx{};
|
2016-12-14 05:34:09 -05:00
|
|
|
|
|
|
|
bool m_firstactivation{true};
|
2016-11-02 15:22:45 -04:00
|
|
|
};
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|