Example of event handling

This commit is contained in:
Sergey Naumov
2016-04-24 11:15:47 +03:00
parent f63bff821f
commit c5735c4c1e
2 changed files with 28 additions and 0 deletions

View File

@@ -15,3 +15,6 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
add_executable(workspaces workspaces.cpp)
target_link_libraries(workspaces ${I3IPCpp_LIBRARIES})
add_executable(events events.cpp)
target_link_libraries(events ${I3IPCpp_LIBRARIES})

25
examples/events.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include <iostream>
#include <i3ipc++/ipc.hpp>
int main() {
i3ipc::connection conn;
conn.subscribe(i3ipc::ET_WORKSPACE | i3ipc::ET_WINDOW);
conn.signal_workspace_event.connect([](const i3ipc::workspace_event_t& ev) {
std::cout << "workspace_event: " << (char)ev.type << std::endl;
});
conn.signal_window_event.connect([](const i3ipc::window_event_t& ev) {
std::cout << "window_event: " << (char)ev.type << std::endl;
});
// Don't forget this:
conn.prepare_to_event_handling();
while (true) {
conn.handle_event();
}
return 0;
}