Bool container_split(container_t *container, unsigned int split_type) { XWindowAttributes attr; int new_x, new_y; unsigned int width, height; container_t *new_container; wm_log(container->wm, LOG_INFO, "%s: horizontal split", __func__); XGetWindowAttributes(container->wm->dpy, container->frame, &attr); if (split_type == SPLIT_VERTICAL) { width = attr.width / 2; height = attr.height; new_x = attr.x + width; new_y = attr.y; } else { /* SPLIT_HORIZONTAL */ width = attr.width; height = attr.height / 2; new_x = attr.x; new_y = attr.y + height; } container_moveresize(container, attr.x, attr.y, width, height); new_container = container_new(container->wm, attr.root, new_x, new_y, width, height); container_show(new_container); XFlush(container->wm->dpy); container_relocate_top_client(container, new_container); container_paint(container); container_paint(new_container); return True; }
GraceApp *gapp_new(void) { GraceApp *gapp; gapp = xmalloc(sizeof(GraceApp)); if (!gapp) { return NULL; } memset(gapp, 0, sizeof(GraceApp)); if (grace_init() != RETURN_SUCCESS) { gapp_free(gapp); return NULL; } gapp->grace = grace_new(bi_home()); if (!gapp->grace) { gapp_free(gapp); return NULL; } graal_set_eval_proc(grace_get_graal(gapp->grace), eval_proc); grace_set_udata(gapp->grace, gapp); gapp->rt = runtime_new(gapp); if (!gapp->rt) { gapp_free(gapp); return NULL; } gapp->gui = gui_new(gapp); if (!gapp->gui) { gapp_free(gapp); return NULL; } gapp->pc = container_new(grace_get_qfactory(gapp->grace), AMEM_MODEL_SIMPLE); if (!gapp->pc) { gapp_free(gapp); return NULL; } return gapp; }
int main(int argc, char **argv) { wm_t *wm = NULL; int i; wm = wm_create(NULL); wm_set_log_level(wm, LOG_INFO); container_context = XUniqueContext(); client_container_context = XUniqueContext(); wm_log(wm, LOG_INFO, "== num screens: %d", wm->num_screens); for (i = 0; i < wm->num_screens; i++) { XWindowAttributes attr; Window root = wm->screens[i]->root;; container_t *root_container; XGetWindowAttributes(wm->dpy, root, &attr); root_container = container_new(wm, root, attr.x, attr.y, attr.width, attr.height); container_show(root_container); wm_log(wm, LOG_INFO, "Setting current container to %tx", root_container); current_container = root_container; /* Grab keys */ XGrabKey(wm->dpy, XKeysymToKeycode(wm->dpy, XK_j), Mod1Mask, root, False, GrabModeAsync, GrabModeAsync); XGrabKey(wm->dpy, XKeysymToKeycode(wm->dpy, XK_h), Mod1Mask, root, False, GrabModeAsync, GrabModeAsync); } container_focus(current_container); wm_listener_add(wm, WM_EVENT_MAPREQUEST, addwin); wm_listener_add(wm, WM_EVENT_MAPNOTIFY, addwin); wm_listener_add(wm, WM_EVENT_UNMAPNOTIFY, unmap); wm_listener_add(wm, WM_EVENT_ENTERNOTIFY, focus_container); wm_listener_add(wm, WM_EVENT_EXPOSE, expose_container); wm_listener_add(wm, WM_EVENT_KEYDOWN, keydown); wm_listener_add(wm, WM_EVENT_KEYUP, keyup); /* Start main loop. At this point, our code will only execute when events * happen */ XSync(wm->dpy, False); wm_main(wm); return 0; }