Skip to content

Commit

Permalink
Use individual wrapper window for each tray client
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick96 committed Mar 16, 2022
1 parent 92fe053 commit 1a4ad99
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 90 deletions.
16 changes: 10 additions & 6 deletions include/components/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ class logger {

explicit logger(loglevel level);

const logger& operator=(const logger&) const {
return *this;
}

static loglevel parse_verbosity(const string& name, loglevel fallback = loglevel::NONE);

void verbosity(loglevel level);

#ifdef DEBUG_LOGGER // {{{
#ifdef DEBUG_LOGGER // {{{
template <typename... Args>
void trace(const string& message, Args&&... args) const {
output(loglevel::TRACE, message, std::forward<Args>(args)...);
Expand All @@ -57,7 +61,7 @@ class logger {
void trace(Args&&...) const {}
template <typename... Args>
void trace_x(Args&&...) const {}
#endif // }}}
#endif // }}}

/**
* Output an info message
Expand Down Expand Up @@ -118,21 +122,21 @@ class logger {
return;
}

#if defined(__clang__) // {{{
#if defined(__clang__) // {{{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-security"
#endif // }}}
#endif // }}}

dprintf(m_fd, (m_prefixes.at(level) + format + m_suffixes.at(level) + "\n").c_str(), convert(values)...);

#if defined(__clang__) // {{{
#if defined(__clang__) // {{{
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif // }}}
#endif // }}}
}

private:
Expand Down
29 changes: 26 additions & 3 deletions include/x11/tray_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class connection;

class tray_client : public non_copyable_mixin {
public:
explicit tray_client(connection& conn, xcb_window_t win, size s);
explicit tray_client(const logger& log, connection& conn, xcb_window_t tray, xcb_window_t win, size s);
~tray_client();

tray_client(tray_client&&);
Expand All @@ -27,7 +27,8 @@ class tray_client : public non_copyable_mixin {
bool mapped() const;
void mapped(bool state);

xcb_window_t window() const;
xcb_window_t embedder() const;
xcb_window_t client() const;

void query_xembed();
bool is_xembed_supported() const;
Expand All @@ -38,8 +39,27 @@ class tray_client : public non_copyable_mixin {
void configure_notify(int x, int y) const;

protected:
const logger& m_log;

connection& m_connection;
xcb_window_t m_window{XCB_NONE};

/**
* Embedder window.
*
* The docking client window is reparented to this window.
* This window is itself a child of the main tray window.
*
* This class owns this window and is responsible for creating/destroying it.
*/
xcb_window_t m_wrapper{XCB_NONE};

/**
* Client window.
*
* The window itself is owned by the application providing it.
* This class is responsible for correctly mapping and reparenting it in accordance with the XEMBED protocol.
*/
xcb_window_t m_client{XCB_NONE};

/**
* Whether the client window supports XEMBED.
Expand All @@ -50,9 +70,12 @@ class tray_client : public non_copyable_mixin {

/**
* _XEMBED_INFO of the client window
*
* Only valid if m_xembed_supported == true
*/
xembed::info m_xembed;

// TODO
bool m_mapped{false};

size m_size;
Expand Down
2 changes: 1 addition & 1 deletion include/x11/tray_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct tray_settings {
/**
* Number of clients currently mapped.
*/
int num_clients{0};
int num_mapped_clients{0};

// This is the width of the bar window
// TODO directly read from bar_settings
Expand Down
54 changes: 27 additions & 27 deletions include/x11/xembed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@

POLYBAR_NS

#define XEMBED_VERSION 0
#define XEMBED_MAPPED (1 << 0)

#define XEMBED_EMBEDDED_NOTIFY 0
#define XEMBED_WINDOW_ACTIVATE 1
#define XEMBED_WINDOW_DEACTIVATE 2
#define XEMBED_REQUEST_FOCUS 3
#define XEMBED_FOCUS_IN 3
#define XEMBED_FOCUS_OUT 4
#define XEMBED_FOCUS_NEXT 5
#define XEMBED_FOCUS_PREV 6

#define XEMBED_FOCUS_CURRENT 0
#define XEMBED_FOCUS_FIRST 1
#define XEMBED_FOCUS_LAST 1
static constexpr uint32_t XEMBED_VERSION = 0;
static constexpr uint32_t XEMBED_MAPPED = (1 << 0);

static constexpr uint32_t XEMBED_EMBEDDED_NOTIFY = 0;
static constexpr uint32_t XEMBED_WINDOW_ACTIVATE = 1;
static constexpr uint32_t XEMBED_WINDOW_DEACTIVATE = 2;
static constexpr uint32_t XEMBED_REQUEST_FOCUS = 3;
static constexpr uint32_t XEMBED_FOCUS_IN = 3;
static constexpr uint32_t XEMBED_FOCUS_OUT = 4;
static constexpr uint32_t XEMBED_FOCUS_NEXT = 5;
static constexpr uint32_t XEMBED_FOCUS_PREV = 6;

static constexpr uint32_t XEMBED_FOCUS_CURRENT = 0;
static constexpr uint32_t XEMBED_FOCUS_FIRST = 1;
static constexpr uint32_t XEMBED_FOCUS_LAST = 2;

/**
* Max XEMBED version supported.
*/
#define XEMBED_MAX_VERSION UINT32_C(0)
static constexpr uint32_t XEMBED_MAX_VERSION = 0;

/**
* Implementation of parts of the XEMBED spec (as much as needed to get the tray working).
Expand All @@ -34,28 +34,28 @@ POLYBAR_NS
namespace xembed {

class info {
public:
void set(uint32_t* data);
public:
void set(uint32_t* data);

uint32_t get_version() const;
uint32_t get_flags() const;
uint32_t get_version() const;
uint32_t get_flags() const;

bool is_mapped() const;
bool is_mapped() const;

protected:
uint32_t version;
uint32_t flags;
protected:
uint32_t version;
uint32_t flags;
};

bool query(connection& conn, xcb_window_t win, info& data);
void send_message(connection& conn, xcb_window_t target, long message, long d1, long d2, long d3);
void send_message(connection& conn, xcb_window_t target, uint32_t message, uint32_t d1, uint32_t d2, uint32_t d3);
void send_focus_event(connection& conn, xcb_window_t target);
void notify_embedded(connection& conn, xcb_window_t win, xcb_window_t embedder, uint32_t version);
void notify_activated(connection& conn, xcb_window_t win);
void notify_deactivated(connection& conn, xcb_window_t win);
void notify_focused(connection& conn, xcb_window_t win, long focus_type);
void notify_focused(connection& conn, xcb_window_t win, uint32_t focus_type);
void notify_unfocused(connection& conn, xcb_window_t win);
void unembed(connection& conn, xcb_window_t win, xcb_window_t root);
} // namespace xembed
} // namespace xembed

POLYBAR_NS_END
6 changes: 3 additions & 3 deletions src/components/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ bar::make_type bar::make(loop& loop, bool only_initialize_values) {
* TODO: Break out all tray handling
*/
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, bool only_initialize_values)
unique_ptr<screen>&& screen, unique_ptr<tags::dispatch>&& dispatch, unique_ptr<tags::action_context>&& action_ctxt,
bool only_initialize_values)
: m_connection(conn)
, m_sig(emitter)
, m_conf(config)
Expand Down Expand Up @@ -386,7 +386,7 @@ void bar::parse(string&& data, bool force) {

auto rect = m_opts.inner_area();

if (m_tray && !m_tray->settings().detached && m_tray->settings().num_clients > 0) {
if (m_tray && !m_tray->settings().detached && m_tray->settings().num_mapped_clients > 0) {
auto trayalign = m_tray->settings().align;
auto traywidth = m_tray->settings().win_size.w;
if (trayalign == alignment::LEFT) {
Expand Down

0 comments on commit 1a4ad99

Please sign in to comment.