#include #include #include #include #include #include #include #include "jswm_util.h" #include "jswm_ctl.h" static inline char *mask_str(t_ilm_notification_mask mask, char *buf) { if (buf) sprintf(buf, "[%x] %s %s %s %s %s %s %s %s", mask, (mask & ILM_NOTIFICATION_VISIBILITY) ? "VISIBILITY" : "", (mask & ILM_NOTIFICATION_OPACITY) ? "OPACITY" : "", (mask & ILM_NOTIFICATION_ORIENTATION) ? "ORIENTATION" : "", (mask & ILM_NOTIFICATION_SOURCE_RECT) ? "SOURCE_RECT" : "", (mask & ILM_NOTIFICATION_DEST_RECT) ? "DEST_RECT" : "", (mask & ILM_NOTIFICATION_CONTENT_AVAILABLE) ? "CONTENT_AVAILABLE" : "", (mask & ILM_NOTIFICATION_CONTENT_REMOVED) ? "CONTENT_REMOVED" : "", (mask & ILM_NOTIFICATION_CONFIGURED) ? "CONFIGURED" : ""); return buf; } static inline char *prop_str(struct ilmSurfaceProperties *p, char *buf) { if (buf) sprintf(buf, "\n\tVisibility: %d\n\tOpacity: %f\n\tOrigSource: (%d %d)\n\tSourceRec:(%d %d %d %d)\n\tDestRec:(%d %d %d %d)", p->visibility, p->opacity, p->origSourceWidth, p->origSourceHeight, p->sourceX, p->sourceY, p->sourceWidth, p->sourceHeight, p->destX, p->destY, p->destWidth, p->destHeight); return buf; } void surface_event_handler(t_ilm_surface surface, struct ilmSurfaceProperties *p, t_ilm_notification_mask mask) { struct surface_event_para sep; char ebuf[256]; char pbuf[1024]; char *estr = mask_str(mask, ebuf); char *pstr = prop_str(p, pbuf); jswm_info("Surface %d event %s\t%s\n", surface, estr, pstr); sep.surface = surface; memcpy(&sep.prop, p, sizeof(*p)); sep.mask = mask; jswm_ctl_commit(JWT_SURFACE_EVENT, &sep, sizeof(sep)); } void birth_death_handler(ilmObjectType object, t_ilm_uint id, t_ilm_bool created, void *user_data) { assert((object == ILM_SURFACE) || (object == ILM_LAYER)); do { int ret; if (object == ILM_SURFACE) { if (created) { jswm_info("Surface %d created\n", id); ret = jswm_ctl_commit(JWT_SURFACE_CREATE, &id, sizeof(id)); if (!ret) { ilmErrorTypes rc; rc = ilm_surfaceAddNotification(id, surface_event_handler); assert(rc == ILM_SUCCESS); } } else { jswm_info("Surface %d destroyed\n", id); jswm_ctl_commit(JWT_SURFACE_DESTROY, &id, sizeof(id)); } } else if (object == ILM_LAYER) { if (created) { jswm_info("Layer %d created\n", id); jswm_ctl_commit(JWT_LAYER_CREATE, &id, sizeof(id)); } else { jswm_info("Layer %d destroyed\n", id); jswm_ctl_commit(JWT_LAYER_DESTROY, &id, sizeof(id)); } } } while (0); } static int jswm_init(void) { int ret = -1; ilmErrorTypes rc; do { ret = jswm_ctl_init(); if (ret < 0) { jswm_err("Failed to initialize jswm ctrl interface.\n"); break; } rc = ilm_registerNotification(birth_death_handler, NULL); if (rc != ILM_SUCCESS) { jswm_err("Failed to register notification.\n"); break; } ret = 0; } while (0); return ret; } int main(int argc, char **argv) { int ret = 1; jswm_log_init(); do { ilmErrorTypes rc = ilm_init(); int timeout_s = 30; int it = 0; while (rc != ILM_SUCCESS) { sleep(1); if (!(--timeout_s)) break; rc = ilm_init(); } if (rc != ILM_SUCCESS) { jswm_err("Fail to connect weston."); break; } if (jswm_init() < 0) break; pause(); ret = 0; } while (0); exit(ret); }