mirror of
https://github.com/polybar/polybar.git
synced 2024-10-27 05:23:39 -04:00
Cleanup tray code
This commit is contained in:
parent
4961a7dcfc
commit
18485d00c2
2 changed files with 13 additions and 45 deletions
|
@ -42,14 +42,10 @@ class bg_slice;
|
||||||
struct tray_settings {
|
struct tray_settings {
|
||||||
alignment align{alignment::NONE};
|
alignment align{alignment::NONE};
|
||||||
bool running{false};
|
bool running{false};
|
||||||
int rel_x{0};
|
|
||||||
int rel_y{0};
|
|
||||||
int orig_x{0};
|
int orig_x{0};
|
||||||
int orig_y{0};
|
int orig_y{0};
|
||||||
int configured_x{0};
|
|
||||||
int configured_y{0};
|
|
||||||
unsigned int configured_w{0U};
|
unsigned int configured_w{0U};
|
||||||
unsigned int configured_h{0U};
|
|
||||||
unsigned int configured_slots{0U};
|
unsigned int configured_slots{0U};
|
||||||
unsigned int width{0U};
|
unsigned int width{0U};
|
||||||
unsigned int width_max{0U};
|
unsigned int width_max{0U};
|
||||||
|
@ -95,7 +91,7 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
|
||||||
|
|
||||||
void query_atom();
|
void query_atom();
|
||||||
void create_window();
|
void create_window();
|
||||||
void create_bg(bool realloc = false);
|
void create_bg();
|
||||||
void restack_window();
|
void restack_window();
|
||||||
void set_wm_hints();
|
void set_wm_hints();
|
||||||
void set_tray_colors();
|
void set_tray_colors();
|
||||||
|
@ -108,7 +104,7 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
|
||||||
void process_docking_request(xcb_window_t win);
|
void process_docking_request(xcb_window_t win);
|
||||||
|
|
||||||
int calculate_x(unsigned width) const;
|
int calculate_x(unsigned width) const;
|
||||||
int calculate_y(bool abspos = true) const;
|
int calculate_y() const;
|
||||||
|
|
||||||
unsigned short int calculate_w() const;
|
unsigned short int calculate_w() const;
|
||||||
unsigned short int calculate_h() const;
|
unsigned short int calculate_h() const;
|
||||||
|
@ -148,15 +144,13 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
|
||||||
vector<shared_ptr<tray_client>> m_clients;
|
vector<shared_ptr<tray_client>> m_clients;
|
||||||
|
|
||||||
tray_settings m_opts{};
|
tray_settings m_opts{};
|
||||||
|
const bar_settings& m_bar_opts;
|
||||||
|
|
||||||
xcb_gcontext_t m_gc{0};
|
xcb_gcontext_t m_gc{0};
|
||||||
xcb_pixmap_t m_pixmap{0};
|
xcb_pixmap_t m_pixmap{0};
|
||||||
unique_ptr<cairo::surface> m_surface;
|
unique_ptr<cairo::surface> m_surface;
|
||||||
unique_ptr<cairo::context> m_context;
|
unique_ptr<cairo::context> m_context;
|
||||||
|
|
||||||
unsigned int m_prevwidth{0U};
|
|
||||||
unsigned int m_prevheight{0U};
|
|
||||||
|
|
||||||
xcb_atom_t m_atom{0};
|
xcb_atom_t m_atom{0};
|
||||||
xcb_window_t m_tray{0};
|
xcb_window_t m_tray{0};
|
||||||
xcb_window_t m_othermanager{0};
|
xcb_window_t m_othermanager{0};
|
||||||
|
@ -171,8 +165,6 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
|
||||||
mutex m_mtx{};
|
mutex m_mtx{};
|
||||||
|
|
||||||
bool m_firstactivation{true};
|
bool m_firstactivation{true};
|
||||||
|
|
||||||
const bar_settings& m_bar_opts;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
|
|
@ -166,9 +166,6 @@ void tray_manager::setup() {
|
||||||
|
|
||||||
m_opts.orig_x += units_utils::percentage_with_offset_to_pixel(offset_x, max_x, m_bar_opts.dpi_x);
|
m_opts.orig_x += units_utils::percentage_with_offset_to_pixel(offset_x, max_x, m_bar_opts.dpi_x);
|
||||||
m_opts.orig_y += units_utils::percentage_with_offset_to_pixel(offset_y, max_y, m_bar_opts.dpi_y);
|
m_opts.orig_y += units_utils::percentage_with_offset_to_pixel(offset_y, max_y, m_bar_opts.dpi_y);
|
||||||
;
|
|
||||||
m_opts.rel_x = m_opts.orig_x - m_bar_opts.pos.x;
|
|
||||||
m_opts.rel_y = m_opts.orig_y - m_bar_opts.pos.y;
|
|
||||||
|
|
||||||
// Put the tray next to the bar in the window stack
|
// Put the tray next to the bar in the window stack
|
||||||
m_opts.sibling = m_bar_opts.window;
|
m_opts.sibling = m_bar_opts.window;
|
||||||
|
@ -263,18 +260,13 @@ void tray_manager::deactivate(bool clear_selection) {
|
||||||
m_connection.free_pixmap(m_pixmap);
|
m_connection.free_pixmap(m_pixmap);
|
||||||
}
|
}
|
||||||
if (m_gc) {
|
if (m_gc) {
|
||||||
m_connection.free_gc(m_pixmap);
|
m_connection.free_gc(m_gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tray = 0;
|
m_tray = 0;
|
||||||
m_pixmap = 0;
|
m_pixmap = 0;
|
||||||
m_gc = 0;
|
m_gc = 0;
|
||||||
m_prevwidth = 0;
|
|
||||||
m_prevheight = 0;
|
|
||||||
m_opts.configured_x = 0;
|
|
||||||
m_opts.configured_y = 0;
|
|
||||||
m_opts.configured_w = 0;
|
m_opts.configured_w = 0;
|
||||||
m_opts.configured_h = 0;
|
|
||||||
m_opts.configured_slots = 0;
|
m_opts.configured_slots = 0;
|
||||||
m_acquired_selection = false;
|
m_acquired_selection = false;
|
||||||
m_mapped = false;
|
m_mapped = false;
|
||||||
|
@ -359,7 +351,6 @@ void tray_manager::reconfigure_window() {
|
||||||
}
|
}
|
||||||
|
|
||||||
m_opts.configured_w = width;
|
m_opts.configured_w = width;
|
||||||
m_opts.configured_x = x;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -485,7 +476,7 @@ void tray_manager::create_window() {
|
||||||
m_log.trace("tray: Create tray window");
|
m_log.trace("tray: Create tray window");
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
auto win = winspec(m_connection, m_tray)
|
auto win = winspec(m_connection)
|
||||||
<< cw_size(calculate_w(), calculate_h())
|
<< cw_size(calculate_w(), calculate_h())
|
||||||
<< cw_pos(calculate_x(calculate_w()), calculate_y())
|
<< cw_pos(calculate_x(calculate_w()), calculate_y())
|
||||||
<< cw_class(XCB_WINDOW_CLASS_INPUT_OUTPUT)
|
<< cw_class(XCB_WINDOW_CLASS_INPUT_OUTPUT)
|
||||||
|
@ -517,28 +508,13 @@ void tray_manager::create_window() {
|
||||||
/**
|
/**
|
||||||
* Create tray window background components
|
* Create tray window background components
|
||||||
*/
|
*/
|
||||||
void tray_manager::create_bg(bool realloc) {
|
void tray_manager::create_bg() {
|
||||||
if (!m_opts.transparent) {
|
if (!m_opts.transparent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!realloc && m_pixmap && m_gc && m_surface && m_context) {
|
if (m_pixmap && m_gc && m_surface && m_context) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (realloc && m_pixmap) {
|
|
||||||
m_connection.free_pixmap(m_pixmap);
|
|
||||||
m_pixmap = 0;
|
|
||||||
}
|
|
||||||
if (realloc && m_gc) {
|
|
||||||
m_connection.free_gc(m_gc);
|
|
||||||
m_gc = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (realloc && m_surface) {
|
|
||||||
m_surface.reset();
|
|
||||||
}
|
|
||||||
if (realloc && m_context) {
|
|
||||||
m_context.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto w = m_opts.width_max;
|
auto w = m_opts.width_max;
|
||||||
auto h = calculate_h();
|
auto h = calculate_h();
|
||||||
|
@ -812,8 +788,8 @@ int tray_manager::calculate_x(unsigned int width) const {
|
||||||
/**
|
/**
|
||||||
* Calculate y position of tray window
|
* Calculate y position of tray window
|
||||||
*/
|
*/
|
||||||
int tray_manager::calculate_y(bool abspos) const {
|
int tray_manager::calculate_y() const {
|
||||||
return abspos ? m_opts.orig_y : m_opts.rel_y;
|
return m_opts.orig_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -944,10 +920,10 @@ void tray_manager::handle(const evt::client_message& evt) {
|
||||||
m_log.trace("tray: Received client_message");
|
m_log.trace("tray: Received client_message");
|
||||||
|
|
||||||
if (SYSTEM_TRAY_REQUEST_DOCK == evt->data.data32[1]) {
|
if (SYSTEM_TRAY_REQUEST_DOCK == evt->data.data32[1]) {
|
||||||
if (!is_embedded(evt->data.data32[2])) {
|
xcb_window_t win = evt->data.data32[2];
|
||||||
process_docking_request(evt->data.data32[2]);
|
if (!is_embedded(win)) {
|
||||||
|
process_docking_request(win);
|
||||||
} else {
|
} else {
|
||||||
auto win = evt->data.data32[2];
|
|
||||||
m_log.warn("Tray client %s already embedded, ignoring request...", m_connection.id(win));
|
m_log.warn("Tray client %s already embedded, ignoring request...", m_connection.id(win));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue