From c5735c4c1e444f285d81c9842a5259866ae13434 Mon Sep 17 00:00:00 2001 From: Sergey Naumov Date: Sun, 24 Apr 2016 11:15:47 +0300 Subject: [PATCH] Example of event handling --- examples/CMakeLists.txt | 3 +++ examples/events.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 examples/events.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 3be1743..f7b7de7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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}) diff --git a/examples/events.cpp b/examples/events.cpp new file mode 100644 index 0000000..efcf81c --- /dev/null +++ b/examples/events.cpp @@ -0,0 +1,25 @@ +#include + +#include + + +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; +}