commit d5c10bffe123589552b36f44cb348cda781a5912
parent 73a48d19aa6ade265811bc8ebc19eae0eb400bb8
Author: deurzen <m.deurzen@tum.de>
Date: Thu, 12 Aug 2021 21:49:25 +0200
adds to IPC message handling
Diffstat:
4 files changed, 91 insertions(+), 42 deletions(-)
diff --git a/src/core/model.cc b/src/core/model.cc
@@ -19,6 +19,12 @@ extern "C" {
#include <unistd.h>
}
+#ifdef ENABLE_IPC
+const bool IPC_ENABLED = true;
+#else
+const bool IPC_ENABLED = false;
+#endif
+
#ifdef DEBUG
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#endif
@@ -713,9 +719,11 @@ Model::Model(Connection& conn)
for (std::size_t i = 0; i < workspace_names.size(); ++i)
m_workspaces.insert_at_back(new Workspace(i, workspace_names[i]));
- acquire_partitions();
+ if constexpr (IPC_ENABLED)
+ m_conn.init_wm_ipc();
- m_conn.init_for_wm(WM_NAME, workspace_names);
+ acquire_partitions();
+ m_conn.init_for_wm(workspace_names);
m_contexts.activate_at_index(0);
m_workspaces.activate_at_index(0);
@@ -872,21 +880,24 @@ void
Model::run()
{
while (m_running)
- if (m_conn.block()) {
- // process IPC message
- m_conn.process_messages(
- [=,this](winsys::Message message) {
- std::visit(m_message_visitor, message);
- }
- );
+ if constexpr (IPC_ENABLED) {
+ if (m_conn.check_progress()) {
+ // process IPC message
+ m_conn.process_messages(
+ [=,this](winsys::Message message) {
+ std::visit(m_message_visitor, message);
+ }
+ );
- // process windowing system event
- m_conn.process_events(
- [=,this](winsys::Event event) {
- std::visit(m_event_visitor, event);
- }
- );
- }
+ // process windowing system event
+ m_conn.process_events(
+ [=,this](winsys::Event event) {
+ std::visit(m_event_visitor, event);
+ }
+ );
+ }
+ } else
+ std::visit(m_event_visitor, m_conn.step());
}
@@ -4005,9 +4016,11 @@ Model::process_command(winsys::CommandMessage message)
{ "Forward", winsys::Direction::Forward },
{ "forward", winsys::Direction::Forward },
{ "fwd", winsys::Direction::Forward },
+ { "f", winsys::Direction::Forward },
{ "Backward", winsys::Direction::Backward },
{ "backward", winsys::Direction::Backward },
{ "bwd", winsys::Direction::Backward },
+ { "b", winsys::Direction::Backward },
};
static const std::unordered_map<std::string_view, std::function<void(void)>> commands = {
@@ -4091,23 +4104,27 @@ Model::process_command(winsys::CommandMessage message)
}
void
-Model::process_config(winsys::ConfigMessage message)
+Model::process_config(winsys::ConfigMessage)
{
+ // TODO
}
void
-Model::process_client(winsys::WindowMessage message)
+Model::process_client(winsys::WindowMessage)
{
+ // TODO
}
void
-Model::process_workspace(winsys::WorkspaceMessage message)
+Model::process_workspace(winsys::WorkspaceMessage)
{
+ // TODO
}
void
-Model::process_query(winsys::QueryMessage message)
+Model::process_query(winsys::QueryMessage)
{
+ // TODO
}
diff --git a/src/winsys/connection.hh b/src/winsys/connection.hh
@@ -23,8 +23,10 @@ namespace winsys
public:
virtual ~Connection() {};
+ virtual void init_wm_ipc() = 0;
virtual bool flush() = 0;
- virtual bool block() = 0;
+ virtual Event step() = 0;
+ virtual bool check_progress() = 0;
virtual void process_events(std::function<void(Event)>) = 0;
virtual void process_messages(std::function<void(Message)>) = 0;
virtual std::vector<Screen> connected_outputs() = 0;
@@ -88,7 +90,7 @@ namespace winsys
virtual std::optional<SizeHints> get_icccm_window_size_hints(Window, std::optional<Dim>) = 0;
// EWMH
- virtual void init_for_wm(std::string const&, std::vector<std::string> const&) = 0;
+ virtual void init_for_wm(std::vector<std::string> const&) = 0;
virtual void set_current_desktop(Index) = 0;
virtual void set_root_window_name(std::string const&) = 0;
virtual void set_window_desktop(Window, Index) = 0;
@@ -110,6 +112,9 @@ namespace winsys
virtual bool window_is_below(Window) = 0;
virtual bool window_is_sticky(Window) = 0;
+ // IPC client
+ virtual void init_for_client() = 0;
+
};
}
diff --git a/src/winsys/xdata/xconnection.cc b/src/winsys/xdata/xconnection.cc
@@ -48,6 +48,7 @@ XConnection::XConnection(const std::string_view wm_name)
m_sock_fd(-1),
m_client_fd(-1),
m_max_fd(-1),
+ m_wm_name(wm_name),
m_interned_atoms({}),
m_atom_names({}),
m_keys({}),
@@ -126,8 +127,16 @@ XConnection::XConnection(const std::string_view wm_name)
m_event_dispatcher[event_base + RRScreenChangeNotify]
= &XConnection::on_screen_change;
}
+}
+
+XConnection::~XConnection()
+{}
- std::string socket_name = wm_name.data() + std::string("_SOCKET");
+
+void
+XConnection::init_wm_ipc()
+{
+ std::string socket_name = m_wm_name.data() + std::string("_SOCKET");
std::string wm_socket;
if (const char* env_wm_socket = std::getenv(socket_name.c_str()))
@@ -161,7 +170,7 @@ XConnection::XConnection(const std::string_view wm_name)
display_nr = display_string.substr(0, screen_nr_pos);
wm_socket = "/tmp/"
- + std::string(wm_name)
+ + std::string(m_wm_name)
+ delim + host_name
+ delim + display_nr
+ delim + screen_nr;
@@ -198,9 +207,6 @@ XConnection::XConnection(const std::string_view wm_name)
fcntl(m_sock_fd, F_SETFD, FD_CLOEXEC | fcntl(m_sock_fd, F_GETFD));
}
-XConnection::~XConnection()
-{}
-
bool
XConnection::flush()
@@ -209,8 +215,19 @@ XConnection::flush()
return true;
}
+winsys::Event
+XConnection::step()
+{
+ next_event(m_current_event);
+
+ if (m_current_event.type >= 0 && m_current_event.type <= 256)
+ return (this->*(m_event_dispatcher[m_current_event.type]))();
+
+ return std::monostate{};
+}
+
bool
-XConnection::block()
+XConnection::check_progress()
{
XFlush(mp_dpy);
@@ -225,14 +242,9 @@ XConnection::block()
void
XConnection::process_events(std::function<void(winsys::Event)> callback)
{
- if (FD_ISSET(m_dpy_fd, &m_descr)) {
- while (XPending(mp_dpy)) {
- next_event(m_current_event);
-
- if (m_current_event.type >= 0 && m_current_event.type <= 256)
- callback((this->*(m_event_dispatcher[m_current_event.type]))());
- }
- }
+ if (FD_ISSET(m_dpy_fd, &m_descr))
+ while (XPending(mp_dpy))
+ callback(step());
}
void
@@ -1299,7 +1311,7 @@ XConnection::get_icccm_window_size_hints(winsys::Window window, std::optional<wi
// EWMH
void
-XConnection::init_for_wm(std::string const& wm_name, std::vector<std::string> const& desktop_names)
+XConnection::init_for_wm(std::vector<std::string> const& desktop_names)
{
if (!mp_dpy || !m_root)
Util::die("unable to set up window manager");
@@ -1319,15 +1331,15 @@ XConnection::init_for_wm(std::string const& wm_name, std::vector<std::string> co
wa.cursor = XCreateFontCursor(mp_dpy, XC_left_ptr);
XChangeWindowAttributes(mp_dpy, m_root, CWCursor, &wa);
- std::vector<std::string> wm_class = { wm_name, wm_name };
+ std::vector<std::string> wm_class = { m_wm_name, m_wm_name };
- replace_string_property(m_check_window, "_NET_WM_NAME", wm_name);
+ replace_string_property(m_check_window, "_NET_WM_NAME", m_wm_name);
replace_stringlist_property(m_check_window, "_WM_CLASS", wm_class);
replace_card_property(m_check_window, "_NET_WM_PID", getpid());
replace_window_property(m_check_window, "_NET_SUPPORTING_WM_CHECK", m_check_window);
replace_window_property(m_root, "_NET_SUPPORTING_WM_CHECK", m_check_window);
- replace_string_property(m_root, "_NET_WM_NAME", wm_name);
+ replace_string_property(m_root, "_NET_WM_NAME", m_wm_name);
replace_stringlist_property(m_root, "_WM_CLASS", wm_class);
std::vector<Atom> supported_atoms;
@@ -1608,6 +1620,14 @@ XConnection::window_is_sticky(winsys::Window window)
}
+// IPC client
+void
+XConnection::init_for_client()
+{
+
+}
+
+
void
XConnection::enable_substructure_events()
{
diff --git a/src/winsys/xdata/xconnection.hh b/src/winsys/xdata/xconnection.hh
@@ -26,8 +26,10 @@ public:
XConnection(const std::string_view);
~XConnection();
+ virtual void init_wm_ipc() override;
virtual bool flush() override;
- virtual bool block() override;
+ virtual winsys::Event step() override;
+ virtual bool check_progress() override;
virtual void process_events(std::function<void(winsys::Event)>) override;
virtual void process_messages(std::function<void(winsys::Message)>) override;
virtual std::vector<winsys::Screen> connected_outputs() override;
@@ -91,7 +93,7 @@ public:
virtual std::optional<winsys::SizeHints> get_icccm_window_size_hints(winsys::Window, std::optional<winsys::Dim>) override;
// EWMH
- virtual void init_for_wm(std::string const&, std::vector<std::string> const&) override;
+ virtual void init_for_wm(std::vector<std::string> const&) override;
virtual void set_current_desktop(Index) override;
virtual void set_root_window_name(std::string const&) override;
virtual void set_window_desktop(winsys::Window, Index) override;
@@ -113,6 +115,9 @@ public:
virtual bool window_is_below(winsys::Window) override;
virtual bool window_is_sticky(winsys::Window) override;
+ // IPC client
+ virtual void init_for_client() override;
+
private:
static int s_otherwm_error_handler(Display*, XErrorEvent*);
static int s_passthrough_error_handler(Display*, XErrorEvent*);
@@ -192,6 +197,8 @@ private:
char m_state_path[256] = { 0 };
struct sockaddr_un m_sock_addr;
+ std::string m_wm_name;
+
XEvent m_current_event;
int m_substructure_level = 0;