Skip to content

Ralino/i3ipcpp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License

i3ipc++

An implementation of i3 IPC in C++11.

Requirements

  • cmake (>= 3.0)
  • C++11 compiler
  • sigc++ 2.0
  • jsoncpp

Using

Yet the only way of using is to add this repo as a submodule

git submodule add https://github.com/drmgc/i3ipcpp.git ./i3ipc++/

Then just type this in your CMakeLists.txt:

...
add_subdirectory(i3ipc++)

include_directories(${I3IPCpp_INCLUDE_DIRS})
link_directories(${I3IPCpp_LIBRARY_DIRS})
...

And then just link:

...
target_link_libraries(someapp ${I3IPCpp_LIBRARIES})
...

Usage

See also examples in examples/ directory.

Connecting

#include <i3ipc++/ipc.hpp>

i3ipc::connection  conn;

The connection will be established automaticly.

Event handling

First of all you need to declare the events you want to handle. As example we want to handle an binding and workspace events:

conn.subscribe(i3ipc::ET_WORKSPACE | i3ipc::ET_BINDING);

Then we need to connect to the signal handlers:

// Handler of WORKSPACE EVENT
conn.signal_workspace_event.connect([](const i3ipc::workspace_event_t&  ev) {
	std::cout << "workspace_event: " << (char)ev.type << std::endl;
	if (ev.current) {
		std::cout << "\tSwitched to #" << ev.current->num << " - \"" << ev.current->name << '"' << std::endl;
	}
});

// Handler of binding event
conn.signal_binding_event.connect([](const i3ipc::binding_t&  b) {
	std::cout << "binding_event:" << std::endl
		<< "\tcommand = \"" << b.command << '"' << std::endl
		<< "\tinput_code = " << b.input_code << std::endl
		<< "\tsymbol = " << b.symbol << std::endl
		<< "\tinput_type = " << static_cast<char>(b.input_type) << std::endl
		<< "<