tray: remove tray-position = adaptive (#2726)
The tray is automatically started if there is a tray module. In addition, `tray-position` and the tray module conflict. Ref #2689
This commit is contained in:
parent
6a43758b5b
commit
86f2baa550
@ -43,7 +43,7 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
|
|||||||
|
|
||||||
const bar_settings& settings() const;
|
const bar_settings& settings() const;
|
||||||
|
|
||||||
void start();
|
void start(const string& tray_module_name);
|
||||||
|
|
||||||
void parse(string&& data, bool force = false);
|
void parse(string&& data, bool force = false);
|
||||||
|
|
||||||
|
@ -100,6 +100,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eve
|
|||||||
eventloop::loop& m_loop;
|
eventloop::loop& m_loop;
|
||||||
unique_ptr<bar> m_bar;
|
unique_ptr<bar> m_bar;
|
||||||
bool m_has_ipc;
|
bool m_has_ipc;
|
||||||
|
string m_tray_module_name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Async handle to notify the eventloop
|
* @brief Async handle to notify the eventloop
|
||||||
|
@ -39,8 +39,10 @@ class connection;
|
|||||||
class background_manager;
|
class background_manager;
|
||||||
class bg_slice;
|
class bg_slice;
|
||||||
|
|
||||||
|
enum class tray_postition { NONE = 0, LEFT, CENTER, RIGHT, MODULE };
|
||||||
|
|
||||||
struct tray_settings {
|
struct tray_settings {
|
||||||
alignment align{alignment::NONE};
|
tray_postition tray_position{tray_postition::NONE};
|
||||||
bool running{false};
|
bool running{false};
|
||||||
int rel_x{0};
|
int rel_x{0};
|
||||||
int rel_y{0};
|
int rel_y{0};
|
||||||
@ -61,7 +63,6 @@ struct tray_settings {
|
|||||||
rgba foreground{};
|
rgba foreground{};
|
||||||
bool transparent{false};
|
bool transparent{false};
|
||||||
bool detached{false};
|
bool detached{false};
|
||||||
bool adaptive{false};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify, evt::client_message,
|
class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify, evt::client_message,
|
||||||
@ -80,7 +81,7 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
|
|||||||
|
|
||||||
const tray_settings settings() const;
|
const tray_settings settings() const;
|
||||||
|
|
||||||
void setup();
|
void setup(const string& tray_module_name);
|
||||||
void activate();
|
void activate();
|
||||||
void activate_delayed(chrono::duration<double, std::milli> delay = 1s);
|
void activate_delayed(chrono::duration<double, std::milli> delay = 1s);
|
||||||
void deactivate(bool clear_selection = true);
|
void deactivate(bool clear_selection = true);
|
||||||
|
@ -388,13 +388,14 @@ void bar::parse(string&& data, bool force) {
|
|||||||
|
|
||||||
auto rect = m_opts.inner_area();
|
auto rect = m_opts.inner_area();
|
||||||
|
|
||||||
if (m_tray && !m_tray->settings().detached && m_tray->settings().configured_slots && !m_tray->settings().adaptive) {
|
if (m_tray && !m_tray->settings().detached && m_tray->settings().configured_slots &&
|
||||||
auto trayalign = m_tray->settings().align;
|
m_tray->settings().tray_position != tray_postition::MODULE) {
|
||||||
|
auto tray_pos = m_tray->settings().tray_position;
|
||||||
auto traywidth = m_tray->settings().configured_w;
|
auto traywidth = m_tray->settings().configured_w;
|
||||||
if (trayalign == alignment::LEFT) {
|
if (tray_pos == tray_postition::LEFT) {
|
||||||
rect.x += traywidth;
|
rect.x += traywidth;
|
||||||
rect.width -= traywidth;
|
rect.width -= traywidth;
|
||||||
} else if (trayalign == alignment::RIGHT) {
|
} else if (tray_pos == tray_postition::RIGHT) {
|
||||||
rect.width -= traywidth;
|
rect.width -= traywidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -872,7 +873,7 @@ void bar::handle(const evt::configure_notify&) {
|
|||||||
m_sig.emit(signals::ui::update_geometry{});
|
m_sig.emit(signals::ui::update_geometry{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar::start() {
|
void bar::start(const string& tray_module_name) {
|
||||||
m_log.trace("bar: Create renderer");
|
m_log.trace("bar: Create renderer");
|
||||||
m_renderer = renderer::make(m_opts, *m_action_ctxt);
|
m_renderer = renderer::make(m_opts, *m_action_ctxt);
|
||||||
m_opts.window = m_renderer->window();
|
m_opts.window = m_renderer->window();
|
||||||
@ -900,7 +901,7 @@ void bar::start() {
|
|||||||
m_renderer->end();
|
m_renderer->end();
|
||||||
|
|
||||||
m_log.trace("bar: Setup tray manager");
|
m_log.trace("bar: Setup tray manager");
|
||||||
m_tray->setup();
|
m_tray->setup(tray_module_name);
|
||||||
|
|
||||||
broadcast_visibility();
|
broadcast_visibility();
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ void controller::read_events(bool confwatch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!m_writeback) {
|
if (!m_writeback) {
|
||||||
m_bar->start();
|
m_bar->start(m_tray_module_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -593,6 +593,13 @@ size_t controller::setup_modules(alignment align) {
|
|||||||
try {
|
try {
|
||||||
auto type = m_conf.get("module/" + module_name, "type");
|
auto type = m_conf.get("module/" + module_name, "type");
|
||||||
|
|
||||||
|
if (type == tray_module::TYPE) {
|
||||||
|
if (!m_tray_module_name.empty()) {
|
||||||
|
throw module_error("Multiple trays defined. Using tray `" + m_tray_module_name + "`");
|
||||||
|
}
|
||||||
|
m_tray_module_name = module_name;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == ipc_module::TYPE && !m_has_ipc) {
|
if (type == ipc_module::TYPE && !m_has_ipc) {
|
||||||
throw application_error("Inter-process messaging needs to be enabled");
|
throw application_error("Inter-process messaging needs to be enabled");
|
||||||
}
|
}
|
||||||
|
@ -67,25 +67,26 @@ tray_manager::~tray_manager() {
|
|||||||
deactivate();
|
deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tray_manager::setup() {
|
void tray_manager::setup(const string& tray_module_name) {
|
||||||
const config& conf = config::make();
|
const config& conf = config::make();
|
||||||
auto bs = conf.section();
|
auto bs = conf.section();
|
||||||
string position;
|
string position = conf.get(bs, "tray-position", "none"s);
|
||||||
|
|
||||||
try {
|
if (!position.empty() && position != "none" && !tray_module_name.empty()) {
|
||||||
position = conf.get(bs, "tray-position");
|
m_log.warn(
|
||||||
} catch (const key_error& err) {
|
"The tray position is manually defined (`tray-position`) and also set by the tray module (%s). `tray-position` "
|
||||||
return m_log.info("Disabling tray manager (reason: missing `tray-position`)");
|
"will be ignored",
|
||||||
|
tray_module_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position == "left") {
|
if (!tray_module_name.empty()) {
|
||||||
m_opts.align = alignment::LEFT;
|
m_opts.tray_position = tray_postition::MODULE;
|
||||||
|
} else if (position == "left") {
|
||||||
|
m_opts.tray_position = tray_postition::LEFT;
|
||||||
} else if (position == "right") {
|
} else if (position == "right") {
|
||||||
m_opts.align = alignment::RIGHT;
|
m_opts.tray_position = tray_postition::RIGHT;
|
||||||
} else if (position == "center") {
|
} else if (position == "center") {
|
||||||
m_opts.align = alignment::CENTER;
|
m_opts.tray_position = tray_postition::CENTER;
|
||||||
} else if (position == "adaptive") {
|
|
||||||
m_opts.adaptive = true;
|
|
||||||
} else if (position != "none") {
|
} else if (position != "none") {
|
||||||
return m_log.err("Disabling tray manager (reason: Invalid position \"" + position + "\")");
|
return m_log.err("Disabling tray manager (reason: Invalid position \"" + position + "\")");
|
||||||
} else {
|
} else {
|
||||||
@ -119,18 +120,20 @@ void tray_manager::setup() {
|
|||||||
|
|
||||||
auto inner_area = m_bar_opts.inner_area(true);
|
auto inner_area = m_bar_opts.inner_area(true);
|
||||||
|
|
||||||
switch (m_opts.align) {
|
switch (m_opts.tray_position) {
|
||||||
case alignment::NONE:
|
case tray_postition::NONE:
|
||||||
break;
|
break;
|
||||||
case alignment::LEFT:
|
case tray_postition::LEFT:
|
||||||
m_opts.orig_x = inner_area.x;
|
m_opts.orig_x = inner_area.x;
|
||||||
break;
|
break;
|
||||||
case alignment::CENTER:
|
case tray_postition::CENTER:
|
||||||
m_opts.orig_x = inner_area.x + inner_area.width / 2 - m_opts.width / 2;
|
m_opts.orig_x = inner_area.x + inner_area.width / 2 - m_opts.width / 2;
|
||||||
break;
|
break;
|
||||||
case alignment::RIGHT:
|
case tray_postition::RIGHT:
|
||||||
m_opts.orig_x = inner_area.x + inner_area.width;
|
m_opts.orig_x = inner_area.x + inner_area.width;
|
||||||
break;
|
break;
|
||||||
|
case tray_postition::MODULE:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conf.has(bs, "tray-transparent")) {
|
if (conf.has(bs, "tray-transparent")) {
|
||||||
@ -801,9 +804,9 @@ void tray_manager::process_docking_request(xcb_window_t win) {
|
|||||||
*/
|
*/
|
||||||
int tray_manager::calculate_x(unsigned int width) const {
|
int tray_manager::calculate_x(unsigned int width) const {
|
||||||
auto x = m_opts.orig_x;
|
auto x = m_opts.orig_x;
|
||||||
if (m_opts.align == alignment::RIGHT) {
|
if (m_opts.tray_position == tray_postition::RIGHT) {
|
||||||
x -= ((m_opts.width + m_opts.spacing) * m_clients.size() + m_opts.spacing);
|
x -= ((m_opts.width + m_opts.spacing) * m_clients.size() + m_opts.spacing);
|
||||||
} else if (m_opts.align == alignment::CENTER) {
|
} else if (m_opts.tray_position == tray_postition::CENTER) {
|
||||||
x -= (width / 2) - (m_opts.width / 2);
|
x -= (width / 2) - (m_opts.width / 2);
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
|
Loading…
Reference in New Issue
Block a user