Example of event handling
This commit is contained in:
@@ -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
25
examples/events.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user