int ipc_init() { GError *err = NULL; connection = i3ipc_connection_new(NULL, &err); if (err != NULL) { LOG("error connecting: %s\n", err->message); g_error_free(err); return 1; } return 0; }
static J4statusPluginContext * _j4status_i3focus_init(J4statusCoreInterface *core) { i3ipcConnection *connection; i3ipcCommandReply *reply; GError *error = NULL; connection = i3ipc_connection_new(NULL, &error); if ( connection == NULL ) { g_warning("Couldn't connection to i3: %s", error->message); g_clear_error(&error); return NULL; } reply = i3ipc_connection_subscribe(connection, I3IPC_EVENT_WINDOW, &error); if ( reply == NULL ) { g_warning("Couldn't subscribe to i3 events: %s", error->message); g_clear_error(&error); g_object_unref(connection); return NULL; } if ( ! reply->success ) { g_warning("Couldn't subscribe to i3 events: %s", reply->error); i3ipc_command_reply_free(reply); g_object_unref(connection); return NULL; } i3ipc_command_reply_free(reply); J4statusPluginContext *context; context = g_new0(J4statusPluginContext, 1); context->connection = connection; context->section = j4status_section_new(core); j4status_section_set_name(context->section, "i3focus"); if ( ! j4status_section_insert(context->section) ) { _j4status_i3focus_uninit(context); return NULL; } g_signal_connect(context->connection, "window", G_CALLBACK(_j4status_i3focus_window_callback), context->section); return context; }
void workspace_callback (i3ipcConnection *conn, i3ipcWorkspaceEvent *event, gpointer user_data) { struct widget *widget = (struct widget*)user_data; json_t *json_data_object = format_workspaces(conn); char *json_str = strdup(json_dumps(json_data_object, 0)); struct js_callback_arg arg = widget_data_arg_string(json_str); struct js_callback_data data = { .widget = widget, .args = &arg, 1 }; web_view_callback(&data); free(json_str); } void* widget_main (struct widget *widget) { i3ipcConnection *conn = i3ipc_connection_new(NULL, NULL); json_t *json_data_object = format_workspaces(conn); char *json_str = strdup(json_dumps(json_data_object, 0)); widget_data_callback(widget, widget_data_arg_string(json_str)); free(json_str); void (*callback)(i3ipcConnection*, i3ipcWorkspaceEvent*, gpointer); callback = workspace_callback; GClosure *closure = g_cclosure_new(G_CALLBACK(callback), widget, NULL); i3ipc_connection_on(conn, (const gchar*)"workspace", closure, NULL); widget_epoll_init(widget); while (true) { widget_epoll_wait_goto(widget, 1000, cleanup); } cleanup: g_object_unref(conn); widget_epoll_cleanup(widget); widget_clean_exit(widget); }