Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/panel/panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,15 @@ class WayfirePanel::impl

if (name == "language")
{
return Widget(new WayfireLanguage());
if (WayfireIPC::get_instance()->connected)
{
return Widget(new WayfireLanguage());
} else
{
std::cerr << "Wayfire IPC not connected, which is required to load language widget." <<
std::endl;
return nullptr;
}
}

if (auto pixel = widget_with_value(name, "spacing"))
Expand Down
8 changes: 8 additions & 0 deletions src/panel/widgets/language.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <cstddef>
#include <cstdint>

Expand Down Expand Up @@ -25,6 +26,13 @@ void WayfireLanguage::init(Gtk::Box *container)
ipc_client->subscribe(this, {"keyboard-modifier-state-changed"});
ipc_client->send("{\"method\":\"wayfire/get-keyboard-state\"}", [=] (wf::json_t data)
{
if (data.serialize().find(
"error") != std::string::npos)
{
std::cerr << "Error getting keyboard state for language widget. Is wayfire ipc-rules plugin enabled?" << std::endl;
return;
}

set_available(data["possible-layouts"]);
set_current(data["layout-index"]);
});
Expand Down
53 changes: 37 additions & 16 deletions src/util/wf-ipc.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <cstdint>
#include <cstdlib>
#include <cstring>
Expand Down Expand Up @@ -31,34 +32,54 @@

WayfireIPC::WayfireIPC()
{
connect();
if (connect())
{
sig_connection = Glib::signal_io().connect(
sigc::mem_fun(*this, &WayfireIPC::receive),
connection->get_socket()->get_fd(),
Glib::IOCondition::IO_IN);

sig_connection = Glib::signal_io().connect(
sigc::mem_fun(*this, &WayfireIPC::receive),
connection->get_socket()->get_fd(),
Glib::IOCondition::IO_IN);
connected = true;
} else
{
std::cerr << "Failed to connect to WAYFIRE_SOCKET. Is wayfire ipc plugin enabled?" << std::endl;
}
}

WayfireIPC::~WayfireIPC()
{
disconnect();
if (connected)
{
disconnect();
}
}

void WayfireIPC::connect()
bool WayfireIPC::connect()
{
const char *socket_path = getenv("WAYFIRE_SOCKET");
if (socket_path == nullptr)
if (!socket_path || std::string(socket_path).empty())
{
throw std::runtime_error("Wayfire socket not found");
std::cerr << "Wayfire socket not found" << std::endl;
return false;
}

auto client = Gio::SocketClient::create();
auto address = Gio::UnixSocketAddress::create(socket_path);
connection = client->connect(address);
connection->get_socket()->set_blocking(false);
output = connection->get_output_stream();
input = connection->get_input_stream();
cancel = Gio::Cancellable::create();
try {
auto client = Gio::SocketClient::create();
auto address = Gio::UnixSocketAddress::create(socket_path);
connection = client->connect(address);
connection->get_socket()->set_blocking(false);
output = connection->get_output_stream();
input = connection->get_input_stream();
cancel = Gio::Cancellable::create();

return true;
} catch (const Glib::Error& ex)
{
std::cerr << "Error connecting to WAYFIRE_SOCKET: " << ex.what();
return false;
}

return false;
}

void WayfireIPC::disconnect()
Expand Down
3 changes: 2 additions & 1 deletion src/util/wf-ipc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class WayfireIPC : public std::enable_shared_from_this<WayfireIPC>
std::queue<std::string> write_queue;
bool writing = false;

void connect();
bool connect();
void disconnect();
void send_message(const std::string& message);
bool send_queue(Glib::IOCondition cond);
Expand All @@ -76,6 +76,7 @@ class WayfireIPC : public std::enable_shared_from_this<WayfireIPC>
void client_destroyed(int id);

static std::shared_ptr<WayfireIPC> get_instance();
bool connected = false;
WayfireIPC();
~WayfireIPC();
};
Loading