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;
|
||||
|
||||
void start();
|
||||
void start(const string& tray_module_name);
|
||||
|
||||
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;
|
||||
unique_ptr<bar> m_bar;
|
||||
bool m_has_ipc;
|
||||
string m_tray_module_name;
|
||||
|
||||
/**
|
||||
* @brief Async handle to notify the eventloop
|
||||
|
@ -39,8 +39,10 @@ class connection;
|
||||
class background_manager;
|
||||
class bg_slice;
|
||||
|
||||
enum class tray_postition { NONE = 0, LEFT, CENTER, RIGHT, MODULE };
|
||||
|
||||
struct tray_settings {
|
||||
alignment align{alignment::NONE};
|
||||
tray_postition tray_position{tray_postition::NONE};
|
||||
bool running{false};
|
||||
int rel_x{0};
|
||||
int rel_y{0};
|
||||
@ -61,7 +63,6 @@ struct tray_settings {
|
||||
rgba foreground{};
|
||||
bool transparent{false};
|
||||
bool detached{false};
|
||||
bool adaptive{false};
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
void setup();
|
||||
void setup(const string& tray_module_name);
|
||||
void activate();
|
||||
void activate_delayed(chrono::duration<double, std::milli> delay = 1s);
|
||||
void deactivate(bool clear_selection = true);
|
||||
|
@ -388,13 +388,14 @@ void bar::parse(string&& data, bool force) {
|
||||
|
||||
auto rect = m_opts.inner_area();
|
||||
|
||||
if (m_tray && !m_tray->settings().detached && m_tray->settings().configured_slots && !m_tray->settings().adaptive) {
|
||||
auto trayalign = m_tray->settings().align;
|
||||
if (m_tray && !m_tray->settings().detached && m_tray->settings().configured_slots &&
|
||||
m_tray->settings().tray_position != tray_postition::MODULE) {
|
||||
auto tray_pos = m_tray->settings().tray_position;
|
||||
auto traywidth = m_tray->settings().configured_w;
|
||||
if (trayalign == alignment::LEFT) {
|
||||
if (tray_pos == tray_postition::LEFT) {
|
||||
rect.x += traywidth;
|
||||
rect.width -= traywidth;
|
||||
} else if (trayalign == alignment::RIGHT) {
|
||||
} else if (tray_pos == tray_postition::RIGHT) {
|
||||
rect.width -= traywidth;
|
||||
}
|
||||
}
|
||||
@ -872,7 +873,7 @@ void bar::handle(const evt::configure_notify&) {
|
||||
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_renderer = renderer::make(m_opts, *m_action_ctxt);
|
||||
m_opts.window = m_renderer->window();
|
||||
@ -900,7 +901,7 @@ void bar::start() {
|
||||
m_renderer->end();
|
||||
|
||||
m_log.trace("bar: Setup tray manager");
|
||||
m_tray->setup();
|
||||
m_tray->setup(tray_module_name);
|
||||
|
||||
broadcast_visibility();
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ void controller::read_events(bool confwatch) {
|
||||
}
|
||||
|
||||
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 {
|
||||
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) {
|
||||
throw application_error("Inter-process messaging needs to be enabled");
|
||||
}
|
||||
|
@ -67,25 +67,26 @@ tray_manager::~tray_manager() {
|
||||
deactivate();
|
||||
}
|
||||
|
||||
void tray_manager::setup() {
|
||||
void tray_manager::setup(const string& tray_module_name) {
|
||||
const config& conf = config::make();
|
||||
auto bs = conf.section();
|
||||
string position;
|
||||
string position = conf.get(bs, "tray-position", "none"s);
|
||||
|
||||
try {
|
||||
position = conf.get(bs, "tray-position");
|
||||
} catch (const key_error& err) {
|
||||
return m_log.info("Disabling tray manager (reason: missing `tray-position`)");
|
||||
if (!position.empty() && position != "none" && !tray_module_name.empty()) {
|
||||
m_log.warn(
|
||||
"The tray position is manually defined (`tray-position`) and also set by the tray module (%s). `tray-position` "
|
||||
"will be ignored",
|
||||
tray_module_name);
|
||||
}
|
||||
|
||||
if (position == "left") {
|
||||
m_opts.align = alignment::LEFT;
|
||||
if (!tray_module_name.empty()) {
|
||||
m_opts.tray_position = tray_postition::MODULE;
|
||||
} else if (position == "left") {
|
||||
m_opts.tray_position = tray_postition::LEFT;
|
||||
} else if (position == "right") {
|
||||
m_opts.align = alignment::RIGHT;
|
||||
m_opts.tray_position = tray_postition::RIGHT;
|
||||
} else if (position == "center") {
|
||||
m_opts.align = alignment::CENTER;
|
||||
} else if (position == "adaptive") {
|
||||
m_opts.adaptive = true;
|
||||
m_opts.tray_position = tray_postition::CENTER;
|
||||
} else if (position != "none") {
|
||||
return m_log.err("Disabling tray manager (reason: Invalid position \"" + position + "\")");
|
||||
} else {
|
||||
@ -119,18 +120,20 @@ void tray_manager::setup() {
|
||||
|
||||
auto inner_area = m_bar_opts.inner_area(true);
|
||||
|
||||
switch (m_opts.align) {
|
||||
case alignment::NONE:
|
||||
switch (m_opts.tray_position) {
|
||||
case tray_postition::NONE:
|
||||
break;
|
||||
case alignment::LEFT:
|
||||
case tray_postition::LEFT:
|
||||
m_opts.orig_x = inner_area.x;
|
||||
break;
|
||||
case alignment::CENTER:
|
||||
case tray_postition::CENTER:
|
||||
m_opts.orig_x = inner_area.x + inner_area.width / 2 - m_opts.width / 2;
|
||||
break;
|
||||
case alignment::RIGHT:
|
||||
case tray_postition::RIGHT:
|
||||
m_opts.orig_x = inner_area.x + inner_area.width;
|
||||
break;
|
||||
case tray_postition::MODULE:
|
||||
break;
|
||||
}
|
||||
|
||||
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 {
|
||||
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);
|
||||
} else if (m_opts.align == alignment::CENTER) {
|
||||
} else if (m_opts.tray_position == tray_postition::CENTER) {
|
||||
x -= (width / 2) - (m_opts.width / 2);
|
||||
}
|
||||
return x;
|
||||
|
Loading…
Reference in New Issue
Block a user