tray: Add back legacy tray implementation
Is used for trays defined through tray-position and nothing else.
This commit is contained in:
parent
cfe9a81f55
commit
ca25b5685c
@ -23,7 +23,9 @@ class connection;
|
|||||||
class logger;
|
class logger;
|
||||||
class renderer;
|
class renderer;
|
||||||
class screen;
|
class screen;
|
||||||
|
namespace legacy_tray {
|
||||||
class tray_manager;
|
class tray_manager;
|
||||||
|
}
|
||||||
|
|
||||||
namespace tags {
|
namespace tags {
|
||||||
class dispatch;
|
class dispatch;
|
||||||
@ -92,7 +94,7 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
|
|||||||
const logger& m_log;
|
const logger& m_log;
|
||||||
eventloop::loop& m_loop;
|
eventloop::loop& m_loop;
|
||||||
unique_ptr<screen> m_screen;
|
unique_ptr<screen> m_screen;
|
||||||
unique_ptr<tray_manager> m_tray;
|
unique_ptr<legacy_tray::tray_manager> m_tray;
|
||||||
unique_ptr<renderer> m_renderer;
|
unique_ptr<renderer> m_renderer;
|
||||||
unique_ptr<tags::dispatch> m_dispatch;
|
unique_ptr<tags::dispatch> m_dispatch;
|
||||||
unique_ptr<tags::action_context> m_action_ctxt;
|
unique_ptr<tags::action_context> m_action_ctxt;
|
||||||
|
236
include/x11/legacy_tray_manager.hpp
Normal file
236
include/x11/legacy_tray_manager.hpp
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "cairo/context.hpp"
|
||||||
|
#include "cairo/surface.hpp"
|
||||||
|
#include "common.hpp"
|
||||||
|
#include "components/logger.hpp"
|
||||||
|
#include "components/types.hpp"
|
||||||
|
#include "events/signal_fwd.hpp"
|
||||||
|
#include "events/signal_receiver.hpp"
|
||||||
|
#include "utils/concurrency.hpp"
|
||||||
|
#include "x11/atoms.hpp"
|
||||||
|
#include "x11/connection.hpp"
|
||||||
|
#include "x11/xembed.hpp"
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
#define TRAY_WM_NAME "Polybar tray window"
|
||||||
|
#define TRAY_WM_CLASS "tray\0Polybar"
|
||||||
|
|
||||||
|
POLYBAR_NS
|
||||||
|
|
||||||
|
// fwd declarations
|
||||||
|
class connection;
|
||||||
|
class background_manager;
|
||||||
|
class bg_slice;
|
||||||
|
|
||||||
|
namespace legacy_tray {
|
||||||
|
|
||||||
|
namespace chrono = std::chrono;
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
using std::atomic;
|
||||||
|
|
||||||
|
enum class tray_postition { NONE = 0, LEFT, CENTER, RIGHT, MODULE };
|
||||||
|
|
||||||
|
struct tray_settings {
|
||||||
|
tray_postition tray_position{tray_postition::NONE};
|
||||||
|
bool running{false};
|
||||||
|
int rel_x{0};
|
||||||
|
int rel_y{0};
|
||||||
|
int orig_x{0};
|
||||||
|
int orig_y{0};
|
||||||
|
int configured_x{0};
|
||||||
|
int configured_y{0};
|
||||||
|
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};
|
||||||
|
rgba background{};
|
||||||
|
rgba foreground{};
|
||||||
|
bool transparent{false};
|
||||||
|
bool detached{false};
|
||||||
|
};
|
||||||
|
|
||||||
|
class tray_client {
|
||||||
|
public:
|
||||||
|
explicit tray_client(connection& conn, xcb_window_t win, unsigned int w, unsigned int h);
|
||||||
|
tray_client(const tray_client& c) = delete;
|
||||||
|
tray_client& operator=(tray_client& c) = delete;
|
||||||
|
|
||||||
|
~tray_client();
|
||||||
|
|
||||||
|
unsigned int width() const;
|
||||||
|
unsigned int height() const;
|
||||||
|
void clear_window() const;
|
||||||
|
|
||||||
|
bool match(const xcb_window_t& win) const;
|
||||||
|
bool mapped() const;
|
||||||
|
void mapped(bool state);
|
||||||
|
|
||||||
|
xcb_window_t window() const;
|
||||||
|
|
||||||
|
void query_xembed();
|
||||||
|
bool is_xembed_supported() const;
|
||||||
|
const xembed::info& get_xembed() const;
|
||||||
|
|
||||||
|
void ensure_state() const;
|
||||||
|
void reconfigure(int x, int y) const;
|
||||||
|
void configure_notify(int x, int y) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
connection& m_connection;
|
||||||
|
xcb_window_t m_window{0};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the client window supports XEMBED.
|
||||||
|
*
|
||||||
|
* A tray client can still work when it doesn't support XEMBED.
|
||||||
|
*/
|
||||||
|
bool m_xembed_supported{false};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _XEMBED_INFO of the client window
|
||||||
|
*/
|
||||||
|
xembed::info m_xembed;
|
||||||
|
|
||||||
|
bool m_mapped{false};
|
||||||
|
|
||||||
|
unsigned int m_width;
|
||||||
|
unsigned int m_height;
|
||||||
|
};
|
||||||
|
|
||||||
|
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>,
|
||||||
|
public signal_receiver<SIGN_PRIORITY_TRAY, signals::ui::visibility_change, signals::ui::dim_window,
|
||||||
|
signals::ui::update_background, signals::ui_tray::tray_pos_change, signals::ui_tray::tray_visibility>,
|
||||||
|
public non_copyable_mixin,
|
||||||
|
public non_movable_mixin {
|
||||||
|
public:
|
||||||
|
using make_type = unique_ptr<tray_manager>;
|
||||||
|
static make_type make(const bar_settings& settings);
|
||||||
|
|
||||||
|
explicit tray_manager(connection& conn, signal_emitter& emitter, const logger& logger, background_manager& back,
|
||||||
|
const bar_settings& settings);
|
||||||
|
|
||||||
|
~tray_manager();
|
||||||
|
|
||||||
|
const tray_settings settings() const;
|
||||||
|
|
||||||
|
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);
|
||||||
|
void reconfigure();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void reconfigure_window();
|
||||||
|
void reconfigure_clients();
|
||||||
|
void reconfigure_bg(bool realloc = false);
|
||||||
|
void refresh_window();
|
||||||
|
void redraw_window(bool realloc_bg = false);
|
||||||
|
|
||||||
|
void query_atom();
|
||||||
|
void create_window();
|
||||||
|
void create_bg(bool realloc = false);
|
||||||
|
void restack_window();
|
||||||
|
void set_wm_hints();
|
||||||
|
void set_tray_colors();
|
||||||
|
|
||||||
|
void acquire_selection();
|
||||||
|
void notify_clients();
|
||||||
|
void notify_clients_delayed();
|
||||||
|
|
||||||
|
void track_selection_owner(xcb_window_t owner);
|
||||||
|
void process_docking_request(xcb_window_t win);
|
||||||
|
|
||||||
|
int calculate_x(unsigned width) const;
|
||||||
|
int calculate_y(bool abspos = true) const;
|
||||||
|
|
||||||
|
unsigned short int calculate_w() const;
|
||||||
|
unsigned short int calculate_h() const;
|
||||||
|
|
||||||
|
int calculate_client_x(const xcb_window_t& win);
|
||||||
|
int calculate_client_y();
|
||||||
|
|
||||||
|
bool is_embedded(const xcb_window_t& win) const;
|
||||||
|
shared_ptr<tray_client> find_client(const xcb_window_t& win) const;
|
||||||
|
void remove_client(shared_ptr<tray_client>& client, bool reconfigure = true);
|
||||||
|
void remove_client(xcb_window_t win, bool reconfigure = true);
|
||||||
|
unsigned int mapped_clients() const;
|
||||||
|
bool change_visibility(bool visible);
|
||||||
|
|
||||||
|
void handle(const evt::expose& evt) override;
|
||||||
|
void handle(const evt::visibility_notify& evt) override;
|
||||||
|
void handle(const evt::client_message& evt) override;
|
||||||
|
void handle(const evt::configure_request& evt) override;
|
||||||
|
void handle(const evt::resize_request& evt) override;
|
||||||
|
void handle(const evt::selection_clear& evt) override;
|
||||||
|
void handle(const evt::property_notify& evt) override;
|
||||||
|
void handle(const evt::reparent_notify& evt) override;
|
||||||
|
void handle(const evt::destroy_notify& evt) override;
|
||||||
|
void handle(const evt::map_notify& evt) override;
|
||||||
|
void handle(const evt::unmap_notify& evt) override;
|
||||||
|
|
||||||
|
bool on(const signals::ui::visibility_change& evt) override;
|
||||||
|
bool on(const signals::ui::dim_window& evt) override;
|
||||||
|
bool on(const signals::ui::update_background& evt) override;
|
||||||
|
bool on(const signals::ui_tray::tray_pos_change& evt) override;
|
||||||
|
bool on(const signals::ui_tray::tray_visibility& evt) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
connection& m_connection;
|
||||||
|
signal_emitter& m_sig;
|
||||||
|
const logger& m_log;
|
||||||
|
background_manager& m_background_manager;
|
||||||
|
std::shared_ptr<bg_slice> m_bg_slice;
|
||||||
|
vector<shared_ptr<tray_client>> m_clients;
|
||||||
|
|
||||||
|
tray_settings m_opts{};
|
||||||
|
|
||||||
|
xcb_gcontext_t m_gc{0};
|
||||||
|
xcb_pixmap_t m_pixmap{0};
|
||||||
|
unique_ptr<cairo::surface> m_surface;
|
||||||
|
unique_ptr<cairo::context> m_context;
|
||||||
|
|
||||||
|
unsigned int m_prevwidth{0U};
|
||||||
|
unsigned int m_prevheight{0U};
|
||||||
|
|
||||||
|
xcb_atom_t m_atom{0};
|
||||||
|
xcb_window_t m_tray{0};
|
||||||
|
xcb_window_t m_othermanager{0};
|
||||||
|
|
||||||
|
atomic<bool> m_activated{false};
|
||||||
|
atomic<bool> m_mapped{false};
|
||||||
|
atomic<bool> m_hidden{false};
|
||||||
|
atomic<bool> m_acquired_selection{false};
|
||||||
|
|
||||||
|
thread m_delaythread;
|
||||||
|
|
||||||
|
mutex m_mtx{};
|
||||||
|
|
||||||
|
bool m_firstactivation{true};
|
||||||
|
|
||||||
|
const bar_settings& m_bar_opts;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace legacy_tray
|
||||||
|
|
||||||
|
POLYBAR_NS_END
|
@ -132,6 +132,7 @@ set(POLY_SOURCES
|
|||||||
${src_dir}/x11/extensions/randr.cpp
|
${src_dir}/x11/extensions/randr.cpp
|
||||||
${src_dir}/x11/icccm.cpp
|
${src_dir}/x11/icccm.cpp
|
||||||
${src_dir}/x11/registry.cpp
|
${src_dir}/x11/registry.cpp
|
||||||
|
${src_dir}/x11/legacy_tray_manager.cpp
|
||||||
${src_dir}/x11/tray_client.cpp
|
${src_dir}/x11/tray_client.cpp
|
||||||
${src_dir}/x11/tray_manager.cpp
|
${src_dir}/x11/tray_manager.cpp
|
||||||
${src_dir}/x11/window.cpp
|
${src_dir}/x11/window.cpp
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "x11/ewmh.hpp"
|
#include "x11/ewmh.hpp"
|
||||||
#include "x11/extensions/all.hpp"
|
#include "x11/extensions/all.hpp"
|
||||||
#include "x11/icccm.hpp"
|
#include "x11/icccm.hpp"
|
||||||
#include "x11/tray_manager.hpp"
|
#include "x11/legacy_tray_manager.hpp"
|
||||||
|
|
||||||
#if WITH_XCURSOR
|
#if WITH_XCURSOR
|
||||||
#include "x11/cursor.hpp"
|
#include "x11/cursor.hpp"
|
||||||
@ -57,8 +57,6 @@ bar::make_type bar::make(loop& loop, bool only_initialize_values) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct bar instance
|
* Construct bar instance
|
||||||
*
|
|
||||||
* TODO: Break out all tray handling
|
|
||||||
*/
|
*/
|
||||||
bar::bar(connection& conn, signal_emitter& emitter, const config& config, const logger& logger, loop& loop,
|
bar::bar(connection& conn, signal_emitter& emitter, const config& config, const logger& logger, loop& loop,
|
||||||
unique_ptr<screen>&& screen, unique_ptr<tags::dispatch>&& dispatch, unique_ptr<tags::action_context>&& action_ctxt,
|
unique_ptr<screen>&& screen, unique_ptr<tags::dispatch>&& dispatch, unique_ptr<tags::action_context>&& action_ctxt,
|
||||||
@ -73,7 +71,7 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
|||||||
, m_action_ctxt(forward<decltype(action_ctxt)>(action_ctxt)) {
|
, m_action_ctxt(forward<decltype(action_ctxt)>(action_ctxt)) {
|
||||||
string bs{m_conf.section()};
|
string bs{m_conf.section()};
|
||||||
|
|
||||||
// m_tray = tray_manager::make(m_opts);
|
m_tray = legacy_tray::tray_manager::make(m_opts);
|
||||||
|
|
||||||
// Get available RandR outputs
|
// Get available RandR outputs
|
||||||
auto monitor_name = m_conf.get(bs, "monitor", ""s);
|
auto monitor_name = m_conf.get(bs, "monitor", ""s);
|
||||||
@ -388,20 +386,16 @@ void bar::parse(string&& data, bool force) {
|
|||||||
|
|
||||||
auto rect = m_opts.inner_area();
|
auto rect = m_opts.inner_area();
|
||||||
|
|
||||||
// TODO use legacy tray implementation
|
if (m_tray && !m_tray->settings().detached && m_tray->settings().configured_slots) {
|
||||||
#if 0
|
|
||||||
if (m_tray && !m_tray->settings().detached && m_tray->settings().num_mapped_clients > 0 &&
|
|
||||||
m_tray->settings().tray_position != tray_postition::MODULE) {
|
|
||||||
auto tray_pos = m_tray->settings().tray_position;
|
auto tray_pos = m_tray->settings().tray_position;
|
||||||
auto traywidth = m_tray->settings().win_size.w;
|
auto traywidth = m_tray->settings().configured_w;
|
||||||
if (tray_pos == tray_postition::LEFT) {
|
if (tray_pos == legacy_tray::tray_postition::LEFT) {
|
||||||
rect.x += traywidth;
|
rect.x += traywidth;
|
||||||
rect.width -= traywidth;
|
rect.width -= traywidth;
|
||||||
} else if (tray_pos == tray_postition::RIGHT) {
|
} else if (tray_pos == legacy_tray::tray_postition::RIGHT) {
|
||||||
rect.width -= traywidth;
|
rect.width -= traywidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
m_log.info("Redrawing bar window");
|
m_log.info("Redrawing bar window");
|
||||||
m_renderer->begin(rect);
|
m_renderer->begin(rect);
|
||||||
@ -840,10 +834,9 @@ void bar::handle(const evt::button_press& evt) {
|
|||||||
*/
|
*/
|
||||||
void bar::handle(const evt::expose& evt) {
|
void bar::handle(const evt::expose& evt) {
|
||||||
if (evt->window == m_opts.x_data.window && evt->count == 0) {
|
if (evt->window == m_opts.x_data.window && evt->count == 0) {
|
||||||
// TODO
|
if (m_tray && m_tray->settings().running) {
|
||||||
// if (m_tray->running()) {
|
broadcast_visibility();
|
||||||
// broadcast_visibility();
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
m_log.trace("bar: Received expose event");
|
m_log.trace("bar: Received expose event");
|
||||||
m_renderer->flush();
|
m_renderer->flush();
|
||||||
@ -880,7 +873,7 @@ void bar::handle(const evt::configure_notify& evt) {
|
|||||||
m_sig.emit(signals::ui::update_geometry{});
|
m_sig.emit(signals::ui::update_geometry{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar::start(const string&) {
|
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);
|
||||||
|
|
||||||
@ -911,7 +904,12 @@ void bar::start(const string&) {
|
|||||||
m_renderer->end();
|
m_renderer->end();
|
||||||
|
|
||||||
m_log.trace("bar: Setup tray manager");
|
m_log.trace("bar: Setup tray manager");
|
||||||
// m_tray->setup(tray_module_name);
|
m_tray->setup(tray_module_name);
|
||||||
|
|
||||||
|
if (m_tray->settings().tray_position == legacy_tray::tray_postition::MODULE ||
|
||||||
|
m_tray->settings().tray_position == legacy_tray::tray_postition::NONE) {
|
||||||
|
m_tray.reset();
|
||||||
|
}
|
||||||
|
|
||||||
broadcast_visibility();
|
broadcast_visibility();
|
||||||
}
|
}
|
||||||
|
1292
src/x11/legacy_tray_manager.cpp
Normal file
1292
src/x11/legacy_tray_manager.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user